Code Duplication    Length = 49-51 lines in 2 locations

main/exercice/exercise.class.php 2 locations

@@ 3549-3599 (lines=51) @@
3546
                        //initialise answer tags
3547
                        $user_tags = $correct_tags = $real_text = array();
3548
                        // the loop will stop at the end of the text
3549
                        while (1) {
3550
                            // quits the loop if there are no more blanks (detect '[')
3551
                            if (($pos = api_strpos($temp, '[')) === false) {
3552
                                // adds the end of the text
3553
                                $answer = $temp;
3554
                                $real_text[] = $answer;
3555
                                break; //no more "blanks", quit the loop
3556
                            }
3557
                            // adds the piece of text that is before the blank
3558
                            //and ends with '[' into a general storage array
3559
                            $real_text[] = api_substr($temp, 0, $pos +1);
3560
                            $answer .= api_substr($temp, 0, $pos +1);
3561
                            //take the string remaining (after the last "[" we found)
3562
                            $temp = api_substr($temp, $pos +1);
3563
                            // quit the loop if there are no more blanks, and update $pos to the position of next ']'
3564
                            if (($pos = api_strpos($temp, ']')) === false) {
3565
                                // adds the end of the text
3566
                                $answer .= $temp;
3567
                                break;
3568
                            }
3569
                            if ($from_database) {
3570
                                $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
3571
                                              WHERE
3572
                                                exe_id = '".$exeId."' AND
3573
                                                question_id= ".intval($questionId)."";
3574
                                $resfill = Database::query($queryfill);
3575
                                $str = Database::result($resfill, 0, 'answer');
3576
                                api_preg_match_all('#\[([^[]*)\]#', $str, $arr);
3577
                                $str = str_replace('\r\n', '', $str);
3578
3579
                                $choice = $arr[1];
3580
                                if (isset($choice[$j])) {
3581
                                    $tmp = api_strrpos($choice[$j], ' / ');
3582
                                    $choice[$j] = api_substr($choice[$j], 0, $tmp);
3583
                                    $choice[$j] = trim($choice[$j]);
3584
                                    // Needed to let characters ' and " to work as part of an answer
3585
                                    $choice[$j] = stripslashes($choice[$j]);
3586
                                } else {
3587
                                    $choice[$j] = null;
3588
                                }
3589
                            } else {
3590
                                // This value is the user input, not escaped while correct answer is escaped by fckeditor
3591
                                $choice[$j] = api_htmlentities(trim($choice[$j]));
3592
                            }
3593
3594
                            $user_tags[] = $choice[$j];
3595
                            //put the contents of the [] answer tag into correct_tags[]
3596
                            $correct_tags[] = api_substr($temp, 0, $pos);
3597
                            $j++;
3598
                            $temp = api_substr($temp, $pos +1);
3599
                        }
3600
                        $answer = '';
3601
                        $real_correct_tags = $correct_tags;
3602
                        $chosen_list = array();
@@ 3773-3821 (lines=49) @@
3770
                    //initialise answer tags
3771
                    $userTags = $correctTags = $realText = array();
3772
                    // the loop will stop at the end of the text
3773
                    while (1) {
3774
                        // quits the loop if there are no more blanks (detect '[')
3775
                        if (($pos = api_strpos($temp, '[')) === false) {
3776
                            // adds the end of the text
3777
                            $answer = $temp;
3778
                            $realText[] = $answer;
3779
                            break; //no more "blanks", quit the loop
3780
                        }
3781
                        // adds the piece of text that is before the blank
3782
                        //and ends with '[' into a general storage array
3783
                        $realText[] = api_substr($temp, 0, $pos +1);
3784
                        $answer .= api_substr($temp, 0, $pos +1);
3785
                        //take the string remaining (after the last "[" we found)
3786
                        $temp = api_substr($temp, $pos +1);
3787
                        // quit the loop if there are no more blanks, and update $pos to the position of next ']'
3788
                        if (($pos = api_strpos($temp, ']')) === false) {
3789
                            // adds the end of the text
3790
                            $answer .= $temp;
3791
                            break;
3792
                        }
3793
                        if ($from_database) {
3794
                            $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
3795
                                          WHERE
3796
                                            exe_id = '".$exeId."' AND
3797
                                            question_id= ".intval($questionId)."";
3798
                            $resfill = Database::query($queryfill);
3799
                            $str = Database::result($resfill, 0, 'answer');
3800
                            api_preg_match_all('#\[([^[]*)\]#', $str, $arr);
3801
                            $str = str_replace('\r\n', '', $str);
3802
                            $choice = $arr[1];
3803
                            if (isset($choice[$j])) {
3804
                                $tmp = api_strrpos($choice[$j], ' / ');
3805
                                $choice[$j] = api_substr($choice[$j], 0, $tmp);
3806
                                $choice[$j] = trim($choice[$j]);
3807
                                // Needed to let characters ' and " to work as part of an answer
3808
                                $choice[$j] = stripslashes($choice[$j]);
3809
                            } else {
3810
                                $choice[$j] = null;
3811
                            }
3812
                        } else {
3813
                            // This value is the user input, not escaped while correct answer is escaped by fckeditor
3814
                            $choice[$j] = api_htmlentities(trim($choice[$j]));
3815
                        }
3816
                        $userTags[] = $choice[$j];
3817
                        //put the contents of the [] answer tag into correct_tags[]
3818
                        $correctTags[] = api_substr($temp, 0, $pos);
3819
                        $j++;
3820
                        $temp = api_substr($temp, $pos +1);
3821
                    }
3822
                    $answer = '';
3823
                    $realCorrectTags = $correctTags;
3824