ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 public 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 public function setValue($a_value)
43 {
44 $this->values = array();
45 if (is_array($a_value)) {
46 if (is_array($a_value['answer'])) {
47 foreach ($a_value['answer'] as $index => $value) {
48 include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
49 $answer = new ASS_AnswerBinaryStateImage($value, $a_value['points'][$index], $index, 1, $a_value['imagename'][$index]);
50 array_push($this->values, $answer);
51 }
52 }
53 }
54 }
55
61 public function setSuffixes($a_suffixes)
62 {
63 $this->suffixes = $a_suffixes;
64 }
65
71 public function setHideImages($a_hide)
72 {
73 $this->hideImages = $a_hide;
74 }
75
81 public function getSuffixes()
82 {
83 return $this->suffixes;
84 }
85
86 public function setShowPoints($a_value)
87 {
88 $this->showPoints = $a_value;
89 }
90
91 public function getShowPoints()
92 {
93 return $this->showPoints;
94 }
95
101 public function setValues($a_values)
102 {
103 $this->values = $a_values;
104 }
105
111 public function getValues()
112 {
113 return $this->values;
114 }
115
121 public function setSingleline($a_value)
122 {
123 $this->singleline = $a_value;
124 }
125
131 public function getSingleline()
132 {
133 return $this->singleline;
134 }
135
141 public function setQuestionObject($a_value)
142 {
143 $this->qstObject = &$a_value;
144 }
145
151 public function getQuestionObject()
152 {
153 return $this->qstObject;
154 }
155
161 public function setAllowMove($a_allow_move)
162 {
163 $this->allowMove = $a_allow_move;
164 }
165
171 public function getAllowMove()
172 {
173 return $this->allowMove;
174 }
175
181 public function checkInput()
182 {
183 global $DIC;
184 $lng = $DIC['lng'];
185
186 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
187
188 if (is_array($_POST[$this->getPostVar()])) {
190 }
191 $foundvalues = $_POST[$this->getPostVar()];
192 if (is_array($foundvalues)) {
193 // check answers
194 if (is_array($foundvalues['answer'])) {
195 foreach ($foundvalues['answer'] as $aidx => $answervalue) {
196 if (((strlen($answervalue)) == 0) && (strlen($foundvalues['imagename'][$aidx]) == 0)) {
197 $this->setAlert($lng->txt("msg_input_is_required"));
198 return false;
199 }
200 }
201 }
202 // check points
203 $max = 0;
204 if (is_array($foundvalues['points'])) {
205 foreach ($foundvalues['points'] as $points) {
206 if ($points > $max) {
207 $max = $points;
208 }
209 if (((strlen($points)) == 0) || (!is_numeric($points))) {
210 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
211 return false;
212 }
213 }
214 }
215 if ($max == 0) {
216 $this->setAlert($lng->txt("enter_enough_positive_points"));
217 return false;
218 }
219
220 if (is_array($_FILES) && count($_FILES) && $this->getSingleline() && (!$this->hideImages)) {
221 if (is_array($_FILES[$this->getPostVar()]['error']['image'])) {
222 foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error) {
223 // error handling
224 if ($error > 0) {
225 switch ($error) {
226 case UPLOAD_ERR_INI_SIZE:
227 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
228 return false;
229 break;
230
231 case UPLOAD_ERR_FORM_SIZE:
232 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
233 return false;
234 break;
235
236 case UPLOAD_ERR_PARTIAL:
237 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
238 return false;
239 break;
240
241 case UPLOAD_ERR_NO_FILE:
242 if ($this->getRequired()) {
243 if ((!strlen($foundvalues['imagename'][$index])) && (!strlen($foundvalues['answer'][$index]))) {
244 $this->setAlert($lng->txt("form_msg_file_no_upload"));
245 return false;
246 }
247 }
248 break;
249
250 case UPLOAD_ERR_NO_TMP_DIR:
251 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
252 return false;
253 break;
254
255 case UPLOAD_ERR_CANT_WRITE:
256 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
257 return false;
258 break;
259
260 case UPLOAD_ERR_EXTENSION:
261 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
262 return false;
263 break;
264 }
265 }
266 }
267 } else {
268 if ($this->getRequired()) {
269 $this->setAlert($lng->txt("form_msg_file_no_upload"));
270 return false;
271 }
272 }
273
274 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
275 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
276 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
277 $filename_arr = pathinfo($filename);
278 $suffix = $filename_arr["extension"];
279 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
280 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
281 // check suffixes
282 if (strlen($tmpname) && is_array($this->getSuffixes())) {
283 if (!in_array(strtolower($suffix), $this->getSuffixes())) {
284 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
285 return false;
286 }
287 }
288 }
289 }
290
291 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
292 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
293 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
294 $filename_arr = pathinfo($filename);
295 $suffix = $filename_arr["extension"];
296 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
297 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
298 // virus handling
299 if (strlen($tmpname)) {
300 $vir = ilUtil::virusHandling($tmpname, $filename);
301 if ($vir[0] == false) {
302 $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
303 return false;
304 }
305 }
306 }
307 }
308 }
309 } else {
310 $this->setAlert($lng->txt("msg_input_is_required"));
311 return false;
312 }
313
314 return $this->checkSubItemsInput();
315 }
316
320 public function insert($a_tpl)
321 {
322 global $DIC;
323 $lng = $DIC['lng'];
324
325 $tpl = new ilTemplate("tpl.prop_singlechoicewizardinput.html", true, true, "Modules/TestQuestionPool");
326 $i = 0;
327 foreach ($this->values as $value) {
328 if ($this->getSingleline()) {
329 if (!$this->hideImages) {
330 if (strlen($value->getImage())) {
331 $imagename = $this->qstObject->getImagePathWeb() . $value->getImage();
332 if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
333 if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->getImage())) {
334 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->getImage();
335 }
336 }
337 $tpl->setCurrentBlock('image');
338 $tpl->setVariable('SRC_IMAGE', $imagename);
339 $tpl->setVariable('IMAGE_NAME', $value->getImage());
340 $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value->getAnswertext()));
341 $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
342 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
343 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
344 $tpl->parseCurrentBlock();
345 }
346 $tpl->setCurrentBlock('addimage');
347 $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
348 $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
349 $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
350 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
351 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
352 $tpl->parseCurrentBlock();
353 }
354
355 if (is_object($value)) {
356 $tpl->setCurrentBlock("prop_text_propval");
357 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
358 $tpl->parseCurrentBlock();
359 if ($this->getShowPoints()) {
360 $tpl->setCurrentBlock("prop_points_propval");
361 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
362 $tpl->parseCurrentBlock();
363 }
364 }
365 $tpl->setCurrentBlock('singleline');
366 $tpl->setVariable("SIZE", $this->getSize());
367 $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
368 $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
369 $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
370 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
371 if ($this->getDisabled()) {
372 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
373 }
374 $tpl->parseCurrentBlock();
375 } elseif (!$this->getSingleline()) {
376 if (is_object($value)) {
377 if ($this->getShowPoints()) {
378 $tpl->setCurrentBlock("prop_points_propval");
379 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
380 $tpl->parseCurrentBlock();
381 }
382 }
383 $tpl->setCurrentBlock('multiline');
384 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
385 $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
386 $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
387 $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
388 if ($this->getDisabled()) {
389 $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
390 }
391 $tpl->parseCurrentBlock();
392 }
393 if ($this->getAllowMove()) {
394 $tpl->setCurrentBlock("move");
395 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
396 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
397 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
398 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
399 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
400 $tpl->parseCurrentBlock();
401 }
402 if ($this->getShowPoints()) {
403 $tpl->setCurrentBlock("points");
404 $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
405 $tpl->setVariable("POINTS_POST_VAR", $this->getPostVar());
406 $tpl->setVariable("POINTS_ROW_NUMBER", $i);
407 $tpl->parseCurrentBlock();
408 }
409 $tpl->setCurrentBlock("row");
410 $tpl->setVariable("POST_VAR", $this->getPostVar());
411 $tpl->setVariable("ROW_NUMBER", $i);
412 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
413 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
414 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
415 if ($this->getDisabled()) {
416 $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
417 }
418 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
419 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
420 $tpl->parseCurrentBlock();
421 $i++;
422 }
423
424 if ($this->getSingleline()) {
425 if (!$this->hideImages) {
426 if (is_array($this->getSuffixes())) {
427 $suff_str = $delim = "";
428 foreach ($this->getSuffixes() as $suffix) {
429 $suff_str .= $delim . "." . $suffix;
430 $delim = ", ";
431 }
432 $tpl->setCurrentBlock('allowed_image_suffixes');
433 $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes") . " " . $suff_str);
434 $tpl->parseCurrentBlock();
435 }
436 $tpl->setCurrentBlock("image_heading");
437 $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
438 $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
439 $tpl->parseCurrentBlock();
440 }
441 }
442
443 if ($this->getShowPoints()) {
444 $tpl->setCurrentBlock("points_heading");
445 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
446 $tpl->parseCurrentBlock();
447 }
448
449 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
450 $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
451 $tpl->setVariable("TEXT_NO", $lng->txt('no'));
452 $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
453 $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
454 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
455 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
456
457 $a_tpl->setCurrentBlock("prop_generic");
458 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
459 $a_tpl->parseCurrentBlock();
460
461 global $DIC;
462 $tpl = $DIC['tpl'];
463 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
464 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/singlechoicewizard.js");
465 }
466}
$tpl
Definition: ilias.php:10
$filename
Definition: buildRTE.php:89
$_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
$i
Definition: disco.tpl.php:19
$index
Definition: metadata.php:60
global $DIC
Definition: saml.php:7