ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilErrorTextWizardInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
13 protected $values = array();
14 protected $key_size = 20;
15 protected $value_size = 20;
16 protected $key_maxlength = 255;
17 protected $value_maxlength = 255;
18 protected $key_name = "";
19 protected $value_name = "";
20
27 function __construct($a_title = "", $a_postvar = "")
28 {
29 parent::__construct($a_title, $a_postvar);
30 }
31
37 function setValue($a_value)
38 {
39 $this->values = array();
40 if (is_array($a_value))
41 {
42 include_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
43 if (is_array($a_value['key']))
44 {
45 foreach ($a_value['key'] as $idx => $key)
46 {
47 array_push($this->values, new assAnswerErrorText($key, $a_value['value'][$idx], str_replace(",", ".", $a_value['points'][$idx])));
48 }
49 }
50 }
51 }
52
58 function setKeySize($a_size)
59 {
60 $this->key_size = $a_size;
61 }
62
68 function getKeySize()
69 {
70 return $this->key_size;
71 }
72
78 function setValueSize($a_size)
79 {
80 $this->value_size = $a_size;
81 }
82
88 function getValueSize()
89 {
90 return $this->value_size;
91 }
92
98 function setKeyMaxlength($a_maxlength)
99 {
100 $this->key_maxlength = $a_maxlength;
101 }
102
109 {
111 }
112
118 function setValueMaxlength($a_maxlength)
119 {
120 $this->value_maxlength = $a_maxlength;
121 }
122
129 {
131 }
132
138 function setValueName($a_name)
139 {
140 $this->value_name = $a_name;
141 }
142
148 function getValueName()
149 {
150 return $this->value_name;
151 }
152
158 function setKeyName($a_name)
159 {
160 $this->key_name = $a_name;
161 }
162
168 function getKeyName()
169 {
170 return $this->key_name;
171 }
172
178 function setValues($a_values)
179 {
180 $this->values = $a_values;
181 }
182
188 function getValues()
189 {
190 return $this->values;
191 }
192
198 function checkInput()
199 {
200 global $lng;
201
202 if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
203 $foundvalues = $_POST[$this->getPostVar()];
204 $max_points = 0;
205
206 if (is_array($foundvalues))
207 {
208 // check answers
209 if (is_array($foundvalues['key']) && is_array($foundvalues['value']))
210 {
211 foreach ($foundvalues['key'] as $val)
212 {
213 if ($this->getRequired() && (strlen($val)) == 0)
214 {
215 $this->setAlert($lng->txt("msg_input_is_required"));
216 return FALSE;
217 }
218 }
219 foreach ($foundvalues['value'] as $val)
220 {
221 if ($this->getRequired() && (strlen($val)) == 0)
222 {
223 $this->setAlert($lng->txt("msg_input_is_required"));
224 return FALSE;
225 }
226 }
227 foreach ($foundvalues['points'] as $val)
228 {
229 if ($this->getRequired() && (strlen($val)) == 0)
230 {
231 $this->setAlert($lng->txt("msg_input_is_required"));
232 return FALSE;
233 }
234 if (!is_numeric(str_replace(",", ".", $val)))
235 {
236 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
237 return FALSE;
238 }
239 if((float)$val <= 0)
240 {
241 $this->setAlert($lng->txt("positive_numbers_required"));
242 return FALSE;
243 }
244 }
245 }
246 else
247 {
248 if ($this->getRequired())
249 {
250 $this->setAlert($lng->txt("msg_input_is_required"));
251 return FALSE;
252 }
253 }
254 }
255 else
256 {
257 if ($this->getRequired())
258 {
259 $this->setAlert($lng->txt("msg_input_is_required"));
260 return FALSE;
261 }
262 }
263
264 return $this->checkSubItemsInput();
265 }
266
272 function insert(&$a_tpl)
273 {
274 global $lng;
275
276 $tpl = new ilTemplate("tpl.prop_errortextwizardinput.html", true, true, "Modules/TestQuestionPool");
277 $i = 0;
278 foreach ($this->values as $value)
279 {
280 if (is_object($value))
281 {
282 if (strlen($value->text_wrong))
283 {
284 $tpl->setCurrentBlock("prop_key_propval");
285 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text_wrong));
286 $tpl->parseCurrentBlock();
287 }
288 if (strlen($value->text_correct))
289 {
290 $tpl->setCurrentBlock("prop_value_propval");
291 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text_correct));
292 $tpl->parseCurrentBlock();
293 }
294 if (strlen($value->points))
295 {
296 $tpl->setCurrentBlock("prop_points_propval");
297 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->points));
298 $tpl->parseCurrentBlock();
299 }
300 }
301
302 $tpl->setCurrentBlock("row");
303 $class = ($i % 2 == 0) ? "even" : "odd";
304 if ($i == 0) $class .= " first";
305 if ($i == count($this->values)-1) $class .= " last";
306 $tpl->setVariable("ROW_CLASS", $class);
307 $tpl->setVariable("ROW_NUMBER", $i);
308
309 $tpl->setVariable("KEY_SIZE", $this->getKeySize());
310 $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
311 $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
312
313 $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
314 $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
315 $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
316
317 $tpl->setVariable("POST_VAR", $this->getPostVar());
318
319 $tpl->parseCurrentBlock();
320
321 $i++;
322 }
323 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
324 $tpl->setVariable("KEY_TEXT", $this->getKeyName());
325 $tpl->setVariable("VALUE_TEXT", $this->getValueName());
326 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
327
328 $a_tpl->setCurrentBlock("prop_generic");
329 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
330 $a_tpl->parseCurrentBlock();
331 }
332}
global $tpl
Definition: ilias.php:8
Class for error text answers.
This class represents a key value pair wizard property in a property form.
checkInput()
Check input, strip slashes etc.
insert(&$a_tpl)
Insert property html.
setValueMaxlength($a_maxlength)
Set value maxlength.
setKeyMaxlength($a_maxlength)
Set key maxlength.
__construct($a_title="", $a_postvar="")
Constructor.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$_POST['username']
Definition: cron.php:12
global $lng
Definition: privfeed.php:40