cab1d08a9840507985b21aac093d9208821e0c91
[Packages/TYPO3.CMS.git] / typo3 / sysext / perm / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 Kasper Skaarhoj (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 Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <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 Skaarhoj <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->startPage($LANG->getLL('permissions'));
315 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
316 } else {
317 // If no access or if ID == zero
318 $this->content.=$this->doc->startPage($LANG->getLL('permissions'));
319 $this->content.=$this->doc->header($LANG->getLL('permissions'));
320 }
321 $this->content.= $this->doc->endPage();
322 }
323
324 /**
325 * Outputting the accumulated content to screen
326 *
327 * @return void
328 */
329 public function printContent() {
330 $this->content = $this->doc->insertStylesAndJS($this->content);
331 echo $this->content;
332 }
333
334 /**
335 * Create the panel of buttons for submitting the form or otherwise perform operations.
336 *
337 * @return array all available buttons as an assoc. array
338 */
339 protected function getButtons() {
340
341 $buttons = array(
342 'csh' => '',
343 'view' => '',
344 'record_list' => '',
345 'shortcut' => '',
346 );
347 // CSH
348 $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_info', '', $GLOBALS['BACK_PATH'], '', TRUE);
349
350 // View page
351 $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) . '">' .
352 t3lib_iconWorks::getSpriteIcon('actions-document-view') .
353 '</a>';
354
355 // Shortcut
356 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
357 $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']);
358 }
359
360 // If access to Web>List for user, then link to that module.
361 if ($GLOBALS['BE_USER']->check('modules','web_list')) {
362 $href = $GLOBALS['BACK_PATH'] . 'db_list.php?id=' . $this->pageinfo['uid'] . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
363 $buttons['record_list'] = '<a href="' . htmlspecialchars($href) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList', 1) . '">' .
364 t3lib_iconWorks::getSpriteIcon('actions-system-list-open') .
365 '</a>';
366 }
367 return $buttons;
368 }
369
370
371
372
373
374
375
376
377 /*****************************
378 *
379 * Listing and Form rendering
380 *
381 *****************************/
382
383 /**
384 * Creating form for editing the permissions ($this->edit = true)
385 * (Adding content to internal content variable)
386 *
387 * @return void
388 */
389 public function doEdit() {
390 global $BE_USER,$LANG;
391
392 if ($BE_USER->workspace != 0) {
393 // Adding section with the permission setting matrix:
394 $lockedMessage = t3lib_div::makeInstance(
395 't3lib_FlashMessage',
396 $LANG->getLL('WorkspaceWarningText'),
397 $LANG->getLL('WorkspaceWarning'),
398 t3lib_FlashMessage::WARNING
399 );
400 t3lib_FlashMessageQueue::addMessage($lockedMessage);
401 }
402
403 // Get usernames and groupnames
404 $beGroupArray = t3lib_BEfunc::getListGroupNames('title,uid');
405 $beGroupKeys = array_keys($beGroupArray);
406
407 $beUserArray = t3lib_BEfunc::getUserNames();
408 if (!$GLOBALS['BE_USER']->isAdmin()) {
409 $beUserArray = t3lib_BEfunc::blindUserNames($beUserArray,$beGroupKeys,1);
410 }
411 $beGroupArray_o = $beGroupArray = t3lib_BEfunc::getGroupNames();
412 if (!$GLOBALS['BE_USER']->isAdmin()) {
413 $beGroupArray = t3lib_BEfunc::blindGroupNames($beGroupArray_o,$beGroupKeys,1);
414 }
415 $firstGroup = $beGroupKeys[0] ? $beGroupArray[$beGroupKeys[0]] : ''; // data of the first group, the user is member of
416
417
418 // Owner selector:
419 $options='';
420 $userset=0; // flag: is set if the page-userid equals one from the user-list
421 foreach($beUserArray as $uid => $row) {
422 if ($uid==$this->pageinfo['perms_userid']) {
423 $userset = 1;
424 $selected=' selected="selected"';
425 } else {
426 $selected='';
427 }
428 $options.='
429 <option value="'.$uid.'"'.$selected.'>'.htmlspecialchars($row['username']).'</option>';
430 }
431 $options='
432 <option value="0"></option>'.$options;
433 $selector='
434 <select name="data[pages]['.$this->id.'][perms_userid]">
435 '.$options.'
436 </select>';
437
438 $this->content.=$this->doc->section($LANG->getLL('Owner').':',$selector);
439
440
441 // Group selector:
442 $options='';
443 $userset=0;
444 foreach($beGroupArray as $uid => $row) {
445 if ($uid==$this->pageinfo['perms_groupid']) {
446 $userset = 1;
447 $selected=' selected="selected"';
448 } else {
449 $selected='';
450 }
451 $options.='
452 <option value="'.$uid.'"'.$selected.'>'.htmlspecialchars($row['title']).'</option>';
453 }
454 if (!$userset && $this->pageinfo['perms_groupid']) { // If the group was not set AND there is a group for the page
455 $options='
456 <option value="'.$this->pageinfo['perms_groupid'].'" selected="selected">'.
457 htmlspecialchars($beGroupArray_o[$this->pageinfo['perms_groupid']]['title']).
458 '</option>'.
459 $options;
460 }
461 $options='
462 <option value="0"></option>'.$options;
463 $selector='
464 <select name="data[pages]['.$this->id.'][perms_groupid]">
465 '.$options.'
466 </select>';
467
468 $this->content.=$this->doc->divider(5);
469 $this->content.=$this->doc->section($LANG->getLL('Group').':',$selector);
470
471 // Permissions checkbox matrix:
472 $code='
473 <table border="0" cellspacing="2" cellpadding="0" id="typo3-permissionMatrix">
474 <tr>
475 <td></td>
476 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('1',1)).'</td>
477 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('16',1)).'</td>
478 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('2',1)).'</td>
479 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('4',1)).'</td>
480 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('8',1)).'</td>
481 </tr>
482 <tr>
483 <td align="right" class="bgColor2">'.$LANG->getLL('Owner',1).'</td>
484 <td class="bgColor-20">'.$this->printCheckBox('perms_user',1).'</td>
485 <td class="bgColor-20">'.$this->printCheckBox('perms_user',5).'</td>
486 <td class="bgColor-20">'.$this->printCheckBox('perms_user',2).'</td>
487 <td class="bgColor-20">'.$this->printCheckBox('perms_user',3).'</td>
488 <td class="bgColor-20">'.$this->printCheckBox('perms_user',4).'</td>
489 </tr>
490 <tr>
491 <td align="right" class="bgColor2">'.$LANG->getLL('Group',1).'</td>
492 <td class="bgColor-20">'.$this->printCheckBox('perms_group',1).'</td>
493 <td class="bgColor-20">'.$this->printCheckBox('perms_group',5).'</td>
494 <td class="bgColor-20">'.$this->printCheckBox('perms_group',2).'</td>
495 <td class="bgColor-20">'.$this->printCheckBox('perms_group',3).'</td>
496 <td class="bgColor-20">'.$this->printCheckBox('perms_group',4).'</td>
497 </tr>
498 <tr>
499 <td align="right" class="bgColor2">'.$LANG->getLL('Everybody',1).'</td>
500 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',1).'</td>
501 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',5).'</td>
502 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',2).'</td>
503 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',3).'</td>
504 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',4).'</td>
505 </tr>
506 </table>
507 <br />
508
509 <input type="hidden" name="data[pages]['.$this->id.'][perms_user]" value="'.$this->pageinfo['perms_user'].'" />
510 <input type="hidden" name="data[pages]['.$this->id.'][perms_group]" value="'.$this->pageinfo['perms_group'].'" />
511 <input type="hidden" name="data[pages]['.$this->id.'][perms_everybody]" value="'.$this->pageinfo['perms_everybody'].'" />
512 '.$this->getRecursiveSelect($this->id,$this->perms_clause).'
513 <input type="submit" name="submit" value="'.$LANG->getLL('Save',1).'" />'.
514 '<input type="submit" value="'.$LANG->getLL('Abort',1).'" onclick="'.htmlspecialchars('jumpToUrl(\'index.php?id='.$this->id.'\'); return false;').'" />
515 <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).'" />
516 ';
517
518 // Adding section with the permission setting matrix:
519 $this->content.=$this->doc->divider(5);
520 $this->content.=$this->doc->section($LANG->getLL('permissions').':',$code);
521
522 // CSH for permissions setting
523 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'perm_module_setting', $GLOBALS['BACK_PATH'], '<br /><br />');
524
525 // Adding help text:
526 if ($BE_USER->uc['helpText']) {
527 $this->content.=$this->doc->divider(20);
528 $legendText = '<strong>'.$LANG->getLL('1',1).'</strong>: '.$LANG->getLL('1_t',1);
529 $legendText.= '<br /><strong>'.$LANG->getLL('16',1).'</strong>: '.$LANG->getLL('16_t',1);
530 $legendText.= '<br /><strong>'.$LANG->getLL('2',1).'</strong>: '.$LANG->getLL('2_t',1);
531 $legendText.= '<br /><strong>'.$LANG->getLL('4',1).'</strong>: '.$LANG->getLL('4_t',1);
532 $legendText.= '<br /><strong>'.$LANG->getLL('8',1).'</strong>: '.$LANG->getLL('8_t',1);
533
534 $code=$legendText.'<br /><br />'.$LANG->getLL('def',1);
535 $this->content.=$this->doc->section($LANG->getLL('Legend',1).':',$code);
536 }
537 }
538
539 /**
540 * Showing the permissions in a tree ($this->edit = false)
541 * (Adding content to internal content variable)
542 *
543 * @return void
544 */
545 public function notEdit() {
546 global $BE_USER,$LANG,$BACK_PATH;
547
548 // 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
549 $beGroupKeys = $BE_USER->userGroupsUID;
550 $beUserArray = t3lib_BEfunc::getUserNames();
551 if (!$GLOBALS['BE_USER']->isAdmin()) {
552 $beUserArray = t3lib_BEfunc::blindUserNames($beUserArray,$beGroupKeys,0);
553 }
554 $beGroupArray = t3lib_BEfunc::getGroupNames();
555 if (!$GLOBALS['BE_USER']->isAdmin()) {
556 $beGroupArray = t3lib_BEfunc::blindGroupNames($beGroupArray,$beGroupKeys,0);
557 }
558
559 // Length of strings:
560 $tLen= ($this->MOD_SETTINGS['mode']=='perms' ? 20 : 30);
561
562
563 // Selector for depth:
564 $code.=$LANG->getLL('Depth').': ';
565 $code.=t3lib_BEfunc::getFuncMenu($this->id,'SET[depth]',$this->MOD_SETTINGS['depth'],$this->MOD_MENU['depth']);
566 $this->content.=$this->doc->section('',$code);
567 $this->content.=$this->doc->spacer(5);
568
569 // Initialize tree object:
570 $tree = t3lib_div::makeInstance('t3lib_pageTree');
571 $tree->init('AND '.$this->perms_clause);
572
573 $tree->addField('perms_user',1);
574 $tree->addField('perms_group',1);
575 $tree->addField('perms_everybody',1);
576 $tree->addField('perms_userid',1);
577 $tree->addField('perms_groupid',1);
578 $tree->addField('hidden');
579 $tree->addField('fe_group');
580 $tree->addField('starttime');
581 $tree->addField('endtime');
582 $tree->addField('editlock');
583
584 // Creating top icon; the current page
585 $HTML=t3lib_iconWorks::getSpriteIconForRecord('pages',$this->pageinfo);
586 $tree->tree[] = array('row'=>$this->pageinfo,'HTML'=>$HTML);
587
588 // Create the tree from $this->id:
589 $tree->getTree($this->id,$this->MOD_SETTINGS['depth'],'');
590
591 // Make header of table:
592 $code='';
593 if ($this->MOD_SETTINGS['mode']=='perms') {
594 $code.='
595 <tr class="t3-row-header">
596 <td colspan="2">&nbsp;</td>
597 <td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
598 <td>' . $LANG->getLL('Owner', TRUE) . '</td>
599 <td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
600 <td align="center">' . $LANG->getLL('Group', TRUE) . '</td>
601 <td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
602 <td align="center">' . $LANG->getLL('Everybody', TRUE) . '</td>
603 <td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
604 <td align="center">' . $LANG->getLL('EditLock', TRUE) . '</td>
605 </tr>
606 ';
607 } else {
608 $code.='
609 <tr class="t3-row-header">
610 <td colspan="2">&nbsp;</td>
611 <td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
612 <td align="center" nowrap="nowrap">' . $LANG->getLL('User', TRUE) . ': ' . htmlspecialchars($BE_USER->user['username']) . '</td>
613 ' . (!$BE_USER->isAdmin() ? '<td><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
614 <td align="center">' . $LANG->getLL('EditLock', TRUE) . '</td>' : '') . '
615 </tr>';
616 }
617
618 // Traverse tree:
619 foreach ($tree->tree as $data) {
620 $cells = array();
621 $pageId = $data['row']['uid'];
622
623 // Background colors:
624 $bgCol = ($this->lastEdited == $pageId ? ' class="bgColor-20"' : '');
625 $lE_bgCol = $bgCol;
626
627 // User/Group names:
628 $userName = $beUserArray[$data['row']['perms_userid']] ? $beUserArray[$data['row']['perms_userid']]['username'] : ($data['row']['perms_userid'] ? $data['row']['perms_userid'] : '');
629 if ($data['row']['perms_userid'] && (!$beUserArray[$data['row']['perms_userid']])) {
630 $userName = SC_mod_web_perm_ajax::renderOwnername($pageId, $data['row']['perms_userid'], htmlspecialchars(t3lib_div::fixed_lgd_cs($userName, 20)), false);
631 } else {
632 $userName = SC_mod_web_perm_ajax::renderOwnername($pageId, $data['row']['perms_userid'], htmlspecialchars(t3lib_div::fixed_lgd_cs($userName, 20)));
633 }
634
635 $groupName = $beGroupArray[$data['row']['perms_groupid']] ? $beGroupArray[$data['row']['perms_groupid']]['title'] : ($data['row']['perms_groupid'] ? $data['row']['perms_groupid'] : '');
636 if ($data['row']['perms_groupid'] && (!$beGroupArray[$data['row']['perms_groupid']])) {
637 $groupName = SC_mod_web_perm_ajax::renderGroupname($pageId, $data['row']['perms_groupid'], htmlspecialchars(t3lib_div::fixed_lgd_cs($groupName, 20)), false);
638 } else {
639 $groupName = SC_mod_web_perm_ajax::renderGroupname($pageId, $data['row']['perms_groupid'], htmlspecialchars(t3lib_div::fixed_lgd_cs($groupName, 20)));
640 }
641
642 // Seeing if editing of permissions are allowed for that page:
643 $editPermsAllowed = ($data['row']['perms_userid'] == $BE_USER->user['uid'] || $BE_USER->isAdmin());
644
645
646 // First column:
647 $cellAttrib = ($data['row']['_CSSCLASS'] ? ' class="'.$data['row']['_CSSCLASS'].'"' : '');
648 $cells[]='
649 <td align="left" nowrap="nowrap"'.($cellAttrib ? $cellAttrib : $bgCol).'>'.$data['HTML'].htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['title'],$tLen)).'&nbsp;</td>';
650
651 // "Edit permissions" -icon
652 if ($editPermsAllowed && $pageId) {
653 $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';
654 $cells[]='
655 <td'.$bgCol.'><a href="'.htmlspecialchars($aHref).'" title="'.$LANG->getLL('ch_permissions',1).'">' . t3lib_iconWorks::getSpriteIcon('actions-document-open') . '</a></td>';
656 } else {
657 $cells[]='
658 <td'.$bgCol.'></td>';
659 }
660
661 // Rest of columns (depending on mode)
662 if ($this->MOD_SETTINGS['mode'] == 'perms') {
663 $cells[]='
664 <td' . $bgCol . ' class="center"><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
665 <td'.$bgCol.' nowrap="nowrap">'.($pageId ? SC_mod_web_perm_ajax::renderPermissions($data['row']['perms_user'], $pageId, 'user').' '.$userName : '').'</td>
666
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_group'], $pageId, 'group').' '.$groupName : '').'</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_everybody'], $pageId, 'everybody') : '').'</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">'.($data['row']['editlock']?'<span id="el_'.$pageId.'" class="editlock"><a class="editlock" onclick="WebPermissions.toggleEditLock(\''.$pageId.'\', \'1\');" title="'.$LANG->getLL('EditLock_descr',1).'">' .
675 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>
676 ';
677 } else {
678 $cells[]='
679 <td' . $bgCol . ' class="center"><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>';
680
681 $bgCol = ($BE_USER->user['uid'] == $data['row']['perms_userid'] ? ' class="bgColor-20"' : $lE_bgCol);
682
683 // FIXME $owner undefined
684 $cells[]='
685 <td'.$bgCol.' nowrap="nowrap" align="center">'.($pageId ? $owner.SC_mod_web_perm_ajax::renderPermissions($BE_USER->calcPerms($data['row']), $pageId, 'user') : '').'</td>
686 '.(!$BE_USER->isAdmin()?'
687 <td' . $bgCol . ' class="center"><img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
688 <td'.$bgCol.' nowrap="nowrap">'.($data['row']['editlock'] ? t3lib_iconWorks::getSpriteIcon('status-warning-lock', array('title' => $LANG->getLL('EditLock_descr', TRUE))) : '').'</td>
689 ':'');
690 $bgCol = $lE_bgCol;
691 }
692
693 // Compile table row:
694 $code .= '
695 <tr>
696 '.implode('
697 ',$cells).'
698 </tr>';
699 }
700
701 // Wrap rows in table tags:
702 $code = '<table border="0" cellspacing="0" cellpadding="0" id="typo3-permissionList">' . $code . '</table>';
703
704 // Adding the content as a section:
705 $this->content.=$this->doc->section('',$code);
706
707 // CSH for permissions setting
708 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'perm_module', $GLOBALS['BACK_PATH'], '<br />|');
709
710 // Creating legend table:
711 $legendText = '<strong>'.$LANG->getLL('1',1).'</strong>: '.$LANG->getLL('1_t',1);
712 $legendText.= '<br /><strong>'.$LANG->getLL('16',1).'</strong>: '.$LANG->getLL('16_t',1);
713 $legendText.= '<br /><strong>'.$LANG->getLL('2',1).'</strong>: '.$LANG->getLL('2_t',1);
714 $legendText.= '<br /><strong>'.$LANG->getLL('4',1).'</strong>: '.$LANG->getLL('4_t',1);
715 $legendText.= '<br /><strong>'.$LANG->getLL('8',1).'</strong>: '.$LANG->getLL('8_t',1);
716
717 $code='<table border="0" id="typo3-legendTable">
718 <tr>
719 <td valign="top">
720 <img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/legend.gif', 'width="86" height="75"') . ' alt="" />
721 </td>
722 <td valign="top" nowrap="nowrap">'.$legendText.'</td>
723 </tr>
724 </table>';
725 $code.='<div id="perm-legend">'.$LANG->getLL('def',1);
726 $code.='<br /><br />'.t3lib_iconWorks::getSpriteIcon('status-status-permission-granted').': '.$LANG->getLL('A_Granted', 1);
727 $code.='<br />'.t3lib_iconWorks::getSpriteIcon('status-status-permission-denied').': '.$LANG->getLL('A_Denied', 1);
728 $code.='</div>';
729
730 // Adding section with legend code:
731 $this->content.=$this->doc->spacer(20);
732 $this->content.=$this->doc->section($LANG->getLL('Legend').':',$code,0,1);
733 }
734
735
736
737
738
739
740
741 /*****************************
742 *
743 * Helper functions
744 *
745 *****************************/
746
747 /**
748 * Print a checkbox for the edit-permission form
749 *
750 * @param string Checkbox name key
751 * @param integer Checkbox number index
752 * @return string HTML checkbox
753 */
754 public function printCheckBox($checkName, $num) {
755 $onclick = 'checkChange(\'check['.$checkName.']\', \'data[pages]['.$GLOBALS['SOBE']->id.']['.$checkName.']\')';
756 return '<input type="checkbox" name="check['.$checkName.']['.$num.']" onclick="'.htmlspecialchars($onclick).'" /><br />';
757 }
758
759
760 /**
761 * 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
762 *
763 * @param array Row array (from pages table)
764 * @param array First group data
765 * @return integer Integer: Combined permissions.
766 */
767 public function groupPerms($row, $firstGroup) {
768 if (is_array($row)) {
769 $out = intval($row['perms_everybody']);
770 if ($row['perms_groupid'] && $firstGroup['uid']==$row['perms_groupid']) {
771 $out |= intval($row['perms_group']);
772 }
773 return $out;
774 }
775 }
776
777 /**
778 * Finding tree and offer setting of values recursively.
779 *
780 * @param integer Page id.
781 * @param string Select clause
782 * @return string Select form element for recursive levels (if any levels are found)
783 */
784 public function getRecursiveSelect($id,$perms_clause) {
785
786 // Initialize tree object:
787 $tree = t3lib_div::makeInstance('t3lib_pageTree');
788 $tree->init('AND '.$perms_clause);
789 $tree->addField('perms_userid',1);
790 $tree->makeHTML=0;
791 $tree->setRecs = 1;
792
793 // Make tree:
794 $tree->getTree($id,$this->getLevels,'');
795
796 // If there are a hierarchy of page ids, then...
797 if ($GLOBALS['BE_USER']->user['uid'] && count($tree->orig_ids_hierarchy)) {
798
799 // Init:
800 $label_recur = $GLOBALS['LANG']->getLL('recursive');
801 $label_levels = $GLOBALS['LANG']->getLL('levels');
802 $label_pA = $GLOBALS['LANG']->getLL('pages_affected');
803 $theIdListArr=array();
804 $opts='
805 <option value=""></option>';
806
807 // Traverse the number of levels we want to allow recursive setting of permissions for:
808 for ($a=$this->getLevels;$a>0;$a--) {
809 if (is_array($tree->orig_ids_hierarchy[$a])) {
810 foreach($tree->orig_ids_hierarchy[$a] as $theId) {
811 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->user['uid']==$tree->recs[$theId]['perms_userid']) {
812 $theIdListArr[]=$theId;
813 }
814 }
815 $lKey = $this->getLevels-$a+1;
816 $opts.='
817 <option value="'.htmlspecialchars(implode(',',$theIdListArr)).'">'.
818 t3lib_div::deHSCentities(htmlspecialchars($label_recur.' '.$lKey.' '.$label_levels)).' ('.count($theIdListArr).' '.$label_pA.')'.
819 '</option>';
820 }
821 }
822
823 // Put the selector box together:
824 $theRecursiveSelect = '<br />
825 <select name="mirror[pages]['.$id.']">
826 '.$opts.'
827 </select>
828 <br /><br />';
829 } else {
830 $theRecursiveSelect = '';
831 }
832
833 // Return selector box element:
834 return $theRecursiveSelect;
835 }
836 }
837
838
839 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/web/perm/index.php']) {
840 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/web/perm/index.php']);
841 }
842
843
844
845
846 // Make instance:
847 $SOBE = t3lib_div::makeInstance('SC_mod_web_perm_index');
848 $SOBE->init();
849 $SOBE->main();
850 $SOBE->printContent();
851
852 ?>