Location: PHPKode > projects > DantoBB > DantoBB_1-0/sources/admin_sqltoolbox.php
<?php

/*
	Copyright (C) 2009 DantoBB Team
	http://www.dantobb.com
*/

/**
 * ACP SQL toolbox
 *
 * Gives an interface to execute SQL queries and basic database maintenance.
 *
 * @author	DantoBB Team
 * @link	http://www.dantobb.com
 * @license	GPL-2
 * @version	$Revision: 1.0 $
 * @copyright	Copyright (C) 2009 DantoBB Team
 * @package	DantoBB
 * @subpackage	ACP
 */

//
// Die when called directly in browser
//
if ( !defined('INCLUDED') )
	exit();

if ( isset($_POST['warned']) )
	$_SESSION['sqltoolbox_warned'] = true;

if ( !isset($_SESSION['sqltoolbox_warned']) ) {
	
	$content = '<h2>'.$lang['SQLToolboxWarningTitle'].'</h2><p><strong>'.$lang['SQLToolboxWarningContent'].'</strong></p>';
	$content .= '<form action="'.$functions->make_url('admin.php', array('act' => 'sqltoolbox')).'" method="post">';
	$content .= '<p class="submit"><input type="submit" name="warned" value="'.$lang['OK'].'" /></p></form>';
	
} else {
	
	$content = '<h2>'.$lang['SQLToolboxExecuteQuery'].'</h2><p>'.$lang['SQLToolboxExecuteQueryInfo'].'</p>';
	
	if ( !empty($_POST['query']) ) {
		
		$result = $db->query(stripslashes($_POST['query']), true);
		
		if ( is_resource($result) || is_object($result) ) {
			
			$results = array();
			while ( $out = $db->fetch_result($result) )
				$results[] = $out;
			ob_start();
			print_r($results);
			$results = ob_get_contents();
			ob_end_clean();
			$results = unhtml(stripslashes(trim($results)));
			$content .= '<p><textarea rows="5" cols="50" readonly="readonly" id="resultset">'.$results.'</textarea></p>';
			
		} elseif ( $result === true ) {
			
			$content .= '<p>'.$lang['SQLToolboxExecutedSuccessfully'].'</p>';
			
		} else {
			
			$content .= '<p><strong>'.unhtml($result).'.</strong></p>';
			
		}
		
	} else {
		
		$_POST['query'] = '';
		
	}
	
	$content .= '<form action="'.$functions->make_url('admin.php', array('act' => 'sqltoolbox')).'" method="post">';
	$content .= '<ul id="adminsqlbuttons">';
	foreach ( $functions->get_dantobb_tables() as $table )
		$content .= '<li><a href="javascript:insert_table(\''.$table.'\')">'.$table.'</a></li> ';
	$content .= '</ul>';
	$content .= '<p><textarea name="query" id="tags-txtarea" rows="5" cols="50">'.unhtml(stripslashes($_POST['query'])).'</textarea></p>';
	$content .= '<p class="submit"><input type="submit" value="'.$lang['SQLToolboxExecute'].'" /> <input type="reset" value="'.$lang['Reset'].'" /></p></form>';
	
	$content .= '<h2>'.$lang['SQLToolboxMaintenance'].'</h2><p>'.$lang['SQLToolboxMaintenanceInfo'].'</p><ul id="adminfunctionsmenu">';
	
	if ( !empty($_GET['do']) && $_GET['do'] == 'repair' ) {
		
		$db->query("REPAIR TABLE ".join(', ', $functions->get_dantobb_tables()));
		$content .= '<li>'.$lang['SQLToolboxRepairTables'].': '.$lang['Done'].'</li> ';
		
	} else {
		
		$content .= '<li><a href="'.$functions->make_url('admin.php', array('act' => 'sqltoolbox', 'do' => 'repair')).'">'.$lang['SQLToolboxRepairTables'].'</a></li> ';
		
	}
	
	if ( !empty($_GET['do']) && $_GET['do'] == 'optimize' ) {
		
		$db->query("OPTIMIZE TABLE ".join(', ', $functions->get_dantobb_tables()));
		$content .= '<li>'.$lang['SQLToolboxOptimizeTables'].': '.$lang['Done'].'</li> ';
		
	} else {
		
		$content .= '<li><a href="'.$functions->make_url('admin.php', array('act' => 'sqltoolbox', 'do' => 'optimize')).'">'.$lang['SQLToolboxOptimizeTables'].'</a></li> ';
		
	}
	
	$content .= '</ul><p>'.$lang['SQLToolboxMaintenanceNote'].'</p>';
	
}

$admin_functions->create_body('sqltoolbox', $content);

?>
Return current item: DantoBB