ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilImagemapFileInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
5
13include_once "./Services/Form/classes/class.ilImageFileInputGUI.php";
14
16{
17 protected $areas = array();
18 protected $image_path = "";
19 protected $image_path_web = "";
20 protected $line_color = "";
21
23
30 function __construct($a_title = "", $a_postvar = "")
31 {
32 global $lng;
33
34 parent::__construct($a_title, $a_postvar);
35 }
36
38 {
39 $this->pointsUncheckedFieldEnabled = (bool)$pointsUncheckedFieldEnabled;
40 }
41
43 {
45 }
46
47 public function setAreas($a_areas)
48 {
49 $this->areas = $a_areas;
50 }
51
52 public function getLineColor()
53 {
54 return $this->line_color;
55 }
56
57 public function setLineColor($a_color)
58 {
59 $this->line_color = $a_color;
60 }
61
62 public function getImagePath()
63 {
64 return $this->image_path;
65 }
66
67 public function setImagePath($a_path)
68 {
69 $this->image_path = $a_path;
70 }
71
72 public function getImagePathWeb()
73 {
75 }
76
77 public function setImagePathWeb($a_path_web)
78 {
79 $this->image_path_web = $a_path_web;
80 }
81
82 public function setAreasByArray($a_areas)
83 {
84 if (is_array($a_areas['name']))
85 {
86 $this->areas = array();
87 include_once "./Modules/TestQuestionPool/classes/class.assAnswerImagemap.php";
88 foreach ($a_areas['name'] as $idx => $name)
89 {
90 if( $this->getPointsUncheckedFieldEnabled() && isset($a_areas['points_unchecked']) )
91 {
92 $pointsUnchecked = $a_areas['points_unchecked'][$idx];
93 }
94 else
95 {
96 $pointsUnchecked = 0.0;
97 }
98
99 array_push($this->areas, new ASS_AnswerImagemap(
100 $name,
101 $a_areas['points'][$idx],
102 $idx,
103 $a_areas['coords'][$idx], $a_areas['shape'][$idx],
104 -1,
105 $pointsUnchecked
106 ));
107 }
108 }
109 }
110
111 public function getAreas()
112 {
113 return $this->areas;
114 }
115
121 function setValueByArray($a_values)
122 {
123 $this->setValue($a_values[$this->getPostVar() . '_name']);
124 $this->setAreasByArray($a_values[$this->getPostVar()]['coords']);
125 }
126
127 public function setValue($a_value)
128 {
129 parent::setValue($a_value);
130 }
131
137 function checkInput()
138 {
139 global $lng;
140
141 if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
142 // remove trailing '/'
143 $_FILES[$this->getPostVar()]["name"] = rtrim($_FILES[$this->getPostVar()]["name"], '/');
144
145 $filename = $_FILES[$this->getPostVar()]["name"];
146 $filename_arr = pathinfo($_FILES[$this->getPostVar()]["name"]);
147 $suffix = $filename_arr["extension"];
148 $mimetype = $_FILES[$this->getPostVar()]["type"];
149 $size_bytes = $_FILES[$this->getPostVar()]["size"];
150 $temp_name = $_FILES[$this->getPostVar()]["tmp_name"];
151 $error = $_FILES[$this->getPostVar()]["error"];
152
153 // error handling
154 if ($error > 0)
155 {
156 switch ($error)
157 {
158 case UPLOAD_ERR_INI_SIZE:
159 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
160 return false;
161 break;
162
163 case UPLOAD_ERR_FORM_SIZE:
164 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
165 return false;
166 break;
167
168 case UPLOAD_ERR_PARTIAL:
169 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
170 return false;
171 break;
172
173 case UPLOAD_ERR_NO_FILE:
174 if ($this->getRequired())
175 {
176 if (!strlen($this->getValue()))
177 {
178 $this->setAlert($lng->txt("form_msg_file_no_upload"));
179 return false;
180 }
181 }
182 break;
183
184 case UPLOAD_ERR_NO_TMP_DIR:
185 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
186 return false;
187 break;
188
189 case UPLOAD_ERR_CANT_WRITE:
190 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
191 return false;
192 break;
193
194 case UPLOAD_ERR_EXTENSION:
195 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
196 return false;
197 break;
198 }
199 }
200
201 // check suffixes
202 if ($_FILES[$this->getPostVar()]["tmp_name"] != "" &&
203 is_array($this->getSuffixes()))
204 {
205 if (!in_array(strtolower($suffix), $this->getSuffixes()))
206 {
207 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
208 return false;
209 }
210 }
211
212 // virus handling
213 if ($_FILES[$this->getPostVar()]["tmp_name"] != "")
214 {
215 $vir = ilUtil::virusHandling($temp_name, $filename);
216 if ($vir[0] == false)
217 {
218 $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
219 return false;
220 }
221 }
222
223 $max = 0;
224 if (is_array($_POST[$this->getPostVar()]['coords']['name']))
225 {
226 foreach ($_POST[$this->getPostVar()]['coords']['name'] as $idx => $name)
227 {
228 if ((!strlen($_POST[$this->getPostVar()]['coords']['points'][$idx])) && ($this->getRequired))
229 {
230 $this->setAlert($lng->txt('form_msg_area_missing_points'));
231 return false;
232 }
233 if ((!is_numeric($_POST[$this->getPostVar()]['coords']['points'][$idx])))
234 {
235 $this->setAlert($lng->txt('form_msg_numeric_value_required'));
236 return false;
237 }
238 if ($_POST[$this->getPostVar()]['coords']['points'][$idx] > 0) $max = $_POST[$this->getPostVar()]['coords']['points'][$idx];
239 }
240 }
241
242 if ($max == 0 && (!$filename) && !$_FILES['imagemapfile']['tmp_name'])
243 {
244 $this->setAlert($lng->txt("enter_enough_positive_points"));
245 return false;
246 }
247 return true;
248 }
249
253 function insert($a_tpl)
254 {
255 global $lng;
256
257 $template = new ilTemplate("tpl.prop_imagemap_file.html", true, true, "Modules/TestQuestionPool");
258
259 $this->outputSuffixes($template, "allowed_image_suffixes");
260
261 if ($this->getImage() != "")
262 {
263 if (strlen($this->getValue()))
264 {
265 $template->setCurrentBlock("has_value");
266 $template->setVariable("TEXT_IMAGE_NAME", $this->getValue());
267 $template->setVariable("POST_VAR_D", $this->getPostVar());
268 $template->parseCurrentBlock();
269 }
270 $template->setCurrentBlock("image");
271 if (count($this->getAreas()))
272 {
273 include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
274 $preview = new ilImagemapPreview($this->getImagePath().$this->getValue());
275 foreach ($this->getAreas() as $index => $area)
276 {
277 $preview->addArea($index, $area->getArea(), $area->getCoords(), $area->getAnswertext(), "", "", true, $this->getLineColor());
278 }
279 $preview->createPreview();
280 $imagepath = $this->getImagePathWeb() . $preview->getPreviewFilename($this->getImagePath(), $this->getValue()) . "?img=" . time();
281 $template->setVariable("SRC_IMAGE", $imagepath);
282 }
283 else
284 {
285 $template->setVariable("SRC_IMAGE", $this->getImage());
286 }
287 $template->setVariable("ALT_IMAGE", $this->getAlt());
288 $template->setVariable("POST_VAR_D", $this->getPostVar());
289 $template->setVariable("TXT_DELETE_EXISTING",
290 $lng->txt("delete_existing_file"));
291 $template->setVariable("TEXT_ADD_RECT", $lng->txt('add_rect'));
292 $template->setVariable("TEXT_ADD_CIRCLE", $lng->txt('add_circle'));
293 $template->setVariable("TEXT_ADD_POLY", $lng->txt('add_poly'));
294 $template->parseCurrentBlock();
295 }
296
297 if(is_array($this->getAreas()) && $this->getAreas())
298 {
299 $counter = 0;
300 foreach ($this->getAreas() as $area)
301 {
302 if (strlen($area->getPoints()))
303 {
304 $template->setCurrentBlock('area_points_value');
305 $template->setVariable('VALUE_POINTS', $area->getPoints());
306 $template->parseCurrentBlock();
307 }
308 if( $this->getPointsUncheckedFieldEnabled() )
309 {
310 if (strlen($area->getPointsUnchecked()))
311 {
312 $template->setCurrentBlock('area_points_unchecked_value');
313 $template->setVariable('VALUE_POINTS_UNCHECKED', $area->getPointsUnchecked());
314 $template->parseCurrentBlock();
315 }
316
317 $template->setCurrentBlock('area_points_unchecked_field');
318 $template->parseCurrentBlock();
319 }
320 if (strlen($area->getAnswertext()))
321 {
322 $template->setCurrentBlock('area_name_value');
323 $template->setVariable('VALUE_NAME', $area->getAnswertext());
324 $template->parseCurrentBlock();
325 }
326 $template->setCurrentBlock('row');
327 $template->setVariable('POST_VAR_R', $this->getPostVar());
328 $template->setVariable('TEXT_SHAPE', strtoupper($area->getArea()));
329 $template->setVariable('VALUE_SHAPE', $area->getArea());
330 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $area->getCoords());
331 $template->setVariable('VALUE_COORDINATES', $area->getCoords());
332 $template->setVariable('TEXT_COORDINATES', $coords);
333 $template->setVariable('COUNTER', $counter);
334 $template->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
335 $template->parseCurrentBlock();
336 $counter++;
337 }
338 $template->setCurrentBlock("areas");
339 $template->setVariable("TEXT_NAME", $lng->txt("ass_imap_hint"));
340 if( $this->getPointsUncheckedFieldEnabled() )
341 {
342 $template->setVariable("TEXT_POINTS", $lng->txt("points_checked"));
343
344 $template->setCurrentBlock('area_points_unchecked_head');
345 $template->setVariable("TEXT_POINTS_UNCHECKED", $lng->txt("points_unchecked"));
346 $template->parseCurrentBlock();
347 }
348 else
349 {
350 $template->setVariable("TEXT_POINTS", $lng->txt("points"));
351 }
352 $template->setVariable("TEXT_SHAPE", $lng->txt("shape"));
353 $template->setVariable("TEXT_COORDINATES", $lng->txt("coordinates"));
354 $template->setVariable("TEXT_COMMANDS", $lng->txt("actions"));
355 $template->parseCurrentBlock();
356 }
357
358 $template->setVariable("POST_VAR", $this->getPostVar());
359 $template->setVariable("ID", $this->getFieldId());
360 $template->setVariable("TXT_BROWSE", $lng->txt("select_file"));
361 $template->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice")." ".
362 $this->getMaxFileSizeString());
363
364 $a_tpl->setCurrentBlock("prop_generic");
365 $a_tpl->setVariable("PROP_GENERIC", $template->get());
366 $a_tpl->parseCurrentBlock();
367
368 global $tpl;
369 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
370 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/imagemap.js");
371 }
372
373}
$error
Definition: Error.php:17
global $tpl
Definition: ilias.php:8
$_POST["username"]
Class for true/false or yes/no answers.
An exception for terminatinating execution or to throw for unit testing.
outputSuffixes($a_tpl, $a_block="allowed_suffixes")
getSuffixes()
Get Accepted Suffixes.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents an image file property in a property form.
getAlt()
Get Alternative Text.
This class represents an image map file property in a property form.
setPointsUncheckedFieldEnabled($pointsUncheckedFieldEnabled)
insert($a_tpl)
Insert property html.
__construct($a_title="", $a_postvar="")
Constructor.
setValueByArray($a_values)
Set value by array.
checkInput()
Check input, strip slashes etc.
Image map image preview creator.
special template class to simplify handling of ITX/PEAR
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
$counter
$coords
Definition: example_030.php:88
global $lng
Definition: privfeed.php:17
$preview