ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
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("fontsize");
54 }
55
61 public function setValue($a_value)
62 {
63 $this->value = $a_value;
64 }
65
71 public function getValue()
72 {
73 return $this->value;
74 }
75
81 public function checkInput()
82 {
84
85 $type = $_POST[$this->getPostVar()]["type"] =
86 ilUtil::stripSlashes($_POST[$this->getPostVar()]["type"]);
87 $num_value = $_POST[$this->getPostVar()]["num_value"] =
88 ilUtil::stripSlashes($_POST[$this->getPostVar()]["num_value"]);
89 $num_unit = $_POST[$this->getPostVar()]["num_unit"] =
90 ilUtil::stripSlashes($_POST[$this->getPostVar()]["num_unit"]);
91 $pre_value = $_POST[$this->getPostVar()]["pre_value"] =
92 ilUtil::stripSlashes($_POST[$this->getPostVar()]["pre_value"]);
93
94 if ($this->getRequired() && $type == "numeric" && trim($num_value) == "") {
95 $this->setAlert($lng->txt("msg_input_is_required"));
96
97 return false;
98 }
99
100 if ($type == "numeric") {
101 if (!is_numeric($num_value) && $num_value != "") {
102 $this->setAlert($lng->txt("sty_msg_input_must_be_numeric"));
103
104 return false;
105 }
106
107 if (trim($num_value) != "") {
108 $this->setValue($num_value . $num_unit);
109 }
110 } else {
111 $this->setValue($pre_value);
112 }
113
114 return true;
115 }
116
120 public function insert(&$a_tpl)
121 {
122 $tpl = new ilTemplate("tpl.prop_fontsize.html", true, true, "Services/Style/Content");
123
124 $tpl->setVariable("POSTVAR", $this->getPostVar());
125
127 $pre_options = ilObjStyleSheet::_getStyleParameterValues("font-size");
128
129 $value = strtolower(trim($this->getValue()));
130
131 if (in_array($value, $pre_options)) {
132 $current_type = "pre";
133 $tpl->setVariable("PREDEFINED_SELECTED", 'checked="checked"');
134 } else {
135 $current_type = "unit";
136 $tpl->setVariable("NUMERIC_SELECTED", 'checked="checked"');
137 $current_unit = "";
138 foreach ($unit_options as $u) {
139 if (substr($value, strlen($value) - strlen($u)) == $u) {
140 $current_unit = $u;
141 }
142 }
143 $tpl->setVariable(
144 "VAL_NUM",
145 substr($value, 0, strlen($value) - strlen($current_unit))
146 );
147 if ($current_unit == "") {
148 $current_unit = "px";
149 }
150 }
151
152 foreach ($unit_options as $option) {
153 $tpl->setCurrentBlock("unit_option");
154 $tpl->setVariable("VAL_UNIT", $option);
155 $tpl->setVariable("TXT_UNIT", $option);
156 if ($current_type == "unit" && $current_unit == $option) {
157 $tpl->setVariable("UNIT_SELECTED", 'selected="selected"');
158 }
159 $tpl->parseCurrentBlock();
160 }
161
162 foreach ($pre_options as $option) {
163 $tpl->setCurrentBlock("pre_option");
164 $tpl->setVariable("VAL_PRE", $option);
165 $tpl->setVariable("TXT_PRE", $option);
166 if ($current_type == "pre" && $value == $option) {
167 $tpl->setVariable("PRE_SELECTED", 'selected="selected"');
168 }
169 $tpl->parseCurrentBlock();
170 }
171
172 $a_tpl->setCurrentBlock("prop_generic");
173 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
174 $a_tpl->parseCurrentBlock();
175 }
176
182 public function setValueByArray($a_values)
183 {
185
186 if ($a_values[$this->getPostVar()]["type"] == "predefined") {
187 $this->setValue($a_values[$this->getPostVar()]["pre_value"]);
188 } else {
189 $this->setValue($a_values[$this->getPostVar()]["num_value"] .
190 $a_values[$this->getPostVar()]["num_unit"]);
191 }
192 }
193}
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 fint size property in a property form.
checkInput()
Check input, strip slashes etc.
__construct($a_title="", $a_postvar="")
Constructor.
setValue($a_value)
Set Value.
insert(&$a_tpl)
Insert property html.
setValueByArray($a_values)
Set value by array.
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)
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