Added more comments, $Id$ keywords etc for the whole core of TYPO3.
[Packages/TYPO3.CMS.git] / typo3 / wizard_table.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skaarhoj (kasper@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 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Wizard to help make tables (eg. for tt_content elements) of type "table".
29 * Each line is a table row, each cell divided by a |
30 *
31 * $Id$
32 *
33 * @author Kasper Skaarhoj <kasper@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 78: class SC_wizard_table
41 * 87: function init()
42 * 117: function main()
43 * 133: function printContent()
44 *
45 * SECTION: OTHER FUNCTIONS:
46 * 156: function changeFunc($cArr,$TABLE_c)
47 * 266: function tableWizard($P)
48 *
49 * TOTAL FUNCTIONS: 5
50 * (This index is automatically created/updated by the extension "extdeveval")
51 *
52 */
53
54
55
56 $BACK_PATH='';
57 require ('init.php');
58 require ('template.php');
59 include ('sysext/lang/locallang_wizards.php');
60
61
62
63
64
65
66
67
68
69
70
71 /**
72 * Script Class
73 *
74 * @author Kasper Skaarhoj <kasper@typo3.com>
75 * @package TYPO3
76 * @subpackage core
77 */
78 class SC_wizard_table {
79 var $include_once=array();
80 var $content;
81 var $P;
82 var $doc;
83
84 /**
85 * @return [type] ...
86 */
87 function init() {
88 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
89
90 $this->P = t3lib_div::GPvar('P',1);
91
92 $this->doc = t3lib_div::makeInstance('mediumDoc');
93 $this->doc->backPath = $BACK_PATH;
94 $this->doc->JScode='
95 <script language="javascript" type="text/javascript">
96 function jumpToUrl(URL,formEl) { //
97 document.location = URL;
98 }
99 </script>
100 ';
101
102 list($rUri) = explode("#",t3lib_div::getIndpEnv("REQUEST_URI"));
103 $this->doc->form ='<form action="'.$rUri.'" method="POST" name="wizardForm">';
104
105 $this->content.=$this->doc->startPage("Table");
106
107 if ($HTTP_POST_VARS["savedok_x"] || $HTTP_POST_VARS["saveandclosedok_x"]) {
108 $this->include_once[]=PATH_t3lib."class.t3lib_tcemain.php";
109 }
110 }
111
112 /**
113 * [Describe function...]
114 *
115 * @return [type] ...
116 */
117 function main() {
118 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
119
120 if ($this->P["table"] && $this->P["field"] && $this->P["uid"]) {
121 $this->content.=$this->doc->section($LANG->getLL("table_title"),$this->tableWizard($this->P),0,1);
122 } else {
123 $this->content.=$this->doc->section($LANG->getLL("table_title"),$GLOBALS["TBE_TEMPLATE"]->rfw($LANG->getLL("table_noData")),0,1);
124 }
125 $this->content.=$this->doc->endPage();
126 }
127
128 /**
129 * [Describe function...]
130 *
131 * @return [type] ...
132 */
133 function printContent() {
134 echo $this->content;
135 }
136
137
138
139
140
141
142
143
144
145 /***************************
146 *
147 * OTHER FUNCTIONS:
148 *
149 ***************************/
150
151 /**
152 * @param [type] $cArr: ...
153 * @param [type] $TABLE_c: ...
154 * @return [type] ...
155 */
156 function changeFunc($cArr,$TABLE_c) {
157 if ($TABLE_c['col_remove']) {
158 $kk = key($TABLE_c['col_remove']);
159 $cmd='col_remove';
160 } elseif ($TABLE_c['col_add']) {
161 $kk = key($TABLE_c['col_add']);
162 $cmd='col_add';
163 } elseif ($TABLE_c['col_start']) {
164 $kk = key($TABLE_c['col_start']);
165 $cmd='col_start';
166 } elseif ($TABLE_c['col_end']) {
167 $kk = key($TABLE_c['col_end']);
168 $cmd='col_end';
169 } elseif ($TABLE_c['col_left']) {
170 $kk = key($TABLE_c['col_left']);
171 $cmd='col_left';
172 } elseif ($TABLE_c['col_right']) {
173 $kk = key($TABLE_c['col_right']);
174 $cmd='col_right';
175 } elseif ($TABLE_c['row_remove']) {
176 $kk = key($TABLE_c['row_remove']);
177 $cmd='row_remove';
178 } elseif ($TABLE_c['row_add']) {
179 $kk = key($TABLE_c['row_add']);
180 $cmd='row_add';
181 } elseif ($TABLE_c['row_top']) {
182 $kk = key($TABLE_c['row_top']);
183 $cmd='row_top';
184 } elseif ($TABLE_c['row_bottom']) {
185 $kk = key($TABLE_c['row_bottom']);
186 $cmd='row_bottom';
187 } elseif ($TABLE_c['row_up']) {
188 $kk = key($TABLE_c['row_up']);
189 $cmd='row_up';
190 } elseif ($TABLE_c['row_down']) {
191 $kk = key($TABLE_c['row_down']);
192 $cmd='row_down';
193 }
194
195 if ($cmd && t3lib_div::testInt($kk)) {
196 // debug($cmd);
197 // debug($cArr);
198 if (substr($cmd,0,4)=='row_') {
199 switch($cmd) {
200 case 'row_remove':
201 unset($cArr[$kk]);
202 break;
203 case 'row_add':
204 $cArr[$kk+1]=array();
205 break;
206 case 'row_top':
207 $cArr[1]=$cArr[$kk];
208 unset($cArr[$kk]);
209 break;
210 case 'row_bottom':
211 $cArr[10000000]=$cArr[$kk];
212 unset($cArr[$kk]);
213 break;
214 case 'row_up':
215 $cArr[$kk-3]=$cArr[$kk];
216 unset($cArr[$kk]);
217 break;
218 case 'row_down':
219 $cArr[$kk+3]=$cArr[$kk];
220 unset($cArr[$kk]);
221 break;
222 }
223 ksort($cArr);
224 }
225 if (substr($cmd,0,4)=='col_') {
226 reset($cArr);
227 while(list($cAK)=each($cArr)) {
228 switch($cmd) {
229 case 'col_remove':
230 unset($cArr[$cAK][$kk]);
231 break;
232 case 'col_add':
233 $cArr[$cAK][$kk+1]='';
234 break;
235 case 'col_start':
236 $cArr[$cAK][1]=$cArr[$cAK][$kk];
237 unset($cArr[$cAK][$kk]);
238 break;
239 case 'col_end':
240 $cArr[$cAK][1000000]=$cArr[$cAK][$kk];
241 unset($cArr[$cAK][$kk]);
242 break;
243 case 'col_left':
244 $cArr[$cAK][$kk-3]=$cArr[$cAK][$kk];
245 unset($cArr[$cAK][$kk]);
246 break;
247 case 'col_right':
248 $cArr[$cAK][$kk+3]=$cArr[$cAK][$kk];
249 unset($cArr[$cAK][$kk]);
250 break;
251 }
252 ksort($cArr[$cAK]);
253 }
254 }
255 // debug($cArr);
256 }
257 return $cArr;
258 }
259
260 /**
261 * [Describe function...]
262 *
263 * @param [type] $P: ...
264 * @return [type] ...
265 */
266 function tableWizard($P) {
267 global $LANG, $HTTP_POST_VARS;
268
269 $TABLE_c = t3lib_div::GPvar('TABLE',1);
270 $row=t3lib_BEfunc::getRecord($P['table'],$P['uid']);
271 if (!is_array($row)) {
272 t3lib_BEfunc::typo3PrintError ('Wizard Error','No reference to record',0);
273 exit;
274 }
275
276 $inputStyle=isset($TABLE_c['textFields']) ? $TABLE_c['textFields'] : 1;
277 $cols=$row['cols'];
278
279 if (isset($TABLE_c['c'])) {
280 $TABLE_c['c'] = $this->changeFunc($TABLE_c['c'],$TABLE_c);
281 $inLines=array();
282
283 reset($TABLE_c["c"]);
284 while(list($a)=each($TABLE_c["c"])) {
285 // for($a=0;$a<intval($TABLE_c["lines"]);$a++) {
286 $thisLine=array();
287 // for($b=0;$b<$cols;$b++) {
288 reset($TABLE_c["c"][$a]);
289 while(list($b)=each($TABLE_c["c"][$a])) {
290 $thisLine[]=str_replace("|","",str_replace(chr(10),"<BR>",str_replace(chr(13),"",$TABLE_c["c"][$a][$b])));
291 }
292 $inLines[]=implode("|",$thisLine);
293 }
294 $bodyText = implode(chr(10),$inLines);
295 // debug(array($bodyText));
296
297
298
299 if ($HTTP_POST_VARS["savedok_x"] || $HTTP_POST_VARS["saveandclosedok_x"]) {
300 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
301 $tce->stripslashes_values=0;
302 $data=array();
303 $data[$P["table"]][$P["uid"]][$P["field"]]=$bodyText;
304 $tce->start($data,array());
305 $tce->process_datamap();
306 if ($HTTP_POST_VARS["saveandclosedok_x"]) {
307 header("Location: ".t3lib_div::locationHeaderUrl($P["returnUrl"]));
308 exit;
309 }
310 }
311 } else {
312 $bodyText = $row["bodytext"];
313 }
314
315 $tLines=explode(chr(10),$bodyText);
316
317 // Columns:
318 if (!$cols && trim($tLines[0])) { // auto...
319 $cols = count(explode("|",$tLines[0]));
320 }
321 $cols=$cols?$cols:4;
322
323 reset($tLines);
324 $tRows=array();
325
326 while(list($k,$v)=each($tLines)) {
327 $cells=array();
328 $vParts = explode("|",$v);
329
330 for ($a=0;$a<$cols;$a++) {
331 $content=$vParts[$a];
332 if ($inputStyle) {
333 $cells[]='<input type="text"'.$this->doc->formWidth(20).' name="TABLE[c]['.(($k+1)*2).']['.(($a+1)*2).']" value="'.htmlspecialchars($content).'">';
334 } else {
335 $content=str_replace("<BR>",chr(10),$content);
336 $cells[]='<textarea '.$this->doc->formWidth(20).' rows="5" name="TABLE[c]['.(($k+1)*2).']['.(($a+1)*2).']">'.t3lib_div::formatForTextarea($content).'</textarea>';
337 }
338 }
339 $onClick="document.wizardForm.action+='#ANC_".(($k+1)*2-2)."';";
340 $onClick=' onClick="'.$onClick.'"';
341 $ctrl="";
342 $brTag=$inputStyle?"":"<BR>";
343 if ($k!=0) {
344 $ctrl.='<input type="image" name="TABLE[row_up]['.(($k+1)*2).']" src="gfx/pil2up.gif" width="12" vspace=2 height="7" border="0"'.$onClick.t3lib_BEfunc::titleAttrib($LANG->getLL("table_up")).'>'.$brTag;
345 } else {
346 $ctrl.='<input type="image" name="TABLE[row_bottom]['.(($k+1)*2).']" src="gfx/turn_up.gif" width="11" vspace=2 height="9" hspace=1 border="0"'.$onClick.t3lib_BEfunc::titleAttrib($LANG->getLL("table_bottom")).'>'.$brTag;
347 }
348 $ctrl.='<input type="image" name="TABLE[row_remove]['.(($k+1)*2).']" src="gfx/garbage.gif" width="11" height="12" border="0"'.$onClick.t3lib_BEfunc::titleAttrib($LANG->getLL("table_removeRow")).'>'.$brTag;
349
350 if (($k+1)!=count($tLines)) {
351 $ctrl.='<input type="image" name="TABLE[row_down]['.(($k+1)*2).']" src="gfx/pil2down.gif" width="12" vspace=2 height="7" hspace=1 border="0"'.$onClick.t3lib_BEfunc::titleAttrib($LANG->getLL("table_down")).'>'.$brTag;
352 } else {
353 $ctrl.='<input type="image" name="TABLE[row_top]['.(($k+1)*2).']" src="gfx/turn_down.gif" width="11" vspace=2 height="9" hspace=1 border="0"'.$onClick.t3lib_BEfunc::titleAttrib($LANG->getLL("table_top")).'>'.$brTag;
354 }
355 $ctrl.='<input type="image" name="TABLE[row_add]['.(($k+1)*2).']" src="gfx/add.gif" width="12" height="12" border="0"'.$onClick.t3lib_BEfunc::titleAttrib($LANG->getLL("table_addRow")).'>'.$brTag;
356
357 $tRows[]='<tr bgColor="'.$this->doc->bgColor4.'"><td bgColor="'.$this->doc->bgColor5.'"><a name="ANC_'.(($k+1)*2).'"></a>'.$ctrl.'</td><td>'.implode('</td><td>',$cells).'</td></tr>';
358 }
359
360 // REMOVE
361 $cells=array();
362 $cells[]='';
363 for ($a=0;$a<$cols;$a++) {
364 $content=$vParts[$a];
365 $content=str_replace("<BR>",chr(10),$content);
366 $ctrl="";
367 if ($a!=0) {
368 $ctrl.='<input type="image" name="TABLE[col_left]['.(($a+1)*2).']" src="gfx/pil2left.gif" width="7" hspace=2 height="12" border="0"'.t3lib_BEfunc::titleAttrib($LANG->getLL("table_left")).'>';
369 } else {
370 $ctrl.='<input type="image" name="TABLE[col_end]['.(($a+1)*2).']" src="gfx/turn_left.gif" width="9" hspace=2 vspace=1 height="11" border="0"'.t3lib_BEfunc::titleAttrib($LANG->getLL("table_end")).'>';
371 }
372 $ctrl.='<input type="image" name="TABLE[col_remove]['.(($a+1)*2).']" src="gfx/garbage.gif" width="11" height="12" border="0"'.t3lib_BEfunc::titleAttrib($LANG->getLL("table_removeColumn")).'>';
373 if (($a+1)!=$cols) {
374 $ctrl.='<input type="image" name="TABLE[col_right]['.(($a+1)*2).']" src="gfx/pil2right.gif" width="7" hspace=2 height="12" border="0"'.t3lib_BEfunc::titleAttrib($LANG->getLL("table_right")).'>';
375 } else {
376 $ctrl.='<input type="image" name="TABLE[col_start]['.(($a+1)*2).']" src="gfx/turn_right.gif" width="9" hspace=2 vspace=1 height="11" border="0"'.t3lib_BEfunc::titleAttrib($LANG->getLL("table_start")).'>';
377 }
378 $ctrl.='<input type="image" name="TABLE[col_add]['.(($a+1)*2).']" src="gfx/add.gif" width="12" hspace=5 height="12" border="0"'.t3lib_BEfunc::titleAttrib($LANG->getLL("table_addColumn")).'>';
379 $cells[]=$ctrl;
380 }
381 $tRows[]='<tr bgColor="'.$this->doc->bgColor5.'"><td align=center>'.implode('</td><td align=center>',$cells).'</td></tr>';
382
383 //
384 $content = '<table border=0 cellpadding=0 cellspacing=1>'.implode("",$tRows).'</table>';
385
386 $closeUrl = $P["returnUrl"];
387
388 $content.= '<BR>';
389 $content.= '<input type="image" border=0 name="savedok" src="gfx/savedok.gif" hspace=2 width="21" height="16"'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:rm.saveDoc"),1).' align=top>';
390 $content.= '<input type="image" border=0 name="saveandclosedok" src="gfx/saveandclosedok.gif" hspace=2 width="21" height="16"'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc"),1).' align=top>';
391 $content.= '<a href="#" onClick="jumpToUrl(unescape(\''.rawurlencode($closeUrl).'\')); return false;"><img border=0 src="gfx/closedok.gif" hspace=2 width="21" height="16"'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:rm.closeDoc"),1).' align=top></a>';
392 $content.= '<input type="image" name="_refresh" src="gfx/refresh_n.gif" width="14" height="14" hspace=10 border="0"'.t3lib_BEfunc::titleAttrib($LANG->getLL("forms_refresh")).'>';
393
394 $content.= '<BR><input type="hidden" name="TABLE[textFields]" value="0"><input type="checkbox" name="TABLE[textFields]" value="1"'.($inputStyle?" CHECKED":"").'> '.$LANG->getLL("table_smallFields");
395
396 return $content;
397 }
398 }
399
400 // Include extension?
401 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_table.php']) {
402 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_table.php']);
403 }
404
405
406
407
408
409
410
411
412
413
414
415
416 // Make instance:
417 $SOBE = t3lib_div::makeInstance('SC_wizard_table');
418 $SOBE->init();
419
420 // Include files?
421 reset($SOBE->include_once);
422 while(list(,$INC_FILE)=each($SOBE->include_once)) {include_once($INC_FILE);}
423
424 $SOBE->main();
425 $SOBE->printContent();
426 ?>