Issues (1061)

Themes/default/Calendar.template.php (5 issues)

1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines https://www.simplemachines.org
7
 * @copyright 2020 Simple Machines and individual contributors
8
 * @license https://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 RC2
11
 */
12
13
/**
14
 * Our main calendar template, which encapsulates weeks and months.
15
 */
16
function template_main()
17
{
18
	global $context;
19
20
	// The main calendar wrapper.
21
	echo '
22
		<div id="calendar">';
23
24
	// Show the mini-blocks if they're enabled.
25
	if (empty($context['blocks_disabled']))
26
		echo '
27
			<div id="month_grid">
28
				', template_show_month_grid('prev', true), '
29
				', template_show_month_grid('current', true), '
30
				', template_show_month_grid('next', true), '
31
			</div>';
32
33
	// What view are we showing?
34
	if ($context['calendar_view'] == 'viewlist')
35
		echo '
36
			<div id="main_grid">
37
				', template_show_upcoming_list('main'), '
38
			</div>';
39
	elseif ($context['calendar_view'] == 'viewweek')
40
		echo '
41
			<div id="main_grid">
42
				', template_show_week_grid('main'), '
43
			</div>';
44
	else
45
		echo '
46
			<div id="main_grid">
47
				', template_show_month_grid('main'), '
48
			</div>';
49
50
	// Close our wrapper.
51
	echo '
52
		</div><!-- #calendar -->';
53
}
54
55
/**
56
 * Display a list of upcoming events, birthdays, and holidays.
57
 *
58
 * @param string $grid_name The grid name
59
 * @return void|bool Returns false if the grid doesn't exist.
60
 */
61
function template_show_upcoming_list($grid_name)
62
{
63
	global $context, $scripturl, $txt;
64
65
	// Bail out if we have nothing to work with
66
	if (!isset($context['calendar_grid_' . $grid_name]))
67
		return false;
68
69
	// Protect programmer sanity
70
	$calendar_data = &$context['calendar_grid_' . $grid_name];
71
72
	// Do we want a title?
73
	if (empty($calendar_data['disable_title']))
74
		echo '
75
			<div class="cat_bar">
76
				<h3 class="catbg centertext largetext">
77
					<a href="', $scripturl, '?action=calendar;viewlist;year=', $calendar_data['start_year'], ';month=', $calendar_data['start_month'], ';day=', $calendar_data['start_day'], '">', $txt['calendar_upcoming'], '</a>
78
				</h3>
79
			</div>';
80
81
	// Give the user some controls to work with
82
	template_calendar_top($calendar_data);
83
84
	// Output something just so people know it's not broken
85
	if (empty($calendar_data['events']) && empty($calendar_data['birthdays']) && empty($calendar_data['holidays']))
86
		echo '
87
			<div class="descbox">', $txt['calendar_empty'], '</div>';
88
89
	// First, list any events
90
	if (!empty($calendar_data['events']))
91
	{
92
		echo '
93
			<div>
94
				<div class="title_bar">
95
					<h3 class="titlebg">', str_replace(':', '', $txt['events']), '</h3>
96
				</div>
97
				<ul>';
98
99
		foreach ($calendar_data['events'] as $date => $date_events)
100
		{
101
			foreach ($date_events as $event)
102
			{
103
				echo '
104
					<li class="windowbg">
105
						<strong class="event_title">', $event['link'], '</strong>';
106
107
				if ($event['can_edit'])
108
					echo ' <a href="' . $event['modify_href'] . '"><span class="main_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
109
110
				if ($event['can_export'])
111
					echo ' <a href="' . $event['export_href'] . '"><span class="main_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
112
113
				echo '
114
						<br>';
115
116
				if (!empty($event['allday']))
117
				{
118
					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
119
				}
120
				else
121
				{
122
					// Display event info relative to user's local timezone
123
					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
124
125
					if ($event['start_date_local'] != $event['end_date_local'])
126
						echo trim($event['end_date_local']) . ', ';
127
128
					echo trim($event['end_time_local']);
129
130
					// Display event info relative to original timezone
131
					if ($event['start_date_local'] . $event['start_time_local'] != $event['start_date_orig'] . $event['start_time_orig'])
132
					{
133
						echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
134
135
						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
136
							echo trim($event['start_date_orig']), ', ';
137
138
						echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
139
140
						if ($event['start_date_orig'] != $event['end_date_orig'])
141
							echo trim($event['end_date_orig']) . ', ';
142
143
						echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
144
					}
145
					// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
146
					else
147
						echo ' ', $event['tz_abbrev'], '</time>';
148
				}
149
150
				if (!empty($event['location']))
151
					echo '<br>', $event['location'];
152
153
				echo '
154
					</li>';
155
			}
156
		}
157
158
		echo '
159
				</ul>
160
			</div>';
161
	}
162
163
	// Next, list any birthdays
164
	if (!empty($calendar_data['birthdays']))
165
	{
166
		echo '
167
			<div>
168
				<div class="title_bar">
169
					<h3 class="titlebg">', str_replace(':', '', $txt['birthdays']), '</h3>
170
				</div>
171
				<div class="windowbg">';
172
173
		foreach ($calendar_data['birthdays'] as $date)
174
		{
175
			echo '
176
					<p class="inline">
177
						<strong>', $date['date_local'], '</strong>: ';
178
179
			unset($date['date_local']);
180
181
			$birthdays = array();
182
183
			foreach ($date as $member)
184
				$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
185
186
			echo implode(', ', $birthdays);
187
188
			echo '
189
					</p>';
190
		}
191
192
		echo '
193
				</div><!-- .windowbg -->
194
			</div>';
195
	}
196
197
	// Finally, list any holidays
198
	if (!empty($calendar_data['holidays']))
199
	{
200
		echo '
201
			<div>
202
				<div class="title_bar">
203
					<h3 class="titlebg">', str_replace(':', '', $txt['calendar_prompt']), '</h3>
204
				</div>
205
				<div class="windowbg">
206
					<p class="inline holidays">';
207
208
		$holidays = array();
209
210
		foreach ($calendar_data['holidays'] as $date)
211
		{
212
			$date_local = $date['date_local'];
213
			unset($date['date_local']);
214
215
			foreach ($date as $holiday)
216
				$holidays[] = $holiday . ' (' . $date_local . ')';
217
		}
218
219
		echo implode(', ', $holidays);
220
221
		echo '
222
					</p>
223
				</div><!-- .windowbg -->
224
			</div>';
225
	}
226
}
227
228
/**
229
 * Display a monthly calendar grid.
230
 *
231
 * @param string $grid_name The grid name
232
 * @param bool $is_mini Is this a mini grid?
233
 * @return void|bool Returns false if the grid doesn't exist.
234
 */
235
function template_show_month_grid($grid_name, $is_mini = false)
236
{
237
	global $context, $txt, $scripturl, $modSettings;
238
239
	// If the grid doesn't exist, no point in proceeding.
240
	if (!isset($context['calendar_grid_' . $grid_name]))
241
		return false;
242
243
	// A handy little pointer variable.
244
	$calendar_data = &$context['calendar_grid_' . $grid_name];
245
246
	// Some conditions for whether or not we should show the week links *here*.
247
	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false)))
248
		$show_week_links = true;
249
	else
250
		$show_week_links = false;
251
252
	// Assuming that we've not disabled it, show the title block!
253
	if (empty($calendar_data['disable_title']))
254
	{
255
		echo '
256
			<div class="cat_bar">
257
				<h3 class="catbg centertext largetext">';
258
259
		// Previous Link: If we're showing prev / next and it's not a mini-calendar.
260
		if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
261
			echo '
262
					<span class="floatleft">
263
						<a href="', $calendar_data['previous_calendar']['href'], '">&#171;</a>
264
					</span>';
265
266
		// Next Link: if we're showing prev / next and it's not a mini-calendar.
267
		if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
268
			echo '
269
					<span class="floatright">
270
						<a href="', $calendar_data['next_calendar']['href'], '">&#187;</a>
271
					</span>';
272
273
		// Arguably the most exciting part, the title!
274
		echo '
275
					<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $calendar_data['current_day'], '">', $txt['months_titles'][$calendar_data['current_month']], ' ', $calendar_data['current_year'], '</a>
276
				</h3>
277
			</div><!-- .cat_bar -->';
278
	}
279
280
	// Show the controls on main grids
281
	if ($is_mini === false)
282
		template_calendar_top($calendar_data);
283
284
	// Finally, the main calendar table.
285
	echo '
286
			<table class="calendar_table">';
287
288
	// Show each day of the week.
289
	if (empty($calendar_data['disable_day_titles']))
290
	{
291
		echo '
292
				<tr>';
293
294
		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
295
		if ($show_week_links === true)
296
			echo '
297
					<th></th>';
298
299
		// Now, loop through each actual day of the week.
300
		foreach ($calendar_data['week_days'] as $day)
301
			echo '
302
					<th class="days" scope="col">', !empty($calendar_data['short_day_titles']) || $is_mini === true ? $txt['days_short'][$day] : $txt['days'][$day], '</th>';
303
304
		echo '
305
				</tr>';
306
	}
307
308
	// Our looping begins on a per-week basis.
309
	foreach ($calendar_data['weeks'] as $week)
310
	{
311
		// Some useful looping variables.
312
		$current_month_started = false;
313
		$count = 1;
314
		$final_count = 1;
315
316
		echo '
317
				<tr class="days_wrapper">';
318
319
		// This is where we add the actual week link, if enabled on this location.
320
		if ($show_week_links === true)
321
			echo '
322
					<td class="windowbg weeks">
323
						<a href="', $scripturl, '?action=calendar;viewweek;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $week['days'][0]['day'], '" title="', $txt['calendar_view_week'], '">&#187;</a>
324
					</td>';
325
326
		// Now loop through each day in the week we're on.
327
		foreach ($week['days'] as $day)
328
		{
329
			// What classes should each day inherit? Day is default.
330
			$classes = array('days');
331
			if (!empty($day['day']))
332
			{
333
				$classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
334
335
				// Additional classes are given for events, holidays, and birthdays.
336
				foreach (array('events', 'holidays', 'birthdays') as $event_type)
337
					if (!empty($day[$event_type]))
338
						$classes[] = $event_type;
339
			}
340
			else
341
			{
342
				$classes[] = 'disabled';
343
			}
344
345
			// Now, implode the classes for each day.
346
			echo '
347
					<td class="', implode(' ', $classes), '">';
348
349
			// If it's within this current month, go ahead and begin.
350
			if (!empty($day['day']))
351
			{
352
				// If it's the first day of this month and not a mini-calendar, we'll add the month title - whether short or full.
353
				$title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : '';
354
355
				// The actual day number - be it a link, or just plain old text!
356
				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
357
					echo '
358
						<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
359
				elseif ($is_mini)
360
					echo '
361
						<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
362
				else
363
					echo '
364
						<span class="day_text">', $title_prefix, $day['day'], '</span>';
365
366
				// A lot of stuff, we're not showing on mini-calendars to conserve space.
367
				if ($is_mini === false)
368
				{
369
					// Holidays are always fun, let's show them!
370
					if (!empty($day['holidays']))
371
						echo '
372
						<div class="smalltext holiday">
373
							<span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '
374
						</div>';
375
376
					// Happy Birthday Dear Member!
377
					if (!empty($day['birthdays']))
378
					{
379
						echo '
380
						<div class="smalltext">
381
							<span class="birthday">', $txt['birthdays'], '</span> ';
382
383
						/* Each of the birthdays has:
384
							id, name (person), age (if they have one set?), and is_last. (last in list?) */
385
						$use_js_hide = empty($context['show_all_birthdays']) && count($day['birthdays']) > 15;
386
						$birthday_count = 0;
387
						foreach ($day['birthdays'] as $member)
388
						{
389
							echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', ';
390
391
							// 9...10! Let's stop there.
392
							if ($birthday_count == 10 && $use_js_hide)
393
								// !!TODO - Inline CSS and JavaScript should be moved.
394
								echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').classList.remove(\'hidden\'); document.getElementById(\'bdhidelink_', $day['day'], '\').classList.add(\'hidden\'); return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" class="hidden">, ';
395
396
							++$birthday_count;
397
						}
398
						if ($use_js_hide)
399
							echo '
400
							</span>';
401
402
						echo '
403
						</div><!-- .smalltext -->';
404
					}
405
406
					// Any special posted events?
407
					if (!empty($day['events']))
408
					{
409
						// Sort events by start time (all day events will be listed first)
410
						uasort($day['events'], function($a, $b) {
411
							if ($a['start_timestamp'] == $b['start_timestamp'])
412
								return 0;
413
414
							return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
415
						});
416
417
						echo '
418
						<div class="smalltext lefttext">
419
							<span class="event">', $txt['events'], '</span><br>';
420
421
						/* The events are made up of:
422
							title, href, is_last, can_edit (are they allowed to?), and modify_href. */
423
						foreach ($day['events'] as $event)
424
						{
425
							$event_icons_needed = ($event['can_edit'] || $event['can_export']) ? true : false;
426
427
							echo '
428
							<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">
429
								', $event['link'], '<br>
430
								<span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
431
432
							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
433
								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
434
							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
435
								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
436
							elseif (!empty($event['allday']))
437
								echo $txt['calendar_allday'];
438
439
							echo '
440
								</span>';
441
442
							if (!empty($event['location']))
443
								echo '
444
								<br>
445
								<span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
446
447
							if ($event['can_edit'] || $event['can_export'])
448
							{
449
								echo '
450
								<span class="modify_event_links">';
451
452
								// If they can edit the event, show an icon they can click on....
453
								if ($event['can_edit'])
454
									echo '
455
									<a class="modify_event" href="', $event['modify_href'], '">
456
										<span class="main_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
457
									</a>';
458
459
								// Exporting!
460
								if ($event['can_export'])
461
									echo '
462
									<a class="modify_event" href="', $event['export_href'], '">
463
										<span class="main_icons calendar_export" title="', $txt['calendar_export'], '"></span>
464
									</a>';
465
466
								echo '
467
								</span><br class="clear">';
468
							}
469
470
							echo '
471
							</div><!-- .event_wrapper -->';
472
						}
473
474
						echo '
475
						</div><!-- .smalltext -->';
476
					}
477
				}
478
				$current_month_started = $count;
479
			}
480
			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
481
			elseif ($is_mini === false)
482
			{
483
				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
484
					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
485
				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
486
					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
487
			}
488
489
			// Close this day and increase var count.
490
			echo '
491
					</td>';
492
493
			++$count;
494
		}
495
496
		echo '
497
				</tr>';
498
	}
499
500
	// The end of our main table.
501
	echo '
502
			</table>';
503
}
504
505
/**
506
 * Shows a weekly grid
507
 *
508
 * @param string $grid_name The name of the grid
509
 * @return void|bool Returns false if the grid doesn't exist
510
 */
511
function template_show_week_grid($grid_name)
512
{
513
	global $context, $txt, $scripturl, $modSettings;
514
515
	// We might have no reason to proceed, if the variable isn't there.
516
	if (!isset($context['calendar_grid_' . $grid_name]))
517
		return false;
518
519
	// Handy pointer.
520
	$calendar_data = &$context['calendar_grid_' . $grid_name];
521
522
	// At the very least, we have one month. Possibly two, though.
523
	$iteration = 1;
524
	foreach ($calendar_data['months'] as $month_data)
525
	{
526
		// For our first iteration, we'll add a nice header!
527
		if ($iteration == 1)
528
		{
529
			echo '
530
				<div class="cat_bar">
531
					<h3 class="catbg centertext largetext">';
532
533
			// Previous Week Link...
534
			if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
535
				echo '
536
						<span class="floatleft">
537
							<a href="', $calendar_data['previous_week']['href'], '">&#171;</a>
538
						</span>';
539
540
			// Next Week Link...
541
			if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
542
				echo '
543
						<span class="floatright">
544
							<a href="', $calendar_data['next_week']['href'], '">&#187;</a>
545
						</span>';
546
547
			// "Week beginning <date>"
548
			if (!empty($calendar_data['week_title']))
549
				echo $calendar_data['week_title'];
550
551
			echo '
552
					</h3>
553
				</div><!-- .cat_bar -->';
554
555
			// Show the controls
556
			template_calendar_top($calendar_data);
557
		}
558
559
		// Our actual month...
560
		echo '
561
				<div class="week_month_title">
562
					<a href="', $scripturl, '?action=calendar;month=', $month_data['current_month'], '">
563
						', $txt['months_titles'][$month_data['current_month']], '
564
					</a>
565
				</div>';
566
567
		// The main table grid for $this week.
568
		echo '
569
				<table class="table_grid calendar_week">
570
					<tr>
571
						<th class="days" scope="col">', $txt['calendar_day'], '</th>
572
						<th class="days" scope="col">', $txt['events'], '</th>
573
						<th class="days" scope="col">', $txt['calendar_prompt'], '</th>
574
						<th class="days" scope="col">', $txt['birthdays'], '</th>
575
					</tr>';
576
577
		// Each day of the week.
578
		foreach ($month_data['days'] as $day)
579
		{
580
			// How should we be highlighted or otherwise not...?
581
			$classes = array('days');
582
			$classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
583
584
			echo '
585
					<tr class="days_wrapper">
586
						<td class="', implode(' ', $classes), ' act_day">';
587
588
			// Should the day number be a link?
589
			if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
590
				echo '
591
							<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
592
			else
593
				echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
594
595
			echo '
596
						</td>
597
						<td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">';
598
599
			// Show any events...
600
			if (!empty($day['events']))
601
			{
602
				// Sort events by start time (all day events will be listed first)
603
				uasort($day['events'], function($a, $b) {
604
					if ($a['start_timestamp'] == $b['start_timestamp'])
605
						return 0;
606
					return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
607
				});
608
609
				foreach ($day['events'] as $event)
610
				{
611
					echo '
612
							<div class="event_wrapper">';
613
614
					$event_icons_needed = ($event['can_edit'] || $event['can_export']) ? true : false;
615
616
					echo $event['link'], '<br>
617
								<span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
618
619
					if (!empty($event['start_time_local']))
620
						echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
621
					else
622
						echo $txt['calendar_allday'];
623
624
					echo '
625
								</span>';
626
627
					if (!empty($event['location']))
628
						echo '<br>
629
								<span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
630
631
					if (!empty($event_icons_needed))
632
					{
633
						echo ' <span class="modify_event_links">';
634
635
						// If they can edit the event, show a star they can click on....
636
						if (!empty($event['can_edit']))
637
							echo '
638
									<a class="modify_event" href="', $event['modify_href'], '">
639
										<span class="main_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
640
									</a>';
641
642
						// Can we export? Sweet.
643
						if (!empty($event['can_export']))
644
							echo '
645
									<a class="modify_event" href="', $event['export_href'], '">
646
										<span class="main_icons calendar_export" title="', $txt['calendar_export'], '"></span>
647
									</a>';
648
649
						echo '
650
								</span><br class="clear">';
651
					}
652
653
					echo '
654
							</div><!-- .event_wrapper -->';
655
				}
656
657
				if (!empty($context['can_post']))
658
				{
659
					echo '
660
							<div class="week_add_event">
661
								<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['calendar_post_event'], '</a>
662
							</div>
663
							<br class="clear">';
664
				}
665
			}
666
			else
667
			{
668
				if (!empty($context['can_post']))
669
					echo '
670
							<div class="week_add_event">
671
								<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['calendar_post_event'], '</a>
672
							</div>';
673
			}
674
			echo '
675
						</td>
676
						<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
677
678
			// Show any holidays!
679
			if (!empty($day['holidays']))
680
				echo implode('<br>', $day['holidays']);
681
682
			echo '
683
						</td>
684
						<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
685
686
			// Show any birthdays...
687
			if (!empty($day['birthdays']))
688
			{
689
				foreach ($day['birthdays'] as $member)
690
					echo '
691
							<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], '</a>
692
							', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '
693
							', $member['is_last'] ? '' : '<br>';
694
			}
695
			echo '
696
						</td>
697
					</tr>';
698
		}
699
700
		// Increase iteration for loop counting.
701
		++$iteration;
702
703
		echo '
704
				</table>';
705
	}
706
}
707
708
/**
709
 * Calendar controls under the title
710
 *
711
 * Creates the view selector (list, month, week), the date selector (either a
712
 * select menu or a date range chooser, depending on the circumstances), and the
713
 * "Post Event" button.
714
 *
715
 * @param array $calendar_data The data for the calendar grid that this is for
716
 */
717
function template_calendar_top($calendar_data)
718
{
719
	global $context, $scripturl, $txt;
720
721
	echo '
722
		<div class="calendar_top roundframe', empty($calendar_data['disable_title']) ? ' noup' : '', '">
723
			<div id="calendar_viewselector" class="buttonrow floatleft">
724
				<a href="', $scripturl, '?action=calendar;viewlist;year=', $context['current_year'], ';month=', $context['current_month'], ';day=', $context['current_day'], '" class="button', $context['calendar_view'] == 'viewlist' ? ' active' : '', '">', $txt['calendar_list'], '</a>
725
				<a href="', $scripturl, '?action=calendar;viewmonth;year=', $context['current_year'], ';month=', $context['current_month'], ';day=', $context['current_day'], '" class="button', $context['calendar_view'] == 'viewmonth' ? ' active' : '', '">', $txt['calendar_month'], '</a>
726
				<a href="', $scripturl, '?action=calendar;viewweek;year=', $context['current_year'], ';month=', $context['current_month'], ';day=', $context['current_day'], '" class="button', $context['calendar_view'] == 'viewweek' ? ' active' : '', '">', $txt['calendar_week'], '</a>
727
			</div>
728
			', template_button_strip($context['calendar_buttons'], 'right');
0 ignored issues
show
Are you sure the usage of template_button_strip($c...dar_buttons'], 'right') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
729
730
	echo '
731
			<form action="', $scripturl, '?action=calendar;', $context['calendar_view'], '" id="', !empty($calendar_data['end_date']) ? 'calendar_range' : 'calendar_navigation', '" method="post" accept-charset="', $context['character_set'], '">
732
				<input type="text" name="start_date" id="start_date" maxlength="10" value="', $calendar_data['start_date'], '" tabindex="', $context['tabindex']++, '" class="date_input start" data-type="date">';
733
734
	if (!empty($calendar_data['end_date']))
735
		echo '
736
				<span>', strtolower($txt['to']), '</span>
737
				<input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="date_input end" data-type="date">';
738
739
	echo '
740
				<input type="submit" class="button" style="float:none" id="view_button" value="', $txt['view'], '">
741
			</form>
742
		</div><!-- .calendar_top -->';
743
}
744
745
/**
746
 * Template for posting a calendar event.
747
 */
748
function template_event_post()
749
{
750
	global $context, $txt, $scripturl, $modSettings;
751
752
	echo '
753
		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);">';
754
755
	if (!empty($context['event']['new']))
756
		echo '
757
			<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
758
759
	// Start the main table.
760
	echo '
761
			<div id="post_event">
762
				<div class="cat_bar">
763
					<h3 class="catbg">
764
						', $context['page_title'], '
765
					</h3>
766
				</div>';
767
768
	if (!empty($context['post_error']['messages']))
769
		echo '
770
				<div class="errorbox">
771
					<dl class="event_error">
772
						<dt>
773
							', $context['error_type'] == 'serious' ? '<strong>' . $txt['error_while_submitting'] . '</strong>' : '', '
774
						</dt>
775
						<dt class="error">
776
							', implode('<br>', $context['post_error']['messages']), '
777
						</dt>
778
					</dl>
779
				</div>';
780
781
	echo '
782
				<div class="roundframe noup">
783
					<fieldset id="event_main">
784
						<legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', '>', $txt['calendar_event_title'], '</span></legend>
785
						<input type="hidden" name="calendar" value="1">
786
						<div class="event_options_left" id="event_title">
787
							<div>
788
								<input type="text" id="evtitle" name="evtitle" maxlength="255" size="55" value="', $context['event']['title'], '" tabindex="', $context['tabindex']++, '">
789
							</div>
790
						</div>';
791
792
	// If this is a new event let the user specify which board they want the linked post to be put into.
793
	if ($context['event']['new'] && !empty($context['event']['categories']))
794
	{
795
		echo '
796
						<div class="event_options_right" id="event_board">
797
							<div>
798
								<span class="label">', $txt['calendar_post_in'], '</span>
799
								<input type="checkbox" name="link_to_board"', (!empty($context['event']['board']) ? ' checked' : ''), ' onclick="toggleLinked(this.form);">
800
								<select name="board"', empty($context['event']['board']) ? ' disabled' : '', '>';
801
802
		foreach ($context['event']['categories'] as $category)
803
		{
804
			echo '
805
									<optgroup label="', $category['name'], '">';
806
807
			foreach ($category['boards'] as $board)
808
				echo '
809
										<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
810
			echo '
811
									</optgroup>';
812
		}
813
		echo '
814
								</select>
815
							</div>
816
						</div><!-- #event_board -->';
817
	}
818
819
	// Note to theme writers: The JavaScript expects the input fields for the start and end dates & times to be contained in a wrapper element with the id "event_time_input"
820
	echo '
821
					</fieldset>
822
					<fieldset id="event_options">
823
						<legend>', $txt['calendar_event_options'], '</legend>
824
						<div class="event_options_left" id="event_time_input">
825
							<div>
826
								<span class="label">', $txt['start'], '</span>
827
								<input type="text" name="start_date" id="start_date" maxlength="10" value="', $context['event']['start_date'], '" tabindex="', $context['tabindex']++, '" class="date_input start" data-type="date">
828
								<input type="text" name="start_time" id="start_time" maxlength="11" value="', $context['event']['start_time_local'], '" tabindex="', $context['tabindex']++, '" class="time_input start" data-type="time"', !empty($context['event']['allday']) ? ' disabled' : '', '>
829
							</div>
830
							<div>
831
								<span class="label">', $txt['end'], '</span>
832
								<input type="text" name="end_date" id="end_date" maxlength="10" value="', $context['event']['end_date'], '" tabindex="', $context['tabindex']++, '" class="date_input end" data-type="date"', $modSettings['cal_maxspan'] == 1 ? ' disabled' : '', '>
833
								<input type="text" name="end_time" id="end_time" maxlength="11" value="', $context['event']['end_time_local'], '" tabindex="', $context['tabindex']++, '" class="time_input end" data-type="time"', !empty($context['event']['allday']) ? ' disabled' : '', '>
834
							</div>
835
						</div><!-- #event_time_input -->
836
						<div class="event_options_right" id="event_time_options">
837
							<div id="event_allday">
838
								<label for="allday"><span class="label">', $txt['calendar_allday'], '</span></label>
839
								<input type="checkbox" name="allday" id="allday"', !empty($context['event']['allday']) ? ' checked' : '', ' tabindex="', $context['tabindex']++, '">
840
							</div>
841
							<div id="event_timezone">
842
								<span class="label">', $txt['calendar_timezone'], '</span>
843
								<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
844
845
	foreach ($context['all_timezones'] as $tz => $tzname)
846
		echo '
847
									<option', is_numeric($tz) ? ' value="" disabled' : ' value="' . $tz . '"', $tz === $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
848
849
	echo '
850
								</select>
851
							</div>
852
						</div><!-- #event_time_options -->
853
						<div>
854
							<span class="label">', $txt['location'], '</span>
855
							<input type="text" name="event_location" id="event_location" maxlength="255" value="', !empty($context['event']['location']) ? $context['event']['location'] : '', '" tabindex="', $context['tabindex']++, '">
856
						</div>
857
					</fieldset>';
858
859
	echo '
860
					<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button">';
861
862
	// Delete button?
863
	if (empty($context['event']['new']))
864
		echo '
865
					<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button you_sure">';
866
867
	echo '
868
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
869
					<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">
870
871
				</div><!-- .roundframe -->
872
			</div><!-- #post_event -->
873
		</form>';
874
}
875
876
/**
877
 * Displays a clock
878
 */
879
function template_bcd()
880
{
881
	global $context, $scripturl;
882
	$alt = false;
883
884
	echo '
885
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
886
			<tr>
887
				<th class="windowbg" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;" colspan="6">BCD Clock</th>
888
			</tr>
889
			<tr class="windowbg">';
890
891
	foreach ($context['clockicons'] as $t => $v)
892
	{
893
		echo '
894
				<td style="padding-', $alt ? 'right' : 'left', ': 1.5em;">';
895
896
		foreach ($v as $i)
897
			echo '
898
					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '"><br>';
899
900
		echo '
901
				</td>';
902
903
		$alt = !$alt;
0 ignored issues
show
The condition $alt is always false.
Loading history...
904
	}
905
	echo '
906
			</tr>
907
			<tr class="windowbg" style="border-top: 1px solid #ccc; text-align: center;">
908
				<td colspan="6">
909
					<a href="', $scripturl, '?action=clock;rb">Are you hardcore?</a>
910
				</td>
911
			</tr>
912
		</table>
913
914
		<script>
915
			var icons = new Object();';
916
917
	foreach ($context['clockicons'] as $t => $v)
918
	{
919
		foreach ($v as $i)
920
			echo '
921
			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
922
	}
923
924
	echo '
925
			function update()
926
			{
927
				// Get the current time
928
				var time = new Date();
929
				var hour = time.getHours();
930
				var min = time.getMinutes();
931
				var sec = time.getSeconds();
932
933
				// Break it up into individual digits
934
				var h1 = parseInt(hour / 10);
935
				var h2 = hour % 10;
936
				var m1 = parseInt(min / 10);
937
				var m2 = min % 10;
938
				var s1 = parseInt(sec / 10);
939
				var s2 = sec % 10;
940
941
				// For each digit figure out which ones to turn off and which ones to turn on
942
				var turnon = new Array();';
943
944
	foreach ($context['clockicons'] as $t => $v)
945
	{
946
		foreach ($v as $i)
947
			echo '
948
				if (', $t, ' >= ', $i, ')
949
				{
950
					turnon.push("', $t, '_', $i, '");
951
					', $t, ' -= ', $i, ';
952
				}';
953
	}
954
955
	echo '
956
				for (var i in icons)
957
					if (!in_array(i, turnon))
958
						icons[i].src = "', $context['offimg'], '";
959
					else
960
						icons[i].src = "', $context['onimg'], '";
961
962
				window.setTimeout("update();", 500);
963
			}
964
			// Checks for variable in theArray.
965
			function in_array(variable, theArray)
966
			{
967
				for (var i = 0; i < theArray.length; i++)
968
				{
969
					if (theArray[i] == variable)
970
						return true;
971
				}
972
				return false;
973
			}
974
975
			update();
976
		</script>';
977
}
978
979
/**
980
 * Displays the hours, minutes and seconds for our clock
981
 */
982
function template_hms()
983
{
984
	global $context, $scripturl;
985
	$alt = false;
986
987
	echo '
988
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
989
			<tr>
990
				<th class="windowbg" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">Binary Clock</th>
991
			</tr>';
992
993
	foreach ($context['clockicons'] as $t => $v)
994
	{
995
		echo '
996
			<tr class="windowbg">
997
				<td>';
998
999
		foreach ($v as $i)
1000
			echo '
1001
					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1002
1003
		echo '
1004
				</td>
1005
			</tr>';
1006
1007
		$alt = !$alt;
0 ignored issues
show
The condition $alt is always false.
Loading history...
1008
	}
1009
	echo '
1010
			<tr class="windowbg" style="border-top: 1px solid #ccc; text-align: center;">
1011
				<td>
1012
					<a href="', $scripturl, '?action=clock">Too tough for you?</a>
1013
				</td>
1014
			</tr>
1015
		</table>';
1016
1017
	echo '
1018
		<script>
1019
			var icons = new Object();';
1020
1021
	foreach ($context['clockicons'] as $t => $v)
1022
	{
1023
		foreach ($v as $i)
1024
			echo '
1025
			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1026
	}
1027
1028
	echo '
1029
			function update()
1030
			{
1031
				// Get the current time
1032
				var time = new Date();
1033
				var h = time.getHours();
1034
				var m = time.getMinutes();
1035
				var s = time.getSeconds();
1036
1037
				// For each digit figure out which ones to turn off and which ones to turn on
1038
				var turnon = new Array();';
1039
1040
	foreach ($context['clockicons'] as $t => $v)
1041
	{
1042
		foreach ($v as $i)
1043
			echo '
1044
				if (', $t, ' >= ', $i, ')
1045
				{
1046
					turnon.push("', $t, '_', $i, '");
1047
					', $t, ' -= ', $i, ';
1048
				}';
1049
	}
1050
1051
	echo '
1052
				for (var i in icons)
1053
					if (!in_array(i, turnon))
1054
						icons[i].src = "', $context['offimg'], '";
1055
					else
1056
						icons[i].src = "', $context['onimg'], '";
1057
1058
				window.setTimeout("update();", 500);
1059
			}
1060
			// Checks for variable in theArray.
1061
			function in_array(variable, theArray)
1062
			{
1063
				for (var i = 0; i < theArray.length; i++)
1064
				{
1065
					if (theArray[i] == variable)
1066
						return true;
1067
				}
1068
				return false;
1069
			}
1070
1071
			update();
1072
		</script>';
1073
}
1074
1075
/**
1076
 * Displays a binary clock
1077
 */
1078
function template_omfg()
1079
{
1080
	global $context;
1081
	$alt = false;
1082
1083
	echo '
1084
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1085
			<tr>
1086
				<th class="windowbg" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">OMFG Binary Clock</th>
1087
			</tr>';
1088
1089
	foreach ($context['clockicons'] as $t => $v)
1090
	{
1091
		echo '
1092
			<tr class="windowbg">
1093
				<td>';
1094
1095
		foreach ($v as $i)
1096
			echo '
1097
					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1098
1099
		echo '
1100
				</td>
1101
			</tr>';
1102
1103
		$alt = !$alt;
0 ignored issues
show
The condition $alt is always false.
Loading history...
1104
	}
1105
1106
	echo '
1107
		</table>
1108
		<script>
1109
			var icons = new Object();';
1110
1111
	foreach ($context['clockicons'] as $t => $v)
1112
	{
1113
		foreach ($v as $i)
1114
			echo '
1115
			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1116
	}
1117
1118
	echo '
1119
			function update()
1120
			{
1121
				// Get the current time
1122
				var time = new Date();
1123
				var month = time.getMonth() + 1;
1124
				var day = time.getDate();
1125
				var year = time.getFullYear();
1126
				year = year % 100;
1127
				var hour = time.getHours();
1128
				var min = time.getMinutes();
1129
				var sec = time.getSeconds();
1130
1131
				// For each digit figure out which ones to turn off and which ones to turn on
1132
				var turnon = new Array();';
1133
1134
	foreach ($context['clockicons'] as $t => $v)
1135
	{
1136
		foreach ($v as $i)
1137
			echo '
1138
				if (', $t, ' >= ', $i, ')
1139
				{
1140
					turnon.push("', $t, '_', $i, '");
1141
					', $t, ' -= ', $i, ';
1142
				}';
1143
	}
1144
1145
	echo '
1146
				for (var i in icons)
1147
					if (!in_array(i, turnon))
1148
						icons[i].src = "', $context['offimg'], '";
1149
					else
1150
						icons[i].src = "', $context['onimg'], '";
1151
1152
				window.setTimeout("update();", 500);
1153
			}
1154
			// Checks for variable in theArray.
1155
			function in_array(variable, theArray)
1156
			{
1157
				for (var i = 0; i < theArray.length; i++)
1158
				{
1159
					if (theArray[i] == variable)
1160
						return true;
1161
				}
1162
				return false;
1163
			}
1164
1165
			update();
1166
		</script>';
1167
}
1168
1169
/**
1170
 * Displays the time
1171
 */
1172
function template_thetime()
1173
{
1174
	global $context;
1175
	$alt = false;
1176
1177
	echo '
1178
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1179
			<tr>
1180
				<th class="windowbg" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">The time you requested</th>
1181
			</tr>';
1182
1183
	foreach ($context['clockicons'] as $v)
1184
	{
1185
		echo '
1186
			<tr class="windowbg">
1187
				<td>';
1188
1189
		foreach ($v as $i)
1190
			echo '
1191
					<img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="" style="padding: 2px;">';
1192
1193
		echo '
1194
				</td>
1195
			</tr>';
1196
1197
		$alt = !$alt;
0 ignored issues
show
The condition $alt is always false.
Loading history...
1198
	}
1199
1200
	echo '
1201
		</table>';
1202
}
1203
1204
?>