7a8f5723fd0467fee7d10d61154a9bb0eaf706e3
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / mod / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 * Backend User Administration Module
29 *
30 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 */
32
33 $GLOBALS['LANG']->includeLLFile('EXT:beuser/mod/locallang.xml');
34
35 $BE_USER->modAccess($MCONF, 1);
36
37
38
39
40
41
42 /**
43 * Base Extension class for printing a page tree (non-browsable though)
44 *
45 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
46 * @package TYPO3
47 * @subpackage tx_beuser
48 */
49 class localPageTree extends t3lib_browseTree {
50 var $expandFirst=0;
51 var $expandAll=0;
52
53 /**
54 * Local backend user (not the GLOBALS[] backend user!!)
55 *
56 * @var t3lib_beUserAuth
57 */
58 var $BE_USER;
59
60 /**
61 * Constructor for the local page tree.
62 *
63 * @param object Local backend user (not the GLOBALS[] backend user!!)
64 * @param array Webmounts for the backend user.
65 * @return void
66 */
67 function __construct($BE_USER, $WEBMOUNTS='') {
68 $this->init();
69
70 $this->BE_USER = $BE_USER;
71 $this->MOUNTS = $WEBMOUNTS;
72 $this->clause = $this->ext_permsC(); // Notice, this clause does NOT filter out un-readable pages. This is the POINT since this class is ONLY used for the main overview where ALL is shown! Otherwise "AND '.$this->BE_USER->getPagePermsClause(1).'" should be added.
73 $this->orderByFields = 'sorting';
74 }
75
76 /**
77 * Return select permissions.
78 *
79 * @return string WHERE query part.
80 */
81 function ext_permsC() {
82 return '';
83 }
84
85 /**
86 * Wraps the title.
87 *
88 * @param string [See parent]
89 * @param array [See parent]
90 * @return string
91 */
92 function wrapTitle($str, $row) {
93 return $str;
94 }
95
96 /**
97 * Wraps the plus/minus icon - in this case we just return blank which means we STRIP AWAY the plus/minus icon!
98 *
99 * @param string [See parent]
100 * @param string [See parent]
101 * @param string [See parent]
102 * @return string
103 */
104 function PM_ATagWrap($icon, $cmd, $bMark = '') {
105 return '';
106 }
107
108 /**
109 * Wrapping the icon of the element/page. Normally a click menu is wrapped around the icon, but in this case only a title parameter is set.
110 *
111 * @param string Icon image tag.
112 * @param array Row.
113 * @return string Icon with title attribute added.
114 */
115 function wrapIcon($icon, $row) {
116 // Add title attribute to input icon tag
117 $title = '['.$row['uid'].'] '.t3lib_BEfunc::getRecordPath($row['uid'], '', 15);
118 $theIcon = $this->addTagAttributes($icon, ($this->titleAttrib ? $this->titleAttrib.'="'.htmlspecialchars($title).'"' : '').' border="0"');
119
120 return $theIcon;
121 }
122
123 /**
124 * This will make sure that no position data is acquired from the BE_USER uc variable.
125 *
126 * @return void
127 */
128 function initializePositionSaving() {
129 $this->stored=array();
130 }
131 }
132
133
134
135
136
137
138
139
140
141
142 /**
143 * Extension class for printing a page tree: All pages of a mount point.
144 *
145 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
146 * @package TYPO3
147 * @subpackage tx_beuser
148 */
149 class printAllPageTree extends localPageTree {
150 var $expandFirst=1;
151 var $expandAll=1;
152
153 /**
154 * Return select permissions.
155 *
156 * @return string WHERE query part.
157 */
158 function ext_permsC() {
159 return ' AND '.$this->BE_USER->getPagePermsClause(1);
160 }
161
162 /**
163 * Returns the plus/minus icon.
164 *
165 * @param string [See parent]
166 * @param string [See parent]
167 * @param string [See parent]
168 * @return string
169 */
170 function PM_ATagWrap($icon, $cmd, $bMark='') {
171 return $icon;
172 }
173
174 /**
175 * Wrapping the icon of the element/page. Normally a click menu is wrapped around the icon, but in this case only a title parameter is set.
176 *
177 * @param string Icon image tag.
178 * @param array Row.
179 * @return string Icon with title attribute added.
180 */
181 function wrapIcon($icon, $row) {
182 // Add title attribute to input icon tag
183 $title = '['.$row['uid'].']';
184 $theIcon = $this->addTagAttributes($icon, ($this->titleAttrib ? $this->titleAttrib.'="'.htmlspecialchars($title).'"' : '').' border="0"');
185
186 return $theIcon;
187 }
188 }
189
190
191
192
193
194
195
196
197
198
199 /**
200 * Extension class for printing a page tree: Printing all pages, with permissions.
201 *
202 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
203 * @package TYPO3
204 * @subpackage tx_beuser
205 */
206 class printAllPageTree_perms extends printAllPageTree {
207
208 /**
209 * Print the tree of pages.
210 *
211 * @param array The tree items
212 * @param boolean If set, the path of the pages in the tree is printed (only done for pages outside of mounts).
213 * @return string HTML content.
214 */
215 function printTree($treeArr='', $printPath=0) {
216 $titleLen=intval($this->BE_USER->uc['titleLen']);
217
218 $be_user_Array = t3lib_BEfunc::getUserNames();
219 $be_group_Array = t3lib_BEfunc::getGroupNames();
220 $lines=array();
221 $lines[]='<tr class="bgColor5">
222 <td nowrap="nowrap"><strong>' . $GLOBALS['LANG']->getLL('pageTitle', TRUE) . '</strong></td>
223 ' . ($printPath?'<td nowrap="nowrap"><strong>' . $GLOBALS['LANG']->getLL('path', TRUE) . '</strong></td>':'') . '
224 <td nowrap="nowrap" colspan="2"><strong>' . $GLOBALS['LANG']->getLL('user', TRUE) . '</strong></td>
225 <td nowrap="nowrap" colspan="2"><strong>' . $GLOBALS['LANG']->getLL('group', TRUE) . ' &nbsp;</strong></td>
226 <td nowrap="nowrap"><strong>' . $GLOBALS['LANG']->getLL('everybody', TRUE) . ' &nbsp;</strong></td>
227 <td nowrap="nowrap"><strong>' . $GLOBALS['LANG']->getLL('thisUser', TRUE) . ' &nbsp;</strong></td>
228 <td nowrap="nowrap"><strong>' . $GLOBALS['LANG']->getLL('mainGroup', TRUE) . '</strong></td>
229 </tr>';
230
231 if (!is_array($treeArr)) {
232 $treeArr = $this->tree;
233 }
234 foreach ($treeArr as $v) {
235 $col1 = ' bgcolor="'.t3lib_div::modifyHtmlColor($GLOBALS['SOBE']->doc->bgColor4, +10, +10, +10).'"';
236 $row = $v['row'];
237 $title = htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'], $this->BE_USER->uc['titleLen']));
238 $lines[]='<tr class="bgColor4">
239 <td nowrap="nowrap">'.$v['HTML'].$title.' &nbsp;</td>
240 '.($printPath?'<td nowrap="nowrap">'.htmlspecialchars(t3lib_BEfunc::getRecordPath ($row['pid'], '', 15)).' &nbsp;</td>':'').'
241 <td nowrap="nowrap"'.$col1.'>'.$be_user_Array[$row['perms_userid']]['username'].' &nbsp;</td>
242 <td nowrap="nowrap"'.$col1.'>'.$this->ext_printPerms($row['perms_user']).' &nbsp;</td>
243 <td nowrap="nowrap">'.$be_group_Array[$row['perms_groupid']]['title'].' &nbsp;</td>
244 <td nowrap="nowrap">'.$this->ext_printPerms($row['perms_group']).' &nbsp;</td>
245 <td nowrap="nowrap" align="center" '.$col1.'>'.$this->ext_printPerms($row['perms_everybody']).' &nbsp;</td>
246 <td nowrap="nowrap" align="center">' . ($row['editlock'] ? t3lib_iconWorks::getSpriteIcon('status-warning-in-use', array('title' => $GLOBALS['LANG']->getLL('editLock', TRUE))) : $this->ext_printPerms($this->BE_USER->calcPerms($row))) . ' &nbsp;</td>
247 <td nowrap="nowrap" align="center">'.$this->ext_printPerms($this->ext_groupPerms($row, $be_group_Array[$this->BE_USER->firstMainGroup])).' &nbsp;</td>
248 </tr>';
249 }
250 return '<table border="0" cellpadding="0" cellspacing="0">'.implode('', $lines).'</table>';
251 }
252
253 /**
254 * Print a set of permissions
255 *
256 * @param integer The permissions integer.
257 * @return string HTML formatted.
258 */
259 function ext_printPerms($int) {
260 $str='';
261 $str.= (($int&1)?'*':'<font color="red">x</font>');
262 $str.= (($int&16)?'*':'<font color="red">x</font>');
263 $str.= (($int&2)?'*':'<font color="red">x</font>');
264 $str.= (($int&4)?'*':'<font color="red">x</font>');
265 $str.= (($int&8)?'*':'<font color="red">x</font>');
266
267 return '<strong style="color:green;">'.$str.'</strong>';
268 }
269
270 /**
271 * 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
272 *
273 * @param array Page record.
274 * @param array First-group record.
275 * @return integer Permissions.
276 */
277 function ext_groupPerms($row, $firstGroup) {
278 if (is_array($row)) {
279 $out=intval($row['perms_everybody']);
280 if ($row['perms_groupid'] && $firstGroup['uid']==$row['perms_groupid']) {
281 $out|= intval($row['perms_group']);
282 }
283 return $out;
284 }
285 }
286 }
287
288
289
290
291
292
293
294
295
296
297
298 /**
299 * Base Extension class for printing a folder tree (non-browsable though)
300 *
301 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
302 * @package TYPO3
303 * @subpackage tx_beuser
304 */
305 class localFolderTree extends t3lib_folderTree {
306 var $expandFirst=0;
307 var $expandAll=0;
308
309 /**
310 * Local backend user (not the GLOBALS[] backend user!!)
311 *
312 * @var t3lib_beUserAuth
313 */
314 var $BE_USER;
315
316 /**
317 * Constructor for the local folder tree.
318 *
319 * @param object Local backend user (not the GLOBALS[] backend user!!)
320 * @param array Filemounts for the backend user.
321 * @return void
322 */
323 function __construct($BE_USER) {
324 $this->init();
325
326 $this->BE_USER = $BE_USER;
327 $this->storages = $BE_USER->getFileStorages();
328 $this->clause = ''; // Notice, this clause does NOT filter out un-readable pages. This is the POINT since this class is ONLY used for the main overview where ALL is shown! Otherwise "AND '.$this->BE_USER->getPagePermsClause(1).'" should be added.
329 }
330
331 /**
332 * Wraps the title.
333 *
334 * @param string [See parent]
335 * @param array [See parent]
336 * @return string
337 */
338 function wrapTitle($str, $row) {
339 return $str;
340 }
341
342 /**
343 * Wraps the plus/minus icon - in this case we just return blank which means we STRIP AWAY the plus/minus icon!
344 *
345 * @param string [See parent]
346 * @param string [See parent]
347 * @param string [See parent]
348 * @return string
349 */
350 function PM_ATagWrap($icon, $cmd, $bMark='') {
351 return '';
352 }
353
354 /**
355 * Wrapping the icon of the element/page. Normally a click menu is wrapped around the icon, but in this case only a title parameter is set.
356 *
357 * @param string $icon The image tag for the icon
358 * @param t3lib_file_Folder $folderObject The row for the current element
359 * @return string The processed icon input value.
360 * @internal
361 */
362 public function wrapIcon($icon, t3lib_file_Folder $folderObject) {
363 // Add title attribute to input icon tag
364 $theFolderIcon = $this->addTagAttributes($icon, ($this->titleAttrib ? $this->titleAttrib . '="' . $this->getTitleAttrib($folderObject) . '"' : ''));
365 return $theFolderIcon;
366 }
367
368
369 /**
370 * This will make sure that no position data is acquired from the BE_USER uc variable.
371 *
372 * @return void
373 */
374 function initializePositionSaving() {
375 $this->stored=array();
376 }
377 }
378
379
380
381
382
383
384
385
386
387
388
389
390
391 /**
392 * Extension class for printing a folder tree: All folders
393 *
394 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
395 * @package TYPO3
396 * @subpackage tx_beuser
397 */
398 class printAllFolderTree extends localFolderTree {
399 var $expandFirst=1;
400 var $expandAll=1;
401
402 /**
403 * Wraps the plus/minus icon - in this case we just return blank which means we STRIP AWAY the plus/minus icon!
404 *
405 * @param string [See parent]
406 * @param string [See parent]
407 * @param string [See parent]
408 * @return string
409 */
410 function PM_ATagWrap($icon, $cmd, $bMark='') {
411 return $icon;
412 }
413 }
414
415
416
417
418
419
420
421
422
423
424
425 /**
426 * Extension class of beuserauth class.
427 *
428 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
429 * @package TYPO3
430 * @subpackage tx_beuser
431 */
432 class local_beUserAuth extends t3lib_beUserAuth {
433 var $ext_pageIdsFromMounts=''; // List of mounted page ids (from browsetree class when selecting mountpoints)
434 var $ext_non_readAccessPageArray=array(); // Storage for non-readable webmounts, see returnWebmounts()
435
436 /**
437 * Returns an array of the webmounts for the user, with non-readable webmounts filtered out.
438 * If there are non-readable webmounts they are registered in $this->ext_non_readAccessPageArray
439 * (Extending function in parent class)
440 *
441 * @param string alternative select clause (default is getPagePermsClause(1)). For instance to make sure that ALL webmounts are selected regardless of whether the user has read access or not, you can set this to "1=1".
442 * @return array Webmounts id's
443 */
444 function returnWebmounts($pClause='') {
445
446 // Get array of webmounts:
447 $webmounts = (string)($this->groupData['webmounts'])!='' ? explode(',', $this->groupData['webmounts']) : Array();
448
449 // Get select clause:
450 $pClause=$pClause?$pClause:$this->getPagePermsClause(1);
451
452 // Traverse mounts, check if they are readable:
453 foreach ($webmounts as $k => $id) {
454 $rec=t3lib_BEfunc::getRecord('pages', $id, '*', ' AND '.$pClause);
455 if (!is_array($rec)) {
456 $this->ext_non_readAccessPageArray[$id]=t3lib_BEfunc::getRecord('pages', $id);
457 unset($webmounts[$k]);
458 }
459 }
460 return $webmounts;
461 }
462
463 /**
464 * Based on the content of ->ext_non_readAccessPageArray (see returnWebmounts()) it generates visually formatted information about these non-readable mounts.
465 *
466 * @return string HTML content showing which DB-mounts were not accessible for the user
467 */
468 function ext_non_readAccessPages() {
469 $lines=array();
470
471 foreach ($this->ext_non_readAccessPageArray as $pA) {
472 if ($pA) {
473 $lines[] = t3lib_BEfunc::getRecordPath($pA['uid'], '', 15);
474 }
475 }
476 if (count($lines)) {
477 return '<table bgcolor="red" border="0" cellpadding="0" cellspacing="0">
478 <tr>
479 <td align="center"><font color="white"><strong>' . $GLOBALS['LANG']->getLL('noReadAccess', TRUE) . '</strong></font></td>
480 </tr>
481 <tr>
482 <td>'.implode('</td></tr><tr><td>', $lines).'</td>
483 </tr>
484 </table>';
485 }
486 }
487
488 /**
489 * This returns the where-clause needed to select the user with respect flags like deleted, hidden, starttime, endtime
490 *
491 * @return string
492 */
493 function user_where_clause() {
494 return 'AND pid=0 ';
495 }
496
497 /**
498 * Creates the overview information based on which analysis topics were selected.
499 *
500 * @param array Array of analysis topics
501 * @param array Array of the selected analysis topics (from session variable somewhere)
502 * @param boolean If set, the full trees of pages/folders are printed.
503 * @return array Array with accumulated HTML content.
504 */
505 function ext_printOverview($uInfo, $compareFlags, $printTrees=0) {
506 // Prepare for file storages and db-mount
507 if ($printTrees) { // ... this is if we see the detailed view for a user:
508 // Page tree object:
509 $pagetree = t3lib_div::makeInstance(!$this->isAdmin() ? 'printAllPageTree_perms' : 'printAllPageTree', $this, $this->returnWebmounts()); // Here, only readable webmounts are returned (1=1)
510 $pagetree->addField('perms_user', 1);
511 $pagetree->addField('perms_group', 1);
512 $pagetree->addField('perms_everybody', 1);
513 $pagetree->addField('perms_userid', 1);
514 $pagetree->addField('perms_groupid', 1);
515 $pagetree->addField('editlock', 1);
516
517 // Folder tree object:
518 $foldertree = t3lib_div::makeInstance('printAllFolderTree', $this);
519 } else {
520 // Page tree object:
521 $pagetree = t3lib_div::makeInstance('localPageTree', $this, $this->returnWebmounts('1=1')); // Here, ALL webmounts are returned (1=1)
522
523 // Folder tree object:
524 $foldertree = t3lib_div::makeInstance('localFolderTree', $this);
525 }
526
527 // Names for modules:
528 $modNames = array(
529 'web' => 'Web',
530 'web_layout' => 'Page',
531 'web_modules' => 'Modules',
532 'web_info' => 'Info',
533 'web_perms' => 'Access',
534 'web_func' => 'Func',
535 'web_list' => 'List',
536 'web_ts' => 'Template',
537 'file' => 'File',
538 'file_list' => 'List',
539 'file_images' => 'Images',
540 'doc' => 'Doc.',
541 'help' => 'Help',
542 'help_about' => 'About',
543 'help_quick' => 'User manual',
544 'help_welcome' => 'Welcome',
545 'user' => 'User',
546 'user_setup' => 'Setup',
547 'user_task' => 'Task center'
548 );
549
550 // Traverse the enabled analysis topics:
551 $out=array();
552 foreach ($uInfo as $k => $v) {
553 if ($compareFlags[$k]) {
554 switch($k) {
555 case 'filemounts':
556 case 'filestorages':
557 $out[$k] = $foldertree->getBrowsableTree();
558 break;
559 case 'webmounts':
560 // Print webmounts:
561 $pagetree->addSelfId=1;
562 $out[$k] = $this->ext_non_readAccessPages(); // Add HTML for non-readable webmounts (only shown when viewing details of a user - in overview/comparison ALL mounts are shown)
563 $out[$k].= $pagetree->getBrowsableTree(); // Add HTML for readable webmounts.
564 $this->ext_pageIdsFromMounts=implode(',', array_unique($pagetree->ids)); // List of mounted page ids
565 break;
566 case 'tempPath':
567 $out[$k] = $GLOBALS['SOBE']->localPath($v);
568 break;
569 case 'pagetypes_select':
570 $pageTypes = explode(',', $v);
571 foreach ($pageTypes as &$vv) {
572 $vv = $GLOBALS['LANG']->sL(t3lib_BEfunc::getLabelFromItemlist('pages', 'doktype', $vv));
573 }
574 unset($vv);
575 $out[$k] = implode('<br />', $pageTypes);
576 break;
577 case 'tables_select':
578 case 'tables_modify':
579 $tables = explode(',', $v);
580 foreach ($tables as &$vv) {
581 if ($vv) {
582 $vv = '<span class="nobr">'.t3lib_iconWorks::getSpriteIconForRecord($vv, array()).$GLOBALS['LANG']->sL($GLOBALS['TCA'][$vv]['ctrl']['title']).'</span>';
583 }
584 }
585 unset($vv);
586 $out[$k] = implode('<br />', $tables);
587 break;
588 case 'non_exclude_fields':
589 $nef = explode(',', $v);
590 $table='';
591 $pout=array();
592 foreach ($nef as $vv) {
593 if ($vv) {
594 list($thisTable,$field) = explode(':', $vv);
595 if ($thisTable!=$table) {
596 $table=$thisTable;
597 t3lib_div::loadTCA($table);
598 $pout[]='<span class="nobr">'.t3lib_iconWorks::getSpriteIconForRecord($table, array()).$GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['ctrl']['title']).'</span>';
599 }
600 if ($GLOBALS['TCA'][$table]['columns'][$field]) {
601 $pout[]='<span class="nobr"> - '.rtrim($GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['columns'][$field]['label']), ':').'</span>';
602 }
603 }
604 }
605 $out[$k] = implode('<br />', $pout);
606 break;
607 case 'groupList':
608 case 'firstMainGroup':
609 $uGroups = explode(',', $v);
610 $table='';
611 $pout=array();
612 foreach ($uGroups as $vv) {
613 if ($vv) {
614 $uGRow = t3lib_BEfunc::getRecord('be_groups', $vv);
615 $title = t3lib_BEfunc::getRecordTitle('be_groups', $uGRow);
616 $pout[] = '<tr><td nowrap="nowrap">' . t3lib_iconWorks::getSpriteIconForRecord('be_groups', $uGRow) .
617 '&nbsp;' . htmlspecialchars($title) . '&nbsp;&nbsp;</td><td width="1%" nowrap="nowrap">' .
618 $GLOBALS['SOBE']->elementLinks('be_groups', $uGRow) . '</td></tr>';
619 }
620 }
621 $out[$k] = '<table border="0" cellpadding="0" cellspacing="0" width="100%">'.implode('', $pout).'</table>';
622 break;
623 case 'modules':
624 $mods = explode(',', $v);
625 $mainMod='';
626 $pout=array();
627 foreach ($mods as $vv) {
628 if ($vv) {
629 list($thisMod,$subMod) = explode('_', $vv);
630 if ($thisMod!=$mainMod) {
631 $mainMod=$thisMod;
632 $pout[]='<span class="nobr">'.($modNames[$mainMod]?$modNames[$mainMod]:$mainMod).'</span>';
633 }
634 if ($subMod) {
635 $pout[]='<span class="nobr"> - '.($modNames[$mainMod.'_'.$subMod]?$modNames[$mainMod.'_'.$subMod]:$mainMod.'_'.$subMod).'</span>';
636 }
637 }
638 }
639 $out[$k] = implode('<br />', $pout);
640 break;
641 case 'userTS':
642
643 $tmpl = t3lib_div::makeInstance('t3lib_tsparser_ext'); // Defined global here!
644 $tmpl->tt_track = 0; // Do not log time-performance information
645
646 $tmpl->fixedLgd=0;
647 $tmpl->linkObjects=0;
648 $tmpl->bType='';
649 $tmpl->ext_expandAllNotes=1;
650 $tmpl->ext_noPMicons=1;
651 $out[$k] = $tmpl->ext_getObjTree($v, '', '', '', '', '1');
652 break;
653 case 'userTS_hl':
654 $tsparser = t3lib_div::makeInstance('t3lib_TSparser');
655 $tsparser->lineNumberOffset=0;
656 $out[$k] = $tsparser->doSyntaxHighlight($v, 0, 1);
657 break;
658 case 'explicit_allowdeny':
659
660 // Explode and flip values:
661 $nef = array_flip(explode(',', $v));
662 $pout = array();
663
664 $theTypes = t3lib_BEfunc::getExplicitAuthFieldValues();
665
666 // Icons:
667 $icons = array(
668 'ALLOW' => t3lib_iconWorks::getSpriteIcon('status-dialog-ok'),
669 'DENY' => t3lib_iconWorks::getSpriteIcon('status-dialog-error'),
670 );
671
672 // Traverse types:
673 foreach ($theTypes as $tableFieldKey => $theTypeArrays) {
674 if (is_array($theTypeArrays['items'])) {
675 $pout[] = '<strong>'.$theTypeArrays['tableFieldLabel'].'</strong>';
676 // Traverse options for this field:
677 foreach ($theTypeArrays['items'] as $itemValue => $itemContent) {
678 $v = $tableFieldKey.':'.$itemValue.':'.$itemContent[0];
679 if (isset($nef[$v])) {
680 unset($nef[$v]);
681 $pout[] = $icons[$itemContent[0]].'['.$itemContent[2].'] '.$itemContent[1];
682 } else {
683 $pout[] = '<em style="color: #666666;">'.$icons[($itemContent[0]=='ALLOW' ? 'DENY' : 'ALLOW')].'['.$itemContent[2].'] '.$itemContent[1].'</em>';
684 }
685 }
686 $pout[] = '';
687 }
688 }
689
690 // Add remaining:
691 if (count($nef)) {
692 $pout = array_merge($pout, array_keys($nef));
693 }
694
695 // Implode for display:
696 $out[$k] = implode('<br />', $pout);
697 break;
698 case 'allowed_languages':
699
700 // Explode and flip values:
701 $nef = array_flip(explode(',', $v));
702 $pout = array();
703
704 // Get languages:
705 $items = t3lib_BEfunc::getSystemLanguages();
706
707 // Traverse values:
708 foreach ($items as $iCfg) {
709 if (isset($nef[$iCfg[1]])) {
710 unset($nef[$iCfg[1]]);
711 if (strpos($iCfg[2], '.gif') === FALSE) {
712 $icon = t3lib_iconWorks::getSpriteIcon($iCfg[2]) . '&nbsp;';
713 } elseif (strlen($iCfg[2])) {
714 $icon = '<img '.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/'.$iCfg[2]).' class="absmiddle" style="margin-right: 5px;" alt="" />';
715 } else {
716 $icon = '';
717 }
718 $pout[] = $icon.$iCfg[0];
719 }
720 }
721
722 // Add remaining:
723 if (count($nef)) {
724 $pout = array_merge($pout, array_keys($nef));
725 }
726
727 // Implode for display:
728 $out[$k] = implode('<br />', $pout);
729 break;
730 case 'workspace_perms':
731 $out[$k] = implode('<br/>', explode(', ', t3lib_BEfunc::getProcessedValue('be_users','workspace_perms', $v)));
732 break;
733 case 'workspace_membership':
734 $out[$k] = implode('<br/>', $this->ext_workspaceMembership());
735 break;
736 case 'custom_options':
737
738 // Explode and flip values:
739 $nef = array_flip(explode(',', $v));
740 $pout = array();
741
742 // Initialize:
743 $customOptions = $GLOBALS['TYPO3_CONF_VARS']['BE']['customPermOptions'];
744 if (is_array($customOptions)) {
745 foreach ($customOptions as $coKey => $coValue) {
746 if (is_array($coValue['items'])) {
747 // Traverse items:
748 foreach ($coValue['items'] as $itemKey => $itemCfg) {
749 $v = $coKey.':'.$itemKey;
750 if (isset($nef[$v])) {
751 unset($nef[$v]);
752 $pout[] = $GLOBALS['LANG']->sl($coValue['header']).' / '.$GLOBALS['LANG']->sl($itemCfg[0]);
753 }
754 }
755 }
756 }
757 }
758
759 // Add remaining:
760 if (count($nef)) {
761 $pout = array_merge($pout, array_keys($nef));
762 }
763
764 // Implode for display:
765 $out[$k] = implode('<br />', $pout);
766 break;
767 }
768 }
769 }
770 return $out;
771 }
772
773 /**
774 * Get HTML code for the pages which were mounted, but NOT readable!
775 *
776 * @return string HTML code.
777 */
778 function ext_getReadableButNonmounted() {
779
780 // List of page id mounts which ARE mounted (and should therefore not be selected)
781 if (!$this->ext_pageIdsFromMounts) {
782 $this->ext_pageIdsFromMounts=0;
783 }
784
785 // User and group names:
786 $be_user_Array = t3lib_BEfunc::getUserNames();
787 $be_group_Array = t3lib_BEfunc::getGroupNames();
788
789 // Create query:
790 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
791 'pid,uid,title,doktype,perms_user,perms_group,perms_everybody,perms_userid,perms_groupid'.(t3lib_extMgm::isLoaded('cms')?',media,layout,hidden,starttime,endtime,fe_group,extendToSubpages':''),
792 'pages',
793 'uid NOT IN ('.$this->ext_pageIdsFromMounts.') AND '.$this->getPagePermsClause(1).t3lib_BEfunc::deleteClause('pages')
794 );
795 $dat = array();
796 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
797 $dat[] = array(
798 'row'=>$row,
799 'HTML'=>t3lib_iconWorks::getSpriteIconForRecord('pages', $row,array('title'=>'['.$row['uid'].']'))
800 );
801 }
802 $pp = t3lib_div::makeInstance('printAllPageTree_perms', $this);
803 return $pp->printTree($dat, 1);
804 }
805
806 /**
807 * Print a set of permissions
808 *
809 * @param integer The permissions integer.
810 * @return string HTML formatted.
811 */
812 function ext_printPerms($int) {
813 $str='';
814 $str.= (($int&1)?'*':'<font color="red">x</font>');
815 $str.= (($int&16)?'*':'<font color="red">x</font>');
816 $str.= (($int&2)?'*':'<font color="red">x</font>');
817 $str.= (($int&4)?'*':'<font color="red">x</font>');
818 $str.= (($int&8)?'*':'<font color="red">x</font>');
819
820 return '<strong style="color:green;">'.$str.'</strong>';
821 }
822
823 /**
824 * 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
825 *
826 * @param array Page record.
827 * @param array First-group record.
828 * @return integer Permissions.
829 */
830 function ext_groupPerms($row, $firstGroup) {
831 if (is_array($row)) {
832 $out=intval($row['perms_everybody']);
833 if ($row['perms_groupid'] && $firstGroup['uid']==$row['perms_groupid']) {
834 $out|= intval($row['perms_group']);
835 }
836 return $out;
837 }
838 }
839
840 /**
841 * Creates uInfo array for the user.
842 *
843 * @param array Might contain array where keys/values indicate whether to render a certain value
844 * @return array Array with the information of the user for each analysis topic.
845 */
846 function ext_compileUserInfoForHash($filter=NULL) {
847 $uInfo=array();
848 $renderAll = !is_array($filter);
849
850 // Filemounts:
851 if ($renderAll || $filter['filemounts']) {
852 $uInfo['filemounts'] = $this->ext_uniqueAndSortList(implode(',', array_keys($this->groupData['filemounts'])));
853 }
854
855 // DBmounts:
856 if ($renderAll || $filter['webmounts']) {
857 $uInfo['webmounts'] = $this->ext_uniqueAndSortList($this->groupData['webmounts']);
858 }
859
860 // Sharing Upload Folder
861 if ($renderAll || $filter['tempPath']) {
862 $fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
863 $fileProcessor->init($this->groupData['filemounts'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
864 $uInfo['tempPath'] = $fileProcessor->findTempFolder(); // The closest TEMP-path is found
865 }
866
867 // First Main Group:
868 if ($renderAll || $filter['firstMainGroup']) {
869 $uInfo['firstMainGroup'] = $this->firstMainGroup;
870 }
871
872 // Group List:
873 if ($renderAll || $filter['groupList']) {
874 $uInfo['groupList'] = $this->groupList; // This gives a list that shows in which order the groups are processed. This may result in a list of groups which is similar to that of another user regarding which group but not the order of groups. For now, I believe it's most usefull to let separate orders of groups appear as different group settings for a user.
875 }
876
877 // Page Types:
878 if ($renderAll || $filter['pagetypes_select']) {
879 $uInfo['pagetypes_select'] = $this->ext_uniqueAndSortList($this->groupData['pagetypes_select']);
880 }
881
882 // Tables select:
883 if ($renderAll || $filter['tables_select']) {
884 $uInfo['tables_select'] = $this->ext_uniqueAndSortList($this->groupData['tables_select'].','.$this->groupData['tables_modify']);
885 }
886
887 // Tables modify:
888 if ($renderAll || $filter['tables_modify']) {
889 $uInfo['tables_modify'] = $this->ext_uniqueAndSortList($this->groupData['tables_modify']);
890 }
891
892 // Non-exclude fields:
893 if ($renderAll || $filter['non_exclude_fields']) {
894 $uInfo['non_exclude_fields'] = $this->ext_uniqueAndSortList($this->groupData['non_exclude_fields']);
895 }
896
897 // Explicit Allow/Deny:
898 if ($renderAll || $filter['explicit_allowdeny']) {
899 $uInfo['explicit_allowdeny'] = $this->ext_uniqueAndSortList($this->groupData['explicit_allowdeny']);
900 }
901
902 // Limit to languages:
903 if ($renderAll || $filter['allowed_languages']) {
904 $uInfo['allowed_languages'] = $this->ext_uniqueAndSortList($this->groupData['allowed_languages']);
905 }
906
907 // Workspace permissions
908 if ($renderAll || $filter['workspace_perms']) {
909 $uInfo['workspace_perms'] = $this->ext_uniqueAndSortList($this->groupData['workspace_perms']);
910 }
911
912 // Workspace membership
913 if ($renderAll || $filter['workspace_membership']) {
914 $uInfo['workspace_membership'] = $this->ext_workspaceMembership();
915 }
916
917 // Custom options:
918 if ($renderAll || $filter['custom_options']) {
919 $uInfo['custom_options'] = $this->ext_uniqueAndSortList($this->groupData['custom_options']);
920 }
921
922 // Modules:
923 if ($renderAll || $filter['modules']) {
924 $uInfo['modules'] = $this->ext_uniqueAndSortList($this->groupData['modules']);
925 }
926
927 // User TS:
928 $this->ext_ksortArrayRecursive($this->userTS);
929 if ($renderAll || $filter['userTS']) {
930 $uInfo['userTS'] = $this->userTS;
931 }
932
933 if ($renderAll || $filter['userTS_hl']) {
934 $uInfo['userTS_hl'] = $this->userTS_text;
935 }
936
937 return $uInfo;
938 }
939
940 /**
941 * Sorts a commalist of values and removes duplicates.
942 *
943 * @param string Commalist.
944 * @return string Sorted, unique commalist.
945 */
946 function ext_uniqueAndSortList($list) {
947 $uList=t3lib_div::trimExplode(',', $list, 1);
948 sort($uList);
949 $uList=array_unique($uList);
950 $uList=implode(',', $uList);
951 return $uList;
952 }
953
954 /**
955 * Key sort input array recursively.
956 *
957 * @param array Multidimensional array (value by reference!)
958 * @return void
959 */
960 function ext_ksortArrayRecursive(&$arr) {
961 krsort($arr);
962 foreach ($arr as &$v) {
963 if (is_array($v)) {
964 $this->ext_ksortArrayRecursive($v);
965 }
966 }
967 unset($v);
968 }
969
970 /**
971 * Returns all workspaces that are accessible for the BE_USER
972 *
973 * @return array with key / value pairs of available workspaces (filtered by BE_USER check)
974 */
975 function ext_workspaceMembership() {
976 // Create accessible workspace arrays:
977 $options = array();
978 if ($this->checkWorkspace(array('uid' => 0))) {
979 $options[0] = '0: ' . $GLOBALS['LANG']->getLL('live', TRUE);
980 }
981
982 // Add custom workspaces (selecting all, filtering by BE_USER check):
983 if (t3lib_extMgm::isLoaded('workspaces')) {
984 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,adminusers,members,reviewers,db_mountpoints', 'sys_workspace', 'pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'), '', 'title');
985 if (count($workspaces)) {
986 foreach ($workspaces as $rec) {
987 if ($this->checkWorkspace($rec)) {
988 $options[$rec['uid']] = $rec['uid'].': '.htmlspecialchars($rec['title']);
989
990 // Check if all mount points are accessible, otherwise show error:
991 if (trim($rec['db_mountpoints'])!=='') {
992 $mountPoints = t3lib_div::intExplode(',', $this->workspaceRec['db_mountpoints'], 1);
993 foreach ($mountPoints as $mpId) {
994 if (!$this->isInWebMount($mpId, '1=1')) {
995 $options[$rec['uid']].= '<br> \- ' . $GLOBALS['LANG']->getLL('notAccessible', TRUE) . ' ' . $mpId;
996 }
997 }
998 }
999 }
1000 }
1001 }
1002 }
1003
1004 return $options;
1005 }
1006 }
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019 /**
1020 * Main script class
1021 *
1022 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
1023 * @package TYPO3
1024 * @subpackage tx_beuser
1025 */
1026 class SC_mod_tools_be_user_index {
1027 var $MCONF=array();
1028 var $MOD_MENU=array();
1029 var $MOD_SETTINGS=array();
1030
1031 /**
1032 * document emplate object
1033 *
1034 * @var noDoc
1035 */
1036 var $doc;
1037
1038 var $include_once=array();
1039 var $content;
1040
1041
1042 /**
1043 * Basic initialization of the class
1044 *
1045 * @return void
1046 */
1047 function init() {
1048 $this->MCONF = $GLOBALS['MCONF'];
1049
1050 $this->menuConfig();
1051 $this->switchUser(t3lib_div::_GP('SwitchUser'));
1052
1053
1054 // **************************
1055 // Initializing
1056 // **************************
1057 $this->doc = t3lib_div::makeInstance('template');
1058 $this->doc->backPath = $GLOBALS['BACK_PATH'];
1059 $this->doc->setModuleTemplate('templates/beuser.html');
1060 $this->doc->form = '<form action="" method="post">';
1061
1062 // JavaScript
1063 $this->doc->JScode = $this->doc->wrapScriptTags('
1064 script_ended = 0;
1065 function jumpToUrl(URL) { //
1066 window.location.href = URL;
1067 }
1068 ' . $this->doc->redirectUrls());
1069 }
1070
1071 /**
1072 * Initialization of the module menu configuration
1073 *
1074 * @return void
1075 */
1076 function menuConfig() {
1077 // MENU-ITEMS:
1078 // If array, then it's a selector box menu
1079 // If empty string it's just a variable, that'll be saved.
1080 // Values NOT in this array will not be saved in the settings-array for the module.
1081 $this->MOD_MENU = array(
1082 'function' => array(
1083 'compare' => $GLOBALS['LANG']->getLL('compareUserSettings', TRUE),
1084 'whoisonline' => $GLOBALS['LANG']->getLL('listUsersOnline', TRUE)
1085 )
1086 );
1087 // CLEAN SETTINGS
1088 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name'], 'ses');
1089 }
1090
1091 /**
1092 * This functions builds the content of the page
1093 *
1094 * @return void
1095 */
1096 function main() {
1097 $this->content = $this->doc->header($GLOBALS['LANG']->getLL('backendUserAdministration', TRUE));
1098
1099 switch($this->MOD_SETTINGS['function']) {
1100 case 'compare':
1101 if (t3lib_div::_GP('ads')) {
1102 $compareFlags = t3lib_div::_GP('compareFlags');
1103 $GLOBALS['BE_USER']->pushModuleData('tools_beuser/index.php/compare', $compareFlags);
1104 } else {
1105 $compareFlags = $GLOBALS['BE_USER']->getModuleData('tools_beuser/index.php/compare', 'ses');
1106 }
1107 $this->content.=$this->compareUsers($compareFlags);
1108 break;
1109 case 'whoisonline':
1110 $this->content.=$this->whoIsOnline();
1111 break;
1112 }
1113 // Setting up the buttons and markers for docheader
1114 $docHeaderButtons = $this->getButtons();
1115 $markers['FUNC_MENU'] = t3lib_BEfunc::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
1116 $markers['CONTENT'] = $this->content;
1117
1118 // Build the <body> for the module
1119 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
1120 // Renders the module page
1121 $this->content = $this->doc->render(
1122 'Backend User Administration',
1123 $this->content
1124 );
1125 }
1126
1127 /**
1128 * Prints the content of the page
1129 *
1130 * @return void
1131 */
1132 function printContent() {
1133 echo $this->content;
1134 }
1135
1136 /**
1137 * Create the panel of buttons for submitting the form or otherwise perform operations.
1138 *
1139 * @return array all available buttons as an assoc. array
1140 */
1141 protected function getButtons() {
1142 $buttons = array(
1143 'add' => '',
1144 'csh' => '',
1145 'shortcut' => '',
1146 'save' => ''
1147 );
1148
1149 // Add user
1150 if ($this->MOD_SETTINGS['function'] === 'compare') {
1151 $buttons['add'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick('&edit[be_users][0]=new', $this->doc->backPath, -1)) .
1152 '" title="' . $GLOBALS['LANG']->getLL('newUser', TRUE) . '">' . t3lib_iconWorks::getSpriteIcon('actions-document-new') . '</a>';
1153 }
1154
1155 // Shortcut
1156 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
1157 $buttons['shortcut'] = $this->doc->makeShortcutIcon('be_user_uid,compareFlags', 'function', $this->MCONF['name']);
1158 }
1159
1160 return $buttons;
1161 }
1162
1163
1164
1165
1166
1167 /***************************
1168 *
1169 * OTHER FUNCTIONS:
1170 *
1171 ***************************/
1172
1173 /**
1174 * Compares the users with the given flags
1175 *
1176 * @param array options that should be taking into account to compare the users
1177 * @return string the content
1178 */
1179 function compareUsers($compareFlags) {
1180 // Menu:
1181 $options = array(
1182 'filemounts' => $GLOBALS['LANG']->getLL('filemounts', TRUE),
1183 'webmounts' => $GLOBALS['LANG']->getLL('webmounts', TRUE),
1184 'tempPath' => $GLOBALS['LANG']->getLL('defaultUploadPath', TRUE),
1185 'firstMainGroup' => $GLOBALS['LANG']->getLL('mainUserGroup', TRUE),
1186 'groupList' => $GLOBALS['LANG']->getLL('memberOfGroups', TRUE),
1187 'pagetypes_select' => $GLOBALS['LANG']->getLL('pageTypesAccess', TRUE),
1188 'tables_select' => $GLOBALS['LANG']->getLL('selectTables', TRUE),
1189 'tables_modify' => $GLOBALS['LANG']->getLL('modifyTables', TRUE),
1190 'non_exclude_fields' => $GLOBALS['LANG']->getLL('nonExcludeFields', TRUE),
1191 'explicit_allowdeny' => $GLOBALS['LANG']->getLL('explicitAllowDeny', TRUE),
1192 'allowed_languages' => $GLOBALS['LANG']->getLL('limitToLanguages', TRUE),
1193 'workspace_perms' => $GLOBALS['LANG']->getLL('workspacePermissions', TRUE),
1194 'workspace_membership' => $GLOBALS['LANG']->getLL('workspaceMembership', TRUE),
1195 'custom_options' => $GLOBALS['LANG']->getLL('customOptions', TRUE),
1196 'modules' => $GLOBALS['LANG']->getLL('modules', TRUE),
1197 'userTS' => $GLOBALS['LANG']->getLL('tsconfig', TRUE),
1198 'userTS_hl' => $GLOBALS['LANG']->getLL('tsconfigHL', TRUE),
1199 );
1200
1201 $be_user_uid = t3lib_div::_GP('be_user_uid');
1202 if ($be_user_uid) {
1203 // This is used to test with other users. Development ONLY!
1204 $tempBE_USER = t3lib_div::makeInstance('local_beUserAuth'); // New backend user object
1205 $tempBE_USER->userTS_dontGetCached=1;
1206 $tempBE_USER->OS = TYPO3_OS;
1207 $tempBE_USER->setBeUserByUid($be_user_uid);
1208 $tempBE_USER->fetchGroupData();
1209
1210 $uInfo = $tempBE_USER->ext_compileUserInfoForHash();
1211 $uInfo_dat = $tempBE_USER->ext_printOverview($uInfo, $options, 1);
1212
1213 $lines=array();
1214 foreach ($options as $kk => $vv) {
1215 $lines[]='<tr class="bgColor4">
1216 <td nowrap="nowrap" valign="top">'.$vv.':&nbsp;&nbsp;</td>
1217 <td>'.$uInfo_dat[$kk].'&nbsp;</td>
1218 </tr>';
1219
1220 if ($kk=='webmounts' && !$tempBE_USER->isAdmin()) {
1221 $lines[]='<tr class="bgColor4">
1222 <td nowrap="nowrap" valign="top">' . $GLOBALS['LANG']->getLL('nonMountedReadablePages', TRUE) . '&nbsp;&nbsp;</td>
1223 <td>'.$tempBE_USER->ext_getReadableButNonmounted().'&nbsp;</td>
1224 </tr>';
1225 }
1226 }
1227
1228 $email = htmlspecialchars($tempBE_USER->user['email']);
1229 $realname = htmlspecialchars($tempBE_USER->user['realName']);
1230 $outTable = '<table border="0" cellpadding="1" cellspacing="1"><tr class="bgColor5"><td>'.t3lib_iconWorks::getSpriteIconForRecord('be_users', $tempBE_USER->user, array('title'=>$tempBE_USER->user['uid'])).htmlspecialchars($tempBE_USER->user['username']).'</td>';
1231 $outTable.= '<td>'.($realname?$realname.', ':'').($email ? '<a href="mailto:'.$email.'">'.$email.'</a>' : '').'</td>';
1232 $outTable.= '<td>'.$this->elementLinks('be_users', $tempBE_USER->user).'</td></tr></table>';
1233 $outTable.= '<strong><a href="'.htmlspecialchars($this->MCONF['_']).'">' . $GLOBALS['LANG']->getLL('backToOverview', TRUE) . '</a></strong><br />';
1234
1235 $outTable.= '<br /><table border="0" cellpadding="2" cellspacing="1">'.implode('', $lines).'</table>';
1236 $content .= $this->doc->section($GLOBALS['LANG']->getLL('userInfo', TRUE), $outTable, FALSE, TRUE);
1237 } else {
1238 $menu = array(0 => array());
1239 $rowCounter = 0;
1240 $columnCounter = 0;
1241 $itemsPerColumn = ceil(count($options) / 3);
1242 foreach ($options as $kk => $vv) {
1243 if ($rowCounter == $itemsPerColumn) {
1244 $rowCounter = 0;
1245 $columnCounter++;
1246 $menu[$columnCounter] = array();
1247 }
1248 $rowCounter++;
1249 $menu[$columnCounter][]='<input type="checkbox" class="checkbox" value="1" name="compareFlags['.$kk.']" id="checkCompare_'.$kk.'"'.($compareFlags[$kk]?' checked="checked"':'').'> <label for="checkCompare_'.$kk.'">'.htmlspecialchars($vv).'</label>';
1250 }
1251 $outCode = '<p>' . $GLOBALS['LANG']->getLL('groupBy', TRUE) . '</p>';
1252 $outCode .= '<table border="0" cellpadding="3" cellspacing="1" class="compare-checklist valign-top"><tr>';
1253 foreach ($menu as $column) {
1254 $outCode .= '<td>' . implode('<br />', $column) . '</td>';
1255 }
1256 $outCode .= '</tr></table>';
1257 $outCode.='<br /><input type="submit" name="ads" value="' . $GLOBALS['LANG']->getLL('update', TRUE) . '">';
1258 $content = $this->doc->section($GLOBALS['LANG']->getLL('groupAndCompareUsers', TRUE), $outCode, FALSE, TRUE);
1259
1260 // Traverse all users
1261 $users = t3lib_BEfunc::getUserNames();
1262 $comparation=array();
1263 $counter=0;
1264
1265
1266 $offset=0;
1267 $numberAtTime=1000;
1268 $tooManyUsers='';
1269
1270 foreach ($users as $r) {
1271 if ($counter>=$offset) {
1272 // This is used to test with other users. Development ONLY!
1273 $tempBE_USER = t3lib_div::makeInstance('local_beUserAuth'); // New backend user object
1274 /* @var $tempBE_USER local_beUserAuth */
1275 $tempBE_USER->OS = TYPO3_OS;
1276 $tempBE_USER->setBeUserByUid($r['uid']);
1277 $tempBE_USER->fetchGroupData();
1278
1279 // Making group data
1280 $md5pre='';
1281 $menu=array();
1282 $uInfo = $tempBE_USER->ext_compileUserInfoForHash((array)$compareFlags);
1283 foreach ($options as $kk => $vv) {
1284 if ($compareFlags[$kk]) {
1285 $md5pre.=serialize($uInfo[$kk]).'|';
1286 }
1287 }
1288 // setting md5:
1289 $md5=md5($md5pre);
1290 if (!isset($comparation[$md5])) {
1291 $comparation[$md5]=$tempBE_USER->ext_printOverview($uInfo, $compareFlags);
1292 $comparation[$md5]['users']=array();
1293 }
1294 $comparation[$md5]['users'][]=$tempBE_USER->user;
1295 unset($tempBE_USER);
1296 }
1297 $counter++;
1298 if ($counter>=($numberAtTime+$offset)) {
1299 $tooManyUsers=$GLOBALS['LANG']->getLL('tooManyUsers', TRUE) . ' ' . count($users) . '. ' . $GLOBALS['LANG']->getLL('canOnlyDisplay', TRUE) . ' ' . $numberAtTime . '.';
1300 break;
1301 }
1302 }
1303
1304 // Print the groups:
1305 $allGroups=array();
1306 // Header:
1307 $allCells = array();
1308
1309 $allCells['USERS'] = '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td><strong>' . $GLOBALS['LANG']->getLL('usernames', TRUE) . '</strong></td></table>';
1310
1311 foreach ($options as $kk => $vv) {
1312 if ($compareFlags[$kk]) {
1313 $allCells[$kk] = '<strong>'.$vv.':</strong>';
1314 }
1315 }
1316 $allGroups[]=$allCells;
1317
1318 foreach ($comparation as $dat) {
1319 $allCells = array();
1320
1321 $curUid = $GLOBALS['BE_USER']->user['uid'];
1322 $uListArr=array();
1323
1324 foreach ($dat['users'] as $uDat) {
1325 $uItem = '<tr><td width="130">' . t3lib_iconWorks::getSpriteIconForRecord('be_users', $uDat, array('title'=> $uDat['uid'] )) . $this->linkUser($uDat['username'], $uDat) . '&nbsp;&nbsp;</td><td nowrap="nowrap">' . $this->elementLinks('be_users', $uDat);
1326 if ($curUid != $uDat['uid'] && !$uDat['disable'] && ($uDat['starttime'] == 0 ||
1327 $uDat['starttime'] < $GLOBALS['EXEC_TIME']) && ($uDat['endtime'] == 0 ||
1328 $uDat['endtime'] > $GLOBALS['EXEC_TIME'])) {
1329 $uItem .= '<a href="' . t3lib_div::linkThisScript(array('SwitchUser'=>$uDat['uid'])) . '" target="_top" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('switchUserTo', TRUE) . ' ' . $uDat['username']) . ' ' . $GLOBALS['LANG']->getLL('changeToMode', TRUE) . '">' .
1330 t3lib_iconWorks::getSpriteIcon('actions-system-backend-user-switch') .
1331 '</a>'.
1332 '<a href="' . t3lib_div::linkThisScript(array('SwitchUser'=>$uDat['uid'], 'switchBackUser' => 1)) . '" target="_top" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('switchUserTo', TRUE) . ' ' . $uDat['username']) . ' ' . $GLOBALS['LANG']->getLL('switchBackMode', TRUE) . '">' .
1333 t3lib_iconWorks::getSpriteIcon('actions-system-backend-user-emulate') .
1334 '</a>';
1335 }
1336 $uItem .= '</td></tr>';
1337 $uListArr[] = $uItem;
1338 }
1339 $allCells['USERS'] = '<table border="0" cellspacing="0" cellpadding="0" width="100%">'.implode('', $uListArr).'</table>';
1340
1341 foreach ($options as $kk => $vv) {
1342 if ($compareFlags[$kk]) {
1343 $allCells[$kk] = $dat[$kk];
1344 }
1345 }
1346 $allGroups[]=$allCells;
1347 }
1348
1349 // Make table
1350 $outTable='';
1351 $TDparams=' nowrap="nowrap" class="bgColor5" valign="top"';
1352 $i = 0;
1353 foreach ($allGroups as $allCells) {
1354 $outTable.='<tr><td'.$TDparams.'>'.implode('</td><td'.$TDparams.'>', $allCells).'</td></tr>';
1355 $TDparams=' nowrap="nowrap" class="'.($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6').'" valign="top"';
1356 }
1357 $outTable='<table border="0" cellpadding="2" cellspacing="2">' . $outTable . '</table>';
1358 $flashMessageCachedGrouplistsUpdated = t3lib_div::makeInstance(
1359 't3lib_FlashMessage',
1360 '',
1361 $GLOBALS['LANG']->getLL('cachedGrouplistsUpdated', TRUE),
1362 t3lib_FlashMessage::INFO
1363 );
1364 t3lib_FlashMessageQueue::addMessage($flashMessageCachedGrouplistsUpdated);
1365 if ($tooManyUsers) {
1366 $flashMessageTooManyUsers = t3lib_div::makeInstance(
1367 't3lib_FlashMessage',
1368 '',
1369 $tooManyUsers,
1370 t3lib_FlashMessage::ERROR
1371 );
1372 t3lib_FlashMessageQueue::addMessage($flashMessageTooManyUsers);
1373 }
1374 $content.= $this->doc->spacer(10);
1375 $content.= $this->doc->section($GLOBALS['LANG']->getLL('result', TRUE), $outTable, 0, 1);
1376 }
1377 return $content;
1378 }
1379
1380
1381 /**
1382 * Creates a HTML anchor to the user record
1383 *
1384 * @param string the string used to identify the user (inside the <a>...</a>)
1385 * @param array the BE user record to link
1386 * @return string the HTML anchor
1387 */
1388 function linkUser($str, $rec) {
1389 return '<a href="'.htmlspecialchars($this->MCONF['_']).'&be_user_uid='.$rec['uid'].'">' . htmlspecialchars($str) . '</a>';
1390 }
1391
1392
1393 /**
1394 * Builds a list of all links for a specific element (here: BE user) and returns it for print.
1395 *
1396 * @param string the db table that should be used
1397 * @param array the BE user record to use
1398 * @return string a HTML formatted list of the link
1399 */
1400 function elementLinks($table, $row) {
1401 // Info:
1402 $cells[]='<a href="#" onclick="top.launchView(\'' . $table . '\', \'' . $row['uid'] . '\',\'' . $GLOBALS['BACK_PATH'] . '\'); return false;" title="' . $GLOBALS['LANG']->getLL('showInformation', TRUE) . '">' .
1403 t3lib_iconWorks::getSpriteIcon('actions-document-info') .
1404 '</a>';
1405
1406 // Edit:
1407 $params='&edit[' . $table . '][' . $row['uid'] . ']=edit';
1408 $cells[]='<a href="#" onclick="' . t3lib_BEfunc::editOnClick($params, $GLOBALS['BACK_PATH'], '') . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:edit', TRUE) . '">' .
1409 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
1410 '</a>';
1411
1412 // Hide:
1413 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
1414 if ($row[$hiddenField]) {
1415 $params='&data[' . $table . '][' . $row['uid'] . '][' . $hiddenField . ']=0';
1416 $cells[]='<a href="' . $this->doc->issueCommand($params) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:enable', TRUE) . '">' .
1417 t3lib_iconWorks::getSpriteIcon('actions-edit-unhide') .
1418 '</a>';
1419 } else {
1420 $params='&data[' . $table . '][' . $row['uid'] . '][' . $hiddenField . ']=1';
1421 $cells[]='<a href="' . $this->doc->issueCommand($params) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disable', TRUE) . '">' .
1422 t3lib_iconWorks::getSpriteIcon('actions-edit-hide') .
1423 '</a>';
1424 }
1425
1426 // Delete
1427 $params='&cmd[' . $table . '][' . $row['uid'] . '][delete]=1';
1428 $cells[]='<a href="' . $this->doc->issueCommand($params) . '" onclick="return confirm(unescape(\'' . $GLOBALS['LANG']->getLL('sureToDelete', TRUE) . '\'));" title="' . $GLOBALS['LANG']->getLL('delete', TRUE) . '">' .
1429 t3lib_iconWorks::getSpriteIcon('actions-edit-delete') .
1430 '</a>';
1431
1432 return implode('', $cells);
1433 }
1434
1435
1436 /**
1437 * Inits all BE-users available, for development ONLY!
1438 *
1439 * @return void
1440 */
1441 function initUsers() {
1442 // Initializing all users in order to generate the usergroup_cached_list
1443 $users = t3lib_BEfunc::getUserNames();
1444
1445 // This is used to test with other users. Development ONLY!
1446 foreach ($users as $r) {
1447 $tempBE_USER = t3lib_div::makeInstance('local_beUserAuth'); // New backend user object
1448 /* @var $tempBE_USER local_beUserAuth */
1449 $tempBE_USER->OS = TYPO3_OS;
1450 $tempBE_USER->setBeUserByUid($r['uid']);
1451 $tempBE_USER->fetchGroupData();
1452 }
1453 }
1454
1455 /**
1456 * Returns the local path for this string (removes the PATH_site if it is included)
1457 *
1458 * @param string the path that will be checked
1459 * @return string the local path
1460 */
1461 function localPath($str) {
1462 if (substr($str, 0, strlen(PATH_site))==PATH_site) {
1463 return substr($str, strlen(PATH_site));
1464 } else {
1465 return $str;
1466 }
1467 }
1468
1469 /**
1470 * Switches to a given user (SU-mode) and then redirects to the start page of the backend to refresh the navigation etc.
1471 *
1472 * @param array BE-user record that will be switched to
1473 * @return void
1474 */
1475 function switchUser($switchUser) {
1476 $uRec=t3lib_BEfunc::getRecord('be_users', $switchUser);
1477 if (is_array($uRec) && $GLOBALS['BE_USER']->isAdmin()) {
1478 $updateData['ses_userid'] = $uRec['uid'];
1479 // user switchback
1480 if (t3lib_div::_GP('switchBackUser')) {
1481 $updateData['ses_backuserid'] = intval($GLOBALS['BE_USER']->user['uid']);
1482 }
1483 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_sessions', 'ses_id=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['BE_USER']->id, 'be_sessions') . ' AND ses_name=' . $GLOBALS['TYPO3_DB']->fullQuoteStr(t3lib_beUserAuth::getCookieName(), 'be_sessions') . ' AND ses_userid=' . intval($GLOBALS['BE_USER']->user['uid']), $updateData);
1484
1485 $redirectUrl = $GLOBALS['BACK_PATH'] . 'index.php' . ($GLOBALS['TYPO3_CONF_VARS']['BE']['interfaces'] ? '' : '?commandLI=1');
1486 t3lib_utility_Http::redirect($redirectUrl);
1487 }
1488 }
1489
1490 /***************************
1491 *
1492 * "WHO IS ONLINE" FUNCTIONS:
1493 *
1494 ***************************/
1495
1496 /**
1497 * @author Martin Kutschker
1498 */
1499 function whoIsOnline() {
1500 $select_fields = 'ses_id, ses_tstamp, ses_iplock, u.uid,u.username, u.admin, u.realName, u.disable, u.starttime, u.endtime, u.deleted, bu.uid AS bu_uid,bu.username AS bu_username, bu.realName AS bu_realName';
1501 $from_table = 'be_sessions INNER JOIN be_users u ON ses_userid=u.uid LEFT OUTER JOIN be_users bu ON ses_backuserid=bu.uid';
1502 $where_clause = '';
1503 $orderBy = 'u.username';
1504
1505 $timeout = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout']);
1506 if ($timeout > 0) {
1507 $where_clause = 'ses_tstamp > ' . ($GLOBALS['EXEC_TIME'] - $timeout);
1508 }
1509
1510 // Fetch active sessions of other users from storage:
1511 $sessions = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($select_fields, $from_table, $where_clause, '', $orderBy);
1512 // Process and visualized each active session as a table row:
1513 if (is_array($sessions)) {
1514 foreach ($sessions as $session) {
1515 $ip = $session['ses_iplock'];
1516 $hostName = '';
1517 if ($session['ses_iplock'] == '[DISABLED]' || $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'] == 0) {
1518 $ip = '-';
1519 } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'] == 4) {
1520 $hostName = ' title="' . @gethostbyaddr($session['ses_iplock']) . '"';
1521 } else {
1522 $ip .= str_repeat('.*', 4-$GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP']);
1523 }
1524 $outTable .= '
1525 <tr class="bgColor4" height="17" valign="top">' .
1526 '<td nowrap="nowrap">' .
1527 t3lib_BEfunc::datetime($session['ses_tstamp']) .
1528 '</td>' .
1529 '<td nowrap="nowrap">' .
1530 '<span'.$hostName.'>'.$ip.'</span>' .
1531 '</td>' .
1532 '<td width="130">' .
1533 t3lib_iconWorks::getSpriteIconForRecord('be_users', $session, array('title'=>$session['uid'])).htmlspecialchars($session['username']).'&nbsp;' .
1534 '</td>' .
1535 '<td nowrap="nowrap">'.htmlspecialchars($session['realName']).'&nbsp;&nbsp;</td>' .
1536 '<td nowrap="nowrap">'.$this->elementLinks('be_users', $session).'</td>' .
1537 '<td nowrap="nowrap" valign="top">'.($session['bu_username'] ? '&nbsp;SU from: ' : '').htmlspecialchars($session['bu_username']).'&nbsp;</td>' .
1538 '<td nowrap="nowrap" valign="top">&nbsp;'.htmlspecialchars($session['bu_realName']).'</td>' .
1539 '</tr>';
1540 }
1541 }
1542 // Wrap <table> tag around the rows:
1543 $outTable = '
1544 <table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">
1545 <tr class="t3-row-header">
1546 <td>' . $GLOBALS['LANG']->getLL('timestamp', TRUE) . '</td>
1547 <td>' . $GLOBALS['LANG']->getLL('host', TRUE) . '</td>
1548 <td colspan="5">' . $GLOBALS['LANG']->getLL('username', TRUE) . '</td>
1549 </tr>' . $outTable . '
1550 </table>';
1551
1552 $content .= $this->doc->section($GLOBALS['LANG']->getLL('whoIsOnline', TRUE), $outTable, FALSE, TRUE);
1553 return $content;
1554 }
1555
1556 }
1557
1558 // Make instance:
1559 $SOBE = t3lib_div::makeInstance('SC_mod_tools_be_user_index');
1560 $SOBE->init();
1561 $SOBE->main();
1562 $SOBE->printContent();
1563
1564 ?>