ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCheckboxInputGUI.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 
24 include_once 'Services/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php';
25 
34 {
38  protected $lng;
39 
40  protected $value = "1";
41  protected $checked;
42  protected $optiontitle = "";
43  protected $additional_attributes = '';
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->setType("checkbox");
58  }
59 
65  public function setValue($a_value)
66  {
67  $this->value = $a_value;
68  }
69 
75  public function getValue()
76  {
77  return $this->value;
78  }
79 
85  public function setChecked($a_checked)
86  {
87  $this->checked = $a_checked;
88  }
89 
95  public function getChecked()
96  {
97  return $this->checked;
98  }
99 
105  public function setOptionTitle($a_optiontitle)
106  {
107  $this->optiontitle = $a_optiontitle;
108  }
109 
115  public function getOptionTitle()
116  {
117  return $this->optiontitle;
118  }
119 
125  public function setValueByArray($a_values)
126  {
127  $this->setChecked($a_values[$this->getPostVar()]);
128  foreach ($this->getSubItems() as $item) {
129  $item->setValueByArray($a_values);
130  }
131  }
132 
138  public function setAdditionalAttributes($a_attrs)
139  {
140  $this->additional_attributes = $a_attrs;
141  }
142 
147  public function getAdditionalAttributes()
148  {
150  }
151 
157  public function checkInput()
158  {
159  $lng = $this->lng;
160 
161  $_POST[$this->getPostVar()] =
163 
164  // getRequired() is NOT processed here!
165 
166  $ok = $this->checkSubItemsInput();
167 
168  // only not ok, if checkbox not checked
169  if (!$ok && $_POST[$this->getPostVar()] == "") {
170  $ok = true;
171  }
172 
173  return $ok;
174  }
175 
180  public function hideSubForm()
181  {
182  return !$this->getChecked();
183  }
184 
188  public function render($a_mode = '')
189  {
190  $tpl = new ilTemplate("tpl.prop_checkbox.html", true, true, "Services/Form");
191 
192  $tpl->setVariable("POST_VAR", $this->getPostVar());
193  $tpl->setVariable("ID", $this->getFieldId());
194  $tpl->setVariable("PROPERTY_VALUE", $this->getValue());
195  $tpl->setVariable("OPTION_TITLE", $this->getOptionTitle());
196  if (strlen($this->getAdditionalAttributes())) {
197  $tpl->setVariable('PROP_CHECK_ATTRS', $this->getAdditionalAttributes());
198  }
199  if ($this->getChecked()) {
200  $tpl->setVariable(
201  "PROPERTY_CHECKED",
202  'checked="checked"'
203  );
204  }
205  if ($this->getDisabled()) {
206  $tpl->setVariable(
207  "DISABLED",
208  'disabled="disabled"'
209  );
210  }
211 
212  if ($a_mode == "toolbar") {
213  // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
214  // -moz-inline-stack for FF2
215  // zoom 1; *display:inline for IE6 & 7
216  $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline;');
217  }
218 
219  return $tpl->get();
220  }
221 
227  public function insert($a_tpl)
228  {
229  $html = $this->render();
230 
231  $a_tpl->setCurrentBlock("prop_generic");
232  $a_tpl->setVariable("PROP_GENERIC", $html);
233  $a_tpl->parseCurrentBlock();
234  }
235 
239  public function getTableFilterHTML()
240  {
241  $html = $this->render();
242  return $html;
243  }
244 
248  public function serializeData()
249  {
250  return serialize($this->getChecked());
251  }
252 
256  public function unserializeData($a_data)
257  {
258  $data = unserialize($a_data);
259 
260  if ($data) {
261  $this->setValue($data);
262  $this->setChecked(true);
263  }
264  }
265 
269  public function getToolbarHTML()
270  {
271  $html = $this->render('toolbar');
272  return $html;
273  }
274 }
insert($a_tpl)
Insert property html.
getOptionTitle()
Get Option Title (optional).
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
Interface for property form input GUI classes that can be used in ilToolbarGUI.
This class represents a checkbox property in a property form.
checkInput()
Check input, strip slashes etc.
setType($a_type)
Set Type.
setChecked($a_checked)
Set Checked.
render($a_mode='')
Render item.
setAdditionalAttributes($a_attrs)
Set addiotional attributes.
unserializeData($a_data)
unserialize data
getFieldId()
Get Post Variable.
setValue($a_value)
Set Value.
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
hideSubForm()
Sub form hidden on init?
getTableFilterHTML()
Get HTML for table filter.
__construct($a_title="", $a_postvar="")
Constructor.
This class represents a property that may include a sub form.
getAdditionalAttributes()
get addtional attributes
setValueByArray($a_values)
Set value by array.
setOptionTitle($a_optiontitle)
Set Option Title (optional).
getToolbarHTML()
Get HTML for toolbar.
$_POST["username"]
$html
Definition: example_001.php:87