rating MDL-21657 removed old per module rating implementations
[moodle.git] / theme / index.php
CommitLineData
b7009474 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * This page prvides the Administration -> ... -> Theme selector UI.
20 */
21
22require_once(dirname(__FILE__) . '/../config.php');
23require_once($CFG->libdir . '/adminlib.php');
24
78946b9b 25$choose = optional_param('choose', '', PARAM_SAFEDIR);
ee8df661 26$chooselegacy = optional_param('chooselegacy', '', PARAM_SAFEDIR);
78946b9b 27$reset = optional_param('reset', 0, PARAM_BOOL);
b7009474 28
29admin_externalpage_setup('themeselector');
30
31unset($SESSION->theme);
32
78946b9b
PS
33if ($reset and confirm_sesskey()) {
34 theme_reset_all_caches();
35
ee8df661 36} else if (($choose || $chooselegacy) && confirm_sesskey()) {
b7009474 37
ee8df661
SH
38 if ($choose) {
39 $chosentheme = $choose;
40 $heading = get_string('themesaved');
41 $config = 'theme';
42 } else {
43 $chosentheme = $chooselegacy;
44 $heading = get_string('legacythemesaved');
45 $config = 'themelegacy';
46 }
47 $theme = theme_config::load($chosentheme);
48 set_config($config, $theme->name);
8ba55c01 49
61ef8f9f 50 echo $OUTPUT->header();
ee8df661 51 echo $OUTPUT->heading($heading);
78946b9b 52 echo $OUTPUT->box_start();
ee8df661 53 echo format_text(get_string('choosereadme', 'theme_'.$CFG->theme), FORMAT_MOODLE);
78946b9b 54 echo $OUTPUT->box_end();
362874da 55 echo $OUTPUT->continue_button($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
344ca4c9 56 echo $OUTPUT->footer();
b7009474 57 exit;
58}
59
60// Otherwise, show a list of themes.
61ef8f9f 61echo $OUTPUT->header('themeselector');
cdc62220 62echo $OUTPUT->heading(get_string('themes'));
b7009474 63
5c2ed7e2 64echo $OUTPUT->single_button(new moodle_url('index.php', array('sesskey'=>sesskey(),'reset'=>1)), get_string('themeresetcaches', 'admin'));
78946b9b 65
fd09397e 66$table = new html_table();
b7009474 67$table->id = 'adminthemeselector';
68$table->head = array(get_string('theme'), get_string('info'));
69
70$themes = get_plugin_list('theme');
78946b9b 71
b7009474 72foreach ($themes as $themename => $themedir) {
9c9cbe76
MD
73
74 // Skip the base theme unless we are in theme designer mode (they might want to look at it)
75 if (!$CFG->themedesignermode && $themename == 'base') {
76 continue;
77 }
b7009474 78
79 // Load the theme config.
80 try {
81 $theme = theme_config::load($themename);
78946b9b 82 } catch (Exception $e) {
b7009474 83 // Bad theme, just skip it for now.
84 continue;
60a9a6ea 85 }
78946b9b
PS
86 if ($themename !== $theme->name) {
87 //obsoleted or broken theme, just skip for now
88 continue;
89 }
74df4357 90
b7009474 91 // Build the table row, and also a list of items to go in the second cell.
92 $row = array();
93 $infoitems = array();
ee8df661 94 $rowclasses = array();
b7009474 95
ee8df661
SH
96 // Set up bools whether this theme is chosen either main or legacy
97 $ischosentheme = ($themename == $CFG->theme);
98 $ischosenlegacytheme = (!empty($CFG->themelegacy) && $themename == $CFG->themelegacy);
b7009474 99
ee8df661
SH
100 if ($ischosentheme) {
101 // Is the chosen main theme
102 $rowclasses[] = 'selectedtheme';
103 }
104 if ($ischosenlegacytheme) {
105 // Is the chosen legacy theme
106 $rowclasses[] = 'selectedlegacytheme';
107 }
0d399dc5 108
ee8df661
SH
109 // link to the screenshot, now mandatory - the image path is hardcoded because we need image from other themes, not the current one
110 $screenshotpath = new moodle_url('/theme/image.php', array('theme'=>$themename, 'image'=>'screenshot','component'=>'theme'));
b7009474 111 // Contents of the first screenshot/preview cell.
ee8df661 112 $row[] = html_writer::empty_tag('img', array('src'=>$screenshotpath, 'alt'=>$themename));
b7009474 113
114 // Contents of the second cell.
115 $infocell = $OUTPUT->heading($themename, 3);
ebb19aba 116
ee8df661
SH
117 // Button to choose this as the main theme
118 $maintheme = new single_button(new moodle_url('/theme/index.php', array('choose' => $themename, 'sesskey' => sesskey())), get_string('useformaintheme'), 'get');
119 $maintheme->disabled = $ischosentheme;
120 $infocell .= $OUTPUT->render($maintheme);
b7009474 121
ee8df661
SH
122 // Button to choose this as the legacy theme
123 $legacytheme = new single_button(new moodle_url('/theme/index.php', array('chooselegacy' => $themename, 'sesskey' => sesskey())), get_string('useforlegacytheme'), 'get');
124 $legacytheme->disabled = $ischosenlegacytheme;
125 $infocell .= $OUTPUT->render($legacytheme);
126
127 $row[] = $infocell;
128
b7009474 129 $table->data[$themename] = $row;
ee8df661 130 $table->rowclasses[$themename] = join(' ', $rowclasses);
b7009474 131}
132
16be8974 133echo html_writer::table($table);
b7009474 134
ee8df661 135echo $OUTPUT->footer();