]> git.mjollnir.org Git - moodle.git/commitdiff
New theme chooser (with better preview using iframes)
authormoodler <moodler>
Sun, 30 Jan 2005 19:27:46 +0000 (19:27 +0000)
committermoodler <moodler>
Sun, 30 Jan 2005 19:27:46 +0000 (19:27 +0000)
It's a bit rough but it works.

theme/index.php
theme/preview.php [new file with mode: 0644]

index 03fd1b60144d058a4fa9d8dee7ddfe2d2a34e2b9..e81c9fda1b818e09d86acc5cd3547ca5b5d0befe 100644 (file)
@@ -2,7 +2,6 @@
 
     require_once("../config.php");
 
-    $preview = optional_param("preview",'',PARAM_FILE); // which theme to show
     $choose = optional_param("choose",'',PARAM_FILE);   // set this theme as default
 
     if (! $site = get_site()) {
         error("You must be an administrator to change themes.");
     }
 
-    if ($choose) {
-        if (!is_dir($choose)) {
-            error("This theme is not installed!");
-        }
-        $preview = $choose;
-    }
-
-    if ($preview and confirm_sesskey()) {
-        $CFG->theme = $preview;
-        $CFG->stylesheet  = "$CFG->wwwroot/theme/$CFG->theme/styles.php?themename=$preview";
-        $CFG->header      = "$CFG->dirroot/theme/$CFG->theme/header.html";
-        $CFG->footer      = "$CFG->dirroot/theme/$CFG->theme/footer.html";
-        include ("$CFG->theme/config.php");
-    }
+    unset($SESSION->theme);
 
     $stradministration = get_string("administration");
     $strconfiguration = get_string("configuration");
     $strthemes = get_string("themes");
     $strpreview = get_string("preview");
-    $strsavechanges = get_string("savechanges");
+    $strchoose = get_string("choose");
+    $strinfo = get_string("info");
     $strtheme = get_string("theme");
     $strthemesaved = get_string("themesaved");
 
-    print_header("$site->shortname: $strthemes", $site->fullname, 
-                 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> ".
-                 "<a href=\"$CFG->wwwroot/$CFG->admin/configure.php\">$strconfiguration</a> -> $strthemes");
 
     if ($choose and confirm_sesskey()) {
+        if (!is_dir($choose)) {
+            error("This theme is not installed!");
+        }
         if (set_config("theme", $choose)) {
+            print_header("$site->shortname: $strthemes", $site->fullname, 
+                 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> ".
+                 "<a href=\"$CFG->wwwroot/$CFG->admin/configure.php\">$strconfiguration</a> -> $strthemes");
             print_heading(get_string("themesaved"));
             print_continue("$CFG->wwwroot/");
 
         }
     }
 
-    print_heading(get_string("previeworchoose"));
+    print_header("$site->shortname: $strthemes", $site->fullname, 
+                 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> ".
+                 "<a href=\"$CFG->wwwroot/$CFG->admin/configure.php\">$strconfiguration</a> -> $strthemes");
+
+
+    print_heading($strthemes);
 
     $themes = get_list_of_plugins("theme");
     $sesskey = !empty($USER->id) ? $USER->sesskey : '';
 
     echo "<table align=\"center\" cellpadding=\"7\" cellspacing=\"5\">";
-    echo "<tr><th class=\"generaltableheader\">$strtheme<th class=\"generaltableheader\">&nbsp;</tr>";
+    echo "<tr class=\"generaltableheader\"><th>$strtheme</th><th>$strinfo</th></tr>";
     foreach ($themes as $theme) {
 
         if (!file_exists("$CFG->dirroot/theme/$theme/config.php")) {   // bad folder
             continue;
         }
-        include ("$CFG->dirroot/theme/$theme/config.php");
 
         echo "<tr>";
+        echo "<td align=\"center\"><iframe name=\"$theme\" src=\"preview.php?preview=$theme\" height=\"150\" width=\"500\"></iframe></td>";
+
         if ($CFG->theme == $theme) {
-            echo "<td align=\"center\" bgcolor=\"$THEME->body\">$theme</td>";
-            echo "<td align=\"center\"><a href=\"index.php?choose=$theme&amp;sesskey=$sesskey\">$strsavechanges</a></td>";
+            echo '<td valign="top" style="border-style:solid; border-width:2px; border-color=#000000">';
         } else {
-            echo "<td align=\"center\" bgcolor=\"$THEME->body\">";
-            echo "<a title=\"$strpreview\" href=\"index.php?preview=$theme&amp;sesskey=$sesskey\">$theme</a>";
-            echo "</td>";
-            echo "<td>&nbsp;</td>";
+            echo '<td valign="top">';
+        }
+        echo "<h4>$theme</h4>";
+        echo "<p><a target=\"$theme\" href=\"preview.php?preview=$theme\">$strpreview</a></p>";
+
+        if (file_exists("$theme/README.html")) {
+            link_to_popup_window('/theme/'.$theme.'/README.html', $theme, $strinfo);
+        } else if (file_exists("$theme/README.txt")) {
+            link_to_popup_window('/theme/'.$theme.'/README.txt', $theme, $strinfo);
+        }
+        if ($CFG->theme != $theme) {
+            echo "<p><a href=\"index.php?choose=$theme&amp;sesskey=$sesskey\">$strchoose</a></p>";
         }
+        echo '</td>';
         echo "</tr>";
     }
     echo "</table>";
diff --git a/theme/preview.php b/theme/preview.php
new file mode 100644 (file)
index 0000000..08b7bd1
--- /dev/null
@@ -0,0 +1,42 @@
+<?php // $Id$
+
+    require_once("../config.php");
+
+    $preview = optional_param('preview','standard',PARAM_FILE); // which theme to show
+
+    if (!file_exists($preview)) {
+        $preview = 'standard';
+    }
+
+    if (! $site = get_site()) {
+        error("Site doesn't exist!");
+    }
+
+    require_login();
+
+    if (!isadmin()) {
+        error("You must be an administrator to change themes.");
+    }
+
+    $CFG->theme       = $preview;
+    $CFG->header      = "$CFG->dirroot/theme/$CFG->theme/header.html";
+    $CFG->footer      = "$CFG->dirroot/theme/$CFG->theme/footer.html";
+
+    print_header();
+    $stradministration = get_string("administration");
+    $strconfiguration = get_string("configuration");
+    $strthemes = get_string("themes");
+    $strpreview = get_string("preview");
+    $strsavechanges = get_string("savechanges");
+    $strtheme = get_string("theme");
+    $strthemesaved = get_string("themesaved");
+
+    print_header("$site->shortname: $strpreview", $site->fullname, "$strthemes -> $strpreview");
+
+    print_simple_box_start('center', '80%');
+    print_heading($preview);
+    print_simple_box_end();
+
+    print_footer();
+
+?>