forked from thegame8714/reactquiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults.php
115 lines (103 loc) · 3.59 KB
/
results.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
require("config.php");
require("dbo_lib.php");
require("question.class.php");
require("myTinCanAPI.class.php");
$questions = array();
// We do not need the totals to show just one question
// $corrects = 0;
// $total = 0;
$page = 0;
if (!empty($_GET['page'])) {
$page = $_GET['page'];
}
$dbo = new DBO ($servername, $username, $password, $dbname);
$sql = "SELECT * FROM questions";
$dbo->query ($sql) or die ($dbo->ShowError ());
$num_questions = $dbo->emaitza_kopurua();
$sql = "SELECT * FROM questions LIMIT ".$page.", 1";
$dbo->query ($sql) or die ($dbo->ShowError ());
while ($questionDB = $dbo->emaitza()) {
$question = new question($questionDB);
$total++;
$qid = 'q'.$question->getId();
$answer = $_POST[$qid];
$passed = $question->isCorrect($answer);
// if ($passed) {
// $corrects++;
// }
$myTC = new MyTinCanAPI();
$myTC->createObject($question->getBefore());
$myTC->createActivityType($question);
$myTC->createVerb($passed);
if (is_array($answer)) {
$answer = implode(',',$answer);
}
$myTC->createResult($passed, $answer);
$myTC->sendStatement();
}
if ($corrects > 0 && $total > 0) {
$scaled = $corrects / $total;
} else {
$scaled = 0;
}
$page++;
// Different for the last question
if ($page == $num_questions) {
$lastTC = new MyTinCanAPI();
$lastTC->createObject($activity['name']);
$lastTC->createLastVerb();
$lastTC->sendStatement();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<title>TIN CAN Test</title>
<link rel="stylesheet" href="./src/css/bootstrap.min.css">
<link rel="stylesheet" href="./src/css/app.css">
<link rel="stylesheet" href="./src/css/tincan.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<h1>Tin Can Test</h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<form name="tincan_test" action="results.php?page=<?php echo $page; ?>" method="post">
<div class="well">
<?php if ($page == $num_questions) {
echo '<h3>Test finished</h3>';
} else {
try {
$sql = "SELECT * FROM questions ORDER BY id LIMIT " . $page . ", 1";
$dbo->query($sql) or die ($dbo->ShowError());
while ($questionDB = $dbo->emaitza()) {
$question = new question($questionDB);
echo $question->render();
}
} catch (PDOException $e) {
echo $e->getMessage();
} ?>
<input type="hidden" value="<?php echo $questions;?>" />
<div class="submit text-right"><input type="submit" value="Next" class="btn btn-primary" /></div>
<?php }
$conn = null;
?>
</div>
</form>
</div>
</div>
</div>
<script src="./src/js/jquery-1.11.3.min.js"></script>
</body>
</html>