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