-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhostedQuizStats.php
231 lines (204 loc) · 13.9 KB
/
hostedQuizStats.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
include 'assets/RandomColor.php';
use Colors\RandomColor;
require_once 'sidebar.php';
require_once 'backend/connector.php';
renderSideBar("hostedQuizStats");
function getAttemptedUsers($qid,$conn)
{
$stmt=$conn->prepare("SELECT count(QuizAttempt.qaid) as ucount FROM Quiz,QuizAttempt where QuizAttempt.qid=Quiz.qid and Quiz.qid=? GROUP BY Quiz.qid");
$stmt->bind_param('i',$qid);
if($stmt->execute()==TRUE)
{
$result = $stmt->get_result();
while($row=$result->fetch_assoc())
{
return $row['ucount'];
}
return "0";
}
else
return "SQL Err";
}
?>
<script src="js/controller.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="js/UIController.js"></script>
<script>let temp = {};</script>
<div class="content ml-3 mr-3">
<div class="card ">
<div class="card-header card-header-success">
<h4 class="card-title">Quizzes Timeline </h4>
</div>
<div class="card-body">
<div id="quizTimelineChart" class="chart mt-2"></div>
</div>
</div>
<div class="card card-plain ">
<div class="card-header card-header-info ml-3 mr-3">
<span class="card-title fs-4 "><span class="material-icons align-middle mr-2">event</span>
Ongoing/Upcoming Quizzes
</span>
</div>
<div class="card-body p-2 row justify-content-center">
<?php
$query = "SELECT Quiz.qid,(SELECT COUNT(Questions.xid) FROM Questions WHERE Questions.qid = Quiz.qid) AS QCount,Quiz.title,Quiz.description, Quiz.fromdate, Quiz.todate, Quiz.uid, Quiz.quizkey, Quiz.password FROM `Quiz`,Questions WHERE Quiz.uid = ? AND Quiz.todate >= CURDATE() GROUP BY Quiz.qid ORDER BY fromdate";
$stmt = $conn->prepare($query);
$stmt->bind_param("i",$_SESSION['uid']);
if($stmt->execute() === TRUE) {
$result = $stmt->get_result();
$i = 1;
$dates = array();
$pastColors = array();
$color = RandomColor::one(array('hue'=>array('green',160),'luminosity'=>"dark"));
while ($row = $result->fetch_assoc()) {
// print_r($row);
$frDate = date_create($row['fromdate'])->setTimezone(new DateTimeZone("Asia/Kolkata"))->format("d/m/Y");
if(!in_array($frDate,$dates)){
array_unshift($dates, $frDate);
$color = RandomColor::one(array('hue'=>array('green',160),'luminosity'=>"dark"));
if(in_array($color,$pastColors)) $color = RandomColor::one(array('hue'=>array('green',160),'luminosity'=>"dark"));
array_unshift($pastColors, $color);
}
?>
<script>
temp = {
qid:"<?php echo $row['qid']; ?>",
qname:"<?php echo $row['title']; ?>",
startDate:"<?php echo date_create($row['fromdate'])->setTimezone(new DateTimeZone("Asia/Kolkata"))->getTimestamp(); ?>",
endDate:"<?php echo date_create($row['todate'])->setTimezone(new DateTimeZone("Asia/Kolkata"))->getTimestamp();?>"
}
quizData.push(temp);
</script>
<div class="col-md-4 col-sm-12 col-xs-12 col-lg-4 pl-4" id="quiz_<?php echo $row['qid'];?>">
<div class="quiz-card card">
<div style="background: <?php echo $color; ?>" class="custom-header ml-3 mr-3">
<div class="row justify-content-center text-center">
<div class="col-12 text-center">
<div class="fs-3 p-2" style="color:#2d2f60; background: #fff;opacity:0.5; border-radius: 8px;"><strong><?php echo $i.".".$row['title']; ?></strong></div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12 fs-5 mt-3">
<span><span class="material-icons align-middle mr-2 fs-2">quiz</span>Questions:
<?php echo $row['QCount'];?>
</span>
</div>
</div>
</div>
<div class="card-body row">
<div class="col-md-12 col-sm-12 col-xs-12 mt-2 pl-4 pr-4 text-justify">
<span class="material-icons align-middle mr-auto">info</span> <?php echo $row['description']; ?>
</div>
<div class="col-md-12 col-sm-12 col-xs-12 fs-6 mt-3 text-center">
<span class="d-flex justify-content-around">
<span class="material-icons align-middle mr-auto">date_range</span>
<span class=" flex-grow-1 mr-4">From <strong><?php
$fr_date = date_create($row['fromdate'])->setTimezone(new DateTimeZone("Asia/Kolkata"))->format("d/m/Y g:i:s A");
echo $fr_date; ?></strong><br/> To
<strong><?php $to_date = date_create($row['todate'])->setTimezone(new DateTimeZone("Asia/Kolkata"))->format("d/m/Y g:i:s A");
echo $to_date; ?></strong></span>
</span>
</div>
</div>
<div class="card-footer ">
<div class="optionsContainer text-center w-100">
<form style="display: inline-block" id="<?php echo $row['qid'];?>" method="post" action="/quizkeeper/hostQuiz.php">
<input type="hidden" name="mode" value="ed+<?php echo $row['qid'];?>">
<button name="edit_quiz_btn" class="btn btn-sm btn-outline-success" onclick="">
Edit Quiz
</button>
</form>
<button id="remove_quiz_btn<?php echo $row['qid'];?>" onclick="removeQuiz(<?php echo $row['qid'];?>)" class="btn btn-sm btn-outline-danger">
Remove Quiz </button>
<span style="position:relative; display: none; margin-bottom: -10px" id="loadbar<?php echo $row['qid'];?>" class="ml-2 fs-6 spinner-border text-danger">
</span>
</div>
</div>
<div class="quiz-creds custom-card bg-light" style="border-radius: 50px 8px 8px 50px;">
<img src="assets/img/shield.png" class="float-left" style="transform: translate(-1px,0px)" width="48px" height="48px">
<div class="text-center text-white" style="transform: translate(-20px,0px)">
<div>key: <strong><?php echo $row['quizkey'];?></strong><br>password: <strong><?php echo $row['password'];?></strong></div>
</div>
</div>
</div>
</div>
<?php $i++;}}?>
<script>prepareQuizTimeline();</script>
</div>
</div>
<!-----------------------------------------------PAST QUIZ--------------------------------------------------------->
<div class="card card-plain mt-5">
<div class="card-header card-header-info ml-3 mr-3">
<span class="card-title fs-4 "><span class="material-icons align-middle mr-2">event</span>
Past Quizzes
</span>
</div>
<div class="card-body p-4 row justify-content-center">
<?php
$query = "SELECT Quiz.qid,(SELECT COUNT(Questions.xid) FROM Questions WHERE Questions.qid = Quiz.qid) AS QCount,Quiz.title,Quiz.description, Quiz.fromdate, Quiz.todate, Quiz.uid, Quiz.quizkey, Quiz.password FROM `Quiz`,Questions WHERE Quiz.uid = ? AND Quiz.todate < CURRENT_TIMESTAMP GROUP BY Quiz.qid ORDER BY fromdate";
$stmt = $conn->prepare($query);
$stmt->bind_param("i",$_SESSION['uid']);
if($stmt->execute() === TRUE) {
$result = $stmt->get_result();
$i = 1;
$dates = array();
$pastColors = array();
$color = RandomColor::one(array('hue'=>array('green', 160),'luminosity'=>"dark"));
while ($row = $result->fetch_assoc()) {
// print_r($row);
$frDate = date_create($row['fromdate'])->setTimezone(new DateTimeZone("Asia/Kolkata"))->format("d/m/Y");
if(!in_array($frDate,$dates)){
array_unshift($dates, $frDate);
$color = RandomColor::one(array('hue'=>array('green', 160),'luminosity'=>"dark"));
if(in_array($color,$pastColors)) $color = RandomColor::one(array('hue'=>array('green',160),'luminosity'=>"dark"));
array_unshift($pastColors, $color);
}
?>
<div class="col-md-12 col-sm-12 col-xs-12 col-lg-12 p-3">
<div class="custom-card row text-center">
<div style="background: <?php echo $color; ?>; border-radius: 8px 0px 0px 8px" class="text-white col-md-4 col-sm-12 col-xs-12 mr-auto">
<div class="row justify-content-center text-center">
<div class="col-12 text-center">
<div style="color:#2d2f60; background: #fff;opacity:0.5; border-radius:0px 0px 8px 8px;"> <strong class="fs-4 p-2" ><?php echo $i.".".$row['title']; ?></strong></div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6 fs-5 mt-2">
<span><span class="material-icons align-middle mr-2 fs-4">quiz</span>
<?php echo $row['QCount'];?>
</span>
</div>
<div class="col-md-6 col-sm-6 col-xs-6 fs-5 mt-2">
<span><span class="material-icons align-middle mr-2 fs-4">people</span><?php echo getAttemptedUsers($row['qid'],$conn);?>
</span>
</div>
</div>
</div>
<div class="card-body col-md-6 col-sm-12 col-xs-12 text-center ml-auto">
<div class="col-md-12 col-sm-12 col-xs-12 fs-6 mt-2">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12 mt-2 pl-4 pr-4 text-justify">
<span class="material-icons align-middle mr-auto">info</span> <?php echo $row['description']; ?>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<span class="material-icons align-middle">date_range</span>
<span class="">From <strong><?php
$fr_date = date_create($row['fromdate'])->setTimezone(new DateTimeZone("Asia/Kolkata"))->format("d/m/Y g:i:s A");
echo $fr_date; ?></strong><br/> To
<strong><?php $to_date = date_create($row['todate'])->setTimezone(new DateTimeZone("Asia/Kolkata"))->format("d/m/Y g:i:s A");
echo $to_date; ?></strong></span>
<form method="post" action="ViewQuizStats.php">
<input type="hidden" value="<?php echo $row['qid'] ?>" name="qid" >
<span class="col-md-3 col-sm-3 col-xs-12 text-right"><button class="btn btn-sm btn-outline-info"><span class="material-icons align-middle">analytics</span> Details</button></span>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php $i++;}}?>
</div>
</div>
</div>
</div> <!--END OF main-panel class-->
</div><!--END OF wrapper class-->
</body>
</html>