18 require_once dirname(__FILE__).
'/../../form_question/form_question.inc';
19 require_once SQ_FUDGE_PATH.
'/general/text.inc';
89 $question_contents = $this->
attr(
'question_contents');
90 $datapath = sq_web_path(
'data').
'/asset_types/form_question_type_tickbox_table/files';
100 if (empty($question_contents ))
return '';
101 $header = array_shift($question_contents);
102 $title = array_shift($header);
105 if (!empty($question_contents)) {
106 foreach ($question_contents as $question_id=>$question) {
107 $question_title = array_shift($question);
108 $this_question = Array();
109 foreach ($question as $option_id=>$option) {
110 if ($submission && isset($submission[$question_id][$option_id])) {
111 $this_question[] = $header[$option_id].
' ('.$option.
')';
114 if (!empty($this_question)) {
115 $output[] = $question_title.
': '.implode(
', ', $this_question);
119 return implode(
"; \n", $output);
124 $header = array_shift($question_contents);
125 $to_output =
'<style type="text/css">@import url("'.$datapath.
'/style.css");</style>'.
126 '<script type="text/javascript" src="'.$datapath.
'/InputTable.js">//blank</script>'.
127 '<table border="0" cellspacing="0" cellpadding="0" id="'.$prefix.
'" class="tbl"></table>'.
128 '<script type="text/javascript">'.
129 "var Quests = Array(\n";
131 if (!empty($header)) {
132 array_walk($header,
'escape_double_quotes');
133 $output[] =
' Array("'.implode(
'", "', $header).
'")';
134 foreach ($question_contents as $question_id=>$question) {
135 array_walk($question,
'escape_double_quotes');
136 $output[] =
' Array("'.implode(
'", "', $question).
'")';
138 $to_output .= implode(
",\n", $output);
140 $to_output .=
");\n";
141 $to_output .=
' var tb = new InputTable("'.$prefix.
'", "tb");'.
142 ' tb.datapath = "'.$datapath.
'";'.
143 ' tb.setup(Quests);'.
150 $to_output =
'<table border="0" cellpadding="0" cellspacing="0" class="sq-backend-table" id="'.$prefix.
'">'.
152 ' <td class="sq-backend-table-header">';
153 if (empty($question_contents) || empty($question_contents[0])) {
154 $to_output .=
'<div align="center">'.translate(
'core_form_tickbox_table_not_properly_defined');
155 if ($type ==
'passive') {
156 $to_output .=
' '.translate(
'core_form_tickbox_table_incorrectly_displayed');
158 $to_output .=
'</div>';
160 $extras = $this->
attr(
'extra');
162 if ($this->
attr(
'tabindex')) {
163 $extras .=
' tabindex="'.$this->attr(
'tabindex').
'"';
166 $header = array_shift($question_contents);
167 $to_output .= array_shift($header).
'</td>';
168 foreach ($header as $key=>$title) {
169 $to_output .=
'<td class="sq-backend-table-header">'.$title.
'</td>';
171 $to_output .=
"</tr>\n";
173 foreach ($question_contents as $question_id=>$question) {
176 if ($j % 2 == 0) $to_output .=
' class="even"';
179 $to_output .=
'<td class="sq-backend-table-header">'.array_shift($question).
'</td>';
180 foreach ($question as $option_id=>$option) {
181 $to_output .=
'<td class="sq-backend-table-cell">';
182 if (empty($option)) {
183 $to_output .=
'—';
184 }
else if ($type !=
'passive') {
186 check_box($prefix.
'['.$question_id.
']['.$option_id.
']',
'1', $submission && isset($submission[$question_id][$option_id]), NULL, $extras);
187 $to_output .= ob_get_contents();
190 label($option, $prefix.
'['.$question_id.
']['.$option_id.
']');
191 $label = ob_get_contents();
193 $to_output .=
' <span onclick="this.previousSibling.previousSibling.checked = !this.previousSibling.previousSibling.checked">'.$label.
'</span>';
195 $to_output .= $option;
197 $to_output .=
'</td>';
199 $to_output .=
'</tr>';
202 $to_output .=
'</table>';
227 if (is_null($answer)) $answer = $this->
getValue();
229 if ($this->
attr(
'is_required')) {
230 $req_rule = Array(
'rule_code' =>
'select_limit',
'operator' =>
'>=',
'value' =>
'1');
231 array_push($this->vars[
'rules'][
'value'], $req_rule);
234 $ok = parent::hasValidValue($answer, $mute_errors);
236 if ($this->
attr(
'is_required')) {
237 array_pop($this->vars[
'rules'][
'value']);
255 $question_contents = $this->
attr(
'question_contents');
256 $datapath = sq_web_path(
'data').
'/asset_types/form_question_type_tickbox_table/files';
257 $submission = array_get_index($this->_tmp,
'submission', FALSE);
258 $to_output =
'<question>';
259 $to_output .=
'<prefix><![CDATA['.$prefix.
']]></prefix>';
260 $to_output .=
'<datapath><![CDATA['.$datapath.
']]></datapath>';
262 if (empty($question_contents )) {
263 $to_output .=
'</question>';
265 $header = array_shift($question_contents);
266 $title = array_shift($header);
267 $to_output .=
'<title><![CDATA['.$title.
']]></title>';
268 $to_output .=
'<optiontitles>';
269 foreach ($header as $key=>$item) {
270 $to_output .=
'<title id="'.$key.
'"><![CDATA['.$item.
']]></title>';
272 $to_output .=
'</optiontitles>';
274 foreach ($question_contents as $question_id=>$question) {
275 $question_title = array_shift($question);
276 $to_output .=
'<subquestion id="'.$question_id.
'">';
277 $to_output .=
'<title><![CDATA['.$question_title.
']]></title>';
279 $to_output .=
'<options>';
280 foreach ($question as $option_id=>$option) {
281 $checked =
'checked="0"';
282 if ($submission && isset($submission[$question_id][$option_id])) {
283 $checked =
'checked="1"';
285 $to_output .=
'<option id="'.$option_id.
'" '.$checked.
'><![CDATA['.$option.
']]></option>';
287 $to_output .=
'</options>';
288 $to_output .=
'</subquestion>';
290 $to_output .=
'</question>';
306 return $prefix =
'q'.str_replace(
':',
'_', $this->
getPrefix());
335 if (empty($value))
return FALSE;
338 list($line,$option) = explode(
'_', $option_code);
341 return !empty($value[$line][$option]);
359 $question_contents = $this->
attr(
'question_contents');
362 list($line_id,$option_id) = explode(
'_', $option_code);
364 $header = array_shift($question_contents);
366 array_shift($header);
368 $line = $question_contents[$line_id];
369 $title = array_shift($line);
371 $option = $header[$option_id];
373 $name = $title.
': '.$option.
' - ('.$line[$option_id].
')';
389 $lines = $this->
attr(
'question_contents');
390 $header = array_shift($lines);
392 array_shift($header);
394 foreach ($lines as $id => $line) {
395 $title = array_shift($line);
396 foreach ($header as $o_id => $o_name) {
397 $option_id = $id.
'_'.$o_id;
398 $options[$option_id] = $title.
': '.$o_name.
' - ('.$line[$o_id].
')';
416 $this->
setValue(array_get_index($_POST, $prefix, Array()));