Fixed bug #12117: Added use of flash messages to the Extension Manager
[Packages/TYPO3.CMS.git] / typo3 / mod / web / perm / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 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']))) . '">' .
352 '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/zoom.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', 1) . '" hspace="3" alt="" />' .
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) . '">' .
364 '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/list.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList', 1) . '" alt="" />' .
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 $this->doc->pushFlashMessage($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 = '<b>'.$LANG->getLL('1',1).'</b>: '.$LANG->getLL('1_t',1);
529 $legendText.= '<br /><b>'.$LANG->getLL('16',1).'</b>: '.$LANG->getLL('16_t',1);
530 $legendText.= '<br /><b>'.$LANG->getLL('2',1).'</b>: '.$LANG->getLL('2_t',1);
531 $legendText.= '<br /><b>'.$LANG->getLL('4',1).'</b>: '.$LANG->getLL('4_t',1);
532 $legendText.= '<br /><b>'.$LANG->getLL('8',1).'</b>: '.$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::getIconImage('pages',$this->pageinfo,$BACK_PATH,'align="top"');
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>
596 <td class="bgColor2" colspan="2">&nbsp;</td>
597 <td class="bgColor2"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
598 <td class="bgColor2" align="center"><b>'.$LANG->getLL('Owner',1).'</b></td>
599 <td class="bgColor2"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
600 <td class="bgColor2" align="center"><b>'.$LANG->getLL('Group',1).'</b></td>
601 <td class="bgColor2"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
602 <td class="bgColor2" align="center"><b>'.$LANG->getLL('Everybody',1).'</b></td>
603 <td class="bgColor2"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
604 <td class="bgColor2" align="center"><b>'.$LANG->getLL('EditLock',1).'</b></td>
605 </tr>
606 ';
607 } else {
608 $code.='
609 <tr>
610 <td class="bgColor2" colspan="2">&nbsp;</td>
611 <td class="bgColor2"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
612 <td class="bgColor2" align="center" nowrap="nowrap"><b>'.$LANG->getLL('User',1).':</b> '.$BE_USER->user['username'].'</td>
613 '.(!$BE_USER->isAdmin()?'<td class="bgColor2"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
614 <td class="bgColor2" align="center"><b>'.$LANG->getLL('EditLock',1).'</b></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).'"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/edit2.gif','width="11" height="12"').' border="0" title="'.$LANG->getLL('ch_permissions',1).'" align="top" alt="" /></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.'><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.'><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.'><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.'><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\');"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/recordlock_warning2.gif','width="22" height="16"').' title="'.$LANG->getLL('EditLock_descr',1).'" alt="Edit 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>
675 ';
676 } else {
677 $cells[]='
678 <td'.$bgCol.'><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>';
679
680 $bgCol = ($BE_USER->user['uid'] == $data['row']['perms_userid'] ? ' class="bgColor-20"' : $lE_bgCol);
681
682 // FIXME $owner undefined
683 $cells[]='
684 <td'.$bgCol.' nowrap="nowrap" align="center">'.($pageId ? $owner.SC_mod_web_perm_ajax::renderPermissions($BE_USER->calcPerms($data['row']), $pageId, 'user') : '').'</td>
685 '.(!$BE_USER->isAdmin()?'
686 <td'.$bgCol.'><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
687 <td'.$bgCol.' nowrap="nowrap">'.($data['row']['editlock']?'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/recordlock_warning2.gif','width="22" height="16"').' title="'.$LANG->getLL('EditLock_descr',1).'" alt="" />' : '').'</td>
688 ':'');
689 $bgCol = $lE_bgCol;
690 }
691
692 // Compile table row:
693 $code .= '
694 <tr>
695 '.implode('
696 ',$cells).'
697 </tr>';
698 }
699
700 // Wrap rows in table tags:
701 $code = '<table border="0" cellspacing="0" cellpadding="0" id="typo3-permissionList" width="99.5%">'.$code.'</table>';
702
703 // Adding the content as a section:
704 $this->content.=$this->doc->section('',$code);
705
706 // CSH for permissions setting
707 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'perm_module', $GLOBALS['BACK_PATH'], '<br />|');
708
709 // Creating legend table:
710 $legendText = '<b>'.$LANG->getLL('1',1).'</b>: '.$LANG->getLL('1_t',1);
711 $legendText.= '<br /><b>'.$LANG->getLL('16',1).'</b>: '.$LANG->getLL('16_t',1);
712 $legendText.= '<br /><b>'.$LANG->getLL('2',1).'</b>: '.$LANG->getLL('2_t',1);
713 $legendText.= '<br /><b>'.$LANG->getLL('4',1).'</b>: '.$LANG->getLL('4_t',1);
714 $legendText.= '<br /><b>'.$LANG->getLL('8',1).'</b>: '.$LANG->getLL('8_t',1);
715
716 $code='<table border="0" id="typo3-legendTable">
717 <tr>
718 <td valign="top"><img src="legend.gif" width="86" height="75" alt="" /></td>
719 <td valign="top" nowrap="nowrap">'.$legendText.'</td>
720 </tr>
721 </table>';
722 $code.='<div id="perm-legend">'.$LANG->getLL('def',1);
723 $code.='<br /><br /><span class="perm-allowed">*</span>: '.$LANG->getLL('A_Granted', 1);
724 $code.='<br /><span class="perm-denied">x</span>: '.$LANG->getLL('A_Denied', 1);
725 $code.='</div>';
726
727 // Adding section with legend code:
728 $this->content.=$this->doc->spacer(20);
729 $this->content.=$this->doc->section($LANG->getLL('Legend').':',$code,0,1);
730 }
731
732
733
734
735
736
737
738 /*****************************
739 *
740 * Helper functions
741 *
742 *****************************/
743
744 /**
745 * Print a checkbox for the edit-permission form
746 *
747 * @param string Checkbox name key
748 * @param integer Checkbox number index
749 * @return string HTML checkbox
750 */
751 public function printCheckBox($checkName, $num) {
752 $onclick = 'checkChange(\'check['.$checkName.']\', \'data[pages]['.$GLOBALS['SOBE']->id.']['.$checkName.']\')';
753 return '<input type="checkbox" name="check['.$checkName.']['.$num.']" onclick="'.htmlspecialchars($onclick).'" /><br />';
754 }
755
756
757 /**
758 * 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
759 *
760 * @param array Row array (from pages table)
761 * @param array First group data
762 * @return integer Integer: Combined permissions.
763 */
764 public function groupPerms($row, $firstGroup) {
765 if (is_array($row)) {
766 $out = intval($row['perms_everybody']);
767 if ($row['perms_groupid'] && $firstGroup['uid']==$row['perms_groupid']) {
768 $out |= intval($row['perms_group']);
769 }
770 return $out;
771 }
772 }
773
774 /**
775 * Finding tree and offer setting of values recursively.
776 *
777 * @param integer Page id.
778 * @param string Select clause
779 * @return string Select form element for recursive levels (if any levels are found)
780 */
781 public function getRecursiveSelect($id,$perms_clause) {
782
783 // Initialize tree object:
784 $tree = t3lib_div::makeInstance('t3lib_pageTree');
785 $tree->init('AND '.$perms_clause);
786 $tree->addField('perms_userid',1);
787 $tree->makeHTML=0;
788 $tree->setRecs = 1;
789
790 // Make tree:
791 $tree->getTree($id,$this->getLevels,'');
792
793 // If there are a hierarchy of page ids, then...
794 if ($GLOBALS['BE_USER']->user['uid'] && count($tree->orig_ids_hierarchy)) {
795
796 // Init:
797 $label_recur = $GLOBALS['LANG']->getLL('recursive');
798 $label_levels = $GLOBALS['LANG']->getLL('levels');
799 $label_pA = $GLOBALS['LANG']->getLL('pages_affected');
800 $theIdListArr=array();
801 $opts='
802 <option value=""></option>';
803
804 // Traverse the number of levels we want to allow recursive setting of permissions for:
805 for ($a=$this->getLevels;$a>0;$a--) {
806 if (is_array($tree->orig_ids_hierarchy[$a])) {
807 foreach($tree->orig_ids_hierarchy[$a] as $theId) {
808 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->user['uid']==$tree->recs[$theId]['perms_userid']) {
809 $theIdListArr[]=$theId;
810 }
811 }
812 $lKey = $this->getLevels-$a+1;
813 $opts.='
814 <option value="'.htmlspecialchars(implode(',',$theIdListArr)).'">'.
815 t3lib_div::deHSCentities(htmlspecialchars($label_recur.' '.$lKey.' '.$label_levels)).' ('.count($theIdListArr).' '.$label_pA.')'.
816 '</option>';
817 }
818 }
819
820 // Put the selector box together:
821 $theRecursiveSelect = '<br />
822 <select name="mirror[pages]['.$id.']">
823 '.$opts.'
824 </select>
825 <br /><br />';
826 } else {
827 $theRecursiveSelect = '';
828 }
829
830 // Return selector box element:
831 return $theRecursiveSelect;
832 }
833 }
834
835
836 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/web/perm/index.php']) {
837 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/web/perm/index.php']);
838 }
839
840
841
842
843 // Make instance:
844 $SOBE = t3lib_div::makeInstance('SC_mod_web_perm_index');
845 $SOBE->init();
846 $SOBE->main();
847 $SOBE->printContent();
848
849 ?>