📄 ucmddisp.pas
字号:
if SameText(login, LOGIN_ADMIN) or SameText(login, LOGIN_GUEST) then
PageMessage := Format(GetMsg('error_del_user'), [login])
else if not DeleteUser(login) then
PageMessage := Format(GetMsg('error_del_user'), [login]);
//Result := DoShowUsers;
Relocation(Format('?cmd=showusers&sid=%s', [SessionID]));
end;
function TCommandsDispatcher.DoEditSectionsAccess : string;
begin
end;
function TCommandsDispatcher.DoShowSectionsAccess : string;
var
Page : TRtcParse;
TableRow : TRtcParse;
S : string;
I : integer;
login: string;
SectionsList:TList;
Section:PSectionRecord;
UserAccessRights : TUserAccessLevel;
Filter : TFilterUserAccessRights;
function InFilter(F: TFilterUserAccessRights; U: TUserAccessLevel): boolean;
begin
Result :=
( F = frAll ) or
( (F = frNone) and (U = uaNone) ) or
( (F = frRead) and (U = uaRead) ) or
( (F = frWrite) and (U = uaWrite) ) or
( (F = frModerate) and (U = uaModerate) ) or
( (F = frPower) and (U in [uaRead..uaModerate]) );
end;
begin
Page := TRtcParse.Create(TemplatePath + 'useraccess.htm');
try
ShowPageMessage(Page);
Page['header_area'] := HeaderArea;
login := GetRequestValue('user');
Page['user'] := login;
Page['user_login_enc'] := URL_Encode(login);
// get filter
Filter := TFilterUserAccessRights(StrToIntDef(GetRequestValue('filter'), 5));
case Filter of
frNone :
Page['none_selected'] := SELECTED;
frRead :
Page['read_selected'] := SELECTED;
frWrite :
Page['write_selected'] := SELECTED;
frModerate :
Page['moderate_selected'] := SELECTED;
frPower :
Page['power_selected'] := SELECTED;
else
Page['all_selected'] := SELECTED;
end;
// list of sections
S := '';
TableRow := TRtcParse.Create(TemplatePath + 'access_table_row.htm');
ForumData.Lock;
try
ForumData.LoadSections;
ForumData.LoadRights;
SectionsList := ForumData.Sections.GetOrderedList;
try
for I := 0 to SectionsList.Count - 1 do
begin
Section := PSectionRecord(SectionsList[I]);
if Section^.Deleted then
Continue;
UserAccessRights :=
ForumData.Rights.GetUserAccessLevel(LowerCase(login), Section^.ID);
if not InFilter(Filter, UserAccessRights) then
Continue;
TableRow.Clear;
TableRow['section_id'] := IntToStr(Section^.ID);
TableRow['section_name'] := Section^.Name;
TableRow['vis_level'] := VisibilityToStr(Section^.VisibilityLevel);
TableRow['access_level'] := AccessToStr(Section^.AccessLevel);
// show Write for all users for public sections
//if (Section^.VisibilityLevel = vlPublic) and (UserAccessRights <> uaModerate) then
// UserAccessRights := uaWrite;
case UserAccessRights of
uaNone :
TableRow['none_selected'] := SELECTED;
uaRead :
TableRow['read_selected'] := SELECTED;
uaWrite :
TableRow['write_selected'] := SELECTED;
uaModerate :
TableRow['moderate_selected'] := SELECTED;
end;
TableRow['user'] := login;
TableRow['sid'] := SessionID;
S := S + TableRow.Output;
end;
finally
SectionsList.Free;
end;
finally
ForumData.Unlock;
TableRow.Free;
end;
Page['table_rows'] := S;
Page['sid'] := SessionID;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.DoSaveSectionsAccess : string;
var
login, section_id : string;
begin
login := GetRequestValue('user');
section_id := GetRequestValue('section_id');
ForumData.Lock;
try
ForumData.LoadRights;
ForumData.Rights.SetUserAccessLevel(
LowerCase(login),
StrToIntDef(section_id, 0),
TUserAccessLevel(StrToIntDef(GetRequestValue('rights'), 0))
);
finally
ForumData.Unlock;
end;
//Result := DoShowSectionsAccess;
Relocation(Format('?cmd=showsectionsaccess&user=%s&sid=%s', [login, SessionID]));
end;
function TCommandsDispatcher.DoShowSections : string;
var
Page : TRtcParse;
TableRow : TRtcParse;
S : string;
I : integer;
SectionsList : TList;
begin
Page := TRtcParse.Create(TemplatePath + 'sections.htm');
try
ShowPageMessage(Page);
Page['header_area'] := HeaderArea;
S := '';
TableRow := TRtcParse.Create(TemplatePath + 'sections_table_row.htm');
ForumData.Lock;
try
ForumData.LoadSections;
SectionsList := ForumData.Sections.GetOrderedList;
try
for I := 0 to SectionsList.Count - 1 do
with PSectionRecord (SectionsList[I])^ do
if not Deleted then begin
TableRow.Clear;
TableRow['section_name'] := Name;
TableRow['section_id'] := IntToStr(ID);
TableRow['vis_level'] := VisibilityToStr(VisibilityLevel);
TableRow['access_level'] := AccessToStr(AccessLevel);
TableRow['topics_count'] := IntToStr(TopicsCount);
TableRow['posts_count'] := IntToStr(PostCount);
if I > 0 then
TableRow['place_above'] := IntToStr(PSectionRecord(SectionsList[I-1])^.ID);
if I < SectionsList.Count - 1 then
TableRow['place_below'] := IntToStr(PSectionRecord(SectionsList[I+1])^.ID);
TableRow['sid'] := SessionID;
S := S + TableRow.Output;
end;
finally
SectionsList.Free;
end;
finally
ForumData.Unlock;
TableRow.Free;
end;
Page['table_rows'] := S;
Page['sid'] := SessionID;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.DoAddSection : string;
var
Page : TRtcParse;
begin
Page := TRtcParse.Create(TemplatePath + 'editsection.htm');
try
Page['header_area'] := HeaderArea;
Page['caption'] := 'Add Section';
Page['sid'] := SessionID;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.DoEditSection : string;
var
Page : TRtcParse;
section_id : string;
Section : PSectionRecord;
begin
Page := TRtcParse.Create(TemplatePath + 'editsection.htm');
ForumData.Lock;
try
ForumData.LoadSections;
Page['header_area'] := HeaderArea;
Page['caption'] := 'Edit Section';
Page['sid'] := SessionID;
section_id := GetRequestValue('section_id');
Page['section_id'] := section_id;
Section := ForumData.Sections.ItemsByID[StrToIntDef(section_id, 0)];
if not Assigned(Section) then
Exit;
Page['section_name'] := Section^.Name;
Page['sort_order'] := IntToStr(Section^.SortOrder);
case Section^.VisibilityLevel of
vlPublic : Page['public_selected'] := SELECTED;
vlPrivate : Page['private_selected'] := SELECTED;
end;
case Section^.AccessLevel of
alOpen : Page['open_selected'] := SELECTED;
alClosed : Page['closed_selected'] := SELECTED;
end;
Result := Page.Output;
finally
ForumData.Unlock;
Page.Free;
end;
end;
function TCommandsDispatcher.DoSaveSection: string;
var
section_id : string;
i_section_id : integer;
sectionname, vis_level, acc_level : string;
Section : PSectionRecord;
begin
section_id := GetRequestValue('section_id');
sectionname := GetRequestValue('section_name');
vis_level := GetRequestValue('vis_level');
acc_level := GetRequestValue('acc_level');
i_section_id := StrToIntDef(section_id, 0);
ForumData.Lock;
try
ForumData.LoadSections;
if section_id = '' then
Section := ForumData.Sections.New
else
begin
Section := ForumData.Sections.ItemsByID[i_section_id];
if not Assigned(Section) then
Section := ForumData.Sections.New;
end;
with Section^ do begin
Name := sectionname;
VisibilityLevel := StrToVisibility(vis_level);
AccessLevel := StrToAccess(acc_level);
SortOrder := StrToIntDef(GetRequestValue('order'), ID)
end;
finally
ForumData.Unlock;
end;
//Result := DoShowSections;
Relocation(Format('?cmd=showsections&sid=%s', [SessionID]));
end;
function TCommandsDispatcher.DoDelSection : string;
var
section_id : integer;
begin
section_id := StrToIntDef(GetRequestValue('section_id'), 0);
ForumData.Lock;
try
ForumData.LoadSections;
if ForumData.Sections.DeleteByID(section_id) then
ForumData.DeleteSection(section_id)
else
PageMessage := GetMsg('error_del_section');
finally
ForumData.Unlock;
end;
//Result := DoShowSections;
Relocation(Format('?cmd=showsections&sid=%s', [SessionID]));
end;
function TCommandsDispatcher.DoIndexPage(msg: string): string;
var
Access_Level : integer;
begin
if assigned(Session) and Session.asBoolean['login'] then
Access_Level:=Session.asInteger['access_level']
else
Access_Level:=ACCESS_LEVEL_USER;
case Access_Level of
ACCESS_LEVEL_ADMIN :
Result := DoAdmin;
ACCESS_LEVEL_USER :
Result := DoForum;
else
begin
DoLogin(True);
Result := DoForum;
end;
end;
end;
function TCommandsDispatcher.DoLogOut: string;
begin
DoLogin(True);
//Result := DoIndexPage;
Relocation('?cmd=home');
end;
function TCommandsDispatcher.DoSavePwd : string;
begin
if assigned(Session) then
ChangePassword(Srv.Session.asString['user_name'], GetRequestValue('old_pwd'), GetRequestValue('pwd'));
//Result := DoLogOut;
Relocation(Format('?cmd=logout&sid=%s', [SessionID]));
end;
function TCommandsDispatcher.DoChangePwd : string;
var
Page : TRtcParse;
begin
Page := TRtcParse.Create(TemplatePath + 'user_changepwd.htm');
try
Page['header_area'] := HeaderArea;
Page['sid'] := SessionID;
Result := Page.Output;
finally
Page.Free;
end;
end;
function TCommandsDispatcher.DoCommonAccess(Cmd: string): string;
begin
if Cmd = 'logout' then
begin
if assigned(Session) then
begin
Srv.Session.Close;
Srv.UnLockSession;
Result := DoLogOut;
end
else
Result := DoIndexPage;
end
else if Cmd = 'changepwd' then
begin
if assigned(Session) and Srv.Session.asBoolean['login'] then
Result := DoChangePwd
else
Result := DoIndexPage;
end
else if Cmd = 'savepwd' then
begin
if assigned(Session) and Srv.Session.asBoolean['login'] then
Result := DoSavePwd
else
Result := DoIndexPage;
end
else if Cmd = 'packages' then
begin
Result := DoPackagesSectionView;
end
else if Cmd = 'redir' then //
begin // for DEBUG purpouse only !
Result := DoRedir; // for DEBUG purpouse only !
end //
else if Cmd = 'home' then
begin
Result := DoIndexPage;
end
else if Cmd = 'forum' then
begin
Result := DoForum;
end
else if Cmd = 'viewsection' then
begin
Result := DoSectionView;
end
else if Cmd = 'newtopic' then
begin
Result := DoNewTopic;
end
else if Cmd = 'savetopic' then
begin
Result := DoSaveTopic;
end
else if Cmd = 'viewtopic' then
begin
Result := DoTopicView;
end
else if Cmd = 'delreply' then
begin
Result := DoDeleteReply;
end
else if Cmd = 'deltopic' then
begin
Result := DoDeleteTopic;
end
else if Cmd = 'setfilter' then
begin
Result := DoSetFilter;
end
else
Result := DoIndexPage;
end;
function TCommandsDispatcher.DoAdminAccess(Cmd: string): string;
var
fname : string;
size : integer;
begin
if Cmd = 'showusers' then
Result := DoShowUsers
else if Cmd = 'showsections' then
Result := DoShowSections
else if Cmd = 'edituser' then
Result := DoEditUser
else if Cmd = 'saveuser' then
Result := DoSaveUser
else if Cmd = 'deluser' then
Result := DoDelUser
else if Cmd = 'showsectionsaccess' then
Result := DoShowSectionsAccess
else if Cmd = 'editsectionsaccess' then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -