2 /***************************************************************
5 * (c) 2007-2010 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 ***************************************************************/
28 // TODO remove the include once the autoloader is in place
29 if(TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) {
30 require_once('interfaces/interface.backend_toolbaritem.php');
34 * class to render the workspace selector
36 * @author Ingo Renner <ingo@typo3.org>
40 class WorkspaceSelector
implements backend_toolbarItem
{
42 protected $changeWorkspace;
43 protected $changeWorkspacePreview;
46 * reference back to the backend object
50 protected $backendReference;
55 * @param TYPO3backend TYPO3 backend object reference
57 public function __construct(TYPO3backend
&$backendReference = null) {
58 $this->backendReference
= $backendReference;
60 $this->changeWorkspace
= t3lib_div
::_GP('changeWorkspace');
61 $this->changeWorkspacePreview
= t3lib_div
::_GP('changeWorkspacePreview');
65 * checks whether the user has access to this toolbar item
67 * @see typo3/alt_shortcut.php
68 * @return boolean true if user has access, false if not
70 public function checkAccess() {
71 if (t3lib_extMgm
::isLoaded('version')) {
73 include(t3lib_extMgm
::extPath('version') . 'ws/conf.php');
75 return ($GLOBALS['BE_USER']->modAccess(array('name' => 'user', 'access' => 'user,group'), false) && $GLOBALS['BE_USER']->modAccess($MCONF, false));
81 * changes workspace if needed and then reloads the backend
85 public function changeWorkspace() {
86 $reloadBackend = false;
88 // Changing workspace and if so, reloading entire backend:
89 if (strlen($this->changeWorkspace
)) {
90 $GLOBALS['BE_USER']->setWorkspace($this->changeWorkspace
);
91 $reloadBackend = true;
94 // Changing workspace preview and if so, reloading entire backend:
95 if (strlen($this->changeWorkspacePreview
)) {
96 $GLOBALS['BE_USER']->setWorkspacePreview($this->changeWorkspacePreview
);
97 $reloadBackend = true;
101 $this->backendReference
->addJavascript(
102 'top.location.href=\'backend.php\';'
108 * toggles the frontend preview setting for workspaces. If the preview is
109 * activated it will turned off and vice versa. Gets called through AJAX
111 * @param array array of parameters from the AJAX interface, currently unused
112 * @param TYPO3AJAX object of type TYPO3AJAX
115 public function toggleWorkspacePreview($parameters = array(), TYPO3AJAX
&$ajaxObj = null) {
116 $newState = $GLOBALS['BE_USER']->user
['workspace_preview'] ?
'0' : '1';
117 $GLOBALS['BE_USER']->setWorkspacePreview($newState);
119 $ajaxObj->addContent('newWorkspacePreviewState', $newState);
120 $ajaxObj->setContentFormat('json');
124 * sets the workspace for the backend
126 * @param unknown_type $params
127 * @param TYPO3AJAX $ajaxObj
129 public function setWorkspace($parameters = array(), TYPO3AJAX
&$ajaxObj = null) {
130 $workspaceId = (int) t3lib_div
::_POST('workspaceId');
132 $GLOBALS['BE_USER']->setWorkspace($workspaceId);
134 $ajaxObj->addContent('setWorkspaceId', $workspaceId);
135 $ajaxObj->setContentFormat('json');
139 * retrieves the available workspaces from the database and checks whether
140 * they're available to the current BE user
142 * @return array array of worspaces available to the current user
144 protected function getAvailableWorkspaces() {
145 $availableWorkspaces = array();
147 // add default workspaces
148 if($GLOBALS['BE_USER']->checkWorkspace(array('uid' => 0))) {
149 $availableWorkspaces[0] = '['.$GLOBALS['LANG']->getLL('bookmark_onlineWS').']';
151 if ($GLOBALS['BE_USER']->checkWorkspace(array('uid' => -1))) {
152 $availableWorkspaces[-1] = '['.$GLOBALS['LANG']->getLL('bookmark_offlineWS').']';
155 // add custom workspaces (selecting all, filtering by BE_USER check):
156 $customWorkspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
157 'uid, title, adminusers, members, reviewers',
159 'pid = 0'.t3lib_BEfunc
::deleteClause('sys_workspace'),
163 if(count($customWorkspaces)) {
164 foreach($customWorkspaces as $workspace) {
165 if($GLOBALS['BE_USER']->checkWorkspace($workspace)) {
166 $availableWorkspaces[$workspace['uid']] = $workspace['uid'] . ': ' . htmlspecialchars($workspace['title']);
171 return $availableWorkspaces;
175 * Creates the selector for workspaces
177 * @return string workspace selector as HTML select
179 public function render() {
180 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.workspace', true);
181 $this->addJavascriptToBackend();
182 $this->changeWorkspace();
183 $availableWorkspaces = $this->getAvailableWorkspaces();
184 $workspaceMenu = array();
186 $stateCheckedIcon = t3lib_iconWorks
::getSpriteIcon('status-status-checked');
188 $stateUncheckedIcon = t3lib_iconWorks
::getSpriteIcon('empty-empty', array(
189 'title' => $GLOBALS['LANG']->getLL('bookmark_inactive')
192 $workspaceMenu[] = '<a href="#" class="toolbar-item">' .
193 t3lib_iconWorks
::getSpriteIcon('apps-toolbar-menu-workspace', array('title' => $title)) .
195 $workspaceMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
197 if (count($availableWorkspaces)) {
198 foreach($availableWorkspaces as $workspaceId => $label) {
200 $icon = $stateUncheckedIcon;
201 if((int) $GLOBALS['BE_USER']->workspace
=== $workspaceId) {
202 $selected = ' class="selected"';
203 $icon = $stateCheckedIcon;
206 $workspaceMenu[] = '<li' . $selected . '>' . $icon .
207 ' <a href="backend.php?changeWorkspace=' .
208 intval($workspaceId) . '" id="ws-' . intval($workspaceId) .
209 '" class="ws">' . $label . '</a></li>';
212 $workspaceMenu[] = '<li>' . $stateUncheckedIcon . ' ' .
213 $GLOBALS['LANG']->getLL('bookmark_noWSfound', true) .
217 // frontend preview toggle
218 $frontendPreviewActiveIcon = $stateUncheckedIcon;
219 if ($GLOBALS['BE_USER']->user
['workspace_preview']) {
220 $frontendPreviewActiveIcon = $stateCheckedIcon;
223 $workspaceMenu[] = '<li class="divider">' . $frontendPreviewActiveIcon .
224 '<a href="backend.php?changeWorkspacePreview=' .
225 ($GLOBALS['BE_USER']->user
['workspace_preview'] ?
'0' : '1') .
226 '" id="frontendPreviewToggle">' . $GLOBALS['LANG']->getLL('bookmark_FEPreview', true) . '</a></li>';
228 // go to workspace module link
229 $workspaceMenu[] = '<li>' . $stateUncheckedIcon . ' ' .
230 '<a href="' . t3lib_extMgm
::extRelPath('version') . 'ws/index.php" target="content" id="goToWsModule">' .
231 ' '. $GLOBALS['LANG']->getLL('bookmark_workspace', true) . '</a></li>';
233 $workspaceMenu[] = '</ul>';
235 return implode(LF
, $workspaceMenu);
239 * adds the necessary JavaScript to the backend
243 protected function addJavascriptToBackend() {
244 $this->backendReference
->addJavascriptFile('js/workspacemenu.js');
248 * returns additional attributes for the list item in the toolbar
250 * @return string list item HTML attibutes
252 public function getAdditionalAttributes() {
253 return ' id="workspace-selector-menu"';
257 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/classes/class.workspaceselector.php']) {
258 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/classes/class.workspaceselector.php']);