[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/calendar/ -> event.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 (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   * This file is part of the Calendar section Moodle
  43   *
  44   * @copyright 2003-2004 Jon Papaioannou (pj@moodle.org)
  45   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
  46   * @package calendar
  47   */
  48  
  49  require_once('../config.php');
  50  require_once($CFG->dirroot.'/calendar/event_form.php');
  51  require_once($CFG->dirroot.'/calendar/lib.php');
  52  require_once($CFG->dirroot.'/course/lib.php');
  53  
  54  require_login();
  55  
  56  $action = optional_param('action', 'new', PARAM_ALPHA);
  57  $eventid = optional_param('id', 0, PARAM_INT);
  58  $courseid = optional_param('courseid', SITEID, PARAM_INT);
  59  $courseid = optional_param('course', $courseid, PARAM_INT);
  60  $day = optional_param('cal_d', 0, PARAM_INT);
  61  $month = optional_param('cal_m', 0, PARAM_INT);
  62  $year = optional_param('cal_y', 0, PARAM_INT);
  63  $time = optional_param('time', 0, PARAM_INT);
  64  
  65  // If a day, month and year were passed then convert it to a timestamp. If these were passed
  66  // then we can assume the day, month and year are passed as Gregorian, as no where in core
  67  // should we be passing these values rather than the time. This is done for BC.
  68  if (!empty($day) && !empty($month) && !empty($year)) {
  69      if (checkdate($month, $day, $year)) {
  70          $time = make_timestamp($year, $month, $day);
  71      } else {
  72          $time = time();
  73      }
  74  } else if (empty($time)) {
  75      $time = time();
  76  }
  77  
  78  $url = new moodle_url('/calendar/event.php', array('action' => $action));
  79  
  80  if ($eventid != 0) {
  81      $url->param('id', $eventid);
  82  }
  83  
  84  if ($courseid != SITEID) {
  85      $url->param('course', $courseid);
  86  }
  87  
  88  $PAGE->set_url($url);
  89  $PAGE->set_pagelayout('admin');
  90  
  91  if ($courseid != SITEID && !empty($courseid)) {
  92      $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  93      $courses = array($course->id => $course);
  94      $issite = false;
  95  } else {
  96      $course = get_site();
  97      $courses = calendar_get_default_courses();
  98      $issite = true;
  99  }
 100  require_login($course, false);
 101  
 102  if ($action === 'delete' && $eventid > 0) {
 103      $deleteurl = new moodle_url('/calendar/delete.php', array('id'=>$eventid));
 104      if ($courseid > 0) {
 105          $deleteurl->param('course', $courseid);
 106      }
 107      redirect($deleteurl);
 108  }
 109  
 110  $calendar = new calendar_information(0, 0, 0, $time);
 111  $calendar->prepare_for_view($course, $courses);
 112  
 113  $formoptions = new stdClass;
 114  if ($eventid !== 0) {
 115      $title = get_string('editevent', 'calendar');
 116      $event = calendar_event::load($eventid);
 117      if (!calendar_edit_event_allowed($event)) {
 118          print_error('nopermissions');
 119      }
 120      $event->action = $action;
 121      $event->course = $courseid;
 122      $event->timedurationuntil = $event->timestart + $event->timeduration;
 123      $event->count_repeats();
 124  
 125      if (!calendar_add_event_allowed($event)) {
 126          print_error('nopermissions');
 127      }
 128  } else {
 129      $title = get_string('newevent', 'calendar');
 130      calendar_get_allowed_types($formoptions->eventtypes, $course);
 131      $event = new stdClass();
 132      $event->action = $action;
 133      $event->course = $courseid;
 134      $event->courseid = $courseid;
 135      $event->timeduration = 0;
 136      if ($formoptions->eventtypes->courses) {
 137          if (!$issite) {
 138              $event->eventtype = 'course';
 139          } else {
 140              unset($formoptions->eventtypes->courses);
 141              unset($formoptions->eventtypes->groups);
 142          }
 143      }
 144      $event->timestart = $time;
 145      $event = new calendar_event($event);
 146      if (!calendar_add_event_allowed($event)) {
 147          print_error('nopermissions');
 148      }
 149  }
 150  
 151  $properties = $event->properties(true);
 152  $formoptions->event = $event;
 153  $formoptions->hasduration = ($event->timeduration > 0);
 154  $mform = new event_form(null, $formoptions);
 155  $mform->set_data($properties);
 156  $data = $mform->get_data();
 157  if ($data) {
 158      if ($data->duration == 1) {
 159          $data->timeduration = $data->timedurationuntil- $data->timestart;
 160      } else if ($data->duration == 2) {
 161          $data->timeduration = $data->timedurationminutes * MINSECS;
 162      } else {
 163          $data->timeduration = 0;
 164      }
 165  
 166      $event->update($data);
 167  
 168      $params = array(
 169          'view' => 'day',
 170          'time' => $event->timestart,
 171      );
 172      $eventurl = new moodle_url('/calendar/view.php', $params);
 173      if (!empty($event->courseid) && $event->courseid != SITEID) {
 174          $eventurl->param('course', $event->courseid);
 175      }
 176      $eventurl->set_anchor('event_'.$event->id);
 177      redirect($eventurl);
 178  }
 179  
 180  $viewcalendarurl = new moodle_url(CALENDAR_URL.'view.php', $PAGE->url->params());
 181  $viewcalendarurl->remove_params(array('id', 'action'));
 182  $viewcalendarurl->param('view', 'upcoming');
 183  $strcalendar = get_string('calendar', 'calendar');
 184  
 185  $PAGE->navbar->add($strcalendar, $viewcalendarurl);
 186  $PAGE->navbar->add($title);
 187  $PAGE->set_title($course->shortname.': '.$strcalendar.': '.$title);
 188  $PAGE->set_heading($course->fullname);
 189  
 190  $renderer = $PAGE->get_renderer('core_calendar');
 191  $calendar->add_sidecalendar_blocks($renderer);
 192  
 193  echo $OUTPUT->header();
 194  echo $OUTPUT->heading($title);
 195  $mform->display();
 196  echo $OUTPUT->footer();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1