ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilFileWizardInputGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
32{
33 protected $filenames = array();
34 protected $allowMove = false;
35 protected $imagepath_web = "";
36
43 function __construct($a_title = "", $a_postvar = "")
44 {
45 parent::__construct($a_title, $a_postvar);
46 }
47
53 public function setImagePathWeb($a_path)
54 {
55 $this->imagepath_web = $a_path;
56 }
57
63 public function getImagePathWeb()
64 {
66 }
67
73 function setFilenames($a_filenames)
74 {
75 $this->filenames = $a_filenames;
76 }
77
83 function getFilenames()
84 {
85 return $this->filenames;
86 }
87
93 function setAllowMove($a_allow_move)
94 {
95 $this->allowMove = $a_allow_move;
96 }
97
103 function getAllowMove()
104 {
105 return $this->allowMove;
106 }
107
113 function checkInput()
114 {
115 global $lng;
116
117 $pictures = $_FILES[$this->getPostVar()];
118 $uploadcheck = true;
119 if (is_array($pictures))
120 {
121 foreach ($pictures['name'] as $index => $name)
122 {
123 // remove trailing '/'
124 while (substr($name, -1) == '/')
125 {
126 $name = substr($name, 0, -1);
127 }
128
129 $filename = $name;
130 $filename_arr = pathinfo($name);
131 $suffix = $filename_arr["extension"];
132 $mimetype = $pictures["type"][$index];
133 $size_bytes = $pictures["size"][$index];
134 $temp_name = $pictures["tmp_name"][$index];
135 $error = $pictures["error"][$index];
136 // error handling
137 if ($error > 0)
138 {
139 switch ($error)
140 {
141 case UPLOAD_ERR_INI_SIZE:
142 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
143 $uploadcheck = false;
144 break;
145
146 case UPLOAD_ERR_FORM_SIZE:
147 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
148 $uploadcheck = false;
149 break;
150
151 case UPLOAD_ERR_PARTIAL:
152 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
153 $uploadcheck = false;
154 break;
155
156 case UPLOAD_ERR_NO_FILE:
157 if ($this->getRequired())
158 {
159 $filename = $this->filenames[$index];
160 if (!strlen($filename))
161 {
162 $this->setAlert($lng->txt("form_msg_file_no_upload"));
163 $uploadcheck = false;
164 }
165 }
166 break;
167
168 case UPLOAD_ERR_NO_TMP_DIR:
169 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
170 $uploadcheck = false;
171 break;
172
173 case UPLOAD_ERR_CANT_WRITE:
174 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
175 $uploadcheck = false;
176 break;
177
178 case UPLOAD_ERR_EXTENSION:
179 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
180 $uploadcheck = false;
181 break;
182 }
183 }
184
185 // check suffixes
186 if ($pictures["tmp_name"][$index] != "" && is_array($this->getSuffixes()))
187 {
188 if (!in_array(strtolower($suffix), $this->getSuffixes()))
189 {
190 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
191 $uploadcheck = false;
192 }
193 }
194
195 // virus handling
196 if ($pictures["tmp_name"][$index] != "")
197 {
198 $vir = ilUtil::virusHandling($temp_name, $filename);
199 if ($vir[0] == false)
200 {
201 $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
202 $uploadcheck = false;
203 }
204 }
205 }
206
207 }
208
209 if (!$uploadcheck)
210 {
211 return FALSE;
212 }
213
214 return $this->checkSubItemsInput();
215 }
216
222 function insert(&$a_tpl)
223 {
224 global $lng;
225
226 $tpl = new ilTemplate("tpl.prop_filewizardinput.html", true, true, "Services/Form");
227
228 $i = 0;
229 foreach ($this->filenames as $value)
230 {
231 if (strlen($value))
232 {
233 $tpl->setCurrentBlock("image");
234 $tpl->setVariable("SRC_IMAGE", $this->getImagePathWeb() . ilUtil::prepareFormOutput($value));
235 $tpl->setVariable("PICTURE_FILE", ilUtil::prepareFormOutput($value));
236 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
237 $tpl->setVariable("ALT_IMAGE", ilUtil::prepareFormOutput($value));
238 $tpl->parseCurrentBlock();
239 }
240 if ($this->getAllowMove())
241 {
242 $tpl->setCurrentBlock("move");
243 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
244 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
245 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
246 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
247 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
248 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
249 $tpl->parseCurrentBlock();
250 }
251
252 $this->outputSuffixes($tpl, "allowed_image_suffixes");
253
254 $tpl->setCurrentBlock("row");
255 $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
256 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
257 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
258 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
259 $tpl->setVariable("ALT_ADD", $lng->txt("add"));
260 $tpl->setVariable("ALT_REMOVE", $lng->txt("remove"));
261 if ($this->getDisabled())
262 {
263 $tpl->setVariable("DISABLED",
264 " disabled=\"disabled\"");
265 }
266
267 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
268 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
269 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
270 $tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " . $this->getMaxFileSizeString());
271 $tpl->parseCurrentBlock();
272 $i++;
273 }
274 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
275
276 $a_tpl->setCurrentBlock("prop_generic");
277 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
278 $a_tpl->parseCurrentBlock();
279
280 global $tpl;
281 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
282 $tpl->addJavascript("./Services/Form/templates/default/filewizard.js");
283 }
284}
global $tpl
Definition: ilias.php:8
This class represents a file property in a property form.
outputSuffixes($a_tpl, $a_block="allowed_suffixes")
getSuffixes()
Get Accepted Suffixes.
This class represents a file wizard property in a property form.
insert(&$a_tpl)
Insert property html.
setImagePathWeb($a_path)
Set the web image path.
setAllowMove($a_allow_move)
Set allow move.
checkInput()
Check input, strip slashes etc.
__construct($a_title="", $a_postvar="")
Constructor.
getImagePathWeb()
Get the web image path.
setFilenames($a_filenames)
Set filenames.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
special template class to simplify handling of ITX/PEAR
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
global $lng
Definition: privfeed.php:40