update README
[moodle-mod_attendance.git] / preferences.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 settings
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 att_preferences_page_params();
29
30 $id = required_param('id', PARAM_INT);
31 $pageparams->action = optional_param('action', null, PARAM_INT);
32 $pageparams->statusid = optional_param('statusid', null, PARAM_INT);
33
34 $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
35 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
36 $att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
37
38 require_login($course, true, $cm);
39
40 $att = new attendance($att, $cm, $course, $PAGE->context, $pageparams);
41
42 $att->perm->require_change_preferences_capability();
43
44 $PAGE->set_url($att->url_preferences());
45 $PAGE->set_title($course->shortname. ": ".$att->name.' - '.get_string('settings', 'attendance'));
46 $PAGE->set_heading($course->fullname);
47 $PAGE->set_cacheable(true);
48 $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
49 $PAGE->navbar->add(get_string('settings', 'attendance'));
50
51 switch ($att->pageparams->action) {
52 case att_preferences_page_params::ACTION_ADD:
53 $newacronym = optional_param('newacronym', null, PARAM_TEXT);
54 $newdescription = optional_param('newdescription', null, PARAM_TEXT);
55 $newgrade = optional_param('newgrade', 0, PARAM_INT);
56
57 $att->add_status($newacronym, $newdescription, $newgrade);
58 break;
59 case att_preferences_page_params::ACTION_DELETE:
60 if (att_has_logs_for_status($att->pageparams->statusid)) {
61 print_error('cantdeletestatus', 'attendance', "attsettings.php?id=$id");
62 }
63
64 $confirm = optional_param('confirm', null, PARAM_INT);
65 if (isset($confirm)) {
66 $att->remove_status($att->pageparams->statusid);
67 redirect($att->url_preferences(), get_string('statusdeleted', 'attendance'));
68 }
69
70 $statuses = $att->get_statuses();
71 $status = $statuses[$att->pageparams->statusid];
72 $message = get_string('deletecheckfull', '', get_string('variable', 'attendance'));
73 $message .= str_repeat(html_writer::empty_tag('br'), 2);
74 $message .= $status->acronym.': '.
75 ($status->description ? $status->description : get_string('nodescription', 'attendance'));
76 $params = array_merge($att->pageparams->get_significant_params(), array('confirm' => 1));
77 echo $OUTPUT->header();
78 echo $OUTPUT->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
79 echo $OUTPUT->confirm($message, $att->url_preferences($params), $att->url_preferences());
80 echo $OUTPUT->footer();
81 exit;
82 case att_preferences_page_params::ACTION_HIDE:
83 $att->update_status($att->pageparams->statusid, null, null, null, 0);
84 break;
85 case att_preferences_page_params::ACTION_SHOW:
86 $att->update_status($att->pageparams->statusid, null, null, null, 1);
87 break;
88 case att_preferences_page_params::ACTION_SAVE:
89 $acronym = required_param_array('acronym', PARAM_MULTILANG);
90 $description = required_param_array('description', PARAM_MULTILANG);
91 $grade = required_param_array('grade', PARAM_INT);
92
93 foreach ($acronym as $id => $v) {
94 $att->update_status($id, $acronym[$id], $description[$id], $grade[$id], null);
95 }
96 if ($att->grade > 0) {
97 att_update_all_users_grades($att->id, $att->course, $att->context, $cm);
98 }
99 break;
100 }
101
102 $output = $PAGE->get_renderer('mod_attendance');
103 $tabs = new attendance_tabs($att, attendance_tabs::TAB_PREFERENCES);
104 $prefdata = new attendance_preferences_data($att);
105
106 // Output starts here.
107
108 echo $output->header();
109 echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .$course->fullname);
110 echo $output->render($tabs);
111 echo $output->render($prefdata);
112
113 echo $output->footer();