agenda.ajax.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls.
  5. */
  6. $type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], ['personal', 'course', 'admin']) ? $_REQUEST['type'] : 'personal';
  7. if ($type == 'personal') {
  8. $cidReset = true; // fixes #5162
  9. }
  10. require_once __DIR__.'/../global.inc.php';
  11. $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
  12. $group_id = api_get_group_id();
  13. if ($type == 'course') {
  14. api_protect_course_script(true);
  15. }
  16. $logInfo = [
  17. 'tool' => TOOL_CALENDAR_EVENT,
  18. 'tool_id' => 0,
  19. 'tool_id_detail' => 0,
  20. 'action' => $action,
  21. 'info' => '',
  22. ];
  23. Event::registerLog($logInfo);
  24. $agenda = new Agenda($type);
  25. // get filtered type
  26. $type = $agenda->getType();
  27. switch ($action) {
  28. case 'add_event':
  29. if (!$agenda->getIsAllowedToEdit()) {
  30. break;
  31. }
  32. $add_as_announcement = isset($_REQUEST['add_as_annonuncement']) ? $_REQUEST['add_as_annonuncement'] : null;
  33. $title = isset($_REQUEST['title']) ? $_REQUEST['title'] : null;
  34. $content = isset($_REQUEST['content']) ? $_REQUEST['content'] : null;
  35. $comment = isset($_REQUEST['comment']) ? $_REQUEST['comment'] : null;
  36. $userToSend = isset($_REQUEST['users_to_send']) ? $_REQUEST['users_to_send'] : [];
  37. echo $agenda->addEvent(
  38. $_REQUEST['start'],
  39. $_REQUEST['end'],
  40. $_REQUEST['all_day'],
  41. $title,
  42. $content,
  43. $userToSend,
  44. $add_as_announcement,
  45. null, //$parentEventId = null,
  46. [], //$attachmentArray = array(),
  47. null, //$attachmentComment = null,
  48. $comment
  49. );
  50. break;
  51. case 'edit_event':
  52. if (!$agenda->getIsAllowedToEdit()) {
  53. break;
  54. }
  55. $id_list = explode('_', $_REQUEST['id']);
  56. $id = $id_list[1];
  57. $agenda->editEvent(
  58. $id,
  59. $_REQUEST['start'],
  60. $_REQUEST['end'],
  61. $_REQUEST['all_day'],
  62. $title,
  63. $content
  64. );
  65. break;
  66. case 'delete_event':
  67. if (!$agenda->getIsAllowedToEdit()) {
  68. break;
  69. }
  70. $id_list = explode('_', $_REQUEST['id']);
  71. $id = $id_list[1];
  72. $deleteAllEventsFromSerie = isset($_REQUEST['delete_all_events']) ? true : false;
  73. $agenda->deleteEvent($id, $deleteAllEventsFromSerie);
  74. break;
  75. case 'resize_event':
  76. if (!$agenda->getIsAllowedToEdit()) {
  77. break;
  78. }
  79. $minute_delta = $_REQUEST['minute_delta'];
  80. $id = explode('_', $_REQUEST['id']);
  81. $id = $id[1];
  82. $agenda->resizeEvent($id, $minute_delta);
  83. break;
  84. case 'move_event':
  85. if (!$agenda->getIsAllowedToEdit()) {
  86. break;
  87. }
  88. $minute_delta = $_REQUEST['minute_delta'];
  89. $allDay = $_REQUEST['all_day'];
  90. $id = explode('_', $_REQUEST['id']);
  91. $id = $id[1];
  92. $agenda->move_event($id, $minute_delta, $allDay);
  93. break;
  94. case 'get_events':
  95. $filter = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : null;
  96. $sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : null;
  97. $result = $agenda->parseAgendaFilter($filter);
  98. $groupId = current($result['groups']);
  99. $userId = current($result['users']);
  100. $start = isset($_REQUEST['start']) ? api_strtotime($_REQUEST['start']) : null;
  101. $end = isset($_REQUEST['end']) ? api_strtotime($_REQUEST['end']) : null;
  102. if ($type == 'personal' && !empty($sessionId)) {
  103. $agenda->setSessionId($sessionId);
  104. }
  105. $events = $agenda->getEvents(
  106. $start,
  107. $end,
  108. api_get_course_int_id(),
  109. $groupId,
  110. $userId
  111. );
  112. header('Content-Type: application/json');
  113. echo $events;
  114. break;
  115. case 'get_user_agenda':
  116. //Used in the admin user list
  117. api_protect_admin_script();
  118. if (api_is_allowed_to_edit(null, true)) {
  119. //@todo move this in the agenda class
  120. $DaysShort = api_get_week_days_short();
  121. $MonthsLong = api_get_months_long();
  122. $user_id = (int) $_REQUEST['user_id'];
  123. $my_course_list = CourseManager::get_courses_list_by_user_id($user_id, true);
  124. if (!is_array($my_course_list)) {
  125. // this is for the special case if the user has no courses (otherwise you get an error)
  126. $my_course_list = [];
  127. }
  128. $today = getdate();
  129. $year = (!empty($_GET['year']) ? (int) $_GET['year'] : null);
  130. if ($year == null) {
  131. $year = $today['year'];
  132. }
  133. $month = (!empty($_GET['month']) ? (int) $_GET['month'] : null);
  134. if ($month == null) {
  135. $month = $today['mon'];
  136. }
  137. $day = (!empty($_GET['day']) ? (int) $_GET['day'] : null);
  138. if ($day == null) {
  139. $day = $today['mday'];
  140. }
  141. $monthName = $MonthsLong[$month - 1];
  142. $week = null;
  143. $agendaitems = Agenda::get_myagendaitems(
  144. $user_id,
  145. $my_course_list,
  146. $month,
  147. $year
  148. );
  149. $agendaitems = Agenda::get_global_agenda_items(
  150. $agendaitems,
  151. $day,
  152. $month,
  153. $year,
  154. $week,
  155. "month_view"
  156. );
  157. if (api_get_setting('allow_personal_agenda') == 'true') {
  158. $agendaitems = Agenda::get_personal_agenda_items(
  159. $user_id,
  160. $agendaitems,
  161. $day,
  162. $month,
  163. $year,
  164. $week,
  165. "month_view"
  166. );
  167. }
  168. Agenda::display_mymonthcalendar(
  169. $user_id,
  170. $agendaitems,
  171. $month,
  172. $year,
  173. [],
  174. $monthName,
  175. false
  176. );
  177. }
  178. break;
  179. default:
  180. echo '';
  181. }
  182. exit;