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