MDL-28014 - unpropitious use of bcmod()
[moodle.git] / mod / feedback / item / multichoice / lib.php
CommitLineData
1adbd2c3 1<?php
01910dff 2defined('MOODLE_INTERNAL') OR die('not allowed');
6ee09cfe 3require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
4
5define('FEEDBACK_MULTICHOICE_TYPE_SEP', '>>>>>');
6define('FEEDBACK_MULTICHOICE_LINE_SEP', '|');
7define('FEEDBACK_MULTICHOICE_ADJUST_SEP', '<<<<<');
79473294
AG
8define('FEEDBACK_MULTICHOICE_IGNOREEMPTY', 'i');
9define('FEEDBACK_MULTICHOICE_HIDENOSELECT', 'h');
6ee09cfe 10
11class feedback_item_multichoice extends feedback_item_base {
12 var $type = "multichoice";
a59ff6b0
AG
13 var $commonparams;
14 var $item_form;
15 var $item;
39790bd8 16
6ee09cfe 17 function init() {
d4b1d58c 18
6ee09cfe 19 }
d4b1d58c 20
a59ff6b0
AG
21 function build_editform($item, $feedback, $cm) {
22 global $DB, $CFG;
23 require_once('multichoice_form.php');
24
25 //get the lastposition number of the feedback_items
26 $position = $item->position;
27 $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
28 if($position == -1){
29 $i_formselect_last = $lastposition + 1;
30 $i_formselect_value = $lastposition + 1;
31 $item->position = $lastposition + 1;
32 }else {
33 $i_formselect_last = $lastposition;
34 $i_formselect_value = $item->position;
35 }
36 //the elements for position dropdownlist
37 $positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true);
39790bd8 38
a59ff6b0
AG
39 $item->presentation = empty($item->presentation) ? '' : $item->presentation;
40 $info = $this->get_info($item);
41
79473294
AG
42 $item->ignoreempty = $this->ignoreempty($item);
43 $item->hidenoselect = $this->hidenoselect($item);
39790bd8 44
73043833
AG
45 //all items for dependitem
46 $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
a59ff6b0
AG
47 $commonparams = array('cmid'=>$cm->id,
48 'id'=>isset($item->id) ? $item->id : NULL,
49 'typ'=>$item->typ,
73043833 50 'items'=>$feedbackitems,
a59ff6b0
AG
51 'feedback'=>$feedback->id);
52
53 //build the form
54 $this->item_form = new feedback_multichoice_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position, 'info'=>$info));
55 }
56
57 //this function only can used after the call of build_editform()
58 function show_editform() {
59 $this->item_form->display();
60 }
39790bd8 61
a59ff6b0
AG
62 function is_cancelled() {
63 return $this->item_form->is_cancelled();
64 }
65
66 function get_data() {
67 if($this->item = $this->item_form->get_data()) {
68 return true;
69 }
70 return false;
71 }
72
73 function save_item() {
74 global $DB;
39790bd8 75
a59ff6b0
AG
76 if(!$item = $this->item_form->get_data()) {
77 return false;
78 }
39790bd8 79
b8baf0ad 80 if(isset($item->clone_item) AND $item->clone_item) {
9e1aed53
AG
81 $item->id = ''; //to clone this item
82 $item->position++;
83 }
39790bd8
PS
84
85 $this->set_ignoreempty($item, $item->ignoreempty);
79473294
AG
86 $this->set_hidenoselect($item, $item->hidenoselect);
87
45c2f92a 88 $item->hasvalue = $this->get_hasvalue();
a59ff6b0
AG
89 if(!$item->id) {
90 $item->id = $DB->insert_record('feedback_item', $item);
91 }else {
92 $DB->update_record('feedback_item', $item);
93 }
39790bd8 94
a59ff6b0
AG
95 return $DB->get_record('feedback_item', array('id'=>$item->id));
96 }
97
6ee09cfe 98
99 //liefert ein eindimensionales Array mit drei Werten(typ, name, XXX)
100 //XXX ist ein eindimensionales Array (anzahl der Antworten bei Typ Radio) Jedes Element ist eine Struktur (answertext, answercount)
101 function get_analysed($item, $groupid = false, $courseid = false) {
102 $info = $this->get_info($item);
d4b1d58c 103
6ee09cfe 104 $analysedItem = array();
105 $analysedItem[] = $item->typ;
106 $analysedItem[] = $item->name;
107 //die moeglichen Antworten extrahieren
108 $answers = null;
109 // $presentation = '';
110 // @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info
d4b1d58c 111
294ce987 112 $answers = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
6ee09cfe 113 if(!is_array($answers)) return null;
114
115 //die Werte holen
79473294 116 $values = feedback_get_group_values($item, $groupid, $courseid, $this->ignoreempty($item));
6ee09cfe 117 if(!$values) return null;
118 //schleife ueber den Werten und ueber die Antwortmoeglichkeiten
d4b1d58c 119
6ee09cfe 120 $analysedAnswer = array();
121 if($info->subtype == 'c') {
2b9ce62e 122 $sizeofanswers = sizeof($answers);
80c12897 123 for ($i = 1; $i <= $sizeofanswers; $i++) {
6ee09cfe 124 $ans = null;
125 $ans->answertext = $answers[$i-1];
126 $ans->answercount = 0;
80c12897 127 foreach ($values as $value) {
6ee09cfe 128 //ist die Antwort gleich dem index der Antworten + 1?
129 $vallist = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value->value);
80c12897 130 foreach ($vallist as $val) {
6ee09cfe 131 if ($val == $i) {
132 $ans->answercount++;
133 }
134 }
135 }
136 $ans->quotient = $ans->answercount / sizeof($values);
137 $analysedAnswer[] = $ans;
138 }
139 }else {
2b9ce62e 140 $sizeofanswers = sizeof($answers);
80c12897 141 for ($i = 1; $i <= $sizeofanswers; $i++) {
6ee09cfe 142 $ans = null;
143 $ans->answertext = $answers[$i-1];
144 $ans->answercount = 0;
80c12897 145 foreach ($values as $value) {
6ee09cfe 146 //ist die Antwort gleich dem index der Antworten + 1?
147 if ($value->value == $i) {
148 $ans->answercount++;
149 }
150 }
151 $ans->quotient = $ans->answercount / sizeof($values);
152 $analysedAnswer[] = $ans;
153 }
154 }
155 $analysedItem[] = $analysedAnswer;
156 return $analysedItem;
157 }
158
159 function get_printval($item, $value) {
160 $info = $this->get_info($item);
d4b1d58c 161
6ee09cfe 162 $printval = '';
d4b1d58c 163
80c12897
SH
164 if (!isset($value->value)) {
165 return $printval;
166 }
d4b1d58c 167
6ee09cfe 168 // @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info
d4b1d58c 169
294ce987 170 $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
d4b1d58c 171
80c12897 172 if ($info->subtype == 'c') {
6ee09cfe 173 $vallist = array_values(explode (FEEDBACK_MULTICHOICE_LINE_SEP, $value->value));
2b9ce62e 174 $sizeofvallist = sizeof($vallist);
80c12897
SH
175 $sizeofpresentation = sizeof($presentation);
176 for ($i = 0; $i < $sizeofvallist; $i++) {
177 for ($k = 0; $k < $sizeofpresentation; $k++) {
178 if ($vallist[$i] == ($k + 1)) {//Die Werte beginnen bei 1, das Array aber mit 0
6ee09cfe 179 $printval .= trim($presentation[$k]) . chr(10);
180 break;
181 }
182 }
183 }
80c12897 184 } else {
6ee09cfe 185 $index = 1;
186 foreach($presentation as $pres){
80c12897 187 if ($value->value == $index){
6ee09cfe 188 $printval = $pres;
189 break;
190 }
191 $index++;
192 }
193 }
194 return $printval;
195 }
196
efc59167 197 function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
6ee09cfe 198 $sep_dec = get_string('separator_decimal', 'feedback');
199 if(substr($sep_dec, 0, 2) == '[['){
200 $sep_dec = FEEDBACK_DECIMAL;
201 }
d4b1d58c 202
6ee09cfe 203 $sep_thous = get_string('separator_thousand', 'feedback');
204 if(substr($sep_thous, 0, 2) == '[['){
205 $sep_thous = FEEDBACK_THOUSAND;
206 }
d4b1d58c 207
6ee09cfe 208 $analysedItem = $this->get_analysed($item, $groupid, $courseid);
209 if($analysedItem) {
efc59167 210 // $itemnr++;
294ce987 211 $itemname = $analysedItem[1];
b7a47958 212 echo '<tr><th colspan="2" align="left">'. $itemnr . '&nbsp;('. $item->label .') ' . $itemname .'</th></tr>';
6ee09cfe 213 $analysedVals = $analysedItem[2];
214 $pixnr = 0;
215 foreach($analysedVals as $val) {
b7030c3d 216 $intvalue = $pixnr % 10;
6ee09cfe 217 $pix = "pics/$intvalue.gif";
218 $pixnr++;
219 $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
220 $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous);
221 echo '<tr><td align="left" valign="top">-&nbsp;&nbsp;' . trim($val->answertext) . ':</td><td align="left" style="width: '.FEEDBACK_MAX_PIX_LENGTH.'"><img alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />&nbsp;' . $val->answercount . (($val->quotient > 0)?'&nbsp;('. $quotient . '&nbsp;%)':'').'</td></tr>';
222 }
223 }
efc59167 224 // return $itemnr;
6ee09cfe 225 }
226
51129b99 227 function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {
6ee09cfe 228 $analysed_item = $this->get_analysed($item, $groupid, $courseid);
229
6ee09cfe 230 $data = $analysed_item[2];
231
51129b99 232 // $worksheet->setFormat("<l><f><ro2><vo><c:green>");
6ee09cfe 233 //frage schreiben
439ae873
AG
234 $worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2);
235 $worksheet->write_string($rowOffset, 1, $analysed_item[1], $xlsFormats->head2);
80c12897 236 if (is_array($data)) {
b692e4aa 237 $sizeofdata = sizeof($data);
80c12897 238 for ($i = 0; $i < $sizeofdata; $i++) {
6ee09cfe 239 $aData = $data[$i];
d4b1d58c 240
51129b99 241 // $worksheet->setFormat("<l><f><ro2><vo><c:blue>");
439ae873 242 $worksheet->write_string($rowOffset, $i + 2, trim($aData->answertext), $xlsFormats->head2);
d4b1d58c 243
51129b99
AG
244 // $worksheet->setFormat("<l><vo>");
245 $worksheet->write_number($rowOffset + 1, $i + 2, $aData->answercount, $xlsFormats->default);
246 // $worksheet->setFormat("<l><f><vo><pr>");
247 $worksheet->write_number($rowOffset + 2, $i + 2, $aData->quotient, $xlsFormats->procent);
6ee09cfe 248 }
249 }
80c12897 250 $rowOffset += 3;
6ee09cfe 251 return $rowOffset;
252 }
39790bd8
PS
253
254 /**
9d5fbd65
AG
255 * print the item at the edit-page of feedback
256 *
257 * @global object
258 * @param object $item
259 * @return void
260 */
261 function print_item_preview($item) {
73043833 262 global $OUTPUT, $DB;
9d5fbd65
AG
263 $info = $this->get_info($item);
264 $align = right_to_left() ? 'right' : 'left';
265
266 $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
267
268
269 //test if required and no value is set so we have to mark this item
270 //we have to differ check and the other subtypes
afdb1920 271 $requiredmark = ($item->required == 1) ? '<span class="feedback_required_mark">*</span>' : '';
39790bd8 272
afdb1920
AG
273 //print the question and label
274 echo '<div class="feedback_item_label_'.$align.'">';
275 echo '('.$item->label.') ';
276 echo format_text($item->name.$requiredmark, true, false, false);
73043833
AG
277 if($item->dependitem) {
278 if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
279 echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>';
280 }
281 }
afdb1920 282 echo '</div>';
39790bd8 283
afdb1920
AG
284 //print the presentation
285 echo '<div class="feedback_item_presentation_'.$align.'">';
9d5fbd65
AG
286 $index = 1;
287 $checked = '';
afdb1920
AG
288 echo '<ul>';
289 if($info->horizontal) {
290 $hv = 'h';
291 }else {
292 $hv = 'v';
293 }
39790bd8 294
79473294 295 if($info->subtype == 'r' AND !$this->hidenoselect($item)) {
afdb1920 296 //print the "not_selected" item on radiobuttons
9d5fbd65 297 ?>
afdb1920
AG
298 <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
299 <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
300 <input type="radio" name="<?php echo $item->typ . '_' . $item->id ;?>" id="<?php echo $item->typ . '_' . $item->id.'_xxx';?>" value="" checked="checked" />
301 </span>
302 <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
303 <label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?>&nbsp;</label>
304 </span>
305 </li>
9d5fbd65
AG
306 <?php
307 }
9d5fbd65
AG
308
309 switch($info->subtype) {
310 case 'r':
311 $this->print_item_radio($presentation, $item, false, $info, $align);
312 break;
313 case 'c':
314 $this->print_item_check($presentation, $item, false, $info, $align);
315 break;
316 case 'd':
317 $this->print_item_dropdown($presentation, $item, false, $info, $align);
318 break;
319 }
afdb1920
AG
320 echo '</ul>';
321 echo '</div>';
9d5fbd65 322 }
39790bd8
PS
323
324 /**
9d5fbd65
AG
325 * print the item at the complete-page of feedback
326 *
327 * @global object
328 * @param object $item
329 * @param string $value
330 * @param bool $highlightrequire
331 * @return void
332 */
333 function print_item_complete($item, $value = '', $highlightrequire = false) {
d4b1d58c 334 global $OUTPUT;
6ee09cfe 335 $info = $this->get_info($item);
e372f4c7 336 $align = right_to_left() ? 'right' : 'left';
d4b1d58c 337
294ce987 338 $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
d4b1d58c 339
340
6ee09cfe 341 //test if required and no value is set so we have to mark this item
342 //we have to differ check and the other subtypes
343 if($info->subtype == 'c') {
344 if (is_array($value)) {
345 $values = $value;
346 }else {
347 $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value);
348 }
349 if($highlightrequire AND $item->required AND $values[0] == '') {
afdb1920 350 $highlight = ' missingrequire';
6ee09cfe 351 }else {
352 $highlight = '';
353 }
354 $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
6ee09cfe 355 }else {
356 if($highlightrequire AND $item->required AND intval($value) <= 0) {
afdb1920 357 $highlight = ' missingrequire';
6ee09cfe 358 }else {
359 $highlight = '';
360 }
361 $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
6ee09cfe 362 }
afdb1920
AG
363
364 //print the question and label
365 echo '<div class="feedback_item_label_'.$align.$highlight.'">';
366 echo format_text($item->name.$requiredmark, true, false, false);
367 echo '</div>';
368
369 //print the presentation
370 echo '<div class="feedback_item_presentation_'.$align.$highlight.'">';
39790bd8 371
afdb1920
AG
372 echo '<ul>';
373 if($info->horizontal) {
374 $hv = 'h';
375 }else {
376 $hv = 'v';
377 }
9d5fbd65 378 //print the "not_selected" item on radiobuttons
79473294 379 if($info->subtype == 'r' AND !$this->hidenoselect($item)) {
9d5fbd65 380 ?>
afdb1920
AG
381 <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
382 <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
383 <input type="radio" name="<?php echo $item->typ.'_'.$item->id ;?>" id="<?php echo $item->typ . '_' . $item->id.'_xxx';?>" value="" <?php echo $value ? '' : 'checked="checked"';?> />
384 </span>
385 <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
386 <label for="<?php echo $item->typ.'_'.$item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?>&nbsp;</label>
387 </span>
388 </li>
9d5fbd65
AG
389 <?php
390 }
9d5fbd65
AG
391
392 switch($info->subtype) {
393 case 'r':
394 $this->print_item_radio($presentation, $item, $value, $info, $align);
395 break;
396 case 'c':
397 $this->print_item_check($presentation, $item, $value, $info, $align);
398 break;
399 case 'd':
400 $this->print_item_dropdown($presentation, $item, $value, $info, $align);
401 break;
402 }
afdb1920
AG
403 echo '</ul>';
404 echo '</div>';
9d5fbd65 405 }
d4b1d58c 406
39790bd8 407 /**
9d5fbd65
AG
408 * print the item at the complete-page of feedback
409 *
410 * @global object
411 * @param object $item
412 * @param string $value
413 * @return void
414 */
415 function print_item_show_value($item, $value = '') {
416 global $OUTPUT;
417 $info = $this->get_info($item);
418 $align = right_to_left() ? 'right' : 'left';
419
420 $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
421
422
423 //test if required and no value is set so we have to mark this item
424 //we have to differ check and the other subtypes
425 if($info->subtype == 'c') {
426 if (is_array($value)) {
427 $values = $value;
428 }else {
429 $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value);
6ee09cfe 430 }
9d5fbd65 431 $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
9d5fbd65
AG
432 }else {
433 $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
9d5fbd65 434 }
39790bd8 435
afdb1920
AG
436 //print the question and label
437 echo '<div class="feedback_item_label_'.$align.'">';
438 echo '('.$item->label.') ';
439 echo format_text($item->name . $requiredmark, true, false, false);
440 echo '</div>';
39790bd8 441
afdb1920
AG
442 //print the presentation
443 echo '<div class="feedback_item_presentation_'.$align.'">';
9d5fbd65 444 $index = 1;
9d5fbd65
AG
445 if($info->subtype == 'c') {
446 echo $OUTPUT->box_start('generalbox boxalign'.$align);
447 foreach($presentation as $pres){
448 foreach($values as $val) {
449 if($val == $index){
afdb1920
AG
450 echo '<div class="feedback_item_multianswer">';
451 echo text_to_html($pres, true, false, false);
452 echo '</div>';
9d5fbd65
AG
453 break;
454 }
6ee09cfe 455 }
9d5fbd65 456 $index++;
6ee09cfe 457 }
9d5fbd65
AG
458 echo $OUTPUT->box_end();
459 }else {
460 foreach($presentation as $pres){
461 if($value == $index){
462 echo $OUTPUT->box_start('generalbox boxalign'.$align);
463 echo text_to_html($pres, true, false, false);
464 echo $OUTPUT->box_end();
465 break;
466 }
467 $index++;
6ee09cfe 468 }
6ee09cfe 469 }
afdb1920 470 echo '</div>';
6ee09cfe 471 }
472
473 function check_value($value, $item) {
474 $info = $this->get_info($item);
d4b1d58c 475
6ee09cfe 476 if($info->subtype == 'c') {
477 if((!isset($value) OR !is_array($value) OR $value[0] == '' OR $value[0] == 0) AND $item->required != 1){
478 return true;
479 }
480 if($value[0] == ""){
481 return false;
482 }
483 return true;
484 }else {
485 //if the item is not required, so the check is true if no value is given
486 if((!isset($value) OR $value == '' OR $value == 0) AND $item->required != 1) return true;
487 if(intval($value) > 0)return true;
488 }
489 return false;
490 }
491
492 function create_value($data) {
493 $vallist = $data;
494 return trim($this->item_arrayToString($vallist));
495 }
39790bd8 496
73043833
AG
497 //compares the dbvalue with the dependvalue
498 //dbvalue is the number of one selection
499 //dependvalue is the presentation of one selection
500 function compare_value($item, $dbvalue, $dependvalue) {
6ee09cfe 501
73043833
AG
502 if (is_array($dbvalue)) {
503 $dbvalues = $dbvalue;
504 }else {
505 $dbvalues = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $dbvalue);
506 }
39790bd8 507
73043833
AG
508 $info = $this->get_info($item);
509 $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation);
510 $index = 1;
511 foreach($presentation as $pres) {
512 foreach($dbvalues as $dbval) {
513 if($dbval == $index AND trim($pres) == $dependvalue) {
514 return true;
515 }
516 }
517 $index++;
518 }
519 return false;
520 }
39790bd8 521
6ee09cfe 522 function get_presentation($data) {
523 $present = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($data->itemvalues));
524 if(!isset($data->subtype)) {
525 $subtype = 'r';
526 }else {
527 $subtype = substr($data->subtype, 0, 1);
528 }
529 if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') {
530 $present .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1';
531 }
532 return $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$present;
533 }
534
535 function get_hasvalue() {
536 return 1;
537 }
d4b1d58c 538
6ee09cfe 539 function get_info($item) {
540 $presentation = empty($item->presentation) ? '' : $item->presentation;
d4b1d58c 541
39790bd8 542 $info = new stdClass();
6ee09cfe 543 //check the subtype of the multichoice
544 //it can be check(c), radio(r) or dropdown(d)
545 $info->subtype = '';
546 $info->presentation = '';
547 $info->horizontal = false;
d4b1d58c 548
6ee09cfe 549 @list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICE_TYPE_SEP, $item->presentation);
550 if(!isset($info->subtype)) {
551 $info->subtype = 'r';
552 }
553
554 if($info->subtype != 'd') {
555 @list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICE_ADJUST_SEP, $info->presentation);
556 if(isset($info->horizontal) AND $info->horizontal == 1) {
557 $info->horizontal = true;
558 }else {
559 $info->horizontal = false;
560 }
561 }
562 return $info;
563 }
d4b1d58c 564
6ee09cfe 565 function item_arrayToString($value) {
80c12897 566 if (!is_array($value)) {
6ee09cfe 567 return $value;
568 }
569 $retval = '';
570 $arrvals = array_values($value);
571 $arrvals = clean_param($arrvals, PARAM_INT); //prevent sql-injection
572 $retval = $arrvals[0];
b692e4aa 573 $sizeofarrvals = sizeof($arrvals);
80c12897 574 for ($i = 1; $i < $sizeofarrvals; $i++) {
6ee09cfe 575 $retval .= FEEDBACK_MULTICHOICE_LINE_SEP.$arrvals[$i];
576 }
577 return $retval;
578 }
d4b1d58c 579
6ee09cfe 580 function print_item_radio($presentation, $item, $value, $info, $align) {
581 $index = 1;
582 $checked = '';
39790bd8 583
afdb1920
AG
584 if($info->horizontal) {
585 $hv = 'h';
586 }else {
587 $hv = 'v';
588 }
589
6ee09cfe 590 foreach($presentation as $radio){
591 if($value == $index){
592 $checked = 'checked="checked"';
593 }else{
594 $checked = '';
595 }
596 $inputname = $item->typ . '_' . $item->id;
597 $inputid = $inputname.'_'.$index;
6ee09cfe 598 ?>
afdb1920
AG
599 <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
600 <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
601 <input type="radio" name="<?php echo $inputname;?>" id="<?php echo $inputid;?>" value="<?php echo $index;?>" <?php echo $checked;?> />
602 </span>
603 <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
6ee09cfe 604 <label for="<?php echo $inputid;?>"><?php echo text_to_html($radio, true, false, false);?>&nbsp;</label>
afdb1920
AG
605 </span>
606 </li>
6ee09cfe 607 <?php
6ee09cfe 608 $index++;
609 }
610 }
611
612 function print_item_check($presentation, $item, $value, $info, $align) {
d4b1d58c 613
6ee09cfe 614 if (is_array($value)) {
615 $values = $value;
616 }else {
617 $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value);
618 }
39790bd8 619
afdb1920
AG
620 if($info->horizontal) {
621 $hv = 'h';
622 }else {
623 $hv = 'v';
624 }
d4b1d58c 625
6ee09cfe 626 $index = 1;
627 $checked = '';
628 foreach($presentation as $check){
629 foreach($values as $val) {
630 if($val == $index){
631 $checked = 'checked="checked"';
632 break;
633 }else{
634 $checked = '';
635 }
636 }
637 $inputname = $item->typ. '_' . $item->id;
638 $inputid = $item->typ. '_' . $item->id.'_'.$index;
6ee09cfe 639 ?>
afdb1920
AG
640 <li class="feedback_item_check_<?php echo $hv.'_'.$align;?>">
641 <span class="feedback_item_check_<?php echo $hv.'_'.$align;?>">
642 <input type="checkbox" name="<?php echo $inputname;?>[]" id="<?php echo $inputid;?>" value="<?php echo $index;?>" <?php echo $checked;?> />
643 </span>
644 <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
645 <label for="<?php echo $inputid;?>"><?php echo text_to_html($check, true, false, false);?>&nbsp;</label>
646 </span>
647 </li>
6ee09cfe 648 <?php
6ee09cfe 649 $index++;
650 }
651 }
d4b1d58c 652
6ee09cfe 653 function print_item_dropdown($presentation, $item, $value, $info, $align) {
afdb1920
AG
654 if($info->horizontal) {
655 $hv = 'h';
656 }else {
657 $hv = 'v';
6ee09cfe 658 }
39790bd8 659
6ee09cfe 660 ?>
afdb1920
AG
661 <li class="feedback_item_select_<?php echo $hv.'_'.$align;?>">
662 <select name="<?php echo $item->typ .'_' . $item->id;?>" size="1">
663 <option value="0">&nbsp;</option>
664 <?php
665 $index = 1;
666 $checked = '';
667 foreach($presentation as $dropdown){
668 if($value == $index){
669 $selected = 'selected="selected"';
670 }else{
671 $selected = '';
672 }
673 ?>
674 <option value="<?php echo $index;?>" <?php echo $selected;?>><?php echo text_to_html($dropdown, true, false, false);?></option>
675 <?php
676 $index++;
677 }
678 ?>
679 </select>
680 </li>
6ee09cfe 681 <?php
682 }
39790bd8 683
79473294
AG
684 function set_ignoreempty($item, $ignoreempty=true) {
685 $item->options = str_replace(FEEDBACK_MULTICHOICE_IGNOREEMPTY, '', $item->options);
686 if($ignoreempty) {
687 $item->options .= FEEDBACK_MULTICHOICE_IGNOREEMPTY;
688 }
689 }
39790bd8 690
79473294
AG
691 function ignoreempty($item) {
692 if(strstr($item->options, FEEDBACK_MULTICHOICE_IGNOREEMPTY)) {
693 return true;
694 }
695 return false;
696 }
39790bd8 697
79473294
AG
698 function set_hidenoselect($item, $hidenoselect=true) {
699 $item->options = str_replace(FEEDBACK_MULTICHOICE_HIDENOSELECT, '', $item->options);
700 if($hidenoselect) {
701 $item->options .= FEEDBACK_MULTICHOICE_HIDENOSELECT;
702 }
703 }
39790bd8 704
79473294
AG
705 function hidenoselect($item) {
706 if(strstr($item->options, FEEDBACK_MULTICHOICE_HIDENOSELECT)) {
707 return true;
708 }
709 return false;
710 }
39790bd8
PS
711
712
6cc1599e
AG
713 function can_switch_require() {
714 return true;
715 }
6ee09cfe 716}