Implement data privacy provider.
[moodle-mod_attendance.git] / manage.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 * Manage attendance sessions
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_manage_page_params();
29
30 $id = required_param('id', PARAM_INT);
31 $from = optional_param('from', null, PARAM_ALPHANUMEXT);
32 $pageparams->view = optional_param('view', null, PARAM_INT);
33 $pageparams->curdate = optional_param('curdate', null, PARAM_INT);
34 $pageparams->perpage = get_config('attendance', 'resultsperpage');
35
36 $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
37 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
38 $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
39
40 require_login($course, true, $cm);
41
42 $context = context_module::instance($cm->id);
43 $capabilities = array(
44 'mod/attendance:manageattendances',
45 'mod/attendance:takeattendances',
46 'mod/attendance:changeattendances'
47 );
48 if (!has_any_capability($capabilities, $context)) {
49 $url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id));
50 redirect($url);
51 }
52
53 $pageparams->init($cm);
54 $att = new mod_attendance_structure($att, $cm, $course, $context, $pageparams);
55
56 // If teacher is coming from block, then check for a session exists for today.
57 if ($from === 'block') {
58 $sessions = $att->get_today_sessions();
59 $size = count($sessions);
60 if ($size == 1) {
61 $sess = reset($sessions);
62 $nottaken = !$sess->lasttaken && has_capability('mod/attendance:takeattendances', $context);
63 $canchange = $sess->lasttaken && has_capability('mod/attendance:changeattendances', $context);
64 if ($nottaken || $canchange) {
65 redirect($att->url_take(array('sessionid' => $sess->id, 'grouptype' => $sess->groupid)));
66 }
67 } else if ($size > 1) {
68 $att->curdate = $today;
69 // Temporarily set $view for single access to page from block.
70 $att->view = ATT_VIEW_DAYS;
71 }
72 }
73
74 $PAGE->set_url($att->url_manage());
75 $PAGE->set_title($course->shortname. ": ".$att->name);
76 $PAGE->set_heading($course->fullname);
77 $PAGE->set_cacheable(true);
78 $PAGE->navbar->add($att->name);
79
80 $output = $PAGE->get_renderer('mod_attendance');
81 $tabs = new attendance_tabs($att, attendance_tabs::TAB_SESSIONS);
82 $filtercontrols = new attendance_filter_controls($att);
83 $sesstable = new attendance_manage_data($att);
84
85
86 $title = get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname);
87 $header = new mod_attendance_header($att, $title);
88
89 // Output starts here.
90
91 echo $output->header();
92 echo $output->render($header);
93 mod_attendance_notifyqueue::show();
94 echo $output->render($tabs);
95 echo $output->render($filtercontrols);
96 echo $output->render($sesstable);
97
98 echo $output->footer();
99