college-cwk-spelling-test/test/view.php

134 lines
3.7 KiB
PHP
Raw Normal View History

2014-03-04 05:08:11 -08:00
<?php
// Include shared subprograms
$level = "../";
require "../common/common.php";
auth(AUTH_PUPIL);
// Load Test details from database
$test = Test::get($_GET['id']);
2014-04-09 08:56:22 -07:00
// Check that test exists
2014-03-04 05:08:11 -08:00
if (!$test)
msgscrn("Test not found","Test could not be found","","");
2014-04-09 08:56:22 -07:00
// Get author of test
2014-03-04 05:08:11 -08:00
$author = User::get($test->userID);
2014-04-09 08:56:22 -07:00
// Show page
2014-03-04 05:08:11 -08:00
showHeader($test->title." - Results");
echo "<h2>".$test->title."</h2>";
echo "<p>Created on ".$test->datecreated;
if ($author)
echo " by ".$author->firstname ." ". $author->surname;
echo "</p>";
// Show user test submissions
if ($current_user->rank == 1 || $_GET['user']){
2014-04-09 08:56:22 -07:00
// Get the id of the pupil whose results we are looking at
2014-03-04 05:08:11 -08:00
$search_id = ($current_user->rank == 1) ? $current_user->id : $_GET['user'];
2014-04-09 08:56:22 -07:00
// Get results
$myres = Score::_search("WHERE userID = $search_id AND testID = {$test->id} ORDER BY scoreID desc");
if (count($myres)<1){
// They have not taken this test yet, display message
if ($search_id == $current_user->id)
echo "You have not taken this test yet.";
else
echo "The pupil has not taken this test yet.";
// Show appropriate buttons
2014-03-04 05:08:11 -08:00
if($current_user->rank > 1)
echo "<p><a href=\"view.php?id={$test->id}\" class=\"button\">Back</a></p>";
else
echo "<p><a href=\"take.php?id={$test->id}\" class=\"button\">Take test</a></p>";
}else{
2014-04-09 08:56:22 -07:00
// Display messages, and table start
2014-03-29 12:41:21 -07:00
echo "<p>Each row in this table is an attempt at the test. The latest attempt is at the top</p>";
if ($_GET['latest']==1){
?>
<style>
.resultTable tr:nth-child(2){
background: yellow;
}
</style>
<p>The row marked in yellow was the latest test.</p>
<?php
}
2014-03-04 05:08:11 -08:00
echo "<table class=\"resultTable\">";
echo "<tr><th>Score</th><th>Incorrect words</th></tr>";
2014-04-09 08:56:22 -07:00
// Loop through scores
foreach($myres as $s){
2014-03-04 05:08:11 -08:00
echo "<tr><td>{$s->score}</td><td>";
2014-04-09 08:56:22 -07:00
// Get the words they got wrong, and print them.
2014-03-04 05:08:11 -08:00
$ww = $s->wrongWords();
if ($ww){
echo "<span style=\"color:red\">";
$comma = false;
foreach($ww as $w){
if ($comma)
echo ", ";
2014-04-09 08:56:22 -07:00
echo "'".$w->word."'";
2014-03-04 05:08:11 -08:00
$comma = true;
}
echo "</span>";
}else{
echo ":D";
}
echo "</td></tr>";
}
echo "</table>";
2014-04-09 08:56:22 -07:00
// Display appropriate buttons
2014-03-04 05:08:11 -08:00
if($current_user->rank > 1)
2014-03-29 12:41:21 -07:00
echo "<p><a href=\"view.php?id={$test->id}\" class=\"button\">Back</a>";
2014-03-04 05:08:11 -08:00
else
2014-03-29 12:41:21 -07:00
echo "<p><a href=\"take.php?id={$test->id}\" class=\"button\">Retake test</a>";
echo "<a href=\"../report.php?id=$search_id\" class=\"button\">View Report</a></p>";
2014-03-04 05:08:11 -08:00
}
}else if($current_user->rank > 1){
2014-04-09 08:56:22 -07:00
// Get users that this test applies to
2014-03-04 05:08:11 -08:00
$users = $test->users();
if (!$users || count($users)<1){
2014-04-09 08:56:22 -07:00
// Display message
2014-03-04 05:08:11 -08:00
echo "No pupils are to take this test<br>";
}else{
2014-04-09 08:56:22 -07:00
// Display table head
2014-03-04 05:08:11 -08:00
echo "<table class=\"resultTable\">";
echo "<tr><th>User</th><th>Score</th><th>Attempts</td><th></th></tr>";
2014-04-09 08:56:22 -07:00
// Loop through users
2014-03-04 05:08:11 -08:00
foreach($users as $u){
echo "<tr><td>{$u->surname} {$u->firstname}</td>";
2014-04-09 08:56:22 -07:00
// Declare score here, so it is in the correct scope
2014-03-04 05:08:11 -08:00
$score = -1;
// Load score submissions
$scr = Score::_search("WHERE userID = {$u->id} AND testID = {$test->id}");
if ($scr){
foreach ($scr as $s){
if ($s->score > $score || $score == -1){
$score = $s->score;
}
}
}
2014-04-09 08:56:22 -07:00
// Display score and attempts
2014-03-04 05:08:11 -08:00
if (!$scr || count($scr)<1){
echo "<td style=\"background:red;color:white;\" colspan=2>Test not taken yet!</td>";
}else{
echo "<td>$score</td><td>".count($scr)." attempts</td>";
}
echo "<td style=\"width: 200px;\"><a class=\"button\" href=\"view.php?id={$test->id}&user={$u->id}\">View</a> <a class=\"button\" href=\"../profile.php?id={$u->id}\">Profile</a></td></tr>";
}
echo "</table>";
}
}
?>