ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilOrderingTextWizardInputGUI.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 
36  protected $disable_text = false;
37  protected $disable_actions = false;
38 
45  function __construct($a_title = "", $a_postvar = "")
46  {
47  parent::__construct($a_title, $a_postvar);
48  $this->validationRegexp = "";
49  }
50 
55  {
56  $this->disable_actions = $disable_actions;
57  }
58 
62  public function setDisableText($disable_text)
63  {
64  $this->disable_text = $disable_text;
65  }
66 
72  function setValues($a_values)
73  {
74  $this->values = $a_values;
75  }
76 
82  function setValue($a_value)
83  {
84  $this->values = $a_value;
85  }
86 
92  function getValues()
93  {
94  return $this->values;
95  }
96 
102  function setAllowMove($a_allow_move)
103  {
104  $this->allowMove = $a_allow_move;
105  }
106 
112  function getAllowMove()
113  {
114  return $this->allowMove;
115  }
116 
122  function checkInput()
123  {
124  global $lng;
125 
126  $foundvalues = $_POST[$this->getPostVar()];
127  if (is_array($foundvalues))
128  {
129  foreach ($foundvalues as $idx => $value)
130  {
131  $_POST[$this->getPostVar()][$idx] = ilUtil::stripSlashes($value);
132  if ($this->getRequired() && trim($value) == "")
133  {
134  $this->setAlert($lng->txt("msg_input_is_required"));
135 
136  return false;
137  }
138  else if (strlen($this->getValidationRegexp()))
139  {
140  if (!preg_match($this->getValidationRegexp(), $value))
141  {
142  $this->setAlert($lng->txt("msg_wrong_format"));
143  return FALSE;
144  }
145  }
146  }
147  }
148  else
149  {
150  $this->setAlert($lng->txt("msg_input_is_required"));
151  return FALSE;
152  }
153 
154  return $this->checkSubItemsInput();
155  }
156 
162  function insert(&$a_tpl)
163  {
164  $tpl = new ilTemplate("tpl.prop_textwizardinput.html", true, true, "Modules/TestQuestionPool");
165  $i = 0;
166  foreach ($this->values as $value)
167  {
168  if (strlen($value))
169  {
170  $tpl->setCurrentBlock("prop_text_propval");
171  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value));
172  $tpl->parseCurrentBlock();
173  }
174 
175  if ($this->getAllowMove())
176  {
177  $tpl->setCurrentBlock("move");
178  $tpl->setVariable("MOVE_ID", $this->getFieldId() . "[$i]");
179  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
180  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
181  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
182  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.png'));
183  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.png'));
184  $tpl->parseCurrentBlock();
185  }
186  $tpl->setCurrentBlock("row");
187  $class = ($i % 2 == 0) ? "even" : "odd";
188  if ($i == 0) $class .= " first";
189  if ($i == count($this->values)-1) $class .= " last";
190  $tpl->setVariable("ROW_CLASS", $class);
191  $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
192  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
193  $tpl->setVariable("SIZE", $this->getSize());
194  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
195 
196  if($this->getDisabled())
197  {
198  $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
199  }
200 
201  if(!$this->disable_actions)
202  {
203  $tpl->setVariable("ID_ADD_BUTTON", $this->getFieldId() . "[$i]");
204  $tpl->setVariable("ID_REMOVE_BUTTON", $this->getFieldId() . "[$i]");
205  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
206  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
207  $tpl->setVariable( "ADD_BUTTON", ilUtil::getImagePath( 'edit_add.png' ) );
208  $tpl->setVariable( "REMOVE_BUTTON", ilUtil::getImagePath( 'edit_remove.png' ) );
209  }
210 
211  if($this->disable_text)
212  {
213  $tpl->setVariable('DISABLED_TEXT', ' readonly="readonly"');
214  }
215 
216  $tpl->parseCurrentBlock();
217  $i++;
218  }
219  $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
220 
221  $a_tpl->setCurrentBlock("prop_generic");
222  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
223  $a_tpl->parseCurrentBlock();
224 
225  global $tpl;
226  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
228  $tpl->addJavascript("./Services/Form/templates/default/textwizard.js");
229  }
230 }