2
0

Calendar.template.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  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. // Holidays are always fun, let's show them!
  179. if (!empty($day['holidays']))
  180. echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
  181. // Happy Birthday Dear, Member!
  182. if (!empty($day['birthdays']))
  183. {
  184. echo '
  185. <div class="smalltext">
  186. <span class="birthday">', $txt['birthdays'], '</span>';
  187. /* Each of the birthdays has:
  188. id, name (person), age (if they have one set?), and is_last. (last in list?) */
  189. $use_js_hide = empty($context['show_all_birthdays']) && count($day['birthdays']) > 15;
  190. $birthday_count = 0;
  191. foreach ($day['birthdays'] as $member)
  192. {
  193. 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) ? '' : ', ';
  194. // 9...10! Let's stop there.
  195. if ($birthday_count == 10 && $use_js_hide)
  196. // !!TODO - Inline CSS and JavaScript should be moved.
  197. 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;">, ';
  198. ++$birthday_count;
  199. }
  200. if ($use_js_hide)
  201. echo '</span>';
  202. echo '</div>';
  203. }
  204. // Any special posted events?
  205. if (!empty($day['events']))
  206. {
  207. echo '
  208. <div class="smalltext lefttext">
  209. <span class="event">', $txt['events'], '</span><br>';
  210. /* The events are made up of:
  211. title, href, is_last, can_edit (are they allowed to?), and modify_href. */
  212. foreach ($day['events'] as $event)
  213. {
  214. // If they can edit the event, show an icon they can click on....
  215. if ($event['can_edit'])
  216. {
  217. echo '
  218. <a class="modify_event" href="', $event['modify_href'], '">
  219. <img src="', $settings['images_url'], '/icons/calendar_modify.png" alt="*" title="', $txt['calendar_edit'], '" class="calendar_icon">
  220. </a>
  221. ';
  222. }
  223. // Exporting!
  224. if ($event['can_export'])
  225. {
  226. echo '
  227. <a class="modify_event" href="', $event['export_href'], '">
  228. <img src="', $settings['images_url'], '/icons/calendar_export.png" alt=">" title="', $txt['calendar_export'], '" class="calendar_icon">
  229. </a>
  230. ';
  231. }
  232. echo $event['is_selected'] ? '<div class="sel_event">' . $event['link'] . '</div>' : $event['link'], $event['is_last'] ? '' : '<br>';
  233. }
  234. echo '</div>';
  235. }
  236. }
  237. $current_month_started = $count;
  238. }
  239. // Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
  240. elseif ($is_mini === false)
  241. {
  242. if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
  243. 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>';
  244. elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
  245. 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>';
  246. }
  247. // Close this day and increase var count.
  248. echo '</td>';
  249. ++$count;
  250. }
  251. echo '</tr>';
  252. }
  253. // Quick Month Navigation + Post Event Link on Main Grids!
  254. if ($is_mini === false)
  255. template_calendar_base($show_week_links === true ? 8 : 7);
  256. // The end of our main table.
  257. echo '</table>';
  258. }
  259. // Or show a weekly one?
  260. function template_show_week_grid($grid_name)
  261. {
  262. global $context, $settings, $txt, $scripturl, $modSettings;
  263. // We might have no reason to proceed, if the variable isn't there.
  264. if (!isset($context['calendar_grid_' . $grid_name]))
  265. return false;
  266. // Handy pointer.
  267. $calendar_data = &$context['calendar_grid_' . $grid_name];
  268. // At the very least, we have one month. Possibly two, though.
  269. $iteration = 1;
  270. $num_months = count($calendar_data['months']);
  271. foreach ($calendar_data['months'] as $month_data)
  272. {
  273. // For our first iteration, we'll add a nice header!
  274. if ($iteration == 1)
  275. {
  276. echo '
  277. <div class="cat_bar">
  278. <h3 class="catbg centertext largetext">';
  279. // Previous Week Link...
  280. if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
  281. {
  282. echo '
  283. <span class="floatleft xlarge_text">
  284. <a href="', $calendar_data['previous_week']['href'], '">&#171;</a>
  285. </span>
  286. ';
  287. }
  288. // The Month Title + Week Number...
  289. if (!empty($calendar_data['week_title']))
  290. echo $calendar_data['week_title'];
  291. // Next Week Link...
  292. if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
  293. {
  294. echo '
  295. <span class="floatright xlarge_text">
  296. <a href="', $calendar_data['next_week']['href'], '">&#187;</a>
  297. </span>
  298. ';
  299. }
  300. echo '
  301. </h3>
  302. </div>
  303. ';
  304. }
  305. // Our actual month...
  306. echo '
  307. <div class="week_month_title">
  308. <a href="', $scripturl, '?action=calendar;month=', $month_data['current_month'], '">
  309. ', $txt['months_titles'][$month_data['current_month']], '
  310. </a>
  311. </div>
  312. ';
  313. // The main table grid for $this week.
  314. echo '
  315. <table class="table_grid calendar_week">
  316. <tr>
  317. <th class="days" scope="col">', $txt['calendar_day'], '</th>
  318. <th class="days" scope="col">', $txt['events'], '</th>
  319. <th class="days" scope="col">', $txt['calendar_prompt'], '</th>
  320. <th class="days" scope="col">', $txt['birthdays'], '</th>
  321. </tr>';
  322. // Each day of the week.
  323. foreach ($month_data['days'] as $day)
  324. {
  325. // How should we be highlighted or otherwise not...?
  326. $classes = array('days');
  327. $classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
  328. $classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
  329. echo '
  330. <tr class="days_wrapper">
  331. <td class="', implode(' ', $classes), ' act_day">';
  332. // Should the day number be a link?
  333. if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
  334. 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>';
  335. else
  336. echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
  337. echo '</td>
  338. <td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', '">';
  339. // Show any events...
  340. if (!empty($day['events']))
  341. {
  342. echo '<div class="event_cont floatleft">';
  343. foreach ($day['events'] as $event)
  344. {
  345. // If they can edit the event, show a star they can click on....
  346. if (!empty($event['can_edit']))
  347. {
  348. echo '
  349. <a href="', $event['modify_href'], '">
  350. <img src="', $settings['images_url'], '/icons/calendar_modify.png" alt="*" title="', $txt['calendar_edit'], '" class="calendar_icon">
  351. </a>
  352. ';
  353. }
  354. // Can we export? Sweet.
  355. if (!empty($event['can_export']))
  356. {
  357. echo '
  358. <a class="modify_event" href="', $event['export_href'], '">
  359. <img src="', $settings['images_url'], '/icons/calendar_export.png" alt=">" title="', $txt['calendar_export'], '" class="calendar_icon">
  360. </a>
  361. ';
  362. }
  363. echo $event['link'], $event['is_last'] ? '' : '<br>';
  364. }
  365. echo '
  366. </div>
  367. <div class="active_post_event floatright">
  368. <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'], '">
  369. <img src="', $settings['images_url'], '/icons/plus.png" alt="*" title="', $txt['calendar_post_event'], '">
  370. </a>
  371. </div>
  372. <br class="clear">
  373. ';
  374. }
  375. else
  376. {
  377. if (!empty($context['can_post']))
  378. {
  379. echo '
  380. <div class="week_add_event">
  381. <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>
  382. </div>
  383. ';
  384. }
  385. }
  386. echo '</td>
  387. <td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', '">';
  388. // Show any holidays!
  389. if (!empty($day['holidays']))
  390. echo implode('<br>', $day['holidays']);
  391. echo '</td>
  392. <td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', '">';
  393. // Show any birthdays...
  394. if (!empty($day['birthdays']))
  395. {
  396. foreach ($day['birthdays'] as $member)
  397. {
  398. echo '
  399. <a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], '</a>
  400. ', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '
  401. ', $member['is_last'] ? '' : '<br>';
  402. }
  403. }
  404. echo '</td>
  405. </tr>
  406. ';
  407. }
  408. // We'll show the lower column after our last month is shown.
  409. if ($iteration == $num_months)
  410. template_calendar_base(4);
  411. // Increase iteration for loop counting.
  412. ++$iteration;
  413. echo '
  414. </table>
  415. ';
  416. }
  417. }
  418. /*
  419. * Calendar Grid Base
  420. *
  421. * This function is ONLY designed for use
  422. * within an existing table element.
  423. *
  424. * @param int $col_span = 1
  425. */
  426. function template_calendar_base($col_span = 1)
  427. {
  428. global $context, $scripturl, $txt;
  429. echo '
  430. <tr>
  431. <td id="post_event" colspan="', $col_span, '">
  432. ', template_button_strip($context['calendar_buttons'], 'right'), '
  433. <form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
  434. <select name="month" id="input_month">';
  435. // Show a select box with all the months.
  436. foreach ($txt['months'] as $number => $month)
  437. {
  438. echo '<option value="', $number, '"', $number == $context['current_month'] ? ' selected' : '', '>', $month, '</option>';
  439. }
  440. echo '</select>
  441. <select name="year">';
  442. // Show a link for every year.....
  443. for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++)
  444. {
  445. echo '<option value="', $year, '"', $year == $context['current_year'] ? ' selected' : '', '>', $year, '</option>';
  446. }
  447. echo '</select>
  448. <input type="submit" class="button_submit" id="view_button" value="', $txt['view'], '">
  449. </form>
  450. <br class="clear">
  451. </td>
  452. </tr>
  453. ';
  454. }
  455. // Template for posting a calendar event.
  456. function template_event_post()
  457. {
  458. global $context, $txt, $scripturl, $modSettings;
  459. echo '
  460. <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;">';
  461. if (!empty($context['event']['new']))
  462. echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
  463. // Start the main table.
  464. echo '
  465. <div id="post_event">
  466. <div class="cat_bar">
  467. <h3 class="catbg">
  468. ', $context['page_title'], '
  469. </h3>
  470. </div>';
  471. if (!empty($context['post_error']['messages']))
  472. {
  473. echo '
  474. <div class="errorbox">
  475. <dl class="event_error">
  476. <dt>
  477. ', $context['error_type'] == 'serious' ? '<strong>' . $txt['error_while_submitting'] . '</strong>' : '', '
  478. </dt>
  479. <dt class="error">
  480. ', implode('<br>', $context['post_error']['messages']), '
  481. </dt>
  482. </dl>
  483. </div>';
  484. }
  485. echo '
  486. <div class="roundframe">
  487. <fieldset id="event_main">
  488. <legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', '>', $txt['calendar_event_title'], '</span></legend>
  489. <input type="text" name="evtitle" maxlength="255" size="70" value="', $context['event']['title'], '" class="input_text">
  490. <div class="smalltext" style="white-space: nowrap;">
  491. <input type="hidden" name="calendar" value="1">', $txt['calendar_year'], '
  492. <select name="year" id="year" onchange="generateDays();">';
  493. // Show a list of all the years we allow...
  494. for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++)
  495. echo '
  496. <option value="', $year, '"', $year == $context['event']['year'] ? ' selected' : '', '>', $year, '&nbsp;</option>';
  497. echo '
  498. </select>
  499. ', $txt['calendar_month'], '
  500. <select name="month" id="month" onchange="generateDays();">';
  501. // There are 12 months per year - ensure that they all get listed.
  502. for ($month = 1; $month <= 12; $month++)
  503. echo '
  504. <option value="', $month, '"', $month == $context['event']['month'] ? ' selected' : '', '>', $txt['months'][$month], '&nbsp;</option>';
  505. echo '
  506. </select>
  507. ', $txt['calendar_day'], '
  508. <select name="day" id="day">';
  509. // This prints out all the days in the current month - this changes dynamically as we switch months.
  510. for ($day = 1; $day <= $context['event']['last_day']; $day++)
  511. echo '
  512. <option value="', $day, '"', $day == $context['event']['day'] ? ' selected' : '', '>', $day, '&nbsp;</option>';
  513. echo '
  514. </select>
  515. </div>
  516. </fieldset>';
  517. if (!empty($modSettings['cal_allowspan']) || $context['event']['new'])
  518. echo '
  519. <fieldset id="event_options">
  520. <legend>', $txt['calendar_event_options'], '</legend>
  521. <div class="event_options smalltext">
  522. <ul class="event_options">';
  523. // If events can span more than one day then allow the user to select how long it should last.
  524. if (!empty($modSettings['cal_allowspan']))
  525. {
  526. echo '
  527. <li>
  528. ', $txt['calendar_numb_days'], '
  529. <select name="span">';
  530. for ($days = 1; $days <= $modSettings['cal_maxspan']; $days++)
  531. echo '
  532. <option value="', $days, '"', $context['event']['span'] == $days ? ' selected' : '', '>', $days, '&nbsp;</option>';
  533. echo '
  534. </select>
  535. </li>';
  536. }
  537. // If this is a new event let the user specify which board they want the linked post to be put into.
  538. if (!empty($context['event']['categories']))
  539. {
  540. echo '
  541. <li>
  542. ', $txt['calendar_link_event'], '
  543. <input type="checkbox" style="vertical-align: middle;" class="input_check" name="link_to_board"', ($context['event']['new'] ? ' checked' : ''), ' onclick="toggleLinked(this.form);">
  544. </li>
  545. <li>
  546. ', $txt['calendar_post_in'], '
  547. <select id="board" name="board" onchange="this.form.submit();"', ($context['event']['new'] ? '' : ' disabled'), '>';
  548. foreach ($context['event']['categories'] as $category)
  549. {
  550. echo '
  551. <optgroup label="', $category['name'], '">';
  552. foreach ($category['boards'] as $board)
  553. echo '
  554. <option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
  555. echo '
  556. </optgroup>';
  557. }
  558. echo '
  559. </select>
  560. </li>';
  561. }
  562. if (!empty($modSettings['cal_allowspan']) || $context['event']['new'])
  563. echo '
  564. </ul>
  565. </div>
  566. </fieldset>';
  567. echo '
  568. <input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">';
  569. // Delete button?
  570. if (empty($context['event']['new']))
  571. echo '
  572. <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" onclick="return confirm(\'', $txt['calendar_confirm_delete'], '\');" class="button_submit">';
  573. echo '
  574. <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
  575. <input type="hidden" name="eventid" value="', $context['event']['eventid'], '">
  576. </div>
  577. </div>
  578. </form>';
  579. }
  580. function template_bcd()
  581. {
  582. global $context, $scripturl;
  583. $alt = false;
  584. echo '
  585. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  586. <tr>
  587. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;" colspan="6">BCD Clock</th>
  588. </tr>
  589. <tr class="windowbg">';
  590. foreach ($context['clockicons'] as $t => $v)
  591. {
  592. echo '<td style="padding-', $alt ? 'right' : 'left', ': 1.5em;">';
  593. foreach ($v as $i)
  594. {
  595. echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '"><br>';
  596. }
  597. echo '</td>';
  598. $alt = !$alt;
  599. }
  600. echo '</tr>
  601. <tr class="', $alt ? 'windowbg2' : 'windowbg', '" style="border-top: 1px solid #ccc; text-align: center;">
  602. <td colspan="6">
  603. <a href="', $scripturl, '?action=clock;rb">Are you hardcore?</a>
  604. </td>
  605. </tr>
  606. </table>
  607. <script><!-- // --><![CDATA[
  608. var icons = new Object();';
  609. foreach ($context['clockicons'] as $t => $v)
  610. {
  611. foreach ($v as $i)
  612. echo '
  613. icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
  614. }
  615. echo '
  616. function update()
  617. {
  618. // Get the current time
  619. var time = new Date();
  620. var hour = time.getHours();
  621. var min = time.getMinutes();
  622. var sec = time.getSeconds();
  623. // Break it up into individual digits
  624. var h1 = parseInt(hour / 10);
  625. var h2 = hour % 10;
  626. var m1 = parseInt(min / 10);
  627. var m2 = min % 10;
  628. var s1 = parseInt(sec / 10);
  629. var s2 = sec % 10;
  630. // For each digit figure out which ones to turn off and which ones to turn on
  631. var turnon = new Array();';
  632. foreach ($context['clockicons'] as $t => $v)
  633. {
  634. foreach ($v as $i)
  635. echo '
  636. if (', $t, ' >= ', $i, ')
  637. {
  638. turnon.push("', $t, '_', $i, '");
  639. ', $t, ' -= ', $i, ';
  640. }';
  641. }
  642. echo '
  643. for (var i in icons)
  644. if (!in_array(i, turnon))
  645. icons[i].src = "', $context['offimg'], '";
  646. else
  647. icons[i].src = "', $context['onimg'], '";
  648. window.setTimeout("update();", 500);
  649. }
  650. // Checks for variable in theArray.
  651. function in_array(variable, theArray)
  652. {
  653. for (var i = 0; i < theArray.length; i++)
  654. {
  655. if (theArray[i] == variable)
  656. return true;
  657. }
  658. return false;
  659. }
  660. update();
  661. // ]]></script>';
  662. }
  663. function template_hms()
  664. {
  665. global $context, $scripturl;
  666. $alt = false;
  667. echo '
  668. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  669. <tr>
  670. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">Binary Clock</th>
  671. </tr>';
  672. foreach ($context['clockicons'] as $t => $v)
  673. {
  674. echo '
  675. <tr class="', $alt ? 'windowbg2' : 'windowbg', '">
  676. <td>';
  677. foreach ($v as $i)
  678. {
  679. echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
  680. }
  681. echo '</td>
  682. </tr>
  683. ';
  684. $alt = !$alt;
  685. }
  686. echo '</tr>
  687. <tr class="', $alt ? 'windowbg2' : 'windowbg', '" style="border-top: 1px solid #ccc; text-align: center;">
  688. <td>
  689. <a href="', $scripturl, '?action=clock">Too tough for you?</a>
  690. </td>
  691. </tr>
  692. </table>
  693. ';
  694. echo '
  695. <script><!-- // --><![CDATA[
  696. var icons = new Object();';
  697. foreach ($context['clockicons'] as $t => $v)
  698. {
  699. foreach ($v as $i)
  700. echo '
  701. icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
  702. }
  703. echo '
  704. function update()
  705. {
  706. // Get the current time
  707. var time = new Date();
  708. var h = time.getHours();
  709. var m = time.getMinutes();
  710. var s = time.getSeconds();
  711. // For each digit figure out which ones to turn off and which ones to turn on
  712. var turnon = new Array();';
  713. foreach ($context['clockicons'] as $t => $v)
  714. {
  715. foreach ($v as $i)
  716. echo '
  717. if (', $t, ' >= ', $i, ')
  718. {
  719. turnon.push("', $t, '_', $i, '");
  720. ', $t, ' -= ', $i, ';
  721. }';
  722. }
  723. echo '
  724. for (var i in icons)
  725. if (!in_array(i, turnon))
  726. icons[i].src = "', $context['offimg'], '";
  727. else
  728. icons[i].src = "', $context['onimg'], '";
  729. window.setTimeout("update();", 500);
  730. }
  731. // Checks for variable in theArray.
  732. function in_array(variable, theArray)
  733. {
  734. for (var i = 0; i < theArray.length; i++)
  735. {
  736. if (theArray[i] == variable)
  737. return true;
  738. }
  739. return false;
  740. }
  741. update();
  742. // ]]></script>';
  743. }
  744. function template_omfg()
  745. {
  746. global $context;
  747. $alt = false;
  748. echo '
  749. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  750. <tr>
  751. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">OMFG Binary Clock</th>
  752. </tr>';
  753. foreach ($context['clockicons'] as $t => $v)
  754. {
  755. echo '
  756. <tr class="', $alt ? 'windowbg2' : 'windowbg', '">
  757. <td>';
  758. foreach ($v as $i)
  759. {
  760. echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
  761. }
  762. echo '</td>
  763. </tr>
  764. ';
  765. $alt = !$alt;
  766. }
  767. echo '</tr>
  768. </table>
  769. ';
  770. echo '
  771. <script><!-- // --><![CDATA[
  772. var icons = new Object();';
  773. foreach ($context['clockicons'] as $t => $v)
  774. {
  775. foreach ($v as $i)
  776. echo '
  777. icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
  778. }
  779. echo '
  780. function update()
  781. {
  782. // Get the current time
  783. var time = new Date();
  784. var month = time.getMonth() + 1;
  785. var day = time.getDate();
  786. var year = time.getFullYear();
  787. year = year % 100;
  788. var hour = time.getHours();
  789. var min = time.getMinutes();
  790. var sec = time.getSeconds();
  791. // For each digit figure out which ones to turn off and which ones to turn on
  792. var turnon = new Array();';
  793. foreach ($context['clockicons'] as $t => $v)
  794. {
  795. foreach ($v as $i)
  796. echo '
  797. if (', $t, ' >= ', $i, ')
  798. {
  799. turnon.push("', $t, '_', $i, '");
  800. ', $t, ' -= ', $i, ';
  801. }';
  802. }
  803. echo '
  804. for (var i in icons)
  805. if (!in_array(i, turnon))
  806. icons[i].src = "', $context['offimg'], '";
  807. else
  808. icons[i].src = "', $context['onimg'], '";
  809. window.setTimeout("update();", 500);
  810. }
  811. // Checks for variable in theArray.
  812. function in_array(variable, theArray)
  813. {
  814. for (var i = 0; i < theArray.length; i++)
  815. {
  816. if (theArray[i] == variable)
  817. return true;
  818. }
  819. return false;
  820. }
  821. update();
  822. // ]]></script>';
  823. }
  824. function template_thetime()
  825. {
  826. global $context;
  827. $alt = false;
  828. echo '
  829. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  830. <tr>
  831. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">The time you requested</th>
  832. </tr>';
  833. foreach ($context['clockicons'] as $v)
  834. {
  835. echo '
  836. <tr class="', $alt ? 'windowbg2' : 'windowbg', '">
  837. <td>';
  838. foreach ($v as $i)
  839. {
  840. echo '<img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="" style="padding: 2px;">';
  841. }
  842. echo '</td>
  843. </tr>
  844. ';
  845. $alt = !$alt;
  846. }
  847. echo '
  848. </table>
  849. ';
  850. }
  851. ?>