agenda.ajax.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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'], array('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. $agenda = new Agenda($type);
  17. switch ($action) {
  18. case 'add_event':
  19. if (!$agenda->getIsAllowedToEdit()) {
  20. break;
  21. }
  22. $add_as_announcement = isset($_REQUEST['add_as_annonuncement']) ? $_REQUEST['add_as_annonuncement'] : null;
  23. $comment = isset($_REQUEST['comment']) ? $_REQUEST['comment'] : null;
  24. $userToSend = isset($_REQUEST['users_to_send']) ? $_REQUEST['users_to_send'] : array();
  25. echo $agenda->addEvent(
  26. $_REQUEST['start'],
  27. $_REQUEST['end'],
  28. $_REQUEST['all_day'],
  29. $_REQUEST['title'],
  30. $_REQUEST['content'],
  31. $userToSend,
  32. $add_as_announcement,
  33. null, //$parentEventId = null,
  34. array(), //$attachmentArray = array(),
  35. null, //$attachmentComment = null,
  36. $comment
  37. );
  38. break;
  39. case 'edit_event':
  40. if (!$agenda->getIsAllowedToEdit()) {
  41. break;
  42. }
  43. $id_list = explode('_', $_REQUEST['id']);
  44. $id = $id_list[1];
  45. $agenda->editEvent(
  46. $id,
  47. $_REQUEST['start'],
  48. $_REQUEST['end'],
  49. $_REQUEST['all_day'],
  50. $_REQUEST['title'],
  51. $_REQUEST['content']
  52. );
  53. break;
  54. case 'delete_event':
  55. if (!$agenda->getIsAllowedToEdit()) {
  56. break;
  57. }
  58. $id_list = explode('_', $_REQUEST['id']);
  59. $id = $id_list[1];
  60. $deleteAllEventsFromSerie = isset($_REQUEST['delete_all_events']) ? true : false;
  61. $agenda->deleteEvent($id, $deleteAllEventsFromSerie);
  62. break;
  63. case 'resize_event':
  64. if (!$agenda->getIsAllowedToEdit()) {
  65. break;
  66. }
  67. $minute_delta = $_REQUEST['minute_delta'];
  68. $id = explode('_', $_REQUEST['id']);
  69. $id = $id[1];
  70. $agenda->resizeEvent($id, $minute_delta);
  71. break;
  72. case 'move_event':
  73. if (!$agenda->getIsAllowedToEdit()) {
  74. break;
  75. }
  76. $minute_delta = $_REQUEST['minute_delta'];
  77. $allDay = $_REQUEST['all_day'];
  78. $id = explode('_', $_REQUEST['id']);
  79. $id = $id[1];
  80. $agenda->move_event($id, $minute_delta, $allDay);
  81. break;
  82. case 'get_events':
  83. $filter = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : null;
  84. $sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : null;
  85. $result = $agenda->parseAgendaFilter($filter);
  86. $groupId = current($result['groups']);
  87. $userId = current($result['users']);
  88. $start = isset($_REQUEST['start']) ? api_strtotime($_REQUEST['start']) : null;
  89. $end = isset($_REQUEST['end']) ? api_strtotime($_REQUEST['end']) : null;
  90. if ($type == 'personal' && !empty($sessionId)) {
  91. $agenda->setSessionId($sessionId);
  92. }
  93. $events = $agenda->getEvents(
  94. $start,
  95. $end,
  96. api_get_course_int_id(),
  97. $groupId,
  98. $userId
  99. );
  100. echo $events;
  101. break;
  102. case 'get_user_agenda':
  103. //Used in the admin user list
  104. api_protect_admin_script();
  105. if (api_is_allowed_to_edit(null, true)) {
  106. //@todo move this in the agenda class
  107. $DaysShort = api_get_week_days_short();
  108. $MonthsLong = api_get_months_long();
  109. $user_id = intval($_REQUEST['user_id']);
  110. $my_course_list = CourseManager::get_courses_list_by_user_id($user_id, true);
  111. if (!is_array($my_course_list)) {
  112. // this is for the special case if the user has no courses (otherwise you get an error)
  113. $my_course_list = array();
  114. }
  115. $today = getdate();
  116. $year = (!empty($_GET['year']) ? (int) $_GET['year'] : null);
  117. if ($year == null) {
  118. $year = $today['year'];
  119. }
  120. $month = (!empty($_GET['month']) ? (int) $_GET['month'] : null);
  121. if ($month == null) {
  122. $month = $today['mon'];
  123. }
  124. $day = (!empty($_GET['day']) ? (int) $_GET['day'] : null);
  125. if ($day == null) {
  126. $day = $today['mday'];
  127. }
  128. $monthName = $MonthsLong[$month - 1];
  129. $week = null;
  130. $agendaitems = Agenda::get_myagendaitems(
  131. $user_id,
  132. $my_course_list,
  133. $month,
  134. $year
  135. );
  136. $agendaitems = Agenda::get_global_agenda_items(
  137. $agendaitems,
  138. $day,
  139. $month,
  140. $year,
  141. $week,
  142. "month_view"
  143. );
  144. if (api_get_setting('allow_personal_agenda') == 'true') {
  145. $agendaitems = Agenda::get_personal_agenda_items(
  146. $user_id,
  147. $agendaitems,
  148. $day,
  149. $month,
  150. $year,
  151. $week,
  152. "month_view"
  153. );
  154. }
  155. Agenda::display_mymonthcalendar(
  156. $user_id,
  157. $agendaitems,
  158. $month,
  159. $year,
  160. array(),
  161. $monthName,
  162. false
  163. );
  164. }
  165. break;
  166. default:
  167. echo '';
  168. }
  169. exit;