2 /***************************************************************
5 * (c) 2007 Ingo Renner <ingo@typo3.org>
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
30 * class to render the workspace selector
32 * @author Ingo Renner <ingo@typo3.org>
36 class WorkspaceSelector
implements backend_toolbarItem
{
38 private $changeWorkspace;
39 private $changeWorkspacePreview;
42 * reference back to the backend object
46 private $backendReference;
53 public function __construct() {
54 $this->changeWorkspace
= t3lib_div
::_GP('changeWorkspace');
55 $this->changeWorkspacePreview
= t3lib_div
::_GP('changeWorkspacePreview');
59 * sets the backend reference
61 * @param TYPO3backend backend object reference
63 public function setBackend(&$backendReference) {
64 $this->backendReference
= $backendReference;
68 * changes workspace if needed and then reloads the backend
72 public function changeWorkspace() {
73 $reloadBackend = false;
75 // Changing workspace and if so, reloading entire backend:
76 if (strlen($this->changeWorkspace
)) {
77 $GLOBALS['BE_USER']->setWorkspace($this->changeWorkspace
);
78 $reloadBackend = true;
81 // Changing workspace preview and if so, reloading entire backend:
82 if (strlen($this->changeWorkspacePreview
)) {
83 $GLOBALS['BE_USER']->setWorkspacePreview($this->changeWorkspacePreview
);
84 $reloadBackend = true;
88 $this->backendReference
->addJavascript(
89 'top.location.href=\'backend.php\';'
95 * retrieves the available workspaces from the database and checks whether
96 * they're available to the current BE user
98 * @return array array of worspaces available to the current user
100 private function getAvailableWorkspaces() {
101 $availableWorkspaces = array();
103 // add default workspaces
104 if($GLOBALS['BE_USER']->checkWorkspace(array('uid' => 0))) {
105 $availableWorkspaces[0] = '['.$GLOBALS['LANG']->getLL('shortcut_onlineWS').']';
107 if ($GLOBALS['BE_USER']->checkWorkspace(array('uid' => -1))) {
108 $availableWorkspaces[-1] = '['.$GLOBALS['LANG']->getLL('shortcut_offlineWS').']';
111 // add custom workspaces (selecting all, filtering by BE_USER check):
112 $customWorkspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
113 'uid, title, adminusers, members, reviewers',
115 'pid = 0'.t3lib_BEfunc
::deleteClause('sys_workspace'),
119 if(count($customWorkspaces)) {
120 foreach($customWorkspaces as $workspace) {
121 if($GLOBALS['BE_USER']->checkWorkspace($workspace)) {
122 $availableWorkspaces[$workspace['uid']] = $workspace['uid'].': '.$workspace['title'];
127 return $availableWorkspaces;
131 * Creates the selector for workspaces
133 * @return string workspace selector as HTML select
135 public function render() {
136 $this->addJavascriptToBackend();
137 $this->changeWorkspace();
140 $workspaceSelector = '';
141 $availableWorkspaces = $this->getAvailableWorkspaces();
143 // build selector box options
144 if(count($availableWorkspaces)) {
145 foreach($availableWorkspaces as $workspaceId => $label) {
148 if((int) $GLOBALS['BE_USER']->workspace
=== $workspaceId) {
149 $selected = ' selected="selected"';
152 $options[$workspaceId] = '<option value="'.htmlspecialchars($workspaceId).'"'.$selected.'>'.htmlspecialchars($label).'</option>';
155 $options[] = '<option value="-99">'.$GLOBALS['LANG']->getLL('shortcut_noWSfound',1).'</option>';
158 // build selector box
159 if(count($options) > 1) {
160 $workspaceSelector .=
161 '<select name="_workspaceSelector" onchange="changeWorkspace(this.options[this.selectedIndex].value);">'
162 .implode("\n", $options)
167 if($GLOBALS['BE_USER']->workspace
!== 0) {
168 $workspaceSelector.= ' <label for="workspacePreview">Frontend Preview:</label> <input type="checkbox" name="workspacePreview" id="workspacePreview" onclick="changeWorkspacePreview('.($GLOBALS['BE_USER']->user
['workspace_preview'] ?
0 : 1).')"; '.($GLOBALS['BE_USER']->user
['workspace_preview'] ?
'checked="checked"' : '').'/>';
171 $workspaceSelector.= ' <a href="mod/user/ws/index.php" target="content">'.
172 t3lib_iconWorks
::getIconImage(
175 $this->doc
->backPath
,
179 return $workspaceSelector;
183 * adds the neccessary javascript ot the backend
186 private function addJavascriptToBackend() {
187 $this->backendReference
->addJavascriptFile('typo3/js/workspaces.js');
191 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/classes/class.workspaceselector.php']) {
192 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/classes/class.workspaceselector.php']);