function showscores($questions, $attempts, $testsettings) { global $isdiag, $allowregen, $isreview, $noindivscores, $scores, $bestscores, $qi, $superdone, $timelimitkickout, $reviewatend; $total = 0; $lastattempttotal = 0; for ($i = 0; $i < count($bestscores); $i++) { if (getpts($bestscores[$i]) > 0) { $total += getpts($bestscores[$i]); } if (getpts($scores[$i]) > 0) { $lastattempttotal += getpts($scores[$i]); } } $totpossible = totalpointspossible($qi); $average = round(100 * (double) $total / (double) $totpossible, 1); $doendredirect = false; $outmsg = ''; if ($testsettings['endmsg'] != '') { $endmsg = unserialize($testsettings['endmsg']); $redirecturl = ''; if (isset($endmsg['msgs'])) { foreach ($endmsg['msgs'] as $sc => $msg) { //array must be reverse sorted if ($endmsg['type'] == 0 && $total >= $sc || $endmsg['type'] == 1 && $average >= $sc) { $outmsg = $msg; break; } } if ($outmsg == '') { $outmsg = $endmsg['def']; } if (!isset($endmsg['commonmsg'])) { $endmsg['commonmsg'] = ''; } if (strpos($outmsg, 'redirectto:') !== false) { $redirecturl = trim(substr($outmsg, 11)); echo "<input type=\"button\" value=\"", _('Continue'), "\" onclick=\"window.location.href='{$redirecturl}'\"/>"; return false; } } } if ($isdiag) { global $userid; $query = "SELECT * from imas_users WHERE id='{$userid}'"; $result = mysql_query($query) or die("Query failed : " . mysql_error()); $userinfo = mysql_fetch_array($result, MYSQL_ASSOC); echo "<h3>{$userinfo['LastName']}, {$userinfo['FirstName']}: "; echo substr($userinfo['SID'], 0, strpos($userinfo['SID'], '~')); echo "</h3>\n"; } echo "<h3>", _('Scores:'), "</h3>\n"; if (!$noindivscores && !$reviewatend) { echo "<table class=scores>"; for ($i = 0; $i < count($scores); $i++) { echo "<tr><td>"; if ($bestscores[$i] == -1) { $bestscores[$i] = 0; } if ($scores[$i] == -1) { $scores[$i] = 0; echo _('Question') . ' ' . ($i + 1) . ': </td><td>'; echo _('Last attempt: '); echo _('Not answered'); echo "</td>"; echo "<td> ", _('Score in Gradebook: '); echo printscore($bestscores[$i], $i); echo "</td>"; echo "</tr>\n"; } else { echo _('Question') . ' ' . ($i + 1) . ': </td><td>'; echo _('Last attempt: '); echo printscore($scores[$i], $i); echo "</td>"; echo "<td> ", _('Score in Gradebook: '); echo printscore($bestscores[$i], $i); echo "</td>"; echo "</tr>\n"; } } echo "</table>"; } global $testid; recordtestdata(); if ($testsettings['testtype'] != "NoScores") { echo "<p>", sprintf(_('Total Points on Last Attempts: %d out of %d possible'), $lastattempttotal, $totpossible), "</p>\n"; //if ($total<$testsettings['minscore']) { if ($testsettings['minscore'] < 10000 && $total < $testsettings['minscore'] || $testsettings['minscore'] > 10000 && $total < ($testsettings['minscore'] - 10000) / 100 * $totpossible) { echo "<p><b>", sprintf(_('Total Points Earned: %d out of %d possible: '), $total, $totpossible); } else { echo "<p><b>", sprintf(_('Total Points in Gradebook: %d out of %d possible: '), $total, $totpossible); } echo "{$average} % </b></p>\n"; if ($outmsg != '') { echo "<p style=\"color:red;font-weight: bold;\">{$outmsg}</p>"; if ($endmsg['commonmsg'] != '' && $endmsg['commonmsg'] != '<p></p>') { echo $endmsg['commonmsg']; } } //if ($total<$testsettings['minscore']) { if ($testsettings['minscore'] < 10000 && $total < $testsettings['minscore'] || $testsettings['minscore'] > 10000 && $total < ($testsettings['minscore'] - 10000) / 100 * $totpossible) { if ($testsettings['minscore'] < 10000) { $reqscore = $testsettings['minscore']; } else { $reqscore = $testsettings['minscore'] - 10000 . '%'; } echo "<p><span style=\"color:red;\"><b>", sprintf(_('A score of %s is required to receive credit for this assessment'), $reqscore), "<br/>", _('Grade in Gradebook: No Credit (NC)'), "</span></p> "; } } else { echo "<p><b>", _('Your scores have been recorded for this assessment.'), "</b></p>"; } //if timelimit is exceeded $now = time(); if (!$timelimitkickout && $testsettings['timelimit'] > 0 && $now - $GLOBALS['starttime'] > $testsettings['timelimit']) { $over = $now - $GLOBALS['starttime'] - $testsettings['timelimit']; echo "<p>", _('Time limit exceeded by'), " "; if ($over > 60) { $overmin = floor($over / 60); echo "{$overmin} ", _('minutes'), ", "; $over = $over - $overmin * 60; } echo "{$over} ", _('seconds'), ".<br/>\n"; echo _('Grade is subject to acceptance by the instructor'), "</p>\n"; } if (!$superdone) { // $total < $totpossible && if ($noindivscores) { echo "<p>", _('<a href="showtest.php?reattempt=all">Reattempt assessment</a> on questions allowed (note: where reattempts are allowed, all scores, correct and incorrect, will be cleared)'), "</p>"; } else { if (canimproveany()) { echo "<p>", _('<a href="showtest.php?reattempt=canimprove">Reattempt assessment</a> on questions that can be improved where allowed'), "</p>"; } if (hasreattemptsany()) { echo "<p>", _('<a href="showtest.php?reattempt=all">Reattempt assessment</a> on all questions where allowed'), "</p>"; } } if ($allowregen) { echo "<p>", _('<a href="showtest.php?regenall=missed">Try similar problems</a> for all questions with less than perfect scores where allowed.'), "</p>"; echo "<p>", _('<a href="showtest.php?regenall=all">Try similar problems</a> for all questions where allowed.'), "</p>"; } } if ($testsettings['testtype'] != "NoScores") { $hascatset = false; foreach ($qi as $qii) { if ($qii['category'] != '0') { $hascatset = true; break; } } if ($hascatset) { include "../assessment/catscores.php"; catscores($questions, $bestscores, $testsettings['defpoints'], $testsettings['defoutcome'], $testsettings['courseid']); } } if ($reviewatend) { global $testtype, $scores, $saenddate, $isteacher, $istutor, $seeds, $attempts, $rawscores, $noraw; $showa = false; for ($i = 0; $i < count($questions); $i++) { echo '<div>'; if (!$noraw) { if (strpos($rawscores[$i], '~') !== false) { $col = explode('~', $rawscores[$i]); } else { $col = array($rawscores[$i]); } } else { $col = scorestocolors($noraw ? $scores[$i] : $rawscores[$i], $qi[$questions[$i]]['points'], $qi[$questions[$i]]['answeights'], $noraw); } displayq($i, $qi[$questions[$i]]['questionsetid'], $seeds[$i], $showa, false, $attempts[$i], false, false, false, $col); echo "<div class=review>", _('Question') . " " . ($i + 1) . ". ", _('Last Attempt:'); echo printscore($scores[$i], $i); echo '<br/>', _('Score in Gradebook: '); echo printscore($bestscores[$i], $i); echo '</div>'; } } return true; }
function recordtestdata($limit = false) { global $isreview, $questions, $bestquestions, $bestscores, $bestattempts, $bestseeds, $bestlastanswers, $scores, $attempts, $seeds, $lastanswers, $testid, $testsettings, $sessiondata, $reattempting, $timesontask, $lti_sourcedid, $qi, $noraw, $rawscores, $bestrawscores, $firstrawscores; if ($noraw) { $bestscorelist = implode(',', $bestscores); } else { $bestscorelist = implode(',', $bestscores) . ';' . implode(',', $bestrawscores) . ';' . implode(',', $firstrawscores); } $bestattemptslist = implode(',', $bestattempts); $bestseedslist = implode(',', $bestseeds); $bestlastanswers = str_replace('~', '', $bestlastanswers); $bestlalist = implode('~', $bestlastanswers); $bestlalist = addslashes(stripslashes($bestlalist)); if ($noraw) { $scorelist = implode(',', $scores); } else { $scorelist = implode(',', $scores) . ';' . implode(',', $rawscores); } $attemptslist = implode(',', $attempts); $seedslist = implode(',', $seeds); $lastanswers = str_replace('~', '', $lastanswers); $lalist = implode('~', $lastanswers); $lalist = addslashes(stripslashes($lalist)); $timeslist = implode(',', $timesontask); $reattemptinglist = implode(',', $reattempting); $questionlist = implode(',', $questions); $bestquestionlist = implode(',', $bestquestions); if ($questionlist != $bestquestionlist) { $questionlist .= ';' . $bestquestionlist; } $now = time(); if ($isreview) { if ($limit) { $query = "UPDATE imas_assessment_sessions SET reviewlastanswers='{$lalist}' "; } else { $query = "UPDATE imas_assessment_sessions SET reviewscores='{$scorelist}',reviewattempts='{$attemptslist}',reviewseeds='{$seedslist}',reviewlastanswers='{$lalist}',"; $query .= "reviewreattempting='{$reattemptinglist}' "; } } else { if ($limit) { $query = "UPDATE imas_assessment_sessions SET lastanswers='{$lalist}',timeontask='{$timeslist}' "; } else { $query = "UPDATE imas_assessment_sessions SET scores='{$scorelist}',attempts='{$attemptslist}',seeds='{$seedslist}',lastanswers='{$lalist}',"; $query .= "bestseeds='{$bestseedslist}',bestattempts='{$bestattemptslist}',bestscores='{$bestscorelist}',bestlastanswers='{$bestlalist}',"; $query .= "endtime={$now},reattempting='{$reattemptinglist}',timeontask='{$timeslist}',questions='{$questionlist}' "; } if (isset($lti_sourcedid) && strlen($lti_sourcedid) > 0 && $sessiondata['ltiitemtype'] == 0) { //update lti record. We only do this for single assessment placements require_once "../includes/ltioutcomes.php"; $total = 0; for ($i = 0; $i < count($bestscores); $i++) { if (getpts($bestscores[$i]) > 0) { $total += getpts($bestscores[$i]); } } $totpossible = totalpointspossible($qi); $grade = round($total / $totpossible, 4); $res = updateLTIgrade('update', $lti_sourcedid, $testsettings['id'], $grade); } } if ($testsettings['isgroup'] > 0 && $sessiondata['groupid'] > 0 && !$isreview) { $query .= "WHERE agroupid='{$sessiondata['groupid']}' AND assessmentid='{$testsettings['id']}'"; } else { $query .= "WHERE id='{$testid}' LIMIT 1"; } mysql_query($query) or die("Query failed : {$query} " . mysql_error()); }