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