Merge pull request #83 from barrysspace/expired_self_enrolments_MDL26
[moodle-mod_attendance.git] / student_attenance_form.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 require_once($CFG->libdir.'/formslib.php');
18
19 class mod_attendance_student_attendance_form extends moodleform {
20 public function definition() {
21 global $CFG, $USER;
22
23 $mform =& $this->_form;
24
25 $course = $this->_customdata['course'];
26 $cm = $this->_customdata['cm'];
27 $modcontext = $this->_customdata['modcontext'];
28 $attforsession = $this->_customdata['session'];
29 $attblock = $this->_customdata['attendance'];
30
31 $statuses = $attblock->get_statuses();
32
33 $mform->addElement('hidden', 'sessid', null);
34 $mform->setType('sessid', PARAM_INT);
35 $mform->setConstant('sessid', $attforsession->id);
36
37 $mform->addElement('hidden', 'sesskey', null);
38 $mform->setType('sesskey', PARAM_INT);
39 $mform->setConstant('sesskey', sesskey());
40
41 // Set a title as the date and time of the session.
42 $sesstiontitle = userdate($attforsession->sessdate, get_string('strftimedate')).' '
43 .userdate($attforsession->sessdate, get_string('strftimehm', 'mod_attendance'));
44
45 $mform->addElement('header', 'session', $sesstiontitle);
46
47 // If a session description is set display it.
48 if (!empty($attforsession->description)) {
49 $mform->addElement('html', $attforsession->description);
50 }
51
52 // Create radio buttons for setting the attendance status.
53 $radioarray = array();
54 foreach ($statuses as $status) {
55 $radioarray[] =& $mform->createElement('radio', 'status', '', $status->description, $status->id, array());
56 }
57 // Add the radio buttons as a control with the user's name in front.
58 $mform->addGroup($radioarray, 'statusarray', $USER->firstname.' '.$USER->lastname.':', array(''), false);
59 $mform->addRule('statusarray', get_string('attendancenotset', 'attendance'), 'required', '', 'client', false, false);
60
61 $this->add_action_buttons();
62 }
63 }