MDL-19674 - err - slighly more sensible version of the previous commit.
[moodle.git] / theme / index.php
CommitLineData
14ed121a 1<?php // $Id$
0d399dc5 2
b0e3a925 3 require_once("../config.php");
6e4dc10f 4 require_once($CFG->libdir.'/adminlib.php');
0d399dc5 5
14ed121a 6 $choose = optional_param("choose",'',PARAM_FILE); // set this theme as default
0d399dc5 7
1ae083e4 8 admin_externalpage_setup('themeselector');
bbc0d9ab 9
8ba55c01 10 unset($SESSION->theme);
0d399dc5 11
0d399dc5 12 $stradministration = get_string("administration");
2f4d324b 13 $strconfiguration = get_string("configuration");
75c64d92 14 $strthemes = get_string("themes");
0d399dc5 15 $strpreview = get_string("preview");
8ba55c01 16 $strchoose = get_string("choose");
17 $strinfo = get_string("info");
0d399dc5 18 $strtheme = get_string("theme");
19 $strthemesaved = get_string("themesaved");
2d47c851 20 $strscreenshot = get_string("screenshot");
21 $stroldtheme = get_string("oldtheme");
0d399dc5 22
0d399dc5 23
14ed121a 24 if ($choose and confirm_sesskey()) {
a44091bf 25 if (!is_dir($CFG->themedir .'/'. $choose)) {
4f2a63c8 26 print_error('themenotinstall');
8ba55c01 27 }
0d399dc5 28 if (set_config("theme", $choose)) {
d65a6501 29 theme_setup($choose);
33dfb53e 30 admin_externalpage_print_header();
0d399dc5 31 print_heading(get_string("themesaved"));
0948ab26 32
33 if (file_exists("$choose/README.html")) {
f5bb6e2d 34 print_box_start();
0948ab26 35 readfile("$choose/README.html");
f5bb6e2d 36 print_box_end();
0948ab26 37
38 } else if (file_exists("$choose/README.txt")) {
f5bb6e2d 39 print_box_start("center");
f722b73c 40 $file = file("$choose/README.txt");
41 echo format_text(implode('', $file), FORMAT_MOODLE);
f5bb6e2d 42 print_box_end();
f722b73c 43 }
9f9bdaf8 44
45 print_continue("$CFG->wwwroot/");
46
33dfb53e 47 admin_externalpage_print_footer();
0d399dc5 48 exit;
49 } else {
4f2a63c8 50 print_error('cannotsettheme');
0d399dc5 51 }
52 }
53
60a9a6ea 54 admin_externalpage_print_header('themeselector');
8ba55c01 55
56
57 print_heading($strthemes);
0d399dc5 58
17da2e6f 59 $themes = get_plugin_list("theme");
973d2660 60 $sesskey = sesskey();
0d399dc5 61
74df4357 62 echo "<table style=\"margin-left:auto;margin-right:auto;\" cellpadding=\"7\" cellspacing=\"5\">\n";
33dfb53e 63
60a9a6ea 64 if (!$USER->screenreader) {
74df4357 65 echo "\t<tr class=\"generaltableheader\">\n\t\t<th scope=\"col\">$strtheme</th>\n";
66 echo "\t\t<th scope=\"col\">$strinfo</th>\n\t</tr>\n";
60a9a6ea 67 }
74df4357 68
69 $original_theme = fullclone($THEME);
70
17da2e6f 71 foreach ($themes as $theme => $themedir) {
9cccc2ef 72
2d47c851 73 unset($THEME);
74
17da2e6f 75 if (!file_exists($themedir.'/config.php')) { // bad folder
9cccc2ef 76 continue;
77 }
9cccc2ef 78
17da2e6f 79 include($themedir.'/config.php');
cc15a607 80
2d47c851 81 $readme = '';
82 $screenshot = '';
83 $screenshotpath = '';
84
85 if (file_exists("$theme/README.html")) {
74df4357 86 $readme = "\t\t\t\t<li>".
87 link_to_popup_window($CFG->themewww .'/'. $theme .'/README.html', $theme, $strinfo, 400, 500, '', 'none', true)."</li>\n";
2d47c851 88 } else if (file_exists("$theme/README.txt")) {
74df4357 89 $readme = "\t\t\t\t<li>".
90 link_to_popup_window($CFG->themewww .'/'. $theme .'/README.txt', $theme, $strinfo, 400, 500, '', 'none', true)."</li>\n";
2d47c851 91 }
92 if (file_exists("$theme/screenshot.png")) {
93 $screenshotpath = "$theme/screenshot.png";
94 } else if (file_exists("$theme/screenshot.jpg")) {
95 $screenshotpath = "$theme/screenshot.jpg";
96 }
97
74df4357 98 echo "\t<tr>\n";
33dfb53e 99
60a9a6ea 100 // no point showing this if user is using screen reader
101 if (!$USER->screenreader) {
74df4357 102 echo "\t\t<td align=\"center\">\n";
60a9a6ea 103 if ($screenshotpath) {
74df4357 104 $screenshot = "\t\t\t\t<li><a href=\"$theme/screenshot.jpg\">$strscreenshot</a></li>\n";
105 echo "\t\t\t<object type=\"text/html\" data=\"$screenshotpath\" height=\"200\" width=\"400\">$theme</object>\n\t\t</td>\n";
60a9a6ea 106 } else {
74df4357 107 echo "\t\t\t<object type=\"text/html\" data=\"preview.php?preview=$theme\" height=\"200\" width=\"400\">$theme</object>\n\t\t</td>\n";
60a9a6ea 108 }
2d47c851 109 }
110
0d399dc5 111 if ($CFG->theme == $theme) {
774b7e8e 112 echo "\t\t" . '<td valign="top" style="border-style:solid; border-width:1px; border-color:#555555">'."\n";
0d399dc5 113 } else {
74df4357 114 echo "\t\t" . '<td valign="top">'."\n";
8ba55c01 115 }
d19d6320 116
2d47c851 117 if (isset($THEME->sheets)) {
774b7e8e 118 echo "\t\t\t" . '<p style="font-size:1.5em;font-weight:bold;">'.$theme.'</p>'."\n";
2d47c851 119 } else {
774b7e8e 120 echo "\t\t\t" . '<p style="font-size:1.5em;font-weight:bold;color:red;">'.$theme.' (Moodle 1.4)</p>'."\n";
cc15a607 121 }
33dfb53e 122
2d47c851 123 if ($screenshot or $readme) {
74df4357 124 echo "\t\t\t<ul>\n";
60a9a6ea 125 if (!$USER->screenreader) {
74df4357 126 echo "\t\t\t\t<li><a href=\"preview.php?preview=$theme\">$strpreview</a></li>\n";
60a9a6ea 127 }
128 echo $screenshot.$readme;
74df4357 129 echo "\t\t\t</ul>\n";
0d399dc5 130 }
2d47c851 131
9eb64c94 132 $options = null;
2d47c851 133 $options['choose'] = $theme;
134 $options['sesskey'] = $sesskey;
74df4357 135 echo "\t\t\t" . print_single_button('index.php', $options, $strchoose, 'get', null, true) . "\n";
136 echo "\t\t</td>\n";
137 echo "\t</tr>\n";
0d399dc5 138 }
74df4357 139 echo "</table>\n";
140
141 $THEME = $original_theme;
0d399dc5 142
1ae083e4 143 admin_externalpage_print_footer();
0d399dc5 144?>