agenda_list.php 2.7 KB

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