Code Duplication    Length = 58-75 lines in 2 locations

main/inc/lib/exercise.lib.php 1 location

@@ 383-457 (lines=75) @@
380
                        }
381
                    }
382
383
                    if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
384
                        $s .= '<input type="hidden" name="choice2[' . $questionId . ']" value="0" />';
385
386
                        $answer_input = '<label class="checkbox">';
387
                        $answer_input .= Display::input(
388
                            'checkbox',
389
                            'choice[' . $questionId . '][' . $numAnswer . ']',
390
                            $numAnswer,
391
                            $attributes
392
                        );
393
                        $answer_input .= $answer;
394
                        $answer_input .= '</label>';
395
396
                        if ($show_comment) {
397
                            $s .= '<tr><td>';
398
                            $s .= $answer_input;
399
                            $s .= '</td>';
400
                            $s .= '<td>';
401
                            $s .= $comment;
402
                            $s .= '</td>';
403
                            $s .= '</tr>';
404
                        } else {
405
                            $s .= $answer_input;
406
                        }
407
                    } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
408
409
                        $my_choice = array();
410
                        if (!empty($user_choice_array)) {
411
                            foreach ($user_choice_array as $item) {
412
                                $item = explode(':', $item);
413
                                $my_choice[$item[0]] = $item[1];
414
                            }
415
                        }
416
417
                        $s .= '<tr>';
418
                        $s .= Display::tag('td', $answer);
419
420
                        if (!empty($quiz_question_options)) {
421
                            foreach ($quiz_question_options as $id => $item) {
422
423
                                if (isset($my_choice[$numAnswer]) && $id == $my_choice[$numAnswer]) {
424
                                    $attributes = array(
425
                                        'checked' => 1,
426
                                        'selected' => 1
427
                                    );
428
                                } else {
429
                                    $attributes = array();
430
                                }
431
432
                                if ($debug_mark_answer) {
433
                                    if ($id == $answerCorrect) {
434
                                        $attributes['checked'] = 1;
435
                                        $attributes['selected'] = 1;
436
                                    }
437
                                }
438
                                $s .= Display::tag(
439
                                    'td',
440
                                    Display::input(
441
                                        'radio',
442
                                        'choice[' . $questionId . '][' . $numAnswer . ']',
443
                                        $id,
444
                                        $attributes
445
                                    ),
446
                                    array('style' => '')
447
                                );
448
                            }
449
                        }
450
451
                        if ($show_comment) {
452
                            $s .= '<td>';
453
                            $s .= $comment;
454
                            $s .= '</td>';
455
                        }
456
                        $s .= '</tr>';
457
                    }
458
                } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
459
                    // multiple answers
460
                    $input_id = 'choice-' . $questionId . '-' . $answerId;

main/exercice/exercise.class.php 1 location

@@ 7150-7207 (lines=58) @@
7147
                        }
7148
                    }
7149
7150
                    if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
7151
                        $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />';
7152
7153
                        $answer_input = '<label class="checkbox">';
7154
                        $answer_input .= Display::input('checkbox', 'choice['.$questionId.']['.$numAnswer.']', $numAnswer, $attributes);
7155
                        $answer_input .= $answer;
7156
                        $answer_input .= '</label>';
7157
7158
                        if ($show_comment) {
7159
                            $s .= '<tr><td>';
7160
                            $s .= $answer_input;
7161
                            $s .= '</td>';
7162
                            $s .= '<td>';
7163
                            $s .= $comment;
7164
                            $s .= '</td>';
7165
                            $s .='</tr>';
7166
                        } else {
7167
                            $s .= $answer_input;
7168
                        }
7169
                    } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
7170
7171
                        $my_choice = array();
7172
                        if (!empty($user_choice_array)) {
7173
                            foreach ($user_choice_array as $item) {
7174
                                $item = explode(':', $item);
7175
                                $my_choice[$item[0]] = $item[1];
7176
                            }
7177
                        }
7178
7179
                        $s .='<tr>';
7180
                        $s .= Display::tag('td', $answer);
7181
7182
                        if (!empty($quiz_question_options)) {
7183
                            foreach ($quiz_question_options as $id => $item) {
7184
                                $id = $item['iid'];
7185
                                if (isset($my_choice[$numAnswer]) && $id == $my_choice[$numAnswer]) {
7186
                                    $attributes = array('checked' => 1, 'selected' => 1);
7187
                                } else {
7188
                                    $attributes = array();
7189
                                }
7190
7191
                                if ($debug_mark_answer) {
7192
                                    if ($id == $answerCorrect) {
7193
                                        $attributes['checked'] = 1;
7194
                                        $attributes['selected'] = 1;
7195
                                    }
7196
                                }
7197
                                $s .= Display::tag('td', Display::input('radio', 'choice['.$questionId.']['.$numAnswer.']', $id, $attributes), array('style' => ''));
7198
                            }
7199
                        }
7200
7201
                        if ($show_comment) {
7202
                            $s .= '<td>';
7203
                            $s .= $comment;
7204
                            $s .= '</td>';
7205
                        }
7206
                        $s.='</tr>';
7207
                    }
7208
7209
                } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
7210