Calendar.template.php 25 KB

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