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