18 require_once dirname(__FILE__).
'/../../form_question/form_question.inc';
72 $extras = $this->
attr(
'extra');
74 if ($this->
attr(
'tabindex')) {
75 $extras .=
' tabindex="'.$this->attr(
'tabindex').
'"';
92 function listBox($options, $multiple=FALSE, $extras=
'')
94 $type = ($multiple) ?
'checkbox' :
'radio';
95 if (!stristr($extras,
'class=')) {
96 $extras .=
' class="sq-form-field"';
98 $name =
'q'.$this->id;
99 $safe_name = str_replace(
':',
'_', $name);
103 if (!is_array($defaults)) $defaults = Array($defaults);
104 foreach ($options as $key => $value) {
107 $html .=
'<input type="'.$type.
'" ';
108 $html .=
'name="'.$name.(($multiple) ?
'[]' :
'').
'" ';
109 $html .=
'id="'.$safe_name.
'_'.$key.
'" ';
110 $html .=
'value="'.htmlspecialchars($key).
'"';
111 if (in_array($key, $defaults)) {
112 $html .=
' checked="checked"';
114 $html .= ($extras ==
'') ?
'/>' :
' '.$extras.
' />';
116 $html .=
' <label for="'.$safe_name.
'_'.$key.
'">'.$value.
'</label>';
136 $options = @unserialize($this->
attr(
'options'));
137 if (!is_array($options) && empty($options)) {
141 foreach (array_keys($options) as $k) {
142 if ($options[$k] ==
'') unset($options[$k]);
167 if (is_null($answer)) $answer = $this->
getValue();
169 if (!is_array($answer)) {
170 $answer = Array($answer);
174 if ($this->
attr(
'is_required')) {
175 $req_rule = Array(
'rule_code' =>
'select_limit',
'operator' =>
'>=',
'value' =>
'1');
176 array_push($this->vars[
'rules'][
'value'], $req_rule);
179 $ok = parent::hasValidValue($value, $mute_errors);
181 if ($this->
attr(
'is_required')) {
182 array_pop($this->vars[
'rules'][
'value']);
202 if ($this->
attr(
'is_required')) {
203 $req_rule = Array(
'rule_code' =>
'select_limit',
'operator' =>
'>=',
'value' =>
'1');
204 array_push($this->vars[
'rules'][
'value'], $req_rule);
207 $code = parent::generateJSCode();
209 if ($this->
attr(
'is_required')) {
210 array_pop($this->vars[
'rules'][
'value']);
228 return Array(
'select_limit',
'selection');
243 if (is_null($answer)) $answer = $this->
getValue();
245 if (is_array($answer)) {
247 foreach ($answer as $a) {
250 return implode(
', ', $ans_str);
268 if (!is_null($values)) {
269 if (is_array($values)) {
270 return in_array($value, $values);
272 return ($value == $values && !empty($values));
275 $defaults = $this->
attr(
'default');
276 return (in_array($value, $defaults));
312 echo
'<select_q id="'.addslashes($this->
id).
'" name="'.htmlspecialchars($this->
attr(
'name')).
'">';
313 if (!is_array($answer)) $answer = Array($answer);
315 foreach ($answer as $a) {
316 echo
'<option value="'.$a.
'">'.htmlspecialchars($this->
getAnswerByOffset($a)).
'</option>';
320 $contents = ob_get_contents();
336 return $this->
attr(
'name');
351 $prefix =
'q'.$this->id;
352 $this->
setValue(array_get_index($_POST, $prefix, Array()));