ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
13 protected $applet;
15 protected $width;
16 protected $height;
17 protected $parameters;
18
25 function __construct($a_title = "", $a_postvar = "")
26 {
27 parent::__construct($a_title, $a_postvar);
28 $this->setType("flash_file");
29 $this->setSuffixes(array("swf"));
30 $this->width = 550;
31 $this->height = 400;
32 $this->parameters = array();
33 }
34
40 function setValueByArray($a_values)
41 {
42 $this->setValue($a_values[$this->getPostVar()]);
43 }
44
45 function getValue()
46 {
47 return $this->getApplet();
48 }
49
50 function setValue($a_value)
51 {
52 if (is_array($a_value))
53 {
54 if (array_key_exists('width', $a_value)) $this->setWidth($a_value['width']);
55 if (array_key_exists('height', $a_value)) $this->setHeight($a_value['height']);
56 if (array_key_exists('filename', $a_value)) $this->setApplet($a_value['filename']);
57 if (is_array($a_value['flash_param_name']))
58 {
59 $this->parameters = array();
60 foreach ($a_value['flash_param_name'] as $idx => $val)
61 {
62 $this->parameters[$val] = $a_value['flash_param_value'][$idx];
63 }
64 }
65 }
66 }
67
73 function checkInput()
74 {
75 global $lng;
76
77 // remove trailing '/'
78 while (substr($_FILES[$this->getPostVar()]["name"],-1) == '/')
79 {
80 $_FILES[$this->getPostVar()]["name"] = substr($_FILES[$this->getPostVar()]["name"],0,-1);
81 }
82
83 $filename = $_FILES[$this->getPostVar()]["name"];
84 $filename_arr = pathinfo($_FILES[$this->getPostVar()]["name"]);
85 $suffix = $filename_arr["extension"];
86 $mimetype = $_FILES[$this->getPostVar()]["type"];
87 $size_bytes = $_FILES[$this->getPostVar()]["size"];
88 $temp_name = $_FILES[$this->getPostVar()]["tmp_name"];
89 $error = $_FILES[$this->getPostVar()]["error"];
90
91 // error handling
92 if ($error > 0)
93 {
94 switch ($error)
95 {
96 case UPLOAD_ERR_INI_SIZE:
97 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
98 return false;
99 break;
100
101 case UPLOAD_ERR_FORM_SIZE:
102 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
103 return false;
104 break;
105
106 case UPLOAD_ERR_PARTIAL:
107 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
108 return false;
109 break;
110
111 case UPLOAD_ERR_NO_FILE:
112 if ($this->getRequired())
113 {
114 if (!strlen($this->getValue()))
115 {
116 $this->setAlert($lng->txt("form_msg_file_no_upload"));
117 return false;
118 }
119 }
120 break;
121
122 case UPLOAD_ERR_NO_TMP_DIR:
123 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
124 return false;
125 break;
126
127 case UPLOAD_ERR_CANT_WRITE:
128 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
129 return false;
130 break;
131
132 case UPLOAD_ERR_EXTENSION:
133 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
134 return false;
135 break;
136 }
137 }
138
139 // check suffixes
140 if ($_FILES[$this->getPostVar()]["tmp_name"] != "" &&
141 is_array($this->getSuffixes()))
142 {
143 if (!in_array(strtolower($suffix), $this->getSuffixes()))
144 {
145 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
146 return false;
147 }
148 }
149
150 // virus handling
151 if ($_FILES[$this->getPostVar()]["tmp_name"] != "")
152 {
153 $vir = ilUtil::virusHandling($temp_name, $filename);
154 if ($vir[0] == false)
155 {
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 {
163 if (($this->getRequired() && strlen($_POST[$this->getPostVar()]['width']) == 0) ||
164 ($this->getRequired() && strlen($_POST[$this->getPostVar()]['height']) == 0))
165 {
166 $this->setAlert($lng->txt("msg_input_is_required"));
167 return false;
168 }
169 if (is_array($_POST[$this->getPostVar()]['flash_param_name']))
170 {
171 foreach ($_POST[$this->getPostVar()]['flash_param_name'] as $idx => $val)
172 {
173 if (strlen($val) == 0 || strlen($_POST[$this->getPostVar()]['flash_param_value'][$idx]) == 0)
174 {
175 $this->setAlert($lng->txt("msg_input_is_required"));
176 return false;
177 }
178 }
179 }
180 }
181
182 return true;
183 }
184
190 function setApplet($a_applet)
191 {
192 $this->applet = $a_applet;
193 }
194
200 function getApplet()
201 {
202 return $this->applet;
203 }
204
210 function setAppletPathWeb($a_path)
211 {
212 $this->applet_path_web = $a_path;
213 }
214
221 {
223 }
224
230 function getWidth()
231 {
232 return $this->width;
233 }
234
240 function setWidth($a_width)
241 {
242 $this->width = $a_width;
243 }
244
250 function getHeight()
251 {
252 return $this->height;
253 }
254
260 function setHeight($a_height)
261 {
262 $this->height = $a_height;
263 }
264
270 function getParameters()
271 {
272 return $this->parameters;
273 }
274
280 function setParameters($a_parameters)
281 {
282 $this->parameters = $a_parameters;
283 }
284
291 function addParameter($name, $value)
292 {
293 $this->parameters[$name] = $value;
294 }
295
301 function removeParameter($name)
302 {
303 unset($this->parameters[$name]);
304 }
305
310 {
311 $this->parameters = array();
312 }
313
317 function insert(&$a_tpl)
318 {
319 global $lng;
320
321 $template = new ilTemplate("tpl.prop_flashfile.html", true, true, "Services/Form");
322 if ($this->getApplet() != "")
323 {
324 $this->outputSuffixes($template);
325 if (count($this->getParameters()))
326 {
327 $index = 0;
328 $params = array();
329 foreach ($this->getParameters() as $name => $value)
330 {
331 array_push($params, urlencode($name) . "=" . urlencode($value));
332 $template->setCurrentBlock("applet_param_input");
333 $template->setVariable("TEXT_NAME", $lng->txt("name"));
334 $template->setVariable("TEXT_VALUE", $lng->txt("value"));
335 $template->setVariable("PARAM_INDEX", $index);
336 $template->setVariable("POST_VAR_P", $this->getPostVar());
337 $template->setVariable("VALUE_NAME", "value=\"" . ilUtil::prepareFormOutput($name) . "\"");
338 $template->setVariable("VALUE_VALUE", "value=\"" . ilUtil::prepareFormOutput($value) . "\"");
339 $template->setVariable("TEXT_DELETE_PARAM", $lng->txt("delete_parameter"));
340 $template->parseCurrentBlock();
341 $index++;
342 }
343 $template->setCurrentBlock("applet_parameter");
344 $template->setVariable("PARAM_VALUE", join($params, "&"));
345 $template->parseCurrentBlock();
346 $template->setCurrentBlock("flash_vars");
347 $template->setVariable("PARAM_VALUE", join($params, "&"));
348 $template->parseCurrentBlock();
349 }
350 $template->setCurrentBlock("applet");
351 $template->setVariable("TEXT_ADD_PARAM", $lng->txt("add_parameter"));
352 $template->setVariable("APPLET_WIDTH", $this->getWidth());
353 $template->setVariable("APPLET_HEIGHT", $this->getHeight());
354 $template->setVariable("POST_VAR_D", $this->getPostVar());
355 $template->setVariable("FILENAME", $this->getApplet());
356 $template->setVariable("TEXT_WIDTH", $lng->txt("width"));
357 $template->setVariable("TEXT_HEIGHT", $lng->txt("height"));
358 $template->setVariable("APPLET_FILE", $this->getApplet());
359 $template->setVariable("APPLET_PATH", $this->getAppletPathWeb().$this->getApplet());
360 if ($this->getWidth()) $template->setVariable("VALUE_WIDTH", "value=\"" . $this->getWidth() . "\"");
361 if ($this->getHeight()) $template->setVariable("VALUE_HEIGHT", "value=\"" . $this->getHeight() . "\"");
362 $template->setVariable("ID", $this->getFieldId());
363 $template->setVariable("TXT_DELETE_EXISTING",
364 $lng->txt("delete_existing_file"));
365 $template->parseCurrentBlock();
366 }
367
368 $js_tpl = new ilTemplate('tpl.flashAddParam.js', true, true, 'Services/Form');
369 $js_tpl->setVariable("TEXT_NAME", $lng->txt("name"));
370 $js_tpl->setVariable("TEXT_VALUE", $lng->txt("value"));
371 $js_tpl->setVariable("POST_VAR", $this->getPostVar());
372 $js_tpl->setVariable("TEXT_DELETE_PARAM", $lng->txt("delete_parameter"));
373 $js_tpl->setVariable("TEXT_CONFIRM_DELETE_PARAMETER", $lng->txt("confirm_delete_parameter"));
374
375 $template->setVariable("POST_VAR", $this->getPostVar());
376 $template->setVariable("ID", $this->getFieldId());
377 $template->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice")." ".$this->getMaxFileSizeString());
378 $template->setVariable("JAVASCRIPT_FLASH", $js_tpl->get());
379
380 $a_tpl->setCurrentBlock("prop_generic");
381 $a_tpl->setVariable("PROP_GENERIC", $template->get());
382 $a_tpl->parseCurrentBlock();
383
384 global $tpl;
385 include_once "./Services/YUI/classes/class.ilYuiUtil.php";
387 }
388
393 {
394 if ($_POST[$this->getPostVar()."_delete"])
395 {
396 return true;
397 }
398 return false;
399 }
400
401}
402?>
global $tpl
Definition: ilias.php:8
This class represents a file property in a property form.
outputSuffixes($a_tpl, $a_block="allowed_suffixes")
getSuffixes()
Get Accepted Suffixes.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
This class represents an image file property in a property form.
insert(&$a_tpl)
Insert property html.
setAppletPathWeb($a_path)
Set applet.path web.
checkInput()
Check input, strip slashes etc.
setApplet($a_applet)
Set applet.
getDeletionFlag()
Get deletion flag.
setHeight($a_height)
Set height.
removeParameter($name)
Remove parameter.
__construct($a_title="", $a_postvar="")
Constructor.
getAppletPathWeb()
Get applet.path web.
addParameter($name, $value)
Add parameter.
setValue($a_value)
Set Value.
setParameters($a_parameters)
Set parameters.
clearParameters()
Remove all parameters.
setValueByArray($a_values)
Set value by array.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
static initConnectionWithAnimation()
Init YUI Connection module.
$_POST['username']
Definition: cron.php:12
$params
Definition: example_049.php:96
global $lng
Definition: privfeed.php:40