-
Notifications
You must be signed in to change notification settings - Fork 0
/
date_test.php
284 lines (231 loc) · 10.4 KB
/
date_test.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php // $Id: index.php,v 1.201.2.10 2009/04/25 21:18:24 stronk7 Exp $
// index.php - the front page.
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
if (!file_exists('./config.php')) {
header('Location: install.php');
die;
}
require_once('config.php');
require_once($CFG->dirroot .'/course/lib.php');
require_once($CFG->dirroot .'/lib/blocklib.php');
print_header($SITE->fullname, $SITE->fullname, 'Register');
//$now = date("U",mktime(9,30,0,9,26,2009));
//$now = date("U",mktime(9,30,0,9,27,2009));
//$now = date("U",mktime(9,45,11,9,27,2009));
//$now = date("U",mktime(10,15,0,9,27,2009));
//$now = date("U",mktime(10,45,0,9,27,2009));
//$now = date("U",mktime(10,46,0,9,27,2009));
$now = date("U",mktime(12,15,10,9,27,2009));
//$now = date("U",mktime(22,00,0,9,27,2009));
//$now = date("U",mktime(22,30,0,9,27,2009));
//$now = date("U",mktime(23,00,0,9,27,2009));
//$now = date("U",mktime(23,01,0,9,27,2009));
//$now = date("U",mktime(00,00,0,9,28,2009));
//$now = date("U",mktime(00,15,0,9,28,2009));
//$now = date("U",mktime(00,30,10,9,28,2009));
$exam_length = 30;
$records = get_records_select('quiz_course_activation', "username = 'jessica' AND courseid = '4'");
/*
$record = new stdClass();
$record->starttime = date("U",mktime(9,30,0,9,27,2009));
$record->endtime = date("U",mktime(11,30,0,9,27,2009));
$records[0] = array($record);
$record->starttime = date("U",mktime(22,30,0,9,27,2009));
$record->endtime = date("U",mktime(0,30,0,9,28,2009));
$records[1] = array($record);
*/
echo date('U', $now)."<br />";
echo date('l dS \of F Y', $now)."<br />";
echo date('h:i:s A', $now)."<br /><br /><br />";
foreach($records as $record){
//echo date('U', $record->starttime)."<br />";
if(compareDates(date("Y-m-d",$now),date("Y-m-d",$record->starttime)) < 0){
//echo "Your Exam is has NOT started<br />";
examStatus(array(1));
echo "Your Exam is on:<br/>";
displayExamInfo($record, $exam_length);
}else if(compareDates(date("Y-m-d",$now),date("Y-m-d",$record->endtime)) > 0){
//echo "Your Exam is OVER. Practical is Over. -- View Grades<br />";
examStatus(array(6));
displayExamInfo($record, $exam_length);
showGrades($record);
}else{
//Exam Day
$starttime = $record->starttime;
$endtime = $record->endtime;
if($now < $starttime){
//echo "Your Exam is has NOT STARTED<br />";
//examStatus(1);
// Exam Instructions
if($now >= $starttime - 1800){
//echo"<font color='green'>Your Exam Instructions are available.</font><br/><br/>";
examStatus(array(1,2));
}else{
//echo "<font color='red'>Your Exam Instructions will be available at: </font>".date("h:i:s A",$record->starttime - ($exam_length * 60))."<br/><br/>";
examStatus(array(1,3),date("h:i:s A",$record->starttime - ($exam_length * 60)));
//echo date("h:i:s A",$record->starttime - ($exam_length * 60))."<br/>";
}
echo "Your Exam is on:<br/>";
displayExamInfo($record, $exam_length);
}else if($now >= $starttime && $now <= $endtime){
//echo "<b><font color='red'>Your Exam has Started:</font></b><br/><br/>";
if($now >= $starttime + ($exam_length * 60)){
//echo "Exam is Over - Practical Instructions Available <br/>";
examStatus(array(5));
}else{
// Starttime to + 30 mins
examStatus(array(4));
}
displayExamInfo($record, $exam_length);
}else{
//echo "Your Exam is OVER - Practical is Over - View Grades<br />";
if($record->grade1 != null){
examStatus(array(6));
}else{
examStatus(array(0));
}
displayExamInfo($record, $exam_length);
showGrades($record);
}
}
echo "<hr/>";
}
print_footer('Register'); // Please do not modify this line
?>
<?php
function displayExamInfo($record, $diff){
// Diff is time in minutes
echo "<b>".date("l dS \of F Y",$record->starttime). "</b> <br/>";
echo date("H:i:s A",$record->starttime) . " to ".date("H:i:s A",$record->endtime)."<br/><br/>";
echo "<b>Instructions: </b>".date("H:i:s A",$record->starttime-($diff*60)) . " to ".date("H:i:s A",$record->starttime)."<br/>";
echo "<b>Exam: </b>".date("H:i:s A",$record->starttime) . " to ".date("H:i:s A",$record->starttime+($diff*60))."<br/>";
echo "<b>Practical: </b>".date("H:i:s A",$record->starttime+($diff*60)) . " to ".date("H:i:s A",$record->endtime)."<br/><br/>";
}
function compareDates($start_date,$end_date) {
$start = strtotime($start_date);
$end = strtotime($end_date);
return $start-$end;
}
function compareTimes($start_date,$end_date) {
$start = strtotime($start_date);
$end = strtotime($end_date);
return $start-$end;
}
function showGrades($record, $return=false){
$report = "";
$quiz = get_record('quiz', 'id', $record->quizid);
$grade1 = "No Grade";
$grade2 = "Not Graded";
if($record->grade2 != null){
$grade2 = $record->grade2;
}
if($record->grade1 != null){
$grade1 = $record->grade1;
}
$report .= "<table border='0' cellpadding='5' cellspacing='5' width='450px'>";
$report .= "<tr><th colspan='4' style='background-color:#CCCCCC;; color:#333333'>$quiz->name</th></tr>";
$report .= "<tr><td><b>Exam:</b></td><td>$grade1 / $quiz->sumgrades</td><td><b>Practical:</b></td><td>$grade2</td></tr>";
$report .= "</table>";
if($return){
return $report;
}else{
echo $report;
}
}
function examStatus($codes,$value="",$return=false){
$message = "";
foreach($codes as $code){
switch($code){
case 1:
$message .= "<font color='red'>Exam has not started</font><br/>";
break;
case 2:
$message .= "<font color='grey'>Orientation materials are ready for review.</font><br/>";
break;
case 3:
$message .= "<font color='grey'>Orientation materials will available for review at: <b>$value</b></font><br/>";
break;
case 4:
$message .= "<font color='green'>Exam Part I is now open.</font><br/>";
break;
case 5:
$message .= "<font color='green'>Exam Part II is now open.</font><br/>";
break;
case 6:
$message .= "<font color='grey'>Exam is finished.</font><br/>";
break;
case 7:
$message .= "<font color='grey'>Not graded.</font><br/>";
break;
case 8:
$message .= "<font color='green'>Graded.</font><br/>";
break;
default:
$message .= "<font color='orange'>Exam was not taken.</font><br/>";
}
}
$container = "<table><tr><td valign='top'><b>Status: </b></td><td>$message</td></tr></table><br/><br/>";
if($return){
return $container;
}else{
echo $container;
}
}
function examStatuses($code,$return=false){
$message = "";
switch($code){
case 1:
$message = "<b>Status: </b> <font color='red'>Exam has not started</font><br/>";
break;
case 2:
$message = "<b>Status: </b> <font color='grey'>Orientation materials are ready for review.</font><br/>";
break;
case 3:
$message = "<b>Status: </b> <font color='grey'>Orientation materials will available for review at: </font>";
break;
case 4:
$message = "<b>Status: </b> <font color='green'>Exam Part I is now open.</font><br/>";
break;
case 5:
$message = "<b>Status: </b> <font color='green'>Exam Part II is now open.</font><br/>";
break;
case 6:
$message = "<b>Status: </b> <font color='grey'>Exam is finished.</font><br/>";
break;
case 7:
$message = "<b>Status: </b> <font color='grey'>Not graded.</font><br/>";
break;
case 8:
$message = "<b>Status: </b> <font color='green'>Graded.</font><br/>";
break;
default:
$message = "<b>Status: </b> <font color='orange'>Exam was not taken.</font><br/>";
}
if($return){
return $message;
}else{
echo $message;
}
}
?>