/
index.php
executable file
·252 lines (218 loc) · 6.53 KB
/
index.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
<?php
/*
* index.php
*
* Copyright © 2008 Dylan Enloe <ninina@koneko-hime>
* Copyright © 2009, 2010 Drew Fisher <kakudevel@gmail.com>
* ALL RIGHTS RESERVED
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
function __autoload($class_name) {
require_once $class_name . '.php';
}
$C = new Connection();
$user = new User();
$page = new Webpage("Con Schedule Test", $user);
$defaultStartTime = "08:00:00";
$defaultEndTime = "03:00:00";
/* NOTE: there is no code in Webpage::printDaySchedule
* that visually separates days, so if you put a "day's"
* start and end time as something greater than 24 hours,
* all you'll get is a big list of half-hour increments from
* the day's start to its end, whatever time that may be.
*/
$conTimes[0]['start'] = "2009-12-30 20:00:00";
$conTimes[0]['end'] = "2009-12-31 00:00:00";
$conTimes[1]['start'] = "2009-12-31 09:00:00";
$conTimes[1]['end'] = "2010-01-01 03:00:00";
$conTimes[2]['start'] = "2010-01-01 09:00:00";
$conTimes[2]['end'] = "2010-01-02 02:00:00";
$conTimes[3]['start'] = "2010-01-02 09:00:00";
$conTimes[3]['end'] = "2010-01-03 00:00:00";
$conDayCount = count($conTimes);
// used if _GET['startTime'] or _GET['endTime'] are specified,
// filled with conTimes span otherwise.
$startDate = NULL;
$endDate = NULL;
$date = NULL;
// check for index.php?date=YYYYMMDD[&startTime=HHMM][&endTime=HHMM]
// or index.php?conday=#[&startTime=HHMM][&endTime=HHMM]
if( isset($_GET['conday']) && strlen($_GET['conday']) <= 2) //I doubt we'll ever have more than 99 days of con...
{
$conday = $C->validate_string($_GET['conday']);
if( isset($conTimes[$conday]) )
{
$ex = explode(" ", $conTimes[$conday]['start'] );
$date = $ex[0];
}
else
{
$conday = NULL;
}
}
if( isset($_GET['date']) && strlen($_GET['date']) == 8 && ! isset($conday) )
{
$date = $C->validate_string($_GET['date']);
}
//if either ?conday or ?date were passed, check for ?startTime and ?endTime
if( isset($conday) || isset($_GET['date']) )
{
$GETvar = $_GET['startTime'];
if( isset($GETvar) && strlen($GETvar) == 4 )
{
$startTime = $C->validate_string($GETvar);
$defaultStartTime = $startTime . "00";
}
$GETvar = $_GET['endTime'];
if( isset($GETvar) && strlen($GETvar) == 4 )
{
$endTime = $C->validate_string($GETvar);
$defaultEndTime = $endTime . "00";
}
$startDate = date_create($date ." ". $defaultStartTime);
$endDate = date_create($date ." ". $defaultEndTime);
// if the end time is before or equal to the start time, assume
// they meant the end time was on the following day.
$diff = $endDate->format("U") - $startDate->format("U");
if( $diff <= 0 )
{
$endDate->modify("+1 day");
}
}
/* special check when ?conday is passed, possibly with a ?startTime, in case
* the $conTimes[$conday]['end'] is before the $defaultEndTime.
* we don't want to print out more times than the official con runs.
*
* (NOTE that if a user specifies an ?endTime that goes beyond the conday time,
* we assume the user knows what they're doing and wants to see till, say, 4am
* even if the con only goes till 2am.)
*/
if( isset($conday) && ! isset($_GET['endTime']) )
{
$conEndTime = date_create( $conTimes[$conday]['end'] );
$diff = $conEndTime->format("U") - $endDate->format("U");
if( $diff < 0)
{
$endDate = date_create( $conTimes[$conday]['end'] );
}
}
//fill in the start and end times with conTimes if not specified via url params
if( ! isset($startDate) && ! isset($endDate) )
{
$startDate = date_create( $conTimes[0]['start'] );
$endDate = date_create( $conTimes[$conDayCount-1]['end'] );
}
$schedule = NULL;
// events query
$q = "
SELECT
e_eventID, e_eventName, r_roomName, e_dateStart,
e_dateEnd, e_eventName, e_eventDesc, e_color, e_panelist
FROM
events, rooms
WHERE
e_roomID = r_roomID
AND
e_dateStart
BETWEEN
'". $startDate->format("Y-m-d H:i:s") ."'
AND
'". $endDate->format("Y-m-d H:i:s") ."'
ORDER BY
r_roomID ASC
;";
$C->query( $q );
$eventCount = $C->result_size();
if( $eventCount < 1 )
{
if( isset($_GET['date']) )
{
$page->printError("No events scheduled for ". $startDate->format("F d, Y"));
echo "<center>";
$page->addURL("index.php","Return to non-filtered event schedule.");
echo "</center>";
exit(0);
}
else {
$page->printError("No events scheduled.");
}
echo "<center>";
if( ! $user->is_Admin() )
{
echo "Please check back later. We'll be posting events soon =^.^=";
}
else
{
echo "Oi, you: ";
$page->addURL("add.php","add an event");
echo "!";
}
echo "</center>";
exit(0);
}
// create the events and roomNames arrays
$roomNames = array();
for( $i=0; $i<$eventCount; $i++ ) {
$row = $C->fetch_assoc();
$events[$i] = new Event(
$row['e_eventID'], $row['e_eventName'], $row['r_roomName'],
$row['e_dateStart'],$row['e_dateEnd'], $row['e_eventDesc'],
$row['e_panelist'], $row['e_color']
);
if( ! in_array($row['r_roomName'], $roomNames))
{
$roomNames[$i] = $row['r_roomName'];
}
}
unset($C); // close the connection
// set up the schedule var
foreach( $roomNames as $roomName )
{
foreach( $events as $event )
{
if( $event->getRoomName() == $roomName )
{
$fmt = $event->getStartDate()->format("Y-m-d H:i:s");
$schedule[$fmt][$roomName] = $event;
}
}
}
// print the schedule(s)
echo "<center>";
if( isset($conday) || isset($_GET['date']) )
{
echo "<hr><hr>";
$page->printError("Schedule for " . $startDate->format("F d, Y"));
echo "<hr><hr><br>";
$page->printDaySchedule($schedule, $roomNames, $startDate, $endDate);
}
else
{
for( $i = 0; $i < $conDayCount; $i++ )
{
$dayStarts = date_create( $conTimes[$i]['start'] );
$dayEnds = date_create( $conTimes[$i]['end'] );
echo "<hr><hr>";
echo "<h2>";
echo "Schedule for " . $dayStarts->format("F d, Y");
echo "</h2>";
echo "<hr><hr><br>";
$page->printDaySchedule($schedule, $roomNames, $dayStarts, $dayEnds);
}
}
echo "</center>";
?>