/
Calendar.template.php
816 lines (686 loc) · 24 KB
/
Calendar.template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines
* @copyright 2011 Simple Machines
* @license http://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.0
*/
// The main calendar - January, for example.
function template_main()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;
echo '
<div id="calendar">
<div id="month_grid">
', template_show_month_grid('prev'), '
', template_show_month_grid('current'), '
', template_show_month_grid('next'), '
</div>
<div id="main_grid" style="', $context['browser']['is_ie'] && !$context['browser']['is_ie8'] ? 'float: ' . ($context['right_to_left'] ? 'right; padding-right' : 'left; padding-left') . ': 20px;' : 'margin-' . ($context['right_to_left'] ? 'right' : 'left') . ': 220px; ', '">
', $context['view_week'] ? template_show_week_grid('main') : template_show_month_grid('main');
// Build the calendar button array.
$calendar_buttons = array(
'post_event' => array('test' => 'can_post', 'text' => 'calendar_post_event', 'image' => 'calendarpe.gif', 'lang' => true, 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']),
);
template_button_strip($calendar_buttons, 'right');
// Show some controls to allow easy calendar navigation.
echo '
<form id="calendar_navigation" action="', $scripturl, '?action=calendar" method="post" accept-charset="', $context['character_set'], '">
<select name="month">';
// Show a select box with all the months.
foreach ($txt['months'] as $number => $month)
echo '
<option value="', $number, '"', $number == $context['current_month'] ? ' selected="selected"' : '', '>', $month, '</option>';
echo '
</select>
<select name="year">';
// Show a link for every year.....
for ($year = $modSettings['cal_minyear']; $year <= $modSettings['cal_maxyear']; $year++)
echo '
<option value="', $year, '"', $year == $context['current_year'] ? ' selected="selected"' : '', '>', $year, '</option>';
echo '
</select>
<input type="submit" class="button_submit" value="', $txt['view'], '">';
echo '
</form>
<br class="clear">
</div>
</div>';
}
// Template for posting a calendar event.
function template_event_post()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;
// Start the javascript for drop down boxes...
echo '
<script type="text/javascript"><!-- // --><![CDATA[
var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
function generateDays()
{
var days = 0, selected = 0;
var dayElement = document.getElementById("day"), yearElement = document.getElementById("year"), monthElement = document.getElementById("month");
monthLength[1] = 28;
if (yearElement.options[yearElement.selectedIndex].value % 4 == 0)
monthLength[1] = 29;
selected = dayElement.selectedIndex;
while (dayElement.options.length)
dayElement.options[0] = null;
days = monthLength[monthElement.value - 1];
for (i = 1; i <= days; i++)
dayElement.options[dayElement.length] = new Option(i, i);
if (selected < days)
dayElement.selectedIndex = selected;
}
function toggleLinked(form)
{
form.board.disabled = !form.link_to_board.checked;
}
// ]]></script>
<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;">';
if (!empty($context['event']['new']))
echo '
<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
// Start the main table.
echo '
<div id="post_event">
<div class="cat_bar">
<h3 class="catbg">
', $context['page_title'], '
</h3>
</div>';
if (!empty($context['post_error']['messages']))
{
echo '
<div class="errorbox">
<dl class="event_error">
<dt>
', $context['error_type'] == 'serious' ? '<strong>' . $txt['error_while_submitting'] . '</strong>' : '', '
</dt>
<dt class="error">
', implode('<br>', $context['post_error']['messages']), '
</dt>
</dl>
</div>';
}
echo '
<div class="windowbg">
<div class="roundframe">
<fieldset id="event_main">
<legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', '>', $txt['calendar_event_title'], '</span></legend>
<input type="text" name="evtitle" maxlength="255" size="70" value="', $context['event']['title'], '" class="input_text">
<div class="smalltext">
<input type="hidden" name="calendar" value="1">', $txt['calendar_year'], '
<select name="year" id="year" onchange="generateDays();">';
// Show a list of all the years we allow...
for ($year = $modSettings['cal_minyear']; $year <= $modSettings['cal_maxyear']; $year++)
echo '
<option value="', $year, '"', $year == $context['event']['year'] ? ' selected="selected"' : '', '>', $year, ' </option>';
echo '
</select>
', $txt['calendar_month'], '
<select name="month" id="month" onchange="generateDays();">';
// There are 12 months per year - ensure that they all get listed.
for ($month = 1; $month <= 12; $month++)
echo '
<option value="', $month, '"', $month == $context['event']['month'] ? ' selected="selected"' : '', '>', $txt['months'][$month], ' </option>';
echo '
</select>
', $txt['calendar_day'], '
<select name="day" id="day">';
// This prints out all the days in the current month - this changes dynamically as we switch months.
for ($day = 1; $day <= $context['event']['last_day']; $day++)
echo '
<option value="', $day, '"', $day == $context['event']['day'] ? ' selected="selected"' : '', '>', $day, ' </option>';
echo '
</select>
</div>
</fieldset>';
if (!empty($modSettings['cal_allowspan']) || $context['event']['new'])
echo '
<fieldset id="event_options">
<legend>', $txt['calendar_event_options'], '</legend>
<div class="event_options smalltext">
<ul class="event_options">';
// If events can span more than one day then allow the user to select how long it should last.
if (!empty($modSettings['cal_allowspan']))
{
echo '
<li>
', $txt['calendar_numb_days'], '
<select name="span">';
for ($days = 1; $days <= $modSettings['cal_maxspan']; $days++)
echo '
<option value="', $days, '"', $context['event']['span'] == $days ? ' selected="selected"' : '', '>', $days, ' </option>';
echo '
</select>
</li>';
}
// If this is a new event let the user specify which board they want the linked post to be put into.
if ($context['event']['new'])
{
echo '
<li>
', $txt['calendar_link_event'], '
<input type="checkbox" style="vertical-align: middle;" class="input_check" name="link_to_board" checked="checked" onclick="toggleLinked(this.form);">
</li>
<li>
', $txt['calendar_post_in'], '
<select id="board" name="board" onchange="this.form.submit();">';
foreach ($context['event']['categories'] as $category)
{
echo '
<optgroup label="', $category['name'], '">';
foreach ($category['boards'] as $board)
echo '
<option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '', ' ', $board['name'], ' </option>';
echo '
</optgroup>';
}
echo '
</select>
</li>';
}
if (!empty($modSettings['cal_allowspan']) || $context['event']['new'])
echo '
</ul>
</div>
</fieldset>';
echo '
<div class="righttext">
<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">';
// Delete button?
if (empty($context['event']['new']))
echo '
<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" onclick="return confirm(\'', $txt['calendar_confirm_delete'], '\');" class="button_submit">';
echo '
<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">
</div>
</div>
</div>
</div>
</form>
<br class="clear">';
}
// Display a monthly calendar grid.
function template_show_month_grid($grid_name)
{
global $context, $settings, $options, $txt, $scripturl, $modSettings, $smcFunc;
if (!isset($context['calendar_grid_' . $grid_name]))
return false;
$calendar_data = &$context['calendar_grid_' . $grid_name];
$colspan = !empty($calendar_data['show_week_links']) ? 8 : 7;
if (empty($calendar_data['disable_title']))
{
echo '
<div class="cat_bar">
<h3 class="catbg centertext" style="font-size: ', $calendar_data['size'] == 'large' ? 'large' : 'small', ';">';
if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'])
echo '
<a href="', $calendar_data['previous_calendar']['href'], '">«</a>';
if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'])
echo '
<span class="floatright"><a href="', $calendar_data['next_calendar']['href'], '">»</a></span>';
if ($calendar_data['show_next_prev'])
echo '
', $txt['months_titles'][$calendar_data['current_month']], ' ', $calendar_data['current_year'];
else
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>';
echo '
</h3>
</div>';
}
echo '
<table cellspacing="1" class="calendar_table">';
// Show each day of the week.
if (empty($calendar_data['disable_day_titles']))
{
echo '
<tr class="title_bar">';
if (!empty($calendar_data['show_week_links']))
echo '
<th> </th>';
foreach ($calendar_data['week_days'] as $day)
{
echo '
<th class="days" scope="col" ', $calendar_data['size'] == 'small' ? 'style="font-size: x-small;"' : '', '>', !empty($calendar_data['short_day_titles']) ? ($smcFunc['substr']($txt['days'][$day], 0, 1)) : $txt['days'][$day], '</th>';
}
echo '
</tr>';
}
/* Each week in weeks contains the following:
days (a list of days), number (week # in the year.) */
foreach ($calendar_data['weeks'] as $week)
{
echo '
<tr class="windowbg">';
if (!empty($calendar_data['show_week_links']))
echo '
<td class="weeks">
<a href="', $scripturl, '?action=calendar;viewweek;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $week['days'][0]['day'], '">»</a>
</td>';
/* Every day has the following:
day (# in month), is_today (is this day *today*?), is_first_day (first day of the week?),
holidays, events, birthdays. (last three are lists.) */
foreach ($week['days'] as $day)
{
// If this is today, make it a different color and show a border.
echo '
<td style="height: ', $calendar_data['size'] == 'small' ? '20' : '100', 'px; padding: 2px;', $calendar_data['size'] == 'small' ? 'font-size: x-small;' : '', '" class="', $day['is_today'] ? 'calendar_today ' : '', 'days">';
// Skip it if it should be blank - it's not a day if it has no number.
if (!empty($day['day']))
{
// Should the day number be a link?
if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
echo '
<a href="', $scripturl, '?action=calendar;sa=post;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $day['day'], '</a>';
else
echo '
', $day['day'];
// Is this the first day of the week? (and are we showing week numbers?)
if ($day['is_first_day'] && $calendar_data['size'] != 'small')
echo '<span class="smalltext"> - <a href="', $scripturl, '?action=calendar;viewweek;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '">', $txt['calendar_week'], ' ', $week['number'], '</a></span>';
// Are there any holidays?
if (!empty($day['holidays']))
echo '
<div class="smalltext holiday">', $txt['calendar_prompt'], ' ', implode(', ', $day['holidays']), '</div>';
// Show any birthdays...
if (!empty($day['birthdays']))
{
echo '
<div class="smalltext">
<span class="birthday">', $txt['birthdays'], '</span>';
/* Each of the birthdays has:
id, name (person), age (if they have one set?), and is_last. (last in list?) */
$use_js_hide = empty($context['show_all_birthdays']) && count($day['birthdays']) > 15;
$count = 0;
foreach ($day['birthdays'] as $member)
{
echo '
<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide)? '' : ', ';
// Stop at ten?
if ($count == 10 && $use_js_hide)
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;">, ';
$count++;
}
if ($use_js_hide)
echo '
</span>';
echo '
</div>';
}
// Any special posted events?
if (!empty($day['events']))
{
echo '
<div class="smalltext">
<span class="event">', $txt['events'], '</span>';
/* The events are made up of:
title, href, is_last, can_edit (are they allowed to?), and modify_href. */
foreach ($day['events'] as $event)
{
// If they can edit the event, show a star they can click on....
if ($event['can_edit'])
echo '
<a class="modify_event" href="', $event['modify_href'], '"><img src="' . $settings['images_url'] . '/icons/modify_small.gif" alt="*"></a>';
echo '
', $event['link'], $event['is_last'] ? '' : ', ';
}
echo '
</div>';
}
}
echo '
</td>';
}
echo '
</tr>';
}
echo '
</table>';
}
// Or show a weekly one?
function template_show_week_grid($grid_name)
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;
if (!isset($context['calendar_grid_' . $grid_name]))
return false;
$calendar_data = &$context['calendar_grid_' . $grid_name];
// Loop through each month (At least one) and print out each day.
foreach ($calendar_data['months'] as $month_data)
{
echo '
<div class="cat_bar">
<h3 class="catbg weekly">';
if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && empty($done_title))
echo '
<a href="', $calendar_data['previous_week']['href'], '">«</a>';
if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && empty($done_title))
echo '
<span class="floatright"><a href="', $calendar_data['next_week']['href'], '">»</a></span>';
echo '
<a href="', $scripturl, '?action=calendar;month=', $month_data['current_month'], ';year=', $month_data['current_year'], '">', $txt['months_titles'][$month_data['current_month']], ' ', $month_data['current_year'], '</a>', empty($done_title) && !empty($calendar_data['week_number']) ? (' - ' . $txt['calendar_week'] . ' ' . $calendar_data['week_number']) : '', '
</h3>
</div>';
$done_title = true;
echo '
<table width="100%" class="calendar_table weeklist" cellspacing="1" cellpadding="0">';
foreach ($month_data['days'] as $day)
{
echo '
<tr>
<td colspan="2">
<div class="title_bar">
<h4 class="titlebg">', $txt['days'][$day['day_of_week']], '</h4>
</div>
</td>
</tr>
<tr class="windowbg">
<td>';
// Should the day number be a link?
if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
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'], '">', $day['day'], '</a>';
else
echo '
', $day['day'];
echo '
</td>
<td class="', $day['is_today'] ? 'calendar_today' : '', ' weekdays">';
// Are there any holidays?
if (!empty($day['holidays']))
echo '
<div class="smalltext holiday">', $txt['calendar_prompt'], ' ', implode(', ', $day['holidays']), '</div>';
// Show any birthdays...
if (!empty($day['birthdays']))
{
echo '
<div class="smalltext">
<span class="birthday">', $txt['birthdays'], '</span>';
/* Each of the birthdays has:
id, name (person), age (if they have one set?), and is_last. (last in list?) */
foreach ($day['birthdays'] as $member)
echo '
<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] ? '' : ', ';
echo '
</div>';
}
// Any special posted events?
if (!empty($day['events']))
{
echo '
<div class="smalltext">
<span class="event">', $txt['events'], '</span>';
/* The events are made up of:
title, href, is_last, can_edit (are they allowed to?), and modify_href. */
foreach ($day['events'] as $event)
{
// If they can edit the event, show a star they can click on....
if ($event['can_edit'])
echo '
<a href="', $event['modify_href'], '"><img src="' . $settings['images_url'] . '/icons/modify_small.gif" alt="*"></a> ';
echo '
', $event['link'], $event['is_last'] ? '' : ', ';
}
echo '
</div>';
}
echo '
</td>
</tr>';
}
echo '
</table>';
}
}
function template_bcd()
{
global $context, $scripturl;
echo '
<table cellpadding="0" cellspacing="1" align="center">
<caption class="titlebg">BCD Clock</caption>
<tr class="windowbg">';
$alt = false;
foreach ($context['clockicons'] as $t => $v)
{
echo '
<td style="padding-', $alt ? 'right' : 'left', ': 1.5em;" valign="bottom">';
foreach ($v as $i)
echo '
<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '"><br>';
echo '
</td>';
$alt = !$alt;
}
echo '
</tr>
</table>
<p align="center"><a href="', $scripturl, '?action=clock;rb">Are you hardcore?</a></p>
<script type="text/javascript"><!-- // --><![CDATA[
var icons = new Object();';
foreach ($context['clockicons'] as $t => $v)
{
foreach ($v as $i)
echo '
icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
}
echo '
function update()
{
// Get the current time
var time = new Date();
var hour = time.getHours();
var min = time.getMinutes();
var sec = time.getSeconds();
// Break it up into individual digits
var h1 = parseInt(hour / 10);
var h2 = hour % 10;
var m1 = parseInt(min / 10);
var m2 = min % 10;
var s1 = parseInt(sec / 10);
var s2 = sec % 10;
// For each digit figure out which ones to turn off and which ones to turn on
var turnon = new Array();';
foreach ($context['clockicons'] as $t => $v)
{
foreach ($v as $i)
echo '
if (', $t, ' >= ', $i, ')
{
turnon.push("', $t, '_', $i, '");
', $t, ' -= ', $i, ';
}';
}
echo '
for (var i in icons)
if (!in_array(i, turnon))
icons[i].src = "', $context['offimg'], '";
else
icons[i].src = "', $context['onimg'], '";
window.setTimeout("update();", 500);
}
// Checks for variable in theArray.
function in_array(variable, theArray)
{
for (var i = 0; i < theArray.length; i++)
{
if (theArray[i] == variable)
return true;
}
return false;
}
update();
// ]]></script>';
}
function template_hms()
{
global $context, $scripturl;
echo '
<table cellpadding="0" cellspacing="1" align="center">
<caption class="titlebg">Binary Clock</caption>';
foreach ($context['clockicons'] as $t => $v)
{
echo '
<tr class="windowbg">
<td align="right">';
foreach ($v as $i)
echo '
<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '">';
echo '
</td>';
}
echo '
</tr>
<tr class="windowbg"><td colspan="6" align="center"><a href="', $scripturl, '?action=clock">Too tough for you?</a></td></tr>
</table>';
echo '
<script type="text/javascript"><!-- // --><![CDATA[
var icons = new Object();';
foreach ($context['clockicons'] as $t => $v)
{
foreach ($v as $i)
echo '
icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
}
echo '
function update()
{
// Get the current time
var time = new Date();
var h = time.getHours();
var m = time.getMinutes();
var s = time.getSeconds();
// For each digit figure out which ones to turn off and which ones to turn on
var turnon = new Array();';
foreach ($context['clockicons'] as $t => $v)
{
foreach ($v as $i)
echo '
if (', $t, ' >= ', $i, ')
{
turnon.push("', $t, '_', $i, '");
', $t, ' -= ', $i, ';
}';
}
echo '
for (var i in icons)
if (!in_array(i, turnon))
icons[i].src = "', $context['offimg'], '";
else
icons[i].src = "', $context['onimg'], '";
window.setTimeout("update();", 500);
}
// Checks for variable in theArray.
function in_array(variable, theArray)
{
for (var i = 0; i < theArray.length; i++)
{
if (theArray[i] == variable)
return true;
}
return false;
}
update();
// ]]></script>';
}
function template_omfg()
{
global $context, $scripturl;
echo '
<table cellpadding="0" cellspacing="1" align="center">
<caption class="titlebg">OMFG Binary Clock</caption>';
foreach ($context['clockicons'] as $t => $v)
{
echo '
<tr class="windowbg">
<td align="right">';
foreach ($v as $i)
echo '
<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '">';
echo '
</td>';
}
echo '
</tr>
</table>';
echo '
<script type="text/javascript"><!-- // --><![CDATA[
var icons = new Object();';
foreach ($context['clockicons'] as $t => $v)
{
foreach ($v as $i)
echo '
icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
}
echo '
function update()
{
// Get the current time
var time = new Date();
var month = time.getMonth() + 1;
var day = time.getDate();
var year = time.getFullYear();
year = year % 100;
var hour = time.getHours();
var min = time.getMinutes();
var sec = time.getSeconds();
// For each digit figure out which ones to turn off and which ones to turn on
var turnon = new Array();';
foreach ($context['clockicons'] as $t => $v)
{
foreach ($v as $i)
echo '
if (', $t, ' >= ', $i, ')
{
turnon.push("', $t, '_', $i, '");
', $t, ' -= ', $i, ';
}';
}
echo '
for (var i in icons)
if (!in_array(i, turnon))
icons[i].src = "', $context['offimg'], '";
else
icons[i].src = "', $context['onimg'], '";
window.setTimeout("update();", 500);
}
// Checks for variable in theArray.
function in_array(variable, theArray)
{
for (var i = 0; i < theArray.length; i++)
{
if (theArray[i] == variable)
return true;
}
return false;
}
update();
// ]]></script>';
}
function template_thetime()
{
global $context, $scripturl;
echo '
<table cellpadding="0" cellspacing="0" border="1" align="center">
<caption>The time you requested</caption>';
foreach ($context['clockicons'] as $t => $v)
{
echo '
<tr class="windowbg">
<td align="right">';
foreach ($v as $i)
echo '
<img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="">';
echo '
</td>';
}
echo '
</tr>
</table>';
}
?>