Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/calendar/ -> view.php (source)

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

   1  <?php
   2  
   3  /////////////////////////////////////////////////////////////////////////////
   4  //                                                                         //
   5  // NOTICE OF COPYRIGHT                                                     //
   6  //                                                                         //
   7  // Moodle - Calendar extension                                             //
   8  //                                                                         //
   9  // Copyright (C) 2003-2004  Greek School Network            www.sch.gr     //
  10  //                                                                         //
  11  // Designed by:                                                            //
  12  //     Avgoustos Tsinakos (tsinakos@teikav.edu.gr)                         //
  13  //     Jon Papaioannou (pj@moodle.org)                                     //
  14  //                                                                         //
  15  // Programming and development:                                            //
  16  //     Jon Papaioannou (pj@moodle.org)                                     //
  17  //                                                                         //
  18  // For bugs, suggestions, etc contact:                                     //
  19  //     Jon Papaioannou (pj@moodle.org)                                     //
  20  //                                                                         //
  21  // The current module was developed at the University of Macedonia         //
  22  // (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) //
  23  // The aim of this project is to provide additional and improved           //
  24  // functionality to the Asynchronous Distance Education service that the   //
  25  // Greek School Network deploys.                                           //
  26  //                                                                         //
  27  // This program is free software; you can redistribute it and/or modify    //
  28  // it under the terms of the GNU General Public License as published by    //
  29  // the Free Software Foundation; either version 2 of the License, or       //
  30  // (at your option) any later version.                                     //
  31  //                                                                         //
  32  // This program is distributed in the hope that it will be useful,         //
  33  // but WITHOUT ANY WARRANTY; without even the implied warranty of          //
  34  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
  35  // GNU General Public License for more details:                            //
  36  //                                                                         //
  37  //          http://www.gnu.org/copyleft/gpl.html                           //
  38  //                                                                         //
  39  /////////////////////////////////////////////////////////////////////////////
  40  
  41  /**
  42   * Display the calendar page.
  43   * @copyright 2003 Jon Papaioannou
  44   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  45   * @package core_calendar
  46   */
  47  
  48  require_once('../config.php');
  49  require_once($CFG->dirroot.'/course/lib.php');
  50  require_once($CFG->dirroot.'/calendar/lib.php');
  51  
  52  $categoryid = optional_param('category', null, PARAM_INT);
  53  $courseid = optional_param('course', SITEID, PARAM_INT);
  54  $view = optional_param('view', 'upcoming', PARAM_ALPHA);
  55  $day = optional_param('cal_d', 0, PARAM_INT);
  56  $mon = optional_param('cal_m', 0, PARAM_INT);
  57  $year = optional_param('cal_y', 0, PARAM_INT);
  58  $time = optional_param('time', 0, PARAM_INT);
  59  $lookahead = optional_param('lookahead', null, PARAM_INT);
  60  
  61  $url = new moodle_url('/calendar/view.php');
  62  
  63  // If a day, month and year were passed then convert it to a timestamp. If these were passed
  64  // then we can assume the day, month and year are passed as Gregorian, as no where in core
  65  // should we be passing these values rather than the time. This is done for BC.
  66  if (!empty($day) && !empty($mon) && !empty($year)) {
  67      if (checkdate($mon, $day, $year)) {
  68          $time = make_timestamp($year, $mon, $day);
  69      }
  70  }
  71  
  72  if (empty($time)) {
  73      $time = time();
  74  }
  75  
  76  $iscoursecalendar = $courseid != SITEID;
  77  
  78  if ($iscoursecalendar) {
  79      $url->param('course', $courseid);
  80  }
  81  
  82  if ($categoryid) {
  83      $url->param('categoryid', $categoryid);
  84  }
  85  
  86  if ($view !== 'upcoming') {
  87      $time = usergetmidnight($time);
  88      $url->param('view', $view);
  89  }
  90  
  91  $url->param('time', $time);
  92  
  93  $PAGE->set_url($url);
  94  
  95  $course = get_course($courseid);
  96  
  97  if ($iscoursecalendar && !empty($courseid)) {
  98      navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id)));
  99      $PAGE->navbar->add(
 100          get_string('calendar', 'calendar'),
 101          new moodle_url('/calendar/view.php', ['view' => 'month', 'course' => $course->id])
 102      );
 103      $PAGE->set_secondary_navigation(false);
 104  } else if (!empty($categoryid)) {
 105      core_course_category::get($categoryid); // Check that category exists and can be accessed.
 106      $PAGE->set_category_by_id($categoryid);
 107      navigation_node::override_active_url(new moodle_url('/course/index.php', array('categoryid' => $categoryid)));
 108      $PAGE->navbar->add(
 109          get_string('calendar', 'calendar'),
 110          new moodle_url('/calendar/view.php', ['view' => 'month', 'category' => $categoryid])
 111      );
 112      $PAGE->set_secondary_navigation(false);
 113  } else {
 114      $PAGE->set_context(context_system::instance());
 115  }
 116  
 117  require_login($course, false);
 118  
 119  $calendar = calendar_information::create($time, $courseid, $categoryid);
 120  
 121  $pagetitle = '';
 122  
 123  $strcalendar = get_string('calendar', 'calendar');
 124  
 125  switch($view) {
 126      case 'day':
 127          $PAGE->navbar->add(userdate($time, get_string('strftimedate')));
 128          $pagetitle = get_string('dayviewtitle', 'calendar', userdate($time, get_string('strftimedaydate')));
 129      break;
 130      case 'month':
 131          $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear')));
 132          $pagetitle = get_string('detailedmonthviewtitle', 'calendar', userdate($time, get_string('strftimemonthyear')));
 133      break;
 134      case 'upcoming':
 135          $pagetitle = get_string('upcomingevents', 'calendar');
 136      break;
 137  }
 138  
 139  // Print title and header
 140  $PAGE->set_pagelayout('standard');
 141  $PAGE->set_title("$course->shortname: $strcalendar: $pagetitle");
 142  
 143  $headingstr = get_string('calendar', 'core_calendar');
 144  $headingstr = ($iscoursecalendar) ? "{$headingstr}: {$COURSE->shortname}" : $headingstr;
 145  $PAGE->set_heading($headingstr);
 146  
 147  $renderer = $PAGE->get_renderer('core_calendar');
 148  $calendar->add_sidecalendar_blocks($renderer, true, $view);
 149  
 150  echo $OUTPUT->header();
 151  echo $renderer->start_layout();
 152  echo html_writer::start_tag('div', ['class' => 'heightcontainer', 'data-calendar-type' => 'main-block']);
 153  
 154  
 155  
 156  list($data, $template) = calendar_get_view($calendar, $view, true, false, $lookahead);
 157  echo $renderer->render_from_template($template, $data);
 158  
 159  echo html_writer::end_tag('div');
 160  
 161  list($data, $template) = calendar_get_footer_options($calendar);
 162  echo $renderer->render_from_template($template, $data);
 163  
 164  echo $renderer->complete_layout();
 165  echo $OUTPUT->footer();