Location: PHPKode > projects > HypatiaDB > hypatiadb/dbdelete.php
<?php

//Notes:
//This page checks to find the db to delete in the
//'db' $_REQUEST arg, then the $_SESSION['current_db']
//or finally be asking the user.
//In the first two cases, it prompts first.

include("common_db.php");
include("functions.php");

dbconnect($host, $username, $password); //from common_db.php
$strings = loadStrings($lang, 'DELDB');
headers();
html();
head($strings['DDB_TITLE']);

if(isset($_REQUEST['db'])) {
	$db = mysql_real_escape_string($_REQUEST['db']);
} else if ($_SESSION['current_db'] != '') {
	$db = mysql_real_escape_string($_SESSION['current_db']);
}

if(isset($_REQUEST['confirm']) && isset($db)) {		//do we have confirmation?
	$confirm = true;
} else {
	$confirm = false;
}

if($confirm && ($_SESSION['session_user_status'] == 'normal' || $_SESSION['session_user_status'] == 'admin')) {	
									//we need to do the check up here
	$query = "DROP DATABASE IF EXISTS `$db`";			//otherwise the navpane will still
									//have the old db in it
	if(mysql_query($query))
		$db_deleted = true;
	else
		$db_deleted = false;
	
	$_SESSION['current_db'] = '';			//non existant dbs can't be selected!
}

menu();
navpane();

echo('<div id="mainpane">');



if(isset($db_deleted)) {

	if($db_deleted)
		printf("<p>$strings[DDB_SUCCESS]</p>", $db);
	else
		printf("<p>$strings[DDB_FAILED]</p>", mysql_error());
} else {
	if(isset($db)) {		//print out confirmation form
		if($_SESSION['session_user_status'] == 'normal' || $_SESSION['session_user_status'] == 'admin') {
?>
<form action="dbdelete.php" method="post">
	<p class="alert"><?php printf($strings['DDB_AREYOUSURE'], $db); ?></p>
	<input type="submit" name="confirm" value="<?php echo($strings['DDB_CONFSUBMIT']); ?>" />
</form>
<?php
		} else {		//not authorised
echo("<p class=\"error\">$strings[DDB_ERR_PERMISSIONS]</p>");
		}
	} else {		//we need to prompt for the name of the database
?>
<p class="alert"><?php echo($strings['DDB_CHOOSEDB']); ?></p>
<form action="dbdelete.php" method="post" class="standalone lblock">
	<label for="db"><?php echo($strings['DDB_DB']) ?><select name="db">
<?php
	echo(listDbs('<option value="%1$s">%1$s</option>'));
?>
</select></label>
	<input type="submit" name="confirm" value="<?php echo($strings['DDB_QRYSUBMIT']); ?>" />
</form>
<?php
	}
}

echo("</div>");

endhtml();

?>
Return current item: HypatiaDB