Some checks added. SC#34.
[moodle.git] / theme / index.php
CommitLineData
14ed121a 1<?php // $Id$
0d399dc5 2
b0e3a925 3 require_once("../config.php");
0d399dc5 4
14ed121a 5 $preview = optional_param("preview",'',PARAM_FILE); // which theme to show
6 $choose = optional_param("choose",'',PARAM_FILE); // set this theme as default
0d399dc5 7
bbc0d9ab 8 if (! $site = get_site()) {
9 error("Site doesn't exist!");
10 }
11
12 require_login();
13
14 if (!isadmin()) {
15 error("You must be an administrator to change themes.");
16 }
17
0d399dc5 18 if ($choose) {
bbc0d9ab 19 if (!is_dir($choose)) {
20 error("This theme is not installed!");
21 }
0d399dc5 22 $preview = $choose;
23 }
24
14ed121a 25 if ($preview and confirm_sesskey()) {
0d399dc5 26 $CFG->theme = $preview;
8120317e 27 $CFG->stylesheet = "$CFG->wwwroot/theme/$CFG->theme/styles.php?themename=$preview";
0d399dc5 28 $CFG->header = "$CFG->dirroot/theme/$CFG->theme/header.html";
29 $CFG->footer = "$CFG->dirroot/theme/$CFG->theme/footer.html";
30 include ("$CFG->theme/config.php");
31 }
32
0d399dc5 33 $stradministration = get_string("administration");
2f4d324b 34 $strconfiguration = get_string("configuration");
75c64d92 35 $strthemes = get_string("themes");
0d399dc5 36 $strpreview = get_string("preview");
37 $strsavechanges = get_string("savechanges");
38 $strtheme = get_string("theme");
39 $strthemesaved = get_string("themesaved");
40
75c64d92 41 print_header("$site->shortname: $strthemes", $site->fullname,
2f4d324b 42 "<a href=\"$CFG->wwwroot/admin/index.php\">$stradministration</a> -> ".
43 "<a href=\"$CFG->wwwroot/admin/configure.php\">$strconfiguration</a> -> $strthemes");
0d399dc5 44
14ed121a 45 if ($choose and confirm_sesskey()) {
0d399dc5 46 if (set_config("theme", $choose)) {
47 print_heading(get_string("themesaved"));
bf04f911 48 print_continue("$CFG->wwwroot/");
0948ab26 49
50 if (file_exists("$choose/README.html")) {
51 print_simple_box_start("center");
52 readfile("$choose/README.html");
53 print_simple_box_end();
54
55 } else if (file_exists("$choose/README.txt")) {
f722b73c 56 print_simple_box_start("center");
57 $file = file("$choose/README.txt");
58 echo format_text(implode('', $file), FORMAT_MOODLE);
59 print_simple_box_end();
60 }
0d399dc5 61 print_footer();
62 exit;
63 } else {
64 error("Could not set the theme!");
65 }
66 }
67
68 print_heading(get_string("previeworchoose"));
69
70 $themes = get_list_of_plugins("theme");
14ed121a 71 $sesskey = !empty($USER->id) ? $USER->sesskey : '';
0d399dc5 72
9a58f7cb 73 echo "<table align=\"center\" cellpadding=\"7\" cellspacing=\"5\">";
74 echo "<tr><th class=\"generaltableheader\">$strtheme<th class=\"generaltableheader\">&nbsp;</tr>";
0d399dc5 75 foreach ($themes as $theme) {
9cccc2ef 76
77 if (!file_exists("$CFG->dirroot/theme/$theme/config.php")) { // bad folder
78 continue;
79 }
80 include ("$CFG->dirroot/theme/$theme/config.php");
81
9a58f7cb 82 echo "<tr>";
0d399dc5 83 if ($CFG->theme == $theme) {
9a58f7cb 84 echo "<td align=\"center\" bgcolor=\"$THEME->body\">$theme</td>";
14ed121a 85 echo "<td align=\"center\"><a href=\"index.php?choose=$theme&amp;sesskey=$sesskey\">$strsavechanges</a></td>";
0d399dc5 86 } else {
9a58f7cb 87 echo "<td align=\"center\" bgcolor=\"$THEME->body\">";
14ed121a 88 echo "<a title=\"$strpreview\" href=\"index.php?preview=$theme&amp;sesskey=$sesskey\">$theme</a>";
9a58f7cb 89 echo "</td>";
90 echo "<td>&nbsp;</td>";
0d399dc5 91 }
f722b73c 92 echo "</tr>";
0d399dc5 93 }
f722b73c 94 echo "</table>";
0d399dc5 95
9a58f7cb 96 echo "<br /><div align=\"center\">";
1b73ea57 97 $options["frame"] = "developer.html";
98 $options["sub"] = "themes";
99 print_single_button("$CFG->wwwroot/doc/index.php", $options, get_string("howtomakethemes"));
f722b73c 100 echo "</div>";
0d399dc5 101 print_footer();
102
103?>