ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $_FILES[$this->getPostVar()]["name"] = rtrim($_FILES[$this->getPostVar()]["name"], '/');
79
80 $filename = $_FILES[$this->getPostVar()]["name"];
81 $filename_arr = pathinfo($_FILES[$this->getPostVar()]["name"]);
82 $suffix = $filename_arr["extension"];
83 $mimetype = $_FILES[$this->getPostVar()]["type"];
84 $size_bytes = $_FILES[$this->getPostVar()]["size"];
85 $temp_name = $_FILES[$this->getPostVar()]["tmp_name"];
86 $error = $_FILES[$this->getPostVar()]["error"];
87
88 // error handling
89 if ($error > 0)
90 {
91 switch ($error)
92 {
93 case UPLOAD_ERR_INI_SIZE:
94 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
95 return false;
96 break;
97
98 case UPLOAD_ERR_FORM_SIZE:
99 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
100 return false;
101 break;
102
103 case UPLOAD_ERR_PARTIAL:
104 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
105 return false;
106 break;
107
108 case UPLOAD_ERR_NO_FILE:
109 if ($this->getRequired())
110 {
111 if (!strlen($this->getValue()))
112 {
113 $this->setAlert($lng->txt("form_msg_file_no_upload"));
114 return false;
115 }
116 }
117 break;
118
119 case UPLOAD_ERR_NO_TMP_DIR:
120 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
121 return false;
122 break;
123
124 case UPLOAD_ERR_CANT_WRITE:
125 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
126 return false;
127 break;
128
129 case UPLOAD_ERR_EXTENSION:
130 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
131 return false;
132 break;
133 }
134 }
135
136 // check suffixes
137 if ($_FILES[$this->getPostVar()]["tmp_name"] != "" &&
138 is_array($this->getSuffixes()))
139 {
140 if (!in_array(strtolower($suffix), $this->getSuffixes()))
141 {
142 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
143 return false;
144 }
145 }
146
147 // virus handling
148 if ($_FILES[$this->getPostVar()]["tmp_name"] != "")
149 {
150 $vir = ilUtil::virusHandling($temp_name, $filename);
151 if ($vir[0] == false)
152 {
153 $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
154 return false;
155 }
156 }
157
158 if (is_array($_POST[$this->getPostVar()]))
159 {
160 if (($this->getRequired() && strlen($_POST[$this->getPostVar()]['width']) == 0) ||
161 ($this->getRequired() && strlen($_POST[$this->getPostVar()]['height']) == 0))
162 {
163 $this->setAlert($lng->txt("msg_input_is_required"));
164 return false;
165 }
166 if (is_array($_POST[$this->getPostVar()]['flash_param_name']))
167 {
168 foreach ($_POST[$this->getPostVar()]['flash_param_name'] as $idx => $val)
169 {
170 if (strlen($val) == 0 || strlen($_POST[$this->getPostVar()]['flash_param_value'][$idx]) == 0)
171 {
172 $this->setAlert($lng->txt("msg_input_is_required"));
173 return false;
174 }
175 }
176 }
177 }
178
179 return true;
180 }
181
187 function setApplet($a_applet)
188 {
189 $this->applet = $a_applet;
190 }
191
197 function getApplet()
198 {
199 return $this->applet;
200 }
201
207 function setAppletPathWeb($a_path)
208 {
209 $this->applet_path_web = $a_path;
210 }
211
218 {
220 }
221
227 function getWidth()
228 {
229 return $this->width;
230 }
231
237 function setWidth($a_width)
238 {
239 $this->width = $a_width;
240 }
241
247 function getHeight()
248 {
249 return $this->height;
250 }
251
257 function setHeight($a_height)
258 {
259 $this->height = $a_height;
260 }
261
267 function getParameters()
268 {
269 return $this->parameters;
270 }
271
277 function setParameters($a_parameters)
278 {
279 $this->parameters = $a_parameters;
280 }
281
288 function addParameter($name, $value)
289 {
290 $this->parameters[$name] = $value;
291 }
292
298 function removeParameter($name)
299 {
300 unset($this->parameters[$name]);
301 }
302
307 {
308 $this->parameters = array();
309 }
310
314 function insert($a_tpl)
315 {
316 global $lng;
317
318 $template = new ilTemplate("tpl.prop_flashfile.html", true, true, "Services/Form");
319 if ($this->getApplet() != "")
320 {
321 $this->outputSuffixes($template);
322 if (count($this->getParameters()))
323 {
324 $index = 0;
325 $params = array();
326 foreach ($this->getParameters() as $name => $value)
327 {
328 array_push($params, urlencode($name) . "=" . urlencode($value));
329 $template->setCurrentBlock("applet_param_input");
330 $template->setVariable("TEXT_NAME", $lng->txt("name"));
331 $template->setVariable("TEXT_VALUE", $lng->txt("value"));
332 $template->setVariable("PARAM_INDEX", $index);
333 $template->setVariable("POST_VAR_P", $this->getPostVar());
334 $template->setVariable("VALUE_NAME", "value=\"" . ilUtil::prepareFormOutput($name) . "\"");
335 $template->setVariable("VALUE_VALUE", "value=\"" . ilUtil::prepareFormOutput($value) . "\"");
336 $template->setVariable("TEXT_DELETE_PARAM", $lng->txt("delete_parameter"));
337 $template->parseCurrentBlock();
338 $index++;
339 }
340 $template->setCurrentBlock("applet_parameter");
341 $template->setVariable("PARAM_VALUE", join($params, "&"));
342 $template->parseCurrentBlock();
343 $template->setCurrentBlock("flash_vars");
344 $template->setVariable("PARAM_VALUE", join($params, "&"));
345 $template->parseCurrentBlock();
346 }
347 $template->setCurrentBlock("applet");
348 $template->setVariable("TEXT_ADD_PARAM", $lng->txt("add_parameter"));
349 $template->setVariable("APPLET_WIDTH", $this->getWidth());
350 $template->setVariable("APPLET_HEIGHT", $this->getHeight());
351 $template->setVariable("POST_VAR_D", $this->getPostVar());
352 $template->setVariable("FILENAME", $this->getApplet());
353 $template->setVariable("TEXT_WIDTH", $lng->txt("width"));
354 $template->setVariable("TEXT_HEIGHT", $lng->txt("height"));
355 $template->setVariable("APPLET_FILE", $this->getApplet());
356 $template->setVariable("APPLET_PATH", $this->getAppletPathWeb().$this->getApplet());
357 if ($this->getWidth()) $template->setVariable("VALUE_WIDTH", "value=\"" . $this->getWidth() . "\"");
358 if ($this->getHeight()) $template->setVariable("VALUE_HEIGHT", "value=\"" . $this->getHeight() . "\"");
359 $template->setVariable("ID", $this->getFieldId());
360 $template->setVariable("TXT_DELETE_EXISTING",
361 $lng->txt("delete_existing_file"));
362 $template->parseCurrentBlock();
363 }
364
365 $js_tpl = new ilTemplate('tpl.flashAddParam.js', true, true, 'Services/Form');
366 $js_tpl->setVariable("TEXT_NAME", $lng->txt("name"));
367 $js_tpl->setVariable("TEXT_VALUE", $lng->txt("value"));
368 $js_tpl->setVariable("POST_VAR", $this->getPostVar());
369 $js_tpl->setVariable("TEXT_DELETE_PARAM", $lng->txt("delete_parameter"));
370 $js_tpl->setVariable("TEXT_CONFIRM_DELETE_PARAMETER", $lng->txt("confirm_delete_parameter"));
371
372 $template->setVariable("POST_VAR", $this->getPostVar());
373 $template->setVariable("ID", $this->getFieldId());
374 $template->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice")." ".$this->getMaxFileSizeString());
375 $template->setVariable("JAVASCRIPT_FLASH", $js_tpl->get());
376
377 $a_tpl->setCurrentBlock("prop_generic");
378 $a_tpl->setVariable("PROP_GENERIC", $template->get());
379 $a_tpl->parseCurrentBlock();
380
381 global $tpl;
382 include_once "./Services/YUI/classes/class.ilYuiUtil.php";
384 }
385
390 {
391 if ($_POST[$this->getPostVar()."_delete"])
392 {
393 return true;
394 }
395 return false;
396 }
397
398}
399?>
$error
Definition: Error.php:17
global $tpl
Definition: ilias.php:8
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
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.
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.
insert($a_tpl)
Insert property html.
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.
$params
Definition: example_049.php:96
global $lng
Definition: privfeed.php:17