ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilFileWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 {
36  protected $lng;
37 
41  protected $tpl;
42 
43  protected $filenames = array();
44  protected $allowMove = false;
45  protected $imagepath_web = "";
46 
53  public function __construct($a_title = "", $a_postvar = "")
54  {
55  global $DIC;
56 
57  $this->lng = $DIC->language();
58  $this->lng->loadLanguageModule("form");
59  $this->tpl = $DIC["tpl"];
60  parent::__construct($a_title, $a_postvar);
61  }
62 
68  public function setImagePathWeb($a_path)
69  {
70  $this->imagepath_web = $a_path;
71  }
72 
78  public function getImagePathWeb()
79  {
80  return $this->imagepath_web;
81  }
82 
88  public function setFilenames($a_filenames)
89  {
90  $this->filenames = $a_filenames;
91  }
92 
98  public function getFilenames()
99  {
100  return $this->filenames;
101  }
102 
108  public function setAllowMove($a_allow_move)
109  {
110  $this->allowMove = $a_allow_move;
111  }
112 
118  public function getAllowMove()
119  {
120  return $this->allowMove;
121  }
122 
128  public function checkInput()
129  {
130  $lng = $this->lng;
131 
132  // see ilFileInputGUI
133  // if no information is received, something went wrong
134  // this is e.g. the case, if the post_max_size has been exceeded
135  if (!is_array($_FILES[$this->getPostVar()])) {
136  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
137  return false;
138  }
139 
140  $pictures = $_FILES[$this->getPostVar()];
141  $uploadcheck = true;
142  if (is_array($pictures)) {
143  foreach ($pictures['name'] as $index => $name) {
144  // remove trailing '/'
145  $name = rtrim($name, '/');
146 
147  $filename = $name;
148  $filename_arr = pathinfo($name);
149  $suffix = $filename_arr["extension"];
150  $mimetype = $pictures["type"][$index];
151  $size_bytes = $pictures["size"][$index];
152  $temp_name = $pictures["tmp_name"][$index];
153  $error = $pictures["error"][$index];
154 
155  include_once("./Services/Utilities/classes/class.ilStr.php");
156  $_FILES[$this->getPostVar()]["name"][$index] = ilStr::normalizeUtf8String($_FILES[$this->getPostVar()]["name"][$index]);
157 
158 
159  // error handling
160  if ($error > 0) {
161  switch ($error) {
162  case UPLOAD_ERR_INI_SIZE:
163  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
164  $uploadcheck = false;
165  break;
166 
167  case UPLOAD_ERR_FORM_SIZE:
168  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
169  $uploadcheck = false;
170  break;
171 
172  case UPLOAD_ERR_PARTIAL:
173  $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
174  $uploadcheck = false;
175  break;
176 
177  case UPLOAD_ERR_NO_FILE:
178  if ($this->getRequired()) {
179  $filename = $this->filenames[$index];
180  if (!strlen($filename)) {
181  $this->setAlert($lng->txt("form_msg_file_no_upload"));
182  $uploadcheck = false;
183  }
184  }
185  break;
186 
187  case UPLOAD_ERR_NO_TMP_DIR:
188  $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
189  $uploadcheck = false;
190  break;
191 
192  case UPLOAD_ERR_CANT_WRITE:
193  $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
194  $uploadcheck = false;
195  break;
196 
197  case UPLOAD_ERR_EXTENSION:
198  $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
199  $uploadcheck = false;
200  break;
201  }
202  }
203 
204  // check suffixes
205  if ($pictures["tmp_name"][$index] != "" && is_array($this->getSuffixes())) {
206  if (!in_array(strtolower($suffix), $this->getSuffixes())) {
207  $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
208  $uploadcheck = false;
209  }
210  }
211 
212  // virus handling
213  if ($pictures["tmp_name"][$index] != "") {
214  $vir = ilUtil::virusHandling($temp_name, $filename);
215  if ($vir[0] == false) {
216  $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
217  $uploadcheck = false;
218  }
219  }
220  }
221  }
222 
223  if (!$uploadcheck) {
224  return false;
225  }
226 
227  return $this->checkSubItemsInput();
228  }
229 
235  public function insert($a_tpl)
236  {
237  $lng = $this->lng;
238 
239  $tpl = new ilTemplate("tpl.prop_filewizardinput.html", true, true, "Services/Form");
240 
241  $i = 0;
242  foreach ($this->filenames as $value) {
243  if (strlen($value)) {
244  $tpl->setCurrentBlock("image");
245  $tpl->setVariable("SRC_IMAGE", $this->getImagePathWeb() . ilUtil::prepareFormOutput($value));
246  $tpl->setVariable("PICTURE_FILE", ilUtil::prepareFormOutput($value));
247  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
248  $tpl->setVariable("ALT_IMAGE", ilUtil::prepareFormOutput($value));
249  $tpl->parseCurrentBlock();
250  }
251  if ($this->getAllowMove()) {
252  $tpl->setCurrentBlock("move");
253  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
254  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
255  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
256  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
257  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
258  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
259  $tpl->parseCurrentBlock();
260  }
261 
262  $this->outputSuffixes($tpl, "allowed_image_suffixes");
263 
264  $tpl->setCurrentBlock("row");
265  $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
266  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
267  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
268  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
269  $tpl->setVariable("ALT_ADD", $lng->txt("add"));
270  $tpl->setVariable("ALT_REMOVE", $lng->txt("remove"));
271  if ($this->getDisabled()) {
272  $tpl->setVariable(
273  "DISABLED",
274  " disabled=\"disabled\""
275  );
276  }
277 
278  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
279  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
280  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
281  $tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " . $this->getMaxFileSizeString());
282  $tpl->setVariable("MAX_UPLOAD_VALUE", $this->getMaxFileUploads());
283  $tpl->setVariable("TXT_MAX_UPLOADS", $lng->txt("form_msg_max_upload") . " " . $this->getMaxFileUploads());
284  $tpl->parseCurrentBlock();
285  $i++;
286  }
287  $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
288 
289  $a_tpl->setCurrentBlock("prop_generic");
290  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
291  $a_tpl->parseCurrentBlock();
292 
293  $main_tpl = $this->tpl;
294  $main_tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
295  $main_tpl->addJavascript("./Services/Form/templates/default/filewizard.js");
296  }
297 }
getSuffixes()
Get Accepted Suffixes.
setAllowMove($a_allow_move)
Set allow move.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
global $DIC
Definition: saml.php:7
getPostVar()
Get Post Variable.
This class represents a file property in a property form.
static normalizeUtf8String($a_str)
Normalize UTF8 string.
setImagePathWeb($a_path)
Set the web image path.
This class represents a file wizard property in a property form.
checkInput()
Check input, strip slashes etc.
static get($a_glyph, $a_text="")
Get glyph html.
__construct($a_title="", $a_postvar="")
Constructor.
$index
Definition: metadata.php:60
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
outputSuffixes($a_tpl, $a_block="allowed_suffixes")
getImagePathWeb()
Get the web image path.
insert($a_tpl)
Insert property html.
setFilenames($a_filenames)
Set filenames.
$i
Definition: disco.tpl.php:19
getMaxFileUploads()
Get number of maximum file uploads as declared in php.ini.