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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
<?php
/**
* Bayonet Content Management System
* Copyright (C) 2008 Joseph Hunkeler & Evan O'Connell
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/**
* Note to anyone feeling the need to edit this file...
* You MUST declare $db as global inside your functions in order access MySQL from here.
*/
/**
* SelectDate($date)
* Function for outputing an html form for selecting a month day and year
* @param date - formatted date string yyyy-mm-dd (optional)
*/
function SelectDate($date = NULL){
//function for adding to the db in sql 'datetime' format
//$date = date("Y-m-d h:i:s", mktime(8, 30, 0, 10, 26, 2009));
//$date = "2009-11-2";
//echo $date."<br />";
//function for parsing our date format into an array
//echo "<pre>";
$date_arr = date_parse($date); //returns an associative array $array['year']
//print_r($date_arr);
//echo "</pre>";
//echo $date_arr['year']." ".$date_arr['month']." ".$date_arr['day']."<br />";;
//List Months
echo '<select name="month">';
for($m = 1;$m <= 12; $m++){
$month = date("F", mktime(0, 0, 0, $m));
if($date_arr['month'] == $m)
echo "<option value='$m' selected=\"selected\">$month</option>";
else
echo "<option value='$m'>$month</option>";
}
echo "</select>";
//List Days
echo '<select name="day">';
for($d = 1;$d <= 31; $d++){
if($date_arr['day'] == $d)
echo "<option value='$d' selected=\"selected\">$d</option>";
else
echo "<option value='$d'>$d</option>";
}
echo "</select>";
//List Years [CurYear, CurYear+5]
echo '<select name="year">';
$y = date('Y', time());
$max = $y+5;
for(;$y<$max; $y++){
if($date_arr['year'] == $y)
echo "<option value='$y' selected=\"selected\">$y</option>";
else
echo "<option value='$y'>$y</option>";
}
echo "</select>";
}
function ListEvents($date){
global $db;
?>
<table width="100%"><tr><td>
<h3>Events for: <?php echo date_format(date_create($date),'F jS, Y'); ?></h3>
</td><td align="right">
<a href="?op=calendar&create=true&date=<?php echo $date; ?>"><img src="images/add.png" /> Add New Event</a>
</td></tr></table>
<?php
echo "<table width=\"100%\">";
$result = $db->Query("SELECT * FROM bayonet_events WHERE `date` = '$date' ORDER BY `time`");
$row = $db->Fetch($result);
foreach($row as $event)
{
$tmp = true;
$datetime = date_create($date.' '.$event['time']);
$time = date_format($datetime, 'g:ia'); //gets time in hour:minutes am|pm
?>
<tr>
<td><strong><?php echo $time." - ".$event['title']; ?></strong></td>
<td><span style="border:1px solid black;background-color:<?php echo $event['color'];?>;"> </span></td>
<td>
<a href="?op=calendar&month=<?php echo $_GET['month']; ?>&year=<?php echo $_GET['year']; ?>&edit=<?php echo $event['event_id'];?>">Edit</a>
|
<a href="?op=calendar&delete=<?php echo $event['event_id']; ?>">Delete</a>
</td>
</tr>
<tr>
<td><?php echo bbcode_format($event['text']); ?><br /><br /></td>
</tr>
<tr>
<td colspan="2" style="border-top:1px solid black;"><br /></td>
</tr>
<?php
}
if(!isset($tmp))
echo "<tr><td>There are no events posted for this day.</td></tr>";
echo "</table>";
}
function EditEvent($event_id){
//function for adding to the db in sql 'datetime' format
//$date = date("Y-m-d h:i:s", mktime(8, 30, 0, 10, 26, 2009));
/*
echo $date."<br />";
//function for parsing our date format into an array
echo "<pre>";
$date_arr = date_parse($date); //returns an associative array $array['year']
print_r($date_arr);
echo "</pre>";
echo $date_arr['year']; */
global $db;
if(isset($_POST['processed'])){
$title = addslashes($_POST['title']);
$text = addslashes($_POST['text']);
$year = addslashes($_POST['year']);
$month = addslashes($_POST['month']);
$day = addslashes($_POST['day']);
$time = addslashes($_POST['time']);
$color = addslashes($_POST['color']);
$date = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
$db->Query("UPDATE `bayonet_events` SET `title` = '$title', `text` = '$text', `color` = '$color', `date` = '$date', `time` = '$time' WHERE `event_id` ='$event_id' LIMIT 1");
}
$result = $db->Query("SELECT * FROM `bayonet_events` WHERE `event_id` = $event_id LIMIT 1");
$event = $db->FetchRow($result);
?>
<h3>Edit Event</h3>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table>
<tr><th>Title</th><td><input type="text" name="title" value="<?php echo $event['title']; ?>" /></td></tr>
<tr><th>Color</th><td><input type="text" name="color" value="<?php echo $event['color']; ?>" /></td></tr>
<tr><th>Date</th><td><?php SelectDate($event['date']); ?></td></tr>
<tr><th>Time</th><td><input type="text" name="time" value="<?php echo substr($event['time'],0,-3); ?>" maxlength="5" size="5" /></td></tr>
<tr><th>Text</th><td><textarea id="markItUp" rows="30" cols="80" name="text"><?php echo $event['text']; ?></textarea></td>
<tr><th colspan="2"><input type="submit" name="processed" value="Submit" /></th></tr>
</table>
</form>
<?php
}
function NewEvent(){
global $db;
if(isset($_POST['processed']))
{
//Secure our data to prevent injection attacks.
$title = addslashes($_POST['title']);
$text = addslashes($_POST['text']);
$year = addslashes($_POST['year']);
$month = addslashes($_POST['month']);
$day = addslashes($_POST['day']);
$time = addslashes($_POST['time']);
$color = addslashes($_POST['color']);
$date = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
if(empty($title) || empty($text))
{
echo "You must fill everything out before proceeding.";
return;
}
$sent = false;
//Update the database with the new data.
if(!$sent){
$sent = true;
$db->Query("INSERT INTO `bayonet_events` (`event_id` ,`date` ,`time` ,`title` ,`text` ,`color`)VALUES (NULL , '$date', '$time', '$title', '$text', '$color')");
//echo '<script>location.href="?op=calendar&list='.$date.'";</script>';
}
echo "New event, '$title', has been added.\n";
PageRedirect(2,"?op=calendar");
//die, because we have completed what we wanted to do.
return;
}
?>
<h3>Add New Event</h3>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
<table>
<tr><th>Title</th><td><input type="text" name="title" value="" /></td></tr>
<tr><th>Color</th><td><input type="text" name="color" value="" /></td></tr>
<tr><th>Date</th><td><?php SelectDate($_GET['date']); ?></td></tr>
<tr><th>Time</th><td><input type="text" name="time" value="12:00" maxlength="5" size="5" /></td></tr>
<tr><th>Text</th><td><textarea id="markItUp" rows="30" cols="80" name="text"></textarea></td>
<tr><th colspan="2"><input type="submit" name="processed" value="Submit" /></th></tr>
</table>
</form>
<?php
}
function DeleteEvent($event_id = 0){
global $db;
$result = $db->Query("SELECT title FROM bayonet_events WHERE event_id = '$event_id'");
$event = $db->Fetch($result);
if(isset($_POST['proceed']))
{
echo "Event '{$event['title']}', was deleted.";
$db->Query("DELETE FROM bayonet_events WHERE event_id = '$event_id' LIMIT 1");
return;
}
if(isset($_POST['cancel']))
{
echo "User cancelled deletion of event: '{$event['title']}'";
return;
}
if($event_id <= 0 || !is_numeric($event_id)) {
echo "Invalid request to delete this event.";
return;
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table>
<th>Are you SURE you want to delete the event titled: '<?php echo $event['title']?>'?</th>
<tr><th><button name="proceed">Yes</button> <button name="cancel">No</button></th></tr>
</table>
</form>
<?php
}
/**
* PrintCalendar() - prints the calendar with events
*/
function PrintCalendar(){
$date = time();
date_default_timezone_set("America/New_York"); //EASTERN TIME ZONE
//GET values for month and year
$month = $_GET['month'];
$year = $_GET['year'];
$useCurDate = true;
//check to makes sure month and year are in the desired ranges
if(!empty($month) && !empty($year) && $month > 0 && $month < 13 && $year > 1990){
$useCurDate = false;
}
//check to see if the get variables are for todays month
if($month == date('n', $date) && $year == date('Y', $date)){
$useCurDate = true;
}
//use current date unless GET values are set
if($useCurDate)
{
$day = date('d', $date);
$today = date('j', $date);
$month = date('m', $date);
$monthNum = date('n', $date);
$year = date('Y', $date);
}
else
{
$monthNum = $month;
//if GET values are equal to curdate, set $today
if($year == date('Y', $date) && $monthNum == date('n', $date))
$today = date('j', $date);
else
$today = 0;
}
/* Accounts for the last couple days from the previous months */
$first_day = mktime(0,0,0,$monthNum, 1, $year);
$title = date('F', $first_day);
$day_of_week = date('D', $first_day);
switch($day_of_week){
case "Sun": $blank = 0; break;
case "Mon": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Wed": $blank = 3; break;
case "Thu": $blank = 4; break;
case "Fri": $blank = 5; break;
case "Sat": $blank = 6; break;
}
/* calculates the days in the current month */
$days_in_month = cal_days_in_month(0, $monthNum, $year);
//makes sure that previous year is not year 0
if($monthNum == 1){
$previous_month = 12;
$previous_year = $year-1;
}else{
$previous_month = $monthNum-1;
$previous_year = $year;
}
//makes sure the next year is not year 13
if($monthNum == 12){
$next_month = 1;
$next_year = $year+1;
}else{
$next_month = $monthNum+1;
$next_year = $year;
}
?>
<center>
<table class="calendar" style="background-color:white;" cellspacing="1" cellpadding="0">
<tr style="background-color:#999999; height:27px;">
<td colspan="50" style="vertical-align:middle; text-align:center;">
<a href="?op=calendar&month=<?php echo $previous_month.'&year='.$previous_year; ?>"><<</a>
<!-- Month Name and Year -->
<span class="monthTitle"><?php echo strtoupper($title).' '.$year; ?></span>
<a href="?op=calendar&month=<?php echo $next_month.'&year='.$next_year; ?>">>></a>
</td>
</tr>
<tr>
<th class="weekday">Sun</th><th class="weekday">Mon</th><th class="weekday">Tue</th><th class="weekday">Wed</th>
<th class="weekday">Thu</th><th class="weekday">Fri</th><th class="weekday">Sat</th>
</tr>
<tr>
<?php
$day_count = 1; //holds the current day of the week 1-7
$day_num = 1; //holds the current day of the month 1-31
$days_monthbefore = cal_days_in_month(0, $previous_month, $year);
//prints the numbers of days for the previous month
while($blank > 0){
$blank = $blank-1;
$days_before = $days_monthbefore-$blank;
echo '<td class="cal_notmonth">'.$days_before.'</td>'; //'.$days_before.'</td>';
$day_count++;
}
$events = GetEventsOnInterval("{$year}-{$monthNum}-01","{$year}-{$monthNum}-{$days_in_month}");
//loop printing each day of the CURRENT month ONLY
while($day_num <= $days_in_month){
if($day_count==1 || $day_count==7){
echo '<td class="cal_weekend">'; //weekends
}else{
echo '<td class="cal_weekday">'; //weekdays
}
$sqlDate = date("Y-m-d", mktime(0, 0, 0, $monthNum, $day_num, $year));
//checks to see if the current day has events
$isEvent=false;
foreach($events as $event){
if($event['date'] == $sqlDate){
$isEvent = true;
}
}
if($useCurDate)
echo "<a href=\"?op=calendar&list={$year}-{$monthNum}-{$day_num}\">";
else
echo "<a href=\"?op=calendar&month={$monthNum}&year={$year}&list={$year}-{$monthNum}-{$day_num}\">";
if($day_num == $today && $isEvent==true){
echo '<div class="eventtoday">'.$day_num.'</div>';
}else if($day_num == $today && $isEvent==false){
echo '<div class="monthtoday">'.$day_num.'</div>';
}else if($day_num != $today && $isEvent==true){
echo '<div class="event" id="event'.$day_num.'" onmouseover="highlightEvent(this.id)" onmouseout="normEvent(this.id)">';
echo $day_num;
echo '</div>';
}else{
echo $day_num;
}
echo "</a>";
echo '</td>';
$day_num++;
$day_count++;
if($day_count > 7){
echo '</tr><tr>';
$day_count = 1;
}
}
$days_after = 1;
//loop for printing the days for the next month
while($day_count > 1 && $day_count <=7){
echo '<td class="cal_notmonth">'.$days_after.'</td>'; //'.$days_after.'</td>';
$days_after++;
$day_count++;
}
?>
</tr>
</table>
</center>
<?php
}
function GetEventsOnInterval($start,$end){
global $db;
$result = $db->Query("SELECT `event_id`, `title`, `color`, `date`, `time` FROM `bayonet_events` WHERE `date` BETWEEN '$start' AND '$end' ORDER BY `time` ASC");
$events = $db->Fetch($result);
return $events;
}
?>
|