[BUGFIX] Reduce spacing CGL violations in /typo3/
[Packages/TYPO3.CMS.git] / typo3 / wizard_edit.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 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 * Wizard to edit records from group/select lists in TCEforms
29 *
30 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34
35
36
37 $BACK_PATH='';
38 require ('init.php');
39 require ('template.php');
40 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
41
42
43 /**
44 * Script Class for redirecting a backend user to the editing form when an "Edit wizard" link was clicked in TCEforms somewhere
45 *
46 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
47 * @package TYPO3
48 * @subpackage core
49 */
50 class SC_wizard_edit {
51
52 // Internal, static: GPvars
53 var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
54 var $doClose; // Boolean; if set, the window will be closed by JavaScript
55
56
57
58
59 /**
60 * Initialization of the script
61 *
62 * @return void
63 */
64 function init() {
65 $this->P = t3lib_div::_GP('P');
66 $this->doClose = t3lib_div::_GP('doClose'); // Used for the return URL to alt_doc.php so that we can close the window.
67 }
68
69 /**
70 * Main function
71 * Makes a header-location redirect to an edit form IF POSSIBLE from the passed data - otherwise the window will just close.
72 *
73 * @return void
74 */
75 function main() {
76 if ($this->doClose) {
77 $this->closeWindow();
78 } else {
79
80 // Initialize:
81 $table = $this->P['table'];
82 $field = $this->P['field'];
83 t3lib_div::loadTCA($table);
84 $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
85 $fTable = $this->P['currentValue']<0 ? $config['neg_foreign_table'] : $config['foreign_table'];
86
87 // Detecting the various allowed field type setups and acting accordingly.
88 if (is_array($config) && $config['type']=='select' && !$config['MM'] && $config['maxitems']<=1 && t3lib_utility_Math::canBeInterpretedAsInteger($this->P['currentValue']) && $this->P['currentValue'] && $fTable) { // SINGLE value:
89 $redirectUrl = 'alt_doc.php?returnUrl=' . rawurlencode('wizard_edit.php?doClose=1') . '&edit[' . $fTable . '][' . $this->P['currentValue'] . ']=edit';
90 t3lib_utility_Http::redirect($redirectUrl);
91 } elseif (is_array($config) && $this->P['currentSelectedValues'] && (($config['type']=='select' && $config['foreign_table']) || ($config['type']=='group' && $config['internal_type']=='db'))) { // MULTIPLE VALUES:
92
93 // Init settings:
94 $allowedTables = $config['type']=='group' ? $config['allowed'] : $config['foreign_table'].','.$config['neg_foreign_table'];
95 $prependName=1;
96 $params='';
97
98 // Selecting selected values into an array:
99 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
100 $dbAnalysis->start($this->P['currentSelectedValues'],$allowedTables);
101 $value = $dbAnalysis->getValueArray($prependName);
102
103 // Traverse that array and make parameters for alt_doc.php:
104 foreach($value as $rec) {
105 $recTableUidParts = t3lib_div::revExplode('_',$rec,2);
106 $params.='&edit['.$recTableUidParts[0].']['.$recTableUidParts[1].']=edit';
107 }
108
109 // Redirect to alt_doc.php:
110 t3lib_utility_Http::redirect('alt_doc.php?returnUrl=' . rawurlencode('wizard_edit.php?doClose=1') . $params);
111 } else {
112 $this->closeWindow();
113 }
114 }
115 }
116
117 /**
118 * Printing a little JavaScript to close the open window.
119 *
120 * @return void
121 */
122 function closeWindow() {
123 echo '<script language="javascript" type="text/javascript">close();</script>';
124 exit;
125 }
126 }
127
128 // Make instance:
129 $SOBE = t3lib_div::makeInstance('SC_wizard_edit');
130 $SOBE->init();
131 $SOBE->main();
132
133 ?>