agenda.ajax.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once '../global.inc.php';
  7. require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.inc.php';
  8. require_once api_get_path(SYS_CODE_PATH).'calendar/myagenda.inc.php';
  9. require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.lib.php';
  10. $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
  11. $type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin')) ? $_REQUEST['type'] : 'personal';
  12. if ($type =='course') {
  13. // Access control
  14. api_protect_course_script(true);
  15. }
  16. $agenda = new Agenda();
  17. $agenda->type = $type; //course,admin or personal
  18. switch ($action) {
  19. case 'add_event':
  20. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  21. break;
  22. }
  23. echo $agenda->add_event($_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'],
  24. $_REQUEST['title'], $_REQUEST['content'], $_REQUEST['users_to_send'], $_REQUEST['add_as_annonuncement']);
  25. break;
  26. case 'edit_event':
  27. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  28. break;
  29. }
  30. $id_list = explode('_', $_REQUEST['id']);
  31. $id = $id_list[1];
  32. $agenda->edit_event($id, $_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content']);
  33. break;
  34. case 'delete_event':
  35. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  36. break;
  37. }
  38. $id_list = explode('_', $_REQUEST['id']);
  39. $id = $id_list[1];
  40. $agenda->delete_event($id);
  41. break;
  42. case 'move_event':
  43. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  44. break;
  45. }
  46. $day_delta = $_REQUEST['day_delta'];
  47. $minute_delta = $_REQUEST['minute_delta'];
  48. $id = explode('_', $_REQUEST['id']);
  49. $id = $id[1];
  50. $agenda->move_event($id, $day_delta, $minute_delta);
  51. break;
  52. case 'get_events':
  53. $start = $_REQUEST['start'];
  54. $end = $_REQUEST['end'];
  55. $events = $agenda->get_events($start, $end, api_get_user_id(), api_get_course_int_id());
  56. echo $events;
  57. break;
  58. case 'get_user_agenda':
  59. //Used in the admin user list
  60. api_protect_admin_script();
  61. if (api_is_allowed_to_edit(null, true)) {
  62. //@todo move this in the agenda class
  63. $DaysShort = api_get_week_days_short();
  64. $MonthsLong = api_get_months_long();
  65. $user_id = intval($_REQUEST['user_id']);
  66. $my_course_list = CourseManager::get_courses_list_by_user_id($user_id, true);
  67. if (!is_array($my_course_list)) {
  68. // this is for the special case if the user has no courses (otherwise you get an error)
  69. $my_course_list = array();
  70. }
  71. $today = getdate();
  72. $year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL);
  73. if ($year == NULL) {
  74. $year = $today['year'];
  75. }
  76. $month = (!empty($_GET['month'])? (int)$_GET['month']:NULL);
  77. if ($month == NULL) {
  78. $month = $today['mon'];
  79. }
  80. $day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL);
  81. if ($day == NULL) {
  82. $day = $today['mday'];
  83. }
  84. $monthName = $MonthsLong[$month -1];
  85. $agendaitems = get_myagendaitems($user_id, $my_course_list, $month, $year);
  86. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  87. if (api_get_setting('allow_personal_agenda') == 'true') {
  88. $agendaitems = get_personal_agenda_items($user_id, $agendaitems, $day, $month, $year, $week, "month_view");
  89. }
  90. display_mymonthcalendar($user_id, $agendaitems, $month, $year, array(), $monthName, false);
  91. }
  92. break;
  93. default:
  94. echo '';
  95. }
  96. exit;