update README
[moodle-mod_attendance.git] / update_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 /**
18 * Update form
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
26 require_once($CFG->libdir.'/formslib.php');
27
28 /**
29 * class for displaying update form.
30 *
31 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 */
34 class mod_attendance_update_form extends moodleform {
35
36 /**
37 * Called to define this moodle form
38 *
39 * @return void
40 */
41 public function definition() {
42
43 global $DB;
44 $mform =& $this->_form;
45
46 $course = $this->_customdata['course'];
47 $cm = $this->_customdata['cm'];
48 $modcontext = $this->_customdata['modcontext'];
49 $sessionid = $this->_customdata['sessionid'];
50
51 if (!$sess = $DB->get_record('attendance_sessions', array('id'=> $sessionid) )) {
52 error('No such session in this course');
53 }
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);
61
62 $mform->addElement('header', 'general', get_string('changesession', 'attendance'));
63
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'));
67
68 for ($i=0; $i<=23; $i++) {
69 $hours[$i] = sprintf("%02d", $i);
70 }
71 for ($i=0; $i<60; $i+=5) {
72 $minutes[$i] = sprintf("%02d", $i);
73 }
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);
77
78 $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), null, $defopts);
79 $mform->setType('sdescription', PARAM_RAW);
80
81 $mform->setDefaults($data);
82
83 $submit_string = get_string('update', 'attendance');
84 $this->add_action_buttons(true, $submit_string);
85 }
86 }