Fixes #223 allow student attendance to be disabled at site-level
[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 redirect($att->url_view());
50 }
51
52 $pageparams->init($cm);
53 $att = new mod_attendance_structure($att, $cm, $course, $context, $pageparams);
54
55 // If teacher is coming from block, then check for a session exists for today.
56 if ($from === 'block') {
57 $sessions = $att->get_today_sessions();
58 $size = count($sessions);
59 if ($size == 1) {
60 $sess = reset($sessions);
61 $nottaken = !$sess->lasttaken && has_capability('mod/attendance:takeattendances', $context);
62 $canchange = $sess->lasttaken && has_capability('mod/attendance:changeattendances', $context);
63 if ($nottaken || $canchange) {
64 redirect($att->url_take(array('sessionid' => $sess->id, 'grouptype' => $sess->groupid)));
65 }
66 } else if ($size > 1) {
67 $att->curdate = $today;
68 // Temporarily set $view for single access to page from block.
69 $att->view = ATT_VIEW_DAYS;
70 }
71 }
72
73 $PAGE->set_url($att->url_manage());
74 $PAGE->set_title($course->shortname. ": ".$att->name);
75 $PAGE->set_heading($course->fullname);
76 $PAGE->set_cacheable(true);
77 $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
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 // Output starts here.
86
87 echo $output->header();
88 echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname));
89 mod_attendance_notifyqueue::show();
90 echo $output->render($tabs);
91 echo $output->render($filtercontrols);
92 echo $output->render($sesstable);
93
94 echo $output->footer();
95