<?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/
 */

$content['settings'] = 'dbWrite,designEdit';
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/core.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/utils.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/session.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/user.php');

if(ctype_digit($_GET['design_id'])) {
    $design_id = $_GET['design_id'];
}

// Get info for this design
$sql = 'SELECT * FROM designs '.
       'WHERE design_id = '.$mdb2->quote($_GET['design_id']);
//echo $sql.'<br>';
$design = $mdb2->queryRow($sql);
if (PEAR::isError($design)) {
    die($design->getMessage());
}

// Sanitize
foreach($design as $name=>$val) {
    $html[$name] = htmlspecialchars($val);
}

// Get field types
$sql = 'SELECT * FROM field_types';
$field_types = $mdb2->queryAll($sql);
if (PEAR::isError($field_types)) {
    die($field_types->getMessage());
}
$newFieldTypeSelect = '<label>Field type <select id="fieldType">';
foreach($field_types as $type) {
    $newFieldTypeSelect .= ' <option title="'.$type['description'].'" value="'.$type['field_type_id'].'">'.$type['field_type_name'].'</option>';
}
$newFieldTypeSelect .= '</select></label>';
unset($field_types);

if ($user['pref_show_des_start_page']) {
    $guidancePage = 'startEditing.php';
} else {
    $guidancePage = 'http://phoebe-guidance.conted.ox.ac.uk/cgi-bin/trac.cgi/wiki/PhoebePh2Contents';
}

// Data area
$content['windowTitle'] = 'Design editor' . ' | ' . $CNF->appName;
$content['main'] = '<div id="unsupportedMsg">
        <h1>Phoebe pedagogic planner</h1>
        <p>Sorry, your browser configuration is not supported at this time.
        We recommend a current version of <a href="http://www.mozilla.com/">Firefox</a> with Javascript enabled.</p>
    </div>
    <div id="phoebeArea" class="hidden">';

$content['main'] .= '
        <!-- Toolbar -->
        <div id="phoebeToolbar">
            <h1 id="editorTitle"><a href="/" class="titleLink" title="Return to the Phoebe homepage">Phoebe</a> : <a href="/designs.php" title="Return to your designs">Your designs</a> : '.$design['title'].'</h1>
            <ul class="buttons">
                <li class="sepButtons"><div id="outlineContainer" class="hidden"><div id="oviewTrig">Outline <img width="16" height="16" src="/inc/img/arrow-d.gif" alt="Open below"/></div></div></li>
                <li class="sepButtons"><a href="http://phoebe-guidance.conted.ox.ac.uk/cgi-bin/trac.cgi/wiki/PhoebePh2Contents" target="guidanceAreaContent"><img width="16" height="16" src="/inc/img/book.gif" alt="View guidance" title="View guidance"/></a></li>
                <li class="sepButtons"><a href="/view/viewDesign.php?design_id='.$design_id.'"><img width="16" height="16" src="/inc/img/view.gif" alt="View design" title="View design"/></a></li>
                <li><a href="#" onclick="changeLayout(0); return false;"><img width="16" height="16" src="/inc/img/split-h.gif" alt="Split view horizontally" title="Split view horizontally"/></a></li>
                <li><a href="#" onclick="changeLayout(1); return false;"><img width="16" height="16" src="/inc/img/split-v.gif" alt="Split view vertically" title="Split view vertically"/></a></li>
                <li><a href="#" onclick="changeLayout(2); return false;"><img width="16" height="16" src="/inc/img/controls-max.gif" alt="Maximise controls" title="Maximise controls"/></a></li>
                <li class="sepButtons"><a href="#" onclick="changeLayout(3); return false;"><img width="16" height="16" src="/inc/img/content-max.gif" alt="Maximise guidance" title="Maximise guidance"/></a></li>
                <li><a href="/help/" target="phoebeHelp"><img src="/inc/img/qmark.gif" alt="" title="Help" width="16" height="16"></a></li>
            </ul>
        </div>';

$content['main'] .= '
        <div id="phoebeMain">

            <!-- Controls area -->
            <div id="controlsArea">
                <div id="controlsAreaTitleBar" class="titlebar hidden"></div>
                <div id="controlsAreaScroll">
                    <div id="controlsAreaContent">
                        <div id="designMeta">
                        </div>

                        <div id="designRoot" class="node">
                        </div>

                        <div id="hiddenNodes" class="hidden">
                            <h2>Hidden fields:</h2>
                            <span id="noHidden">There are no hidden fields.</span>
                        </div>
                    </div>
                </div>
                <div id="controlsAreaStatusBar" class="statusBar hidden"></div>
            </div>

            <div id="splitBar"> </div>

            <!-- guidance material area -->
            <div id="guidanceArea">
                <div id="guidanceAreaTitleBar" class="titlebar hidden"></div>
                    <div id="guidanceAreaScroll">
                        <iframe id="guidanceAreaContent" name="guidanceAreaContent" src="'.$guidancePage.'" width="100%" height="100%"> </iframe>
                    </div>
                <div id="guidanceAreaStatusBar" class="statusBar hidden"></div>
            </div>

            <div id="mask" class="hidden"> </div>
        </div>

    </div>';

// Write via template
include_once($CNF->template);
?>
