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