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