ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTextWizardInputGUI.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 
42  function __construct($a_title = "", $a_postvar = "")
43  {
44  parent::__construct($a_title, $a_postvar);
45  $this->validationRegexp = "";
46  }
47 
53  function setValues($a_values)
54  {
55  $this->values = $a_values;
56  }
57 
63  function setValue($a_value)
64  {
65  $this->values = $a_value;
66  }
67 
73  function getValues()
74  {
75  return $this->values;
76  }
77 
83  function setAllowMove($a_allow_move)
84  {
85  $this->allowMove = $a_allow_move;
86  }
87 
93  function getAllowMove()
94  {
95  return $this->allowMove;
96  }
97 
103  function checkInput()
104  {
105  global $lng;
106 
107  $foundvalues = $_POST[$this->getPostVar()];
108  if (is_array($foundvalues))
109  {
110  foreach ($foundvalues as $idx => $value)
111  {
112  $_POST[$this->getPostVar()][$idx] = ilUtil::stripSlashes($value);
113  if ($this->getRequired() && trim($value) == "")
114  {
115  $this->setAlert($lng->txt("msg_input_is_required"));
116 
117  return false;
118  }
119  else if (strlen($this->getValidationRegexp()))
120  {
121  if (!preg_match($this->getValidationRegexp(), $value))
122  {
123  $this->setAlert($lng->txt("msg_wrong_format"));
124  return FALSE;
125  }
126  }
127  }
128  }
129  else
130  {
131  $this->setAlert($lng->txt("msg_input_is_required"));
132  return FALSE;
133  }
134 
135  return $this->checkSubItemsInput();
136  }
137 
143  function insert(&$a_tpl)
144  {
145  $tpl = new ilTemplate("tpl.prop_textwizardinput.html", true, true, "Services/Form");
146  $i = 0;
147  foreach ($this->values as $value)
148  {
149  if (strlen($value))
150  {
151  $tpl->setCurrentBlock("prop_text_propval");
152  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value));
153  $tpl->parseCurrentBlock();
154  }
155  if ($this->getAllowMove())
156  {
157  $tpl->setCurrentBlock("move");
158  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
159  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
160  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
161  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.png'));
162  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.png'));
163  $tpl->parseCurrentBlock();
164  }
165  $tpl->setCurrentBlock("row");
166  $class = ($i % 2 == 0) ? "even" : "odd";
167  if ($i == 0) $class .= " first";
168  if ($i == count($this->values)-1) $class .= " last";
169  $tpl->setVariable("ROW_CLASS", $class);
170  $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
171  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
172  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
173  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
174  $tpl->setVariable("SIZE", $this->getSize());
175  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
176  if ($this->getDisabled())
177  {
178  $tpl->setVariable("DISABLED",
179  " disabled=\"disabled\"");
180  }
181  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
182  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
183  $tpl->parseCurrentBlock();
184  $i++;
185  }
186  $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
187 
188  $a_tpl->setCurrentBlock("prop_generic");
189  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
190  $a_tpl->parseCurrentBlock();
191 
192  global $tpl;
193  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
195  $tpl->addJavascript("./Services/Form/templates/default/textwizard.js");
196  }
197 }