ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBackgroundPositionInputGUI.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 
41  function __construct($a_title = "", $a_postvar = "")
42  {
43  parent::__construct($a_title, $a_postvar);
44  $this->setType("border_width");
45  $this->dirs = array("horizontal", "vertical");
46  }
47 
53  function setHorizontalValue($a_horizontalvalue)
54  {
55  $this->horizontalvalue = $a_horizontalvalue;
56  }
57 
63  function getHorizontalValue()
64  {
65  return $this->horizontalvalue;
66  }
67 
73  function setVerticalValue($a_verticalvalue)
74  {
75  $this->verticalvalue = $a_verticalvalue;
76  }
77 
83  function getVerticalValue()
84  {
85  return $this->verticalvalue;
86  }
87 
91  function getValue()
92  {
93  if ($this->getHorizontalValue() != "")
94  {
95  if ($this->getVerticalValue() != "")
96  {
97  return $this->getHorizontalValue()." ".$this->getVerticalValue();
98  }
99  else
100  {
101  return $this->getHorizontalValue();
102  }
103  }
104  else
105  {
106  if ($this->getVerticalValue() != "")
107  {
108  return "left ".$this->getVerticalValue();
109  }
110  }
111  return "";
112  }
113 
117  function setValue($a_val)
118  {
119  $a_val = trim($a_val);
120  $a_val_arr = explode(" ", $a_val);
121  $hor = trim($a_val_arr[0]);
122  $ver = trim($a_val_arr[1]);
123  if ($hor == "center" && $ver == "")
124  {
125  $ver = "center";
126  }
127  $this->setHorizontalValue($hor);
128  $this->setVerticalValue($ver);
129  }
130 
136  function checkInput()
137  {
138  global $lng;
139 
140  foreach ($this->dirs as $dir)
141  {
142  $type = $_POST[$this->getPostVar()][$dir]["type"] =
143  ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["type"]);
144  $num_value = $_POST[$this->getPostVar()][$dir]["num_value"] =
145  trim(ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["num_value"]));
146  $num_unit = $_POST[$this->getPostVar()][$dir]["num_unit"] =
147  trim(ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["num_unit"]));
148  $pre_value = $_POST[$this->getPostVar()][$dir]["pre_calue"] =
149  ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["pre_value"]);
150 
151  /*
152  if ($this->getRequired() && trim($num_value) == "")
153  {
154  $this->setAlert($lng->txt("msg_input_is_required"));
155 
156  return false;
157  }*/
158 
159  if (!is_numeric($num_value) && trim($num_value) != "")
160  {
161  $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
162  return false;
163  }
164 
165  $value = "";
166  if ($type == "numeric")
167  {
168  if ($num_value != "")
169  {
170  $value = $num_value.$num_unit;
171  }
172  }
173  else
174  {
175  $value = $pre_value;
176  }
177 
178  if (trim($value) != "")
179  {
180  switch ($dir)
181  {
182  case "horizontal": $this->setHorizontalValue($value); break;
183  case "vertical": $this->setVerticalValue($value); break;
184  }
185  }
186 
187  }
188 
189  return true;
190  }
191 
195  function insert(&$a_tpl)
196  {
197  global $lng;
198 
199  $layout_tpl = new ilTemplate("tpl.prop_hv_layout.html", true, true, "Services/Style");
200 
201  foreach ($this->dirs as $dir)
202  {
203  $tpl = new ilTemplate("tpl.prop_background_position.html", true, true, "Services/Style");
205  $pre_options = ilObjStyleSheet::_getStyleParameterValues("background-position");
206  $pre_options = $pre_options[$dir];
207  switch($dir)
208  {
209  case "horizontal": $value = strtolower(trim($this->getHorizontalValue())); break;
210  case "vertical": $value = strtolower(trim($this->getVerticalValue())); break;
211  }
212 
213  if (in_array($value, $pre_options))
214  {
215  $current_type = "pre";
216  $tpl->setVariable("PREDEFINED_SELECTED", 'checked="checked"');
217  }
218  else
219  {
220  $current_type = "unit";
221  $tpl->setVariable("NUMERIC_SELECTED", 'checked="checked"');
222 
223  $current_unit = "";
224  foreach ($unit_options as $u)
225  {
226  if (substr($value, strlen($value) - strlen($u)) == $u)
227  {
228  $current_unit = $u;
229  }
230  }
231  $disp_val = substr($value, 0, strlen($value) - strlen($current_unit));
232  if ($current_unit == "")
233  {
234  $current_unit = "px";
235  }
236  $tpl->setVariable("VAL_NUM", $disp_val);
237  }
238 
239  foreach ($unit_options as $option)
240  {
241  $tpl->setCurrentBlock("unit_option");
242  $tpl->setVariable("VAL_UNIT", $option);
243  $tpl->setVariable("TXT_UNIT", $option);
244  if ($current_type == "unit" && $current_unit == $option)
245  {
246  $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
247  }
248  $tpl->parseCurrentBlock();
249  }
250 
251  foreach ($pre_options as $option)
252  {
253  $tpl->setCurrentBlock("pre_option");
254  $tpl->setVariable("VAL_PRE", $option);
255  $tpl->setVariable("TXT_PRE", $option);
256  if ($current_type == "pre" && $value == $option)
257  {
258  $tpl->setVariable("PRE_SELECTED", 'selected="selected"');
259  }
260  $tpl->parseCurrentBlock();
261  }
262 
263  $tpl->setVariable("POSTVAR", $this->getPostVar());
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  $layout_tpl->setVariable("COLSPAN", "2");
270 
271  $a_tpl->setCurrentBlock("prop_generic");
272  $a_tpl->setVariable("PROP_GENERIC", $layout_tpl->get());
273  $a_tpl->parseCurrentBlock();
274  }
275 
281  function setValueByArray($a_values)
282  {
283  global $ilUser;
284 
285  if ($a_values[$this->getPostVar()]["horizontal"]["type"] == "predefined")
286  {
287  $this->setHorizontalValue($a_values[$this->getPostVar()]["horizontal"]["pre_value"]);
288  }
289  else
290  {
291  $this->setHorizontalValue($a_values[$this->getPostVar()]["horizontal"]["num_value"].
292  $a_values[$this->getPostVar()]["horizontal"]["num_unit"]);
293  }
294  if ($a_values[$this->getPostVar()]["vertical"]["type"] == "predefined")
295  {
296  $this->setVerticalValue($a_values[$this->getPostVar()]["vertical"]["pre_value"]);
297  }
298  else
299  {
300  $this->setVerticalValue($a_values[$this->getPostVar()]["vertical"]["num_value"].
301  $a_values[$this->getPostVar()]["vertical"]["num_unit"]);
302  }
303  }
304 
305 }