ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCSSRectInputGUI.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 $lng;
37
38 protected $top;
39 protected $left;
40 protected $right;
41 protected $bottom;
42 protected $size;
43 protected $useUnits;
44
51 public function __construct($a_title = "", $a_postvar = "")
52 {
53 global $DIC;
54
55 $this->lng = $DIC->language();
56 parent::__construct($a_title, $a_postvar);
57 $this->size = 6;
58 $this->useUnits = true;
59 }
60
61 public function setValue($valueArray)
62 {
63 $this->top = $valueArray['top'];
64 $this->left = $valueArray['left'];
65 $this->right = $valueArray['right'];
66 $this->bottom = $valueArray['bottom'];
67 }
68
74 public function setUseUnits($a_value)
75 {
76 $this->useUnits = $a_value;
77 }
78
84 public function useUnits()
85 {
86 return $this->useUnits;
87 }
88
94 public function setTop($a_value)
95 {
96 $this->top = $a_value;
97 }
98
104 public function getTop()
105 {
106 return $this->top;
107 }
108
114 public function setBottom($a_value)
115 {
116 $this->bottom = $a_value;
117 }
118
124 public function getBottom()
125 {
126 return $this->bottom;
127 }
128
134 public function setLeft($a_value)
135 {
136 $this->left = $a_value;
137 }
138
144 public function getLeft()
145 {
146 return $this->left;
147 }
148
154 public function setRight($a_value)
155 {
156 $this->right = $a_value;
157 }
158
164 public function getRight()
165 {
166 return $this->right;
167 }
168
174 public function setSize($a_size)
175 {
176 $this->size = $a_size;
177 }
178
184 public function setValueByArray($a_values)
185 {
186 $postVar = $this->getPostVar();
187
188 $values = array(
189 'top' => $a_values[$postVar . '_top'],
190 'bottom' => $a_values[$postVar . '_bottom'],
191 'right' => $a_values[$postVar . '_right'],
192 'left' => $a_values[$postVar . '_left'],
193 );
194
195 $this->setValue($values);
196 }
197
203 public function getSize()
204 {
205 return $this->size;
206 }
207
213 public function checkInput()
214 {
216
217 $_POST[$this->getPostVar() . '_top'] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['top']);
218 $_POST[$this->getPostVar() . '_right'] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['right']);
219 $_POST[$this->getPostVar() . '_bottom'] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['bottom']);
220 $_POST[$this->getPostVar() . '_left'] = ilUtil::stripSlashes($_POST[$this->getPostVar()]['left']);
221
222 if (
223 $this->getRequired() &&
224 (
225 (trim($_POST[$this->getPostVar() . '_top'] == ""))
226 || (trim($_POST[$this->getPostVar() . '_bottom']) == "")
227 || (trim($_POST[$this->getPostVar() . '_left']) == "")
228 || (trim($_POST[$this->getPostVar() . '_right']) == "")
229 )
230 ) {
231 $this->setAlert($lng->txt("msg_input_is_required"));
232 return false;
233 }
234
235 if ($this->useUnits()) {
236 if ((!preg_match('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*))|0)(cm|mm|in|pt|pc|px|em)$/is', $_POST[$this->getPostVar() . '_top'])) ||
237 (!preg_match('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*))|0)(cm|mm|in|pt|pc|px|em)$/is', $_POST[$this->getPostVar() . '_right'])) ||
238 (!preg_match('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*))|0)(cm|mm|in|pt|pc|px|em)$/is', $_POST[$this->getPostVar() . '_bottom'])) ||
239 (!preg_match('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*))|0)(cm|mm|in|pt|pc|px|em)$/is', $_POST[$this->getPostVar() . '_left']))) {
240 $this->setAlert($lng->txt("msg_unit_is_required"));
241 return false;
242 }
243 }
244 return $this->checkSubItemsInput();
245 }
246
252 public function insert($a_tpl)
253 {
255
256 if (strlen($this->getTop())) {
257 $a_tpl->setCurrentBlock("cssrect_value_top");
258 $a_tpl->setVariable("CSSRECT_VALUE", ilUtil::prepareFormOutput($this->getTop()));
259 $a_tpl->parseCurrentBlock();
260 }
261 if (strlen($this->getBottom())) {
262 $a_tpl->setCurrentBlock("cssrect_value_bottom");
263 $a_tpl->setVariable("CSSRECT_VALUE", ilUtil::prepareFormOutput($this->getBottom()));
264 $a_tpl->parseCurrentBlock();
265 }
266 if (strlen($this->getLeft())) {
267 $a_tpl->setCurrentBlock("cssrect_value_left");
268 $a_tpl->setVariable("CSSRECT_VALUE", ilUtil::prepareFormOutput($this->getLeft()));
269 $a_tpl->parseCurrentBlock();
270 }
271 if (strlen($this->getRight())) {
272 $a_tpl->setCurrentBlock("cssrect_value_right");
273 $a_tpl->setVariable("CSSRECT_VALUE", ilUtil::prepareFormOutput($this->getRight()));
274 $a_tpl->parseCurrentBlock();
275 }
276 $a_tpl->setCurrentBlock("cssrect");
277 $a_tpl->setVariable("ID", $this->getFieldId());
278 $a_tpl->setVariable("SIZE", $this->getSize());
279 $a_tpl->setVariable("POST_VAR", $this->getPostVar());
280 $a_tpl->setVariable("TEXT_TOP", $lng->txt("pos_top"));
281 $a_tpl->setVariable("TEXT_RIGHT", $lng->txt("pos_right"));
282 $a_tpl->setVariable("TEXT_BOTTOM", $lng->txt("pos_bottom"));
283 $a_tpl->setVariable("TEXT_LEFT", $lng->txt("pos_left"));
284 if ($this->getDisabled()) {
285 $a_tpl->setVariable(
286 "DISABLED",
287 " disabled=\"disabled\""
288 );
289 }
290 $a_tpl->parseCurrentBlock();
291 }
292}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a text property in a property form.
setTop($a_value)
Set Top.
__construct($a_title="", $a_postvar="")
Constructor.
insert($a_tpl)
Insert property html.
setUseUnits($a_value)
Set use units.
setBottom($a_value)
Set Bottom.
setLeft($a_value)
Set Left.
setValueByArray($a_values)
Set value by array.
setRight($a_value)
Set Right.
checkInput()
Check input, strip slashes etc.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
This class represents a property that may include a sub form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc