ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSelectBuilderInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14 
15  protected $open_answer_indexes = array();
16 
17 
18  // constructor
19  public function __construct($a_title = "", $a_postvar = "")
20  {
21  parent::__construct($a_title, $a_postvar);
22  }
23 
24 
28  public function getOpenAnswerIndexes()
29  {
31  }
32 
36  public function setOpenAnswerIndexes($a_indexes)
37  {
38  $this->open_answer_indexes = $a_indexes;
39  }
40 
44  public function addOpenAnswerIndex($a_idx)
45  {
46  $this->open_answer_indexes[] = $a_idx;
47  }
48 
54  public function isOpenAnswerIndex($a_idx)
55  {
56  return in_array($a_idx,(array) $this->open_answer_indexes);
57  }
58 
64  public function checkInput()
65  {
66  global $lng;
67 
68  $foundvalues = $_POST[$this->getPostVar()];
69 
70 
71 
72  $this->setOpenAnswerIndexes(array());
73  if (is_array($foundvalues))
74  {
75  foreach ($foundvalues as $idx => $value)
76  {
77  $_POST[$this->getPostVar()][$idx] = ilUtil::stripSlashes($value);
78  if ($this->getRequired() && trim($value) == "")
79  {
80  $this->setAlert($lng->txt("msg_input_is_required"));
81 
82  return false;
83  }
84  else if (strlen($this->getValidationRegexp()))
85  {
86  if (!preg_match($this->getValidationRegexp(), $value))
87  {
88  $this->setAlert($lng->txt("msg_wrong_format"));
89  return FALSE;
90  }
91  }
92  }
93  }
94  else
95  {
96  $this->setAlert($lng->txt("msg_input_is_required"));
97  return FALSE;
98  }
99 
100  foreach((array) $_POST[$this->getPostVar().'_open'] as $oindex => $ovalue)
101  {
102  $this->addOpenAnswerIndex($oindex);
103  }
104 
105 
106  return $this->checkSubItemsInput();
107  }
108 
114  public function insert($a_tpl)
115  {
116  $tpl = new ilTemplate("tpl.prop_selectbuilder.html", true, true, "Services/Form");
117  $i = 0;
118  foreach ($this->values as $value)
119  {
120  if(!is_string($value))
121  {
122  continue;
123  }
124 
125  if (strlen((string) $value))
126  {
127  $tpl->setCurrentBlock("prop_text_propval");
128  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput((string) $value));
129  $tpl->parseCurrentBlock();
130  }
131  if ($this->getAllowMove())
132  {
133  $tpl->setCurrentBlock("move");
134  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
135  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
136  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
137  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.png'));
138  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.png'));
139  $tpl->parseCurrentBlock();
140  }
141  $tpl->setCurrentBlock("row");
142  $class = ($i % 2 == 0) ? "even" : "odd";
143  if ($i == 0) $class .= " first";
144  if ($i == count($this->values)-1) $class .= " last";
145  $tpl->setVariable("ROW_CLASS", $class);
146  $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
147  #$tpl->setVariable('POST_VAR_OPEN',$this->getPostVar().'[open]'.'['.$i.']');
148  $tpl->setVariable('POST_VAR_OPEN',$this->getPostVar().'_open'.'['.$i.']');
149  $tpl->setVariable('POST_VAR_OPEN_ID', $this->getPostVar().'_open['.$i.']');
150 
151  if($this->isOpenAnswerIndex($i))
152  {
153  $tpl->setVariable('PROP_OPEN_CHECKED','checked="checked"');
154  }
155  if($this->getDisabled())
156  {
157  $tpl->setVariable('PROP_OPEN_DISABLED','disabled="disabled"');
158  }
159 
160  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
161  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
162  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
163  $tpl->setVariable("SIZE", $this->getSize());
164  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
165  if ($this->getDisabled())
166  {
167  $tpl->setVariable("DISABLED",
168  " disabled=\"disabled\"");
169  }
170  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
171  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
172  $tpl->parseCurrentBlock();
173  $i++;
174  }
175  $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
176 
177  $a_tpl->setCurrentBlock("prop_generic");
178  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
179  $a_tpl->parseCurrentBlock();
180 
181  global $tpl;
182  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
184  $tpl->addJavascript("./Services/Form/templates/default/textwizard.js");
185  }
186 
187 
188 }