/
testingstudent.php
237 lines (185 loc) · 8.45 KB
/
testingstudent.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
<html>
<?php
echo "<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script>
<link rel='stylesheet' type='text/css' href='css/jquery.countdown.css'>
<script type='text/javascript' src='js/jquery.plugin.js'></script>
<script type='text/javascript' src='js/jquery.countdown.js'></script>
";
date_default_timezone_set('America/Chicago');
require_once 'login.php';
include 'cheatsheat.php';
mylog('post begins');
echo "<html>";
$db_server = mysqli_connect("localhost", "root", "root", "schedule");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
global $db_server;
$today = date("Y-m-d");
global $today;
function display() {
$db_server = mysqli_connect("localhost", "root", "root", "schedule");
$today = date("Y-m-d");
$cycquery = "SELECT cycleday FROM days WHERE daate = '$today';";
mylog($cycquery);
$cycresult = mysqli_query($db_server, $cycquery);
if ($cycquery->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$row = mysqli_fetch_array($cycresult, MYSQLI_ASSOC);
mylog("fetched today's date");
mysqli_free_result($cycresult);
$cyclevalue = $row['cycleday'];
echo "<h2 style='text-align:center'> TODAY IS </h2><h1 style='text-align:center'> $cyclevalue DAY</h1> ";
}
function timecheck() {
$db_server = mysqli_connect("localhost", "root", "root", "schedule");
$today = date("Y-m-d");
$currenthour = date("H");
echo $currenttime;
$db_server = mysqli_connect("localhost", "root", "root", "schedule");
$cycquery = "SELECT cycleday FROM days WHERE daate = '$today';";
mylog($cycquery);
$cycresult = mysqli_query($db_server, $cycquery);
if ($cycquery->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$row = mysqli_fetch_array($cycresult, MYSQLI_ASSOC);
mylog("fetched today's date");
mysqli_free_result($cycresult);
$cyclevalue = $row['cycleday'];
$dayoftheweek = date('D');
$currentminute = date("i");
if ($cyclevalue === 'D' || $dayoftheweek === 'Wed') {
mylog("entered conditional of timecheck");
//check with dday mod times
$nextmodtimefortoday = ddaytimemath();
$ddaymodquery = "SELECT modd FROM ddaymodtimes WHERE timee = '0000-00-00 $nextmodtimefortoday';";
mylog($ddaymodquery);
$ddaymodqueryresult = mysqli_query($db_server, $ddaymodquery);
if ($ddayquery->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$row = mysqli_fetch_array($ddaymodqueryresult, MYSQLI_ASSOC);
mysqli_free_result($ddaymodqueryresult);
$mod = $row['modd'];
echo "<h1 style='text-align: center'> The next mod is: $mod </h1>";
mylog($ddaymodquery);
} else {
$db_server = mysqli_connect("localhost", "root", "root", "schedule");
//check with normal mod times
$THEformattedtime = date('H:i');
$THEFORMATTEDNOW = "0000-00-00 $THEformattedtime:00";
$normalmodquery = "SELECT modd FROM normalmodtimes WHERE timee > '$THEFORMATTEDNOW' LIMIT 1;";
$normalmodqueryresult = mysqli_query($db_server, $normalmodquery);
if ($normalmodquery->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
mylog("THE NORMAL MOD QUERY SHOULD BE: $normalmodquery");
$row = mysqli_fetch_array($normalmodqueryresult, MYSQLI_ASSOC);
mysqli_free_result($normalmodqueryresult);
$mod = $row['modd'];
echo "<h1 style='text-align: center'> The next mod is: $mod </h1>";
$nextmodtimequery = "SELECT timee FROM normalmodtimes WHERE modd = '$mod';";
$nextmodtimequeryresult = mysqli_query($db_server, $nextmodtimequery);
if ($nextmodtimequery->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
mylog("THE NEXT MODTIME QUERY SHOULD BE: $nextmodtimequery");
$row = mysqli_fetch_array($nextmodtimequeryresult, MYSQLI_ASSOC);
mysqli_free_result($nextmodtimequeryresult);
$timee = $row['timee'];
$substroftime = substr($timee, -8);
echo "this is the next mod's time $substroftime";
echo "</br>";
echo " this is today: $today ";
echo "</br>";
echo " this is the next mod today! $today $substroftime";
echo "</br>";
$dateandsubstroftime = $today . $substroftime;
echo "</br>";
$astime = strtotime($dateandsubstroftime);
echo "</br>";
echo $astime;
echo "</br>";
echo date("h:i:s");
echo "</br>";
echo date("h:i:s", $astime);
echo $interval->format("I:S");
$timetillnextmod = $interval; //timee minus current time
echo "<script>
$(function () {
var austDay = new Date();
austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
$('#defaultCountdown').countdown({until: $astime});
$('#year').text(austDay.getFullYear());
});
</script>";
}
}
$b = "</br>";
function ddaytimemath() {
$today = date("Y-m-d");
$currenthour = date('H');
$currentminute = date("i");
mylog( "Current minute is $currentminute ");
$currentminuteroundeddown = $currentminute * .1;
mylog( "current minute times .1 is $currentminuteroundeddown ");
$currentminuteroundeddowntothewhole = ceil($currentminuteroundeddown);
mylog("current minute times .1 and rounded is $currentminuteroundeddowntothewhole ");
$currentminuteroundedtothetenthofanhour = $currentminuteroundeddowntothewhole * 10;
mylog("current minute times .1 and rounded times 10 is $currentminuteroundedtothetenthofanhour ");
if ($currentminuteroundedtothetenthofanhour == 10 || $currentminuteroundedtothetenthofanhour == 30 || $currentminuteroundedtothetenthofanhour == 50) {
//then we're good
mylog("rounding resulted in $currentminuteroundedtothetenthofanhour");
$amorpm = date('A');
$nextmodtimefordday = "$currenthour:$currentminuteroundedtothetenthofanhour:00 $amorpm";
echo "the next mod is at $nextmodtimefordday";
return $nextmodtimefordday;
} else {
$fixednext10mininterval = $currentminuteroundedtothetenthofanhour + 10;
mylog("it needed to be rounded some more... $fixednext10mininterval");
$nextmodtimefordday = "$currenthour:$fixednext10mininterval";
echo "<h2 style='text-align:center'> the next mod is at $nextmodtimefordday </h2>";
return $nextmodtimefordday;
}
}
function umbrellafunction(){
$db_server = mysqli_connect("localhost", "root", "root", "schedule");
$today = date("Y-m-d");
$todayactivequery = "SELECT active FROM days WHERE daate = '$today'";
mylog($todayactivequery);
$todayactiveresult = mysqli_query($db_server, $todayactivequery);
if ($todayactivequery->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$row = mysqli_fetch_array($todayactiveresult, MYSQLI_ASSOC);
mysqli_free_result($todayactiveresult);
$active = $row['active'];
if ($active === 'y') {
display();
} else {
echo "<h2 style='text-align: center'> We appreciate the enthusiasm, but today isn't a school day!</h2>";
}
timecheck();
}
umbrellafunction();
echo "<script type='text/javascript'>
$(function () {
var austDay = new Date();
austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
$('#defaultCountdown').countdown({until: austDay});
$('#year').text(austDay.getFullYear());
});
</script>";
?>
<script type='text/javascript'>
$(function () {
var austDay = new Date();
austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
$('#defaultCountdown').countdown({until: austDay});
$('#year').text(austDay.getFullYear());
});
</script>
</html>