|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file contains several functions for retrieving and manipulating calendar events, birthdays and holidays. |
|
5
|
|
|
* |
|
6
|
|
|
* Simple Machines Forum (SMF) |
|
7
|
|
|
* |
|
8
|
|
|
* @package SMF |
|
9
|
|
|
* @author Simple Machines https://www.simplemachines.org |
|
10
|
|
|
* @copyright 2021 Simple Machines and individual contributors |
|
11
|
|
|
* @license https://www.simplemachines.org/about/smf/license.php BSD |
|
12
|
|
|
* |
|
13
|
|
|
* @version 2.1 RC3 |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
if (!defined('SMF')) |
|
17
|
|
|
die('No direct access...'); |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Get all birthdays within the given time range. |
|
21
|
|
|
* finds all the birthdays in the specified range of days. |
|
22
|
|
|
* works with birthdays set for no year, or any other year, and respects month and year boundaries. |
|
23
|
|
|
* |
|
24
|
|
|
* @param string $low_date The low end of the range, inclusive, in YYYY-MM-DD format |
|
25
|
|
|
* @param string $high_date The high end of the range, inclusive, in YYYY-MM-DD format |
|
26
|
|
|
* @return array An array of days, each of which is an array of birthday information for the context |
|
27
|
|
|
*/ |
|
28
|
|
|
function getBirthdayRange($low_date, $high_date) |
|
29
|
|
|
{ |
|
30
|
|
|
global $smcFunc; |
|
31
|
|
|
|
|
32
|
|
|
// We need to search for any birthday in this range, and whatever year that birthday is on. |
|
33
|
|
|
$year_low = (int) substr($low_date, 0, 4); |
|
34
|
|
|
$year_high = (int) substr($high_date, 0, 4); |
|
35
|
|
|
|
|
36
|
|
|
if ($smcFunc['db_title'] !== POSTGRE_TITLE) |
|
37
|
|
|
{ |
|
38
|
|
|
// Collect all of the birthdays for this month. I know, it's a painful query. |
|
39
|
|
|
$result = $smcFunc['db_query']('birthday_array', ' |
|
40
|
|
|
SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate |
|
41
|
|
|
FROM {db_prefix}members |
|
42
|
|
|
WHERE YEAR(birthdate) != {string:year_one} |
|
43
|
|
|
AND MONTH(birthdate) != {int:no_month} |
|
44
|
|
|
AND DAYOFMONTH(birthdate) != {int:no_day} |
|
45
|
|
|
AND YEAR(birthdate) <= {int:max_year} |
|
46
|
|
|
AND ( |
|
47
|
|
|
DATE_FORMAT(birthdate, {string:year_low}) BETWEEN {date:low_date} AND {date:high_date}' . ($year_low == $year_high ? '' : ' |
|
48
|
|
|
OR DATE_FORMAT(birthdate, {string:year_high}) BETWEEN {date:low_date} AND {date:high_date}') . ' |
|
49
|
|
|
) |
|
50
|
|
|
AND is_activated = {int:is_activated}', |
|
51
|
|
|
array( |
|
52
|
|
|
'is_activated' => 1, |
|
53
|
|
|
'no_month' => 0, |
|
54
|
|
|
'no_day' => 0, |
|
55
|
|
|
'year_one' => '1004', |
|
56
|
|
|
'year_low' => $year_low . '-%m-%d', |
|
57
|
|
|
'year_high' => $year_high . '-%m-%d', |
|
58
|
|
|
'low_date' => $low_date, |
|
59
|
|
|
'high_date' => $high_date, |
|
60
|
|
|
'max_year' => $year_high, |
|
61
|
|
|
) |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
else |
|
65
|
|
|
{ |
|
66
|
|
|
$result = $smcFunc['db_query']('birthday_array', ' |
|
67
|
|
|
SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate |
|
68
|
|
|
FROM {db_prefix}members |
|
69
|
|
|
WHERE YEAR(birthdate) != {string:year_one} |
|
70
|
|
|
AND MONTH(birthdate) != {int:no_month} |
|
71
|
|
|
AND DAYOFMONTH(birthdate) != {int:no_day} |
|
72
|
|
|
AND ( |
|
73
|
|
|
indexable_month_day(birthdate) BETWEEN indexable_month_day({date:year_low_low_date}) AND indexable_month_day({date:year_low_high_date})' . ($year_low == $year_high ? '' : ' |
|
74
|
|
|
OR indexable_month_day(birthdate) BETWEEN indexable_month_day({date:year_high_low_date}) AND indexable_month_day({date:year_high_high_date})') . ' |
|
75
|
|
|
) |
|
76
|
|
|
AND is_activated = {int:is_activated}', |
|
77
|
|
|
array( |
|
78
|
|
|
'is_activated' => 1, |
|
79
|
|
|
'no_month' => 0, |
|
80
|
|
|
'no_day' => 0, |
|
81
|
|
|
'year_one' => '1004', |
|
82
|
|
|
'year_low' => $year_low . '-%m-%d', |
|
83
|
|
|
'year_high' => $year_high . '-%m-%d', |
|
84
|
|
|
'year_low_low_date' => $low_date, |
|
85
|
|
|
'year_low_high_date' => ($year_low == $year_high ? $high_date : $year_low . '-12-31'), |
|
86
|
|
|
'year_high_low_date' => ($year_low == $year_high ? $low_date : $year_high . '-01-01'), |
|
87
|
|
|
'year_high_high_date' => $high_date, |
|
88
|
|
|
) |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
$bday = array(); |
|
92
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
93
|
|
|
{ |
|
94
|
|
|
if ($year_low != $year_high) |
|
95
|
|
|
$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low; |
|
96
|
|
|
else |
|
97
|
|
|
$age_year = $year_low; |
|
98
|
|
|
|
|
99
|
|
|
$bday[$age_year . substr($row['birthdate'], 4)][] = array( |
|
100
|
|
|
'id' => $row['id_member'], |
|
101
|
|
|
'name' => $row['real_name'], |
|
102
|
|
|
'age' => $row['birth_year'] > 1004 && $row['birth_year'] <= $age_year ? $age_year - $row['birth_year'] : null, |
|
103
|
|
|
'is_last' => false |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
$smcFunc['db_free_result']($result); |
|
107
|
|
|
|
|
108
|
|
|
ksort($bday); |
|
109
|
|
|
|
|
110
|
|
|
// Set is_last, so the themes know when to stop placing separators. |
|
111
|
|
|
foreach ($bday as $mday => $array) |
|
112
|
|
|
$bday[$mday][count($array) - 1]['is_last'] = true; |
|
113
|
|
|
|
|
114
|
|
|
return $bday; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Get all calendar events within the given time range. |
|
119
|
|
|
* |
|
120
|
|
|
* - finds all the posted calendar events within a date range. |
|
121
|
|
|
* - both the earliest_date and latest_date should be in the standard YYYY-MM-DD format. |
|
122
|
|
|
* - censors the posted event titles. |
|
123
|
|
|
* - uses the current user's permissions if use_permissions is true, otherwise it does nothing "permission specific" |
|
124
|
|
|
* |
|
125
|
|
|
* @param string $low_date The low end of the range, inclusive, in YYYY-MM-DD format |
|
126
|
|
|
* @param string $high_date The high end of the range, inclusive, in YYYY-MM-DD format |
|
127
|
|
|
* @param bool $use_permissions Whether to use permissions |
|
128
|
|
|
* @return array Contextual information if use_permissions is true, and an array of the data needed to build that otherwise |
|
129
|
|
|
*/ |
|
130
|
|
|
function getEventRange($low_date, $high_date, $use_permissions = true) |
|
131
|
|
|
{ |
|
132
|
|
|
global $scripturl, $modSettings, $user_info, $smcFunc, $context, $sourcedir; |
|
133
|
|
|
static $timezone_array = array(); |
|
134
|
|
|
require_once($sourcedir . '/Subs.php'); |
|
135
|
|
|
|
|
136
|
|
|
if (empty($timezone_array['default'])) |
|
137
|
|
|
$timezone_array['default'] = timezone_open(date_default_timezone_get()); |
|
138
|
|
|
|
|
139
|
|
|
$low_object = date_create($low_date); |
|
140
|
|
|
$high_object = date_create($high_date); |
|
141
|
|
|
|
|
142
|
|
|
// Find all the calendar info... |
|
143
|
|
|
$result = $smcFunc['db_query']('calendar_get_events', ' |
|
144
|
|
|
SELECT |
|
145
|
|
|
cal.id_event, cal.title, cal.id_member, cal.id_topic, cal.id_board, |
|
146
|
|
|
cal.start_date, cal.end_date, cal.start_time, cal.end_time, cal.timezone, cal.location, |
|
147
|
|
|
b.member_groups, t.id_first_msg, t.approved, b.id_board |
|
148
|
|
|
FROM {db_prefix}calendar AS cal |
|
149
|
|
|
LEFT JOIN {db_prefix}boards AS b ON (b.id_board = cal.id_board) |
|
150
|
|
|
LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = cal.id_topic) |
|
151
|
|
|
WHERE cal.start_date <= {date:high_date} |
|
152
|
|
|
AND cal.end_date >= {date:low_date}' . ($use_permissions ? ' |
|
153
|
|
|
AND (cal.id_board = {int:no_board_link} OR {query_wanna_see_board})' : ''), |
|
154
|
|
|
array( |
|
155
|
|
|
'high_date' => $high_date, |
|
156
|
|
|
'low_date' => $low_date, |
|
157
|
|
|
'no_board_link' => 0, |
|
158
|
|
|
) |
|
159
|
|
|
); |
|
160
|
|
|
$events = array(); |
|
161
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
162
|
|
|
{ |
|
163
|
|
|
// If the attached topic is not approved then for the moment pretend it doesn't exist |
|
164
|
|
|
if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) |
|
165
|
|
|
continue; |
|
166
|
|
|
|
|
167
|
|
|
// Force a censor of the title - as often these are used by others. |
|
168
|
|
|
censorText($row['title'], $use_permissions ? false : true); |
|
169
|
|
|
|
|
170
|
|
|
// Get the various time and date properties for this event |
|
171
|
|
|
list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
|
172
|
|
|
|
|
173
|
|
|
if (empty($timezone_array[$tz])) |
|
174
|
|
|
$timezone_array[$tz] = timezone_open($tz); |
|
175
|
|
|
|
|
176
|
|
|
// Sanity check |
|
177
|
|
|
if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
178
|
|
|
continue; |
|
179
|
|
|
|
|
180
|
|
|
// Get set up for the loop |
|
181
|
|
|
$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), $timezone_array[$tz]); |
|
182
|
|
|
$end_object = date_create($row['end_date'] . (!$allday ? ' ' . $row['end_time'] : ''), $timezone_array[$tz]); |
|
183
|
|
|
date_timezone_set($start_object, $timezone_array['default']); |
|
184
|
|
|
date_timezone_set($end_object, $timezone_array['default']); |
|
185
|
|
|
date_time_set($start_object, 0, 0, 0); |
|
186
|
|
|
date_time_set($end_object, 0, 0, 0); |
|
187
|
|
|
$start_date_string = date_format($start_object, 'Y-m-d'); |
|
188
|
|
|
$end_date_string = date_format($end_object, 'Y-m-d'); |
|
189
|
|
|
|
|
190
|
|
|
$cal_date = ($start_object >= $low_object) ? $start_object : $low_object; |
|
191
|
|
|
while ($cal_date <= $end_object && $cal_date <= $high_object) |
|
192
|
|
|
{ |
|
193
|
|
|
$starts_today = (date_format($cal_date, 'Y-m-d') == $start_date_string); |
|
194
|
|
|
$ends_today = (date_format($cal_date, 'Y-m-d') == $end_date_string); |
|
195
|
|
|
|
|
196
|
|
|
$eventProperties = array( |
|
197
|
|
|
'id' => $row['id_event'], |
|
198
|
|
|
'title' => $row['title'], |
|
199
|
|
|
'year' => $start['year'], |
|
200
|
|
|
'month' => $start['month'], |
|
201
|
|
|
'day' => $start['day'], |
|
202
|
|
|
'hour' => !$allday ? $start['hour'] : null, |
|
203
|
|
|
'minute' => !$allday ? $start['minute'] : null, |
|
204
|
|
|
'second' => !$allday ? $start['second'] : null, |
|
205
|
|
|
'start_date' => $row['start_date'], |
|
206
|
|
|
'start_date_local' => $start['date_local'], |
|
207
|
|
|
'start_date_orig' => $start['date_orig'], |
|
208
|
|
|
'start_time' => !$allday ? $row['start_time'] : null, |
|
209
|
|
|
'start_time_local' => !$allday ? $start['time_local'] : null, |
|
210
|
|
|
'start_time_orig' => !$allday ? $start['time_orig'] : null, |
|
211
|
|
|
'start_timestamp' => $start['timestamp'], |
|
212
|
|
|
'start_datetime' => $start['datetime'], |
|
213
|
|
|
'start_iso_gmdate' => $start['iso_gmdate'], |
|
214
|
|
|
'end_year' => $end['year'], |
|
215
|
|
|
'end_month' => $end['month'], |
|
216
|
|
|
'end_day' => $end['day'], |
|
217
|
|
|
'end_hour' => !$allday ? $end['hour'] : null, |
|
218
|
|
|
'end_minute' => !$allday ? $end['minute'] : null, |
|
219
|
|
|
'end_second' => !$allday ? $end['second'] : null, |
|
220
|
|
|
'end_date' => $row['end_date'], |
|
221
|
|
|
'end_date_local' => $end['date_local'], |
|
222
|
|
|
'end_date_orig' => $end['date_orig'], |
|
223
|
|
|
'end_time' => !$allday ? $row['end_time'] : null, |
|
224
|
|
|
'end_time_local' => !$allday ? $end['time_local'] : null, |
|
225
|
|
|
'end_time_orig' => !$allday ? $end['time_orig'] : null, |
|
226
|
|
|
'end_timestamp' => $end['timestamp'], |
|
227
|
|
|
'end_datetime' => $end['datetime'], |
|
228
|
|
|
'end_iso_gmdate' => $end['iso_gmdate'], |
|
229
|
|
|
'allday' => $allday, |
|
230
|
|
|
'tz' => !$allday ? $tz : null, |
|
231
|
|
|
'tz_abbrev' => !$allday ? $tz_abbrev : null, |
|
232
|
|
|
'span' => $span, |
|
233
|
|
|
'is_last' => false, |
|
234
|
|
|
'id_board' => $row['id_board'], |
|
235
|
|
|
'is_selected' => !empty($context['selected_event']) && $context['selected_event'] == $row['id_event'], |
|
236
|
|
|
'starts_today' => $starts_today, |
|
237
|
|
|
'ends_today' => $ends_today, |
|
238
|
|
|
'location' => $row['location'], |
|
239
|
|
|
); |
|
240
|
|
|
|
|
241
|
|
|
// If we're using permissions (calendar pages?) then just ouput normal contextual style information. |
|
242
|
|
|
if ($use_permissions) |
|
243
|
|
|
$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
244
|
|
|
'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0', |
|
245
|
|
|
'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>', |
|
246
|
|
|
'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')), |
|
247
|
|
|
'modify_href' => $scripturl . '?action=' . ($row['id_board'] == 0 ? 'calendar;sa=post;' : 'post;msg=' . $row['id_first_msg'] . ';topic=' . $row['id_topic'] . '.0;calendar;') . 'eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
|
248
|
|
|
'can_export' => !empty($modSettings['cal_export']) ? true : false, |
|
249
|
|
|
'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
|
250
|
|
|
)); |
|
251
|
|
|
// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info. |
|
252
|
|
|
else |
|
253
|
|
|
$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
254
|
|
|
'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0', |
|
255
|
|
|
'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>', |
|
256
|
|
|
'can_edit' => false, |
|
257
|
|
|
'can_export' => !empty($modSettings['cal_export']) ? true : false, |
|
258
|
|
|
'topic' => $row['id_topic'], |
|
259
|
|
|
'msg' => $row['id_first_msg'], |
|
260
|
|
|
'poster' => $row['id_member'], |
|
261
|
|
|
'allowed_groups' => explode(',', $row['member_groups']), |
|
262
|
|
|
)); |
|
263
|
|
|
|
|
264
|
|
|
date_add($cal_date, date_interval_create_from_date_string('1 day')); |
|
265
|
|
|
} |
|
266
|
|
|
} |
|
267
|
|
|
$smcFunc['db_free_result']($result); |
|
268
|
|
|
|
|
269
|
|
|
// If we're doing normal contextual data, go through and make things clear to the templates ;). |
|
270
|
|
|
if ($use_permissions) |
|
271
|
|
|
{ |
|
272
|
|
|
foreach ($events as $mday => $array) |
|
273
|
|
|
$events[$mday][count($array) - 1]['is_last'] = true; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
ksort($events); |
|
277
|
|
|
|
|
278
|
|
|
return $events; |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
/** |
|
282
|
|
|
* Get all holidays within the given time range. |
|
283
|
|
|
* |
|
284
|
|
|
* @param string $low_date The low end of the range, inclusive, in YYYY-MM-DD format |
|
285
|
|
|
* @param string $high_date The high end of the range, inclusive, in YYYY-MM-DD format |
|
286
|
|
|
* @return array An array of days, which are all arrays of holiday names. |
|
287
|
|
|
*/ |
|
288
|
|
|
function getHolidayRange($low_date, $high_date) |
|
289
|
|
|
{ |
|
290
|
|
|
global $smcFunc; |
|
291
|
|
|
|
|
292
|
|
|
// Get the lowest and highest dates for "all years". |
|
293
|
|
|
if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) |
|
294
|
|
|
$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec} |
|
295
|
|
|
OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}'; |
|
296
|
|
|
else |
|
297
|
|
|
$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}'; |
|
298
|
|
|
|
|
299
|
|
|
// Find some holidays... ;). |
|
300
|
|
|
$result = $smcFunc['db_query']('', ' |
|
301
|
|
|
SELECT event_date, YEAR(event_date) AS year, title |
|
302
|
|
|
FROM {db_prefix}calendar_holidays |
|
303
|
|
|
WHERE event_date BETWEEN {date:low_date} AND {date:high_date} |
|
304
|
|
|
OR ' . $allyear_part, |
|
305
|
|
|
array( |
|
306
|
|
|
'low_date' => $low_date, |
|
307
|
|
|
'high_date' => $high_date, |
|
308
|
|
|
'all_year_low' => '1004' . substr($low_date, 4), |
|
309
|
|
|
'all_year_high' => '1004' . substr($high_date, 4), |
|
310
|
|
|
'all_year_jan' => '1004-01-01', |
|
311
|
|
|
'all_year_dec' => '1004-12-31', |
|
312
|
|
|
) |
|
313
|
|
|
); |
|
314
|
|
|
$holidays = array(); |
|
315
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
316
|
|
|
{ |
|
317
|
|
|
if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) |
|
318
|
|
|
$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4); |
|
319
|
|
|
else |
|
320
|
|
|
$event_year = substr($low_date, 0, 4); |
|
321
|
|
|
|
|
322
|
|
|
$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title']; |
|
323
|
|
|
} |
|
324
|
|
|
$smcFunc['db_free_result']($result); |
|
325
|
|
|
|
|
326
|
|
|
ksort($holidays); |
|
327
|
|
|
|
|
328
|
|
|
return $holidays; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
/** |
|
332
|
|
|
* Does permission checks to see if an event can be linked to a board/topic. |
|
333
|
|
|
* checks if the current user can link the current topic to the calendar, permissions et al. |
|
334
|
|
|
* this requires the calendar_post permission, a forum moderator, or a topic starter. |
|
335
|
|
|
* expects the $topic and $board variables to be set. |
|
336
|
|
|
* if the user doesn't have proper permissions, an error will be shown. |
|
337
|
|
|
*/ |
|
338
|
|
|
function canLinkEvent() |
|
339
|
|
|
{ |
|
340
|
|
|
global $user_info, $topic, $board, $smcFunc; |
|
341
|
|
|
|
|
342
|
|
|
// If you can't post, you can't link. |
|
343
|
|
|
isAllowedTo('calendar_post'); |
|
344
|
|
|
|
|
345
|
|
|
// No board? No topic?!? |
|
346
|
|
|
if (empty($board)) |
|
347
|
|
|
fatal_lang_error('missing_board_id', false); |
|
348
|
|
|
if (empty($topic)) |
|
349
|
|
|
fatal_lang_error('missing_topic_id', false); |
|
350
|
|
|
|
|
351
|
|
|
// Administrator, Moderator, or owner. Period. |
|
352
|
|
|
if (!allowedTo('admin_forum') && !allowedTo('moderate_board')) |
|
353
|
|
|
{ |
|
354
|
|
|
// Not admin or a moderator of this board. You better be the owner - or else. |
|
355
|
|
|
$result = $smcFunc['db_query']('', ' |
|
356
|
|
|
SELECT id_member_started |
|
357
|
|
|
FROM {db_prefix}topics |
|
358
|
|
|
WHERE id_topic = {int:current_topic} |
|
359
|
|
|
LIMIT 1', |
|
360
|
|
|
array( |
|
361
|
|
|
'current_topic' => $topic, |
|
362
|
|
|
) |
|
363
|
|
|
); |
|
364
|
|
|
if ($row = $smcFunc['db_fetch_assoc']($result)) |
|
365
|
|
|
{ |
|
366
|
|
|
// Not the owner of the topic. |
|
367
|
|
|
if ($row['id_member_started'] != $user_info['id']) |
|
368
|
|
|
fatal_lang_error('not_your_topic', 'user'); |
|
369
|
|
|
} |
|
370
|
|
|
// Topic/Board doesn't exist..... |
|
371
|
|
|
else |
|
372
|
|
|
fatal_lang_error('calendar_no_topic', 'general'); |
|
373
|
|
|
$smcFunc['db_free_result']($result); |
|
374
|
|
|
} |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* Returns date information about 'today' relative to the users time offset. |
|
379
|
|
|
* returns an array with the current date, day, month, and year. |
|
380
|
|
|
* takes the users time offset into account. |
|
381
|
|
|
* |
|
382
|
|
|
* @return array An array of info about today, based on forum time. Has 'day', 'month', 'year' and 'date' (in YYYY-MM-DD format) |
|
383
|
|
|
*/ |
|
384
|
|
|
function getTodayInfo() |
|
385
|
|
|
{ |
|
386
|
|
|
return array( |
|
387
|
|
|
'day' => (int) strftime('%d', forum_time()), |
|
388
|
|
|
'month' => (int) strftime('%m', forum_time()), |
|
389
|
|
|
'year' => (int) strftime('%Y', forum_time()), |
|
390
|
|
|
'date' => strftime('%Y-%m-%d', forum_time()), |
|
391
|
|
|
); |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
/** |
|
395
|
|
|
* Provides information (link, month, year) about the previous and next month. |
|
396
|
|
|
* |
|
397
|
|
|
* @param string $selected_date A date in YYYY-MM-DD format |
|
398
|
|
|
* @param array $calendarOptions An array of calendar options |
|
399
|
|
|
* @param bool $is_previous Whether this is the previous month |
|
400
|
|
|
* @return array A large array containing all the information needed to show a calendar grid for the given month |
|
401
|
|
|
*/ |
|
402
|
|
|
function getCalendarGrid($selected_date, $calendarOptions, $is_previous = false) |
|
403
|
|
|
{ |
|
404
|
|
|
global $scripturl, $modSettings; |
|
405
|
|
|
|
|
406
|
|
|
$selected_object = date_create($selected_date); |
|
407
|
|
|
|
|
408
|
|
|
$next_object = date_create($selected_date); |
|
409
|
|
|
date_add($next_object, date_interval_create_from_date_string('1 month')); |
|
410
|
|
|
|
|
411
|
|
|
$prev_object = date_create($selected_date); |
|
412
|
|
|
date_sub($prev_object, date_interval_create_from_date_string('1 month')); |
|
413
|
|
|
|
|
414
|
|
|
// Eventually this is what we'll be returning. |
|
415
|
|
|
$calendarGrid = array( |
|
416
|
|
|
'week_days' => array(), |
|
417
|
|
|
'weeks' => array(), |
|
418
|
|
|
'short_day_titles' => !empty($calendarOptions['short_day_titles']), |
|
419
|
|
|
'short_month_titles' => !empty($calendarOptions['short_month_titles']), |
|
420
|
|
|
'current_month' => date_format($selected_object, 'n'), |
|
421
|
|
|
'current_year' => date_format($selected_object, 'Y'), |
|
422
|
|
|
'current_day' => date_format($selected_object, 'd'), |
|
423
|
|
|
'show_next_prev' => !empty($calendarOptions['show_next_prev']), |
|
424
|
|
|
'show_week_links' => isset($calendarOptions['show_week_links']) ? $calendarOptions['show_week_links'] : 0, |
|
425
|
|
|
'previous_calendar' => array( |
|
426
|
|
|
'year' => date_format($prev_object, 'Y'), |
|
427
|
|
|
'month' => date_format($prev_object, 'n'), |
|
428
|
|
|
'day' => date_format($prev_object, 'd'), |
|
429
|
|
|
'start_date' => date_format($prev_object, 'Y-m-d'), |
|
430
|
|
|
'disabled' => $modSettings['cal_minyear'] > date_format($prev_object, 'Y'), |
|
431
|
|
|
), |
|
432
|
|
|
'next_calendar' => array( |
|
433
|
|
|
'year' => date_format($next_object, 'Y'), |
|
434
|
|
|
'month' => date_format($next_object, 'n'), |
|
435
|
|
|
'day' => date_format($next_object, 'd'), |
|
436
|
|
|
'start_date' => date_format($next_object, 'Y-m-d'), |
|
437
|
|
|
'disabled' => $modSettings['cal_maxyear'] < date_format($next_object, 'Y'), |
|
438
|
|
|
), |
|
439
|
|
|
'start_date' => timeformat(date_format($selected_object, 'U'), get_date_or_time_format('date')), |
|
|
|
|
|
|
440
|
|
|
); |
|
441
|
|
|
|
|
442
|
|
|
// Get today's date. |
|
443
|
|
|
$today = getTodayInfo(); |
|
444
|
|
|
|
|
445
|
|
|
$first_day_object = date_create(date_format($selected_object, 'Y-m-01')); |
|
446
|
|
|
$last_day_object = date_create(date_format($selected_object, 'Y-m-t')); |
|
447
|
|
|
|
|
448
|
|
|
// Get information about this month. |
|
449
|
|
|
$month_info = array( |
|
450
|
|
|
'first_day' => array( |
|
451
|
|
|
'day_of_week' => date_format($first_day_object, 'w'), |
|
452
|
|
|
'week_num' => date_format($first_day_object, 'W'), |
|
453
|
|
|
'date' => date_format($first_day_object, 'Y-m-d'), |
|
454
|
|
|
), |
|
455
|
|
|
'last_day' => array( |
|
456
|
|
|
'day_of_month' => date_format($last_day_object, 't'), |
|
457
|
|
|
'date' => date_format($last_day_object, 'Y-m-d'), |
|
458
|
|
|
), |
|
459
|
|
|
'first_day_of_year' => date_format(date_create(date_format($selected_object, 'Y-01-01')), 'w'), |
|
460
|
|
|
'first_day_of_next_year' => date_format(date_create((date_format($selected_object, 'Y') + 1) . '-01-01'), 'w'), |
|
461
|
|
|
); |
|
462
|
|
|
|
|
463
|
|
|
// The number of days the first row is shifted to the right for the starting day. |
|
464
|
|
|
$nShift = $month_info['first_day']['day_of_week']; |
|
465
|
|
|
|
|
466
|
|
|
$calendarOptions['start_day'] = empty($calendarOptions['start_day']) ? 0 : (int) $calendarOptions['start_day']; |
|
467
|
|
|
|
|
468
|
|
|
// Starting any day other than Sunday means a shift... |
|
469
|
|
|
if (!empty($calendarOptions['start_day'])) |
|
470
|
|
|
{ |
|
471
|
|
|
$nShift -= $calendarOptions['start_day']; |
|
472
|
|
|
if ($nShift < 0) |
|
473
|
|
|
$nShift = 7 + $nShift; |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
// Number of rows required to fit the month. |
|
477
|
|
|
$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7); |
|
478
|
|
|
if (($month_info['last_day']['day_of_month'] + $nShift) % 7) |
|
479
|
|
|
$nRows++; |
|
480
|
|
|
|
|
481
|
|
|
// Fetch the arrays for birthdays, posted events, and holidays. |
|
482
|
|
|
$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array(); |
|
483
|
|
|
$events = $calendarOptions['show_events'] ? getEventRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array(); |
|
484
|
|
|
$holidays = $calendarOptions['show_holidays'] ? getHolidayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array(); |
|
485
|
|
|
|
|
486
|
|
|
// Days of the week taking into consideration that they may want it to start on any day. |
|
487
|
|
|
$count = $calendarOptions['start_day']; |
|
488
|
|
|
for ($i = 0; $i < 7; $i++) |
|
489
|
|
|
{ |
|
490
|
|
|
$calendarGrid['week_days'][] = $count; |
|
491
|
|
|
$count++; |
|
492
|
|
|
if ($count == 7) |
|
493
|
|
|
$count = 0; |
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
// Iterate through each week. |
|
497
|
|
|
$calendarGrid['weeks'] = array(); |
|
498
|
|
|
for ($nRow = 0; $nRow < $nRows; $nRow++) |
|
499
|
|
|
{ |
|
500
|
|
|
// Start off the week - and don't let it go above 52, since that's the number of weeks in a year. |
|
501
|
|
|
$calendarGrid['weeks'][$nRow] = array( |
|
502
|
|
|
'days' => array(), |
|
503
|
|
|
); |
|
504
|
|
|
|
|
505
|
|
|
// And figure out all the days. |
|
506
|
|
|
for ($nCol = 0; $nCol < 7; $nCol++) |
|
507
|
|
|
{ |
|
508
|
|
|
$nDay = ($nRow * 7) + $nCol - $nShift + 1; |
|
509
|
|
|
|
|
510
|
|
|
if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) |
|
511
|
|
|
$nDay = 0; |
|
512
|
|
|
|
|
513
|
|
|
$date = date_format($selected_object, 'Y-m-') . sprintf('%02d', $nDay); |
|
514
|
|
|
|
|
515
|
|
|
$calendarGrid['weeks'][$nRow]['days'][$nCol] = array( |
|
516
|
|
|
'day' => $nDay, |
|
517
|
|
|
'date' => $date, |
|
518
|
|
|
'is_today' => $date == $today['date'], |
|
519
|
|
|
'is_first_day' => !empty($calendarOptions['show_week_num']) && (($month_info['first_day']['day_of_week'] + $nDay - 1) % 7 == $calendarOptions['start_day']), |
|
520
|
|
|
'is_first_of_month' => $nDay === 1, |
|
521
|
|
|
'holidays' => !empty($holidays[$date]) ? $holidays[$date] : array(), |
|
522
|
|
|
'events' => !empty($events[$date]) ? $events[$date] : array(), |
|
523
|
|
|
'birthdays' => !empty($bday[$date]) ? $bday[$date] : array(), |
|
524
|
|
|
); |
|
525
|
|
|
} |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
// What is the last day of the month? |
|
529
|
|
|
if ($is_previous === true) |
|
530
|
|
|
$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month']; |
|
531
|
|
|
|
|
532
|
|
|
// We'll use the shift in the template. |
|
533
|
|
|
$calendarGrid['shift'] = $nShift; |
|
534
|
|
|
|
|
535
|
|
|
// Set the previous and the next month's links. |
|
536
|
|
|
$calendarGrid['previous_calendar']['href'] = $scripturl . '?action=calendar;viewmonth;year=' . $calendarGrid['previous_calendar']['year'] . ';month=' . $calendarGrid['previous_calendar']['month'] . ';day=' . $calendarGrid['previous_calendar']['day']; |
|
537
|
|
|
$calendarGrid['next_calendar']['href'] = $scripturl . '?action=calendar;viewmonth;year=' . $calendarGrid['next_calendar']['year'] . ';month=' . $calendarGrid['next_calendar']['month'] . ';day=' . $calendarGrid['previous_calendar']['day']; |
|
538
|
|
|
|
|
539
|
|
|
loadDatePicker('#calendar_navigation .date_input'); |
|
540
|
|
|
loadDatePair('#calendar_navigation', 'date_input'); |
|
541
|
|
|
|
|
542
|
|
|
return $calendarGrid; |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
/** |
|
546
|
|
|
* Returns the information needed to show a calendar for the given week. |
|
547
|
|
|
* |
|
548
|
|
|
* @param string $selected_date A date in YYYY-MM-DD format |
|
549
|
|
|
* @param array $calendarOptions An array of calendar options |
|
550
|
|
|
* @return array An array of information needed to display the grid for a single week on the calendar |
|
551
|
|
|
*/ |
|
552
|
|
|
function getCalendarWeek($selected_date, $calendarOptions) |
|
553
|
|
|
{ |
|
554
|
|
|
global $scripturl, $modSettings, $txt; |
|
555
|
|
|
|
|
556
|
|
|
$selected_object = date_create($selected_date); |
|
557
|
|
|
|
|
558
|
|
|
// Get today's date. |
|
559
|
|
|
$today = getTodayInfo(); |
|
560
|
|
|
|
|
561
|
|
|
// What is the actual "start date" for the passed day. |
|
562
|
|
|
$calendarOptions['start_day'] = empty($calendarOptions['start_day']) ? 0 : (int) $calendarOptions['start_day']; |
|
563
|
|
|
$day_of_week = date_format($selected_object, 'w'); |
|
564
|
|
|
$first_day_object = date_create($selected_date); |
|
565
|
|
|
if ($day_of_week != $calendarOptions['start_day']) |
|
566
|
|
|
{ |
|
567
|
|
|
// Here we offset accordingly to get things to the real start of a week. |
|
568
|
|
|
$date_diff = $day_of_week - $calendarOptions['start_day']; |
|
569
|
|
|
if ($date_diff < 0) |
|
570
|
|
|
$date_diff += 7; |
|
571
|
|
|
|
|
572
|
|
|
date_sub($first_day_object, date_interval_create_from_date_string($date_diff . ' days')); |
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
$last_day_object = date_create(date_format($first_day_object, 'Y-m-d')); |
|
576
|
|
|
date_add($last_day_object, date_interval_create_from_date_string('1 week')); |
|
577
|
|
|
|
|
578
|
|
|
$month = date_format($first_day_object, 'n'); |
|
|
|
|
|
|
579
|
|
|
$year = date_format($first_day_object, 'Y'); |
|
|
|
|
|
|
580
|
|
|
$day = date_format($first_day_object, 'd'); |
|
|
|
|
|
|
581
|
|
|
|
|
582
|
|
|
$next_object = date_create($selected_date); |
|
583
|
|
|
date_add($next_object, date_interval_create_from_date_string('1 week')); |
|
584
|
|
|
|
|
585
|
|
|
$prev_object = date_create($selected_date); |
|
586
|
|
|
date_sub($prev_object, date_interval_create_from_date_string('1 week')); |
|
587
|
|
|
|
|
588
|
|
|
// Now start filling in the calendar grid. |
|
589
|
|
|
$calendarGrid = array( |
|
590
|
|
|
'show_next_prev' => !empty($calendarOptions['show_next_prev']), |
|
591
|
|
|
'previous_week' => array( |
|
592
|
|
|
'year' => date_format($prev_object, 'Y'), |
|
593
|
|
|
'month' => date_format($prev_object, 'n'), |
|
594
|
|
|
'day' => date_format($prev_object, 'd'), |
|
595
|
|
|
'start_date' => date_format($prev_object, 'Y-m-d'), |
|
596
|
|
|
'disabled' => $modSettings['cal_minyear'] > date_format($prev_object, 'Y'), |
|
597
|
|
|
), |
|
598
|
|
|
'next_week' => array( |
|
599
|
|
|
'year' => date_format($next_object, 'Y'), |
|
600
|
|
|
'month' => date_format($next_object, 'n'), |
|
601
|
|
|
'day' => date_format($next_object, 'd'), |
|
602
|
|
|
'start_date' => date_format($next_object, 'Y-m-d'), |
|
603
|
|
|
'disabled' => $modSettings['cal_maxyear'] < date_format($next_object, 'Y'), |
|
604
|
|
|
), |
|
605
|
|
|
'start_date' => timeformat(date_format($selected_object, 'U'), get_date_or_time_format('date')), |
|
|
|
|
|
|
606
|
|
|
); |
|
607
|
|
|
|
|
608
|
|
|
// Fetch the arrays for birthdays, posted events, and holidays. |
|
609
|
|
|
$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange(date_format($first_day_object, 'Y-m-d'), date_format($last_day_object, 'Y-m-d')) : array(); |
|
610
|
|
|
$events = $calendarOptions['show_events'] ? getEventRange(date_format($first_day_object, 'Y-m-d'), date_format($last_day_object, 'Y-m-d')) : array(); |
|
611
|
|
|
$holidays = $calendarOptions['show_holidays'] ? getHolidayRange(date_format($first_day_object, 'Y-m-d'), date_format($last_day_object, 'Y-m-d')) : array(); |
|
612
|
|
|
|
|
613
|
|
|
$calendarGrid['week_title'] = sprintf($txt['calendar_week_beginning'], $txt['months'][date_format($first_day_object, 'n')], date_format($first_day_object, 'j'), date_format($first_day_object, 'Y')); |
|
614
|
|
|
|
|
615
|
|
|
// This holds all the main data - there is at least one month! |
|
616
|
|
|
$calendarGrid['months'] = array(); |
|
617
|
|
|
$current_day_object = date_create(date_format($first_day_object, 'Y-m-d')); |
|
618
|
|
|
for ($i = 0; $i < 7; $i++) |
|
619
|
|
|
{ |
|
620
|
|
|
$current_month = date_format($current_day_object, 'n'); |
|
621
|
|
|
$current_day = date_format($current_day_object, 'j'); |
|
622
|
|
|
$current_date = date_format($current_day_object, 'Y-m-d'); |
|
623
|
|
|
|
|
624
|
|
|
if (!isset($calendarGrid['months'][$current_month])) |
|
625
|
|
|
$calendarGrid['months'][$current_month] = array( |
|
626
|
|
|
'current_month' => $current_month, |
|
627
|
|
|
'current_year' => date_format($current_day_object, 'Y'), |
|
628
|
|
|
'days' => array(), |
|
629
|
|
|
); |
|
630
|
|
|
|
|
631
|
|
|
$calendarGrid['months'][$current_month]['days'][$current_day] = array( |
|
632
|
|
|
'day' => $current_day, |
|
633
|
|
|
'day_of_week' => (date_format($current_day_object, 'w') + 7) % 7, |
|
634
|
|
|
'date' => $current_date, |
|
635
|
|
|
'is_today' => $current_date == $today['date'], |
|
636
|
|
|
'holidays' => !empty($holidays[$current_date]) ? $holidays[$current_date] : array(), |
|
637
|
|
|
'events' => !empty($events[$current_date]) ? $events[$current_date] : array(), |
|
638
|
|
|
'birthdays' => !empty($bday[$current_date]) ? $bday[$current_date] : array() |
|
639
|
|
|
); |
|
640
|
|
|
|
|
641
|
|
|
date_add($current_day_object, date_interval_create_from_date_string('1 day')); |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
// Set the previous and the next week's links. |
|
645
|
|
|
$calendarGrid['previous_week']['href'] = $scripturl . '?action=calendar;viewweek;year=' . $calendarGrid['previous_week']['year'] . ';month=' . $calendarGrid['previous_week']['month'] . ';day=' . $calendarGrid['previous_week']['day']; |
|
646
|
|
|
$calendarGrid['next_week']['href'] = $scripturl . '?action=calendar;viewweek;year=' . $calendarGrid['next_week']['year'] . ';month=' . $calendarGrid['next_week']['month'] . ';day=' . $calendarGrid['next_week']['day']; |
|
647
|
|
|
|
|
648
|
|
|
loadDatePicker('#calendar_navigation .date_input'); |
|
649
|
|
|
loadDatePair('#calendar_navigation', 'date_input', ''); |
|
650
|
|
|
|
|
651
|
|
|
return $calendarGrid; |
|
652
|
|
|
} |
|
653
|
|
|
|
|
654
|
|
|
/** |
|
655
|
|
|
* Returns the information needed to show a list of upcoming events, birthdays, and holidays on the calendar. |
|
656
|
|
|
* |
|
657
|
|
|
* @param string $start_date The start of a date range in YYYY-MM-DD format |
|
658
|
|
|
* @param string $end_date The end of a date range in YYYY-MM-DD format |
|
659
|
|
|
* @param array $calendarOptions An array of calendar options |
|
660
|
|
|
* @return array An array of information needed to display a list of upcoming events, etc., on the calendar |
|
661
|
|
|
*/ |
|
662
|
|
|
function getCalendarList($start_date, $end_date, $calendarOptions) |
|
663
|
|
|
{ |
|
664
|
|
|
global $modSettings, $user_info, $txt, $context, $sourcedir; |
|
665
|
|
|
require_once($sourcedir . '/Subs.php'); |
|
666
|
|
|
|
|
667
|
|
|
// DateTime objects make life easier |
|
668
|
|
|
$start_object = date_create($start_date); |
|
669
|
|
|
$end_object = date_create($end_date); |
|
670
|
|
|
|
|
671
|
|
|
$calendarGrid = array( |
|
672
|
|
|
'start_date' => timeformat(date_format($start_object, 'U'), get_date_or_time_format('date')), |
|
|
|
|
|
|
673
|
|
|
'start_year' => date_format($start_object, 'Y'), |
|
674
|
|
|
'start_month' => date_format($start_object, 'm'), |
|
675
|
|
|
'start_day' => date_format($start_object, 'd'), |
|
676
|
|
|
'end_date' => timeformat(date_format($end_object, 'U'), get_date_or_time_format('date')), |
|
677
|
|
|
'end_year' => date_format($end_object, 'Y'), |
|
678
|
|
|
'end_month' => date_format($end_object, 'm'), |
|
679
|
|
|
'end_day' => date_format($end_object, 'd'), |
|
680
|
|
|
); |
|
681
|
|
|
|
|
682
|
|
|
$calendarGrid['birthdays'] = $calendarOptions['show_birthdays'] ? getBirthdayRange($start_date, $end_date) : array(); |
|
683
|
|
|
$calendarGrid['holidays'] = $calendarOptions['show_holidays'] ? getHolidayRange($start_date, $end_date) : array(); |
|
684
|
|
|
$calendarGrid['events'] = $calendarOptions['show_events'] ? getEventRange($start_date, $end_date) : array(); |
|
685
|
|
|
|
|
686
|
|
|
// Get rid of duplicate events |
|
687
|
|
|
$temp = array(); |
|
688
|
|
|
foreach ($calendarGrid['events'] as $date => $date_events) |
|
689
|
|
|
{ |
|
690
|
|
|
foreach ($date_events as $event_key => $event_val) |
|
691
|
|
|
{ |
|
692
|
|
|
if (in_array($event_val['id'], $temp)) |
|
693
|
|
|
unset($calendarGrid['events'][$date][$event_key]); |
|
694
|
|
|
else |
|
695
|
|
|
$temp[] = $event_val['id']; |
|
696
|
|
|
} |
|
697
|
|
|
} |
|
698
|
|
|
|
|
699
|
|
|
// Give birthdays and holidays a friendly format, without the year |
|
700
|
|
|
$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), get_date_or_time_format('date')); |
|
701
|
|
|
|
|
702
|
|
|
foreach (array('birthdays', 'holidays') as $type) |
|
703
|
|
|
{ |
|
704
|
|
|
foreach ($calendarGrid[$type] as $date => $date_content) |
|
|
|
|
|
|
705
|
|
|
{ |
|
706
|
|
|
$date_local = preg_replace('~(?<=\s)0+(\d)~', '$1', trim(timeformat(strtotime($date), $date_format), " \t\n\r\0\x0B,./;:<>()[]{}\\|-_=+")); |
|
707
|
|
|
|
|
708
|
|
|
$calendarGrid[$type][$date]['date_local'] = $date_local; |
|
709
|
|
|
} |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
loadDatePicker('#calendar_range .date_input'); |
|
713
|
|
|
loadDatePair('#calendar_range', 'date_input', ''); |
|
714
|
|
|
|
|
715
|
|
|
return $calendarGrid; |
|
716
|
|
|
} |
|
717
|
|
|
|
|
718
|
|
|
/** |
|
719
|
|
|
* Loads the necessary JavaScript and CSS to create a datepicker. |
|
720
|
|
|
* |
|
721
|
|
|
* @param string $selector A CSS selector for the input field(s) that the datepicker should be attached to. |
|
722
|
|
|
* @param string $date_format The date format to use, in strftime() format. |
|
723
|
|
|
*/ |
|
724
|
|
|
function loadDatePicker($selector = 'input.date_input', $date_format = '') |
|
725
|
|
|
{ |
|
726
|
|
|
global $modSettings, $txt, $context, $user_info, $options; |
|
727
|
|
|
|
|
728
|
|
|
if (empty($date_format)) |
|
729
|
|
|
$date_format = get_date_or_time_format('date'); |
|
730
|
|
|
|
|
731
|
|
|
// Convert to format used by datepicker |
|
732
|
|
|
$date_format = strtr($date_format, array( |
|
733
|
|
|
// Day |
|
734
|
|
|
'%a' => 'D', '%A' => 'DD', '%e' => 'd', '%d' => 'dd', '%j' => 'oo', '%u' => '', '%w' => '', |
|
735
|
|
|
// Week |
|
736
|
|
|
'%U' => '', '%V' => '', '%W' => '', |
|
737
|
|
|
// Month |
|
738
|
|
|
'%b' => 'M', '%B' => 'MM', '%h' => 'M', '%m' => 'mm', |
|
739
|
|
|
// Year |
|
740
|
|
|
'%C' => '', '%g' => 'y', '%G' => 'yy', '%y' => 'y', '%Y' => 'yy', |
|
741
|
|
|
// Time (we remove all of these) |
|
742
|
|
|
'%H' => '', '%k' => '', '%I' => '', '%l' => '', '%M' => '', '%p' => '', '%P' => '', |
|
743
|
|
|
'%r' => '', '%R' => '', '%S' => '', '%T' => '', '%X' => '', '%z' => '', '%Z' => '', |
|
744
|
|
|
// Time and Date Stamps |
|
745
|
|
|
'%c' => 'D, d M yy', '%D' => 'mm/dd/y', '%F' => 'yy-mm-dd', '%s' => '@', '%x' => 'D, d M yy', |
|
746
|
|
|
// Miscellaneous |
|
747
|
|
|
'%n' => ' ', '%t' => ' ', '%%' => '%', |
|
748
|
|
|
)); |
|
749
|
|
|
|
|
750
|
|
|
loadCSSFile('jquery-ui.datepicker.css', array(), 'smf_datepicker'); |
|
751
|
|
|
loadJavaScriptFile('jquery-ui.datepicker.min.js', array('defer' => true), 'smf_datepicker'); |
|
752
|
|
|
addInlineJavaScript(' |
|
753
|
|
|
$("' . $selector . '").datepicker({ |
|
754
|
|
|
dateFormat: "' . $date_format . '", |
|
755
|
|
|
autoSize: true, |
|
756
|
|
|
isRTL: ' . ($context['right_to_left'] ? 'true' : 'false') . ', |
|
757
|
|
|
constrainInput: true, |
|
758
|
|
|
showAnim: "", |
|
759
|
|
|
showButtonPanel: false, |
|
760
|
|
|
yearRange: "' . $modSettings['cal_minyear'] . ':' . $modSettings['cal_maxyear'] . '", |
|
761
|
|
|
hideIfNoPrevNext: true, |
|
762
|
|
|
monthNames: ["' . implode('", "', $txt['months_titles']) . '"], |
|
763
|
|
|
monthNamesShort: ["' . implode('", "', $txt['months_short']) . '"], |
|
764
|
|
|
dayNames: ["' . implode('", "', $txt['days']) . '"], |
|
765
|
|
|
dayNamesShort: ["' . implode('", "', $txt['days_short']) . '"], |
|
766
|
|
|
dayNamesMin: ["' . implode('", "', $txt['days_short']) . '"], |
|
767
|
|
|
prevText: "' . $txt['prev_month'] . '", |
|
768
|
|
|
nextText: "' . $txt['next_month'] . '", |
|
769
|
|
|
firstDay: ' . (!empty($options['calendar_start_day']) ? $options['calendar_start_day'] : 0) . ', |
|
770
|
|
|
});', true); |
|
771
|
|
|
} |
|
772
|
|
|
|
|
773
|
|
|
/** |
|
774
|
|
|
* Loads the necessary JavaScript and CSS to create a timepicker. |
|
775
|
|
|
* |
|
776
|
|
|
* @param string $selector A CSS selector for the input field(s) that the timepicker should be attached to. |
|
777
|
|
|
* @param string $time_format A time format in strftime format |
|
778
|
|
|
*/ |
|
779
|
|
|
function loadTimePicker($selector = 'input.time_input', $time_format = '') |
|
780
|
|
|
{ |
|
781
|
|
|
global $modSettings, $txt, $context; |
|
782
|
|
|
|
|
783
|
|
|
if (empty($time_format)) |
|
784
|
|
|
$time_format = get_date_or_time_format('time'); |
|
785
|
|
|
|
|
786
|
|
|
// Format used for timepicker |
|
787
|
|
|
$time_format = strtr($time_format, array( |
|
788
|
|
|
'%H' => 'H', |
|
789
|
|
|
'%k' => 'G', |
|
790
|
|
|
'%I' => 'h', |
|
791
|
|
|
'%l' => 'g', |
|
792
|
|
|
'%M' => 'i', |
|
793
|
|
|
'%p' => 'A', |
|
794
|
|
|
'%P' => 'a', |
|
795
|
|
|
'%r' => 'h:i:s A', |
|
796
|
|
|
'%R' => 'H:i', |
|
797
|
|
|
'%S' => 's', |
|
798
|
|
|
'%T' => 'H:i:s', |
|
799
|
|
|
'%X' => 'H:i:s', |
|
800
|
|
|
)); |
|
801
|
|
|
|
|
802
|
|
|
loadCSSFile('jquery.timepicker.css', array(), 'smf_timepicker'); |
|
803
|
|
|
loadJavaScriptFile('jquery.timepicker.min.js', array('defer' => true), 'smf_timepicker'); |
|
804
|
|
|
addInlineJavaScript(' |
|
805
|
|
|
$("' . $selector . '").timepicker({ |
|
806
|
|
|
timeFormat: "' . $time_format . '", |
|
807
|
|
|
showDuration: true, |
|
808
|
|
|
maxTime: "23:59:59", |
|
809
|
|
|
});', true); |
|
810
|
|
|
} |
|
811
|
|
|
|
|
812
|
|
|
/** |
|
813
|
|
|
* Loads the necessary JavaScript for Datepair.js. |
|
814
|
|
|
* |
|
815
|
|
|
* Datepair.js helps to keep date ranges sane in the UI. |
|
816
|
|
|
* |
|
817
|
|
|
* @param string $container CSS selector for the containing element of the date/time inputs to be paired. |
|
818
|
|
|
* @param string $date_class The CSS class of the date inputs to be paired. |
|
819
|
|
|
* @param string $time_class The CSS class of the time inputs to be paired. |
|
820
|
|
|
*/ |
|
821
|
|
|
function loadDatePair($container, $date_class = '', $time_class = '') |
|
822
|
|
|
{ |
|
823
|
|
|
global $modSettings, $txt, $context; |
|
824
|
|
|
|
|
825
|
|
|
$container = (string) $container; |
|
826
|
|
|
$date_class = (string) $date_class; |
|
827
|
|
|
$time_class = (string) $time_class; |
|
828
|
|
|
|
|
829
|
|
|
if ($container == '') |
|
830
|
|
|
return; |
|
831
|
|
|
|
|
832
|
|
|
loadJavaScriptFile('jquery.datepair.min.js', array('defer' => true), 'smf_datepair'); |
|
833
|
|
|
|
|
834
|
|
|
$datepair_options = ''; |
|
835
|
|
|
|
|
836
|
|
|
// If we're not using a date input, we might as well disable these. |
|
837
|
|
|
if ($date_class == '') |
|
838
|
|
|
{ |
|
839
|
|
|
$datepair_options .= ' |
|
840
|
|
|
parseDate: function (el) {}, |
|
841
|
|
|
updateDate: function (el, v) {},'; |
|
842
|
|
|
} |
|
843
|
|
|
else |
|
844
|
|
|
{ |
|
845
|
|
|
$datepair_options .= ' |
|
846
|
|
|
dateClass: "' . $date_class . '",'; |
|
847
|
|
|
|
|
848
|
|
|
// Customize Datepair to work with jQuery UI's datepicker. |
|
849
|
|
|
$datepair_options .= ' |
|
850
|
|
|
parseDate: function (el) { |
|
851
|
|
|
var val = $(el).datepicker("getDate"); |
|
852
|
|
|
if (!val) { |
|
853
|
|
|
return null; |
|
854
|
|
|
} |
|
855
|
|
|
var utc = new Date(val); |
|
856
|
|
|
return utc && new Date(utc.getTime() + (utc.getTimezoneOffset() * 60000)); |
|
857
|
|
|
}, |
|
858
|
|
|
updateDate: function (el, v) { |
|
859
|
|
|
$(el).datepicker("setDate", new Date(v.getTime() - (v.getTimezoneOffset() * 60000))); |
|
860
|
|
|
},'; |
|
861
|
|
|
} |
|
862
|
|
|
|
|
863
|
|
|
// If not using a time input, disable time functions. |
|
864
|
|
|
if ($time_class == '') |
|
865
|
|
|
{ |
|
866
|
|
|
$datepair_options .= ' |
|
867
|
|
|
parseTime: function(input){}, |
|
868
|
|
|
updateTime: function(input, dateObj){}, |
|
869
|
|
|
setMinTime: function(input, dateObj){},'; |
|
870
|
|
|
} |
|
871
|
|
|
else |
|
872
|
|
|
{ |
|
873
|
|
|
$datepair_options .= ' |
|
874
|
|
|
timeClass: "' . $time_class . '",'; |
|
875
|
|
|
} |
|
876
|
|
|
|
|
877
|
|
|
addInlineJavaScript(' |
|
878
|
|
|
$("' . $container . '").datepair({' . $datepair_options . "\n\t});", true); |
|
879
|
|
|
|
|
880
|
|
|
} |
|
881
|
|
|
|
|
882
|
|
|
/** |
|
883
|
|
|
* Retrieve all events for the given days, independently of the users offset. |
|
884
|
|
|
* cache callback function used to retrieve the birthdays, holidays, and events between now and now + days_to_index. |
|
885
|
|
|
* widens the search range by an extra 24 hours to support time offset shifts. |
|
886
|
|
|
* used by the cache_getRecentEvents function to get the information needed to calculate the events taking the users time offset into account. |
|
887
|
|
|
* |
|
888
|
|
|
* @param array $eventOptions With the keys 'num_days_shown', 'include_holidays', 'include_birthdays' and 'include_events' |
|
889
|
|
|
* @return array An array containing the data that was cached as well as an expression to calculate whether the data should be refreshed and when it expires |
|
890
|
|
|
*/ |
|
891
|
|
|
function cache_getOffsetIndependentEvents($eventOptions) |
|
892
|
|
|
{ |
|
893
|
|
|
$days_to_index = $eventOptions['num_days_shown']; |
|
894
|
|
|
|
|
895
|
|
|
$low_date = strftime('%Y-%m-%d', forum_time(false) - 24 * 3600); |
|
896
|
|
|
$high_date = strftime('%Y-%m-%d', forum_time(false) + $days_to_index * 24 * 3600); |
|
897
|
|
|
|
|
898
|
|
|
return array( |
|
899
|
|
|
'data' => array( |
|
900
|
|
|
'holidays' => (!empty($eventOptions['include_holidays']) ? getHolidayRange($low_date, $high_date) : array()), |
|
901
|
|
|
'birthdays' => (!empty($eventOptions['include_birthdays']) ? getBirthdayRange($low_date, $high_date) : array()), |
|
902
|
|
|
'events' => (!empty($eventOptions['include_events']) ? getEventRange($low_date, $high_date, false) : array()), |
|
903
|
|
|
), |
|
904
|
|
|
'refresh_eval' => 'return \'' . strftime('%Y%m%d', forum_time(false)) . '\' != strftime(\'%Y%m%d\', forum_time(false)) || (!empty($modSettings[\'calendar_updated\']) && ' . time() . ' < $modSettings[\'calendar_updated\']);', |
|
905
|
|
|
'expires' => time() + 3600, |
|
906
|
|
|
); |
|
907
|
|
|
} |
|
908
|
|
|
|
|
909
|
|
|
/** |
|
910
|
|
|
* cache callback function used to retrieve the upcoming birthdays, holidays, and events within the given period, taking into account the users time offset. |
|
911
|
|
|
* Called from the BoardIndex to display the current day's events on the board index |
|
912
|
|
|
* used by the board index and SSI to show the upcoming events. |
|
913
|
|
|
* |
|
914
|
|
|
* @param array $eventOptions An array of event options. |
|
915
|
|
|
* @return array An array containing the info that was cached as well as a few other relevant things |
|
916
|
|
|
*/ |
|
917
|
|
|
function cache_getRecentEvents($eventOptions) |
|
918
|
|
|
{ |
|
919
|
|
|
// With the 'static' cached data we can calculate the user-specific data. |
|
920
|
|
|
$cached_data = cache_quick_get('calendar_index', 'Subs-Calendar.php', 'cache_getOffsetIndependentEvents', array($eventOptions)); |
|
921
|
|
|
|
|
922
|
|
|
// Get the information about today (from user perspective). |
|
923
|
|
|
$today = getTodayInfo(); |
|
924
|
|
|
|
|
925
|
|
|
$return_data = array( |
|
926
|
|
|
'calendar_holidays' => array(), |
|
927
|
|
|
'calendar_birthdays' => array(), |
|
928
|
|
|
'calendar_events' => array(), |
|
929
|
|
|
); |
|
930
|
|
|
|
|
931
|
|
|
// Set the event span to be shown in seconds. |
|
932
|
|
|
$days_for_index = $eventOptions['num_days_shown'] * 86400; |
|
933
|
|
|
|
|
934
|
|
|
// Get the current member time/date. |
|
935
|
|
|
$now = forum_time(); |
|
936
|
|
|
|
|
937
|
|
|
if (!empty($eventOptions['include_holidays'])) |
|
938
|
|
|
{ |
|
939
|
|
|
// Holidays between now and now + days. |
|
940
|
|
|
for ($i = $now; $i < $now + $days_for_index; $i += 86400) |
|
941
|
|
|
{ |
|
942
|
|
|
if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) |
|
943
|
|
|
$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
944
|
|
|
} |
|
945
|
|
|
} |
|
946
|
|
|
|
|
947
|
|
|
if (!empty($eventOptions['include_birthdays'])) |
|
948
|
|
|
{ |
|
949
|
|
|
// Happy Birthday, guys and gals! |
|
950
|
|
|
for ($i = $now; $i < $now + $days_for_index; $i += 86400) |
|
951
|
|
|
{ |
|
952
|
|
|
$loop_date = strftime('%Y-%m-%d', $i); |
|
953
|
|
|
if (isset($cached_data['birthdays'][$loop_date])) |
|
954
|
|
|
{ |
|
955
|
|
|
foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) |
|
956
|
|
|
$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
957
|
|
|
$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]); |
|
958
|
|
|
} |
|
959
|
|
|
} |
|
960
|
|
|
} |
|
961
|
|
|
|
|
962
|
|
|
if (!empty($eventOptions['include_events'])) |
|
963
|
|
|
{ |
|
964
|
|
|
$duplicates = array(); |
|
965
|
|
|
for ($i = $now; $i < $now + $days_for_index; $i += 86400) |
|
966
|
|
|
{ |
|
967
|
|
|
// Determine the date of the current loop step. |
|
968
|
|
|
$loop_date = strftime('%Y-%m-%d', $i); |
|
969
|
|
|
|
|
970
|
|
|
// No events today? Check the next day. |
|
971
|
|
|
if (empty($cached_data['events'][$loop_date])) |
|
972
|
|
|
continue; |
|
973
|
|
|
|
|
974
|
|
|
// Loop through all events to add a few last-minute values. |
|
975
|
|
|
foreach ($cached_data['events'][$loop_date] as $ev => $event) |
|
976
|
|
|
{ |
|
977
|
|
|
// Create a shortcut variable for easier access. |
|
978
|
|
|
$this_event = &$cached_data['events'][$loop_date][$ev]; |
|
979
|
|
|
|
|
980
|
|
|
// Skip duplicates. |
|
981
|
|
|
if (isset($duplicates[$this_event['topic'] . $this_event['title']])) |
|
982
|
|
|
{ |
|
983
|
|
|
unset($cached_data['events'][$loop_date][$ev]); |
|
984
|
|
|
continue; |
|
985
|
|
|
} |
|
986
|
|
|
else |
|
987
|
|
|
$duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
988
|
|
|
|
|
989
|
|
|
// Might be set to true afterwards, depending on the permissions. |
|
990
|
|
|
$this_event['can_edit'] = false; |
|
991
|
|
|
$this_event['is_today'] = $loop_date === $today['date']; |
|
992
|
|
|
$this_event['date'] = $loop_date; |
|
993
|
|
|
} |
|
994
|
|
|
|
|
995
|
|
|
if (!empty($cached_data['events'][$loop_date])) |
|
996
|
|
|
$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
997
|
|
|
} |
|
998
|
|
|
} |
|
999
|
|
|
|
|
1000
|
|
|
// Mark the last item so that a list separator can be used in the template. |
|
1001
|
|
|
for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) |
|
1002
|
|
|
$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
1003
|
|
|
for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) |
|
1004
|
|
|
$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
1005
|
|
|
|
|
1006
|
|
|
return array( |
|
1007
|
|
|
'data' => $return_data, |
|
1008
|
|
|
'expires' => time() + 3600, |
|
1009
|
|
|
'refresh_eval' => 'return \'' . strftime('%Y%m%d', forum_time(false)) . '\' != strftime(\'%Y%m%d\', forum_time(false)) || (!empty($modSettings[\'calendar_updated\']) && ' . time() . ' < $modSettings[\'calendar_updated\']);', |
|
1010
|
|
|
'post_retri_eval' => ' |
|
1011
|
|
|
global $context, $scripturl, $user_info; |
|
1012
|
|
|
|
|
1013
|
|
|
foreach ($cache_block[\'data\'][\'calendar_events\'] as $k => $event) |
|
1014
|
|
|
{ |
|
1015
|
|
|
// Remove events that the user may not see or wants to ignore. |
|
1016
|
|
|
if ((count(array_intersect($user_info[\'groups\'], $event[\'allowed_groups\'])) === 0 && !allowedTo(\'admin_forum\') && !empty($event[\'id_board\'])) || in_array($event[\'id_board\'], $user_info[\'ignoreboards\'])) |
|
1017
|
|
|
unset($cache_block[\'data\'][\'calendar_events\'][$k]); |
|
1018
|
|
|
else |
|
1019
|
|
|
{ |
|
1020
|
|
|
// Whether the event can be edited depends on the permissions. |
|
1021
|
|
|
$cache_block[\'data\'][\'calendar_events\'][$k][\'can_edit\'] = allowedTo(\'calendar_edit_any\') || ($event[\'poster\'] == $user_info[\'id\'] && allowedTo(\'calendar_edit_own\')); |
|
1022
|
|
|
|
|
1023
|
|
|
// The added session code makes this URL not cachable. |
|
1024
|
|
|
$cache_block[\'data\'][\'calendar_events\'][$k][\'modify_href\'] = $scripturl . \'?action=\' . ($event[\'topic\'] == 0 ? \'calendar;sa=post;\' : \'post;msg=\' . $event[\'msg\'] . \';topic=\' . $event[\'topic\'] . \'.0;calendar;\') . \'eventid=\' . $event[\'id\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\']; |
|
1025
|
|
|
} |
|
1026
|
|
|
} |
|
1027
|
|
|
|
|
1028
|
|
|
if (empty($params[0][\'include_holidays\'])) |
|
1029
|
|
|
$cache_block[\'data\'][\'calendar_holidays\'] = array(); |
|
1030
|
|
|
if (empty($params[0][\'include_birthdays\'])) |
|
1031
|
|
|
$cache_block[\'data\'][\'calendar_birthdays\'] = array(); |
|
1032
|
|
|
if (empty($params[0][\'include_events\'])) |
|
1033
|
|
|
$cache_block[\'data\'][\'calendar_events\'] = array(); |
|
1034
|
|
|
|
|
1035
|
|
|
$cache_block[\'data\'][\'show_calendar\'] = !empty($cache_block[\'data\'][\'calendar_holidays\']) || !empty($cache_block[\'data\'][\'calendar_birthdays\']) || !empty($cache_block[\'data\'][\'calendar_events\']);', |
|
1036
|
|
|
); |
|
1037
|
|
|
} |
|
1038
|
|
|
|
|
1039
|
|
|
/** |
|
1040
|
|
|
* Makes sure the calendar post is valid. |
|
1041
|
|
|
*/ |
|
1042
|
|
|
function validateEventPost() |
|
1043
|
|
|
{ |
|
1044
|
|
|
global $modSettings, $smcFunc; |
|
1045
|
|
|
|
|
1046
|
|
|
if (!isset($_POST['deleteevent'])) |
|
1047
|
|
|
{ |
|
1048
|
|
|
// The 2.1 way |
|
1049
|
|
|
if (isset($_POST['start_date'])) |
|
1050
|
|
|
{ |
|
1051
|
|
|
$d = date_parse(convertDateToEnglish($_POST['start_date'])); |
|
1052
|
|
|
if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
1053
|
|
|
fatal_lang_error('invalid_date', false); |
|
1054
|
|
|
if (empty($d['year'])) |
|
1055
|
|
|
fatal_lang_error('event_year_missing', false); |
|
1056
|
|
|
if (empty($d['month'])) |
|
1057
|
|
|
fatal_lang_error('event_month_missing', false); |
|
1058
|
|
|
} |
|
1059
|
|
|
elseif (isset($_POST['start_datetime'])) |
|
1060
|
|
|
{ |
|
1061
|
|
|
$d = date_parse(convertDateToEnglish($_POST['start_datetime'])); |
|
1062
|
|
|
if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
1063
|
|
|
fatal_lang_error('invalid_date', false); |
|
1064
|
|
|
if (empty($d['year'])) |
|
1065
|
|
|
fatal_lang_error('event_year_missing', false); |
|
1066
|
|
|
if (empty($d['month'])) |
|
1067
|
|
|
fatal_lang_error('event_month_missing', false); |
|
1068
|
|
|
} |
|
1069
|
|
|
// The 2.0 way |
|
1070
|
|
|
else |
|
1071
|
|
|
{ |
|
1072
|
|
|
// No month? No year? |
|
1073
|
|
|
if (!isset($_POST['month'])) |
|
1074
|
|
|
fatal_lang_error('event_month_missing', false); |
|
1075
|
|
|
if (!isset($_POST['year'])) |
|
1076
|
|
|
fatal_lang_error('event_year_missing', false); |
|
1077
|
|
|
|
|
1078
|
|
|
// Check the month and year... |
|
1079
|
|
|
if ($_POST['month'] < 1 || $_POST['month'] > 12) |
|
1080
|
|
|
fatal_lang_error('invalid_month', false); |
|
1081
|
|
|
if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) |
|
1082
|
|
|
fatal_lang_error('invalid_year', false); |
|
1083
|
|
|
} |
|
1084
|
|
|
} |
|
1085
|
|
|
|
|
1086
|
|
|
// Make sure they're allowed to post... |
|
1087
|
|
|
isAllowedTo('calendar_post'); |
|
1088
|
|
|
|
|
1089
|
|
|
// If they want to us to calculate an end date, make sure it will fit in an acceptable range. |
|
1090
|
|
|
if (isset($_POST['span'])) |
|
1091
|
|
|
{ |
|
1092
|
|
|
if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) |
|
1093
|
|
|
fatal_lang_error('invalid_days_numb', false); |
|
1094
|
|
|
} |
|
1095
|
|
|
|
|
1096
|
|
|
// There is no need to validate the following values if we are just deleting the event. |
|
1097
|
|
|
if (!isset($_POST['deleteevent'])) |
|
1098
|
|
|
{ |
|
1099
|
|
|
// If we're doing things the 2.0 way, check the day |
|
1100
|
|
|
if (empty($_POST['start_date']) && empty($_POST['start_datetime'])) |
|
1101
|
|
|
{ |
|
1102
|
|
|
// No day? |
|
1103
|
|
|
if (!isset($_POST['day'])) |
|
1104
|
|
|
fatal_lang_error('event_day_missing', false); |
|
1105
|
|
|
|
|
1106
|
|
|
// Bad day? |
|
1107
|
|
|
if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) |
|
1108
|
|
|
fatal_lang_error('invalid_date', false); |
|
1109
|
|
|
} |
|
1110
|
|
|
|
|
1111
|
|
|
if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) |
|
1112
|
|
|
fatal_lang_error('event_title_missing', false); |
|
1113
|
|
|
elseif (!isset($_POST['evtitle'])) |
|
1114
|
|
|
$_POST['evtitle'] = $_POST['subject']; |
|
1115
|
|
|
|
|
1116
|
|
|
// No title? |
|
1117
|
|
|
if ($smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
1118
|
|
|
fatal_lang_error('no_event_title', false); |
|
1119
|
|
|
if ($smcFunc['strlen']($_POST['evtitle']) > 100) |
|
1120
|
|
|
$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
1121
|
|
|
$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']); |
|
1122
|
|
|
} |
|
1123
|
|
|
} |
|
1124
|
|
|
|
|
1125
|
|
|
/** |
|
1126
|
|
|
* Get the event's poster. |
|
1127
|
|
|
* |
|
1128
|
|
|
* @param int $event_id The ID of the event |
|
1129
|
|
|
* @return int|bool The ID of the poster or false if the event was not found |
|
1130
|
|
|
*/ |
|
1131
|
|
|
function getEventPoster($event_id) |
|
1132
|
|
|
{ |
|
1133
|
|
|
global $smcFunc; |
|
1134
|
|
|
|
|
1135
|
|
|
// A simple database query, how hard can that be? |
|
1136
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1137
|
|
|
SELECT id_member |
|
1138
|
|
|
FROM {db_prefix}calendar |
|
1139
|
|
|
WHERE id_event = {int:id_event} |
|
1140
|
|
|
LIMIT 1', |
|
1141
|
|
|
array( |
|
1142
|
|
|
'id_event' => $event_id, |
|
1143
|
|
|
) |
|
1144
|
|
|
); |
|
1145
|
|
|
|
|
1146
|
|
|
// No results, return false. |
|
1147
|
|
|
if ($smcFunc['db_num_rows'] === 0) |
|
1148
|
|
|
return false; |
|
1149
|
|
|
|
|
1150
|
|
|
// Grab the results and return. |
|
1151
|
|
|
list ($poster) = $smcFunc['db_fetch_row']($request); |
|
1152
|
|
|
$smcFunc['db_free_result']($request); |
|
1153
|
|
|
return (int) $poster; |
|
1154
|
|
|
} |
|
1155
|
|
|
|
|
1156
|
|
|
/** |
|
1157
|
|
|
* Consolidating the various INSERT statements into this function. |
|
1158
|
|
|
* Inserts the passed event information into the calendar table. |
|
1159
|
|
|
* Allows to either set a time span (in days) or an end_date. |
|
1160
|
|
|
* Does not check any permissions of any sort. |
|
1161
|
|
|
* |
|
1162
|
|
|
* @param array $eventOptions An array of event options ('title', 'span', 'start_date', 'end_date', etc.) |
|
1163
|
|
|
*/ |
|
1164
|
|
|
function insertEvent(&$eventOptions) |
|
1165
|
|
|
{ |
|
1166
|
|
|
global $smcFunc, $context; |
|
1167
|
|
|
|
|
1168
|
|
|
// Add special chars to the title. |
|
1169
|
|
|
$eventOptions['title'] = $smcFunc['htmlspecialchars']($eventOptions['title'], ENT_QUOTES); |
|
1170
|
|
|
|
|
1171
|
|
|
$eventOptions['location'] = isset($eventOptions['location']) ? $smcFunc['htmlspecialchars']($eventOptions['location'], ENT_QUOTES) : ''; |
|
1172
|
|
|
|
|
1173
|
|
|
// Set the start and end dates and times |
|
1174
|
|
|
list($start_date, $end_date, $start_time, $end_time, $tz) = setEventStartEnd($eventOptions); |
|
1175
|
|
|
|
|
1176
|
|
|
// If no topic and board are given, they are not linked to a topic. |
|
1177
|
|
|
$eventOptions['board'] = isset($eventOptions['board']) ? (int) $eventOptions['board'] : 0; |
|
1178
|
|
|
$eventOptions['topic'] = isset($eventOptions['topic']) ? (int) $eventOptions['topic'] : 0; |
|
1179
|
|
|
|
|
1180
|
|
|
$event_columns = array( |
|
1181
|
|
|
'id_board' => 'int', 'id_topic' => 'int', 'title' => 'string-60', 'id_member' => 'int', |
|
1182
|
|
|
'start_date' => 'date', 'end_date' => 'date', 'location' => 'string-255', |
|
1183
|
|
|
); |
|
1184
|
|
|
$event_parameters = array( |
|
1185
|
|
|
$eventOptions['board'], $eventOptions['topic'], $eventOptions['title'], $eventOptions['member'], |
|
1186
|
|
|
$start_date, $end_date, $eventOptions['location'], |
|
1187
|
|
|
); |
|
1188
|
|
|
if (!empty($start_time) && !empty($end_time) && !empty($tz) && in_array($tz, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
|
|
|
|
|
1189
|
|
|
{ |
|
1190
|
|
|
$event_columns['start_time'] = 'time'; |
|
1191
|
|
|
$event_parameters[] = $start_time; |
|
1192
|
|
|
$event_columns['end_time'] = 'time'; |
|
1193
|
|
|
$event_parameters[] = $end_time; |
|
1194
|
|
|
$event_columns['timezone'] = 'string'; |
|
1195
|
|
|
$event_parameters[] = $tz; |
|
1196
|
|
|
} |
|
1197
|
|
|
|
|
1198
|
|
|
call_integration_hook('integrate_create_event', array(&$eventOptions, &$event_columns, &$event_parameters)); |
|
1199
|
|
|
|
|
1200
|
|
|
// Insert the event! |
|
1201
|
|
|
$eventOptions['id'] = $smcFunc['db_insert']('', |
|
1202
|
|
|
'{db_prefix}calendar', |
|
1203
|
|
|
$event_columns, |
|
1204
|
|
|
$event_parameters, |
|
1205
|
|
|
array('id_event'), |
|
1206
|
|
|
1 |
|
1207
|
|
|
); |
|
1208
|
|
|
|
|
1209
|
|
|
// If this isn't tied to a topic, we need to notify people about it. |
|
1210
|
|
|
if (empty($eventOptions['topic'])) |
|
1211
|
|
|
{ |
|
1212
|
|
|
$smcFunc['db_insert']('insert', |
|
1213
|
|
|
'{db_prefix}background_tasks', |
|
1214
|
|
|
array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
|
1215
|
|
|
array('$sourcedir/tasks/EventNew-Notify.php', 'EventNew_Notify_Background', $smcFunc['json_encode'](array( |
|
1216
|
|
|
'event_title' => $eventOptions['title'], |
|
1217
|
|
|
'event_id' => $eventOptions['id'], |
|
1218
|
|
|
'sender_id' => $eventOptions['member'], |
|
1219
|
|
|
'sender_name' => $eventOptions['member'] == $context['user']['id'] ? $context['user']['name'] : '', |
|
1220
|
|
|
'time' => time(), |
|
1221
|
|
|
)), 0), |
|
1222
|
|
|
array('id_task') |
|
1223
|
|
|
); |
|
1224
|
|
|
} |
|
1225
|
|
|
|
|
1226
|
|
|
// Update the settings to show something calendar-ish was updated. |
|
1227
|
|
|
updateSettings(array( |
|
1228
|
|
|
'calendar_updated' => time(), |
|
1229
|
|
|
)); |
|
1230
|
|
|
} |
|
1231
|
|
|
|
|
1232
|
|
|
/** |
|
1233
|
|
|
* modifies an event. |
|
1234
|
|
|
* allows to either set a time span (in days) or an end_date. |
|
1235
|
|
|
* does not check any permissions of any sort. |
|
1236
|
|
|
* |
|
1237
|
|
|
* @param int $event_id The ID of the event |
|
1238
|
|
|
* @param array $eventOptions An array of event information |
|
1239
|
|
|
*/ |
|
1240
|
|
|
function modifyEvent($event_id, &$eventOptions) |
|
1241
|
|
|
{ |
|
1242
|
|
|
global $smcFunc; |
|
1243
|
|
|
|
|
1244
|
|
|
// Properly sanitize the title and location |
|
1245
|
|
|
$eventOptions['title'] = $smcFunc['htmlspecialchars']($eventOptions['title'], ENT_QUOTES); |
|
1246
|
|
|
$eventOptions['location'] = $smcFunc['htmlspecialchars']($eventOptions['location'], ENT_QUOTES); |
|
1247
|
|
|
|
|
1248
|
|
|
// Set the new start and end dates and times |
|
1249
|
|
|
list($start_date, $end_date, $start_time, $end_time, $tz) = setEventStartEnd($eventOptions); |
|
1250
|
|
|
|
|
1251
|
|
|
$event_columns = array( |
|
1252
|
|
|
'start_date' => '{date:start_date}', |
|
1253
|
|
|
'end_date' => '{date:end_date}', |
|
1254
|
|
|
'title' => 'SUBSTRING({string:title}, 1, 60)', |
|
1255
|
|
|
'id_board' => '{int:id_board}', |
|
1256
|
|
|
'id_topic' => '{int:id_topic}', |
|
1257
|
|
|
'location' => 'SUBSTRING({string:location}, 1, 255)', |
|
1258
|
|
|
); |
|
1259
|
|
|
$event_parameters = array( |
|
1260
|
|
|
'start_date' => $start_date, |
|
1261
|
|
|
'end_date' => $end_date, |
|
1262
|
|
|
'title' => $eventOptions['title'], |
|
1263
|
|
|
'location' => $eventOptions['location'], |
|
1264
|
|
|
'id_board' => isset($eventOptions['board']) ? (int) $eventOptions['board'] : 0, |
|
1265
|
|
|
'id_topic' => isset($eventOptions['topic']) ? (int) $eventOptions['topic'] : 0, |
|
1266
|
|
|
); |
|
1267
|
|
|
if (!empty($start_time) && !empty($end_time) && !empty($tz) && in_array($tz, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
|
|
|
|
|
1268
|
|
|
{ |
|
1269
|
|
|
$event_columns['start_time'] = '{time:start_time}'; |
|
1270
|
|
|
$event_parameters['start_time'] = $start_time; |
|
1271
|
|
|
$event_columns['end_time'] = '{time:end_time}'; |
|
1272
|
|
|
$event_parameters['end_time'] = $end_time; |
|
1273
|
|
|
$event_columns['timezone'] = '{string:timezone}'; |
|
1274
|
|
|
$event_parameters['timezone'] = $tz; |
|
1275
|
|
|
} |
|
1276
|
|
|
|
|
1277
|
|
|
// This is to prevent hooks to modify the id of the event |
|
1278
|
|
|
$real_event_id = $event_id; |
|
1279
|
|
|
call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters)); |
|
1280
|
|
|
|
|
1281
|
|
|
$column_clauses = array(); |
|
1282
|
|
|
foreach ($event_columns as $col => $crit) |
|
1283
|
|
|
$column_clauses[] = $col . ' = ' . $crit; |
|
1284
|
|
|
|
|
1285
|
|
|
$smcFunc['db_query']('', ' |
|
1286
|
|
|
UPDATE {db_prefix}calendar |
|
1287
|
|
|
SET |
|
1288
|
|
|
' . implode(', ', $column_clauses) . ' |
|
1289
|
|
|
WHERE id_event = {int:id_event}', |
|
1290
|
|
|
array_merge( |
|
1291
|
|
|
$event_parameters, |
|
1292
|
|
|
array( |
|
1293
|
|
|
'id_event' => $real_event_id |
|
1294
|
|
|
) |
|
1295
|
|
|
) |
|
1296
|
|
|
); |
|
1297
|
|
|
|
|
1298
|
|
|
if (empty($start_time) || empty($end_time) || empty($tz) || !in_array($tz, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
|
|
|
|
|
1299
|
|
|
{ |
|
1300
|
|
|
$smcFunc['db_query']('', ' |
|
1301
|
|
|
UPDATE {db_prefix}calendar |
|
1302
|
|
|
SET start_time = NULL, end_time = NULL, timezone = NULL |
|
1303
|
|
|
WHERE id_event = {int:id_event}', |
|
1304
|
|
|
array( |
|
1305
|
|
|
'id_event' => $real_event_id |
|
1306
|
|
|
) |
|
1307
|
|
|
); |
|
1308
|
|
|
} |
|
1309
|
|
|
|
|
1310
|
|
|
updateSettings(array( |
|
1311
|
|
|
'calendar_updated' => time(), |
|
1312
|
|
|
)); |
|
1313
|
|
|
} |
|
1314
|
|
|
|
|
1315
|
|
|
/** |
|
1316
|
|
|
* Remove an event |
|
1317
|
|
|
* removes an event. |
|
1318
|
|
|
* does no permission checks. |
|
1319
|
|
|
* |
|
1320
|
|
|
* @param int $event_id The ID of the event to remove |
|
1321
|
|
|
*/ |
|
1322
|
|
|
function removeEvent($event_id) |
|
1323
|
|
|
{ |
|
1324
|
|
|
global $smcFunc; |
|
1325
|
|
|
|
|
1326
|
|
|
$smcFunc['db_query']('', ' |
|
1327
|
|
|
DELETE FROM {db_prefix}calendar |
|
1328
|
|
|
WHERE id_event = {int:id_event}', |
|
1329
|
|
|
array( |
|
1330
|
|
|
'id_event' => $event_id, |
|
1331
|
|
|
) |
|
1332
|
|
|
); |
|
1333
|
|
|
|
|
1334
|
|
|
call_integration_hook('integrate_remove_event', array($event_id)); |
|
1335
|
|
|
|
|
1336
|
|
|
updateSettings(array( |
|
1337
|
|
|
'calendar_updated' => time(), |
|
1338
|
|
|
)); |
|
1339
|
|
|
} |
|
1340
|
|
|
|
|
1341
|
|
|
/** |
|
1342
|
|
|
* Gets all the events properties |
|
1343
|
|
|
* |
|
1344
|
|
|
* @param int $event_id The ID of the event |
|
1345
|
|
|
* @return array An array of event information |
|
1346
|
|
|
*/ |
|
1347
|
|
|
function getEventProperties($event_id) |
|
1348
|
|
|
{ |
|
1349
|
|
|
global $smcFunc; |
|
1350
|
|
|
|
|
1351
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1352
|
|
|
SELECT |
|
1353
|
|
|
c.id_event, c.id_board, c.id_topic, c.id_member, c.title, |
|
1354
|
|
|
c.start_date, c.end_date, c.start_time, c.end_time, c.timezone, c.location, |
|
1355
|
|
|
t.id_first_msg, t.id_member_started, |
|
1356
|
|
|
mb.real_name, m.modified_time |
|
1357
|
|
|
FROM {db_prefix}calendar AS c |
|
1358
|
|
|
LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = c.id_topic) |
|
1359
|
|
|
LEFT JOIN {db_prefix}members AS mb ON (mb.id_member = t.id_member_started) |
|
1360
|
|
|
LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg) |
|
1361
|
|
|
WHERE c.id_event = {int:id_event}', |
|
1362
|
|
|
array( |
|
1363
|
|
|
'id_event' => $event_id, |
|
1364
|
|
|
) |
|
1365
|
|
|
); |
|
1366
|
|
|
|
|
1367
|
|
|
// If nothing returned, we are in poo, poo. |
|
1368
|
|
|
if ($smcFunc['db_num_rows']($request) === 0) |
|
1369
|
|
|
return false; |
|
1370
|
|
|
|
|
1371
|
|
|
$row = $smcFunc['db_fetch_assoc']($request); |
|
1372
|
|
|
$smcFunc['db_free_result']($request); |
|
1373
|
|
|
|
|
1374
|
|
|
list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
|
1375
|
|
|
|
|
1376
|
|
|
// Sanity check |
|
1377
|
|
|
if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
1378
|
|
|
return false; |
|
1379
|
|
|
|
|
1380
|
|
|
$return_value = array( |
|
1381
|
|
|
'boards' => array(), |
|
1382
|
|
|
'board' => $row['id_board'], |
|
1383
|
|
|
'new' => 0, |
|
1384
|
|
|
'eventid' => $event_id, |
|
1385
|
|
|
'year' => $start['year'], |
|
1386
|
|
|
'month' => $start['month'], |
|
1387
|
|
|
'day' => $start['day'], |
|
1388
|
|
|
'hour' => !$allday ? $start['hour'] : null, |
|
1389
|
|
|
'minute' => !$allday ? $start['minute'] : null, |
|
1390
|
|
|
'second' => !$allday ? $start['second'] : null, |
|
1391
|
|
|
'start_date' => $row['start_date'], |
|
1392
|
|
|
'start_date_local' => $start['date_local'], |
|
1393
|
|
|
'start_date_orig' => $start['date_orig'], |
|
1394
|
|
|
'start_time' => !$allday ? $row['start_time'] : null, |
|
1395
|
|
|
'start_time_local' => !$allday ? $start['time_local'] : null, |
|
1396
|
|
|
'start_time_orig' => !$allday ? $start['time_orig'] : null, |
|
1397
|
|
|
'start_timestamp' => $start['timestamp'], |
|
1398
|
|
|
'start_datetime' => $start['datetime'], |
|
1399
|
|
|
'start_iso_gmdate' => $start['iso_gmdate'], |
|
1400
|
|
|
'end_year' => $end['year'], |
|
1401
|
|
|
'end_month' => $end['month'], |
|
1402
|
|
|
'end_day' => $end['day'], |
|
1403
|
|
|
'end_hour' => !$allday ? $end['hour'] : null, |
|
1404
|
|
|
'end_minute' => !$allday ? $end['minute'] : null, |
|
1405
|
|
|
'end_second' => !$allday ? $end['second'] : null, |
|
1406
|
|
|
'end_date' => $row['end_date'], |
|
1407
|
|
|
'end_date_local' => $end['date_local'], |
|
1408
|
|
|
'end_date_orig' => $end['date_orig'], |
|
1409
|
|
|
'end_time' => !$allday ? $row['end_time'] : null, |
|
1410
|
|
|
'end_time_local' => !$allday ? $end['time_local'] : null, |
|
1411
|
|
|
'end_time_orig' => !$allday ? $end['time_orig'] : null, |
|
1412
|
|
|
'end_timestamp' => $end['timestamp'], |
|
1413
|
|
|
'end_datetime' => $end['datetime'], |
|
1414
|
|
|
'end_iso_gmdate' => $end['iso_gmdate'], |
|
1415
|
|
|
'allday' => $allday, |
|
1416
|
|
|
'tz' => !$allday ? $tz : null, |
|
1417
|
|
|
'tz_abbrev' => !$allday ? $tz_abbrev : null, |
|
1418
|
|
|
'span' => $span, |
|
1419
|
|
|
'title' => $row['title'], |
|
1420
|
|
|
'location' => $row['location'], |
|
1421
|
|
|
'member' => $row['id_member'], |
|
1422
|
|
|
'realname' => $row['real_name'], |
|
1423
|
|
|
'sequence' => $row['modified_time'], |
|
1424
|
|
|
'topic' => array( |
|
1425
|
|
|
'id' => $row['id_topic'], |
|
1426
|
|
|
'member_started' => $row['id_member_started'], |
|
1427
|
|
|
'first_msg' => $row['id_first_msg'], |
|
1428
|
|
|
), |
|
1429
|
|
|
); |
|
1430
|
|
|
|
|
1431
|
|
|
$return_value['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $return_value['month'] == 12 ? 1 : $return_value['month'] + 1, 0, $return_value['month'] == 12 ? $return_value['year'] + 1 : $return_value['year'])); |
|
1432
|
|
|
|
|
1433
|
|
|
return $return_value; |
|
1434
|
|
|
} |
|
1435
|
|
|
|
|
1436
|
|
|
/** |
|
1437
|
|
|
* Gets an initial set of date and time values for creating a new event. |
|
1438
|
|
|
* |
|
1439
|
|
|
* @return array An array containing an initial set of date and time values for an event. |
|
1440
|
|
|
*/ |
|
1441
|
|
|
function getNewEventDatetimes() |
|
1442
|
|
|
{ |
|
1443
|
|
|
// Ensure setEventStartEnd() has something to work with |
|
1444
|
|
|
$now = date_create(); |
|
1445
|
|
|
$tz = getUserTimezone(); |
|
1446
|
|
|
date_timezone_set($now, timezone_open($tz)); |
|
1447
|
|
|
|
|
1448
|
|
|
$_POST['year'] = !empty($_POST['year']) ? $_POST['year'] : date_format($now, 'Y'); |
|
1449
|
|
|
$_POST['month'] = !empty($_POST['month']) ? $_POST['month'] : date_format($now, 'm'); |
|
1450
|
|
|
$_POST['day'] = !empty($_POST['day']) ? $_POST['day'] : date_format($now, 'd'); |
|
1451
|
|
|
$_POST['hour'] = !empty($_POST['hour']) ? $_POST['hour'] : date_format($now, 'H'); |
|
1452
|
|
|
$_POST['minute'] = !empty($_POST['minute']) ? $_POST['minute'] : date_format($now, 'i'); |
|
1453
|
|
|
$_POST['second'] = !empty($_POST['second']) ? $_POST['second'] : date_format($now, 's'); |
|
1454
|
|
|
|
|
1455
|
|
|
// Set the basic values for the new event |
|
1456
|
|
|
$row_keys = array('start_date', 'end_date', 'start_time', 'end_time', 'timezone'); |
|
1457
|
|
|
$row = array_combine($row_keys, setEventStartEnd()); |
|
1458
|
|
|
|
|
1459
|
|
|
// And now set the full suite of values |
|
1460
|
|
|
list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
|
1461
|
|
|
|
|
1462
|
|
|
// Default theme only uses some of this info, but others might want it all |
|
1463
|
|
|
$eventProperties = array( |
|
1464
|
|
|
'year' => $start['year'], |
|
1465
|
|
|
'month' => $start['month'], |
|
1466
|
|
|
'day' => $start['day'], |
|
1467
|
|
|
'hour' => !$allday ? $start['hour'] : null, |
|
1468
|
|
|
'minute' => !$allday ? $start['minute'] : null, |
|
1469
|
|
|
'second' => !$allday ? $start['second'] : null, |
|
1470
|
|
|
'start_date' => $row['start_date'], |
|
1471
|
|
|
'start_date_local' => $start['date_local'], |
|
1472
|
|
|
'start_date_orig' => $start['date_orig'], |
|
1473
|
|
|
'start_time' => !$allday ? $row['start_time'] : null, |
|
1474
|
|
|
'start_time_local' => !$allday ? $start['time_local'] : null, |
|
1475
|
|
|
'start_time_orig' => !$allday ? $start['time_orig'] : null, |
|
1476
|
|
|
'start_timestamp' => $start['timestamp'], |
|
1477
|
|
|
'start_datetime' => $start['datetime'], |
|
1478
|
|
|
'start_iso_gmdate' => $start['iso_gmdate'], |
|
1479
|
|
|
'end_year' => $end['year'], |
|
1480
|
|
|
'end_month' => $end['month'], |
|
1481
|
|
|
'end_day' => $end['day'], |
|
1482
|
|
|
'end_hour' => !$allday ? $end['hour'] : null, |
|
1483
|
|
|
'end_minute' => !$allday ? $end['minute'] : null, |
|
1484
|
|
|
'end_second' => !$allday ? $end['second'] : null, |
|
1485
|
|
|
'end_date' => $row['end_date'], |
|
1486
|
|
|
'end_date_local' => $end['date_local'], |
|
1487
|
|
|
'end_date_orig' => $end['date_orig'], |
|
1488
|
|
|
'end_time' => !$allday ? $row['end_time'] : null, |
|
1489
|
|
|
'end_time_local' => !$allday ? $end['time_local'] : null, |
|
1490
|
|
|
'end_time_orig' => !$allday ? $end['time_orig'] : null, |
|
1491
|
|
|
'end_timestamp' => $end['timestamp'], |
|
1492
|
|
|
'end_datetime' => $end['datetime'], |
|
1493
|
|
|
'end_iso_gmdate' => $end['iso_gmdate'], |
|
1494
|
|
|
'allday' => $allday, |
|
1495
|
|
|
'tz' => !$allday ? $tz : null, |
|
1496
|
|
|
'tz_abbrev' => !$allday ? $tz_abbrev : null, |
|
1497
|
|
|
'span' => $span, |
|
1498
|
|
|
); |
|
1499
|
|
|
|
|
1500
|
|
|
return $eventProperties; |
|
1501
|
|
|
} |
|
1502
|
|
|
|
|
1503
|
|
|
/** |
|
1504
|
|
|
* Set the start and end dates and times for a posted event for insertion into the database. |
|
1505
|
|
|
* Validates all date and times given to it. |
|
1506
|
|
|
* Makes sure events do not exceed the maximum allowed duration (if any). |
|
1507
|
|
|
* If passed an array that defines any time or date parameters, they will be used. Otherwise, gets the values from $_POST. |
|
1508
|
|
|
* |
|
1509
|
|
|
* @param array $eventOptions An array of optional time and date parameters (span, start_year, end_month, etc., etc.) |
|
1510
|
|
|
* @return array An array containing $start_date, $end_date, $start_time, $end_time |
|
1511
|
|
|
*/ |
|
1512
|
|
|
function setEventStartEnd($eventOptions = array()) |
|
1513
|
|
|
{ |
|
1514
|
|
|
global $modSettings; |
|
1515
|
|
|
|
|
1516
|
|
|
// Set $span, in case we need it |
|
1517
|
|
|
$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0); |
|
1518
|
|
|
if ($span > 0) |
|
1519
|
|
|
$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
1520
|
|
|
|
|
1521
|
|
|
// Define the timezone for this event, falling back to the default if not provided |
|
1522
|
|
|
if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
|
|
|
|
|
1523
|
|
|
$tz = $eventOptions['tz']; |
|
1524
|
|
|
elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
|
|
|
|
|
1525
|
|
|
$tz = $_POST['tz']; |
|
1526
|
|
|
else |
|
1527
|
|
|
$tz = getUserTimezone(); |
|
1528
|
|
|
|
|
1529
|
|
|
// Is this supposed to be an all day event, or should it have specific start and end times? |
|
1530
|
|
|
if (isset($eventOptions['allday'])) |
|
1531
|
|
|
$allday = $eventOptions['allday']; |
|
1532
|
|
|
elseif (empty($_POST['allday'])) |
|
1533
|
|
|
$allday = false; |
|
1534
|
|
|
else |
|
1535
|
|
|
$allday = true; |
|
1536
|
|
|
|
|
1537
|
|
|
// Input might come as individual parameters... |
|
1538
|
|
|
$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null); |
|
1539
|
|
|
$start_month = isset($eventOptions['month']) ? $eventOptions['month'] : (isset($_POST['month']) ? $_POST['month'] : null); |
|
1540
|
|
|
$start_day = isset($eventOptions['day']) ? $eventOptions['day'] : (isset($_POST['day']) ? $_POST['day'] : null); |
|
1541
|
|
|
$start_hour = isset($eventOptions['hour']) ? $eventOptions['hour'] : (isset($_POST['hour']) ? $_POST['hour'] : null); |
|
1542
|
|
|
$start_minute = isset($eventOptions['minute']) ? $eventOptions['minute'] : (isset($_POST['minute']) ? $_POST['minute'] : null); |
|
1543
|
|
|
$start_second = isset($eventOptions['second']) ? $eventOptions['second'] : (isset($_POST['second']) ? $_POST['second'] : null); |
|
1544
|
|
|
$end_year = isset($eventOptions['end_year']) ? $eventOptions['end_year'] : (isset($_POST['end_year']) ? $_POST['end_year'] : null); |
|
1545
|
|
|
$end_month = isset($eventOptions['end_month']) ? $eventOptions['end_month'] : (isset($_POST['end_month']) ? $_POST['end_month'] : null); |
|
1546
|
|
|
$end_day = isset($eventOptions['end_day']) ? $eventOptions['end_day'] : (isset($_POST['end_day']) ? $_POST['end_day'] : null); |
|
1547
|
|
|
$end_hour = isset($eventOptions['end_hour']) ? $eventOptions['end_hour'] : (isset($_POST['end_hour']) ? $_POST['end_hour'] : null); |
|
1548
|
|
|
$end_minute = isset($eventOptions['end_minute']) ? $eventOptions['end_minute'] : (isset($_POST['end_minute']) ? $_POST['end_minute'] : null); |
|
1549
|
|
|
$end_second = isset($eventOptions['end_second']) ? $eventOptions['end_second'] : (isset($_POST['end_second']) ? $_POST['end_second'] : null); |
|
1550
|
|
|
|
|
1551
|
|
|
// ... or as datetime strings ... |
|
1552
|
|
|
$start_string = isset($eventOptions['start_datetime']) ? $eventOptions['start_datetime'] : (isset($_POST['start_datetime']) ? $_POST['start_datetime'] : null); |
|
1553
|
|
|
$end_string = isset($eventOptions['end_datetime']) ? $eventOptions['end_datetime'] : (isset($_POST['end_datetime']) ? $_POST['end_datetime'] : null); |
|
1554
|
|
|
|
|
1555
|
|
|
// ... or as date strings and time strings. |
|
1556
|
|
|
$start_date_string = isset($eventOptions['start_date']) ? $eventOptions['start_date'] : (isset($_POST['start_date']) ? $_POST['start_date'] : null); |
|
1557
|
|
|
$start_time_string = isset($eventOptions['start_time']) ? $eventOptions['start_time'] : (isset($_POST['start_time']) ? $_POST['start_time'] : null); |
|
1558
|
|
|
$end_date_string = isset($eventOptions['end_date']) ? $eventOptions['end_date'] : (isset($_POST['end_date']) ? $_POST['end_date'] : null); |
|
1559
|
|
|
$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null); |
|
1560
|
|
|
|
|
1561
|
|
|
// If the date and time were given in separate strings, combine them |
|
1562
|
|
|
if (empty($start_string) && isset($start_date_string)) |
|
1563
|
|
|
$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
1564
|
|
|
if (empty($end_string) && isset($end_date_string)) |
|
1565
|
|
|
$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
1566
|
|
|
|
|
1567
|
|
|
// If some form of string input was given, override individually defined options with it |
|
1568
|
|
|
if (isset($start_string)) |
|
1569
|
|
|
{ |
|
1570
|
|
|
$start_string_parsed = date_parse(convertDateToEnglish($start_string)); |
|
1571
|
|
|
if (empty($start_string_parsed['error_count']) && empty($start_string_parsed['warning_count'])) |
|
1572
|
|
|
{ |
|
1573
|
|
|
if ($start_string_parsed['year'] != false) |
|
1574
|
|
|
{ |
|
1575
|
|
|
$start_year = $start_string_parsed['year']; |
|
1576
|
|
|
$start_month = $start_string_parsed['month']; |
|
1577
|
|
|
$start_day = $start_string_parsed['day']; |
|
1578
|
|
|
} |
|
1579
|
|
|
if ($start_string_parsed['hour'] != false) |
|
1580
|
|
|
{ |
|
1581
|
|
|
$start_hour = $start_string_parsed['hour']; |
|
1582
|
|
|
$start_minute = $start_string_parsed['minute']; |
|
1583
|
|
|
$start_second = $start_string_parsed['second']; |
|
1584
|
|
|
} |
|
1585
|
|
|
} |
|
1586
|
|
|
} |
|
1587
|
|
|
if (isset($end_string)) |
|
1588
|
|
|
{ |
|
1589
|
|
|
$end_string_parsed = date_parse(convertDateToEnglish($end_string)); |
|
1590
|
|
|
if (empty($end_string_parsed['error_count']) && empty($end_string_parsed['warning_count'])) |
|
1591
|
|
|
{ |
|
1592
|
|
|
if ($end_string_parsed['year'] != false) |
|
1593
|
|
|
{ |
|
1594
|
|
|
$end_year = $end_string_parsed['year']; |
|
1595
|
|
|
$end_month = $end_string_parsed['month']; |
|
1596
|
|
|
$end_day = $end_string_parsed['day']; |
|
1597
|
|
|
} |
|
1598
|
|
|
if ($end_string_parsed['hour'] != false) |
|
1599
|
|
|
{ |
|
1600
|
|
|
$end_hour = $end_string_parsed['hour']; |
|
1601
|
|
|
$end_minute = $end_string_parsed['minute']; |
|
1602
|
|
|
$end_second = $end_string_parsed['second']; |
|
1603
|
|
|
} |
|
1604
|
|
|
} |
|
1605
|
|
|
} |
|
1606
|
|
|
|
|
1607
|
|
|
// Validate input |
|
1608
|
|
|
$start_date_isvalid = checkdate($start_month, $start_day, $start_year); |
|
1609
|
|
|
$end_date_isvalid = checkdate($end_month, $end_day, $end_year); |
|
1610
|
|
|
|
|
1611
|
|
|
$start_time_isset = (isset($start_hour) && isset($start_minute) && isset($start_second)); |
|
1612
|
|
|
$d = date_parse(sprintf('%02d:%02d:%02d', $start_hour, $start_minute, $start_second)); |
|
1613
|
|
|
$start_time_isvalid = ($d['error_count'] == 0 && $d['warning_count'] == 0) ? true : false; |
|
1614
|
|
|
|
|
1615
|
|
|
$end_time_isset = (isset($end_hour) && isset($end_minute) && isset($end_second)); |
|
1616
|
|
|
$d = date_parse(sprintf('%02d:%02d:%02d', $end_hour, $end_minute, $end_second)); |
|
1617
|
|
|
$end_time_isvalid = ($d['error_count'] == 0 && $d['warning_count'] == 0) ? true : false; |
|
1618
|
|
|
|
|
1619
|
|
|
// Uh-oh... |
|
1620
|
|
|
if ($start_date_isvalid === false) |
|
1621
|
|
|
{ |
|
1622
|
|
|
fatal_lang_error('invalid_date', false); |
|
1623
|
|
|
} |
|
1624
|
|
|
|
|
1625
|
|
|
// Make sure we use valid values for everything |
|
1626
|
|
|
if ($end_date_isvalid === false) |
|
1627
|
|
|
{ |
|
1628
|
|
|
$end_year = $start_year; |
|
1629
|
|
|
$end_month = $start_month; |
|
1630
|
|
|
$end_day = $start_day; |
|
1631
|
|
|
} |
|
1632
|
|
|
|
|
1633
|
|
|
if ($allday === true || $start_time_isset === false || $start_time_isvalid === false) |
|
1634
|
|
|
{ |
|
1635
|
|
|
$allday = true; |
|
1636
|
|
|
$start_hour = 0; |
|
1637
|
|
|
$start_minute = 0; |
|
1638
|
|
|
$start_second = 0; |
|
1639
|
|
|
} |
|
1640
|
|
|
|
|
1641
|
|
|
if ($allday === true || $end_time_isvalid === false || $end_time_isset === false) |
|
1642
|
|
|
{ |
|
1643
|
|
|
$end_hour = $start_hour; |
|
1644
|
|
|
$end_minute = $start_minute; |
|
1645
|
|
|
$end_second = $start_second; |
|
1646
|
|
|
} |
|
1647
|
|
|
|
|
1648
|
|
|
// Now create our datetime objects |
|
1649
|
|
|
$start_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
|
1650
|
|
|
$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $end_year, $end_month, $end_day, $end_hour, $end_minute, $end_second) . ' ' . $tz); |
|
1651
|
|
|
|
|
1652
|
|
|
// Is $end_object too early? |
|
1653
|
|
|
if ($start_object >= $end_object) |
|
1654
|
|
|
{ |
|
1655
|
|
|
$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
|
1656
|
|
|
if ($span > 0) |
|
1657
|
|
|
date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
1658
|
|
|
else |
|
1659
|
|
|
date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
1660
|
|
|
} |
|
1661
|
|
|
|
|
1662
|
|
|
// Is $end_object too late? |
|
1663
|
|
|
if (!empty($modSettings['cal_maxspan'])) |
|
1664
|
|
|
{ |
|
1665
|
|
|
$date_diff = date_diff($start_object, $end_object); |
|
1666
|
|
|
if ($date_diff->days > $modSettings['cal_maxspan']) |
|
1667
|
|
|
{ |
|
1668
|
|
|
if ($modSettings['cal_maxspan'] > 1) |
|
1669
|
|
|
{ |
|
1670
|
|
|
$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
|
1671
|
|
|
date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days')); |
|
1672
|
|
|
} |
|
1673
|
|
|
else |
|
1674
|
|
|
$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
1675
|
|
|
} |
|
1676
|
|
|
} |
|
1677
|
|
|
|
|
1678
|
|
|
// Finally, make our strings |
|
1679
|
|
|
$start_date = date_format($start_object, 'Y-m-d'); |
|
1680
|
|
|
$end_date = date_format($end_object, 'Y-m-d'); |
|
1681
|
|
|
|
|
1682
|
|
|
if ($allday == true) |
|
1683
|
|
|
{ |
|
1684
|
|
|
$start_time = null; |
|
1685
|
|
|
$end_time = null; |
|
1686
|
|
|
$tz = null; |
|
1687
|
|
|
} |
|
1688
|
|
|
else |
|
1689
|
|
|
{ |
|
1690
|
|
|
$start_time = date_format($start_object, 'H:i:s'); |
|
1691
|
|
|
$end_time = date_format($end_object, 'H:i:s'); |
|
1692
|
|
|
} |
|
1693
|
|
|
|
|
1694
|
|
|
return array($start_date, $end_date, $start_time, $end_time, $tz); |
|
1695
|
|
|
} |
|
1696
|
|
|
|
|
1697
|
|
|
/** |
|
1698
|
|
|
* Helper function for getEventRange, getEventProperties, getNewEventDatetimes, etc. |
|
1699
|
|
|
* |
|
1700
|
|
|
* @param array $row A database row representing an event from the calendar table |
|
1701
|
|
|
* @return array An array containing the start and end date and time properties for the event |
|
1702
|
|
|
*/ |
|
1703
|
|
|
function buildEventDatetimes($row) |
|
1704
|
|
|
{ |
|
1705
|
|
|
global $sourcedir, $user_info, $txt; |
|
1706
|
|
|
static $date_format = '', $time_format = ''; |
|
1707
|
|
|
|
|
1708
|
|
|
require_once($sourcedir . '/Subs.php'); |
|
1709
|
|
|
static $timezone_array = array(); |
|
1710
|
|
|
|
|
1711
|
|
|
loadLanguage('Timezones'); |
|
1712
|
|
|
|
|
1713
|
|
|
// First, try to create a better date format, ignoring the "time" elements. |
|
1714
|
|
|
if (empty($date_format)) |
|
1715
|
|
|
$date_format = get_date_or_time_format('date'); |
|
1716
|
|
|
|
|
1717
|
|
|
// We want a fairly compact version of the time, but as close as possible to the user's settings. |
|
1718
|
|
|
if (empty($time_format)) |
|
1719
|
|
|
$time_format = strtr(get_date_or_time_format('time'), array( |
|
1720
|
|
|
'%I' => '%l', |
|
1721
|
|
|
'%H' => '%k', |
|
1722
|
|
|
'%S' => '', |
|
1723
|
|
|
'%r' => '%l:%M %p', |
|
1724
|
|
|
'%R' => '%k:%M', |
|
1725
|
|
|
'%T' => '%l:%M', |
|
1726
|
|
|
)); |
|
1727
|
|
|
|
|
1728
|
|
|
// Should this be an all day event? |
|
1729
|
|
|
$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false; |
|
|
|
|
|
|
1730
|
|
|
|
|
1731
|
|
|
// How many days does this event span? |
|
1732
|
|
|
$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d'); |
|
1733
|
|
|
|
|
1734
|
|
|
// We need to have a defined timezone in the steps below |
|
1735
|
|
|
if (empty($row['timezone'])) |
|
1736
|
|
|
$row['timezone'] = getUserTimezone(); |
|
1737
|
|
|
|
|
1738
|
|
|
if (empty($timezone_array[$row['timezone']])) |
|
1739
|
|
|
$timezone_array[$row['timezone']] = timezone_open($row['timezone']); |
|
1740
|
|
|
|
|
1741
|
|
|
// Get most of the standard date information for the start and end datetimes |
|
1742
|
|
|
$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : '')); |
|
1743
|
|
|
$end = date_parse($row['end_date'] . (!$allday ? ' ' . $row['end_time'] : '')); |
|
1744
|
|
|
|
|
1745
|
|
|
// But we also want more info, so make some DateTime objects we can use |
|
1746
|
|
|
$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), $timezone_array[$row['timezone']]); |
|
1747
|
|
|
$end_object = date_create($row['end_date'] . (!$allday ? ' ' . $row['end_time'] : ''), $timezone_array[$row['timezone']]); |
|
1748
|
|
|
|
|
1749
|
|
|
// Unix timestamps are good |
|
1750
|
|
|
$start['timestamp'] = date_format($start_object, 'U'); |
|
1751
|
|
|
$end['timestamp'] = date_format($end_object, 'U'); |
|
1752
|
|
|
|
|
1753
|
|
|
// Datetime string without timezone (e.g. '2016-12-28 22:45:30') |
|
1754
|
|
|
$start['datetime'] = date_format($start_object, 'Y-m-d H:i:s'); |
|
1755
|
|
|
$end['datetime'] = date_format($start_object, 'Y-m-d H:i:s'); |
|
1756
|
|
|
|
|
1757
|
|
|
// ISO formatted datetime string, relative to UTC (e.g. '2016-12-29T05:45:30+00:00') |
|
1758
|
|
|
$start['iso_gmdate'] = gmdate('c', $start['timestamp']); |
|
1759
|
|
|
$end['iso_gmdate'] = gmdate('c', $end['timestamp']); |
|
1760
|
|
|
|
|
1761
|
|
|
// Strings showing the datetimes in the user's preferred format, relative to the user's time zone |
|
1762
|
|
|
list($start['date_local'], $start['time_local']) = explode(' § ', timeformat($start['timestamp'], $date_format . ' § ' . $time_format)); |
|
|
|
|
|
|
1763
|
|
|
list($end['date_local'], $end['time_local']) = explode(' § ', timeformat($end['timestamp'], $date_format . ' § ' . $time_format)); |
|
1764
|
|
|
|
|
1765
|
|
|
// Strings showing the datetimes in the user's preferred format, relative to the event's time zone |
|
1766
|
|
|
list($start['date_orig'], $start['time_orig']) = explode(' § ', timeformat(strtotime(date_format($start_object, 'Y-m-d H:i:s')), $date_format . ' § ' . $time_format, 'none')); |
|
1767
|
|
|
list($end['date_orig'], $end['time_orig']) = explode(' § ', timeformat(strtotime(date_format($end_object, 'Y-m-d H:i:s')), $date_format . ' § ' . $time_format, 'none')); |
|
1768
|
|
|
|
|
1769
|
|
|
// The time zone identifier (e.g. 'Europe/London') and abbreviation (e.g. 'GMT') |
|
1770
|
|
|
$tz = date_format($start_object, 'e'); |
|
1771
|
|
|
$tz_abbrev = date_format($start_object, 'T'); |
|
1772
|
|
|
|
|
1773
|
|
|
// If the abbreviation is just a numerical offset from UTC, make that clear. |
|
1774
|
|
|
if (strspn($tz_abbrev, '+-') > 0) |
|
1775
|
|
|
$tz_abbrev = 'UTC' . $tz_abbrev; |
|
1776
|
|
|
|
|
1777
|
|
|
return array($start, $end, $allday, $span, $tz, $tz_abbrev); |
|
1778
|
|
|
} |
|
1779
|
|
|
|
|
1780
|
|
|
/** |
|
1781
|
|
|
* Gets all of the holidays for the listing |
|
1782
|
|
|
* |
|
1783
|
|
|
* @param int $start The item to start with (for pagination purposes) |
|
1784
|
|
|
* @param int $items_per_page How many items to show on each page |
|
1785
|
|
|
* @param string $sort A string indicating how to sort the results |
|
1786
|
|
|
* @return array An array of holidays, each of which is an array containing the id, year, month, day and title of the holiday |
|
1787
|
|
|
*/ |
|
1788
|
|
|
function list_getHolidays($start, $items_per_page, $sort) |
|
1789
|
|
|
{ |
|
1790
|
|
|
global $smcFunc; |
|
1791
|
|
|
|
|
1792
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1793
|
|
|
SELECT id_holiday, YEAR(event_date) AS year, MONTH(event_date) AS month, DAYOFMONTH(event_date) AS day, title |
|
1794
|
|
|
FROM {db_prefix}calendar_holidays |
|
1795
|
|
|
ORDER BY {raw:sort} |
|
1796
|
|
|
LIMIT {int:start}, {int:max}', |
|
1797
|
|
|
array( |
|
1798
|
|
|
'sort' => $sort, |
|
1799
|
|
|
'start' => $start, |
|
1800
|
|
|
'max' => $items_per_page, |
|
1801
|
|
|
) |
|
1802
|
|
|
); |
|
1803
|
|
|
$holidays = array(); |
|
1804
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1805
|
|
|
$holidays[] = $row; |
|
1806
|
|
|
$smcFunc['db_free_result']($request); |
|
1807
|
|
|
|
|
1808
|
|
|
return $holidays; |
|
1809
|
|
|
} |
|
1810
|
|
|
|
|
1811
|
|
|
/** |
|
1812
|
|
|
* Helper function to get the total number of holidays |
|
1813
|
|
|
* |
|
1814
|
|
|
* @return int The total number of holidays |
|
1815
|
|
|
*/ |
|
1816
|
|
|
function list_getNumHolidays() |
|
1817
|
|
|
{ |
|
1818
|
|
|
global $smcFunc; |
|
1819
|
|
|
|
|
1820
|
|
|
$request = $smcFunc['db_query']('', ' |
|
1821
|
|
|
SELECT COUNT(*) |
|
1822
|
|
|
FROM {db_prefix}calendar_holidays', |
|
1823
|
|
|
array( |
|
1824
|
|
|
) |
|
1825
|
|
|
); |
|
1826
|
|
|
list($num_items) = $smcFunc['db_fetch_row']($request); |
|
1827
|
|
|
$smcFunc['db_free_result']($request); |
|
1828
|
|
|
|
|
1829
|
|
|
return (int) $num_items; |
|
1830
|
|
|
} |
|
1831
|
|
|
|
|
1832
|
|
|
/** |
|
1833
|
|
|
* Remove a holiday from the calendar |
|
1834
|
|
|
* |
|
1835
|
|
|
* @param array $holiday_ids An array of IDs of holidays to delete |
|
1836
|
|
|
*/ |
|
1837
|
|
|
function removeHolidays($holiday_ids) |
|
1838
|
|
|
{ |
|
1839
|
|
|
global $smcFunc; |
|
1840
|
|
|
|
|
1841
|
|
|
$smcFunc['db_query']('', ' |
|
1842
|
|
|
DELETE FROM {db_prefix}calendar_holidays |
|
1843
|
|
|
WHERE id_holiday IN ({array_int:id_holiday})', |
|
1844
|
|
|
array( |
|
1845
|
|
|
'id_holiday' => $holiday_ids, |
|
1846
|
|
|
) |
|
1847
|
|
|
); |
|
1848
|
|
|
|
|
1849
|
|
|
updateSettings(array( |
|
1850
|
|
|
'calendar_updated' => time(), |
|
1851
|
|
|
)); |
|
1852
|
|
|
} |
|
1853
|
|
|
|
|
1854
|
|
|
/** |
|
1855
|
|
|
* Helper function to convert date string to english |
|
1856
|
|
|
* so that date_parse can parse the date |
|
1857
|
|
|
* |
|
1858
|
|
|
* @param string $date A localized date string |
|
1859
|
|
|
* @return string English date string |
|
1860
|
|
|
*/ |
|
1861
|
|
|
function convertDateToEnglish($date) |
|
1862
|
|
|
{ |
|
1863
|
|
|
global $txt, $context; |
|
1864
|
|
|
|
|
1865
|
|
|
if ($context['user']['language'] == 'english') |
|
1866
|
|
|
return $date; |
|
1867
|
|
|
|
|
1868
|
|
|
return strtr($date, array_combine(array_merge($txt['months_titles'], $txt['months_short']), array_merge(array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')))); |
|
1869
|
|
|
} |
|
1870
|
|
|
|
|
1871
|
|
|
?> |