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

include_once($_SERVER['DOCUMENT_ROOT'].'/inc/core.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/session.php');

$mdb2->loadModule('Manager');

// Construct page
$content['windowTitle'] = 'Nuke the Phoebe database' . ' | ' . $CNF->appName;
$content['settings'] = '';
$content['main'] = "<h1>Nuke the Phoebe database</h1>\n";

if($_POST['reallySure'] == "yes") {
    $content['main'] .= "<p>Dropping tables:</p>\n";
    $content['main'] .= '<ul>';
    foreach ($mdb2->listTables() as $table) {
        $affected = $mdb2->dropTable($table);
        $content['main'] .= "<li>$table</li>\n";
    }
    $content['main'] .= '</ul>';
    
    // Always check that result is not an error
    if (PEAR::isError($affected)) {
        die($affected->getMessage());
    } else {
        $content['main'] .= "<p>Done</p>\n";
    }
} else {
    $content['main'] .= '<form action="" method="POST"><dl><dt>Really delete <strong>all</strong> data with no hope of recovery?</dt>';
    $content['main'] .= '<dd><label>Yes, I\'m really sure: <input type="checkbox" name="reallySure" value="yes"></label></dd>';
    $content['main'] .= '<dd><input type="submit" value="Delete everything"></dd>';
    $content['main'] .= '</dl></form>';
}

$content['main'] .= '<p><a href="nuke.php">Nuke page</a>.</p>';
$content['main'] .= '<p><a href="/install.php">Install page</a>.</p>';

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