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/>.
20 * @package mod_attendance
21 * @copyright 2013 Davo Smith, Synergy Learning
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(dirname(__FILE__
).'/../../config.php');
27 global $CFG, $DB, $PAGE, $OUTPUT;
28 require_once($CFG->dirroot
.'/mod/attendance/locallib.php');
29 require_once($CFG->dirroot
.'/mod/attendance/tempedit_form.php');
31 $id = required_param('id', PARAM_INT
);
32 $userid = required_param('userid', PARAM_INT
);
33 $action = optional_param('action', null
, PARAM_ALPHA
);
35 $cm = get_coursemodule_from_id('attendance', $id, 0, false
, MUST_EXIST
);
36 $course = $DB->get_record('course', array('id' => $cm->course
), '*', MUST_EXIST
);
37 $att = $DB->get_record('attendance', array('id' => $cm->instance
), '*', MUST_EXIST
);
38 $tempuser = $DB->get_record('attendance_tempusers', array('id' => $userid), '*', MUST_EXIST
);
40 $att = new mod_attendance_structure($att, $cm, $course);
42 $params = array('userid' => $tempuser->id
);
44 $params['action'] = $action;
46 $PAGE->set_url($att->url_tempedit($params));
48 require_login($course, true
, $cm);
49 $context = context_module
::instance($cm->id
);
50 require_capability('mod/attendance:managetemporaryusers', $context);
52 $PAGE->set_title($course->shortname
.": ".$att->name
.' - '.get_string('tempusersedit', 'attendance'));
53 $PAGE->set_heading($course->fullname
);
54 $PAGE->set_cacheable(true
);
55 $PAGE->navbar
->add(get_string('tempusersedit', 'attendance'));
57 /** @var mod_attendance_renderer $output */
58 $output = $PAGE->get_renderer('mod_attendance');
60 if ($action == 'delete') {
61 if (optional_param('confirm', false
, PARAM_BOOL
)) {
64 // Remove the user from the grades table, the attendance log and the tempusers table.
65 $DB->delete_records('grade_grades', array('userid' => $tempuser->studentid
));
66 $DB->delete_records('attendance_log', array('studentid' => $tempuser->studentid
));
67 $DB->delete_records('attendance_tempusers', array('id' => $tempuser->id
));
69 redirect($att->url_managetemp());
72 $info = (object)array(
73 'fullname' => $tempuser->fullname
,
74 'email' => $tempuser->email
,
76 $msg = get_string('confirmdeleteuser', 'attendance', $info);
77 $continue = new moodle_url($PAGE->url
, array('confirm' => 1, 'sesskey' => sesskey()));
79 echo $output->header();
80 echo $output->confirm($msg, $continue, $att->url_managetemp());
81 echo $output->footer();
87 $formdata = new stdClass();
88 $formdata->id
= $cm->id
;
89 $formdata->tname
= $tempuser->fullname
;
90 $formdata->userid
= $tempuser->id
;
91 $formdata->temail
= $tempuser->email
;
93 $mform = new tempedit_form();
94 $mform->set_data($formdata);
96 if ($mform->is_cancelled()) {
97 redirect($att->url_managetemp());
98 } else if ($tempuser = $mform->get_data()) {
100 $updateuser = new stdClass();
101 $updateuser->id
= $tempuser->userid
;
102 $updateuser->fullname
= $tempuser->tname
;
103 $updateuser->email
= $tempuser->temail
;
104 $DB->update_record('attendance_tempusers', $updateuser);
105 redirect($att->url_managetemp());
108 $tabs = new attendance_tabs($att, attendance_tabs
::TAB_TEMPORARYUSERS
);
110 echo $output->header();
111 echo $output->heading(get_string('tempusersedit', 'attendance').' : '.format_string($course->fullname
));
112 echo $output->render($tabs);
114 echo $output->footer($course);