ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 public function __construct($a_title = "", $a_postvar = "")
31 {
32 global $DIC;
33 $lng = $DIC['lng'];
34
35 parent::__construct($a_title, $a_postvar);
36 }
37
39 {
40 $this->pointsUncheckedFieldEnabled = (bool) $pointsUncheckedFieldEnabled;
41 }
42
44 {
46 }
47
48 public function setAreas($a_areas)
49 {
50 $this->areas = $a_areas;
51 }
52
53 public function getLineColor()
54 {
55 return $this->line_color;
56 }
57
58 public function setLineColor($a_color)
59 {
60 $this->line_color = $a_color;
61 }
62
63 public function getImagePath()
64 {
65 return $this->image_path;
66 }
67
68 public function setImagePath($a_path)
69 {
70 $this->image_path = $a_path;
71 }
72
73 public function getImagePathWeb()
74 {
76 }
77
78 public function setImagePathWeb($a_path_web)
79 {
80 $this->image_path_web = $a_path_web;
81 }
82
83 public function setAreasByArray($a_areas)
84 {
85 if (is_array($a_areas['name'])) {
86 $this->areas = array();
87 include_once "./Modules/TestQuestionPool/classes/class.assAnswerImagemap.php";
88 foreach ($a_areas['name'] as $idx => $name) {
89 if ($this->getPointsUncheckedFieldEnabled() && isset($a_areas['points_unchecked'])) {
90 $pointsUnchecked = $a_areas['points_unchecked'][$idx];
91 } else {
92 $pointsUnchecked = 0.0;
93 }
94
95 array_push($this->areas, new ASS_AnswerImagemap(
96 $name,
97 $a_areas['points'][$idx],
98 $idx,
99 $a_areas['coords'][$idx],
100 $a_areas['shape'][$idx],
101 -1,
102 $pointsUnchecked
103 ));
104 }
105 }
106 }
107
108 public function getAreas()
109 {
110 return $this->areas;
111 }
112
118 public function setValueByArray($a_values)
119 {
120 $this->setValue($a_values[$this->getPostVar() . '_name']);
121 $this->setAreasByArray($a_values[$this->getPostVar()]['coords']);
122 }
123
124 public function setValue($a_value)
125 {
126 parent::setValue($a_value);
127 }
128
134 public function checkInput()
135 {
136 global $DIC;
137 $lng = $DIC['lng'];
138
139 if (is_array($_POST[$this->getPostVar()])) {
141 }
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 switch ($error) {
156 case UPLOAD_ERR_INI_SIZE:
157 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
158 return false;
159 break;
160
161 case UPLOAD_ERR_FORM_SIZE:
162 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
163 return false;
164 break;
165
166 case UPLOAD_ERR_PARTIAL:
167 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
168 return false;
169 break;
170
171 case UPLOAD_ERR_NO_FILE:
172 if ($this->getRequired()) {
173 if (!strlen($this->getValue())) {
174 $this->setAlert($lng->txt("form_msg_file_no_upload"));
175 return false;
176 }
177 }
178 break;
179
180 case UPLOAD_ERR_NO_TMP_DIR:
181 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
182 return false;
183 break;
184
185 case UPLOAD_ERR_CANT_WRITE:
186 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
187 return false;
188 break;
189
190 case UPLOAD_ERR_EXTENSION:
191 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
192 return false;
193 break;
194 }
195 }
196
197 // check suffixes
198 if ($_FILES[$this->getPostVar()]["tmp_name"] != "" &&
199 is_array($this->getSuffixes())) {
200 if (!in_array(strtolower($suffix), $this->getSuffixes())) {
201 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
202 return false;
203 }
204 }
205
206 // virus handling
207 if ($_FILES[$this->getPostVar()]["tmp_name"] != "") {
208 $vir = ilUtil::virusHandling($temp_name, $filename);
209 if ($vir[0] == false) {
210 $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
211 return false;
212 }
213 }
214
215 $max = 0;
216 if (is_array($_POST[$this->getPostVar()]['coords']['name'])) {
217 foreach ($_POST[$this->getPostVar()]['coords']['name'] as $idx => $name) {
218 if ((!strlen($_POST[$this->getPostVar()]['coords']['points'][$idx])) && ($this->getRequired)) {
219 $this->setAlert($lng->txt('form_msg_area_missing_points'));
220 return false;
221 }
222 if ((!is_numeric($_POST[$this->getPostVar()]['coords']['points'][$idx]))) {
223 $this->setAlert($lng->txt('form_msg_numeric_value_required'));
224 return false;
225 }
226 if ($_POST[$this->getPostVar()]['coords']['points'][$idx] > 0) {
227 $max = $_POST[$this->getPostVar()]['coords']['points'][$idx];
228 }
229 }
230 }
231
232 if ($max == 0 && (!$filename) && !$_FILES['imagemapfile']['tmp_name']) {
233 $this->setAlert($lng->txt("enter_enough_positive_points"));
234 return false;
235 }
236 return true;
237 }
238
242 public function insert($a_tpl)
243 {
244 global $DIC;
245 $lng = $DIC['lng'];
246
247 $template = new ilTemplate("tpl.prop_imagemap_file.html", true, true, "Modules/TestQuestionPool");
248
249 $this->outputSuffixes($template, "allowed_image_suffixes");
250
251 if ($this->getImage() != "") {
252 if (strlen($this->getValue())) {
253 $template->setCurrentBlock("has_value");
254 $template->setVariable("TEXT_IMAGE_NAME", $this->getValue());
255 $template->setVariable("POST_VAR_D", $this->getPostVar());
256 $template->parseCurrentBlock();
257 }
258 $template->setCurrentBlock("image");
259 if (count($this->getAreas())) {
260 include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
261 $preview = new ilImagemapPreview($this->getImagePath() . $this->getValue());
262 foreach ($this->getAreas() as $index => $area) {
263 $preview->addArea($index, $area->getArea(), $area->getCoords(), $area->getAnswertext(), "", "", true, $this->getLineColor());
264 }
265 $preview->createPreview();
266 $imagepath = $this->getImagePathWeb() . $preview->getPreviewFilename($this->getImagePath(), $this->getValue()) . "?img=" . time();
267 $template->setVariable("SRC_IMAGE", $imagepath);
268 } else {
269 $template->setVariable("SRC_IMAGE", $this->getImage());
270 }
271 $template->setVariable("ALT_IMAGE", $this->getAlt());
272 $template->setVariable("POST_VAR_D", $this->getPostVar());
273 $template->setVariable(
274 "TXT_DELETE_EXISTING",
275 $lng->txt("delete_existing_file")
276 );
277 $template->setVariable("TEXT_ADD_RECT", $lng->txt('add_rect'));
278 $template->setVariable("TEXT_ADD_CIRCLE", $lng->txt('add_circle'));
279 $template->setVariable("TEXT_ADD_POLY", $lng->txt('add_poly'));
280 $template->parseCurrentBlock();
281 }
282
283 if (is_array($this->getAreas()) && $this->getAreas()) {
284 $counter = 0;
285 foreach ($this->getAreas() as $area) {
286 if (strlen($area->getPoints())) {
287 $template->setCurrentBlock('area_points_value');
288 $template->setVariable('VALUE_POINTS', $area->getPoints());
289 $template->parseCurrentBlock();
290 }
291 if ($this->getPointsUncheckedFieldEnabled()) {
292 if (strlen($area->getPointsUnchecked())) {
293 $template->setCurrentBlock('area_points_unchecked_value');
294 $template->setVariable('VALUE_POINTS_UNCHECKED', $area->getPointsUnchecked());
295 $template->parseCurrentBlock();
296 }
297
298 $template->setCurrentBlock('area_points_unchecked_field');
299 $template->parseCurrentBlock();
300 }
301 if (strlen($area->getAnswertext())) {
302 $template->setCurrentBlock('area_name_value');
303 $template->setVariable('VALUE_NAME', $area->getAnswertext());
304 $template->parseCurrentBlock();
305 }
306 $template->setCurrentBlock('row');
307 $template->setVariable('POST_VAR_R', $this->getPostVar());
308 $template->setVariable('TEXT_SHAPE', strtoupper($area->getArea()));
309 $template->setVariable('VALUE_SHAPE', $area->getArea());
310 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $area->getCoords());
311 $template->setVariable('VALUE_COORDINATES', $area->getCoords());
312 $template->setVariable('TEXT_COORDINATES', $coords);
313 $template->setVariable('COUNTER', $counter);
314 $template->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
315 $template->parseCurrentBlock();
316 $counter++;
317 }
318 $template->setCurrentBlock("areas");
319 $template->setVariable("TEXT_NAME", $lng->txt("ass_imap_hint"));
320 if ($this->getPointsUncheckedFieldEnabled()) {
321 $template->setVariable("TEXT_POINTS", $lng->txt("points_checked"));
322
323 $template->setCurrentBlock('area_points_unchecked_head');
324 $template->setVariable("TEXT_POINTS_UNCHECKED", $lng->txt("points_unchecked"));
325 $template->parseCurrentBlock();
326 } else {
327 $template->setVariable("TEXT_POINTS", $lng->txt("points"));
328 }
329 $template->setVariable("TEXT_SHAPE", $lng->txt("shape"));
330 $template->setVariable("TEXT_COORDINATES", $lng->txt("coordinates"));
331 $template->setVariable("TEXT_COMMANDS", $lng->txt("actions"));
332 $template->parseCurrentBlock();
333 }
334
335 $template->setVariable("POST_VAR", $this->getPostVar());
336 $template->setVariable("ID", $this->getFieldId());
337 $template->setVariable("TXT_BROWSE", $lng->txt("select_file"));
338 $template->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " .
339 $this->getMaxFileSizeString());
340
341 $a_tpl->setCurrentBlock("prop_generic");
342 $a_tpl->setVariable("PROP_GENERIC", $template->get());
343 $a_tpl->parseCurrentBlock();
344
345 global $DIC;
346 $tpl = $DIC['tpl'];
347 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
348 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/imagemap.js");
349 }
350}
$_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
if($format !==null) $name
Definition: metadata.php:230
$index
Definition: metadata.php:128
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$preview
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$DIC
Definition: xapitoken.php:46