agenda_list.php 2.6 KB

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