This repository was archived by the owner on Jan 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcalendar.php
More file actions
executable file
·392 lines (345 loc) · 11.3 KB
/
calendar.php
File metadata and controls
executable file
·392 lines (345 loc) · 11.3 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="includes/style.css" type="text/css" />
<link rel="stylesheet" href="includes/calendar.css" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js" type='text/javascript'></script>
<script src="includes/jquery.curvycorners.min.js" type='text/javascript'></script>
<?php
date_default_timezone_set("America/Vancouver");
@include('includes/passwords.priv');
$dbconn = pg_connect("host={$sql_host} dbname={$sql_database} user={$sql_user} password={$sql_password}");
$showEdit = false;
if(isset($_COOKIE['session']))
{
$showEdit = true;
}
function getURLQuery($year, $month)
{
while($month > 12)
{
$month -= 12;
$year += 1;
}
while($month < 1)
{
$month += 12;
$year -= 1;
}
if($year <= 1970 || $year >= 2036 )
{
$year = $curYear;
}
return 'calendar.php?year='.$year.'&month='.$month;
}
function getMonthName($month)
{
while($month > 12)
{
$month -= 12;
}
while($month < 1)
{
$month += 12;
}
switch ($month)
{
case 1: return "January"; break;
case 2: return "February"; break;
case 3: return "March"; break;
case 4: return "April"; break;
case 5: return "May"; break;
case 6: return "June"; break;
case 7: return "July"; break;
case 8: return "August"; break;
case 9: return "September"; break;
case 10: return "October"; break;
case 11: return "November"; break;
case 12: return "December"; break;
default: return "Unknown"; break;
}
}
function getEvent($year, $month, $day)
{
return "";
}
function getWeekDay($year, $month, $day)
{
return date('w', strtotime($year . "/" . $month . "/" . $day));
}
$curYear = date('Y');
$usedYear = "";
if(isset($_GET["year"]))
{
$usedYear = $_GET["year"];
}else
{
$usedYear = $curYear;
}
$curMonth = date('n');
$usedMonth = "";
if(isset($_GET["month"]))
{
$usedMonth = $_GET["month"];
if($usedMonth == "")
{
$usedMonth = $curMonth;
}
}else
{
$usedMonth = $curMonth;
}
while($usedMonth < 1){
$usedMonth += 12;
$usedYear -= 1;
}
while($usedMonth > 12){
$usedMonth -= 12;
$usedYear += 1;
}
$curDay = date('j');
if($usedYear <= 1970 || $usedYear >= 2036 )
{
$usedYear = $curYear;
$usedMonth = $curMonth;
}
$usedMonthS = getMonthName($usedMonth);
$prevMonthS = getMonthName($usedMonth-1);
$nextMonthS = getMonthName($usedMonth+1);
$dayCount = date('t', strtotime($usedYear."/".$usedMonth."/".$curDay));
$dayIndex = 1;
$calendarCount = 0;
$startDay = getWeekDay($usedYear, $usedMonth, 1);
define('TITLE', $usedMonthS." ".$usedYear." Events");?>
<script type="text/javascript">
<!--
var maxLoad = 10000;
var currentGETs = new Array();
var currentINTs = new Array();
var day = 0;
var doneFade = false;
var doneLoad = false;
var publicData = "";
var defaultHTML = "<div class='dayClose'><img src='images/close.png' title='Close' alt='Close'/></div><div class='dayCreate'><img src='images/create.png' title='Create New Event' alt='Create New Event'/></div>";
var defaultHTMLNoCreate = "<div class='dayClose'><img src='images/close.png' title='Close' alt='Close'/></div>";
var get = location.search.replace('?', '').split('&').map(function(val){
return val.split('=');
});
$(document).ready(function(){
$.ajaxSetup({ timeout: maxLoad });
jQuery.fn.center = function () {
this.css({"position" : "absolute" , "top" : Math.min(120, (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop()) + "px" ,
"left" : Math.max(0, (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft()) + "px"});
return this;
};
$.fn.showHtml = function(html, speed, callback){
return this.each(function()
{
// The element to be modified
var el = $(this);
// Preserve the original values of width and height - they'll need
// to be modified during the animation, but can be restored once
// the animation has completed.
var finish = {width: this.style.width, height: this.style.height};
// The original width and height represented as pixel values.
// These will only be the same as `finish` if this element had its
// dimensions specified explicitly and in pixels. Of course, if that
// was done then this entire routine is pointless, as the dimensions
// won't change when the content is changed.
var cur = {width: el.width()+'px', height: el.height()+'px'};
// Modify the element's contents. Element will resize.
el.html(html);
// Capture the final dimensions of the element
// (with initial style settings still in effect)
var next = {width: el.width()+'px', height: el.height()+'px'};
el .css(cur) // restore initial dimensions
.animate(next, speed, function() // animate to final dimensions
{
el.css(finish); // restore initial style settings
if ( $.isFunction(callback) ) callback();
});
});
};
$('.cell,.cellh').click(function() {
day = $(this).attr("id").substr(3);
$('#dayInfoBack').height($(document).height());
$('#dayInfoBack').width($(document).width());
$('#dayInfoBack').fadeIn(300);
//$('#dayInfo').center();
$('#dayInfo').fadeIn(300, afterFade);
doneFade = false;
doneLoad = false;
var needLoad = true;
for(var i = 0; i < currentGETs.length; i++){
if(currentGETs[i] == day){
needLoad = false;
}
}
if(needLoad == true){
var localDay = day;
currentGETs.push(day);
currentINTs.push(setTimeout(function() {
for(var i = 0; i < currentGETs.length; i++){
if(currentGETs[i] == localDay){
currentGETs[i] = currentGETs[currentGETs.length-1];
currentGETs.pop();
break;
}
}
if(localDay == day){
doneLoad = true;
if(doneFade == true){
$('#dayInfo').showHtml(defaultHTMLNoCreate+"<h1>Error</h1><h2>Failed to load Data</h2>"+
"<p>Please try again later. If the problem persists, please contact the webmaster at <a href='mailto:csss-exec@sfu.ca'>csss-exec@sfu.ca</a></p>", 500);
//$('#dayInfo').css({"background" : "#FFF" , "min-height" : "10px" , "padding" : "10px"});
$('.dayClose').click(closeInfo);
}else
{
publicData = data;
}
}
}, maxLoad+100));
<?php if($showEdit){ ?>
$.get("includes/dayDetails.php?year=<?php echo $usedYear ?>&month=<?php echo $usedMonth ?>&day="+day+"&edit", function(data){
<?php }else{ ?>
$.get("includes/dayDetails.php?year=<?php echo $usedYear ?>&month=<?php echo $usedMonth ?>&day="+day, function(data){
<?php } ?>
for(var i = 0; i < currentGETs.length; i++){
if(currentGETs[i] == localDay){
currentGETs[i] = currentGETs[currentGETs.length-1];
clearInterval(currentINTs[i]);
currentINTs[i] = currentINTs[currentINTs.length-1];
currentGETs.pop();
currentINTs.pop();
break;
}
}
if(localDay == day){
doneLoad = true;
if(doneFade == true){
<?php if($showEdit){ ?>
$('#dayInfo').showHtml(defaultHTML+data, 300);
<?php }else{ ?>
$('#dayInfo').showHtml(defaultHTMLNoCreate+data, 300);
<?php } ?>
//$('#dayInfo').css({"background" : "#FFF" , "min-height" : "10px" , "padding" : "10px"});
$('.dayClose').click(closeInfo);
$('.dayCreate').click(createEvent);
}else
{
publicData = data;
}
}
});
}
});
function afterFade(){
doneFade = true;
if(doneLoad == true){
//$('#dayInfo').html("</div><div class='dayClose'><img src='images/close.gif'></div>"+publicData, 300);
<?php if($showEdit){ ?>
$('#dayInfo').showHtml(defaultHTML+publicData, 300);
<?php }else{ ?>
$('#dayInfo').showHtml(defaultHTMLNoCreate+publicData, 300);
<?php } ?>
$('.dayClose').click(closeInfo);
$('.dayCreate').click(createEvent);
publicData = "";
}
}
function closeInfo(){
day = 0;
$('#dayInfoBack').fadeOut(150, function() {
$('#dayInfoBack').height("100%");
$('#dayInfoBack').width("100%");
});
$('#dayInfo').fadeOut(150, function() {
$('#dayInfo').html("<div class='dayLoading'><img src='images/loading.gif'></div>"+defaultHTMLNoCreate);
$('.dayClose').click(closeInfo);
//$('#dayInfo').css({"top" : "0px", "left" : "0px"});
});
}
function createEvent(){
var curDate = new Date(<?php echo $usedYear; ?>, <?php echo $usedMonth ?>-1, day);
window.location.href = 'https://'+window.location.hostname+'/createEvent.php?sdate='+(curDate.getTime() / 1000);
}
$('#dayInfoBack').click(closeInfo);
$('.dayClose').click(closeInfo);
for(var i = 0; i < get.length; i++)
{
if(get[i][0] == "day")
{
$('div [data-id="'+get[i][1]+'"]').click();
break;
}
}
});
//-->
</script>
<?php
@include('includes/header.inc.php'); ?>
<div id="dayInfoBack"></div>
<div id="dayInfo"><div class="dayLoading"><img src="images/loading.gif" alt='Loading'/></div><div class="dayClose"><img src="images/close.png" alt='Close'/></div></div>
<div id="calendar">
<div id="calendar-header">
<?php
echo '<div id="calendar-header-left"><a href="'.getURLQuery($usedYear, $usedMonth-1).'">← '.$prevMonthS.'</a></div>';
echo '<div id="calendar-header-mid"><h1>'.$usedMonthS.' '.$usedYear.'</h1></div>';
echo '<div id="calendar-header-right"><a href="'.getURLQuery($usedYear, $usedMonth+1).'">'.$nextMonthS.' →</a></div>';
?>
</div>
<div class="day">Sunday</div>
<div class="day">Monday</div>
<div class="day">Tuesday</div>
<div class="day">Wednesday</div>
<div class="day">Thursday</div>
<div class="day">Friday</div>
<div class="day">Saturday</div>
<?php
while($startDay > 0)
{
echo '<div class="cellg"></div>';
$startDay--;
$calendarCount++;
}
while($dayIndex <= $dayCount)
{
// get events for day;
if ( $dayIndex == $curDay && $curMonth == $usedMonth && $curYear == $usedYear )
{
echo '<div class="cellh" id="day'.$dayIndex.'">';
}else
{
echo '<div class="cell" id="day'.$dayIndex.'">';
}
echo '<noscript><div><a href="dayInfo.php?year='.$usedYear.'&month='.$usedMonth.'&day='.$dayIndex.'"><span class="clickable"></span></a></div></noscript>';
echo '<h2>'.$dayIndex . '</h2>';
// get any events from db
$dayStart = pg_escape_string(mktime(0,0,0, $usedMonth, $dayIndex, $usedYear));
$dayEnd = pg_escape_string(mktime(0,0,0, $usedMonth, $dayIndex+1, $usedYear));
// get events where event starts during the day, or the event ends during the day, or the event spans over the entire day
$eventsQuery = pg_query($dbconn, "SELECT name FROM events WHERE ( (sdate>=$dayStart AND sdate<$dayEnd) OR (edate>$dayStart AND edate<$dayEnd) OR (sdate<$dayStart AND edate>$dayEnd)) ORDER BY sdate;");
$eventCount = 0;
$eventTotal = pg_num_rows($eventsQuery);
while($data = pg_fetch_array($eventsQuery))
{
if($eventCount >= 4)
{
echo '<div class="cellMore"> and '.($eventTotal-$eventCount).' more... </div>';
break;
}
echo '<div class="cellName">'.htmlspecialchars($data['name']).'</div>';
$eventCount += 1;
}
echo '</div>';
$dayIndex++;
$calendarCount++;
}
while($calendarCount % 7 != 0){
echo '<div class="cellg"></div>';
$calendarCount++;
}?>
<div id="calendar-bot"></div>
</div>
<?php @include('includes/footer.inc.php'); ?>