agenda.ajax.php 5.9 KB

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