ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMatchingWizardInputGUI.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 './Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php';
5require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
6
18{
19 protected $text_name = '';
20 protected $image_name = '';
21 protected $values = array();
22 protected $allowMove = false;
23 protected $qstObject = null;
24 protected $suffixes = array();
25 protected $hideImages = false;
26
35 public function __construct($a_title = "", $a_postvar = "")
36 {
37 global $DIC;
38 $lng = $DIC['lng'];
39
40 parent::__construct($a_title, $a_postvar);
41 $this->setSuffixes(array("jpg", "jpeg", "png", "gif"));
42 $this->setSize('40');
43 $this->setMaxLength(800);
44 $this->text_name = $lng->txt('answer_text');
45 $this->image_name = $lng->txt('answer_image');
46 }
47
53 public function setSuffixes($a_suffixes)
54 {
55 $this->suffixes = $a_suffixes;
56 }
57
63 public function getSuffixes()
64 {
65 return $this->suffixes;
66 }
67
73 public function setHideImages($a_hide)
74 {
75 $this->hideImages = $a_hide;
76 }
77
83 public function setValues($a_values)
84 {
85 $this->values = $a_values;
86 }
87
93 public function getValues()
94 {
95 return $this->values;
96 }
97
98 public function setTextName($a_value)
99 {
100 $this->text_name = $a_value;
101 }
102
103 public function setImageName($a_value)
104 {
105 $this->image_name = $a_value;
106 }
107
113 public function setQuestionObject($a_value)
114 {
115 $this->qstObject = &$a_value;
116 }
117
123 public function getQuestionObject()
124 {
125 return $this->qstObject;
126 }
127
133 public function setAllowMove($a_allow_move)
134 {
135 $this->allowMove = $a_allow_move;
136 }
137
143 public function getAllowMove()
144 {
145 return $this->allowMove;
146 }
147
153 public function setValue($a_value)
154 {
155 $this->values = array();
156 if (is_array($a_value)) {
157 if (is_array($a_value['answer'])) {
158 foreach ($a_value['answer'] as $index => $value) {
159 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
160 $answer = new assAnswerMatchingTerm($value, $a_value['imagename'][$index], $a_value['identifier'][$index]);
161 array_push($this->values, $answer);
162 }
163 }
164 }
165 }
166
172 public function checkInput()
173 {
174 global $DIC;
175 $lng = $DIC['lng'];
176 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
177 if (is_array($_POST[$this->getPostVar()])) {
179 }
180 $foundvalues = $_POST[$this->getPostVar()];
181 if (is_array($foundvalues)) {
182 // check answers
183 if (is_array($foundvalues['answer'])) {
184 foreach ($foundvalues['answer'] as $aidx => $answervalue) {
185 if (((strlen($answervalue)) == 0) && (strlen($foundvalues['imagename'][$aidx]) == 0)) {
186 $this->setAlert($lng->txt("msg_input_is_required"));
187 return false;
188 }
189 }
190 }
191 if (!$this->hideImages) {
192 if (is_array($_FILES[$this->getPostVar()]['error']['image'])) {
193 foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error) {
194 // error handling
195 if ($error > 0) {
196 switch ($error) {
197 case UPLOAD_ERR_INI_SIZE:
198 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
199 return false;
200 break;
201
202 case UPLOAD_ERR_FORM_SIZE:
203 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
204 return false;
205 break;
206
207 case UPLOAD_ERR_PARTIAL:
208 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
209 return false;
210 break;
211
212 case UPLOAD_ERR_NO_FILE:
213 if ($this->getRequired()) {
214 if ((!strlen($foundvalues['imagename'][$index])) && (!strlen($foundvalues['answer'][$index]))) {
215 $this->setAlert($lng->txt("form_msg_file_no_upload"));
216 return false;
217 }
218 }
219 break;
220
221 case UPLOAD_ERR_NO_TMP_DIR:
222 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
223 return false;
224 break;
225
226 case UPLOAD_ERR_CANT_WRITE:
227 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
228 return false;
229 break;
230
231 case UPLOAD_ERR_EXTENSION:
232 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
233 return false;
234 break;
235 }
236 }
237 }
238 }
239
240 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
241 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
242 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
243 $filename_arr = pathinfo($filename);
244 $suffix = $filename_arr["extension"];
245
246 // check suffixes
247 if ($tmpname != '' && is_array($this->getSuffixes())) {
248 $vir = ilUtil::virusHandling($tmpname, $filename);
249 if ($vir[0] == false) {
250 $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
251 return false;
252 }
253
254 if (!in_array(strtolower($suffix), $this->getSuffixes())) {
255 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
256 return false;
257 }
258 }
259 }
260 }
261 }
262 }
263 return $this->checkSubItemsInput();
264 }
265
271 public function insert($a_tpl)
272 {
273 global $DIC;
274 $lng = $DIC['lng'];
275
276 $tpl = new ilTemplate("tpl.prop_matchingwizardinput.html", true, true, "Modules/TestQuestionPool");
277 $i = 0;
278 foreach ($this->values as $value) {
279 if (!$this->hideImages) {
280 if (strlen($value->picture)) {
281 $imagename = $this->qstObject->getImagePathWeb() . $value->picture;
282 if ($this->qstObject->getThumbSize()) {
283 if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->picture)) {
284 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->picture;
285 }
286 }
287 $tpl->setCurrentBlock('image');
288 $tpl->setVariable('SRC_IMAGE', $imagename);
289 $tpl->setVariable('IMAGE_NAME', $value->picture);
290 $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value->text));
291 $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
292 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
293 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
294 $tpl->parseCurrentBlock();
295 }
296 $tpl->setCurrentBlock('addimage');
297 $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
298 $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
299 $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
300 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
301 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
302 $tpl->parseCurrentBlock();
303 }
304
305 if (is_object($value)) {
306 $tpl->setCurrentBlock("prop_text_propval");
307 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text));
308 $tpl->parseCurrentBlock();
309 }
310 // this block does not exist in the template
311 // $tpl->setCurrentBlock('singleline');
312 $tpl->setVariable("SIZE", $this->getSize());
313 $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
314 $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
315 $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
316 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
317 if ($this->getDisabled()) {
318 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
319 }
320 $tpl->parseCurrentBlock();
321 if ($this->getAllowMove()) {
322 $tpl->setCurrentBlock("move");
323 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
324 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
325 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
326 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
327 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
328 $tpl->parseCurrentBlock();
329 }
330 $tpl->setCurrentBlock("row");
331 $tpl->setVariable("POST_VAR", $this->getPostVar());
332 $tpl->setVariable("ROW_NUMBER", $i + 1);
333 $tpl->setVariable("ROW_IDENTIFIER", $value->identifier);
334 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
335 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
336 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
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->hideImages) {
344 if (is_array($this->getSuffixes())) {
345 $suff_str = $delim = "";
346 foreach ($this->getSuffixes() as $suffix) {
347 $suff_str .= $delim . "." . $suffix;
348 $delim = ", ";
349 }
350 $tpl->setCurrentBlock('allowed_image_suffixes');
351 $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes") . " " . $suff_str);
352 $tpl->parseCurrentBlock();
353 }
354 $tpl->setCurrentBlock("image_heading");
355 $tpl->setVariable("ANSWER_IMAGE", $this->image_name);
356 $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
357 $tpl->parseCurrentBlock();
358 }
359
360 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
361 $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
362 $tpl->setVariable("TEXT_NO", $lng->txt('no'));
363 $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
364 $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
365 $tpl->setVariable("ANSWER_TEXT", $this->text_name);
366 $tpl->setVariable("NUMBER_TEXT", $lng->txt('row'));
367 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
368
369 $a_tpl->setCurrentBlock("prop_generic");
370 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
371 $a_tpl->parseCurrentBlock();
372 }
373
374 public function setPending(string $a_val): void
375 {
376 $this->pending = $a_val;
377 }
378
379 public function getPending(): string
380 {
381 return $this->pending;
382 }
383}
$filename
Definition: buildRTE.php:89
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class for matching question terms.
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 single choice wizard property in a property form.
setAllowMove($a_allow_move)
Set allow move.
setQuestionObject($a_value)
Set question object.
setHideImages($a_hide)
Set hide images.
insert($a_tpl)
Insert property html.
checkInput()
Check input, strip slashes etc.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
__construct($a_title="", $a_postvar="")
Constructor.
static _getUsedHTMLTagsAsString($a_module="")
Returns a string of all allowed HTML tags for text editing.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
setMaxLength($a_maxlength)
Set Max Length.
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