ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilTRBLBorderWidthInputGUI.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
46 public function __construct($a_title = "", $a_postvar = "")
47 {
48 global $DIC;
49
50 $this->lng = $DIC->language();
51 $this->user = $DIC->user();
52 parent::__construct($a_title, $a_postvar);
53 $this->setType("border_width");
54 $this->dirs = array("all", "top", "bottom", "left", "right");
55 }
56
62 public function setAllValue($a_allvalue)
63 {
64 $this->allvalue = $a_allvalue;
65 }
66
72 public function getAllValue()
73 {
74 return $this->allvalue;
75 }
76
82 public function setTopValue($a_topvalue)
83 {
84 $this->topvalue = $a_topvalue;
85 }
86
92 public function getTopValue()
93 {
94 return $this->topvalue;
95 }
96
102 public function setBottomValue($a_bottomvalue)
103 {
104 $this->bottomvalue = $a_bottomvalue;
105 }
106
112 public function getBottomValue()
113 {
114 return $this->bottomvalue;
115 }
116
122 public function setLeftValue($a_leftvalue)
123 {
124 $this->leftvalue = $a_leftvalue;
125 }
126
132 public function getLeftValue()
133 {
134 return $this->leftvalue;
135 }
136
142 public function setRightValue($a_rightvalue)
143 {
144 $this->rightvalue = $a_rightvalue;
145 }
146
152 public function getRightValue()
153 {
154 return $this->rightvalue;
155 }
156
162 public function checkInput()
163 {
165
166 foreach ($this->dirs as $dir) {
167 $type = $_POST[$this->getPostVar()][$dir]["type"] =
168 ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["type"]);
169 $num_value = $_POST[$this->getPostVar()][$dir]["num_value"] =
170 trim(ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["num_value"]));
171 $num_unit = $_POST[$this->getPostVar()][$dir]["num_unit"] =
172 trim(ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["num_unit"]));
173 $pre_value = $_POST[$this->getPostVar()][$dir]["pre_calue"] =
174 ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["pre_value"]);
175
176 /*
177 if ($this->getRequired() && trim($num_value) == "")
178 {
179 $this->setAlert($lng->txt("msg_input_is_required"));
180
181 return false;
182 }*/
183
184 if (!is_numeric($num_value) && $num_value != "") {
185 $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
186 return false;
187 }
188
189 $value = "";
190 if ($type == "numeric") {
191 if ($num_value != "") {
192 $value = $num_value . $num_unit;
193 }
194 } else {
195 $value = $pre_value;
196 }
197
198 if (trim($value) != "") {
199 switch ($dir) {
200 case "all": $this->setAllValue($value); break;
201 case "top": $this->setTopValue($value); break;
202 case "bottom": $this->setBottomValue($value); break;
203 case "left": $this->setLeftValue($value); break;
204 case "right": $this->setRightValue($value); break;
205 }
206 }
207 }
208
209 return true;
210 }
211
215 public function insert(&$a_tpl)
216 {
218
219 $layout_tpl = new ilTemplate("tpl.prop_trbl_layout.html", true, true, "Services/Style/Content");
220
221 foreach ($this->dirs as $dir) {
222 $tpl = new ilTemplate("tpl.prop_trbl_border_width.html", true, true, "Services/Style/Content");
224 $pre_options = ilObjStyleSheet::_getStyleParameterValues("border-width");
225
226 switch ($dir) {
227 case "all": $value = strtolower(trim($this->getAllValue())); break;
228 case "top": $value = strtolower(trim($this->getTopValue())); break;
229 case "bottom": $value = strtolower(trim($this->getBottomValue())); break;
230 case "left": $value = strtolower(trim($this->getLeftValue())); break;
231 case "right": $value = strtolower(trim($this->getRightValue())); break;
232 }
233
234 if (in_array($value, $pre_options)) {
235 $current_type = "pre";
236 $tpl->setVariable("PREDEFINED_SELECTED", 'checked="checked"');
237 } else {
238 $current_type = "unit";
239 $tpl->setVariable("NUMERIC_SELECTED", 'checked="checked"');
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 $tpl->setVariable("VAL_NUM", $disp_val);
252 }
253
254 foreach ($unit_options as $option) {
255 $tpl->setCurrentBlock("unit_option");
256 $tpl->setVariable("VAL_UNIT", $option);
257 $tpl->setVariable("TXT_UNIT", $option);
258 if ($current_type == "unit" && $current_unit == $option) {
259 $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
260 }
261 $tpl->parseCurrentBlock();
262 }
263
264 foreach ($pre_options as $option) {
265 $tpl->setCurrentBlock("pre_option");
266 $tpl->setVariable("VAL_PRE", $option);
267 $tpl->setVariable("TXT_PRE", $option);
268 if ($current_type == "pre" && $value == $option) {
269 $tpl->setVariable("PRE_SELECTED", 'selected="selected"');
270 }
271 $tpl->parseCurrentBlock();
272 }
273
274 $tpl->setVariable("POSTVAR", $this->getPostVar());
275 $tpl->setVariable("TXT_DIR", $lng->txt("sty_$dir"));
276 $tpl->setVariable("DIR", $dir);
277
278 $layout_tpl->setVariable(strtoupper($dir), $tpl->get());
279 }
280 $layout_tpl->setVariable("COLSPAN", "2");
281
282 $a_tpl->setCurrentBlock("prop_generic");
283 $a_tpl->setVariable("PROP_GENERIC", $layout_tpl->get());
284 $a_tpl->parseCurrentBlock();
285 }
286
292 public function setValueByArray($a_values)
293 {
295
296 if ($a_values[$this->getPostVar()]["all"]["type"] == "predefined") {
297 $this->setAllValue($a_values[$this->getPostVar()]["all"]["pre_value"]);
298 } else {
299 $this->setAllValue($a_values[$this->getPostVar()]["all"]["num_value"] .
300 $a_values[$this->getPostVar()]["all"]["num_unit"]);
301 }
302 if ($a_values[$this->getPostVar()]["bottom"]["type"] == "predefined") {
303 $this->setBottomValue($a_values[$this->getPostVar()]["bottom"]["pre_value"]);
304 } else {
305 $this->setBottomValue($a_values[$this->getPostVar()]["bottom"]["num_value"] .
306 $a_values[$this->getPostVar()]["bottom"]["num_unit"]);
307 }
308 if ($a_values[$this->getPostVar()]["top"]["type"] == "predefined") {
309 $this->setTopValue($a_values[$this->getPostVar()]["top"]["pre_value"]);
310 } else {
311 $this->setTopValue($a_values[$this->getPostVar()]["top"]["num_value"] .
312 $a_values[$this->getPostVar()]["top"]["num_unit"]);
313 }
314 if ($a_values[$this->getPostVar()]["left"]["type"] == "predefined") {
315 $this->setLeftValue($a_values[$this->getPostVar()]["left"]["pre_value"]);
316 } else {
317 $this->setLeftValue($a_values[$this->getPostVar()]["left"]["num_value"] .
318 $a_values[$this->getPostVar()]["left"]["num_unit"]);
319 }
320 if ($a_values[$this->getPostVar()]["right"]["type"] == "predefined") {
321 $this->setRightValue($a_values[$this->getPostVar()]["right"]["pre_value"]);
322 } else {
323 $this->setRightValue($a_values[$this->getPostVar()]["right"]["num_value"] .
324 $a_values[$this->getPostVar()]["right"]["num_unit"]);
325 }
326 }
327}
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)
static _getStyleParameterValues($par)
This class represents a border width with all/top/right/bottom/left in a property form.
checkInput()
Check input, strip slashes etc.
setLeftValue($a_leftvalue)
Set Left Value.
setTopValue($a_topvalue)
Set Top Value.
insert(&$a_tpl)
Insert property html.
setBottomValue($a_bottomvalue)
Set Bottom Value.
setRightValue($a_rightvalue)
Set Right Value.
setAllValue($a_allvalue)
Set All Value.
__construct($a_title="", $a_postvar="")
Constructor.
setValueByArray($a_values)
Set value by array.
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