fixed missing for-id link in multiple uploads select field
[Packages/TYPO3.CMS.git] / typo3 / file_upload.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 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 * 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 * Web>File: Upload of files
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 77: class SC_file_upload
41 * 103: function init()
42 * 171: function main()
43 * 241: function printContent()
44 *
45 * TOTAL FUNCTIONS: 3
46 * (This index is automatically created/updated by the extension "extdeveval")
47 *
48 */
49
50
51
52 $BACK_PATH = '';
53 require('init.php');
54 require('template.php');
55 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
56 require_once(PATH_t3lib.'class.t3lib_basicfilefunc.php');
57 require_once(PATH_t3lib.'class.t3lib_parsehtml.php');
58
59
60
61
62
63
64
65
66
67
68
69
70 /**
71 * Script Class for display up to 10 upload fields
72 *
73 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
74 * @package TYPO3
75 * @subpackage core
76 */
77 class SC_file_upload {
78
79 // External, static:
80 var $uploadNumber=10;
81
82 // Internal, static:
83 /**
84 * Document template object
85 *
86 * @var smallDoc
87 */
88 var $doc;
89
90 /**
91 * File processing object
92 *
93 * @var t3lib_basicFileFunctions
94 */
95 var $basicff;
96 var $icon; // Will be set to the proper icon for the $target value.
97 var $shortPath; // Relative path to current found filemount
98 var $title; // Name of the filemount
99
100 /**
101 * Charset processing object
102 *
103 * @var t3lib_cs
104 */
105 protected $charsetConversion;
106
107 // Internal, static (GPVar):
108 var $number;
109 var $target; // Set with the target path inputted in &target
110 var $returnUrl; // Return URL of list module.
111
112 // Internal, dynamic:
113 var $content; // Accumulating content
114
115
116 /**
117 * Constructor for initializing the class
118 *
119 * @return void
120 */
121 function init() {
122 global $LANG,$BACK_PATH,$TYPO3_CONF_VARS;
123
124 // Initialize GPvars:
125 $this->number = t3lib_div::_GP('number');
126 $this->target = t3lib_div::_GP('target');
127 $this->returnUrl = t3lib_div::_GP('returnUrl');
128 $this->returnUrl = $this->returnUrl ? $this->returnUrl : t3lib_div::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir.'file_list.php?id='.rawurlencode($this->target);
129
130 if (empty($this->number)) {
131 $defaultFileUploads = $GLOBALS['BE_USER']->getTSConfigVal('options.defaultFileUploads');
132 if ($defaultFileUploads) {
133 $this->number = t3lib_div::intInRange($defaultFileUploads,1,$this->uploadNumber);
134 }
135 }
136 // Init basic-file-functions object:
137 $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
138 $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
139
140 // Init basic-charset-functions object:
141 $this->charsetConversion = t3lib_div::makeInstance('t3lib_cs');
142
143 // Cleaning and checking target
144 $this->target = $this->charsetConversion->conv($this->target, 'utf-8', $GLOBALS['LANG']->charSet);
145 $this->target = $this->basicff->is_directory($this->target);
146 $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
147 if (!$this->target || !$key) {
148 t3lib_BEfunc::typo3PrintError ('Parameter Error','Target was not a directory!','');
149 exit;
150 }
151
152 // Finding the icon
153 switch($GLOBALS['FILEMOUNTS'][$key]['type']) {
154 case 'user': $this->icon = 'gfx/i/_icon_ftp_user.gif'; break;
155 case 'group': $this->icon = 'gfx/i/_icon_ftp_group.gif'; break;
156 default: $this->icon = 'gfx/i/_icon_ftp.gif'; break;
157 }
158
159 $this->icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$this->icon,'width="18" height="16"').' title="" alt="" />';
160
161 // Relative path to filemount, $key:
162 $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
163
164 // Setting title:
165 $this->title = $this->icon.$GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
166
167 // Setting template object
168 $this->doc = t3lib_div::makeInstance('template');
169 $this->doc->setModuleTemplate('templates/file_upload.html');
170 $this->doc->backPath = $BACK_PATH;
171
172 if($GLOBALS['BE_USER']->jsConfirmation(1)) {
173 $confirm = ' && confirm('.$LANG->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')).')';
174 } else {
175 $confirm = '';
176 }
177 $this->doc->JScode=$this->doc->wrapScriptTags('
178 var path = "'.$this->target.'";
179
180 function reload(a) { //
181 if (!changed || (changed '.$confirm.')) {
182 var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl='
183 . urlencode($this->charsetConversion->conv($this->returnUrl, $GLOBALS['LANG']->charSet, 'utf-8'))
184 . '";
185 window.location.href = "file_upload.php?"+params;
186 }
187 }
188 function backToList() { //
189 top.goToModule("file_list");
190 }
191 var changed = 0;
192 ');
193 }
194
195 /**
196 * Main function, rendering the upload file form fields
197 *
198 * @return void
199 */
200 function main() {
201 global $LANG;
202
203 // Make page header:
204 $this->content = $this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
205
206 $pageContent.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
207 $pageContent.=$this->doc->spacer(5);
208 $pageContent.=$this->doc->divider(5);
209
210
211 $code = '<form action="tce_file.php" method="post" name="editform" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'">';
212 // Making the selector box for the number of concurrent uploads
213 $this->number = t3lib_div::intInRange($this->number,1,10);
214 $code .= '
215 <div id="c-select">
216 <label for="number-of-uploads">' .
217 $LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.number_of_files') .
218 '</label>
219 <select name="number" id="number-of-uploads" onchange="reload(this.options[this.selectedIndex].value);">';
220 for ($a=1;$a<=$this->uploadNumber;$a++) {
221 $code.='<option value="' . $a . '"' .
222 ($this->number == $a ? ' selected="selected"' : '' ) .
223 '>' . $a . '</option>';
224 }
225 $code.='
226 </select>
227 </div>
228 ';
229
230 // Make checkbox for "overwrite"
231 $code.='
232 <div id="c-override">
233 <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> <label for="overwriteExistingFiles">'.$LANG->getLL('overwriteExistingFiles',1).'</label>
234 </div>
235 ';
236
237 // Produce the number of upload-fields needed:
238 $code.='
239 <div id="c-upload">
240 ';
241 for ($a=0;$a<$this->number;$a++) {
242 // Adding 'size="50" ' for the sake of Mozilla!
243 $code.='
244 <input type="file" name="upload_'.$a.'"'.$this->doc->formWidth(35).' size="50" onclick="changed=1;" />
245 <input type="hidden" name="file[upload]['.$a.'][target]" value="'.htmlspecialchars($this->target).'" />
246 <input type="hidden" name="file[upload]['.$a.'][data]" value="'.$a.'" /><br />
247 ';
248 }
249 $code.='
250 </div>
251 ';
252
253 // Submit button:
254 $code.='
255 <div id="c-submit">
256 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit',1).'" />
257 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
258 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
259 </div>
260 ';
261
262 // Add the HTML as a section:
263 $pageContent.= $this->doc->section('',$code);
264
265
266 // Header Buttons
267 $docHeaderButtons = array(
268 'csh' => t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH'])
269 );
270
271 $markerArray = array(
272 'CSH' => $docHeaderButtons['csh'],
273 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
274 'CONTENT' => $pageContent,
275 'PATH' => $this->title,
276 );
277
278 $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
279 $this->content.= $this->doc->endPage();
280 $this->content = $this->doc->insertStylesAndJS($this->content);
281 }
282
283 /**
284 * Outputting the accumulated content to screen
285 *
286 * @return void
287 */
288 function printContent() {
289 echo $this->content;
290 }
291 }
292
293
294 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_upload.php']) {
295 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_upload.php']);
296 }
297
298
299
300 // Make instance:
301 $SOBE = t3lib_div::makeInstance('SC_file_upload');
302 $SOBE->init();
303 $SOBE->main();
304 $SOBE->printContent();
305
306 ?>