agenda.ajax.php 6.1 KB

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