index.php 72.2 KB
Newer Older
Kasper Skårhøj's avatar
Kasper Skårhøj committed
1
2
3
4
<?php
/***************************************************************
*  Copyright notice
*
5
*  (c) 2004-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
Kasper Skårhøj's avatar
Kasper Skårhøj committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
Kasper Skårhøj's avatar
Kasper Skårhøj committed
25
 * Versioning module
Kasper Skårhøj's avatar
Kasper Skårhøj committed
26
27
28
 *
 * @author	Kasper Skaarhoj <kasperYYYY@typo3.com>
 */
29
30
31
32
33
/**
 * [CLASS/FUNCTION INDEX of SCRIPT]
 *
 *
 *
34
 *  102: class tx_version_cm1 extends t3lib_SCbase
Kasper Skårhøj's avatar
Kasper Skårhøj committed
35
36
 *
 *              SECTION: Standard module initialization
37
38
39
40
 *  138:     function menuConfig()
 *  175:     function main()
 *  236:     function jumpToUrl(URL)
 *  296:     function printContent()
Kasper Skårhøj's avatar
Kasper Skårhøj committed
41
42
 *
 *              SECTION: Versioning management
43
44
45
46
 *  322:     function versioningMgm()
 *  485:     function pageSubContent($pid,$c=0)
 *  539:     function lookForOwnVersions($table,$uid)
 *  556:     function adminLinks($table,$row)
Kasper Skårhøj's avatar
Kasper Skårhøj committed
47
48
 *
 *              SECTION: Workspace management
49
50
51
52
53
 *  628:     function workspaceMgm()
 *  688:     function displayWorkspaceOverview()
 *  758:     function displayWorkspaceOverview_list($pArray)
 *  923:     function displayWorkspaceOverview_setInPageArray(&$pArray,$table,$row)
 *  936:     function displayWorkspaceOverview_allStageCmd()
Kasper Skårhøj's avatar
Kasper Skårhøj committed
54
55
 *
 *              SECTION: Helper functions (REDUNDANT FROM user/ws/index.php - someone could refactor this...)
56
57
58
59
60
61
62
63
64
65
66
67
68
 *  986:     function formatVerId($verId)
 *  996:     function formatWorkspace($wsid)
 * 1023:     function formatCount($count)
 * 1050:     function versionsInOtherWS($table,$uid)
 * 1080:     function showStageChangeLog($table,$id,$stageCommands)
 * 1129:     function subElements($uid,$treeLevel,$origId=0)
 * 1232:     function subElements_getNonPageRecords($tN, $uid, &$recList)
 * 1262:     function subElements_renderItem(&$tCell,$tN,$uid,$rec,$origId,$iconMode,$HTMLdata)
 * 1331:     function markupNewOriginals()
 * 1353:     function createDiffView($table, $diff_1_record, $diff_2_record)
 * 1470:     function displayWorkspaceOverview_stageCmd($table,&$rec_off)
 * 1557:     function displayWorkspaceOverview_commandLinks($table,&$rec_on,&$rec_off,$vType)
 * 1627:     function displayWorkspaceOverview_commandLinksSub($table,$rec,$origId)
Kasper Skårhøj's avatar
Kasper Skårhøj committed
69
 *
70
71
72
73
 *              SECTION: Processing
 * 1683:     function publishAction()
 *
 * TOTAL FUNCTIONS: 27
74
75
76
 * (This index is automatically created/updated by the extension "extdeveval")
 *
 */
Kasper Skårhøj's avatar
Kasper Skårhøj committed
77
78
79
80


	// DEFAULT initialization of a module [BEGIN]
unset($MCONF);
Kasper Skårhøj's avatar
Kasper Skårhøj committed
81
82
83
84
require ('conf.php');
require ($BACK_PATH.'init.php');
require ($BACK_PATH.'template.php');
$LANG->includeLLFile('EXT:version/locallang.xml');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
85
86
	// DEFAULT initialization of a module [END]

Kasper Skårhøj's avatar
Kasper Skårhøj committed
87
require_once(PATH_typo3.'mod/user/ws/class.wslib.php');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
88
89


Kasper Skårhøj's avatar
Kasper Skårhøj committed
90

91
/**
Kasper Skårhøj's avatar
Kasper Skårhøj committed
92
 * Versioning module, including workspace management
93
94
95
96
97
 *
 * @author	Kasper Skaarhoj <kasperYYYY@typo3.com>
 * @package TYPO3
 * @subpackage core
 */
Kasper Skårhøj's avatar
Kasper Skårhøj committed
98
99
class tx_version_cm1 extends t3lib_SCbase {

Kasper Skårhøj's avatar
Kasper Skårhøj committed
100
101
102
103
		// Default variables for backend modules
	var $MCONF = array();				// Module configuration
	var $MOD_MENU = array();			// Module menu items
	var $MOD_SETTINGS = array();		// Module session settings
104
105
106
107
108
109
110

	/**
	 * document template object
	 *
	 * @var mediumDoc
	 */
	var $doc;
Kasper Skårhøj's avatar
Kasper Skårhøj committed
111
112
113
114
115
116
117
118
119
120
121
	var $content;						// Accumulated content


		// Internal:
	var $showWorkspaceCol = 0;
	var $formatWorkspace_cache = array();
	var $formatCount_cache = array();
	var $targets = array();		// Accumulation of online targets.
	var $pageModule = '';			// Name of page module
	var $publishAccess = FALSE;
	var $be_user_Array = array();
122
	var $stageIndex = array();
Kasper Skårhøj's avatar
   
Kasper Skårhøj committed
123
	var $recIndex = array();
124
	protected $showDraftWorkspace = FALSE; // Determines whether to show the dummy draft workspace
Kasper Skårhøj's avatar
Kasper Skårhøj committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143






	/*********************************
	 *
	 * Standard module initialization
	 *
	 *********************************/

	/**
	 * Initialize menu configuration
	 *
	 * @return	void
	 */
	function menuConfig()	{

144
145
146
147
148
149
150
			// fetches the configuration of the version extension
		$versionExtconf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['version']);
			// show draft workspace only if enabled in the version extensions config
		if($versionExtconf['showDraftWorkspace']) {
			$this->showDraftWorkspace = TRUE;
		}

Kasper Skårhøj's avatar
Kasper Skårhøj committed
151
152
153
			// Menu items:
		$this->MOD_MENU = array(
			'filter' => array(
154
155
156
				1 => $GLOBALS['LANG']->getLL('filter_drafts'),
				2 => $GLOBALS['LANG']->getLL('filter_archive'),
				0 => $GLOBALS['LANG']->getLL('filter_all'),
Kasper Skårhøj's avatar
Kasper Skårhøj committed
157
158
			),
			'display' => array(
159
160
161
				0 => $GLOBALS['LANG']->getLL('liveWorkspace'),
				-98 => $GLOBALS['LANG']->getLL('draftWorkspaces'),
				-99 => $GLOBALS['LANG']->getLL('filter_all'),
Kasper Skårhøj's avatar
Kasper Skårhøj committed
162
163
164
			),
			'diff' => ''
		);
165
166
167
168
		
		if($this->showDraftWorkspace === TRUE) {
			$this->MOD_MENU['display'][-1] = $GLOBALS['LANG']->getLL('defaultDraft');
		}
Kasper Skårhøj's avatar
Kasper Skårhøj committed
169
170
171
172
173
174
175
176
177
178
179
180
181
182

			// Add workspaces:
		if ($GLOBALS['BE_USER']->workspace===0)	{	// Spend time on this only in online workspace because it might take time:
			$workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
			foreach($workspaces as $rec)	{
				if ($GLOBALS['BE_USER']->checkWorkspace($rec))	{
					$this->MOD_MENU['display'][$rec['uid']] = '['.$rec['uid'].'] '.$rec['title'];
				}
			}
		}

			// CLEANSE SETTINGS
		$this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name'], 'ses');
	}
Kasper Skårhøj's avatar
Kasper Skårhøj committed
183

Kasper Skårhøj's avatar
Kasper Skårhøj committed
184
185
	/**
	 * Main function of the module. Write the content to $this->content
186
	 *
Kasper Skårhøj's avatar
Kasper Skårhøj committed
187
	 * @return	void
Kasper Skårhøj's avatar
Kasper Skårhøj committed
188
189
190
	 */
	function main()	{
		global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
191
		
192
193
194
195
196
197
198
			// Template markers
		$markers = array(
			'CSH' => '',
			'FUNC_MENU' => '',
			'WS_MENU' => '',
			'CONTENT' => ''
		);
Ingo Renner's avatar
Ingo Renner committed
199

Kasper Skårhøj's avatar
Kasper Skårhøj committed
200
201
			// Setting module configuration:
		$this->MCONF = $GLOBALS['MCONF'];
Ingo Renner's avatar
Ingo Renner committed
202

Kasper Skårhøj's avatar
   
Kasper Skårhøj committed
203
		$this->REQUEST_URI = str_replace('&sendToReview=1','',t3lib_div::getIndpEnv('REQUEST_URI'));
Kasper Skårhøj's avatar
Kasper Skårhøj committed
204

Kasper Skårhøj's avatar
Kasper Skårhøj committed
205
			// Draw the header.
206
		$this->doc = t3lib_div::makeInstance('template');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
207
		$this->doc->backPath = $BACK_PATH;
208
		$this->doc->setModuleTemplate('templates/version.html');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
209

210
211
212
213
214
215
	        // Add styles
		$this->doc->inDocStylesArray[$GLOBALS['MCONF']['name']] = '
.version-diff-1 { background-color: green; }
.version-diff-2 { background-color: red; }
';

Kasper Skårhøj's avatar
Kasper Skårhøj committed
216
			// Setting up the context sensitive menu:
217
		$this->doc->getContextMenuCode();
Kasper Skårhøj's avatar
Kasper Skårhøj committed
218

Kasper Skårhøj's avatar
Kasper Skårhøj committed
219
220
221
222
223
224
225
226
227
			// Getting input data:
		$this->id = intval(t3lib_div::_GP('id'));		// Page id. If set, indicates activation from Web>Versioning module
		if (!$this->id)	{
			$this->uid = intval(t3lib_div::_GP('uid'));		// Record uid. Goes with table name to indicate specific record
			$this->table = t3lib_div::_GP('table');			// Record table. Goes with uid to indicate specific record
		} else {
			$this->uid = $this->id;
			$this->table = 'pages';
		}
Kasper Skårhøj's avatar
Kasper Skårhøj committed
228
		$this->details = t3lib_div::_GP('details');		// Page id. If set, indicates activation from Web>Versioning module
229
		$this->diffOnly = t3lib_div::_GP('diffOnly');		// Flag. If set, shows only the offline version and with diff-view
Kasper Skårhøj's avatar
Kasper Skårhøj committed
230
231
232
233

			// Force this setting:
		$this->MOD_SETTINGS['expandSubElements'] = TRUE;
		$this->MOD_SETTINGS['diff'] = $this->details || $this->MOD_SETTINGS['diff']?1:0;
Kasper Skårhøj's avatar
Kasper Skårhøj committed
234

Kasper Skårhøj's avatar
Kasper Skårhøj committed
235
			// Reading the record:
Kasper Skårhøj's avatar
Kasper Skårhøj committed
236
		$record = t3lib_BEfunc::getRecord($this->table,$this->uid);
Kasper Skårhøj's avatar
Kasper Skårhøj committed
237
238
239
		if ($record['pid']==-1)	{
			$record = t3lib_BEfunc::getRecord($this->table,$record['t3ver_oid']);
		}
Ingo Renner's avatar
Ingo Renner committed
240

241
		$this->recordFound = is_array($record);
Ingo Renner's avatar
Ingo Renner committed
242

243
		$pidValue = $this->table==='pages' ? $this->uid : $record['pid'];
Kasper Skårhøj's avatar
Kasper Skårhøj committed
244

Kasper Skårhøj's avatar
Kasper Skårhøj committed
245
			// Checking access etc.
246
247
		if ($this->recordFound && $TCA[$this->table]['ctrl']['versioningWS'])	{
			$this->doc->form='<form action="" method="post">';
Kasper Skårhøj's avatar
Kasper Skårhøj committed
248
249
			$this->uid = $record['uid']; 	// Might have changed if new live record was found!

Kasper Skårhøj's avatar
Kasper Skårhøj committed
250
251
				// Access check!
				// The page will show only if there is a valid page and if this page may be viewed by the user
252
			$this->pageinfo = t3lib_BEfunc::readPageAccess($pidValue,$this->perms_clause);
Kasper Skårhøj's avatar
Kasper Skårhøj committed
253
254
			$access = is_array($this->pageinfo) ? 1 : 0;

255
			if (($pidValue && $access) || ($BE_USER->user['admin'] && !$pidValue))	{
Kasper Skårhøj's avatar
Kasper Skårhøj committed
256
257

					// JavaScript
258
				$this->doc->JScode.= '
Kasper Skårhøj's avatar
Kasper Skårhøj committed
259
260
261
					<script language="javascript" type="text/javascript">
						script_ended = 0;
						function jumpToUrl(URL)	{
262
							window.location.href = URL;
Kasper Skårhøj's avatar
Kasper Skårhøj committed
263
						}
Kasper Skårhøj's avatar
Kasper Skårhøj committed
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279

						function hlSubelements(origId, verId, over, diffLayer)	{	//
							if (over)	{
								document.getElementById(\'orig_\'+origId).attributes.getNamedItem("class").nodeValue = \'typo3-ver-hl\';
								document.getElementById(\'ver_\'+verId).attributes.getNamedItem("class").nodeValue = \'typo3-ver-hl\';
								if (diffLayer)	{
									document.getElementById(\'diff_\'+verId).style.visibility = \'visible\';
								}
							} else {
								document.getElementById(\'orig_\'+origId).attributes.getNamedItem("class").nodeValue = \'typo3-ver\';
								document.getElementById(\'ver_\'+verId).attributes.getNamedItem("class").nodeValue = \'typo3-ver\';
								if (diffLayer)	{
									document.getElementById(\'diff_\'+verId).style.visibility = \'hidden\';
								}
							}
						}
Kasper Skårhøj's avatar
Kasper Skårhøj committed
280
281
282
					</script>
				';

Kasper Skårhøj's avatar
Kasper Skårhøj committed
283
284
285
286
287
288
289
290
					// If another page module was specified, replace the default Page module with the new one
				$newPageModule = trim($BE_USER->getTSConfigVal('options.overridePageModule'));
				$this->pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';

					// Setting publish access permission for workspace:
				$this->publishAccess = $BE_USER->workspacePublishAccess($BE_USER->workspace);

					// Render content:
Kasper Skårhøj's avatar
Kasper Skårhøj committed
291
292
293
294
295
				if ($this->id)	{
					$this->workspaceMgm();
				} else {
					$this->versioningMgm();
				}
Kasper Skårhøj's avatar
Kasper Skårhøj committed
296
297
298
			}

			$this->content.=$this->doc->spacer(10);
Ingo Renner's avatar
Ingo Renner committed
299

300
				// Setting up the buttons and markers for docheader
301
			$docHeaderButtons = $this->getButtons();
302
303
304
305
			$markers['CSH'] = $docHeaderButtons['csh'];
			$markers['FUNC_MENU'] = t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
			$markers['WS_MENU'] = $this->workspaceMenu();
			$markers['CONTENT'] = $this->content;
306
		} else {
307
308
				// If no access or id value, create empty document
			$this->content = $this->doc->section($LANG->getLL('clickAPage_header'), $LANG->getLL('clickAPage_content'), 0, 1);
Ingo Renner's avatar
Ingo Renner committed
309

310
311
312
				// Setting up the buttons and markers for docheader
			$docHeaderButtons = $this->getButtons();
			$markers['CONTENT'] = $this->content;
Kasper Skårhøj's avatar
Kasper Skårhøj committed
313
		}
314
315
316
317
318
			// Build the <body> for the module
		$this->content = $this->doc->startPage($LANG->getLL('title'));
		$this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
		$this->content.= $this->doc->endPage();
		$this->content = $this->doc->insertStylesAndJS($this->content);
Kasper Skårhøj's avatar
Kasper Skårhøj committed
319
	}
320
321

	/**
Kasper Skårhøj's avatar
Kasper Skårhøj committed
322
	 * Outputs accumulated module content to browser.
323
	 *
Kasper Skårhøj's avatar
Kasper Skårhøj committed
324
	 * @return	void
325
	 */
Kasper Skårhøj's avatar
Kasper Skårhøj committed
326
327
328
329
	function printContent()	{
		echo $this->content;
	}

330
331
332
333
334
	/**
	 * Create the panel of buttons for submitting the form or otherwise perform operations.
	 *
	 * @return	array	all available buttons as an assoc. array
	 */
335
	protected function getButtons()	{
336
		global $TCA, $LANG, $BACK_PATH, $BE_USER;
Ingo Renner's avatar
Ingo Renner committed
337

338
339
340
341
342
343
344
345
		$buttons = array(
			'csh' => '',
			'view' => '',
			'record_list' => '',
			'shortcut' => '',
		);
			// CSH
		//$buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_txversionM1', '', $GLOBALS['BACK_PATH']);
Ingo Renner's avatar
Ingo Renner committed
346

347
348
		if ($this->recordFound && $TCA[$this->table]['ctrl']['versioningWS']) {
				// View page
349
			$buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::viewOnClick($this->pageinfo['uid'], $BACK_PATH, t3lib_BEfunc::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', TRUE) . '">' .
350
						t3lib_iconWorks::getSpriteIcon('actions-document-view') .
351
					'</a>';
Ingo Renner's avatar
Ingo Renner committed
352

353
354
355
356
				// Shortcut
			if ($BE_USER->mayMakeShortcut())	{
				$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']);
			}
Ingo Renner's avatar
Ingo Renner committed
357

358
359
360
				// If access to Web>List for user, then link to that module.
			if ($BE_USER->check('modules','web_list'))	{
				$href = $BACK_PATH . 'db_list.php?id=' . $this->pageinfo['uid'] . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
361
				$buttons['record_list'] = '<a href="' . htmlspecialchars($href) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList', TRUE) . '">' .
362
							t3lib_iconWorks::getSpriteIcon('actions-system-list-open') .
363
364
						'</a>';
			}
365
366
367
		}
		return $buttons;
	}
Kasper Skårhøj's avatar
Kasper Skårhøj committed
368
369
370
371
372
373
374
375
376
377
378
379
380
381








	/******************************
	 *
	 * Versioning management
	 *
	 ******************************/

382
	/**
Kasper Skårhøj's avatar
Kasper Skårhøj committed
383
	 * Management of versions for record
384
	 *
Kasper Skårhøj's avatar
Kasper Skårhøj committed
385
	 * @return	void
386
	 */
Kasper Skårhøj's avatar
Kasper Skårhøj committed
387
	function versioningMgm()	{
Kasper Skårhøj's avatar
Kasper Skårhøj committed
388
389
390
391
392
393
394
		global $TCA;

			// Diffing:
		$diff_1 = t3lib_div::_POST('diff_1');
		$diff_2 = t3lib_div::_POST('diff_2');
		if (t3lib_div::_POST('do_diff'))	{
			$content='';
395
			$content.='<h3>' . $GLOBALS['LANG']->getLL('diffing') . ':</h3>';
Kasper Skårhøj's avatar
Kasper Skårhøj committed
396
397
398
399
400
401
402
403
404
405
406
			if ($diff_1 && $diff_2)	{
				$diff_1_record = t3lib_BEfunc::getRecord($this->table, $diff_1);
				$diff_2_record = t3lib_BEfunc::getRecord($this->table, $diff_2);

				if (is_array($diff_1_record) && is_array($diff_2_record))	{
					t3lib_div::loadTCA($this->table);
					$t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');

					$tRows=array();
								$tRows[] = '
									<tr class="bgColor5 tableheader">
407
408
										<td>' . $GLOBALS['LANG']->getLL('fieldname') . '</td>
										<td width="98%">' . $GLOBALS['LANG']->getLL('coloredDiffView') . ':</td>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
									</tr>
								';
					foreach($diff_1_record as $fN => $fV)	{
						if ($TCA[$this->table]['columns'][$fN] && $TCA[$this->table]['columns'][$fN]['config']['type']!='passthrough' && !t3lib_div::inList('t3ver_label',$fN))	{
							if (strcmp($diff_1_record[$fN],$diff_2_record[$fN]))	{

								$diffres = $t3lib_diff_Obj->makeDiffDisplay(
									t3lib_BEfunc::getProcessedValue($this->table,$fN,$diff_2_record[$fN],0,1),
									t3lib_BEfunc::getProcessedValue($this->table,$fN,$diff_1_record[$fN],0,1)
								);

								$tRows[] = '
									<tr class="bgColor4">
										<td>'.$fN.'</td>
										<td width="98%">'.$diffres.'</td>
									</tr>
								';
							}
						}
					}

					if (count($tRows)>1)	{
431
						$content .= '<table border="0" cellpadding="1" cellspacing="1" width="100%">' . implode('', $tRows) . '</table><br /><br />';
Kasper Skårhøj's avatar
Kasper Skårhøj committed
432
					} else {
433
						$content .= $GLOBALS['LANG']->getLL('recordsMatchesCompletely');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
434
					}
435
				} else $content .= $GLOBALS['LANG']->getLL('errorRecordsNotFound');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
436
			} else {
437
				$content .= $GLOBALS['LANG']->getLL('errorDiffSources');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
438
439
440
441
442
			}
		}

			// Element:
		$record = t3lib_BEfunc::getRecord($this->table,$this->uid);
443
		$recordIcon = t3lib_iconWorks::getSpriteIconForRecord($this->table, $record);
444
		$recTitle = t3lib_BEfunc::getRecordTitle($this->table,$record,TRUE);
Kasper Skårhøj's avatar
Kasper Skårhøj committed
445
446
447
448

			// Display versions:
		$content.='
			'.$recordIcon.$recTitle.'
Kasper Skårhøj's avatar
   
Kasper Skårhøj committed
449
			<form name="theform" action="'.str_replace('&sendToReview=1','',$this->REQUEST_URI).'" method="post">
Kasper Skårhøj's avatar
Kasper Skårhøj committed
450
451
452
453
454
			<table border="0" cellspacing="1" cellpadding="1">';
			$content.='
				<tr class="bgColor5 tableheader">
					<td>&nbsp;</td>
					<td>&nbsp;</td>
455
456
457
458
459
460
461
462
463
464
465
					<td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_title') . '">' . $GLOBALS['LANG']->getLL('tblHeader_title') . '</td>
					<td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_uid') . '">' . $GLOBALS['LANG']->getLL('tblHeader_uid') . '</td>
					<td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_oid') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_oid') . '</td>
					<td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_id') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_id') . '</td>
					<td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_wsid') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_wsid') . '</td>
					<td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_state') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_state') . '</td>
					<td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_stage') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_stage') . '</td>
					<td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_count') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_count') . '</td>
					<td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_pid') . '">' . $GLOBALS['LANG']->getLL('tblHeader_pid') . '</td>
					<td title="' . $GLOBALS['LANG']->getLL('tblHeaderDesc_t3ver_label') . '">' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_label') . '</td>
					<td colspan="2"><input type="submit" name="do_diff" value="' . $GLOBALS['LANG']->getLL('diff') . '" /></td>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
466
467
				</tr>';

468
		$versions = t3lib_BEfunc::selectVersionsOfRecord($this->table, $this->uid, '*', $GLOBALS['BE_USER']->workspace);
Kasper Skårhøj's avatar
Kasper Skårhøj committed
469
470
471
472
		foreach($versions as $row)	{
			$adminLinks = $this->adminLinks($this->table,$row);

			$content.='
473
				<tr class="' . ($row['uid'] != $this->uid ? 'bgColor4' : 'bgColor2 tableheader') . '">
474
					<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) . '">'.
475
						t3lib_iconWorks::getSpriteIcon('actions-version-swap-version') .
476
						'</a>' /* (
Kasper Skårhøj's avatar
Kasper Skårhøj committed
477
478
479
480
481
482
							$this->table == 'pages' ?
							'<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').'">'.
						'<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert2.gif','width="14" height="14"').' alt="" title="Publish page AND content!" />'.
						'</a>'.
							'<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').'">'.
						'<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert4.gif','width="14" height="14"').' alt="" title="Publish page AND content! - AND ALL SUBPAGES!" />'.
483
						'</a>' : '') */ : t3lib_iconWorks::getSpriteIcon('status-status-current', array('title' =>  $GLOBALS['LANG']->getLL('currentOnlineVersion', TRUE)))) . '</td>
484
					<td nowrap="nowrap">'.$adminLinks.'</td>
485
					<td nowrap="nowrap">'.t3lib_BEfunc::getRecordTitle($this->table,$row,TRUE).'</td>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
486
487
488
					<td>'.$row['uid'].'</td>
					<td>'.$row['t3ver_oid'].'</td>
					<td>'.$row['t3ver_id'].'</td>
489
					<td>'.$row['t3ver_wsid'].'</td>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
490
491
492
					<td>'.$row['t3ver_state'].'</td>
					<td>'.$row['t3ver_stage'].'</td>
					<td>'.$row['t3ver_count'].'</td>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
493
					<td>'.$row['pid'].'</td>
494
495
496
					<td nowrap="nowrap"><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick('&edit['.$this->table.']['.$row['uid'].']=edit&columnsOnly=t3ver_label',$this->doc->backPath)).'" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.edit', TRUE) . '">' .
							t3lib_iconWorks::getSpriteIcon('actions-document-open') .
						'</a>' . htmlspecialchars($row['t3ver_label']) . '</td>
497
498
					<td class="version-diff-1"><input type="radio" name="diff_1" value="'.$row['uid'].'"'.($diff_1==$row['uid'] ? ' checked="checked"':'').'/></td>
					<td class="version-diff-2"><input type="radio" name="diff_2" value="'.$row['uid'].'"'.($diff_2==$row['uid'] ? ' checked="checked"':'').'/></td>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
499
500
				</tr>';

Kasper Skårhøj's avatar
Kasper Skårhøj committed
501
502
				// 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;)
			if ($this->table == 'pages' && $row['uid']!=$this->uid)	{
Kasper Skårhøj's avatar
Kasper Skårhøj committed
503
504
505
506
507
508
509
				$sub = $this->pageSubContent($row['uid']);

				if ($sub)	{
					$content.='
						<tr>
							<td></td>
							<td></td>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
510
							<td colspan="10">'.$sub.'</td>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
511
512
513
514
515
516
517
							<td colspan="2"></td>
						</tr>';
				}
			}
		}
		$content.='</table></form>';

518
		$this->content .= $this->doc->section($GLOBALS['LANG']->getLL('title'), $content, 0, 1);
Kasper Skårhøj's avatar
Kasper Skårhøj committed
519
520
521
522
523
524


			// Create new:
		$content='

			<form action="'.$this->doc->backPath.'tce_db.php" method="post">
525
			' . $GLOBALS['LANG']->getLL('tblHeader_t3ver_label') . ': <input type="text" name="cmd[' . $this->table . '][' . $this->uid . '][version][label]" /><br />
526
			'.(($this->table == 'pages' && $GLOBALS['TYPO3_CONF_VARS']['BE']['elementVersioningOnly'] == FALSE)? '<select name="cmd['.$this->table.']['.$this->uid.'][version][treeLevels]">
527
528
529
				'.($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(0) ? '<option value="0">' . $GLOBALS['LANG']->getLL('cmdPid0') . '</option>' : '').'
				'.($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(1) ? '<option value="100">' . $GLOBALS['LANG']->getLL('cmdPid100') . '</option>' : '').'
				'.($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(-1) ? '<option value="-1">' . $GLOBALS['LANG']->getLL('cmdPid1') . '</option>' : '').'
Kasper Skårhøj's avatar
Kasper Skårhøj committed
530
			</select>' : '').'
531
			<br /><input type="hidden" name="cmd[' . $this->table . '][' . $this->uid . '][version][action]" value="new" />
Kasper Skårhøj's avatar
Kasper Skårhøj committed
532
			<input type="hidden" name="prErr" value="1" />
Kasper Skårhøj's avatar
   
Kasper Skårhøj committed
533
			<input type="hidden" name="redirect" value="'.htmlspecialchars($this->REQUEST_URI).'" />
534
			<input type="submit" name="_" value="' . $GLOBALS['LANG']->getLL('createNewVersion') . '" />
Kasper Skårhøj's avatar
Kasper Skårhøj committed
535
536
537
538
539
540

			</form>

		';

		$this->content.=$this->doc->spacer(15);
541
		$this->content.=$this->doc->section($GLOBALS['LANG']->getLL('createNewVersion'), $content,0,1);
Kasper Skårhøj's avatar
Kasper Skårhøj committed
542
543
544

	}

545
	/**
Kasper Skårhøj's avatar
Kasper Skårhøj committed
546
	 * Recursively look for children for page version with $pid
547
	 *
Kasper Skårhøj's avatar
Kasper Skårhøj committed
548
549
550
	 * @param	integer		UID of page record for which to look up sub-elements following that version
	 * @param	integer		Counter, do not set (limits to 100 levels)
	 * @return	string		Table with content if any
551
	 */
Kasper Skårhøj's avatar
Kasper Skårhøj committed
552
553
554
	function pageSubContent($pid,$c=0)	{
		global $TCA;

555
556
557
		$tableNames = t3lib_div::removeArrayEntryByValue(array_keys($TCA),'pages');
		$tableNames[] = 'pages';

Kasper Skårhøj's avatar
Kasper Skårhøj committed
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
		foreach($tableNames as $tN)	{
				// Basically list ALL tables - not only those being copied might be found!
			#if ($TCA[$tN]['ctrl']['versioning_followPages'] || $tN=='pages')	{
				$mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $tN, 'pid='.intval($pid).t3lib_BEfunc::deleteClause($tN), '', ($TCA[$tN]['ctrl']['sortby'] ? $TCA[$tN]['ctrl']['sortby'] : ''));

				if ($GLOBALS['TYPO3_DB']->sql_num_rows($mres))	{
					$content.='
						<tr>
							<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>
						</tr>';
					while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres))	{
						$ownVer = $this->lookForOwnVersions($tN,$subrow['uid']);
						$content.='
							<tr>
								<td>'.$this->adminLinks($tN,$subrow).'</td>
								<td>'.$subrow['uid'].'</td>
								'.($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>').'
575
								<td width="98%">'.t3lib_BEfunc::getRecordTitle($tN,$subrow,TRUE).'</td>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
576
577
							</tr>';

Kasper Skårhøj's avatar
Kasper Skårhøj committed
578
						if ($tN == 'pages' && $c<100)	{
Kasper Skårhøj's avatar
Kasper Skårhøj committed
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
							$sub = $this->pageSubContent($subrow['uid'],$c+1);

							if ($sub)	{
								$content.='
									<tr>
										<td></td>
										<td></td>
										<td></td>
										<td width="98%">'.$sub.'</td>
									</tr>';
							}
						}
					}
				}
			#}
		}

		return $content ? '<table border="1" cellpadding="1" cellspacing="0" width="100%">'.$content.'</table>' : '';
	}

599
	/**
Kasper Skårhøj's avatar
Kasper Skårhøj committed
600
	 * Look for number of versions of a record
601
	 *
Kasper Skårhøj's avatar
Kasper Skårhøj committed
602
603
604
	 * @param	string		Table name
	 * @param	integer		Record uid
	 * @return	integer		Number of versions for record, false if none.
605
	 */
Kasper Skårhøj's avatar
Kasper Skårhøj committed
606
607
608
609
610
611
612
613
614
615
	function lookForOwnVersions($table,$uid)	{
		global $TCA;

		$versions = t3lib_BEfunc::selectVersionsOfRecord($table, $uid, 'uid');
		if (is_array($versions))	{
			return count($versions);
		}
		return FALSE;
	}

616
	/**
Kasper Skårhøj's avatar
Kasper Skårhøj committed
617
	 * Administrative links for a table / record
618
	 *
Kasper Skårhøj's avatar
Kasper Skårhøj committed
619
620
621
	 * @param	string		Table name
	 * @param	array		Record for which administrative links are generated.
	 * @return	string		HTML link tags.
622
	 */
Kasper Skårhøj's avatar
Kasper Skårhøj committed
623
624
625
	function adminLinks($table,$row)	{
		global $BE_USER;

Kasper Skårhøj's avatar
Kasper Skårhøj committed
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') .
Kasper Skårhøj's avatar
Kasper Skårhøj committed
629
630
						'</a>';

Kasper Skårhøj's avatar
Kasper Skårhøj committed
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') .
Kasper Skårhøj's avatar
Kasper Skårhøj committed
634
635
636
637
						'</a>';



Kasper Skårhøj's avatar
Kasper Skårhøj committed
638
639
640
641
642
643
644
645
646
647
648
		if ($table == 'pages')	{

				// If another page module was specified, replace the default Page module with the new one
			$newPageModule = trim($BE_USER->getTSConfigVal('options.overridePageModule'));
			$pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';

				// Perform some acccess checks:
			$a_wl = $BE_USER->check('modules','web_list');
			$a_wp = t3lib_extMgm::isLoaded('cms') && $BE_USER->check('modules',$pageModule);

			$adminLink.='<a href="#" onclick="top.loadEditId('.$row['uid'].');top.goToModule(\''.$pageModule.'\'); return false;">'.
649
							t3lib_iconWorks::getSpriteIcon('actions-page-open') .
Kasper Skårhøj's avatar
Kasper Skårhøj committed
650
651
						'</a>';
			$adminLink.='<a href="#" onclick="top.loadEditId('.$row['uid'].');top.goToModule(\'web_list\'); return false;">'.
652
							t3lib_iconWorks::getSpriteIcon('actions-system-list-open') .
Kasper Skårhøj's avatar
Kasper Skårhøj committed
653
654
655
656
						'</a>';

				// "View page" icon is added:
			$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') .
Kasper Skårhøj's avatar
Kasper Skårhøj committed
658
659
660
661
662
663
664
				'</a>';
		} else {
			if ($row['pid']==-1)	{
				$getVars = '&ADMCMD_vPrev['.rawurlencode($table.':'.$row['t3ver_oid']).']='.$row['uid'];

					// "View page" icon is added:
				$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') .
Kasper Skårhøj's avatar
Kasper Skårhøj committed
666
667
668
669
670
671
					'</a>';
			}
		}

		return $adminLink;
	}
Kasper Skårhøj's avatar
Kasper Skårhøj committed
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695











	/******************************
	 *
	 * Workspace management
	 *
	 ******************************/

	/**
	 * Management of workspace for page ID
	 * Called when $this->id is set.
	 *
	 * @return	void
	 */
	function workspaceMgm()	{
Kasper Skårhøj's avatar
Kasper Skårhøj committed
696

697
698
699
700
701
702
703
			// Perform workspace publishing action if buttons are pressed:
		$errors = $this->publishAction();

			// Generate workspace overview:
		$WSoverview = $this->displayWorkspaceOverview();

			// Buttons for publish / swap:
704
		$actionLinks = '<br />';
705
706
		if ($GLOBALS['BE_USER']->workspace!==0)	{
			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
718
		$actionLinks.= '<input type="submit" name="_previewLink" value="' . $GLOBALS['LANG']->getLL('previewLink') . '" />';
		$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>' . $GLOABLS['LANG']->getLL('errors') . '</h3><br />' . implode('<br />', $errors) . '<hr />' : ''), 0, 1);
723
724
		}

725
		if (t3lib_div::_POST('_previewLink'))	{
726
727
728
			$ttlHours = intval($GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.previewLinkTTLHours'));
			$ttlHours = ($ttlHours ? $ttlHours : 24*2);

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
732
			} else {
				$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
739
			// Output overview content:
		$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

Kasper Skårhøj's avatar
Kasper Skårhøj committed
742
	}
Ingo Renner's avatar
Ingo Renner committed
743

744
745
746
747
748
749
750
751
	function workspaceMenu() {
		if($this->id) {
			$menu = '';
			if ($GLOBALS['BE_USER']->workspace===0)	{
				$menu.= t3lib_BEfunc::getFuncMenu($this->id,'SET[filter]',$this->MOD_SETTINGS['filter'],$this->MOD_MENU['filter']);
				$menu.= t3lib_BEfunc::getFuncMenu($this->id,'SET[display]',$this->MOD_SETTINGS['display'],$this->MOD_MENU['display']);
			}
			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
			}
Ingo Renner's avatar
Ingo Renner committed
754

755
756
757
758
759
			if ($menu)	{
				return $menu;
			}
		}
	}
Kasper Skårhøj's avatar
Kasper Skårhøj committed
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810

	/**
	 * Rendering the overview of versions in the current workspace
	 *
	 * @return	string		HTML (table)
	 * @see typo3/mod/user/ws/index.php for sister function!
	 */
	function displayWorkspaceOverview()	{

			// Initialize variables:
		$this->showWorkspaceCol = $GLOBALS['BE_USER']->workspace===0 && $this->MOD_SETTINGS['display']<=-98;

			// Get usernames and groupnames
		$be_group_Array = t3lib_BEfunc::getListGroupNames('title,uid');
		$groupArray = array_keys($be_group_Array);
		$this->be_user_Array = t3lib_BEfunc::getUserNames();
		if (!$GLOBALS['BE_USER']->isAdmin())		$this->be_user_Array = t3lib_BEfunc::blindUserNames($this->be_user_Array,$groupArray,1);

			// Initialize Workspace ID and filter-value:
		if ($GLOBALS['BE_USER']->workspace===0)	{
			$wsid = $this->details ? -99 : $this->MOD_SETTINGS['display'];		// Set wsid to the value from the menu (displaying content of other workspaces)
			$filter = $this->details ? 0 : $this->MOD_SETTINGS['filter'];
		} else {
			$wsid = $GLOBALS['BE_USER']->workspace;
			$filter = 0;
		}

			// Initialize workspace object and request all pending versions:
		$wslibObj = t3lib_div::makeInstance('wslib');

			// Selecting ALL versions belonging to the workspace:
		$versions = $wslibObj->selectVersionsInWorkspace($wsid, $filter, -99, $this->uid);	// $this->uid is the page id of LIVE record.

			// Traverse versions and build page-display array:
		$pArray = array();
		foreach($versions as $table => $records)	{
			foreach($records as $rec)	{
				$pageIdField = $table==='pages' ? 't3ver_oid' : 'realpid';
				$this->displayWorkspaceOverview_setInPageArray(
					$pArray,
					$table,
					$rec
				);
			}
		}

			// Make header of overview:
		$tableRows = array();
		if (count($pArray))	{
			$tableRows[] = '
				<tr class="bgColor5 tableheader">
811
812
813
					'.($this->diffOnly?'':'<td nowrap="nowrap" colspan="2">' . $GLOBALS['LANG']->getLL('liveVersion') . '</td>').'
					<td nowrap="nowrap" colspan="2">' . $GLOBALS['LANG']->getLL('wsVersions') . '</td>
					<td nowrap="nowrap"'.($this->diffOnly?' colspan="2"':' colspan="4"').'>' . $GLOBALS['LANG']->getLL('controls') . '</td>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
814
815
816
817
818
819
820
821
				</tr>';

				// Add lines from overview:
			$tableRows = array_merge($tableRows, $this->displayWorkspaceOverview_list($pArray));

			$table = '<table border="0" cellpadding="0" cellspacing="1" class="lrPadding workspace-overview">'.implode('',$tableRows).'</table>';
		} else $table = '';

822
823
		$returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
		$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 />' : '';
Kasper Skårhøj's avatar
Kasper Skårhøj committed
827
828
829

		$versionSelector = $GLOBALS['BE_USER']->workspace ? $this->doc->getVersionSelector($this->id) : '';

830
		return $versionSelector.$linkBack.$resetDiffOnly.$table.$this->markupNewOriginals();
Kasper Skårhøj's avatar
Kasper Skårhøj committed
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
	}

	/**
	 * Rendering the content for the publish / review overview:
	 * (Made for internal recursive calling)
	 *
	 * @param	array		Storage of the elements to display (see displayWorkspaceOverview() / displayWorkspaceOverview_setInPageArray())
	 * @return	array		Table rows, see displayWorkspaceOverview()
	 */
	function displayWorkspaceOverview_list($pArray)	{
		global $TCA;

			// If there ARE elements on this level, print them:
		$warnAboutVersions_nonPages = FALSE;
		$warnAboutVersions_page = FALSE;
		if (is_array($pArray))	{
			foreach($pArray as $table => $oidArray)	{
				foreach($oidArray as $oid => $recs)	{

						// Get CURRENT online record and icon based on "t3ver_oid":
					$rec_on = t3lib_BEfunc::getRecord($table,$oid);
852
					$icon = t3lib_iconWorks::getSpriteIconForRecord($table, $rec_on, array('title' => t3lib_BEfunc::getRecordIconAltText($rec_on,$table)));
Kasper Skårhøj's avatar
Kasper Skårhøj committed
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
					if ($GLOBALS['BE_USER']->workspace===0) {	// Only edit online records if in ONLINE workspace:
						$icon = $this->doc->wrapClickMenuOnIcon($icon, $table, $rec_on['uid'], 1, '', '+edit,view,info,delete');
					}

						// Online version display:
						// Create the main cells which will span over the number of versions there is.
					$verLinkUrl = $TCA[$table]['ctrl']['versioningWS'];
					$origElement = $icon.
						($verLinkUrl ? '<a href="'.htmlspecialchars('index.php?table='.$table.'&uid='.$rec_on['uid']).'">' : '').
						t3lib_BEfunc::getRecordTitle($table,$rec_on,TRUE).
						($verLinkUrl ? '</a>' : '');
					$mainCell_rowSpan = count($recs)>1 ? ' rowspan="'.count($recs).'"' : '';
					$mainCell = '
								<td align="center"'.$mainCell_rowSpan.'>'.$this->formatVerId($rec_on['t3ver_id']).'</td>
								<td nowrap="nowrap"'.$mainCell_rowSpan.'>'.
									$origElement.
									'###SUB_ELEMENTS###'.	// For substitution with sub-elements, if any.
								'</td>';

						// Offline versions display:
						// Traverse the versions of the element
					foreach($recs as $rec)	{

							// Get the offline version record and icon:
						$rec_off = t3lib_BEfunc::getRecord($table,$rec['uid']);
878
879
880
881
882
883
884
885
886
887
888

						// Prepare swap-mode values:
						if ($table==='pages' && $rec_off['t3ver_swapmode']!=-1)	{
							if ($rec_off['t3ver_swapmode']>0)	{
								$vType = 'branch';
							} else {
								$vType = 'page';
							}
						} else {
							$vType = 'element';
						}
Ingo Renner's avatar
Ingo Renner committed
889

890
						// Get icon
891
						$icon = t3lib_iconWorks::getSpriteIconForRecord($table, $rec_off, array('title' => t3lib_BEfunc::getRecordIconAltText($rec_off, $table)));
892
893
						$tempUid = ($table != 'pages' || $vType==='branch' || $GLOBALS['BE_USER']->workspace===0 ? $rec_off['uid'] : $rec_on['uid']);
						$icon = $this->doc->wrapClickMenuOnIcon($icon, $table, $tempUid, 1, '', '+edit,' . ($table == 'pages' ? 'view,info,' : '') . 'delete');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
894
895

							// Prepare diff-code:
896
						if ($this->MOD_SETTINGS['diff'] || $this->diffOnly)	{
897
898
899
							$diffCode = '';
							list($diffHTML,$diffPct) = $this->createDiffView($table, $rec_off, $rec_on);
							if ($rec_on['t3ver_state']==1)	{	// New record:
900
								$diffCode.= $this->doc->icons(1) . $GLOBALS['LANG']->getLL('newElement') . '<br />';
901
902
								$diffCode.= $diffHTML;
							} elseif ($rec_off['t3ver_state']==2)	{
903
								$diffCode.= $this->doc->icons(2) . $GLOBALS['LANG']->getLL('deletedElement') . '<br />';
904
							} elseif ($rec_on['t3ver_state']==3)	{
905
								$diffCode.= $this->doc->icons(1) . $GLOBALS['LANG']->getLL('moveToPlaceholder') . '<br />';
906
							} elseif ($rec_off['t3ver_state']==4)	{
907
								$diffCode.= $this->doc->icons(1) . $GLOBALS['LANG']->getLL('moveToPointer') . '<br />';
Kasper Skårhøj's avatar
Kasper Skårhøj committed
908
							} else {
909
								$diffCode.= ($diffPct<0 ? $GLOBALS['LANG']->getLL('notAvailable') : ($diffPct ? $diffPct . '% ' . $GLOBALS['LANG']->getLL('change') : ''));
910
								$diffCode.= $diffHTML;
Kasper Skårhøj's avatar
Kasper Skårhøj committed
911
912
913
914
915
							}
						} else $diffCode = '';

						switch($vType) {
							case 'element':
916
								$swapLabel = $GLOBALS['LANG']->getLL('element');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
917
918
919
920
								$swapClass = 'ver-element';
								$warnAboutVersions_nonPages = $warnAboutVersions_page;	// Setting this if sub elements are found with a page+content (must be rendered prior to this of course!)
							break;
							case 'page':
921
								$swapLabel = $GLOBALS['LANG']->getLL('page');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
922
923
924
925
								$swapClass = 'ver-page';
								$warnAboutVersions_page = !$this->showWorkspaceCol;		// This value is true only if multiple workspaces are shown and we need the opposite here.
							break;
							case 'branch':
926
								$swapLabel = $GLOBALS['LANG']->getLL('branch');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
927
928
929
930
931
932
933
934
935
936
937
938
939
940
								$swapClass = 'ver-branch';
							break;
						}

							// Modify main cell based on first version shown:
						$subElements = array();
						if ($table==='pages' && $rec_off['t3ver_swapmode']!=-1 && $mainCell)	{	// For "Page" and "Branch" swap modes where $mainCell is still carrying content (only first version)
							$subElements['on'] = $this->subElements($rec_on['uid'], $rec_off['t3ver_swapmode']);
							$subElements['off'] = $this->subElements($rec_off['uid'],$rec_off['t3ver_swapmode'],$rec_on['uid']);
						}
						$mainCell = str_replace('###SUB_ELEMENTS###', $subElements['on'], $mainCell);

							// Create version element:
						$versionsInOtherWS = $this->versionsInOtherWS($table, $rec_on['uid']);
941
						$versionsInOtherWSWarning = $versionsInOtherWS && $GLOBALS['BE_USER']->workspace !== 0 ? '<br />' . $this->doc->icons(2) . $GLOBALS['LANG']->getLL('otherVersions') . $versionsInOtherWS : '';
942
943
						$multipleWarning = (!$mainCell && $GLOBALS['BE_USER']->workspace !== 0 ? '<br />' . $this->doc->icons(3) . '<strong>' . $GLOBALS['LANG']->getLL('multipleVersions') . '</strong>' : '');
						$verWarning = $warnAboutVersions || ($warnAboutVersions_nonPages && $GLOBALS['TCA'][$table]['ctrl']['versioning_followPages']) ? '<br />' . $this->doc->icons(3) . '<strong>' . $GLOBALS['LANG']->getLL('versionInVersion') . '</strong>' : '';
Kasper Skårhøj's avatar
Kasper Skårhøj committed
944
						$verElement = $icon.
Kasper Skårhøj's avatar
   
Kasper Skårhøj committed
945
							(!$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)).'">' : '').
Kasper Skårhøj's avatar
Kasper Skårhøj committed
946
947
948
949
950
951
952
953
954
955
956
957
							t3lib_BEfunc::getRecordTitle($table,$rec_off,TRUE).
							(!$this->details ? '</a>' : '').
							$versionsInOtherWSWarning.
							$multipleWarning.
							$verWarning;

						$ctrlTable = '
								<td nowrap="nowrap">'.$this->showStageChangeLog($table,$rec_off['uid'],$this->displayWorkspaceOverview_stageCmd($table,$rec_off)).'</td>
								<td nowrap="nowrap" class="'.$swapClass.'">'.
									$this->displayWorkspaceOverview_commandLinks($table,$rec_on,$rec_off,$vType).
									htmlspecialchars($swapLabel).
									'&nbsp;&nbsp;</td>
958
								'.(!$this->diffOnly?'<td nowrap="nowrap"><strong>' . $GLOBALS['LANG']->getLL('lifecycle')  . ':</strong> '.htmlspecialchars($this->formatCount($rec_off['t3ver_count'])).'</td>'.		// Lifecycle
Kasper Skårhøj's avatar
Kasper Skårhøj committed
959
									($this->showWorkspaceCol ? '
960
								<td nowrap="nowrap">&nbsp;&nbsp;<strong>' . $GLOBALS['LANG']->getLL('workspace')  . ':</strong> '.htmlspecialchars($this->formatWorkspace($rec_off['t3ver_wsid'])).'</td>' : ''):'');
Kasper Skårhøj's avatar
Kasper Skårhøj committed
961
962
963

						if ($diffCode)	{
							$verElement = $verElement.'
964
							<br /><strong>' . $GLOBALS['LANG']->getLL('diffToLiveElement') . '</strong>
Kasper Skårhøj's avatar
Kasper Skårhøj committed
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
							<table border="0" cellpadding="0" cellspacing="0" class="ver-verElement">
								<tr>
									<td class="c-diffCell">'.$diffCode.'</td>
								</tr>
							</table>';
						}


							// Create version cell:
						$verCell = '
								<td align="center">'.$this->formatVerId($rec_off['t3ver_id']).'</td>
								<td nowrap="nowrap">'.
									$verElement.
									$subElements['off'].
									'</td>
980
								';
Kasper Skårhøj's avatar
Kasper Skårhøj committed
981
982
983
984

							// Compile table row:
						$tableRows[] = '
							<tr class="bgColor4">
985
986
987
988
989
								'.
								($this->diffOnly?'':$mainCell).
								$verCell.
								$ctrlTable.
								'
Kasper Skårhøj's avatar
Kasper Skårhøj committed
990
991
992
993
994
995
996
997
998
999
1000
							</tr>';

							// Reset the main cell:
						$mainCell = '';

					}
				}
			}
		}

		return $tableRows;
For faster browsing, not all history is shown. View entire blame