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 * Prints attendance info for particular user
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
26 require_once(dirname(__FILE__
).'/../../config.php');
27 require_once(dirname(__FILE__
).'/locallib.php');
29 $pageparams = new mod_attendance_view_page_params();
31 $id = required_param('id', PARAM_INT
);
32 $pageparams->studentid
= optional_param('studentid', null
, PARAM_INT
);
33 $pageparams->mode
= optional_param('mode', mod_attendance_view_page_params
::MODE_THIS_COURSE
, PARAM_INT
);
34 $pageparams->view
= optional_param('view', null
, PARAM_INT
);
35 $pageparams->curdate
= optional_param('curdate', null
, PARAM_INT
);
37 $cm = get_coursemodule_from_id('attendance', $id, 0, false
, MUST_EXIST
);
38 $course = $DB->get_record('course', array('id' => $cm->course
), '*', MUST_EXIST
);
39 $attendance = $DB->get_record('attendance', array('id' => $cm->instance
), '*', MUST_EXIST
);
41 require_login($course, true
, $cm);
42 $context = context_module
::instance($cm->id
);
43 require_capability('mod/attendance:view', $context);
45 $pageparams->init($cm);
46 $att = new mod_attendance_structure($attendance, $cm, $course, $context, $pageparams);
48 // Not specified studentid for displaying attendance?
49 // Redirect to appropriate page if can.
50 if (!$pageparams->studentid
) {
51 $capabilities = array(
52 'mod/attendance:manageattendances',
53 'mod/attendance:takeattendances',
54 'mod/attendance:changeattendances'
56 if (has_any_capability($capabilities, $context)) {
57 redirect($att->url_manage());
58 } else if (has_capability('mod/attendance:viewreports', $context)) {
59 redirect($att->url_report());
63 $PAGE->set_url($att->url_view());
64 $PAGE->set_title($course->shortname
. ": ".$att->name
);
65 $PAGE->set_heading($course->fullname
);
66 $PAGE->set_cacheable(true
);
67 $PAGE->navbar
->add(get_string('attendancereport', 'attendance'));
69 $output = $PAGE->get_renderer('mod_attendance');
71 if (isset($pageparams->studentid
) && $USER->id
!= $pageparams->studentid
) {
72 // Only users with proper permissions should be able to see any user's individual report.
73 require_capability('mod/attendance:viewreports', $context);
74 $userid = $pageparams->studentid
;
76 // A valid request to see another users report has not been sent, show the user's own.
80 $userdata = new attendance_user_data($att, $userid);
81 $header = new mod_attendance_header($att);
83 echo $output->header();
85 echo $output->render($header);
86 echo $output->render($userdata);
88 echo $output->footer();