ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
5 
14 {
15  protected $values = array();
16  protected $allowMove = false;
17  protected $singleline = true;
18  protected $qstObject = null;
19  protected $suffixes = array();
20  protected $showPoints = true;
21  protected $hideImages = false;
22 
29  public function __construct($a_title = "", $a_postvar = "")
30  {
31  parent::__construct($a_title, $a_postvar);
32  $this->setSuffixes(array("jpg", "jpeg", "png", "gif"));
33  $this->setSize('25');
34  $this->validationRegexp = "";
35  }
36 
42  public function setValue($a_value)
43  {
44  $this->values = array();
45  if (is_array($a_value)) {
46  if (is_array($a_value['answer'])) {
47  foreach ($a_value['answer'] as $index => $value) {
48  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
49  $answer = new ASS_AnswerBinaryStateImage($value, $a_value['points'][$index], $index, 1, $a_value['imagename'][$index]);
50  array_push($this->values, $answer);
51  }
52  }
53  }
54  }
55 
61  public function setSuffixes($a_suffixes)
62  {
63  $this->suffixes = $a_suffixes;
64  }
65 
71  public function setHideImages($a_hide)
72  {
73  $this->hideImages = $a_hide;
74  }
75 
81  public function getSuffixes()
82  {
83  return $this->suffixes;
84  }
85 
86  public function setShowPoints($a_value)
87  {
88  $this->showPoints = $a_value;
89  }
90 
91  public function getShowPoints()
92  {
93  return $this->showPoints;
94  }
95 
101  public function setValues($a_values)
102  {
103  $this->values = $a_values;
104  }
105 
111  public function getValues()
112  {
113  return $this->values;
114  }
115 
121  public function setSingleline($a_value)
122  {
123  $this->singleline = $a_value;
124  }
125 
131  public function getSingleline()
132  {
133  return $this->singleline;
134  }
135 
141  public function setQuestionObject($a_value)
142  {
143  $this->qstObject =&$a_value;
144  }
145 
151  public function getQuestionObject()
152  {
153  return $this->qstObject;
154  }
155 
161  public function setAllowMove($a_allow_move)
162  {
163  $this->allowMove = $a_allow_move;
164  }
165 
171  public function getAllowMove()
172  {
173  return $this->allowMove;
174  }
175 
181  public function checkInput()
182  {
183  global $lng;
184 
185  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
186 
187  if (is_array($_POST[$this->getPostVar()])) {
189  }
190  $foundvalues = $_POST[$this->getPostVar()];
191  if (is_array($foundvalues)) {
192  // check answers
193  if (is_array($foundvalues['answer'])) {
194  foreach ($foundvalues['answer'] as $aidx => $answervalue) {
195  if (((strlen($answervalue)) == 0) && (strlen($foundvalues['imagename'][$aidx]) == 0)) {
196  $this->setAlert($lng->txt("msg_input_is_required"));
197  return false;
198  }
199  }
200  }
201  // check points
202  $max = 0;
203  if (is_array($foundvalues['points'])) {
204  foreach ($foundvalues['points'] as $points) {
205  if ($points > $max) {
206  $max = $points;
207  }
208  if (((strlen($points)) == 0) || (!is_numeric($points))) {
209  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
210  return false;
211  }
212  }
213  }
214  if ($max == 0) {
215  $this->setAlert($lng->txt("enter_enough_positive_points"));
216  return false;
217  }
218 
219  if (is_array($_FILES) && count($_FILES) && $this->getSingleline() && (!$this->hideImages)) {
220  if (is_array($_FILES[$this->getPostVar()]['error']['image'])) {
221  foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error) {
222  // error handling
223  if ($error > 0) {
224  switch ($error) {
225  case UPLOAD_ERR_INI_SIZE:
226  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
227  return false;
228  break;
229 
230  case UPLOAD_ERR_FORM_SIZE:
231  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
232  return false;
233  break;
234 
235  case UPLOAD_ERR_PARTIAL:
236  $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
237  return false;
238  break;
239 
240  case UPLOAD_ERR_NO_FILE:
241  if ($this->getRequired()) {
242  if ((!strlen($foundvalues['imagename'][$index])) && (!strlen($foundvalues['answer'][$index]))) {
243  $this->setAlert($lng->txt("form_msg_file_no_upload"));
244  return false;
245  }
246  }
247  break;
248 
249  case UPLOAD_ERR_NO_TMP_DIR:
250  $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
251  return false;
252  break;
253 
254  case UPLOAD_ERR_CANT_WRITE:
255  $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
256  return false;
257  break;
258 
259  case UPLOAD_ERR_EXTENSION:
260  $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
261  return false;
262  break;
263  }
264  }
265  }
266  } else {
267  if ($this->getRequired()) {
268  $this->setAlert($lng->txt("form_msg_file_no_upload"));
269  return false;
270  }
271  }
272 
273  if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
274  foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
275  $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
276  $filename_arr = pathinfo($filename);
277  $suffix = $filename_arr["extension"];
278  $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
279  $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
280  // check suffixes
281  if (strlen($tmpname) && is_array($this->getSuffixes())) {
282  if (!in_array(strtolower($suffix), $this->getSuffixes())) {
283  $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
284  return false;
285  }
286  }
287  }
288  }
289 
290  if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
291  foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
292  $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
293  $filename_arr = pathinfo($filename);
294  $suffix = $filename_arr["extension"];
295  $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
296  $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
297  // virus handling
298  if (strlen($tmpname)) {
299  $vir = ilUtil::virusHandling($tmpname, $filename);
300  if ($vir[0] == false) {
301  $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
302  return false;
303  }
304  }
305  }
306  }
307  }
308  } else {
309  $this->setAlert($lng->txt("msg_input_is_required"));
310  return false;
311  }
312 
313  return $this->checkSubItemsInput();
314  }
315 
319  public function insert($a_tpl)
320  {
321  global $lng;
322 
323  $tpl = new ilTemplate("tpl.prop_singlechoicewizardinput.html", true, true, "Modules/TestQuestionPool");
324  $i = 0;
325  foreach ($this->values as $value) {
326  if ($this->getSingleline()) {
327  if (!$this->hideImages) {
328  if (strlen($value->getImage())) {
329  $imagename = $this->qstObject->getImagePathWeb() . $value->getImage();
330  if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
331  if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->getImage())) {
332  $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->getImage();
333  }
334  }
335  $tpl->setCurrentBlock('image');
336  $tpl->setVariable('SRC_IMAGE', $imagename);
337  $tpl->setVariable('IMAGE_NAME', $value->getImage());
338  $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value->getAnswertext()));
339  $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
340  $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
341  $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
342  $tpl->parseCurrentBlock();
343  }
344  $tpl->setCurrentBlock('addimage');
345  $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
346  $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
347  $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
348  $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
349  $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
350  $tpl->parseCurrentBlock();
351  }
352 
353  if (is_object($value)) {
354  $tpl->setCurrentBlock("prop_text_propval");
355  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
356  $tpl->parseCurrentBlock();
357  if ($this->getShowPoints()) {
358  $tpl->setCurrentBlock("prop_points_propval");
359  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
360  $tpl->parseCurrentBlock();
361  }
362  }
363  $tpl->setCurrentBlock('singleline');
364  $tpl->setVariable("SIZE", $this->getSize());
365  $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
366  $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
367  $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
368  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
369  if ($this->getDisabled()) {
370  $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
371  }
372  $tpl->parseCurrentBlock();
373  } elseif (!$this->getSingleline()) {
374  if (is_object($value)) {
375  if ($this->getShowPoints()) {
376  $tpl->setCurrentBlock("prop_points_propval");
377  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
378  $tpl->parseCurrentBlock();
379  }
380  }
381  $tpl->setCurrentBlock('multiline');
382  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
383  $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
384  $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
385  $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
386  if ($this->getDisabled()) {
387  $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
388  }
389  $tpl->parseCurrentBlock();
390  }
391  if ($this->getAllowMove()) {
392  $tpl->setCurrentBlock("move");
393  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
394  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
395  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
396  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
397  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
398  $tpl->parseCurrentBlock();
399  }
400  if ($this->getShowPoints()) {
401  $tpl->setCurrentBlock("points");
402  $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
403  $tpl->setVariable("POINTS_POST_VAR", $this->getPostVar());
404  $tpl->setVariable("POINTS_ROW_NUMBER", $i);
405  $tpl->parseCurrentBlock();
406  }
407  $tpl->setCurrentBlock("row");
408  $tpl->setVariable("POST_VAR", $this->getPostVar());
409  $tpl->setVariable("ROW_NUMBER", $i);
410  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
411  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
412  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
413  if ($this->getDisabled()) {
414  $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
415  }
416  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
417  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
418  $tpl->parseCurrentBlock();
419  $i++;
420  }
421 
422  if ($this->getSingleline()) {
423  if (!$this->hideImages) {
424  if (is_array($this->getSuffixes())) {
425  $suff_str = $delim = "";
426  foreach ($this->getSuffixes() as $suffix) {
427  $suff_str.= $delim . "." . $suffix;
428  $delim = ", ";
429  }
430  $tpl->setCurrentBlock('allowed_image_suffixes');
431  $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes") . " " . $suff_str);
432  $tpl->parseCurrentBlock();
433  }
434  $tpl->setCurrentBlock("image_heading");
435  $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
436  $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
437  $tpl->parseCurrentBlock();
438  }
439  }
440 
441  if ($this->getShowPoints()) {
442  $tpl->setCurrentBlock("points_heading");
443  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
444  $tpl->parseCurrentBlock();
445  }
446 
447  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
448  $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
449  $tpl->setVariable("TEXT_NO", $lng->txt('no'));
450  $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
451  $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
452  $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
453  $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
454 
455  $a_tpl->setCurrentBlock("prop_generic");
456  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
457  $a_tpl->parseCurrentBlock();
458 
459  global $tpl;
460  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
461  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/singlechoicewizard.js");
462  }
463 }
setQuestionObject($a_value)
Set question object.
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.
Class for answers with a binary state indicator.
static get($a_glyph, $a_text="")
Get glyph html.
static getFileSizeInfo()
$index
Definition: metadata.php:60
setAlert($a_alert)
Set Alert Text.
$error
Definition: Error.php:17
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
setSize($a_size)
Set Size.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
This class represents a text property in a property form.
__construct($a_title="", $a_postvar="")
Constructor.
Create styles array
The data for the language used.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
This class represents a single choice wizard property in a property form.
$i
Definition: disco.tpl.php:19
checkInput()
Check input, strip slashes etc.
$_POST["username"]