ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilKVPWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 {
33  protected $values = array();
34  protected $allowMove = false;
35  protected $key_size = 20;
36  protected $value_size = 20;
37  protected $key_maxlength = 255;
38  protected $value_maxlength = 255;
39  protected $key_name = "";
40  protected $value_name = "";
41 
48  function __construct($a_title = "", $a_postvar = "")
49  {
50  parent::__construct($a_title, $a_postvar);
51  }
52 
58  function setValue($a_value)
59  {
60  $this->values = array();
61  if (is_array($a_value))
62  {
63  if (is_array($a_value['key']))
64  {
65  foreach ($a_value['key'] as $idx => $key)
66  {
67  array_push($this->values, array($key, $a_value['value'][$idx]));
68  }
69  }
70  }
71  }
72 
78  function setKeySize($a_size)
79  {
80  $this->key_size = $a_size;
81  }
82 
88  function getKeySize()
89  {
90  return $this->key_size;
91  }
92 
98  function setValueSize($a_size)
99  {
100  $this->value_size = $a_size;
101  }
102 
108  function getValueSize()
109  {
110  return $this->value_size;
111  }
112 
118  function setKeyMaxlength($a_maxlength)
119  {
120  $this->key_maxlength = $a_maxlength;
121  }
122 
128  function getKeyMaxlength()
129  {
130  return $this->key_maxlength;
131  }
132 
138  function setValueMaxlength($a_maxlength)
139  {
140  $this->value_maxlength = $a_maxlength;
141  }
142 
148  function getValueMaxlength()
149  {
150  return $this->value_maxlength;
151  }
152 
158  function setValueName($a_name)
159  {
160  $this->value_name = $a_name;
161  }
162 
168  function getValueName()
169  {
170  return $this->value_name;
171  }
172 
178  function setKeyName($a_name)
179  {
180  $this->key_name = $a_name;
181  }
182 
188  function getKeyName()
189  {
190  return $this->key_name;
191  }
192 
198  function setValues($a_values)
199  {
200  $this->values = $a_values;
201  }
202 
208  function getValues()
209  {
210  return $this->values;
211  }
212 
218  function setAllowMove($a_allow_move)
219  {
220  $this->allowMove = $a_allow_move;
221  }
222 
228  function getAllowMove()
229  {
230  return $this->allowMove;
231  }
232 
238  function checkInput()
239  {
240  global $lng;
241 
242  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
243  $foundvalues = $_POST[$this->getPostVar()];
244  if (is_array($foundvalues))
245  {
246  // check answers
247  if (is_array($foundvalues['key']) && is_array($foundvalues['value']))
248  {
249  foreach ($foundvalues['key'] as $val)
250  {
251  if ($this->getRequired() && (strlen($val)) == 0)
252  {
253  $this->setAlert($lng->txt("msg_input_is_required"));
254  return FALSE;
255  }
256  }
257  foreach ($foundvalues['value'] as $val)
258  {
259  if ($this->getRequired() && (strlen($val)) == 0)
260  {
261  $this->setAlert($lng->txt("msg_input_is_required"));
262  return FALSE;
263  }
264  }
265  }
266  else
267  {
268  if ($this->getRequired())
269  {
270  $this->setAlert($lng->txt("msg_input_is_required"));
271  return FALSE;
272  }
273  }
274  }
275  else
276  {
277  if ($this->getRequired())
278  {
279  $this->setAlert($lng->txt("msg_input_is_required"));
280  return FALSE;
281  }
282  }
283  return $this->checkSubItemsInput();
284  }
285 
291  function insert(&$a_tpl)
292  {
293  global $lng;
294 
295  $tpl = new ilTemplate("tpl.prop_kvpwizardinput.html", true, true, "Modules/TestQuestionPool");
296  $i = 0;
297  foreach ($this->values as $value)
298  {
299  if (is_array($value))
300  {
301  $tpl->setCurrentBlock("prop_key_propval");
302  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value[0]));
303  $tpl->parseCurrentBlock();
304  $tpl->setCurrentBlock("prop_value_propval");
305  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value[1]));
306  $tpl->parseCurrentBlock();
307  }
308  if ($this->getAllowMove())
309  {
310  $tpl->setCurrentBlock("move");
311  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
312  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
313  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
314  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.gif'));
315  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.gif'));
316  $tpl->parseCurrentBlock();
317  }
318 
319  $tpl->setCurrentBlock("row");
320  $class = ($i % 2 == 0) ? "even" : "odd";
321  if ($i == 0) $class .= " first";
322  if ($i == count($this->values)-1) $class .= " last";
323  $tpl->setVariable("ROW_CLASS", $class);
324  $tpl->setVariable("ROW_NUMBER", $i);
325 
326  $tpl->setVariable("KEY_SIZE", $this->getKeySize());
327  $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
328  $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
329 
330  $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
331  $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
332  $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
333 
334  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
335  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
336  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
337  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
338  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
339 
340  $tpl->setVariable("POST_VAR", $this->getPostVar());
341 
342  $tpl->parseCurrentBlock();
343 
344  $i++;
345  }
346  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
347  $tpl->setVariable("KEY_TEXT", $this->getKeyName());
348  $tpl->setVariable("VALUE_TEXT", $this->getValueName());
349 
350  $a_tpl->setCurrentBlock("prop_generic");
351  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
352  $a_tpl->parseCurrentBlock();
353 
354  global $tpl;
355  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
357  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/kvpwizard.js");
358  }
359 }