ManageCalendar.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.0
  11. */
  12. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. // The main controlling function doesn't have much to do... yet.
  15. function ManageCalendar()
  16. {
  17. global $context, $txt, $scripturl, $modSettings;
  18. isAllowedTo('admin_forum');
  19. // Everything's gonna need this.
  20. loadLanguage('ManageCalendar');
  21. // Default text.
  22. $context['explain_text'] = $txt['calendar_desc'];
  23. // Little short on the ground of functions here... but things can and maybe will change...
  24. $subActions = array(
  25. 'editholiday' => 'EditHoliday',
  26. 'holidays' => 'ModifyHolidays',
  27. 'settings' => 'ModifyCalendarSettings'
  28. );
  29. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'holidays';
  30. // Set up the two tabs here...
  31. $context[$context['admin_menu_name']]['tab_data'] = array(
  32. 'title' => $txt['manage_calendar'],
  33. 'help' => 'calendar',
  34. 'description' => $txt['calendar_settings_desc'],
  35. 'tabs' => array(
  36. 'holidays' => array(
  37. 'description' => $txt['manage_holidays_desc'],
  38. ),
  39. 'settings' => array(
  40. 'description' => $txt['calendar_settings_desc'],
  41. ),
  42. ),
  43. );
  44. $subActions[$_REQUEST['sa']]();
  45. }
  46. // The function that handles adding, and deleting holiday data
  47. function ModifyHolidays()
  48. {
  49. global $sourcedir, $scripturl, $txt, $context;
  50. // Submitting something...
  51. if (isset($_REQUEST['delete']) && !empty($_REQUEST['holiday']))
  52. {
  53. checkSession();
  54. foreach ($_REQUEST['holiday'] as $id => $value)
  55. $_REQUEST['holiday'][$id] = (int) $id;
  56. // Now the IDs are "safe" do the delete...
  57. require_once($sourcedir . '/Subs-Calendar.php');
  58. removeHolidays($_REQUEST['holiday']);
  59. }
  60. $listOptions = array(
  61. 'id' => 'holiday_list',
  62. 'title' => $txt['current_holidays'],
  63. 'items_per_page' => 20,
  64. 'base_href' => $scripturl . '?action=admin;area=managecalendar;sa=holidays',
  65. 'default_sort_col' => 'name',
  66. 'get_items' => array(
  67. 'file' => $sourcedir . '/Subs-Calendar.php',
  68. 'function' => 'list_getHolidays',
  69. ),
  70. 'get_count' => array(
  71. 'file' => $sourcedir . '/Subs-Calendar.php',
  72. 'function' => 'list_getNumHolidays',
  73. ),
  74. 'no_items_label' => $txt['holidays_no_entries'],
  75. 'columns' => array(
  76. 'name' => array(
  77. 'header' => array(
  78. 'value' => $txt['holidays_title'],
  79. ),
  80. 'data' => array(
  81. 'sprintf' => array(
  82. 'format' => '<a href="' . $scripturl . '?action=admin;area=managecalendar;sa=editholiday;holiday=%1$d">%2$s</a>',
  83. 'params' => array(
  84. 'id_holiday' => false,
  85. 'title' => false,
  86. ),
  87. ),
  88. ),
  89. 'sort' => array(
  90. 'default' => 'title',
  91. 'reverse' => 'title DESC',
  92. )
  93. ),
  94. 'date' => array(
  95. 'header' => array(
  96. 'value' => $txt['date'],
  97. ),
  98. 'data' => array(
  99. 'function' => create_function('$rowData', '
  100. global $txt;
  101. // Recurring every year or just a single year?
  102. $year = $rowData[\'year\'] == \'0004\' ? sprintf(\'(%1$s)\', $txt[\'every_year\']) : $rowData[\'year\'];
  103. // Construct the date.
  104. return sprintf(\'%1$d %2$s %3$s\', $rowData[\'day\'], $txt[\'months\'][(int) $rowData[\'month\']], $year);
  105. '),
  106. 'class' => 'windowbg',
  107. ),
  108. 'sort' => array(
  109. 'default' => 'event_date',
  110. 'reverse' => 'event_date DESC',
  111. ),
  112. ),
  113. 'check' => array(
  114. 'header' => array(
  115. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  116. ),
  117. 'data' => array(
  118. 'sprintf' => array(
  119. 'format' => '<input type="checkbox" name="holiday[%1$d]" class="input_check" />',
  120. 'params' => array(
  121. 'id_holiday' => false,
  122. ),
  123. ),
  124. 'style' => 'text-align: center',
  125. ),
  126. ),
  127. ),
  128. 'form' => array(
  129. 'href' => $scripturl . '?action=admin;area=managecalendar;sa=holidays',
  130. ),
  131. 'additional_rows' => array(
  132. array(
  133. 'position' => 'below_table_data',
  134. 'value' => '
  135. <a href="' . $scripturl . '?action=admin;area=managecalendar;sa=editholiday" style="margin: 0 1em">[' . $txt['holidays_add'] . ']</a>
  136. <input type="submit" name="delete" value="' . $txt['quickmod_delete_selected'] . '" class="button_submit" />',
  137. 'style' => 'text-align: right;',
  138. ),
  139. ),
  140. );
  141. require_once($sourcedir . '/Subs-List.php');
  142. createList($listOptions);
  143. //loadTemplate('ManageCalendar');
  144. $context['page_title'] = $txt['manage_holidays'];
  145. // Since the list is the only thing to show, use the default list template.
  146. $context['default_list'] = 'holiday_list';
  147. $context['sub_template'] = 'show_list';
  148. }
  149. // This function is used for adding/editing a specific holiday
  150. function EditHoliday()
  151. {
  152. global $txt, $context, $scripturl, $smcFunc;
  153. loadTemplate('ManageCalendar');
  154. $context['is_new'] = !isset($_REQUEST['holiday']);
  155. $context['page_title'] = $context['is_new'] ? $txt['holidays_add'] : $txt['holidays_edit'];
  156. $context['sub_template'] = 'edit_holiday';
  157. // Cast this for safety...
  158. if (isset($_REQUEST['holiday']))
  159. $_REQUEST['holiday'] = (int) $_REQUEST['holiday'];
  160. // Submitting?
  161. if (isset($_POST[$context['session_var']]) && (isset($_REQUEST['delete']) || $_REQUEST['title'] != ''))
  162. {
  163. checkSession();
  164. // Not too long good sir?
  165. $_REQUEST['title'] = $smcFunc['substr']($_REQUEST['title'], 0, 60);
  166. $_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0;
  167. if (isset($_REQUEST['delete']))
  168. $smcFunc['db_query']('', '
  169. DELETE FROM {db_prefix}calendar_holidays
  170. WHERE id_holiday = {int:selected_holiday}',
  171. array(
  172. 'selected_holiday' => $_REQUEST['holiday'],
  173. )
  174. );
  175. else
  176. {
  177. $date = strftime($_REQUEST['year'] <= 4 ? '0004-%m-%d' : '%Y-%m-%d', mktime(0, 0, 0, $_REQUEST['month'], $_REQUEST['day'], $_REQUEST['year']));
  178. if (isset($_REQUEST['edit']))
  179. $smcFunc['db_query']('', '
  180. UPDATE {db_prefix}calendar_holidays
  181. SET event_date = {date:holiday_date}, title = {string:holiday_title}
  182. WHERE id_holiday = {int:selected_holiday}',
  183. array(
  184. 'holiday_date' => $date,
  185. 'selected_holiday' => $_REQUEST['holiday'],
  186. 'holiday_title' => $_REQUEST['title'],
  187. )
  188. );
  189. else
  190. $smcFunc['db_insert']('',
  191. '{db_prefix}calendar_holidays',
  192. array(
  193. 'event_date' => 'date', 'title' => 'string-60',
  194. ),
  195. array(
  196. $date, $_REQUEST['title'],
  197. ),
  198. array('id_holiday')
  199. );
  200. }
  201. updateSettings(array(
  202. 'calendar_updated' => time(),
  203. ));
  204. redirectexit('action=admin;area=managecalendar;sa=holidays');
  205. }
  206. // Default states...
  207. if ($context['is_new'])
  208. $context['holiday'] = array(
  209. 'id' => 0,
  210. 'day' => date('d'),
  211. 'month' => date('m'),
  212. 'year' => '0000',
  213. 'title' => ''
  214. );
  215. // If it's not new load the data.
  216. else
  217. {
  218. $request = $smcFunc['db_query']('', '
  219. SELECT id_holiday, YEAR(event_date) AS year, MONTH(event_date) AS month, DAYOFMONTH(event_date) AS day, title
  220. FROM {db_prefix}calendar_holidays
  221. WHERE id_holiday = {int:selected_holiday}
  222. LIMIT 1',
  223. array(
  224. 'selected_holiday' => $_REQUEST['holiday'],
  225. )
  226. );
  227. while ($row = $smcFunc['db_fetch_assoc']($request))
  228. $context['holiday'] = array(
  229. 'id' => $row['id_holiday'],
  230. 'day' => $row['day'],
  231. 'month' => $row['month'],
  232. 'year' => $row['year'] <= 4 ? 0 : $row['year'],
  233. 'title' => $row['title']
  234. );
  235. $smcFunc['db_free_result']($request);
  236. }
  237. // Last day for the drop down?
  238. $context['holiday']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['holiday']['month'] == 12 ? 1 : $context['holiday']['month'] + 1, 0, $context['holiday']['month'] == 12 ? $context['holiday']['year'] + 1 : $context['holiday']['year']));
  239. }
  240. function ModifyCalendarSettings($return_config = false)
  241. {
  242. global $modSettings, $context, $settings, $txt, $boarddir, $sourcedir, $scripturl, $smcFunc;
  243. // Load the boards list.
  244. $boards = array('');
  245. $request = $smcFunc['db_query']('order_by_board_order', '
  246. SELECT b.id_board, b.name AS board_name, c.name AS cat_name
  247. FROM {db_prefix}boards AS b
  248. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)',
  249. array(
  250. )
  251. );
  252. while ($row = $smcFunc['db_fetch_assoc']($request))
  253. $boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
  254. $smcFunc['db_free_result']($request);
  255. // Look, all the calendar settings - of which there are many!
  256. $config_vars = array(
  257. // All the permissions:
  258. array('permissions', 'calendar_view', 'help' => 'cal_enabled'),
  259. array('permissions', 'calendar_post'),
  260. array('permissions', 'calendar_edit_own'),
  261. array('permissions', 'calendar_edit_any'),
  262. '',
  263. // How many days to show on board index, and where to display events etc?
  264. array('int', 'cal_days_for_index'),
  265. array('select', 'cal_showholidays', array(0 => $txt['setting_cal_show_never'], 1 => $txt['setting_cal_show_cal'], 3 => $txt['setting_cal_show_index'], 2 => $txt['setting_cal_show_all'])),
  266. array('select', 'cal_showbdays', array(0 => $txt['setting_cal_show_never'], 1 => $txt['setting_cal_show_cal'], 3 => $txt['setting_cal_show_index'], 2 => $txt['setting_cal_show_all'])),
  267. array('select', 'cal_showevents', array(0 => $txt['setting_cal_show_never'], 1 => $txt['setting_cal_show_cal'], 3 => $txt['setting_cal_show_index'], 2 => $txt['setting_cal_show_all'])),
  268. '',
  269. // Linking events etc...
  270. array('select', 'cal_defaultboard', $boards),
  271. array('check', 'cal_daysaslink'),
  272. array('check', 'cal_allow_unlinked'),
  273. array('check', 'cal_showInTopic'),
  274. '',
  275. // Dates of calendar...
  276. array('int', 'cal_minyear'),
  277. array('int', 'cal_maxyear'),
  278. '',
  279. // Calendar spanning...
  280. array('check', 'cal_allowspan'),
  281. array('int', 'cal_maxspan'),
  282. );
  283. if ($return_config)
  284. return $config_vars;
  285. // Get the settings template fired up.
  286. require_once($sourcedir . '/ManageServer.php');
  287. // Some important context stuff
  288. $context['page_title'] = $txt['calendar_settings'];
  289. $context['sub_template'] = 'show_settings';
  290. // Get the final touches in place.
  291. $context['post_url'] = $scripturl . '?action=admin;area=managecalendar;save;sa=settings';
  292. $context['settings_title'] = $txt['calendar_settings'];
  293. // Saving the settings?
  294. if (isset($_GET['save']))
  295. {
  296. checkSession();
  297. saveDBSettings($config_vars);
  298. // Update the stats in case.
  299. updateSettings(array(
  300. 'calendar_updated' => time(),
  301. ));
  302. redirectexit('action=admin;area=managecalendar;sa=settings');
  303. }
  304. // Prepare the settings...
  305. prepareDBSettingContext($config_vars);
  306. }
  307. ?>