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