b5c8c2568baa1ba60d850aea46868e186a1dece8
[moodle.git] / theme / index.php
1 <?PHP // $Id$
3     require_once("../config.php");
5     optional_variable($preview);   // which theme to show
6     optional_variable($choose);    // 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) {
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) {
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");
72     echo "<table align=\"center\" cellpadding=\"7\" cellspacing=\"5\">";
73     echo "<tr><th class=\"generaltableheader\">$strtheme<th class=\"generaltableheader\">&nbsp;</tr>";
74     foreach ($themes as $theme) {
76         if (!file_exists("$CFG->dirroot/theme/$theme/config.php")) {   // bad folder
77             continue;
78         }
79         include ("$CFG->dirroot/theme/$theme/config.php");
81         echo "<tr>";
82         if ($CFG->theme == $theme) {
83             echo "<td align=\"center\" bgcolor=\"$THEME->body\">$theme</td>";
84             echo "<td align=\"center\"><a href=\"index.php?choose=$theme\">$strsavechanges</a></td>";
85         } else {
86             echo "<td align=\"center\" bgcolor=\"$THEME->body\">";
87             echo "<a title=\"$strpreview\" href=\"index.php?preview=$theme\">$theme</a>";
88             echo "</td>";
89             echo "<td>&nbsp;</td>";
90         }
91         echo "</tr>";
92     }
93     echo "</table>";
95     echo "<br /><div align=\"center\">";
96     $options["frame"] = "developer.html";
97     $options["sub"] = "themes";
98     print_single_button("$CFG->wwwroot/doc/index.php", $options, get_string("howtomakethemes"));
99     echo "</div>";
100     print_footer();
102 ?>