ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilFlashFileInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
16  protected $lng;
17 
18  protected $applet;
19  protected $applet_path_web;
20  protected $width;
21  protected $height;
22  protected $parameters;
23 
30  public function __construct($a_title = "", $a_postvar = "")
31  {
32  global $DIC;
33 
34  $this->lng = $DIC->language();
35  parent::__construct($a_title, $a_postvar);
36  $this->setType("flash_file");
37  $this->setSuffixes(array("swf"));
38  $this->width = 550;
39  $this->height = 400;
40  $this->parameters = array();
41  }
42 
48  public function setValueByArray($a_values)
49  {
50  $this->setValue($a_values[$this->getPostVar()]);
51  }
52 
53  public function getValue()
54  {
55  return $this->getApplet();
56  }
57 
58  public function setValue($a_value)
59  {
60  if (is_array($a_value)) {
61  if (array_key_exists('width', $a_value)) {
62  $this->setWidth($a_value['width']);
63  }
64  if (array_key_exists('height', $a_value)) {
65  $this->setHeight($a_value['height']);
66  }
67  if (array_key_exists('filename', $a_value)) {
68  $this->setApplet($a_value['filename']);
69  }
70  if (is_array($a_value['flash_param_name'])) {
71  $this->parameters = array();
72  foreach ($a_value['flash_param_name'] as $idx => $val) {
73  $this->parameters[$val] = $a_value['flash_param_value'][$idx];
74  }
75  }
76  }
77  }
78 
84  public function checkInput()
85  {
86  $lng = $this->lng;
87 
88  // remove trailing '/'
89  $_FILES[$this->getPostVar()]["name"] = rtrim($_FILES[$this->getPostVar()]["name"], '/');
90 
91  $filename = $_FILES[$this->getPostVar()]["name"];
92  $filename_arr = pathinfo($_FILES[$this->getPostVar()]["name"]);
93  $suffix = $filename_arr["extension"];
94  $mimetype = $_FILES[$this->getPostVar()]["type"];
95  $size_bytes = $_FILES[$this->getPostVar()]["size"];
96  $temp_name = $_FILES[$this->getPostVar()]["tmp_name"];
97  $error = $_FILES[$this->getPostVar()]["error"];
98 
99  // error handling
100  if ($error > 0) {
101  switch ($error) {
102  case UPLOAD_ERR_INI_SIZE:
103  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
104  return false;
105  break;
106 
107  case UPLOAD_ERR_FORM_SIZE:
108  $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
109  return false;
110  break;
111 
112  case UPLOAD_ERR_PARTIAL:
113  $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
114  return false;
115  break;
116 
117  case UPLOAD_ERR_NO_FILE:
118  if ($this->getRequired()) {
119  if (!strlen($this->getValue())) {
120  $this->setAlert($lng->txt("form_msg_file_no_upload"));
121  return false;
122  }
123  }
124  break;
125 
126  case UPLOAD_ERR_NO_TMP_DIR:
127  $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
128  return false;
129  break;
130 
131  case UPLOAD_ERR_CANT_WRITE:
132  $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
133  return false;
134  break;
135 
136  case UPLOAD_ERR_EXTENSION:
137  $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
138  return false;
139  break;
140  }
141  }
142 
143  // check suffixes
144  if ($_FILES[$this->getPostVar()]["tmp_name"] != "" &&
145  is_array($this->getSuffixes())) {
146  if (!in_array(strtolower($suffix), $this->getSuffixes())) {
147  $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
148  return false;
149  }
150  }
151 
152  // virus handling
153  if ($_FILES[$this->getPostVar()]["tmp_name"] != "") {
154  $vir = ilUtil::virusHandling($temp_name, $filename);
155  if ($vir[0] == false) {
156  $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
157  return false;
158  }
159  }
160 
161  if (is_array($_POST[$this->getPostVar()])) {
162  if (($this->getRequired() && strlen($_POST[$this->getPostVar()]['width']) == 0) ||
163  ($this->getRequired() && strlen($_POST[$this->getPostVar()]['height']) == 0)) {
164  $this->setAlert($lng->txt("msg_input_is_required"));
165  return false;
166  }
167  if (is_array($_POST[$this->getPostVar()]['flash_param_name'])) {
168  foreach ($_POST[$this->getPostVar()]['flash_param_name'] as $idx => $val) {
169  if (strlen($val) == 0 || strlen($_POST[$this->getPostVar()]['flash_param_value'][$idx]) == 0) {
170  $this->setAlert($lng->txt("msg_input_is_required"));
171  return false;
172  }
173  }
174  }
175  }
176 
177  return true;
178  }
179 
185  public function setApplet($a_applet)
186  {
187  $this->applet = $a_applet;
188  }
189 
195  public function getApplet()
196  {
197  return $this->applet;
198  }
199 
205  public function setAppletPathWeb($a_path)
206  {
207  $this->applet_path_web = $a_path;
208  }
209 
215  public function getAppletPathWeb()
216  {
217  return $this->applet_path_web;
218  }
219 
225  public function getWidth()
226  {
227  return $this->width;
228  }
229 
235  public function setWidth($a_width)
236  {
237  $this->width = $a_width;
238  }
239 
245  public function getHeight()
246  {
247  return $this->height;
248  }
249 
255  public function setHeight($a_height)
256  {
257  $this->height = $a_height;
258  }
259 
265  public function getParameters()
266  {
267  return $this->parameters;
268  }
269 
275  public function setParameters($a_parameters)
276  {
277  $this->parameters = $a_parameters;
278  }
279 
286  public function addParameter($name, $value)
287  {
288  $this->parameters[$name] = $value;
289  }
290 
296  public function removeParameter($name)
297  {
298  unset($this->parameters[$name]);
299  }
300 
304  public function clearParameters()
305  {
306  $this->parameters = array();
307  }
308 
312  public function insert($a_tpl)
313  {
314  $lng = $this->lng;
315 
316  $template = new ilTemplate("tpl.prop_flashfile.html", true, true, "Services/Form");
317  if ($this->getApplet() != "") {
318  $this->outputSuffixes($template);
319  if (count($this->getParameters())) {
320  $index = 0;
321  $params = array();
322  foreach ($this->getParameters() as $name => $value) {
323  array_push($params, urlencode($name) . "=" . urlencode($value));
324  $template->setCurrentBlock("applet_param_input");
325  $template->setVariable("TEXT_NAME", $lng->txt("name"));
326  $template->setVariable("TEXT_VALUE", $lng->txt("value"));
327  $template->setVariable("PARAM_INDEX", $index);
328  $template->setVariable("POST_VAR_P", $this->getPostVar());
329  $template->setVariable("VALUE_NAME", "value=\"" . ilUtil::prepareFormOutput($name) . "\"");
330  $template->setVariable("VALUE_VALUE", "value=\"" . ilUtil::prepareFormOutput($value) . "\"");
331  $template->setVariable("TEXT_DELETE_PARAM", $lng->txt("delete_parameter"));
332  $template->parseCurrentBlock();
333  $index++;
334  }
335  $template->setCurrentBlock("applet_parameter");
336  $template->setVariable("PARAM_VALUE", join("&", $params));
337  $template->parseCurrentBlock();
338  $template->setCurrentBlock("flash_vars");
339  $template->setVariable("PARAM_VALUE", join("&", $params));
340  $template->parseCurrentBlock();
341  }
342  $template->setCurrentBlock("applet");
343  $template->setVariable("TEXT_ADD_PARAM", $lng->txt("add_parameter"));
344  $template->setVariable("APPLET_WIDTH", $this->getWidth());
345  $template->setVariable("APPLET_HEIGHT", $this->getHeight());
346  $template->setVariable("POST_VAR_D", $this->getPostVar());
347  $template->setVariable("FILENAME", $this->getApplet());
348  $template->setVariable("TEXT_WIDTH", $lng->txt("width"));
349  $template->setVariable("TEXT_HEIGHT", $lng->txt("height"));
350  $template->setVariable("APPLET_FILE", $this->getApplet());
351  $template->setVariable("APPLET_PATH", $this->getAppletPathWeb() . $this->getApplet());
352  if ($this->getWidth()) {
353  $template->setVariable("VALUE_WIDTH", "value=\"" . $this->getWidth() . "\"");
354  }
355  if ($this->getHeight()) {
356  $template->setVariable("VALUE_HEIGHT", "value=\"" . $this->getHeight() . "\"");
357  }
358  $template->setVariable("ID", $this->getFieldId());
359  $template->setVariable(
360  "TXT_DELETE_EXISTING",
361  $lng->txt("delete_existing_file")
362  );
363  $template->parseCurrentBlock();
364  }
365 
366  $js_tpl = new ilTemplate('tpl.flashAddParam.js', true, true, 'Services/Form');
367  $js_tpl->setVariable("TEXT_NAME", $lng->txt("name"));
368  $js_tpl->setVariable("TEXT_VALUE", $lng->txt("value"));
369  $js_tpl->setVariable("POST_VAR", $this->getPostVar());
370  $js_tpl->setVariable("TEXT_DELETE_PARAM", $lng->txt("delete_parameter"));
371  $js_tpl->setVariable("TEXT_CONFIRM_DELETE_PARAMETER", $lng->txt("confirm_delete_parameter"));
372 
373  $template->setVariable("POST_VAR", $this->getPostVar());
374  $template->setVariable("ID", $this->getFieldId());
375  $template->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " . $this->getMaxFileSizeString());
376  $template->setVariable("JAVASCRIPT_FLASH", $js_tpl->get());
377 
378  $a_tpl->setCurrentBlock("prop_generic");
379  $a_tpl->setVariable("PROP_GENERIC", $template->get());
380  $a_tpl->parseCurrentBlock();
381 
382  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
384  }
385 
389  public function getDeletionFlag()
390  {
391  if ($_POST[$this->getPostVar() . "_delete"]) {
392  return true;
393  }
394  return false;
395  }
396 }
getSuffixes()
Get Accepted Suffixes.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
setParameters($a_parameters)
Set parameters.
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
setHeight($a_height)
Set height.
$template
global $DIC
Definition: saml.php:7
clearParameters()
Remove all parameters.
getPostVar()
Get Post Variable.
This class represents a file property in a property form.
This class represents an image file property in a property form.
removeParameter($name)
Remove parameter.
__construct($a_title="", $a_postvar="")
Constructor.
setValueByArray($a_values)
Set value by array.
$index
Definition: metadata.php:60
setAlert($a_alert)
Set Alert Text.
checkInput()
Check input, strip slashes etc.
setType($a_type)
Set Type.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
setApplet($a_applet)
Set applet.
outputSuffixes($a_tpl, $a_block="allowed_suffixes")
setAppletPathWeb($a_path)
Set applet.path web.
addParameter($name, $value)
Add parameter.
getAppletPathWeb()
Get applet.path web.
insert($a_tpl)
Insert property html.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
$_POST["username"]
setWidth($a_width)
Set width.
static initConnectionWithAnimation()
Init YUI Connection module.
getDeletionFlag()
Get deletion flag.