PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Private/Modules/ControlPanel/Output/ModifyLevel.pm.pl

http://superlinks.googlecode.com/
Perl | 344 lines | 303 code | 14 blank | 27 comment | 1 complexity | 683950dc31aafba02793cbe91217b149 MD5 | raw file
Possible License(s): GPL-2.0
  1. ###############################################################################
  2. # SuperLinks #
  3. # Copyright (c) 2000-2007 Greg Nolle (http://greg.nolle.co.uk) #
  4. ###############################################################################
  5. # This program is free software; you can redistribute it and/or modify it #
  6. # under the terms of the GNU General Public License as published by the Free #
  7. # Software Foundation; either version 2 of the License, or (at your option) #
  8. # any later version. #
  9. # #
  10. # This program is distributed in the hope that it will be useful, but WITHOUT #
  11. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
  12. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
  13. # more details. # # #
  14. # You should have received a copy of the GNU General Public License along #
  15. # with this program; if not, write to the Free Software Foundation, Inc., #
  16. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #
  17. ###############################################################################
  18. # ControlPanel/Output/ModifyLevel.pm.pl -> ModifyLevel module #
  19. ###############################################################################
  20. # DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING! #
  21. ###############################################################################
  22. package Skin::CP::ModifyLevel;
  23. BEGIN { require "System.pm.pl"; import System qw($SYSTEM); }
  24. BEGIN { require "General.pm.pl"; import General qw($GENERAL); }
  25. require "Standard.pm.pl";
  26. use HTML::Dialog;
  27. use HTML::Form;
  28. use strict;
  29. sub new {
  30. my ($class) = @_;
  31. my $self = {};
  32. return bless ($self, $class);
  33. }
  34. sub DESTROY { }
  35. ###############################################################################
  36. # show subroutine
  37. sub show {
  38. my $self = shift;
  39. my %in = (input => undef, error => "", @_);
  40. my $LANGUAGE = {
  41. "MISSING" => {
  42. "TITLE" => qq~<li>You didn't fill in the "Title" field.~
  43. },
  44. "TOOLONG" => {
  45. "TITLE" => qq~<li>The value for the "Title" field must be 256 characters or less.~
  46. },
  47. "ERROR" => qq~<p><font class="error">There were errors:<ul>[%error%]</ul></font>~
  48. };
  49. $in{'error'} = &Standard::ProcessError(LANGUAGE => $LANGUAGE, ERROR => $in{'error'});
  50. #----------------------------------------------------------------------#
  51. # Printing page... #
  52. my $Dialog = HTML::Dialog->new();
  53. my $Form = HTML::Form->new();
  54. my $Body = $Dialog->TableRow(items => [{ body => "Please fill out all the required (<font class=\"form-required\"><b>*</b></font>) fields:".$in{'error'}, colspan => "2" }]);
  55. $Body .= $Dialog->FormTextBox(
  56. value => $in{'input'}->{'LEVEL'}->{'ID'},
  57. subject => "ID"
  58. );
  59. $Body .= $Dialog->FormTextBox(
  60. name => "FORM_TITLE",
  61. value => $in{'input'}->{'LEVEL'}->{'TITLE'},
  62. subject => "Title",
  63. required => 1
  64. );
  65. $Body .= $Dialog->FormCheckBox(
  66. name => "FORM_SUPERUSER",
  67. value => $in{'input'}->{'LEVEL'}->{'permissions'}->{'SUPERUSER'},
  68. items => [{ value => "1", label => "Superuser (can do everything)?" }]
  69. );
  70. my @General = (
  71. { name => "SYSTEMOPTIONS", label => "View/Modify system options?" },
  72. { name => "GENERALOPTIONS", label => "View/Modify general options?" },
  73. { name => "EXTRAFIELDS_VIEW", label => "View extra resource fields?" },
  74. { name => "EXTRAFIELDS_CREATE", label => "Create extra resource fields?" },
  75. { name => "EXTRAFIELDS_MODIFY", label => "Modify extra resource fields?" },
  76. { name => "EXTRAFIELDS_REMOVE", label => "Remove extra resource fields?" },
  77. { name => "CATEGORIES_VIEW", label => "View categories?" },
  78. { name => "CATEGORIES_CREATE", label => "Create categories?" },
  79. { name => "CATEGORIES_MODIFY", label => "Modify categories?" },
  80. { name => "CATEGORIES_REMOVE", label => "Remove categories?" },
  81. { name => "RESOURCES_VIEW", label => "View resources?" },
  82. { name => "RESOURCES_APPROVE", label => "Approve resources?" },
  83. { name => "RESOURCES_CREATE", label => "Create resources?" },
  84. { name => "RESOURCES_MODIFY", label => "Modify resources?" },
  85. { name => "RESOURCES_REMOVE", label => "Remove resources?" },
  86. { name => "REVIEWS_VIEW", label => "View reviews?" },
  87. { name => "REVIEWS_MODIFY", label => "Modify reviews?" },
  88. { name => "REVIEWS_REMOVE", label => "Remove reviews?" },
  89. { name => "ADMINS_VIEW", label => "View admins?" },
  90. { name => "ADMINS_CREATE", label => "Create admins?" },
  91. { name => "ADMINS_MODIFY", label => "Modify admins?" },
  92. { name => "ADMINS_REMOVE", label => "Remove admins?" },
  93. { name => "LEVELS_VIEW", label => "View levels?" },
  94. { name => "LEVELS_CREATE", label => "Create levels?" },
  95. { name => "LEVELS_MODIFY", label => "Modify levels?" },
  96. { name => "LEVELS_REMOVE", label => "Remove levels?" },
  97. { name => "SKINS_VIEW", label => "View skins?" },
  98. { name => "SKINS_CREATE", label => "Create skins?" },
  99. { name => "SKINS_MODIFY", label => "Modify skins?" },
  100. { name => "SKINS_REMOVE", label => "Remove skins?" },
  101. { name => "STYLESHEETS_VIEW", label => "View stylesheets?" },
  102. { name => "STYLESHEETS_CREATE", label => "Create stylesheets?" },
  103. { name => "STYLESHEETS_MODIFY", label => "Modify stylesheets?" },
  104. { name => "STYLESHEETS_REMOVE", label => "Remove stylesheets?" },
  105. { name => "LANGUAGESETS_VIEW", label => "View language sets?" },
  106. { name => "LANGUAGESETS_CREATE", label => "Create language sets?" },
  107. { name => "LANGUAGESETS_MODIFY", label => "Modify language sets?" },
  108. { name => "LANGUAGESETS_REMOVE", label => "Remove language sets?" },
  109. { name => "TEMPLATESETS_VIEW", label => "View template sets?" },
  110. { name => "TEMPLATESETS_CREATE", label => "Create template sets?" },
  111. { name => "TEMPLATESETS_MODIFY", label => "Modify template sets?" },
  112. { name => "TEMPLATESETS_REMOVE", label => "Remove template sets?" },
  113. { name => "BACKUPS_VIEW", label => "View backups?" },
  114. { name => "BACKUPS_CREATE", label => "Create backups?" },
  115. { name => "BACKUPS_REMOVE", label => "Remove backups?" },
  116. { name => "BACKUPS_RESTORE", label => "Restore backups?" },
  117. { name => "CONVERTDATABASE", label => "Convert database?" },
  118. { name => "IMPORTEXPORT", label => "Import/Export?" },
  119. { name => "EMAIL", label => "Email list members?" },
  120. { name => "EXPIRE", label => "Expire all static pages?" },
  121. { name => "INSTALLPACKAGE", label => "Install package?" },
  122. { name => "UPDATE", label => "Update superlinks?" }
  123. );
  124. my @Category = (
  125. { name => "RESOURCES_VIEW", label => "View resources?" },
  126. { name => "RESOURCES_APPROVE", label => "Approve resources?" },
  127. { name => "RESOURCES_CREATE", label => "Create resources?" },
  128. { name => "RESOURCES_MODIFY", label => "Modify resources?" },
  129. { name => "RESOURCES_REMOVE", label => "Remove resources?" },
  130. { name => "REVIEWS_VIEW", label => "View reviews?" },
  131. { name => "REVIEWS_MODIFY", label => "Modify reviews?" },
  132. { name => "REVIEWS_REMOVE", label => "Remove reviews?" },
  133. );
  134. unless ($SL::QUERY{'NotFirst'}) {
  135. foreach my $key (keys %{ $in{'input'}->{'LEVEL'}->{'permissions'} }) {
  136. if ($key eq "CATEGORIES") {
  137. foreach my $category (keys %{ $in{'input'}->{'LEVEL'}->{'permissions'}->{'CATEGORIES'} }) {
  138. $SL::QUERY{'FORM_CATEGORY_'.$category} = "1";
  139. foreach my $perm (keys %{ $in{'input'}->{'LEVEL'}->{'permissions'}->{'CATEGORIES'}->{$category} }) {
  140. $SL::QUERY{'FORM_CATEGORY_'.$category.'_'.$perm} = $in{'input'}->{'LEVEL'}->{'permissions'}->{'CATEGORIES'}->{$category}->{$perm};
  141. }
  142. }
  143. } else {
  144. $SL::QUERY{'FORM_'.$key} = $in{'input'}->{'LEVEL'}->{'permissions'}->{$key};
  145. }
  146. }
  147. }
  148. my %Hiddens = %SL::QUERY;
  149. delete($Hiddens{'CP'});
  150. delete($Hiddens{'action'});
  151. delete($Hiddens{'SID'});
  152. delete($Hiddens{'Referer'});
  153. delete($Hiddens{'FORM_TITLE'});
  154. delete($Hiddens{'FORM_SUPERUSER'});
  155. delete($Hiddens{'SECTION'});
  156. delete($Hiddens{'ADD_CATEGORY'});
  157. my @options;
  158. push(@options, { value => "GENERAL", label => "General Permissions" });
  159. push(@options, { value => ".", label => "" });
  160. push(@options, { value => "..", label => "Categories" });
  161. push(@options, { value => "...", label => "---------------------------" });
  162. if ($SL::QUERY{'ADD_CATEGORY'} ne "") {
  163. $SL::QUERY{'FORM_CATEGORY_'.$SL::QUERY{'ADD_CATEGORY'}} = 1;
  164. $Hiddens{'FORM_CATEGORY_'.$SL::QUERY{'ADD_CATEGORY'}} = 1;
  165. }
  166. $Hiddens{'DEL_CATEGORY'} = "";
  167. if ($SL::QUERY{'DEL_CATEGORY'} ne "") {
  168. foreach my $key (grep(/^FORM_CATEGORY_$SL::QUERY{'DEL_CATEGORY'}(.*)$/, keys %SL::QUERY)) {
  169. delete($Hiddens{$key});
  170. delete($SL::QUERY{$key});
  171. $SL::QUERY{'SECTION'} = "";
  172. }
  173. }
  174. foreach my $key (keys %SL::QUERY) {
  175. next unless ($key !~ /^FORM_CATEGORY_(.*)_/ && $key =~ /^FORM_CATEGORY_(.*)$/);
  176. my $category = $in{'input'}->{'CATEGORIES'}->[$in{'input'}->{'CATEGORIES_IX'}->{$1}];
  177. push(@options, { value => "CATEGORY_".$1, label => $category->{'FULL_TITLE'} });
  178. }
  179. $Body .= $Dialog->FormSelectBox(
  180. name => "SECTION",
  181. subject => "Sections",
  182. rows => 5,
  183. extra => { onChange => "form.action.value='ModifyLevel';form.submit()" },
  184. items => \@options
  185. );
  186. my $value = qq~<table cellpadding="3" cellspacing="1" border="0" width="100%">~;
  187. $value .= qq~<tr>~;
  188. $value .= qq~<td width="100%">~;
  189. @options = ({ value => "", label => "" });
  190. foreach my $category (@{ $in{'input'}->{'CATEGORIES'} }) {
  191. push(@options, { value => $category->{'ID'}, label => $category->{'FULL_TITLE'} });
  192. }
  193. $value .= $Form->SelectBox(
  194. name => "ADD_CATEGORY",
  195. items => \@options,
  196. empty => 1
  197. );
  198. $value .= qq~</td>~;
  199. $value .= qq~<td>~;
  200. $value .= $Form->Button(
  201. items => [
  202. { type => "button", value => "Add", extra => { onClick => "form.action.value='ModifyLevel';form.submit();" } }
  203. ]
  204. );
  205. $value .= qq~</td>~;
  206. $value .= qq~</tr>~;
  207. $value .= qq~</table>~;
  208. $Body .= $Dialog->FormTextBox(
  209. value => $value,
  210. subject => "Add Category Line"
  211. );
  212. @options = ();
  213. if ($SL::QUERY{'SECTION'} eq "GENERAL") {
  214. foreach my $permission (@General) {
  215. delete($Hiddens{'FORM_'.$permission->{'name'}});
  216. push(@options, $Form->CheckBox(name => "FORM_".$permission->{'name'}, default => $SL::QUERY{'FORM_'.$permission->{'name'}}, items => [{ value => "1", label => $permission->{'label'} }]));
  217. }
  218. } elsif ($SL::QUERY{'SECTION'} =~ /^CATEGORY_(.*)$/) {
  219. foreach my $permission (@Category) {
  220. delete($Hiddens{'FORM_CATEGORY_'.$1.'_'.$permission->{'name'}});
  221. push(@options, $Form->CheckBox(name => "FORM_CATEGORY_".$1."_".$permission->{'name'}, default => $SL::QUERY{'FORM_CATEGORY_'.$1.'_'.$permission->{'name'}}, items => [{ value => "1", label => $permission->{'label'} }]));
  222. }
  223. push(@options, $Form->Button(items => [{ type => "button", value => "Delete Category Line", extra => { onClick => "form.DEL_CATEGORY.value='".$1."';form.action.value='ModifyLevel';form.submit();" } }]));
  224. }
  225. if (scalar(@options) >= 1) {
  226. $Body .= $Dialog->FormTextBox(
  227. value => join("<br>", @options),
  228. subject => "Permissions"
  229. );
  230. } else {
  231. $Body .= $Dialog->FormTextBox(
  232. value => "Please select a section above to show individual permissions.",
  233. subject => "Permissions"
  234. );
  235. }
  236. $Body .= $Dialog->FormButton(
  237. items => [
  238. { type => "submit", value => "Modify" },
  239. { type => "reset", value => "Cancel" }
  240. ], join => "&nbsp;"
  241. );
  242. my @Hiddens;
  243. foreach my $key (keys %Hiddens) {
  244. push(@Hiddens, { name => $key, value => $Hiddens{$key} });
  245. }
  246. $Body = $Dialog->Table(body => $Body);
  247. $Body = $Dialog->StandardPage(
  248. body => $Body,
  249. header => "Modify a Level",
  250. form => 1,
  251. head_extra => "<script src=\"$SYSTEM->{'PUBLIC_URL'}/functions.js\"></script>",
  252. hiddens => [
  253. @Hiddens,
  254. { name => "NotFirst", value => "1" },
  255. { name => "Referer", value => $SL::QUERY{'Referer'} },
  256. { name => "LID", value => $in{'input'}->{'LEVEL'}->{'ID'} },
  257. { name => "action", value => "DoModifyLevel" },
  258. { name => "CP", value => "1" },
  259. { name => "SID", value => $SL::ADMIN{'SID'} }
  260. ],
  261. ($in{'input'}->{'LEVEL'}->{'ID'} != $SL::ADMIN{'LEVEL'} ? (toolbar => [
  262. { type => "divider" },
  263. { type => "icon", url => "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=DoRemoveLevels&LID=$in{'input'}->{'LEVEL'}->{'ID'}&Referer=".$SL::CGI->escape($SL::QUERY{'Referer'})."&SID=$SL::ADMIN{'SID'}');", icon => "Toolbar/remove.gif", caption => "Remove" }
  264. ]) : ())
  265. );
  266. return $Body;
  267. }
  268. ###############################################################################
  269. # do subroutine
  270. sub do {
  271. my $self = shift;
  272. my %in = (input => undef, @_);
  273. #----------------------------------------------------------------------#
  274. # Printing page... #
  275. my $Dialog = HTML::Dialog->new();
  276. my $Body = $Dialog->TableRow(items => [{ body => "The following level has been modified:", colspan => 2 }]);
  277. $Body .= $Dialog->FormTextBox(
  278. value => $in{'input'}->{'RECORD'}->{'ID'},
  279. subject => "ID"
  280. );
  281. $Body .= $Dialog->FormTextBox(
  282. value => $in{'input'}->{'RECORD'}->{'TITLE'},
  283. subject => "Title"
  284. );
  285. $Body .= $Dialog->TableDivider(colspan => 2);
  286. $Body .= $Dialog->TableRow(items => [{ body => "Click <a href=\"".($SL::QUERY{'Referer'} || "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=Levels&SID=$SL::ADMIN{'SID'}")."\">here</a> if you're not redirected in 5 seconds.", colspan => 2 }]);
  287. $Body = $Dialog->Table(body => $Body);
  288. $Body = $Dialog->StandardPage(
  289. body => $Body,
  290. header => "Modify a Level",
  291. metas => [
  292. { http_equiv => "refresh", content => "5; url=".($SL::QUERY{'Referer'} || "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=Levels&SID=$SL::ADMIN{'SID'}") }
  293. ]
  294. );
  295. return $Body;
  296. }
  297. 1;