Fixed bug #15686: Call the list module through the dispatcher instead directly (Thank...
[Packages/TYPO3.CMS.git] / typo3 / sysext / perm / mod1 / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Module: Permission setting
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
32 * XHTML compliant
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 90: class SC_mod_web_perm_index
42 * 194: public function init()
43 * 246: public function menuConfig()
44 * 277: public function main()
45 * 344: public function printContent()
46 * 354: private function getButtons()
47 *
48 * SECTION: Listing and Form rendering
49 * 398: public function doEdit()
50 * 545: public function notEdit()
51 *
52 * SECTION: Helper functions
53 * 739: public function printCheckBox($checkName, $num)
54 * 752: public function printPerms($int, $pageId = 0, $who = 'user')
55 * 772: public function groupPerms($row, $firstGroup)
56 * 789: public function getRecursiveSelect($id,$perms_clause)
57 *
58 * TOTAL FUNCTIONS: 11
59 * (This index is automatically created/updated by the extension "extdeveval")
60 *
61 */
62
63 unset($MCONF);
64 require('conf.php');
65 require($BACK_PATH.'init.php');
66 require($BACK_PATH.'template.php');
67 require('class.sc_mod_web_perm_ajax.php');
68 $LANG->includeLLFile('EXT:lang/locallang_mod_web_perm.xml');
69
70 $BE_USER->modAccess($MCONF,1);
71
72
73
74
75
76
77 /**
78 * Module: Permission setting
79 *
80 * Script Class for the Web > Access module
81 * This module lets you view and change permissions for pages.
82 *
83 * Variables:
84 * $this->MOD_SETTINGS['depth']: intval 1-3: decides the depth of the list
85 * $this->MOD_SETTINGS['mode']: 'perms' / '': decides if we view a user-overview or the permissions.
86 *
87 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
88 * @author Andreas Kundoch <typo3@mehrwert.de>
89 * @package TYPO3
90 * @subpackage core
91 * @version $Id$
92 */
93 class SC_mod_web_perm_index {
94
95 /**
96 * Number of levels to enable recursive settings for
97 * @var integer
98 */
99 public $getLevels = 10;
100
101 /**
102 * Module config
103 * Internal static
104 * @var array
105 */
106 protected $MCONF = array();
107
108 /**
109 * Document Template Object
110 * @var template
111 */
112 public $doc;
113
114 /**
115 * Content accumulation
116 * @var string
117 */
118 public $content;
119
120 /**
121 * Module menu
122 * @var array
123 */
124 public $MOD_MENU = array();
125
126 /**
127 * Module settings, cleansed.
128 * @var aray
129 */
130 public $MOD_SETTINGS = array();
131
132 /**
133 * Page select permissions
134 * @var string
135 */
136 public $perms_clause;
137
138 /**
139 * Current page record
140 * @var array
141 */
142 public $pageinfo;
143
144 /**
145 * Background color 1
146 * @var string
147 */
148 public $color;
149
150 /**
151 * Background color 2
152 * @var string
153 */
154 public $color2;
155
156 /**
157 * Background color 3
158 * @var string
159 */
160 public $color3;
161
162 /**
163 * Set internally if the current user either OWNS the page OR is admin user!
164 * @var boolean
165 */
166 public $editingAllowed;
167
168 /**
169 * Internal, static: GPvars: Page id.
170 * @var integer
171 */
172 public $id;
173
174 /**
175 * If set, editing of the page permissions will occur (showing the editing screen). Notice:
176 * This value is evaluated against permissions and so it will change internally!
177 * @var boolean
178 */
179 public $edit;
180
181 /**
182 * ID to return to after editing.
183 * @var integer
184 */
185 public $return_id;
186
187 /**
188 * Id of the page which was just edited.
189 * @var integer
190 */
191 public $lastEdited;
192
193 /**
194 * Initialization of the class
195 *
196 * @return void
197 */
198 public function init() {
199
200 // Setting GPvars:
201 $this->id = intval(t3lib_div::_GP('id'));
202 $this->edit = t3lib_div::_GP('edit');
203 $this->return_id = t3lib_div::_GP('return_id');
204 $this->lastEdited = t3lib_div::_GP('lastEdited');
205
206 // Module name;
207 $this->MCONF = $GLOBALS['MCONF'];
208
209 // Page select clause:
210 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
211
212 // Initializing document template object:
213 $this->doc = t3lib_div::makeInstance('template');
214 $this->doc->backPath = $GLOBALS['BACK_PATH'];
215 $this->doc->setModuleTemplate('templates/perm.html');
216 $this->doc->form = '<form action="'.$GLOBALS['BACK_PATH'].'tce_db.php" method="post" name="editform">';
217 $this->doc->loadJavascriptLib('../t3lib/jsfunc.updateform.js');
218 $this->doc->getPageRenderer()->loadPrototype();
219 $this->doc->loadJavascriptLib(TYPO3_MOD_PATH . 'perm.js');
220
221 // Setting up the context sensitive menu:
222 $this->doc->getContextMenuCode();
223
224 // Set up menus:
225 $this->menuConfig();
226 }
227
228 /**
229 * Configuration of the menu and initialization of ->MOD_SETTINGS
230 *
231 * @return void
232 */
233 public function menuConfig() {
234 global $LANG;
235
236 // MENU-ITEMS:
237 // If array, then it's a selector box menu
238 // If empty string it's just a variable, that'll be saved.
239 // Values NOT in this array will not be saved in the settings-array for the module.
240 $temp = $LANG->getLL('levels');
241 $this->MOD_MENU = array(
242 'depth' => array(
243 1 => '1 '.$temp,
244 2 => '2 '.$temp,
245 3 => '3 '.$temp,
246 4 => '4 '.$temp,
247 10 => '10 '.$temp
248 ),
249 'mode' => array(
250 0 => $LANG->getLL('user_overview'),
251 'perms' => $LANG->getLL('permissions')
252 )
253 );
254
255 // Clean up settings:
256 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
257 }
258
259 /**
260 * Main function, creating the content for the access editing forms/listings
261 *
262 * @return void
263 */
264 public function main() {
265 global $BE_USER, $LANG;
266
267 // Access check...
268 // The page will show only if there is a valid page and if this page may be viewed by the user
269 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id, $this->perms_clause);
270 $access = is_array($this->pageinfo);
271
272 // Checking access:
273 if (($this->id && $access) || ($BE_USER->isAdmin() && !$this->id)) {
274 if ($BE_USER->isAdmin() && !$this->id) {
275 $this->pageinfo=array('title' => '[root-level]','uid'=>0,'pid'=>0);
276 }
277
278 // This decides if the editform can and will be drawn:
279 $this->editingAllowed = ($this->pageinfo['perms_userid']==$BE_USER->user['uid'] || $BE_USER->isAdmin());
280 $this->edit = $this->edit && $this->editingAllowed;
281
282 // If $this->edit then these functions are called in the end of the page...
283 if ($this->edit) {
284 $this->doc->postCode.= $this->doc->wrapScriptTags('
285 setCheck("check[perms_user]","data[pages]['.$this->id.'][perms_user]");
286 setCheck("check[perms_group]","data[pages]['.$this->id.'][perms_group]");
287 setCheck("check[perms_everybody]","data[pages]['.$this->id.'][perms_everybody]");
288 ');
289 }
290
291 // Draw the HTML page header.
292 $this->content.=$this->doc->header($LANG->getLL('permissions') . ($this->edit ? ': '.$LANG->getLL('Edit') : ''));
293 $this->content.=$this->doc->spacer(5);
294
295 $vContent = $this->doc->getVersionSelector($this->id,1);
296 if ($vContent) {
297 $this->content .= $this->doc->section('',$vContent);
298 }
299
300 // Main function, branching out:
301 if (!$this->edit) {
302 $this->notEdit();
303 } else {
304 $this->doEdit();
305 }
306
307 $docHeaderButtons = $this->getButtons();
308
309 $markers['CSH'] = $this->docHeaderButtons['csh'];
310 $markers['FUNC_MENU'] = t3lib_BEfunc::getFuncMenu($this->id, 'SET[mode]', $this->MOD_SETTINGS['mode'], $this->MOD_MENU['mode']);
311 $markers['CONTENT'] = $this->content;
312
313 // Build the <body> for the module
314 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
315 } else {
316 // If no access or if ID == zero
317 $this->content =$this->doc->header($LANG->getLL('permissions'));
318 }
319 // Renders the module page
320 $this->content = $this->doc->render(
321 $LANG->getLL('permissions'),
322 $this->content
323 );
324 }
325
326 /**
327 * Outputting the accumulated content to screen
328 *
329 * @return void
330 */
331 public function printContent() {
332 $this->content = $this->doc->insertStylesAndJS($this->content);
333 echo $this->content;
334 }
335
336 /**
337 * Create the panel of buttons for submitting the form or otherwise perform operations.
338 *
339 * @return array all available buttons as an assoc. array
340 */
341 protected function getButtons() {
342
343 $buttons = array(
344 'csh' => '',
345 'view' => '',
346 'record_list' => '',
347 'shortcut' => '',
348 );
349 // CSH
350 $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_info', '', $GLOBALS['BACK_PATH'], '', TRUE);
351
352 // View page
353 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::viewonclick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'], t3lib_BEfunc::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', 1) . '">' .
354 t3lib_iconWorks::getSpriteIcon('actions-document-view') .
355 '</a>';
356
357 // Shortcut
358 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
359 $buttons['shortcut'] = $this->doc->makeShortcutIcon('id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
360 }
361
362 // If access to Web>List for user, then link to that module.
363 $buttons['record_list'] = t3lib_BEfunc::getListViewLink(
364 array(
365 'id' => $this->pageinfo['uid'],
366 'returnUrl' => t3lib_div::getIndpEnv('REQUEST_URI'),
367 ),
368 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList')
369 );
370 return $buttons;
371 }
372
373
374
375
376
377
378
379
380 /*****************************
381 *
382 * Listing and Form rendering
383 *
384 *****************************/
385
386 /**
387 * Creating form for editing the permissions ($this->edit = true)
388 * (Adding content to internal content variable)
389 *
390 * @return void
391 */
392 public function doEdit() {
393 global $BE_USER,$LANG;
394
395 if ($BE_USER->workspace != 0) {
396 // Adding section with the permission setting matrix:
397 $lockedMessage = t3lib_div::makeInstance(
398 't3lib_FlashMessage',
399 $LANG->getLL('WorkspaceWarningText'),
400 $LANG->getLL('WorkspaceWarning'),
401 t3lib_FlashMessage::WARNING
402 );
403 t3lib_FlashMessageQueue::addMessage($lockedMessage);
404 }
405
406 // Get usernames and groupnames
407 $beGroupArray = t3lib_BEfunc::getListGroupNames('title,uid');
408 $beGroupKeys = array_keys($beGroupArray);
409
410 $beUserArray = t3lib_BEfunc::getUserNames();
411 if (!$GLOBALS['BE_USER']->isAdmin()) {
412 $beUserArray = t3lib_BEfunc::blindUserNames($beUserArray,$beGroupKeys,1);
413 }
414 $beGroupArray_o = $beGroupArray = t3lib_BEfunc::getGroupNames();
415 if (!$GLOBALS['BE_USER']->isAdmin()) {
416 $beGroupArray = t3lib_BEfunc::blindGroupNames($beGroupArray_o,$beGroupKeys,1);
417 }
418 $firstGroup = $beGroupKeys[0] ? $beGroupArray[$beGroupKeys[0]] : ''; // data of the first group, the user is member of
419
420
421 // Owner selector:
422 $options='';
423 $userset=0; // flag: is set if the page-userid equals one from the user-list
424 foreach($beUserArray as $uid => $row) {
425 if ($uid==$this->pageinfo['perms_userid']) {
426 $userset = 1;
427 $selected=' selected="selected"';
428 } else {
429 $selected='';
430 }
431 $options.='
432 <option value="'.$uid.'"'.$selected.'>'.htmlspecialchars($row['username']).'</option>';
433 }
434 $options='
435 <option value="0"></option>'.$options;
436 $selector='
437 <select name="data[pages]['.$this->id.'][perms_userid]">
438 '.$options.'
439 </select>';
440
441 $this->content.=$this->doc->section($LANG->getLL('Owner').':',$selector);
442
443
444 // Group selector:
445 $options='';
446 $userset=0;
447 foreach($beGroupArray as $uid => $row) {
448 if ($uid==$this->pageinfo['perms_groupid']) {
449 $userset = 1;
450 $selected=' selected="selected"';
451 } else {
452 $selected='';
453 }
454 $options.='
455 <option value="'.$uid.'"'.$selected.'>'.htmlspecialchars($row['title']).'</option>';
456 }
457 if (!$userset && $this->pageinfo['perms_groupid']) { // If the group was not set AND there is a group for the page
458 $options='
459 <option value="'.$this->pageinfo['perms_groupid'].'" selected="selected">'.
460 htmlspecialchars($beGroupArray_o[$this->pageinfo['perms_groupid']]['title']).
461 '</option>'.
462 $options;
463 }
464 $options='
465 <option value="0"></option>'.$options;
466 $selector='
467 <select name="data[pages]['.$this->id.'][perms_groupid]">
468 '.$options.'
469 </select>';
470
471 $this->content.=$this->doc->divider(5);
472 $this->content.=$this->doc->section($LANG->getLL('Group').':',$selector);
473
474 // Permissions checkbox matrix:
475 $code='
476 <table border="0" cellspacing="2" cellpadding="0" id="typo3-permissionMatrix">
477 <tr>
478 <td></td>
479 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('1',1)).'</td>
480 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('16',1)).'</td>
481 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('2',1)).'</td>
482 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('4',1)).'</td>
483 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('8',1)).'</td>
484 </tr>
485 <tr>
486 <td align="right" class="bgColor2">'.$LANG->getLL('Owner',1).'</td>
487 <td class="bgColor-20">'.$this->printCheckBox('perms_user',1).'</td>
488 <td class="bgColor-20">'.$this->printCheckBox('perms_user',5).'</td>
489 <td class="bgColor-20">'.$this->printCheckBox('perms_user',2).'</td>
490 <td class="bgColor-20">'.$this->printCheckBox('perms_user',3).'</td>
491 <td class="bgColor-20">'.$this->printCheckBox('perms_user',4).'</td>
492 </tr>
493 <tr>
494 <td align="right" class="bgColor2">'.$LANG->getLL('Group',1).'</td>
495 <td class="bgColor-20">'.$this->printCheckBox('perms_group',1).'</td>
496 <td class="bgColor-20">'.$this->printCheckBox('perms_group',5).'</td>
497 <td class="bgColor-20">'.$this->printCheckBox('perms_group',2).'</td>
498 <td class="bgColor-20">'.$this->printCheckBox('perms_group',3).'</td>
499 <td class="bgColor-20">'.$this->printCheckBox('perms_group',4).'</td>
500 </tr>
501 <tr>
502 <td align="right" class="bgColor2">'.$LANG->getLL('Everybody',1).'</td>
503 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',1).'</td>
504 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',5).'</td>
505 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',2).'</td>
506 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',3).'</td>
507 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',4).'</td>
508 </tr>
509 </table>
510 <br />
511
512 <input type="hidden" name="data[pages]['.$this->id.'][perms_user]" value="'.$this->pageinfo['perms_user'].'" />
513 <input type="hidden" name="data[pages]['.$this->id.'][perms_group]" value="'.$this->pageinfo['perms_group'].'" />
514 <input type="hidden" name="data[pages]['.$this->id.'][perms_everybody]" value="'.$this->pageinfo['perms_everybody'].'" />
515 '.$this->getRecursiveSelect($this->id,$this->perms_clause).'
516 <input type="submit" name="submit" value="'.$LANG->getLL('Save',1).'" />'.
517 '<input type="submit" value="'.$LANG->getLL('Abort',1).'" onclick="'.htmlspecialchars('jumpToUrl(\'index.php?id='.$this->id.'\'); return false;').'" />
518 <input type="hidden" name="redirect" value="'.htmlspecialchars(TYPO3_MOD_PATH.'index.php?mode='.$this->MOD_SETTINGS['mode'].'&depth='.$this->MOD_SETTINGS['depth'].'&id='.intval($this->return_id).'&lastEdited='.$this->id).'" />
519 ';
520
521 // Adding section with the permission setting matrix:
522 $this->content.=$this->doc->divider(5);
523 $this->content.=$this->doc->section($LANG->getLL('permissions').':',$code);
524
525 // CSH for permissions setting
526 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'perm_module_setting', $GLOBALS['BACK_PATH'], '<br /><br />');
527
528 // Adding help text:
529 if ($BE_USER->uc['helpText']) {
530 $this->content.=$this->doc->divider(20);
531 $legendText = '<strong>'.$LANG->getLL('1',1).'</strong>: '.$LANG->getLL('1_t',1);
532 $legendText.= '<br /><strong>'.$LANG->getLL('16',1).'</strong>: '.$LANG->getLL('16_t',1);
533 $legendText.= '<br /><strong>'.$LANG->getLL('2',1).'</strong>: '.$LANG->getLL('2_t',1);
534 $legendText.= '<br /><strong>'.$LANG->getLL('4',1).'</strong>: '.$LANG->getLL('4_t',1);
535 $legendText.= '<br /><strong>'.$LANG->getLL('8',1).'</strong>: '.$LANG->getLL('8_t',1);
536
537 $code=$legendText.'<br /><br />'.$LANG->getLL('def',1);
538 $this->content.=$this->doc->section($LANG->getLL('Legend',1).':',$code);
539 }
540 }
541
542 /**
543 * Showing the permissions in a tree ($this->edit = false)
544 * (Adding content to internal content variable)
545 *
546 * @return void
547 */
548 public function notEdit() {
549 global $BE_USER,$LANG,$BACK_PATH;
550
551 // Get usernames and groupnames: The arrays we get in return contains only 1) users which are members of the groups of the current user, 2) groups that the current user is member of
552 $beGroupKeys = $BE_USER->userGroupsUID;
553 $beUserArray = t3lib_BEfunc::getUserNames();
554 if (!$GLOBALS['BE_USER']->isAdmin()) {
555 $beUserArray = t3lib_BEfunc::blindUserNames($beUserArray,$beGroupKeys,0);
556 }
557 $beGroupArray = t3lib_BEfunc::getGroupNames();
558 if (!$GLOBALS['BE_USER']->isAdmin()) {
559 $beGroupArray = t3lib_BEfunc::blindGroupNames($beGroupArray,$beGroupKeys,0);
560 }
561
562 // Length of strings:
563 $tLen= ($this->MOD_SETTINGS['mode']=='perms' ? 20 : 30);
564
565
566 // Selector for depth:
567 $code.=$LANG->getLL('Depth').': ';
568 $code.=t3lib_BEfunc::getFuncMenu($this->id,'SET[depth]',$this->MOD_SETTINGS['depth'],$this->MOD_MENU['depth']);
569 $this->content.=$this->doc->section('',$code);
570 $this->content.=$this->doc->spacer(5);
571
572 // Initialize tree object:
573 $tree = t3lib_div::makeInstance('t3lib_pageTree');
574 $tree->init('AND '.$this->perms_clause);
575
576 $tree->addField('perms_user',1);
577 $tree->addField('perms_group',1);
578 $tree->addField('perms_everybody',1);
579 $tree->addField('perms_userid',1);
580 $tree->addField('perms_groupid',1);
581 $tree->addField('hidden');
582 $tree->addField('fe_group');
583 $tree->addField('starttime');
584 $tree->addField('endtime');
585 $tree->addField('editlock');
586
587 // Creating top icon; the current page
588 $HTML=t3lib_iconWorks::getSpriteIconForRecord('pages',$this->pageinfo);
589 $tree->tree[] = array('row'=>$this->pageinfo,'HTML'=>$HTML);
590
591 // Create the tree from $this->id:
592 $tree->getTree($this->id,$this->MOD_SETTINGS['depth'],'');
593
594 // Make header of table:
595 $code='';
596 if ($this->MOD_SETTINGS['mode']=='perms') {
597 $code.='
598 <tr class="t3-row-header">
599 <td colspan="2">&nbsp;</td>
600 <td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
601 <td>' . $LANG->getLL('Owner', TRUE) . '</td>
602 <td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
603 <td align="center">' . $LANG->getLL('Group', TRUE) . '</td>
604 <td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
605 <td align="center">' . $LANG->getLL('Everybody', TRUE) . '</td>
606 <td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
607 <td align="center">' . $LANG->getLL('EditLock', TRUE) . '</td>
608 </tr>
609 ';
610 } else {
611 $code.='
612 <tr class="t3-row-header">
613 <td colspan="2">&nbsp;</td>
614 <td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
615 <td align="center" nowrap="nowrap">' . $LANG->getLL('User', TRUE) . ': ' . htmlspecialchars($BE_USER->user['username']) . '</td>
616 ' . (!$BE_USER->isAdmin() ? '<td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
617 <td align="center">' . $LANG->getLL('EditLock', TRUE) . '</td>' : '') . '
618 </tr>';
619 }
620
621 // Traverse tree:
622 foreach ($tree->tree as $data) {
623 $cells = array();
624 $pageId = $data['row']['uid'];
625
626 // Background colors:
627 $bgCol = ($this->lastEdited == $pageId ? ' class="bgColor-20"' : '');
628 $lE_bgCol = $bgCol;
629
630 // User/Group names:
631 $userName = $beUserArray[$data['row']['perms_userid']] ? $beUserArray[$data['row']['perms_userid']]['username'] : ($data['row']['perms_userid'] ? $data['row']['perms_userid'] : '');
632 if ($data['row']['perms_userid'] && (!$beUserArray[$data['row']['perms_userid']])) {
633 $userName = SC_mod_web_perm_ajax::renderOwnername($pageId, $data['row']['perms_userid'], htmlspecialchars(t3lib_div::fixed_lgd_cs($userName, 20)), false);
634 } else {
635 $userName = SC_mod_web_perm_ajax::renderOwnername($pageId, $data['row']['perms_userid'], htmlspecialchars(t3lib_div::fixed_lgd_cs($userName, 20)));
636 }
637
638 $groupName = $beGroupArray[$data['row']['perms_groupid']] ? $beGroupArray[$data['row']['perms_groupid']]['title'] : ($data['row']['perms_groupid'] ? $data['row']['perms_groupid'] : '');
639 if ($data['row']['perms_groupid'] && (!$beGroupArray[$data['row']['perms_groupid']])) {
640 $groupName = SC_mod_web_perm_ajax::renderGroupname($pageId, $data['row']['perms_groupid'], htmlspecialchars(t3lib_div::fixed_lgd_cs($groupName, 20)), false);
641 } else {
642 $groupName = SC_mod_web_perm_ajax::renderGroupname($pageId, $data['row']['perms_groupid'], htmlspecialchars(t3lib_div::fixed_lgd_cs($groupName, 20)));
643 }
644
645 // Seeing if editing of permissions are allowed for that page:
646 $editPermsAllowed = ($data['row']['perms_userid'] == $BE_USER->user['uid'] || $BE_USER->isAdmin());
647
648
649 // First column:
650 $cellAttrib = ($data['row']['_CSSCLASS'] ? ' class="'.$data['row']['_CSSCLASS'].'"' : '');
651 $cells[]='
652 <td align="left" nowrap="nowrap"'.($cellAttrib ? $cellAttrib : $bgCol).'>'.$data['HTML'].htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['title'],$tLen)).'&nbsp;</td>';
653
654 // "Edit permissions" -icon
655 if ($editPermsAllowed && $pageId) {
656 $aHref = 'index.php?mode='.$this->MOD_SETTINGS['mode'].'&depth='.$this->MOD_SETTINGS['depth'].'&id='.($data['row']['_ORIG_uid'] ? $data['row']['_ORIG_uid'] : $pageId).'&return_id='.$this->id.'&edit=1';
657 $cells[]='
658 <td'.$bgCol.'><a href="'.htmlspecialchars($aHref).'" title="'.$LANG->getLL('ch_permissions',1).'">' . t3lib_iconWorks::getSpriteIcon('actions-document-open') . '</a></td>';
659 } else {
660 $cells[]='
661 <td'.$bgCol.'></td>';
662 }
663
664 // Rest of columns (depending on mode)
665 if ($this->MOD_SETTINGS['mode'] == 'perms') {
666 $cells[]='
667 <td' . $bgCol . ' class="center"><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
668 <td'.$bgCol.' nowrap="nowrap">'.($pageId ? SC_mod_web_perm_ajax::renderPermissions($data['row']['perms_user'], $pageId, 'user').' '.$userName : '').'</td>
669
670 <td' . $bgCol . ' class="center"><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
671 <td'.$bgCol.' nowrap="nowrap">'.($pageId ? SC_mod_web_perm_ajax::renderPermissions($data['row']['perms_group'], $pageId, 'group').' '.$groupName : '').'</td>
672
673 <td' . $bgCol . ' class="center"><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
674 <td'.$bgCol.' nowrap="nowrap">'.($pageId ? ' '.SC_mod_web_perm_ajax::renderPermissions($data['row']['perms_everybody'], $pageId, 'everybody') : '').'</td>
675
676 <td' . $bgCol . ' class="center"><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
677 <td'.$bgCol.' nowrap="nowrap">'.($data['row']['editlock']?'<span id="el_'.$pageId.'" class="editlock"><a class="editlock" onclick="WebPermissions.toggleEditLock(\''.$pageId.'\', \'1\');" title="'.$LANG->getLL('EditLock_descr',1).'">' .
678 t3lib_iconWorks::getSpriteIcon('status-warning-lock') . '</a></span>' : ( $pageId === 0 ? '' : '<span id="el_'.$pageId.'" class="editlock"><a class="editlock" onclick="WebPermissions.toggleEditLock(\''.$pageId.'\', \'0\');" title="Enable the &raquo;Admin-only&laquo; edit lock for this page">[+]</a></span>')).'</td>
679 ';
680 } else {
681 $cells[]='
682 <td' . $bgCol . ' class="center"><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>';
683
684 $bgCol = ($BE_USER->user['uid'] == $data['row']['perms_userid'] ? ' class="bgColor-20"' : $lE_bgCol);
685
686 // FIXME $owner undefined
687 $cells[]='
688 <td'.$bgCol.' nowrap="nowrap" align="center">'.($pageId ? $owner.SC_mod_web_perm_ajax::renderPermissions($BE_USER->calcPerms($data['row']), $pageId, 'user') : '').'</td>
689 '.(!$BE_USER->isAdmin()?'
690 <td' . $bgCol . ' class="center"><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
691 <td'.$bgCol.' nowrap="nowrap">'.($data['row']['editlock'] ? t3lib_iconWorks::getSpriteIcon('status-warning-lock', array('title' => $LANG->getLL('EditLock_descr', TRUE))) : '').'</td>
692 ':'');
693 $bgCol = $lE_bgCol;
694 }
695
696 // Compile table row:
697 $code .= '
698 <tr>
699 '.implode('
700 ',$cells).'
701 </tr>';
702 }
703
704 // Wrap rows in table tags:
705 $code = '<table border="0" cellspacing="0" cellpadding="0" id="typo3-permissionList">' . $code . '</table>';
706
707 // Adding the content as a section:
708 $this->content.=$this->doc->section('',$code);
709
710 // CSH for permissions setting
711 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'perm_module', $GLOBALS['BACK_PATH'], '<br />|');
712
713 // Creating legend table:
714 $legendText = '<strong>'.$LANG->getLL('1',1).'</strong>: '.$LANG->getLL('1_t',1);
715 $legendText.= '<br /><strong>'.$LANG->getLL('16',1).'</strong>: '.$LANG->getLL('16_t',1);
716 $legendText.= '<br /><strong>'.$LANG->getLL('2',1).'</strong>: '.$LANG->getLL('2_t',1);
717 $legendText.= '<br /><strong>'.$LANG->getLL('4',1).'</strong>: '.$LANG->getLL('4_t',1);
718 $legendText.= '<br /><strong>'.$LANG->getLL('8',1).'</strong>: '.$LANG->getLL('8_t',1);
719
720 $code='<table border="0" id="typo3-legendTable">
721 <tr>
722 <td valign="top">
723 <img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/legend.gif', 'width="86" height="75"') . ' alt="" />
724 </td>
725 <td valign="top" nowrap="nowrap">'.$legendText.'</td>
726 </tr>
727 </table>';
728 $code.='<div id="perm-legend">'.$LANG->getLL('def',1);
729 $code.='<br /><br />'.t3lib_iconWorks::getSpriteIcon('status-status-permission-granted').': '.$LANG->getLL('A_Granted', 1);
730 $code.='<br />'.t3lib_iconWorks::getSpriteIcon('status-status-permission-denied').': '.$LANG->getLL('A_Denied', 1);
731 $code.='</div>';
732
733 // Adding section with legend code:
734 $this->content.=$this->doc->spacer(20);
735 $this->content.=$this->doc->section($LANG->getLL('Legend').':',$code,0,1);
736 }
737
738
739
740
741
742
743
744 /*****************************
745 *
746 * Helper functions
747 *
748 *****************************/
749
750 /**
751 * Print a checkbox for the edit-permission form
752 *
753 * @param string Checkbox name key
754 * @param integer Checkbox number index
755 * @return string HTML checkbox
756 */
757 public function printCheckBox($checkName, $num) {
758 $onclick = 'checkChange(\'check['.$checkName.']\', \'data[pages]['.$GLOBALS['SOBE']->id.']['.$checkName.']\')';
759 return '<input type="checkbox" name="check['.$checkName.']['.$num.']" onclick="'.htmlspecialchars($onclick).'" /><br />';
760 }
761
762
763 /**
764 * Returns the permissions for a group based of the perms_groupid of $row. If the $row[perms_groupid] equals the $firstGroup[uid] then the function returns perms_everybody OR'ed with perms_group, else just perms_everybody
765 *
766 * @param array Row array (from pages table)
767 * @param array First group data
768 * @return integer Integer: Combined permissions.
769 */
770 public function groupPerms($row, $firstGroup) {
771 if (is_array($row)) {
772 $out = intval($row['perms_everybody']);
773 if ($row['perms_groupid'] && $firstGroup['uid']==$row['perms_groupid']) {
774 $out |= intval($row['perms_group']);
775 }
776 return $out;
777 }
778 }
779
780 /**
781 * Finding tree and offer setting of values recursively.
782 *
783 * @param integer Page id.
784 * @param string Select clause
785 * @return string Select form element for recursive levels (if any levels are found)
786 */
787 public function getRecursiveSelect($id,$perms_clause) {
788
789 // Initialize tree object:
790 $tree = t3lib_div::makeInstance('t3lib_pageTree');
791 $tree->init('AND '.$perms_clause);
792 $tree->addField('perms_userid',1);
793 $tree->makeHTML=0;
794 $tree->setRecs = 1;
795
796 // Make tree:
797 $tree->getTree($id,$this->getLevels,'');
798
799 // If there are a hierarchy of page ids, then...
800 if ($GLOBALS['BE_USER']->user['uid'] && count($tree->orig_ids_hierarchy)) {
801
802 // Init:
803 $label_recur = $GLOBALS['LANG']->getLL('recursive');
804 $label_levels = $GLOBALS['LANG']->getLL('levels');
805 $label_pA = $GLOBALS['LANG']->getLL('pages_affected');
806 $theIdListArr=array();
807 $opts='
808 <option value=""></option>';
809
810 // Traverse the number of levels we want to allow recursive setting of permissions for:
811 for ($a=$this->getLevels;$a>0;$a--) {
812 if (is_array($tree->orig_ids_hierarchy[$a])) {
813 foreach($tree->orig_ids_hierarchy[$a] as $theId) {
814 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->user['uid']==$tree->recs[$theId]['perms_userid']) {
815 $theIdListArr[]=$theId;
816 }
817 }
818 $lKey = $this->getLevels-$a+1;
819 $opts.='
820 <option value="'.htmlspecialchars(implode(',',$theIdListArr)).'">'.
821 t3lib_div::deHSCentities(htmlspecialchars($label_recur.' '.$lKey.' '.$label_levels)).' ('.count($theIdListArr).' '.$label_pA.')'.
822 '</option>';
823 }
824 }
825
826 // Put the selector box together:
827 $theRecursiveSelect = '<br />
828 <select name="mirror[pages]['.$id.']">
829 '.$opts.'
830 </select>
831 <br /><br />';
832 } else {
833 $theRecursiveSelect = '';
834 }
835
836 // Return selector box element:
837 return $theRecursiveSelect;
838 }
839 }
840
841
842 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/mod/web/perm/index.php'])) {
843 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/mod/web/perm/index.php']);
844 }
845
846
847
848
849 // Make instance:
850 $SOBE = t3lib_div::makeInstance('SC_mod_web_perm_index');
851 $SOBE->init();
852 $SOBE->main();
853 $SOBE->printContent();
854
855 ?>