PageRenderTime 67ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/tiki-minical.php

https://gitlab.com/ElvisAns/tiki
PHP | 181 lines | 164 code | 4 blank | 13 comment | 36 complexity | 7a8443afd642f725a01da30a319d4692 MD5 | raw file
  1. <?php
  2. // (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
  3. //
  4. // All Rights Reserved. See copyright.txt for details and a complete list of authors.
  5. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
  6. // $Id$
  7. $section = 'calendar';
  8. require_once('tiki-setup.php');
  9. include_once('lib/minical/minicallib.php');
  10. $access->check_feature('feature_minical');
  11. $access->check_user($user);
  12. $access->check_permission('tiki_p_minical');
  13. if (! isset($_REQUEST["eventId"])) {
  14. $_REQUEST["eventId"] = 0;
  15. }
  16. if (isset($_REQUEST['remove'])) {
  17. $access->check_authenticity();
  18. $minicallib->minical_remove_event($user, $_REQUEST['remove']);
  19. }
  20. if (isset($_REQUEST['remove2'])) {
  21. $access->check_authenticity();
  22. $minicallib->minical_remove_event($user, $_REQUEST['eventId']);
  23. }
  24. if (isset($_REQUEST['delete'])) {
  25. $access->check_authenticity();
  26. foreach (array_keys($_REQUEST["event"]) as $ev) {
  27. $minicallib->minical_remove_event($user, $ev);
  28. }
  29. }
  30. if (isset($_REQUEST['day']) && isset($_REQUEST['mon']) && isset($_REQUEST['year'])) {
  31. $pdate = mktime(0, 0, 0, $_REQUEST['mon'], $_REQUEST['day'], $_REQUEST['year']);
  32. } else {
  33. if (isset($_SESSION['thedate'])) {
  34. $pdate = mktime(0, 0, 0, date("m", $_SESSION['thedate']), date("d", $_SESSION['thedate']), date("Y", $_SESSION['thedate']));
  35. } else {
  36. $pdate = date("U");
  37. }
  38. }
  39. $yesterday = $pdate - 60 * 60 * 24;
  40. $tomorrow = $pdate + 60 * 60 * 24;
  41. $smarty->assign('yesterday', $yesterday);
  42. $smarty->assign('tomorrow', $tomorrow);
  43. $smarty->assign('day', date("d", $pdate));
  44. $smarty->assign('mon', date("m", $pdate));
  45. $smarty->assign('year', date("Y", $pdate));
  46. $pdate_h = mktime(date("G"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate));
  47. $smarty->assign('pdate', $pdate);
  48. $smarty->assign('pdate_h', $pdate_h);
  49. if (isset($_REQUEST['removeold'])) {
  50. $access->check_authenticity();
  51. $minicallib->minical_remove_old($user, $pdate_h);
  52. }
  53. if ($_REQUEST["eventId"]) {
  54. $info = $minicallib->minical_get_event($user, $_REQUEST["eventId"]);
  55. $ev_pdate = $info['start'];
  56. $ev_pdate_h = $info['start'];
  57. } else {
  58. $info = [];
  59. $info['title'] = '';
  60. $info['topicId'] = 0;
  61. $info['description'] = '';
  62. $info['start'] = mktime(date("H"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate));
  63. $info['duration'] = 60 * 60;
  64. }
  65. $smarty->assign('ev_pdate', $ev_pdate);
  66. $smarty->assign('ev_pdate_h', $ev_pdate_h);
  67. if (isset($_REQUEST['save'])) {
  68. check_ticket('minical');
  69. //Convert 12-hour clock hours to 24-hour scale to compute time
  70. if (! empty($_REQUEST['Time_Meridian'])) {
  71. $_REQUEST['Time_Hour'] = date('H', strtotime($_REQUEST['Time_Hour'] . ':00 ' . $_REQUEST['Time_Meridian']));
  72. }
  73. $start = mktime($_REQUEST['Time_Hour'], $_REQUEST['Time_Minute'], 0, $_REQUEST['Date_Month'], $_REQUEST['Date_Day'], $_REQUEST['Date_Year']);
  74. $minicallib->minical_replace_event($user, $_REQUEST["eventId"], $_REQUEST["title"], $_REQUEST["description"], $start, ($_REQUEST['duration_hours'] * 60 * 60) + ($_REQUEST['duration_minutes'] * 60), $_REQUEST['topicId']);
  75. $info = [];
  76. $info['title'] = '';
  77. $info['topicId'] = 0;
  78. $info['description'] = '';
  79. $info['start'] = mktime(date("h"), date("i"), date("s"), date("m", $pdate), date("d", $pdate), date("Y", $pdate));
  80. $info['duration'] = 60 * 60;
  81. $_REQUEST["eventId"] = 0;
  82. }
  83. $smarty->assign('eventId', $_REQUEST["eventId"]);
  84. $smarty->assign('info', $info);
  85. //Check here the interval for the calendar
  86. if (! isset($_REQUEST['view'])) {
  87. $_REQUEST['view'] = 'daily';
  88. }
  89. $smarty->assign('view', $_REQUEST['view']);
  90. $minical_interval = $tikilib->get_user_preference($user, 'minical_interval', 60 * 60);
  91. $minical_start_hour = $tikilib->get_user_preference($user, 'minical_start_hour', 9);
  92. $minical_end_hour = $tikilib->get_user_preference($user, 'minical_end_hour', 20);
  93. $minical_public = $tikilib->get_user_preference($user, 'minical_public', 'n');
  94. $minical_upcoming = $tikilib->get_user_preference($user, 'minical_upcoming', 7);
  95. // Interval is in hours
  96. if ($_REQUEST['view'] == 'daily') {
  97. $tempdate = $pdate - $pdate % (24 * 60 * 60); /// added by Wells Wang to solve Mini Cal Event List Wrong Time BUG
  98. $slot_start = $tempdate + 60 * 60 * $minical_start_hour;
  99. $slot_end = $tempdate + 60 * 60 * $minical_end_hour;
  100. $interval = $minical_interval;
  101. }
  102. // end of modification
  103. if ($_REQUEST['view'] == 'weekly') {
  104. $interval = 24 * 60 * 60;
  105. // Determine weekday
  106. $wd = date('w', $pdate);
  107. if ($wd == 0) {
  108. $wd = 7;
  109. }
  110. $wd = $wd - 1;
  111. // Now get the number of days to substract
  112. $week_start = $pdate - ($wd * 60 * 60 * 24);
  113. $week_end = $week_start + 60 * 60 * 24 * 7 - 1;
  114. $smarty->assign('week_start', $week_start);
  115. $smarty->assign('week_end', $week_end);
  116. $next_week_start = $week_end + 1;
  117. $smarty->assign('next_week_start', $next_week_start);
  118. $prev_week_start = $week_start - (60 * 60 * 24 * 7);
  119. $smarty->assign('prev_week_start', $prev_week_start);
  120. $slot_start = $pdate - ($wd * 60 * 60 * 24);
  121. $slot_end = $slot_start + 60 * 60 * 24 * 7 - 1;
  122. }
  123. if ($_REQUEST['view'] == 'daily' || $_REQUEST['view'] == 'weekly') {
  124. $smarty->assign('slot_start', $slot_start);
  125. $smarty->assign('slot_end', $slot_end);
  126. $events = $minicallib->minical_events_by_slot($user, $slot_start, $slot_end, $interval);
  127. $smarty->assign_by_ref('slots', $events);
  128. }
  129. // List view
  130. if ($_REQUEST['view'] == 'list') {
  131. if (! isset($_REQUEST["sort_mode"])) {
  132. $sort_mode = 'start_asc';
  133. } else {
  134. $sort_mode = $_REQUEST["sort_mode"];
  135. }
  136. if (! isset($_REQUEST["offset"])) {
  137. $offset = 0;
  138. } else {
  139. $offset = $_REQUEST["offset"];
  140. }
  141. $smarty->assign_by_ref('offset', $offset);
  142. if (isset($_REQUEST["find"])) {
  143. $find = $_REQUEST["find"];
  144. } else {
  145. $find = '';
  146. }
  147. $smarty->assign('find', $find);
  148. $smarty->assign_by_ref('sort_mode', $sort_mode);
  149. if (isset($_SESSION['thedate'])) {
  150. $pdate = $_SESSION['thedate'];
  151. } else {
  152. $pdate = date("U");
  153. }
  154. $channels = $minicallib->minical_list_events($user, $offset, $maxRecords, $sort_mode, $find);
  155. $smarty->assign_by_ref('cant_pages', $channels["cant"]);
  156. $smarty->assign('channels', $channels["data"]);
  157. }
  158. $upcoming = $minicallib->minical_list_events_from_date($user, 0, $minical_upcoming, 'start_asc', '', $pdate_h);
  159. $smarty->assign('upcoming', $upcoming['data']);
  160. //Use 12- or 24-hour clock for $publishDate time selector based on admin and user preferences
  161. $userprefslib = TikiLib::lib('userprefs');
  162. $smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user));
  163. $hours = range(0, 23);
  164. $smarty->assign('hours', $hours);
  165. $minutes = range(0, 59);
  166. $smarty->assign('minutes', $minutes);
  167. $duration_hours = $info['duration'] / (60 * 60);
  168. $duration_minutes = $info['duration'] % (60 * 60);
  169. $smarty->assign('duration_hours', $duration_hours);
  170. $smarty->assign('duration_minutes', $duration_minutes);
  171. $topics = $minicallib->minical_list_topics($user, 0, -1, 'name_asc', '');
  172. $smarty->assign('topics', $topics['data']);
  173. include_once('tiki-section_options.php');
  174. include_once('tiki-mytiki_shared.php');
  175. ask_ticket('minical');
  176. $smarty->assign('mid', 'tiki-minical.tpl');
  177. $smarty->display("tiki.tpl");