|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00004 // // 00005 // NOTICE OF COPYRIGHT // 00006 // // 00007 // Moodle - Calendar extension // 00008 // // 00009 // Copyright (C) 2003-2004 Greek School Network www.sch.gr // 00010 // // 00011 // Designed by: // 00012 // Avgoustos Tsinakos (tsinakos@teikav.edu.gr) // 00013 // Jon Papaioannou (pj@moodle.org) // 00014 // // 00015 // Programming and development: // 00016 // Jon Papaioannou (pj@moodle.org) // 00017 // // 00018 // For bugs, suggestions, etc contact: // 00019 // Jon Papaioannou (pj@moodle.org) // 00020 // // 00021 // The current module was developed at the University of Macedonia // 00022 // (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) // 00023 // The aim of this project is to provide additional and improved // 00024 // functionality to the Asynchronous Distance Education service that the // 00025 // Greek School Network deploys. // 00026 // // 00027 // This program is free software; you can redistribute it and/or modify // 00028 // it under the terms of the GNU General Public License as published by // 00029 // the Free Software Foundation; either version 2 of the License, or // 00030 // (at your option) any later version. // 00031 // // 00032 // This program is distributed in the hope that it will be useful, // 00033 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00034 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00035 // GNU General Public License for more details: // 00036 // // 00037 // http://www.gnu.org/copyleft/gpl.html // 00038 // // 00040 00049 require_once('../config.php'); 00050 require_once($CFG->dirroot.'/calendar/event_form.php'); 00051 require_once($CFG->dirroot.'/calendar/lib.php'); 00052 require_once($CFG->dirroot.'/course/lib.php'); 00053 00054 require_login(); 00055 00056 $action = optional_param('action', 'new', PARAM_ALPHA); 00057 $eventid = optional_param('id', 0, PARAM_INT); 00058 $courseid = optional_param('courseid', SITEID, PARAM_INT); 00059 $courseid = optional_param('course', $courseid, PARAM_INT); 00060 $cal_y = optional_param('cal_y', 0, PARAM_INT); 00061 $cal_m = optional_param('cal_m', 0, PARAM_INT); 00062 $cal_d = optional_param('cal_d', 0, PARAM_INT); 00063 00064 $url = new moodle_url('/calendar/event.php', array('action' => $action)); 00065 if ($eventid != 0) { 00066 $url->param('id', $eventid); 00067 } 00068 if ($courseid != SITEID) { 00069 $url->param('course', $courseid); 00070 } 00071 if ($cal_y !== 0) { 00072 $url->param('cal_y', $cal_y); 00073 } 00074 if ($cal_m !== 0) { 00075 $url->param('cal_m', $cal_m); 00076 } 00077 if ($cal_d !== 0) { 00078 $url->param('cal_d', $cal_d); 00079 } 00080 $PAGE->set_url($url); 00081 $PAGE->set_pagelayout('standard'); 00082 00083 if ($courseid != SITEID && !empty($courseid)) { 00084 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); 00085 $courses = array($course->id => $course); 00086 $issite = false; 00087 } else { 00088 $course = get_site(); 00089 $courses = calendar_get_default_courses(); 00090 $issite = true; 00091 } 00092 require_login($course, false); 00093 00094 if ($action === 'delete' && $eventid > 0) { 00095 $deleteurl = new moodle_url('/calendar/delete.php', array('id'=>$eventid)); 00096 if ($courseid > 0) { 00097 $deleteurl->param('course', $courseid); 00098 } 00099 redirect($deleteurl); 00100 } 00101 00102 $calendar = new calendar_information($cal_d, $cal_m, $cal_y); 00103 $calendar->prepare_for_view($course, $courses); 00104 00105 $formoptions = new stdClass; 00106 if ($eventid !== 0) { 00107 $title = get_string('editevent', 'calendar'); 00108 $event = calendar_event::load($eventid); 00109 if (!calendar_edit_event_allowed($event)) { 00110 print_error('nopermissions'); 00111 } 00112 $event->action = $action; 00113 $event->course = $courseid; 00114 $event->timedurationuntil = $event->timestart + $event->timeduration; 00115 $event->count_repeats(); 00116 00117 if (!calendar_add_event_allowed($event)) { 00118 print_error('nopermissions'); 00119 } 00120 } else { 00121 $title = get_string('newevent', 'calendar'); 00122 calendar_get_allowed_types($formoptions->eventtypes, $course); 00123 $event = new stdClass(); 00124 $event->action = $action; 00125 $event->course = $courseid; 00126 $event->timeduration = 0; 00127 if ($formoptions->eventtypes->courses) { 00128 if (!$issite) { 00129 $event->courseid = $courseid; 00130 $event->eventtype = 'course'; 00131 } else { 00132 unset($formoptions->eventtypes->courses); 00133 unset($formoptions->eventtypes->groups); 00134 } 00135 } 00136 if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) { 00137 $event->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0); 00138 } else if($cal_y && $cal_m && checkdate($cal_m, 1, $cal_y)) { 00139 $now = usergetdate(time()); 00140 if($cal_y == $now['year'] && $cal_m == $now['mon']) { 00141 $event->timestart = make_timestamp($cal_y, $cal_m, $now['mday'], 0, 0, 0); 00142 } else { 00143 $event->timestart = make_timestamp($cal_y, $cal_m, 1, 0, 0, 0); 00144 } 00145 } 00146 $event = new calendar_event($event); 00147 if (!calendar_add_event_allowed($event)) { 00148 print_error('nopermissions'); 00149 } 00150 } 00151 00152 $properties = $event->properties(true); 00153 $formoptions->event = $event; 00154 $formoptions->hasduration = ($event->timeduration > 0); 00155 $mform = new event_form(null, $formoptions); 00156 $mform->set_data($properties); 00157 $data = $mform->get_data(); 00158 if ($data) { 00159 if ($data->duration == 1) { 00160 $data->timeduration = $data->timedurationuntil- $data->timestart; 00161 } else if ($data->duration == 2) { 00162 $data->timeduration = $data->timedurationminutes * MINSECS; 00163 } else { 00164 $data->timeduration = 0; 00165 } 00166 00167 $event->update($data); 00168 00169 $params = array( 00170 'view' => 'day', 00171 'cal_d' => date('j', $event->timestart), 00172 'cal_m' => date('n', $event->timestart), 00173 'cal_y' => date('y', $event->timestart), 00174 ); 00175 $eventurl = new moodle_url('/calendar/view.php', $params); 00176 if (!empty($event->courseid) && $event->courseid != SITEID) { 00177 $eventurl->param('course', $event->courseid); 00178 } 00179 $eventurl->set_anchor('event_'.$event->id); 00180 redirect($eventurl); 00181 } 00182 00183 $viewcalendarurl = new moodle_url(CALENDAR_URL.'view.php', $PAGE->url->params()); 00184 $viewcalendarurl->remove_params(array('id', 'action')); 00185 $viewcalendarurl->param('view', 'upcoming'); 00186 $strcalendar = get_string('calendar', 'calendar'); 00187 00188 $PAGE->navbar->add($strcalendar, $viewcalendarurl); 00189 $PAGE->navbar->add($title); 00190 $PAGE->set_title($course->shortname.': '.$strcalendar.': '.$title); 00191 $PAGE->set_heading($course->fullname); 00192 00193 $renderer = $PAGE->get_renderer('core_calendar'); 00194 $calendar->add_sidecalendar_blocks($renderer); 00195 00196 echo $OUTPUT->header(); 00197 echo $renderer->start_layout(); 00198 echo $OUTPUT->heading($title); 00199 $mform->display(); 00200 echo $renderer->complete_layout(); 00201 echo $OUTPUT->footer();