agenda.ajax.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 'resize_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->resize_event($id, $day_delta, $minute_delta);
  51. break;
  52. case 'move_event':
  53. if (!api_is_allowed_to_edit(null, true) && $type == 'course') {
  54. break;
  55. }
  56. $day_delta = $_REQUEST['day_delta'];
  57. $minute_delta = $_REQUEST['minute_delta'];
  58. $id = explode('_', $_REQUEST['id']);
  59. $id = $id[1];
  60. $agenda->move_event($id, $day_delta, $minute_delta);
  61. break;
  62. case 'get_events':
  63. $start = $_REQUEST['start'];
  64. $end = $_REQUEST['end'];
  65. $events = $agenda->get_events($start, $end, api_get_user_id(), api_get_course_int_id());
  66. echo $events;
  67. break;
  68. case 'get_user_agenda':
  69. //Used in the admin user list
  70. api_protect_admin_script();
  71. if (api_is_allowed_to_edit(null, true)) {
  72. //@todo move this in the agenda class
  73. $DaysShort = api_get_week_days_short();
  74. $MonthsLong = api_get_months_long();
  75. $user_id = intval($_REQUEST['user_id']);
  76. $my_course_list = CourseManager::get_courses_list_by_user_id($user_id, true);
  77. if (!is_array($my_course_list)) {
  78. // this is for the special case if the user has no courses (otherwise you get an error)
  79. $my_course_list = array();
  80. }
  81. $today = getdate();
  82. $year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL);
  83. if ($year == NULL) {
  84. $year = $today['year'];
  85. }
  86. $month = (!empty($_GET['month'])? (int)$_GET['month']:NULL);
  87. if ($month == NULL) {
  88. $month = $today['mon'];
  89. }
  90. $day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL);
  91. if ($day == NULL) {
  92. $day = $today['mday'];
  93. }
  94. $monthName = $MonthsLong[$month -1];
  95. $agendaitems = get_myagendaitems($user_id, $my_course_list, $month, $year);
  96. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  97. if (api_get_setting('allow_personal_agenda') == 'true') {
  98. $agendaitems = get_personal_agenda_items($user_id, $agendaitems, $day, $month, $year, $week, "month_view");
  99. }
  100. display_mymonthcalendar($user_id, $agendaitems, $month, $year, array(), $monthName, false);
  101. }
  102. break;
  103. default:
  104. echo '';
  105. }
  106. exit;