ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
35  protected $value = "1";
36  protected $checked;
37  protected $optiontitle = "";
38  protected $additional_attributes = '';
39 
46  function __construct($a_title = "", $a_postvar = "")
47  {
48  parent::__construct($a_title, $a_postvar);
49  $this->setType("checkbox");
50  }
51 
57  function setValue($a_value)
58  {
59  $this->value = $a_value;
60  }
61 
67  function getValue()
68  {
69  return $this->value;
70  }
71 
77  function setChecked($a_checked)
78  {
79  $this->checked = $a_checked;
80  }
81 
87  function getChecked()
88  {
89  return $this->checked;
90  }
91 
97  function setOptionTitle($a_optiontitle)
98  {
99  $this->optiontitle = $a_optiontitle;
100  }
101 
107  function getOptionTitle()
108  {
109  return $this->optiontitle;
110  }
111 
117  function setValueByArray($a_values)
118  {
119  $this->setChecked($a_values[$this->getPostVar()]);
120  foreach($this->getSubItems() as $item)
121  {
122  $item->setValueByArray($a_values);
123  }
124  }
125 
131  function setAdditionalAttributes($a_attrs)
132  {
133  $this->additional_attributes = $a_attrs;
134  }
135 
141  {
143  }
144 
150  function checkInput()
151  {
152  global $lng;
153 
154  $_POST[$this->getPostVar()] =
156 
157  // getRequired() is NOT processed here!
158 
159  $ok = $this->checkSubItemsInput();
160 
161  // only not ok, if checkbox not checked
162  if (!$ok && $_POST[$this->getPostVar()] == "")
163  {
164  $ok = true;
165  }
166 
167  return $ok;
168  }
169 
174  public function hideSubForm()
175  {
176  return !$this->getChecked();
177  }
178 
182  function render($a_mode = '')
183  {
184  $tpl = new ilTemplate("tpl.prop_checkbox.html", true, true, "Services/Form");
185 
186  $tpl->setVariable("POST_VAR", $this->getPostVar());
187  $tpl->setVariable("ID", $this->getFieldId());
188  $tpl->setVariable("PROPERTY_VALUE", $this->getValue());
189  $tpl->setVariable("OPTION_TITLE", $this->getOptionTitle());
190  if(strlen($this->getAdditionalAttributes()))
191  {
192  $tpl->setVariable('PROP_CHECK_ATTRS',$this->getAdditionalAttributes());
193  }
194  if ($this->getChecked())
195  {
196  $tpl->setVariable("PROPERTY_CHECKED",
197  'checked="checked"');
198  }
199  if ($this->getDisabled())
200  {
201  $tpl->setVariable("DISABLED",
202  'disabled="disabled"');
203  }
204 
205  if ($a_mode == "toolbar")
206  {
207  // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
208  // -moz-inline-stack for FF2
209  // zoom 1; *display:inline for IE6 & 7
210  $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline;');
211  }
212 
213  return $tpl->get();
214  }
215 
221  function insert(&$a_tpl)
222  {
223  $html = $this->render();
224 
225  $a_tpl->setCurrentBlock("prop_generic");
226  $a_tpl->setVariable("PROP_GENERIC", $html);
227  $a_tpl->parseCurrentBlock();
228  }
229 
234  {
235  $html = $this->render();
236  return $html;
237  }
238 
242  function serializeData()
243  {
244  return serialize($this->getChecked());
245  }
246 
250  function unserializeData($a_data)
251  {
252  $data = unserialize($a_data);
253 
254  if ($data)
255  {
256  $this->setValue($data);
257  $this->setChecked(true);
258  }
259  }
260 
264  function getToolbarHTML()
265  {
266  $html = $this->render('toolbar');
267  return $html;
268  }
269 }