ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNumberInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 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 $minvalue = false;
37  protected $maxvalue = false;
38 
45  function __construct($a_title = "", $a_postvar = "")
46  {
47  parent::__construct($a_title, $a_postvar);
48  }
49 
55  function setValue($a_value)
56  {
57  $this->value = $a_value;
58  }
59 
65  function getValue()
66  {
67  return $this->value;
68  }
69 
75  function setMaxLength($a_maxlength)
76  {
77  $this->maxlength = $a_maxlength;
78  }
79 
85  function getMaxLength()
86  {
87  return $this->maxlength;
88  }
89 
95  function setSize($a_size)
96  {
97  $this->size = $a_size;
98  }
99 
105  function setValueByArray($a_values)
106  {
107  $this->setValue($a_values[$this->getPostVar()]);
108  }
109 
115  function getSize()
116  {
117  return $this->size;
118  }
119 
125  function setMinValue($a_minvalue)
126  {
127  $this->minvalue = $a_minvalue;
128  }
129 
135  function getMinValue()
136  {
137  return $this->minvalue;
138  }
139 
145  function setMaxValue($a_maxvalue)
146  {
147  $this->maxvalue = $a_maxvalue;
148  }
149 
155  function getMaxValue()
156  {
157  return $this->maxvalue;
158  }
159 
165  function setDecimals($a_decimals)
166  {
167  $this->decimals = $a_decimals;
168  }
169 
175  function getDecimals()
176  {
177  return $this->decimals;
178  }
179 
185  function checkInput()
186  {
187  global $lng;
188 
189  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
190  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
191  {
192  $this->setAlert($lng->txt("msg_input_is_required"));
193 
194  return false;
195  }
196 
197  if (trim($_POST[$this->getPostVar()]) != "" &&
198  ! is_numeric($_POST[$this->getPostVar()]))
199  {
200  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
201 
202  return false;
203  }
204 
205  if (trim($_POST[$this->getPostVar()]) != "" &&
206  $this->getMinValue() !== false &&
207  $_POST[$this->getPostVar()] < $this->getMinValue())
208  {
209  $this->setAlert($lng->txt("form_msg_value_too_low"));
210 
211  return false;
212  }
213 
214  if (trim($_POST[$this->getPostVar()]) != "" &&
215  $this->getMaxValue() !== false &&
216  $_POST[$this->getPostVar()] > $this->getMaxValue())
217  {
218  $this->setAlert($lng->txt("form_msg_value_too_high"));
219 
220  return false;
221  }
222 
223  return $this->checkSubItemsInput();
224  }
225 
231  function insert(&$a_tpl)
232  {
233  global $lng;
234 
235  if (strlen($this->getValue()))
236  {
237  $a_tpl->setCurrentBlock("prop_number_propval");
238  $a_tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
239  $a_tpl->parseCurrentBlock();
240  }
241  $a_tpl->setCurrentBlock("prop_number");
242 
243  $a_tpl->setVariable("POST_VAR", $this->getPostVar());
244  $a_tpl->setVariable("ID", $this->getFieldId());
245  $a_tpl->setVariable("SIZE", $this->getSize());
246  $a_tpl->setVariable("MAXLENGTH", $this->getMaxLength());
247  if ($this->getDisabled())
248  {
249  $a_tpl->setVariable("DISABLED",
250  " disabled=\"disabled\"");
251  }
252 
253  // constraints
254  if ($this->getDecimals() > 0)
255  {
256  $constraints = $lng->txt("form_format").": ###.".str_repeat("#", $this->getDecimals());
257  $delim = ", ";
258  }
259  if ($this->getMinValue() !== false)
260  {
261  $constraints.= $delim.$lng->txt("form_min_value").": ".$this->getMinValue();
262  $delim = ", ";
263  }
264  if ($this->getMaxValue() !== false)
265  {
266  $constraints.= $delim.$lng->txt("form_max_value").": ".$this->getMaxValue();
267  $delim = ", ";
268  }
269  if ($constraints != "")
270  {
271  $a_tpl->setVariable("TXT_NUMBER_CONSTRAINTS", $constraints);
272  }
273 
274  $a_tpl->parseCurrentBlock();
275  }
276 }