ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFontSizeInputGUI.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("fontsize");
45  }
46 
52  function setValue($a_value)
53  {
54  $this->value = $a_value;
55  }
56 
62  function getValue()
63  {
64  return $this->value;
65  }
66 
72  function checkInput()
73  {
74  global $lng;
75 
76  $type = $_POST[$this->getPostVar()]["type"] =
77  ilUtil::stripSlashes($_POST[$this->getPostVar()]["type"]);
78  $num_value = $_POST[$this->getPostVar()]["num_value"] =
79  ilUtil::stripSlashes($_POST[$this->getPostVar()]["num_value"]);
80  $num_unit = $_POST[$this->getPostVar()]["num_unit"] =
81  ilUtil::stripSlashes($_POST[$this->getPostVar()]["num_unit"]);
82  $pre_value = $_POST[$this->getPostVar()]["pre_value"] =
83  ilUtil::stripSlashes($_POST[$this->getPostVar()]["pre_value"]);
84 
85  if ($this->getRequired() && $type == "numeric" && trim($num_value) == "")
86  {
87  $this->setAlert($lng->txt("msg_input_is_required"));
88 
89  return false;
90  }
91 
92  if ($type == "numeric")
93  {
94  if (!is_numeric($num_value) && $num_value != "")
95  {
96  $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
97 
98  return false;
99  }
100 
101  if (trim($num_value) != "")
102  {
103  $this->setValue($num_value.$num_unit);
104  }
105  }
106  else
107  {
108  $this->setValue($pre_value);
109  }
110 
111  return true;
112  }
113 
117  function insert(&$a_tpl)
118  {
119  $tpl = new ilTemplate("tpl.prop_fontsize.html", true, true, "Services/Style");
120 
121  $tpl->setVariable("POSTVAR", $this->getPostVar());
122 
124  $pre_options = ilObjStyleSheet::_getStyleParameterValues("font-size");
125 
126  $value = strtolower(trim($this->getValue()));
127 
128  if (in_array($value, $pre_options))
129  {
130  $current_type = "pre";
131  $tpl->setVariable("PREDEFINED_SELECTED", 'checked="checked"');
132  }
133  else
134  {
135  $current_type = "unit";
136  $tpl->setVariable("NUMERIC_SELECTED", 'checked="checked"');
137  $current_unit = "";
138  foreach ($unit_options as $u)
139  {
140  if (substr($value, strlen($value) - strlen($u)) == $u)
141  {
142  $current_unit = $u;
143  }
144  }
145  $tpl->setVariable("VAL_NUM",
146  substr($value, 0, strlen($value) - strlen($current_unit)));
147  if ($current_unit == "")
148  {
149  $current_unit = "px";
150  }
151  }
152 
153  foreach ($unit_options as $option)
154  {
155  $tpl->setCurrentBlock("unit_option");
156  $tpl->setVariable("VAL_UNIT", $option);
157  $tpl->setVariable("TXT_UNIT", $option);
158  if ($current_type == "unit" && $current_unit == $option)
159  {
160  $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
161  }
162  $tpl->parseCurrentBlock();
163  }
164 
165  foreach ($pre_options as $option)
166  {
167  $tpl->setCurrentBlock("pre_option");
168  $tpl->setVariable("VAL_PRE", $option);
169  $tpl->setVariable("TXT_PRE", $option);
170  if ($current_type == "pre" && $value == $option)
171  {
172  $tpl->setVariable("PRE_SELECTED", 'selected="selected"');
173  }
174  $tpl->parseCurrentBlock();
175  }
176 
177  $a_tpl->setCurrentBlock("prop_generic");
178  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
179  $a_tpl->parseCurrentBlock();
180  }
181 
187  function setValueByArray($a_values)
188  {
189  global $ilUser;
190 
191  if ($a_values[$this->getPostVar()]["type"] == "predefined")
192  {
193  $this->setValue($a_values[$this->getPostVar()]["pre_value"]);
194  }
195  else
196  {
197  $this->setValue($a_values[$this->getPostVar()]["num_value"].
198  $a_values[$this->getPostVar()]["num_unit"]);
199  }
200  }
201 
202 }