ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilSelectInputGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
6include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
7include_once 'Services/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php';
8include_once 'Services/Form/interfaces/interface.ilMultiValuesItem.php';
9
18{
19 protected $cust_attr = array();
20 protected $options = array();
21 protected $value;
22
29 function __construct($a_title = "", $a_postvar = "")
30 {
31 parent::__construct($a_title, $a_postvar);
32 $this->setType("select");
33 }
34
40 function setOptions($a_options)
41 {
42 $this->options = $a_options;
43 }
44
50 function getOptions()
51 {
52 return $this->options ? $this->options : array();
53 }
54
60 function setValue($a_value)
61 {
62 if($this->getMulti() && is_array($a_value))
63 {
64 $this->setMultiValues($a_value);
65 $a_value = array_shift($a_value);
66 }
67 $this->value = $a_value;
68 }
69
75 function getValue()
76 {
77 return $this->value;
78 }
79
80
86 function setValueByArray($a_values)
87 {
88 $this->setValue($a_values[$this->getPostVar()]);
89 foreach($this->getSubItems() as $item)
90 {
91 $item->setValueByArray($a_values);
92 }
93 }
94
100 function checkInput()
101 {
102 global $lng;
103
104 $valid = true;
105 if(!$this->getMulti())
106 {
108 if($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
109 {
110 $valid = false;
111 }
112 }
113 else
114 {
115 foreach($_POST[$this->getPostVar()] as $idx => $value)
116 {
117 $_POST[$this->getPostVar()][$idx] = ilUtil::stripSlashes($value);
118 }
119 $_POST[$this->getPostVar()] = array_unique($_POST[$this->getPostVar()]);
120
121 if($this->getRequired() && !trim(implode("", $_POST[$this->getPostVar()])))
122 {
123 $valid = false;
124 }
125 }
126 if (!$valid)
127 {
128 $this->setAlert($lng->txt("msg_input_is_required"));
129 return false;
130 }
131 return $this->checkSubItemsInput();
132 }
133
134 public function addCustomAttribute($a_attr)
135 {
136 $this->cust_attr[] = $a_attr;
137 }
138
139 public function getCustomAttributes()
140 {
141 return (array) $this->cust_attr;
142 }
143
147 function render($a_mode = "")
148 {
149 $tpl = new ilTemplate("tpl.prop_select.html", true, true, "Services/Form");
150
151 foreach($this->getCustomAttributes() as $attr)
152 {
153 $tpl->setCurrentBlock('cust_attr');
154 $tpl->setVariable('CUSTOM_ATTR',$attr);
155 $tpl->parseCurrentBlock();
156 }
157
158 // determin value to select. Due to accessibility reasons we
159 // should always select a value (per default the first one)
160 $first = true;
161 foreach($this->getOptions() as $option_value => $option_text)
162 {
163 if ($first)
164 {
165 $sel_value = $option_value;
166 }
167 $first = false;
168 if ((string) $option_value == (string) $this->getValue())
169 {
170 $sel_value = $option_value;
171 }
172 }
173 foreach($this->getOptions() as $option_value => $option_text)
174 {
175 $tpl->setCurrentBlock("prop_select_option");
176 $tpl->setVariable("VAL_SELECT_OPTION", ilUtil::prepareFormOutput($option_value));
177 if((string) $sel_value == (string) $option_value)
178 {
179 $tpl->setVariable("CHK_SEL_OPTION",
180 'selected="selected"');
181 }
182 $tpl->setVariable("TXT_SELECT_OPTION", $option_text);
183 $tpl->parseCurrentBlock();
184 }
185 $tpl->setVariable("ID", $this->getFieldId());
186
187 $postvar = $this->getPostVar();
188 if($this->getMulti() && substr($postvar, -2) != "[]")
189 {
190 $postvar .= "[]";
191 }
192
193 if ($this->getDisabled())
194 {
195 if($this->getMulti())
196 {
197 $value = $this->getMultiValues();
198 $hidden = "";
199 if(is_array($value))
200 {
201 foreach($value as $item)
202 {
203 $hidden .= $this->getHiddenTag($postvar, $item);
204 }
205 }
206 }
207 else
208 {
209 $hidden = $this->getHiddenTag($postvar, $this->getValue());
210 }
211 if($hidden)
212 {
213 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
214 $tpl->setVariable("HIDDEN_INPUT", $hidden);
215 }
216 }
217 else
218 {
219 $tpl->setVariable("POST_VAR", $postvar);
220 }
221
222 // multi icons
223 if($this->getMulti() && !$a_mode && !$this->getDisabled())
224 {
225 $tpl->touchBlock("inline_in_bl");
226 $tpl->setVariable("MULTI_ICONS", $this->getMultiIconsHTML());
227 }
228
229 return $tpl->get();
230 }
231
237 function insert(&$a_tpl)
238 {
239 $a_tpl->setCurrentBlock("prop_generic");
240 $a_tpl->setVariable("PROP_GENERIC", $this->render());
241 $a_tpl->parseCurrentBlock();
242 }
243
248 {
249 $html = $this->render();
250 return $html;
251 }
252
256 function getToolbarHTML()
257 {
258 $html = $this->render("toolbar");
259 return $html;
260 }
261
269 function setHideSubForm($a_value, $a_condition = null)
270 {
271 $this->hide_sub = (bool)$a_value;
272
273 if($a_condition)
274 {
275 $this->addCustomAttribute('onchange="if(this.value '.$a_condition.')'.
276 ' { il.Form.showSubForm(\'subform_'.$this->getFieldId().'\', \'il_prop_cont_'.$this->getFieldId().'\'); }'.
277 ' else { il.Form.hideSubForm(\'subform_'.$this->getFieldId().'\'); };"');
278 }
279 }
280
281 function hideSubForm()
282 {
283 return (bool)$this->hide_sub;
284 }
285
286}
global $tpl
Definition: ilias.php:8
getMultiIconsHTML()
Get HTML for multiple value icons.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
getHiddenTag($a_post_var, $a_value)
Get hidden tag (used for disabled properties)
setAlert($a_alert)
Set Alert Text.
getMultiValues()
Get multi values.
setMultiValues(array $a_values)
Set multi values.
getFieldId()
Get Post Variable.
This class represents a selection list property in a property form.
__construct($a_title="", $a_postvar="")
Constructor.
setValue($a_value)
Set Value.
setOptions($a_options)
Set Options.
getTableFilterHTML()
Get HTML for table filter.
insert(&$a_tpl)
Insert property html.
checkInput()
Check input, strip slashes etc.
render($a_mode="")
Render item.
setValueByArray($a_values)
Set value by array.
setHideSubForm($a_value, $a_condition=null)
Set initial sub form visibility, optionally add dynamic value-based condition.
getToolbarHTML()
Get HTML for toolbar.
This class represents a property that may include a sub form.
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
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$_POST['username']
Definition: cron.php:12
$valid
$html
Definition: example_001.php:87
Interface for multi values support.
Interface for property form input GUI classes that can be used in table filters.
Interface for property form input GUI classes that can be used in ilToolbarGUI.
global $lng
Definition: privfeed.php:40