Calendar.template.php 24 KB

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