lib-navigation MDL-21113 Fixed minor javascript error when positioning sidepanel...
[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
25$choose = optional_param('choose', '', PARAM_FILE);
26
27admin_externalpage_setup('themeselector');
28
29unset($SESSION->theme);
30
31if ($choose and confirm_sesskey()) {
32 // The user has chosen one theme from the list of all themes, show a
33 // 'You have chosen a new theme' confirmation page.
34
35 if (!is_dir($CFG->themedir .'/'. $choose)) {
36 print_error('themenotinstall');
0d399dc5 37 }
38
b7009474 39 set_config('theme', $choose);
8ba55c01 40
b7009474 41 admin_externalpage_print_header();
cdc62220 42 echo $OUTPUT->heading(get_string('themesaved'));
8ba55c01 43
b7009474 44 $readmehtml = $CFG->themedir . '/' . $choose . '/README.html';
45 $readmetxt = $CFG->themedir . '/' . $choose . '/README.txt';
46 if (is_readable($readmehtml)) {
ebb19aba 47 echo $OUTPUT->box_start();
b7009474 48 readfile($readmehtml);
ebb19aba 49 echo $OUTPUT->box_end();
0d399dc5 50
b7009474 51 } else if (is_readable($readmetxt)) {
ebb19aba 52 echo $OUTPUT->box_start();
b7009474 53 $text = file_get_contents($readmetxt);
54 echo format_text($text, FORMAT_MOODLE);
ebb19aba 55 echo $OUTPUT->box_end();
b7009474 56 }
0d399dc5 57
362874da 58 echo $OUTPUT->continue_button($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
33dfb53e 59
344ca4c9 60 echo $OUTPUT->footer();
b7009474 61 exit;
62}
63
64// Otherwise, show a list of themes.
65admin_externalpage_print_header('themeselector');
cdc62220 66echo $OUTPUT->heading(get_string('themes'));
b7009474 67
fd09397e 68$table = new html_table();
b7009474 69$table->id = 'adminthemeselector';
70$table->head = array(get_string('theme'), get_string('info'));
71
72$themes = get_plugin_list('theme');
73$sesskey = sesskey();
74foreach ($themes as $themename => $themedir) {
75
76 // Load the theme config.
77 try {
78 $theme = theme_config::load($themename);
79 } catch (coding_exception $e) {
80 // Bad theme, just skip it for now.
81 continue;
60a9a6ea 82 }
74df4357 83
b7009474 84 // Build the table row, and also a list of items to go in the second cell.
85 $row = array();
86 $infoitems = array();
87
88 // Preview link.
89 $infoitems['preview'] = '<a href="preview.php?preview=' . $themename . '">' . get_string('preview') . '</a>';
90
91 // First cell (a preview) and also a link to the screenshot, if there is one.
92 $screenshotpath = '';
93 if (file_exists($theme->dir . '/screenshot.png')) {
94 $screenshotpath = $themename . '/screenshot.png';
95 } else if (file_exists($theme->dir . '/screenshot.jpg')) {
96 $screenshotpath = $themename . '/screenshot.jpg';
97 }
98 if ($screenshotpath) {
99 $infoitems['screenshot'] = '<a href="' . $CFG->themewww .'/'. $screenshotpath . '">' .
100 get_string('screenshot') . '</a>';
0d399dc5 101 }
74df4357 102
b7009474 103 // Link to the themes's readme.
104 $readmeurl = '';
105 if (file_exists($theme->dir . '/README.html')) {
106 $readmeurl = $CFG->themewww .'/'. $themename .'/README.html';
107 } else if (file_exists($theme->dir . '/README.txt')) {
108 $readmeurl = $CFG->themewww .'/'. $themename .'/README.txt';
109 }
110 if ($readmeurl) {
5a142c82 111 $link = html_link::make($readmeurl, get_string('info'));
112 $link->add_action(new popup_action('click', $link->url, $themename));
aa6c1ced 113 $infoitems['readme'] = $OUTPUT->link($link);
b7009474 114 }
0d399dc5 115
b7009474 116 // Contents of the first screenshot/preview cell.
117 if ($screenshotpath) {
118 $row[] = '<object type="text/html" data="' . $CFG->themewww .'/' . $screenshotpath .
119 '" height="200" width="400">' . $themename . '</object>';
120 } else {
121 $row[] = '<object type="text/html" data="preview.php?preview=' . $themename .
122 '" height="200" width="400">' . $themename . '</object>';
123 }
124
125 // Contents of the second cell.
126 $infocell = $OUTPUT->heading($themename, 3);
127 if ($infoitems) {
128 $infocell .= "<ul>\n<li>" . implode("</li>\n<li>", $infoitems) . "</li>\n</ul>\n";
129 }
130 if ($themename != $CFG->theme) {
fd09397e 131 $infocell .= $OUTPUT->button(html_form::make_button('index.php', array('choose' => $themename, 'sesskey' => $sesskey),
132 get_string('choose'), 'get'));
ebb19aba 133
b7009474 134 }
135 $row[] = $infocell;
136
137 $table->data[$themename] = $row;
138 if ($themename == $CFG->theme) {
704ac344 139 $table->rowclasses[$themename] = 'selectedtheme';
b7009474 140 }
141}
142
fd09397e 143echo $OUTPUT->table($table);
b7009474 144
344ca4c9 145echo $OUTPUT->footer();
0d399dc5 146?>