e1ed00b0a834ee09aca2de78ef3bb0e76db806f1
[Packages/TYPO3.CMS.git] / typo3 / sysext / perm / Classes / Controller / PermissionModuleController.php
1 <?php
2 namespace TYPO3\CMS\Perm\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31 use TYPO3\CMS\Backend\Utility\BackendUtility;
32 use TYPO3\CMS\Backend\Utility\IconUtility;
33
34 /**
35 * Module: Permission setting
36 *
37 * Script Class for the Web > Access module
38 * This module lets you view and change permissions for pages.
39 *
40 * Variables:
41 * $this->MOD_SETTINGS['depth']: int 1-3: decides the depth of the list
42 *
43 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
44 * @author Andreas Kundoch <typo3@mehrwert.de>
45 */
46 class PermissionModuleController {
47
48 /**
49 * Number of levels to enable recursive settings for
50 *
51 * @var integer
52 */
53 public $getLevels = 10;
54
55 /**
56 * Module config
57 * Internal static
58 *
59 * @var array
60 */
61 protected $MCONF = array();
62
63 /**
64 * Document Template Object
65 *
66 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
67 */
68 public $doc;
69
70 /**
71 * Content accumulation
72 *
73 * @var string
74 */
75 public $content;
76
77 /**
78 * Module menu
79 *
80 * @var array
81 */
82 public $MOD_MENU = array();
83
84 /**
85 * Module settings, cleansed.
86 *
87 * @var aray
88 */
89 public $MOD_SETTINGS = array();
90
91 /**
92 * Page select permissions
93 *
94 * @var string
95 */
96 public $perms_clause;
97
98 /**
99 * Current page record
100 *
101 * @var array
102 */
103 public $pageinfo;
104
105 /**
106 * Background color 1
107 *
108 * @var string
109 */
110 public $color;
111
112 /**
113 * Background color 2
114 *
115 * @var string
116 */
117 public $color2;
118
119 /**
120 * Background color 3
121 *
122 * @var string
123 */
124 public $color3;
125
126 /**
127 * Set internally if the current user either OWNS the page OR is admin user!
128 *
129 * @var boolean
130 */
131 public $editingAllowed;
132
133 /**
134 * Internal, static: GPvars: Page id.
135 *
136 * @var integer
137 */
138 public $id;
139
140 /**
141 * If set, editing of the page permissions will occur (showing the editing screen). Notice:
142 * This value is evaluated against permissions and so it will change internally!
143 *
144 * @var boolean
145 */
146 public $edit;
147
148 /**
149 * ID to return to after editing.
150 *
151 * @var integer
152 */
153 public $return_id;
154
155 /**
156 * Id of the page which was just edited.
157 *
158 * @var integer
159 */
160 public $lastEdited;
161
162 /**
163 * Initialization of the class
164 *
165 * @return void
166 */
167 public function init() {
168 // Setting GPvars:
169 $this->id = (int)GeneralUtility::_GP('id');
170 $this->edit = GeneralUtility::_GP('edit');
171 $this->return_id = GeneralUtility::_GP('return_id');
172 $this->lastEdited = GeneralUtility::_GP('lastEdited');
173 // Module name;
174 $this->MCONF = $GLOBALS['MCONF'];
175 // Page select clause:
176 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
177 // Initializing document template object:
178 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
179 $this->doc->backPath = $GLOBALS['BACK_PATH'];
180 $this->doc->setModuleTemplate('EXT:perm/Resources/Private/Templates/perm.html');
181 $this->doc->form = '<form action="' . $GLOBALS['BACK_PATH'] . 'tce_db.php" method="post" name="editform">';
182 $this->doc->loadJavascriptLib('js/jsfunc.updateform.js');
183 $this->doc->getPageRenderer()->loadPrototype();
184 $this->doc->loadJavascriptLib(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('perm') . 'mod1/perm.js');
185 // Setting up the context sensitive menu:
186 $this->doc->getContextMenuCode();
187 // Set up menus:
188 $this->menuConfig();
189 }
190
191 /**
192 * Configuration of the menu and initialization of ->MOD_SETTINGS
193 *
194 * @return void
195 */
196 public function menuConfig() {
197 $level = $GLOBALS['LANG']->getLL('levels');
198 $this->MOD_MENU = array(
199 'depth' => array(
200 1 => '1 ' . $level,
201 2 => '2 ' . $level,
202 3 => '3 ' . $level,
203 4 => '4 ' . $level,
204 10 => '10 ' . $level
205 )
206 );
207 // Clean up settings:
208 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name']);
209 }
210
211 /**
212 * Main function, creating the content for the access editing forms/listings
213 *
214 * @return void
215 */
216 public function main() {
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 = BackendUtility::readPageAccess($this->id, $this->perms_clause);
220 $access = is_array($this->pageinfo);
221 // Checking access:
222 if ($this->id && $access || $GLOBALS['BE_USER']->isAdmin() && !$this->id) {
223 if ($GLOBALS['BE_USER']->isAdmin() && !$this->id) {
224 $this->pageinfo = array('title' => '[root-level]', 'uid' => 0, 'pid' => 0);
225 }
226 // This decides if the editform can and will be drawn:
227 $this->editingAllowed = $this->pageinfo['perms_userid'] == $GLOBALS['BE_USER']->user['uid'] || $GLOBALS['BE_USER']->isAdmin();
228 $this->edit = $this->edit && $this->editingAllowed;
229 // If $this->edit then these functions are called in the end of the page...
230 if ($this->edit) {
231 $this->doc->postCode .= $this->doc->wrapScriptTags('
232 setCheck("check[perms_user]", "data[pages][' . $this->id . '][perms_user]");
233 setCheck("check[perms_group]", "data[pages][' . $this->id . '][perms_group]");
234 setCheck("check[perms_everybody]", "data[pages][' . $this->id . '][perms_everybody]");
235 ');
236 }
237 // Draw the HTML page header.
238 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('permissions') . ($this->edit ? ': ' . $GLOBALS['LANG']->getLL('Edit') : ''));
239 $this->content .= $this->doc->spacer(5);
240 $vContent = $this->doc->getVersionSelector($this->id, 1);
241 if ($vContent) {
242 $this->content .= $this->doc->section('', $vContent);
243 }
244 // Main function, branching out:
245 if (!$this->edit) {
246 $this->notEdit();
247 } else {
248 $this->doEdit();
249 }
250 $docHeaderButtons = $this->getButtons();
251 $markers['CSH'] = $this->docHeaderButtons['csh'];
252 $markers['FUNC_MENU'] = BackendUtility::getFuncMenu($this->id, 'SET[mode]', $this->MOD_SETTINGS['mode'], $this->MOD_MENU['mode']);
253 $markers['CONTENT'] = $this->content;
254 // Build the <body> for the module
255 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
256 } else {
257 // If no access or if ID == zero
258 $this->content = $this->doc->header($GLOBALS['LANG']->getLL('permissions'));
259 }
260 // Renders the module page
261 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('permissions'), $this->content);
262 }
263
264 /**
265 * Outputting the accumulated content to screen
266 *
267 * @return void
268 */
269 public function printContent() {
270 $this->content = $this->doc->insertStylesAndJS($this->content);
271 echo $this->content;
272 }
273
274 /**
275 * Create the panel of buttons for submitting the form or otherwise perform operations.
276 *
277 * @return array all available buttons as an assoc. array
278 */
279 protected function getButtons() {
280 $buttons = array(
281 'csh' => '',
282 'view' => '',
283 'shortcut' => ''
284 );
285 // CSH
286 $buttons['csh'] = BackendUtility::cshItem('_MOD_web_info', '', $GLOBALS['BACK_PATH'], '', TRUE);
287 // View page
288 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewonclick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
289 // Shortcut
290 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
291 $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']);
292 }
293 return $buttons;
294 }
295
296 /*****************************
297 *
298 * Listing and Form rendering
299 *
300 *****************************/
301 /**
302 * Creating form for editing the permissions ($this->edit = TRUE)
303 * (Adding content to internal content variable)
304 *
305 * @return void
306 */
307 public function doEdit() {
308 if ($GLOBALS['BE_USER']->workspace != 0) {
309 // Adding section with the permission setting matrix:
310 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('WorkspaceWarningText'), $GLOBALS['LANG']->getLL('WorkspaceWarning'), \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
311 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
312 $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
313 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
314 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
315 $defaultFlashMessageQueue->enqueue($flashMessage);
316 }
317 // Get usernames and groupnames
318 $beGroupArray = BackendUtility::getListGroupNames('title,uid');
319 $beGroupKeys = array_keys($beGroupArray);
320 $beUserArray = BackendUtility::getUserNames();
321 if (!$GLOBALS['BE_USER']->isAdmin()) {
322 $beUserArray = BackendUtility::blindUserNames($beUserArray, $beGroupKeys, 1);
323 }
324 $beGroupArray_o = ($beGroupArray = BackendUtility::getGroupNames());
325 if (!$GLOBALS['BE_USER']->isAdmin()) {
326 $beGroupArray = BackendUtility::blindGroupNames($beGroupArray_o, $beGroupKeys, 1);
327 }
328
329 // Owner selector:
330 $options = '';
331 // flag: is set if the page-userid equals one from the user-list
332 $userset = 0;
333 foreach ($beUserArray as $uid => $row) {
334 if ($uid == $this->pageinfo['perms_userid']) {
335 $userset = 1;
336 $selected = ' selected="selected"';
337 } else {
338 $selected = '';
339 }
340 $options .= '
341 <option value="' . $uid . '"' . $selected . '>' . htmlspecialchars($row['username']) . '</option>';
342 }
343 $options = '
344 <option value="0"></option>' . $options;
345 $selector = '
346 <select name="data[pages][' . $this->id . '][perms_userid]">
347 ' . $options . '
348 </select>';
349 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('Owner') . ':', $selector);
350 // Group selector:
351 $options = '';
352 $userset = 0;
353 foreach ($beGroupArray as $uid => $row) {
354 if ($uid == $this->pageinfo['perms_groupid']) {
355 $userset = 1;
356 $selected = ' selected="selected"';
357 } else {
358 $selected = '';
359 }
360 $options .= '
361 <option value="' . $uid . '"' . $selected . '>' . htmlspecialchars($row['title']) . '</option>';
362 }
363 // If the group was not set AND there is a group for the page
364 if (!$userset && $this->pageinfo['perms_groupid']) {
365 $options = '
366 <option value="' . $this->pageinfo['perms_groupid'] . '" selected="selected">' . htmlspecialchars($beGroupArray_o[$this->pageinfo['perms_groupid']]['title']) . '</option>' . $options;
367 }
368 $options = '
369 <option value="0"></option>' . $options;
370 $selector = '
371 <select name="data[pages][' . $this->id . '][perms_groupid]">
372 ' . $options . '
373 </select>';
374 $this->content .= $this->doc->divider(5);
375 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('Group') . ':', $selector);
376 // Permissions checkbox matrix:
377 $code = '
378 <table border="0" cellspacing="2" cellpadding="0" id="typo3-permissionMatrix">
379 <tr>
380 <td></td>
381 <td class="bgColor2">' . str_replace(' ', '<br />', $GLOBALS['LANG']->getLL('1', TRUE)) . '</td>
382 <td class="bgColor2">' . str_replace(' ', '<br />', $GLOBALS['LANG']->getLL('16', TRUE)) . '</td>
383 <td class="bgColor2">' . str_replace(' ', '<br />', $GLOBALS['LANG']->getLL('2', TRUE)) . '</td>
384 <td class="bgColor2">' . str_replace(' ', '<br />', $GLOBALS['LANG']->getLL('4', TRUE)) . '</td>
385 <td class="bgColor2">' . str_replace(' ', '<br />', $GLOBALS['LANG']->getLL('8', TRUE)) . '</td>
386 </tr>
387 <tr>
388 <td align="right" class="bgColor2">' . $GLOBALS['LANG']->getLL('Owner', TRUE) . '</td>
389 <td class="bgColor-20">' . $this->printCheckBox('perms_user', 1) . '</td>
390 <td class="bgColor-20">' . $this->printCheckBox('perms_user', 5) . '</td>
391 <td class="bgColor-20">' . $this->printCheckBox('perms_user', 2) . '</td>
392 <td class="bgColor-20">' . $this->printCheckBox('perms_user', 3) . '</td>
393 <td class="bgColor-20">' . $this->printCheckBox('perms_user', 4) . '</td>
394 </tr>
395 <tr>
396 <td align="right" class="bgColor2">' . $GLOBALS['LANG']->getLL('Group', TRUE) . '</td>
397 <td class="bgColor-20">' . $this->printCheckBox('perms_group', 1) . '</td>
398 <td class="bgColor-20">' . $this->printCheckBox('perms_group', 5) . '</td>
399 <td class="bgColor-20">' . $this->printCheckBox('perms_group', 2) . '</td>
400 <td class="bgColor-20">' . $this->printCheckBox('perms_group', 3) . '</td>
401 <td class="bgColor-20">' . $this->printCheckBox('perms_group', 4) . '</td>
402 </tr>
403 <tr>
404 <td align="right" class="bgColor2">' . $GLOBALS['LANG']->getLL('Everybody', TRUE) . '</td>
405 <td class="bgColor-20">' . $this->printCheckBox('perms_everybody', 1) . '</td>
406 <td class="bgColor-20">' . $this->printCheckBox('perms_everybody', 5) . '</td>
407 <td class="bgColor-20">' . $this->printCheckBox('perms_everybody', 2) . '</td>
408 <td class="bgColor-20">' . $this->printCheckBox('perms_everybody', 3) . '</td>
409 <td class="bgColor-20">' . $this->printCheckBox('perms_everybody', 4) . '</td>
410 </tr>
411 </table>
412 <br />
413
414 <input type="hidden" name="data[pages][' . $this->id . '][perms_user]" value="' . $this->pageinfo['perms_user'] . '" />
415 <input type="hidden" name="data[pages][' . $this->id . '][perms_group]" value="' . $this->pageinfo['perms_group'] . '" />
416 <input type="hidden" name="data[pages][' . $this->id . '][perms_everybody]" value="' . $this->pageinfo['perms_everybody'] . '" />
417 ' . $this->getRecursiveSelect($this->id, $this->perms_clause) . '
418 <input type="submit" name="submit" value="' . $GLOBALS['LANG']->getLL('Save', TRUE) . '" />' . '<input type="submit" value="' . $GLOBALS['LANG']->getLL('Abort', TRUE) . '" onclick="' . htmlspecialchars(('jumpToUrl(' . GeneralUtility::quoteJSvalue((BackendUtility::getModuleUrl('web_perm') . '&id=' . $this->id), TRUE) . '); return false;')) . '" />
419 <input type="hidden" name="redirect" value="' . htmlspecialchars((BackendUtility::getModuleUrl('web_perm') . '&mode=' . $this->MOD_SETTINGS['mode'] . '&depth=' . $this->MOD_SETTINGS['depth'] . '&id=' . (int)$this->return_id . '&lastEdited=' . $this->id)) . '" />
420 ' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction');
421 // Adding section with the permission setting matrix:
422 $this->content .= $this->doc->divider(5);
423 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('permissions') . ':', $code);
424 // CSH for permissions setting
425 $this->content .= BackendUtility::cshItem('xMOD_csh_corebe', 'perm_module_setting', $GLOBALS['BACK_PATH'], '<br /><br />');
426 // Adding help text:
427 if ($GLOBALS['BE_USER']->uc['helpText']) {
428 $this->content .= $this->doc->divider(20);
429 $legendText = '<strong>' . $GLOBALS['LANG']->getLL('1', TRUE) . '</strong>: ' . $GLOBALS['LANG']->getLL('1_t', TRUE);
430 $legendText .= '<br /><strong>' . $GLOBALS['LANG']->getLL('16', TRUE) . '</strong>: ' . $GLOBALS['LANG']->getLL('16_t', TRUE);
431 $legendText .= '<br /><strong>' . $GLOBALS['LANG']->getLL('2', TRUE) . '</strong>: ' . $GLOBALS['LANG']->getLL('2_t', TRUE);
432 $legendText .= '<br /><strong>' . $GLOBALS['LANG']->getLL('4', TRUE) . '</strong>: ' . $GLOBALS['LANG']->getLL('4_t', TRUE);
433 $legendText .= '<br /><strong>' . $GLOBALS['LANG']->getLL('8', TRUE) . '</strong>: ' . $GLOBALS['LANG']->getLL('8_t', TRUE);
434 $code = $legendText . '<br /><br />' . $GLOBALS['LANG']->getLL('def', TRUE);
435 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('Legend', TRUE) . ':', $code);
436 }
437 }
438
439 /**
440 * Showing the permissions in a tree ($this->edit = FALSE)
441 * (Adding content to internal content variable)
442 *
443 * @return void
444 */
445 public function notEdit() {
446 // 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
447 $beGroupKeys = $GLOBALS['BE_USER']->userGroupsUID;
448 $beUserArray = BackendUtility::getUserNames();
449 if (!$GLOBALS['BE_USER']->isAdmin()) {
450 $beUserArray = BackendUtility::blindUserNames($beUserArray, $beGroupKeys, 0);
451 }
452 $beGroupArray = BackendUtility::getGroupNames();
453 if (!$GLOBALS['BE_USER']->isAdmin()) {
454 $beGroupArray = BackendUtility::blindGroupNames($beGroupArray, $beGroupKeys, 0);
455 }
456 // Length of strings:
457 $tLen = 20;
458 // Selector for depth:
459 $code = $GLOBALS['LANG']->getLL('Depth') . ': ';
460 $code .= BackendUtility::getFuncMenu($this->id, 'SET[depth]', $this->MOD_SETTINGS['depth'], $this->MOD_MENU['depth']);
461 $this->content .= $this->doc->section('', $code);
462 $this->content .= $this->doc->spacer(5);
463 // Initialize tree object:
464 $tree = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
465 $tree->init('AND ' . $this->perms_clause);
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 $tree->addField('editlock');
476 // Creating top icon; the current page
477 $HTML = IconUtility::getSpriteIconForRecord('pages', $this->pageinfo);
478 $tree->tree[] = array('row' => $this->pageinfo, 'HTML' => $HTML);
479 // Create the tree from $this->id:
480 $tree->getTree($this->id, $this->MOD_SETTINGS['depth'], '');
481 // Make header of table:
482 $code = '
483 <tr class="t3-row-header">
484 <td colspan="2">&nbsp;</td>
485 <td><img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
486 <td>' . $GLOBALS['LANG']->getLL('Owner', TRUE) . '</td>
487 <td><img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
488 <td align="center">' . $GLOBALS['LANG']->getLL('Group', TRUE) . '</td>
489 <td><img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
490 <td align="center">' . $GLOBALS['LANG']->getLL('Everybody', TRUE) . '</td>
491 <td><img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
492 <td align="center">' . $GLOBALS['LANG']->getLL('EditLock', TRUE) . '</td>
493 </tr>
494 ';
495 // Traverse tree:
496 foreach ($tree->tree as $data) {
497 $cells = array();
498 $pageId = $data['row']['uid'];
499 // Background colors:
500 $bgCol = $this->lastEdited == $pageId ? ' class="bgColor-20"' : '';
501 $lE_bgCol = $bgCol;
502 // User/Group names:
503 $userName = $beUserArray[$data['row']['perms_userid']] ? $beUserArray[$data['row']['perms_userid']]['username'] : ($data['row']['perms_userid'] ? $data['row']['perms_userid'] : '');
504 if ($data['row']['perms_userid'] && !$beUserArray[$data['row']['perms_userid']]) {
505 $userName = \TYPO3\CMS\Perm\Controller\PermissionAjaxController::renderOwnername($pageId, $data['row']['perms_userid'], htmlspecialchars(GeneralUtility::fixed_lgd_cs($userName, 20)), FALSE);
506 } else {
507 $userName = \TYPO3\CMS\Perm\Controller\PermissionAjaxController::renderOwnername($pageId, $data['row']['perms_userid'], htmlspecialchars(GeneralUtility::fixed_lgd_cs($userName, 20)));
508 }
509 $groupName = $beGroupArray[$data['row']['perms_groupid']] ? $beGroupArray[$data['row']['perms_groupid']]['title'] : ($data['row']['perms_groupid'] ? $data['row']['perms_groupid'] : '');
510 if ($data['row']['perms_groupid'] && !$beGroupArray[$data['row']['perms_groupid']]) {
511 $groupName = \TYPO3\CMS\Perm\Controller\PermissionAjaxController::renderGroupname($pageId, $data['row']['perms_groupid'], htmlspecialchars(GeneralUtility::fixed_lgd_cs($groupName, 20)), FALSE);
512 } else {
513 $groupName = \TYPO3\CMS\Perm\Controller\PermissionAjaxController::renderGroupname($pageId, $data['row']['perms_groupid'], htmlspecialchars(GeneralUtility::fixed_lgd_cs($groupName, 20)));
514 }
515 // Seeing if editing of permissions are allowed for that page:
516 $editPermsAllowed = $data['row']['perms_userid'] == $GLOBALS['BE_USER']->user['uid'] || $GLOBALS['BE_USER']->isAdmin();
517 // First column:
518 $cellAttrib = $data['row']['_CSSCLASS'] ? ' class="' . $data['row']['_CSSCLASS'] . '"' : '';
519 $cells[] = '
520 <td align="left" nowrap="nowrap"' . ($cellAttrib ? $cellAttrib : $bgCol) . '>' . $data['HTML'] . htmlspecialchars(GeneralUtility::fixed_lgd_cs($data['row']['title'], $tLen)) . '&nbsp;</td>';
521 // "Edit permissions" -icon
522 if ($editPermsAllowed && $pageId) {
523 $aHref = BackendUtility::getModuleUrl('web_perm') . '&mode=' . $this->MOD_SETTINGS['mode'] . '&depth=' . $this->MOD_SETTINGS['depth'] . '&id=' . ($data['row']['_ORIG_uid'] ? $data['row']['_ORIG_uid'] : $pageId) . '&return_id=' . $this->id . '&edit=1';
524 $cells[] = '
525 <td' . $bgCol . '><a href="' . htmlspecialchars($aHref) . '" title="' . $GLOBALS['LANG']->getLL('ch_permissions', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a></td>';
526 } else {
527 $cells[] = '
528 <td' . $bgCol . '></td>';
529 }
530
531 $cells[] = '
532 <td' . $bgCol . ' class="center"><img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
533 <td' . $bgCol . ' nowrap="nowrap">' . ($pageId ? \TYPO3\CMS\Perm\Controller\PermissionAjaxController::renderPermissions($data['row']['perms_user'], $pageId, 'user') . ' ' . $userName : '') . '</td>
534
535 <td' . $bgCol . ' class="center"><img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
536 <td' . $bgCol . ' nowrap="nowrap">' . ($pageId ? \TYPO3\CMS\Perm\Controller\PermissionAjaxController::renderPermissions($data['row']['perms_group'], $pageId, 'group') . ' ' . $groupName : '') . '</td>
537
538 <td' . $bgCol . ' class="center"><img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
539 <td' . $bgCol . ' nowrap="nowrap">' . ($pageId ? ' ' . \TYPO3\CMS\Perm\Controller\PermissionAjaxController::renderPermissions($data['row']['perms_everybody'], $pageId, 'everybody') : '') . '</td>
540
541 <td' . $bgCol . ' class="center"><img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/line.gif', 'width="5" height="16"') . ' alt="" /></td>
542 <td' . $bgCol . ' nowrap="nowrap">' . ($data['row']['editlock'] ? '<span id="el_' . $pageId . '" class="editlock"><a class="editlock" onclick="WebPermissions.toggleEditLock(\'' . $pageId . '\', \'1\');" title="' . $GLOBALS['LANG']->getLL('EditLock_descr', TRUE) . '">' . IconUtility::getSpriteIcon('status-warning-lock') . '</a></span>' : ($pageId === 0 ? '' : '<span id="el_' . $pageId . '" class="editlock"><a class="editlock" onclick="WebPermissions.toggleEditLock(\'' . $pageId . '\', \'0\');" title="Enable the &raquo;Admin-only&laquo; edit lock for this page">[+]</a></span>')) . '</td>
543 ';
544 // Compile table row:
545 $code .= '
546 <tr>
547 ' . implode('
548 ', $cells) . '
549 </tr>';
550 }
551 // Wrap rows in table tags:
552 $code = '<table border="0" cellspacing="0" cellpadding="0" id="typo3-permissionList">' . $code . '</table>';
553 // Adding the content as a section:
554 $this->content .= $this->doc->section('', $code);
555 // CSH for permissions setting
556 $this->content .= BackendUtility::cshItem('xMOD_csh_corebe', 'perm_module', $GLOBALS['BACK_PATH'], '<br />|');
557 // Creating legend table:
558 $legendText = '<strong>' . $GLOBALS['LANG']->getLL('1', TRUE) . '</strong>: ' . $GLOBALS['LANG']->getLL('1_t', TRUE);
559 $legendText .= '<br /><strong>' . $GLOBALS['LANG']->getLL('16', TRUE) . '</strong>: ' . $GLOBALS['LANG']->getLL('16_t', TRUE);
560 $legendText .= '<br /><strong>' . $GLOBALS['LANG']->getLL('2', TRUE) . '</strong>: ' . $GLOBALS['LANG']->getLL('2_t', TRUE);
561 $legendText .= '<br /><strong>' . $GLOBALS['LANG']->getLL('4', TRUE) . '</strong>: ' . $GLOBALS['LANG']->getLL('4_t', TRUE);
562 $legendText .= '<br /><strong>' . $GLOBALS['LANG']->getLL('8', TRUE) . '</strong>: ' . $GLOBALS['LANG']->getLL('8_t', TRUE);
563
564 $code = '<div id="permission-information">
565 <img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/legend.gif', 'width="86" height="75"') . ' alt="" />
566 <div class="text">' . $legendText . '</div></div>';
567
568 $code .= '<div id="perm-legend">' . $GLOBALS['LANG']->getLL('def', TRUE);
569 $code .= '<br /><br />' . IconUtility::getSpriteIcon('status-status-permission-granted') . ': ' . $GLOBALS['LANG']->getLL('A_Granted', TRUE);
570 $code .= '<br />' . IconUtility::getSpriteIcon('status-status-permission-denied') . ': ' . $GLOBALS['LANG']->getLL('A_Denied', TRUE);
571 $code .= '</div>';
572 // Adding section with legend code:
573 $this->content .= $this->doc->spacer(20);
574 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('Legend') . ':', $code, 0, 1);
575 }
576
577 /*****************************
578 *
579 * Helper functions
580 *
581 *****************************/
582 /**
583 * Print a checkbox for the edit-permission form
584 *
585 * @param string $checkName Checkbox name key
586 * @param integer $num Checkbox number index
587 * @return string HTML checkbox
588 */
589 public function printCheckBox($checkName, $num) {
590 $onclick = 'checkChange(\'check[' . $checkName . ']\', \'data[pages][' . $GLOBALS['SOBE']->id . '][' . $checkName . ']\')';
591 return '<input type="checkbox" name="check[' . $checkName . '][' . $num . ']" onclick="' . htmlspecialchars($onclick) . '" /><br />';
592 }
593
594 /**
595 * Finding tree and offer setting of values recursively.
596 *
597 * @param integer $id Page id.
598 * @param string $perms_clause Select clause
599 * @return string Select form element for recursive levels (if any levels are found)
600 */
601 public function getRecursiveSelect($id, $perms_clause) {
602 // Initialize tree object:
603 $tree = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
604 $tree->init('AND ' . $perms_clause);
605 $tree->addField('perms_userid', 1);
606 $tree->makeHTML = 0;
607 $tree->setRecs = 1;
608 // Make tree:
609 $tree->getTree($id, $this->getLevels, '');
610 // If there are a hierarchy of page ids, then...
611 if ($GLOBALS['BE_USER']->user['uid'] && count($tree->orig_ids_hierarchy)) {
612 // Init:
613 $label_recur = $GLOBALS['LANG']->getLL('recursive');
614 $label_levels = $GLOBALS['LANG']->getLL('levels');
615 $label_pA = $GLOBALS['LANG']->getLL('pages_affected');
616 $theIdListArr = array();
617 $opts = '
618 <option value=""></option>';
619 // Traverse the number of levels we want to allow recursive setting of permissions for:
620 for ($a = $this->getLevels; $a > 0; $a--) {
621 if (is_array($tree->orig_ids_hierarchy[$a])) {
622 foreach ($tree->orig_ids_hierarchy[$a] as $theId) {
623 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->user['uid'] == $tree->recs[$theId]['perms_userid']) {
624 $theIdListArr[] = $theId;
625 }
626 }
627 $lKey = $this->getLevels - $a + 1;
628 $opts .= '
629 <option value="' . htmlspecialchars(implode(',', $theIdListArr)) . '">' . GeneralUtility::deHSCentities(htmlspecialchars(($label_recur . ' ' . $lKey . ' ' . $label_levels))) . ' (' . count($theIdListArr) . ' ' . $label_pA . ')' . '</option>';
630 }
631 }
632 // Put the selector box together:
633 $theRecursiveSelect = '<br />
634 <select name="mirror[pages][' . $id . ']">
635 ' . $opts . '
636 </select>
637 <br /><br />';
638 } else {
639 $theRecursiveSelect = '';
640 }
641 // Return selector box element:
642 return $theRecursiveSelect;
643 }
644
645 }