ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
33  protected $filenames = array();
34  protected $allowMove = false;
35  protected $imagepath_web = "";
36 
43  function __construct($a_title = "", $a_postvar = "")
44  {
45  parent::__construct($a_title, $a_postvar);
46  }
47 
53  public function setImagePathWeb($a_path)
54  {
55  $this->imagepath_web = $a_path;
56  }
57 
63  public function getImagePathWeb()
64  {
65  return $this->imagepath_web;
66  }
67 
73  function setFilenames($a_filenames)
74  {
75  $this->filenames = $a_filenames;
76  }
77 
83  function getFilenames()
84  {
85  return $this->filenames;
86  }
87 
93  function setAllowMove($a_allow_move)
94  {
95  $this->allowMove = $a_allow_move;
96  }
97 
103  function getAllowMove()
104  {
105  return $this->allowMove;
106  }
107 
113  function checkInput()
114  {
115  global $lng;
116 
117  // see ilFileInputGUI
118  // if no information is received, something went wrong
119  // this is e.g. the case, if the post_max_size has been exceeded
120  if (!is_array($_FILES[$this->getPostVar()]))
121  {
122  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
123  return false;
124  }
125 
126  $pictures = $_FILES[$this->getPostVar()];
127  $uploadcheck = true;
128  if (is_array($pictures))
129  {
130  foreach ($pictures['name'] as $index => $name)
131  {
132  // remove trailing '/'
133  $name = rtrim($name, '/');
134 
135  $filename = $name;
136  $filename_arr = pathinfo($name);
137  $suffix = $filename_arr["extension"];
138  $mimetype = $pictures["type"][$index];
139  $size_bytes = $pictures["size"][$index];
140  $temp_name = $pictures["tmp_name"][$index];
141  $error = $pictures["error"][$index];
142 
143  include_once("./Services/Utilities/classes/class.ilStr.php");
144  $_FILES[$this->getPostVar()]["name"][$index] = ilStr::normalizeUtf8String($_FILES[$this->getPostVar()]["name"][$index]);
145 
146 
147  // error handling
148  if ($error > 0)
149  {
150  switch ($error)
151  {
152  case UPLOAD_ERR_INI_SIZE:
153  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
154  $uploadcheck = false;
155  break;
156 
157  case UPLOAD_ERR_FORM_SIZE:
158  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
159  $uploadcheck = false;
160  break;
161 
162  case UPLOAD_ERR_PARTIAL:
163  $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
164  $uploadcheck = false;
165  break;
166 
167  case UPLOAD_ERR_NO_FILE:
168  if ($this->getRequired())
169  {
170  $filename = $this->filenames[$index];
171  if (!strlen($filename))
172  {
173  $this->setAlert($lng->txt("form_msg_file_no_upload"));
174  $uploadcheck = false;
175  }
176  }
177  break;
178 
179  case UPLOAD_ERR_NO_TMP_DIR:
180  $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
181  $uploadcheck = false;
182  break;
183 
184  case UPLOAD_ERR_CANT_WRITE:
185  $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
186  $uploadcheck = false;
187  break;
188 
189  case UPLOAD_ERR_EXTENSION:
190  $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
191  $uploadcheck = false;
192  break;
193  }
194  }
195 
196  // check suffixes
197  if ($pictures["tmp_name"][$index] != "" && is_array($this->getSuffixes()))
198  {
199  if (!in_array(strtolower($suffix), $this->getSuffixes()))
200  {
201  $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
202  $uploadcheck = false;
203  }
204  }
205 
206  // virus handling
207  if ($pictures["tmp_name"][$index] != "")
208  {
209  $vir = ilUtil::virusHandling($temp_name, $filename);
210  if ($vir[0] == false)
211  {
212  $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
213  $uploadcheck = false;
214  }
215  }
216  }
217 
218  }
219 
220  if (!$uploadcheck)
221  {
222  return FALSE;
223  }
224 
225  return $this->checkSubItemsInput();
226  }
227 
233  function insert($a_tpl)
234  {
235  global $lng;
236 
237  $tpl = new ilTemplate("tpl.prop_filewizardinput.html", true, true, "Services/Form");
238 
239  $i = 0;
240  foreach ($this->filenames as $value)
241  {
242  if (strlen($value))
243  {
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  {
253  $tpl->setCurrentBlock("move");
254  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
255  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
256  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
257  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
258  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
259  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
260  $tpl->parseCurrentBlock();
261  }
262 
263  $this->outputSuffixes($tpl, "allowed_image_suffixes");
264 
265  $tpl->setCurrentBlock("row");
266  $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
267  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
268  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
269  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
270  $tpl->setVariable("ALT_ADD", $lng->txt("add"));
271  $tpl->setVariable("ALT_REMOVE", $lng->txt("remove"));
272  if ($this->getDisabled())
273  {
274  $tpl->setVariable("DISABLED",
275  " disabled=\"disabled\"");
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->parseCurrentBlock();
283  $i++;
284  }
285  $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
286 
287  $a_tpl->setCurrentBlock("prop_generic");
288  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
289  $a_tpl->parseCurrentBlock();
290 
291  global $tpl;
292  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
293  $tpl->addJavascript("./Services/Form/templates/default/filewizard.js");
294  }
295 }
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
$error
Definition: Error.php:17
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
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.
setAlert($a_alert)
Set Alert Text.
global $tpl
Definition: ilias.php:8
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.
global $lng
Definition: privfeed.php:17