* Fixed bug #11138: Validation issue: End tag for "br" omitted, but OMITTAG NO was...
[Packages/TYPO3.CMS.git] / typo3 / sysext / version / cm1 / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004-2009 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 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * Versioning module
26 *
27 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
28 */
29 /**
30 * [CLASS/FUNCTION INDEX of SCRIPT]
31 *
32 *
33 *
34 * 102: class tx_version_cm1 extends t3lib_SCbase
35 *
36 * SECTION: Standard module initialization
37 * 138: function menuConfig()
38 * 175: function main()
39 * 236: function jumpToUrl(URL)
40 * 296: function printContent()
41 *
42 * SECTION: Versioning management
43 * 322: function versioningMgm()
44 * 485: function pageSubContent($pid,$c=0)
45 * 539: function lookForOwnVersions($table,$uid)
46 * 556: function adminLinks($table,$row)
47 *
48 * SECTION: Workspace management
49 * 628: function workspaceMgm()
50 * 688: function displayWorkspaceOverview()
51 * 758: function displayWorkspaceOverview_list($pArray)
52 * 923: function displayWorkspaceOverview_setInPageArray(&$pArray,$table,$row)
53 * 936: function displayWorkspaceOverview_allStageCmd()
54 *
55 * SECTION: Helper functions (REDUNDANT FROM user/ws/index.php - someone could refactor this...)
56 * 986: function formatVerId($verId)
57 * 996: function formatWorkspace($wsid)
58 * 1023: function formatCount($count)
59 * 1050: function versionsInOtherWS($table,$uid)
60 * 1080: function showStageChangeLog($table,$id,$stageCommands)
61 * 1129: function subElements($uid,$treeLevel,$origId=0)
62 * 1232: function subElements_getNonPageRecords($tN, $uid, &$recList)
63 * 1262: function subElements_renderItem(&$tCell,$tN,$uid,$rec,$origId,$iconMode,$HTMLdata)
64 * 1331: function markupNewOriginals()
65 * 1353: function createDiffView($table, $diff_1_record, $diff_2_record)
66 * 1470: function displayWorkspaceOverview_stageCmd($table,&$rec_off)
67 * 1557: function displayWorkspaceOverview_commandLinks($table,&$rec_on,&$rec_off,$vType)
68 * 1627: function displayWorkspaceOverview_commandLinksSub($table,$rec,$origId)
69 *
70 * SECTION: Processing
71 * 1683: function publishAction()
72 *
73 * TOTAL FUNCTIONS: 27
74 * (This index is automatically created/updated by the extension "extdeveval")
75 *
76 */
77
78
79 // DEFAULT initialization of a module [BEGIN]
80 unset($MCONF);
81 require ('conf.php');
82 require ($BACK_PATH.'init.php');
83 require ($BACK_PATH.'template.php');
84 $LANG->includeLLFile('EXT:version/locallang.xml');
85 // DEFAULT initialization of a module [END]
86
87 require_once(PATH_typo3.'mod/user/ws/class.wslib.php');
88
89
90
91 /**
92 * Versioning module, including workspace management
93 *
94 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
95 * @package TYPO3
96 * @subpackage core
97 */
98 class tx_version_cm1 extends t3lib_SCbase {
99
100 // Default variables for backend modules
101 var $MCONF = array(); // Module configuration
102 var $MOD_MENU = array(); // Module menu items
103 var $MOD_SETTINGS = array(); // Module session settings
104
105 /**
106 * document template object
107 *
108 * @var mediumDoc
109 */
110 var $doc;
111 var $content; // Accumulated content
112
113
114 // Internal:
115 var $showWorkspaceCol = 0;
116 var $formatWorkspace_cache = array();
117 var $formatCount_cache = array();
118 var $targets = array(); // Accumulation of online targets.
119 var $pageModule = ''; // Name of page module
120 var $publishAccess = FALSE;
121 var $be_user_Array = array();
122 var $stageIndex = array();
123 var $recIndex = array();
124
125
126
127
128
129
130 /*********************************
131 *
132 * Standard module initialization
133 *
134 *********************************/
135
136 /**
137 * Initialize menu configuration
138 *
139 * @return void
140 */
141 function menuConfig() {
142
143 // Menu items:
144 $this->MOD_MENU = array(
145 'filter' => array(
146 1 => $GLOBALS['LANG']->getLL('filter_drafts'),
147 2 => $GLOBALS['LANG']->getLL('filter_archive'),
148 0 => $GLOBALS['LANG']->getLL('filter_all'),
149 ),
150 'display' => array(
151 0 => $GLOBALS['LANG']->getLL('liveWorkspace'),
152 -98 => $GLOBALS['LANG']->getLL('draftWorkspaces'),
153 -99 => $GLOBALS['LANG']->getLL('filter_all'),
154 -1 => $GLOBALS['LANG']->getLL('defaultDraft')
155 ),
156 'diff' => ''
157 );
158
159 // Add workspaces:
160 if ($GLOBALS['BE_USER']->workspace===0) { // Spend time on this only in online workspace because it might take time:
161 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
162 foreach($workspaces as $rec) {
163 if ($GLOBALS['BE_USER']->checkWorkspace($rec)) {
164 $this->MOD_MENU['display'][$rec['uid']] = '['.$rec['uid'].'] '.$rec['title'];
165 }
166 }
167 }
168
169 // CLEANSE SETTINGS
170 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name'], 'ses');
171 }
172
173 /**
174 * Main function of the module. Write the content to $this->content
175 *
176 * @return void
177 */
178 function main() {
179 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
180
181 // Template markers
182 $markers = array(
183 'CSH' => '',
184 'FUNC_MENU' => '',
185 'WS_MENU' => '',
186 'CONTENT' => ''
187 );
188
189 // Setting module configuration:
190 $this->MCONF = $GLOBALS['MCONF'];
191
192 $this->REQUEST_URI = str_replace('&sendToReview=1','',t3lib_div::getIndpEnv('REQUEST_URI'));
193
194 // Draw the header.
195 $this->doc = t3lib_div::makeInstance('template');
196 $this->doc->backPath = $BACK_PATH;
197 $this->doc->setModuleTemplate('templates/version.html');
198
199 // Add styles
200 $this->doc->inDocStylesArray[$GLOBALS['MCONF']['name']] = '
201 .version-diff-1 { background-color: green; }
202 .version-diff-2 { background-color: red; }
203 ';
204
205 // Setting up the context sensitive menu:
206 $this->doc->getContextMenuCode();
207
208 // Getting input data:
209 $this->id = intval(t3lib_div::_GP('id')); // Page id. If set, indicates activation from Web>Versioning module
210 if (!$this->id) {
211 $this->uid = intval(t3lib_div::_GP('uid')); // Record uid. Goes with table name to indicate specific record
212 $this->table = t3lib_div::_GP('table'); // Record table. Goes with uid to indicate specific record
213 } else {
214 $this->uid = $this->id;
215 $this->table = 'pages';
216 }
217 $this->details = t3lib_div::_GP('details'); // Page id. If set, indicates activation from Web>Versioning module
218 $this->diffOnly = t3lib_div::_GP('diffOnly'); // Flag. If set, shows only the offline version and with diff-view
219
220 // Force this setting:
221 $this->MOD_SETTINGS['expandSubElements'] = TRUE;
222 $this->MOD_SETTINGS['diff'] = $this->details || $this->MOD_SETTINGS['diff']?1:0;
223
224 // Reading the record:
225 $record = t3lib_BEfunc::getRecord($this->table,$this->uid);
226 if ($record['pid']==-1) {
227 $record = t3lib_BEfunc::getRecord($this->table,$record['t3ver_oid']);
228 }
229
230 $this->recordFound = is_array($record);
231
232 $pidValue = $this->table==='pages' ? $this->uid : $record['pid'];
233
234 // Checking access etc.
235 if ($this->recordFound && $TCA[$this->table]['ctrl']['versioningWS']) {
236 $this->doc->form='<form action="" method="post">';
237 $this->uid = $record['uid']; // Might have changed if new live record was found!
238
239 // Access check!
240 // The page will show only if there is a valid page and if this page may be viewed by the user
241 $this->pageinfo = t3lib_BEfunc::readPageAccess($pidValue,$this->perms_clause);
242 $access = is_array($this->pageinfo) ? 1 : 0;
243
244 if (($pidValue && $access) || ($BE_USER->user['admin'] && !$pidValue)) {
245
246 // JavaScript
247 $this->doc->JScode.= '
248 <script language="javascript" type="text/javascript">
249 script_ended = 0;
250 function jumpToUrl(URL) {
251 window.location.href = URL;
252 }
253
254 function hlSubelements(origId, verId, over, diffLayer) { //
255 if (over) {
256 document.getElementById(\'orig_\'+origId).attributes.getNamedItem("class").nodeValue = \'typo3-ver-hl\';
257 document.getElementById(\'ver_\'+verId).attributes.getNamedItem("class").nodeValue = \'typo3-ver-hl\';
258 if (diffLayer) {
259 document.getElementById(\'diff_\'+verId).style.visibility = \'visible\';
260 }
261 } else {
262 document.getElementById(\'orig_\'+origId).attributes.getNamedItem("class").nodeValue = \'typo3-ver\';
263 document.getElementById(\'ver_\'+verId).attributes.getNamedItem("class").nodeValue = \'typo3-ver\';
264 if (diffLayer) {
265 document.getElementById(\'diff_\'+verId).style.visibility = \'hidden\';
266 }
267 }
268 }
269 </script>
270 ';
271
272 // If another page module was specified, replace the default Page module with the new one
273 $newPageModule = trim($BE_USER->getTSConfigVal('options.overridePageModule'));
274 $this->pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
275
276 // Setting publish access permission for workspace:
277 $this->publishAccess = $BE_USER->workspacePublishAccess($BE_USER->workspace);
278
279 // Render content:
280 if ($this->id) {
281 $this->workspaceMgm();
282 } else {
283 $this->versioningMgm();
284 }
285 }
286
287 $this->content.=$this->doc->spacer(10);
288
289 // Setting up the buttons and markers for docheader
290 $docHeaderButtons = $this->getButtons();
291 $markers['CSH'] = $docHeaderButtons['csh'];
292 $markers['FUNC_MENU'] = t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
293 $markers['WS_MENU'] = $this->workspaceMenu();
294 $markers['CONTENT'] = $this->content;
295 } else {
296 // If no access or id value, create empty document
297 $this->content = $this->doc->section($LANG->getLL('clickAPage_header'), $LANG->getLL('clickAPage_content'), 0, 1);
298
299 // Setting up the buttons and markers for docheader
300 $docHeaderButtons = $this->getButtons();
301 $markers['CONTENT'] = $this->content;
302 }
303 // Build the <body> for the module
304 $this->content = $this->doc->startPage($LANG->getLL('title'));
305 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
306 $this->content.= $this->doc->endPage();
307 $this->content = $this->doc->insertStylesAndJS($this->content);
308 }
309
310 /**
311 * Outputs accumulated module content to browser.
312 *
313 * @return void
314 */
315 function printContent() {
316 echo $this->content;
317 }
318
319 /**
320 * Create the panel of buttons for submitting the form or otherwise perform operations.
321 *
322 * @return array all available buttons as an assoc. array
323 */
324 protected function getButtons() {
325 global $TCA, $LANG, $BACK_PATH, $BE_USER;
326
327 $buttons = array(
328 'csh' => '',
329 'view' => '',
330 'record_list' => '',
331 'shortcut' => '',
332 );
333 // CSH
334 //$buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_txversionM1', '', $GLOBALS['BACK_PATH']);
335
336 if ($this->recordFound && $TCA[$this->table]['ctrl']['versioningWS']) {
337 // View page
338 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::viewOnClick($this->pageinfo['uid'], $BACK_PATH, t3lib_BEfunc::BEgetRootLine($this->pageinfo['uid']))) . '">' .
339 '<img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/zoom.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', 1) . '" hspace="3" alt="" />' .
340 '</a>';
341
342 // Shortcut
343 if ($BE_USER->mayMakeShortcut()) {
344 $buttons['shortcut'] = $this->doc->makeShortcutIcon('id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
345 }
346
347 // If access to Web>List for user, then link to that module.
348 if ($BE_USER->check('modules','web_list')) {
349 $href = $BACK_PATH . 'db_list.php?id=' . $this->pageinfo['uid'] . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
350 $buttons['record_list'] = '<a href="' . htmlspecialchars($href) . '">' .
351 '<img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/list.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList', 1) . '" alt="" />' .
352 '</a>';
353 }
354 }
355 return $buttons;
356 }
357
358
359
360
361
362
363
364
365 /******************************
366 *
367 * Versioning management
368 *
369 ******************************/
370
371 /**
372 * Management of versions for record
373 *
374 * @return void
375 */
376 function versioningMgm() {
377 global $TCA;
378
379 // Diffing:
380 $diff_1 = t3lib_div::_POST('diff_1');
381 $diff_2 = t3lib_div::_POST('diff_2');
382 if (t3lib_div::_POST('do_diff')) {
383 $content='';
384 $content.='<h3>' . $GLOBALS['LANG']->getLL('diffing') . ':</h3>';
385 if ($diff_1 && $diff_2) {
386 $diff_1_record = t3lib_BEfunc::getRecord($this->table, $diff_1);
387 $diff_2_record = t3lib_BEfunc::getRecord($this->table, $diff_2);
388
389 if (is_array($diff_1_record) && is_array($diff_2_record)) {
390 t3lib_div::loadTCA($this->table);
391 $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
392
393 $tRows=array();
394 $tRows[] = '
395 <tr class="bgColor5 tableheader">
396 <td>' . $GLOBALS['LANG']->getLL('fieldname') . '</td>
397 <td width="98%">' . $GLOBALS['LANG']->getLL('coloredDiffView') . ':</td>
398 </tr>
399 ';
400 foreach($diff_1_record as $fN => $fV) {
401 if ($TCA[$this->table]['columns'][$fN] && $TCA[$this->table]['columns'][$fN]['config']['type']!='passthrough' && !t3lib_div::inList('t3ver_label',$fN)) {
402 if (strcmp($diff_1_record[$fN],$diff_2_record[$fN])) {
403
404 $diffres = $t3lib_diff_Obj->makeDiffDisplay(
405 t3lib_BEfunc::getProcessedValue($this->table,$fN,$diff_2_record[$fN],0,1),
406 t3lib_BEfunc::getProcessedValue($this->table,$fN,$diff_1_record[$fN],0,1)
407 );
408
409 $tRows[] = '
410 <tr class="bgColor4">
411 <td>'.$fN.'</td>
412 <td width="98%">'.$diffres.'</td>
413 </tr>
414 ';
415 }
416 }
417 }
418
419 if (count($tRows)>1) {
420 $content .= '<table border="0" cellpadding="1" cellspacing="1" width="100%">' . implode('', $tRows) . '</table><br /><br />';
421 } else {
422 $content .= $GLOBALS['LANG']->getLL('recordsMatchesCompletely');
423 }
424 } else $content .= $GLOBALS['LANG']->getLL('errorRecordsNotFound');
425 } else {
426 $content .= $GLOBALS['LANG']->getLL('errorDiffSources');
427 }
428 }
429
430 // Element:
431 $record = t3lib_BEfunc::getRecord($this->table,$this->uid);
432 $recordIcon = t3lib_iconWorks::getIconImage($this->table,$record,$this->doc->backPath,'class="absmiddle"');
433 $recTitle = t3lib_BEfunc::getRecordTitle($this->table,$record,TRUE);
434
435 // Display versions:
436 $content.='
437 '.$recordIcon.$recTitle.'
438 <form name="theform" action="'.str_replace('&sendToReview=1','',$this->REQUEST_URI).'" method="post">
439 <table border="0" cellspacing="1" cellpadding="1">';
440 $content.='
441 <tr class="bgColor5 tableheader">
442 <td>&nbsp;</td>
443 <td>&nbsp;</td>
444 <td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_title') . '">' . $GLOBALS['LANG']->getLL('tblHeader_title') . '</td>
445 <td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_uid') . '">' . $GLOBALS['LANG']->getLL('tblHeader_uid') . '</td>
446 <td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_oid') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_oid') . '</td>
447 <td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_id') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_id') . '</td>
448 <td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_wsid') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_wsid') . '</td>
449 <td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_state') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_state') . '</td>
450 <td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_stage') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_stage') . '</td>
451 <td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_count') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_count') . '</td>
452 <td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_pid') . '">' . $GLOBALS['LANG']->getLL('tblHeader_pid') . '</td>
453 <td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_label') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_label') . '</td>
454 <td colspan="2"><input type="submit" name="do_diff" value="' . $GLOBALS['LANG']->getLL('diff') . '" /></td>
455 </tr>';
456
457 $versions = t3lib_BEfunc::selectVersionsOfRecord($this->table, $this->uid, '*', $GLOBALS['BE_USER']->workspace);
458 foreach($versions as $row) {
459 $adminLinks = $this->adminLinks($this->table,$row);
460
461 $content.='
462 <tr class="'.($row['uid']!=$this->uid ? 'bgColor4' : 'bgColor2 tableheader').'">
463 <td>'.($row['uid']!=$this->uid ? '<a href="'.$this->doc->issueCommand('&cmd['.$this->table.']['.$this->uid.'][version][swapWith]='.$row['uid'].'&cmd['.$this->table.']['.$this->uid.'][version][action]=swap').'">'.
464 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert1.gif','width="14" height="14"').' alt="" title="' . $GLOBALS['LANG']->getLL('swapWithCurrent') . '" />'.
465 '</a>' /* (
466 $this->table == 'pages' ?
467 '<a href="'.$this->doc->issueCommand('&cmd['.$this->table.']['.$this->uid.'][version][action]=swap&cmd['.$this->table.']['.$this->uid.'][version][swapWith]='.$row['uid'].'&cmd['.$this->table.']['.$this->uid.'][version][swapContent]=1').'">'.
468 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert2.gif','width="14" height="14"').' alt="" title="Publish page AND content!" />'.
469 '</a>'.
470 '<a href="'.$this->doc->issueCommand('&cmd['.$this->table.']['.$this->uid.'][version][action]=swap&cmd['.$this->table.']['.$this->uid.'][version][swapWith]='.$row['uid'].'&cmd['.$this->table.']['.$this->uid.'][version][swapContent]=ALL').'">'.
471 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert4.gif','width="14" height="14"').' alt="" title="Publish page AND content! - AND ALL SUBPAGES!" />'.
472 '</a>' : '') */ : '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/blinkarrow_left.gif','width="5" height="9"').' alt="" title="' . $GLOBALS['LANG']->getLL('currentOnlineVersion') . '"/>').'</td>
473 <td nowrap="nowrap">'.$adminLinks.'</td>
474 <td nowrap="nowrap">'.t3lib_BEfunc::getRecordTitle($this->table,$row,TRUE).'</td>
475 <td>'.$row['uid'].'</td>
476 <td>'.$row['t3ver_oid'].'</td>
477 <td>'.$row['t3ver_id'].'</td>
478 <td>'.$row['t3ver_wsid'].'</td>
479 <td>'.$row['t3ver_state'].'</td>
480 <td>'.$row['t3ver_stage'].'</td>
481 <td>'.$row['t3ver_count'].'</td>
482 <td>'.$row['pid'].'</td>
483 <td nowrap="nowrap"><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick('&edit['.$this->table.']['.$row['uid'].']=edit&columnsOnly=t3ver_label',$this->doc->backPath)).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' alt="" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.edit'). '"/></a>' . htmlspecialchars($row['t3ver_label']).'</td>
484 <td class="version-diff-1"><input type="radio" name="diff_1" value="'.$row['uid'].'"'.($diff_1==$row['uid'] ? ' checked="checked"':'').'/></td>
485 <td class="version-diff-2"><input type="radio" name="diff_2" value="'.$row['uid'].'"'.($diff_2==$row['uid'] ? ' checked="checked"':'').'/></td>
486 </tr>';
487
488 // Show sub-content if the table is pages AND it is not the online branch (because that will mostly render the WHOLE tree below - not smart;)
489 if ($this->table == 'pages' && $row['uid']!=$this->uid) {
490 $sub = $this->pageSubContent($row['uid']);
491
492 if ($sub) {
493 $content.='
494 <tr>
495 <td></td>
496 <td></td>
497 <td colspan="10">'.$sub.'</td>
498 <td colspan="2"></td>
499 </tr>';
500 }
501 }
502 }
503 $content.='</table></form>';
504
505 $this->content.=$this->doc->section('',$content,0,1);
506
507
508 // Create new:
509 $content='
510
511 <form action="'.$this->doc->backPath.'tce_db.php" method="post">
512 ' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_label') . ': <input type="text" name="cmd[' . $this->table . '][' . $this->uid . '][version][label]" /><br />
513 '.($this->table == 'pages' ? '<select name="cmd['.$this->table.']['.$this->uid.'][version][treeLevels]">
514 '.($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(0) ? '<option value="0">' . $GLOBALS['LANG']->getLL('cmdPid0') . '</option>' : '').'
515 '.($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(1) ? '<option value="100">' . $GLOBALS['LANG']->getLL('cmdPid100') . '</option>' : '').'
516 '.($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(-1) ? '<option value="-1">' . $GLOBALS['LANG']->getLL('cmdPid1') . '</option>' : '').'
517 </select>' : '').'
518 <br /><input type="hidden" name="cmd[' . $this->table . '][' . $this->uid . '][version][action]" value="new" />
519 <input type="hidden" name="prErr" value="1" />
520 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->REQUEST_URI).'" />
521 <input type="submit" name="_" value="' . $GLOBALS['LANG']->getLL('createNewVersion') . '" />
522
523 </form>
524
525 ';
526
527 $this->content.=$this->doc->spacer(15);
528 $this->content.=$this->doc->section($GLOBALS['LANG']->getLL('createNewVersion'), $content,0,1);
529
530 }
531
532 /**
533 * Recursively look for children for page version with $pid
534 *
535 * @param integer UID of page record for which to look up sub-elements following that version
536 * @param integer Counter, do not set (limits to 100 levels)
537 * @return string Table with content if any
538 */
539 function pageSubContent($pid,$c=0) {
540 global $TCA;
541
542 $tableNames = t3lib_div::removeArrayEntryByValue(array_keys($TCA),'pages');
543 $tableNames[] = 'pages';
544
545 foreach($tableNames as $tN) {
546 // Basically list ALL tables - not only those being copied might be found!
547 #if ($TCA[$tN]['ctrl']['versioning_followPages'] || $tN=='pages') {
548 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $tN, 'pid='.intval($pid).t3lib_BEfunc::deleteClause($tN), '', ($TCA[$tN]['ctrl']['sortby'] ? $TCA[$tN]['ctrl']['sortby'] : ''));
549
550 if ($GLOBALS['TYPO3_DB']->sql_num_rows($mres)) {
551 $content.='
552 <tr>
553 <td colspan="4" class="'.($TCA[$tN]['ctrl']['versioning_followPages'] ? 'bgColor6' : ($tN=='pages' ? 'bgColor5' : 'bgColor-10')).'"'.(!$TCA[$tN]['ctrl']['versioning_followPages'] && $tN!='pages' ? ' style="color: #666666; font-style:italic;"':'').'>'.$tN.'</td>
554 </tr>';
555 while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
556 $ownVer = $this->lookForOwnVersions($tN,$subrow['uid']);
557 $content.='
558 <tr>
559 <td>'.$this->adminLinks($tN,$subrow).'</td>
560 <td>'.$subrow['uid'].'</td>
561 '.($ownVer>1 ? '<td style="font-weight: bold; background-color: yellow;"><a href="index.php?table='.rawurlencode($tN).'&uid='.$subrow['uid'].'">'.($ownVer-1).'</a></td>' : '<td></td>').'
562 <td width="98%">'.t3lib_BEfunc::getRecordTitle($tN,$subrow,TRUE).'</td>
563 </tr>';
564
565 if ($tN == 'pages' && $c<100) {
566 $sub = $this->pageSubContent($subrow['uid'],$c+1);
567
568 if ($sub) {
569 $content.='
570 <tr>
571 <td></td>
572 <td></td>
573 <td></td>
574 <td width="98%">'.$sub.'</td>
575 </tr>';
576 }
577 }
578 }
579 }
580 #}
581 }
582
583 return $content ? '<table border="1" cellpadding="1" cellspacing="0" width="100%">'.$content.'</table>' : '';
584 }
585
586 /**
587 * Look for number of versions of a record
588 *
589 * @param string Table name
590 * @param integer Record uid
591 * @return integer Number of versions for record, false if none.
592 */
593 function lookForOwnVersions($table,$uid) {
594 global $TCA;
595
596 $versions = t3lib_BEfunc::selectVersionsOfRecord($table, $uid, 'uid');
597 if (is_array($versions)) {
598 return count($versions);
599 }
600 return FALSE;
601 }
602
603 /**
604 * Administrative links for a table / record
605 *
606 * @param string Table name
607 * @param array Record for which administrative links are generated.
608 * @return string HTML link tags.
609 */
610 function adminLinks($table,$row) {
611 global $BE_USER;
612
613 // Edit link:
614 $adminLink = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick('&edit['.$table.']['.$row['uid'].']=edit',$this->doc->backPath)).'">'.
615 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' alt="" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.edit'). '"/>'.
616 '</a>';
617
618 // Delete link:
619 $adminLink.= '<a href="'.htmlspecialchars($this->doc->issueCommand('&cmd['.$table.']['.$row['uid'].'][delete]=1')).'">'.
620 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' alt="" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.delete'). '"/>'.
621 '</a>';
622
623
624
625 if ($table == 'pages') {
626
627 // If another page module was specified, replace the default Page module with the new one
628 $newPageModule = trim($BE_USER->getTSConfigVal('options.overridePageModule'));
629 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
630
631 // Perform some acccess checks:
632 $a_wl = $BE_USER->check('modules','web_list');
633 $a_wp = t3lib_extMgm::isLoaded('cms') && $BE_USER->check('modules',$pageModule);
634
635 $adminLink.='<a href="#" onclick="top.loadEditId('.$row['uid'].');top.goToModule(\''.$pageModule.'\'); return false;">'.
636 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,t3lib_extMgm::extRelPath('cms').'layout/layout.gif','width="14" height="12"').' title="" alt="" />'.
637 '</a>';
638 $adminLink.='<a href="#" onclick="top.loadEditId('.$row['uid'].');top.goToModule(\'web_list\'); return false;">'.
639 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'mod/web/list/list.gif','width="14" height="12"').' title="" alt="" />'.
640 '</a>';
641
642 // "View page" icon is added:
643 $adminLink.='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($row['uid'],$this->doc->backPath,t3lib_BEfunc::BEgetRootLine($row['uid']))).'">'.
644 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
645 '</a>';
646 } else {
647 if ($row['pid']==-1) {
648 $getVars = '&ADMCMD_vPrev['.rawurlencode($table.':'.$row['t3ver_oid']).']='.$row['uid'];
649
650 // "View page" icon is added:
651 $adminLink.='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($row['_REAL_PID'],$this->doc->backPath,t3lib_BEfunc::BEgetRootLine($row['_REAL_PID']),'','',$getVars)).'">'.
652 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
653 '</a>';
654 }
655 }
656
657 return $adminLink;
658 }
659
660
661
662
663
664
665
666
667
668
669
670 /******************************
671 *
672 * Workspace management
673 *
674 ******************************/
675
676 /**
677 * Management of workspace for page ID
678 * Called when $this->id is set.
679 *
680 * @return void
681 */
682 function workspaceMgm() {
683
684 // Perform workspace publishing action if buttons are pressed:
685 $errors = $this->publishAction();
686
687 // Generate workspace overview:
688 $WSoverview = $this->displayWorkspaceOverview();
689
690 // Buttons for publish / swap:
691 $actionLinks = '<br />';
692 if ($GLOBALS['BE_USER']->workspace!==0) {
693 if ($this->publishAccess) {
694 $actionLinks.= '<input type="submit" name="_publish" value="' . $GLOBALS['LANG']->getLL('publishPage') . '" onclick="return confirm(\'' . sprintf($GLOBALS['LANG']->getLL('publishPageQuestion'), $GLOBALS['BE_USER']->workspaceRec['publish_access'] & 1 ? $GLOBALS['LANG']->getLL('publishPageQuestionStage') : '') . '\');"/>';
695 if ($GLOBALS['BE_USER']->workspaceSwapAccess()) {
696 $actionLinks.= '<input type="submit" name="_swap" value="' . $GLOBALS['LANG']->getLL('swapPage') . '" onclick="return confirm(\'' . sprintf($GLOBALS['LANG']->getLL('swapPageQuestion'), $GLOBALS['BE_USER']->workspaceRec['publish_access'] & 1 ? $GLOBALS['LANG']->getLL('publishPageQuestionStage') : '') . '\');" />';
697 }
698 } else {
699 $actionLinks.= $this->doc->icons(1) . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:no_publish_permission');
700 }
701 }
702
703 $actionLinks.= '<input type="submit" name="_" value="' . $GLOBALS['LANG']->getLL('refresh') . '" />';
704 $actionLinks.= '<input type="submit" name="_previewLink" value="' . $GLOBALS['LANG']->getLL('previewLink') . '" />';
705 $actionLinks.= $this->displayWorkspaceOverview_allStageCmd();
706
707 if ($actionLinks || count($errors)) {
708 $this->content .= $this->doc->section('', $actionLinks . (count($errors) ? '<h3>' . $GLOABLS['LANG']->getLL('errors') . '</h3><br />' . implode('<br />', $errors) . '<hr />' : ''), 0, 1);
709 }
710
711 if (t3lib_div::_POST('_previewLink')) {
712 $ttlHours = intval($GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.previewLinkTTLHours'));
713 $ttlHours = ($ttlHours ? $ttlHours : 24*2);
714
715 if (t3lib_div::_POST('_previewLink_wholeWorkspace')) {
716 $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($this->id);
717 } else {
718 $params = 'id='.$this->id.'&ADMCMD_previewWS='.$GLOBALS['BE_USER']->workspace;
719 $previewUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev='.t3lib_BEfunc::compilePreviewKeyword($params, $GLOBALS['BE_USER']->user['uid'],60*60*$ttlHours);
720 }
721 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('previewUrl'), sprintf($GLOBALS['LANG']->getLL('previewInstruction'), $ttlHours) . '<br /><br /><a target="_blank" href="' . htmlspecialchars($previewUrl) . '">' . $previewUrl . '</a>', 0, 1);
722 }
723
724 // Output overview content:
725 $this->content.= $this->doc->spacer(15);
726 $this->content.= $this->doc->section($this->details ? $GLOBALS['LANG']->getLL('versionDetails') : $GLOBALS['LANG']->getLL('wsManagement'), $WSoverview,0,1);
727
728 }
729
730 function workspaceMenu() {
731 if($this->id) {
732 $menu = '';
733 if ($GLOBALS['BE_USER']->workspace===0) {
734 $menu.= t3lib_BEfunc::getFuncMenu($this->id,'SET[filter]',$this->MOD_SETTINGS['filter'],$this->MOD_MENU['filter']);
735 $menu.= t3lib_BEfunc::getFuncMenu($this->id,'SET[display]',$this->MOD_SETTINGS['display'],$this->MOD_MENU['display']);
736 }
737 if (!$this->details && $GLOBALS['BE_USER']->workspace && !$this->diffOnly) {
738 $menu.= t3lib_BEfunc::getFuncCheck($this->id,'SET[diff]',$this->MOD_SETTINGS['diff'],'','','id="checkDiff"').' <label for="checkDiff">' . $GLOBALS['LANG']->getLL('showDiffView') . '</label>';
739 }
740
741 if ($menu) {
742 return $menu;
743 }
744 }
745 }
746
747 /**
748 * Rendering the overview of versions in the current workspace
749 *
750 * @return string HTML (table)
751 * @see typo3/mod/user/ws/index.php for sister function!
752 */
753 function displayWorkspaceOverview() {
754
755 // Initialize variables:
756 $this->showWorkspaceCol = $GLOBALS['BE_USER']->workspace===0 && $this->MOD_SETTINGS['display']<=-98;
757
758 // Get usernames and groupnames
759 $be_group_Array = t3lib_BEfunc::getListGroupNames('title,uid');
760 $groupArray = array_keys($be_group_Array);
761 $this->be_user_Array = t3lib_BEfunc::getUserNames();
762 if (!$GLOBALS['BE_USER']->isAdmin()) $this->be_user_Array = t3lib_BEfunc::blindUserNames($this->be_user_Array,$groupArray,1);
763
764 // Initialize Workspace ID and filter-value:
765 if ($GLOBALS['BE_USER']->workspace===0) {
766 $wsid = $this->details ? -99 : $this->MOD_SETTINGS['display']; // Set wsid to the value from the menu (displaying content of other workspaces)
767 $filter = $this->details ? 0 : $this->MOD_SETTINGS['filter'];
768 } else {
769 $wsid = $GLOBALS['BE_USER']->workspace;
770 $filter = 0;
771 }
772
773 // Initialize workspace object and request all pending versions:
774 $wslibObj = t3lib_div::makeInstance('wslib');
775
776 // Selecting ALL versions belonging to the workspace:
777 $versions = $wslibObj->selectVersionsInWorkspace($wsid, $filter, -99, $this->uid); // $this->uid is the page id of LIVE record.
778
779 // Traverse versions and build page-display array:
780 $pArray = array();
781 foreach($versions as $table => $records) {
782 foreach($records as $rec) {
783 $pageIdField = $table==='pages' ? 't3ver_oid' : 'realpid';
784 $this->displayWorkspaceOverview_setInPageArray(
785 $pArray,
786 $table,
787 $rec
788 );
789 }
790 }
791
792 // Make header of overview:
793 $tableRows = array();
794 if (count($pArray)) {
795 $tableRows[] = '
796 <tr class="bgColor5 tableheader">
797 '.($this->diffOnly?'':'<td nowrap="nowrap" colspan="2">' . $GLOBALS['LANG']->getLL('liveVersion') . '</td>').'
798 <td nowrap="nowrap" colspan="2">' . $GLOBALS['LANG']->getLL('wsVersions') . '</td>
799 <td nowrap="nowrap"'.($this->diffOnly?' colspan="2"':' colspan="4"').'>' . $GLOBALS['LANG']->getLL('controls') . '</td>
800 </tr>';
801
802 // Add lines from overview:
803 $tableRows = array_merge($tableRows, $this->displayWorkspaceOverview_list($pArray));
804
805 $table = '<table border="0" cellpadding="0" cellspacing="1" class="lrPadding workspace-overview">'.implode('',$tableRows).'</table>';
806 } else $table = '';
807
808 $linkBack = t3lib_div::_GP('returnUrl') ? '<a href="' . htmlspecialchars(t3lib_div::_GP('returnUrl')) . '" class="typo3-goBack"><img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/goback.gif', 'width="14" height="14"') . ' alt="" />' . $GLOBALS['LANG']->getLL('goBack') . '</a><br /><br />' : '';
809 $resetDiffOnly = $this->diffOnly ? '<a href="index.php?id=' . intval($this->id) . '" class="typo3-goBack">' . $GLOBALS['LANG']->getLL('showAllInformation') . '</a><br /><br />' : '';
810
811 $versionSelector = $GLOBALS['BE_USER']->workspace ? $this->doc->getVersionSelector($this->id) : '';
812
813 return $versionSelector.$linkBack.$resetDiffOnly.$table.$this->markupNewOriginals();
814 }
815
816 /**
817 * Rendering the content for the publish / review overview:
818 * (Made for internal recursive calling)
819 *
820 * @param array Storage of the elements to display (see displayWorkspaceOverview() / displayWorkspaceOverview_setInPageArray())
821 * @return array Table rows, see displayWorkspaceOverview()
822 */
823 function displayWorkspaceOverview_list($pArray) {
824 global $TCA;
825
826 // If there ARE elements on this level, print them:
827 $warnAboutVersions_nonPages = FALSE;
828 $warnAboutVersions_page = FALSE;
829 if (is_array($pArray)) {
830 foreach($pArray as $table => $oidArray) {
831 foreach($oidArray as $oid => $recs) {
832
833 // Get CURRENT online record and icon based on "t3ver_oid":
834 $rec_on = t3lib_BEfunc::getRecord($table,$oid);
835 $icon = t3lib_iconWorks::getIconImage($table, $rec_on, $this->doc->backPath,' align="top" title="'.t3lib_BEfunc::getRecordIconAltText($rec_on,$table).'"');
836 if ($GLOBALS['BE_USER']->workspace===0) { // Only edit online records if in ONLINE workspace:
837 $icon = $this->doc->wrapClickMenuOnIcon($icon, $table, $rec_on['uid'], 1, '', '+edit,view,info,delete');
838 }
839
840 // Online version display:
841 // Create the main cells which will span over the number of versions there is.
842 $verLinkUrl = $TCA[$table]['ctrl']['versioningWS'];
843 $origElement = $icon.
844 ($verLinkUrl ? '<a href="'.htmlspecialchars('index.php?table='.$table.'&uid='.$rec_on['uid']).'">' : '').
845 t3lib_BEfunc::getRecordTitle($table,$rec_on,TRUE).
846 ($verLinkUrl ? '</a>' : '');
847 $mainCell_rowSpan = count($recs)>1 ? ' rowspan="'.count($recs).'"' : '';
848 $mainCell = '
849 <td align="center"'.$mainCell_rowSpan.'>'.$this->formatVerId($rec_on['t3ver_id']).'</td>
850 <td nowrap="nowrap"'.$mainCell_rowSpan.'>'.
851 $origElement.
852 '###SUB_ELEMENTS###'. // For substitution with sub-elements, if any.
853 '</td>';
854
855 // Offline versions display:
856 // Traverse the versions of the element
857 foreach($recs as $rec) {
858
859 // Get the offline version record and icon:
860 $rec_off = t3lib_BEfunc::getRecord($table,$rec['uid']);
861
862 // Prepare swap-mode values:
863 if ($table==='pages' && $rec_off['t3ver_swapmode']!=-1) {
864 if ($rec_off['t3ver_swapmode']>0) {
865 $vType = 'branch';
866 } else {
867 $vType = 'page';
868 }
869 } else {
870 $vType = 'element';
871 }
872
873 // Get icon
874 $icon = t3lib_iconWorks::getIconImage($table, $rec_off, $this->doc->backPath, ' align="top" title="'.t3lib_BEfunc::getRecordIconAltText($rec_off,$table).'"');
875 $tempUid = ($table != 'pages' || $vType==='branch' || $GLOBALS['BE_USER']->workspace===0 ? $rec_off['uid'] : $rec_on['uid']);
876 $icon = $this->doc->wrapClickMenuOnIcon($icon, $table, $tempUid, 1, '', '+edit,' . ($table == 'pages' ? 'view,info,' : '') . 'delete');
877
878 // Prepare diff-code:
879 if ($this->MOD_SETTINGS['diff'] || $this->diffOnly) {
880 $diffCode = '';
881 list($diffHTML,$diffPct) = $this->createDiffView($table, $rec_off, $rec_on);
882 if ($rec_on['t3ver_state']==1) { // New record:
883 $diffCode.= $this->doc->icons(1) . $GLOBALS['LANG']->getLL('newElement') . '<br />';
884 $diffCode.= $diffHTML;
885 } elseif ($rec_off['t3ver_state']==2) {
886 $diffCode.= $this->doc->icons(2) . $GLOBALS['LANG']->getLL('deletedElement') . '<br />';
887 } elseif ($rec_on['t3ver_state']==3) {
888 $diffCode.= $this->doc->icons(1) . $GLOBALS['LANG']->getLL('moveToPlaceholder') . '<br />';
889 } elseif ($rec_off['t3ver_state']==4) {
890 $diffCode.= $this->doc->icons(1) . $GLOBALS['LANG']->getLL('moveToPointer') . '<br />';
891 } else {
892 $diffCode.= ($diffPct<0 ? $GLOBALS['LANG']->getLL('notAvailable') : ($diffPct ? $diffPct . '% ' . $GLOBALS['LANG']->getLL('change') : ''));
893 $diffCode.= $diffHTML;
894 }
895 } else $diffCode = '';
896
897 switch($vType) {
898 case 'element':
899 $swapLabel = $GLOBALS['LANG']->getLL('element');
900 $swapClass = 'ver-element';
901 $warnAboutVersions_nonPages = $warnAboutVersions_page; // Setting this if sub elements are found with a page+content (must be rendered prior to this of course!)
902 break;
903 case 'page':
904 $swapLabel = $GLOBALS['LANG']->getLL('page');
905 $swapClass = 'ver-page';
906 $warnAboutVersions_page = !$this->showWorkspaceCol; // This value is true only if multiple workspaces are shown and we need the opposite here.
907 break;
908 case 'branch':
909 $swapLabel = $GLOBALS['LANG']->getLL('branch');
910 $swapClass = 'ver-branch';
911 break;
912 }
913
914 // Modify main cell based on first version shown:
915 $subElements = array();
916 if ($table==='pages' && $rec_off['t3ver_swapmode']!=-1 && $mainCell) { // For "Page" and "Branch" swap modes where $mainCell is still carrying content (only first version)
917 $subElements['on'] = $this->subElements($rec_on['uid'], $rec_off['t3ver_swapmode']);
918 $subElements['off'] = $this->subElements($rec_off['uid'],$rec_off['t3ver_swapmode'],$rec_on['uid']);
919 }
920 $mainCell = str_replace('###SUB_ELEMENTS###', $subElements['on'], $mainCell);
921
922 // Create version element:
923 $versionsInOtherWS = $this->versionsInOtherWS($table, $rec_on['uid']);
924 $versionsInOtherWSWarning = $versionsInOtherWS && $GLOBALS['BE_USER']->workspace !== 0 ? '<br />' . $this->doc->icons(2) . $GLOBALS['LANG']->getLL('otherVersions') . $versionsInOtherWS : '';
925 $multipleWarning = (!$mainCell && $GLOBALS['BE_USER']->workspace !== 0 ? '<br />' . $this->doc->icons(3) . '<b>' . $GLOBALS['LANG']->getLL('multipleVersions') . '</b>' : '');
926 $verWarning = $warnAboutVersions || ($warnAboutVersions_nonPages && $GLOBALS['TCA'][$table]['ctrl']['versioning_followPages']) ? '<br />' . $this->doc->icons(3) . '<b>' . $GLOBALS['LANG']->getLL('versionInVersion') . '</b>' : '';
927 $verElement = $icon.
928 (!$this->details ? '<a href="'.htmlspecialchars($this->doc->backPath.t3lib_extMgm::extRelPath('version').'cm1/index.php?id='.($table==='pages'?$rec_on['uid']:$rec_on['pid']).'&details='.rawurlencode($table.':'.$rec_off['uid']).'&returnUrl='.rawurlencode($this->REQUEST_URI)).'">' : '').
929 t3lib_BEfunc::getRecordTitle($table,$rec_off,TRUE).
930 (!$this->details ? '</a>' : '').
931 $versionsInOtherWSWarning.
932 $multipleWarning.
933 $verWarning;
934
935 $ctrlTable = '
936 <td nowrap="nowrap">'.$this->showStageChangeLog($table,$rec_off['uid'],$this->displayWorkspaceOverview_stageCmd($table,$rec_off)).'</td>
937 <td nowrap="nowrap" class="'.$swapClass.'">'.
938 $this->displayWorkspaceOverview_commandLinks($table,$rec_on,$rec_off,$vType).
939 htmlspecialchars($swapLabel).
940 '&nbsp;&nbsp;</td>
941 '.(!$this->diffOnly?'<td nowrap="nowrap"><b>' . $GLOBALS['LANG']->getLL('lifecycle') . ':</b> '.htmlspecialchars($this->formatCount($rec_off['t3ver_count'])).'</td>'. // Lifecycle
942 ($this->showWorkspaceCol ? '
943 <td nowrap="nowrap">&nbsp;&nbsp;<b>' . $GLOBALS['LANG']->getLL('workspace') . ':</b> '.htmlspecialchars($this->formatWorkspace($rec_off['t3ver_wsid'])).'</td>' : ''):'');
944
945 if ($diffCode) {
946 $verElement = $verElement.'
947 <br /><b>' . $GLOBALS['LANG']->getLL('diffToLiveElement') . '</b>
948 <table border="0" cellpadding="0" cellspacing="0" class="ver-verElement">
949 <tr>
950 <td class="c-diffCell">'.$diffCode.'</td>
951 </tr>
952 </table>';
953 }
954
955
956 // Create version cell:
957 $verCell = '
958 <td align="center">'.$this->formatVerId($rec_off['t3ver_id']).'</td>
959 <td nowrap="nowrap">'.
960 $verElement.
961 $subElements['off'].
962 '</td>
963 ';
964
965 // Compile table row:
966 $tableRows[] = '
967 <tr class="bgColor4">
968 '.
969 ($this->diffOnly?'':$mainCell).
970 $verCell.
971 $ctrlTable.
972 '
973 </tr>';
974
975 // Reset the main cell:
976 $mainCell = '';
977
978 }
979 }
980 }
981 }
982
983 return $tableRows;
984 }
985
986 /**
987 * Building up of the $pArray
988 * (Internal)
989 *
990 * @param array Array that is built up with the page tree structure
991 * @param string Table name
992 * @param array Table row
993 * @return void $pArray is passed by reference and modified internally
994 */
995 function displayWorkspaceOverview_setInPageArray(&$pArray,$table,$row) {
996 if (!$this->details || $this->details==$table.':'.$row['uid']) {
997 $pArray[$table][$row['t3ver_oid']][] = $row;
998 }
999 }
1000
1001 /**
1002 * Links to stage change of a version
1003 *
1004 * @param string Table name
1005 * @param array Offline record (version)
1006 * @return string HTML content, mainly link tags and images.
1007 */
1008 function displayWorkspaceOverview_allStageCmd() {
1009
1010 $table = t3lib_div::_GP('table');
1011 if ($table && $table!='pages') {
1012 $uid = t3lib_div::_GP('uid');
1013 if ($rec_off = t3lib_BEfunc::getRecordWSOL($table,$uid)) {
1014 $uid = $rec_off['_ORIG_uid'];
1015 }
1016 } else $table = '';
1017
1018 if ($table) {
1019 if ($uid && $this->recIndex[$table][$uid]) {
1020 $sId = $this->recIndex[$table][$uid];
1021 switch($sId) {
1022 case 1:
1023 $label = $GLOBALS['LANG']->getLL('commentForReviewer');
1024 break;
1025 case 10:
1026 $label = $GLOBALS['LANG']->getLL('commentForPublisher');
1027 break;
1028 }
1029 } else $sId = 0;
1030 } else {
1031 if (count($this->stageIndex[1])) { // Review:
1032 $sId = 1;
1033 $color = '#666666';
1034 $label = $GLOBALS['LANG']->getLL('sendItemsToReview') . $GLOBALS['LANG']->getLL('commentForReviewer');
1035 $titleAttrib = $GLOBALS['LANG']->getLL('sendAllToReview');
1036 } elseif(count($this->stageIndex[10])) { // Publish:
1037 $sId = 10;
1038 $color = '#6666cc';
1039 $label = $GLOBALS['LANG']->getLL('approveToPublish') . $GLOBALS['LANG']->getLL('commentForPublisher');
1040 $titleAttrib = $GLOBALS['LANG']->getLL('approveAllToPublish');
1041 } else {
1042 $sId = 0;
1043 }
1044 }
1045
1046 if ($sId>0) {
1047 $issueCmd = '';
1048 $itemCount = 0;
1049
1050 if ($table && $uid && $this->recIndex[$table][$uid]) {
1051 $issueCmd.='&cmd['.$table.']['.$uid.'][version][action]=setStage';
1052 $issueCmd.='&cmd['.$table.']['.$uid.'][version][stageId]='.$this->recIndex[$table][$uid];
1053 } else {
1054 foreach($this->stageIndex[$sId] as $table => $uidArray) {
1055 $issueCmd.='&cmd['.$table.']['.implode(',',$uidArray).'][version][action]=setStage';
1056 $issueCmd.='&cmd['.$table.']['.implode(',',$uidArray).'][version][stageId]='.$sId;
1057 $itemCount+=count($uidArray);
1058 }
1059 }
1060
1061 $onClick = 'var commentTxt=window.prompt("'.sprintf($label,$itemCount).'","");
1062 if (commentTxt!=null) {window.location.href="'.$this->doc->issueCommand($issueCmd,$this->REQUEST_URI).'&generalComment="+escape(commentTxt);}';
1063
1064 if (t3lib_div::_GP('sendToReview')) {
1065 $onClick.= ' else {window.location.href = "'.$this->REQUEST_URI.'"}';
1066 $actionLinks.=
1067 $this->doc->wrapScriptTags($onClick);
1068 } else {
1069 $onClick.= ' return false;';
1070 $actionLinks.=
1071 '<input type="submit" name="_" value="'.htmlspecialchars($titleAttrib).'" onclick="'.htmlspecialchars($onClick).'" />';
1072 }
1073 } elseif (t3lib_div::_GP('sendToReview')) {
1074 $onClick = 'window.location.href = "'.$this->REQUEST_URI.'";';
1075 $actionLinks.=
1076 $this->doc->wrapScriptTags($onClick);
1077 } else $actionLinks = '';
1078
1079 return $actionLinks;
1080 }
1081
1082
1083
1084
1085
1086
1087 /**************************************
1088 *
1089 * Helper functions (REDUNDANT FROM user/ws/index.php - someone could refactor this...)
1090 *
1091 *************************************/
1092
1093 /**
1094 * Formatting the version number for HTML output
1095 *
1096 * @param integer Version number
1097 * @return string Version number for output
1098 */
1099 function formatVerId($verId) {
1100 return '1.'.$verId;
1101 }
1102
1103 /**
1104 * Formatting workspace ID into a visual label
1105 *
1106 * @param integer Workspace ID
1107 * @return string Workspace title
1108 */
1109 function formatWorkspace($wsid) {
1110
1111 // Render, if not cached:
1112 if (!isset($this->formatWorkspace_cache[$wsid])) {
1113 switch($wsid) {
1114 case -1:
1115 $this->formatWorkspace_cache[$wsid] = $GLOBALS['LANG']->getLL('offline');
1116 break;
1117 case 0:
1118 $this->formatWorkspace_cache[$wsid] = ''; // Does not output anything for ONLINE because it might confuse people to think that the elemnet IS online which is not the case - only that it exists as an offline version in the online workspace...
1119 break;
1120 default:
1121 list($titleRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('title','sys_workspace','uid='.intval($wsid).t3lib_BEfunc::deleteClause('sys_workspace'));
1122 $this->formatWorkspace_cache[$wsid] = '['.$wsid.'] '.$titleRec['title'];
1123 break;
1124 }
1125 }
1126
1127 return $this->formatWorkspace_cache[$wsid];
1128 }
1129
1130 /**
1131 * Format publishing count for version (lifecycle state)
1132 *
1133 * @param integer t3ver_count value (number of times it has been online)
1134 * @return string String translation of count.
1135 */
1136 function formatCount($count) {
1137
1138 // Render, if not cached:
1139 if (!isset($this->formatCount_cache[$count])) {
1140 switch($count) {
1141 case 0:
1142 $this->formatCount_cache[$count] = $GLOBALS['LANG']->getLL('draft');
1143 break;
1144 case 1:
1145 $this->formatCount_cache[$count] = $GLOBALS['LANG']->getLL('archive');
1146 break;
1147 default:
1148 $this->formatCount_cache[$count] = sprintf($GLOBALS['LANG']->getLL('publishedXTimes'), $count);
1149 break;
1150 }
1151 }
1152
1153 return $this->formatCount_cache[$count];
1154 }
1155
1156 /**
1157 * Looking for versions of a record in other workspaces than the current
1158 *
1159 * @param string Table name
1160 * @param integer Record uid
1161 * @return string List of other workspace IDs
1162 */
1163 function versionsInOtherWS($table,$uid) {
1164
1165 // Check for duplicates:
1166 // Select all versions of record NOT in this workspace:
1167 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
1168 't3ver_wsid',
1169 $table,
1170 'pid=-1
1171 AND t3ver_oid='.intval($uid).'
1172 AND t3ver_wsid!='.intval($GLOBALS['BE_USER']->workspace).'
1173 AND (t3ver_wsid=-1 OR t3ver_wsid>0)'.
1174 t3lib_BEfunc::deleteClause($table),
1175 '',
1176 't3ver_wsid',
1177 '',
1178 't3ver_wsid'
1179 );
1180 if (count($rows)) {
1181 return implode(',',array_keys($rows));
1182 }
1183 }
1184
1185 /**
1186 * Looks up stage changes for version and displays a formatted view on mouseover.
1187 *
1188 * @param string Table name
1189 * @param integer Record ID
1190 * @param string HTML string to wrap the mouseover around (should be stage change links)
1191 * @return string HTML code.
1192 */
1193 function showStageChangeLog($table,$id,$stageCommands) {
1194 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
1195 'log_data,tstamp,userid',
1196 'sys_log',
1197 'action=6 and details_nr=30
1198 AND tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_log').'
1199 AND recuid='.intval($id)
1200 );
1201
1202 $entry = array();
1203 foreach($rows as $dat) {
1204 $data = unserialize($dat['log_data']);
1205 $username = $this->be_user_Array[$dat['userid']] ? $this->be_user_Array[$dat['userid']]['username'] : '['.$dat['userid'].']';
1206
1207 switch($data['stage']) {
1208 case 1:
1209 $text = $GLOBALS['LANG']->getLL('stage.sentToReview');
1210 break;
1211 case 10:
1212 $text = $GLOBALS['LANG']->getLL('stage.approvedForPublish');
1213 break;
1214 case -1:
1215 $text = $GLOBALS['LANG']->getLL('stage.rejectedElement');
1216 break;
1217 case 0:
1218 $text = $GLOBALS['LANG']->getLL('stage.resetToEdit');
1219 break;
1220 default:
1221 $text = $GLOBALS['LANG']->getLL('stage.undefined');
1222 break;
1223 }
1224 $text = t3lib_BEfunc::dateTime($dat['tstamp']).': "'.$username.'" '.$text;
1225 $text.= ($data['comment'] ? '<br />' . $GLOBALS['LANG']->getLL('userComment') . ': <em>' . htmlspecialchars($data['comment']) . '</em>' : '');
1226
1227 $entry[] = $text;
1228 }
1229
1230 return count($entry) ? '<span onmouseover="document.getElementById(\'log_'.$table.$id.'\').style.visibility = \'visible\';" onmouseout="document.getElementById(\'log_'.$table.$id.'\').style.visibility = \'hidden\';">'.$stageCommands.' ('.count($entry).')</span>'.
1231 '<div class="logLayer" style="visibility: hidden; position: absolute;" id="log_'.$table.$id.'">'.implode('<hr/>',array_reverse($entry)).'</div>' : $stageCommands;
1232 }
1233
1234 /**
1235 * Creates display of sub elements of a page when the swap mode is either "Page" or "Branch" (0 / ALL)
1236 *
1237 * @param integer Page uid (for either online or offline version, but it MUST have swapmode/treeLevel set to >0 (not -1 indicating element versioning)
1238 * @param integer The treeLevel value, >0 indicates "branch" while 0 means page+content. (-1 would have meant element versioning, but that should never happen for a call to this function!)
1239 * @param integer For offline versions; This is t3ver_oid, the original ID of the online page.
1240 * @return string HTML content.
1241 */
1242 function subElements($uid,$treeLevel,$origId=0) {
1243 global $TCA;
1244
1245 if (!$this->details && ($GLOBALS['BE_USER']->workspace===0 || !$this->MOD_SETTINGS['expandSubElements'])) { // In online workspace we have a reduced view because otherwise it will bloat the listing:
1246 return '<br />
1247 <img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/joinbottom.gif','width="18" height="16"').' align="top" alt="" title="" />'.
1248 ($origId ?
1249 '<a href="'.htmlspecialchars($this->doc->backPath.t3lib_extMgm::extRelPath('version').'cm1/index.php?id='.$uid.'&details='.rawurlencode('pages:'.$uid).'&returnUrl='.rawurlencode($this->REQUEST_URI)).'">'.
1250 '<span class="typo3-dimmed"><em>' . $GLOBALS['LANG']->getLL('subElementsClick') . '</em><span></a>' :
1251 '<span class="typo3-dimmed"><em>' . $GLOBALS['LANG']->getLL('subElements') . '</em><span>');
1252 } else { // For an offline workspace, show sub elements:
1253
1254 $tCell = array();
1255
1256 // Find records that follow pages when swapping versions:
1257 $recList = array();
1258 foreach($TCA as $tN => $tCfg) {
1259 if ($tN!='pages' && ($treeLevel>0 || $TCA[$tN]['ctrl']['versioning_followPages'])) {
1260 $this->subElements_getNonPageRecords($tN, $uid, $recList);
1261 }
1262 }
1263
1264 // Render records collected above:
1265 $elCount = count($recList)-1;
1266 foreach($recList as $c => $comb) {
1267 list($tN,$rec) = $comb;
1268
1269 $this->subElements_renderItem(
1270 $tCell,
1271 $tN,
1272 $uid,
1273 $rec,
1274 $origId,
1275 $c==$elCount && $treeLevel==0 ? 1 : 0, // If true, will show bottom-join icon.
1276 ''
1277 );
1278 }
1279
1280 // For branch, dive into the subtree:
1281 if ($treeLevel>0) {
1282
1283 // Drawing tree:
1284 $tree = t3lib_div::makeInstance('t3lib_pageTree');
1285 $tree->init('AND '.$GLOBALS['BE_USER']->getPagePermsClause(1));
1286 $tree->makeHTML = 2; // 2=Also rendering depth-data into the result array
1287 $tree->getTree($uid, 99, '');
1288
1289 // Traverse page tree:
1290 foreach($tree->tree as $data) {
1291
1292 // Render page in table cell:
1293 $this->subElements_renderItem(
1294 $tCell,
1295 'pages',
1296 $uid,
1297 t3lib_BEfunc::getRecord('pages',$data['row']['uid']), // Needs all fields, at least more than what is given in $data['row']...
1298 $origId,
1299 2, // 2=the join icon and icon for the record is not rendered for pages (where all is in $data['HTML']
1300 $data['HTML']
1301 );
1302
1303 // Find all records from page and collect in $recList:
1304 $recList = array();
1305 foreach($TCA as $tN => $tCfg) {
1306 if ($tN!=='pages') {
1307 $this->subElements_getNonPageRecords($tN, $data['row']['uid'], $recList);
1308 }
1309 }
1310
1311 // Render records collected above:
1312 $elCount = count($recList)-1;
1313 foreach($recList as $c => $comb) {
1314 list($tN,$rec) = $comb;
1315
1316 $this->subElements_renderItem(
1317 $tCell,
1318 $tN,
1319 $uid,
1320 $rec,
1321 $origId,
1322 $c==$elCount?1:0, // If true, will show bottom-join icon.
1323 $data['HTML_depthData']
1324 );
1325 }
1326 }
1327 }
1328
1329 return '
1330 <!-- Sub-element tree for versions -->
1331 <table border="0" cellpadding="0" cellspacing="1" class="ver-subtree">
1332 '.implode('',$tCell).'
1333 </table>';
1334 }
1335 }
1336
1337 /**
1338 * Select records from a table and add them to recList
1339 *
1340 * @param string Table name (from TCA)
1341 * @param integer PID to select records from
1342 * @param array Array where records are accumulated, passed by reference
1343 * @return void
1344 */
1345 function subElements_getNonPageRecords($tN, $uid, &$recList) {
1346 global $TCA;
1347
1348 $records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
1349 '*',
1350 $tN,
1351 'pid='.intval($uid).
1352 ($TCA[$tN]['ctrl']['versioningWS'] ? ' AND t3ver_state=0' : '').
1353 t3lib_BEfunc::deleteClause($tN),
1354 '',
1355 $TCA[$tN]['ctrl']['sortby'] ? $TCA[$tN]['ctrl']['sortby'] : $GLOBALS['TYPO3_DB']->stripOrderBy($TCA[$tN]['ctrl']['default_sortby'])
1356 );
1357
1358 foreach($records as $rec) {
1359 $recList[] = array($tN,$rec);
1360 }
1361 }
1362
1363 /**
1364 * Render a single item in a subelement list into a table row:
1365 *
1366 * @param array Table rows, passed by reference
1367 * @param string Table name
1368 * @param integer Page uid for which the subelements are selected/shown
1369 * @param array Row of element in list
1370 * @param integer The uid of the online version of $uid. If zero it means we are drawing a row for the online version itself while a value means we are drawing display for an offline version.
1371 * @param integer Mode of icon display: 0=not the last, 1= is the last in list (make joinbottom icon then), 2=do not shown icons are all (for pages from the page tree already rendered)
1372 * @param string Prefix HTML data (icons for tree rendering)
1373 * @return void (Content accumulated in $tCell!)
1374 */
1375 function subElements_renderItem(&$tCell,$tN,$uid,$rec,$origId,$iconMode,$HTMLdata) {
1376 global $TCA;
1377
1378 // Initialize:
1379 $origUidFields = $TCA[$tN]['ctrl']['origUid'];
1380 $diffCode = '';
1381
1382 if ($origUidFields) { // If there is a field for this table with original uids we will use that to connect records:
1383 if (!$origId) { // In case we are displaying the online originals:
1384 $this->targets['orig_'.$uid.'_'.$tN.'_'.$rec['uid']] = $rec; // Build up target array (important that
1385 $tdParams = ' id="orig_'.$uid.'_'.$tN.'_'.$rec['uid'].'" class="typo3-ver"'; // Setting ID of the table row
1386 } else { // Version branch:
1387 if ($this->targets['orig_'.$origId.'_'.$tN.'_'.$rec[$origUidFields]]) { // If there IS a corresponding original record...:
1388
1389 // Prepare Table row parameters:
1390 $tdParams = ' onmouseover="hlSubelements(\''.$origId.'_'.$tN.'_'.$rec[$origUidFields].'\', \''.$uid.'_'.$tN.'_'.$rec[$origUidFields].'\', 1, '.($this->MOD_SETTINGS['diff']==2?1:0).');"'.
1391 ' onmouseout="hlSubelements(\''.$origId.'_'.$tN.'_'.$rec[$origUidFields].'\', \''.$uid.'_'.$tN.'_'.$rec[$origUidFields].'\', 0, '.($this->MOD_SETTINGS['diff']==2?1:0).');"'.
1392 ' id="ver_'.$uid.'_'.$tN.'_'.$rec[$origUidFields].'" class="typo3-ver"';
1393
1394 // Create diff view:
1395 if ($this->MOD_SETTINGS['diff']) {
1396 list($diffHTML,$diffPct) = $this->createDiffView($tN, $rec, $this->targets['orig_'.$origId.'_'.$tN.'_'.$rec[$origUidFields]]);
1397
1398 if ($this->MOD_SETTINGS['diff']==2) {
1399 $diffCode =
1400 ($diffPct ? '<span class="nobr">'.$diffPct.'% change</span>' : '-').
1401 '<div style="visibility: hidden; position: absolute;" id="diff_'.$uid.'_'.$tN.'_'.$rec[$origUidFields].'" class="diffLayer">'.
1402 $diffHTML.
1403 '</div>';
1404 } else {
1405 $diffCode =
1406 ($diffPct<0 ? $GLOBALS['LANG']->getLL('notAvailable') : ($diffPct ? $diffPct . '% ' . $GLOBALS['LANG']->getLL('change') : '')).
1407 $diffHTML;
1408 }
1409 }
1410
1411 // Unsetting the target fields allows us to mark all originals without a version in the subtree (see ->markupNewOriginals())
1412 unset($this->targets['orig_'.$origId.'_'.$tN.'_'.$rec[$origUidFields]]);
1413 } else { // No original record, so must be new:
1414 $tdParams = ' class="typo3-ver-new"';
1415 }
1416 }
1417 } else { // If no original uid column is supported for this table we are forced NOT to display any diff or highlighting.
1418 $tdParams = ' class="typo3-ver-noComp"';
1419 }
1420
1421 // Compile the cell:
1422 $tCell[] = '
1423 <tr'.$tdParams.'>
1424 <td class="iconTitle">'.
1425 $HTMLdata.
1426 ($iconMode < 2 ?
1427 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/join'.($iconMode ? 'bottom' : '').'.gif','width="18" height="16"').' alt="" />'.
1428 t3lib_iconWorks::getIconImage($tN, $rec, $this->doc->backPath,'') : '').
1429 t3lib_BEfunc::getRecordTitle($tN, $rec, TRUE).
1430 '</td>
1431 <td class="cmdCell">'.
1432 $this->displayWorkspaceOverview_commandLinksSub($tN,$rec,$origId).
1433 '</td>'.($origId ? '<td class="diffCell">'.
1434 $diffCode.
1435 '</td>':'').'
1436 </tr>';
1437 }
1438
1439 /**
1440 * JavaScript code to mark up new records that are online (in sub element lists)
1441 *
1442 * @return string HTML javascript section
1443 */
1444 function markupNewOriginals() {
1445
1446 if (count($this->targets)) {
1447 $scriptCode = '';
1448 foreach($this->targets as $key => $rec) {
1449 $scriptCode.='
1450 document.getElementById(\''.$key.'\').attributes.getNamedItem("class").nodeValue = \'typo3-ver-new\';
1451 ';
1452 }
1453
1454 return $this->doc->wrapScriptTags($scriptCode);
1455 }
1456 }
1457
1458 /**
1459 * Create visual difference view of two records. Using t3lib_diff library
1460 *
1461 * @param string Table name
1462 * @param array New version record (green)
1463 * @param array Old version record (red)
1464 * @return array Array with two keys (0/1) with HTML content / percentage integer (if -1, then it means N/A) indicating amount of change
1465 */
1466 function createDiffView($table, $diff_1_record, $diff_2_record) {
1467 global $TCA;
1468
1469 // Initialize:
1470 $pctChange = 'N/A';
1471
1472 // Check that records are arrays:
1473 if (is_array($diff_1_record) && is_array($diff_2_record)) {
1474
1475 // Load full table description and initialize diff-object:
1476 t3lib_div::loadTCA($table);
1477 $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
1478
1479 // Add header row:
1480 $tRows = array();
1481 $tRows[] = '
1482 <tr class="bgColor5 tableheader">
1483 <td>' . $GLOBALS['LANG']->getLL('fieldname') . ':</td>
1484 <td width="98%" nowrap="nowrap">' . $GLOBALS['LANG']->getLL('coloredDiffView') . ':</td>
1485 </tr>
1486 ';
1487
1488 // Initialize variables to pick up string lengths in:
1489 $allStrLen = 0;
1490 $diffStrLen = 0;
1491
1492 // Traversing the first record and process all fields which are editable:
1493 foreach($diff_1_record as $fN => $fV) {
1494 if ($TCA[$table]['columns'][$fN] && $TCA[$table]['columns'][$fN]['config']['type']!='passthrough' && !t3lib_div::inList('t3ver_label',$fN)) {
1495
1496 // Check if it is files:
1497 $isFiles = FALSE;
1498 if (strcmp(trim($diff_1_record[$fN]),trim($diff_2_record[$fN])) &&
1499 $TCA[$table]['columns'][$fN]['config']['type']=='group' &&
1500 $TCA[$table]['columns'][$fN]['config']['internal_type']=='file') {
1501
1502 // Initialize:
1503 $uploadFolder = $TCA[$table]['columns'][$fN]['config']['uploadfolder'];
1504 $files1 = array_flip(t3lib_div::trimExplode(',', $diff_1_record[$fN],1));
1505 $files2 = array_flip(t3lib_div::trimExplode(',', $diff_2_record[$fN],1));
1506
1507 // Traverse filenames and read their md5 sum:
1508 foreach($files1 as $filename => $tmp) {
1509 $files1[$filename] = @is_file(PATH_site.$uploadFolder.'/'.$filename) ? md5(t3lib_div::getUrl(PATH_site.$uploadFolder.'/'.$filename)) : $filename;
1510 }
1511 foreach($files2 as $filename => $tmp) {
1512 $files2[$filename] = @is_file(PATH_site.$uploadFolder.'/'.$filename) ? md5(t3lib_div::getUrl(PATH_site.$uploadFolder.'/'.$filename)) : $filename;
1513 }
1514
1515 // Implode MD5 sums and set flag:
1516 $diff_1_record[$fN] = implode(' ',$files1);
1517 $diff_2_record[$fN] = implode(' ',$files2);
1518 $isFiles = TRUE;
1519 }
1520
1521 // If there is a change of value:
1522 if (strcmp(trim($diff_1_record[$fN]),trim($diff_2_record[$fN]))) {
1523
1524
1525 // Get the best visual presentation of the value and present that:
1526 $val1 = t3lib_BEfunc::getProcessedValue($table,$fN,$diff_2_record[$fN],0,1);
1527 $val2 = t3lib_BEfunc::getProcessedValue($table,$fN,$diff_1_record[$fN],0,1);
1528
1529 // Make diff result and record string lenghts:
1530 $diffres = $t3lib_diff_Obj->makeDiffDisplay($val1,$val2,$isFiles?'div':'span');
1531 $diffStrLen+= $t3lib_diff_Obj->differenceLgd;
1532 $allStrLen+= strlen($val1.$val2);
1533
1534 // If the compared values were files, substituted MD5 hashes:
1535 if ($isFiles) {
1536 $allFiles = array_merge($files1,$files2);
1537 foreach($allFiles as $filename => $token) {
1538 if (strlen($token)==32 && strstr($diffres,$token)) {
1539 $filename =
1540 t3lib_BEfunc::thumbCode(array($fN=>$filename),$table,$fN,$this->doc->backPath).
1541 $filename;
1542 $diffres = str_replace($token,$filename,$diffres);
1543 }
1544 }
1545 }
1546
1547 // Add table row with result:
1548 $tRows[] = '
1549 <tr class="bgColor4">
1550 <td>'.htmlspecialchars($GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel($table,$fN))).'</td>
1551 <td width="98%">'.$diffres.'</td>
1552 </tr>
1553 ';
1554 } else {
1555 // Add string lengths even if value matched - in this was the change percentage is not high if only a single field is changed:
1556 $allStrLen+=strlen($diff_1_record[$fN].$diff_2_record[$fN]);
1557 }
1558 }
1559 }
1560
1561 // Calculate final change percentage:
1562 $pctChange = $allStrLen ? ceil($diffStrLen*100/$allStrLen) : -1;
1563
1564 // Create visual representation of result:
1565 if (count($tRows)>1) {
1566 $content.= '<table border="0" cellpadding="1" cellspacing="1" class="diffTable">'.implode('',$tRows).'</table>';
1567 } else {
1568 $content.= '<span class="nobr">'.$this->doc->icons(1) . $GLOBALS['LANG']->getLL('completeMatch') . '</span>';
1569 }
1570 } else $content.= $this->doc->icons(3) . $GLOBALS['LANG']->getLL('errorRecordsNotFound');
1571
1572 // Return value:
1573 return array($content,$pctChange);
1574 }
1575
1576 /**
1577 * Links to stage change of a version
1578 *
1579 * @param string Table name
1580 * @param array Offline record (version)
1581 * @return string HTML content, mainly link tags and images.
1582 */
1583 function displayWorkspaceOverview_stageCmd($table,&$rec_off) {
1584 #debug($rec_off['t3ver_stage']);
1585 switch((int)$rec_off['t3ver_stage']) {
1586 case 0:
1587 $sId = 1;
1588 $sLabel = $GLOBALS['LANG']->getLL('editing');
1589 $color = '#666666';
1590 $label = $GLOBALS['LANG']->getLL('commentForReviewer');
1591 $titleAttrib = $GLOBALS['LANG']->getLL('sendToReview');
1592 break;
1593 case 1:
1594 $sId = 10;
1595 $sLabel = $GLOBALS['LANG']->getLL('review');
1596 $color = '#6666cc';
1597 $label = $GLOBALS['LANG']->getLL('commentForPublisher');
1598 $titleAttrib = $GLOBALS['LANG']->getLL('approveForPublishing');
1599 break;
1600 case 10:
1601 $sLabel = $GLOBALS['LANG']->getLL('publish');
1602 $color = '#66cc66';
1603 break;
1604 case -1:
1605 $sLabel = $this->doc->icons(2) . $GLOBALS['LANG']->getLL('rejected');
1606 $sId = 0;
1607 $color = '#ff0000';
1608 $label = $GLOBALS['LANG']->getLL('comment');
1609 $titleAttrib = $GLOBALS['LANG']->getLL('resetStage');
1610 break;
1611 default:
1612 $sLabel = $GLOBALS['LANG']->getLL('undefined');
1613 $sId = 0;
1614 $color = '';
1615 break;
1616 }
1617 #debug($sId);
1618
1619 $raiseOk = !$GLOBALS['BE_USER']->workspaceCannotEditOfflineVersion($table,$rec_off);
1620
1621 if ($raiseOk && $rec_off['t3ver_stage']!=-1) {
1622 $onClick = 'var commentTxt=window.prompt("' . $GLOBALS['LANG']->getLL('rejectExplain') . '","");
1623 if (commentTxt!=null) {window.location.href="'.$this->doc->issueCommand(
1624 '&cmd['.$table.']['.$rec_off['uid'].'][version][action]=setStage'.
1625 '&cmd['.$table.']['.$rec_off['uid'].'][version][stageId]=-1'
1626 ).'&cmd['.$table.']['.$rec_off['uid'].'][version][comment]="+escape(commentTxt);}'.
1627 ' return false;';
1628 // Reject:
1629 $actionLinks.=
1630 '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
1631 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/down.gif','width="14" height="14"').' alt="" align="top" title="' . $GLOBALS['LANG']->getLL('reject') . '" />'.
1632 '</a>';
1633 } else {
1634 // Reject:
1635 $actionLinks.=
1636 '<img src="'.$this->doc->backPath.'gfx/clear.gif" width="14" height="14" alt="" align="top" title="" />';
1637 }
1638
1639 $actionLinks.= '<span style="background-color: '.$color.'; color: white;">'.$sLabel.'</span>';
1640
1641 // Raise
1642 if ($raiseOk) {
1643 $onClick = 'var commentTxt=window.prompt("'.$label.'","");
1644 if (commentTxt!=null) {window.location.href="'.$this->doc->issueCommand(
1645 '&cmd['.$table.']['.$rec_off['uid'].'][version][action]=setStage'.
1646 '&cmd['.$table.']['.$rec_off['uid'].'][version][stageId]='.$sId
1647 ).'&cmd['.$table.']['.$rec_off['uid'].'][version][comment]="+escape(commentTxt);}'.
1648 ' return false;';
1649 if ($rec_off['t3ver_stage']!=10) {
1650 $actionLinks.=
1651 '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
1652 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/up.gif','width="14" height="14"').' alt="" align="top" title="'.htmlspecialchars($titleAttrib).'" />'.
1653 '</a>';
1654
1655 $this->stageIndex[$sId][$table][] = $rec_off['uid'];
1656 $this->recIndex[$table][$rec_off['uid']] = $sId;
1657 }
1658 }
1659 return $actionLinks;
1660 }
1661
1662 /**
1663 * Links to publishing etc of a version
1664 *
1665 * @param string Table name
1666 * @param array Online record
1667 * @param array Offline record (version)
1668 * @param string Swap type, "branch", "page" or "element"
1669 * @return string HTML content, mainly link tags and images.
1670 */
1671 function displayWorkspaceOverview_commandLinks($table,&$rec_on,&$rec_off,$vType) {
1672 if ($this->publishAccess && (!($GLOBALS['BE_USER']->workspaceRec['publish_access']&1) || (int)$rec_off['t3ver_stage']===10)) {
1673 $actionLinks =
1674 '<a href="'.htmlspecialchars($this->doc->issueCommand(
1675 '&cmd['.$table.']['.$rec_on['uid'].'][version][action]=swap'.
1676 '&cmd['.$table.']['.$rec_on['uid'].'][version][swapWith]='.$rec_off['uid']
1677 )).'">'.
1678 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert1.gif','width="14" height="14"').' alt="" align="top" title="' . $GLOBALS['LANG']->getLL('publish') . '" />'.
1679 '</a>';
1680 if ($GLOBALS['BE_USER']->workspaceSwapAccess()) {
1681 $actionLinks.=
1682 '<a href="'.htmlspecialchars($this->doc->issueCommand(
1683 '&cmd['.$table.']['.$rec_on['uid'].'][version][action]=swap'.
1684 '&cmd['.$table.']['.$rec_on['uid'].'][version][swapWith]='.$rec_off['uid'].
1685 '&cmd['.$table.']['.$rec_on['uid'].'][version][swapIntoWS]=1'
1686 )).'">'.
1687 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/swap.png','width="14" height="14"').' alt="" align="top" title="' . $GLOBALS['LANG']->getLL('swap') . '" />'.
1688 '</a>';
1689 }
1690 }
1691
1692 if (!$GLOBALS['BE_USER']->workspaceCannotEditOfflineVersion($table,$rec_off)) {
1693 // Release
1694 $actionLinks.=
1695 '<a href="'.htmlspecialchars($this->doc->issueCommand('&cmd['.$table.']['.$rec_off['uid'].'][version][action]=clearWSID')).'" onclick="return confirm(\'' . $GLOBALS['LANG']->getLL('removeFromWorkspace') . '?\');">'.
1696 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/group_clear.gif','width="14" height="14"').' alt="" align="top" title="' . $GLOBALS['LANG']->getLL('removeFromWorkspace') . '" />'.
1697 '</a>';
1698
1699 // Edit
1700 if ($table==='pages' && $vType!=='element') {
1701 $tempUid = ($vType==='branch' || $GLOBALS['BE_USER']->workspace===0 ? $rec_off['uid'] : $rec_on['uid']);
1702 $actionLinks.=
1703 '<a href="#" onclick="top.loadEditId('.$tempUid.');top.goToModule(\''.$this->pageModule.'\'); return false;">'.
1704 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,t3lib_extMgm::extRelPath('cms').'layout/layout.gif','width="14" height="12"').' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:img_title_edit_page'). '" alt="" />'.
1705 '</a>';
1706 } else {
1707 $params = '&edit['.$table.']['.$rec_off['uid'].']=edit';
1708 $actionLinks.=
1709 '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->doc->backPath)).'">'.
1710 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/edit2.gif','width="12" height="12"').' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:img_title_edit_element'). '" alt="" />'.
1711 '</a>';
1712 }
1713 }
1714
1715 // History/Log
1716 $actionLinks.=
1717 '<a href="'.htmlspecialchars($this->doc->backPath.'show_rechis.php?element='.rawurlencode($table.':'.$rec_off['uid']).'&returnUrl='.rawurlencode($this->REQUEST_URI)).'">'.
1718 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/history2.gif','width="13" height="12"').' title="' . $GLOBALS['LANG']->getLL('showLog') . '" alt="" />'.
1719 '</a>';
1720
1721 // View
1722 if ($table==='pages') {
1723 $tempUid = ($vType==='branch' || $GLOBALS['BE_USER']->workspace===0 ? $rec_off['uid'] : $rec_on['uid']);
1724 $actionLinks.=
1725 '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($tempUid,$this->doc->backPath,t3lib_BEfunc::BEgetRootLine($tempUid))).'">'.
1726 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
1727 '</a>';
1728 }
1729
1730 return $actionLinks;
1731 }
1732
1733 /**
1734 * Links to publishing etc of a version
1735 *
1736 * @param string Table name
1737 * @param array Record
1738 * @param integer The uid of the online version of $uid. If zero it means we are drawing a row for the online version itself while a value means we are drawing display for an offline version.
1739 * @return string HTML content, mainly link tags and images.
1740 */
1741 function displayWorkspaceOverview_commandLinksSub($table,$rec,$origId) {
1742 $uid = $rec['uid'];
1743 if ($origId || $GLOBALS['BE_USER']->workspace===0) {
1744 if (!$GLOBALS['BE_USER']->workspaceCannotEditRecord($table,$rec)) {
1745 // Edit
1746 if ($table==='pages') {
1747 $actionLinks.=
1748 '<a href="#" onclick="top.loadEditId('.$uid.');top.goToModule(\''.$this->pageModule.'\'); return false;">'.
1749 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,t3lib_extMgm::extRelPath('cms').'layout/layout.gif','width="14" height="12"').' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:img_title_edit_page'). '" alt="" />'.
1750 '</a>';
1751 } else {
1752 $params = '&edit['.$table.']['.$uid.']=edit';
1753 $actionLinks.=
1754 '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->doc->backPath)).'">'.
1755 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/edit2.gif','width="12" height="12"').' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_user_ws.xml:img_title_edit_element'). '" alt="" />'.
1756 '</a>';
1757 }
1758 }
1759
1760 // History/Log
1761 $actionLinks.=
1762 '<a href="'.htmlspecialchars($this->doc->backPath.'show_rechis.php?element='.rawurlencode($table.':'.$uid).'&returnUrl='.rawurlencode($this->REQUEST_URI)).'">'.
1763 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/history2.gif','width="13" height="12"').' title="' . $GLOBALS['LANG']->getLL('showLog') . '" alt="" />'.
1764 '</a>';
1765 }
1766
1767 // View
1768 if ($table==='pages') {
1769 $actionLinks.=
1770 '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($uid,$this->doc->backPath,t3lib_BEfunc::BEgetRootLine($uid))).'">'.
1771 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
1772 '</a>';
1773 }
1774
1775 return $actionLinks;
1776 }
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786 /**********************************
1787 *
1788 * Processing
1789 *
1790 **********************************/
1791
1792 /**
1793 * Will publish workspace if buttons are pressed
1794 *
1795 * @return void
1796 */
1797 function publishAction() {
1798
1799 // If "Publish" or "Swap" buttons are pressed:
1800 if (t3lib_div::_POST('_publish') || t3lib_div::_POST('_swap')) {
1801
1802 if ($this->table==='pages') { // Making sure ->uid is a page ID!
1803 // Initialize workspace object and request all pending versions:
1804 $wslibObj = t3lib_div::makeInstance('wslib');
1805 $cmd = $wslibObj->getCmdArrayForPublishWS($GLOBALS['BE_USER']->workspace, t3lib_div::_POST('_swap'),$this->uid);
1806
1807 // Execute the commands:
1808 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
1809 $tce->stripslashes_values = 0;
1810 $tce->start(array(), $cmd);
1811 $tce->process_cmdmap();
1812
1813 t3lib_BEfunc::getSetUpdateSignal('updatePageTree');
1814
1815 return $tce->errorLog;
1816 }
1817 }
1818 }
1819 }
1820
1821
1822
1823 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/version/cm1/index.php']) {
1824 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/version/cm1/index.php']);
1825 }
1826
1827
1828
1829
1830 // Make instance:
1831 $SOBE = t3lib_div::makeInstance('tx_version_cm1');
1832 $SOBE->init();
1833
1834
1835 $SOBE->main();
1836 $SOBE->printContent();
1837
1838 ?>