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