agenda_list.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.calendar
  5. */
  6. //require_once '../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. } else {
  29. // Agenda is out of the course tool (e.g personal agenda)
  30. // Little hack to sort the events by start date in personal agenda (Agenda events List view - See #8014)
  31. usort($events, function($a, $b) {
  32. $t1 = strtotime($a['start']);
  33. $t2 = strtotime($b['start']);
  34. return $t1 - $t2;
  35. });
  36. $url = false;
  37. if (!empty($events)) {
  38. foreach ($events as &$event) {
  39. $courseId = isset($event['course_id']) ? $event['course_id'] : '';
  40. $event['url'] = api_get_self() . '?cid=' . $courseId . '&type=' . $event['type'];
  41. }
  42. }
  43. }
  44. $actions = $agenda->displayActions('list');
  45. $tpl = new Template(get_lang('Events'));
  46. $tpl->assign('agenda_events', $events);
  47. $tpl->assign('url', $url);
  48. $tpl->assign('actions', $actions);
  49. $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
  50. if (api_is_allowed_to_edit()) {
  51. if (isset($_GET['action']) && $_GET['action'] == 'change_visibility') {
  52. $courseInfo = api_get_course_info();
  53. if (empty($courseInfo)) {
  54. // This happens when list agenda is not inside a course
  55. if (
  56. ($type == 'course' || $type == 'session') &&
  57. isset($_GET['cid']) &&
  58. intval($_GET['cid']) !== 0
  59. ) {
  60. // For course and session event types
  61. // Just needs course ID
  62. $courseInfo = array('real_id' => intval($_GET['cid']));
  63. $agenda->changeVisibility($_GET['id'], $_GET['visibility'], $courseInfo);
  64. }
  65. }
  66. header('Location: '. api_get_self());
  67. exit;
  68. }
  69. }
  70. // Loading Agenda template
  71. $templateName = $tpl->get_template('agenda/event_list.tpl');
  72. $content = $tpl->fetch($templateName);
  73. $tpl->assign('content', $content);
  74. // Loading main Chamilo 1 col template
  75. $tpl->display_one_col_template();