agenda.ajax.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. $type = isset($_GET['type']) && in_array($_GET['type'], array('personal', 'course', 'admin')) ? $_GET['type'] : 'personal';
  7. if ($type == 'personal') {
  8. $cidReset = true; // fixes #5162
  9. }
  10. require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.inc.php';
  11. $action = isset($_GET['a']) ? $_GET['a'] : null;
  12. if ($type == 'course') {
  13. api_protect_course_script(true);
  14. }
  15. $group_id = api_get_group_id();
  16. $user_id = api_get_user_id();
  17. $is_group_tutor = GroupManager::is_tutor_of_group($user_id, $group_id);
  18. $agenda = new Agenda();
  19. $agenda->setType($type); //course,admin or personal
  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. $usersToSend = isset($_REQUEST['users_to_send']) ? $_REQUEST['users_to_send'] : null;
  27. echo $agenda->add_event($_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content'], $usersToSend, $add_as_announcement);
  28. break;
  29. case 'edit_event':
  30. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  31. break;
  32. }
  33. $id_list = explode('_', $_REQUEST['id']);
  34. $id = $id_list[1];
  35. $agenda->edit_event($id, $_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content']);
  36. break;
  37. case 'delete_event':
  38. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  39. break;
  40. }
  41. $id_list = explode('_', $_REQUEST['id']);
  42. $id = $id_list[1];
  43. $agenda->delete_event($id);
  44. break;
  45. case 'resize_event':
  46. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  47. break;
  48. }
  49. $day_delta = $_REQUEST['day_delta'];
  50. $minute_delta = $_REQUEST['minute_delta'];
  51. $id = explode('_', $_REQUEST['id']);
  52. $id = $id[1];
  53. $agenda->resize_event($id, $day_delta, $minute_delta);
  54. break;
  55. case 'move_event':
  56. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  57. break;
  58. }
  59. $day_delta = $_REQUEST['day_delta'];
  60. $minute_delta = $_REQUEST['minute_delta'];
  61. $id = explode('_', $_REQUEST['id']);
  62. $id = $id[1];
  63. $agenda->move_event($id, $day_delta, $minute_delta);
  64. break;
  65. case 'get_events':
  66. $user_id = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : null;
  67. if (substr($user_id, 0, 1) == 'G') {
  68. $length = strlen($user_id);
  69. $group_id = substr($user_id, 2, $length-1);
  70. }
  71. $events = $agenda->get_events(
  72. $_REQUEST['start'],
  73. $_REQUEST['end'],
  74. api_get_course_int_id(),
  75. $group_id ,
  76. $user_id
  77. );
  78. echo $events;
  79. break;
  80. case 'get_user_agenda':
  81. //Used in the admin user list
  82. api_protect_admin_script();
  83. if (api_is_allowed_to_edit(null, true)) {
  84. //@todo move this in the agenda class
  85. $DaysShort = api_get_week_days_short();
  86. $MonthsLong = api_get_months_long();
  87. $user_id = intval($_REQUEST['user_id']);
  88. $my_course_list = CourseManager::get_courses_list_by_user_id($user_id, true);
  89. if (!is_array($my_course_list)) {
  90. // this is for the special case if the user has no courses (otherwise you get an error)
  91. $my_course_list = array();
  92. }
  93. $today = getdate();
  94. $year = (!empty($_GET['year']) ? (int) $_GET['year'] : NULL);
  95. if ($year == NULL) {
  96. $year = $today['year'];
  97. }
  98. $month = (!empty($_GET['month']) ? (int) $_GET['month'] : NULL);
  99. if ($month == NULL) {
  100. $month = $today['mon'];
  101. }
  102. $day = (!empty($_GET['day']) ? (int) $_GET['day'] : NULL);
  103. if ($day == NULL) {
  104. $day = $today['mday'];
  105. }
  106. $monthName = $MonthsLong[$month - 1];
  107. $agendaitems = get_myagendaitems($user_id, $my_course_list, $month, $year);
  108. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  109. if (api_get_setting('allow_personal_agenda') == 'true') {
  110. $agendaitems = get_personal_agenda_items($user_id, $agendaitems, $day, $month, $year, $week, "month_view");
  111. }
  112. display_mymonthcalendar($user_id, $agendaitems, $month, $year, array(), $monthName, false);
  113. }
  114. break;
  115. default:
  116. echo '';
  117. }
  118. exit;