diff --git a/lib/weblib.php b/lib/weblib.php
index f351fcb5760..76429b2be7a 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -1490,7 +1490,7 @@ function highlightfast($needle, $haystack) {
function print_header ($title='', $heading='', $navigation='', $focus='', $meta='',
$cache=true, $button=' ', $menu='', $usexml=false, $bodytags='') {
- global $USER, $CFG, $SESSION, $ME;
+ global $USER, $CFG, $THEME, $SESSION, $ME;
/// This is an ugly hack to be replaced later by a proper global $COURSE
global $course;
@@ -1498,14 +1498,22 @@ function print_header ($title='', $heading='', $navigation='', $focus='', $meta=
$CFG->courselang = $course->lang;
}
-/// Set up all our style sheets
- if ($CFG->theme != 'standard') { // Always include the standard stylesheet
- $meta = "\n".'';
+/// Add the required stylesheets
+ $stylesheets = '';
+ $theme = current_theme();
+ if ($theme != 'standard') { /// The standard sheet is always loaded first
+ $stylesheets .= ''."\n";
}
- $meta .= "\n".'';
+ if (!empty($THEME->parent)) { /// Parent stylesheets are loaded next
+ $stylesheets .= ''."\n";
+ }
+ $stylesheets .= ''."\n";
+
+ $meta = $stylesheets.$meta;
- // Add a stylesheet for the HTML editor
- $meta = "\n".''."\n$meta\n";
if ($navigation == 'home') {
$home = true;
@@ -1736,6 +1744,34 @@ function print_footer($course=NULL, $usercourse=NULL) {
include ($CFG->dirroot.'/theme/'.$CFG->theme.'/footer.html');
}
+/**
+ * Returns the name of the current theme
+ *
+ * @uses $CFG
+ * @param $USER
+ * @param $SESSION
+ * @return string
+ */
+function current_theme() {
+ global $CFG, $USER, $SESSION;
+
+/// Logic for this will probably change to accomodate local theme rules.
+
+ if (!empty($CFG->coursetheme)) { // Course theme can override all other settings for this page
+ return $CFG->coursetheme;
+
+ } else if (!empty($SESSION->theme)) { // Session theme can override other settings
+ return $SESSION->theme;
+
+ } else if (!empty($USER->theme)) { // User theme can override site theme
+ return $USER->theme;
+
+ } else {
+ return $CFG->theme;
+ }
+}
+
+
/**
* This function is called by stylesheets to set up the header
* approriately as well as the current path
@@ -1764,6 +1800,7 @@ function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='') {
}
+
/**
* Returns text to be displayed to the user which reflects their login status
*