ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMultipleChoiceWizardInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php";
5
14{
20 public function setValue($a_value)
21 {
22 $this->values = [];
23 if (is_array($a_value)) {
24 if (is_array($a_value['answer'])) {
25 foreach ($a_value['answer'] as $index => $value) {
26 include_once './Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php';
27 $answer = new ASS_AnswerMultipleResponseImage($value, $a_value['points'][$index], $index, $a_value['points_unchecked'][$index], $a_value['imagename'][$index], $a_value['answer_id'][$index]);
28 array_push($this->values, $answer);
29 }
30 }
31 }
32 }
33
39 public function checkInput()
40 {
41 global $DIC;
42 $lng = $DIC['lng'];
43
44 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
45
46 if (is_array($_POST[$this->getPostVar()]) && $_POST["types"] == 1) {
49 } elseif (is_array($_POST[$this->getPostVar()]) && $_POST["types"] == 0) {
52 }
53
54 $foundvalues = $_POST[$this->getPostVar()];
55 if (is_array($foundvalues)) {
56 // check answers
57 if (is_array($foundvalues['answer'])) {
58 foreach ($foundvalues['answer'] as $aidx => $answervalue) {
59 if (((strlen($answervalue)) == 0) && (strlen($foundvalues['imagename'][$aidx]) == 0)) {
60 $this->setAlert($lng->txt("msg_input_is_required"));
61 return false;
62 }
63 }
64 }
65 // check points
66 $max = 0;
67 if (is_array($foundvalues['points'])) {
68 foreach ($foundvalues['points'] as $points) {
69 if ($points > $max) {
70 $max = $points;
71 }
72 if (((strlen($points)) == 0) || (!is_numeric($points))) {
73 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
74 return false;
75 }
76 }
77 foreach ($foundvalues['points_unchecked'] as $points) {
78 if (((strlen($points)) == 0) || (!is_numeric($points))) {
79 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
80 return false;
81 }
82 }
83 }
84 if ($max == 0) {
85 $this->setAlert($lng->txt("enter_enough_positive_points_checked"));
86 return false;
87 }
88
89 if (is_array($_FILES) && count($_FILES) && $this->getSingleline()) {
90 if (!$this->hideImages) {
91 if (is_array($_FILES[$this->getPostVar()]['error']['image'])) {
92 foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error) {
93 // error handling
94 if ($error > 0) {
95 switch ($error) {
96 case UPLOAD_ERR_INI_SIZE:
97 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
98 return false;
99 break;
100
101 case UPLOAD_ERR_FORM_SIZE:
102 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
103 return false;
104 break;
105
106 case UPLOAD_ERR_PARTIAL:
107 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
108 return false;
109 break;
110
111 case UPLOAD_ERR_NO_FILE:
112 if ($this->getRequired()) {
113 if ((!strlen($foundvalues['imagename'][$index])) && (!strlen($foundvalues['answer'][$index]))) {
114 $this->setAlert($lng->txt("form_msg_file_no_upload"));
115 return false;
116 }
117 }
118 break;
119
120 case UPLOAD_ERR_NO_TMP_DIR:
121 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
122 return false;
123 break;
124
125 case UPLOAD_ERR_CANT_WRITE:
126 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
127 return false;
128 break;
129
130 case UPLOAD_ERR_EXTENSION:
131 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
132 return false;
133 break;
134 }
135 }
136 }
137 } else {
138 if ($this->getRequired()) {
139 $this->setAlert($lng->txt("form_msg_file_no_upload"));
140 return false;
141 }
142 }
143
144 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
145 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
146 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
147 $filename_arr = pathinfo($filename);
148 $suffix = $filename_arr["extension"];
149 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
150 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
151 // check suffixes
152 if (strlen($tmpname) && is_array($this->getSuffixes())) {
153 if (!in_array(strtolower($suffix), $this->getSuffixes())) {
154 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
155 return false;
156 }
157 }
158 }
159 }
160
161 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
162 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
163 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
164 $filename_arr = pathinfo($filename);
165 $suffix = $filename_arr["extension"];
166 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
167 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
168 // virus handling
169 if (strlen($tmpname)) {
170 $vir = ilUtil::virusHandling($tmpname, $filename);
171 if ($vir[0] == false) {
172 $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
173 return false;
174 }
175 }
176 }
177 }
178 }
179 }
180 } else {
181 $this->setAlert($lng->txt("msg_input_is_required"));
182 return false;
183 }
184
185 return $this->checkSubItemsInput();
186 }
187
192 public function insert($a_tpl)
193 {
194 global $DIC;
195 $lng = $DIC['lng'];
196
197 $tpl = new ilTemplate("tpl.prop_multiplechoicewizardinput.html", true, true, "Modules/TestQuestionPool");
198 $i = 0;
199 foreach ($this->values as $value) {
200 if ($this->getSingleline()) {
201 if (!$this->hideImages) {
202 if (strlen($value->getImage())) {
203 $imagename = $this->qstObject->getImagePathWeb() . $value->getImage();
204 if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
205 if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->getImage())) {
206 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->getImage();
207 }
208 }
209 $tpl->setCurrentBlock('image');
210 $tpl->setVariable('SRC_IMAGE', $imagename);
211 $tpl->setVariable('IMAGE_NAME', $value->getImage());
212 $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value->getAnswertext()));
213 $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
214 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
215 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
216 $tpl->parseCurrentBlock();
217 }
218 $tpl->setCurrentBlock('addimage');
219 $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
220 $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
221 $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
222 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
223 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
224 $tpl->parseCurrentBlock();
225 }
226
227 if (is_object($value)) {
228 $tpl->setCurrentBlock("prop_text_propval");
229 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
230 $tpl->parseCurrentBlock();
231 $tpl->setCurrentBlock("prop_points_propval");
232 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPointsChecked()));
233 $tpl->parseCurrentBlock();
234 $tpl->setCurrentBlock("prop_points_unchecked_propval");
235 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPointsUnchecked()));
236 $tpl->parseCurrentBlock();
237 $tpl->setCurrentBlock("prop_answer_id_propval");
238 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getId()));
239 $tpl->parseCurrentBlock();
240 }
241 $tpl->setCurrentBlock('singleline');
242 $tpl->setVariable("SIZE", $this->getSize());
243 $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
244 $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
245 $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
246 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
247 if ($this->getDisabled()) {
248 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
249 }
250 $tpl->parseCurrentBlock();
251 } elseif (!$this->getSingleline()) {
252 if (is_object($value)) {
253 $tpl->setCurrentBlock("prop_points_propval");
254 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
255 $tpl->parseCurrentBlock();
256 $tpl->setCurrentBlock("prop_points_unchecked_propval");
257 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPointsUnchecked()));
258 $tpl->parseCurrentBlock();
259 $tpl->setCurrentBlock("prop_answer_id_propval");
260 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getId()));
261 $tpl->parseCurrentBlock();
262 }
263 $tpl->setCurrentBlock('multiline');
264 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
265 $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
266 $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
267 $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
268 if ($this->getDisabled()) {
269 $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
270 }
271 $tpl->parseCurrentBlock();
272 }
273 if ($this->getAllowMove()) {
274 $tpl->setCurrentBlock("move");
275 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
276 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
277 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
278 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
279 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
280 $tpl->parseCurrentBlock();
281 }
282 $tpl->setCurrentBlock("row");
283 $tpl->setVariable("POST_VAR", $this->getPostVar());
284 $tpl->setVariable("ROW_NUMBER", $i);
285 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
286 $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
287 $tpl->setVariable("POINTS_UNCHECKED_ID", $this->getPostVar() . "[points_unchecked][$i]");
288 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
289 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
290 if ($this->getDisabled()) {
291 $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
292 }
293 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
294 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
295 $tpl->parseCurrentBlock();
296 $i++;
297 }
298
299 if ($this->getSingleline()) {
300 if (!$this->hideImages) {
301 if (is_array($this->getSuffixes())) {
302 $suff_str = $delim = "";
303 foreach ($this->getSuffixes() as $suffix) {
304 $suff_str .= $delim . "." . $suffix;
305 $delim = ", ";
306 }
307 $tpl->setCurrentBlock('allowed_image_suffixes');
308 $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes") . " " . $suff_str);
309 $tpl->parseCurrentBlock();
310 }
311
312 $tpl->setCurrentBlock("image_heading");
313 $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
314 $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
315 $tpl->parseCurrentBlock();
316 }
317 }
318
319 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
320 $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
321 $tpl->setVariable("TEXT_NO", $lng->txt('no'));
322 $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
323 $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
324 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
325 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
326 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
327 $tpl->setVariable("POINTS_CHECKED_TEXT", $lng->txt('checkbox_checked'));
328 $tpl->setVariable("POINTS_UNCHECKED_TEXT", $lng->txt('checkbox_unchecked'));
329
330 $a_tpl->setCurrentBlock("prop_generic");
331 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
332 $a_tpl->parseCurrentBlock();
333
334 global $DIC;
335 $tpl = $DIC['tpl'];
336 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
337 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/multiplechoicewizard.js");
338 }
339}
$filename
Definition: buildRTE.php:89
$_POST["username"]
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked,...
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.
This class represents a multiple choice wizard property in a property form.
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.
special template class to simplify handling of ITX/PEAR
getMaxLength()
Get Max Length.
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