forked from e107inc/calendar_menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.php
301 lines (252 loc) · 8.76 KB
/
calendar.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
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
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2013 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Event calendar plugin - large calendar display
*
*/
/**
* e107 Event calendar plugin
*
* Event calendar plugin - large calendar display
*
* @package e107_plugins
* @subpackage event_calendar
*/
if (!defined('e_SINGLE_ENTRY'))
{
require_once('../../class2.php');
}
$e107 = e107::getInstance();
$tp = e107::getParser();
if (!$e107->isInstalled('calendar_menu')) header('Location: '.e_BASE.'index.php');
if (isset($_POST['viewallevents']))
{
Header('Location: '.e_PLUGIN_ABS.'calendar_menu/event.php?' . $_POST['enter_new_val']);
exit();
}
if (isset($_POST['doit']))
{
Header('Location: '.e_PLUGIN_ABS.'calendar_menu/event.php?ne.' . $_POST['enter_new_val']);
exit();
}
if (isset($_POST['subs']))
{
Header('Location: '.e_PLUGIN_ABS.'calendar_menu/subscribe.php');
exit();
}
if (isset($_POST['printlists']))
{
Header('Location: '.e_PLUGIN_ABS.'calendar_menu/ec_pf_page.php');
exit();
}
require_once(e_PLUGIN.'calendar_menu/calendar_shortcodes.php');
$calSc = new event_calendar_shortcodes();
include_lan(e_PLUGIN.'calendar_menu/languages/'.e_LANGUAGE.'.php');
define('PAGE_NAME', EC_LAN_121);
require_once(e_PLUGIN.'calendar_menu/ecal_class.php');
$ecal_class = new ecal_class;
if (is_readable(THEME.'calendar_template.php'))
{
require(THEME.'calendar_template.php');
}
else
{
require(e_PLUGIN.'calendar_menu/calendar_template.php');
}
if(is_array($CALENDAR_TEMPLATE) && deftrue('BOOTSTRAP',false)) // new v2.x format.
{
$CALENDAR_TIME_TABLE = $CALENDAR_TEMPLATE['time_table'];
$CALENDAR_CALENDAR_START = $CALENDAR_TEMPLATE['calendar_start'];
$CALENDAR_CALENDAR_HEADER_START = $CALENDAR_TEMPLATE['calendar_header_start'];
$CALENDAR_CALENDAR_HEADER = $CALENDAR_TEMPLATE['calendar_header'];
$CALENDAR_CALENDAR_HEADER_END = $CALENDAR_TEMPLATE['calendar_header_end'];
$CALENDAR_CALENDAR_END = $CALENDAR_TEMPLATE['calendar_end'];
$CALENDAR_CALENDAR_WEEKSWITCH = $CALENDAR_TEMPLATE['calendar_weekswitch'];
$CALENDAR_CALENDAR_DAY_NON = $CALENDAR_TEMPLATE['calendar_day_non'];
$CALENDAR_CALENDAR_DAY_TODAY = $CALENDAR_TEMPLATE['calendar_day_today'];
$CALENDAR_CALENDAR_DAY_EVENT = $CALENDAR_TEMPLATE['calendar_day_event'];
$CALENDAR_SHOWEVENT = $CALENDAR_TEMPLATE['showevent'];
$CALENDAR_CALENDAR_DAY_EMPTY = $CALENDAR_TEMPLATE['calendar_day_empty'];
$CALENDAR_CALENDAR_DAY_END = $CALENDAR_TEMPLATE['calendar_day_end'];
}
$cat_filter = intval(varset($_POST['event_cat_ids'],-1));
if ($cat_filter == -1) $cat_filter = '*';
require_once(HEADERF);
// get date within area to display
unset($dateArray);
if (e_QUERY)
{
$qs = explode('.', e_QUERY); // Get date from query
$dateArray = $ecal_class->gmgetdate($qs[0]);
}
if (!isset($dateArray))
{ // Show current month
$dateArray = $ecal_class->cal_date;
}
// These are used in the day display loop
$month = $dateArray['mon']; // Number of month being shown
$year = $dateArray['year']; // Number of year being shown
$nowmonth = $ecal_class->cal_date['mon'];
$nowyear = $ecal_class->cal_date['year'];
$nowday = $ecal_class->cal_date['mday'];
// Set date window for display
$monthstart = gmmktime(0, 0, 0, $month, 1, $year); // Start of month to be shown
$monthend = gmmktime(0, 0, 0, $month + 1, 1, $year) - 1; // End of month to be shown
$calSc->ecalClass = &$ecal_class;
$calSc->setCalDate($dateArray);
$calSc->catFilter = $cat_filter;
//-------------------------------------------------
// Start calculating text to display
//-------------------------------------------------
// time switch buttons
$cal_text = $tp->parseTemplate($CALENDAR_TIME_TABLE, FALSE, $calSc);
// navigation buttons
$nav_text = $tp->parseTemplate($CALENDAR_NAVIGATION_TABLE, FALSE, $calSc);
// We'll need virtually all of the event-related fields, so get them regardless. Just cut back on category fields
$ev_list = $ecal_class->get_events($monthstart, $monthend, FALSE, $cat_filter, TRUE, '*', 'event_cat_name,event_cat_icon');
// We create an array $events[] which has a 'primary' index of each day of the current month - 1..31 potentially
// For each day there is then a sub-array entry for each event
// Note that the new class-based retrieval adds an 'is_recent' flag to the data if changed according to the configured criteria
$events = array();
foreach ($ev_list as $row)
{
$row['startofevent'] = TRUE; // This sets 'large print' and so on for the first day of an event
// check for recurring events in this month (could also use is_array($row['event_start']) as a test)
if($row['event_recurring'] != '0')
{ // There could be several dates for the same event, if its a daily/weekly event
$t_start = $row['event_start'];
foreach ($t_start as $ev_start)
{
// Need to save event, copy marker for date
$row['event_start'] = $ev_start;
$events[gmdate('j',$ev_start)][] = $row;
}
}
else
{ // Its a 'normal' event
$tmp = gmdate('j',$row['event_start']); // Day of month for start
if ($row['event_allday'])
{
$tmp2 = $tmp; // Same day for start and end
}
else
{
$tmp2 = gmdate('j',$row['event_end']-1); // Day of month for end - knock off a second to allow for BST and suchlike
}
if(($row['event_start']>=$monthstart) && ($row['event_start']<=$monthend))
{ // Start within month
$events[$tmp][] = $row;
$tmp++;
if ($row['event_end']>$monthend)
{ // End outside month
$tmp2 = gmdate("t", $monthstart); // number of days in this month
}
}
else
{ // Start before month
$tmp = 1;
if ($row['event_end']>$monthend)
{ // End outside month
$tmp2 = gmdate("t", $monthstart); // number of days in this month
}
}
// Now put in markers for all 'non-start' days within current month
$row['startofevent'] = FALSE;
for ($c= $tmp; $c<=$tmp2; $c++)
{
$events[$c][] = $row;
}
}
}
// ****** CAUTION - the category dropdown also used $sql object - take care to avoid interference!
$start = $monthstart;
$numberdays = gmdate("t", $start); // number of days in this month
$text = "";
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_START, FALSE, $calSc);
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_HEADER_START, FALSE, $calSc);
// Display the column headers
for ($i = 0; $i < 7; $i++)
{
$calSc->headerDay = $ecal_class->day_offset_string($i);
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_HEADER, FALSE, $calSc);
}
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_HEADER_END, FALSE, $calSc);
// Calculate number of days to skip before 'real' days on first line of calendar
$firstdayoffset = gmdate('w',$start) - $ecal_class->ec_first_day_of_week;
if ($firstdayoffset < 0) $firstdayoffset+= 7;
for ($i=0; $i<$firstdayoffset; $i++)
{
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_DAY_NON, FALSE, $calSc);
}
$loop = $firstdayoffset;
for ($c = 1; $c <= $numberdays; $c++)
{ // Loop through the number of days in this month
$calSc->todayStart = $start; // Start of current day
$calSc->curDay = $c; // Current day of month
$got_ev = array_key_exists($c, $events) && is_array($events[$c]) && count($events[$c]) > 0; // Flag set if events on this day
// Highlight the current day.
if ($nowday == $c && $month == $nowmonth && $year == $nowyear)
{ //today
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_DAY_TODAY, FALSE, $calSc);
}
elseif ($got_ev)
{ //day has events
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_DAY_EVENT, FALSE, $calSc);
}
else
{ // no events and not today
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_DAY_EMPTY, FALSE, $calSc);
}
if ($got_ev)
{
foreach($events[$c] as $ev)
{
if ($ev['startofevent'])
{
$ev['indicat'] = '';
$ev['imagesize'] = '8';
$ev['fulltopic'] = TRUE;
}
else
{
$ev['indicat'] = '';
$ev['imagesize'] = '4';
$ev['fulltopic'] = FALSE;
}
//setScVar('event_calendar_shortcodes', 'event', $ev); // Give shortcodes the event data
$calSc->event = $ev;
$text .= $tp->parseTemplate($CALENDAR_SHOWEVENT, FALSE, $calSc);
}
}
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_DAY_END, FALSE, $calSc);
$loop++;
if ($loop == 7)
{
$loop = 0;
if($c != $numberdays)
{
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_WEEKSWITCH, FALSE, $calSc);
}
}
$start += 86400;
}
//remainder cells to end the row properly with empty cells
if($loop!=0)
{
for ($c=$loop; $c<7; $c++)
{
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_DAY_NON, FALSE, $calSc);
}
}
$text .= $tp->parseTemplate($CALENDAR_CALENDAR_END, FALSE, $calSc);
$ns->tablerender(EC_LAN_79, $cal_text . $nav_text . $text);
// Claim back memory from key variables
unset($ev_list);
unset($text);
require_once(FOOTERF);
?>