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