ILIAS  Release_4_0_x_branch Revision 61816
 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  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
243  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
244  $foundvalues = $_POST[$this->getPostVar()];
245  if (is_array($foundvalues))
246  {
247  // check answers
248  if (is_array($foundvalues['key']) && is_array($foundvalues['value']))
249  {
250  foreach ($foundvalues['key'] as $val)
251  {
252  if ($this->getRequired() && (strlen($val)) == 0)
253  {
254  $this->setAlert($lng->txt("msg_input_is_required"));
255  return FALSE;
256  }
257  }
258  foreach ($foundvalues['value'] as $val)
259  {
260  if ($this->getRequired() && (strlen($val)) == 0)
261  {
262  $this->setAlert($lng->txt("msg_input_is_required"));
263  return FALSE;
264  }
265  }
266  }
267  else
268  {
269  if ($this->getRequired())
270  {
271  $this->setAlert($lng->txt("msg_input_is_required"));
272  return FALSE;
273  }
274  }
275  }
276  else
277  {
278  if ($this->getRequired())
279  {
280  $this->setAlert($lng->txt("msg_input_is_required"));
281  return FALSE;
282  }
283  }
284  return $this->checkSubItemsInput();
285  }
286 
292  function insert(&$a_tpl)
293  {
294  global $lng;
295 
296  $tpl = new ilTemplate("tpl.prop_kvpwizardinput.html", true, true, "Modules/TestQuestionPool");
297  $i = 0;
298  foreach ($this->values as $value)
299  {
300  if (is_array($value))
301  {
302  $tpl->setCurrentBlock("prop_key_propval");
303  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value[0]));
304  $tpl->parseCurrentBlock();
305  $tpl->setCurrentBlock("prop_value_propval");
306  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value[1]));
307  $tpl->parseCurrentBlock();
308  }
309  if ($this->getAllowMove())
310  {
311  $tpl->setCurrentBlock("move");
312  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
313  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
314  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
315  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.gif'));
316  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.gif'));
317  $tpl->parseCurrentBlock();
318  }
319 
320  $tpl->setCurrentBlock("row");
321  $class = ($i % 2 == 0) ? "even" : "odd";
322  if ($i == 0) $class .= " first";
323  if ($i == count($this->values)-1) $class .= " last";
324  $tpl->setVariable("ROW_CLASS", $class);
325  $tpl->setVariable("ROW_NUMBER", $i);
326 
327  $tpl->setVariable("KEY_SIZE", $this->getKeySize());
328  $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
329  $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
330 
331  $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
332  $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
333  $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
334 
335  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
336  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
337  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
338  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
339  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
340 
341  $tpl->setVariable("POST_VAR", $this->getPostVar());
342 
343  $tpl->parseCurrentBlock();
344 
345  $i++;
346  }
347  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
348  $tpl->setVariable("KEY_TEXT", $this->getKeyName());
349  $tpl->setVariable("VALUE_TEXT", $this->getValueName());
350 
351  $a_tpl->setCurrentBlock("prop_generic");
352  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
353  $a_tpl->parseCurrentBlock();
354 
355  global $tpl;
356  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
358  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/kvpwizard.js");
359  }
360 }