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/>.
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($CFG->libdir
.'/formslib.php');
29 * class for displaying update form.
31 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class mod_attendance_update_form
extends moodleform
{
37 * Called to define this moodle form
41 public function definition() {
44 $mform =& $this->_form
;
46 $course = $this->_customdata
['course'];
47 $cm = $this->_customdata
['cm'];
48 $modcontext = $this->_customdata
['modcontext'];
49 $sessionid = $this->_customdata
['sessionid'];
51 if (!$sess = $DB->get_record('attendance_sessions', array('id'=> $sessionid) )) {
52 error('No such session in this course');
54 $dhours = floor($sess->duration
/ HOURSECS
);
55 $dmins = floor(($sess->duration
- $dhours * HOURSECS
) / MINSECS
);
56 $defopts = array('maxfiles'=>EDITOR_UNLIMITED_FILES
, 'noclean'=>true
, 'context'=>$modcontext);
57 $sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attendance', 'session', $sess->id
);
58 $data = array('sessiondate' => $sess->sessdate
,
59 'durtime' => array('hours' => $dhours, 'minutes' => $dmins),
60 'sdescription' => $sess->description_editor
);
62 $mform->addElement('header', 'general', get_string('changesession', 'attendance'));
64 $mform->addElement('static', 'olddate', get_string('olddate', 'attendance'),
65 userdate($sess->sessdate
, get_string('strftimedmyhm', 'attendance')));
66 $mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', 'attendance'));
68 for ($i=0; $i<=23; $i++
) {
69 $hours[$i] = sprintf("%02d", $i);
71 for ($i=0; $i<60; $i+
=5) {
72 $minutes[$i] = sprintf("%02d", $i);
74 $durselect[] =& $mform->createElement('select', 'hours', '', $hours);
75 $durselect[] =& $mform->createElement('select', 'minutes', '', $minutes, false
, true
);
76 $mform->addGroup($durselect, 'durtime', get_string('duration', 'attendance'), array(' '), true
);
78 $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), null
, $defopts);
79 $mform->setType('sdescription', PARAM_RAW
);
81 $mform->setDefaults($data);
83 $submit_string = get_string('update', 'attendance');
84 $this->add_action_buttons(true
, $submit_string);