18 require_once dirname(__FILE__).
'/../../form_question/form_question.inc';
19 require_once SQ_FUDGE_PATH.
'/csv/csv.inc';
61 return Array(
'select_limit',
'selection');
88 $name =
'q'.$this->id;
91 $extras =
'id="'.str_replace(
':',
'_', $name).
'" '.$this->
attr(
'extra');
93 if ($this->
attr(
'tabindex')) {
94 $extras .=
' tabindex="'.$this->attr(
'tabindex').
'"';
99 $html = ob_get_contents();
115 $options = $this->
attr(
'options');
117 if (count($options) > 0) {
118 $decoded_options = Array();
120 foreach (array_keys($options) as $k) {
121 if ($options[$k] !=
'') {
122 $decoded_options[html_entity_decode($k, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)] = html_entity_decode($options[$k], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
125 $options = $decoded_options;
128 if ($this->
attr(
'allow_empty')) {
129 if(array_key_exists(html_entity_decode($this->
attr(
'empty_key'), ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), $options)) {
130 trigger_localised_error(
'CORE0302', E_USER_NOTICE);
132 $empty = Array(html_entity_decode($this->
attr(
'empty_key'), ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET) => html_entity_decode($this->
attr(
'empty_text'), ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
133 $options = $empty + $options;
153 if (is_null($answer)) $answer = $this->value;
155 if (is_array($answer)) {
157 foreach ($answer as $a) {
160 if ($answer_by_offset != $this->
attr(
'empty_text')) {
166 return implode(
', ', $ans_str);
171 if ($answer_by_offset != $this->
attr(
'empty_text')) {
192 echo
'<select_q id="'.addslashes($this->
id).
'" name="'.htmlentities($this->
attr(
'name'), ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'">';
193 if (!is_array($answer)) $answer = Array($answer);
195 foreach ($answer as $a) {
196 echo
'<option value="'.$a.
'">'.htmlentities($this->
getAnswerByOffset($a), ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'</option>';
200 $contents = ob_get_contents();
219 if (!is_array($options)) {
220 $options = Array($options);
223 return in_array($option, $options);
239 return $option_name == $this->
attr(
'empty_text');
275 $csv =
new CSV($filename);
278 $values = $csv->values;
282 if (!empty($values)) {
285 $num_columns = count($values[0]);
288 foreach ($values as $row) {
289 if ($num_columns === 1) {
292 $value = htmlentities($row[0], ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
293 $options[$index] = $value;
296 $key = htmlentities($row[0], ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
297 $value = htmlentities($row[1], ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
298 $options[$key] = $value;
300 if ($num_columns === 3) {
309 if ($num_columns === 3) {
310 if (!$this->
attr(
'multiple')) {
311 if (count($defaults) > 1) {
312 trigger_localised_error(
'CORE0286', E_USER_NOTICE);
314 if (count($defaults) > 0) {
315 $defaults = Array($defaults[0]);
324 $current_default = $this->
attr(
'default');
325 if (!is_array($current_default)) {
326 $current_default = Array($current_default);
328 foreach ($current_default as $default_key) {
331 if (!isset($options[$default_key])) {
332 unset($current_default[$default_key]);