Calendar.template.php 24 KB

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