2
0

Calendar.template.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2014 Simple Machines and individual contributors
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. // Our main calendar template, which encapsulates weeks and months.
  13. function template_main()
  14. {
  15. global $context;
  16. // The main calendar wrapper.
  17. echo '<div id="calendar">';
  18. // Show the mini-blocks if they're enabled.
  19. if (empty($context['blocks_disabled']))
  20. {
  21. echo '
  22. <div id="month_grid">
  23. ', template_show_month_grid('prev', true), '
  24. ', template_show_month_grid('current', true), '
  25. ', template_show_month_grid('next', true), '
  26. </div>
  27. ';
  28. }
  29. // Are we viewing a specific week or a specific month?
  30. if (isset($_GET['viewweek']))
  31. {
  32. echo '
  33. <div id="main_grid"', !empty($context['blocks_disabled']) ? ' class="full_width"' : '', '>
  34. ', template_show_week_grid('main'), '
  35. </div>
  36. ';
  37. }
  38. else
  39. {
  40. echo '
  41. <div id="main_grid"', !empty($context['blocks_disabled']) ? ' class="full_width"' : '', '>
  42. ', template_show_month_grid('main'), '
  43. </div>
  44. ';
  45. }
  46. // Close our wrapper.
  47. echo '<br class="clear" />
  48. </div>';
  49. }
  50. // Display a monthly calendar grid.
  51. function template_show_month_grid($grid_name, $is_mini = false)
  52. {
  53. global $context, $settings, $txt, $scripturl, $modSettings;
  54. // If the grid doesn't exist, no point in proceeding.
  55. if (!isset($context['calendar_grid_' . $grid_name]))
  56. return false;
  57. // A handy little pointer variable.
  58. $calendar_data = &$context['calendar_grid_' . $grid_name];
  59. // Some conditions for whether or not we should show the week links *here*.
  60. if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false)))
  61. $show_week_links = true;
  62. else
  63. $show_week_links = false;
  64. // Assuming that we've not disabled it, show the title block!
  65. if (empty($calendar_data['disable_title']))
  66. {
  67. echo '
  68. <div class="cat_bar">
  69. <h3 class="catbg centertext largetext">';
  70. // Previous Link: If we're showing prev / next and it's not a mini-calendar.
  71. if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
  72. {
  73. echo '
  74. <span class="floatleft xlarge_text">
  75. <a href="', $calendar_data['previous_calendar']['href'], '">&#171;</a>
  76. </span>
  77. ';
  78. }
  79. // Arguably the most exciting part, the title!
  80. echo '<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>';
  81. // Next Link: if we're showing prev / next and it's not a mini-calendar.
  82. if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
  83. {
  84. echo '
  85. <span class="floatright xlarge_text">
  86. <a href="', $calendar_data['next_calendar']['href'], '">&#187;</a>
  87. </span>
  88. ';
  89. }
  90. echo '
  91. </h3>
  92. </div>
  93. ';
  94. }
  95. // Finally, the main calendar table.
  96. echo '<table class="calendar_table">';
  97. // Show each day of the week.
  98. if (empty($calendar_data['disable_day_titles']))
  99. {
  100. echo '<tr>';
  101. // If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
  102. if ($show_week_links === true)
  103. echo '<th>&nbsp;</th>';
  104. // Now, loop through each actual day of the week.
  105. foreach ($calendar_data['week_days'] as $day)
  106. {
  107. echo '<th class="days" scope="col">', !empty($calendar_data['short_day_titles']) || $is_mini === true ? $txt['days_short'][$day] : $txt['days'][$day], '</th>';
  108. }
  109. echo '</tr>';
  110. }
  111. // Our looping begins on a per-week basis.
  112. foreach ($calendar_data['weeks'] as $week)
  113. {
  114. // Some useful looping variables.
  115. $current_month_started = false;
  116. $count = 1;
  117. $final_count = 1;
  118. echo '<tr class="days_wrapper">';
  119. // This is where we add the actual week link, if enabled on this location.
  120. if ($show_week_links === true)
  121. {
  122. echo '
  123. <td class="windowbg2 weeks">
  124. <a href="', $scripturl, '?action=calendar;viewweek;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $week['days'][0]['day'], '" title="', $txt['calendar_view_week'], '">&#187;</a>
  125. </td>
  126. ';
  127. }
  128. // Now loop through each day in the week we're on.
  129. foreach ($week['days'] as $day)
  130. {
  131. // What classes should each day inherit? Day is default.
  132. $classes = array('days');
  133. if (!empty($day['day']))
  134. {
  135. // Default Classes (either compact or comfortable and either calendar_today or windowbg).
  136. $classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
  137. $classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
  138. // Additional classes are given for events, holidays, and birthdays.
  139. if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
  140. {
  141. if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1,3)))
  142. $classes[] = 'events';
  143. elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2,3)))
  144. $classes[] = 'events';
  145. }
  146. if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
  147. {
  148. if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1,3)))
  149. $classes[] = 'holidays';
  150. elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2,3)))
  151. $classes[] = 'holidays';
  152. }
  153. if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
  154. {
  155. if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1,3)))
  156. $classes[] = 'birthdays';
  157. elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2,3)))
  158. $classes[] = 'birthdays';
  159. }
  160. }
  161. else
  162. $classes[] = 'disabled';
  163. // Now, implode the classes for each day.
  164. echo '<td class="', implode(' ', $classes), '">';
  165. // If it's within this current month, go ahead and begin.
  166. if (!empty($day['day']))
  167. {
  168. // If it's the first day of this month and not a mini-calendar, we'll add the month title - whether short or full.
  169. $title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : '';
  170. // The actual day number - be it a link, or just plain old text!
  171. if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
  172. echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
  173. else
  174. echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
  175. // A lot of stuff, we're not showing on mini-calendars to conserve space.
  176. if ($is_mini === false)
  177. {
  178. // If this is the first day of a week and we're showing week numbers, go ahead and do so now.
  179. if ($day['is_first_day'] && !empty($context['tpl_show_week_num']))
  180. 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>';
  181. // Holidays are always fun, let's show them!
  182. if (!empty($day['holidays']))
  183. echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
  184. // Happy Birthday Dear, Member!
  185. if (!empty($day['birthdays']))
  186. {
  187. echo '
  188. <div class="smalltext">
  189. <span class="birthday">', $txt['birthdays'], '</span>';
  190. /* Each of the birthdays has:
  191. id, name (person), age (if they have one set?), and is_last. (last in list?) */
  192. $use_js_hide = empty($context['show_all_birthdays']) && count($day['birthdays']) > 15;
  193. $birthday_count = 0;
  194. foreach ($day['birthdays'] as $member)
  195. {
  196. echo '<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) ? '' : ', ';
  197. // 9...10! Let's stop there.
  198. if ($birthday_count == 10 && $use_js_hide)
  199. // !!TODO - Inline CSS and JavaScript should be moved.
  200. 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;">, ';
  201. ++$birthday_count;
  202. }
  203. if ($use_js_hide)
  204. echo '</span>';
  205. echo '</div>';
  206. }
  207. // Any special posted events?
  208. if (!empty($day['events']))
  209. {
  210. echo '
  211. <div class="smalltext lefttext">
  212. <span class="event">', $txt['events'], '</span><br />';
  213. /* The events are made up of:
  214. title, href, is_last, can_edit (are they allowed to?), and modify_href. */
  215. foreach ($day['events'] as $event)
  216. {
  217. // If they can edit the event, show an icon they can click on....
  218. if ($event['can_edit'])
  219. {
  220. echo '
  221. <a class="modify_event" href="', $event['modify_href'], '">
  222. <img src="', $settings['images_url'], '/icons/calendar_modify.png" alt="*" title="', $txt['calendar_edit'], '" class="calendar_icon" />
  223. </a>
  224. ';
  225. }
  226. // Exporting!
  227. if ($event['can_export'])
  228. {
  229. echo '
  230. <a class="modify_event" href="', $event['export_href'], '">
  231. <img src="', $settings['images_url'], '/icons/calendar_export.png" alt=">" title="', $txt['calendar_export'], '" class="calendar_icon" />
  232. </a>
  233. ';
  234. }
  235. echo $event['link'], $event['is_last'] ? '' : '<br />';
  236. }
  237. echo '</div>';
  238. }
  239. }
  240. $current_month_started = $count;
  241. }
  242. // Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
  243. elseif ($is_mini === false)
  244. {
  245. if ($current_month_started === false && !empty($context['calendar_grid_prev']))
  246. echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- + 1, '</a>';
  247. elseif (!empty($context['calendar_grid_next']))
  248. echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
  249. }
  250. // Close this day and increase var count.
  251. echo '</td>';
  252. ++$count;
  253. }
  254. echo '</tr>';
  255. }
  256. // Quick Month Navigation + Post Event Link on Main Grids!
  257. if ($is_mini === false)
  258. template_calendar_base($show_week_links === true ? 8 : 7);
  259. // The end of our main table.
  260. echo '</table>';
  261. }
  262. // Or show a weekly one?
  263. function template_show_week_grid($grid_name)
  264. {
  265. global $context, $settings, $txt, $scripturl, $modSettings;
  266. // We might have no reason to proceed, if the variable isn't there.
  267. if (!isset($context['calendar_grid_' . $grid_name]))
  268. return false;
  269. // Handy pointer.
  270. $calendar_data = &$context['calendar_grid_' . $grid_name];
  271. // At the very least, we have one month. Possibly two, though.
  272. $iteration = 1;
  273. $num_months = count($calendar_data['months']);
  274. foreach ($calendar_data['months'] as $month_data)
  275. {
  276. // For our first iteration, we'll add a nice header!
  277. if ($iteration == 1)
  278. {
  279. echo '
  280. <div class="cat_bar">
  281. <h3 class="catbg centertext largetext">';
  282. // Previous Week Link...
  283. if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
  284. {
  285. echo '
  286. <span class="floatleft xlarge_text>
  287. <a href="', $calendar_data['previous_week']['href'], '">&#171;</a>
  288. </span>
  289. ';
  290. }
  291. // The Month Title + Week Number...
  292. if (!empty($calendar_data['week_number']))
  293. echo $txt['calendar_week'], ' ', $calendar_data['week_number'], ' - ', $month_data['current_year'];
  294. // Next Week Link...
  295. if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
  296. {
  297. echo '
  298. <span class="floatright xlarge_text">
  299. <a href="', $calendar_data['next_week']['href'], '">&#187;</a>
  300. </span>
  301. ';
  302. }
  303. echo '
  304. </h3>
  305. </div>
  306. ';
  307. }
  308. // Our actual month...
  309. echo '
  310. <div class="week_month_title">
  311. <a href="', $scripturl, '?action=calendar;month=', $month_data['current_month'], '">
  312. ', $txt['months_titles'][$month_data['current_month']], '
  313. </a>
  314. </div>
  315. ';
  316. // The main table grid for $this week.
  317. echo '
  318. <table class="table_grid calendar_week">
  319. <tr>
  320. <th class="days" scope="col">', $txt['calendar_day'], '</th>
  321. <th class="days" scope="col">', $txt['events'], '</th>
  322. <th class="days" scope="col">', $txt['calendar_prompt'], '</th>
  323. <th class="days" scope="col">', $txt['birthdays'], '</th>
  324. </tr>';
  325. // Each day of the week.
  326. foreach ($month_data['days'] as $day)
  327. {
  328. // How should we be highlighted or otherwise not...?
  329. $classes = array('days');
  330. $classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
  331. $classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
  332. echo '
  333. <tr class="days_wrapper">
  334. <td class="', implode(' ', $classes), ' act_day">';
  335. // Should the day number be a link?
  336. if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
  337. echo '<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>';
  338. else
  339. echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
  340. echo '</td>
  341. <td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', '">';
  342. // Show any events...
  343. if (!empty($day['events']))
  344. {
  345. echo '<div class="event_cont floatleft">';
  346. foreach ($day['events'] as $event)
  347. {
  348. // If they can edit the event, show a star they can click on....
  349. if (!empty($event['can_edit']))
  350. {
  351. echo '
  352. <a href="', $event['modify_href'], '">
  353. <img src="', $settings['images_url'], '/icons/calendar_modify.png" alt="*" title="', $txt['calendar_edit'], '" class="calendar_icon" />
  354. </a>
  355. ';
  356. }
  357. // Can we export? Sweet.
  358. if (!empty($event['can_export']))
  359. {
  360. echo '
  361. <a class="modify_event" href="', $event['export_href'], '">
  362. <img src="', $settings['images_url'], '/icons/calendar_export.png" alt=">" title="', $txt['calendar_export'], '" class="calendar_icon" />
  363. </a>
  364. ';
  365. }
  366. echo $event['link'], $event['is_last'] ? '' : '<br />';
  367. }
  368. echo '
  369. </div>
  370. <div class="active_post_event floatright">
  371. <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'], '">
  372. <img src="', $settings['images_url'], '/icons/plus.png" alt="*" title="', $txt['calendar_post_event'], '" />
  373. </a>
  374. </div>
  375. <br class="clear" />
  376. ';
  377. }
  378. else
  379. {
  380. if (!empty($context['can_post']))
  381. {
  382. echo '
  383. <div class="week_add_event">
  384. <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['calendar_post_event'], '</a>
  385. </div>
  386. ';
  387. }
  388. }
  389. echo '</td>
  390. <td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', '">';
  391. // Show any holidays!
  392. if (!empty($day['holidays']))
  393. echo implode('<br />', $day['holidays']);
  394. echo '</td>
  395. <td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', '">';
  396. // Show any birthdays...
  397. if (!empty($day['birthdays']))
  398. {
  399. foreach ($day['birthdays'] as $member)
  400. {
  401. echo '
  402. <a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], '</a>
  403. ', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '
  404. ', $member['is_last'] ? '' : '<br />';
  405. }
  406. }
  407. echo '</td>
  408. </tr>
  409. ';
  410. }
  411. // We'll show the lower column after our last month is shown.
  412. if ($iteration == $num_months)
  413. template_calendar_base(4);
  414. // Increase iteration for loop counting.
  415. ++$iteration;
  416. echo '
  417. </table>
  418. ';
  419. }
  420. }
  421. /*
  422. * Calendar Grid Base
  423. *
  424. * This function is ONLY designed for use
  425. * within an existing table element.
  426. *
  427. * @param int $col_span = 1
  428. */
  429. function template_calendar_base($col_span = 1)
  430. {
  431. global $context, $scripturl, $txt;
  432. echo '
  433. <tr>
  434. <td id="post_event" colspan="', $col_span, '">
  435. ', template_button_strip($context['calendar_buttons'], 'right'), '
  436. <form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
  437. <select name="month" id="input_month">';
  438. // Show a select box with all the months.
  439. foreach ($txt['months'] as $number => $month)
  440. {
  441. echo '<option value="', $number, '"', $number == $context['current_month'] ? ' selected="selected"' : '', '>', $month, '</option>';
  442. }
  443. echo '</select>
  444. <select name="year">';
  445. // Show a link for every year.....
  446. for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++)
  447. {
  448. echo '<option value="', $year, '"', $year == $context['current_year'] ? ' selected="selected"' : '', '>', $year, '</option>';
  449. }
  450. echo '</select>
  451. <input type="submit" class="button_submit" id="view_button" value="', $txt['view'], '" />
  452. </form>
  453. <br class="clear" />
  454. </td>
  455. </tr>
  456. ';
  457. }
  458. // Template for posting a calendar event.
  459. function template_event_post()
  460. {
  461. global $context, $txt, $scripturl;
  462. // Start the javascript for drop down boxes...
  463. echo '
  464. <script><!-- // --><![CDATA[
  465. var monthLength;
  466. monthLength = [
  467. 31, 28, 31, 30,
  468. 31, 30, 31, 31,
  469. 30, 31, 30, 31
  470. ];
  471. function generateDays()
  472. {
  473. var days, selected, dayElement, monthElement, yearElement;
  474. dayElement = document.getElementById("day"), yearElement = document.getElementById("year"), monthElement = document.getElementById("month");
  475. monthLength[1] = 28;
  476. if (yearElement.options[yearElement.selectedIndex].value % 4 == 0)
  477. monthLength[1] = 29;
  478. selected = dayElement.selectedIndex;
  479. while (dayElement.options.length)
  480. {
  481. dayElement.options[0] = null;
  482. }
  483. days = monthLength[monthElement.value - 1];
  484. for (i = 0; i <= days; ++i)
  485. {
  486. dayElement.options[dayElement.length] = new Option(i, i);
  487. }
  488. if (selected < days)
  489. dayElement.selectedIndex = selected;
  490. }
  491. // ]]></script>
  492. <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;">';
  493. if (!empty($context['event']['new']))
  494. echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '" />';
  495. // Start the main table.
  496. echo '
  497. <div id="post_event">
  498. <div class="cat_bar">
  499. <h3 class="catbg">
  500. ', $context['page_title'], '
  501. </h3>
  502. </div>';
  503. if (!empty($context['post_error']['messages']))
  504. {
  505. echo '
  506. <div class="errorbox">
  507. <dl class="event_error">
  508. <dt>
  509. ', $context['error_type'] == 'serious' ? '<strong>' . $txt['error_while_submitting'] . '</strong>' : '', '
  510. </dt>
  511. <dt class="error">
  512. ', implode('<br />', $context['post_error']['messages']), '
  513. </dt>
  514. </dl>
  515. </div>';
  516. }
  517. echo '
  518. <div class="roundframe">
  519. <fieldset id="event_main">
  520. <legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', '>', $txt['calendar_event_title'], '</span></legend>
  521. <input type="text" name="evtitle" maxlength="255" size="70" value="', $context['event']['title'], '" class="input_text" />
  522. <div class="smalltext" style="white-space: nowrap;">
  523. <input type="hidden" name="calendar" value="1" />', $txt['calendar_year'], '
  524. <select name="year" id="year" onchange="generateDays();">';
  525. // Show a list of all the years we allow...
  526. for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++)
  527. echo '
  528. <option value="', $year, '"', $year == $context['event']['year'] ? ' selected="selected"' : '', '>', $year, '&nbsp;</option>';
  529. echo '
  530. </select>
  531. ', $txt['calendar_month'], '
  532. <select name="month" id="month" onchange="generateDays();">';
  533. // There are 12 months per year - ensure that they all get listed.
  534. for ($month = 1; $month <= 12; $month++)
  535. echo '
  536. <option value="', $month, '"', $month == $context['event']['month'] ? ' selected="selected"' : '', '>', $txt['months'][$month], '&nbsp;</option>';
  537. echo '
  538. </select>
  539. ', $txt['calendar_day'], '
  540. <select name="day" id="day">';
  541. // This prints out all the days in the current month - this changes dynamically as we switch months.
  542. for ($day = 1; $day <= $context['event']['last_day']; $day++)
  543. echo '
  544. <option value="', $day, '"', $day == $context['event']['day'] ? ' selected="selected"' : '', '>', $day, '&nbsp;</option>';
  545. echo '
  546. </select>
  547. </div>
  548. </fieldset>';
  549. if (!empty($modSettings['cal_allowspan']) || $context['event']['new'])
  550. echo '
  551. <fieldset id="event_options">
  552. <legend>', $txt['calendar_event_options'], '</legend>
  553. <div class="event_options smalltext">
  554. <ul class="event_options">';
  555. // If events can span more than one day then allow the user to select how long it should last.
  556. if (!empty($modSettings['cal_allowspan']))
  557. {
  558. echo '
  559. <li>
  560. ', $txt['calendar_numb_days'], '
  561. <select name="span">';
  562. for ($days = 1; $days <= $modSettings['cal_maxspan']; $days++)
  563. echo '
  564. <option value="', $days, '"', $context['event']['span'] == $days ? ' selected="selected"' : '', '>', $days, '&nbsp;</option>';
  565. echo '
  566. </select>
  567. </li>';
  568. }
  569. // If this is a new event let the user specify which board they want the linked post to be put into.
  570. if ($context['event']['new'])
  571. {
  572. echo '
  573. <li>
  574. ', $txt['calendar_link_event'], '
  575. <input type="checkbox" style="vertical-align: middle;" class="input_check" name="link_to_board" checked="checked" onclick="toggleLinked(this.form);" />
  576. </li>
  577. <li>
  578. ', $txt['calendar_post_in'], '
  579. <select id="board" name="board" onchange="this.form.submit();">';
  580. foreach ($context['event']['categories'] as $category)
  581. {
  582. echo '
  583. <optgroup label="', $category['name'], '">';
  584. foreach ($category['boards'] as $board)
  585. echo '
  586. <option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
  587. echo '
  588. </optgroup>';
  589. }
  590. echo '
  591. </select>
  592. </li>';
  593. }
  594. if (!empty($modSettings['cal_allowspan']) || $context['event']['new'])
  595. echo '
  596. </ul>
  597. </div>
  598. </fieldset>';
  599. echo '
  600. <input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit" />';
  601. // Delete button?
  602. if (empty($context['event']['new']))
  603. echo '
  604. <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" onclick="return confirm(\'', $txt['calendar_confirm_delete'], '\');" class="button_submit" />';
  605. echo '
  606. <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
  607. <input type="hidden" name="eventid" value="', $context['event']['eventid'], '" />
  608. </div>
  609. </div>
  610. </form>';
  611. }
  612. function template_bcd()
  613. {
  614. global $context, $scripturl;
  615. $alt = false;
  616. echo '
  617. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  618. <tr>
  619. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;" colspan="6">BCD Clock</th>
  620. </tr>
  621. <tr class="windowbg">';
  622. foreach ($context['clockicons'] as $t => $v)
  623. {
  624. echo '<td style="padding-', $alt ? 'right' : 'left', ': 1.5em;">';
  625. foreach ($v as $i)
  626. {
  627. echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" /><br />';
  628. }
  629. echo '</td>';
  630. $alt = !$alt;
  631. }
  632. echo '</tr>
  633. <tr class="', $alt ? 'windowbg2' : 'windowbg', '" style="border-top: 1px solid #ccc; text-align: center;">
  634. <td colspan="6">
  635. <a href="', $scripturl, '?action=clock;rb">Are you hardcore?</a>
  636. </td>
  637. </tr>
  638. </table>
  639. <script><!-- // --><![CDATA[
  640. var icons = new Object();';
  641. foreach ($context['clockicons'] as $t => $v)
  642. {
  643. foreach ($v as $i)
  644. echo '
  645. icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
  646. }
  647. echo '
  648. function update()
  649. {
  650. // Get the current time
  651. var time = new Date();
  652. var hour = time.getHours();
  653. var min = time.getMinutes();
  654. var sec = time.getSeconds();
  655. // Break it up into individual digits
  656. var h1 = parseInt(hour / 10);
  657. var h2 = hour % 10;
  658. var m1 = parseInt(min / 10);
  659. var m2 = min % 10;
  660. var s1 = parseInt(sec / 10);
  661. var s2 = sec % 10;
  662. // For each digit figure out which ones to turn off and which ones to turn on
  663. var turnon = new Array();';
  664. foreach ($context['clockicons'] as $t => $v)
  665. {
  666. foreach ($v as $i)
  667. echo '
  668. if (', $t, ' >= ', $i, ')
  669. {
  670. turnon.push("', $t, '_', $i, '");
  671. ', $t, ' -= ', $i, ';
  672. }';
  673. }
  674. echo '
  675. for (var i in icons)
  676. if (!in_array(i, turnon))
  677. icons[i].src = "', $context['offimg'], '";
  678. else
  679. icons[i].src = "', $context['onimg'], '";
  680. window.setTimeout("update();", 500);
  681. }
  682. // Checks for variable in theArray.
  683. function in_array(variable, theArray)
  684. {
  685. for (var i = 0; i < theArray.length; i++)
  686. {
  687. if (theArray[i] == variable)
  688. return true;
  689. }
  690. return false;
  691. }
  692. update();
  693. // ]]></script>';
  694. }
  695. function template_hms()
  696. {
  697. global $context, $scripturl;
  698. $alt = false;
  699. echo '
  700. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  701. <tr>
  702. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">Binary Clock</th>
  703. </tr>';
  704. foreach ($context['clockicons'] as $t => $v)
  705. {
  706. echo '
  707. <tr class="', $alt ? 'windowbg2' : 'windowbg', '">
  708. <td>';
  709. foreach ($v as $i)
  710. {
  711. echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;" />';
  712. }
  713. echo '</td>
  714. </tr>
  715. ';
  716. $alt = !$alt;
  717. }
  718. echo '</tr>
  719. <tr class="', $alt ? 'windowbg2' : 'windowbg', '" style="border-top: 1px solid #ccc; text-align: center;">
  720. <td>
  721. <a href="', $scripturl, '?action=clock">Too tough for you?</a>
  722. </td>
  723. </tr>
  724. </table>
  725. ';
  726. echo '
  727. <script><!-- // --><![CDATA[
  728. var icons = new Object();';
  729. foreach ($context['clockicons'] as $t => $v)
  730. {
  731. foreach ($v as $i)
  732. echo '
  733. icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
  734. }
  735. echo '
  736. function update()
  737. {
  738. // Get the current time
  739. var time = new Date();
  740. var h = time.getHours();
  741. var m = time.getMinutes();
  742. var s = time.getSeconds();
  743. // For each digit figure out which ones to turn off and which ones to turn on
  744. var turnon = new Array();';
  745. foreach ($context['clockicons'] as $t => $v)
  746. {
  747. foreach ($v as $i)
  748. echo '
  749. if (', $t, ' >= ', $i, ')
  750. {
  751. turnon.push("', $t, '_', $i, '");
  752. ', $t, ' -= ', $i, ';
  753. }';
  754. }
  755. echo '
  756. for (var i in icons)
  757. if (!in_array(i, turnon))
  758. icons[i].src = "', $context['offimg'], '";
  759. else
  760. icons[i].src = "', $context['onimg'], '";
  761. window.setTimeout("update();", 500);
  762. }
  763. // Checks for variable in theArray.
  764. function in_array(variable, theArray)
  765. {
  766. for (var i = 0; i < theArray.length; i++)
  767. {
  768. if (theArray[i] == variable)
  769. return true;
  770. }
  771. return false;
  772. }
  773. update();
  774. // ]]></script>';
  775. }
  776. function template_omfg()
  777. {
  778. global $context;
  779. $alt = false;
  780. echo '
  781. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  782. <tr>
  783. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">OMFG Binary Clock</th>
  784. </tr>';
  785. foreach ($context['clockicons'] as $t => $v)
  786. {
  787. echo '
  788. <tr class="', $alt ? 'windowbg2' : 'windowbg', '">
  789. <td>';
  790. foreach ($v as $i)
  791. {
  792. echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;" />';
  793. }
  794. echo '</td>
  795. </tr>
  796. ';
  797. $alt = !$alt;
  798. }
  799. echo '</tr>
  800. </table>
  801. ';
  802. echo '
  803. <script><!-- // --><![CDATA[
  804. var icons = new Object();';
  805. foreach ($context['clockicons'] as $t => $v)
  806. {
  807. foreach ($v as $i)
  808. echo '
  809. icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
  810. }
  811. echo '
  812. function update()
  813. {
  814. // Get the current time
  815. var time = new Date();
  816. var month = time.getMonth() + 1;
  817. var day = time.getDate();
  818. var year = time.getFullYear();
  819. year = year % 100;
  820. var hour = time.getHours();
  821. var min = time.getMinutes();
  822. var sec = time.getSeconds();
  823. // For each digit figure out which ones to turn off and which ones to turn on
  824. var turnon = new Array();';
  825. foreach ($context['clockicons'] as $t => $v)
  826. {
  827. foreach ($v as $i)
  828. echo '
  829. if (', $t, ' >= ', $i, ')
  830. {
  831. turnon.push("', $t, '_', $i, '");
  832. ', $t, ' -= ', $i, ';
  833. }';
  834. }
  835. echo '
  836. for (var i in icons)
  837. if (!in_array(i, turnon))
  838. icons[i].src = "', $context['offimg'], '";
  839. else
  840. icons[i].src = "', $context['onimg'], '";
  841. window.setTimeout("update();", 500);
  842. }
  843. // Checks for variable in theArray.
  844. function in_array(variable, theArray)
  845. {
  846. for (var i = 0; i < theArray.length; i++)
  847. {
  848. if (theArray[i] == variable)
  849. return true;
  850. }
  851. return false;
  852. }
  853. update();
  854. // ]]></script>';
  855. }
  856. function template_thetime()
  857. {
  858. global $context;
  859. $alt = false;
  860. echo '
  861. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  862. <tr>
  863. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">The time you requested</th>
  864. </tr>';
  865. foreach ($context['clockicons'] as $v)
  866. {
  867. echo '
  868. <tr class="', $alt ? 'windowbg2' : 'windowbg', '">
  869. <td>';
  870. foreach ($v as $i)
  871. {
  872. echo '<img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="" style="padding: 2px;" />';
  873. }
  874. echo '</td>
  875. </tr>
  876. ';
  877. $alt = !$alt;
  878. }
  879. echo '
  880. </table>
  881. ';
  882. }
  883. ?>