ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
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  $this->dirs = array("all", "top", "bottom", "left", "right");
47  }
48 
54  function setAllValue($a_allvalue)
55  {
56  $this->allvalue = $a_allvalue;
57  }
58 
64  function getAllValue()
65  {
66  return $this->allvalue;
67  }
68 
74  function setTopValue($a_topvalue)
75  {
76  $this->topvalue = $a_topvalue;
77  }
78 
84  function getTopValue()
85  {
86  return $this->topvalue;
87  }
88 
94  function setBottomValue($a_bottomvalue)
95  {
96  $this->bottomvalue = $a_bottomvalue;
97  }
98 
104  function getBottomValue()
105  {
106  return $this->bottomvalue;
107  }
108 
114  function setLeftValue($a_leftvalue)
115  {
116  $this->leftvalue = $a_leftvalue;
117  }
118 
124  function getLeftValue()
125  {
126  return $this->leftvalue;
127  }
128 
134  function setRightValue($a_rightvalue)
135  {
136  $this->rightvalue = $a_rightvalue;
137  }
138 
144  function getRightValue()
145  {
146  return $this->rightvalue;
147  }
148 
154  function setAllowPercentage($a_allowpercentage)
155  {
156  $this->allowpercentage = $a_allowpercentage;
157  }
158 
165  {
166  return $this->allowpercentage;
167  }
168 
174  function checkInput()
175  {
176  global $lng;
177 
178  foreach ($this->dirs as $dir)
179  {
180  $num_value = $_POST[$this->getPostVar()][$dir]["num_value"] =
181  trim(ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["num_value"]));
182  $num_unit = $_POST[$this->getPostVar()][$dir]["num_unit"] =
183  trim(ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["num_unit"]));
184 
185  /*
186  if ($this->getRequired() && trim($num_value) == "")
187  {
188  $this->setAlert($lng->txt("msg_input_is_required"));
189 
190  return false;
191  }*/
192 
193  if (!is_numeric($num_value) && $num_value != "")
194  {
195  $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
196  return false;
197  }
198 
199  if (trim($num_value) != "")
200  {
201  switch ($dir)
202  {
203  case "all": $this->setAllValue($num_value.$num_unit); break;
204  case "top": $this->setTopValue($num_value.$num_unit); break;
205  case "bottom": $this->setBottomValue($num_value.$num_unit); break;
206  case "left": $this->setLeftValue($num_value.$num_unit); break;
207  case "right": $this->setRightValue($num_value.$num_unit); break;
208  }
209  }
210  }
211 
212  return true;
213  }
214 
218  function insert(&$a_tpl)
219  {
220  global $lng;
221 
222  $layout_tpl = new ilTemplate("tpl.prop_trbl_layout.html", true, true, "Services/Style");
223 
224  foreach ($this->dirs as $dir)
225  {
226  $tpl = new ilTemplate("tpl.prop_trbl_style_numeric.html", true, true, "Services/Style");
228 
229  switch($dir)
230  {
231  case "all": $value = strtolower(trim($this->getAllValue())); break;
232  case "top": $value = strtolower(trim($this->getTopValue())); break;
233  case "bottom": $value = strtolower(trim($this->getBottomValue())); break;
234  case "left": $value = strtolower(trim($this->getLeftValue())); break;
235  case "right": $value = strtolower(trim($this->getRightValue())); break;
236  }
237 
238  $current_unit = "";
239  foreach ($unit_options as $u)
240  {
241  if (substr($value, strlen($value) - strlen($u)) == $u)
242  {
243  $current_unit = $u;
244  }
245  }
246  $disp_val = substr($value, 0, strlen($value) - strlen($current_unit));
247  if ($current_unit == "")
248  {
249  $current_unit = "px";
250  }
251 
252  foreach ($unit_options as $option)
253  {
254  $tpl->setCurrentBlock("unit_option");
255  $tpl->setVariable("VAL_UNIT", $option);
256  $tpl->setVariable("TXT_UNIT", $option);
257  if ($current_unit == $option)
258  {
259  $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
260  }
261  $tpl->parseCurrentBlock();
262  }
263 
264  $tpl->setVariable("POSTVAR", $this->getPostVar());
265  $tpl->setVariable("VAL_NUM", $disp_val);
266  $tpl->setVariable("TXT_DIR", $lng->txt("sty_$dir"));
267  $tpl->setVariable("DIR", $dir);
268 
269  $layout_tpl->setVariable(strtoupper($dir), $tpl->get());
270  }
271 
272  $a_tpl->setCurrentBlock("prop_generic");
273  $a_tpl->setVariable("PROP_GENERIC", $layout_tpl->get());
274  $a_tpl->parseCurrentBlock();
275  }
276 
282  function setValueByArray($a_values)
283  {
284  global $ilUser;
285 
286  $this->setAllValue($a_values[$this->getPostVar()]["all"]["num_value"].
287  $a_values[$this->getPostVar()]["all"]["num_unit"]);
288  $this->setBottomValue($a_values[$this->getPostVar()]["bottom"]["num_value"].
289  $a_values[$this->getPostVar()]["bottom"]["num_unit"]);
290  $this->setTopValue($a_values[$this->getPostVar()]["top"]["num_value"].
291  $a_values[$this->getPostVar()]["top"]["num_unit"]);
292  $this->setLeftValue($a_values[$this->getPostVar()]["left"]["num_value"].
293  $a_values[$this->getPostVar()]["left"]["num_unit"]);
294  $this->setRightValue($a_values[$this->getPostVar()]["right"]["num_value"].
295  $a_values[$this->getPostVar()]["right"]["num_unit"]);
296  }
297 
298 }