<?php
/**
 * Phoebe pedagogic planner
 *
 * PHP version 5
 *
 * LICENSE: The GNU General Public License (GPL), version 2. See LICENSE.txt
 *
 * Copyright (c) 2006-2008 JISC/HEFCE/University of Oxford
 *
 * @author      David Balch <david.balch@conted.ox.ac.uk>
 * @license     http://opensource.org/licenses/gpl-license.php GPL2
 * @link        http://phoebe-project.conted.ox.ac.uk/
 */

// Phoebe page template
header("Content-Type: text/html;charset=utf-8");

// Account navigation
$accountNav = '<div id="accountNav">';
if (isset($_SESSION['openid'])) {
    // Logged in with OpenID
    $accountNav .= 'Logged in as '.$_SESSION['openid'].' | <a href="/account.php">Your account</a> | ';
    $accountNav .= '<a href="/login/logout.php">Logout</a>';
} else if (isset($_SESSION['userid'])) {
    // Logged in with Phoebe
    $sql = 'SELECT login_name FROM users'.
           ' WHERE user_id = '.$mdb2->quote($_SESSION['userid']);
    //echo $sql;

    $user = $mdb2->queryRow($sql);
    if (PEAR::isError($user)) {
        die('Error accessing database - '.$user->getMessage());
    } else {
        $accountNav .= 'Logged in as '.$user['login_name'].' | <a href="/account.php">Your account</a> | ';
        $accountNav .= '<a href="/login/logout.php">Logout</a>';
    }
} else {
    // Not logged in
    $accountNav .= 'You are not logged in | <a href="/login/index.php?curfile='.$_SERVER['PHP_SELF'].'">Register/Login</a>';
}
$accountNav .= ' | <a href="/about/">About Phoebe</a> | <a href="/help/">Help <img src="/inc/img/qmark.gif" alt="" title="Help" width="16" height="16"></a>';
$accountNav .= '</div>';

if (strpos($content['settings'], 'structureEdit') !== false) {
    $pageId = ' id="editTemplate"';
} else if (strpos($content['settings'], 'designEdit') !== false) {
    $pageId = ' id="editDesign"';
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html<?php echo $pageId; ?>>
    <head>
        <title><?php echo $content['windowTitle']; ?></title>
        <link type="text/css" href="/inc/css/p.css" rel="Stylesheet">
        <script type="text/javascript" src="/inc/js/extra.js"> </script>
        <script type="text/javascript" src="/inc/js/jquery.js"> </script>
        <script type="text/javascript" src="/inc/js/jquery.jeditable.js"> </script>

        <script language="javascript" type="text/javascript" src="/firebuglite/firebug/firebug.js"></script>

        <?php 
        if (strpos($content['settings'], 'desMetaEdit') !== false) {
            echo '<script type="text/javascript" src="/inc/tiny_mce/tiny_mce.js"> </script>';
        }

        if (strpos($content['settings'], 'manager') !== false || strpos($content['settings'], 'loginpage') !== false) {
            // Phoebe Design management functionality includes ?>
            <script type="text/javascript" src="/inc/js/pCommon.js"> </script>
        <?php }
        if (strpos($content['settings'], 'userAcEdit') !== false || strpos($content['settings'], 'desMetaEdit') !== false) {
            // Phoebe preference editing ?>
            <script type="text/javascript" src="/inc/js/metaEdit.js"> </script>
        <?php }

        if (strpos($content['settings'], 'designEdit') !== false) {
            // Phoebe editing functionality-only includes ?>
            <link type="text/css" href="/inc/css/pFrames.css" rel="Stylesheet">
            <link type="text/css" href="/inc/css/pFunct.css" rel="Stylesheet">

            <script type="text/javascript" src="/inc/tiny_mce/tiny_mce.js"> </script>
            <script type="text/javascript" src="/inc/js/interface.js"> </script>
            <script type="text/javascript" src="/inc/js/pCommon.js"> </script>
            <script type="text/javascript" src="/inc/js/pEditDes.js"> </script>

        <?php } else if (strpos($content['settings'], 'structureEdit') !== false) {
            // Phoebe structure editing functionality-only includes ?>
            <link type="text/css" href="/inc/css/pFrames.css" rel="Stylesheet">
            <link type="text/css" href="/inc/css/pFunct.css" rel="Stylesheet">

            <script type="text/javascript" src="/inc/tiny_mce/tiny_mce.js"> </script>
            <script type="text/javascript" src="/inc/js/interface.js"> </script>
            <script type="text/javascript" src="/inc/js/pCommon.js"> </script>
            <script type="text/javascript" src="/inc/js/pEditStruc.js"> </script>

        <?php } else if (strpos($content['settings'], 'browse') !== false) {
            // Phoebe editing functionality-only includes ?>
            <link type="text/css" href="/inc/css/pBrowse.css" rel="Stylesheet">

        <?php } if (strpos($content['settings'], 'admin') !== false || strpos($content['settings'], 'startEdit') !== false) {
            // Admin only ?>
            <link type="text/css" href="/inc/css/admin.css" rel="Stylesheet">
        <?php } ?>

        <?php if (strpos($content['settings'], 'view') !== false) {
            // Phoebe Design management functionality includes ?>
            <link type="text/css" href="/inc/css/pView.css" rel="Stylesheet">
        <?php } ?>
        <link type="text/css" href="/inc/css/print.css" rel="Stylesheet" media="print">
        <!--[if IE 6]>
            <link rel="stylesheet" type="text/css" href="/inc/css/ie6.css" />
        <![endif]-->
        <!--[if IE 7]>
            <link rel="stylesheet" type="text/css" href="/inc/css/ie7.css" />
        <![endif]-->

    </head>

    <?php
        echo '<body>';
        if (strpos($content['settings'], 'startEdit') === false) {
            echo $accountNav;
        }
        echo $content['main']; ?>
        <?php if (strpos($content['settings'], 'edit') == false) { ?>
        <div id="footer">
            <a href="http://www.ox.ac.uk/" id="oxCrest"><img src="/inc/img/oxCrest.png" width="75" height="75" alt="University of Oxford crest"></a>
            <a href="http://www.jisc.ac.uk/" id="jiscLogo"><img src="/inc/img/jiscLogo.png" width="75" height="75" alt="JISC logo"></a>
            &copy; 2006-<?php print(date("Y",time())); ?> University of Oxford.
        </div>
        <?php } ?>
    </body>
</html>