<?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,desMetaEdit,manager';
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');

// Construct page
$content['windowTitle'] = 'Designs by '.$userName.' | Phoebe — pedagogic planner';
$content['main'] .= '<h1 id="mainTitle"><a href="/" class="titleLink">Phoebe</a></h1>';
$content['main'] .= $topNav;
$content['main'] .= '<h2>Designs by '.$userName.'</h2>';
$content['main'] .= '<p id="quickDesc">Manage your designs here...</p>';


// Get all designs for this user
$sql = 'SELECT * FROM designs '.
       ' LEFT OUTER JOIN users'.
       ' ON designs.owner_id = users.user_id '.
       'WHERE owner_id = '.$user_id.
       ' AND is_template = 0'.
       ' ORDER BY title';
//echo $sql.'<br>';
$designs = $mdb2->queryAll($sql);
if (PEAR::isError($designs)) {
    die($designs->getMessage());
}

// Get all details of default design
$sql = 'SELECT title FROM designs '.
       'WHERE design_id = '.$_SESSION['userprefs']['pref_default_template_id'];
//echo $sql.'<br>';
$defaultDesign = $mdb2->queryRow($sql);
if (PEAR::isError($defaultDesign)) {
    die($defaultDesign->getMessage());
}



$content['main'] .= '<h3>Your designs</h3>';
if ($designs) {
    // Layout all templates and designs in tables
    foreach($designs as $design) {
        $designSection .= designSummary($design);
    }
    $content['main'] .= $designSection;
} else {
    $content['main'] .= '<p>You have not created any designs yet.</p>';
}

$content['main'] .= '<br/><h3>Create a new design</h3>';
$content['main'] .= '<ul><li>Create a <a href="/createDesign.php?newFromTemplate=1&amp;clone='.$_SESSION['userprefs']['pref_default_template_id'].'">new design <img src="/inc/img/new.gif" alt="Create new standard design" height="16" width="16"></a> from the default template (<i>'.$defaultDesign['title'].'</i>).</li>';
$content['main'] .= '<li>Choose a <a href="/templates.php">different template</a> for your new design.</li>';
$content['main'] .= '<li>Find an <a href="/sharedDesigns.php">existing design</a> to start from.</li>';
$content['main'] .= '<li><a href="/importDesign.php">Import a design</a> from XML.</li></ul>';

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