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