ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilImagemapCorrectionsInputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
14 {
15  public function setValueByArray($a_values)
16  {
17  $this->setAreasByArray($a_values[$this->getPostVar()]['coords']);
18  }
19 
20  public function setAreasByArray($a_areas)
21  {
22  if (is_array($a_areas['points'])) {
23  foreach ($this->areas as $idx => $name) {
24  if ($this->getPointsUncheckedFieldEnabled() && isset($a_areas['points_unchecked'])) {
25  $this->areas[$idx]->setPointsUnchecked($a_areas['points_unchecked'][$idx]);
26  } else {
27  $this->areas[$idx]->setPointsUnchecked(0);
28  }
29 
30  $this->areas[$idx]->setPoints($a_areas['points'][$idx]);
31  }
32  }
33  }
34 
35  public function checkInput()
36  {
37  global $DIC;
38  $lng = $DIC['lng'];
39 
40  if (is_array($_POST[$this->getPostVar()])) {
42  }
43 
44  $max = 0;
45  if (is_array($_POST[$this->getPostVar()]['coords']['points'])) {
46  foreach ($_POST[$this->getPostVar()]['coords']['points'] as $idx => $name) {
47  if ((!strlen($_POST[$this->getPostVar()]['coords']['points'][$idx])) && ($this->getRequired)) {
48  $this->setAlert($lng->txt('form_msg_area_missing_points'));
49  return false;
50  }
51  if ((!is_numeric($_POST[$this->getPostVar()]['coords']['points'][$idx]))) {
52  $this->setAlert($lng->txt('form_msg_numeric_value_required'));
53  return false;
54  }
55  if ($_POST[$this->getPostVar()]['coords']['points'][$idx] > 0) {
56  $max = $_POST[$this->getPostVar()]['coords']['points'][$idx];
57  }
58  }
59  }
60 
61  if ($max == 0) {
62  $this->setAlert($lng->txt("enter_enough_positive_points"));
63  return false;
64  }
65  return true;
66  }
67 
68  public function insert($a_tpl)
69  {
70  global $DIC;
71  $lng = $DIC['lng'];
72 
73  $template = new ilTemplate("tpl.prop_imagemapquestioncorrection_input.html", true, true, "Modules/TestQuestionPool");
74 
75  if ($this->getImage() != "") {
76  $template->setCurrentBlock("image");
77  if (count($this->getAreas())) {
78  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
79  $preview = new ilImagemapPreview($this->getImagePath() . $this->getValue());
80  foreach ($this->getAreas() as $index => $area) {
81  $preview->addArea($index, $area->getArea(), $area->getCoords(), $area->getAnswertext(), "", "", true, $this->getLineColor());
82  }
83  $preview->createPreview();
84  $imagepath = $this->getImagePathWeb() . $preview->getPreviewFilename($this->getImagePath(), $this->getValue()) . "?img=" . time();
85  $template->setVariable("SRC_IMAGE", $imagepath);
86  } else {
87  $template->setVariable("SRC_IMAGE", $this->getImage());
88  }
89  $template->setVariable("ALT_IMAGE", $this->getAlt());
90  $template->setVariable("POST_VAR_D", $this->getPostVar());
91  $template->parseCurrentBlock();
92  }
93 
94  if (is_array($this->getAreas()) && $this->getAreas()) {
95  $counter = 0;
96  foreach ($this->getAreas() as $area) {
97  if (strlen($area->getPoints())) {
98  $template->setCurrentBlock('area_points_value');
99  $template->setVariable('VALUE_POINTS', $area->getPoints());
100  $template->parseCurrentBlock();
101  }
102  if ($this->getPointsUncheckedFieldEnabled()) {
103  if (strlen($area->getPointsUnchecked())) {
104  $template->setCurrentBlock('area_points_unchecked_value');
105  $template->setVariable('VALUE_POINTS_UNCHECKED', $area->getPointsUnchecked());
106  $template->parseCurrentBlock();
107  }
108 
109  $template->setCurrentBlock('area_points_unchecked_field');
110  $template->parseCurrentBlock();
111  }
112  $template->setCurrentBlock('row');
113  if (strlen($area->getAnswertext())) {
114  $template->setVariable('ANSWER_AREA', $area->getAnswertext());
115  }
116  $template->setVariable('POST_VAR_R', $this->getPostVar());
117  $template->setVariable('TEXT_SHAPE', strtoupper($area->getArea()));
118  $template->setVariable('VALUE_SHAPE', $area->getArea());
119  $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $area->getCoords());
120  $template->setVariable('VALUE_COORDINATES', $area->getCoords());
121  $template->setVariable('TEXT_COORDINATES', $coords);
122  $template->setVariable('COUNTER', $counter);
123  $template->parseCurrentBlock();
124  $counter++;
125  }
126  $template->setCurrentBlock("areas");
127  $template->setVariable("TEXT_NAME", $lng->txt("ass_imap_hint"));
128  if ($this->getPointsUncheckedFieldEnabled()) {
129  $template->setVariable("TEXT_POINTS", $lng->txt("points_checked"));
130 
131  $template->setCurrentBlock('area_points_unchecked_head');
132  $template->setVariable("TEXT_POINTS_UNCHECKED", $lng->txt("points_unchecked"));
133  $template->parseCurrentBlock();
134  } else {
135  $template->setVariable("TEXT_POINTS", $lng->txt("points"));
136  }
137  $template->setVariable("TEXT_SHAPE", $lng->txt("shape"));
138  $template->setVariable("TEXT_COORDINATES", $lng->txt("coordinates"));
139  $template->setVariable("TEXT_COMMANDS", $lng->txt("actions"));
140  $template->parseCurrentBlock();
141  }
142 
143  $template->setVariable("POST_VAR", $this->getPostVar());
144  $template->setVariable("ID", $this->getFieldId());
145  $template->setVariable("TXT_BROWSE", $lng->txt("select_file"));
146  $template->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " .
147  $this->getMaxFileSizeString());
148 
149  $a_tpl->setCurrentBlock("prop_generic");
150  $a_tpl->setVariable("PROP_GENERIC", $template->get());
151  $a_tpl->parseCurrentBlock();
152 
153  global $DIC;
154  $tpl = $DIC['tpl'];
155  #$tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
156  #$tpl->addJavascript("./Modules/TestQuestionPool/templates/default/imagemap.js");
157  }
158 }
getAlt()
Get Alternative Text.
$template
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
$preview
$index
Definition: metadata.php:60
$coords
Definition: example_030.php:88
Image map image preview creator.
setAlert($a_alert)
Set Alert Text.
This class represents an image map file property in a property form.
getFieldId()
Get Post Variable.
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.
$_POST["username"]