2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Reset Calendar events.
20 * @package mod_attendance
21 * @copyright 2017 onwards Dan Marsden http://danmarsden.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../../config.php');
26 require_once($CFG->libdir
.'/adminlib.php');
27 require_once($CFG->dirroot
.'/mod/attendance/lib.php');
28 require_once($CFG->dirroot
.'/mod/attendance/locallib.php');
30 $action = optional_param('action', '', PARAM_ALPHA
);
32 admin_externalpage_setup('managemodules');
33 $context = context_system
::instance();
36 require_capability('mod/attendance:viewreports', $context);
38 $exportfilename = 'attendance-absentee.csv';
40 $PAGE->set_url('/mod/attendance/resetcalendar.php');
42 $PAGE->set_heading($SITE->fullname
);
44 echo $OUTPUT->header();
45 echo $OUTPUT->heading(get_string('resetcalendar', 'mod_attendance'));
46 $tabmenu = attendance_print_settings_tabs('resetcalendar');
49 if (get_config('attendance', 'enablecalendar')) {
50 // Check to see if all sessions have calendar events.
51 if ($action == 'create' && confirm_sesskey()) {
52 $sessions = $DB->get_recordset('attendance_sessions', array('caleventid' => 0));
53 foreach ($sessions as $session) {
54 attendance_create_calendar_event($session);
55 if ($session->caleventid
) {
56 $DB->update_record('attendance_sessions', $session);
60 echo $OUTPUT->notification(get_string('eventscreated', 'mod_attendance'), 'notifysuccess');
62 if ($DB->record_exists('attendance_sessions', array('caleventid' => 0))) {
63 $createurl = new moodle_url('/mod/attendance/resetcalendar.php', array('action' => 'create'));
64 $returnurl = new moodle_url('/admin/settings.php', array('section' => 'modsettingattendance'));
66 echo $OUTPUT->confirm(get_string('resetcaledarcreate', 'mod_attendance'), $createurl, $returnurl);
68 echo $OUTPUT->box(get_string("noeventstoreset", "mod_attendance"));
72 if ($action == 'delete' && confirm_sesskey()) {
73 $caleventids = $DB->get_records_select_menu('attendance_sessions', 'caleventid > 0', array(),
74 '', 'caleventid, caleventid as id2');
75 $DB->delete_records_list('event', 'id', $caleventids);
76 $DB->execute("UPDATE {attendance_sessions} set caleventid = 0");
77 echo $OUTPUT->notification(get_string('eventsdeleted', 'mod_attendance'), 'notifysuccess');
79 // Check to see if there are any events that need to be deleted.
80 if ($DB->record_exists_select('attendance_sessions', 'caleventid > 0')) {
81 $deleteurl = new moodle_url('/mod/attendance/resetcalendar.php', array('action' => 'delete'));
82 $returnurl = new moodle_url('/admin/settings.php', array('section' => 'modsettingattendance'));
84 echo $OUTPUT->confirm(get_string('resetcaledardelete', 'mod_attendance'), $deleteurl, $returnurl);
86 echo $OUTPUT->box(get_string("noeventstoreset", "mod_attendance"));
92 echo $OUTPUT->footer();