Updated years from 2004 to 2005 + all function indexes. NO actual code changes done!
[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 * version module cm1
26 *
27 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
28 */
29 /**
30 * [CLASS/FUNCTION INDEX of SCRIPT]
31 *
32 *
33 *
34 * 73: class tx_version_cm1 extends t3lib_SCbase
35 * 80: function main()
36 * 105: function jumpToUrl(URL)
37 * 139: function printContent()
38 * 150: function moduleContent()
39 * 307: function pageSubContent($pid,$c=0)
40 * 359: function lookForOwnVersions($table,$uid)
41 * 376: function adminLinks($table,$row)
42 *
43 * TOTAL FUNCTIONS: 7
44 * (This index is automatically created/updated by the extension "extdeveval")
45 *
46 */
47
48
49 // DEFAULT initialization of a module [BEGIN]
50 unset($MCONF);
51 require ("conf.php");
52 require ($BACK_PATH."init.php");
53 require ($BACK_PATH."template.php");
54 $LANG->includeLLFile("EXT:version/cm1/locallang.php");
55 require_once (PATH_t3lib."class.t3lib_scbase.php");
56 // ....(But no access check here...)
57 // DEFAULT initialization of a module [END]
58
59
60
61
62
63 require_once(PATH_t3lib.'class.t3lib_diff.php');
64
65
66 /**
67 * Context Menu module for versioning. NOT READY FOR RELEASE YET
68 *
69 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
70 * @package TYPO3
71 * @subpackage core
72 */
73 class tx_version_cm1 extends t3lib_SCbase {
74
75 /**
76 * Main function of the module. Write the content to $this->content
77 *
78 * @return [type] ...
79 */
80 function main() {
81 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
82
83 // Draw the header.
84 $this->doc = t3lib_div::makeInstance("mediumDoc");
85 $this->doc->backPath = $BACK_PATH;
86 $this->doc->form='<form action="" method="post">';
87
88
89 $this->uid = intval(t3lib_div::_GP('uid'));
90 $this->table = t3lib_div::_GP('table');
91 $record = t3lib_BEfunc::getRecord($this->table,$this->uid);
92
93 if (is_array($record) && $TCA[$this->table]['ctrl']['versioning']) {
94 // Access check!
95 // The page will show only if there is a valid page and if this page may be viewed by the user
96 $this->pageinfo = t3lib_BEfunc::readPageAccess($record['pid'],$this->perms_clause);
97 $access = is_array($this->pageinfo) ? 1 : 0;
98
99 if (($record['pid'] && $access) || ($BE_USER->user["admin"] && !$record['pid'])) {
100
101 // JavaScript
102 $this->doc->JScode = '
103 <script language="javascript" type="text/javascript">
104 script_ended = 0;
105 function jumpToUrl(URL) {
106 document.location = URL;
107 }
108 </script>
109 ';
110
111 # $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);
112
113 $this->content.=$this->doc->startPage($LANG->getLL("title"));
114 $this->content.=$this->doc->header($LANG->getLL("title"));
115 # $this->content.=$this->doc->spacer(5);
116 # $this->content.=$this->doc->section('',$headerSection);
117 # $this->content.=$this->doc->divider(5);
118
119
120
121 // Render content:
122 $this->moduleContent();
123
124 // ShortCut
125 if ($BE_USER->mayMakeShortcut()) {
126 $this->content.=$this->doc->spacer(20).$this->doc->section("",$this->doc->makeShortcutIcon("id",implode(",",array_keys($this->MOD_MENU)),$this->MCONF["name"]));
127 }
128 }
129
130 $this->content.=$this->doc->spacer(10);
131 }
132 }
133
134 /**
135 * [Describe function...]
136 *
137 * @return [type] ...
138 */
139 function printContent() {
140
141 $this->content.=$this->doc->endPage();
142 echo $this->content;
143 }
144
145 /**
146 * [Describe function...]
147 *
148 * @return [type] ...
149 */
150 function moduleContent() {
151 global $TCA;
152
153 // Diffing:
154 $diff_1 = t3lib_div::_POST('diff_1');
155 $diff_2 = t3lib_div::_POST('diff_2');
156 if (t3lib_div::_POST('do_diff')) {
157 $content='';
158 $content.='<h3>DIFFING:</h3>';
159 if ($diff_1 && $diff_2) {
160 $diff_1_record = t3lib_BEfunc::getRecord($this->table, $diff_1);
161 $diff_2_record = t3lib_BEfunc::getRecord($this->table, $diff_2);
162
163 if (is_array($diff_1_record) && is_array($diff_2_record)) {
164 t3lib_div::loadTCA($this->table);
165 $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
166
167 $tRows=array();
168 $tRows[] = '
169 <tr class="bgColor5 tableheader">
170 <td>Fieldname:</td>
171 <td width="98%">Colored diff-view:</td>
172 </tr>
173 ';
174 foreach($diff_1_record as $fN => $fV) {
175 if ($TCA[$this->table]['columns'][$fN] && $TCA[$this->table]['columns'][$fN]['config']['type']!='passthrough' && !t3lib_div::inList('t3ver_label',$fN)) {
176 if (strcmp($diff_1_record[$fN],$diff_2_record[$fN])) {
177
178 $diffres = $t3lib_diff_Obj->makeDiffDisplay(
179 t3lib_BEfunc::getProcessedValue($this->table,$fN,$diff_2_record[$fN],0,1),
180 t3lib_BEfunc::getProcessedValue($this->table,$fN,$diff_1_record[$fN],0,1)
181 );
182
183 $tRows[] = '
184 <tr class="bgColor4">
185 <td>'.$fN.'</td>
186 <td width="98%">'.$diffres.'</td>
187 </tr>
188 ';
189 }
190 }
191 }
192
193 if (count($tRows)>1) {
194 $content.='<table border="0" cellpadding="1" cellspacing="1" width="100%">'.implode('',$tRows).'</table><br/><br/>';
195 } else {
196 $content.='Records matches completely on all editable fields!';
197 }
198 } else $content.='ERROR: Records could strangely not be found!';
199 } else {
200 $content.='ERROR: You didn\'t select two sources for diffing!';
201 }
202 }
203
204 // Element:
205 $record = t3lib_BEfunc::getRecord($this->table,$this->uid);
206 $recordIcon = t3lib_iconWorks::getIconImage($this->table,$record,$this->doc->backPath,'class="absmiddle"');
207 $recTitle = t3lib_BEfunc::getRecordTitle($this->table,$record,1);
208
209 // Display versions:
210 $content.='
211 '.$recordIcon.$recTitle.'
212 <form action="'.t3lib_div::getIndpEnv('REQUEST_URI').'" method="post">
213 <table border="0" cellspacing="1" cellpadding="1">';
214 $content.='
215 <tr class="bgColor5 tableheader">
216 <td>&nbsp;</td>
217 <td>&nbsp;</td>
218 <td>Title</td>
219 <td>UID</td>
220 <td>t3ver_oid</td>
221 <td>t3ver_id</td>
222 <td>pid</td>
223 <td>t3ver_label</td>
224 <td colspan="2"><input type="submit" name="do_diff" value="Diff" /></td>
225 </tr>';
226
227 $versions = t3lib_BEfunc::selectVersionsOfRecord($this->table, $this->uid);
228 foreach($versions as $row) {
229 $adminLinks = $this->adminLinks($this->table,$row);
230
231 $content.='
232 <tr class="'.($row['uid']!=$this->uid ? 'bgColor4' : 'bgColor2 tableheader').'">
233 <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').'">'.
234 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert1.gif','width="14" height="14"').' alt="" title="SWAP with current" />'.
235 '</a>'.(
236 $this->table == 'pages' ?
237 '<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').'">'.
238 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert2.gif','width="14" height="14"').' alt="" title="Publish page AND content!" />'.
239 '</a>'.
240 '<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').'">'.
241 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert4.gif','width="14" height="14"').' alt="" title="Publish page AND content! - AND ALL SUBPAGES!" />'.
242 '</a>' : '') : '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/blinkarrow_left.gif','width="5" height="9"').' alt="" title="CURRENT ONLINE VERSION!"/>').'</td>
243 <td>'.$adminLinks.'</td>
244 <td nowrap="nowrap">'.t3lib_BEfunc::getRecordTitle($this->table,$row,1).'</td>
245 <td>'.$row['uid'].'</td>
246 <td>'.$row['t3ver_oid'].'</td>
247 <td>'.$row['t3ver_id'].'</td>
248 <td>'.$row['pid'].'</td>
249 <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>
250 <td bgcolor="green"><input type="radio" name="diff_1" value="'.$row['uid'].'"'.($diff_1==$row['uid'] ? ' checked="checked"':'').'/></td>
251 <td bgcolor="red"><input type="radio" name="diff_2" value="'.$row['uid'].'"'.($diff_2==$row['uid'] ? ' checked="checked"':'').'/></td>
252 </tr>';
253
254 if ($this->table == 'pages') { // && $row['uid']!=$this->uid
255 $sub = $this->pageSubContent($row['uid']);
256
257 if ($sub) {
258 $content.='
259 <tr>
260 <td></td>
261 <td></td>
262 <td colspan="6">'.$sub.'</td>
263 <td colspan="2"></td>
264 </tr>';
265 }
266 }
267 }
268 $content.='</table></form>';
269
270 $this->content.=$this->doc->section('',$content,0,1);
271
272
273 // Create new:
274 $content='
275
276 <form action="'.$this->doc->backPath.'tce_db.php" method="post">
277 Label: <input type="text" name="cmd['.$this->table.']['.$this->uid.'][version][label]" /><br/>
278 '.($this->table == 'pages' ? '<select name="cmd['.$this->table.']['.$this->uid.'][version][treeLevels]">
279 <option value="0">Page + content</option>
280 <option value="1">1 level</option>
281 <option value="2">2 levels</option>
282 <option value="3">3 levels</option>
283 <option value="4">4 levels</option>
284 <option value="-1">Just page record</option>
285 </select>' : '').'
286 <br/><input type="hidden" name="cmd['.$this->table.']['.$this->uid.'][version][action]" value="new" />
287 <input type="hidden" name="prErr" value="1" />
288 <input type="hidden" name="redirect" value="'.t3lib_div::getIndpEnv('REQUEST_URI').'" />
289 <input type="submit" name="_" value="Create new version" />
290
291 </form>
292
293 ';
294
295 $this->content.=$this->doc->spacer(15);
296 $this->content.=$this->doc->section("Create new version",$content,0,1);
297
298 }
299
300 /**
301 * [Describe function...]
302 *
303 * @param [type] $pid: ...
304 * @param [type] $c: ...
305 * @return [type] ...
306 */
307 function pageSubContent($pid,$c=0) {
308 global $TCA;
309
310 $tableNames = array_keys($TCA);
311 foreach($tableNames as $tN) {
312 // Basically list ALL tables - not only those being copied might be found!
313 #if ($TCA[$tN]['ctrl']['versioning_followPages'] || $tN=='pages') {
314 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $tN, 'pid='.intval($pid).t3lib_BEfunc::deleteClause($tN), '', ($TCA[$tN]['ctrl']['sortby'] ? $TCA[$tN]['ctrl']['sortby'] : ''));
315
316 if ($GLOBALS['TYPO3_DB']->sql_num_rows($mres)) {
317 $content.='
318 <tr>
319 <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>
320 </tr>';
321 while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
322 $ownVer = $this->lookForOwnVersions($tN,$subrow['uid']);
323 $content.='
324 <tr>
325 <td>'.$this->adminLinks($tN,$subrow).'</td>
326 <td>'.$subrow['uid'].'</td>
327 '.($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>').'
328 <td width="98%">'.t3lib_BEfunc::getRecordTitle($tN,$subrow,1).'</td>
329 </tr>';
330
331 if ($tN == 'pages' && $c<10) {
332 $sub = $this->pageSubContent($subrow['uid'],$c+1);
333
334 if ($sub) {
335 $content.='
336 <tr>
337 <td></td>
338 <td></td>
339 <td></td>
340 <td width="98%">'.$sub.'</td>
341 </tr>';
342 }
343 }
344 }
345 }
346 #}
347 }
348
349 return $content ? '<table border="1" cellpadding="1" cellspacing="0" width="100%">'.$content.'</table>' : '';
350 }
351
352 /**
353 * [Describe function...]
354 *
355 * @param [type] $table: ...
356 * @param [type] $uid: ...
357 * @return [type] ...
358 */
359 function lookForOwnVersions($table,$uid) {
360 global $TCA;
361
362 $versions = t3lib_BEfunc::selectVersionsOfRecord($table, $uid, 'uid');
363 if (is_array($versions)) {
364 return count($versions);
365 }
366 return FALSE;
367 }
368
369 /**
370 * [Describe function...]
371 *
372 * @param [type] $table: ...
373 * @param [type] $row: ...
374 * @return [type] ...
375 */
376 function adminLinks($table,$row) {
377 global $BE_USER;
378
379 $adminLink = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick('&edit['.$table.']['.$row['uid'].']=edit',$this->doc->backPath)).'">'.
380 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' alt="" title="Edit"/>'.
381 '</a>';
382
383 if ($table == 'pages') {
384
385 // If another page module was specified, replace the default Page module with the new one
386 $newPageModule = trim($BE_USER->getTSConfigVal('options.overridePageModule'));
387 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
388
389 // Perform some acccess checks:
390 $a_wl = $BE_USER->check('modules','web_list');
391 $a_wp = t3lib_extMgm::isLoaded('cms') && $BE_USER->check('modules',$pageModule);
392
393 $adminLink.='<a href="#" onclick="top.loadEditId('.$row['uid'].');top.goToModule(\''.$pageModule.'\'); return false;">'.
394 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,t3lib_extMgm::extRelPath('cms').'layout/layout.gif','width="14" height="12"').' title="" alt="" />'.
395 '</a>';
396 $adminLink.='<a href="#" onclick="top.loadEditId('.$row['uid'].');top.goToModule(\'web_list\'); return false;">'.
397 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'mod/web/list/list.gif','width="14" height="12"').' title="" alt="" />'.
398 '</a>';
399
400 // "View page" icon is added:
401 $adminLink.='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($row['uid'],$this->doc->backPath,t3lib_BEfunc::BEgetRootLine($row['uid']))).'">'.
402 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
403 '</a>';
404 } else {
405 if ($row['pid']==-1) {
406 $getVars = '&ADMCMD_vPrev['.rawurlencode($table.':'.$row['t3ver_oid']).']='.$row['uid'];
407
408 // "View page" icon is added:
409 $adminLink.='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($row['_REAL_PID'],$this->doc->backPath,t3lib_BEfunc::BEgetRootLine($row['_REAL_PID']),'','',$getVars)).'">'.
410 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
411 '</a>';
412 }
413 }
414
415 return $adminLink;
416 }
417 }
418
419
420
421 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/version/cm1/index.php"]) {
422 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/version/cm1/index.php"]);
423 }
424
425
426
427
428 // Make instance:
429 $SOBE = t3lib_div::makeInstance("tx_version_cm1");
430 $SOBE->init();
431
432
433 $SOBE->main();
434 $SOBE->printContent();
435
436 ?>