Updated years from 2004 to 2005 + all function indexes. NO actual code changes done!
[Packages/TYPO3.CMS.git] / typo3 / file_upload.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 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 * 162: function main()
43 * 235: 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
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 var $doc; // Template object.
84 var $basicff; // Instance of "t3lib_basicFileFunctions"
85 var $icon; // Will be set to the proper icon for the $target value.
86 var $shortPath; // Relative path to current found filemount
87 var $title; // Name of the filemount
88
89 // Internal, static (GPVar):
90 var $number;
91 var $target; // Set with the target path inputted in &target
92 var $returnUrl; // Return URL of list module.
93
94 // Internal, dynamic:
95 var $content; // Accumulating content
96
97
98 /**
99 * Constructor for initializing the class
100 *
101 * @return void
102 */
103 function init() {
104 global $LANG,$BACK_PATH,$TYPO3_CONF_VARS;
105
106 // Initialize GPvars:
107 $this->number = t3lib_div::_GP('number');
108 $this->target = t3lib_div::_GP('target');
109 $this->returnUrl = t3lib_div::_GP('returnUrl');
110
111 // Init basic-file-functions object:
112 $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
113 $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
114
115 // Cleaning and checking target
116 $this->target=$this->basicff->is_directory($this->target); // Cleaning and checking target
117 $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
118 if (!$this->target || !$key) {
119 t3lib_BEfunc::typo3PrintError ('Parameter Error','Target was not a directory!','');
120 exit;
121 }
122
123 // Finding the icon
124 switch($GLOBALS['FILEMOUNTS'][$key]['type']) {
125 case 'user': $this->icon = 'gfx/i/_icon_ftp_user.gif'; break;
126 case 'group': $this->icon = 'gfx/i/_icon_ftp_group.gif'; break;
127 default: $this->icon = 'gfx/i/_icon_ftp.gif'; break;
128 }
129
130 // Relative path to filemount, $key:
131 $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
132
133 // Setting title:
134 $this->title = $GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
135
136 // Setting template object
137 $this->doc = t3lib_div::makeInstance('smallDoc');
138 $this->doc->docType = 'xhtml_trans';
139 $this->doc->backPath = $BACK_PATH;
140 $this->doc->form='<form action="tce_file.php" method="post" name="editform" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'">';
141 $this->doc->JScode=$this->doc->wrapScriptTags('
142 var path = "'.$this->target.'";
143
144 function reload(a) { //
145 if (!changed || (changed && confirm('.$LANG->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')).'))) {
146 var params = "&target="+escape(path)+"&number="+a;
147 document.location = "file_upload.php?"+params;
148 }
149 }
150 function backToList() { //
151 top.goToModule("file_list");
152 }
153 var changed = 0;
154 ');
155 }
156
157 /**
158 * Main function, rendering the upload file form fields
159 *
160 * @return void
161 */
162 function main() {
163 global $LANG;
164
165 // Make page header:
166 $this->content='';
167 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
168 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
169 $this->content.=$this->doc->spacer(5);
170 $this->content.=$this->doc->section('',$this->doc->getFileheader($this->title,$this->shortPath,$this->icon));
171 $this->content.=$this->doc->divider(5);
172
173
174 // Making the selector box for the number of concurrent uploads
175 $this->number = t3lib_div::intInRange($this->number,1,10);
176 $code='
177 <div id="c-select">
178 <select name="number" onchange="reload(this.options[this.selectedIndex].value);">';
179 for ($a=1;$a<=$this->uploadNumber;$a++) {
180 $code.='
181 <option value="'.$a.'"'.($this->number==$a?' selected="selected"':'').'>'.$a.' '.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.files',1).'</option>';
182 }
183 $code.='
184 </select>
185 </div>
186 ';
187
188 // Make checkbox for "overwrite"
189 $code.='
190 <div id="c-override">
191 <input type="checkbox" name="overwriteExistingFiles" value="1" /> '.$LANG->getLL('overwriteExistingFiles',1).'
192 </div>
193 ';
194
195 // Produce the number of upload-fields needed:
196 $code.='
197 <div id="c-upload">
198 ';
199 for ($a=0;$a<$this->number;$a++) {
200 // Adding 'size="50" ' for the sake of Mozilla!
201 $code.='
202 <input type="file" name="upload_'.$a.'"'.$this->doc->formWidth(35).' size="50" onclick="changed=1;" />
203 <input type="hidden" name="file[upload]['.$a.'][target]" value="'.htmlspecialchars($this->target).'" />
204 <input type="hidden" name="file[upload]['.$a.'][data]" value="'.$a.'" /><br />
205 ';
206 }
207 $code.='
208 </div>
209 ';
210
211 // Submit button:
212 $code.='
213 <div id="c-submit">
214 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit',1).'" />
215 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
216 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
217 </div>
218 ';
219
220 // CSH:
221 $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH'],'<br/>');
222
223 // Add the HTML as a section:
224 $this->content.= $this->doc->section('',$code);
225
226 // Ending page
227 $this->content.= $this->doc->endPage();
228 }
229
230 /**
231 * Outputting the accumulated content to screen
232 *
233 * @return void
234 */
235 function printContent() {
236
237 echo $this->content;
238 }
239 }
240
241 // Include extension?
242 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_upload.php']) {
243 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_upload.php']);
244 }
245
246
247
248
249
250
251
252
253
254
255
256
257 // Make instance:
258 $SOBE = t3lib_div::makeInstance('SC_file_upload');
259 $SOBE->init();
260 $SOBE->main();
261 $SOBE->printContent();
262 ?>