<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html<?php echo $direction ?>>
<head>
    <?php echo $meta ?>
    <meta name="keywords" content="moodle, <?php echo $title ?> " />
    <title><?php echo $title ?></title>
    <link rel="shortcut icon" href="<?php echo $CFG->themewww .'/'. current_theme() ?>/favicon.ico" />

    <?php include("$CFG->javascript"); ?>

    <?php

        global $PAGE;

        if (function_exists('is_in_popup')) {
            $inpopup = is_in_popup();
        } else {
            $inpopup = false;
        }

        // handle pages which get displayed wrong
        // either no custom corners or too much

        // all admin pages are build with the layout-table: sideblocks and content
        if (!empty($PAGE) && ($PAGE->type == 'admin') && (strstr($bodytags, ' nocoursepage'))) {
            $bodytags = str_replace(' nocoursepage', '', $bodytags);
        }

        // list of pages using the layout-table to be able to view sideblocks
        $excludelist = array('mod-chat-view', 'mod-data-view', 'mod-quiz-view',
            'my-index');

        if (!empty($PAGE) && (in_array($PAGE->type, $excludelist)) &&
            (strstr($bodytags, ' nocoursepage'))) {
            $bodytags = str_replace(' nocoursepage', '', $bodytags);
        }

        // add 'nocoursepage' to the list of CLASSes on several pages
        if (strpos($bodytags, 'nocoursepage') === false) {
            $includelist = array('admin-roles-assign', 'admin-roles-override', 
                'mod-data-view');
            preg_match('/id="([^"]*)"/i', $bodytags, $ids);
            if (in_array($ids[1], $includelist)) {
                // exclude roles called from the admin area (courseid 1)
                // include user roles for the Moodle user settings called
                // from the start page
                if (($COURSE->id > 1) || ($_GET['contextid'] == 30)) {
                    preg_match('/class="([^"]*)"/i', $bodytags, $classes);
                    $classlist = explode (' ', $classes[1]);
                    if (!in_array('nocoursepage', $classlist)) {
                        array_push($classlist, 'nocoursepage');
                        $bodytags = str_replace($classes[0],
                            'class="'.implode(' ', $classlist).'"', $bodytags);
                    }
                }
            }
        }
    ?>
</head>

<body<?php
    echo " $bodytags";
    if ($focus) {
        echo " onload=\"setfocus()\"";
    };
    ?>>

    <?php if(!empty($infooutput)) { ?>
        <div id="infowrapper"><div id="infooverlay"><?php echo $infooutput; ?></div></div>
    <?php } ?>
<div id="page"<?php echo (' class="'.(($inpopup) ? 'inpopup' : 'notinpopup').'"'); ?>>

<?php if (!$inpopup) {
    if ($home) {  // This is what gets printed on the home page only
?>
    <?php print_container_start(true, '', 'header-home'); ?>
        <div class="wraphome clearfix">
            <h1 class="headermain"><?php echo $heading ?></h1>
            <div class="headermenu"><?php echo $menu ?></div>
        </div>
    <?php print_container_end(); ?>
<?php } else if ($heading) {  // This is what gets printed on any other page with a heading
?>
    <?php print_container_start(true, '', 'header'); ?>
        <h1 class="headermain"><?php echo $heading ?></h1>
        <div class="headermenu"><?php echo $menu ?></div>
    <div class="navbar clearfix">
    <?php if ($navigation) { // This is the navigation table with breadcrumbs
    ?>
        <div class="breadcrumb"><?php print_navigation($navigation); ?></div>
        <div class="navbutton"><?php echo $button; ?></div>
    <?php } ?>
    </div>
    <?php print_container_end(); ?>
<?php }
}
?>
    <!-- END OF HEADER -->
<?php print_container_start(true, false, 'content'); ?>
