1 | unit PagePortal;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, WebPage, HTTPServer, SqlDatabase, Utils,
|
---|
7 | Generics, WebSession, HtmlClasses, ModularSystem, ModuleUser, ModuleNews;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TWebPagePortal }
|
---|
12 |
|
---|
13 | TWebPagePortal = class(TWebPage)
|
---|
14 | procedure DataModuleProduce(HandlerData: THTTPHandlerData);
|
---|
15 | private
|
---|
16 | Session: TWebSession;
|
---|
17 | function ShowPanel(Title, Content: string; Menu: TStrings = nil): string;
|
---|
18 | function SystemMessage(Title, Text: string): string;
|
---|
19 | function ShowLinks(GroupId: Integer): string;
|
---|
20 | procedure Show(HandlerData: THTTPHandlerData);
|
---|
21 | function OnlineHostList: string;
|
---|
22 | function UserPanel: string;
|
---|
23 | function WebcamPanel: string;
|
---|
24 | public
|
---|
25 | ModuleUser: TModuleUser;
|
---|
26 | ModuleNews: TModuleNews;
|
---|
27 | end;
|
---|
28 |
|
---|
29 | var
|
---|
30 | WebPagePortal: TWebPagePortal;
|
---|
31 |
|
---|
32 |
|
---|
33 | implementation
|
---|
34 |
|
---|
35 | {$R *.lfm}
|
---|
36 |
|
---|
37 | uses
|
---|
38 | Core, WebObjects, User;
|
---|
39 |
|
---|
40 | function TWebPagePortal.SystemMessage(Title, Text: string): string;
|
---|
41 | begin
|
---|
42 | Result := '<table align="center"><tr><td><div class="SystemMessage"><h3>' +
|
---|
43 | Title + '</h3><div>' + Text + '</div></div</td></tr></table>';
|
---|
44 | end;
|
---|
45 |
|
---|
46 | procedure TWebPagePortal.DataModuleProduce(HandlerData: THTTPHandlerData);
|
---|
47 | begin
|
---|
48 | Session := TWebSession(HandlerData);
|
---|
49 | with TWebSession(HandlerData) do begin
|
---|
50 | Show(HandlerData);
|
---|
51 | GeneratePage(Self);
|
---|
52 | end;
|
---|
53 | end;
|
---|
54 |
|
---|
55 | function TWebPagePortal.ShowLinks(GroupId: Integer): string;
|
---|
56 | var
|
---|
57 | HyperlinkGroups: TDbRows;
|
---|
58 | Hyperlinks: TDbRows;
|
---|
59 | Hyperlink: TDictionaryStringString;
|
---|
60 | I: Integer;
|
---|
61 | begin
|
---|
62 | try
|
---|
63 | HyperlinkGroups := TDbRows.Create;
|
---|
64 | Hyperlinks := TDbRows.Create;
|
---|
65 | Session.Database.Query(HyperlinkGroups, 'SELECT * FROM `HyperlinkGroup` WHERE `Id`=' + IntToStr(GroupId));
|
---|
66 |
|
---|
67 | Result := '';
|
---|
68 | Session.Database.Query(Hyperlinks, 'SELECT * FROM `Hyperlink` WHERE (`Group`=' + IntToStr(GroupId) + ') AND (`Enable` = 1)');
|
---|
69 | for I := 0 to HyperLinks.Count - 1 do begin
|
---|
70 | HyperLink := Hyperlinks[I];
|
---|
71 | if HyperLink.Items['IconFile'] = '' then
|
---|
72 | HyperLink.Items['IconFile'] := 'clear.png';
|
---|
73 | if Copy(HyperLink.Items['URL'], 1, 4) <> 'http' then
|
---|
74 | HyperLink.Items['URL'] := NavigationLink(HyperLink.Items['URL']);
|
---|
75 | if ((HyperLink.Items['PermissionModule'] = '') or
|
---|
76 | ((HyperLink.Items['PermissionModule'] <> '') and
|
---|
77 | ModuleUser.User.CheckPermission(HyperLink.Items['PermissionModule'], HyperLink.Items['PermissionOperation']))) then
|
---|
78 | Result := Result + '<img alt="' + HyperLink.Items['Name'] + '" src="images/favicons/' + HyperLink.Items['IconFile'] + '" width="16" height="16" /> <a href="' + HyperLink.Items['URL'] + '">' + HyperLink.Items['Name'] + '</a><br />';
|
---|
79 | end;
|
---|
80 | Result := ShowPanel(HyperlinkGroups[0].Items['Name'], Result);
|
---|
81 |
|
---|
82 | finally
|
---|
83 | HyperlinkGroups.Free;
|
---|
84 | Hyperlinks.Free;
|
---|
85 | end;
|
---|
86 | end;
|
---|
87 |
|
---|
88 | procedure TWebPagePortal.Show(HandlerData: THTTPHandlerData);
|
---|
89 | var
|
---|
90 | Output: string;
|
---|
91 | Form: TQueryForm;
|
---|
92 | UserOptions: TQueryForm;
|
---|
93 | PanelColumn: TDictionaryStringString;
|
---|
94 | Panel: TDictionaryStringString;
|
---|
95 | Width: string;
|
---|
96 | DbRows: TDbRows;
|
---|
97 | DbRows2: TDbRows;
|
---|
98 | I, J: Integer;
|
---|
99 | Action: string;
|
---|
100 | begin
|
---|
101 | try
|
---|
102 | DbRows := TDbRows.Create;
|
---|
103 | DbRows2 := TDbRows.Create;
|
---|
104 | Output := '';
|
---|
105 | with Session.Request do
|
---|
106 | if Query.TryGetValue('Action', Action) then begin
|
---|
107 | if Action = 'CustomizeNewsSave' then begin
|
---|
108 | //Output := $this->System->Modules['News']->CustomizeSave();
|
---|
109 | end else
|
---|
110 | if Action = 'LoginForm' then begin
|
---|
111 | Form := TQueryForm.Create; // UserLogin
|
---|
112 | Form.AddNewAction('Přihlásit', '?Action=Login');
|
---|
113 | Output := Output + Form.AsXmlElement.AsString;
|
---|
114 | Output := Output + '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> ' +
|
---|
115 | '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
|
---|
116 | end else
|
---|
117 | if Action = 'Login' then begin
|
---|
118 | Form := TQueryForm.Create; // UserLogin
|
---|
119 | Form.Load(Session.Request.Post);
|
---|
120 | ModuleUser.UserOnline.Login(
|
---|
121 | ModuleUser.User.GetIdByNamePassword(
|
---|
122 | TQueryFormGroup(Form.Groups[0]).Rows.FindByName('Username').Value.Value,
|
---|
123 | TQueryFormGroup(Form.Groups[0]).Rows.FindByName('Password').Value.Value));
|
---|
124 | Output := Output + SystemMessage('Přihlášení', 'Přihlášení provedeno');
|
---|
125 | if ModuleUser.User.Id <> UnknownUser then begin
|
---|
126 | //Form.LoadValuesFromForm;
|
---|
127 | TQueryFormGroup(Form.Groups[0]).Rows.FindByName('Password').Value.Value := '';
|
---|
128 | Output := Output + Form.AsXmlElement.AsString;
|
---|
129 | Output := Output + '<div class="Centred"><a href="?Action=UserRegister">Registrovat se</a> ' +
|
---|
130 | '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
|
---|
131 | end;
|
---|
132 | end else
|
---|
133 | if Action = 'Logout' then begin
|
---|
134 | ModuleUser.UserOnline.Logout;
|
---|
135 | Output := Output + SystemMessage('Odhlášení', 'Uživatel odhlášen');
|
---|
136 | end else
|
---|
137 | if Action = 'UserOptions' then begin
|
---|
138 | UserOptions := TQueryForm.Create; // UserOptions
|
---|
139 | //UserOptions.LoadValuesFromDatabase(Session.User.Id);
|
---|
140 | UserOptions.AddNewAction('Uložit', '?Action=UserOptionsSave');
|
---|
141 | Output := Output + UserOptions.AsXmlElement.AsString;
|
---|
142 | end else
|
---|
143 | if Action = 'UserOptionsSave' then begin
|
---|
144 | UserOptions := TQueryForm.Create; // UserOptions
|
---|
145 | UserOptions.Load(Session.Request.Post);
|
---|
146 | //UserOptions.SaveValuesToDatabase($this->System->Modules['User']->User['Id']);
|
---|
147 | Output := Output + SystemMessage('Nastavení', 'Nastavení uloženo.');
|
---|
148 | //this->System->Modules['Log']->NewRecord('User', 'Nastavení uživatele změněno', $UserOptions->Values['Name']);
|
---|
149 | //UserOptions.LoadValuesFromDatabase($this->System->Modules['User']->User['Id']);
|
---|
150 | UserOptions.AddNewAction('Uložit', '?Action=UserOptionsSave');
|
---|
151 | Output := Output + UserOptions.AsXmlElement.AsString;
|
---|
152 | end else
|
---|
153 | if Action = 'UserRegister' then begin
|
---|
154 | Form := TQueryForm.Create; //'UserRegister');
|
---|
155 | Form.Load(Session.Request.Post);
|
---|
156 | Form.AddNewAction('Uložit', '?Action=UserRegisterSave');
|
---|
157 | Output := Output + Form.AsXmlElement.AsString;
|
---|
158 | end else
|
---|
159 | if Action = 'UserRegisterConfirm' then begin
|
---|
160 | //Session.User.RegisterConfirm($_GET['User'], $_GET['H']);
|
---|
161 | Output := Output + SystemMessage('Potvrzení registrace', 'Registrace potvrzena');
|
---|
162 | end else
|
---|
163 | if Action = 'PasswordRecovery' then begin
|
---|
164 | Form := TQueryForm.Create; // PasswordRecovery
|
---|
165 | Form.AddNewAction('Obnovit', '?Action=PasswordRecovery2');
|
---|
166 | Output := Output + Form.AsXmlElement.AsString;
|
---|
167 | end else
|
---|
168 | if Action = 'PasswordRecovery2' then begin
|
---|
169 | Form := TQueryForm.Create; // PasswordRecovery
|
---|
170 | Form.Load(Session.Request.Post);
|
---|
171 | //Result = Session.User.PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']);
|
---|
172 | Output := Output + SystemMessage('Obnova hesla', 'Heslo obnoveno');
|
---|
173 | //if Result <> USER_PASSWORD_RECOVERY_SUCCESS then begin
|
---|
174 | Output := Output + Form.AsXmlElement.AsString;
|
---|
175 | //end;
|
---|
176 | end else
|
---|
177 | if Action = 'PasswordRecoveryConfirm' then begin
|
---|
178 | //Session.User.PasswordRecoveryConfirm($_GET['User'], $_GET['H'], $_GET['P']);
|
---|
179 | Output := Output + SystemMessage('Obnova hesla', 'Potvrzení obnovení hesla');
|
---|
180 | end (*else
|
---|
181 | if Action = 'UserRegisterSave' then begin
|
---|
182 | Form := TQueryForm.Create; // UserRegister
|
---|
183 | Form.Load(Session.Request.Post);
|
---|
184 | Session.User.Register(Form->Values['Login'], $Form->Values['Password'], $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['Name'], $Form->Values['PhoneNumber'], $Form->Values['ICQ']);
|
---|
185 | $Output := Output + $this->SystemMessage('Registrace nového účtu', $Result);
|
---|
186 | if Result <> USER_REGISTRATED then begin
|
---|
187 | Form.OnSubmit := '?Action=UserRegisterSave';
|
---|
188 | $Output := Output + Form.ShowEditForm;
|
---|
189 | end;
|
---|
190 | end else
|
---|
191 | if Action = 'MemberOptions' then begin
|
---|
192 | $UserOptions = new Form('MemberOptions');
|
---|
193 | $DbResult = $this->Database->query('SELECT Member.Id, Member.InternetTariffNextMonth, Member.FamilyMemberCount, Member.BillingPeriodNext, Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, Subject.IC, Subject.DIC FROM Member JOIN Subject ON Subject.Id = Member.Subject WHERE Member.Id='.$this->System->Modules['User']->User['Member']);
|
---|
194 | $DbRow = $DbResult->fetch_array();
|
---|
195 | foreach($UserOptions->Definition['Items'] as $Index => $Item)
|
---|
196 | begin
|
---|
197 | $UserOptions->Values[$Index] = $DbRow[$Index];
|
---|
198 | end;
|
---|
199 | $UserOptions->OnSubmit = '?Action=MemberOptionsSave';
|
---|
200 | $Output .= $UserOptions->ShowEditForm();
|
---|
201 | end else
|
---|
202 | if Action = 'MemberOptionsSave' then begin
|
---|
203 | $UserOptions = new Form('MemberOptions');
|
---|
204 | $UserOptions->LoadValuesFromForm();
|
---|
205 | if($UserOptions->Values['FamilyMemberCount'] < 0)
|
---|
206 | $UserOptions->Values['FamilyMemberCount'] = 0;
|
---|
207 | if($UserOptions->Values['BillingPeriodNext'] < 2)
|
---|
208 | $UserOptions->Values['BillingPeriodNext'] = 2;
|
---|
209 |
|
---|
210 | $DbResult = $this->Database->update('Member', 'Id='.$this->System->Modules['User']->User['Member'], array('InternetTariffNextMonth' => $UserOptions->Values['InternetTariffNextMonth'], 'FamilyMemberCount' => $UserOptions->Values['FamilyMemberCount'], 'BillingPeriodNext' => $UserOptions->Values['BillingPeriodNext']));
|
---|
211 | $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$this->System->Modules['User']->User['Member']);
|
---|
212 | $Member = $DbResult->fetch_assoc();
|
---|
213 | $DbResult = $this->Database->update('Subject', 'Id='.$Member['Subject'], array('Name' => $UserOptions->Values['Name'], 'AddressStreet' => $UserOptions->Values['AddressStreet'], 'AddressTown' => $UserOptions->Values['AddressTown'], 'AddressPSC' => $UserOptions->Values['AddressPSC'], 'IC' => $UserOptions->Values['IC'], 'DIC' => $UserOptions->Values['DIC']));
|
---|
214 | $Output .= $this->SystemMessage('Nastavení', 'Nastavení domácnosti uloženo.');
|
---|
215 | $this->System->Modules['Log']->NewRecord('Member+Subject', 'Nastavení člena/subjektu změněno', $UserOptions->Values['Name']);
|
---|
216 | $DbResult = $this->Database->query('SELECT Member.Id, Member.InternetTariffNextMonth, Member.FamilyMemberCount, Member.BillingPeriodNext, Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, Subject.IC, Subject.DIC FROM Member JOIN Subject ON Subject.Id = Member.Subject WHERE Member.Id='.$this->System->Modules['User']->User['Member']);
|
---|
217 | $DbRow = $DbResult->fetch_array();
|
---|
218 | foreach($UserOptions->Definition['Items'] as $Index => $Item)
|
---|
219 | {
|
---|
220 | $UserOptions->Values[$Index] = $DbRow[$Index];
|
---|
221 | }
|
---|
222 | $UserOptions->OnSubmit = '?Action=MemberOptionsSave';
|
---|
223 | $Output .= $UserOptions->ShowEditForm();
|
---|
224 | end;
|
---|
225 | end *);
|
---|
226 | end;
|
---|
227 |
|
---|
228 | //Session.Database.Database := Config['Database']['Database'];
|
---|
229 |
|
---|
230 | // Show pannels
|
---|
231 | //if(IsInternetAddr()) echo('Internet'); else echo('LAN');
|
---|
232 | // $Output .= $this->InfoBar();
|
---|
233 | Output := Output + '<table id="MainTable"><tr>';
|
---|
234 | Session.Database.Select(DbRows, 'PanelColumn', '*');
|
---|
235 | for I := 0 to DbRows.Count - 1 do begin
|
---|
236 | PanelColumn := DbRows[I];
|
---|
237 | if PanelColumn.Items['Width'] <> '' then
|
---|
238 | Width := ' width="' + PanelColumn.Items['Width'] + '"'
|
---|
239 | else Width := '';
|
---|
240 | Output := Output + '<td valign="top"' + Width + '>';
|
---|
241 | Session.Database.Query(DbRows2, 'SELECT * FROM `Panel` WHERE `PanelColumn`=' +
|
---|
242 | PanelColumn.Items['Id'] + ' ORDER BY `Order`');
|
---|
243 | for J := 0 to DbRows2.Count - 1 do begin
|
---|
244 | Panel := DbRows2[J];
|
---|
245 | if Panel.Items['Module'] = 'HyperlinkGroup' then
|
---|
246 | Output := Output + ShowLinks(StrToInt(Panel.Items['Parameters']))
|
---|
247 | else if Panel.Items['Module'] = 'OnlineHostList' then
|
---|
248 | Output := Output + ShowPanel('Online počítače', OnlineHostList)
|
---|
249 | else if Panel.Items['Module'] = 'UserOptions' then
|
---|
250 | begin
|
---|
251 | if ModuleUser.User.Id <> UnknownUser then
|
---|
252 | Output := Output + ShowPanel('Přihlášený uživatel', UserPanel);
|
---|
253 | end else
|
---|
254 | if Panel.Items['Module'] = 'Webcam' then
|
---|
255 | Output := Output + ShowPanel('Kamery', WebcamPanel)
|
---|
256 | else if Panel.Items['Module'] = 'NewsGroupList' then
|
---|
257 | Output := Output + ShowPanel('Aktuality',
|
---|
258 | ModuleNews.Show(HandlerData)); //,
|
---|
259 | //['<a href="?Action=CustomizeNews">Upravit</a>']);
|
---|
260 | end;
|
---|
261 | Output := Output + '</td>';
|
---|
262 | end;
|
---|
263 | Output := Output + '</tr></table>';
|
---|
264 | with TWebSession(HandlerData) do begin
|
---|
265 | with HtmlDocument.Body, SubItems.AddString do
|
---|
266 | Text := Text + Output;
|
---|
267 | end;
|
---|
268 | finally
|
---|
269 | DbRows2.Free;
|
---|
270 | DbRows.Free;
|
---|
271 | end;
|
---|
272 | end;
|
---|
273 |
|
---|
274 | function TWebPagePortal.OnlineHostList: string;
|
---|
275 | begin
|
---|
276 | Result := '';
|
---|
277 | end;
|
---|
278 |
|
---|
279 | function TWebPagePortal.UserPanel: string;
|
---|
280 | begin
|
---|
281 | Result := '';
|
---|
282 | end;
|
---|
283 |
|
---|
284 | function TWebPagePortal.ShowPanel(Title, Content: string; Menu: TStrings): string;
|
---|
285 | var
|
---|
286 | I: Integer;
|
---|
287 | TitleCombined: string;
|
---|
288 | begin
|
---|
289 | TitleCombined := '';
|
---|
290 | if Assigned(Menu) then
|
---|
291 | if Menu.Count > 0 then
|
---|
292 | for I := 0 to Menu.Count - 1 do
|
---|
293 | TitleCombined := TitleCombined + '<div class="Action">' + Menu[I] + '</div>';
|
---|
294 | Result := '<div class="Panel"><div class="Title">' + TitleCombined +
|
---|
295 | '</div><div class="Content">' + Content + '</div></div>';
|
---|
296 | end;
|
---|
297 |
|
---|
298 | function TWebPagePortal.WebcamPanel: string;
|
---|
299 | begin
|
---|
300 | Result := '';
|
---|
301 | end;
|
---|
302 |
|
---|
303 | end.
|
---|
304 |
|
---|