/**
  * Return the standard string that says whether you are logged in (and switched
  * roles/logged in as another user).
  * @param bool $withlinks if false, then don't include any links in the HTML produced.
  * If not set, the default is the nologinlinks option from the theme config.php file,
  * and if that is not set, then links are included.
  * @return string HTML fragment.
  */
 public function login_info($withlinks = null)
 {
     global $USER, $CFG, $DB, $SESSION;
     if (during_initial_install()) {
         return '';
     }
     if (is_null($withlinks)) {
         $withlinks = empty($this->page->layout_options['nologinlinks']);
     }
     $loginpage = (string) $this->page->url === get_login_url();
     $course = $this->page->course;
     if (\core\session\manager::is_loggedinas()) {
         $realuser = \core\session\manager::get_realuser();
         $fullname = fullname($realuser, true);
         if ($withlinks) {
             $loginastitle = get_string('loginas');
             $realuserinfo = " [<a href=\"{$CFG->wwwroot}/course/loginas.php?id={$course->id}&amp;sesskey=" . sesskey() . "\"";
             $realuserinfo .= "title =\"" . $loginastitle . "\">{$fullname}</a>] ";
         } else {
             $realuserinfo = " [{$fullname}] ";
         }
     } else {
         $realuserinfo = '';
     }
     $loginurl = get_login_url();
     if (empty($course->id)) {
         // $course->id is not defined during installation
         return '';
     } else {
         if (isloggedin()) {
             $context = context_course::instance($course->id);
             $fullname = fullname($USER, true);
             // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page)
             if ($withlinks) {
                 $linktitle = get_string('viewprofile');
                 $username = "******"{$CFG->wwwroot}/user/profile.php?id={$USER->id}\" title=\"{$linktitle}\">{$fullname}</a>";
             } else {
                 $username = $fullname;
             }
             if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id' => $USER->mnethostid))) {
                 if ($withlinks) {
                     $username .= " from <a href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
                 } else {
                     $username .= " from {$idprovider->name}";
                 }
             }
             if (isguestuser()) {
                 $loggedinas = $realuserinfo . get_string('loggedinasguest');
                 if (!$loginpage && $withlinks) {
                     $loggedinas .= " (<a href=\"{$loginurl}\">" . get_string('login') . '</a>)';
                 }
             } else {
                 if (is_role_switched($course->id)) {
                     // Has switched roles
                     $rolename = '';
                     if ($role = $DB->get_record('role', array('id' => $USER->access['rsw'][$context->path]))) {
                         $rolename = ': ' . role_get_name($role, $context);
                     }
                     $loggedinas = get_string('loggedinas', 'moodle', $username) . $rolename;
                     if ($withlinks) {
                         $url = new moodle_url('/course/switchrole.php', array('id' => $course->id, 'sesskey' => sesskey(), 'switchrole' => 0, 'returnurl' => $this->page->url->out_as_local_url(false)));
                         $loggedinas .= '(' . html_writer::tag('a', get_string('switchrolereturn'), array('href' => $url)) . ')';
                     }
                 } else {
                     $loggedinas = $realuserinfo . get_string('loggedinas', 'moodle', $username);
                     if ($withlinks) {
                         echo "<i class='fa fa-user hide979 mywhite'></i> ";
                         //****************$loggedinas .= " (<a href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';
                         $loggedinas .= " <span class=\"line-trans\">|</span><a class=\"logtop\" href=\"{$CFG->wwwroot}/login/logout.php?sesskey=" . sesskey() . "\"> " . get_string('logout') . '</a><span class="line-trans"> |</span>';
                     }
                 }
             }
         } else {
             $loggedinas = get_string('loggedinnot', 'moodle');
             if (!$loginpage && $withlinks) {
                 //****************$loggedinas $loggedinas .= " (<a href=\"$loginurl\">".get_string('login').'</a>)';
                 echo "<i class='fa fa-lock hide979 mywhite'></i> ";
                 $loggedinas .= " | <a href=\"{$loginurl}\">" . get_string('login') . '</a> |';
             }
         }
     }
     $loggedinas = '<div class="logininfo">' . $loggedinas . '</div>';
     if (isset($SESSION->justloggedin)) {
         unset($SESSION->justloggedin);
         if (!empty($CFG->displayloginfailures)) {
             if (!isguestuser()) {
                 if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) {
                     $loggedinas .= '&nbsp;<div class="loginfailures">';
                     if (empty($count->accounts)) {
                         $loggedinas .= get_string('failedloginattempts', '', $count);
                     } else {
                         $loggedinas .= get_string('failedloginattemptsall', '', $count);
                     }
                     if (file_exists("{$CFG->dirroot}/report/log/index.php") and has_capability('report/log:view', context_system::instance())) {
                         $loggedinas .= ' (<a href="' . $CFG->wwwroot . '/report/log/index.php' . '?chooselog=1&amp;id=1&amp;modid=site_errors">' . get_string('logs') . '</a>)';
                     }
                     $loggedinas .= '</div>';
                 }
             }
         }
     }
     return $loggedinas;
 }
Esempio n. 2
0
/**
 * Print a standard header
 *
 * @uses $USER
 * @uses $CFG
 * @uses $SESSION
 * @param string  $title Appears at the top of the window
 * @param string  $heading Appears at the top of the page
 * @param array   $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
 * @param string  $focus Indicates form element to get cursor focus on load eg  inputform.password
 * @param string  $meta Meta tags to be added to the header
 * @param boolean $cache Should this page be cacheable?
 * @param string  $button HTML code for a button (usually for module editing)
 * @param string  $menu HTML code for a popup menu
 * @param boolean $usexml use XML for this page
 * @param string  $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
 * @param bool    $return If true, return the visible elements of the header instead of echoing them.
 */
function print_header($title = '', $heading = '', $navigation = '', $focus = '', $meta = '', $cache = true, $button = '&nbsp;', $menu = '', $usexml = false, $bodytags = '', $return = false)
{
    global $USER, $CFG, $THEME, $SESSION, $ME, $SITE, $COURSE, $PAGE;
    if (gettype($navigation) == 'string' && strlen($navigation) != 0 && $navigation != 'home') {
        debugging("print_header() was sent a string as 3rd ({$navigation}) parameter. " . "This is deprecated in favour of an array built by build_navigation(). Please upgrade your code.", DEBUG_DEVELOPER);
    }
    $PAGE->set_state(moodle_page::STATE_PRINTING_HEADER);
    $heading = format_string($heading);
    // Fix for MDL-8582
    if (CLI_SCRIPT) {
        $output = $heading;
        if ($return) {
            return $output;
        } else {
            console_write($output . "\n", '', false);
            return;
        }
    }
    /// Add the required stylesheets
    $stylesheetshtml = '';
    foreach ($CFG->stylesheets as $stylesheet) {
        $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />' . "\n";
    }
    $meta = $stylesheetshtml . $meta;
    /// Add the meta page from the themes if any were requested
    $metapage = '';
    if (!isset($THEME->standardmetainclude) || $THEME->standardmetainclude) {
        ob_start();
        include_once $CFG->dirroot . '/theme/standard/meta.php';
        $metapage .= ob_get_contents();
        ob_end_clean();
    }
    if ($THEME->parent && (!isset($THEME->parentmetainclude) || $THEME->parentmetainclude)) {
        if (file_exists($CFG->dirroot . '/theme/' . $THEME->parent . '/meta.php')) {
            ob_start();
            include_once $CFG->dirroot . '/theme/' . $THEME->parent . '/meta.php';
            $metapage .= ob_get_contents();
            ob_end_clean();
        }
    }
    if (!isset($THEME->metainclude) || $THEME->metainclude) {
        if (file_exists($CFG->dirroot . '/theme/' . current_theme() . '/meta.php')) {
            ob_start();
            include_once $CFG->dirroot . '/theme/' . current_theme() . '/meta.php';
            $metapage .= ob_get_contents();
            ob_end_clean();
        }
    }
    $meta = $meta . "\n" . $metapage;
    $meta .= "\n" . require_js('', 1);
    $meta .= standard_js_config();
    /// Set up some navigation variables
    if (is_newnav($navigation)) {
        $home = false;
    } else {
        if ($navigation == 'home') {
            $home = true;
            $navigation = '';
        } else {
            $home = false;
        }
    }
    /// This is another ugly hack to make navigation elements available to print_footer later
    $THEME->title = $title;
    $THEME->heading = $heading;
    $THEME->navigation = $navigation;
    $THEME->button = $button;
    $THEME->menu = $menu;
    $navmenulist = isset($THEME->navmenulist) ? $THEME->navmenulist : '';
    if ($button == '') {
        $button = '&nbsp;';
    }
    if (file_exists($CFG->dataroot . '/' . SITEID . '/maintenance.html')) {
        $button = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/maintenance.php">' . get_string('maintenancemode', 'admin') . '</a> ' . $button;
        if (!empty($title)) {
            $title .= ' - ';
        }
        $title .= get_string('maintenancemode', 'admin');
    }
    if (!$menu and $navigation) {
        if (empty($CFG->loginhttps)) {
            $wwwroot = $CFG->wwwroot;
        } else {
            $wwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
        }
        $menu = user_login_string($COURSE);
    }
    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)) {
                    $menu .= '&nbsp;<font size="1">';
                    if (empty($count->accounts)) {
                        $menu .= get_string('failedloginattempts', '', $count);
                    } else {
                        $menu .= get_string('failedloginattemptsall', '', $count);
                    }
                    if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_SYSTEM))) {
                        $menu .= ' (<a href="' . $CFG->wwwroot . '/course/report/log/index.php' . '?chooselog=1&amp;id=1&amp;modid=site_errors">' . get_string('logs') . '</a>)';
                    }
                    $menu .= '</font>';
                }
            }
        }
    }
    $meta = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\n" . $meta . "\n";
    if (!$usexml) {
        @header('Content-Type: text/html; charset=utf-8');
    }
    @header('Content-Script-Type: text/javascript');
    @header('Content-Style-Type: text/css');
    //Accessibility: added the 'lang' attribute to $direction, used in theme <html> tag.
    $direction = get_html_lang($dir = true);
    if ($cache) {
        // Allow caching on "back" (but not on normal clicks)
        @header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
        @header('Pragma: no-cache');
        @header('Expires: ');
    } else {
        // Do everything we can to always prevent clients and proxies caching
        @header('Cache-Control: no-store, no-cache, must-revalidate');
        @header('Cache-Control: post-check=0, pre-check=0', false);
        @header('Pragma: no-cache');
        @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
        @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        $meta .= "\n<meta http-equiv=\"pragma\" content=\"no-cache\" />";
        $meta .= "\n<meta http-equiv=\"expires\" content=\"0\" />";
    }
    @header('Accept-Ranges: none');
    $currentlanguage = current_language();
    if (empty($usexml)) {
        $direction = ' xmlns="http://www.w3.org/1999/xhtml"' . $direction;
        // See debug_header
    } else {
        $mathplayer = preg_match("/MathPlayer/i", $_SERVER['HTTP_USER_AGENT']);
        if (!$mathplayer) {
            header('Content-Type: application/xhtml+xml');
        }
        echo '<?xml version="1.0" ?>' . "\n";
        if (!empty($CFG->xml_stylesheets)) {
            $stylesheets = explode(';', $CFG->xml_stylesheets);
            foreach ($stylesheets as $stylesheet) {
                echo '<?xml-stylesheet type="text/xsl" href="' . $CFG->wwwroot . '/' . $stylesheet . '" ?>' . "\n";
            }
        }
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1';
        if (!empty($CFG->xml_doctype_extra)) {
            echo ' plus ' . $CFG->xml_doctype_extra;
        }
        echo '//' . strtoupper($currentlanguage) . '" "' . $CFG->xml_dtd . '">' . "\n";
        $direction = " xmlns=\"http://www.w3.org/1999/xhtml\"\n                       xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n                       xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n                       {$direction}";
        if ($mathplayer) {
            $meta .= '<object id="mathplayer" classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">' . "\n";
            $meta .= '<!--comment required to prevent this becoming an empty tag-->' . "\n";
            $meta .= '</object>' . "\n";
            $meta .= '<?import namespace="math" implementation="#mathplayer" ?>' . "\n";
        }
    }
    // Clean up the title
    $title = format_string($title);
    // fix for MDL-8582
    $title = str_replace('"', '&quot;', $title);
    // Create class and id for this page
    $pageid = $PAGE->pagetype;
    $pageclass = $PAGE->bodyclasses;
    $bodytags .= ' class="' . $pageclass . '" id="' . $pageid . '"';
    require_once $CFG->libdir . '/editor/htmlEditor.class.php';
    $htmlEditorObject = new htmlEditor();
    $htmlEditor = $htmlEditorObject->configure(NULL, $COURSE->id);
    ob_start();
    include $CFG->header;
    $output = ob_get_contents();
    ob_end_clean();
    // container debugging info
    $THEME->open_header_containers = open_containers();
    // Skip to main content, see skip_main_destination().
    if ($pageid == 'course-view' or $pageid == 'site-index' or $pageid == 'course-index') {
        $skiplink = '<a class="skip" href="#maincontent">' . get_string('tocontent', 'access') . '</a>';
        if (!preg_match('/(.*<div[^>]+id="page"[^>]*>)(.*)/s', $output, $matches)) {
            preg_match('/(.*<body.*?>)(.*)/s', $output, $matches);
        }
        $output = $matches[1] . "\n" . $skiplink . $matches[2];
    }
    $output = force_strict_header($output);
    if (!empty($CFG->messaging)) {
        $output .= message_popup_window();
    }
    // Add in any extra JavaScript libraries that occurred during the header
    $output .= require_js('', 2);
    $output .= print_js_call('moodle_initialise_body', array(), true);
    $PAGE->set_state(moodle_page::STATE_IN_BODY);
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
 /**
  * Return the standard string that says whether you are logged in (and switched
  * roles/logged in as another user).
  *
  * @return string HTML fragment.
  */
 public function login_info()
 {
     global $USER, $CFG, $DB, $SESSION;
     if (during_initial_install()) {
         return '';
     }
     $loginpage = (string) $this->page->url === get_login_url();
     $course = $this->page->course;
     if (session_is_loggedinas()) {
         $realuser = session_get_realuser();
         $fullname = fullname($realuser, true);
         $realuserinfo = " [<a href=\"{$CFG->wwwroot}/course/loginas.php?id={$course->id}&amp;sesskey=" . sesskey() . "\">{$fullname}</a>] ";
     } else {
         $realuserinfo = '';
     }
     $loginurl = get_login_url();
     if (empty($course->id)) {
         // $course->id is not defined during installation
         return '';
     } else {
         if (isloggedin()) {
             $context = get_context_instance(CONTEXT_COURSE, $course->id);
             $fullname = fullname($USER, true);
             // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page)
             $username = "******"{$CFG->wwwroot}/user/profile.php?id={$USER->id}\">{$fullname}</a>";
             if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id' => $USER->mnethostid))) {
                 $username .= " from <a href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
             }
             if (isguestuser()) {
                 $loggedinas = $realuserinfo . get_string('loggedinasguest');
                 if (!$loginpage) {
                     $loggedinas .= " (<a href=\"{$loginurl}\">" . get_string('login') . '</a>)';
                 }
             } else {
                 if (is_role_switched($course->id)) {
                     // Has switched roles
                     $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 . " (<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}&amp;switchrole=0&amp;sesskey=" . sesskey() . "\">" . get_string('switchrolereturn') . '</a>)';
                 } else {
                     $loggedinas = $realuserinfo . get_string('loggedinas', 'moodle', $username) . ' ' . " (<a href=\"{$CFG->wwwroot}/login/logout.php?sesskey=" . sesskey() . "\">" . get_string('logout') . '</a>)';
                 }
             }
         } else {
             $loggedinas = get_string('loggedinnot', 'moodle');
             if (!$loginpage) {
                 $loggedinas .= " (<a href=\"{$loginurl}\">" . get_string('login') . '</a>)';
             }
         }
     }
     $loggedinas = '<div class="logininfo">' . $loggedinas . '</div>';
     if (isset($SESSION->justloggedin)) {
         unset($SESSION->justloggedin);
         if (!empty($CFG->displayloginfailures)) {
             if (!isguestuser()) {
                 if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) {
                     $loggedinas .= '&nbsp;<div class="loginfailures">';
                     if (empty($count->accounts)) {
                         $loggedinas .= get_string('failedloginattempts', '', $count);
                     } else {
                         $loggedinas .= get_string('failedloginattemptsall', '', $count);
                     }
                     if (file_exists("{$CFG->dirroot}/report/log/index.php") and has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) {
                         $loggedinas .= ' (<a href="' . $CFG->wwwroot . '/report/log/index.php' . '?chooselog=1&amp;id=1&amp;modid=site_errors">' . get_string('logs') . '</a>)';
                     }
                     $loggedinas .= '</div>';
                 }
             }
         }
     }
     return $loggedinas;
 }
 public function login_info()
 {
     global $USER, $CFG, $DB, $SESSION;
     if (during_initial_install()) {
         return '';
     }
     $course = $this->page->course;
     if (empty($course->id)) {
         // $course->id is not defined during installation
         return '';
     }
     if (session_is_loggedinas()) {
         $real_user = session_get_realuser();
         $real['name'] = fullname($real_user, true);
         $real['link'] = html::url("{$CFG->wwwroot}/course/loginas.php", array('id' => $course->id, 'sesskey' => sesskey()));
     } else {
         $real = null;
     }
     if (!isloggedin()) {
         return bootsnipp::sign_up_sign_in(new moodle_url('/login/index.php'));
     }
     $logout['link'] = html::url("{$CFG->wwwroot}/login/logout.php", array('sesskey' => sesskey()));
     $logout['name'] = get_string('logout');
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
     $user['name'] = fullname($USER, true);
     $user['link'] = html::url("{$CFG->wwwroot}/user/profile.php", array('id' => $USER->id));
     if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id' => $USER->mnethostid))) {
         $mnet['link'] = $idprovider->wwwroot;
         $mnet['name'] = $idprovider->name;
     } else {
         $mnet = null;
     }
     if (isguestuser()) {
         $guest['link'] = get_login_url();
         $guest['name'] = get_string('login');
         return bootsnipp::guest_user($user['name'], $guest, $logout);
     }
     if (is_role_switched($course->id)) {
         if ($role = $DB->get_record('role', array('id' => $USER->access['rsw'][$context->path]))) {
             $user['name'] .= ': ' . format_string($role->name);
         }
         $role_switch['link'] = "{$CFG->wwwroot}/course/view.php?id={$course->id}&switchrole=0&sesskey=" . sesskey();
         $role_switch['name'] = get_string('switchrolereturn');
     } else {
         $role_switch = null;
     }
     $loginfailures = null;
     if (isset($SESSION->justloggedin)) {
         unset($SESSION->justloggedin);
         if (!empty($CFG->displayloginfailures) && !isguestuser()) {
             if (file_exists("{$CFG->dirroot}/report/log/index.php") and has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) {
                 if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) {
                     $loginfailures['link'] = "{$CFG->wwwroot}/report/log/index.php?chooselog=1&id=1&modid=site_errors";
                     if (empty($count->accounts)) {
                         $loginfailures['name'] = get_string('failedloginattempts', '', $count);
                     } else {
                         $loginfailures['name'] = get_string('failedloginattemptsall', '', $count);
                     }
                 }
             }
         }
     }
     return bootsnipp::signed_in($user, $loginfailures, $mnet, $real, $role_switch, $logout);
 }
Esempio n. 5
0
/**
 * Print a standard header
 *
 * @uses $USER
 * @uses $CFG
 * @uses $SESSION
 * @param string  $title Appears at the top of the window
 * @param string  $heading Appears at the top of the page
 * @param array   $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
 * @param string  $focus Indicates form element to get cursor focus on load eg  inputform.password
 * @param string  $meta Meta tags to be added to the header
 * @param boolean $cache Should this page be cacheable?
 * @param string  $button HTML code for a button (usually for module editing)
 * @param string  $menu HTML code for a popup menu
 * @param boolean $usexml use XML for this page
 * @param string  $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
 * @param bool    $return If true, return the visible elements of the header instead of echoing them.
 */
function print_header($title = '', $heading = '', $navigation = '', $focus = '', $meta = '', $cache = true, $button = '&nbsp;', $menu = '', $usexml = false, $bodytags = '', $return = false)
{
    global $USER, $CFG, $THEME, $SESSION, $ME, $SITE, $COURSE;
    global $MODULE_INCLUDE;
    if ($MODULE_INCLUDE) {
        return;
    }
    if (gettype($navigation) == 'string' && strlen($navigation) != 0 && $navigation != 'home') {
        debugging("print_header() was sent a string as 3rd ({$navigation}) parameter. " . "This is deprecated in favour of an array built by build_navigation(). Please upgrade your code.", DEBUG_DEVELOPER);
    }
    $heading = format_string($heading);
    // Fix for MDL-8582
    /// This makes sure that the header is never repeated twice on a page
    if (defined('HEADER_PRINTED')) {
        debugging('print_header() was called more than once - this should not happen.  Please check the code for this page closely. Note: error() and redirect() are now safe to call after print_header().');
        return;
    }
    define('HEADER_PRINTED', 'true');
    /// Perform a browser environment check for the flash version.  Should only run once per login session.
    if (isloggedin() && !empty($CFG->excludeoldflashclients) && empty($SESSION->flashversion)) {
        // Unfortunately we can't use require_js here and keep it all clean in 1.9 ...
        // require_js(array('yui_yahoo', 'yui_event', 'yui_connection', $CFG->httpswwwroot."/lib/swfobject/swfobject.js"));
        $meta .= '<script type="text/javascript"  src="' . $CFG->wwwroot . '/lib/yui/yahoo/yahoo-min.js"></script>';
        $meta .= '<script type="text/javascript"  src="' . $CFG->wwwroot . '/lib/yui/event/event-min.js"></script>';
        $meta .= '<script type="text/javascript"  src="' . $CFG->wwwroot . '/lib/yui/connection/connection-min.js"></script>';
        $meta .= '<script type="text/javascript"  src="' . $CFG->wwwroot . '/lib/swfobject/swfobject.js"></script>';
        $meta .= "<script type=\"text/javascript\">\n" . "  var flashversion = swfobject.getFlashPlayerVersion();\n" . "  YAHOO.util.Connect.asyncRequest('GET','" . $CFG->wwwroot . "/login/environment.php?sesskey=" . sesskey() . "&amp;flashversion='+flashversion.major+'.'+flashversion.minor+'.'+flashversion.release);\n" . "</script>";
    }
    /// Add the required stylesheets
    $stylesheetshtml = '';
    foreach ($CFG->stylesheets as $stylesheet) {
        $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />' . "\n";
    }
    $meta = $stylesheetshtml . $meta;
    /// Add the meta page from the themes if any were requested
    $metapage = '';
    if (!isset($THEME->standardmetainclude) || $THEME->standardmetainclude) {
        ob_start();
        include_once $CFG->dirroot . '/theme/standard/meta.php';
        $metapage .= ob_get_contents();
        ob_end_clean();
    }
    if ($THEME->parent && (!isset($THEME->parentmetainclude) || $THEME->parentmetainclude)) {
        if (file_exists($CFG->dirroot . '/theme/' . $THEME->parent . '/meta.php')) {
            ob_start();
            include_once $CFG->dirroot . '/theme/' . $THEME->parent . '/meta.php';
            $metapage .= ob_get_contents();
            ob_end_clean();
        }
    }
    if (!isset($THEME->metainclude) || $THEME->metainclude) {
        if (file_exists($CFG->dirroot . '/theme/' . current_theme() . '/meta.php')) {
            ob_start();
            include_once $CFG->dirroot . '/theme/' . current_theme() . '/meta.php';
            $metapage .= ob_get_contents();
            ob_end_clean();
        }
    }
    $meta = $meta . "\n" . $metapage;
    $meta .= "\n" . require_js('', 1);
    /// Set up some navigation variables
    if (is_newnav($navigation)) {
        $home = false;
    } else {
        if ($navigation == 'home') {
            $home = true;
            $navigation = '';
        } else {
            $home = false;
        }
    }
    /// This is another ugly hack to make navigation elements available to print_footer later
    $THEME->title = $title;
    $THEME->heading = $heading;
    $THEME->navigation = $navigation;
    $THEME->button = $button;
    $THEME->menu = $menu;
    $navmenulist = isset($THEME->navmenulist) ? $THEME->navmenulist : '';
    if ($button == '') {
        $button = '&nbsp;';
    }
    if (file_exists($CFG->dataroot . '/' . SITEID . '/maintenance.html')) {
        $button = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/maintenance.php">' . get_string('maintenancemode', 'admin') . '</a> ' . $button;
        if (!empty($title)) {
            $title .= ' - ';
        }
        $title .= get_string('maintenancemode', 'admin');
    }
    if (!$menu and $navigation) {
        if (empty($CFG->loginhttps)) {
            $wwwroot = $CFG->wwwroot;
        } else {
            $wwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
        }
        $menu = user_login_string($COURSE);
    }
    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)) {
                    $menu .= '&nbsp;<font size="1">';
                    if (empty($count->accounts)) {
                        $menu .= get_string('failedloginattempts', '', $count);
                    } else {
                        $menu .= get_string('failedloginattemptsall', '', $count);
                    }
                    if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_SYSTEM))) {
                        $menu .= ' (<a href="' . $CFG->wwwroot . '/course/report/log/index.php' . '?chooselog=1&amp;id=1&amp;modid=site_errors">' . get_string('logs') . '</a>)';
                    }
                    $menu .= '</font>';
                }
            }
        }
    }
    $meta = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\n" . $meta . "\n";
    if (!$usexml) {
        @header('Content-Type: text/html; charset=utf-8');
    }
    @header('Content-Script-Type: text/javascript');
    @header('Content-Style-Type: text/css');
    //Accessibility: added the 'lang' attribute to $direction, used in theme <html> tag.
    $direction = get_html_lang($dir = true);
    if ($cache) {
        // Allow caching on "back" (but not on normal clicks)
        @header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
        @header('Pragma: no-cache');
        @header('Expires: ');
    } else {
        // Do everything we can to always prevent clients and proxies caching
        @header('Cache-Control: no-store, no-cache, must-revalidate');
        @header('Cache-Control: post-check=0, pre-check=0', false);
        @header('Pragma: no-cache');
        @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
        @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        $meta .= "\n<meta http-equiv=\"pragma\" content=\"no-cache\" />";
        $meta .= "\n<meta http-equiv=\"expires\" content=\"0\" />";
    }
    @header('Accept-Ranges: none');
    $currentlanguage = current_language();
    if (empty($usexml)) {
        $direction = ' xmlns="http://www.w3.org/1999/xhtml"' . $direction;
        // See debug_header
    } else {
        $mathplayer = preg_match("/MathPlayer/i", $_SERVER['HTTP_USER_AGENT']);
        if (!$mathplayer) {
            header('Content-Type: application/xhtml+xml');
        }
        echo '<?xml version="1.0" ?>' . "\n";
        if (!empty($CFG->xml_stylesheets)) {
            $stylesheets = explode(';', $CFG->xml_stylesheets);
            foreach ($stylesheets as $stylesheet) {
                echo '<?xml-stylesheet type="text/xsl" href="' . $CFG->wwwroot . '/' . $stylesheet . '" ?>' . "\n";
            }
        }
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1';
        if (!empty($CFG->xml_doctype_extra)) {
            echo ' plus ' . $CFG->xml_doctype_extra;
        }
        echo '//' . strtoupper($currentlanguage) . '" "' . $CFG->xml_dtd . '">' . "\n";
        $direction = " xmlns=\"http://www.w3.org/1999/xhtml\"\n                       xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n                       xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n                       {$direction}";
        if ($mathplayer) {
            $meta .= '<object id="mathplayer" classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">' . "\n";
            $meta .= '<!--comment required to prevent this becoming an empty tag-->' . "\n";
            $meta .= '</object>' . "\n";
            $meta .= '<?import namespace="math" implementation="#mathplayer" ?>' . "\n";
        }
    }
    // Clean up the title
    $title = format_string($title);
    // fix for MDL-8582
    $title = str_replace('"', '&quot;', $title);
    // Create class and id for this page
    page_id_and_class($pageid, $pageclass);
    $pageclass .= ' course-' . $COURSE->id;
    if (!isloggedin()) {
        $pageclass .= ' notloggedin';
    }
    if (!empty($USER->editing)) {
        $pageclass .= ' editing';
    }
    if (!empty($CFG->blocksdrag)) {
        $pageclass .= ' drag';
    }
    $pageclass .= ' dir-' . get_string('thisdirection');
    $pageclass .= ' lang-' . $currentlanguage;
    $bodytags .= ' class="' . $pageclass . '" id="' . $pageid . '"';
    ob_start();
    include $CFG->header;
    $output = ob_get_contents();
    ob_end_clean();
    // container debugging info
    $THEME->open_header_containers = open_containers();
    // Skip to main content, see skip_main_destination().
    if ($pageid == 'course-view' or $pageid == 'site-index' or $pageid == 'course-index') {
        $skiplink = '<a class="skip" href="#maincontent">' . get_string('tocontent', 'access') . '</a>';
        if (!preg_match('/(.*<div[^>]+id="page"[^>]*>)(.*)/s', $output, $matches)) {
            preg_match('/(.*<body.*?>)(.*)/s', $output, $matches);
        }
        $output = $matches[1] . "\n" . $skiplink . $matches[2];
    }
    $output = force_strict_header($output);
    if (!empty($CFG->messaging)) {
        $output .= message_popup_window();
    }
    // Add in any extra JavaScript libraries that occurred during the header
    $output .= require_js('', 2);
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
Esempio n. 6
0
    public function login_info($withlinks = null) {
        global $USER, $CFG, $DB, $SESSION,$OUTPUT;

        if (during_initial_install()) {
            return '';
        }

        if (is_null($withlinks)) {
            $withlinks = empty($this->page->layout_options['nologinlinks']);
        }

        $loginpage = ((string)$this->page->url === get_login_url());
        $course = $this->page->course;
        if (\core\session\manager::is_loggedinas()) {
            $realuser = session_get_realuser();
            $fullname = fullname($realuser, true);
            if ($withlinks) {
                $loginastitle = get_string('loginas');
                $realuserinfo = " <a href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;sesskey=".sesskey()."\"";
                $realuserinfo .= "title =\"".$loginastitle."\">$fullname</a>";
            } else {
                $realuserinfo = "$fullname";
            }
        } else {
            $realuserinfo = '';
        }

        $loginurl = get_login_url();

        if (empty($course->id)) {
            // $course->id is not defined during installation
            return '';
        } else if (isloggedin()) {
            $context = context_course::instance($course->id);

            $fullname = fullname($USER, true);
            // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page)
            if ($withlinks) {
                $linktitle = get_string('viewprofile');
                $username = "******"$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id\" title=\"$linktitle\">$fullname</a>";
            } else {
                $username = $fullname;
            }
            if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) {
                if ($withlinks) {
                    $username .= " from <a href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
                } else {
                    $username .= " from {$idprovider->name}";
                }
            }
            if (isguestuser()) {
                $loggedinas = get_string('loggedinasguest','theme_colms');
                $loggout = "<a href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\" id='logout'>".get_string('logout').'</a>';
                if (!$loginpage && $withlinks) {
                    $loggedinas .= " (<a href=\"$loginurl\" style=\"vertical-align:middle;margin:0;\">".get_string('login').'</a>)';
                }
            } else if (is_role_switched($course->id)) { // Has switched roles
                $rolename = '';
                if ($role = $DB->get_record('role', array('id'=>$USER->access['rsw'][$context->path]))) {
                    // $rolename = ': '.role_get_name($role, $context);
					$rolename = '';
                }
                $loggedinas = get_string('loggedinas', 'theme_colms', $username).$rolename;
                if ($withlinks) {
                    $url = new moodle_url('/course/switchrole.php', array('id'=>$course->id,'sesskey'=>sesskey(), 'switchrole'=>0, 'returnurl'=>$this->page->url->out_as_local_url(false)));
                    // $loggedinas .= '('.html_writer::tag('a', get_string('switchrolereturn'), array('href'=>$url)).')';
                }
            } else {
                $loggedinas = $realuserinfo.get_string('loggedinas', 'theme_colms', $username);
                if ($withlinks) {
                    $loggout = "<a href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\" id='logout'>".get_string('logout').'</a>';
                }
            }
        } else {
            $loggedinas = get_string('loggedinnot', 'theme_colms');
            if (!$loginpage && $withlinks) {
                $loggedinas = "<a href='javascript:void(0)' id='login_button'>".get_string('login').'</a>';
            }
        }
        // if(isloggedin() || isguestuser()){
        // $loggedinas = '<div class="logininfo"><div id="logoutlink">'. $loggedinas .'<a href="javascript:void(0)" id="pop_logout"><img src=' . $OUTPUT->pix_url("down_arrow","theme") .'  /></a></div>', array("class"=>"userimg")) . ''.$loggout.'</div>';
        // }
		if(isloggedin() || isguestuser()){
		$loggout = "<a href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\" class='box_log'>".get_string('logout').'</a>';
        $loggedinas = '<div class="logininfo"><div class="logoutlink">'. $loggedinas .'</div><div class="box_log">'.$loggout.'</div></div>';
        }
        if (isset($SESSION->justloggedin)) {
            unset($SESSION->justloggedin);
            if (!empty($CFG->displayloginfailures)) {
                if (!isguestuser()) {
                    if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) {
                        $loggedinas .= '&nbsp;<div class="loginfailures">';
                        if (empty($count->accounts)) {
                            $loggedinas .= get_string('failedloginattempts', '', $count);
                        } else {
                            $loggedinas .= get_string('failedloginattemptsall', '', $count);
                        }
                        if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', context_system::instance())) {
                            $loggedinas .= ' (<a href="'.$CFG->wwwroot.'/report/log/index.php'.
                                                 '?chooselog=1&amp;id=1&amp;modid=site_errors">'.get_string('logs').'</a>)';
                        }
                        $loggedinas .= '</div>';
                    }
                }
            }
        }
        
        return $loggedinas;
    }
Esempio n. 7
0
/**
 * 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 = " [<a {$CFG->frametarget}\n        href=\"{$CFG->wwwroot}/course/loginas.php?id={$course->id}&amp;return=1&amp;sesskey=" . sesskey() . "\">{$fullname}</a>] ";
    } 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 = "******"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$course->id}\">{$fullname}</a>";
            if (is_mnet_remote_user($user) and $idprovider = $DB->get_record('mnet_host', array('id' => $user->mnethostid))) {
                $username .= " from <a {$CFG->frametarget} href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
            }
            if (isset($user->username) && $user->username == 'guest') {
                $loggedinas = $realuserinfo . get_string('loggedinasguest') . " (<a {$CFG->frametarget} href=\"{$loginurl}\">" . get_string('login') . '</a>)';
            } 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 . " (<a {$CFG->frametarget}\n                      href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}&amp;switchrole=0&amp;sesskey=" . sesskey() . "\">" . get_string('switchrolereturn') . '</a>)';
                } else {
                    $loggedinas = $realuserinfo . get_string('loggedinas', 'moodle', $username) . ' ' . " (<a {$CFG->frametarget} href=\"{$CFG->wwwroot}/login/logout.php?sesskey=" . sesskey() . "\">" . get_string('logout') . '</a>)';
                }
            }
        } else {
            $loggedinas = get_string('loggedinnot', 'moodle') . " (<a {$CFG->frametarget} href=\"{$loginurl}\">" . get_string('login') . '</a>)';
        }
    }
    $loggedinas = '<div class="logininfo">' . $loggedinas . '</div>';
    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 .= '&nbsp;<div class="loginfailures">';
                    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 .= ' (<a href="' . $CFG->wwwroot . '/course/report/log/index.php' . '?chooselog=1&amp;id=1&amp;modid=site_errors">' . get_string('logs') . '</a>)';
                    }
                    $loggedinas .= '</div>';
                }
            }
        }
    }
    return $loggedinas;
}
 /**
  * Return the standard string that says whether you are logged in (and switched
  * roles/logged in as another user).
  * @param bool $withlinks if false, then don't include any links in the HTML produced.
  * If not set, the default is the nologinlinks option from the theme config.php file,
  * and if that is not set, then links are included.
  * @return string HTML fragment.
  */
 public function login_info($withlinks = null)
 {
     global $USER, $CFG, $DB, $SESSION;
     if (right_to_left()) {
         $direction = array('left-side' => 'right', 'right-side' => 'left');
         $dir = 'right';
     } else {
         $direction = array('left-side' => 'left', 'right-side' => 'right');
         $dir = '';
     }
     // Check Page layout options for links
     // Obscure, but whatever...
     if (is_null($withlinks)) {
         $withlinks = empty($this->page->layout_options['nologinlinks']);
     }
     // Setup a check for if we're on the login page
     $loginurl = get_login_url();
     $loginpage = (string) $this->page->url === $loginurl;
     $logouturl = $CFG->wwwroot . '/login/logout.php';
     // This should be overridden with sesskey() info
     $logouturl = $CFG->wwwroot . '/login/logout.php?sesskey=' . sesskey();
     $course = $this->page->course;
     if (during_initial_install() || empty($course->id)) {
         // $course->id is not defined during installation
         // Logins don't exist yet...
         return '';
     }
     // Assume they're not logged in
     $loggedinas = '';
     // Build some general output components
     // Divider
     $divider = html_writer::empty_tag('li', array('class' => 'divider ' . $dir));
     // Start li
     $startli = html_writer::start_tag('li', array('class' => $dir));
     $startdropdownli = html_writer::start_tag('li', array('class' => 'has-dropdown ' . $dir));
     // End li
     $endli = html_writer::end_tag('li');
     // Login button
     $loginbutton = $divider;
     $loginbutton .= html_writer::start_tag('li', array('class' => 'has-form'));
     $loginbutton .= html_writer::tag('a', get_string('login'), array('href' => $loginurl, 'class' => 'button'));
     $loginbutton .= html_writer::end_tag('li');
     // Logout button
     $logoutbutton = html_writer::empty_tag('li', array('class' => 'divider'));
     $logoutbutton .= html_writer::start_tag('li', array('class' => 'has-form'));
     $logoutbutton .= html_writer::tag('a', get_string('logout'), array('href' => $logouturl, 'class' => 'button'));
     $logoutbutton .= html_writer::end_tag('li');
     if (!$loginpage) {
         // Don't show any login info on the login page
         if (isloggedin()) {
             // Logged in users (MNET, guest, switched role, loggedinas, normal)
             $fullname = fullname($USER, true);
             $mnetuser = is_mnet_remote_user($USER) && ($idprovider = $DB->get_record('mnet_host', array('id' => $USER->mnethostid)));
             $mnetuserpanel = '';
             $roleswitched = is_role_switched($course->id);
             $roleswitchedpanel = '';
             $loggedinasuser = session_is_loggedinas();
             $loggedinasuserpanel = '';
             if ($mnetuser) {
                 $providerurl = $idprovider->wwwroot;
                 $providername = $idprovider->name;
                 $providerlink = html_writer::tag('a', $providername, array('href' => $providerurl));
                 $roleswitched || $loggedinasuser ? $mnetuserpanel .= $divider : null;
                 if ($withlinks) {
                     $mnetuserpanel .= $startli;
                     $mnetuserpanel .= html_writer::tag('label', get_string('yourhost', 'mnet') . ':');
                     $mnetuserpanel .= html_writer::tag('li', $providerlink);
                     $mnetuserpanel .= $endli;
                 } else {
                     $mnetuserpanel .= $startli;
                     $mnetuserpanel .= html_writer::tag('label', $providername);
                     $mnetuserpanel .= $endli;
                 }
             }
             if ($roleswitched) {
                 $rolename = '';
                 $context = context_course::instance($course->id);
                 if ($role = $DB->get_record('role', array('id' => $USER->access['rsw'][$context->path]))) {
                     $rolename = format_string($role->name);
                 }
                 if (empty($rolename)) {
                     // Specially for Admins - they have no original role Title...
                     $rolename = get_string('admin');
                 }
                 $returnrolelinkparams = array('id' => $course->id, 'sesskey' => sesskey(), 'switchrole' => 0, 'returnurl' => $this->page->url->out_as_local_url(false));
                 $returnrolelink = new moodle_url('/course/switchrole.php', $returnrolelinkparams);
                 $returnrolelink = html_writer::tag('a', $rolename, array('href' => $returnrolelink));
                 // Add a divider if the user is also role switched or MNET
                 $mnetuser || $loggedinasuser ? $roleswitchedpanel .= $divider : null;
                 if ($withlinks) {
                     $roleswitchedpanel .= $startli;
                     $roleswitchedpanel .= html_writer::tag('label', get_string('switchrolereturn'));
                     $roleswitchedpanel .= $endli;
                     $roleswitchedpanel .= html_writer::tag('li', $returnrolelink);
                 } else {
                     $roleswitchedpanel .= $startli;
                     $roleswitchedpanel .= html_writer::tag('label', get_string('role') . ': ' . $rolename);
                     $roleswitchedpanel .= $endli;
                 }
             }
             if ($loggedinasuser) {
                 $realuser = session_get_realuser();
                 $realuser = fullname($realuser, true);
                 $realuserprofilelink = $CFG->wwwroot . '/course/loginas.php?id=' . $course->id . '&sesskey=' . sesskey();
                 $realuserprofile = html_writer::tag('a', $realuser, array('href' => $realuserprofilelink));
                 // Add a divider if the user is also role switched or MNET
                 $mnetuser || $roleswitched ? $loggedinasuserpanel .= $divider : null;
                 if ($withlinks) {
                     $loggedinasuserpanel .= $startli;
                     $loggedinasuserpanel .= html_writer::tag('label', get_string('returntooriginaluser', '', $realuser));
                     $loggedinasuserpanel .= $endli;
                     $loggedinasuserpanel .= html_writer::tag('li', $realuserprofile);
                 } else {
                     $loggedinasuserpanel .= $startli;
                     $loggedinasuserpanel .= html_writer::tag('label', get_string('loggedinas', '', $realuser));
                     $loggedinasuserpanel .= $endli;
                 }
             }
             $hasdropdown = $mnetuser || $roleswitched || $loggedinasuser;
             $dropdown = $mnetuserpanel . $roleswitchedpanel . $loggedinasuserpanel;
             $dropdown = html_writer::tag('ul', $dropdown, array('class' => 'dropdown'));
             if (isguestuser()) {
                 // Guest user
                 $fullname = html_writer::tag('span', $fullname);
                 $loggedinas = $divider . $startli . $fullname . $endli;
                 //@TODO: Write a style to swap tag for span
                 if ($withlinks) {
                     $loggedinas .= $loginbutton;
                 }
             } else {
                 // Normal User
                 if ($withlinks) {
                     //Link to profile page
                     $userprofilelink = $CFG->wwwroot . '/user/profile.php?id=' . $USER->id;
                     $userprofile = html_writer::tag('a', $fullname, array('href' => $userprofilelink));
                     // Check to see if we need a dropdown
                     if ($hasdropdown) {
                         $loggedinas = $divider . $startdropdownli . $userprofile . $dropdown . $endli . $logoutbutton;
                     } else {
                         // Normal User
                         $loggedinas = $divider . $startli . $userprofile . $endli . $logoutbutton;
                     }
                 } else {
                     $fullname = html_writer::tag('a', $fullname, array('href' => '#'));
                     //@ TODO Write SPAN rules to show dropdown menu
                     if ($hasdropdown) {
                         $loggedinas = $divider . $startdropdownli . $fullname . $dropdown . $endli;
                     } else {
                         $loggedinas = $divider . $startli . $fullname . $endli;
                     }
                 }
             }
         } else {
             // All not logged in users
             if ($withlinks) {
                 // Add a "login" button
                 $loggedinas = $loginbutton;
             } else {
                 // Don't need to output anything
                 $loggedinas = '';
             }
         }
     }
     if (isset($SESSION->justloggedin)) {
         unset($SESSION->justloggedin);
         if (!empty($CFG->displayloginfailures)) {
             if (!isguestuser()) {
                 if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) {
                     $loggedinas .= '&nbsp;<div class="loginfailures">';
                     if (empty($count->accounts)) {
                         $loggedinas .= get_string('failedloginattempts', '', $count);
                     } else {
                         $loggedinas .= get_string('failedloginattemptsall', '', $count);
                     }
                     if (file_exists("{$CFG->dirroot}/report/log/index.php") and has_capability('report/log:view', context_system::instance())) {
                         $loggedinas .= ' (<a href="' . $CFG->wwwroot . '/report/log/index.php' . '?chooselog=1&amp;id=1&amp;modid=site_errors">' . get_string('logs') . '</a>)';
                     }
                     $loggedinas .= '</div>';
                 }
             }
         }
     }
     return $loggedinas;
 }
Esempio n. 9
0
/**
 * Print a standard header
 *
 * @uses $USER
 * @uses $CFG
 * @uses $SESSION
 * @param string $title Appears at the top of the window
 * @param string $heading Appears at the top of the page
 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
 * @param string $focus Indicates form element to get cursor focus on load eg  inputform.password
 * @param string $meta Meta tags to be added to the header
 * @param boolean $cache Should this page be cacheable?
 * @param string $button HTML code for a button (usually for module editing)
 * @param string $menu HTML code for a popup menu
 * @param boolean $usexml use XML for this page
 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
 * @param bool   $return If true, return the visible elements of the header instead of echoing them.
 */
function print_header($title = '', $heading = '', $navigation = '', $focus = '', $meta = '', $cache = true, $button = '&nbsp;', $menu = '', $usexml = false, $bodytags = '', $return = false)
{
    global $USER, $CFG, $THEME, $SESSION, $ME, $SITE, $COURSE;
    $heading = format_string($heading);
    // Fix for MDL-8582
    /// This makes sure that the header is never repeated twice on a page
    if (defined('HEADER_PRINTED')) {
        debugging('print_header() was called more than once - this should not happen.  Please check the code for this page closely. Note: error() and redirect() are now safe to call after print_header().');
        return;
    }
    define('HEADER_PRINTED', 'true');
    /// Add the required stylesheets
    $stylesheetshtml = '';
    foreach ($CFG->stylesheets as $stylesheet) {
        $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />' . "\n";
    }
    $meta = $stylesheetshtml . $meta;
    /// Add the meta page from the themes if any were requested
    $metapage = '';
    if (!isset($THEME->standardmetainclude) || $THEME->standardmetainclude) {
        ob_start();
        include_once $CFG->dirroot . '/theme/standard/meta.php';
        $metapage .= ob_get_contents();
        ob_end_clean();
    }
    if ($THEME->parent && (!isset($THEME->parentmetainclude) || $THEME->parentmetainclude)) {
        if (file_exists($CFG->dirroot . '/theme/' . $THEME->parent . '/meta.php')) {
            ob_start();
            include_once $CFG->dirroot . '/theme/' . $THEME->parent . '/meta.php';
            $metapage .= ob_get_contents();
            ob_end_clean();
        }
    }
    if (!isset($THEME->metainclude) || $THEME->metainclude) {
        if (file_exists($CFG->dirroot . '/theme/' . current_theme() . '/meta.php')) {
            ob_start();
            include_once $CFG->dirroot . '/theme/' . current_theme() . '/meta.php';
            $metapage .= ob_get_contents();
            ob_end_clean();
        }
    }
    $meta = $meta . "\n" . $metapage;
    /// Add the required JavaScript Libraries
    $meta .= "\n" . require_js();
    if ($navigation == 'home') {
        $home = true;
        $navigation = '';
    } else {
        $home = false;
    }
    /// This is another ugly hack to make navigation elements available to print_footer later
    $THEME->title = $title;
    $THEME->heading = $heading;
    $THEME->navigation = $navigation;
    $THEME->button = $button;
    $THEME->menu = $menu;
    $navmenulist = isset($THEME->navmenulist) ? $THEME->navmenulist : '';
    if ($button == '') {
        $button = '&nbsp;';
    }
    if (!$menu and $navigation) {
        if (empty($CFG->loginhttps)) {
            $wwwroot = $CFG->wwwroot;
        } else {
            $wwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
        }
        $menu = user_login_string($COURSE);
    }
    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)) {
                    $menu .= '&nbsp;<font size="1">';
                    if (empty($count->accounts)) {
                        $menu .= get_string('failedloginattempts', '', $count);
                    } else {
                        $menu .= get_string('failedloginattemptsall', '', $count);
                    }
                    if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
                        $menu .= ' (<a href="' . $CFG->wwwroot . '/course/report/log/index.php' . '?chooselog=1&amp;id=1&amp;modid=site_errors">' . get_string('logs') . '</a>)';
                    }
                    $menu .= '</font>';
                }
            }
        }
    }
    $meta = '<meta http-equiv="content-type" content="text/html; charset=utf-8" />' . "\n" . $meta . "\n";
    if (!$usexml) {
        @header('Content-type: text/html; charset=utf-8');
    }
    //Accessibility: added the 'lang' attribute to $direction, used in theme <html> tag.
    $direction = get_html_lang($dir = true);
    if ($cache) {
        // Allow caching on "back" (but not on normal clicks)
        @header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
        @header('Pragma: no-cache');
        @header('Expires: ');
    } else {
        // Do everything we can to always prevent clients and proxies caching
        @header('Cache-Control: no-store, no-cache, must-revalidate');
        @header('Cache-Control: post-check=0, pre-check=0', false);
        @header('Pragma: no-cache');
        @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
        @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        $meta .= "\n<meta http-equiv=\"pragma\" content=\"no-cache\" />";
        $meta .= "\n<meta http-equiv=\"expires\" content=\"0\" />";
    }
    @header('Accept-Ranges: none');
    $currentlanguage = current_language();
    if (empty($usexml)) {
        $direction = ' xmlns="http://www.w3.org/1999/xhtml"' . $direction;
        // See debug_header
    } else {
        $mathplayer = preg_match("/MathPlayer/i", $_SERVER['HTTP_USER_AGENT']);
        if (!$mathplayer) {
            header('Content-Type: application/xhtml+xml');
        }
        echo '<?xml version="1.0" ?>' . "\n";
        if (!empty($CFG->xml_stylesheets)) {
            $stylesheets = explode(';', $CFG->xml_stylesheets);
            foreach ($stylesheets as $stylesheet) {
                echo '<?xml-stylesheet type="text/xsl" href="' . $CFG->wwwroot . '/' . $stylesheet . '" ?>' . "\n";
            }
        }
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1';
        if (!empty($CFG->xml_doctype_extra)) {
            echo ' plus ' . $CFG->xml_doctype_extra;
        }
        echo '//' . strtoupper($currentlanguage) . '" "' . $CFG->xml_dtd . '">' . "\n";
        $direction = " xmlns=\"http://www.w3.org/1999/xhtml\"\n                       xmlns:math=\"http://www.w3.org/1998/Math/MathML\"\n                       xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n                       {$direction}";
        if ($mathplayer) {
            $meta .= '<object id="mathplayer" classid="clsid:32F66A20-7614-11D4-BD11-00104BD3F987">' . "\n";
            $meta .= '<!--comment required to prevent this becoming an empty tag-->' . "\n";
            $meta .= '</object>' . "\n";
            $meta .= '<?import namespace="math" implementation="#mathplayer" ?>' . "\n";
        }
    }
    // Clean up the title
    $title = format_string($title);
    // fix for MDL-8582
    $title = str_replace('"', '&quot;', $title);
    // Create class and id for this page
    page_id_and_class($pageid, $pageclass);
    $pageclass .= ' course-' . $COURSE->id;
    if ($pageid != 'site-index' && $pageid != 'course-view' && strstr($pageid, 'admin') === FALSE) {
        $pageclass .= ' nocoursepage';
    }
    if (!isloggedin()) {
        $pageclass .= ' notloggedin';
    }
    if (!empty($USER->editing)) {
        $pageclass .= ' editing';
    }
    if (!empty($CFG->blocksdrag)) {
        $pageclass .= ' drag';
    }
    $pageclass .= ' lang-' . $currentlanguage;
    $bodytags .= ' class="' . $pageclass . '" id="' . $pageid . '"';
    ob_start();
    include $CFG->header;
    $output = ob_get_contents();
    ob_end_clean();
    $output = force_strict_header($output);
    if (!empty($CFG->messaging)) {
        $output .= message_popup_window();
    }
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
 /**
  * Return the standard string that says whether you are logged in (and switched
  * roles/logged in as another user).
  * @param bool $withlinks if false, then don't include any links in the HTML produced.
  * If not set, the default is the nologinlinks option from the theme config.php file,
  * and if that is not set, then links are included.
  * @return string HTML fragment.
  */
 public function login_info($withlinks = null, $asmenu = false)
 {
     global $USER, $CFG, $DB, $SESSION;
     if (during_initial_install()) {
         return '';
     }
     if (is_null($withlinks)) {
         $withlinks = empty($this->page->layout_options['nologinlinks']);
     }
     $loginpage = (string) $this->page->url === get_login_url();
     $course = $this->page->course;
     if (\core\session\manager::is_loggedinas()) {
         $realuser = \core\session\manager::get_realuser();
         $fullname = fullname($realuser, true);
         if ($withlinks) {
             $loginastitle = get_string('loginas');
             $realuserinfo = " <small>[</small><a href=\"{$CFG->wwwroot}/course/loginas.php?id={$course->id}&amp;sesskey=" . sesskey() . "\"";
             $realuserinfo .= "title =\"" . $loginastitle . "\">{$fullname}</a> <small>]</small> ";
         } else {
             $realuserinfo = " <small>[</small> {$fullname} <small>]</small> ";
         }
     } else {
         $realuserinfo = '';
     }
     $loginurl = get_login_url();
     $loggedinas = '';
     if (empty($course->id)) {
         // The $course->id is not defined during installation.
         return '';
     } else {
         if (isloggedin()) {
             $context = context_course::instance($course->id);
             $fullname = fullname($USER, true);
             $linktitle = get_string('viewprofile');
             $userpicture = '';
             if (!empty($USER->id)) {
                 $userpicture = $this->user_picture($USER, array('size' => 35, 'link' => false, 'class' => 'nav_userpicture'));
             }
             $username = "******"{$CFG->wwwroot}/user/profile.php?id={$USER->id}\" " . "title=\"{$linktitle}\" class='userloginprofile'>{$userpicture}{$fullname}</a>";
             if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id' => $USER->mnethostid))) {
                 $username .= " from <a href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
             }
             $loggedinas = $username;
             if (isguestuser()) {
                 $loggedinas = $realuserinfo . get_string('loggedinasguest');
                 if (!$loginpage) {
                     $loggedinas .= " <small>(</small> <a href=\"{$loginurl}\">" . get_string('login') . '</a> <small>)</small>';
                 }
             } else {
                 if (is_role_switched($course->id)) {
                     // Has switched roles.
                     $rolename = '';
                     if ($role = $DB->get_record('role', array('id' => $USER->access['rsw'][$context->path]))) {
                         $rolename = '<span class="role-name">: ' . role_get_name($role, $context) . '</span>';
                     }
                     $loggedinas .= $rolename;
                     $url = new moodle_url('/course/switchrole.php', array('id' => $course->id, 'sesskey' => sesskey(), 'switchrole' => 0, 'returnurl' => $this->page->url->out_as_local_url(false)));
                     $loggedinas .= html_writer::tag('a', get_string('switchrolereturn'), array('href' => $url));
                 } else {
                     $loggedinas .= " <small>(</small> <a href=\"{$CFG->wwwroot}/login/logout.php?sesskey=" . sesskey() . "\">" . get_string('logout') . '</a> <small>)</small>';
                 }
             }
         } else {
             if (!$loginpage) {
                 $loggedinas = " <small>(</small> <a href=\"{$loginurl}\">" . get_string('login') . '</a> <small>)</small>';
             }
         }
     }
     $loggedinas = '<div class="logininfo">' . $loggedinas . '</div>';
     if (isset($SESSION->justloggedin)) {
         unset($SESSION->justloggedin);
         if (!empty($CFG->displayloginfailures)) {
             if (!isguestuser()) {
                 if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) {
                     $loggedinas .= '&nbsp;<div class="loginfailures">';
                     if (empty($count->accounts)) {
                         $loggedinas .= get_string('failedloginattempts', '', $count);
                     } else {
                         $loggedinas .= get_string('failedloginattemptsall', '', $count);
                     }
                     if (file_exists("{$CFG->dirroot}/report/log/index.php") and has_capability('report/log:view', context_system::instance())) {
                         $loggedinas .= ' <a href="' . $CFG->wwwroot . '/report/log/index.php' . '?chooselog=1&amp;id=1&amp;modid=site_errors">' . get_string('logs') . '</a>';
                     }
                     $loggedinas .= '</div>';
                 }
             }
         }
     }
     return $loggedinas;
 }