ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNumericStyleValueInputGUI.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 $allowpercentage = true;
35 
42  function __construct($a_title = "", $a_postvar = "")
43  {
44  parent::__construct($a_title, $a_postvar);
45  $this->setType("style_numeric");
46 
47  }
48 
54  function setValue($a_value)
55  {
56  $this->value = $a_value;
57  }
58 
64  function getValue()
65  {
66  return $this->value;
67  }
68 
74  function setAllowPercentage($a_allowpercentage)
75  {
76  $this->allowpercentage = $a_allowpercentage;
77  }
78 
84  function getAllowPercentage()
85  {
87  }
88 
94  function checkInput()
95  {
96  global $lng;
97 
98  $num_value = $_POST[$this->getPostVar()]["num_value"] =
99  trim(ilUtil::stripSlashes($_POST[$this->getPostVar()]["num_value"]));
100  $num_unit = $_POST[$this->getPostVar()]["num_unit"] =
101  trim(ilUtil::stripSlashes($_POST[$this->getPostVar()]["num_unit"]));
102 
103  if ($this->getRequired() && trim($num_value) == "")
104  {
105  $this->setAlert($lng->txt("msg_input_is_required"));
106 
107  return false;
108  }
109 
110  if (!is_numeric($num_value) && $num_value != "")
111  {
112  $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
113 
114  return false;
115  }
116 
117  if (trim($num_value) != "")
118  {
119  $this->setValue($num_value.$num_unit);
120  }
121 
122  return true;
123  }
124 
128  function insert(&$a_tpl)
129  {
130  $tpl = new ilTemplate("tpl.prop_style_numeric.html", true, true, "Services/Style");
131 
132  $tpl->setVariable("POSTVAR", $this->getPostVar());
133 
135 
136  $value = strtolower(trim($this->getValue()));
137 
138  $current_unit = "";
139  foreach ($unit_options as $u)
140  {
141  if (substr($value, strlen($value) - strlen($u)) == $u)
142  {
143  $current_unit = $u;
144  }
145  }
146  $tpl->setVariable("VAL_NUM",
147  substr($value, 0, strlen($value) - strlen($current_unit)));
148  if ($current_unit == "")
149  {
150  $current_unit = "px";
151  }
152 
153  foreach ($unit_options as $option)
154  {
155  $tpl->setCurrentBlock("unit_option");
156  $tpl->setVariable("VAL_UNIT", $option);
157  $tpl->setVariable("TXT_UNIT", $option);
158  if ($current_unit == $option)
159  {
160  $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
161  }
162  $tpl->parseCurrentBlock();
163  }
164 
165  $a_tpl->setCurrentBlock("prop_generic");
166  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
167  $a_tpl->parseCurrentBlock();
168  }
169 
175  function setValueByArray($a_values)
176  {
177  global $ilUser;
178 
179  $this->setValue($a_values[$this->getPostVar()]["num_value"].
180  $a_values[$this->getPostVar()]["num_unit"]);
181  }
182 
183 }