nzart-exam-generator/index.php

174 lines
8.1 KiB
PHP
Raw Normal View History

2016-12-30 05:16:13 +00:00
<?php
require_once('includes/include.php');
2017-01-01 22:12:27 +00:00
if(isset($_REQUEST['method'])) {
2017-01-01 09:06:48 +00:00
User::loginOrRegister($_REQUEST);
}
if(isset($_REQUEST['logout'])) User::logout();
$loggedIn = $user = false;
if(isset($_SESSION['userId'])) {
$user = User::getById($_SESSION['userId']);
}
2016-12-31 11:23:57 +00:00
$questions = [];
2017-01-01 22:12:27 +00:00
if (isset($_REQUEST['viewresult']) && is_object($user)) {
$result = Result::getById($_REQUEST['viewresult']);
if(!is_object($result) || $result->getUser() != $user->getId()) {
header("Location: //".$_SERVER['HTTP_HOST']);
exit();
2016-12-31 22:36:29 +00:00
}
2017-01-01 22:12:27 +00:00
$res = $result->getResult();
foreach($res as $p=>$r) {
$_POST[$p] = $r;
}
$_POST['mark'] = 1;
} elseif (isset($_REQUEST['results']) && is_object($user)) {
$results = $user->getResults();
}
if (isset($_POST['mark'])) {
2016-12-31 22:27:08 +00:00
unset($_POST['mark']);
2017-01-01 22:12:27 +00:00
$score['total'] = $score['correct'] = $score['wrong'] = 0;
2016-12-31 22:27:08 +00:00
foreach($_POST as $i=>$q) {
$question = Question::getById($i);
$answer = Answer::getById($q);
2017-01-01 22:12:27 +00:00
if(!is_object($question) || !is_object($answer)) continue;
2016-12-31 22:27:08 +00:00
if($answer->isCorrect()) {
2017-01-01 22:12:27 +00:00
$score['correct']++;
2016-12-31 22:27:08 +00:00
} else {
$output .= "<span style='font-weight:bold'>".$question->getQuestion()."</span><br>";
$corAnswer = $question->getCorrectAnswer();
2016-12-31 22:36:29 +00:00
$output .= "Your Answer: ".$answer->getAnswer()."<br>Correct Answer: ".$corAnswer->getAnswer().'<br><br>';
2017-01-01 22:12:27 +00:00
$score['wrong']++;
2016-12-31 22:27:08 +00:00
}
2017-01-01 22:12:27 +00:00
$score['total']++;
2016-12-31 22:27:08 +00:00
}
2017-01-01 09:06:48 +00:00
if(is_object($user)) {
2017-01-01 22:12:27 +00:00
$user->storeResult($_POST, $score);
2017-01-01 09:06:48 +00:00
}
2017-01-01 22:12:27 +00:00
} else {
if(isset($_GET['questions'])) {
define('QUESTION_COUNT', intval($_GET['questions']));
} else {
define('QUESTION_COUNT', 60);
}
$questions = Question::getQuestions(QUESTION_COUNT);
2016-12-31 11:23:57 +00:00
}
2016-12-30 05:16:13 +00:00
?><!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>NZART - Practice Exam</title>
<meta name="description" content="Unofficial NZART Practice Exam">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
2017-01-01 09:06:48 +00:00
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.12.0.min.js"><\/script>')</script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
2016-12-30 05:16:13 +00:00
</head>
<body>
<div id="container">
2017-01-01 09:06:48 +00:00
<div id="user"><?php if(is_object($user)) {
2017-01-01 22:12:27 +00:00
echo "<a href='index.php?results=1'>Result History</a>. Welcome Back ".$_SESSION['username'].".<br><a href='index.php?logout=1'>Logout</a>";
2017-01-01 09:06:48 +00:00
} else {
2017-01-01 22:12:27 +00:00
echo "<div id='loginTrigger'>Login or Register</div>";
2017-01-01 09:06:48 +00:00
} ?></div>
<div id="cover" style="display:none;"></div>
<div id="login" style="display:none;">
2017-01-01 22:12:27 +00:00
<h2 style="margin:0 0 5px 0;padding:0;">Login/Register</h2>
2017-01-01 09:06:48 +00:00
<form method="post">
<label>Username<input type="text" name="username"><br/></label>
2017-01-01 22:12:27 +00:00
<label>Password<input type="password" name="password"><br/></label><br/>
<input type="hidden" name="method" value="register">
2017-01-01 09:06:48 +00:00
<button type="submit" class="loginbutton" value="login">Login</button>
2017-01-01 22:12:27 +00:00
<button type="submit" class="loginbutton" value="register">Register</button>
<script type="text/javascript">
$(".loginbutton").on("click", function(){
$('input[name=method]').attr("value",$(this).attr("value"));
});
</script>
2017-01-01 09:06:48 +00:00
</form>
</div>
2016-12-30 05:16:13 +00:00
<div id="header"><h1>Unofficial NZART Practice Exam</h1></div>
<div id="body" class="center">
2016-12-31 22:40:02 +00:00
New Exam: <a href="/index.php?questions=10">10 Questions</a> -
<a href="/index.php?questions=20">30 Questions (Half Exam)</a> -
<a href="/index.php?questions=60">60 Questions (Full Exam)</a> -
<a href="/index.php?questions=600">600 Questions (All Questions)</a>
2016-12-31 22:36:29 +00:00
<br/><br/>
2017-01-01 22:12:27 +00:00
<?php if(isset($score)) {
echo "<h3>Score ".(($score['correct']/$score['total'])*100)."% (".$score['correct']."/".$score['total'].")</h3>";
2016-12-31 22:27:08 +00:00
echo $output;
2017-01-01 22:12:27 +00:00
} elseif (isset($results)) {
$day = [];
foreach ($results as $i=>$result) {
2017-01-01 22:12:27 +00:00
$score = $result->getScore();
$date = date("Y-m-d", $result->getTime());
$day[$date][] = date("h:i a", $result->getTime())." - Score ".(($score['correct']/$score['total'])*100)."% (".$score['correct']."/".$score['total']."). ".
2017-01-01 22:12:27 +00:00
"<a href='index.php?viewresult=".$result->getId()."'>View Result</a><br/>";
2017-01-02 09:11:33 +00:00
$day[$date]['total'][] = ($score['correct'] / $score['total']) * 100;
2017-01-01 22:12:27 +00:00
}
foreach ($day as $t=>$da) {
2017-01-02 09:15:14 +00:00
echo "<br/><span style='font-weight:bold'>".$t."</span> - ";
2017-01-02 09:11:33 +00:00
$total = 0;
foreach($da['total'] as $t) {
$total = $total+$t;
}
$total = round(($total/count($da['total'])),2);
2017-01-02 09:15:14 +00:00
echo $total."% Average<br/>";
unset($da['total']);
foreach($da as $c=>$d) {
echo $d;
}
}
2017-01-01 22:12:27 +00:00
} else {
if(!is_object($user)) { ?>
Please Login to track results.<br>
<?php } ?><span style="font-weight:bold">
<?=QUESTION_COUNT?> Questions</span><br><br>
2016-12-31 11:23:57 +00:00
<form action="/" method="POST">
2016-12-30 05:16:13 +00:00
<table>
<tbody>
<?php
$letters = range('A', 'Z');
foreach($questions as $i=>$q) {
echo "<tr>";
echo "<td>".($i+1)."</td>";
2016-12-31 11:23:57 +00:00
echo "<td style='padding-left:10px'>".$q->getQuestion()."</td>";
2016-12-30 05:16:13 +00:00
echo "</tr>";
2016-12-31 07:36:47 +00:00
if(!empty($q->getImage())) {
echo "<tr>";
echo "<td></td><td><img src='img/".str_replace("\"",'',$q->getImage())."'></td>";
echo "</tr>";
}
2016-12-30 05:16:13 +00:00
foreach($q->answers as $x=>$ans) {
echo "<tr>";
2016-12-31 11:23:57 +00:00
echo "<td></td>";
2016-12-31 22:38:05 +00:00
echo "<td style='padding-left:10px'><input type='radio' name='".$q->getId()."' value='".$ans->getId()."' required> ".($letters[$x].". ".$ans->getAnswer())."</td>";
2016-12-30 05:16:13 +00:00
echo "</tr>";
}
2016-12-31 07:36:47 +00:00
echo "<tr><td>&nbsp;</td><td></td></tr>";
2016-12-30 05:16:13 +00:00
}
?>
2016-12-31 11:23:57 +00:00
<tr><td></td><td><input type="hidden" name="mark" value="1"><button type="submit">Submit</button></td></tr>
2016-12-30 05:16:13 +00:00
</tbody>
</table>
2016-12-31 11:23:57 +00:00
</form>
<?php } ?>
2016-12-30 05:16:13 +00:00
</div>
<div id="footer">
All Questions and images from NZART question bank located
<a target="_blank" href="http://www.nzart.org.nz/exam/download-examination-files/">Here</a>.<br/>
This site is open-source. Code can be found <a target="_blank" href="https://gitlab.com/idanoo/nzart-exam">here</a>.<br>
2016-12-31 07:28:37 +00:00
Last updated 31-12-2016.
2016-12-30 05:16:13 +00:00
</div>
</div>
</body>
</html>