agenda.ajax.php 6.0 KB

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