MDL-56092 auth_email: New WS auth_email_get_signup_settings
[moodle.git] / theme / index.php
blob25dda1ae2cc9374ebe76761fc24d50f5048da124
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.
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/>.
17 /**
18 * This page provides the Administration -> ... -> Theme selector UI.
20 * @package core
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 require_once(__DIR__ . '/../config.php');
25 require_once($CFG->libdir . '/adminlib.php');
27 $choose = optional_param('choose', '', PARAM_PLUGIN);
28 $reset = optional_param('reset', 0, PARAM_BOOL);
29 $device = optional_param('device', '', PARAM_TEXT);
30 $unsettheme = optional_param('unsettheme', 0, PARAM_BOOL);
31 $confirmation = optional_param('confirmation', 0, PARAM_BOOL);
33 admin_externalpage_setup('themeselector');
35 if (!empty($device)) {
36 // Make sure the device requested is valid.
37 $devices = core_useragent::get_device_type_list();
38 if (!in_array($device, $devices)) {
39 // The provided device isn't a valid device throw an error.
40 print_error('invaliddevicetype');
44 unset($SESSION->theme);
46 if ($reset and confirm_sesskey()) {
47 theme_reset_all_caches();
48 } else if ($choose && $confirmation) {
50 $theme = theme_config::load($choose);
51 echo $OUTPUT->header();
52 echo $OUTPUT->heading(get_string('themesaved'));
53 echo $OUTPUT->box_start();
54 echo format_text(get_string('choosereadme', 'theme_'.$theme->name), FORMAT_MOODLE);
55 echo $OUTPUT->box_end();
56 echo $OUTPUT->continue_button($CFG->wwwroot . '/theme/index.php');
57 echo $OUTPUT->footer();
58 exit;
60 } else if ($choose && $device && !theme_is_device_locked($device) && !$unsettheme && confirm_sesskey()) {
61 // Load the theme to make sure it is valid.
62 $theme = theme_config::load($choose);
64 // Get the config argument for the chosen device.
65 $themename = core_useragent::get_device_type_cfg_var_name($device);
66 set_config($themename, $theme->name);
68 $urlconfirm = new moodle_url('/theme/index.php', array('confirmation' => 1, 'choose' => $choose));
69 redirect($urlconfirm);
70 } else if ($device && !theme_is_device_locked($device) && $unsettheme && confirm_sesskey() && ($device != 'default')) {
71 // Unset the theme and continue.
72 unset_config(core_useragent::get_device_type_cfg_var_name($device));
73 $device = '';
76 // Otherwise, show either a list of devices, or is enabledevicedetection set to no or a
77 // device is specified show a list of themes.
79 $table = new html_table();
80 $table->data = array();
81 $heading = '';
82 if (!empty($CFG->enabledevicedetection) && empty($device)) {
83 $heading = get_string('selectdevice', 'admin');
84 // Display a list of devices that a user can select a theme for.
86 $strthemenotselected = get_string('themenoselected', 'admin');
87 $strthemeselect = get_string('themeselect', 'admin');
89 // Display the device selection screen.
90 $table->id = 'admindeviceselector';
91 $table->head = array(get_string('devicetype', 'admin'), get_string('currenttheme', 'admin'), get_string('info'));
93 $devices = core_useragent::get_device_type_list();
94 foreach ($devices as $thedevice) {
96 $headingthemename = ''; // To output the picked theme name when needed.
97 $themename = core_useragent::get_device_type_theme($thedevice);
98 if (!$themename && $thedevice == 'default') {
99 $themename = theme_config::DEFAULT_THEME;
101 $themelocked = theme_is_device_locked($thedevice);
103 $screenshotcell = $strthemenotselected;
104 $unsetthemebutton = '';
105 if ($themename) {
106 // Check the theme exists.
107 $themename = clean_param($themename, PARAM_THEME);
108 if (empty($themename)) {
109 // Likely the theme has been deleted.
110 unset_config(core_useragent::get_device_type_cfg_var_name($thedevice));
111 } else {
112 $strthemename = get_string('pluginname', 'theme_'.$themename);
113 // Link to the screenshot, now mandatory - the image path is hardcoded because we need image from other themes,
114 // not the current one.
115 $screenshoturl = new moodle_url('/theme/image.php',
116 array('theme' => $themename, 'image' => 'screenshot', 'component' => 'theme'));
117 // Contents of the screenshot/preview cell.
118 $screenshotcell = html_writer::empty_tag('img', array('src' => $screenshoturl, 'alt' => $strthemename));
119 // Show the name of the picked theme.
120 $headingthemename = $OUTPUT->heading($strthemename, 3);
122 // If not default device then show option to unset theme.
123 if ($thedevice != 'default' && !$themelocked) {
124 $unsetthemestr = get_string('unsettheme', 'admin');
125 $unsetthemeurl = new moodle_url('/theme/index.php',
126 array('device' => $thedevice, 'sesskey' => sesskey(), 'unsettheme' => true));
127 $unsetthemebutton = new single_button($unsetthemeurl, $unsetthemestr, 'get');
128 $unsetthemebutton = $OUTPUT->render($unsetthemebutton);
132 $deviceurl = new moodle_url('/theme/index.php', array('device' => $thedevice, 'sesskey' => sesskey()));
134 $select = '';
135 if (!$themelocked) {
136 $select = $OUTPUT->render(new single_button($deviceurl, $strthemeselect, 'get'));
139 $lockwarning = '';
140 if ($themelocked) {
141 $lockwarning = html_writer::div(get_string('configoverride', 'admin'), 'alert alert-info');
144 $table->data[] = array(
145 $OUTPUT->heading(ucfirst($thedevice), 3),
146 $screenshotcell,
147 $headingthemename . $lockwarning . $select . $unsetthemebutton
150 } else {
151 // Either a device has been selected of $CFG->enabledevicedetection is off so display a list
152 // of themes to select.
153 $heading = get_string('selecttheme', 'admin', $device);
154 if (empty($device)) {
155 // If $CFG->enabledevicedetection is off this will return 'default'.
156 $device = core_useragent::get_device_type();
159 $themelocked = theme_is_device_locked($device);
160 $table->id = 'adminthemeselector';
161 $table->head = array(get_string('theme'), get_string('info'));
163 $themes = array();
164 if ($themelocked) {
165 $heading = get_string('currenttheme', 'admin');
166 $themename = theme_get_locked_theme_for_device($device);
167 $themedirectory = core_component::get_plugin_directory('theme', $themename);
168 $themes[$themename] = $themedirectory;
169 } else {
170 $themes = core_component::get_plugin_list('theme');
173 foreach ($themes as $themename => $themedir) {
175 // Load the theme config.
176 try {
177 $theme = theme_config::load($themename);
178 } catch (Exception $e) {
179 // Bad theme, just skip it for now.
180 continue;
182 if ($themename !== $theme->name) {
183 // Obsoleted or broken theme, just skip for now.
184 continue;
186 if (empty($CFG->themedesignermode) && $theme->hidefromselector) {
187 // The theme doesn't want to be shown in the theme selector and as theme
188 // designer mode is switched off we will respect that decision.
189 continue;
191 $strthemename = get_string('pluginname', 'theme_'.$themename);
193 // Build the table row, and also a list of items to go in the second cell.
194 $row = array();
195 $infoitems = array();
196 $rowclasses = array();
198 // Set up bools whether this theme is chosen either main or legacy.
199 $ischosentheme = ($themename == core_useragent::get_device_type_theme($device));
201 if ($ischosentheme) {
202 // Is the chosen main theme.
203 $rowclasses[] = 'selectedtheme';
206 // Link to the screenshot, now mandatory - the image path is hardcoded because we need image from other themes,
207 // not the current one.
208 $screenshotpath = new moodle_url('/theme/image.php',
209 array('theme'=>$themename, 'image'=>'screenshot', 'component'=>'theme'));
210 // Contents of the first screenshot/preview cell.
211 $row[] = html_writer::empty_tag('img', array('src'=>$screenshotpath, 'alt'=>$strthemename));
212 // Contents of the second cell.
213 $infocell = $OUTPUT->heading($strthemename, 3);
215 if ($themelocked) {
216 $infocell .= html_writer::div(get_string('configoverride', 'admin'), 'alert alert-info');
219 // Button to choose this as the main theme or unset this theme for devices other then default.
220 if (!$themelocked) {
221 if (($ischosentheme) && ($device != 'default')) {
222 $unsetthemestr = get_string('unsettheme', 'admin');
223 $unsetthemeurl = new moodle_url('/theme/index.php',
224 array('device' => $device, 'unsettheme' => true, 'sesskey' => sesskey()));
225 $unsetbutton = new single_button($unsetthemeurl, $unsetthemestr, 'get');
226 $infocell .= $OUTPUT->render($unsetbutton);
227 } else if ((!$ischosentheme)) {
228 $setthemestr = get_string('usetheme');
229 $setthemeurl = new moodle_url('/theme/index.php',
230 array('device' => $device, 'choose' => $themename, 'sesskey' => sesskey()));
231 $setthemebutton = new single_button($setthemeurl, $setthemestr, 'get');
232 $infocell .= $OUTPUT->render($setthemebutton);
236 $row[] = $infocell;
238 $table->data[$themename] = $row;
239 $table->rowclasses[$themename] = join(' ', $rowclasses);
242 echo $OUTPUT->header('themeselector');
243 echo $OUTPUT->heading($heading);
245 $params = array('sesskey' => sesskey(), 'reset' => 1);
246 if (!empty($device)) {
247 $params['device'] = $device;
249 echo $OUTPUT->single_button(new moodle_url('index.php', $params), get_string('themeresetcaches', 'admin'));
251 echo html_writer::table($table);
253 echo $OUTPUT->footer();