This commit was manufactured by cvs2svn to create tag
[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 include (PATH_typo3.'sysext/lang/locallang_mod_web_perm.php');
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_pre($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 // Main function, branching out:
255 if (!$this->edit) {
256 $this->notEdit();
257 } else {
258 $this->doEdit();
259 }
260
261 // ShortCut
262 if ($BE_USER->mayMakeShortcut()) {
263 $this->content.=
264 $this->doc->spacer(20).
265 $this->doc->section('',$this->doc->makeShortcutIcon('id,edit,return_id',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']));
266 }
267 } else {
268 // If no access or if ID == zero
269 $this->content.=$this->doc->startPage($LANG->getLL('permissions'));
270 $this->content.=$this->doc->header($LANG->getLL('permissions'));
271 }
272
273 // Ending page:
274 $this->content.=$this->doc->endPage();
275 }
276
277 /**
278 * Outputting the accumulated content to screen
279 *
280 * @return void
281 */
282 function printContent() {
283
284 echo $this->content;
285 }
286
287
288
289
290
291
292
293
294
295
296 /*****************************
297 *
298 * Listing and Form rendering
299 *
300 *****************************/
301
302 /**
303 * Creating form for editing the permissions ($this->edit = true)
304 * (Adding content to internal content variable)
305 *
306 * @return void
307 */
308 function doEdit() {
309 global $BE_USER,$LANG;
310
311 // Get usernames and groupnames
312 $be_group_Array=t3lib_BEfunc::getListGroupNames('title,uid');
313 $groupArray=array_keys($be_group_Array);
314
315 $be_user_Array = t3lib_BEfunc::getUserNames();
316 if (!$GLOBALS['BE_USER']->isAdmin()) $be_user_Array = t3lib_BEfunc::blindUserNames($be_user_Array,$groupArray,1);
317 $be_group_Array_o = $be_group_Array = t3lib_BEfunc::getGroupNames();
318 if (!$GLOBALS['BE_USER']->isAdmin()) $be_group_Array = t3lib_BEfunc::blindGroupNames($be_group_Array_o,$groupArray,1);
319 $firstGroup = $groupArray[0] ? $be_group_Array[$groupArray[0]] : ''; // data of the first group, the user is member of
320
321
322 // Owner selector:
323 $options='';
324 $userset=0; // flag: is set if the page-userid equals one from the user-list
325 foreach($be_user_Array as $uid => $row) {
326 if ($uid==$this->pageinfo['perms_userid']) {
327 $userset = 1;
328 $selected=' selected="selected"';
329 } else {$selected='';}
330 $options.='
331 <option value="'.$uid.'"'.$selected.'>'.htmlspecialchars($row['username']).'</option>';
332 }
333 $options='
334 <option value="0"></option>'.$options;
335 $selector='
336 <select name="data[pages]['.$this->id.'][perms_userid]">
337 '.$options.'
338 </select>';
339
340 $this->content.=$this->doc->section($LANG->getLL('Owner').':',$selector);
341
342
343 // Group selector:
344 $options='';
345 $userset=0;
346 foreach($be_group_Array as $uid => $row) {
347 if ($uid==$this->pageinfo['perms_groupid']) {
348 $userset = 1;
349 $selected=' selected="selected"';
350 } else {$selected='';}
351 $options.='
352 <option value="'.$uid.'"'.$selected.'>'.htmlspecialchars($row['title']).'</option>';
353 }
354 if (!$userset && $this->pageinfo['perms_groupid']) { // If the group was not set AND there is a group for the page
355 $options='
356 <option value="'.$this->pageinfo['perms_groupid'].'" selected="selected">'.
357 htmlspecialchars($be_group_Array_o[$this->pageinfo['perms_groupid']]['title']).
358 '</option>'.
359 $options;
360 }
361 $options='
362 <option value="0"></option>'.$options;
363 $selector='
364 <select name="data[pages]['.$this->id.'][perms_groupid]">
365 '.$options.'
366 </select>';
367
368 $this->content.=$this->doc->divider(5);
369 $this->content.=$this->doc->section($LANG->getLL('Group').':',$selector);
370
371 // Permissions checkbox matrix:
372 $code='
373 <table border="0" cellspacing="2" cellpadding="0" id="typo3-permissionMatrix">
374 <tr>
375 <td></td>
376 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('1',1)).'</td>
377 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('16',1)).'</td>
378 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('2',1)).'</td>
379 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('4',1)).'</td>
380 <td class="bgColor2">'.str_replace(' ','<br />',$LANG->getLL('8',1)).'</td>
381 </tr>
382 <tr>
383 <td align="right" class="bgColor2">'.$LANG->getLL('Owner',1).'</td>
384 <td class="bgColor-20">'.$this->printCheckBox('perms_user',1).'</td>
385 <td class="bgColor-20">'.$this->printCheckBox('perms_user',5).'</td>
386 <td class="bgColor-20">'.$this->printCheckBox('perms_user',2).'</td>
387 <td class="bgColor-20">'.$this->printCheckBox('perms_user',3).'</td>
388 <td class="bgColor-20">'.$this->printCheckBox('perms_user',4).'</td>
389 </tr>
390 <tr>
391 <td align="right" class="bgColor2">'.$LANG->getLL('Group',1).'</td>
392 <td class="bgColor-20">'.$this->printCheckBox('perms_group',1).'</td>
393 <td class="bgColor-20">'.$this->printCheckBox('perms_group',5).'</td>
394 <td class="bgColor-20">'.$this->printCheckBox('perms_group',2).'</td>
395 <td class="bgColor-20">'.$this->printCheckBox('perms_group',3).'</td>
396 <td class="bgColor-20">'.$this->printCheckBox('perms_group',4).'</td>
397 </tr>
398 <tr>
399 <td align="right" class="bgColor2">'.$LANG->getLL('Everybody',1).'</td>
400 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',1).'</td>
401 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',5).'</td>
402 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',2).'</td>
403 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',3).'</td>
404 <td class="bgColor-20">'.$this->printCheckBox('perms_everybody',4).'</td>
405 </tr>
406 </table>
407 <br />
408
409 <input type="hidden" name="data[pages]['.$this->id.'][perms_user]" value="'.$this->pageinfo['perms_user'].'" />
410 <input type="hidden" name="data[pages]['.$this->id.'][perms_group]" value="'.$this->pageinfo['perms_group'].'" />
411 <input type="hidden" name="data[pages]['.$this->id.'][perms_everybody]" value="'.$this->pageinfo['perms_everybody'].'" />
412 '.$this->getRecursiveSelect($this->id,$this->perms_clause).'
413 <input type="submit" name="submit" value="'.$LANG->getLL('Save',1).'" />'.
414 '<input type="submit" value="'.$LANG->getLL('Abort',1).'" onclick="'.htmlspecialchars('jumpToUrl(\'index.php?id='.$this->id.'\'); return false;').'" />
415 <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).'" />
416 ';
417
418 // Adding section with the permission setting matrix:
419 $this->content.=$this->doc->divider(5);
420 $this->content.=$this->doc->section($LANG->getLL('permissions').':',$code);
421
422 // Adding help text:
423 if ($BE_USER->uc['helpText']) {
424 $this->content.=$this->doc->divider(20);
425 $legendText = '<b>'.$LANG->getLL('1',1).'</b>: '.$LANG->getLL('1_t',1);
426 $legendText.= '<br /><b>'.$LANG->getLL('16',1).'</b>: '.$LANG->getLL('16_t',1);
427 $legendText.= '<br /><b>'.$LANG->getLL('2',1).'</b>: '.$LANG->getLL('2_t',1);
428 $legendText.= '<br /><b>'.$LANG->getLL('4',1).'</b>: '.$LANG->getLL('4_t',1);
429 $legendText.= '<br /><b>'.$LANG->getLL('8',1).'</b>: '.$LANG->getLL('8_t',1);
430
431 $code=$legendText.'<br /><br />'.$LANG->getLL('def',1);
432 $this->content.=$this->doc->section($LANG->getLL('Legend',1).':',$code);
433 }
434 }
435
436 /**
437 * Showing the permissions in a tree ($this->edit = false)
438 * (Adding content to internal content variable)
439 *
440 * @return void
441 */
442 function notEdit() {
443 global $BE_USER,$LANG,$BACK_PATH;
444
445 // 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
446 $groupArray = $BE_USER->userGroupsUID;
447 $be_user_Array = t3lib_BEfunc::getUserNames();
448 if (!$GLOBALS['BE_USER']->isAdmin()) $be_user_Array = t3lib_BEfunc::blindUserNames($be_user_Array,$groupArray,0);
449 $be_group_Array = t3lib_BEfunc::getGroupNames();
450 if (!$GLOBALS['BE_USER']->isAdmin()) $be_group_Array = t3lib_BEfunc::blindGroupNames($be_group_Array,$groupArray,0);
451
452 // Length of strings:
453 $tLen= ($this->MOD_SETTINGS['mode']=='perms' ? 20 : 30);
454
455
456 // Selector for depth:
457 $code.=$LANG->getLL('Depth').': ';
458 $code.=t3lib_BEfunc::getFuncMenu($this->id,'SET[depth]',$this->MOD_SETTINGS['depth'],$this->MOD_MENU['depth']);
459 $this->content.=$this->doc->section('',$code);
460 $this->content.=$this->doc->spacer(5);
461
462 // Initialize tree object:
463 $tree = t3lib_div::makeInstance('t3lib_pageTree');
464 $tree->init('AND '.$this->perms_clause);
465
466 $tree->addField('perms_user',1);
467 $tree->addField('perms_group',1);
468 $tree->addField('perms_everybody',1);
469 $tree->addField('perms_userid',1);
470 $tree->addField('perms_groupid',1);
471 $tree->addField('hidden');
472 $tree->addField('fe_group');
473 $tree->addField('starttime');
474 $tree->addField('endtime');
475
476 // Creating top icon; the current page
477 $HTML=t3lib_iconWorks::getIconImage('pages',$this->pageinfo,$BACK_PATH,'align="top"');
478 $tree->tree[]=Array('row'=>$this->pageinfo,'HTML'=>$HTML);
479
480 // Create the tree from $this->id:
481 $tree->getTree($this->id,$this->MOD_SETTINGS['depth'],'');
482
483 // Make header of table:
484 $code='';
485 if ($this->MOD_SETTINGS['mode']=='perms') {
486 $code.='
487 <tr>
488 <td class="bgColor2" colspan="2">&nbsp;</td>
489 <td class="bgColor2"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
490 <td class="bgColor2" align="center"><b>'.$LANG->getLL('Owner',1).'</b></td>
491 <td class="bgColor2"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
492 <td class="bgColor2" align="center"><b>'.$LANG->getLL('Group',1).'</b></td>
493 <td class="bgColor2"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
494 <td class="bgColor2" align="center"><b>'.$LANG->getLL('Everybody',1).'</b></td>
495 </tr>
496 ';
497 } else {
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" nowrap="nowrap"><b>'.$LANG->getLL('User',1).':</b> '.$BE_USER->user['username'].'</td>
503 </tr>';
504 }
505
506 // Traverse tree:
507 foreach($tree->tree as $data) {
508 $cells=array();
509
510 // Background colors:
511 if ($this->lastEdited==$data['row']['uid']) {$bgCol = ' class="bgColor-20"';} else {$bgCol = '';}
512 $lE_bgCol = $bgCol;
513
514 // User/Group names:
515 $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>' : '');
516 $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>' : '');
517 $groupN=t3lib_div::fixed_lgd($groupN,20);
518
519 // Seeing if editing of permissions are allowed for that page:
520 $editPermsAllowed=($data['row']['perms_userid']==$BE_USER->user['uid'] || $BE_USER->isAdmin());
521
522 // First column:
523 $cells[]='
524 <td align="left" nowrap="nowrap"'.$bgCol.'>'.$data['HTML'].htmlspecialchars(t3lib_div::fixed_lgd($data['row']['title'],$tLen)).'&nbsp;</td>';
525
526 // "Edit permissions" -icon
527 if ($editPermsAllowed && $data['row']['uid']) {
528 $aHref = 'index.php?mode='.$this->MOD_SETTINGS['mode'].'&depth='.$this->MOD_SETTINGS['depth'].'&id='.$data['row']['uid'].'&return_id='.$this->id.'&edit=1';
529 $cells[]='
530 <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>';
531 } else {
532 $cells[]='
533 <td'.$bgCol.'></td>';
534 }
535
536 // Rest of columns (depending on mode)
537 if ($this->MOD_SETTINGS['mode']=='perms') {
538 $cells[]='
539 <td'.$bgCol.'><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
540 <td'.$bgCol.' nowrap="nowrap">'.($data['row']['uid']?$this->printPerms($data['row']['perms_user']).' '.$userN:'').'</td>
541
542 <td'.$bgCol.'><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
543 <td'.$bgCol.' nowrap="nowrap">'.($data['row']['uid']?$this->printPerms($data['row']['perms_group']).' '.$groupN:'').'</td>
544
545 <td'.$bgCol.'><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>
546 <td'.$bgCol.' nowrap="nowrap">'.($data['row']['uid']?' '.$this->printPerms($data['row']['perms_everybody']):'').'</td>
547 ';
548 } else {
549 $cells[]='
550 <td'.$bgCol.'><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/line.gif','width="5" height="16"').' alt="" /></td>';
551
552 if ($BE_USER->user['uid']==$data['row']['perms_userid']) {$bgCol = ' class="bgColor-20"';} else {$bgCol = $lE_bgCol;}
553 $cells[]='
554 <td'.$bgCol.' nowrap="nowrap" align="center">'.($data['row']['uid']?$owner.$this->printPerms($BE_USER->calcPerms($data['row'])):'').'</td>';
555 $bgCol = $lE_bgCol;
556 }
557
558 // Compile table row:
559 $code.='
560 <tr>
561 '.implode('
562 ',$cells).'
563 </tr>';
564 }
565
566 // Wrap rows in table tags:
567 $code='<table border="0" cellspacing="0" cellpadding="0" id="typo3-permissionList">'.$code.'</table>';
568
569 // Adding the content as a section:
570 $this->content.=$this->doc->section('',$code);
571
572
573 // Creating legend table:
574 $legendText = '<b>'.$LANG->getLL('1',1).'</b>: '.$LANG->getLL('1_t',1);
575 $legendText.= '<br /><b>'.$LANG->getLL('16',1).'</b>: '.$LANG->getLL('16_t',1);
576 $legendText.= '<br /><b>'.$LANG->getLL('2',1).'</b>: '.$LANG->getLL('2_t',1);
577 $legendText.= '<br /><b>'.$LANG->getLL('4',1).'</b>: '.$LANG->getLL('4_t',1);
578 $legendText.= '<br /><b>'.$LANG->getLL('8',1).'</b>: '.$LANG->getLL('8_t',1);
579
580 $code='<table border="0" id="typo3-legendTable">
581 <tr>
582 <td valign="top"><img src="legend.gif" width="86" height="75" alt="" /></td>
583 <td valign="top" nowrap="nowrap">'.$legendText.'</td>
584 </tr>
585 </table>';
586 $code.='<br />'.$LANG->getLL('def',1);
587 $code.='<br /><br /><span class="perm-allowed">*</span>: '.$LANG->getLL('A_Granted',1);
588 $code.='<br /><span class="perm-denied">x</span>: '.$LANG->getLL('A_Denied',1);
589
590 // Adding section with legend code:
591 $this->content.=$this->doc->spacer(20);
592 $this->content.=$this->doc->section($LANG->getLL('Legend').':',$code,0,1);
593 }
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608 /*****************************
609 *
610 * Helper functions
611 *
612 *****************************/
613
614 /**
615 * Print a checkbox for the edit-permission form
616 *
617 * @param string Checkbox name key
618 * @param integer Checkbox number index
619 * @return string HTML checkbox
620 */
621 function printCheckBox($checkName,$num) {
622 $onClick = 'checkChange(\'check['.$checkName.']\', \'data[pages]['.$GLOBALS['SOBE']->id.']['.$checkName.']\')';
623 return '<input type="checkbox" name="check['.$checkName.']['.$num.']" onclick="'.htmlspecialchars($onClick).'" /><br />';
624 }
625
626 /**
627 * Print a set of permissions
628 *
629 * @param integer Permission integer (bits)
630 * @return string HTML marked up x/* indications.
631 */
632 function printPerms($int) {
633 $str='';
634 $str.= (($int&1)?'*':'<span class="perm-denied">x</span>');
635 $str.= (($int&16)?'*':'<span class="perm-denied">x</span>');
636 $str.= (($int&2)?'*':'<span class="perm-denied">x</span>');
637 $str.= (($int&4)?'*':'<span class="perm-denied">x</span>');
638 $str.= (($int&8)?'*':'<span class="perm-denied">x</span>');
639
640 return '<span class="perm-allowed">'.$str.'</span>';
641 }
642
643 /**
644 * 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
645 *
646 * @param array Row array (from pages table)
647 * @param array First group data
648 * @return integer Integer: Combined permissions.
649 */
650 function groupPerms($row,$firstGroup) {
651 if (is_array($row)) {
652 $out=intval($row['perms_everybody']);
653 if ($row['perms_groupid'] && $firstGroup['uid']==$row['perms_groupid']) {
654 $out|= intval($row['perms_group']);
655 }
656 return $out;
657 }
658 }
659
660 /**
661 * Finding tree and offer setting of values recursively.
662 *
663 * @param integer Page id.
664 * @param string Select clause
665 * @return string Select form element for recursive levels (if any levels are found)
666 */
667 function getRecursiveSelect($id,$perms_clause) {
668
669 // Initialize tree object:
670 $tree = t3lib_div::makeInstance('t3lib_pageTree');
671 $tree->init('AND '.$perms_clause);
672 $tree->addField('perms_userid',1);
673 $tree->makeHTML=0;
674 $tree->setRecs = 1;
675
676 // Make tree:
677 $tree->getTree($id,$this->getLevels,'');
678
679 // If there are a hierarchy of page ids, then...
680 if ($GLOBALS['BE_USER']->user['uid'] && count($tree->ids_hierarchy)) {
681
682 // Init:
683 $label_recur = $GLOBALS['LANG']->getLL('recursive');
684 $label_levels = $GLOBALS['LANG']->getLL('levels');
685 $label_pA = $GLOBALS['LANG']->getLL('pages_affected');
686 $theIdListArr=array();
687 $opts='
688 <option value=""></option>';
689
690 // Traverse the number of levels we want to allow recursive setting of permissions for:
691 for ($a=$this->getLevels;$a>0;$a--) {
692 if (is_array($tree->ids_hierarchy[$a])) {
693 foreach($tree->ids_hierarchy[$a] as $theId) {
694 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->user['uid']==$tree->recs[$theId]['perms_userid']) {
695 $theIdListArr[]=$theId;
696 }
697 }
698 $lKey = $this->getLevels-$a+1;
699 $opts.='
700 <option value="'.htmlspecialchars(implode(',',$theIdListArr)).'">'.
701 t3lib_div::deHSCentities(htmlspecialchars($label_recur.' '.$lKey.' '.$label_levels)).' ('.count($theIdListArr).' '.$label_pA.')'.
702 '</option>';
703 }
704 }
705
706 // Put the selector box together:
707 $theRecursiveSelect = '<br />
708 <select name="mirror[pages]['.$id.']">
709 '.$opts.'
710 </select>
711
712 <br /><br />';
713 } else {
714 $theRecursiveSelect = '';
715 }
716
717 // Return selector box element:
718 return $theRecursiveSelect;
719 }
720 }
721
722 // Include extension?
723 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/web/perm/index.php']) {
724 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/web/perm/index.php']);
725 }
726
727
728
729
730
731
732
733
734
735
736
737
738 // Make instance:
739 $SOBE = t3lib_div::makeInstance('SC_mod_web_perm_index');
740 $SOBE->init();
741 $SOBE->main();
742 $SOBE->printContent();
743
744 if ($TYPO3_CONF_VARS['BE']['compressionLevel']) {
745 new gzip_encode($TYPO3_CONF_VARS['BE']['compressionLevel']);
746 }
747 ?>