[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/calendar/ -> view.php (source)

   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 ([email protected])                         //
  13  //     Jon Papaioannou ([email protected])                                     //
  14  //                                                                         //
  15  // Programming and development:                                            //
  16  //     Jon Papaioannou ([email protected])                                     //
  17  //                                                                         //
  18  // For bugs, suggestions, etc contact:                                     //
  19  //     Jon Papaioannou ([email protected])                                     //
  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  //  Display the calendar page.
  42  
  43  require_once('../config.php');
  44  require_once($CFG->dirroot.'/course/lib.php');
  45  require_once($CFG->dirroot.'/calendar/lib.php');
  46  
  47  $courseid = optional_param('course', SITEID, PARAM_INT);
  48  $view = optional_param('view', 'upcoming', PARAM_ALPHA);
  49  $day = optional_param('cal_d', 0, PARAM_INT);
  50  $mon = optional_param('cal_m', 0, PARAM_INT);
  51  $year = optional_param('cal_y', 0, PARAM_INT);
  52  $time = optional_param('time', 0, PARAM_INT);
  53  
  54  $url = new moodle_url('/calendar/view.php');
  55  
  56  if ($courseid != SITEID) {
  57      $url->param('course', $courseid);
  58  }
  59  
  60  if ($view !== 'upcoming') {
  61      $url->param('view', $view);
  62  }
  63  
  64  // If a day, month and year were passed then convert it to a timestamp. If these were passed
  65  // then we can assume the day, month and year are passed as Gregorian, as no where in core
  66  // should we be passing these values rather than the time. This is done for BC.
  67  if (!empty($day) && !empty($mon) && !empty($year)) {
  68      if (checkdate($mon, $day, $year)) {
  69          $time = make_timestamp($year, $mon, $day);
  70      } else {
  71          $time = time();
  72      }
  73  } else if (empty($time)) {
  74      $time = time();
  75  }
  76  
  77  $url->param('time', $time);
  78  
  79  $PAGE->set_url($url);
  80  
  81  if ($courseid != SITEID && !empty($courseid)) {
  82      $course = $DB->get_record('course', array('id' => $courseid));
  83      $courses = array($course->id => $course);
  84      $issite = false;
  85      navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id)));
  86  } else {
  87      $course = get_site();
  88      $courses = calendar_get_default_courses();
  89      $issite = true;
  90  }
  91  
  92  require_course_login($course);
  93  
  94  $calendar = new calendar_information(0, 0, 0, $time);
  95  $calendar->prepare_for_view($course, $courses);
  96  
  97  $pagetitle = '';
  98  
  99  $strcalendar = get_string('calendar', 'calendar');
 100  
 101  switch($view) {
 102      case 'day':
 103          $PAGE->navbar->add(userdate($time, get_string('strftimedate')));
 104          $pagetitle = get_string('dayviewtitle', 'calendar', userdate($time, get_string('strftimedaydate')));
 105      break;
 106      case 'month':
 107          $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear')));
 108          $pagetitle = get_string('detailedmonthviewtitle', 'calendar', userdate($time, get_string('strftimemonthyear')));
 109      break;
 110      case 'upcoming':
 111          $pagetitle = get_string('upcomingevents', 'calendar');
 112      break;
 113  }
 114  
 115  // Print title and header
 116  $PAGE->set_pagelayout('standard');
 117  $PAGE->set_title("$course->shortname: $strcalendar: $pagetitle");
 118  $PAGE->set_heading($COURSE->fullname);
 119  $PAGE->set_button(calendar_preferences_button($course));
 120  
 121  $renderer = $PAGE->get_renderer('core_calendar');
 122  $calendar->add_sidecalendar_blocks($renderer, true, $view);
 123  
 124  echo $OUTPUT->header();
 125  echo $renderer->start_layout();
 126  echo html_writer::start_tag('div', array('class'=>'heightcontainer'));
 127  
 128  switch($view) {
 129      case 'day':
 130          echo $renderer->show_day($calendar);
 131      break;
 132      case 'month':
 133          echo $renderer->show_month_detailed($calendar, $url);
 134      break;
 135      case 'upcoming':
 136          $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
 137          if (isset($CFG->calendar_lookahead)) {
 138              $defaultlookahead = intval($CFG->calendar_lookahead);
 139          }
 140          $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
 141  
 142          $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
 143          if (isset($CFG->calendar_maxevents)) {
 144              $defaultmaxevents = intval($CFG->calendar_maxevents);
 145          }
 146          $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
 147          echo $renderer->show_upcoming_events($calendar, $lookahead, $maxevents);
 148      break;
 149  }
 150  
 151  //Link to calendar export page.
 152  echo $OUTPUT->container_start('bottom');
 153  if (!empty($CFG->enablecalendarexport)) {
 154      echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar'));
 155      if (calendar_user_can_add_event($course)) {
 156          echo $OUTPUT->single_button(new moodle_url('/calendar/managesubscriptions.php', array('course'=>$courseid)), get_string('managesubscriptions', 'calendar'));
 157      }
 158      if (isloggedin()) {
 159          $authtoken = sha1($USER->id . $DB->get_field('user', 'password', array('id' => $USER->id)) . $CFG->calendar_exportsalt);
 160          $link = new moodle_url(
 161              '/calendar/export_execute.php',
 162              array('preset_what'=>'all', 'preset_time' => 'recentupcoming', 'userid' => $USER->id, 'authtoken'=>$authtoken)
 163          );
 164          echo html_writer::tag('a', 'iCal',
 165              array('href' => $link, 'title' => get_string('quickdownloadcalendar', 'calendar'), 'class' => 'ical-link'));
 166      }
 167  }
 168  
 169  echo $OUTPUT->container_end();
 170  echo html_writer::end_tag('div');
 171  echo $renderer->complete_layout();
 172  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1