ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  $pictures = $_FILES[$this->getPostVar()];
118  $uploadcheck = true;
119  if (is_array($pictures))
120  {
121  foreach ($pictures['name'] as $index => $name)
122  {
123  // remove trailing '/'
124  while (substr($name, -1) == '/')
125  {
126  $name = substr($name, 0, -1);
127  }
128 
129  $filename = $name;
130  $filename_arr = pathinfo($name);
131  $suffix = $filename_arr["extension"];
132  $mimetype = $pictures["type"][$index];
133  $size_bytes = $pictures["size"][$index];
134  $temp_name = $pictures["tmp_name"][$index];
135  $error = $pictures["error"][$index];
136  // error handling
137  if ($error > 0)
138  {
139  switch ($error)
140  {
141  case UPLOAD_ERR_INI_SIZE:
142  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
143  $uploadcheck = false;
144  break;
145 
146  case UPLOAD_ERR_FORM_SIZE:
147  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
148  $uploadcheck = false;
149  break;
150 
151  case UPLOAD_ERR_PARTIAL:
152  $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
153  $uploadcheck = false;
154  break;
155 
156  case UPLOAD_ERR_NO_FILE:
157  if ($this->getRequired())
158  {
159  $filename = $this->filenames[$index];
160  if (!strlen($filename))
161  {
162  $this->setAlert($lng->txt("form_msg_file_no_upload"));
163  $uploadcheck = false;
164  }
165  }
166  break;
167 
168  case UPLOAD_ERR_NO_TMP_DIR:
169  $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
170  $uploadcheck = false;
171  break;
172 
173  case UPLOAD_ERR_CANT_WRITE:
174  $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
175  $uploadcheck = false;
176  break;
177 
178  case UPLOAD_ERR_EXTENSION:
179  $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
180  $uploadcheck = false;
181  break;
182  }
183  }
184 
185  // check suffixes
186  if ($pictures["tmp_name"][$index] != "" && is_array($this->getSuffixes()))
187  {
188  if (!in_array(strtolower($suffix), $this->getSuffixes()))
189  {
190  $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
191  $uploadcheck = false;
192  }
193  }
194 
195  // virus handling
196  if ($pictures["tmp_name"][$index] != "")
197  {
198  $vir = ilUtil::virusHandling($temp_name, $filename);
199  if ($vir[0] == false)
200  {
201  $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
202  $uploadcheck = false;
203  }
204  }
205  }
206 
207  }
208 
209  if (!$uploadcheck)
210  {
211  return FALSE;
212  }
213 
214  return $this->checkSubItemsInput();
215  }
216 
222  function insert(&$a_tpl)
223  {
224  global $lng;
225 
226  $tpl = new ilTemplate("tpl.prop_filewizardinput.html", true, true, "Services/Form");
227 
228  $i = 0;
229  foreach ($this->filenames as $value)
230  {
231  if (strlen($value))
232  {
233  $tpl->setCurrentBlock("image");
234  $tpl->setVariable("SRC_IMAGE", $this->getImagePathWeb() . ilUtil::prepareFormOutput($value));
235  $tpl->setVariable("PICTURE_FILE", ilUtil::prepareFormOutput($value));
236  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
237  $tpl->setVariable("ALT_IMAGE", ilUtil::prepareFormOutput($value));
238  $tpl->parseCurrentBlock();
239  }
240  if ($this->getAllowMove())
241  {
242  $tpl->setCurrentBlock("move");
243  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
244  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
245  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
246  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.gif'));
247  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.gif'));
248  $tpl->parseCurrentBlock();
249  }
250 
251  $this->outputSuffixes($tpl, "allowed_image_suffixes");
252 
253  $tpl->setCurrentBlock("row");
254  $class = ($i % 2 == 0) ? "even" : "odd";
255  if ($i == 0) $class .= " first";
256  if ($i == count($this->filenames)-1) $class .= " last";
257  $tpl->setVariable("ROW_CLASS", $class);
258  $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
259  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
260  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
261  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
262  $tpl->setVariable("ALT_ADD", $lng->txt("add"));
263  $tpl->setVariable("ALT_REMOVE", $lng->txt("remove"));
264  if ($this->getDisabled())
265  {
266  $tpl->setVariable("DISABLED",
267  " disabled=\"disabled\"");
268  }
269  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
270  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
271  $tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " . $this->getMaxFileSizeString());
272  $tpl->parseCurrentBlock();
273  $i++;
274  }
275  $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
276 
277  $a_tpl->setCurrentBlock("prop_generic");
278  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
279  $a_tpl->parseCurrentBlock();
280 
281  global $tpl;
282  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
284  $tpl->addJavascript("./Services/Form/templates/default/filewizard.js");
285  }
286 }