Calendar.template.php 24 KB

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