ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_once './Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php';
5 require_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 $lng;
38 
39  parent::__construct($a_title, $a_postvar);
40  $this->setSuffixes(array("jpg", "jpeg", "png", "gif"));
41  $this->setSize('40');
42  $this->text_name = $lng->txt('answer_text');
43  $this->image_name = $lng->txt('answer_image');
44  }
45 
51  public function setSuffixes($a_suffixes)
52  {
53  $this->suffixes = $a_suffixes;
54  }
55 
61  public function getSuffixes()
62  {
63  return $this->suffixes;
64  }
65 
71  public function setHideImages($a_hide)
72  {
73  $this->hideImages = $a_hide;
74  }
75 
81  public function setValues($a_values)
82  {
83  $this->values = $a_values;
84  }
85 
91  public function getValues()
92  {
93  return $this->values;
94  }
95 
96  public function setTextName($a_value)
97  {
98  $this->text_name = $a_value;
99  }
100 
101  public function setImageName($a_value)
102  {
103  $this->image_name = $a_value;
104  }
105 
111  public function setQuestionObject($a_value)
112  {
113  $this->qstObject =&$a_value;
114  }
115 
121  public function getQuestionObject()
122  {
123  return $this->qstObject;
124  }
125 
131  public function setAllowMove($a_allow_move)
132  {
133  $this->allowMove = $a_allow_move;
134  }
135 
141  public function getAllowMove()
142  {
143  return $this->allowMove;
144  }
145 
151  public function setValue($a_value)
152  {
153  $this->values = array();
154  if (is_array($a_value)) {
155  if (is_array($a_value['answer'])) {
156  foreach ($a_value['answer'] as $index => $value) {
157  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
158  $answer = new assAnswerMatchingTerm($value, $a_value['imagename'][$index], $a_value['identifier'][$index]);
159  array_push($this->values, $answer);
160  }
161  }
162  }
163  }
164 
170  public function checkInput()
171  {
172  global $lng;
173  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
174  if (is_array($_POST[$this->getPostVar()])) {
176  }
177  $foundvalues = $_POST[$this->getPostVar()];
178  if (is_array($foundvalues)) {
179  // check answers
180  if (is_array($foundvalues['answer'])) {
181  foreach ($foundvalues['answer'] as $aidx => $answervalue) {
182  if (((strlen($answervalue)) == 0) && (strlen($foundvalues['imagename'][$aidx]) == 0)) {
183  $this->setAlert($lng->txt("msg_input_is_required"));
184  return false;
185  }
186  }
187  }
188  if (!$this->hideImages) {
189  if (is_array($_FILES[$this->getPostVar()]['error']['image'])) {
190  foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error) {
191  // error handling
192  if ($error > 0) {
193  switch ($error) {
194  case UPLOAD_ERR_INI_SIZE:
195  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
196  return false;
197  break;
198 
199  case UPLOAD_ERR_FORM_SIZE:
200  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
201  return false;
202  break;
203 
204  case UPLOAD_ERR_PARTIAL:
205  $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
206  return false;
207  break;
208 
209  case UPLOAD_ERR_NO_FILE:
210  if ($this->getRequired()) {
211  if ((!strlen($foundvalues['imagename'][$index])) && (!strlen($foundvalues['answer'][$index]))) {
212  $this->setAlert($lng->txt("form_msg_file_no_upload"));
213  return false;
214  }
215  }
216  break;
217 
218  case UPLOAD_ERR_NO_TMP_DIR:
219  $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
220  return false;
221  break;
222 
223  case UPLOAD_ERR_CANT_WRITE:
224  $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
225  return false;
226  break;
227 
228  case UPLOAD_ERR_EXTENSION:
229  $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
230  return false;
231  break;
232  }
233  }
234  }
235  }
236 
237  if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
238  foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
239  $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
240  $filename_arr = pathinfo($filename);
241  $suffix = $filename_arr["extension"];
242 
243  // check suffixes
244  if (strlen($tmpname) && is_array($this->getSuffixes())) {
245  $vir = ilUtil::virusHandling($tmpname, $filename);
246  if ($vir[0] == false) {
247  $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
248  return false;
249  }
250 
251  if (!in_array(strtolower($suffix), $this->getSuffixes())) {
252  $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
253  return false;
254  }
255  }
256  }
257  }
258  }
259  }
260  return $this->checkSubItemsInput();
261  }
262 
268  public function insert($a_tpl)
269  {
270  global $lng;
271 
272  $tpl = new ilTemplate("tpl.prop_matchingwizardinput.html", true, true, "Modules/TestQuestionPool");
273  $i = 0;
274  foreach ($this->values as $value) {
275  if (!$this->hideImages) {
276  if (strlen($value->picture)) {
277  $imagename = $this->qstObject->getImagePathWeb() . $value->picture;
278  if ($this->qstObject->getThumbSize()) {
279  if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->picture)) {
280  $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->picture;
281  }
282  }
283  $tpl->setCurrentBlock('image');
284  $tpl->setVariable('SRC_IMAGE', $imagename);
285  $tpl->setVariable('IMAGE_NAME', $value->picture);
286  $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value->text));
287  $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
288  $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
289  $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
290  $tpl->parseCurrentBlock();
291  }
292  $tpl->setCurrentBlock('addimage');
293  $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
294  $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
295  $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
296  $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
297  $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
298  $tpl->parseCurrentBlock();
299  }
300 
301  if (is_object($value)) {
302  $tpl->setCurrentBlock("prop_text_propval");
303  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text));
304  $tpl->parseCurrentBlock();
305  }
306  // this block does not exist in the template
307  // $tpl->setCurrentBlock('singleline');
308  $tpl->setVariable("SIZE", $this->getSize());
309  $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
310  $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
311  $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
312  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
313  if ($this->getDisabled()) {
314  $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
315  }
316  $tpl->parseCurrentBlock();
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+1);
329  $tpl->setVariable("ROW_IDENTIFIER", $value->identifier);
330  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
331  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
332  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
333  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
334  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
335  $tpl->parseCurrentBlock();
336  $i++;
337  }
338 
339  if (!$this->hideImages) {
340  if (is_array($this->getSuffixes())) {
341  $suff_str = $delim = "";
342  foreach ($this->getSuffixes() as $suffix) {
343  $suff_str.= $delim . "." . $suffix;
344  $delim = ", ";
345  }
346  $tpl->setCurrentBlock('allowed_image_suffixes');
347  $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes") . " " . $suff_str);
348  $tpl->parseCurrentBlock();
349  }
350  $tpl->setCurrentBlock("image_heading");
351  $tpl->setVariable("ANSWER_IMAGE", $this->image_name);
352  $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
353  $tpl->parseCurrentBlock();
354  }
355 
356  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
357  $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
358  $tpl->setVariable("TEXT_NO", $lng->txt('no'));
359  $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
360  $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
361  $tpl->setVariable("ANSWER_TEXT", $this->text_name);
362  $tpl->setVariable("NUMBER_TEXT", $lng->txt('row'));
363  $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
364 
365  $a_tpl->setCurrentBlock("prop_generic");
366  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
367  $a_tpl->parseCurrentBlock();
368  }
369 }
Class for matching question terms.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaxLength()
Get Max Length.
This class represents a single choice wizard property in a property form.
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.
setHideImages($a_hide)
Set hide images.
__construct($a_title="", $a_postvar="")
Constructor.
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
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
insert($a_tpl)
Insert property html.
setQuestionObject($a_value)
Set question object.
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.
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
$_POST["username"]
setAllowMove($a_allow_move)
Set allow move.