<?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'] = 'manager,dbWrite,userAcEdit';
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/core.php');
include_once($_SERVER['DOCUMENT_ROOT']."/inc/utils.php");
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/session.php');

$sql = 'SELECT * FROM designs '.
       ' LEFT OUTER JOIN users'.
       ' ON designs.owner_id = users.user_id '.
       'WHERE is_template = 1'.
       ' AND (owner_id = '.$user_id.' OR share_level > 0)'.
       ' ORDER BY title';
//echo $sql;

$designs = $mdb2->queryAll($sql);
if (PEAR::isError($designs)) {
    die($designs->getMessage());
}

if ($designs) {
    // Layout each designs in a block
    foreach($designs as $design) {
        if($design['owner_id'] == $user_id) {
            $myTemplateSection .= designSummary($design);
        } else {
            $otherTemplatesSection .= designSummary($design);
        }
    }
} else {
    $designsTable .= '<p>There are no shared designs.</p>';
}

// Construct page
$content['windowTitle'] = 'Templates | Phoebe — pedagogic planner';
$content['main'] = '<h1 id="mainTitle"><a href="/" class="titleLink">Phoebe</a></h1>';
$content['main'] .= $topNav;
$content['main'] .= '<h2>Templates</h2>';

$content['main'] .= '<p id="quickDesc">View, create and manage learning design templates.</p>';

$content['main'] .= '<h3>Your templates</h3>';
$content['main'] .= $myTemplateSection;
$content['main'] .= '<br>';
$content['main'] .= '<h3>Others\' templates</h3>';
$content['main'] .= $otherTemplatesSection;

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