diff --git a/auth/shibboleth/login.php b/auth/shibboleth/login.php index b37d1f9558e16..b77f45b2150a3 100644 --- a/auth/shibboleth/login.php +++ b/auth/shibboleth/login.php @@ -21,17 +21,6 @@ /// Define variables used in page $site = get_site(); - if (empty($CFG->langmenu)) { - $langmenu = ""; - } else { - $currlang = current_language(); - $langs = get_list_of_languages(); - $select = html_select::make_popup_form("$CFG->httpswwwroot/login/index.php", 'lang', $langs, 'chooselang', $currlang); - $select->nothinglabel = false; - $select->set_label(get_accesshide(get_string('language'))); - $langmenu = '
'.$OUTPUT->select($select).'
'; - } - $loginsite = get_string("loginsite"); $loginurl = (!empty($CFG->alternateloginurl)) ? $CFG->alternateloginurl : ''; @@ -82,7 +71,6 @@ $PAGE->set_title("$site->fullname: $loginsite"); $PAGE->set_heading($site->fullname); $PAGE->set_focuscontrol('idp'); - $PAGE->set_headingmenu($langmenu); echo $OUTPUT->header(); include("index_form.html"); diff --git a/calendar/delete.php b/calendar/delete.php index b42fc294bc33e..c92ed08db579e 100644 --- a/calendar/delete.php +++ b/calendar/delete.php @@ -95,7 +95,6 @@ $PAGE->navbar->add($title); $PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title); $PAGE->set_heading($strcalendar); -$PAGE->set_headingmenu(user_login_string($site)); echo $OUTPUT->header(); echo $OUTPUT->box_start('eventlist'); diff --git a/calendar/event.php b/calendar/event.php index 405a95951c4dd..bcc94083fc5cd 100644 --- a/calendar/event.php +++ b/calendar/event.php @@ -207,7 +207,6 @@ $PAGE->navbar->add($title); $PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title); $PAGE->set_heading($strcalendar); -$PAGE->set_headingmenu(user_login_string($site)); echo $OUTPUT->header(); diff --git a/calendar/export.php b/calendar/export.php index e3ef48ce0203a..eae5bbcfbcc26 100644 --- a/calendar/export.php +++ b/calendar/export.php @@ -133,7 +133,6 @@ $PAGE->set_title($site->shortname.': '.$strcalendar.': '.$pagetitle); $PAGE->set_heading($strcalendar); -$PAGE->set_headingmenu(user_login_string($site)); $PAGE->set_button($prefsbutton); $PAGE->set_focuscontrol('eventform.name'); diff --git a/calendar/preferences.php b/calendar/preferences.php index 01a1c2b23ec70..935c5b1377348 100644 --- a/calendar/preferences.php +++ b/calendar/preferences.php @@ -68,7 +68,6 @@ $PAGE->set_title("$site->shortname: $strcalendar: $strpreferences"); $PAGE->set_heading($strcalendar); -$PAGE->set_headingmenu(user_login_string($site)); echo $OUTPUT->header(); diff --git a/calendar/view.php b/calendar/view.php index b348425f7fdc7..da79b2812fb19 100644 --- a/calendar/view.php +++ b/calendar/view.php @@ -152,7 +152,6 @@ // Print title and header $PAGE->set_title("$site->shortname: $strcalendar: $pagetitle"); $PAGE->set_heading($strcalendar); -$PAGE->set_headingmenu(user_login_string($site)); $PAGE->set_button($prefsbutton); $PAGE->requires->yui2_lib('animation'); diff --git a/course/info.php b/course/info.php index e30301d59aef2..2065271c06a4a 100644 --- a/course/info.php +++ b/course/info.php @@ -38,7 +38,6 @@ $PAGE->set_heading('Course info'); $PAGE->set_course($course); $PAGE->navbar->add(get_string('summary')); - $PAGE->set_headingmenu(user_login_string()); echo $OUTPUT->header(); echo $OUTPUT->heading(''.format_string($course->fullname) . '
(' . format_string($course->shortname) . ')'); diff --git a/course/view.php b/course/view.php index fb7319da74613..3c1f3309cf337 100644 --- a/course/view.php +++ b/course/view.php @@ -198,8 +198,6 @@ $PAGE->set_title(get_string('course') . ': ' . $course->fullname); $PAGE->set_heading($course->fullname); $PAGE->set_button($buttons); - //TODO: MDL-21123 this should be done in course page layout, not here with this ugly hack! - //$PAGE->set_headingmenu(user_login_string($course, $USER)); echo $OUTPUT->header(); if ($completion->is_enabled() && ajaxenabled()) { diff --git a/group/assign.php b/group/assign.php index 78fec568ce3bb..b8d7b54561593 100644 --- a/group/assign.php +++ b/group/assign.php @@ -123,7 +123,6 @@ /// Print header $PAGE->set_title("$course->shortname: $strgroups"); $PAGE->set_heading($course->fullname); -$PAGE->set_headingmenu(user_login_string($course, $USER)); echo $OUTPUT->header(); ?> diff --git a/group/members.php b/group/members.php index 0c0f92885ba98..8d563c6df903c 100644 --- a/group/members.php +++ b/group/members.php @@ -85,7 +85,6 @@ /// Print header $PAGE->set_title("$course->shortname: $strgroups"); $PAGE->set_heading($course->fullname); -$PAGE->set_headingmenu(user_login_string($course, $USER)); echo $OUTPUT->header(); ?> diff --git a/index.php b/index.php index 7827976ab623d..ea44a8a30edb9 100644 --- a/index.php +++ b/index.php @@ -69,18 +69,6 @@ $PAGE->set_pagetype('site-index'); $PAGE->set_course($SITE); - if (empty($CFG->langmenu)) { - $langmenu = ''; - } else { - $currlang = current_language(); - $langs = get_list_of_languages(); - - $select = html_select::make_popup_form($CFG->wwwroot .'/index.php', 'lang', $langs, 'chooselang', $currlang); - $select->nothinglabel = false; - $select->set_label(get_accesshide(get_string('language'))); - //TODO: MDL-21123 - $langmenu = '
'.$OUTPUT->select($select).'
'; - } $PAGE->set_other_editing_capability('moodle/course:manageactivities'); $PAGE->set_url(''); $PAGE->set_docs_path(''); @@ -88,8 +76,7 @@ $editing = $PAGE->user_is_editing(); $PAGE->set_title($SITE->fullname); $PAGE->set_heading($SITE->fullname); - $PAGE->set_headingmenu($langmenu); - echo $OUTPUT->header($langmenu); + echo $OUTPUT->header(); /// Print Section if ($SITE->numsections > 0) { diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 3ebeecf3960bb..675a94fbb85b4 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2169,6 +2169,23 @@ function print_footer($course = NULL, $usercourse = NULL, $return = false) { } } +/** + * Returns text to be displayed to the user which reflects their login status + * + * @global object + * @global object + * @global object + * @global object + * @uses CONTEXT_COURSE + * @param course $course {@link $COURSE} object containing course information + * @param user $user {@link $USER} object containing user information + * @return string HTML + */ +function user_login_string($course='ignored', $user='ignored') { + debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.'); + return ''; +} + /** * Prints a nice side block with an optional header. The content can either * be a block of HTML or a list of text with optional icons. diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 20a277f6e7ec0..dc1a6179f61af 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -556,10 +556,6 @@ public static function make_popup_form($baseurl, $name, $options, $formid, $sele $selectedurl = $baseurl->out(false, array($name => $selected), false); } - if (!($baseurl instanceof moodle_url)) { - $baseurl = new moodle_url($baseurl); - } - // Replace real value by formatted URLs foreach ($options as $value => $label) { $options[$baseurl->out(false, array($name => $value), false)] = $label; diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 56966d4f68a44..ddede978f80c8 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -458,8 +458,80 @@ public function standard_end_of_body_html() { * @return string HTML fragment. */ public function login_info() { - global $USER; - return user_login_string($this->page->course, $USER); + global $USER, $CFG, $DB; + + if (during_initial_install()) { + return ''; + } + + $course = $this->page->course; + + if (session_is_loggedinas()) { + $realuser = session_get_realuser(); + $fullname = fullname($realuser, true); + $realuserinfo = " [frametarget + href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&return=1&sesskey=".sesskey()."\">$fullname] "; + } else { + $realuserinfo = ''; + } + + $loginurl = get_login_url(); + + if (empty($course->id)) { + // $course->id is not defined during installation + return ''; + } else if (!empty($USER->id)) { + $context = get_context_instance(CONTEXT_COURSE, $course->id); + + $fullname = fullname($USER, true); + $username = "frametarget href=\"$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id\">$fullname"; + if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) { + $username .= " from frametarget href=\"{$idprovider->wwwroot}\">{$idprovider->name}"; + } + if (isset($USER->username) && $USER->username == 'guest') { + $loggedinas = $realuserinfo.get_string('loggedinasguest'). + " (frametarget href=\"$loginurl\">".get_string('login').')'; + } else if (!empty($USER->access['rsw'][$context->path])) { + $rolename = ''; + if ($role = $DB->get_record('role', array('id'=>$USER->access['rsw'][$context->path]))) { + $rolename = ': '.format_string($role->name); + } + $loggedinas = get_string('loggedinas', 'moodle', $username).$rolename. + " (frametarget + href=\"$CFG->wwwroot/course/view.php?id=$course->id&switchrole=0&sesskey=".sesskey()."\">".get_string('switchrolereturn').')'; + } else { + $loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).' '. + " (frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').')'; + } + } else { + $loggedinas = get_string('loggedinnot', 'moodle'). + " (frametarget href=\"$loginurl\">".get_string('login').')'; + } + + $loggedinas = '
'.$loggedinas.'
'; + + if (isset($SESSION->justloggedin)) { + unset($SESSION->justloggedin); + if (!empty($CFG->displayloginfailures)) { + if (!empty($USER->username) and $USER->username != 'guest') { + if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) { + $loggedinas .= ' 
'; + if (empty($count->accounts)) { + $loggedinas .= get_string('failedloginattempts', '', $count); + } else { + $loggedinas .= get_string('failedloginattemptsall', '', $count); + } + if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_SYSTEM))) { + $loggedinas .= ' ('.get_string('logs').')'; + } + $loggedinas .= '
'; + } + } + } + } + + return $loggedinas; } /** @@ -668,6 +740,35 @@ public function container_end_all($shouldbenone = false) { return $this->opencontainers->pop_all_but_last($shouldbenone); } + /** + * Returns lang menu or '', this method also checks forcing of languages in courses. + * @return string + */ + public function lang_menu() { + global $CFG; + + if (empty($CFG->langmenu)) { + return ''; + } + + if ($this->page->course != SITEID and !empty($this->page->course->lang)) { + // do not show lang menu if language forced + return ''; + } + + $currlang = current_language(); + $langs = get_list_of_languages(); + + if (count($langs) < 2) { + return ''; + } + + $select = html_select::make_popup_form($this->page->url, 'lang', $langs, 'chooselang', $currlang); + $select->nothinglabel = false; + $select->set_label(get_accesshide(get_string('language'))); + return '
'.$this->select($select).'
'; + } + /** * Output the row of editing icons for a block, as defined by the controls array. * @param array $controls an array like {@link block_contents::$controls}. @@ -1028,7 +1129,7 @@ public function doc_link($path, $text=false, $iconpath=false) { * @param moodle_action_icon $icon A moodle_action_icon object * @return string HTML fragment */ - public function action_icon($icon) { + public function action_icon(moodle_action_icon $icon) { $icon = clone($icon); $icon->prepare($this, $this->page, $this->target); $imageoutput = $this->image($icon->image); diff --git a/lib/weblib.php b/lib/weblib.php index b99b5e141343a..0afb83d8afe72 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -498,6 +498,7 @@ public function out($omitquerystring = false, array $overrideparams = null, $esc $uri .= $this->host ? $this->host : ''; $uri .= $this->port ? ':'.$this->port : ''; $uri .= $this->path ? $this->path : ''; + if (!$omitquerystring) { $querystring = $this->get_query_string($overrideparams, $escaped); if ($querystring) { @@ -1906,101 +1907,6 @@ function send_headers($contenttype, $cacheable = true) { @header('Accept-Ranges: none'); } -/** - * Returns text to be displayed to the user which reflects their login status - * - * @global object - * @global object - * @global object - * @global object - * @uses CONTEXT_COURSE - * @param course $course {@link $COURSE} object containing course information - * @param user $user {@link $USER} object containing user information - * @return string HTML - */ -function user_login_string($course=NULL, $user=NULL) { - global $USER, $CFG, $SITE, $DB; - - if (during_initial_install()) { - return ''; - } - - if (empty($user) and !empty($USER->id)) { - $user = $USER; - } - - if (empty($course)) { - $course = $SITE; - } - - if (session_is_loggedinas()) { - $realuser = session_get_realuser(); - $fullname = fullname($realuser, true); - $realuserinfo = " [frametarget - href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&return=1&sesskey=".sesskey()."\">$fullname] "; - } else { - $realuserinfo = ''; - } - - $loginurl = get_login_url(); - - if (empty($course->id)) { - // $course->id is not defined during installation - return ''; - } else if (!empty($user->id)) { - $context = get_context_instance(CONTEXT_COURSE, $course->id); - - $fullname = fullname($user, true); - $username = "frametarget href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$fullname"; - if (is_mnet_remote_user($user) and $idprovider = $DB->get_record('mnet_host', array('id'=>$user->mnethostid))) { - $username .= " from frametarget href=\"{$idprovider->wwwroot}\">{$idprovider->name}"; - } - if (isset($user->username) && $user->username == 'guest') { - $loggedinas = $realuserinfo.get_string('loggedinasguest'). - " (frametarget href=\"$loginurl\">".get_string('login').')'; - } else if (!empty($user->access['rsw'][$context->path])) { - $rolename = ''; - if ($role = $DB->get_record('role', array('id'=>$user->access['rsw'][$context->path]))) { - $rolename = ': '.format_string($role->name); - } - $loggedinas = get_string('loggedinas', 'moodle', $username).$rolename. - " (frametarget - href=\"$CFG->wwwroot/course/view.php?id=$course->id&switchrole=0&sesskey=".sesskey()."\">".get_string('switchrolereturn').')'; - } else { - $loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).' '. - " (frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').')'; - } - } else { - $loggedinas = get_string('loggedinnot', 'moodle'). - " (frametarget href=\"$loginurl\">".get_string('login').')'; - } - - $loggedinas = '
'.$loggedinas.'
'; - - if (isset($SESSION->justloggedin)) { - unset($SESSION->justloggedin); - if (!empty($CFG->displayloginfailures)) { - if (!empty($USER->username) and $USER->username != 'guest') { - if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) { - $loggedinas .= ' 
'; - if (empty($count->accounts)) { - $loggedinas .= get_string('failedloginattempts', '', $count); - } else { - $loggedinas .= get_string('failedloginattemptsall', '', $count); - } - if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_SYSTEM))) { - $loggedinas .= ' ('.get_string('logs').')'; - } - $loggedinas .= '
'; - } - } - } - } - - return $loggedinas; -} - /** * Return the right arrow with text ('next'), and optionally embedded in a link. * diff --git a/login/index.php b/login/index.php index c6ba22dacd556..b223ab45e978e 100644 --- a/login/index.php +++ b/login/index.php @@ -61,20 +61,10 @@ $PAGE->set_url("$CFG->httpswwwroot/login/index.php"); + /// Define variables used in page $site = get_site(); -if (empty($CFG->langmenu)) { - $langmenu = ""; -} else { - $currlang = current_language(); - $langs = get_list_of_languages(); - $select = html_select::make_popup_form("$CFG->httpswwwroot/login/index.php", 'lang', $langs, 'chooselang', $currlang); - $select->nothinglabel = false; - $select->set_label(get_accesshide(get_string('language'))); - $langmenu = $OUTPUT->select($select); -} - $loginsite = get_string("loginsite"); $PAGE->navbar->add($loginsite); @@ -221,7 +211,6 @@ $days2expire = $userauth->password_expire($USER->username); $PAGE->set_title("$site->fullname: $loginsite"); $PAGE->set_heading("$site->fullname"); - $PAGE->set_headingmenu("
$langmenu
"); if (intval($days2expire) > 0 && intval($days2expire) < intval($userauth->config->expiration_warning)) { echo $OUTPUT->header(); echo $OUTPUT->confirm(get_string('auth_passwordwillexpire', 'auth', $days2expire), $passwordchangeurl, $urltogo); @@ -325,7 +314,6 @@ $PAGE->set_title("$site->fullname: $loginsite"); $PAGE->set_heading("$site->fullname"); -$PAGE->set_headingmenu("
$langmenu
"); $PAGE->set_focuscontrol($focus); echo $OUTPUT->header(); diff --git a/login/signup.php b/login/signup.php index cbcac7c6152dc..f8102be4df19e 100644 --- a/login/signup.php +++ b/login/signup.php @@ -69,23 +69,12 @@ function signup_captcha_enabled() { $newaccount = get_string('newaccount'); $login = get_string('login'); -if (empty($CFG->langmenu)) { - $langmenu = ''; -} else { - $currlang = current_language(); - $langs = get_list_of_languages(); - $select = html_select::make_popup_form("$CFG->wwwroot/login/signup.php", 'lang', $langs, 'chooselang', $currlang); - $select->nothinglabel = false; - $langmenu = $OUTPUT->select($select); -} - $PAGE->navbar->add($login); $PAGE->navbar->add($newaccount); $PAGE->set_url(new moodle_url($CFG->wwwroot.'/login/signup.php')); $PAGE->set_title($newaccount); $PAGE->set_heading($newaccount); $PAGE->set_focuscontrol($mform_signup->focus()); -$PAGE->set_headingmenu("
$langmenu
"); echo $OUTPUT->header(); $mform_signup->display(); diff --git a/mod/hotpot/view.php b/mod/hotpot/view.php index 33d616d3e7ac6..85524484534c7 100644 --- a/mod/hotpot/view.php +++ b/mod/hotpot/view.php @@ -48,12 +48,10 @@ $heading = $course->fullname; $button = '
'.$button.'
'; - $loggedinas = ''.user_login_string($course, $USER).''; $PAGE->set_title($title); $PAGE->set_heading($heading); $PAGE->set_button($button); - $PAGE->set_headingmenu($loggedinas); $time = time(); $hppassword = optional_param('hppassword', '', PARAM_RAW); diff --git a/my/index.php b/my/index.php index c1a7f27330ae4..46dfad0854d4d 100644 --- a/my/index.php +++ b/my/index.php @@ -44,23 +44,10 @@ $header = $SITE->shortname . ': ' . $strmymoodle; $PAGE->navbar->add($strmymoodle); - $loggedinas = user_login_string(); - - if (empty($CFG->langmenu)) { - $langmenu = ''; - } else { - $currlang = current_language(); - $langs = get_list_of_languages(); - $select = html_select::make_popup_form($CFG->wwwroot .'/my/index.php', 'lang', $langs, 'chooselang', $currlang); - $select->nothinglabel = false; - $select->set_label(get_accesshide(get_string('language'))); - $langmenu = $OUTPUT->select($select); - } $PAGE->set_title($strmymoodle); $PAGE->set_heading($header); $PAGE->set_button($button); - $PAGE->set_headingmenu($loggedinas . $langmenu); echo $OUTPUT->header(); /// The main overview in the middle of the page diff --git a/theme/base/config.php b/theme/base/config.php index 44b85a7a80d9a..8733dc11c3ef0 100644 --- a/theme/base/config.php +++ b/theme/base/config.php @@ -66,6 +66,7 @@ 'file' => 'general.php', 'regions' => array('side-pre', 'side-post'), 'defaultregion' => 'side-post', + 'options' => array('langmenu'=>true), ), 'coursecategory' => array( 'theme' => 'base', @@ -100,6 +101,7 @@ 'file' => 'general.php', 'regions' => array('side-pre', 'side-post'), 'defaultregion' => 'side-post', + 'options' => array('langmenu'=>true), ), // My public page 'mypublic' => array( @@ -112,6 +114,7 @@ 'theme' => 'base', 'file' => 'general.php', 'regions' => array(), + 'options' => array('langmenu'=>true), ), // Pages that appear in pop-up windows - no navigation, no blocks, no header. diff --git a/theme/base/layout/frontpage.php b/theme/base/layout/frontpage.php index 80c3e20d27e43..fb827d9ada79c 100644 --- a/theme/base/layout/frontpage.php +++ b/theme/base/layout/frontpage.php @@ -24,11 +24,9 @@

heading ?>

headingmenu) { - echo $PAGE->headingmenu; - } else { echo $OUTPUT->login_info(); - } + echo $OUTPUT->lang_menu(); + echo $PAGE->headingmenu; ?>
diff --git a/theme/base/layout/general.php b/theme/base/layout/general.php index 3d5db37b53ecd..a2f3f6935fbdf 100644 --- a/theme/base/layout/general.php +++ b/theme/base/layout/general.php @@ -23,7 +23,13 @@ heading) { ?> diff --git a/theme/standard/config.php b/theme/standard/config.php index 5accb06f2fc1f..7bdd78c509cb5 100644 --- a/theme/standard/config.php +++ b/theme/standard/config.php @@ -97,6 +97,7 @@ 'file' => 'normal.php', 'regions' => array('side-pre', 'side-post'), 'defaultregion' => 'side-post', + 'options' => array('langmenu'=>true), ), 'coursecategory' => array( 'theme' => 'base', @@ -131,6 +132,7 @@ 'file' => 'normal.php', 'regions' => array('side-pre', 'side-post'), 'defaultregion' => 'side-post', + 'options' => array('langmenu'=>true), ), // My public page 'mypublic' => array( @@ -143,6 +145,7 @@ 'theme' => 'standard', 'file' => 'normal.php', 'regions' => array(), + 'options' => array('langmenu'=>true), ), // Pages that appear in pop-up windows - no navigation, no blocks, no header. diff --git a/theme/standard/layout/frametop.php b/theme/standard/layout/frametop.php index cc75449ca0fab..adbd333d90b0d 100644 --- a/theme/standard/layout/frametop.php +++ b/theme/standard/layout/frametop.php @@ -13,7 +13,13 @@ heading) { ?> diff --git a/theme/standard/layout/home.php b/theme/standard/layout/home.php index bba952486fc0c..92e8dc7d4055c 100644 --- a/theme/standard/layout/home.php +++ b/theme/standard/layout/home.php @@ -14,10 +14,9 @@

heading ?>

login_info(); - if ($PAGE->headingmenu) { + echo $OUTPUT->login_info(); + echo $OUTPUT->lang_menu(); echo $PAGE->headingmenu; - } ?>

diff --git a/theme/standard/layout/normal.php b/theme/standard/layout/normal.php index 323b2cb3cb480..fd02965289539 100644 --- a/theme/standard/layout/normal.php +++ b/theme/standard/layout/normal.php @@ -13,7 +13,13 @@ heading) { ?>