Location: PHPKode > projects > HypatiaDB > hypatiadb/maintenance.php
<?php
include("common_db.php");
include("functions.php");
dbconnect($host, $username, $password); //from common_db.php
$strings = loadStrings($lang, 'MAINT');


headers();
html();
head($strings['MAINT_HEADING']);
menu();
navpane();

//check for permissions
if($_SESSION['session_user_status']!='admin') {
	printAuthError();
	//we should be dead by now, but let's die again anyway
	die();
}

//check if we need to do something
if(isset($_REQUEST['action'])) {
	include('includes/maint.php');
	switch($_REQUEST['action']) {
		case 'opt':
			$result = optimise_table($_REQUEST['db'], $_REQUEST['tbl']);
			if(is_string($result)) {
				$out = sprintf($strings['MAINT_OPTIMISEFAILED'], $result);
			} else {
				$out = '<h2>' . sprintf($strings['MAINT_OPTIMISERESULTS'], "$_REQUEST[db].$_REQUEST[tbl]") . '</h2><ul>';
				while($row=mysql_fetch_array($result)) {
					$out .= "<li>$row[Msg_type]: $row[Msg_text]</li>";
				}
				$out .= "</ul>";
			}
		break;
		case 'an':
			$result = analyse_table($_REQUEST['db'], $_REQUEST['tbl']);
			if(is_string($result)) {
				$out = sprintf($strings['MAINT_ANALYSEFAILED'], $result);
			} else {
				$out = '<h2>' . sprintf($strings['MAINT_ANALYSERESULTS'], "$_REQUEST[db].$_REQUEST[tbl]") . '</h2><ul>';
				while($row=mysql_fetch_array($result)) {
					$out .= "<li>$row[Msg_type]: $row[Msg_text]</li>";
				}
				$out .= "</ul>";
			}
		break;
		case 'check':
			$result = check_table($_REQUEST['db'], $_REQUEST['tbl']);
			if(is_string($result)) {
				$out = sprintf($strings['MAINT_CHECKFAILED'], $result);
			} else {
				$out = '<h2>' . sprintf($strings['MAINT_CHECKRESULTS'], "$_REQUEST[db].$_REQUEST[tbl]") . '</h2><ul>';
				while($row=mysql_fetch_array($result)) {
					$out .= "<li>$row[Msg_type]: $row[Msg_text]</li>";
				}
				$out .= "</ul>";
			}
		break;
		case 'repair':
			$result = repair_table($_REQUEST['db'], $_REQUEST['tbl']);
			if(is_string($result)) {
				$out = sprintf($strings['MAINT_REPAIRFAILED'], $result);
			} else {
				$out = '<h2>' . sprintf($strings['MAINT_REPAIRRESULTS'], "$_REQUEST[db].$_REQUEST[tbl]") . '</h2><ul>';
				while($row=mysql_fetch_array($result)) {
					$out .= "<li>$row[Msg_type]: $row[Msg_text]</li>";
				}
				$out .= "</ul>";
			}
		break;
	}
}

?>
	<div id="mainpane">
		<?php echo($strings['MAINT_INTRO']); ?>
<?
if(isset($out)) {
	echo $out;
}

echo('<table class="browse">');
//get a list of databases and then the tables within them
$sql = "SHOW DATABASES";
$databases = mysql_query($sql);

while($db = mysql_fetch_array($databases)) {
	if($db[0] != 'mysql' && $db[0] != 'HypatiaDB' && $db[0] != 'information_schema') {
	echo("<tr class=\"firstrow\"><th colspan=\"5\">$db[0]</th></tr>");
	$sql = "SHOW TABLES IN `$db[0]`";

	$tables = mysql_query($sql);
	while($table = mysql_fetch_array($tables)) {
		echo("<tr><td class=\"firstcol\">$table[0]</td><td><a href=\"maintenance.php?action=opt&amp;db=" . htmlspecialchars($db[0]) . "&amp;tbl=" . htmlspecialchars($table[0]) . "\">$strings[MAINT_OPTIMISE]</a></td><td><a href=\"maintenance.php?action=an&amp;db=" . htmlspecialchars($db[0]) . "&amp;tbl=" . htmlspecialchars($table[0]) . "\">$strings[MAINT_ANALYSE]</a></td><td><a href=\"maintenance.php?action=check&amp;db=" . htmlspecialchars($db[0]) . "&amp;tbl=" . htmlspecialchars($table[0]) . "\">$strings[MAINT_CHECK]</a></td><td><a href=\"maintenance.php?action=repair&amp;db=" . htmlspecialchars($db[0]) . "&amp;tbl=" . htmlspecialchars($table[0]) . "\">$strings[MAINT_REPAIR]</a></td></tr>");
	}
	}
}

?>
</table>
	</div>
<?php
endhtml();
?>
Return current item: HypatiaDB