· 10 years ago · Mar 20, 2016, 09:18 AM
1<?php
2/*Written by cached on August 19, 2006
3 *Copyleft 2006
4 *All wrongs reserved
5 */
6############CHANGE THESE VALUES#########################
7$name = "Cached"; #This just changes the title of pages
8$timezone = -5; #Timezone. This is currently set to GMT -5
9$dateorder = 1;#sets order of date 1=mm/dd/yyyy 2=dd/mm/yyyy
10$classes = array('European Literature H', 'AP Statistics', 'Math IV AP', 'AP Physics C', 'AP Computer Science', 'Spanish H'); #A comma seperated list of classes
11$assigntypes = array('Normal', 'TEST!','QUIZ!','Paper!','Project!','Urgent!','Extra Credit!'); #possible assignment types. first element is always unbolded
12$assigncolors = array('#000000', '#FF0000', '#FF3300', '#DDDD00', '#0000FF', '#00FF00', '#AAAAAA'); #corresponding colors. works with either RGB representations or HTML allowed colors
13$testtypes = array('1','2');
14$dbuser = "cached_root"; #User with access to database
15$dbpass = "SOMEPASS"; #Some password for your database
16$dbname = "cached_school"; #name of database to put table in
17############STOP CHANGING VALUES#######################
18?>
19<html>
20<head>
21<title>
22 <? print "$name" ?>’s Homework
23</title>
24</head>
25<body><iframe name="dummy" width="0" height="0" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
26<script language="javascript" type="text/javascript">
27<!--
28function go(hid)
29{
30 destination = "homework.php?pagenum=99&hid=" + hid;
31 frames['dummy'].location.href = destination;
32}
33
34// -->
35</SCRIPT>
36</HEAD>
37<?php
38$showoptions = "Your options are: <ul><li><a href=\"homework.php?pagenum=0\">Home Page</a><li><a href=\"homework.php?pagenum=1\">Add Exam/Homework</a><li><a href=\"homework.php?pagenum=2\">Modify Exam/Homework</a><li><a href=\"homework.php?pagenum=3\">Show calendar</a><li><a href=\"homework.php?pagenum=10\">Check upcoming exams</a></li></ul>";
39if (count($assigntypes) != count($assigncolors))
40{
41 die ("You must have the same amount of types and corresponding colors!");
42}
43$classselect = "";
44for ($i = 0; $i<count($classes); $i++)
45{
46 $classselect .= "<option value=\"" . $classes[$i] . "\">" . $classes[$i] . "</option>";
47}
48$classselect .= "<option value=\"other\">Other</option>";
49$assignselect = "";
50for ($i = 0; $i<count($assigntypes); $i++)
51{
52 $assignselect .= "<option value=\"$i\">" . $assigntypes[$i] . "</option>";
53}
54$linkID = mysql_connect("localhost", $dbuser, $dbpass);
55$dbid = mysql_select_db($dbname, $linkID);
56#check if table exists
57$result = mysql_query("SHOW TABLES FROM $dbname LIKE 'homework'");
58if (mysql_num_rows($result)==0)
59{
60 $query = "CREATE TABLE `homework` (`id` mediumint(8) unsigned NOT NULL auto_increment, `subject` varchar(32) character set latin1 collate latin1_bin NOT NULL, `assignment` blob NOT NULL, `assignedd` tinyint(3) unsigned NOT NULL, `assignedm` tinyint(3) unsigned NOT NULL, `assignedy` smallint(5) unsigned NOT NULL, `dued` tinyint(3) unsigned NOT NULL, `duem` tinyint(3) unsigned NOT NULL, `duey` smallint(5) unsigned NOT NULL, `type` tinyint(3) unsigned NOT NULL, `isdone` tinyint(4) NOT NULL default '0', PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8";
61 $result = @mysql_query($query);
62}
63$tdif = $timezone * 3600;
64if (!isset($_GET['pagenum']) or $_GET['pagenum'] == 0)
65{
66 $tomorrow = mktime(date("H"), date("i"), date("s")-date("Z")+$tdif, date("m") , date("d")+1, date("Y"));
67 $td = strftime("%d", $tomorrow);
68 $tm = strftime("%m", $tomorrow);
69 $ty = strftime("%Y", $tomorrow);
70 $result = mysql_query("SELECT * FROM homework WHERE dued = '$td' and duem = '$tm' and duey = '$ty'") or die(mysql_error());
71 if (mysql_num_rows($result) == 0)
72 {
73 print "No homework added for tomorrow";
74 }
75 else
76 {
77 print "<b>Homework due tomorrow:</b><table border=0><tr><th align=\"center\">ID</th><th align=\"center\">Subject</th><th align=\"center\">Assignment</th><th align=\"center\">Type</th><th align=\"center\">Due</th><th align=\"center\">Assigned</th><th align=\"center\">Completed</th>";
78 while ($row = mysql_fetch_assoc($result))
79 {
80 if ($dateorder == 1)
81 {
82 $showdue = $row[duem] . "/" . $row[dued] . "/" . $row[duey];
83 $showassign = $row[assignedm] . "/" . $row[assignedd] . "/" . $row[assignedy];
84 $writeassign = "<select name = \"amonth\">$months</select>/<select name=\"aday\">$days</select>/<select name=\"ayear\">$years</select> (MM/DD/YY)";
85 $writedue = "<select name = \"dmonth\">$dmonths</select>/<select name=\"dday\">$ddays</select>/<select name=\"dyear\">$dyears</select> (MM/DD/YY)";
86 }
87 else
88 {
89 $showdue = $row[dued] . "/" . $row[duem] . "/" . $row[duey];
90 $showassign = $row[assignedd] . "/" . $row[assignedm] . "/" . $row[assignedy];
91 $writeassign = "<select name=\"aday\">$days</select>/<select name=\"amonth\">$months</select>/<select name=\"ayear\">$years</select> (DD/MM/YY)";
92 $writedue = "<select name=\"dday\">$ddays</select>/<select name=\"dmonth\">$dmonths</select>/<select name=\"dyear\">$dyears</select> (DD/MM/YY)";
93 }
94 print "<tr><td align=\"center\"><a href=\"homework.php?pagenum=5&id=" . $row[id] . "\">" . $row[id] . "</a></td><td align=\"center\"><i>" . $row[subject] . "</i></td><td align=\"center\" width=\"500\"> " . $row[assignment] . " </td><td align=\"center\">";
95 $bold = "<b>";;
96 $unbold = "</b>";;
97 if ($row[type] == 0)
98 {
99 $bold = "";
100 $unbold = "";
101 }
102 print "<font color=\"" . $assigncolors[$row[type]] . "\">$bold" . $assigntypes[$row[type]] . "$unbold</font>";
103 if ($row[isdone])
104 {
105 $checked = " checked";
106 }
107 else
108 {
109 $checked = "";
110 }
111 print "</td><td align=\"center\">" . $showdue . "</td><td align=\"center\">" . $showassign . "</td><td align=\"center\"><input type=\"checkbox\"$checked onClick=\"go(" . $row[id] . ")\"> </td></tr>";
112 }
113 }
114 print "</table><p>$showoptions";
115}
116elseif ($_GET['pagenum'] == 1) #write homework
117{
118 $now = mktime(date("H"), date("i"), date("s")-date("Z")+$tdif, date("m"), date("d"), date("Y"));
119 $nd = strftime("%d", $now);
120 $nm = strftime("%m", $now);
121 $ny = strftime("%Y", $now);
122 $tomorrow = mktime(date("H"), date("i"), date("s")-date("Z")+$tdif, date("m") , date("d")+1, date("Y"));
123 $td = strftime("%d", $tomorrow);
124 $tm = strftime("%m", $tomorrow);
125 $ty = strftime("%Y", $tomorrow);
126 $days = "<option value=\"$nd\">$nd</option>";
127 $ddays = "<option value=\"$td\">$td</option>";
128 for ($i = 1; $i<=31; $i++)
129 {
130 if ($i < 10)
131 {
132 $si = 0 . $i;
133 }
134 else
135 {
136 $si = $i;
137 }
138 $days .= "<option value=\"$si\">$si</option>";
139 $ddays .= "<option value=\"$si\">$si</option>";
140 }
141 $months = "<option value=\"$nm\">$nm</option>";
142 $dmonths = "<option value=\"$tm\">$tm</option>";
143 for ($i = 1; $i<=12; $i++)
144 {
145 if ($i < 10)
146 {
147 $si = 0 . $i;
148 }
149 else
150 {
151 $si = $i;
152 }
153 $months .= "<option value=\"$si\">$si</option>";
154 $dmonths .= "<option value=\"$si\">$si</option>";
155 }
156 $years = "<option value=\"$ny\">0" . ($ny % 1000) . "</option>";
157 $dyears = "<option value=\"$ty\">0" . ($ty % 1000) . "</option>";
158 for ($i = 6; $i<=7; $i++)
159 {
160 $years .= "<option value=\"200$i\">0$i</option>";
161 $dyears .= "<option value=\"200$i\">0$i</option>";
162 }
163 if ($dateorder == 1)
164 {
165 $showdue = $row[duem] . "/" . $row[dued] . "/" . $row[duey];
166 $showassign = $row[assignedm] . "/" . $row[assignedd] . "/" . $row[assignedy];
167 $writeassign = "<select name = \"amonth\">$months</select>/<select name=\"aday\">$days</select>/<select name=\"ayear\">$years</select> (MM/DD/YY)";
168 $writedue = "<select name = \"dmonth\">$dmonths</select>/<select name=\"dday\">$ddays</select>/<select name=\"dyear\">$dyears</select> (MM/DD/YY)";
169 }
170 else
171 {
172 $showdue = $row[dued] . "/" . $row[duem] . "/" . $row[duey];
173 $showassign = $row[assignedd] . "/" . $row[assignedm] . "/" . $row[assignedy];
174 $writeassign = "<select name=\"aday\">$days</select>/<select name=\"amonth\">$months</select>/<select name=\"ayear\">$years</select> (DD/MM/YY)";
175 $writedue = "<select name=\"dday\">$ddays</select>/<select name=\"dmonth\">$dmonths</select>/<select name=\"dyear\">$dyears</select> (DD/MM/YY)";
176 }
177 print "<h3>Add Assignment:</h3><p><br><form action=\"homework.php?pagenum=4\" method=\"POST\"><table border=\"0\"><tr><td>Class Name</td><td><select name=classname><option value=\"\">Select a Class</option>$classselect</select> If other please type subject here: <input type=\"text\" name=\"osubject\"></td></tr><tr><td>Assignment</td><td><textarea name=\"assignment\" cols=\"60\" rows=\"7\"></textarea></td></tr><tr><td>Assigned On:</td><td>$writeassign</td></tr><tr><td>Due on: </td><td>$writedue</td></tr><tr><td>Type: </td><td><select name=\"type\">$assignselect</select></td></tr><tr><td> </td><td><input type=\"submit\" name=\"submit\" value=\"Add Assignment\"></td></tr></table></form><p>$showoptions";
178}
179elseif ($_GET['pagenum'] == 2)#modify exam/homework
180{
181 print "<h2>Modify Exam/Homework</h2><br>Click on the ID of the assignment you wish to change<p>";
182 if (!isset($_GET['rowid']))
183 {
184 $rowid = 0;
185 }
186 else
187 {
188 $rowid = $_GET['rowid'];
189 if ($rowid < 0)
190 {
191 $rowid = 0;
192 }
193 }
194 print "Recent assignments $rowid - " . ($rowid+30) . ". <a href=\"homework.php?pagenum=2&rowid=" . ($rowid-30) . "\">Newer</a> · <a href=\"homework.php?pagenum=2&rowid=" . ($rowid+30) . "\">Older</a><br>";
195 print "<b>Homework:</b><table border=0><tr><th align=\"center\">ID</th><th align=\"center\">Subject</th><th align=\"center\">Assignment</th><th align=\"center\">Type</th><th align=\"center\">Due</th><th align=\"center\">Assigned</th><th align=\"center\">Completed</th>";
196 $result = mysql_query("SELECT * FROM homework ORDER BY id DESC LIMIT $rowid, 30") or die(mysql_error());
197 while ($row = mysql_fetch_assoc($result))
198 {
199 if ($dateorder == 1)
200 {
201 $showdue = $row[duem] . "/" . $row[dued] . "/" . $row[duey];
202 $showassign = $row[assignedm] . "/" . $row[assignedd] . "/" . $row[assignedy];
203 $writeassign = "<select name = \"amonth\">$months</select>/<select name=\"aday\">$days</select>/<select name=\"ayear\">$years</select> (MM/DD/YY)";
204 $writedue = "<select name = \"dmonth\">$dmonths</select>/<select name=\"dday\">$ddays</select>/<select name=\"dyear\">$dyears</select> (MM/DD/YY)";
205 }
206 else
207 {
208 $showdue = $row[dued] . "/" . $row[duem] . "/" . $row[duey];
209 $showassign = $row[assignedd] . "/" . $row[assignedm] . "/" . $row[assignedy];
210 $writeassign = "<select name=\"aday\">$days</select>/<select name=\"amonth\">$months</select>/<select name=\"ayear\">$years</select> (DD/MM/YY)";
211 $writedue = "<select name=\"dday\">$ddays</select>/<select name=\"dmonth\">$dmonths</select>/<select name=\"dyear\">$dyears</select> (DD/MM/YY)";
212 }
213 print "<tr><td align=\"center\"><a href=\"homework.php?pagenum=5&id=" . $row[id] . "\">" . $row[id] . "</a></td><td align=\"center\"><i>" . $row[subject] . "</i></td><td align=\"center\" width=\"500\"> " . $row[assignment] . " </td><td align=\"center\">";
214 $bold = "<b>";
215 $unbold = "</b>";
216 if ($row[type] == 0)
217 {
218 $bold = "";
219 $unbold = "";
220 }
221 print "<font color=\"" . $assigncolors[$row[type]] . "\">$bold" . $assigntypes[$row[type]] . "$unbold</font>";
222 if ($row[isdone])
223 {
224 $checked = " checked";
225 }
226 else
227 {
228 $checked = "";
229 }
230 print "</td><td align=\"center\">" . $showdue . "</td><td align=\"center\">" . $showassign . "</td><td align=\"center\"><input type=\"checkbox\"$checked onClick=\"go(" . $row[id] . ")\"></td></tr>";
231 }
232 print "</table><p>$showoptions";
233}
234elseif ($_GET['pagenum'] == 3)#calendar
235{
236 $months = array("","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
237 $dim = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
238 $now = mktime(date("H"), date("i"), date("s")-date("Z")+$tdif, date("m") , date("d"), date("Y"));
239 if (!isset($_GET['month']) or $_GET['month'] < 1 or $_GET['month'] > 12)
240 {
241 $month = strftime("%m", $now)+0;
242 $year = strftime("%Y", $now)+0;
243 }
244 else
245 {
246 $month = $_GET['month'];
247 $year = $_GET['year'];
248 }
249 if (($year % 4) == 0 && (($year % 400 == 0) or ($year % 100 != 0))) #leap year check
250 {
251 $dim[2] = 29;
252 }
253 $monthstart = mktime(date("H"), date("i"), date("s")-date("Z")+$tdif,$month,1,$year);
254 $monthstart = (date("N", $monthstart)%7)+1;
255 print "<h2>Calendar</h2><p><table border=1><tr><th colspan=7><center>" . $months[$month] . " $year</center></th></tr><tr><td align=\"center\">S</td><td align=\"center\">M</td><td align=\"center\">T</td><td align=\"center\">W</td><td align=\"center\">T</td><td align=\"center\">F</td><td align=\"center\">S</td></tr>";
256 $preset = "";
257 #$queries = "";
258 for ($i=1;$i<$monthstart;$i++)
259 {
260 $preset .= "<td align=\"center\"> </td>";
261 }
262 if ($month < 10)
263 {
264 $si = 0 . $month;
265 }
266 else
267 {
268 $si = $month;
269 }
270 for ($i=1;$i<=$dim[$month];$i++)
271 {
272 if (($i+$monthstart-1)%7 == 1)
273 {
274 print "<tr>";
275 }
276
277 if ($i==1)
278 {
279 print $preset;
280 }
281 $count = mysql_query("SELECT id FROM homework WHERE duey='$year' and duem='$si' and dued='$i'");
282 #$queries .= "SELECT id FROM homework WHERE duey='$year' and duem='$si' and duem='$i'<br>";
283 $count = mysql_num_rows($count);
284 print "<td align=\"center\">";
285 if ($count == 0)
286 {
287 print " $i ";
288 }
289 else
290 {
291 print "<a href=\"homework.php?pagenum=6&month=$si&year=$year&day=$i\">$i ($count)</a>";
292 }
293 print "</td>";
294 if (($i+$monthstart-1)%7 == 0 or $i == $dim[$month])
295 {
296 print "</tr>";
297 }
298 }
299 $nmonth = $month+1;
300 $pmonth = $month-1;
301 $pyear = $year;
302 $nyear = $year;
303 if ($month==12)
304 {
305 $nmonth = 1;
306 $nyear = $year+1;
307 }
308 if ($month==1)
309 {
310 $pmonth = 12;
311 $pyear = $year - 1;
312 }
313 print "</table><br><a href=\"homework.php?pagenum=3&year=$pyear&month=$pmonth\">Previous</a> · <a href=\"homework.php?pagenum=3&year=$nyear&month=$nmonth\">Next</a><p>$showoptions";
314}
315elseif ($_GET['pagenum'] == 4)#place homework
316{
317 if (!isset($_POST['classname']))
318 {
319 die("You were redirected here from the wrong place!");
320 }
321 #check if homework is good
322 $subject = $_POST['classname'];
323 $assignment = htmlspecialchars($_POST['assignment']);
324 if ($subject == "other" or strlen($subject) == 0)
325 {
326 $subject = $_POST['osubject'];
327
328 if (strlen($subject) == 0)
329 {
330 die("No subject specified!<p>$showoptions");
331 }
332 if (strlen($assignment) == 0)
333 {
334 die("No assignment written!<p>$showoptions");
335 }
336 }
337 $subject = htmlspecialchars($subject);
338 $duem = $_POST['dmonth'];
339 $dued = $_POST['dday'];
340 $duey = $_POST['dyear'];
341 $assignedm = $_POST['amonth'];
342 $assignedd = $_POST['aday'];
343 $assignedy = $_POST['ayear'];
344 $type = $_POST['type'];
345 $dim = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
346 if (($duey % 4) == 0 && (($duey % 400 == 0) or ($duey % 100 != 0))) #leap year check
347 {
348 $dim[2] = 29;
349 }
350 if ($dued > $dim[$duem+0])
351 {
352 die("Invalid day in month ($dued>" . $dim[$duem+0] . ")<p>$showoptions");
353 }
354 $result = mysql_query("INSERT INTO homework (subject, assignment, assignedd, assignedm, assignedy, dued, duem, duey, type) VALUES ('$subject', '$assignment', '$assignedd', '$assignedm', '$assignedy', '$dued', '$duem', '$duey', '$type')") or die(mysql_error());
355 print "Homework added successfully!<p>$showoptions";
356}
357elseif ($_GET['pagenum'] == 5)
358{
359 if (!isset($_GET['id']))
360 {
361 die("You have been redirected here from the wrong place<p>$showoptions");
362 }
363 $id = $_GET['id'];
364 $result = mysql_query("SELECT * FROM homework WHERE id='$id' LIMIT 1");
365 $row = mysql_fetch_assoc($result);
366 $days = "<option value=\"" . $row[assignedd] . "\">" . $row[assignedd] . "</option>";
367 $ddays = "<option value=\"" . $row[dued] . "\">" . $row[dued] . "</option>";
368 for ($i = 1; $i<=31; $i++)
369 {
370 if ($i < 10)
371 {
372 $si = 0 . $i;
373 }
374 else
375 {
376 $si = $i;
377 }
378 $days .= "<option value=\"$si\">$si</option>";
379 $ddays .= "<option value=\"$si\">$si</option>";
380 }
381 $months = "<option value=\"" . $row[assignedm] . "\">" . $row[assignedm] . "</option>";
382 $dmonths = "<option value=\"" . $row[duem] . "\">" . $row[duem] . "</option>";
383 for ($i = 1; $i<=12; $i++)
384 {
385 if ($i < 10)
386 {
387 $si = 0 . $i;
388 }
389 else
390 {
391 $si = $i;
392 }
393 $months .= "<option value=\"$si\">$si</option>";
394 $dmonths .= "<option value=\"$si\">$si</option>";
395 }
396 $years = "<option value=\"" . $row[assignedy] . "\">0" . ($row[assignedy] % 1000) . "</option>";
397 $dyears = "<option value=\"" . $row[duey] . "\">0" . ($row[duey] % 1000) . "</option>";
398 for ($i = 6; $i<=7; $i++)
399 {
400 $years .= "<option value=\"200$i\">0$i</option>";
401 $dyears .= "<option value=\"200$i\">0$i</option>";
402 }
403 $l = $assigntypes[$row[type]];
404 if ($row[isdone] == 1)
405 {
406 $checked = " checked";
407 }
408 else
409 {
410 $checked = "";
411 }
412 if ($dateorder == 1)
413 {
414 $showdue = $row[duem] . "/" . $row[dued] . "/" . $row[duey];
415 $showassign = $row[assignedm] . "/" . $row[assignedd] . "/" . $row[assignedy];
416 $writeassign = "<select name = \"amonth\">$months</select>/<select name=\"aday\">$days</select>/<select name=\"ayear\">$years</select> (MM/DD/YY)";
417 $writedue = "<select name = \"dmonth\">$dmonths</select>/<select name=\"dday\">$ddays</select>/<select name=\"dyear\">$dyears</select> (MM/DD/YY)";
418 }
419 else
420 {
421 $showdue = $row[dued] . "/" . $row[duem] . "/" . $row[duey];
422 $showassign = $row[assignedd] . "/" . $row[assignedm] . "/" . $row[assignedy];
423 $writeassign = "<select name=\"aday\">$days</select>/<select name=\"amonth\">$months</select>/<select name=\"ayear\">$years</select> (DD/MM/YY)";
424 $writedue = "<select name=\"dday\">$ddays</select>/<select name=\"dmonth\">$dmonths</select>/<select name=\"dyear\">$dyears</select> (DD/MM/YY)";
425 }
426 print "<h3>Modify Assignment:</h3><p><br><form action=\"homework.php?pagenum=7\" method=\"POST\"><input type=\"hidden\" name=\"id\" value=\"$id\"><table border=\"0\"><tr><td>Class Name</td><td><select name=classname><option value=\"" . $row[subject] . "\">" . $row[subject] . "</option>$classselect</select> If other please type subject here: <input type=\"text\" name=\"osubject\"></td></tr><tr><td>Assignment</td><td><textarea name=\"assignment\" cols=\"60\" rows=\"7\">" . $row[assignment] . "</textarea></td></tr><tr><td>Assigned On:</td><td>$writeassign</td></tr><tr><td>Due on: </td><td>$writedue</td></tr><tr><td>Type: </td><td><select name=\"type\"><option value=\"" . $row[type] . "\">$l</option>$assignselect</select></td></tr><tr><td>Completed</td><td><input type=\"checkbox\" name=\"isdone\"$checked></td></tr><tr><td> </td><td><input type=\"submit\" name=\"submit\" value=\"Modify Assignment\"></td></tr></table></form><br><a href=\"homework.php?pagenum=8&id=$id\">Delete this assignment</a><p>$showoptions";
427}
428elseif ($_GET['pagenum'] == 6)#Viewing a day
429{
430 $td = $_GET[day];
431 $tm = $_GET[month];
432 $ty = $_GET[year];
433 $result = mysql_query("SELECT * FROM homework WHERE dued = '$td' and duem = '$tm' and duey = '$ty'") or die(mysql_error());
434 if (mysql_num_rows($result) == 0)
435 {
436 print "No homework added for $tm/$td/$ty";
437 }
438 else
439 {
440 print "<b>Homework due on $tm/$td/$ty:</b><table border=0><tr><th align=\"center\">ID</th><th align=\"center\">Subject</th><th align=\"center\">Assignment</th><th align=\"center\">Type</th><th align=\"center\">Due</th><th align=\"center\">Assigned</th><th align=\"center\">Completed</th>";
441 while ($row = mysql_fetch_assoc($result))
442 {
443 print "<tr><td align=\"center\"><a href=\"homework.php?pagenum=5&id=" . $row[id] . "\">" . $row[id] . "</a></td><td align=\"center\"><i>" . $row[subject] . "</i></td><td align=\"center\" width=\"500\"> " . $row[assignment] . " </td><td align=\"center\">";
444 $bold = "<b>";
445 $unbold = "</b>";
446 if ($row[type] == 0)
447 {
448 $bold = "";
449 $unbold = "";
450 }
451 print "<font color=\"" . $assigncolors[$row[type]] . "\">$bold" . $assigntypes[$row[type]] . "$unbold</font>";
452 if ($row[isdone])
453 {
454 $checked = " checked";
455 }
456 else
457 {
458 $checked = "";
459 }
460 print "</td><td align=\"center\">" . $showdue . "</td><td align=\"center\">" . $showassign . "</td><td align=\"center\"><input type=\"checkbox\"$checked onClick=\"go(" . $row[id] . ")\"> </td></tr>";
461 }
462 }
463 print "</table><p>$showoptions";
464}
465elseif ($_GET['pagenum'] == 7) #change homework db
466{
467 if (!isset($_POST['classname']))
468 {
469 die("You were redirected here from the wrong place!");
470 }
471 #check if homework is good
472 $subject = $_POST['classname'];
473 $assignment = htmlspecialchars($_POST['assignment']);
474 if ($subject == "other" or strlen($subject) == 0)
475 {
476 $subject = $_POST['osubject'];
477
478 if (strlen($subject) == 0)
479 {
480 die("No subject specified!<p>$showoptions");
481 }
482 if (strlen($assignment) == 0)
483 {
484 die("No assignment written!<p>$showoptions");
485 }
486 }
487 $subject = htmlspecialchars($subject);
488 $duem = $_POST['dmonth'];
489 $dued = $_POST['dday'];
490 $duey = $_POST['dyear'];
491 $assignedm = $_POST['amonth'];
492 $assignedd = $_POST['aday'];
493 $assignedy = $_POST['ayear'];
494 $type = $_POST['type'];
495 $isdone = $_POST['isdone'];
496 if ($isdone == "on")
497 {
498 $isdone = 1;
499 }
500 else
501 {
502 $isdone = 0;
503 }
504 $id = $_POST['id'];
505 $dim = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
506 if (($duey % 4) == 0 && (($duey % 400 == 0) or ($duey % 100 != 0))) #leap year check
507 {
508 $dim[2] = 29;
509 }
510 if ($dued > $dim[$duem+0])
511 {
512 die("Invalid day in month ($dued>" . $dim[$duem+0] . ")<p>$showoptions");
513 }
514 $result = mysql_query("UPDATE homework SET subject='$subject', assignment='$assignment', duem = '$duem', dued = '$dued', duey = '$duey', assignedm = '$assignedm', assignedd = '$assignedd', assignedy = '$assignedy', type='$type', isdone='$isdone' WHERE id='$id'") or die(mysql_error());
515 print "Homework modified successfully!<p>$showoptions";
516}
517elseif ($_GET['pagenum'] == 8) #delete prompt
518{
519 if (!isset($_GET['id']))
520 {
521 die("You have been redirected here from the wrong place<p>$showoptions");
522 }
523 $id = $_GET['id'];
524 print "Are you sure you wish to delete homework #$id?<br><a href=\"homework.php?pagenum=9&id=$id\">Yes</a> · <a href=\"homework.php\">No</a><p>$showoptions";
525}
526elseif ($_GET['pagenum'] == 9) #final delete
527{
528 if (!isset($_GET['id']))
529 {
530 die("You have been redirected here from the wrong place<p>$showoptions");
531 }
532 $id = $_GET['id'];
533 $result = mysql_query("DELETE FROM homework WHERE id='$id'") or die(mysql_error());
534 print "Homework id #$id deleted successfully!<p>$showoptions";
535}
536elseif ($_GET['pagenum'] == 10) #upcoming tests
537{
538 $testsql = "(";
539 for ($i = 0; $i<count($testtypes); $i++)
540 {
541 if ($i > 0)
542 {
543 $testsql .= " or ";
544 }
545 $testsql .= "type = '" . $testtypes[$i] . "'";
546 }
547 $testsql .= ")";
548 $tomorrow = mktime(date("H"), date("i"), date("s")-date("Z")+$tdif, date("m") , date("d"), date("Y"));
549 $td = strftime("%d", $tomorrow);
550 $tm = strftime("%m", $tomorrow);
551 $ty = strftime("%Y", $tomorrow);
552 $q1 = "SELECT * FROM homework WHERE $testsql and duem > '$tm' OR duey > '$ty' ORDER BY duey,duem,dued DESC LIMIT 10";
553 $q2 = "SELECT * FROM homework WHERE $testsql and dued >'$td' AND duem = '$tm' AND duey = '$ty' ORDER BY dued DESC";
554
555 $result = mysql_query($q1) or die(mysql_error());
556 $result2 = mysql_query($q2) or die(mysql_error());
557 $results = array($result, $result2);
558 if (mysql_num_rows($result) == 0 and mysql_num_rows($result2) == 0)
559 {
560 #print "$q1<br>$q2<br>";
561 die("No upcoming tests found<p>$showoptions");
562 }
563 print "<b>Upcoming Tests/Quizzes:</b><table border=0><tr><th align=\"center\">ID</th><th align=\"center\">Subject</th><th align=\"center\">Assignment</th><th align=\"center\">Type</th><th align=\"center\">Date</th><th align=\"center\">Assigned</th><th align=\"center\">Completed</th>";
564 for ($i=0;$i<2;$i++)
565 {
566 while ($row = mysql_fetch_assoc($results[$i]))
567 {
568 if ($dateorder == 1)
569 {
570 $showdue = $row[duem] . "/" . $row[dued] . "/" . $row[duey];
571 $showassign = $row[assignedm] . "/" . $row[assignedd] . "/" . $row[assignedy];
572 $writeassign = "<select name = \"amonth\">$months</select>/<select name=\"aday\">$days</select>/<select name=\"ayear\">$years</select> (MM/DD/YY)";
573 $writedue = "<select name = \"dmonth\">$dmonths</select>/<select name=\"dday\">$ddays</select>/<select name=\"dyear\">$dyears</select> (MM/DD/YY)";
574 }
575 else
576 {
577 $showdue = $row[dued] . "/" . $row[duem] . "/" . $row[duey];
578 $showassign = $row[assignedd] . "/" . $row[assignedm] . "/" . $row[assignedy];
579 $writeassign = "<select name=\"aday\">$days</select>/<select name=\"amonth\">$months</select>/<select name=\"ayear\">$years</select> (DD/MM/YY)";
580 $writedue = "<select name=\"dday\">$ddays</select>/<select name=\"dmonth\">$dmonths</select>/<select name=\"dyear\">$dyears</select> (DD/MM/YY)";
581 }
582 print "<tr><td align=\"center\"><a href=\"homework.php?pagenum=5&id=" . $row[id] . "\">" . $row[id] . "</a></td><td align=\"center\"><i>" . $row[subject] . "</i></td><td align=\"center\" width=\"500\"> " . $row[assignment] . " </td><td align=\"center\">";
583 $bold = "<b>";;
584 $unbold = "</b>";;
585 if ($row[type] == 0)
586 {
587 $bold = "";
588 $unbold = "";
589 }
590 print "<font color=\"" . $assigncolors[$row[type]] . "\">$bold" . $assigntypes[$row[type]] . "$unbold</font>";
591 if ($row[isdone])
592 {
593 $checked = " checked";
594 }
595 else
596 {
597 $checked = "";
598 }
599 print "</td><td align=\"center\"><b>" . $showdue . "</b></td><td align=\"center\">" . $showassign . "</td><td align=\"center\"><input type=\"checkbox\"$checked onClick=\"go(" . $row[id] . ")\"> </td></tr>";
600 }
601 }
602 print "</table><p>$showoptions";
603}
604elseif ($_GET['pagenum'] == 99)
605{
606 $hid = $_GET['hid'];
607 $a = mysql_query("SELECT isdone FROM homework WHERE id='$hid' LIMIT 1");
608 $a = mysql_fetch_assoc($a);
609 $b = 1 - $a[isdone];
610 $query = "UPDATE homework SET isdone = '$b' WHERE id='$hid'";
611 $a = mysql_query($query);
612}
613?>
614</body></html>