Calendar.template.php 24 KB

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