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