ec01b6169b99e0cfc6cf1de51db158079e8ed5c1
[Packages/TYPO3.CMS.git] / typo3 / mod / user / ws / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2007 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Module: Workspace manager
29 *
30 * $Id$
31 *
32 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
33 * @author Dmitry Dulepov <typo3@accio.lv>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 101: class SC_mod_user_ws_index extends t3lib_SCbase
41 *
42 * SECTION: Standard module initialization
43 * 128: function menuConfig()
44 * 175: function init()
45 * 233: function main()
46 * 280: function printContent()
47 *
48 * SECTION: Module content: Publish
49 * 310: function moduleContent_publish()
50 * 411: function displayVersionDetails($details)
51 * 420: function displayWorkspaceOverview()
52 *
53 * SECTION: Module content: Workspace list
54 * 461: function moduleContent_workspaceList()
55 * 476: function workspaceList_displayUserWorkspaceList()
56 * 553: function workspaceList_getUserWorkspaceList()
57 * 592: function workspaceList_formatWorkspaceData(&$wksp)
58 * 634: function workspaceList_getWebMountPoints(&$wksp)
59 * 683: function workspaceList_getFileMountPoints(&$wksp)
60 * 736: function workspaceList_displayUserWorkspaceListHeader()
61 * 756: function workspaceList_getUserList(&$wksp)
62 * 783: function workspaceList_getUserListForSysWorkspace(&$wksp)
63 * 810: function workspaceList_getUserListWithAccess(&$list, $access)
64 * 883: function workspaceList_displayIcons($currentWorkspace, &$wksp)
65 * 931: function workspaceList_hasEditAccess(&$wksp)
66 * 943: function workspaceList_createFakeWorkspaceRecord($uid)
67 *
68 * TOTAL FUNCTIONS: 20
69 * (This index is automatically created/updated by the extension "extdeveval")
70 *
71 */
72
73
74 // Initialize module:
75 unset($MCONF);
76 require ('conf.php');
77 require ($BACK_PATH.'init.php');
78 require ($BACK_PATH.'template.php');
79 $BE_USER->modAccess($MCONF,1);
80
81 // Include libraries of various kinds used inside:
82 $LANG->includeLLFile('EXT:lang/locallang_mod_user_ws.xml');
83 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
84 require_once(PATH_t3lib.'class.t3lib_scbase.php');
85 require_once(PATH_typo3.'mod/user/ws/class.wslib.php');
86 require_once(PATH_typo3.'mod/user/ws/class.wslib_gui.php');
87 require_once(PATH_t3lib.'class.t3lib_diff.php');
88 require_once(PATH_t3lib.'class.t3lib_pagetree.php');
89 require_once(PATH_t3lib.'class.t3lib_tcemain.php');
90
91
92
93
94 /**
95 * Module: Workspace manager
96 *
97 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
98 * @package TYPO3
99 * @subpackage core
100 */
101 class SC_mod_user_ws_index extends t3lib_SCbase {
102
103 // Default variables for backend modules
104 var $MCONF = array(); // Module configuration
105 var $MOD_MENU = array(); // Module menu items
106 var $MOD_SETTINGS = array(); // Module session settings
107
108 /**
109 * Document Template Object
110 *
111 * @var noDoc
112 */
113 var $doc;
114 var $content; // Accumulated content
115
116
117 // Internal:
118 var $publishAccess = FALSE;
119 var $be_user_Array = array();
120 var $be_user_Array_full = array(); // not blinded, used by workspace listing
121
122
123 /*********************************
124 *
125 * Standard module initialization
126 *
127 *********************************/
128
129 /**
130 * Initialize menu configuration
131 *
132 * @return void
133 */
134 function menuConfig() {
135 global $LANG;
136
137 // Menu items:
138 $this->MOD_MENU = array(
139 'function' => array(
140 'publish' => $LANG->getLL('menuitem_review'),
141 'workspaces' => $LANG->getLL('menuitem_workspaces'),
142 ),
143 'filter' => array(
144 1 => $LANG->getLL('filter_drafts'),
145 2 => $LANG->getLL('filter_archive'),
146 0 => $LANG->getLL('filter_all'),
147 ),
148 'display' => array(
149 0 => '['.$LANG->getLL('shortcut_onlineWS').']',
150 -98 => $LANG->getLL('label_offlineWSes'),
151 -99 => $LANG->getLL('label_allWSes'),
152 -1 => '['.$LANG->getLL('shortcut_offlineWS').']'
153 ),
154 'diff' => array(
155 0 => $LANG->getLL('diff_no_diff'),
156 1 => $LANG->getLL('diff_show_inline'),
157 2 => $LANG->getLL('diff_show_popup'),
158 ),
159 'expandSubElements' => '',
160 );
161
162 // Add workspaces:
163 if ($GLOBALS['BE_USER']->workspace===0) { // Spend time on this only in online workspace because it might take time:
164 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
165 foreach($workspaces as $rec) {
166 if ($GLOBALS['BE_USER']->checkWorkspace($rec)) {
167 $this->MOD_MENU['display'][$rec['uid']] = '['.$rec['uid'].'] '.$rec['title'];
168 }
169 }
170 }
171
172 // CLEANSE SETTINGS
173 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name'], 'ses');
174 }
175
176 /**
177 * Executes action for selected elements, if any is sent:
178 */
179 function execute() {
180 $post = t3lib_div::_POST();
181
182 # debug($post);
183
184 if ($post['_with_selected_do']) {
185 if (is_array($post['items']) && count($post['items'])) {
186 $cmdArray = array();
187
188 foreach($post['items'] as $item => $v) {
189 list($table,$uid) = explode(':',$item,2);
190
191 if ($GLOBALS['TCA'][$table] && t3lib_div::testInt($uid)) {
192 switch($post['_with_selected_do']) {
193 case "stage_-1":
194 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
195 $cmdArray[$table][$uid]['version']['stageId'] = -1;
196 break;
197 case "stage_0":
198 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
199 $cmdArray[$table][$uid]['version']['stageId'] = 0;
200 break;
201 case "stage_1":
202 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
203 $cmdArray[$table][$uid]['version']['stageId'] = 1;
204 break;
205 case "stage_10":
206 $cmdArray[$table][$uid]['version']['action'] = 'setStage';
207 $cmdArray[$table][$uid]['version']['stageId'] = 10;
208 break;
209 case "publish":
210 if ($onlineRec = t3lib_BEfunc::getLiveVersionOfRecord($table,$uid,'uid')) {
211 $cmdArray[$table][$onlineRec['uid']]['version']['action'] = 'swap';
212 $cmdArray[$table][$onlineRec['uid']]['version']['swapWith'] = $uid;
213 }
214 break;
215 case "swap":
216 if ($onlineRec = t3lib_BEfunc::getLiveVersionOfRecord($table,$uid,'uid')) {
217 $cmdArray[$table][$onlineRec['uid']]['version']['action'] = 'swap';
218 $cmdArray[$table][$onlineRec['uid']]['version']['swapWith'] = $uid;
219 $cmdArray[$table][$onlineRec['uid']]['version']['swapIntoWS'] = 1;
220 }
221 break;
222 case "release":
223 $cmdArray[$table][$uid]['version']['action'] = 'clearWSID';
224 break;
225 case "flush":
226 $cmdArray[$table][$uid]['version']['action'] = 'flush';
227 break;
228 }
229 }
230 }
231
232 # debug($cmdArray);
233
234 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
235 $tce->stripslashes_values = 0;
236 $tce->start(array(), $cmdArray);
237 $tce->process_cmdmap();
238 }
239 }
240 }
241
242 /**
243 * Standard init function of a module.
244 *
245 * @return void
246 */
247 function init() {
248 global $BACK_PATH, $BE_USER;
249
250 // Setting module configuration:
251 $this->MCONF = $GLOBALS['MCONF'];
252
253 // Initialize Document Template object:
254 $this->doc = t3lib_div::makeInstance('noDoc');
255 $this->doc->backPath = $BACK_PATH;
256 $this->doc->docType = 'xhtml_trans';
257
258 // JavaScript
259 $plusIcon = t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/ol/plusbullet.gif', 'width="18" height="16"', 1);
260 $minusIcon = t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/ol/minusbullet.gif', 'width="18" height="16"', 1);
261 $this->doc->JScode = $this->doc->wrapScriptTags('
262 script_ended = 0;
263 function jumpToUrl(URL) { //
264 window.location.href = URL;
265 }
266
267 function expandCollapse(rowNumber) { //
268 elementId = \'wl_\' + rowNumber;
269 element = document.getElementById(elementId);
270 image = document.getElementById(elementId + \'i\');
271 if (element.style) {
272 if (element.style.display == \'none\') {
273 element.style.display = \'\';
274 image.src = \'' . $minusIcon . '\';
275 } else {
276 element.style.display = \'none\';
277 image.src = \'' . $plusIcon . '\';
278 }
279 }
280 }
281 ');
282 $this->doc->form = '<form action="index.php" method="post" name="pageform">';
283
284 // Setting up the context sensitive menu:
285 $this->doc->getContextMenuCode();
286
287 // Add JS for dynamic tabs:
288 $this->doc->JScode.= $this->doc->getDynTabMenuJScode();
289
290 // Setting publish access permission for workspace:
291 $this->publishAccess = $BE_USER->workspacePublishAccess($BE_USER->workspace);
292
293 // Parent initialization:
294 parent::init();
295 }
296
297 /**
298 * Main function for Workspace Manager module.
299 *
300 * @return void
301 */
302 function main() {
303 global $LANG, $BE_USER, $BACK_PATH;
304
305 // See if we need to switch workspace
306 $changeWorkspace = t3lib_div::_GET('changeWorkspace');
307 if ($changeWorkspace != '') {
308 $BE_USER->setWorkspace($changeWorkspace);
309 $this->content = $this->doc->startPage($LANG->getLL('title'));
310 $this->content .= $this->doc->wrapScriptTags('top.location.href="' . $BACK_PATH . 'alt_main.php";');
311 }
312 else {
313 // Starting page:
314 $this->content.=$this->doc->startPage($LANG->getLL('title'));
315 $this->content.=$this->doc->header($LANG->getLL('title'));
316 $this->content.=$this->doc->spacer(5);
317
318 // Get usernames and groupnames
319 $be_group_Array = t3lib_BEfunc::getListGroupNames('title,uid');
320 $groupArray = array_keys($be_group_Array);
321 // Need 'admin' field for t3lib_iconWorks::getIconImage()
322 $this->be_user_Array_full = $this->be_user_Array = t3lib_BEfunc::getUserNames('username,usergroup,usergroup_cached_list,uid,admin,workspace_perms');
323 if (!$GLOBALS['BE_USER']->isAdmin()) {
324 $this->be_user_Array = t3lib_BEfunc::blindUserNames($this->be_user_Array,$groupArray,1);
325 }
326
327 // Build top menu:
328 $menuItems = array();
329 $menuItems[] = array(
330 'label' => $LANG->getLL('menuitem_review'),
331 'content' => $this->moduleContent_publish()
332 );
333 $menuItems[] = array(
334 'label' => $LANG->getLL('menuitem_workspaces'),
335 'content' => $this->moduleContent_workspaceList()
336 );
337
338 // Add hidden fields and create tabs:
339 $content = $this->doc->getDynTabMenu($menuItems,'user_ws');
340 $this->content.=$this->doc->section('',$content,0,1);
341 }
342 }
343
344 /**
345 * Print module content. Called as last thing in the global scope.
346 *
347 * @return void
348 */
349 function printContent() {
350 global $SOBE;
351
352 $this->content.= $this->doc->endPage();
353 echo $this->content;
354 }
355
356
357
358
359
360
361
362
363
364
365
366
367
368 /*********************************
369 *
370 * Module content: Publish
371 *
372 *********************************/
373
374 /**
375 * Rendering the content for the publish and review panel in the workspace manager
376 *
377 * @return string HTML content
378 */
379 function moduleContent_publish() {
380 global $LANG;
381
382 // Initialize:
383 $content = '';
384 $details = t3lib_div::_GP('details');
385
386 // Create additional menus:
387 $menu = '';
388 if ($GLOBALS['BE_USER']->workspace===0) {
389 $menu.= t3lib_BEfunc::getFuncMenu(0,'SET[filter]',$this->MOD_SETTINGS['filter'],$this->MOD_MENU['filter']);
390 $menu.= t3lib_BEfunc::getFuncMenu(0,'SET[display]',$this->MOD_SETTINGS['display'],$this->MOD_MENU['display']);
391 }
392 $menu.= t3lib_BEfunc::getFuncMenu(0,'SET[diff]',$this->MOD_SETTINGS['diff'],$this->MOD_MENU['diff']);
393 if ($GLOBALS['BE_USER']->workspace!==0) {
394 $menu.= t3lib_BEfunc::getFuncCheck(0,'SET[expandSubElements]',$this->MOD_SETTINGS['expandSubElements'],'','','id="checkExpandSubElements"').' <label for="checkExpandSubElements">'.$LANG->getLL('label_showsubelements').'</label> ';
395 }
396
397 // Create header:
398 $title = '';
399 $description = '';
400 switch($GLOBALS['BE_USER']->workspace) {
401 case 0:
402 $title = t3lib_iconWorks::getIconImage('sys_workspace', array(), $this->doc->backPath, ' align="top"').'['.$LANG->getLL('shortcut_onlineWS').']';
403 $description = $LANG->getLL('workspace_description_live');
404 break;
405 case -1:
406 $title = t3lib_iconWorks::getIconImage('sys_workspace', array(), $this->doc->backPath, ' align="top"').'['.$LANG->getLL('shortcut_offlineWS').']';
407 $description = $LANG->getLL('workspace_description_draft');
408 break;
409 case -99:
410 $title = $this->doc->icons(3).'[' . $LANG->getLL('shortcut_noWSfound') . ']';
411 $description = $LANG->getLL('workspace_description_no_access');
412 break;
413 default:
414 $title = t3lib_iconWorks::getIconImage('sys_workspace', $GLOBALS['BE_USER']->workspaceRec, $this->doc->backPath, ' align="top"').
415 '['.$GLOBALS['BE_USER']->workspace.'] '.t3lib_BEfunc::getRecordTitle('sys_workspace',$GLOBALS['BE_USER']->workspaceRec,TRUE);
416 $description = ($GLOBALS['BE_USER']->workspaceRec['description'] ? htmlspecialchars($GLOBALS['BE_USER']->workspaceRec['description']) : '<em>[' . $LANG->getLL('shortcut_noWSfound') . ']</em>');
417 break;
418 }
419
420 // Buttons for publish / swap:
421 $actionLinks = '';
422 if ($GLOBALS['BE_USER']->workspace!==0) {
423 if ($this->publishAccess) {
424 $confirmation = $LANG->JScharCode($LANG->getLL(($GLOBALS['BE_USER']->workspaceRec['publish_access'] & 1) ? 'submit_publish_workspace_confirmation_1' : 'submit_publish_workspace_confirmation_2'));
425 $actionLinks.= '<input type="submit" name="_publish" value="' . $LANG->getLL('submit_publish_workspace') . '" onclick="if (confirm(' . $confirmation . ')) window.location.href=\'publish.php?swap=0\';return false"/>';
426 if ($GLOBALS['BE_USER']->workspaceSwapAccess()) {
427 $confirmation = $LANG->JScharCode($LANG->getLL(($GLOBALS['BE_USER']->workspaceRec['publish_access'] & 1) ? 'submit_swap_workspace_confirmation_1' : 'submit_swap_workspace_confirmation_2'));
428 $actionLinks.= '<input type="submit" name="_swap" value="' . $LANG->getLL('submit_swap_workspace') . '" onclick="if (confirm(' . $confirmation . ')) window.location.href=\'publish.php?swap=1\';return false ;" />';
429 }
430 } else {
431 $actionLinks.= $this->doc->icons(1) . $LANG->getLL('no_publish_permission');
432 }
433
434 // Preview of workspace link
435 if (t3lib_div::_POST('_previewLink')) {
436 $previewUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev='.t3lib_BEfunc::compilePreviewKeyword('', $GLOBALS['BE_USER']->user['uid'],60*60*24*2,$GLOBALS['BE_USER']->workspace);
437 $actionLinks.= '<br/>Any user can browse the workspace frontend using this link for the next 48 hours (does not require backend login):<br/><br/><a target="_blank" href="'.htmlspecialchars($previewUrl).'">'.$previewUrl.'</a>';
438 } else {
439 $actionLinks.= '<input type="submit" name="_previewLink" value="Generate Workspace Preview Link" />';
440 }
441 }
442
443 $wsAccess = $GLOBALS['BE_USER']->checkWorkspace($GLOBALS['BE_USER']->workspaceRec);
444
445 // Add header to content variable:
446 $content = '
447 <table border="0" cellpadding="1" cellspacing="1" class="lrPadding" style="border: 1px solid black;">
448 <tr>
449 <td class="bgColor2" nowrap="nowrap"><b>' . $LANG->getLL('label_workspace') . '</b>&nbsp;</td>
450 <td class="bgColor4" nowrap="nowrap">'.$title.'</td>
451 </tr>
452 <tr>
453 <td class="bgColor2" nowrap="nowrap"><b>' . $LANG->getLL('label_description') . '</b>&nbsp;</td>
454 <td class="bgColor4">'.$description.'</td>
455 </tr>'.($GLOBALS['BE_USER']->workspace!=-99 && !$details ? '
456 <tr>
457 <td class="bgColor2" nowrap="nowrap"><b>' . $LANG->getLL('label_options') . '</b>&nbsp;</td>
458 <td class="bgColor4">'.$menu.$actionLinks.'</td>
459 </tr>
460 <tr>
461 <td class="bgColor2" nowrap="nowrap"><b>' . $LANG->getLL('label_status') . '</b>&nbsp;</td>
462 <td class="bgColor4">'.$LANG->getLL('label_access_level').' ' . $GLOBALS['LANG']->getLL('workspace_list_access_' . $wsAccess['_ACCESS']) . '</td>
463 </tr>' : '').'
464 </table>
465 <br/>
466 ';
467
468 // Add publishing and review overview:
469 if ($GLOBALS['BE_USER']->workspace!=-99) {
470 if ($details) {
471 $content.= $this->displayVersionDetails($details);
472 } else {
473 $content.= $this->displayWorkspaceOverview();
474 }
475 $content.='<br/>';
476 }
477
478 // Return content:
479 return $content;
480 }
481
482 /**
483 * Display details for a single version from workspace
484 *
485 * @param string Version identification, made of table and uid
486 * @return string HTML string
487 */
488 function displayVersionDetails($details) {
489 return 'TODO: Show details for version "'.$details.'"<hr/><a href="index.php">BACK</a>';
490 }
491
492 /**
493 * Rendering the overview of versions in the current workspace
494 *
495 * @return string HTML (table)
496 */
497 function displayWorkspaceOverview() {
498
499 // Initialize Workspace ID and filter-value:
500 if ($GLOBALS['BE_USER']->workspace===0) {
501 $wsid = $this->MOD_SETTINGS['display']; // Set wsid to the value from the menu (displaying content of other workspaces)
502 $filter = $this->MOD_SETTINGS['filter'];
503 } else {
504 $wsid = $GLOBALS['BE_USER']->workspace;
505 $filter = 0;
506 }
507
508 // Instantiate workspace GUI library and generate workspace overview
509 $wslibGuiObj = t3lib_div::makeInstance('wslib_gui');
510 $wslibGuiObj->diff = $this->MOD_SETTINGS['diff'];
511 $wslibGuiObj->expandSubElements = $this->MOD_SETTINGS['expandSubElements'];
512 $wslibGuiObj->alwaysDisplayHeader = true;
513 return $wslibGuiObj->getWorkspaceOverview($this->doc, $wsid, $filter);
514 }
515
516
517
518
519
520
521
522
523
524
525
526
527
528 /********************************
529 *
530 * Module content: Workspace list
531 *
532 ********************************/
533
534 /**
535 * Rendering of the workspace list
536 *
537 * @return string HTML
538 */
539 function moduleContent_workspaceList() {
540 // Original Kasper's TODO: Workspace listing
541 //
542 // - LISTING: Shows list of available workspaces for user. Used can see title, description, publication time, freeze-state, db-mount, member users/groups etc. Current workspace is indicated.
543 // - SWITCHING: Switching between available workspaces is done by a button shown for each in the list
544 // - ADMIN: Administrator of a workspace can click an edit-button linking to a form where he can edit the workspace. Users and groups should be selected based on some filtering so he cannot select groups he is not a member off himself (or some other rule... like for permission display with blinded users/groups)
545 // - CREATE: If allowed, the user can create a new workspace which brings up a form where he can enter basic data. This is saved by a local instance of tcemain with forced admin-rights (creation in pid=0!).
546 return $this->workspaceList_displayUserWorkspaceList();
547 }
548
549 /**
550 * Generates HTML to display a list of workspaces.
551 *
552 * @return string Generated HTML code
553 */
554 function workspaceList_displayUserWorkspaceList() {
555 global $BACK_PATH, $LANG;
556
557 // table header
558 $content = $this->workspaceList_displayUserWorkspaceListHeader();
559
560 // get & walk workspace list generating content
561 $wkspList = $this->workspaceList_getUserWorkspaceList();
562 $rowNum = 1;
563 foreach ($wkspList as $wksp) {
564 $currentWksp = ($GLOBALS['BE_USER']->workspace == $wksp['uid']);
565
566 // Each workspace data occupies two rows:
567 // (1) Folding + Icons + Title + Description
568 // (2) Information about workspace (initially hidden)
569
570 $cssClass = ($currentWksp ? 'bgColor3' : 'bgColor4');
571 // Start first row
572 $content .= '<tr class="' . $cssClass . '">';
573
574 // row #1, column #1: expand icon
575 $content .= '<td>' .
576 '<a href="javascript:expandCollapse(' . $rowNum . ')">' .
577 '<img ' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/ol/plusbullet.gif', 'width="18" height="16"') . ' id="wl_' . $rowNum . 'i" border="0" hspace="1" alt="' . $LANG->getLL('img_title_show_more') . '" />' .
578 '</a></td>';
579
580 // row #1, column #2: icon panel
581 $content .= '<td nowrap="nowrap">'; // Mozilla Firefox will attempt wrap due to `width="1"` on topmost column
582 $content .= $this->workspaceList_displayIcons($currentWksp, $wksp);
583 $content .= '</td>';
584
585 // row #1, column #3: current workspace indicator
586 $content .= '<td nowrap="nowrap" style="text-align: center">'; // Mozilla Firefox will attempt wrap due to `width="1"` on topmost column
587 $content .= (!$currentWksp ? '&nbsp;' : '<img ' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/icon_ok.gif', 'width="18" height="16"') . ' id="wl_' . $rowNum . 'i" border="0" hspace="1" alt="' . $LANG->getLL('img_title_current_workspace') . '" />');
588 $content .= '</td>';
589
590 // row #1, column #4 and 5: title and description
591 $content .= '<td nowrap="nowrap">' . $wksp['title'] . '</td>' .
592 '<td>' . nl2br($wksp['description']) . '</td>';
593 $content .= '</tr>';
594
595 // row #2, column #1 and #2
596 $content .= '<tr id="wl_' . $rowNum . '" class="bgColor" style="display: none">';
597 $content .= '<td colspan="2" style="border-right: none;">&nbsp;</td>';
598
599 // row #2, column #3, #4 and #4
600 $content .= '<td colspan="3" style="border-left: none;">' .
601 $this->workspaceList_formatWorkspaceData($wksp) .
602 '</td>';
603
604 $content .= '</tr>';
605 $rowNum++;
606 }
607 $content .= '</table>';
608
609 $newWkspUrl = 'workspaceforms.php?action=new';
610
611 // workspace creation link
612 if ($GLOBALS['BE_USER']->isAdmin() || 0 != ($GLOBALS['BE_USER']->groupData['workspace_perms'] & 4)) {
613 $content .= '<br /><a href="' . $newWkspUrl . '">' .
614 '<img ' .
615 t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/new_el.gif', 'width="11" height="12"') .
616 ' alt="' . $LANG->getLL('img_title_create_new_workspace'). '" id="ver-wl-new-workspace-icon" />' .
617 $LANG->getLL('link_text_create_new_workspace') . '</a>';
618 }
619 return $content;
620 }
621
622
623
624
625
626 /**
627 * Retrieves a list of workspaces where user has access.
628 *
629 * @return array A list of workspaces available to the current BE user
630 */
631 function workspaceList_getUserWorkspaceList() {
632
633 // Get list of all workspaces. Note: system workspaces will be always displayed before custom ones!
634 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
635 $availableWorkspaces = array();
636
637 // Live
638 $wksp = $this->workspaceList_createFakeWorkspaceRecord(0);
639 $wksp = $GLOBALS['BE_USER']->checkWorkspace($wksp);
640 if (false !== $wksp) {
641 $availableWorkspaces[] = $wksp;
642 }
643
644 // Draft
645 $wksp = $this->workspaceList_createFakeWorkspaceRecord(-1);
646 $wksp = $GLOBALS['BE_USER']->checkWorkspace($wksp);
647 if (false !== $wksp) {
648 $availableWorkspaces[] = $wksp;
649 }
650
651 // Custom
652 foreach($workspaces as $rec) {
653 // see if user can access this workspace in any way
654 if (false !== ($result = $GLOBALS['BE_USER']->checkWorkspace($rec))) {
655 $availableWorkspaces[] = $result; // `$result` contains `$rec` plus access type through '_ACCESS' key
656 }
657 }
658 return $availableWorkspaces;
659 }
660
661 /**
662 * Create inner information panel for workspace list. This panel is
663 * initially hidden and becomes visible when user click on the expand
664 * icon on the very left of workspace list against the workspace he
665 * wants to explore.
666 *
667 * @param array Workspace information
668 * @return string Formatted workspace information
669 */
670 function workspaceList_formatWorkspaceData(&$wksp) {
671 global $LANG;
672
673 $content = '<table cellspacing="1" cellpadding="1" width="100%" class="ver-wl-details-table">' .
674 '<tr><td class="ver-wl-details-label"><b>' . $LANG->getLL('workspace_list_label_file_mountpoints') . '</b></td>' .
675 '<td class="ver-wl-details">' . $this->workspaceList_getFileMountPoints($wksp) . '</td></tr>' .
676 '<tr><td class="ver-wl-details-label"><b>' . $LANG->getLL('workspace_list_label_db_mountpoints') . '</b></td>' .
677 '<td class="ver-wl-details">' . $this->workspaceList_getWebMountPoints($wksp) . '</td></tr>';
678 if ($wksp['uid'] > 0) {
679 // Displaying information below makes sence only for custom workspaces
680 $content .=
681 '<tr><td class="ver-wl-details-label"><b>' . $LANG->getLL('workspace_list_label_frozen') . '</b></td>' .
682 '<td class="ver-wl-details">' . $LANG->getLL($wksp['freeze'] ? 'workspace_list_label_frozen_yes' : 'workspace_list_label_frozen_no') . '</td></tr>' .
683 '<tr><td class="ver-wl-details-label"><b>' . $LANG->getLL('workspace_list_label_publish_date') . '</b></td>' .
684 '<td class="ver-wl-details">' . ($wksp['publish_time'] == 0 ? '&nbsp;&ndash;' : t3lib_BEfunc::datetime($wksp['publish_time'])) . '</td></tr>' .
685 '<tr><td class="ver-wl-details-label"><b>' . $LANG->getLL('workspace_list_label_unpublish_date') . '</b></td>' .
686 '<td class="ver-wl-details">' . ($wksp['unpublish_time'] == 0 ? '&nbsp;&ndash;' : t3lib_BEfunc::datetime($wksp['unpublish_time'])) . '</td></tr>' .
687 '<tr><td class="ver-wl-details-label"><b>' . $LANG->getLL('workspace_list_label_your_access') . '</b></td>' .
688 '<td class="ver-wl-details">' . $LANG->getLL('workspace_list_access_' . $wksp['_ACCESS']) . '</td></tr>' .
689 '<tr><td class="ver-wl-details-label"><b>' . $LANG->getLL('workspace_list_label_workspace_users') . '</b></td>' .
690 '<td class="ver-wl-details">' . $this->workspaceList_getUserList($wksp) . '</td></tr>';
691 }
692 else if ($GLOBALS['BE_USER']->isAdmin()) {
693 // show users for draft/live workspace only to admin users
694 $content .= '<tr><td class="ver-wl-details-label"><b>' . $LANG->getLL('workspace_list_label_workspace_users') . '</b></td>' .
695 '<td class="ver-wl-details">' . $this->workspaceList_getUserList($wksp) . '</td></tr>';
696 }
697 $content .= '</table>';
698
699 return $content;
700 }
701
702
703
704
705
706 /**
707 * Retrieves and formats database mount points lists.
708 *
709 * @param array &$wksp Workspace record
710 * @return string Generated HTML
711 */
712 function workspaceList_getWebMountPoints(&$wksp) {
713 if ($wksp['uid'] <= 0) {
714 // system workspaces
715 return $GLOBALS['LANG']->getLL($wksp['uid'] == 0 ? 'workspace_list_db_mount_point_live' : 'workspace_list_db_mount_point_draft');
716 }
717
718 // here only if obtaining mount points for custom workspaces
719
720 // Warning: all fields needed for t3lib_iconWorks::getIconImage()!
721 $MPs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'pages', 'deleted=0 AND uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($wksp['db_mountpoints']) . ')', '', 'title');
722 $content_array = array();
723 if (count($MPs) > 0) {
724 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
725 if (!$isAdmin) {
726 // We need to fetch user's mount point list (including MPS mounted from groups).
727 // This list must not be affects by current user's workspace. It means we cannot use
728 // $BE_USER->isInWebMount() to check mount points.
729 $userMPs = explode(',', $GLOBALS['BE_USER']->dataLists['webmount_list']); // includes group data if necessary!
730 }
731 foreach ($MPs as $mp) {
732 if (!$isAdmin && !in_array($mp['uid'], $userMPs)) {
733 // Show warning icon
734 $title = $GLOBALS['LANG']->getLL('workspace_list_mount_point_inaccessible');
735 $str = '<img ' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning.gif', 'width="18" height="16"') .
736 ' alt="' . $title . '" title="' . $title . '" align="absmiddle" />';
737 $classAttr = 'class="ver-wl-mp-inacessible" ';
738 }
739 else {
740 // normal icon
741 $str = t3lib_iconWorks::getIconImage('pages', $mp, $GLOBALS['BACK_PATH'], ' align="absmiddle"');
742 $classAttr = '';
743 }
744 // Will show UID on hover. Just convinient to user.
745 $content_array[] = $str . '<span ' . $classAttr . 'title="UID: ' . $mp['uid'] . '">' . $mp['title'] . '</span>';
746 }
747 }
748 if (count($content_array) > 0) {
749 return implode('<br />', $content_array);
750 }
751 // no mount points
752 return $GLOBALS['LANG']->getLL('workspace_list_db_mount_point_custom');
753 }
754
755 /**
756 * Retrieves and formats file mount points lists.
757 *
758 * @param array &$wksp Workspace record
759 * @return string Generated HTML
760 */
761 function workspaceList_getFileMountPoints(&$wksp) {
762 if ($wksp['uid'] == -1) {
763 // draft workspace - none!
764 return $GLOBALS['LANG']->getLL('workspace_list_file_mount_point_draft');
765 }
766 else if ($wksp['uid'] == 0) {
767 // live workspace
768 return $GLOBALS['LANG']->getLL('workspace_list_file_mount_point_live');
769 }
770
771 // Here if displaying information for custom workspace
772
773 // Warning: all fields needed for t3lib_iconWorks::getIconImage()!
774 $MPs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_filemounts', 'deleted=0 AND hidden=0 AND uid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($wksp['file_mountpoints']) . ')', '', 'title');
775 if (count($MPs) != 0) {
776 // Has mount points
777 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
778 if (!$isAdmin) {
779 // We need to fetch user's mount point list (including MPS mounted from groups).
780 // This list must not be affects by current user's workspace. It means we cannot use
781 // $BE_USER->isInWebMount() to check mount points.
782 $userMPs = explode(',', $GLOBALS['BE_USER']->dataLists['filemount_list']); // includes group data if necessary!
783 }
784 foreach ($MPs as $mp) {
785 if (!$isAdmin && !in_array($mp['uid'], $userMPs)) {
786 // Show warning icon
787 $title = $GLOBALS['LANG']->getLL('workspace_list_mount_point_inaccessible');
788 $str = '<img ' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning.gif', 'width="18" height="16"') .
789 ' alt="' . $title . '" title="' . $title . '" align="absmiddle" />';
790 $classAttr = 'class="ver-wl-mp-inacessible" ';
791 }
792 else {
793 // normal icon
794 $str = t3lib_iconWorks::getIconImage('sys_filemounts', $mp, $GLOBALS['BACK_PATH'], ' align="absmiddle"');
795 $classAttr = '';
796 }
797 // Will show UID on hover. Just convinient to user.
798 $content_array[] = $str . '<span ' . $classAttr . 'title="UID: ' . $mp['uid'] . '">' . $mp['title'] . '</span>';
799 }
800 }
801 if (count($content_array) > 0) {
802 return implode('<br />', $content_array);
803 }
804 // No file mount points
805 return $GLOBALS['LANG']->getLL('workspace_list_file_mount_point_custom');
806 }
807
808 /**
809 * Creates a header for the workspace list table. This function only makes
810 * <code>workspaceList_displayUserWorkspaceList()</code> smaller.
811 *
812 * @return string Generated content
813 */
814 function workspaceList_displayUserWorkspaceListHeader() {
815 global $LANG;
816 // TODO CSH lables?
817 return '<table border="0" cellpadding="0" cellspacing="1" class="lrPadding workspace-overview ver-wl-table">
818 <tr class="bgColor5 tableheader">
819 <td width="1">&nbsp;</td>
820 <td width="1">&nbsp;</td>
821 <td nowrap="nowrap">' . $LANG->getLL('workspace_list_label_current_workspace') . '</td>
822 <td nowrap="nowrap">' . $LANG->getLL('workspace_list_label_workspace_title') . '</td>
823 <td nowrap="nowrap">' . $LANG->getLL('workspace_list_label_workspace_description') . '</td>
824 </tr>';
825 }
826
827
828 /**
829 * Generates a list of <code>&lt;option&gt;</code> tags with user names.
830 *
831 * @param array Workspace record
832 * @return string Generated content
833 */
834 function workspaceList_getUserList(&$wksp) {
835 global $LANG;
836
837 if ($wksp['uid'] > 0) {
838 // custom workspaces
839 $content = $this->workspaceList_getUserListWithAccess($wksp['adminusers'], $LANG->getLL('workspace_list_label_owners')); // owners
840 $content .= $this->workspaceList_getUserListWithAccess($wksp['members'], $LANG->getLL('workspace_list_label_members')); // members
841 $content .= $this->workspaceList_getUserListWithAccess($wksp['reviewers'], $LANG->getLL('workspace_list_label_reviewers')); // reviewers
842 if ($content != '') {
843 $content = '<table cellpadding="0" cellspacing="1" width="100%" class="lrPadding workspace-overview">' . $content . '</table>';
844 } else {
845 $content = $LANG->getLL($wksp['uid'] > 0 ? 'workspace_list_access_admins_only' : 'workspace_list_access_anyone');
846 }
847 }
848 else {
849 // live and draft workspace
850 $content = $this->workspaceList_getUserListForSysWorkspace($wksp);
851 }
852 return $content;
853 }
854
855 /**
856 * Generates a list of user names that has access to the system workspace.
857 *
858 * @param array &$wksp Workspace record
859 * @return string Generated content
860 */
861 function workspaceList_getUserListForSysWorkspace(&$wksp) {
862 $option = ($wksp['uid'] == 0 ? 1 : 2);
863 $content_array = array();
864 foreach ($this->be_user_Array_full as $uid => $user) {
865 if ($user['admin'] != 0 || 0 != ($user['workspace_perms'] & $option)) {
866 if ($uid == $GLOBALS['BE_USER']->user['uid']) {
867 // highlight current user
868 $tag0 = '<span class="ver-wl-current-user">';
869 $tag1 = '</span>';
870 }
871 else {
872 $tag0 = $tag1 = '';
873 }
874 $content_array[] = $this->doc->wrapClickMenuOnIcon(t3lib_iconWorks::getIconImage('be_users', $uid, $GLOBALS['BACK_PATH'], ' align="middle" alt="UID: ' . $uid . '"'), 'be_users', $uid, 2).
875 $tag0 . $user['username'] . $tag1;
876 }
877 }
878 return implode('<br />', $content_array);
879 }
880
881 /**
882 * Generates a list of user names that has access to the workspace.
883 *
884 * @param array A list of user IDs separated by comma
885 * @param string Access string
886 * @return string Generated content
887 */
888 function workspaceList_getUserListWithAccess(&$list, $access) {
889 $content_array = array();
890 if ($list != '') {
891 $userIDs = explode(',', $list);
892
893 // get user names and sort
894 $regExp = '/^(be_[^_]+)_(\d+)$/';
895 $groups = false;
896 foreach ($userIDs as $userUID) {
897 $id = $userUID;
898
899 if (preg_match($regExp, $userUID)) {
900 $table = preg_replace($regExp, '\1', $userUID);
901 $id = intval(preg_replace($regExp, '\2', $userUID));
902 if ($table == 'be_users') {
903 // user
904 $icon = $GLOBALS['TCA']['be_users']['typeicons'][$this->be_user_Array[$id]['admin']];
905 if ($id == $GLOBALS['BE_USER']->user['uid']) {
906 // highlight current user
907 $tag0 = '<span class="ver-wl-current-user">';
908 $tag1 = '</span>';
909 }
910 else {
911 $tag0 = $tag1 = '';
912 }
913 $content_array[] = $this->doc->wrapClickMenuOnIcon(t3lib_iconWorks::getIconImage($table, $this->be_user_Array[$id], $GLOBALS['BACK_PATH'], ' align="middle" alt="UID: ' . $id . '"'), $table, $id, 2) .
914 $tag0 . $this->be_user_Array_full[$id]['username'] . $tag1;
915 }
916 else {
917 // group
918 if (false === $groups) {
919 $groups = t3lib_BEfunc::getGroupNames();
920 }
921 $content_array[] = $this->doc->wrapClickMenuOnIcon(t3lib_iconWorks::getIconImage($table, $groups[$id], $GLOBALS['BACK_PATH'], ' align="middle" alt="UID: ' . $id . '"'), $table, $id, 2) .
922 $groups[$id]['title'];
923 }
924 }
925 else {
926 // user id
927 if ($userUID == $GLOBALS['BE_USER']->user['uid']) {
928 // highlight current user
929 $tag0 = '<span class="ver-wl-current-user">';
930 $tag1 = '</span>';
931 }
932 else {
933 $tag0 = $tag1 = '';
934 }
935 $content_array[] = t3lib_iconWorks::getIconImage('be_users', $this->be_user_Array[$id], $GLOBALS['BACK_PATH'], ' align="middle" alt="UID: ' . $id . '"') .
936 $tag0 . $this->be_user_Array_full[$userUID]['username'] . $tag1;
937 }
938 }
939 sort($content_array);
940 }
941 else {
942 $content_array[] = '&nbsp;&ndash;';
943 }
944
945 $content = '<tr><td class="ver-wl-details-label ver-wl-details-user-list-label">';
946 // TODO CSH lable explaining access here?
947 $content .= '<b>' . $access . '</b></td>';
948 $content .= '<td class="ver-wl-details">' . implode('<br />', $content_array) . '</td></tr>';
949 return $content;
950 }
951
952
953
954 /**
955 * Creates a list of icons for workspace.
956 *
957 * @param boolean <code>true</code> if current workspace
958 * @param array Workspace record
959 * @return string Generated content
960 */
961 function workspaceList_displayIcons($currentWorkspace, &$wksp) {
962 global $BACK_PATH, $LANG;
963
964 $content = '';
965 // `edit workspace` button
966 if ($this->workspaceList_hasEditAccess($wksp)) {
967 // User can modify workspace parameters, display corresponding link and icon
968 $editUrl = 'workspaceforms.php?action=edit&amp;wkspId=' . $wksp['uid'];
969
970 $content .= '<a href="' . $editUrl . '" />' .
971 '<img ' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/edit2.gif', 'width="11" height="12"') . ' border="0" alt="' . $LANG->getLL('workspace_list_icon_title_edit_workspace') . '" align="middle" hspace="1" />' .
972 '</a>';
973 } else {
974 // User can NOT modify workspace parameters, display space
975 // Get only withdth and height from skinning API
976 $content .= '<img src="clear.gif" ' .
977 t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/edit2.gif', 'width="11" height="12"', 2) .
978 ' border="0" alt="" hspace="1" align="middle" />';
979 }
980 // `switch workspace` button
981 if (!$currentWorkspace) {
982 // Workspace switching button
983 $content .= '<a href="' .
984 t3lib_div::getIndpEnv('SCRIPT_NAME') .
985 '?changeWorkspace=' . $wksp['uid'] . '"/>' .
986 '<img ' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/switch.gif', 'width="11" height="10"') . ' border="0" alt="' . $LANG->getLL('workspace_list_icon_title_switch_workspace') . '" align="middle" hspace="1" />' .
987 '</a>';
988 } else {
989 // Current workspace: empty space instead of workspace switching button
990 //
991 // Here get only width and height from skinning API
992 $content .= '<img src="clear.gif" ' .
993 t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/switch.png', 'width="18" height="16"', 2) .
994 ' border="0" alt="" hspace="1" align="middle" alt="" />';
995 }
996 return $content;
997 }
998
999 /**
1000 * Checks if user has edit access to workspace. Access is granted if
1001 * workspace is custom and user is admin or the the owner of the workspace.
1002 * This function assumes that <code>$wksp</code> were passed through
1003 * <code>$GLOBALS['BE_USER']->checkWorkspace()</code> function to obtain
1004 * <code>_ACCESS</code> attribute of the workspace.
1005 *
1006 * @param array Workspace record
1007 * @return boolean <code>true</code> if user can modify workspace parameters
1008 */
1009 function workspaceList_hasEditAccess(&$wksp) {
1010 $access = &$wksp['_ACCESS'];
1011 return ($wksp['uid'] > 0 && ($access == 'admin' || $access == 'owner'));
1012 }
1013
1014 /**
1015 * Creates a fake workspace record for system workspaces. Record contains
1016 * all fields found in <code>sys_workspaces</code>.
1017 *
1018 * @param integer System workspace ID. Currently <code>0</code> and <code>-1</code> are accepted.
1019 * @return array Generated record (see <code>sys_workspaces</code> for structure)
1020 */
1021 function workspaceList_createFakeWorkspaceRecord($uid) {
1022 global $BE_USER, $LANG;
1023
1024 $record = array(
1025 'uid' => $uid,
1026 'pid' => 0, // always 0!
1027 'tstamp' => 0, // does not really matter
1028 'deleted' => 0,
1029 'title' => ($uid == 0 ? '['.$LANG->getLL('shortcut_onlineWS').']' : '['.$LANG->getLL('shortcut_offlineWS').']'),
1030 'description' => ($uid == 0 ? $LANG->getLL('shortcut_onlineWS') : $LANG->getLL('shortcut_offlineWS')),
1031 'adminusers' => '',
1032 'members' => '',
1033 'reviewers' => '',
1034 'db_mountpoints' => '', // TODO get mount points from user profile
1035 'file_mountpoints' => '', // TODO get mount points from user profile for live workspace only (uid == 0)
1036 'publish_time' => 0,
1037 'unpublish_time' => 0,
1038 'freeze' => 0,
1039 'live_edit' => ($uid == 0),
1040 'vtypes' => 0,
1041 'disable_autocreate' => 0,
1042 'swap_modes' => 0,
1043 'publish_access' => 0,
1044 'stagechg_notification' => 0
1045 );
1046 return $record;
1047 }
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072 /**************************************
1073 *
1074 * Helper functions
1075 *
1076 *************************************/
1077
1078
1079
1080
1081
1082
1083 }
1084
1085 // Include extension?
1086 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/index.php']) {
1087 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/index.php']);
1088 }
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098 // Make instance:
1099 $SOBE = t3lib_div::makeInstance('SC_mod_user_ws_index');
1100 $SOBE->execute();
1101 $SOBE->init();
1102 $SOBE->main();
1103 $SOBE->printContent();
1104 ?>