ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 while (substr($_FILES[$this->getPostVar()]["name"],-1) == '/')
144 {
145 $_FILES[$this->getPostVar()]["name"] = substr($_FILES[$this->getPostVar()]["name"],0,-1);
146 }
147
148 $filename = $_FILES[$this->getPostVar()]["name"];
149 $filename_arr = pathinfo($_FILES[$this->getPostVar()]["name"]);
150 $suffix = $filename_arr["extension"];
151 $mimetype = $_FILES[$this->getPostVar()]["type"];
152 $size_bytes = $_FILES[$this->getPostVar()]["size"];
153 $temp_name = $_FILES[$this->getPostVar()]["tmp_name"];
154 $error = $_FILES[$this->getPostVar()]["error"];
155
156 // error handling
157 if ($error > 0)
158 {
159 switch ($error)
160 {
161 case UPLOAD_ERR_INI_SIZE:
162 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
163 return false;
164 break;
165
166 case UPLOAD_ERR_FORM_SIZE:
167 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
168 return false;
169 break;
170
171 case UPLOAD_ERR_PARTIAL:
172 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
173 return false;
174 break;
175
176 case UPLOAD_ERR_NO_FILE:
177 if ($this->getRequired())
178 {
179 if (!strlen($this->getValue()))
180 {
181 $this->setAlert($lng->txt("form_msg_file_no_upload"));
182 return false;
183 }
184 }
185 break;
186
187 case UPLOAD_ERR_NO_TMP_DIR:
188 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
189 return false;
190 break;
191
192 case UPLOAD_ERR_CANT_WRITE:
193 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
194 return false;
195 break;
196
197 case UPLOAD_ERR_EXTENSION:
198 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
199 return false;
200 break;
201 }
202 }
203
204 // check suffixes
205 if ($_FILES[$this->getPostVar()]["tmp_name"] != "" &&
206 is_array($this->getSuffixes()))
207 {
208 if (!in_array(strtolower($suffix), $this->getSuffixes()))
209 {
210 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
211 return false;
212 }
213 }
214
215 // virus handling
216 if ($_FILES[$this->getPostVar()]["tmp_name"] != "")
217 {
218 $vir = ilUtil::virusHandling($temp_name, $filename);
219 if ($vir[0] == false)
220 {
221 $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
222 return false;
223 }
224 }
225
226 $max = 0;
227 if (is_array($_POST[$this->getPostVar()]['coords']['name']))
228 {
229 foreach ($_POST[$this->getPostVar()]['coords']['name'] as $idx => $name)
230 {
231 if ((!strlen($_POST[$this->getPostVar()]['coords']['points'][$idx])) && ($this->getRequired))
232 {
233 $this->setAlert($lng->txt('form_msg_area_missing_points'));
234 return false;
235 }
236 if ((!is_numeric($_POST[$this->getPostVar()]['coords']['points'][$idx])))
237 {
238 $this->setAlert($lng->txt('form_msg_numeric_value_required'));
239 return false;
240 }
241 if ($_POST[$this->getPostVar()]['coords']['points'][$idx] > 0) $max = $_POST[$this->getPostVar()]['coords']['points'][$idx];
242 }
243 }
244
245 if ($max == 0 && (!$filename))
246 {
247 $this->setAlert($lng->txt("enter_enough_positive_points"));
248 return false;
249 }
250 return true;
251 }
252
256 function insert(&$a_tpl)
257 {
258 global $lng;
259
260 $template = new ilTemplate("tpl.prop_imagemap_file.html", true, true, "Modules/TestQuestionPool");
261
262 $this->outputSuffixes($template, "allowed_image_suffixes");
263
264 if ($this->getImage() != "")
265 {
266 if (strlen($this->getValue()))
267 {
268 $template->setCurrentBlock("has_value");
269 $template->setVariable("TEXT_IMAGE_NAME", $this->getValue());
270 $template->setVariable("POST_VAR_D", $this->getPostVar());
271 $template->parseCurrentBlock();
272 }
273 $template->setCurrentBlock("image");
274 if (count($this->getAreas()))
275 {
276 include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
277 $preview = new ilImagemapPreview($this->getImagePath().$this->getValue());
278 foreach ($this->getAreas() as $index => $area)
279 {
280 $preview->addArea($index, $area->getArea(), $area->getCoords(), $area->getAnswertext(), "", "", true, $this->getLineColor());
281 }
282 $preview->createPreview();
283 $imagepath = $this->getImagePathWeb() . $preview->getPreviewFilename($this->getImagePath(), $this->getValue()) . "?img=" . time();
284 $template->setVariable("SRC_IMAGE", $imagepath);
285 }
286 else
287 {
288 $template->setVariable("SRC_IMAGE", $this->getImage());
289 }
290 $template->setVariable("ALT_IMAGE", $this->getAlt());
291 $template->setVariable("POST_VAR_D", $this->getPostVar());
292 $template->setVariable("TXT_DELETE_EXISTING",
293 $lng->txt("delete_existing_file"));
294 $template->setVariable("TEXT_ADD_RECT", $lng->txt('add_rect'));
295 $template->setVariable("TEXT_ADD_CIRCLE", $lng->txt('add_circle'));
296 $template->setVariable("TEXT_ADD_POLY", $lng->txt('add_poly'));
297 $template->parseCurrentBlock();
298 }
299
300 if(is_array($this->getAreas()) && $this->getAreas())
301 {
302 $counter = 0;
303 foreach ($this->getAreas() as $area)
304 {
305 if (strlen($area->getPoints()))
306 {
307 $template->setCurrentBlock('area_points_value');
308 $template->setVariable('VALUE_POINTS', $area->getPoints());
309 $template->parseCurrentBlock();
310 }
311 if( $this->getPointsUncheckedFieldEnabled() )
312 {
313 if (strlen($area->getPointsUnchecked()))
314 {
315 $template->setCurrentBlock('area_points_unchecked_value');
316 $template->setVariable('VALUE_POINTS_UNCHECKED', $area->getPointsUnchecked());
317 $template->parseCurrentBlock();
318 }
319
320 $template->setCurrentBlock('area_points_unchecked_field');
321 $template->parseCurrentBlock();
322 }
323 if (strlen($area->getAnswertext()))
324 {
325 $template->setCurrentBlock('area_name_value');
326 $template->setVariable('VALUE_NAME', $area->getAnswertext());
327 $template->parseCurrentBlock();
328 }
329 $template->setCurrentBlock('row');
330 $template->setVariable('POST_VAR_R', $this->getPostVar());
331 $template->setVariable('TEXT_SHAPE', strtoupper($area->getArea()));
332 $template->setVariable('VALUE_SHAPE', $area->getArea());
333 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $area->getCoords());
334 $template->setVariable('VALUE_COORDINATES', $area->getCoords());
335 $template->setVariable('TEXT_COORDINATES', $coords);
336 $template->setVariable('COUNTER', $counter);
337 $template->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
338 $template->parseCurrentBlock();
339 $counter++;
340 }
341 $template->setCurrentBlock("areas");
342 $template->setVariable("TEXT_NAME", $lng->txt("ass_imap_hint"));
343 if( $this->getPointsUncheckedFieldEnabled() )
344 {
345 $template->setVariable("TEXT_POINTS", $lng->txt("points_checked"));
346
347 $template->setCurrentBlock('area_points_unchecked_head');
348 $template->setVariable("TEXT_POINTS_UNCHECKED", $lng->txt("points_unchecked"));
349 $template->parseCurrentBlock();
350 }
351 else
352 {
353 $template->setVariable("TEXT_POINTS", $lng->txt("points"));
354 }
355 $template->setVariable("TEXT_SHAPE", $lng->txt("shape"));
356 $template->setVariable("TEXT_COORDINATES", $lng->txt("coordinates"));
357 $template->setVariable("TEXT_COMMANDS", $lng->txt("actions"));
358 $template->parseCurrentBlock();
359 }
360
361 $template->setVariable("POST_VAR", $this->getPostVar());
362 $template->setVariable("ID", $this->getFieldId());
363 $template->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice")." ".
364 $this->getMaxFileSizeString());
365
366 $a_tpl->setCurrentBlock("prop_generic");
367 $a_tpl->setVariable("PROP_GENERIC", $template->get());
368 $a_tpl->parseCurrentBlock();
369
370 global $tpl;
371 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
372 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/imagemap.js");
373 }
374
375}
global $tpl
Definition: ilias.php:8
Class for true/false or yes/no answers.
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)
__construct($a_title="", $a_postvar="")
Constructor.
setValueByArray($a_values)
Set value by array.
checkInput()
Check input, strip slashes etc.
insert(&$a_tpl)
Insert property html.
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
$_POST['username']
Definition: cron.php:12
$coords
Definition: example_030.php:88
global $lng
Definition: privfeed.php:40
$preview