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