ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSelectInputGUI.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/Table/interfaces/interface.ilTableFilterItem.php");
25 include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
26 
35 {
36  protected $options = array();
37  protected $value;
38 
45  function __construct($a_title = "", $a_postvar = "")
46  {
47  parent::__construct($a_title, $a_postvar);
48  $this->setType("select");
49  }
50 
56  function setOptions($a_options)
57  {
58  $this->options = $a_options;
59  }
60 
66  function getOptions()
67  {
68  return $this->options ? $this->options : array();
69  }
70 
76  function setValue($a_value)
77  {
78  $this->value = $a_value;
79  }
80 
86  function getValue()
87  {
88  return $this->value;
89  }
90 
96  function setValueByArray($a_values)
97  {
98  $this->setValue($a_values[$this->getPostVar()]);
99  }
100 
106  function checkInput()
107  {
108  global $lng;
109 
110  $_POST[$this->getPostVar()] =
112  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
113  {
114  $this->setAlert($lng->txt("msg_input_is_required"));
115 
116  return false;
117  }
118  return $this->checkSubItemsInput();
119  }
120 
124  function render($a_mode = "")
125  {
126  $tpl = new ilTemplate("tpl.prop_select.html", true, true, "Services/Form");
127 
128  // determin value to select. Due to accessibility reasons we
129  // should always select a value (per default the first one)
130  $first = true;
131  foreach($this->getOptions() as $option_value => $option_text)
132  {
133  if ($first)
134  {
135  $sel_value = $option_value;
136  }
137  $first = false;
138  if ((string) $option_value == (string) $this->getValue())
139  {
140  $sel_value = $option_value;
141  }
142  }
143  foreach($this->getOptions() as $option_value => $option_text)
144  {
145  $tpl->setCurrentBlock("prop_select_option");
146  $tpl->setVariable("VAL_SELECT_OPTION", $option_value);
147  if((string) $sel_value == (string) $option_value)
148  {
149  $tpl->setVariable("CHK_SEL_OPTION",
150  'selected="selected"');
151  }
152  $tpl->setVariable("TXT_SELECT_OPTION", $option_text);
153  $tpl->parseCurrentBlock();
154  }
155  $tpl->setVariable("ID", $this->getFieldId());
156  if ($this->getDisabled())
157  {
158  $tpl->setVariable("DISABLED",
159  " disabled=\"disabled\"");
160  }
161  if ($this->getDisabled())
162  {
163  $tpl->setVariable("DISABLED",
164  " disabled=\"disabled\"");
165  $tpl->setVariable("HIDDEN_INPUT",
166  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
167  }
168  else
169  {
170  $tpl->setVariable("POST_VAR", $this->getPostVar());
171  }
172 
173  return $tpl->get();
174  }
175 
181  function insert(&$a_tpl)
182  {
183  $a_tpl->setCurrentBlock("prop_generic");
184  $a_tpl->setVariable("PROP_GENERIC", $this->render());
185  $a_tpl->parseCurrentBlock();
186  }
187 
192  {
193  $html = $this->render();
194  return $html;
195  }
196 
200  function getToolbarHTML()
201  {
202  $html = $this->render("toolbar");
203  return $html;
204  }
205 
206 }