ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTextInputGUI.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 $value;
34  protected $maxlength = 200;
35  protected $size = 40;
36  protected $validationRegexp;
37 
44  function __construct($a_title = "", $a_postvar = "")
45  {
46  parent::__construct($a_title, $a_postvar);
47  $this->setInputType("text");
48  $this->validationRegexp = "";
49  }
50 
56  function setValue($a_value)
57  {
58  $this->value = $a_value;
59  }
60 
66  function getValue()
67  {
68  return $this->value;
69  }
70 
76  function setValidationRegexp($a_value)
77  {
78  $this->validationRegexp = $a_value;
79  }
80 
87  {
89  }
90 
96  function setMaxLength($a_maxlength)
97  {
98  $this->maxlength = $a_maxlength;
99  }
100 
106  function getMaxLength()
107  {
108  return $this->maxlength;
109  }
110 
116  function setSize($a_size)
117  {
118  $this->size = $a_size;
119  }
120 
126  function setValueByArray($a_values)
127  {
128  $this->setValue($a_values[$this->getPostVar()]);
129  }
130 
136  function getSize()
137  {
138  return $this->size;
139  }
140 
148  public function setInputType($a_type)
149  {
150  $this->input_type = $a_type;
151  }
152 
158  public function getInputType()
159  {
160  return $this->input_type;
161  }
162 
163 
169  function checkInput()
170  {
171  global $lng;
172 
173  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
174  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
175  {
176  $this->setAlert($lng->txt("msg_input_is_required"));
177 
178  return false;
179  }
180  else if (strlen($this->getValidationRegexp()))
181  {
182  if (!preg_match($this->getValidationRegexp(), $_POST[$this->getPostVar()]))
183  {
184  $this->setAlert($lng->txt("msg_wrong_format"));
185  return FALSE;
186  }
187  }
188 
189  return $this->checkSubItemsInput();
190  }
191 
197  function insert(&$a_tpl)
198  {
199  if (strlen($this->getValue()))
200  {
201  $a_tpl->setCurrentBlock("prop_text_propval");
202  $a_tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
203  $a_tpl->parseCurrentBlock();
204  }
205  $a_tpl->setCurrentBlock("prop_text");
206  switch($this->getInputType())
207  {
208  case 'password':
209  $a_tpl->setVariable('PROP_INPUT_TYPE','password');
210  break;
211  case 'hidden':
212  $a_tpl->setVariable('PROP_INPUT_TYPE','hidden');
213  break;
214  case 'text':
215  default:
216  $a_tpl->setVariable('PROP_INPUT_TYPE','text');
217  }
218  $a_tpl->setVariable("POST_VAR", $this->getPostVar());
219  $a_tpl->setVariable("ID", $this->getFieldId());
220  $a_tpl->setVariable("SIZE", $this->getSize());
221  $a_tpl->setVariable("MAXLENGTH", $this->getMaxLength());
222  if ($this->getDisabled())
223  {
224  $a_tpl->setVariable("DISABLED",
225  " disabled=\"disabled\"");
226  }
227  $a_tpl->parseCurrentBlock();
228  }
229 }