ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSingleChoiceWizardInputGUI.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/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
5
14{
15 protected $values = array();
16 protected $allowMove = false;
17 protected $singleline = true;
18 protected $qstObject = null;
19 protected $suffixes = array();
20 protected $showPoints = true;
21 protected $hideImages = false;
22
29 function __construct($a_title = "", $a_postvar = "")
30 {
31 parent::__construct($a_title, $a_postvar);
32 $this->setSuffixes(array("jpg", "jpeg", "png", "gif"));
33 $this->setSize('25');
34 $this->validationRegexp = "";
35 }
36
42 function setValue($a_value)
43 {
44 $this->values = array();
45 if (is_array($a_value))
46 {
47 if (is_array($a_value['answer']))
48 {
49 foreach ($a_value['answer'] as $index => $value)
50 {
51 include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
52 $answer = new ASS_AnswerBinaryStateImage($value, $a_value['points'][$index], $index, 1, $a_value['imagename'][$index]);
53 array_push($this->values, $answer);
54 }
55 }
56 }
57 }
58
64 function setSuffixes($a_suffixes)
65 {
66 $this->suffixes = $a_suffixes;
67 }
68
74 function setHideImages($a_hide)
75 {
76 $this->hideImages = $a_hide;
77 }
78
84 function getSuffixes()
85 {
86 return $this->suffixes;
87 }
88
89 public function setShowPoints($a_value)
90 {
91 $this->showPoints = $a_value;
92 }
93
94 public function getShowPoints()
95 {
96 return $this->showPoints;
97 }
98
104 function setValues($a_values)
105 {
106 $this->values = $a_values;
107 }
108
114 function getValues()
115 {
116 return $this->values;
117 }
118
124 function setSingleline($a_value)
125 {
126 $this->singleline = $a_value;
127 }
128
134 function getSingleline()
135 {
136 return $this->singleline;
137 }
138
144 function setQuestionObject($a_value)
145 {
146 $this->qstObject =& $a_value;
147 }
148
155 {
156 return $this->qstObject;
157 }
158
164 function setAllowMove($a_allow_move)
165 {
166 $this->allowMove = $a_allow_move;
167 }
168
174 function getAllowMove()
175 {
176 return $this->allowMove;
177 }
178
184 function checkInput()
185 {
186 global $lng;
187
188 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
189
190 if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
191 $foundvalues = $_POST[$this->getPostVar()];
192 if (is_array($foundvalues))
193 {
194 // check answers
195 if (is_array($foundvalues['answer']))
196 {
197 foreach ($foundvalues['answer'] as $aidx => $answervalue)
198 {
199 if (((strlen($answervalue)) == 0) && (strlen($foundvalues['imagename'][$aidx]) == 0))
200 {
201 $this->setAlert($lng->txt("msg_input_is_required"));
202 return FALSE;
203 }
204 }
205 }
206 // check points
207 $max = 0;
208 if (is_array($foundvalues['points']))
209 {
210 foreach ($foundvalues['points'] as $points)
211 {
212 if ($points > $max) $max = $points;
213 if (((strlen($points)) == 0) || (!is_numeric($points)))
214 {
215 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
216 return FALSE;
217 }
218 }
219 }
220 if ($max == 0)
221 {
222 $this->setAlert($lng->txt("enter_enough_positive_points"));
223 return false;
224 }
225
226 if (is_array($_FILES) && count($_FILES) && $this->getSingleline() && (!$this->hideImages))
227 {
228 if (is_array($_FILES[$this->getPostVar()]['error']['image']))
229 {
230 foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error)
231 {
232 // error handling
233 if ($error > 0)
234 {
235 switch ($error)
236 {
237 case UPLOAD_ERR_INI_SIZE:
238 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
239 return false;
240 break;
241
242 case UPLOAD_ERR_FORM_SIZE:
243 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
244 return false;
245 break;
246
247 case UPLOAD_ERR_PARTIAL:
248 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
249 return false;
250 break;
251
252 case UPLOAD_ERR_NO_FILE:
253 if ($this->getRequired())
254 {
255 if ((!strlen($foundvalues['imagename'][$index])) && (!strlen($foundvalues['answer'][$index])))
256 {
257 $this->setAlert($lng->txt("form_msg_file_no_upload"));
258 return false;
259 }
260 }
261 break;
262
263 case UPLOAD_ERR_NO_TMP_DIR:
264 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
265 return false;
266 break;
267
268 case UPLOAD_ERR_CANT_WRITE:
269 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
270 return false;
271 break;
272
273 case UPLOAD_ERR_EXTENSION:
274 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
275 return false;
276 break;
277 }
278 }
279 }
280 }
281 else
282 {
283 if ($this->getRequired())
284 {
285 $this->setAlert($lng->txt("form_msg_file_no_upload"));
286 return false;
287 }
288 }
289
290 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image']))
291 {
292 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname)
293 {
294 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
295 $filename_arr = pathinfo($filename);
296 $suffix = $filename_arr["extension"];
297 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
298 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
299 // check suffixes
300 if (strlen($tmpname) && is_array($this->getSuffixes()))
301 {
302 if (!in_array(strtolower($suffix), $this->getSuffixes()))
303 {
304 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
305 return false;
306 }
307 }
308 }
309 }
310
311 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image']))
312 {
313 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname)
314 {
315 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
316 $filename_arr = pathinfo($filename);
317 $suffix = $filename_arr["extension"];
318 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
319 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
320 // virus handling
321 if (strlen($tmpname))
322 {
323 $vir = ilUtil::virusHandling($tmpname, $filename);
324 if ($vir[0] == false)
325 {
326 $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
327 return false;
328 }
329 }
330 }
331 }
332 }
333 }
334 else
335 {
336 $this->setAlert($lng->txt("msg_input_is_required"));
337 return FALSE;
338 }
339
340 return $this->checkSubItemsInput();
341 }
342
346 function insert($a_tpl)
347 {
348 global $lng;
349
350 $tpl = new ilTemplate("tpl.prop_singlechoicewizardinput.html", true, true, "Modules/TestQuestionPool");
351 $i = 0;
352 foreach ($this->values as $value)
353 {
354 if ($this->getSingleline())
355 {
356 if (!$this->hideImages)
357 {
358 if (strlen($value->getImage()))
359 {
360 $imagename = $this->qstObject->getImagePathWeb() . $value->getImage();
361 if (($this->getSingleline()) && ($this->qstObject->getThumbSize()))
362 {
363 if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->getImage()))
364 {
365 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->getImage();
366 }
367 }
368 $tpl->setCurrentBlock('image');
369 $tpl->setVariable('SRC_IMAGE', $imagename);
370 $tpl->setVariable('IMAGE_NAME', $value->getImage());
371 $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value->getAnswertext()));
372 $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
373 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
374 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
375 $tpl->parseCurrentBlock();
376 }
377 $tpl->setCurrentBlock('addimage');
378 $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
379 $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
380 $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
381 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
382 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
383 $tpl->parseCurrentBlock();
384 }
385
386 if (is_object($value))
387 {
388 $tpl->setCurrentBlock("prop_text_propval");
389 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
390 $tpl->parseCurrentBlock();
391 if( $this->getShowPoints() ) {
392 $tpl->setCurrentBlock("prop_points_propval");
393 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
394 $tpl->parseCurrentBlock();
395 }
396 }
397 $tpl->setCurrentBlock('singleline');
398 $tpl->setVariable("SIZE", $this->getSize());
399 $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
400 $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
401 $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
402 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
403 if ($this->getDisabled())
404 {
405 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
406 }
407 $tpl->parseCurrentBlock();
408 }
409 else if (!$this->getSingleline())
410 {
411 if (is_object($value))
412 {
413 if ($this->getShowPoints())
414 {
415 $tpl->setCurrentBlock("prop_points_propval");
416 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
417 $tpl->parseCurrentBlock();
418 }
419 }
420 $tpl->setCurrentBlock('multiline');
421 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
422 $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
423 $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
424 $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
425 if ($this->getDisabled())
426 {
427 $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
428 }
429 $tpl->parseCurrentBlock();
430 }
431 if ($this->getAllowMove())
432 {
433 $tpl->setCurrentBlock("move");
434 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
435 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
436 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
437 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
438 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
439 $tpl->parseCurrentBlock();
440 }
441 if ($this->getShowPoints())
442 {
443 $tpl->setCurrentBlock("points");
444 $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
445 $tpl->setVariable("POINTS_POST_VAR", $this->getPostVar());
446 $tpl->setVariable("POINTS_ROW_NUMBER", $i);
447 $tpl->parseCurrentBlock();
448 }
449 $tpl->setCurrentBlock("row");
450 $tpl->setVariable("POST_VAR", $this->getPostVar());
451 $tpl->setVariable("ROW_NUMBER", $i);
452 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
453 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
454 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
455 if ($this->getDisabled())
456 {
457 $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
458 }
459 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
460 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
461 $tpl->parseCurrentBlock();
462 $i++;
463 }
464
465 if ($this->getSingleline())
466 {
467 if (!$this->hideImages)
468 {
469 if (is_array($this->getSuffixes()))
470 {
471 $suff_str = $delim = "";
472 foreach($this->getSuffixes() as $suffix)
473 {
474 $suff_str.= $delim.".".$suffix;
475 $delim = ", ";
476 }
477 $tpl->setCurrentBlock('allowed_image_suffixes');
478 $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes")." ".$suff_str);
479 $tpl->parseCurrentBlock();
480 }
481 $tpl->setCurrentBlock("image_heading");
482 $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
483 $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
484 $tpl->parseCurrentBlock();
485 }
486 }
487
488 if ($this->getShowPoints())
489 {
490 $tpl->setCurrentBlock("points_heading");
491 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
492 $tpl->parseCurrentBlock();
493 }
494
495 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
496 $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
497 $tpl->setVariable("TEXT_NO", $lng->txt('no'));
498 $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
499 $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
500 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
501 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
502
503 $a_tpl->setCurrentBlock("prop_generic");
504 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
505 $a_tpl->parseCurrentBlock();
506
507 global $tpl;
508 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
509 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/singlechoicewizard.js");
510 }
511}
$error
Definition: Error.php:17
global $tpl
Definition: ilias.php:8
$_POST["username"]
Class for answers with a binary state indicator.
An exception for terminatinating execution or to throw for unit testing.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
static _getUsedHTMLTagsAsString($a_module="")
Returns a string of all allowed HTML tags for text editing.
This class represents a single choice wizard property in a property form.
checkInput()
Check input, strip slashes etc.
setQuestionObject($a_value)
Set question object.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
__construct($a_title="", $a_postvar="")
Constructor.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
getMaxLength()
Get Max Length.
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
global $lng
Definition: privfeed.php:17