diff --git a/index.php b/index.php index bdff0d4f32b..9eddfd1f8d3 100644 --- a/index.php +++ b/index.php @@ -32,15 +32,7 @@ } } - if (empty($USER->id)) { - if (empty($CFG->loginhttps)) { - $wwwroot = $CFG->wwwroot; - } else { - $wwwroot = str_replace('http', 'https', $CFG->wwwroot); - } - $loginstring = "
".get_string('login').'
'; - } else { - $loginstring = user_login_string($SITE); + if (!empty($USER->id)) { add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID); } @@ -60,7 +52,7 @@ print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home', '', '', - true, '', $loginstring.$langmenu); + true, '', user_login_string($SITE).$langmenu); ?> diff --git a/lib/datalib.php b/lib/datalib.php index fb42be230d3..685224dbd22 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -1335,18 +1335,16 @@ function get_courses_notin_metacourse($metacourseid,$count=false) { global $CFG; - $site = get_site(); // we don't want the site course in here. - if ($count) { $sql = "SELECT COUNT(c.id)"; - } - else { + } else { $sql = "SELECT c.id,c.shortname,c.fullname"; } $alreadycourses = get_courses_in_metacourse($metacourseid); - $sql .= " FROM {$CFG->prefix}course c WHERE ".((!empty($alreadycourses)) ? "c.id NOT IN (".implode(',',array_keys($alreadycourses)).") AND " : "")." c.id !=$metacourseid and c.id != $site->id and c.metacourse != 1"; + $sql .= " FROM {$CFG->prefix}course c WHERE ".((!empty($alreadycourses)) ? "c.id NOT IN (".implode(',',array_keys($alreadycourses)).") + AND " : "")." c.id !=$metacourseid and c.id != ".SITEID." and c.metacourse != 1"; return get_records_sql($sql); } @@ -1999,9 +1997,15 @@ function user_group($courseid, $userid) { * @return course A {@link $COURSE} object for the site * @todo Finish documenting this function. */ -function get_site () { +function get_site() { - if ( $course = get_record('course', 'category', 0)) { + global $SITE; + + if (!empty($SITE->id)) { // We already have a global to use, so return that + return $SITE; + } + + if ($course = get_record('course', 'category', 0)) { return $course; } else { return false; diff --git a/lib/weblib.php b/lib/weblib.php index 3ea647e1920..728c041318a 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1501,7 +1501,7 @@ function highlightfast($needle, $haystack) { function print_header ($title='', $heading='', $navigation='', $focus='', $meta='', $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='') { - global $USER, $CFG, $THEME, $SESSION, $ME; + global $USER, $CFG, $THEME, $SESSION, $ME, $SITE; /// This is an ugly hack to be replaced later by a proper global $COURSE global $course; @@ -1543,7 +1543,7 @@ function print_header ($title='', $heading='', $navigation='', $focus='', $meta= if (isset($course->id)) { $menu = user_login_string($course); } else { - $menu = user_login_string(get_site()); + $menu = user_login_string($SITE); } } @@ -1908,15 +1908,18 @@ function theme_setup($theme = '', $params=NULL) { * @param course $course {@link $COURSE} object containing course information * @param user $user {@link $USER} object containing user information * @return string - * @todo Finish documenting this function */ -function user_login_string($course, $user=NULL) { - global $USER, $CFG; +function user_login_string($course=NULL, $user=NULL) { + global $USER, $CFG, $SITE; if (empty($user) and isset($USER->id)) { $user = $USER; } + if (empty($course)) { + $course = $SITE; + } + if (isset($user->realuser)) { if ($realuser = get_record('user', 'id', $user->realuser)) { $fullname = fullname($realuser, true);