agenda.ajax.php 4.7 KB

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