ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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->tpl = $DIC["tpl"];
59  parent::__construct($a_title, $a_postvar);
60  }
61 
67  public function setImagePathWeb($a_path)
68  {
69  $this->imagepath_web = $a_path;
70  }
71 
77  public function getImagePathWeb()
78  {
79  return $this->imagepath_web;
80  }
81 
87  public function setFilenames($a_filenames)
88  {
89  $this->filenames = $a_filenames;
90  }
91 
97  public function getFilenames()
98  {
99  return $this->filenames;
100  }
101 
107  public function setAllowMove($a_allow_move)
108  {
109  $this->allowMove = $a_allow_move;
110  }
111 
117  public function getAllowMove()
118  {
119  return $this->allowMove;
120  }
121 
127  public function checkInput()
128  {
129  $lng = $this->lng;
130 
131  // see ilFileInputGUI
132  // if no information is received, something went wrong
133  // this is e.g. the case, if the post_max_size has been exceeded
134  if (!is_array($_FILES[$this->getPostVar()])) {
135  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
136  return false;
137  }
138 
139  $pictures = $_FILES[$this->getPostVar()];
140  $uploadcheck = true;
141  if (is_array($pictures)) {
142  foreach ($pictures['name'] as $index => $name) {
143  // remove trailing '/'
144  $name = rtrim($name, '/');
145 
146  $filename = $name;
147  $filename_arr = pathinfo($name);
148  $suffix = $filename_arr["extension"];
149  $mimetype = $pictures["type"][$index];
150  $size_bytes = $pictures["size"][$index];
151  $temp_name = $pictures["tmp_name"][$index];
152  $error = $pictures["error"][$index];
153 
154  include_once("./Services/Utilities/classes/class.ilStr.php");
155  $_FILES[$this->getPostVar()]["name"][$index] = ilStr::normalizeUtf8String($_FILES[$this->getPostVar()]["name"][$index]);
156 
157 
158  // error handling
159  if ($error > 0) {
160  switch ($error) {
161  case UPLOAD_ERR_INI_SIZE:
162  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
163  $uploadcheck = false;
164  break;
165 
166  case UPLOAD_ERR_FORM_SIZE:
167  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
168  $uploadcheck = false;
169  break;
170 
171  case UPLOAD_ERR_PARTIAL:
172  $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
173  $uploadcheck = false;
174  break;
175 
176  case UPLOAD_ERR_NO_FILE:
177  if ($this->getRequired()) {
178  $filename = $this->filenames[$index];
179  if (!strlen($filename)) {
180  $this->setAlert($lng->txt("form_msg_file_no_upload"));
181  $uploadcheck = false;
182  }
183  }
184  break;
185 
186  case UPLOAD_ERR_NO_TMP_DIR:
187  $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
188  $uploadcheck = false;
189  break;
190 
191  case UPLOAD_ERR_CANT_WRITE:
192  $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
193  $uploadcheck = false;
194  break;
195 
196  case UPLOAD_ERR_EXTENSION:
197  $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
198  $uploadcheck = false;
199  break;
200  }
201  }
202 
203  // check suffixes
204  if ($pictures["tmp_name"][$index] != "" && is_array($this->getSuffixes())) {
205  if (!in_array(strtolower($suffix), $this->getSuffixes())) {
206  $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
207  $uploadcheck = false;
208  }
209  }
210 
211  // virus handling
212  if ($pictures["tmp_name"][$index] != "") {
213  $vir = ilUtil::virusHandling($temp_name, $filename);
214  if ($vir[0] == false) {
215  $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
216  $uploadcheck = false;
217  }
218  }
219  }
220  }
221 
222  if (!$uploadcheck) {
223  return false;
224  }
225 
226  return $this->checkSubItemsInput();
227  }
228 
234  public function insert($a_tpl)
235  {
236  $lng = $this->lng;
237 
238  $tpl = new ilTemplate("tpl.prop_filewizardinput.html", true, true, "Services/Form");
239 
240  $i = 0;
241  foreach ($this->filenames as $value) {
242  if (strlen($value)) {
243  $tpl->setCurrentBlock("image");
244  $tpl->setVariable("SRC_IMAGE", $this->getImagePathWeb() . ilUtil::prepareFormOutput($value));
245  $tpl->setVariable("PICTURE_FILE", ilUtil::prepareFormOutput($value));
246  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
247  $tpl->setVariable("ALT_IMAGE", ilUtil::prepareFormOutput($value));
248  $tpl->parseCurrentBlock();
249  }
250  if ($this->getAllowMove()) {
251  $tpl->setCurrentBlock("move");
252  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
253  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
254  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
255  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
256  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
257  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
258  $tpl->parseCurrentBlock();
259  }
260 
261  $this->outputSuffixes($tpl, "allowed_image_suffixes");
262 
263  $tpl->setCurrentBlock("row");
264  $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
265  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
266  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
267  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
268  $tpl->setVariable("ALT_ADD", $lng->txt("add"));
269  $tpl->setVariable("ALT_REMOVE", $lng->txt("remove"));
270  if ($this->getDisabled()) {
271  $tpl->setVariable(
272  "DISABLED",
273  " disabled=\"disabled\""
274  );
275  }
276 
277  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
278  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
279  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
280  $tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " . $this->getMaxFileSizeString());
281  $tpl->parseCurrentBlock();
282  $i++;
283  }
284  $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
285 
286  $a_tpl->setCurrentBlock("prop_generic");
287  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
288  $a_tpl->parseCurrentBlock();
289 
290  $main_tpl = $this->tpl;
291  $main_tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
292  $main_tpl->addJavascript("./Services/Form/templates/default/filewizard.js");
293  }
294 }
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.
$error
Definition: Error.php:17
if($format !==null) $name
Definition: metadata.php:146
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
outputSuffixes($a_tpl, $a_block="allowed_suffixes")
Create styles array
The data for the language used.
getImagePathWeb()
Get the web image path.
insert($a_tpl)
Insert property html.
setFilenames($a_filenames)
Set filenames.
$i
Definition: disco.tpl.php:19