agenda_list.php 3.4 KB

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