ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilMultipleChoiceWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
27{
28 private string $pending;
29
30 public function setValue($a_value): void
31 {
32 $this->values = [];
33 if (is_array($a_value) && isset($a_value['answer']) && is_array($a_value['answer'])) {
34 foreach ($a_value['answer'] as $index => $value) {
35 $answer = new ASS_AnswerMultipleResponseImage($value, (float) ($a_value['points'][$index] ?? 0), $index);
36 $answer->setPointsChecked((float) ($a_value['points'][$index] ?? 0));
37 $answer->setPointsUnchecked((float) ($a_value['points_unchecked'][$index] ?? 0));
38 if (isset($a_value['imagename'][$index])) {
39 $answer->setImage($a_value['imagename'][$index]);
40 }
41 $this->values[] = $answer;
42 }
43 }
44 }
45
50 public function checkInput(): bool
51 {
52 global $DIC;
53 $lng = $DIC['lng'];
54
55 $post_var = $this->getPostVar();
56 if (!$this->post_wrapper->has($post_var)) {
57 return false;
58 }
59
60 $values = $this->post_wrapper->retrieve($post_var, $this->refinery->custom()->transformation(fn ($v) => $v));
61
62 $values = ilArrayUtil::stripSlashesRecursive( //TODO: move into transform
63 $values,
64 false,
66 );
67
68 $foundvalues = $values;
69
70 if (is_array($foundvalues)) {
71 // check answers
72 if (is_array($foundvalues['answer'])) {
73 foreach ($foundvalues['answer'] as $aidx => $answervalue) {
74 if (((strlen($answervalue)) == 0) && (!isset($foundvalues['imagename']) || !isset($foundvalues['imagename'][$aidx]) || strlen($foundvalues['imagename'][$aidx]) == 0)) {
75 $this->setAlert($lng->txt("msg_input_is_required"));
76 return false;
77 }
78
79 if (mb_strlen($answervalue) > $this->getMaxLength()) {
80 $this->setAlert($lng->txt("msg_input_char_limit_max"));
81 return false;
82 }
83 }
84 }
85 // check points
86 $max = 0;
87 if (is_array($foundvalues['points'])) {
88 foreach ($foundvalues['points'] as $points) {
89 $points = str_replace(',', '.', $points);
90 if ($points > $max) {
91 $max = $points;
92 }
93 if (((strlen($points)) == 0) || (!is_numeric($points))) {
94 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
95 return false;
96 }
97 }
98 foreach ($foundvalues['points_unchecked'] as $points) {
99 $points = str_replace(',', '.', $points);
100 if (((strlen($points)) == 0) || (!is_numeric($points))) {
101 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
102 return false;
103 }
104 }
105 }
106 if ($max == 0) {
107 $this->setAlert($lng->txt("enter_enough_positive_points_checked"));
108 return false;
109 }
110
111 if (is_array($_FILES) && count($_FILES) && $this->getSingleline()) {
112 if (!$this->hideImages) {
113 if (is_array($_FILES[$this->getPostVar()]['error']['image'])) {
114 foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error) {
115 // error handling
116 if ($error > 0) {
117 switch ($error) {
118 case UPLOAD_ERR_FORM_SIZE:
119 case UPLOAD_ERR_INI_SIZE:
120 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
121 return false;
122 break;
123
124 case UPLOAD_ERR_PARTIAL:
125 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
126 return false;
127 break;
128
129 case UPLOAD_ERR_NO_FILE:
130 if ($this->getRequired()) {
131 if (isset($a_value['imagename']) && (!strlen($foundvalues['imagename'][$index])) && (!strlen($foundvalues['answer'][$index]))) {
132 $this->setAlert($lng->txt("form_msg_file_no_upload"));
133 return false;
134 }
135 }
136 break;
137
138 case UPLOAD_ERR_NO_TMP_DIR:
139 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
140 return false;
141 break;
142
143 case UPLOAD_ERR_CANT_WRITE:
144 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
145 return false;
146 break;
147
148 case UPLOAD_ERR_EXTENSION:
149 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
150 return false;
151 break;
152 }
153 }
154 }
155 } else {
156 if ($this->getRequired()) {
157 $this->setAlert($lng->txt("form_msg_file_no_upload"));
158 return false;
159 }
160 }
161
162 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
163 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
164 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
165 $filename_arr = pathinfo($filename);
166 if (isset($filename_arr["extension"])) {
167 $suffix = $filename_arr["extension"];
168 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
169 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
170 // check suffixes
171 if (strlen($tmpname) && is_array($this->getSuffixes())) {
172 if (!in_array(strtolower($suffix), $this->getSuffixes())) {
173 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
174 return false;
175 }
176 }
177 }
178 }
179 }
180
181 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
182 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
183 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
184 $filename_arr = pathinfo($filename);
185 if (isset($filename_arr["extension"])) {
186 $suffix = $filename_arr["extension"];
187 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
188 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
189 // virus handling
190 if (strlen($tmpname)) {
192 if ($vir[0] == false) {
193 $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
194 return false;
195 }
196 }
197 }
198 }
199 }
200 }
201 }
202 } else {
203 $this->setAlert($lng->txt("msg_input_is_required"));
204 return false;
205 }
206
207 return $this->checkSubItemsInput();
208 }
209
214 public function insert(ilTemplate $a_tpl): void
215 {
216 global $DIC;
217 $lng = $DIC['lng'];
218
219 $tpl = new ilTemplate("tpl.prop_multiplechoicewizardinput.html", true, true, "Modules/TestQuestionPool");
220 $i = 0;
221 foreach ($this->values as $value) {
222 if ($this->getSingleline()) {
223 if (!$this->hideImages) {
224 if (strlen($value->getImage())) {
225 $imagename = $this->qstObject->getImagePathWeb() . $value->getImage();
226 if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
227 if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->getImage())) {
228 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->getImage();
229 }
230 }
231 $tpl->setCurrentBlock('image');
232 $tpl->setVariable('SRC_IMAGE', $imagename);
233 $tpl->setVariable('IMAGE_NAME', $value->getImage());
234 $tpl->setVariable(
235 'ALT_IMAGE',
237 );
238 $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
239 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
240 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
241 $tpl->parseCurrentBlock();
242 }
243 $tpl->setCurrentBlock('addimage');
244 $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
245 $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
246 $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
247 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
248 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
249 $tpl->parseCurrentBlock();
250 }
251
252 if (is_object($value)) {
253 $tpl->setCurrentBlock("prop_text_propval");
254 $tpl->setVariable(
255 "PROPERTY_VALUE",
257 );
258 $tpl->parseCurrentBlock();
259 $tpl->setCurrentBlock("prop_points_propval");
260 $tpl->setVariable(
261 "PROPERTY_VALUE",
263 );
264 $tpl->parseCurrentBlock();
265 $tpl->setCurrentBlock("prop_points_unchecked_propval");
266 $tpl->setVariable(
267 "PROPERTY_VALUE",
269 );
270 $tpl->parseCurrentBlock();
271 $tpl->setCurrentBlock("prop_answer_id_propval");
272 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value->getId()));
273 $tpl->parseCurrentBlock();
274 }
275 $tpl->setCurrentBlock('singleline');
276 $tpl->setVariable("SIZE", $this->getSize());
277 $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
278 $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
279 $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
280 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
281 if ($this->getDisabled()) {
282 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
283 }
284 $tpl->parseCurrentBlock();
285 } elseif (!$this->getSingleline()) {
286 if (is_object($value)) {
287 $tpl->setCurrentBlock("prop_points_propval");
288 $tpl->setVariable(
289 "PROPERTY_VALUE",
291 );
292 $tpl->parseCurrentBlock();
293 $tpl->setCurrentBlock("prop_points_unchecked_propval");
294 $tpl->setVariable(
295 "PROPERTY_VALUE",
297 );
298 $tpl->parseCurrentBlock();
299 $tpl->setCurrentBlock("prop_answer_id_propval");
300 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value->getId()));
301 $tpl->parseCurrentBlock();
302 }
303 $tpl->setCurrentBlock('multiline');
304 $tpl->setVariable(
305 "PROPERTY_VALUE",
307 );
308 $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
309 $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
310 $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
311 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
312 if ($this->getDisabled()) {
313 $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
314 }
315 $tpl->parseCurrentBlock();
316 }
317 if ($this->getAllowMove()) {
318 $tpl->setCurrentBlock("move");
319 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
320 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
321 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
322 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
323 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
324 $tpl->parseCurrentBlock();
325 }
326 $tpl->setCurrentBlock("row");
327 $tpl->setVariable("POST_VAR", $this->getPostVar());
328 $tpl->setVariable("ROW_NUMBER", $i);
329 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
330 $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
331 $tpl->setVariable("POINTS_UNCHECKED_ID", $this->getPostVar() . "[points_unchecked][$i]");
332 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
333 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
334 if ($this->getDisabled()) {
335 $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
336 }
337 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
338 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
339 $tpl->parseCurrentBlock();
340 $i++;
341 }
342
343 if ($this->getSingleline()) {
344 if (!$this->hideImages) {
345 if (is_array($this->getSuffixes())) {
346 $suff_str = $delim = "";
347 foreach ($this->getSuffixes() as $suffix) {
348 $suff_str .= $delim . "." . $suffix;
349 $delim = ", ";
350 }
351 $tpl->setCurrentBlock('allowed_image_suffixes');
352 $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes") . " " . $suff_str);
353 $tpl->parseCurrentBlock();
354 }
355
356 $tpl->setCurrentBlock("image_heading");
357 $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
358 $tpl->setVariable("TXT_MAX_SIZE", ilFileUtils::getFileSizeInfo());
359 $tpl->parseCurrentBlock();
360 }
361 }
362
363 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
364 $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
365 $tpl->setVariable("TEXT_NO", $lng->txt('no'));
366 $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
367 $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
368 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
369 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
370 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
371 $tpl->setVariable("POINTS_CHECKED_TEXT", $lng->txt('checkbox_checked'));
372 $tpl->setVariable("POINTS_UNCHECKED_TEXT", $lng->txt('checkbox_unchecked'));
373
374 $a_tpl->setCurrentBlock("prop_generic");
375 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
376 $a_tpl->parseCurrentBlock();
377
378 global $DIC;
379 $tpl = $DIC['tpl'];
380 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
381 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/multiplechoicewizard.js");
382 }
383
384 public function setPending(string $a_val): void
385 {
386 $this->pending = $a_val;
387 }
388
389 public function getPending(): string
390 {
391 return $this->pending;
392 }
393}
$filename
Definition: buildRTE.php:78
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
static getFileSizeInfo()
static get(string $a_glyph, string $a_text="")
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static prepareFormOutput($a_str, bool $a_strip=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
insert(ilTemplate $a_tpl)
Insert property html.
static _getUsedHTMLTagsAsString(string $a_module="")
Returns a string of all allowed HTML tags for text editing.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$index
Definition: metadata.php:145
$i
Definition: metadata.php:41