Fixed bug #13294: IRRE deleted combo records are still validated by TBE_EDITOR (Thank...
[Packages/TYPO3.CMS.git] / typo3 / alt_palette.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 Kasper Skårhøj (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 * 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 * Displays the secondary-options palette for the TCEFORMs wherever they are shown.
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
32 * XHTML compliant
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 81: class formRender extends t3lib_TCEforms
42 * 91: function printPalette($palArr)
43 *
44 *
45 * 154: class formRender_vert extends t3lib_TCEforms
46 * 163: function printPalette($palArr)
47 *
48 *
49 * 223: class SC_alt_palette
50 * 247: function init()
51 * 301: function main()
52 * 341: function printContent()
53 *
54 * TOTAL FUNCTIONS: 5
55 * (This index is automatically created/updated by the extension "extdeveval")
56 *
57 * @deprecated since TYPO3 4.5, this file will be removed in TYPO3 4.7. The TYPO3 backend is using typo3/backend.php with less frames, which makes this file obsolete.
58 */
59
60
61 require('init.php');
62 require('template.php');
63 $LANG->includeLLFile('EXT:lang/locallang_alt_doc.xml');
64
65
66 t3lib_div::deprecationLog('alt_palette.php is deprecated since TYPO3 4.5, this file will be removed in TYPO3 4.7. The TYPO3 backend is using typo3/backend.php with less frames, which makes this file obsolete.');
67
68
69
70
71 /**
72 * Class for rendering the form fields.
73 * Extending the TCEforms class
74 *
75 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
76 * @package TYPO3
77 * @subpackage core
78 * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.6
79 */
80 class formRender extends t3lib_TCEforms {
81
82 /**
83 * Creates the HTML content for the palette
84 * (Horizontally, for display in the top frame)
85 * (Used if GET var "backRef" IS set)
86 *
87 * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.6
88 * @param array Array of information from which the fields are built.
89 * @return string HTML output
90 */
91 function printPalette($palArr) {
92 t3lib_div::logDeprecatedFunction();
93
94 $out='';
95
96 // For each element on the palette, write a few table cells with the field name, content and control images:
97 foreach($palArr as $content) {
98 $iRow[]='
99 <td>'.
100 '<img name="req_'.$content['TABLE'].'_'.$content['ID'].'_'.$content['FIELD'].'" class="c-reqIcon" src="clear.gif" width="10" height="10" alt="" />'.
101 '<img name="cm_'.$content['TABLE'].'_'.$content['ID'].'_'.$content['FIELD'].'" class="c-cmIcon" src="clear.gif" width="7" height="10" alt="" />'.
102 '</td>
103 <td class="c-label">'.
104 $content['NAME'].'&nbsp;'.
105 '</td>
106 <td class="c-csh">'.
107 $content['ITEM'].$content['HELP_ICON'].
108 '</td>';
109 }
110
111 // Finally, wrap it all in a table:
112 $out='
113
114
115
116 <!--
117 TCEforms palette, rendered in top frame.
118 -->
119 <table border="0" cellpadding="0" cellspacing="0" id="typo3-TCEforms-palette">
120 <tr>
121 <td class="c-close">'.
122 '<a href="#" onclick="closePal();return false;">' . t3lib_iconWorks::getSpriteIcon('actions-document-close', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.close', TRUE))) . '</a>'.
123 '</td>'.
124 implode('',$iRow).'
125 </tr>
126 </table>
127
128 ';
129
130 // Return the result:
131 return $out;
132 }
133 }
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148 /**
149 * Child class for alternative rendering of form fields (when the secondary fields are shown in a little window rather than the top bar).
150 * (Used if GET var "backRef" is not set, presuming a window is opened instead.)
151 *
152 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
153 * @package TYPO3
154 * @subpackage core
155 */
156 class formRender_vert extends t3lib_TCEforms {
157
158 /**
159 * Creates the HTML content for the palette.
160 * (Vertically, for display in a browser window, not top frame)
161 *
162 * @param array Array of information from which the fields are built.
163 * @return string HTML output
164 */
165 function printPalette($palArr) {
166 $out='';
167 $bgColor=' bgcolor="'.$this->colorScheme[2].'"';
168
169 // For each element on the palette, write a few table cells with the field name, content and control images:
170 foreach($palArr as $content) {
171 $iRow[]='
172 <tr>
173 <td><img src="clear.gif" width="'.intval($this->paletteMargin).'" height="1" alt="" /></td>
174 <td'.$bgColor.'>&nbsp;</td>
175 <td nowrap="nowrap"'.$bgColor.'><font color="'.$this->colorScheme[4].'">'.$content['NAME'].'</font></td>
176 </tr>';
177 $iRow[]='
178 <tr>
179 <td></td>
180 <td valign="top"><img name="req_'.$content['TABLE'].'_'.$content['ID'].'_'.$content['FIELD'].'" src="clear.gif" width="10" height="10" vspace="4" alt="" /><img name="cm_'.$content['TABLE'].'_'.$content['ID'].'_'.$content['FIELD'].'" src="clear.gif" width="7" height="10" vspace="4" alt="" /></td>
181 <td nowrap="nowrap" valign="top">'.$content['ITEM'].$content['HELP_ICON'].'</td>
182 </tr>';
183 }
184
185 // Adding the close button:
186 $iRow[]='
187 <tr>
188 <td></td>
189 <td></td>
190 <td nowrap="nowrap" valign="top">
191 <br />
192 <input type="submit" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.close',1).'" onclick="closePal(); return false;" />
193 </td>
194 </tr>';
195
196 // Finally, wrap it all in a table:
197 $out='
198 <table border="0" cellpadding="0" cellspacing="0" id="typo3-TCEforms-palette-vert">
199 '.implode('',$iRow).'
200 </table>';
201
202 // Return content:
203 return $out;
204 }
205 }
206
207
208
209
210
211
212
213
214
215
216
217 /**
218 * Script Class for rendering the palette form for TCEforms in some other frame (in top frame, horizontally)
219 * It can also be called in a pop-up window in which case a vertically oriented set of form fields are rendered instead.
220 *
221 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
222 * @package TYPO3
223 * @subpackage core
224 */
225 class SC_alt_palette {
226
227 // Internal:
228 var $content; // Content accumulation
229 var $backRef; // String, which is the reference back to the window which opened this one.
230 var $formRef; // String, which is the reference to the form.
231 var $doc; // Template object.
232
233 // Internal, static: GPvar:
234 var $formName; // Form name
235 var $GPbackref; // The value of the original backRef GPvar (not necessarily the same as $this->backRef)
236 var $inData; // Contains tablename, uid and palette number
237 var $prependFormFieldNames; // Prefix for form fields.
238 var $rec; // The "record" with the data to display in the form fields.
239
240
241
242
243
244 /**
245 * Constructor for the class
246 *
247 * @return void
248 */
249 function init() {
250
251 // Setting GPvars, etc.
252 $this->formName = $this->sanitizeHtmlName(t3lib_div::_GP('formName'));
253 $this->GPbackref = $this->sanitizeHtmlName(t3lib_div::_GP('backRef'));
254 $this->inData = t3lib_div::_GP('inData');
255 // safeguards the input with whitelisting
256 if (!preg_match('/^[a-zA-Z0-9\-_\:]+$/', $this->inData)) {
257 $this->inData = '';
258 }
259 $this->prependFormFieldNames =
260 $this->sanitizeHtmlName(t3lib_div::_GP('prependFormFieldNames'));
261 $this->rec = t3lib_div::_GP('rec');
262
263 // Making references:
264 $this->backRef = $this->GPbackref ? $this->GPbackref : 'window.opener';
265
266 $this->formRef = $this->backRef.'.document.'.$this->formName;
267
268 // Start template object:
269 $this->doc = t3lib_div::makeInstance('template');
270 $this->doc->bodyTagMargins['x']=0;
271 $this->doc->bodyTagMargins['y']=0;
272 $this->doc->form='<form action="#" method="post" name="'.htmlspecialchars($this->formName).'" onsubmit="return false;">';
273 $this->doc->backPath = '';
274
275 // In case the palette is opened in a SEPARATE window (as the case is with frontend editing) then another body-tag id should be used (so we don't get the background image for the palette shown!)
276 if (!$this->GPbackref) $this->doc->bodyTagId.= '-vert';
277
278 // Setting JavaScript functions for the header:
279 $this->doc->JScode = $this->doc->wrapScriptTags('
280 var serialNumber = "";
281 function timeout_func() { //
282 if ('.$this->backRef.' && '.$this->backRef.'.document && '.$this->formRef.') {
283 if ('.$this->formRef.'["_serialNumber"]) {
284 if (serialNumber) {
285 if ('.$this->formRef.'["_serialNumber"].value != serialNumber) {closePal(); return false;}
286 } else {
287 serialNumber = '.$this->formRef.'["_serialNumber"].value;
288 }
289 }
290 window.setTimeout("timeout_func();",1*1000);
291 } else closePal();
292 }
293 function closePal() { //
294 '.($this->GPbackref?'window.location.href="alt_topmenu_dummy.php";':'close();').'
295 }
296 timeout_func();
297 onBlur="alert();";
298 ');
299 }
300
301 /**
302 * Sanitizes HTML names, IDs, frame names etc.
303 *
304 * @param string $input the string to sanitize
305 *
306 * @return string the unchanged $input if $input is considered to be harmless,
307 * an empty string otherwise
308 */
309 protected function sanitizeHtmlName($input) {
310 $result = $input;
311
312 if (!preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $result)) {
313 $result = '';
314 }
315
316 return $result;
317 }
318
319 /**
320 * Main function, rendering the palette form
321 *
322 * @return void
323 */
324 function main() {
325
326 $this->content='';
327
328 $inData = explode(':',$this->inData);
329
330 // Begin edit:
331 if (is_array($inData) && count($inData)==3) {
332
333 // Create the TCEforms object:
334 $tceforms = $this->GPbackref ? new formRender() : new formRender_vert();
335 $tceforms->initDefaultBEMode();
336 $tceforms->palFieldTemplate='###FIELD_PALETTE###';
337 $tceforms->palettesCollapsed=0;
338 $tceforms->isPalettedoc=$this->backRef;
339
340 $tceforms->formName = $this->formName;
341 $tceforms->prependFormFieldNames = $this->prependFormFieldNames;
342
343 // Initialize other data:
344 $table=$inData[0];
345 $theUid=$inData[1];
346 $thePalNum = $inData[2];
347 $this->rec['uid']=$theUid;
348
349 // Getting the palette fields rendered:
350 $panel.=$tceforms->getPaletteFields($table,$this->rec,$thePalNum,'',implode(',',array_keys($this->rec)));
351 $formContent=$panel;
352
353 // Add all the content, including JavaScript as needed.
354 $this->content.=$tceforms->printNeededJSFunctions_top().$formContent.$tceforms->printNeededJSFunctions();
355 }
356
357 // Assemble the page:
358 $tempContent = $this->content;
359 $this->content = $this->doc->startPage('TYPO3 Edit Palette');
360 $this->content.= $tempContent;
361 }
362
363 /**
364 * Outputting the accumulated content to screen
365 *
366 * @return void
367 */
368 function printContent() {
369 $this->content.= $this->doc->endPage();
370 $this->content = $this->doc->insertStylesAndJS($this->content);
371 echo $this->content;
372 }
373 }
374
375
376 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_palette.php']) {
377 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_palette.php']);
378 }
379
380
381
382 // Make instance:
383 $SOBE = t3lib_div::makeInstance('SC_alt_palette');
384 $SOBE->init();
385 $SOBE->main();
386 $SOBE->printContent();
387
388 ?>