ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilImageWizardInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Form/classes/class.ilTextInputGUI.php';
5require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
6
15{
16 protected $values = array();
17 protected $allowMove = false;
18 protected $qstObject = null;
19 protected $suffixes = array();
20
27 function __construct($a_title = "", $a_postvar = "")
28 {
29 parent::__construct($a_title, $a_postvar);
31 $this->setSize('25');
32 $this->validationRegexp = "";
33 }
34
40 function setValue($a_value)
41 {
42 $this->values = array();
43 if (is_array($a_value))
44 {
45 if (is_array($a_value['count']))
46 {
47 foreach ($a_value['count'] as $index => $value)
48 {
49 array_push($this->values, $a_value['imagename'][$index]);
50 }
51 }
52 }
53 }
54
60 function setSuffixes($a_suffixes)
61 {
62 $this->suffixes = $a_suffixes;
63 }
64
70 function getSuffixes()
71 {
72 return $this->suffixes;
73 }
74
80 function setValues($a_values)
81 {
82 $this->values = $a_values;
83 }
84
90 function getValues()
91 {
92 return $this->values;
93 }
94
100 function setQuestionObject($a_value)
101 {
102 $this->qstObject =& $a_value;
103 }
104
111 {
112 return $this->qstObject;
113 }
114
120 function setAllowMove($a_allow_move)
121 {
122 $this->allowMove = $a_allow_move;
123 }
124
130 function getAllowMove()
131 {
132 return $this->allowMove;
133 }
134
140 function checkInput()
141 {
142 global $lng;
143
144 if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
145 if (is_array($_FILES[$this->getPostVar()]['error']['image']))
146 {
147 foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error)
148 {
149 // error handling
150 if ($error > 0)
151 {
152 switch ($error)
153 {
154 case UPLOAD_ERR_INI_SIZE:
155 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
156 return false;
157 break;
158
159 case UPLOAD_ERR_FORM_SIZE:
160 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
161 return false;
162 break;
163
164 case UPLOAD_ERR_PARTIAL:
165 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
166 return false;
167 break;
168
169 case UPLOAD_ERR_NO_FILE:
170 if ($this->getRequired())
171 {
172 if (!strlen($_POST[$this->getPostVar()]['imagename'][$index]))
173 {
174 $this->setAlert($lng->txt("form_msg_file_no_upload"));
175 return false;
176 }
177 }
178 break;
179
180 case UPLOAD_ERR_NO_TMP_DIR:
181 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
182 return false;
183 break;
184
185 case UPLOAD_ERR_CANT_WRITE:
186 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
187 return false;
188 break;
189
190 case UPLOAD_ERR_EXTENSION:
191 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
192 return false;
193 break;
194 }
195 }
196 }
197 }
198 else
199 {
200 if ($this->getRequired())
201 {
202 $this->setAlert($lng->txt("form_msg_file_no_upload"));
203 return false;
204 }
205 }
206
207 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image']))
208 {
209 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname)
210 {
211 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
212 $filename_arr = pathinfo($filename);
213 $suffix = $filename_arr["extension"];
214 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
215 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
216 // check suffixes
217 if (strlen($tmpname) && is_array($this->getSuffixes()))
218 {
219 if (!in_array(strtolower($suffix), $this->getSuffixes()))
220 {
221 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
222 return false;
223 }
224 }
225 }
226 }
227
228 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image']))
229 {
230 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname)
231 {
232 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
233 $filename_arr = pathinfo($filename);
234 $suffix = $filename_arr["extension"];
235 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
236 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
237 // virus handling
238 if (strlen($tmpname))
239 {
240 $vir = ilUtil::virusHandling($tmpname, $filename);
241 if ($vir[0] == false)
242 {
243 $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
244 return false;
245 }
246 }
247 }
248 }
249
250 return $this->checkSubItemsInput();
251 }
252
258 function insert(&$a_tpl)
259 {
260 global $lng;
261
262 $tpl = new ilTemplate("tpl.prop_imagewizardinput.html", true, true, "Modules/TestQuestionPool");
263 $i = 0;
264 foreach ($this->values as $value)
265 {
266 if (strlen($value))
267 {
268 $imagename = $this->qstObject->getImagePathWeb() . $value;
269 if ($this->qstObject->getThumbSize())
270 {
271 if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value))
272 {
273 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value;
274 }
275 }
276 $tpl->setCurrentBlock('image');
277 $tpl->setVariable('SRC_IMAGE', $imagename);
278 $tpl->setVariable('IMAGE_NAME', $value);
279 $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value));
280 $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
281 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
282 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
283 $tpl->parseCurrentBlock();
284 }
285 $tpl->setCurrentBlock('addimage');
286 $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
287 $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
288 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
289 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
290 $tpl->parseCurrentBlock();
291
292 if ($this->getAllowMove())
293 {
294 $tpl->setCurrentBlock("move");
295 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
296 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
297 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
298 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
299 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
300 $tpl->parseCurrentBlock();
301 }
302 $tpl->setCurrentBlock("row");
303 $tpl->setVariable("POST_VAR", $this->getPostVar());
304 $tpl->setVariable("ROW_NUMBER", $i);
305 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
306 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
307 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
308 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
309 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
310 $tpl->parseCurrentBlock();
311 $i++;
312 }
313
314 if (is_array($this->getSuffixes()))
315 {
316 $suff_str = $delim = "";
317 foreach($this->getSuffixes() as $suffix)
318 {
319 $suff_str.= $delim.".".$suffix;
320 $delim = ", ";
321 }
322 $tpl->setCurrentBlock('allowed_image_suffixes');
323 $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes")." ".$suff_str);
324 $tpl->parseCurrentBlock();
325 }
326 /*
327 $tpl->setCurrentBlock("image_heading");
328 $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
329 $tpl->parseCurrentBlock();
330 */
331
332 $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
333 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
334 $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
335 $tpl->setVariable("TEXT_NO", $lng->txt('no'));
336 $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
337 $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
338 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
339 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
340
341 $a_tpl->setCurrentBlock("prop_generic");
342 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
343 $a_tpl->parseCurrentBlock();
344
345 global $tpl;
346 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
347 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/imagewizard.js");
348 }
349}
global $tpl
Definition: ilias.php:8
$filename
Definition: buildRTE.php:89
static getAllowedImageFileExtensions()
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a single choice wizard property in a property form.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
checkInput()
Check input, strip slashes etc.
insert(&$a_tpl)
Insert property html.
__construct($a_title="", $a_postvar="")
Constructor.
setAllowMove($a_allow_move)
Set allow move.
getSuffixes()
Get Accepted Suffixes.
setQuestionObject($a_value)
Set question object.
getQuestionObject()
Get question object.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
setSize($a_size)
Set Size.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
static getFileSizeInfo()
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$_POST['username']
Definition: cron.php:12
global $lng
Definition: privfeed.php:40