-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.php
121 lines (112 loc) · 4.65 KB
/
database.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Interacts with the database to save/reset font size settings (1)
*
* This file handles all the blocks database interaction. If saving,
* it will check if the current user already has a saved setting, and
* create/update it as appropriate. If resetting, it will delete the
* user's setting from the database. If responding to AJAX, it responds
* with suitable HTTP error codes. Otherwise, it sets a message to
* display, and redirects the user back to where they came from. (2)
*
* @package block_accessibility (3)
* @copyright 2009 © Taunton's College (4)
* @author Mark Johnson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5)
*/
require_once('../../config.php');
require_once($CFG->dirroot . '/blocks/accessibility/lib.php');
require_login();
$op = required_param('op', PARAM_TEXT);
$size = optional_param('size', false, PARAM_BOOL);
$scheme = optional_param('scheme', false, PARAM_BOOL);
$atbar = optional_param('atbar', false, PARAM_BOOL);
if (!accessibility_is_ajax()) {
$redirect = required_param('redirect', PARAM_TEXT);
$redirecturl = safe_redirect_url($redirect);
}
switch ($op) {
case 'save':
if ($setting = $DB->get_record('block_accessibility', array('userid' => $USER->id))) {
// Check if the user's already got a saved setting. If they have, just update it.
if ($size && isset($USER->fontsize)) {
$setting->fontsize = $USER->fontsize;
}
if ($scheme && isset($USER->colourscheme)) {
$setting->colourscheme = $USER->colourscheme;
}
if ($atbar) {
$setting->autoload_atbar = 1;
}
$DB->update_record('block_accessibility', $setting);
} else {
$setting = new stdClass;
// Otherwise, create a new record for them.
if ($size && isset($USER->fontsize)) {
$setting->fontsize = $USER->fontsize;
}
if ($scheme && isset($USER->colourscheme)) {
$setting->colourscheme = $USER->colourscheme;
}
if ($atbar) {
$setting->autoload_atbar = 1;
}
$setting->userid = $USER->id;
$DB->insert_record('block_accessibility', $setting);
}
if (!accessibility_is_ajax()) {
// If not responding to AJAX, set a message to display and redirect.
$USER->accessabilitymsg = get_string('saved', 'block_accessibility');
redirect($redirecturl);
}
break;
case 'reset':
if ($setting = $DB->get_record('block_accessibility', array('userid' => $USER->id))) {
// If they've got a record, delete it and redirect the user if appropriate.
if ($size) {
$setting->fontsize = null;
} else {
if (!empty($USER->fontsize)) {
$setting->fontsize = $USER->fontsize;
}
}
if ($scheme) {
$setting->colourscheme = null;
} else {
if (!empty($USER->colourscheme)) {
$setting->colourscheme = $USER->colourscheme;
}
}
if ($atbar) {
$setting->autoload_atbar = 0;
}
if (empty($setting->fontsize) && empty($setting->colourscheme) && empty($setting->atbar)) {
$DB->delete_records('block_accessibility', array('userid' => $USER->id));
} else {
$DB->update_record('block_accessibility', $setting);
}
if (!accessibility_is_ajax()) {
$USER->accessabilitymsg = get_string('reset', 'block_accessibility');
}
}
if (!accessibility_is_ajax()) {
redirect($redirecturl);
}
break;
default:
header("HTTP/1.0 400 Bad Request");
}