ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilImageWizardInputGUI.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/Form/classes/class.ilTextInputGUI.php';
5 require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
6 
15 {
16  protected $values = array();
17  protected $allowMove = false;
18  protected $qstObject = null;
19  protected $suffixes = array();
20 
27  public function __construct($a_title = "", $a_postvar = "")
28  {
29  parent::__construct($a_title, $a_postvar);
31  $this->setSize('25');
32  $this->validationRegexp = "";
33  }
34 
40  public function setValue($a_value)
41  {
42  $this->values = array();
43  if (is_array($a_value)) {
44  if (is_array($a_value['count'])) {
45  foreach ($a_value['count'] as $index => $value) {
46  array_push($this->values, $a_value['imagename'][$index]);
47  }
48  }
49  }
50  }
51 
57  public function setSuffixes($a_suffixes)
58  {
59  $this->suffixes = $a_suffixes;
60  }
61 
67  public function getSuffixes()
68  {
69  return $this->suffixes;
70  }
71 
77  public function setValues($a_values)
78  {
79  $this->values = $a_values;
80  }
81 
87  public function getValues()
88  {
89  return $this->values;
90  }
91 
97  public function setQuestionObject($a_value)
98  {
99  $this->qstObject =&$a_value;
100  }
101 
107  public function getQuestionObject()
108  {
109  return $this->qstObject;
110  }
111 
117  public function setAllowMove($a_allow_move)
118  {
119  $this->allowMove = $a_allow_move;
120  }
121 
127  public function getAllowMove()
128  {
129  return $this->allowMove;
130  }
131 
137  public function checkInput()
138  {
139  global $lng;
140 
141  if (is_array($_POST[$this->getPostVar()])) {
143  }
144  if (is_array($_FILES[$this->getPostVar()]['error']['image'])) {
145  foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error) {
146  // error handling
147  if ($error > 0) {
148  switch ($error) {
149  case UPLOAD_ERR_INI_SIZE:
150  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
151  return false;
152  break;
153 
154  case UPLOAD_ERR_FORM_SIZE:
155  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
156  return false;
157  break;
158 
159  case UPLOAD_ERR_PARTIAL:
160  $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
161  return false;
162  break;
163 
164  case UPLOAD_ERR_NO_FILE:
165  if ($this->getRequired()) {
166  if (!strlen($_POST[$this->getPostVar()]['imagename'][$index])) {
167  $this->setAlert($lng->txt("form_msg_file_no_upload"));
168  return false;
169  }
170  }
171  break;
172 
173  case UPLOAD_ERR_NO_TMP_DIR:
174  $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
175  return false;
176  break;
177 
178  case UPLOAD_ERR_CANT_WRITE:
179  $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
180  return false;
181  break;
182 
183  case UPLOAD_ERR_EXTENSION:
184  $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
185  return false;
186  break;
187  }
188  }
189  }
190  } else {
191  if ($this->getRequired()) {
192  $this->setAlert($lng->txt("form_msg_file_no_upload"));
193  return false;
194  }
195  }
196 
197  if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
198  foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
199  $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
200  $filename_arr = pathinfo($filename);
201  $suffix = $filename_arr["extension"];
202  $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
203  $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
204  // check suffixes
205  if (strlen($tmpname) && is_array($this->getSuffixes())) {
206  if (!in_array(strtolower($suffix), $this->getSuffixes())) {
207  $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
208  return false;
209  }
210  }
211  }
212  }
213 
214  if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
215  foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
216  $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
217  $filename_arr = pathinfo($filename);
218  $suffix = $filename_arr["extension"];
219  $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
220  $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
221  // virus handling
222  if (strlen($tmpname)) {
223  $vir = ilUtil::virusHandling($tmpname, $filename);
224  if ($vir[0] == false) {
225  $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
226  return false;
227  }
228  }
229  }
230  }
231 
232  return $this->checkSubItemsInput();
233  }
234 
240  public function insert($a_tpl)
241  {
242  global $lng;
243 
244  $tpl = new ilTemplate("tpl.prop_imagewizardinput.html", true, true, "Modules/TestQuestionPool");
245  $i = 0;
246  foreach ($this->values as $value) {
247  if (strlen($value)) {
248  $imagename = $this->qstObject->getImagePathWeb() . $value;
249  if ($this->qstObject->getThumbSize()) {
250  if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value)) {
251  $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value;
252  }
253  }
254  $tpl->setCurrentBlock('image');
255  $tpl->setVariable('SRC_IMAGE', $imagename);
256  $tpl->setVariable('IMAGE_NAME', $value);
257  $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value));
258  $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
259  $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
260  $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
261  $tpl->parseCurrentBlock();
262  }
263  $tpl->setCurrentBlock('addimage');
264  $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
265  $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
266  $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
267  $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
268  $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
269  $tpl->parseCurrentBlock();
270 
271  if ($this->getAllowMove()) {
272  $tpl->setCurrentBlock("move");
273  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
274  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
275  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
276  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
277  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
278  $tpl->parseCurrentBlock();
279  }
280  $tpl->setCurrentBlock("row");
281  $tpl->setVariable("POST_VAR", $this->getPostVar());
282  $tpl->setVariable("ROW_NUMBER", $i);
283  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
284  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
285  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
286  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
287  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
288  $tpl->parseCurrentBlock();
289  $i++;
290  }
291 
292  if (is_array($this->getSuffixes())) {
293  $suff_str = $delim = "";
294  foreach ($this->getSuffixes() as $suffix) {
295  $suff_str.= $delim . "." . $suffix;
296  $delim = ", ";
297  }
298  $tpl->setCurrentBlock('allowed_image_suffixes');
299  $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes") . " " . $suff_str);
300  $tpl->parseCurrentBlock();
301  }
302  /*
303  $tpl->setCurrentBlock("image_heading");
304  $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
305  $tpl->parseCurrentBlock();
306  */
307 
308  $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
309  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
310  $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
311  $tpl->setVariable("TEXT_NO", $lng->txt('no'));
312  $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
313  $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
314  $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
315  $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
316 
317  $a_tpl->setCurrentBlock("prop_generic");
318  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
319  $a_tpl->parseCurrentBlock();
320 
321  global $tpl;
322  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
323  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/imagewizard.js");
324  }
325 }
setAllowMove($a_allow_move)
Set allow move.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static getAllowedImageMaterialFileExtensions()
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
setSuffixes($a_suffixes)
Set Accepted Suffixes.
__construct($a_title="", $a_postvar="")
Constructor.
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
setQuestionObject($a_value)
Set question object.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a single choice wizard property in a property form.
static getFileSizeInfo()
setValues($a_values)
Set Values.
$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.
getQuestionObject()
Get question object.
Create styles array
The data for the language used.
insert($a_tpl)
Insert property html.
checkInput()
Check input, strip slashes etc.
$i
Definition: disco.tpl.php:19
getSuffixes()
Get Accepted Suffixes.
$_POST["username"]