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