ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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  while (substr($name, -1) == '/')
134  {
135  $name = substr($name, 0, -1);
136  }
137 
138  $filename = $name;
139  $filename_arr = pathinfo($name);
140  $suffix = $filename_arr["extension"];
141  $mimetype = $pictures["type"][$index];
142  $size_bytes = $pictures["size"][$index];
143  $temp_name = $pictures["tmp_name"][$index];
144  $error = $pictures["error"][$index];
145  // error handling
146  if ($error > 0)
147  {
148  switch ($error)
149  {
150  case UPLOAD_ERR_INI_SIZE:
151  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
152  $uploadcheck = false;
153  break;
154 
155  case UPLOAD_ERR_FORM_SIZE:
156  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
157  $uploadcheck = false;
158  break;
159 
160  case UPLOAD_ERR_PARTIAL:
161  $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
162  $uploadcheck = false;
163  break;
164 
165  case UPLOAD_ERR_NO_FILE:
166  if ($this->getRequired())
167  {
168  $filename = $this->filenames[$index];
169  if (!strlen($filename))
170  {
171  $this->setAlert($lng->txt("form_msg_file_no_upload"));
172  $uploadcheck = false;
173  }
174  }
175  break;
176 
177  case UPLOAD_ERR_NO_TMP_DIR:
178  $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
179  $uploadcheck = false;
180  break;
181 
182  case UPLOAD_ERR_CANT_WRITE:
183  $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
184  $uploadcheck = false;
185  break;
186 
187  case UPLOAD_ERR_EXTENSION:
188  $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
189  $uploadcheck = false;
190  break;
191  }
192  }
193 
194  // check suffixes
195  if ($pictures["tmp_name"][$index] != "" && is_array($this->getSuffixes()))
196  {
197  if (!in_array(strtolower($suffix), $this->getSuffixes()))
198  {
199  $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
200  $uploadcheck = false;
201  }
202  }
203 
204  // virus handling
205  if ($pictures["tmp_name"][$index] != "")
206  {
207  $vir = ilUtil::virusHandling($temp_name, $filename);
208  if ($vir[0] == false)
209  {
210  $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
211  $uploadcheck = false;
212  }
213  }
214  }
215 
216  }
217 
218  if (!$uploadcheck)
219  {
220  return FALSE;
221  }
222 
223  return $this->checkSubItemsInput();
224  }
225 
231  function insert(&$a_tpl)
232  {
233  global $lng;
234 
235  $tpl = new ilTemplate("tpl.prop_filewizardinput.html", true, true, "Services/Form");
236 
237  $i = 0;
238  foreach ($this->filenames as $value)
239  {
240  if (strlen($value))
241  {
242  $tpl->setCurrentBlock("image");
243  $tpl->setVariable("SRC_IMAGE", $this->getImagePathWeb() . ilUtil::prepareFormOutput($value));
244  $tpl->setVariable("PICTURE_FILE", ilUtil::prepareFormOutput($value));
245  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
246  $tpl->setVariable("ALT_IMAGE", ilUtil::prepareFormOutput($value));
247  $tpl->parseCurrentBlock();
248  }
249  if ($this->getAllowMove())
250  {
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  {
272  $tpl->setVariable("DISABLED",
273  " disabled=\"disabled\"");
274  }
275 
276  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
277  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
278  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
279  $tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " . $this->getMaxFileSizeString());
280  $tpl->parseCurrentBlock();
281  $i++;
282  }
283  $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
284 
285  $a_tpl->setCurrentBlock("prop_generic");
286  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
287  $a_tpl->parseCurrentBlock();
288 
289  global $tpl;
290  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
291  $tpl->addJavascript("./Services/Form/templates/default/filewizard.js");
292  }
293 }
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
getPostVar()
Get Post Variable.
This class represents a file property in a property form.
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.
insert(&$a_tpl)
Insert property html.
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")
getImagePathWeb()
Get the web image path.
setFilenames($a_filenames)
Set filenames.
global $lng
Definition: privfeed.php:40