Fixed bug #16000: Move versioning selector to the version extension
[Packages/TYPO3.CMS.git] / typo3 / sysext / version / class.tx_version_gui.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * (c) 2010 Benjamin Mack (benni@typo3.org)
7 *
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 *
31 * Contains some parts for staging, versioning and workspaces
32 * to interact with the TYPO3 Core Engine
33 *
34 */
35 class tx_version_gui {
36
37 /**
38 * Creates the version selector for the page id inputted.
39 * Moved out of the core file typo3/template.php
40 *
41 * @param integer Page id to create selector for.
42 * @param boolean If set, there will be no button for swapping page.
43 * @return void
44 */
45 public function getVersionSelector($id, $noAction = FALSE) {
46 if ($id <= 0) {
47 return;
48 }
49 if ($GLOBALS['BE_USER']->workspace == 0) {
50
51 // Get Current page record:
52 $curPage = t3lib_BEfunc::getRecord('pages', $id);
53 // If the selected page is not online, find the right ID
54 $onlineId = ($curPage['pid']==-1 ? $curPage['t3ver_oid'] : $id);
55 // Select all versions of online version:
56 $versions = t3lib_BEfunc::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id');
57
58 // If more than one was found...:
59 if (count($versions) > 1) {
60 $selectorLabel = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.label', TRUE) . '</strong>';
61
62 // Create selector box entries:
63 $opt = array();
64 foreach ($versions as $vRow) {
65 if ($vRow['uid'] == $onlineId) {
66 // Live version
67 $label = '[' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.live', TRUE) . ']';
68 } else {
69 $label = $vRow['t3ver_label'] . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionId', TRUE) . ' ' . $vRow['t3ver_id'] .
70 ($vRow['t3ver_wsid'] != 0 ? ' ' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspaceId', TRUE) . ' ' . $vRow['t3ver_wsid'] : '') . ')';
71 }
72
73 $opt[] = '<option value="' . htmlspecialchars(t3lib_div::linkThisScript(array('id' => $vRow['uid']))) . '"' .
74 ($id == $vRow['uid'] ? ' selected="selected"' : '') . '>' .
75 htmlspecialchars($label) . '</option>';
76 }
77
78 // Add management link:
79 $management = '<input type="button" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.mgm', TRUE) . '" onclick="window.location.href=\'' .
80 htmlspecialchars($GLOBALS['TBE_TEMPLATE']->backPath . t3lib_extMgm::extRelPath('version') . 'cm1/index.php?table=pages&uid=' . $onlineId) . '\';" />';
81 // Create onchange handler:
82 $onChange = "window.location.href=this.options[this.selectedIndex].value;";
83
84 // Controls:
85 if ($id == $onlineId) {
86 $controls .= '<img' . t3lib_iconWorks::skinImg($GLOBALS['TBE_TEMPLATE']->backPath, 'gfx/blinkarrow_left.gif','width="5" height="9"') .
87 ' class="absmiddle" alt="" /> <strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.online', TRUE) .
88 '</strong>';
89 } elseif (!$noAction) {
90 $controls .= '<a href="' . $GLOBALS['TBE_TEMPLATE']->issueCommand('&cmd[pages][' . $onlineId . '][version][swapWith]=' . $id .
91 '&cmd[pages][' . $onlineId . '][version][action]=swap', t3lib_div::linkThisScript(array('id' => $onlineId))) .
92 '" class="nobr">' . t3lib_iconWorks::getSpriteIcon('actions-version-swap-version', array(
93 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.swapPage', TRUE),
94 'style' => 'margin-left:5px;vertical-align:bottom;'
95 )) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.swap', TRUE) . '</strong></a>';
96 }
97
98 // Write out HTML code:
99 return '
100 <!--
101 Version selector:
102 -->
103 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
104 <tr>
105 <td>' . $selectorLabel . '</td>
106 <td>
107 <select onchange="' . htmlspecialchars($onChange) . '">
108 ' . implode('', $opt) . '
109 </select></td>
110 <td>' . $controls . '</td>
111 <td>' . $management . '</td>
112 </tr>
113 </table>
114 ';
115 }
116 } elseif ($GLOBALS['BE_USER']->workspace !== 0) {
117
118 // Write out HTML code:
119 switch ($GLOBALS['BE_USER']->workspace) {
120 case 0:
121 $wsTitle = $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:live', TRUE);
122 break;
123 case -1:
124 $wsTitle = $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:draft', TRUE);
125 break;
126 default:
127 $wsTitle = $GLOBALS['BE_USER']->workspaceRec['title'];
128 break;
129 }
130
131 if (t3lib_BEfunc::isPidInVersionizedBranch($id) == 'branchpoint') {
132 return '
133
134 <!--
135 Version selector:
136 -->
137 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
138 <tr>
139 <td>' . $selectorLabel . '</td>
140 <td>Workspace: "' . htmlspecialchars($wsTitle) . '"</td>
141 <td><em>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.inBranch', TRUE) . '</em></td>
142 </tr>
143 </table>
144 ';
145 } else {
146
147 // Get Current page record:
148 $curPage = t3lib_BEfunc::getRecord('pages', $id);
149 // If the selected page is not online, find the right ID
150 $onlineId = ($curPage['pid']==-1 ? $curPage['t3ver_oid'] : $id);
151 // The version of page:
152 $verPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, 'pages', $onlineId);
153
154 if (!$verPage) {
155
156 if (!count(t3lib_BEfunc::countVersionsOfRecordsOnPage($GLOBALS['BE_USER']->workspace, $onlineId))) {
157 if ($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(0)) {
158
159 $onClick = $GLOBALS['TBE_TEMPLATE']->issueCommand('&cmd[pages][' . $onlineId . '][version][action]=new&cmd[pages][' . $onlineId . '][version][treeLevels]=0',
160 t3lib_div::linkThisScript(array(
161 'id' => $onlineId
162 )));
163 $onClick = 'window.location.href=\'' . $onClick . '\'; return false;';
164 // Write out HTML code:
165 return '
166
167 <!--
168 No version yet, create one?
169 -->
170 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
171 <tr>
172 <td>' . $selectorLabel . '</td>
173 <td>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspace', TRUE) . ': "' . htmlspecialchars($wsTitle) . '"</td>
174 <td>
175 <input type="button" value="New version of page" name="_" onclick="' . htmlspecialchars($onClick) . '" /></td>
176 </tr>
177 </table>
178 ';
179 }
180 } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['elementVersioningOnly'] == FALSE && $GLOBALS['TYPO3_CONF_VARS']['BE']['newPagesVersioningType'] == 0) {
181 // only add this info if old/deprecated newPagesVersioning is allowed
182 return '
183
184 <!--
185 Version selector:
186 -->
187 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
188 <tr>
189 <td>' . $selectorLabel . '</td>
190 <td>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspace', TRUE) . ': "' . htmlspecialchars($wsTitle) . '"</td>
191 <td><em>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.versionsFound', TRUE) . '</em></td>
192 </tr>
193 </table>
194 ';
195 }
196 } elseif ($verPage['t3ver_swapmode']==0) {
197 $onClick = $GLOBALS['TBE_TEMPLATE']->issueCommand('&cmd[pages][' . $onlineId . '][version][action]=swap&cmd[pages][' .
198 $onlineId . '][version][swapWith]=' . $verPage['uid'],
199 t3lib_div::linkThisScript(array(
200 'id' => $onlineId
201 )));
202 $onClick = 'window.location.href=\'' . $onClick . '\'; return false;';
203
204 // Write out HTML code:
205 return '
206
207 <!--
208 Version selector:
209 -->
210 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
211 <tr>
212 <td>' . $selectorLabel . '</td>
213 <td>' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:workspace', TRUE) . ': "' . htmlspecialchars($wsTitle) . '"</td>
214 <td>
215 <input type="button" value="' . $GLOBALS['LANG']->sL('LLL:EXT:version/locallang.xml:versionSelect.publish', TRUE) .
216 '" onclick="' . htmlspecialchars($onClick) . '" /></td>
217 </tr>
218 </table>
219 ';
220 }
221 }
222 }
223 }
224
225 }
226
227 ?>