Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/calendar/delete.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 require_once('../config.php');
00028 require_once($CFG->dirroot.'/calendar/event_form.php');
00029 require_once($CFG->dirroot.'/calendar/lib.php');
00030 require_once($CFG->dirroot.'/course/lib.php');
00031 
00032 $eventid = required_param('id', PARAM_INT);
00033 $confirm = optional_param('confirm', false, PARAM_BOOL);
00034 $repeats = optional_param('repeats', false, PARAM_BOOL);
00035 $courseid = optional_param('course', 0, PARAM_INT);
00036 
00037 $PAGE->set_url('/calendar/delete.php', array('id'=>$eventid));
00038 
00039 if(!$site = get_site()) {
00040     redirect(new moodle_url('/admin/index.php'));
00041 }
00042 
00043 $event = calendar_event::load($eventid);
00044 
00051 if ($event->eventtype !== 'user' && $event->eventtype !== 'site') {
00052     $courseid = $event->courseid;
00053 }
00054 $course = $DB->get_record('course', array('id'=>$courseid));
00055 require_login($course);
00056 if (!$course) {
00057     $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong
00058 }
00059 
00060 // Check the user has the required capabilities to edit an event
00061 if (!calendar_edit_event_allowed($event)) {
00062     print_error('nopermissions');
00063 }
00064 
00065 // Count the repeats, do we need to consider the possibility of deleting repeats
00066 $event->timedurationuntil = $event->timestart + $event->timeduration;
00067 $event->count_repeats();
00068 
00069 // Is used several times, and sometimes with modification if required
00070 $viewcalendarurl = new moodle_url(CALENDAR_URL.'view.php', array('view'=>'upcoming'));
00071 $viewcalendarurl->param('cal_y', date('Y', $event->timestart));
00072 $viewcalendarurl->param('cal_m', date('m', $event->timestart));
00073 
00074 // If confirm is set (PARAM_BOOL) then we have confirmation of initention to delete
00075 if ($confirm) {
00076     // Confirm the session key to stop CSRF
00077     if (!confirm_sesskey()) {
00078         print_error('confirmsesskeybad');
00079     }
00080     // Delete the event and possibly repeats
00081     $event->delete($repeats);
00082     // If the event has an associated course then we need to include it in the redirect link
00083     if (!empty($event->courseid) && $event->courseid > 0) {
00084         $viewcalendarurl->param('course', $event->courseid);
00085     }
00086     // And redirect
00087     redirect($viewcalendarurl);
00088 }
00089 
00090 // Prepare the page to show the confirmation form
00091 $title = get_string('deleteevent', 'calendar');
00092 $strcalendar = get_string('calendar', 'calendar');
00093 
00094 $PAGE->navbar->add($strcalendar, $viewcalendarurl);
00095 $PAGE->navbar->add($title);
00096 $PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title);
00097 $PAGE->set_heading($COURSE->fullname);
00098 echo $OUTPUT->header();
00099 echo $OUTPUT->box_start('eventlist');
00100 
00101 // Delete this event button is always shown
00102 $url = new moodle_url(CALENDAR_URL.'delete.php', array('id'=>$event->id, 'confirm'=>true));
00103 $buttons = $OUTPUT->single_button($url, get_string('delete'));
00104 
00105 // If there are repeated events then add a Delete Repeated button
00106 $repeatspan = '';
00107 if (!empty($event->eventrepeats) && $event->eventrepeats > 0) {
00108     $url = new moodle_url(CALENDAR_URL.'delete.php', array('id'=>$event->repeatid, 'confirm'=>true, 'repeats'=>true));
00109     $buttons .= $OUTPUT->single_button($url, get_string('deleteall'));
00110     $repeatspan = '<br /><br /><span>'.get_string('youcandeleteallrepeats', 'calendar').'</span>';
00111 }
00112 
00113 // And add the cancel button
00114 $buttons .= $OUTPUT->single_button($viewcalendarurl, get_string('cancel'));
00115 
00116 // And show the buttons and notes
00117 echo $OUTPUT->box_start('generalbox', 'notice');
00118 echo $OUTPUT->box(get_string('confirmeventdelete', 'calendar').$repeatspan);
00119 echo $OUTPUT->box($buttons, 'buttons');
00120 echo $OUTPUT->box_end();
00121 
00122 // Print the event so that people can visually confirm they have the correct event
00123 $event->time = calendar_format_event_time($event, time(), null, false);
00124 calendar_print_event($event, false);
00125 
00126 echo $OUTPUT->box_end();
00127 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations