ILIAS  release_4-4 Revision
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 
108  function getKeyMaxlength()
109  {
110  return $this->key_maxlength;
111  }
112 
118  function setValueMaxlength($a_maxlength)
119  {
120  $this->value_maxlength = $a_maxlength;
121  }
122 
128  function getValueMaxlength()
129  {
130  return $this->value_maxlength;
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  if (is_array($foundvalues))
205  {
206  // check answers
207  if (is_array($foundvalues['key']) && is_array($foundvalues['value']))
208  {
209  foreach ($foundvalues['key'] as $val)
210  {
211  if ($this->getRequired() && (strlen($val)) == 0)
212  {
213  $this->setAlert($lng->txt("msg_input_is_required"));
214  return FALSE;
215  }
216  }
217  foreach ($foundvalues['value'] as $val)
218  {
219  if ($this->getRequired() && (strlen($val)) == 0)
220  {
221  $this->setAlert($lng->txt("msg_input_is_required"));
222  return FALSE;
223  }
224  }
225  foreach ($foundvalues['points'] as $val)
226  {
227  if ($this->getRequired() && (strlen($val)) == 0)
228  {
229  $this->setAlert($lng->txt("msg_input_is_required"));
230  return FALSE;
231  }
232  if (!is_numeric(str_replace(",", ".", $val)))
233  {
234  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
235  return FALSE;
236  }
237  }
238  }
239  else
240  {
241  if ($this->getRequired())
242  {
243  $this->setAlert($lng->txt("msg_input_is_required"));
244  return FALSE;
245  }
246  }
247  }
248  else
249  {
250  if ($this->getRequired())
251  {
252  $this->setAlert($lng->txt("msg_input_is_required"));
253  return FALSE;
254  }
255  }
256  return $this->checkSubItemsInput();
257  }
258 
264  function insert(&$a_tpl)
265  {
266  global $lng;
267 
268  $tpl = new ilTemplate("tpl.prop_errortextwizardinput.html", true, true, "Modules/TestQuestionPool");
269  $i = 0;
270  foreach ($this->values as $value)
271  {
272  if (is_object($value))
273  {
274  if (strlen($value->text_wrong))
275  {
276  $tpl->setCurrentBlock("prop_key_propval");
277  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text_wrong));
278  $tpl->parseCurrentBlock();
279  }
280  if (strlen($value->text_correct))
281  {
282  $tpl->setCurrentBlock("prop_value_propval");
283  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text_correct));
284  $tpl->parseCurrentBlock();
285  }
286  if (strlen($value->points))
287  {
288  $tpl->setCurrentBlock("prop_points_propval");
289  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->points));
290  $tpl->parseCurrentBlock();
291  }
292  }
293 
294  $tpl->setCurrentBlock("row");
295  $class = ($i % 2 == 0) ? "even" : "odd";
296  if ($i == 0) $class .= " first";
297  if ($i == count($this->values)-1) $class .= " last";
298  $tpl->setVariable("ROW_CLASS", $class);
299  $tpl->setVariable("ROW_NUMBER", $i);
300 
301  $tpl->setVariable("KEY_SIZE", $this->getKeySize());
302  $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
303  $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
304 
305  $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
306  $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
307  $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
308 
309  $tpl->setVariable("POST_VAR", $this->getPostVar());
310 
311  $tpl->parseCurrentBlock();
312 
313  $i++;
314  }
315  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
316  $tpl->setVariable("KEY_TEXT", $this->getKeyName());
317  $tpl->setVariable("VALUE_TEXT", $this->getValueName());
318  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
319 
320  $a_tpl->setCurrentBlock("prop_generic");
321  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
322  $a_tpl->parseCurrentBlock();
323  }
324 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
$_POST['username']
Definition: cron.php:12
__construct($a_title="", $a_postvar="")
Constructor.
checkInput()
Check input, strip slashes etc.
getPostVar()
Get Post Variable.
setKeyMaxlength($a_maxlength)
Set key maxlength.
Class for error text answers.
setAlert($a_alert)
Set Alert Text.
setValueMaxlength($a_maxlength)
Set value maxlength.
special template class to simplify handling of ITX/PEAR
insert(&$a_tpl)
Insert property html.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
This class represents a text property in a property form.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
global $lng
Definition: privfeed.php:40
This class represents a key value pair wizard property in a property form.