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