Completed
Push — release-2.1 ( dd6be9...02c57b )
by John
33:22 queued 26:19
created

Calendar.template.php ➔ template_show_upcoming_list()   D

Complexity

Conditions 24
Paths 33

Size

Total Lines 162
Code Lines 66

Duplication

Lines 72
Ratio 44.44 %

Importance

Changes 0
Metric Value
cc 24
eloc 66
nc 33
nop 1
dl 72
loc 162
rs 4.5989
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines http://www.simplemachines.org
7
 * @copyright 2017 Simple Machines and individual contributors
8
 * @license http://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 Beta 3
11
 */
12
13
/**
14
 * Our main calendar template, which encapsulates weeks and months.
15
 */
16
function template_main()
0 ignored issues
show
Best Practice introduced by
The function template_main() has been defined more than once; this definition is ignored, only the first definition in Themes/default/BoardIndex.template.php (L56-178) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
17
{
18
	global $context;
19
20
	// The main calendar wrapper.
21
	echo '<div id="calendar">';
22
23
	// Show the mini-blocks if they're enabled.
24
	if (empty($context['blocks_disabled']))
25
	{
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
	}
34
35
	// What view are we showing?
36
	if ($context['calendar_view'] == 'view_list')
37
	{
38
		echo '
39
			<div id="main_grid">
40
				', template_show_upcoming_list('main'), '
41
			</div>
42
		';
43
	}
44
	elseif ($context['calendar_view'] == 'view_week')
45
	{
46
		echo '
47
			<div id="main_grid">
48
				', template_show_week_grid('main'), '
49
			</div>
50
		';
51
	}
52
	else
53
	{
54
		echo '
55
			<div id="main_grid">
56
				', template_show_month_grid('main'), '
57
			</div>
58
		';
59
	}
60
61
	// Close our wrapper.
62
	echo '
63
	</div>';
64
}
65
66
67
/**
68
 * Display a list of upcoming events, birthdays, and holidays.
69
 *
70
 * @param string $grid_name The grid name
71
 * @return void|bool Returns false if the grid doesn't exist.
72
 */
73
function template_show_upcoming_list($grid_name)
74
{
75
	global $context, $scripturl, $txt, $modSettings;
76
77
	// Bail out if we have nothing to work with
78
	if (!isset($context['calendar_grid_' . $grid_name]))
79
		return false;
80
81
	// Protect programmer sanity
82
	$calendar_data = &$context['calendar_grid_' . $grid_name];
83
84
	// Do we want a title?
85
	if (empty($calendar_data['disable_title']))
86
	{
87
		echo '
88
			<div class="cat_bar">
89
				<h3 class="catbg centertext largetext">
90
					<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>
91
				</h3>
92
			</div>';
93
	}
94
95
	// Give the user some controls to work with
96
	template_calendar_top($calendar_data);
97
98
	// First, list any events
99 View Code Duplication
	if (!empty($calendar_data['events']))
100
	{
101
		echo '
102
			<div>
103
				<div class="title_bar">
104
					<h3 class="titlebg">', str_replace(':', '', $txt['events']), '</h3>
105
				</div>
106
				<ul>';
107
108
		foreach ($calendar_data['events'] as $date => $date_events)
109
		{
110
			foreach ($date_events as $event)
111
			{
112
				echo '
113
					<li class="windowbg">
114
						<b class="event_title">', $event['link'], '</b>';
115
116
				if ($event['can_edit'])
117
					echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
118
119
				if ($event['can_export'])
120
					echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
121
122
				echo '
123
						<br>';
124
125
				if (!empty($event['allday']))
126
				{
127
					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>' : '';
128
				}
129
				else
130
				{
131
					// Display event info relative to user's local timezone
132
					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'] . '">';
133
134
					if ($event['start_date_local'] != $event['end_date_local'])
135
						echo trim($event['end_date_local']) . ', ';
136
137
					echo trim($event['end_time_local']);
138
139
					// Display event info relative to original timezone
140
					if ($event['start_date_local'] . $event['start_time_local'] != $event['start_date_orig'] . $event['start_time_orig'])
141
					{
142
						echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
143
144
						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'])
145
							echo trim($event['start_date_orig']), ', ';
146
147
						echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
148
149
						if ($event['start_date_orig'] != $event['end_date_orig'])
150
							echo trim($event['end_date_orig']) . ', ';
151
152
						echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
153
					}
154
					// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
155
					else
156
						echo ' ', $event['tz_abbrev'], '</time>';
157
				}
158
159
				if (!empty($event['location']))
160
					echo '<br>', $event['location'];
161
162
				echo '
163
					</li>';
164
			}
165
		}
166
167
		echo '
168
				</ul>
169
			</div>';
170
	}
171
172
	// Next, list any birthdays
173
	if (!empty($calendar_data['birthdays']))
174
	{
175
		echo '
176
			<div>
177
				<div class="title_bar">
178
					<h3 class="titlebg">', str_replace(':', '', $txt['birthdays']), '</h3>
179
				</div>
180
				<div class="windowbg">';
181
182
		foreach ($calendar_data['birthdays'] as $date)
183
		{
184
			echo '
185
					<p class="inline">
186
						<b>', $date['date_local'], '</b>: ';
187
188
			unset($date['date_local']);
189
190
			$birthdays = array();
191
192
			foreach ($date as $member)
193
				$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
194
195
			echo implode(', ', $birthdays);
196
197
			echo '
198
					</p>';
199
		}
200
201
		echo '
202
				</div>
203
			</div>';
204
	}
205
206
	// Finally, list any holidays
207
	if (!empty($calendar_data['holidays']))
208
	{
209
		echo '
210
			<div>
211
				<div class="title_bar">
212
					<h3 class="titlebg">', str_replace(':', '', $txt['calendar_prompt']), '</h3>
213
				</div>
214
				<div class="windowbg">
215
					<p class="inline holidays">';
216
217
		$holidays = array();
218
219
		foreach ($calendar_data['holidays'] as $date)
220
		{
221
			$date_local = $date['date_local'];
222
			unset($date['date_local']);
223
224
			foreach ($date as $holiday)
225
				$holidays[] = $holiday . ' (' . $date_local . ')';
226
		}
227
228
		echo implode(', ', $holidays);
229
230
		echo '</p>
231
				</div>
232
			</div>';
233
	}
234
}
235
236
/**
237
 * Display a monthly calendar grid.
238
 *
239
 * @param string $grid_name The grid name
240
 * @param bool $is_mini Is this a mini grid?
241
 * @return void|bool Returns false if the grid doesn't exist.
242
 */
243
function template_show_month_grid($grid_name, $is_mini = false)
244
{
245
	global $context, $settings, $txt, $scripturl, $modSettings;
246
247
	// If the grid doesn't exist, no point in proceeding.
248
	if (!isset($context['calendar_grid_' . $grid_name]))
249
		return false;
250
251
	// A handy little pointer variable.
252
	$calendar_data = &$context['calendar_grid_' . $grid_name];
253
254
	// Some conditions for whether or not we should show the week links *here*.
255
	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)))
256
		$show_week_links = true;
257
	else
258
		$show_week_links = false;
259
260
	// Assuming that we've not disabled it, show the title block!
261
	if (empty($calendar_data['disable_title']))
262
	{
263
		echo '
264
			<div class="cat_bar">
265
				<h3 class="catbg centertext largetext">';
266
267
				// Previous Link: If we're showing prev / next and it's not a mini-calendar.
268
				if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
269
				{
270
					echo '
271
						<span class="floatleft">
272
							<a href="', $calendar_data['previous_calendar']['href'], '">&#171;</a>
273
						</span>
274
					';
275
				}
276
277
				// Next Link: if we're showing prev / next and it's not a mini-calendar.
278 View Code Duplication
				if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
279
				{
280
					echo '
281
						<span class="floatright">
282
							<a href="', $calendar_data['next_calendar']['href'], '">&#187;</a>
283
						</span>
284
					';
285
				}
286
287
				// Arguably the most exciting part, the title!
288
				echo '<a href="', $scripturl, '?action=calendar;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], '">', $txt['months_titles'][$calendar_data['current_month']], ' ', $calendar_data['current_year'], '</a>';
289
290
				echo '
291
				</h3>
292
			</div>
293
		';
294
	}
295
296
	// Show the controls on main grids
297
	if ($is_mini === false)
298
		template_calendar_top($calendar_data);
299
300
	// Finally, the main calendar table.
301
	echo '<table class="calendar_table">';
302
303
	// Show each day of the week.
304
	if (empty($calendar_data['disable_day_titles']))
305
	{
306
		echo '<tr>';
307
308
		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
309
		if ($show_week_links === true)
310
			echo '<th>&nbsp;</th>';
311
312
		// Now, loop through each actual day of the week.
313
		foreach ($calendar_data['week_days'] as $day)
314
		{
315
			echo '<th class="days" scope="col">', !empty($calendar_data['short_day_titles']) || $is_mini === true ? $txt['days_short'][$day] : $txt['days'][$day], '</th>';
316
		}
317
318
		echo '</tr>';
319
	}
320
321
	// Our looping begins on a per-week basis.
322
	foreach ($calendar_data['weeks'] as $week)
323
	{
324
325
		// Some useful looping variables.
326
		$current_month_started = false;
327
		$count = 1;
328
		$final_count = 1;
329
330
		echo '<tr class="days_wrapper">';
331
332
		// This is where we add the actual week link, if enabled on this location.
333
		if ($show_week_links === true)
334
		{
335
			echo '
336
				<td class="windowbg2 weeks">
337
					<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>
338
				</td>
339
			';
340
		}
341
342
		// Now loop through each day in the week we're on.
343
		foreach ($week['days'] as $day)
344
		{
345
			// What classes should each day inherit? Day is default.
346
			$classes = array('days');
347
			if (!empty($day['day']))
348
			{
349
350
				// Default Classes (either compact or comfortable and either calendar_today or windowbg).
351
				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
352
				$classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
353
354
				// Additional classes are given for events, holidays, and birthdays.
355 View Code Duplication
				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
356
				{
357
					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3)))
358
						$classes[] = 'events';
359
					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3)))
360
						$classes[] = 'events';
361
				}
362 View Code Duplication
				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
363
				{
364
					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3)))
365
						$classes[] = 'holidays';
366
					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3)))
367
						$classes[] = 'holidays';
368
				}
369 View Code Duplication
				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
370
				{
371
					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3)))
372
						$classes[] = 'birthdays';
373
					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3)))
374
						$classes[] = 'birthdays';
375
				}
376
			}
377
			else
378
			{
379
				// Default Classes (either compact or comfortable and disabled).
380
				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
381
				$classes[] = 'disabled';
382
			}
383
384
			// Now, implode the classes for each day.
385
			echo '<td class="', implode(' ', $classes), '">';
386
387
			// If it's within this current month, go ahead and begin.
388
			if (!empty($day['day']))
389
			{
390
391
				// If it's the first day of this month and not a mini-calendar, we'll add the month title - whether short or full.
392
				$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']] . ' ') : '';
393
394
				// The actual day number - be it a link, or just plain old text!
395
				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
396
					echo '<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>';
397
				else
398
					echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
399
400
				// A lot of stuff, we're not showing on mini-calendars to conserve space.
401
				if ($is_mini === false)
402
				{
403
					// Holidays are always fun, let's show them!
404
					if (!empty($day['holidays']))
405
						echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
406
407
					// Happy Birthday Dear, Member!
408
					if (!empty($day['birthdays']))
409
					{
410
						echo '
411
							<div class="smalltext">
412
								<span class="birthday">', $txt['birthdays'], '</span> ';
413
414
						/* Each of the birthdays has:
415
							id, name (person), age (if they have one set?), and is_last. (last in list?) */
416
						$use_js_hide = empty($context['show_all_birthdays']) && count($day['birthdays']) > 15;
417
						$birthday_count = 0;
418
						foreach ($day['birthdays'] as $member)
419
						{
420
							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) ? '' : ', ';
421
422
							// 9...10! Let's stop there.
423
							if ($birthday_count == 10 && $use_js_hide)
424
								// !!TODO - Inline CSS and JavaScript should be moved.
425
								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'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, ';
426
427
							++$birthday_count;
428
						}
429
						if ($use_js_hide)
430
							echo '</span>';
431
432
						echo '</div>';
433
					}
434
435
					// Any special posted events?
436
					if (!empty($day['events']))
437
					{
438
						// Sort events by start time (all day events will be listed first)
439 View Code Duplication
						uasort($day['events'], function($a, $b) {
440
						    if ($a['start_timestamp'] == $b['start_timestamp'])
441
						        return 0;
442
						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
443
						});
444
445
						echo '
446
							<div class="smalltext lefttext">
447
								<span class="event">', $txt['events'], '</span><br>';
448
449
						/* The events are made up of:
450
							title, href, is_last, can_edit (are they allowed to?), and modify_href. */
451
						foreach ($day['events'] as $event)
452
						{
453
							$event_icons_needed = ($event['can_edit'] || $event['can_export']) ? true : false;
454
455
							echo '<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' : '', '">', $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
456
457
							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
458
								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
459
							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
460
								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
461
							elseif (!empty($event['allday']))
462
								echo $txt['calendar_allday'];
463
464
							echo '</span>';
465
466 View Code Duplication
							if (!empty($event['location']))
467
								echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
468
469
							if ($event['can_edit'] || $event['can_export'])
470
							{
471
								echo ' <span class="modify_event_links">';
472
473
								// If they can edit the event, show an icon they can click on....
474
								if ($event['can_edit'])
475
								{
476
									echo '
477
										<a class="modify_event" href="', $event['modify_href'], '">
478
											<span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
479
										</a>';
480
								}
481
								// Exporting!
482
								if ($event['can_export'])
483
								{
484
									echo '
485
										<a class="modify_event" href="', $event['export_href'], '">
486
											<span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span>
487
										</a>';
488
								}
489
490
								echo '</span><br class="clear">';
491
							}
492
493
							echo '</div>';
494
						}
495
496
						echo '</div>';
497
					}
498
				}
499
				$current_month_started = $count;
500
			}
501
			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
502
			elseif ($is_mini === false)
503
			{
504
				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
505
					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>';
506
				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
507
					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>';
508
			}
509
510
			// Close this day and increase var count.
511
			echo '</td>';
512
			++$count;
513
		}
514
515
		echo '</tr>';
516
	}
517
518
	// The end of our main table.
519
	echo '</table>';
520
}
521
522
/**
523
 * Shows a weekly grid
524
 *
525
 * @param string $grid_name The name of the grid
526
 * @return void|bool Returns false if the grid doesn't exist
527
 */
528
function template_show_week_grid($grid_name)
529
{
530
	global $context, $settings, $txt, $scripturl, $modSettings;
531
532
	// We might have no reason to proceed, if the variable isn't there.
533
	if (!isset($context['calendar_grid_' . $grid_name]))
534
		return false;
535
536
	// Handy pointer.
537
	$calendar_data = &$context['calendar_grid_' . $grid_name];
538
539
	// At the very least, we have one month. Possibly two, though.
540
	$iteration = 1;
541
	$num_months = count($calendar_data['months']);
0 ignored issues
show
Unused Code introduced by
$num_months is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
542
	foreach ($calendar_data['months'] as $month_data)
543
	{
544
		// For our first iteration, we'll add a nice header!
545
		if ($iteration == 1)
546
		{
547
			echo '
548
				<div class="cat_bar">
549
					<h3 class="catbg centertext largetext">';
550
					// Previous Week Link...
551 View Code Duplication
					if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
552
					{
553
						echo '
554
							<span class="floatleft">
555
								<a href="', $calendar_data['previous_week']['href'], '">&#171;</a>
556
							</span>
557
						';
558
					}
559
560
					// Next Week Link...
561 View Code Duplication
					if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
562
					{
563
						echo '
564
							<span class="floatright">
565
								<a href="', $calendar_data['next_week']['href'], '">&#187;</a>
566
							</span>';
567
					}
568
569
					// The Month Title + Week Number...
570
					if (!empty($calendar_data['week_title']))
571
							echo $calendar_data['week_title'];
572
573
					echo '
574
					</h3>
575
				</div>';
576
577
			// Show the controls
578
			template_calendar_top($calendar_data);
579
		}
580
581
		// Our actual month...
582
		echo '
583
			<div class="week_month_title">
584
				<a href="', $scripturl, '?action=calendar;month=', $month_data['current_month'], '">
585
					', $txt['months_titles'][$month_data['current_month']], '
586
				</a>
587
			</div>';
588
589
		// The main table grid for $this week.
590
		echo '
591
			<table class="table_grid calendar_week">
592
				<tr>
593
					<th class="days" scope="col">', $txt['calendar_day'], '</th>
594
					<th class="days" scope="col">', $txt['events'], '</th>
595
					<th class="days" scope="col">', $txt['calendar_prompt'], '</th>
596
					<th class="days" scope="col">', $txt['birthdays'], '</th>
597
				</tr>';
598
				// Each day of the week.
599
				foreach ($month_data['days'] as $day)
600
				{
601
					// How should we be highlighted or otherwise not...?
602
					$classes = array('days');
603
					$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
604
					$classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
605
606
					echo '
607
						<tr class="days_wrapper">
608
							<td class="', implode(' ', $classes), ' act_day">';
609
							// Should the day number be a link?
610
							if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
611
								echo '<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>';
612
							else
613
								echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
614
615
							echo '</td>
616
							<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'] : '', '">';
617
							// Show any events...
618
							if (!empty($day['events']))
619
							{
620
								// Sort events by start time (all day events will be listed first)
621 View Code Duplication
								uasort($day['events'], function($a, $b) {
622
								    if ($a['start_timestamp'] == $b['start_timestamp'])
623
								        return 0;
624
								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
625
								});
626
627
								foreach ($day['events'] as $event)
628
								{
629
									echo '<div class="event_wrapper">';
630
631
									$event_icons_needed = ($event['can_edit'] || $event['can_export']) ? true : false;
632
633
									echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
634
635
									if (!empty($event['start_time_local']))
636
										echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
637
									else
638
										echo $txt['calendar_allday'];
639
640
									echo '</span>';
641
642 View Code Duplication
									if (!empty($event['location']))
643
										echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
644
645
									if (!empty($event_icons_needed))
646
									{
647
										echo ' <span class="modify_event_links">';
648
649
										// If they can edit the event, show a star they can click on....
650
										if (!empty($event['can_edit']))
651
										{
652
											echo '
653
												<a class="modify_event" href="', $event['modify_href'], '">
654
													<span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
655
												</a>';
656
										}
657
										// Can we export? Sweet.
658
										if (!empty($event['can_export']))
659
										{
660
											echo '
661
												<a class="modify_event" href="', $event['export_href'], '">
662
													<span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span>
663
												</a>';
664
										}
665
666
										echo '</span><br class="clear">';
667
									}
668
669
									echo '
670
									</div>';
671
								}
672
								if (!empty($context['can_post']))
673
								{
674
									echo '
675
									<div class="week_add_event">
676
										<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>
677
									</div>
678
									<br class="clear">';
679
								}
680
							}
681 View Code Duplication
							else
682
							{
683
								if (!empty($context['can_post']))
684
								{
685
									echo '
686
										<div class="week_add_event">
687
											<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>
688
										</div>';
689
								}
690
							}
691
							echo '</td>
692
							<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
693
							// Show any holidays!
694
							if (!empty($day['holidays']))
695
								echo implode('<br>', $day['holidays']);
696
697
							echo '</td>
698
							<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
699
							// Show any birthdays...
700
							if (!empty($day['birthdays']))
701
							{
702 View Code Duplication
								foreach ($day['birthdays'] as $member)
703
								{
704
									echo '
705
										<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], '</a>
706
										', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '
707
									', $member['is_last'] ? '' : '<br>';
708
								}
709
							}
710
							echo '</td>
711
						</tr>';
712
				}
713
714
				// Increase iteration for loop counting.
715
				++$iteration;
716
717
				echo '
718
			</table>';
719
	}
720
}
721
722
/**
723
 * Calendar controls under the title
724
 *
725
 * Creates the view selector (list, month, week), the date selector (either a
726
 * select menu or a date range chooser, depending on the circumstances), and the
727
 * "Post Event" button.
728
 *
729
 * @param array $calendar_data The data for the calendar grid that this is for
730
 */
731
function template_calendar_top($calendar_data)
732
{
733
	global $context, $scripturl, $txt;
734
735
	echo '
736
		<div class="calendar_top roundframe', empty($calendar_data['disable_title']) ? ' noup' : '', '">
737
			<div id="calendar_viewselector" class="buttonrow floatleft">
738
				<a href="', $scripturl, '?action=calendar;viewlist;year=', $context['current_year'], ';month=', $context['current_month'], ';day=', $context['current_day'], '" class="button', $context['calendar_view'] == 'view_list' ? ' active' : '', '">', $txt['calendar_list'], '</a>
739
				<a href="', $scripturl, '?action=calendar;viewmonth;year=', $context['current_year'], ';month=', $context['current_month'], '" class="button', $context['calendar_view'] == 'view_month' ? ' active' : '', '">', $txt['calendar_month'], '</a>
740
				<a href="', $scripturl, '?action=calendar;viewweek;year=', $context['current_year'], ';month=', $context['current_month'], ';day=', $context['current_day'], '" class="button', $context['calendar_view'] == 'view_week' ? ' active' : '', '">', $txt['calendar_week'], '</a>
741
			</div>
742
			', template_button_strip($context['calendar_buttons'], 'right');
743
744
	if ($context['calendar_view'] == 'view_list')
745
	{
746
		echo '
747
			<form action="', $scripturl, '?action=calendar;viewlist" id="calendar_range" method="post" accept-charset="', $context['character_set'], '">
748
				<input type="text" name="start_date" id="start_date" maxlength="10" value="', $calendar_data['start_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input start" data-type="date">
749
				<span>', strtolower($txt['to']), '</span>
750
				<input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input end" data-type="date">
751
				<input type="submit" class="button_submit" style="float:none" id="view_button" value="', $txt['view'], '">
752
			</form>';
753
	}
754
	else
755
	{
756
		echo'
757
			<form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
758
				<select name="month" id="input_month">';
759
760
				// Show a select box with all the months.
761
				foreach ($txt['months_short'] as $number => $month)
762
				{
763
					echo '
764
					<option value="', $number, '"', $number == $context['current_month'] ? ' selected' : '', '>', $month, '</option>';
765
				}
766
767
				echo '
768
				</select>
769
				<select name="year">';
770
771
				// Show a link for every year.....
772
				for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++)
773
				{
774
					echo '<option value="', $year, '"', $year == $context['current_year'] ? ' selected' : '', '>', $year, '</option>';
775
				}
776
777
				echo '</select>
778
				<input type="submit" class="button_submit" id="view_button" value="', $txt['view'], '">
779
			</form>';
780
	}
781
782
	echo'
783
		</div>';
784
}
785
786
/**
787
 * Template for posting a calendar event.
788
 */
789
function template_event_post()
790
{
791
	global $context, $txt, $scripturl, $modSettings;
792
793
	echo '
794
		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);smc_saveEntities(\'postevent\', [\'evtitle\']);" style="margin: 0;">';
795
796
	if (!empty($context['event']['new']))
797
		echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
798
799
	// Start the main table.
800
	echo '
801
		<div id="post_event">
802
			<div class="cat_bar">
803
				<h3 class="catbg">
804
					', $context['page_title'], '
805
				</h3>
806
			</div>';
807
808
	if (!empty($context['post_error']['messages']))
809
	{
810
		echo '
811
			<div class="errorbox">
812
				<dl class="event_error">
813
					<dt>
814
						', $context['error_type'] == 'serious' ? '<strong>' . $txt['error_while_submitting'] . '</strong>' : '', '
815
					</dt>
816
					<dt class="error">
817
						', implode('<br>', $context['post_error']['messages']), '
818
					</dt>
819
				</dl>
820
			</div>';
821
	}
822
823
	echo '
824
			<div class="roundframe noup">
825
				<fieldset id="event_main">
826
					<legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', '>', $txt['calendar_event_title'], '</span></legend>
827
					<input type="hidden" name="calendar" value="1">
828
					<div class="event_options_left" id="event_title">
829
						<div>
830
							<input type="text" id="evtitle" name="evtitle" maxlength="255" size="55" value="', $context['event']['title'], '" tabindex="', $context['tabindex']++, '" class="input_text">
831
						</div>
832
					</div>';
833
834
	// If this is a new event let the user specify which board they want the linked post to be put into.
835
	if ($context['event']['new'] && !empty($context['event']['categories']))
836
	{
837
		echo '
838
					<div class="event_options_right" id="event_board">
839
						<div>
840
							<span class="label">', $txt['calendar_post_in'], '</span>
841
							<input type="checkbox" style="vertical-align: middle;" class="input_check" name="link_to_board"', (!empty($context['event']['board']) ? ' checked' : ''), ' onclick="toggleLinked(this.form);">
842
							<select name="board"', empty($context['event']['board']) ? ' disabled' : '', '>';
843 View Code Duplication
		foreach ($context['event']['categories'] as $category)
844
		{
845
			echo '
846
								<optgroup label="', $category['name'], '">';
847
			foreach ($category['boards'] as $board)
848
				echo '
849
									<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
850
			echo '
851
								</optgroup>';
852
		}
853
		echo '
854
							</select>
855
						</div>
856
					</div>';
857
	}
858
859
	// Note to theme writers: The JavaScripts expect the input fields for the start and end dates & times to be contained in a wrapper element with the id "event_time_input"
860
	echo '
861
				</fieldset>
862
				<fieldset id="event_options">
863
					<legend>', $txt['calendar_event_options'], '</legend>
864
					<div class="event_options_left" id="event_time_input">
865
						<div>
866
							<span class="label">', $txt['start'], '</span>
867
							<input type="text" name="start_date" id="start_date" maxlength="10" value="', $context['event']['start_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input start" data-type="date">
868
							<input type="text" name="start_time" id="start_time" maxlength="11" value="', $context['event']['start_time_local'], '" tabindex="', $context['tabindex']++, '" class="input_text time_input start" data-type="time"', !empty($context['event']['allday']) ? ' disabled' : '', '>
869
						</div>
870
						<div>
871
							<span class="label">', $txt['end'], '</span>
872
							<input type="text" name="end_date" id="end_date" maxlength="10" value="', $context['event']['end_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input end" data-type="date"', $modSettings['cal_maxspan'] == 1 ? ' disabled' : '', '>
873
							<input type="text" name="end_time" id="end_time" maxlength="11" value="', $context['event']['end_time_local'], '" tabindex="', $context['tabindex']++, '" class="input_text time_input end" data-type="time"', !empty($context['event']['allday']) ? ' disabled' : '', '>
874
						</div>
875
					</div>
876
					<div class="event_options_right" id="event_time_options">
877
						<div id="event_allday">
878
							<label for="allday"><span class="label">', $txt['calendar_allday'], '</span></label>
879
							<input type="checkbox" name="allday" id="allday"', !empty($context['event']['allday']) ? ' checked' : '', ' tabindex="', $context['tabindex']++, '">
880
						</div>
881
						<div id="event_timezone">
882
							<span class="label">', $txt['calendar_timezone'], '</span>
883
							<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
884
885 View Code Duplication
	foreach ($context['all_timezones'] as $tz => $tzname)
886
		echo '
887
								<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
888
889
	echo '
890
							</select>
891
						</div>
892
					</div>
893
					<div>
894
						<span class="label">', $txt['location'], '</span>
895
						<input type="text" name="event_location" id="event_location" maxlength="255" value="', !empty($context['event']['location']) ? $context['event']['location'] : '', '" tabindex="', $context['tabindex']++, '" class="input_text">
896
					</div>
897
				</fieldset>';
898
899
	echo '
900
				<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">';
901
	// Delete button?
902
	if (empty($context['event']['new']))
903
		echo '
904
				<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button_submit you_sure">';
905
906
	echo '
907
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
908
				<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">
909
910
			</div>
911
		</div>
912
		</form>';
913
}
914
915 View Code Duplication
function template_bcd()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
916
{
917
	global $context, $scripturl;
918
	$alt = false;
919
	echo '
920
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
921
			<tr>
922
				<th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;" colspan="6">BCD Clock</th>
923
			</tr>
924
			<tr class="windowbg">';
925
			foreach ($context['clockicons'] as $t => $v)
926
			{
927
				echo '<td style="padding-', $alt ? 'right' : 'left', ': 1.5em;">';
928
				foreach ($v as $i)
929
				{
930
					echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '"><br>';
931
				}
932
				echo '</td>';
933
				$alt = !$alt;
934
			}
935
			echo '</tr>
936
			<tr class="', $alt ? 'windowbg2' : 'windowbg', '" style="border-top: 1px solid #ccc; text-align: center;">
937
				<td colspan="6">
938
					<a href="', $scripturl, '?action=clock;rb">Are you hardcore?</a>
939
				</td>
940
			</tr>
941
		</table>
942
943
		<script>
944
		var icons = new Object();';
945
946
		foreach ($context['clockicons'] as $t => $v)
947
		{
948
			foreach ($v as $i)
949
				echo '
950
			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
951
		}
952
953
		echo '
954
		function update()
955
		{
956
			// Get the current time
957
			var time = new Date();
958
			var hour = time.getHours();
959
			var min = time.getMinutes();
960
			var sec = time.getSeconds();
961
962
			// Break it up into individual digits
963
			var h1 = parseInt(hour / 10);
964
			var h2 = hour % 10;
965
			var m1 = parseInt(min / 10);
966
			var m2 = min % 10;
967
			var s1 = parseInt(sec / 10);
968
			var s2 = sec % 10;
969
970
			// For each digit figure out which ones to turn off and which ones to turn on
971
			var turnon = new Array();';
972
973
		foreach ($context['clockicons'] as $t => $v)
974
		{
975
			foreach ($v as $i)
976
				echo '
977
			if (', $t, ' >= ', $i, ')
978
			{
979
				turnon.push("', $t, '_', $i, '");
980
				', $t, ' -= ', $i, ';
981
			}';
982
		}
983
984
		echo '
985
			for (var i in icons)
986
				if (!in_array(i, turnon))
987
					icons[i].src = "', $context['offimg'], '";
988
				else
989
					icons[i].src = "', $context['onimg'], '";
990
991
			window.setTimeout("update();", 500);
992
		}
993
		// Checks for variable in theArray.
994
		function in_array(variable, theArray)
995
		{
996
			for (var i = 0; i < theArray.length; i++)
997
			{
998
				if (theArray[i] == variable)
999
					return true;
1000
			}
1001
			return false;
1002
		}
1003
1004
		update();
1005
		</script>';
1006
}
1007
1008 View Code Duplication
function template_hms()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1009
{
1010
	global $context, $scripturl;
1011
	$alt = false;
1012
	echo '
1013
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1014
			<tr>
1015
				<th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">Binary Clock</th>
1016
			</tr>';
1017
			foreach ($context['clockicons'] as $t => $v)
1018
			{
1019
				echo '
1020
					<tr class="', $alt ? 'windowbg2' : 'windowbg', '">
1021
						<td>';
1022
						foreach ($v as $i)
1023
						{
1024
							echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1025
						}
1026
						echo '</td>
1027
					</tr>
1028
				';
1029
				$alt = !$alt;
1030
			}
1031
			echo '</tr>
1032
			<tr class="', $alt ? 'windowbg2' : 'windowbg', '" style="border-top: 1px solid #ccc; text-align: center;">
1033
				<td>
1034
					<a href="', $scripturl, '?action=clock">Too tough for you?</a>
1035
				</td>
1036
			</tr>
1037
		</table>';
1038
1039
	echo '
1040
	<script>
1041
	var icons = new Object();';
1042
1043
	foreach ($context['clockicons'] as $t => $v)
1044
	{
1045
		foreach ($v as $i)
1046
			echo '
1047
		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1048
	}
1049
1050
	echo '
1051
	function update()
1052
	{
1053
		// Get the current time
1054
		var time = new Date();
1055
		var h = time.getHours();
1056
		var m = time.getMinutes();
1057
		var s = time.getSeconds();
1058
1059
		// For each digit figure out which ones to turn off and which ones to turn on
1060
		var turnon = new Array();';
1061
1062
	foreach ($context['clockicons'] as $t => $v)
1063
	{
1064
		foreach ($v as $i)
1065
			echo '
1066
		if (', $t, ' >= ', $i, ')
1067
		{
1068
			turnon.push("', $t, '_', $i, '");
1069
			', $t, ' -= ', $i, ';
1070
		}';
1071
	}
1072
1073
	echo '
1074
		for (var i in icons)
1075
			if (!in_array(i, turnon))
1076
				icons[i].src = "', $context['offimg'], '";
1077
			else
1078
				icons[i].src = "', $context['onimg'], '";
1079
1080
		window.setTimeout("update();", 500);
1081
	}
1082
	// Checks for variable in theArray.
1083
	function in_array(variable, theArray)
1084
	{
1085
		for (var i = 0; i < theArray.length; i++)
1086
		{
1087
			if (theArray[i] == variable)
1088
				return true;
1089
		}
1090
		return false;
1091
	}
1092
1093
	update();
1094
	</script>';
1095
}
1096
1097
function template_omfg()
1098
{
1099
	global $context;
1100
	$alt = false;
1101
	echo '
1102
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1103
			<tr>
1104
				<th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">OMFG Binary Clock</th>
1105
			</tr>';
1106
			foreach ($context['clockicons'] as $t => $v)
1107
			{
1108
				echo '
1109
					<tr class="', $alt ? 'windowbg2' : 'windowbg', '">
1110
						<td>';
1111
						foreach ($v as $i)
1112
						{
1113
							echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1114
						}
1115
						echo '</td>
1116
					</tr>
1117
				';
1118
				$alt = !$alt;
1119
			}
1120
		echo '</tr>
1121
		</table>';
1122
1123
	echo '
1124
	<script>
1125
	var icons = new Object();';
1126
1127
	foreach ($context['clockicons'] as $t => $v)
1128
	{
1129
		foreach ($v as $i)
1130
			echo '
1131
		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1132
	}
1133
1134
	echo '
1135
	function update()
1136
	{
1137
		// Get the current time
1138
		var time = new Date();
1139
		var month = time.getMonth() + 1;
1140
		var day = time.getDate();
1141
		var year = time.getFullYear();
1142
		year = year % 100;
1143
		var hour = time.getHours();
1144
		var min = time.getMinutes();
1145
		var sec = time.getSeconds();
1146
1147
		// For each digit figure out which ones to turn off and which ones to turn on
1148
		var turnon = new Array();';
1149
1150
	foreach ($context['clockicons'] as $t => $v)
1151
	{
1152
		foreach ($v as $i)
1153
		echo '
1154
		if (', $t, ' >= ', $i, ')
1155
		{
1156
			turnon.push("', $t, '_', $i, '");
1157
			', $t, ' -= ', $i, ';
1158
		}';
1159
	}
1160
1161
	echo '
1162
		for (var i in icons)
1163
			if (!in_array(i, turnon))
1164
				icons[i].src = "', $context['offimg'], '";
1165
			else
1166
				icons[i].src = "', $context['onimg'], '";
1167
1168
		window.setTimeout("update();", 500);
1169
	}
1170
	// Checks for variable in theArray.
1171
	function in_array(variable, theArray)
1172
	{
1173
		for (var i = 0; i < theArray.length; i++)
1174
		{
1175
			if (theArray[i] == variable)
1176
				return true;
1177
		}
1178
		return false;
1179
	}
1180
1181
	update();
1182
	</script>';
1183
}
1184
1185
function template_thetime()
1186
{
1187
	global $context;
1188
	$alt = false;
1189
	echo '
1190
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1191
			<tr>
1192
				<th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">The time you requested</th>
1193
			</tr>';
1194
			foreach ($context['clockicons'] as $v)
1195
			{
1196
				echo '
1197
					<tr class="', $alt ? 'windowbg2' : 'windowbg', '">
1198
						<td>';
1199
						foreach ($v as $i)
1200
						{
1201
							echo '<img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="" style="padding: 2px;">';
1202
						}
1203
						echo '</td>
1204
					</tr>
1205
				';
1206
				$alt = !$alt;
1207
			}
1208
			echo '
1209
		</table>';
1210
}
1211
1212
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...