ILIAS  release_7 Revision v7.30-3-g800a261c036
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{
16 protected const ALLOWED_PAGE_HTML_TAGS = '<em>, <strong>';
17
18 protected $values = [];
19 protected $allowMove = false;
20 protected $singleline = true;
21 protected $qstObject = null;
22 protected $suffixes = [];
23 protected $showPoints = true;
24 protected $hideImages = false;
25
32 public function __construct($a_title = '', $a_postvar = '')
33 {
34 parent::__construct($a_title, $a_postvar);
35 $this->setSuffixes(['jpg', 'jpeg', 'png', 'gif']);
36 $this->setSize('25');
37 $this->validationRegexp = '';
38 }
39
45 public function setValue($a_value)
46 {
47 $this->values = [];
48 if (is_array($a_value)) {
49 if (is_array($a_value['answer'])) {
50 foreach ($a_value['answer'] as $index => $value) {
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], $a_value['answer_id'][$index]);
53 array_push($this->values, $answer);
54 }
55 }
56 }
57 }
58
64 public function setSuffixes($a_suffixes)
65 {
66 $this->suffixes = $a_suffixes;
67 }
68
74 public function setHideImages($a_hide)
75 {
76 $this->hideImages = $a_hide;
77 }
78
84 public 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 public function setValues($a_values)
105 {
106 $this->values = $a_values;
107 }
108
114 public function getValues()
115 {
116 return $this->values;
117 }
118
124 public function setSingleline($a_value)
125 {
126 $this->singleline = $a_value;
127 }
128
134 public function getSingleline()
135 {
136 return $this->singleline;
137 }
138
144 public function setQuestionObject($a_value)
145 {
146 $this->qstObject = &$a_value;
147 }
148
154 public function getQuestionObject()
155 {
156 return $this->qstObject;
157 }
158
164 public function setAllowMove($a_allow_move)
165 {
166 $this->allowMove = $a_allow_move;
167 }
168
174 public function getAllowMove()
175 {
176 return $this->allowMove;
177 }
178
184 public function checkInput()
185 {
186 global $DIC;
187 $lng = $DIC['lng'];
188
189 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
190
191 if (is_array($_POST[$this->getPostVar()]) && $_POST["types"] == 1) {
193 $_POST[$this->getPostVar()],
194 false,
196 );
197 } elseif (is_array($_POST[$this->getPostVar()]) && $_POST["types"] == 0) {
199 $_POST[$this->getPostVar()],
200 true,
202 );
203 }
204
205 $foundvalues = $_POST[$this->getPostVar()];
206 if (is_array($foundvalues)) {
207 // check answers
208 if (is_array($foundvalues['answer'])) {
209 foreach ($foundvalues['answer'] as $aidx => $answervalue) {
210 if (((strlen($answervalue)) == 0) && (!isset($foundvalues['imagename'][$aidx]) || strlen($foundvalues['imagename'][$aidx]) == 0)) {
211 $this->setAlert($lng->txt("msg_input_is_required"));
212 return false;
213 }
214 }
215 }
216 // check points
217 $max = 0;
218 if (is_array($foundvalues['points'])) {
219 foreach ($foundvalues['points'] as $points) {
220 if ($points > $max) {
221 $max = $points;
222 }
223 if (((strlen($points)) == 0) || (!is_numeric($points))) {
224 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
225 return false;
226 }
227 }
228 }
229 if ($max == 0) {
230 $this->setAlert($lng->txt("enter_enough_positive_points"));
231 return false;
232 }
233
234 if (is_array($_FILES) && count($_FILES) && $this->getSingleline() && (!$this->hideImages)) {
235 if (is_array($_FILES[$this->getPostVar()]['error']['image'])) {
236 foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error) {
237 // error handling
238 if ($error > 0) {
239 switch ($error) {
240 case UPLOAD_ERR_INI_SIZE:
241 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
242 return false;
243 break;
244
245 case UPLOAD_ERR_FORM_SIZE:
246 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
247 return false;
248 break;
249
250 case UPLOAD_ERR_PARTIAL:
251 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
252 return false;
253 break;
254
255 case UPLOAD_ERR_NO_FILE:
256 if ($this->getRequired()) {
257 if ((!strlen($foundvalues['imagename'][$index])) && (!strlen($foundvalues['answer'][$index]))) {
258 $this->setAlert($lng->txt("form_msg_file_no_upload"));
259 return false;
260 }
261 }
262 break;
263
264 case UPLOAD_ERR_NO_TMP_DIR:
265 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
266 return false;
267 break;
268
269 case UPLOAD_ERR_CANT_WRITE:
270 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
271 return false;
272 break;
273
274 case UPLOAD_ERR_EXTENSION:
275 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
276 return false;
277 break;
278 }
279 }
280 }
281 } else {
282 if ($this->getRequired()) {
283 $this->setAlert($lng->txt("form_msg_file_no_upload"));
284 return false;
285 }
286 }
287
288 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
289 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
290 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
291 $filename_arr = pathinfo($filename);
292 $suffix = $filename_arr["extension"];
293 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
294 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
295 // check suffixes
296 if (strlen($tmpname) && is_array($this->getSuffixes())) {
297 if (!in_array(strtolower($suffix), $this->getSuffixes())) {
298 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
299 return false;
300 }
301 }
302 }
303 }
304
305 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
306 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
307 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
308 $filename_arr = pathinfo($filename);
309 $suffix = $filename_arr["extension"];
310 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
311 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
312 // virus handling
313 if (strlen($tmpname)) {
314 $vir = ilUtil::virusHandling($tmpname, $filename);
315 if ($vir[0] == false) {
316 $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
317 return false;
318 }
319 }
320 }
321 }
322 }
323 } else {
324 $this->setAlert($lng->txt("msg_input_is_required"));
325 return false;
326 }
327
328 return $this->checkSubItemsInput();
329 }
330
334 public function insert($a_tpl)
335 {
336 global $DIC;
337 $lng = $DIC['lng'];
338
339 $tpl = new ilTemplate("tpl.prop_singlechoicewizardinput.html", true, true, "Modules/TestQuestionPool");
340 $i = 0;
341 foreach ($this->values as $value) {
342 if ($this->getSingleline()) {
343 if (!$this->hideImages) {
344 if (strlen($value->getImage())) {
345 $imagename = $this->qstObject->getImagePathWeb() . $value->getImage();
346 if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
347 if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->getImage())) {
348 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->getImage();
349 }
350 }
351 $tpl->setCurrentBlock('image');
352 $tpl->setVariable('SRC_IMAGE', $imagename);
353 $tpl->setVariable('IMAGE_NAME', $value->getImage());
354 $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value->getAnswertext()));
355 $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
356 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
357 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
358 $tpl->parseCurrentBlock();
359 }
360 $tpl->setCurrentBlock('addimage');
361 $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
362 $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
363 $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
364 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
365 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
366 $tpl->parseCurrentBlock();
367 }
368
369 if (is_object($value)) {
370 $tpl->setCurrentBlock("prop_text_propval");
371 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
372 $tpl->parseCurrentBlock();
373 if ($this->getShowPoints()) {
374 $tpl->setCurrentBlock("prop_points_propval");
375 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
376 $tpl->parseCurrentBlock();
377 }
378 $tpl->setCurrentBlock("prop_answer_id_propval");
379 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getId()));
380 $tpl->parseCurrentBlock();
381 }
382 $tpl->setCurrentBlock('singleline');
383 $tpl->setVariable("SIZE", $this->getSize());
384 $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
385 $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
386 $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
387 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
388 if ($this->getDisabled()) {
389 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
390 }
391 $tpl->parseCurrentBlock();
392 } elseif (!$this->getSingleline()) {
393 if (is_object($value)) {
394 if ($this->getShowPoints()) {
395 $tpl->setCurrentBlock("prop_points_propval");
396 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
397 $tpl->parseCurrentBlock();
398 }
399 $tpl->setCurrentBlock("prop_answer_id_propval");
400 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getId()));
401 $tpl->parseCurrentBlock();
402 }
403 $tpl->setCurrentBlock('multiline');
404 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
405 $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
406 $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
407 $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
408 if ($this->getDisabled()) {
409 $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
410 }
411 $tpl->parseCurrentBlock();
412 }
413 if ($this->getAllowMove()) {
414 $tpl->setCurrentBlock("move");
415 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
416 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
417 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
418 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
419 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
420 $tpl->parseCurrentBlock();
421 }
422 if ($this->getShowPoints()) {
423 $tpl->setCurrentBlock("points");
424 $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
425 $tpl->setVariable("POINTS_POST_VAR", $this->getPostVar());
426 $tpl->setVariable("POINTS_ROW_NUMBER", $i);
427 $tpl->parseCurrentBlock();
428 }
429 $tpl->setCurrentBlock("row");
430 $tpl->setVariable("POST_VAR", $this->getPostVar());
431 $tpl->setVariable("ROW_NUMBER", $i);
432 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
433 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
434 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
435 if ($this->getDisabled()) {
436 $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
437 }
438 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
439 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
440 $tpl->parseCurrentBlock();
441 $i++;
442 }
443
444 if ($this->getSingleline()) {
445 if (!$this->hideImages) {
446 if (is_array($this->getSuffixes())) {
447 $suff_str = $delim = "";
448 foreach ($this->getSuffixes() as $suffix) {
449 $suff_str .= $delim . "." . $suffix;
450 $delim = ", ";
451 }
452 $tpl->setCurrentBlock('allowed_image_suffixes');
453 $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes") . " " . $suff_str);
454 $tpl->parseCurrentBlock();
455 }
456 $tpl->setCurrentBlock("image_heading");
457 $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
458 $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
459 $tpl->parseCurrentBlock();
460 }
461 }
462
463 if ($this->getShowPoints()) {
464 $tpl->setCurrentBlock("points_heading");
465 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
466 $tpl->parseCurrentBlock();
467 }
468
469 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
470 $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
471 $tpl->setVariable("TEXT_NO", $lng->txt('no'));
472 $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
473 $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
474 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
475 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
476
477 $a_tpl->setCurrentBlock("prop_generic");
478 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
479 $a_tpl->parseCurrentBlock();
480
481 global $DIC;
482 $tpl = $DIC['tpl'];
483 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
484 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/singlechoicewizard.js");
485 }
486}
$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.
__construct($a_title='', $a_postvar='')
Constructor.
setQuestionObject($a_value)
Set question object.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
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 $DIC
Definition: goto.php:24
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$index
Definition: metadata.php:128
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc