📄 ucmddisp.pas
字号:
Result := DoEditSectionsAccess
else if Cmd = 'savesectionsaccess' then
Result := DoSaveSectionsAccess
else if Cmd = 'addsection' then
Result := DoAddSection
else if Cmd = 'editsection' then
Result := DoEditSection
else if Cmd = 'movesection' then
Result := DoMoveSection
else if Cmd = 'savesection' then
Result := DoSaveSection
else if Cmd = 'delsection' then
Result := DoDelSection
//--- Packages -----------------------------------------------------
else if Cmd = 'showpacks' then
Result := DoShowPackages
else if Cmd = 'showpacksaccess' then
Result := DoShowPackAccess
else if Cmd = 'editpacksaccess' then
Result := DoEditPackAccess
else if Cmd = 'savepacksaccess' then
Result := DoSavePackAccess
else if Cmd = 'addpack' then
Result := DoAddPack
else if Cmd = 'editpack' then
Result := DoEditPack
else if Cmd = 'savepack' then
Result := DoSavePack
else if Cmd = 'delpack' then
Result := DoDelPack
else if Cmd = 'packfiles' then
Result := DoPackFiles
else if Cmd = 'addfile' then
Result := DoAddFile
else if Cmd = 'editfile' then
Result := DoEditFile
else if Cmd = 'savefile' then
begin
if Srv.Request.Params['datafile']<>'' then
begin // save new/updates file
if not DirectoryExists(UploadPath) then
CreateDir(UploadPath);
fname := ExtractFileName(Srv.Request.Params['datafile']);
Srv.Request.Info['fname'] := fname;
if Srv.Request.Params.GetFile('datafile', UploadPath+'\' + fname) then begin
size := File_Size(UploadPath+'\' + fname);
if size = 0 then begin
PageMessage := GetMsg('error_file_size');
//Result := DoPackFiles;
Relocation(Format('?cmd=packfiles&pack_id=%s&sid=%s', [GetRequestValue('pack_id'), SessionID]));
Exit;
end;
Srv.Request.Info['size'] := IntToStr(size);
Result := DoSaveFile;
end;
end
else // save selected file
begin
Srv.Request.Info['fname'] := GetRequestValue('filename');
Result := DoSaveFile;
end;
end
else if Cmd = 'delfile' then
Result := DoDelFile
//------------------------------------------------------------------
else
Result := DoCommonAccess(Cmd);
end;
function TCommandsDispatcher.DoAdmin : string;
var
Page : TRtcParse;
begin
Page := TRtcParse.Create(TemplatePath + 'admin.htm');
try
ShowPageMessage(Page);
Page['header_area'] := HeaderArea;
Page['sid'] := SessionID;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.DoForum : string;
var
Page : TRtcParseEx;
TableRow : TRtcParseEx;
S : string;
I : integer;
Section : PSectionRecord;
login: string;
SectionsList : TList;
PreviousLogon : TDateTime;
begin
Page := TRtcParseEx.Create(TemplatePath + 'index.htm');
try
ShowPageMessage(Page);
Page['header_area'] := HeaderArea(GetMsg('title_index'));
Page['sid'] := SessionID;
Page['packs_section_name'] := GetMsg('Download Area');
Page['forum_page_header'] := GetMsg('Forum');
login := GetSessionLogin;
if assigned(Session) then
PreviousLogon := Session.asDateTime['previous logon']
else
PreviousLogon := Now-1; // will mark all topics posted in the last 24 hours
S := '';
// Show Sections
TableRow := TRtcParseEx.Create(TemplatePath + 'forum_area_row.htm');
ForumData.Lock;
try
ForumData.LoadSections;
ForumData.LoadRights;
SectionsList := ForumData.Sections.GetOrderedList;
try
for I := 0 to SectionsList.Count - 1 do begin
Section := SectionsList[I];
if not IsSectionVisible(Section^.VisibilityLevel,
ForumData.Rights.GetUserAccessLevel(LowerCase(login), Section^.ID)) then
Continue;
TableRow.Clear;
TableRow['section_id'] := IntToStr(Section^.ID);
TableRow['section_name'] := Section^.Name;
TableRow['posts_count'] := IntToStr(Section^.PostCount);
TableRow['topics_count'] := IntToStr(Section^.TopicsCount);
TableRow.Condition['topics_exists'] := (Section^.PostCount > 0);
TableRow.Condition['new_posts'] := assigned(Session) and (PreviousLogon < Section^.LastPostTimeStamp);
if Section^.PostCount > 0 then begin
TableRow.Condition['last_topic_exist'] := not ((Section^.LastPostTopicID = 0) and
SameText('deleted', Section^.LastPostTopicName));
TableRow['last_post_timestamp'] := DateTimeToStr(Section^.LastPostTimeStamp);
TableRow['last_post_topic_subject'] := Section^.LastPostTopicName;
TableRow['last_post_topic_id'] := IntToStr(Section^.LastPostTopicID);
end;
TableRow['sid'] := SessionID;
S := S + TableRow.Output;
end;
finally
SectionsList.Free;
end;
finally
ForumData.Unlock;
TableRow.Free;
end;
Page['forum_table_rows'] := S;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.GetRequestValue (name : string) : string;
begin
if Srv.Request.Method='GET' then
Result := URL_Decode(Srv.Request.Query[name])
else
Result := Srv.Request.Params[name];
end;
constructor TCommandsDispatcher.Create(aSrv: TRtcDataServer);
begin
fSrv := aSrv;
end;
function TCommandsDispatcher.GetSession: TRtcServerSession;
begin
Result := Srv.Session;
end;
function TCommandsDispatcher.GetTemplatePath: string;
begin
Result := Forum_Templates_Path;
end;
procedure TCommandsDispatcher.ShowPageMessage(Page: TRtcParse);
begin
if Trim(PageMessage) <> '' then
begin
Page['message_text'] := PageMessage;
Page['message_visible'] := '1';
end
else
begin
Page['message_text'] := '';
Page['message_visible'] := '';
end;
PageMessage := '';
end;
procedure TCommandsDispatcher.ShowPageMessage(Page: TRtcParseEx);
begin
if Trim(PageMessage) <> '' then
begin
Page['message_text'] := PageMessage;
Page['message_visible'] := '1';
end
else
begin
Page['message_text'] := '';
Page['message_visible'] := '';
end;
PageMessage := '';
end;
procedure TCommandsDispatcher.Relocation(URL: string);
begin
Srv.Response.Status(302,'Moved');
Srv.Response['Location'] := URL;
Srv.Write('Status 302: Moved');
end;
function TCommandsDispatcher.HeaderArea(DocumentTitle : string = '') : string;
var
Page : TRtcParseEx;
fname : string;
login : string;
username : string;
filter : string;
sid : string;
begin
if Assigned(Session) and Session.asBoolean['login'] then
begin
login := Session.asString['user_name'];
filter := Session.asString['forum_filter'];
fname := TemplatePath + 'logged.htm';
GetUserInfo(login, username);
sid := SessionID;
end
else
begin
login := LOGIN_GUEST;
filter := '';
fname := TemplatePath + 'notlogged.htm';
username := 'Guest';
end;
Page := TRtcParseEx.Create(fname);
try
Page.Silent := True;
Page['user_name'] := username;
Page['now_datetime'] := DateTimeToStr(Now);
Page['logged_ip_address'] := Srv.PeerAddr;
Page['sid'] := sid;
Page['title_of_document'] := DocumentTitle;
Page['filter_text'] := filter;
if Assigned(Session) and not SameText(login, LOGIN_ADMIN) then
Page.Condition['show_forum_filter'] := true;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.FindSession: boolean;
begin
Result :=
Srv.FindSession(GetRequestValue('sid'))
{$IFDEF USE_COOKIE_SESSIONID}
or Srv.FindSession(Srv.Request.Cookie['session'])
{$ENDIF}
;
end;
function TCommandsDispatcher.DoAddFile: string;
var
Page : TRtcParseEx;
pack_id : string;
packname, order_link, extend_lic_link : string;
S : string;
Files, PackFiles, SL : TStringList;
I : integer;
file_id : string;
begin
Result := '';
Page := TRtcParseEx.Create(TemplatePath + 'editfile.htm');
try
ShowPageMessage(Page);
Page['header_area'] := HeaderArea;
pack_id := GetRequestValue('pack_id');
if not GetPackInfo(pack_id, packname, order_link, extend_lic_link) then
Exit;
Page['pack_id'] := pack_id;
Page['package_name'] := packname;
Page['new_checked'] := CHECKED;
Page.Condition['select'] := False;
Page['none_selected'] := SELECTED;
S := '';
Files := TStringList.Create;
PackFiles := TStringList.Create;
SL := TStringList.Create;
try
GetFilesAll(Files);
GetFilesTiny(pack_id, PackFiles);
for I := 0 to Files.Count - 1 do begin
file_id := Files.Names[I];
if PackFiles.IndexOfName(file_id) < 0 then begin
SL.CommaText := _GetValueFromIndex(Files,I);
S := S + Format(
'<option value="%s">%s (%s)</option>'#13#10, [
file_id, SL.Values['desc'], SL.Values['fname']
]);
end;
end;
finally
SL.Free;
PackFiles.Free;
Files.Free;
end;
Page['options_files'] := S;
Page['sid'] := SessionID;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.DoAddPack: string;
var
Page : TRtcParse;
begin
Page := TRtcParse.Create(TemplatePath + 'editpack.htm');
try
ShowPageMessage(Page);
Page['header_area'] := HeaderArea;
Page['caption'] := 'Add package';
if DEFAULT_PACK_VISIBILITY_LEVEL = 'public' then
Page['public_selected'] := SELECTED
else
Page['private_selected'] := SELECTED;
Page['sid'] := SessionID;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.DoDelFile: string;
var
pack_id, file_id : string;
fname, description, filedatetime, size : string;
begin
pack_id := GetRequestValue('pack_id');
file_id := GetRequestValue('file_id');
if GetFileInfo(pack_id, file_id, fname, description, filedatetime, size) then begin
if DelFile(pack_id, file_id) then
Delete_File(fname);
end;
//Result := DoPackFiles;
Relocation(Format('?cmd=packfiles&pack_id=%s&sid=%s', [pack_id, SessionID]));
end;
function TCommandsDispatcher.DoDelPack: string;
begin
if not DeletePack(GetRequestValue('pack_id')) then
PageMessage := GetMsg('error_del_pack');
//Result := DoShowPackages;
Relocation(Format('?cmd=showpacks&sid=%s', [SessionID]));
end;
function TCommandsDispatcher.DoEditFile: string;
var
Page : TRtcParseEx;
pack_id : string;
packname, order_link, extend_lic_link : string;
fname, description, filedatetime, size : string;
S : string;
Files, PackFiles, SL : TStringList;
I : integer;
file_id, f_id : string;
sel : string;
begin
Result := '';
Page := TRtcParseEx.Create(TemplatePath + 'editfile.htm');
try
ShowPageMessage(Page);
Page['header_area'] := HeaderArea;
pack_id := GetRequestValue('pack_id');
if not GetPackInfo(pack_id, packname, order_link, extend_lic_link) then
Exit;
file_id := GetRequestValue('file_id');
if not GetFileInfo(pack_id, file_id, fname, description, filedatetime, size) then
Exit;
Page['pack_id'] := pack_id;
Page['file_id'] := file_id;
Page['package_name'] := packname;
Page['select_checked'] := CHECKED;
Page.Condition['select'] := True;
S := '';
Files := TStringList.Create;
PackFiles := TStringList.Create;
SL := TStringList.Create;
try
GetFilesAll(Files);
GetFilesTiny(pack_id, PackFiles);
for I := 0 to Files.Count - 1 do begin
f_id := Files.Names[I];
if (f_id = file_id) or (PackFiles.IndexOfName(f_id) < 0) then begin
SL.CommaText := _GetValueFromIndex(Files,I);
if f_id = file_id then
begin
sel := SELECTED;
Page['name'] := SL.Values['desc'];
end
else
sel := '';
S := S + Format(
'<option %s value="%s">%s (%s)</option>'#13#10, [
sel, f_id, SL.Values['desc'], SL.Values['fname']
]);
end;
end;
finally
SL.Free;
PackFiles.Free;
Files.Free;
end;
Page['options_files'] := S;
Page['sid'] := SessionID;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.DoEditPack: string;
var
Page : TRtcParse;
pack_id, packname, order_link, extend_lic_link : string;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -