agenda.ajax.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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; //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. echo $agenda->add_event($_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content'], $_REQUEST['users_to_send'], $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. $events = $agenda->get_events($_REQUEST['start'], $_REQUEST['end'], api_get_course_int_id(), $group_id, $_REQUEST['user_id']);
  69. echo $events;
  70. break;
  71. case 'get_user_agenda':
  72. //Used in the admin user list
  73. api_protect_admin_script();
  74. if (api_is_allowed_to_edit(null, true)) {
  75. //@todo move this in the agenda class
  76. $DaysShort = api_get_week_days_short();
  77. $MonthsLong = api_get_months_long();
  78. $user_id = intval($_REQUEST['user_id']);
  79. $my_course_list = CourseManager::get_courses_list_by_user_id($user_id, true);
  80. if (!is_array($my_course_list)) {
  81. // this is for the special case if the user has no courses (otherwise you get an error)
  82. $my_course_list = array();
  83. }
  84. $today = getdate();
  85. $year = (!empty($_GET['year']) ? (int) $_GET['year'] : NULL);
  86. if ($year == NULL) {
  87. $year = $today['year'];
  88. }
  89. $month = (!empty($_GET['month']) ? (int) $_GET['month'] : NULL);
  90. if ($month == NULL) {
  91. $month = $today['mon'];
  92. }
  93. $day = (!empty($_GET['day']) ? (int) $_GET['day'] : NULL);
  94. if ($day == NULL) {
  95. $day = $today['mday'];
  96. }
  97. $monthName = $MonthsLong[$month - 1];
  98. $agendaitems = get_myagendaitems($user_id, $my_course_list, $month, $year);
  99. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  100. if (api_get_setting('allow_personal_agenda') == 'true') {
  101. $agendaitems = get_personal_agenda_items($user_id, $agendaitems, $day, $month, $year, $week, "month_view");
  102. }
  103. display_mymonthcalendar($user_id, $agendaitems, $month, $year, array(), $monthName, false);
  104. }
  105. break;
  106. default:
  107. echo '';
  108. }
  109. exit;