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