Example #1
0
                 $reloadqi = true;
             }
         }
     }
 } else {
     if ($_GET['regenall'] == "all") {
         for ($i = 0; $i < count($questions); $i++) {
             if ($qi[$questions[$i]]['allowregen'] == 0) {
                 continue;
             }
             $scores[$i] = -1;
             $rawscores[$i] = -1;
             $attempts[$i] = 0;
             $seeds[$i] = rand(1, 9999);
             $newla = array();
             deletefilesifnotused($lastanswers[$i], $bestlastanswers[$i]);
             $laarr = explode('##', $lastanswers[$i]);
             foreach ($laarr as $lael) {
                 if ($lael == "ReGen") {
                     $newla[] = "ReGen";
                 }
             }
             $newla[] = "ReGen";
             $lastanswers[$i] = implode('##', $newla);
             $reattempting = array();
             if (isset($qi[$questions[$i]]['answeights'])) {
                 $reloadqi = true;
             }
         }
     } else {
         if ($_GET['regenall'] == "fromscratch" && $testsettings['testtype'] == "Practice" && !$isreview) {
Example #2
0
function scorequestion($qn, $rectime = true)
{
    global $questions, $scores, $seeds, $testsettings, $qi, $attempts, $lastanswers, $isreview, $bestquestions, $bestseeds, $bestscores, $bestattempts, $bestlastanswers, $reattempting, $rawscores, $bestrawscores, $firstrawscores;
    global $regenonreattempt, $sessiondata;
    //list($qsetid,$cat) = getqsetid($questions[$qn]);
    $lastrawscore = $rawscores[$qn];
    list($unitrawscore, $rawscores[$qn]) = scoreq($qn, $qi[$questions[$qn]]['questionsetid'], $seeds[$qn], $_POST["qn{$qn}"], $attempts[$qn], $qi[$questions[$qn]]['points']);
    $afterpenalty = calcpointsafterpenalty($unitrawscore, $qi[$questions[$qn]], $testsettings, $attempts[$qn]);
    $rawscore = calcpointsafterpenalty($unitrawscore, $qi[$questions[$qn]], $testsettings, 0);
    //possible
    $noscores = $testsettings['testtype'] == "NoScores";
    //work in progress
    //need to rework canimprove
    if (!$regenonreattempt && $attempts[$qn] > 0 && strpos($afterpenalty, '~') !== false && !$noscores) {
        $appts = explode('~', $afterpenalty);
        $prepts = explode('~', $rawscore);
        $curs = explode('~', $scores[$qn]);
        if (count($appts) != count($curs)) {
            //number of parts has changed - ignore previous work
            $scores[$qn] = $afterpenalty;
        } else {
            for ($k = 0; $k < count($curs); $k++) {
                if ($appts[$k] > $curs[$k]) {
                    //part after penalty better than orig, replace
                    $curs[$k] = $appts[$k];
                }
                if ($prepts[$k] < $curs[$k]) {
                    //changed correct to incorrect, take away pts
                    $curs[$k] = $appts[$k];
                }
            }
            $scores[$qn] = implode('~', $curs);
        }
    } else {
        $scores[$qn] = $afterpenalty;
    }
    if (!$isreview && $attempts[$qn] == 0 && strpos($lastanswers[$qn], '##') === false && !$sessiondata['isteacher']) {
        $firstrawscores[$qn] = $rawscores[$qn];
        if ($rectime) {
            global $timesontask;
            $time = explode('~', $timesontask[$qn]);
            $time = $time[0];
        } else {
            $time = 0;
            //for all at once display, where time is not useful info
        }
        $query = "INSERT INTO imas_firstscores (courseid,qsetid,score,scoredet,timespent) VALUES ";
        $query .= "('" . addslashes($testsettings['courseid']) . "','" . $qi[$questions[$qn]]['questionsetid'] . "','" . round(100 * getpts($unitrawscore)) . "','" . $rawscores[$qn] . "','{$time}')";
        mysql_query($query) or die("Query failed : " . mysql_error());
    }
    //$scores[$qn] = $afterpenalty;
    $attempts[$qn]++;
    $loc = array_search($qn, $reattempting);
    if ($loc !== false) {
        array_splice($reattempting, $loc, 1);
    }
    if ((getpts($scores[$qn]) >= getpts($bestscores[$qn]) || $noscores && ($lastrawscore != $rawscores[$qn] || $rawscore == 0)) && !$isreview) {
        $bestseeds[$qn] = $seeds[$qn];
        $bestscores[$qn] = $scores[$qn];
        $bestrawscores[$qn] = $rawscores[$qn];
        $bestattempts[$qn] = $attempts[$qn];
        deletefilesifnotused($bestlastanswers[$qn], $lastanswers[$qn]);
        $bestlastanswers[$qn] = $lastanswers[$qn];
        $bestquestions[$qn] = $questions[$qn];
    }
    return $rawscore;
}