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