Code Duplication    Length = 58-75 lines in 2 locations

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

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

main/exercise/exercise.class.php 1 location

@@ 7230-7287 (lines=58) @@
7227
                        }
7228
                    }
7229
7230
                    if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
7231
                        $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />';
7232
7233
                        $answer_input = '<label class="checkbox">';
7234
                        $answer_input .= Display::input('checkbox', 'choice['.$questionId.']['.$numAnswer.']', $numAnswer, $attributes);
7235
                        $answer_input .= $answer;
7236
                        $answer_input .= '</label>';
7237
7238
                        if ($show_comment) {
7239
                            $s .= '<tr><td>';
7240
                            $s .= $answer_input;
7241
                            $s .= '</td>';
7242
                            $s .= '<td>';
7243
                            $s .= $comment;
7244
                            $s .= '</td>';
7245
                            $s .='</tr>';
7246
                        } else {
7247
                            $s .= $answer_input;
7248
                        }
7249
                    } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
7250
7251
                        $my_choice = array();
7252
                        if (!empty($user_choice_array)) {
7253
                            foreach ($user_choice_array as $item) {
7254
                                $item = explode(':', $item);
7255
                                $my_choice[$item[0]] = $item[1];
7256
                            }
7257
                        }
7258
7259
                        $s .='<tr>';
7260
                        $s .= Display::tag('td', $answer);
7261
7262
                        if (!empty($quiz_question_options)) {
7263
                            foreach ($quiz_question_options as $id => $item) {
7264
                                $id = $item['iid'];
7265
                                if (isset($my_choice[$numAnswer]) && $id == $my_choice[$numAnswer]) {
7266
                                    $attributes = array('checked' => 1, 'selected' => 1);
7267
                                } else {
7268
                                    $attributes = array();
7269
                                }
7270
7271
                                if ($debug_mark_answer) {
7272
                                    if ($id == $answerCorrect) {
7273
                                        $attributes['checked'] = 1;
7274
                                        $attributes['selected'] = 1;
7275
                                    }
7276
                                }
7277
                                $s .= Display::tag('td', Display::input('radio', 'choice['.$questionId.']['.$numAnswer.']', $id, $attributes), array('style' => ''));
7278
                            }
7279
                        }
7280
7281
                        if ($show_comment) {
7282
                            $s .= '<td>';
7283
                            $s .= $comment;
7284
                            $s .= '</td>';
7285
                        }
7286
                        $s.='</tr>';
7287
                    }
7288
7289
                } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
7290