Implement data privacy provider.
[moodle-mod_attendance.git] / resetcalendar.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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.
13 //
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/>.
16
17 /**
18 * Reset Calendar events.
19 *
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
23 */
24
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');
29
30 $action = optional_param('action', '', PARAM_ALPHA);
31
32 admin_externalpage_setup('managemodules');
33 $context = context_system::instance();
34
35 // Check permissions.
36 require_capability('mod/attendance:viewreports', $context);
37
38 $exportfilename = 'attendance-absentee.csv';
39
40 $PAGE->set_url('/mod/attendance/resetcalendar.php');
41
42 $PAGE->set_heading($SITE->fullname);
43
44 echo $OUTPUT->header();
45 echo $OUTPUT->heading(get_string('resetcalendar', 'mod_attendance'));
46 $tabmenu = attendance_print_settings_tabs('resetcalendar');
47 echo $tabmenu;
48
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);
57 }
58 }
59 $sessions->close();
60 echo $OUTPUT->notification(get_string('eventscreated', 'mod_attendance'), 'notifysuccess');
61 } else {
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'));
65
66 echo $OUTPUT->confirm(get_string('resetcaledarcreate', 'mod_attendance'), $createurl, $returnurl);
67 } else {
68 echo $OUTPUT->box(get_string("noeventstoreset", "mod_attendance"));
69 }
70 }
71 } else {
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');
78 } else {
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'));
83
84 echo $OUTPUT->confirm(get_string('resetcaledardelete', 'mod_attendance'), $deleteurl, $returnurl);
85 } else {
86 echo $OUTPUT->box(get_string("noeventstoreset", "mod_attendance"));
87 }
88 }
89
90 }
91
92 echo $OUTPUT->footer();