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