ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
36  protected $user;
37 
38  protected $value;
39  protected $allowpercentage = true;
40 
47  public function __construct($a_title = "", $a_postvar = "")
48  {
49  global $DIC;
50 
51  $this->lng = $DIC->language();
52  $this->user = $DIC->user();
53  parent::__construct($a_title, $a_postvar);
54  $this->setType("style_numeric");
55  }
56 
62  public function setValue($a_value)
63  {
64  $this->value = $a_value;
65  }
66 
72  public function getValue()
73  {
74  return $this->value;
75  }
76 
82  public function setAllowPercentage($a_allowpercentage)
83  {
84  $this->allowpercentage = $a_allowpercentage;
85  }
86 
92  public function getAllowPercentage()
93  {
95  }
96 
102  public function checkInput()
103  {
104  $lng = $this->lng;
105 
106  $num_value = $_POST[$this->getPostVar()]["num_value"] =
107  trim(ilUtil::stripSlashes($_POST[$this->getPostVar()]["num_value"]));
108  $num_unit = $_POST[$this->getPostVar()]["num_unit"] =
109  trim(ilUtil::stripSlashes($_POST[$this->getPostVar()]["num_unit"]));
110 
111  if ($this->getRequired() && trim($num_value) == "") {
112  $this->setAlert($lng->txt("msg_input_is_required"));
113 
114  return false;
115  }
116 
117  if (!is_numeric($num_value) && $num_value != "") {
118  $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
119 
120  return false;
121  }
122 
123  if (trim($num_value) != "") {
124  $this->setValue($num_value . $num_unit);
125  }
126 
127  return true;
128  }
129 
133  public function insert(&$a_tpl)
134  {
135  $tpl = new ilTemplate("tpl.prop_style_numeric.html", true, true, "Services/Style/Content");
136 
137  $tpl->setVariable("POSTVAR", $this->getPostVar());
138 
140 
141  $value = strtolower(trim($this->getValue()));
142 
143  $current_unit = "";
144  foreach ($unit_options as $u) {
145  if (substr($value, strlen($value) - strlen($u)) == $u) {
146  $current_unit = $u;
147  }
148  }
149  $tpl->setVariable(
150  "VAL_NUM",
151  substr($value, 0, strlen($value) - strlen($current_unit))
152  );
153  if ($current_unit == "") {
154  $current_unit = "px";
155  }
156 
157  foreach ($unit_options as $option) {
158  $tpl->setCurrentBlock("unit_option");
159  $tpl->setVariable("VAL_UNIT", $option);
160  $tpl->setVariable("TXT_UNIT", $option);
161  if ($current_unit == $option) {
162  $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
163  }
164  $tpl->parseCurrentBlock();
165  }
166 
167  $a_tpl->setCurrentBlock("prop_generic");
168  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
169  $a_tpl->parseCurrentBlock();
170  }
171 
177  public function setValueByArray($a_values)
178  {
180 
181  $this->setValue($a_values[$this->getPostVar()]["num_value"] .
182  $a_values[$this->getPostVar()]["num_unit"]);
183  }
184 }
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
setValueByArray($a_values)
Set value by array.
setAllowPercentage($a_allowpercentage)
Set Allow Percentage.
checkInput()
Check input, strip slashes etc.
user()
Definition: user.php:4
This class represents a numeric style property in a property form.
setAlert($a_alert)
Set Alert Text.
setType($a_type)
Set Type.
special template class to simplify handling of ITX/PEAR
$ilUser
Definition: imgupload.php:18
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
__construct($a_title="", $a_postvar="")
Constructor.
static _getStyleParameterNumericUnits($a_no_percentage=false)
This class represents a property in a property form.
$_POST["username"]