agenda_list.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.calendar
  5. */
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. $interbreadcrumb[] = array(
  8. 'url' => api_get_path(WEB_CODE_PATH) . "calendar/agenda_js.php",
  9. 'name' => get_lang('Agenda')
  10. );
  11. $currentCourseId = api_get_course_int_id();
  12. $agenda = new Agenda();
  13. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
  14. $agenda->setType($type);
  15. $events = $agenda->getEvents(
  16. null,
  17. null,
  18. $currentCourseId,
  19. api_get_group_id(),
  20. null,
  21. 'array'
  22. );
  23. $this_section = SECTION_MYAGENDA;
  24. if (!empty($currentCourseId) && $currentCourseId != -1) {
  25. // Agenda is inside a course tool
  26. $url = api_get_self() . '?' . api_get_cidreq();
  27. $this_section = SECTION_COURSES;
  28. // Order by start date
  29. usort($events, function($a, $b) {
  30. $t1 = strtotime($a['start']);
  31. $t2 = strtotime($b['start']);
  32. return $t1 > $t2;
  33. });
  34. } else {
  35. // Agenda is out of the course tool (e.g personal agenda)
  36. // Little hack to sort the events by start date in personal agenda (Agenda events List view - See #8014)
  37. usort($events, function($a, $b) {
  38. $t1 = strtotime($a['start']);
  39. $t2 = strtotime($b['start']);
  40. return $t1 - $t2;
  41. });
  42. $url = false;
  43. if (!empty($events)) {
  44. foreach ($events as &$event) {
  45. $courseId = isset($event['course_id']) ? $event['course_id'] : '';
  46. $event['url'] = api_get_self() . '?cid=' . $courseId . '&type=' . $event['type'];
  47. }
  48. }
  49. }
  50. $actions = $agenda->displayActions('list');
  51. $tpl = new Template(get_lang('Events'));
  52. $tpl->assign('agenda_events', $events);
  53. $tpl->assign('url', $url);
  54. $tpl->assign('show_action', in_array($type, ['course', 'session']));
  55. $tpl->assign('actions', $actions);
  56. $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
  57. if (api_is_allowed_to_edit()) {
  58. if (isset($_GET['action']) && $_GET['action'] == 'change_visibility') {
  59. $courseInfo = api_get_course_info();
  60. $courseCondition = '';
  61. // This happens when list agenda is not inside a course
  62. if (($type == 'course' || $type == 'session' && !empty($courseInfo))) {
  63. // For course and session event types
  64. // Just needs course ID
  65. $agenda->changeVisibility($_GET['id'], $_GET['visibility'], $courseInfo);
  66. } else {
  67. $courseCondition = '&'.api_get_cidreq();
  68. }
  69. header('Location: '. api_get_self().'?type='.$agenda->type.$courseCondition);
  70. exit;
  71. }
  72. }
  73. $templateName = $tpl->get_template('agenda/event_list.tpl');
  74. $content = $tpl->fetch($templateName);
  75. $tpl->assign('content', $content);
  76. $tpl->display_one_col_template();