Calendar.template.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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. // 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['is_selected'] ? '<div class="sel_event">' . $event['link'] . '</div>' : $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' : '', '>', $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' : '', '>', $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. echo '
  463. <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;">';
  464. if (!empty($context['event']['new']))
  465. echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
  466. // Start the main table.
  467. echo '
  468. <div id="post_event">
  469. <div class="cat_bar">
  470. <h3 class="catbg">
  471. ', $context['page_title'], '
  472. </h3>
  473. </div>';
  474. if (!empty($context['post_error']['messages']))
  475. {
  476. echo '
  477. <div class="errorbox">
  478. <dl class="event_error">
  479. <dt>
  480. ', $context['error_type'] == 'serious' ? '<strong>' . $txt['error_while_submitting'] . '</strong>' : '', '
  481. </dt>
  482. <dt class="error">
  483. ', implode('<br>', $context['post_error']['messages']), '
  484. </dt>
  485. </dl>
  486. </div>';
  487. }
  488. echo '
  489. <div class="roundframe">
  490. <fieldset id="event_main">
  491. <legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', '>', $txt['calendar_event_title'], '</span></legend>
  492. <input type="text" name="evtitle" maxlength="255" size="70" value="', $context['event']['title'], '" class="input_text">
  493. <div class="smalltext" style="white-space: nowrap;">
  494. <input type="hidden" name="calendar" value="1">', $txt['calendar_year'], '
  495. <select name="year" id="year" onchange="generateDays();">';
  496. // Show a list of all the years we allow...
  497. for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++)
  498. echo '
  499. <option value="', $year, '"', $year == $context['event']['year'] ? ' selected' : '', '>', $year, '&nbsp;</option>';
  500. echo '
  501. </select>
  502. ', $txt['calendar_month'], '
  503. <select name="month" id="month" onchange="generateDays();">';
  504. // There are 12 months per year - ensure that they all get listed.
  505. for ($month = 1; $month <= 12; $month++)
  506. echo '
  507. <option value="', $month, '"', $month == $context['event']['month'] ? ' selected' : '', '>', $txt['months'][$month], '&nbsp;</option>';
  508. echo '
  509. </select>
  510. ', $txt['calendar_day'], '
  511. <select name="day" id="day">';
  512. // This prints out all the days in the current month - this changes dynamically as we switch months.
  513. for ($day = 1; $day <= $context['event']['last_day']; $day++)
  514. echo '
  515. <option value="', $day, '"', $day == $context['event']['day'] ? ' selected' : '', '>', $day, '&nbsp;</option>';
  516. echo '
  517. </select>
  518. </div>
  519. </fieldset>';
  520. if (!empty($modSettings['cal_allowspan']) || $context['event']['new'])
  521. echo '
  522. <fieldset id="event_options">
  523. <legend>', $txt['calendar_event_options'], '</legend>
  524. <div class="event_options smalltext">
  525. <ul class="event_options">';
  526. // If events can span more than one day then allow the user to select how long it should last.
  527. if (!empty($modSettings['cal_allowspan']))
  528. {
  529. echo '
  530. <li>
  531. ', $txt['calendar_numb_days'], '
  532. <select name="span">';
  533. for ($days = 1; $days <= $modSettings['cal_maxspan']; $days++)
  534. echo '
  535. <option value="', $days, '"', $context['event']['span'] == $days ? ' selected' : '', '>', $days, '&nbsp;</option>';
  536. echo '
  537. </select>
  538. </li>';
  539. }
  540. // If this is a new event let the user specify which board they want the linked post to be put into.
  541. if ($context['event']['new'])
  542. {
  543. echo '
  544. <li>
  545. ', $txt['calendar_link_event'], '
  546. <input type="checkbox" style="vertical-align: middle;" class="input_check" name="link_to_board" checked onclick="toggleLinked(this.form);">
  547. </li>
  548. <li>
  549. ', $txt['calendar_post_in'], '
  550. <select id="board" name="board" onchange="this.form.submit();">';
  551. foreach ($context['event']['categories'] as $category)
  552. {
  553. echo '
  554. <optgroup label="', $category['name'], '">';
  555. foreach ($category['boards'] as $board)
  556. echo '
  557. <option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
  558. echo '
  559. </optgroup>';
  560. }
  561. echo '
  562. </select>
  563. </li>';
  564. }
  565. if (!empty($modSettings['cal_allowspan']) || $context['event']['new'])
  566. echo '
  567. </ul>
  568. </div>
  569. </fieldset>';
  570. echo '
  571. <input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">';
  572. // Delete button?
  573. if (empty($context['event']['new']))
  574. echo '
  575. <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" onclick="return confirm(\'', $txt['calendar_confirm_delete'], '\');" class="button_submit">';
  576. echo '
  577. <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
  578. <input type="hidden" name="eventid" value="', $context['event']['eventid'], '">
  579. </div>
  580. </div>
  581. </form>';
  582. }
  583. function template_bcd()
  584. {
  585. global $context, $scripturl;
  586. $alt = false;
  587. echo '
  588. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  589. <tr>
  590. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;" colspan="6">BCD Clock</th>
  591. </tr>
  592. <tr class="windowbg">';
  593. foreach ($context['clockicons'] as $t => $v)
  594. {
  595. echo '<td style="padding-', $alt ? 'right' : 'left', ': 1.5em;">';
  596. foreach ($v as $i)
  597. {
  598. echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '"><br>';
  599. }
  600. echo '</td>';
  601. $alt = !$alt;
  602. }
  603. echo '</tr>
  604. <tr class="', $alt ? 'windowbg2' : 'windowbg', '" style="border-top: 1px solid #ccc; text-align: center;">
  605. <td colspan="6">
  606. <a href="', $scripturl, '?action=clock;rb">Are you hardcore?</a>
  607. </td>
  608. </tr>
  609. </table>
  610. <script><!-- // --><![CDATA[
  611. var icons = new Object();';
  612. foreach ($context['clockicons'] as $t => $v)
  613. {
  614. foreach ($v as $i)
  615. echo '
  616. icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
  617. }
  618. echo '
  619. function update()
  620. {
  621. // Get the current time
  622. var time = new Date();
  623. var hour = time.getHours();
  624. var min = time.getMinutes();
  625. var sec = time.getSeconds();
  626. // Break it up into individual digits
  627. var h1 = parseInt(hour / 10);
  628. var h2 = hour % 10;
  629. var m1 = parseInt(min / 10);
  630. var m2 = min % 10;
  631. var s1 = parseInt(sec / 10);
  632. var s2 = sec % 10;
  633. // For each digit figure out which ones to turn off and which ones to turn on
  634. var turnon = new Array();';
  635. foreach ($context['clockicons'] as $t => $v)
  636. {
  637. foreach ($v as $i)
  638. echo '
  639. if (', $t, ' >= ', $i, ')
  640. {
  641. turnon.push("', $t, '_', $i, '");
  642. ', $t, ' -= ', $i, ';
  643. }';
  644. }
  645. echo '
  646. for (var i in icons)
  647. if (!in_array(i, turnon))
  648. icons[i].src = "', $context['offimg'], '";
  649. else
  650. icons[i].src = "', $context['onimg'], '";
  651. window.setTimeout("update();", 500);
  652. }
  653. // Checks for variable in theArray.
  654. function in_array(variable, theArray)
  655. {
  656. for (var i = 0; i < theArray.length; i++)
  657. {
  658. if (theArray[i] == variable)
  659. return true;
  660. }
  661. return false;
  662. }
  663. update();
  664. // ]]></script>';
  665. }
  666. function template_hms()
  667. {
  668. global $context, $scripturl;
  669. $alt = false;
  670. echo '
  671. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  672. <tr>
  673. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">Binary Clock</th>
  674. </tr>';
  675. foreach ($context['clockicons'] as $t => $v)
  676. {
  677. echo '
  678. <tr class="', $alt ? 'windowbg2' : 'windowbg', '">
  679. <td>';
  680. foreach ($v as $i)
  681. {
  682. echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
  683. }
  684. echo '</td>
  685. </tr>
  686. ';
  687. $alt = !$alt;
  688. }
  689. echo '</tr>
  690. <tr class="', $alt ? 'windowbg2' : 'windowbg', '" style="border-top: 1px solid #ccc; text-align: center;">
  691. <td>
  692. <a href="', $scripturl, '?action=clock">Too tough for you?</a>
  693. </td>
  694. </tr>
  695. </table>
  696. ';
  697. echo '
  698. <script><!-- // --><![CDATA[
  699. var icons = new Object();';
  700. foreach ($context['clockicons'] as $t => $v)
  701. {
  702. foreach ($v as $i)
  703. echo '
  704. icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
  705. }
  706. echo '
  707. function update()
  708. {
  709. // Get the current time
  710. var time = new Date();
  711. var h = time.getHours();
  712. var m = time.getMinutes();
  713. var s = time.getSeconds();
  714. // For each digit figure out which ones to turn off and which ones to turn on
  715. var turnon = new Array();';
  716. foreach ($context['clockicons'] as $t => $v)
  717. {
  718. foreach ($v as $i)
  719. echo '
  720. if (', $t, ' >= ', $i, ')
  721. {
  722. turnon.push("', $t, '_', $i, '");
  723. ', $t, ' -= ', $i, ';
  724. }';
  725. }
  726. echo '
  727. for (var i in icons)
  728. if (!in_array(i, turnon))
  729. icons[i].src = "', $context['offimg'], '";
  730. else
  731. icons[i].src = "', $context['onimg'], '";
  732. window.setTimeout("update();", 500);
  733. }
  734. // Checks for variable in theArray.
  735. function in_array(variable, theArray)
  736. {
  737. for (var i = 0; i < theArray.length; i++)
  738. {
  739. if (theArray[i] == variable)
  740. return true;
  741. }
  742. return false;
  743. }
  744. update();
  745. // ]]></script>';
  746. }
  747. function template_omfg()
  748. {
  749. global $context;
  750. $alt = false;
  751. echo '
  752. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  753. <tr>
  754. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">OMFG Binary Clock</th>
  755. </tr>';
  756. foreach ($context['clockicons'] as $t => $v)
  757. {
  758. echo '
  759. <tr class="', $alt ? 'windowbg2' : 'windowbg', '">
  760. <td>';
  761. foreach ($v as $i)
  762. {
  763. echo '<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
  764. }
  765. echo '</td>
  766. </tr>
  767. ';
  768. $alt = !$alt;
  769. }
  770. echo '</tr>
  771. </table>
  772. ';
  773. echo '
  774. <script><!-- // --><![CDATA[
  775. var icons = new Object();';
  776. foreach ($context['clockicons'] as $t => $v)
  777. {
  778. foreach ($v as $i)
  779. echo '
  780. icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
  781. }
  782. echo '
  783. function update()
  784. {
  785. // Get the current time
  786. var time = new Date();
  787. var month = time.getMonth() + 1;
  788. var day = time.getDate();
  789. var year = time.getFullYear();
  790. year = year % 100;
  791. var hour = time.getHours();
  792. var min = time.getMinutes();
  793. var sec = time.getSeconds();
  794. // For each digit figure out which ones to turn off and which ones to turn on
  795. var turnon = new Array();';
  796. foreach ($context['clockicons'] as $t => $v)
  797. {
  798. foreach ($v as $i)
  799. echo '
  800. if (', $t, ' >= ', $i, ')
  801. {
  802. turnon.push("', $t, '_', $i, '");
  803. ', $t, ' -= ', $i, ';
  804. }';
  805. }
  806. echo '
  807. for (var i in icons)
  808. if (!in_array(i, turnon))
  809. icons[i].src = "', $context['offimg'], '";
  810. else
  811. icons[i].src = "', $context['onimg'], '";
  812. window.setTimeout("update();", 500);
  813. }
  814. // Checks for variable in theArray.
  815. function in_array(variable, theArray)
  816. {
  817. for (var i = 0; i < theArray.length; i++)
  818. {
  819. if (theArray[i] == variable)
  820. return true;
  821. }
  822. return false;
  823. }
  824. update();
  825. // ]]></script>';
  826. }
  827. function template_thetime()
  828. {
  829. global $context;
  830. $alt = false;
  831. echo '
  832. <table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
  833. <tr>
  834. <th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">The time you requested</th>
  835. </tr>';
  836. foreach ($context['clockicons'] as $v)
  837. {
  838. echo '
  839. <tr class="', $alt ? 'windowbg2' : 'windowbg', '">
  840. <td>';
  841. foreach ($v as $i)
  842. {
  843. echo '<img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="" style="padding: 2px;">';
  844. }
  845. echo '</td>
  846. </tr>
  847. ';
  848. $alt = !$alt;
  849. }
  850. echo '
  851. </table>
  852. ';
  853. }
  854. ?>