Location: PHPKode > projects > WB News > admin/db_backup.php
<?php

/*========================================================*\
||########################################################||
||#                                                      #||
||#     WB News v2.0.0                                   #||
||# ---------------------------------------------------- #||
||#     Copyright (c) 2004-2007                          #||
||#     Created: 24th August 2005                        #||
||#     Filename: user.php                               #||
||#                                                      #||
||########################################################||
/*========================================================*/

/**
 *  @author $Author: pmcilwaine $
 *	@version $Id: db_backup.php,v 1.1.2.2 2008/06/21 03:21:27 pmcilwaine Exp $
 */

require_once( "global.php" );
require_once( INCDIR . "/backup.php" );
// require_once( INCDIR . "/restore_database.php" );

$auth->login_if( !$auth->has_perm("canbackup") );

$_SESSION["return_page"] = make_url();

$page = new PageTemplateEngine( BuildPath("admin/main-page.ihtml") );
$tmpl->SetFilename( BuildPath("admin/backup_main.ihtml") );

$params = array(
	"entry" => "\t<li>%s</li>\n\t",
	"separator" => FALSE,
	"class_open" => "open",
	"links" => toolbarmenu()
	);
$toolbar = include( INCDIR . "/page-menu.php" );

$page->AddParam( "toolbar", $toolbar );
$page->AddParam( "userinfo", $userinfo );

$myform = "backup";

if ( $_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["form"]) && $_POST["form"] == $myform )
{

	$err_msg = array();

	switch ( Submit() )
	{
	case "Backup":
		
		$backup =  sanitize_post( "backup" );
		if ( !in_array( $backup, array( "sql", "xml" ) ) )
		{
			$err_msg["backup"] = "Invalid backup option";
		}
		
		if ( count($err_msg) > 0 )
		{
			$_SESSION["formdata"] = $_POST;
			$_SESSION["err_msg"] = $err_msg;
			redirect( make_url() );
			exit;
		}

		$backup = new backup( $backup );
		$backup->SendFIle();
		exit;
	case "Restore":

		/**
		 * The database restoration was disabled, there is still quite a lot of work involved
		 * but due to time constraints was not able to be completed before release.
		 */
		redirect( make_url() );
		exit;
		
		$overwrite = array_key_exists( "overwrite", $_POST );
		
		header( "Content-Type: text/plain" );
		
		if ( !file_exists($_FILES["restore"]["tmp_name"]) )
		{
			$err_msg["restore"] = "File was not uploaded.";
		}
		
		if ( "text/xml" != $_FILES["restore"]["type"] )
		{
			$err_msg["restore"] = "Invalid file type must be XML";
		}
		
		if ( !move_uploaded_file( $_FILES["restore"]["tmp_name"], $config["installdir"] . "/tmp/" . $_FILES["restore"]["name"] ) )
		{
			$err_msg["restore"] = "Couldn't move file please upload again";
		}
		
		$restore = new RestoreDatabase( $config["installdir"] . "/tmp/" . $_FILES["restore"]["name"] );
		$restore->Parse();
		
		if ( NULL != $restore->err_msg )
		{
			$err_msg["restore"] = $restore->err_msg;
		}
		
		if ( count($err_msg) > 0 )
		{
			$_SESSION["formdata"] = $_POST;
			$_SESSION["err_msg"] = $err_msg;
			redirect( make_url() );
			exit;
		}
		
		if ( !$restore->RestoreData() )
		{
			$err_msg["restore"] = $restore->err_msg;
			$_SESSION["formdata"] = $_POST;
			$_SESSION["err_msg"] = $err_msg;
			redirect( make_url() );
			exit;
		}

		exit;
	default:
		exit;
	}

}

$formdata =& $tmpl->AddParam( "formdata", array() );
$options =& $tmpl->AddParam( "options", array() );

$formdata["hidden"] = array(
	"form" => $myform
	);

$options["backup"] = array(
	"sql" => "SQL",
	"xml" => "XML"
	);

$formdata["backup"] = NULL;
$formdata["overwrite"] = NULL;

$tmpl->AddParam( "backup", "Backup" );
$tmpl->AddParam( "restore", "Restore" );

$pagemenu =& $tmpl->AddParam( "pagemenu", array() );
$page->BindParam( "pagemenu", $tmpl );

$params = array(
	"entry" => "\t<li>%s</li>\n\t",
	"separator" => "\t<li>|</li>\n\t",
	"links" => buildmenu( $theme_info["pagemenu_build"] )
	);
$params = array_merge( $params, $theme_info["pagemenu"] );
$pagemenu = include( INCDIR . "/page-menu.php" );

if ( isset($_SESSION["formdata"]) )
{
	if ( isset($_SESSION["err_msg"]) )
	{
		$tmpl->AddParam( "msg", $_SESSION["err_msg"] );
	}
	
	unset( $_SESSION["formdata"], $_SESSION["err_msg"] );
}

$page->ParseContent( $tmpl->GetHTML() );
$page->ShowPage();

?>
Return current item: WB News