Implement data privacy provider.
[moodle-mod_attendance.git] / take.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 * Take Attendance
19 *
20 * @package mod_attendance
21 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25 require_once(dirname(__FILE__).'/../../config.php');
26 require_once(dirname(__FILE__).'/locallib.php');
27
28 $pageparams = new mod_attendance_take_page_params();
29
30 $id = required_param('id', PARAM_INT);
31 $pageparams->sessionid = required_param('sessionid', PARAM_INT);
32 $pageparams->grouptype = required_param('grouptype', PARAM_INT);
33 $pageparams->sort = optional_param('sort', ATT_SORT_DEFAULT, PARAM_INT);
34 $pageparams->copyfrom = optional_param('copyfrom', null, PARAM_INT);
35 $pageparams->viewmode = optional_param('viewmode', null, PARAM_INT);
36 $pageparams->gridcols = optional_param('gridcols', null, PARAM_INT);
37 $pageparams->page = optional_param('page', 1, PARAM_INT);
38 $pageparams->perpage = optional_param('perpage', get_config('attendance', 'resultsperpage'), PARAM_INT);
39
40 $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
41 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
42 $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
43 // Check this is a valid session for this attendance.
44 $session = $DB->get_record('attendance_sessions', array('id' => $pageparams->sessionid, 'attendanceid' => $att->id),
45 '*', MUST_EXIST);
46
47 require_login($course, true, $cm);
48 $context = context_module::instance($cm->id);
49 require_capability('mod/attendance:takeattendances', $context);
50
51 $pageparams->group = groups_get_activity_group($cm, true);
52
53 $pageparams->init($course->id);
54 $att = new mod_attendance_structure($att, $cm, $course, $PAGE->context, $pageparams);
55
56 $allowedgroups = groups_get_activity_allowed_groups($cm);
57 if (!empty($pageparams->grouptype) && !array_key_exists($pageparams->grouptype, $allowedgroups)) {
58 $group = groups_get_group($pageparams->grouptype);
59 throw new moodle_exception('cannottakeforgroup', 'attendance', '', $group->name);
60 }
61
62 if (($formdata = data_submitted()) && confirm_sesskey()) {
63 $att->take_from_form_data($formdata);
64 }
65
66 $PAGE->set_url($att->url_take());
67 $PAGE->set_title($course->shortname. ": ".$att->name);
68 $PAGE->set_heading($course->fullname);
69 $PAGE->set_cacheable(true);
70 $PAGE->navbar->add($att->name);
71
72 $output = $PAGE->get_renderer('mod_attendance');
73 $tabs = new attendance_tabs($att);
74 $sesstable = new attendance_take_data($att);
75
76 // Output starts here.
77
78 echo $output->header();
79 echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname));
80 echo $output->render($tabs);
81 echo $output->render($sesstable);
82
83 echo $output->footer();