Changeset 102 for trunk/UCore.pas


Ignore:
Timestamp:
Oct 4, 2012, 2:06:55 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Kostra modulů IS a Portal. TWebSession je nutno oddělit z UCore.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r101 r102  
    1919  TCore = class;
    2020
    21   { TWebSession }
    22 
    23   TWebSession = class(THTTPHandlerData)
    24   private
    25     procedure TopMenu;
    26     procedure Footer;
    27   public
    28     MainModule: TCore;
    29     Database: TSqlDatabase;
    30     SessionStorage: THTTPSessionStorageMySQL;
    31     User: TWebUser;
    32     UserOnline: TWebOnlineUser;
    33     HtmlDocument: THtmlDocument;
    34     GlobalTitle: string;
    35     TimeStart: TDateTime;
    36     procedure LoadUserInfo;
    37     procedure InitDatabase;
    38     procedure GeneratePage(Page: TWebPage);
    39     constructor Create; override;
    40     destructor Destroy; override;
    41   end;
    4221
    4322  { TCore }
     
    8766uses
    8867  UModuleSystem, UModuleZdechovNET, UModuleUser, UPageAdmin, UModuleTV,
    89   UModuleFinance, UModuleNetwork;
     68  UModuleFinance, UModuleNetwork, UModulePortal, UModuleIS;
    9069
    9170resourcestring
    9271  SError = '<div>Error: %s</div>';
    93 
    94 { TWebSession }
    95 
    96 constructor TWebSession.Create;
    97 begin
    98   inherited;
    99   Database := TSqlDatabase.Create(nil);
    100   SessionStorage := THTTPSessionStorageMySQL.Create(nil);
    101   SessionStorage.Database := Database;
    102   HtmlDocument := THtmlDocument.Create;
    103   User := TWebUser.Create;
    104   User.Database := Database;
    105   UserOnline := TWebOnlineUser.Create;
    106   UserOnline.Database := Database;
    107 end;
    108 
    109 destructor TWebSession.Destroy;
    110 begin
    111   FreeAndNil(HtmlDocument);
    112   FreeAndNil(User);
    113   FreeAndNil(UserOnline);
    114   FreeAndNil(SessionStorage);
    115   FreeAndNil(Database);
    116   inherited;
    117 end;
    118 
    119 procedure TWebSession.InitDatabase;
    120 var
    121   DbRows: TDbRows;
    122 begin
    123   with Database do begin
    124     Connect;
    125   end;
    126   try
    127     DbRows := TDbRows.Create;
    128     Database.Query(DbRows, 'SET NAMES utf8');
    129   finally
    130     DbRows.Free;
    131   end;
    132 end;
    133 
    134 procedure TWebSession.LoadUserInfo;
    135 begin
    136   if Core.ModuleManager.ModuleRunning('User') then begin
    137     User.HandlerData := Self;
    138     UserOnline.HandlerData := Self;
    139     UserOnline.Update;
    140     User.Id := UserOnline.User;
    141     User.Load;
    142   end;
    143 end;
    144 
    145 procedure TWebSession.GeneratePage(Page: TWebPage);
    146 var
    147   I: Integer;
    148   TitleTag: THtmlString;
    149 begin
    150     HtmlDocument.ContentLanguage := 'cs';
    151     GlobalTitle := 'ZděchovNET';
    152     HtmlDocument.Styles.Add(NavigationLink('/Style/' + MainModule.Style + '/Style.css'));
    153     HtmlDocument.Scripts.Add(NavigationLink('/Style/' + MainModule.Style + '/Global.js'));
    154     HtmlDocument.Scripts.Add(NavigationLink('/Style/' + MainModule.Style + '/jquery.js'));
    155 
    156       TitleTag := THtmlString.Create;
    157       HtmlDocument.Body.SubItems.Insert(0, TitleTag);
    158       TopMenu;
    159       //Page.Page.OnProduce(HandlerData);
    160       HtmlDocument.Title := Page.Caption;
    161       TitleTag.Text := '<div class="TitlePanel"><span class="GlobalTitle">' + GlobalTitle +
    162         '</span> - ' + HtmlDocument.Title + '</div>';
    163       HtmlDocument.Title := GlobalTitle + ' - ' + HtmlDocument.Title;
    164       with HtmlDocument.AsXmlDocument do
    165       try
    166         Formated := MainModule.FormatHTML;
    167         Response.Content.WriteString(AsString);
    168       finally
    169         Free;
    170       end;
    171 end;
    17272
    17373
     
    282182    RegisterModule(TModuleFinance.Create(nil), True);
    283183    RegisterModule(TModuleNetwork.Create(nil), True);
     184    RegisterModule(TModulePortal.Create(nil), True);
     185    RegisterModule(TModuleIS.Create(nil), True);
    284186  end;
    285187end;
Note: See TracChangeset for help on using the changeset viewer.