Initial revision
[Packages/TYPO3.CMS.git] / typo3 / wizard_table.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (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 * @author Kasper Skårhøj <kasper@typo3.com>
32 * @package TYPO3
33 * @subpackage core
34 *
35 */
36
37
38
39 $BACK_PATH="";
40 require ("init.php");
41 require ("template.php");
42 include ("sysext/lang/locallang_wizards.php");
43
44
45 // ***************************
46 // Script Classes
47 // ***************************
48 class SC_wizard_table {
49 var $include_once=array();
50 var $content;
51 var $P;
52 var $doc;
53
54 function init() {
55 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
56
57 $this->P = t3lib_div::GPvar("P",1);
58
59 $this->doc = t3lib_div::makeInstance("mediumDoc");
60 $this->doc->backPath = $BACK_PATH;
61 $this->doc->JScode='
62 <script language="javascript" type="text/javascript">
63 function jumpToUrl(URL,formEl) {
64 document.location = URL;
65 }
66 </script>
67 ';
68
69 list($rUri) = explode("#",t3lib_div::getIndpEnv("REQUEST_URI"));
70 $this->doc->form ='<form action="'.$rUri.'" method="POST" name="wizardForm">';
71
72 $this->content.=$this->doc->startPage("Table");
73
74 if ($HTTP_POST_VARS["savedok_x"] || $HTTP_POST_VARS["saveandclosedok_x"]) {
75 $this->include_once[]=PATH_t3lib."class.t3lib_tcemain.php";
76 }
77 }
78 function main() {
79 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
80
81 if ($this->P["table"] && $this->P["field"] && $this->P["uid"]) {
82 $this->content.=$this->doc->section($LANG->getLL("table_title"),$this->tableWizard($this->P),0,1);
83 } else {
84 $this->content.=$this->doc->section($LANG->getLL("table_title"),$GLOBALS["TBE_TEMPLATE"]->rfw($LANG->getLL("table_noData")),0,1);
85 }
86 $this->content.=$this->doc->endPage();
87 }
88 function printContent() {
89 echo $this->content;
90 }
91
92 // ***************************
93 // OTHER FUNCTIONS:
94 // ***************************
95 function changeFunc($cArr,$TABLE_c) {
96 if ($TABLE_c["col_remove"]) {
97 $kk = key($TABLE_c["col_remove"]);
98 $cmd="col_remove";
99 } elseif ($TABLE_c["col_add"]) {
100 $kk = key($TABLE_c["col_add"]);
101 $cmd="col_add";
102 } elseif ($TABLE_c["col_start"]) {
103 $kk = key($TABLE_c["col_start"]);
104 $cmd="col_start";
105 } elseif ($TABLE_c["col_end"]) {
106 $kk = key($TABLE_c["col_end"]);
107 $cmd="col_end";
108 } elseif ($TABLE_c["col_left"]) {
109 $kk = key($TABLE_c["col_left"]);
110 $cmd="col_left";
111 } elseif ($TABLE_c["col_right"]) {
112 $kk = key($TABLE_c["col_right"]);
113 $cmd="col_right";
114 } elseif ($TABLE_c["row_remove"]) {
115 $kk = key($TABLE_c["row_remove"]);
116 $cmd="row_remove";
117 } elseif ($TABLE_c["row_add"]) {
118 $kk = key($TABLE_c["row_add"]);
119 $cmd="row_add";
120 } elseif ($TABLE_c["row_top"]) {
121 $kk = key($TABLE_c["row_top"]);
122 $cmd="row_top";
123 } elseif ($TABLE_c["row_bottom"]) {
124 $kk = key($TABLE_c["row_bottom"]);
125 $cmd="row_bottom";
126 } elseif ($TABLE_c["row_up"]) {
127 $kk = key($TABLE_c["row_up"]);
128 $cmd="row_up";
129 } elseif ($TABLE_c["row_down"]) {
130 $kk = key($TABLE_c["row_down"]);
131 $cmd="row_down";
132 }
133
134 if ($cmd && t3lib_div::testInt($kk)) {
135 // debug($cmd);
136 // debug($cArr);
137 if (substr($cmd,0,4)=="row_") {
138 switch($cmd) {
139 case "row_remove":
140 unset($cArr[$kk]);
141 break;
142 case "row_add":
143 $cArr[$kk+1]=array();
144 break;
145 case "row_top":
146 $cArr[1]=$cArr[$kk];
147 unset($cArr[$kk]);
148 break;
149 case "row_bottom":
150 $cArr[10000000]=$cArr[$kk];
151 unset($cArr[$kk]);
152 break;
153 case "row_up":
154 $cArr[$kk-3]=$cArr[$kk];
155 unset($cArr[$kk]);
156 break;
157 case "row_down":
158 $cArr[$kk+3]=$cArr[$kk];
159 unset($cArr[$kk]);
160 break;
161 }
162 ksort($cArr);
163 }
164 if (substr($cmd,0,4)=="col_") {
165 reset($cArr);
166 while(list($cAK)=each($cArr)) {
167 switch($cmd) {
168 case "col_remove":
169 unset($cArr[$cAK][$kk]);
170 break;
171 case "col_add":
172 $cArr[$cAK][$kk+1]="";
173 break;
174 case "col_start":
175 $cArr[$cAK][1]=$cArr[$cAK][$kk];
176 unset($cArr[$cAK][$kk]);
177 break;
178 case "col_end":
179 $cArr[$cAK][1000000]=$cArr[$cAK][$kk];
180 unset($cArr[$cAK][$kk]);
181 break;
182 case "col_left":
183 $cArr[$cAK][$kk-3]=$cArr[$cAK][$kk];
184 unset($cArr[$cAK][$kk]);
185 break;
186 case "col_right":
187 $cArr[$cAK][$kk+3]=$cArr[$cAK][$kk];
188 unset($cArr[$cAK][$kk]);
189 break;
190 }
191 ksort($cArr[$cAK]);
192 }
193 }
194 // debug($cArr);
195 }
196
197
198 return $cArr;
199 }
200 function tableWizard($P) {
201 global $LANG, $HTTP_POST_VARS;
202
203 $TABLE_c = t3lib_div::GPvar("TABLE",1);
204 $row=t3lib_BEfunc::getRecord($P["table"],$P["uid"]);
205 if (!is_array($row)) {
206 t3lib_BEfunc::typo3PrintError ("Wizard Error","No reference to record",0);
207 exit;
208 }
209
210 $inputStyle=isset($TABLE_c["textFields"]) ? $TABLE_c["textFields"] : 1;
211 $cols=$row["cols"];
212
213 if (isset($TABLE_c["c"])) {
214 $TABLE_c["c"] = $this->changeFunc($TABLE_c["c"],$TABLE_c);
215 $inLines=array();
216
217 reset($TABLE_c["c"]);
218 while(list($a)=each($TABLE_c["c"])) {
219 // for($a=0;$a<intval($TABLE_c["lines"]);$a++) {
220 $thisLine=array();
221 // for($b=0;$b<$cols;$b++) {
222 reset($TABLE_c["c"][$a]);
223 while(list($b)=each($TABLE_c["c"][$a])) {
224 $thisLine[]=str_replace("|","",str_replace(chr(10),"<BR>",str_replace(chr(13),"",$TABLE_c["c"][$a][$b])));
225 }
226 $inLines[]=implode("|",$thisLine);
227 }
228 $bodyText = implode(chr(10),$inLines);
229 // debug(array($bodyText));
230
231
232
233 if ($HTTP_POST_VARS["savedok_x"] || $HTTP_POST_VARS["saveandclosedok_x"]) {
234 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
235 $tce->stripslashes_values=0;
236 $data=array();
237 $data[$P["table"]][$P["uid"]][$P["field"]]=$bodyText;
238 $tce->start($data,array());
239 $tce->process_datamap();
240 if ($HTTP_POST_VARS["saveandclosedok_x"]) {
241 header("Location: ".t3lib_div::locationHeaderUrl($P["returnUrl"]));
242 exit;
243 }
244 }
245 } else {
246 $bodyText = $row["bodytext"];
247 }
248
249 $tLines=explode(chr(10),$bodyText);
250
251 // Columns:
252 if (!$cols && trim($tLines[0])) { // auto...
253 $cols = count(explode("|",$tLines[0]));
254 }
255 $cols=$cols?$cols:4;
256
257 reset($tLines);
258 $tRows=array();
259
260 while(list($k,$v)=each($tLines)) {
261 $cells=array();
262 $vParts = explode("|",$v);
263
264 for ($a=0;$a<$cols;$a++) {
265 $content=$vParts[$a];
266 if ($inputStyle) {
267 $cells[]='<input type="text"'.$this->doc->formWidth(20).' name="TABLE[c]['.(($k+1)*2).']['.(($a+1)*2).']" value="'.htmlspecialchars($content).'">';
268 } else {
269 $content=str_replace("<BR>",chr(10),$content);
270 $cells[]='<textarea '.$this->doc->formWidth(20).' rows="5" name="TABLE[c]['.(($k+1)*2).']['.(($a+1)*2).']">'.t3lib_div::formatForTextarea($content).'</textarea>';
271 }
272 }
273 $onClick="document.wizardForm.action+='#ANC_".(($k+1)*2-2)."';";
274 $onClick=' onClick="'.$onClick.'"';
275 $ctrl="";
276 $brTag=$inputStyle?"":"<BR>";
277 if ($k!=0) {
278 $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;
279 } else {
280 $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;
281 }
282 $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;
283
284 if (($k+1)!=count($tLines)) {
285 $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;
286 } else {
287 $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;
288 }
289 $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;
290
291 $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>';
292 }
293
294 // REMOVE
295 $cells=array();
296 $cells[]='';
297 for ($a=0;$a<$cols;$a++) {
298 $content=$vParts[$a];
299 $content=str_replace("<BR>",chr(10),$content);
300 $ctrl="";
301 if ($a!=0) {
302 $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")).'>';
303 } else {
304 $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")).'>';
305 }
306 $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")).'>';
307 if (($a+1)!=$cols) {
308 $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")).'>';
309 } else {
310 $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")).'>';
311 }
312 $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")).'>';
313 $cells[]=$ctrl;
314 }
315 $tRows[]='<tr bgColor="'.$this->doc->bgColor5.'"><td align=center>'.implode('</td><td align=center>',$cells).'</td></tr>';
316
317 //
318 $content = '<table border=0 cellpadding=0 cellspacing=1>'.implode("",$tRows).'</table>';
319
320 $closeUrl = $P["returnUrl"];
321
322 $content.= '<BR>';
323 $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>';
324 $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>';
325 $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>';
326 $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")).'>';
327
328 $content.= '<BR><input type="hidden" name="TABLE[textFields]" value="0"><input type="checkbox" name="TABLE[textFields]" value="1"'.($inputStyle?" CHECKED":"").'> '.$LANG->getLL("table_smallFields");
329
330 return $content;
331 }
332 }
333
334 // Include extension?
335 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/wizard_table.php"]) {
336 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/wizard_table.php"]);
337 }
338
339
340
341
342
343
344
345
346
347
348
349
350 // Make instance:
351 $SOBE = t3lib_div::makeInstance("SC_wizard_table");
352 $SOBE->init();
353
354 // Include files?
355 reset($SOBE->include_once);
356 while(list(,$INC_FILE)=each($SOBE->include_once)) {include_once($INC_FILE);}
357
358 $SOBE->main();
359 $SOBE->printContent();
360 ?>