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