ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTRBLNumericStyleValueInputGUI.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 $this->dirs = array("all", "top", "bottom", "left", "right");
56 }
57
63 public function setAllValue($a_allvalue)
64 {
65 $this->allvalue = $a_allvalue;
66 }
67
73 public function getAllValue()
74 {
75 return $this->allvalue;
76 }
77
83 public function setTopValue($a_topvalue)
84 {
85 $this->topvalue = $a_topvalue;
86 }
87
93 public function getTopValue()
94 {
95 return $this->topvalue;
96 }
97
103 public function setBottomValue($a_bottomvalue)
104 {
105 $this->bottomvalue = $a_bottomvalue;
106 }
107
113 public function getBottomValue()
114 {
115 return $this->bottomvalue;
116 }
117
123 public function setLeftValue($a_leftvalue)
124 {
125 $this->leftvalue = $a_leftvalue;
126 }
127
133 public function getLeftValue()
134 {
135 return $this->leftvalue;
136 }
137
143 public function setRightValue($a_rightvalue)
144 {
145 $this->rightvalue = $a_rightvalue;
146 }
147
153 public function getRightValue()
154 {
155 return $this->rightvalue;
156 }
157
163 public function setAllowPercentage($a_allowpercentage)
164 {
165 $this->allowpercentage = $a_allowpercentage;
166 }
167
173 public function getAllowPercentage()
174 {
176 }
177
183 public function checkInput()
184 {
186
187 foreach ($this->dirs as $dir) {
188 $num_value = $_POST[$this->getPostVar()][$dir]["num_value"] =
189 trim(ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["num_value"]));
190 $num_unit = $_POST[$this->getPostVar()][$dir]["num_unit"] =
191 trim(ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["num_unit"]));
192
193 /*
194 if ($this->getRequired() && trim($num_value) == "")
195 {
196 $this->setAlert($lng->txt("msg_input_is_required"));
197
198 return false;
199 }*/
200
201 if (!is_numeric($num_value) && $num_value != "") {
202 $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
203 return false;
204 }
205
206 if (trim($num_value) != "") {
207 switch ($dir) {
208 case "all": $this->setAllValue($num_value . $num_unit); break;
209 case "top": $this->setTopValue($num_value . $num_unit); break;
210 case "bottom": $this->setBottomValue($num_value . $num_unit); break;
211 case "left": $this->setLeftValue($num_value . $num_unit); break;
212 case "right": $this->setRightValue($num_value . $num_unit); break;
213 }
214 }
215 }
216
217 return true;
218 }
219
223 public function insert(&$a_tpl)
224 {
226
227 $layout_tpl = new ilTemplate("tpl.prop_trbl_layout.html", true, true, "Services/Style/Content");
228
229 foreach ($this->dirs as $dir) {
230 $tpl = new ilTemplate("tpl.prop_trbl_style_numeric.html", true, true, "Services/Style/Content");
232
233 switch ($dir) {
234 case "all": $value = strtolower(trim($this->getAllValue())); break;
235 case "top": $value = strtolower(trim($this->getTopValue())); break;
236 case "bottom": $value = strtolower(trim($this->getBottomValue())); break;
237 case "left": $value = strtolower(trim($this->getLeftValue())); break;
238 case "right": $value = strtolower(trim($this->getRightValue())); break;
239 }
240
241 $current_unit = "";
242 foreach ($unit_options as $u) {
243 if (substr($value, strlen($value) - strlen($u)) == $u) {
244 $current_unit = $u;
245 }
246 }
247 $disp_val = substr($value, 0, strlen($value) - strlen($current_unit));
248 if ($current_unit == "") {
249 $current_unit = "px";
250 }
251
252 foreach ($unit_options as $option) {
253 $tpl->setCurrentBlock("unit_option");
254 $tpl->setVariable("VAL_UNIT", $option);
255 $tpl->setVariable("TXT_UNIT", $option);
256 if ($current_unit == $option) {
257 $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
258 }
259 $tpl->parseCurrentBlock();
260 }
261
262 $tpl->setVariable("POSTVAR", $this->getPostVar());
263 $tpl->setVariable("VAL_NUM", $disp_val);
264 $tpl->setVariable("TXT_DIR", $lng->txt("sty_$dir"));
265 $tpl->setVariable("DIR", $dir);
266
267 $layout_tpl->setVariable(strtoupper($dir), $tpl->get());
268 }
269
270 $a_tpl->setCurrentBlock("prop_generic");
271 $a_tpl->setVariable("PROP_GENERIC", $layout_tpl->get());
272 $a_tpl->parseCurrentBlock();
273 }
274
280 public function setValueByArray($a_values)
281 {
283
284 $this->setAllValue($a_values[$this->getPostVar()]["all"]["num_value"] .
285 $a_values[$this->getPostVar()]["all"]["num_unit"]);
286 $this->setBottomValue($a_values[$this->getPostVar()]["bottom"]["num_value"] .
287 $a_values[$this->getPostVar()]["bottom"]["num_unit"]);
288 $this->setTopValue($a_values[$this->getPostVar()]["top"]["num_value"] .
289 $a_values[$this->getPostVar()]["top"]["num_unit"]);
290 $this->setLeftValue($a_values[$this->getPostVar()]["left"]["num_value"] .
291 $a_values[$this->getPostVar()]["left"]["num_unit"]);
292 $this->setRightValue($a_values[$this->getPostVar()]["right"]["num_value"] .
293 $a_values[$this->getPostVar()]["right"]["num_unit"]);
294 }
295}
user()
Definition: user.php:4
$tpl
Definition: ilias.php:10
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a property in a property form.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
static _getStyleParameterNumericUnits($a_no_percentage=false)
This class represents a numeric style property with all/top/right/bottom/left in a property form.
__construct($a_title="", $a_postvar="")
Constructor.
setAllowPercentage($a_allowpercentage)
Set Allow Percentage.
special template class to simplify handling of ITX/PEAR
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18