agenda.ajax.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. if ($type == 'course') {
  16. api_protect_course_script(true);
  17. }
  18. $group_id = api_get_group_id();
  19. $user_id = api_get_user_id();
  20. $is_group_tutor = GroupManager::is_tutor_of_group($user_id, $group_id);
  21. $agenda = new Agenda();
  22. $agenda->type = $type; //course,admin or personal
  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. $usersToSend = isset($_REQUEST['users_to_send']) ? $_REQUEST['users_to_send'] : null;
  30. echo $agenda->add_event($_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content'], $usersToSend, $add_as_announcement);
  31. break;
  32. case 'edit_event':
  33. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  34. break;
  35. }
  36. $id_list = explode('_', $_REQUEST['id']);
  37. $id = $id_list[1];
  38. $agenda->edit_event($id, $_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content']);
  39. break;
  40. case 'delete_event':
  41. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  42. break;
  43. }
  44. $id_list = explode('_', $_REQUEST['id']);
  45. $id = $id_list[1];
  46. $agenda->delete_event($id);
  47. break;
  48. case 'resize_event':
  49. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  50. break;
  51. }
  52. $day_delta = $_REQUEST['day_delta'];
  53. $minute_delta = $_REQUEST['minute_delta'];
  54. $id = explode('_', $_REQUEST['id']);
  55. $id = $id[1];
  56. $agenda->resize_event($id, $day_delta, $minute_delta);
  57. break;
  58. case 'move_event':
  59. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  60. break;
  61. }
  62. $day_delta = $_REQUEST['day_delta'];
  63. $minute_delta = $_REQUEST['minute_delta'];
  64. $id = explode('_', $_REQUEST['id']);
  65. $id = $id[1];
  66. $agenda->move_event($id, $day_delta, $minute_delta);
  67. break;
  68. case 'get_events':
  69. // The following code needs a security check for permissions
  70. /*
  71. $uid = $user_id;
  72. if (!empty($_REQUEST['user_id'])) {
  73. $uid = intval($user_id);
  74. }
  75. */
  76. $events = $agenda->get_events($_REQUEST['start'], $_REQUEST['end'], api_get_course_int_id(), $group_id, $user_id);
  77. echo $events;
  78. break;
  79. case 'get_user_agenda':
  80. //Used in the admin user list
  81. api_protect_admin_script();
  82. if (api_is_allowed_to_edit(null, true)) {
  83. //@todo move this in the agenda class
  84. $DaysShort = api_get_week_days_short();
  85. $MonthsLong = api_get_months_long();
  86. $user_id = intval($_REQUEST['user_id']);
  87. $my_course_list = CourseManager::get_courses_list_by_user_id($user_id, true);
  88. if (!is_array($my_course_list)) {
  89. // this is for the special case if the user has no courses (otherwise you get an error)
  90. $my_course_list = array();
  91. }
  92. $today = getdate();
  93. $year = (!empty($_GET['year']) ? (int) $_GET['year'] : NULL);
  94. if ($year == NULL) {
  95. $year = $today['year'];
  96. }
  97. $month = (!empty($_GET['month']) ? (int) $_GET['month'] : NULL);
  98. if ($month == NULL) {
  99. $month = $today['mon'];
  100. }
  101. $day = (!empty($_GET['day']) ? (int) $_GET['day'] : NULL);
  102. if ($day == NULL) {
  103. $day = $today['mday'];
  104. }
  105. $monthName = $MonthsLong[$month - 1];
  106. $agendaitems = get_myagendaitems($user_id, $my_course_list, $month, $year);
  107. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  108. if (api_get_setting('allow_personal_agenda') == 'true') {
  109. $agendaitems = get_personal_agenda_items($user_id, $agendaitems, $day, $month, $year, $week, "month_view");
  110. }
  111. display_mymonthcalendar($user_id, $agendaitems, $month, $year, array(), $monthName, false);
  112. }
  113. break;
  114. default:
  115. echo '';
  116. }
  117. exit;