2001-07-13 16:25:12 +00:00
< ? php
/***************************************************************************
2001-08-30 22:20:23 +00:00
* admin_db_utilities . php
2001-07-13 16:25:12 +00:00
* -------------------
* begin : Thu May 31 , 2001
2001-08-30 22:20:23 +00:00
* copyright : ( C ) 2001 The phpBB Group
* email : support @ phpbb . com
*
2001-07-13 16:25:12 +00:00
* $Id $
2001-08-30 22:20:23 +00:00
*
2001-07-13 16:25:12 +00:00
****************************************************************************/
2001-08-30 22:20:23 +00:00
/***************************************************************************
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
***************************************************************************/
2001-07-13 16:25:12 +00:00
/***************************************************************************
* We will attempt to create a file based backup of all of the data in the
* users phpBB database . The resulting file should be able to be imported by
* the db_restore . php function , or by using the mysql command_line
*
* Some functions are adapted from the upgrade_20 . php script and others
* adapted from the unoficial phpMyAdmin 2.2 . 0.
***************************************************************************/
if ( $setmodules == 1 )
{
$filename = basename ( __FILE__ );
2001-07-14 20:00:27 +00:00
$module [ 'General' ][ 'Backup_DB' ] = $filename . " ?perform=backup " ;
$module [ 'General' ][ 'Restore_DB' ] = $filename . " ?perform=restore " ;
2001-07-13 16:25:12 +00:00
return ;
}
2001-08-03 13:16:59 +00:00
//
2001-10-14 15:46:53 +00:00
// Load default header
2001-08-03 13:16:59 +00:00
//
2001-10-14 15:46:53 +00:00
$phpbb_root_dir = " ./../ " ;
$no_page_header = TRUE ;
require ( 'pagestart.inc' );
include ( $phpbb_root_path . 'includes/sql_parse.' . $phpEx );
2001-08-03 13:16:59 +00:00
2001-07-14 20:00:27 +00:00
//
// Set VERBOSE to 1 for debugging info..
//
define ( " VERBOSE " , 0 );
//
2001-08-30 22:20:23 +00:00
// Increase maximum execution time, but don't complain about it if it isn't
2001-07-13 16:25:12 +00:00
// allowed.
2001-07-14 20:00:27 +00:00
//
2001-09-18 19:01:58 +00:00
@ set_time_limit ( 1200 );
2001-07-13 16:25:12 +00:00
2001-10-14 15:46:53 +00:00
// -----------------------
2001-07-13 16:25:12 +00:00
// The following functions are adapted from phpMyAdmin and upgrade_20.php
//
2001-11-20 20:33:15 +00:00
function gzip_PrintFourChars ( $Val )
{
for ( $i = 0 ; $i < 4 ; $i ++ )
{
$return .= chr ( $Val % 256 );
$Val = floor ( $Val / 256 );
}
return $return ;
}
2001-07-13 16:25:12 +00:00
//
// This function is used for grabbing the sequences for postgres...
2001-07-14 20:00:27 +00:00
//
function pg_get_sequences ( $crlf , $backup_type )
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
global $db ;
2001-08-30 22:20:23 +00:00
$get_seq_sql = " SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*'
2001-07-14 20:00:27 +00:00
AND relkind = 'S' ORDER BY relname " ;
2001-07-13 16:25:12 +00:00
$seq = $db -> sql_query ( $get_seq_sql );
2001-07-14 20:00:27 +00:00
if ( ! $num_seq = $db -> sql_numrows ( $seq ) )
{
2001-07-13 16:25:12 +00:00
$return_val = " # No Sequences Found $crlf " ;
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
else
{
$return_val = " # Sequences $crlf " ;
$i_seq = 0 ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
while ( $i_seq < $num_seq )
{
$row = sql_fetchrow ( $seq );
$sequence = $row [ 'relname' ];
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$get_props_sql = " SELECT * FROM $sequence " ;
$seq_props = $db -> sql_query ( $get_props_sql );
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( $db -> sql_numrows ( $seq_props ) > 0 )
{
$row1 = $db -> sql_fetchrow ( $seq_props );
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( $backup_type == 'structure' )
{
$row [ 'last_value' ] = 1 ;
2001-08-30 22:20:23 +00:00
}
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$return_val .= " CREATE SEQUENCE $sequence start " . $row [ 'last_value' ] . ' increment ' . $row [ 'increment_by' ] . ' maxvalue ' . $row [ 'max_value' ] . ' minvalue ' . $row [ 'min_value' ] . ' cache ' . $row [ 'cache_value' ] . " ; $crlf " ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
} // End if numrows > 0
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if (( $row [ 'last_value' ] > 1 ) && ( $backup_type != 'structure' ))
{
$return_val .= " SELECT NEXTVALE(' $sequence '); $crlf " ;
unset ( $row [ 'last_value' ]);
}
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$i_seq ++ ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
} // End while..
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
} // End else...
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
return $returnval ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
} // End function...
2001-07-14 20:00:27 +00:00
//
2001-08-30 22:20:23 +00:00
// The following functions will return the "CREATE TABLE syntax for the
// varying DBMS's
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
// This function returns, will return the table def's for postgres...
2001-07-14 20:00:27 +00:00
//
function get_table_def_postgres ( $table , $crlf )
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
global $drop , $db ;
2001-07-13 16:25:12 +00:00
$schema_create = " " ;
2001-08-01 15:27:13 +00:00
//
// Get a listing of the fields, with their associated types, etc.
//
2001-07-14 20:00:27 +00:00
$field_query = " SELECT a.attnum, a.attname AS field, t.typename as type, a.attlen AS length, a.atttypmod as lengthvar, a.attnotnull as notnull
FROM pg_class c , pg_attribute a , pg_type t
WHERE c . relname = '$table'
AND a . attnum > 0
AND a . attrelid = c . oid
AND a . attypid = t . oid
ORDER BY a . attnum " ;
2001-07-13 16:25:12 +00:00
$result = $db -> sql_query ( $field_query );
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( ! $result )
{
2001-07-29 23:26:40 +00:00
message_die ( GENERAL_ERROR , " Failed in get_table_def (show fields) " , " " , __LINE__ , __FILE__ , $field_query );
2001-07-13 16:25:12 +00:00
} // end if..
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( $drop == 1 )
{
$schema_create .= " DROP TABLE $table ; $crlf " ;
} // end if
2001-07-14 20:00:27 +00:00
2001-08-01 15:27:13 +00:00
//
// Ok now we actually start building the SQL statements to restore the tables
//
2001-07-13 16:25:12 +00:00
$schema_create .= " CREATE TABLE $table ( $crlf " ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
2001-08-01 15:27:13 +00:00
//
// Get the data from the table
//
2001-07-13 16:25:12 +00:00
$sql_get_default = " SELECT d.adsrc AS rowdefault
2001-07-14 20:00:27 +00:00
FROM pg_attrdef d , pg_class c
2001-08-30 22:20:23 +00:00
WHERE ( c . relname = '$table' )
AND ( c . oid = d . adrelid )
2001-07-14 20:00:27 +00:00
AND d . adnum = " . $row['attnum'] ;
2001-07-13 16:25:12 +00:00
$def_res = $db -> sql_query ( $sql_get_default );
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( ! $def_res )
{
unset ( $row [ 'rowdefault' ]);
2001-07-14 20:00:27 +00:00
}
2001-08-30 22:20:23 +00:00
else
2001-07-13 16:25:12 +00:00
{
$row [ 'rowdefault' ] = @ pg_result ( $def_res , 0 , 'rowdefault' );
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
if ( $row [ 'type' ] == 'bpchar' )
{
// Internally stored as bpchar, but isn't accepted in a CREATE TABLE statement.
$row [ 'type' ] = 'char' ;
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
$schema_create .= ' ' . $row [ 'field' ] . ' ' . $row [ 'type' ];
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( eregi ( 'char' , $row [ 'type' ]))
{
if ( $row [ 'lengthvar' ] > 0 )
{
$schema_create .= '(' . ( $row [ 'lengthvar' ] - 4 ) . ')' ;
2001-07-14 20:00:27 +00:00
}
}
2001-07-13 16:25:12 +00:00
if ( eregi ( 'numeric' , $row [ 'type' ]))
{
$schema_create .= '(' ;
$schema_create .= sprintf ( " %s,%s " , (( $row [ 'lengthvar' ] >> 16 ) & 0xffff ), (( $row [ 'lengthvar' ] - 4 ) & 0xffff ));
$schema_create .= ')' ;
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
if ( ! empty ( $row [ 'rowdefault' ]))
{
$schema_create .= ' DEFAULT ' . $row [ 'rowdefault' ];
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
if ( $row [ 'notnull' ] == 't' )
{
$schema_create .= ' NOT NULL' ;
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
$schema_create .= " , $crlf " ;
2001-07-14 20:00:27 +00:00
}
2001-08-01 15:27:13 +00:00
//
// Get the listing of primary keys.
//
2001-07-14 20:00:27 +00:00
$sql_pri_keys = " SELECT ic.relname AS index_name, bc.relname AS tab_name, ta.attname AS column_name, i.indisunique AS unique_key, i.indisprimary AS primary_key
2001-08-30 22:20:23 +00:00
FROM pg_class bc , pg_class ic , pg_index i , pg_attribute ta , pg_attribute ia
WHERE ( bc . oid = i . indrelid )
AND ( ic . oid = i . indexrelid )
AND ( ia . attrelid = i . indexrelid )
AND ( ta . attrelid = bc . oid )
AND ( bc . relname = '$table' )
AND ( ta . attrelid = i . indrelid )
2001-07-14 20:00:27 +00:00
AND ( ta . attnum = i . indkey [ ia . attnum - 1 ])
ORDER BY index_name , tab_name , column_name " ;
2001-07-13 16:25:12 +00:00
$result = $db -> sql_query ( $sql_pri_keys );
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( ! $result )
{
2001-07-14 20:00:27 +00:00
message_die ( GENERAL_ERROR , " Failed in get_table_def (show fields) " , " " , __LINE__ , __FILE__ , $sql_pri_keys );
}
2001-07-13 16:25:12 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
if ( $row [ 'primary_key' ] == 't' )
{
if ( ! empty ( $primary_key ))
{
$primary_key .= ', ' ;
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
$primary_key .= $row [ 'column_name' ];
$primary_key_name = $row [ 'index_name' ];
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
else
{
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
// We have to store this all this info because it is possible to have a multi-column key...
// we can loop through it again and build the statement
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
$index_rows [ $row [ 'index_name' ]][ 'table' ] = $table ;
$index_rows [ $row [ 'index_name' ]][ 'unique' ] = ( $row [ 'unique_key' ] == 't' ) ? ' UNIQUE ' : '' ;
$index_rows [ $row [ 'index_name' ]][ 'column_names' ] .= $row [ 'column_name' ] . ', ' ;
2001-07-14 20:00:27 +00:00
}
}
2001-07-13 16:25:12 +00:00
if ( ! empty ( $index_rows ))
{
while ( list ( $idx_name , $props ) = each ( $index_rows ))
{
$props [ 'column_names' ] = ereg_replace ( " , $ " , " " , $props [ 'column_name' ]);
$index_create .= 'CREATE ' . $props [ 'unique' ] . " INDEX $idx_name ON $table ( " . $props [ 'column_names' ] . " ); $crlf " ;
2001-07-14 20:00:27 +00:00
}
}
2001-07-13 16:25:12 +00:00
if ( ! empty ( $primary_key ))
{
$schema_create .= " CONSTRAINT $primary_key_name PRIMARY KEY ( $primary_key ), $crlf " ;
2001-07-14 20:00:27 +00:00
}
//
2001-07-13 16:25:12 +00:00
// Generate constraint clauses for CHECK constraints
2001-07-14 20:00:27 +00:00
//
2001-08-30 22:20:23 +00:00
$sql_checks = " SELECT rcname as index_name, rcsrc
2001-07-14 20:00:27 +00:00
FROM pg_relcheck , pg_class bc
2001-08-30 22:20:23 +00:00
WHERE rcrelid = bc . oid
2001-07-14 20:00:27 +00:00
AND bc . relname = '$table'
AND NOT EXISTS (
2001-08-30 22:20:23 +00:00
SELECT *
FROM pg_relcheck as c , pg_inherits as i
WHERE i . inhrelid = pg_relcheck . rcrelid
AND c . rcname = pg_relcheck . rcname
AND c . rcsrc = pg_relcheck . rcsrc
2001-07-14 20:00:27 +00:00
AND c . rcrelid = i . inhparent
) " ;
2001-07-13 16:25:12 +00:00
$result = $db -> sql_query ( $sql_checks );
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( ! $result )
{
2001-07-27 23:16:09 +00:00
message_die ( GENERAL_ERROR , " Failed in get_table_def (show fields) " , " " , __LINE__ , __FILE__ , $sql_checks );
2001-07-14 20:00:27 +00:00
}
2001-08-30 22:20:23 +00:00
2001-08-01 15:27:13 +00:00
//
// Add the constraints to the sql file.
//
2001-07-13 16:25:12 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
$schema_create .= ' CONSTRAINT ' . $row [ 'index_name' ] . ' CHECK ' . $row [ 'rcsrc' ] . " , $crlf " ;
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
$schema_create = ereg_replace ( ',' . $crlf . '$' , '' , $schema_create );
$index_create = ereg_replace ( ',' . $crlf . '$' , '' , $index_create );
$schema_create .= " $crlf ); $crlf " ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( ! empty ( $index_create ))
{
$schema_create .= $index_create ;
2001-07-14 20:00:27 +00:00
}
2001-08-01 15:27:13 +00:00
//
// Ok now we've built all the sql return it to the calling function.
//
2001-07-13 16:25:12 +00:00
return ( stripslashes ( $schema_create ));
2001-07-14 20:00:27 +00:00
}
//
2001-07-13 16:25:12 +00:00
// This function returns the "CREATE TABLE" syntax for mysql dbms...
2001-07-14 20:00:27 +00:00
//
2001-08-30 22:20:23 +00:00
function get_table_def_mysql ( $table , $crlf )
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
global $drop , $db ;
2001-07-13 16:25:12 +00:00
$schema_create = " " ;
$field_query = " SHOW FIELDS FROM $table " ;
$key_query = " SHOW KEYS FROM $table " ;
2001-07-14 20:00:27 +00:00
//
// If the user has selected to drop existing tables when doing a restore.
2001-07-13 16:25:12 +00:00
// Then we add the statement to drop the tables....
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
if ( $drop == 1 )
{
$schema_create .= " DROP TABLE IF EXISTS $table ; $crlf " ;
}
2001-08-30 22:20:23 +00:00
2001-07-13 16:25:12 +00:00
$schema_create .= " CREATE TABLE $table ( $crlf " ;
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
// Ok lets grab the fields...
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
$result = $db -> sql_query ( $field_query );
if ( ! result )
{
2001-07-14 20:00:27 +00:00
message_die ( GENERAL_ERROR , " Failed in get_table_def (show fields) " , " " , __LINE__ , __FILE__ , $field_query );
2001-07-13 16:25:12 +00:00
}
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
$schema_create .= ' ' . $row [ 'Field' ] . ' ' . $row [ 'Type' ];
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( ! empty ( $row [ 'Default' ]))
{
$schema_create .= ' DEFAULT \'' . $row [ 'Default' ] . '\'' ;
}
2001-07-14 20:00:27 +00:00
2001-08-30 22:20:23 +00:00
if ( $row [ 'Null' ] != " YES " )
2001-07-13 16:25:12 +00:00
{
$schema_create .= ' NOT NULL' ;
}
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( $row [ 'Extra' ] != " " )
{
$schema_create .= ' ' . $row [ 'Extra' ];
}
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$schema_create .= " , $crlf " ;
}
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
// Drop the last ',$crlf' off ;)
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
$schema_create = ereg_replace ( ',' . $crlf . '$' , " " , $schema_create );
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
// Get any Indexed fields from the database...
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
$result = $db -> sql_query ( $key_query );
if ( ! $result )
{
2001-07-14 20:00:27 +00:00
message_die ( GENERAL_ERROR , " FAILED IN get_table_def (show keys) " , " " , __LINE__ , __FILE__ , $key_query );
2001-07-13 16:25:12 +00:00
}
2001-07-14 20:00:27 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
2001-07-13 16:25:12 +00:00
$kname = $row [ 'Key_name' ];
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if (( $kname != 'PRIMARY' ) && ( $row [ 'Non_unique' ] == 0 ))
{
$kname = " UNIQUE| $kname " ;
}
2001-07-14 20:00:27 +00:00
2001-08-30 22:20:23 +00:00
if ( ! is_array ( $index [ $kname ]))
2001-07-13 16:25:12 +00:00
{
$index [ $kname ] = array ();
}
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$index [ $kname ][] = $row [ 'Column_name' ];
}
2001-07-14 20:00:27 +00:00
2001-08-30 22:20:23 +00:00
while ( list ( $x , $columns ) = @ each ( $index ))
2001-07-13 16:25:12 +00:00
{
$schema_create .= " , $crlf " ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( $x == 'PRIMARY' )
{
$schema_create .= ' PRIMARY KEY (' . implode ( $columns , ', ' ) . ')' ;
2001-08-30 22:20:23 +00:00
}
2001-07-13 16:25:12 +00:00
elseif ( substr ( $x , 0 , 6 ) == 'UNIQUE' )
{
$schema_create .= ' UNIQUE ' . substr ( $x , 7 ) . ' (' . implode ( $columns , ', ' ) . ')' ;
2001-08-30 22:20:23 +00:00
}
2001-07-13 16:25:12 +00:00
else
{
$schema_create .= " KEY $x ( " . implode ( $columns , ', ' ) . ')' ;
}
}
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$schema_create .= " $crlf ); " ;
2001-07-14 20:00:27 +00:00
2001-08-30 22:20:23 +00:00
if ( get_magic_quotes_runtime ())
2001-07-13 16:25:12 +00:00
{
return ( stripslashes ( $schema_create ));
2001-08-30 22:20:23 +00:00
}
else
2001-07-13 16:25:12 +00:00
{
return ( $schema_create );
}
2001-08-30 22:20:23 +00:00
2001-07-13 16:25:12 +00:00
} // End get_table_def_mysql
2001-07-14 20:00:27 +00:00
//
// This fuction will return a tables create definition to be used as an sql
2001-07-13 16:25:12 +00:00
// statement.
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
//
2001-08-30 22:20:23 +00:00
// The following functions Get the data from the tables and format it as a
2001-07-13 16:25:12 +00:00
// series of INSERT statements, for each different DBMS...
// After every row a custom callback function $handler gets called.
// $handler must accept one parameter ($sql_insert);
//
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
// Here is the function for postgres...
2001-07-14 20:00:27 +00:00
//
function get_table_content_postgres ( $table , $handler )
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
global $db ;
2001-08-01 15:27:13 +00:00
//
// Grab all of the data from current table.
//
2001-07-13 16:25:12 +00:00
$result = $db -> sql_query ( " SELECT * FROM $table " );
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( ! $result )
{
2001-07-14 20:00:27 +00:00
message_die ( GENERAL_ERROR , " Faild in get_table_content (select *) " , " " , __LINE__ , __FILE__ , " SELECT * FROM $table " );
}
2001-07-13 16:25:12 +00:00
$i_num_fields = $db -> sql_numfields ( $result );
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
for ( $i = 0 ; $i < $i_num_fields ; $i ++ )
{
$aryType [] = $db -> sql_fieldtype ( $i , $result );
$aryName [] = $db -> sql_fieldname ( $i , $result );
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
$iRec = 0 ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
while ( $row = $db -> fetchrow ( $result ))
{
unset ( $schema_vals );
unset ( $schema_fields );
unset ( $schema_insert );
2001-08-30 22:20:23 +00:00
//
2001-08-01 15:27:13 +00:00
// Build the SQL statement to recreate the data.
//
2001-07-13 16:25:12 +00:00
for ( $i = 0 ; $i < $i_num_fields ; $i ++ )
{
$strVal = $row [ $aryName [ $i ]];
if ( eregi ( " char|text|bool " , $aryType [ $i ]))
{
$strQuote = " ' " ;
$strEmpty = " " ;
$strVal = addslashes ( $strVal );
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
elseif ( eregi ( " date|timestamp " , $aryType [ $i ]))
{
if ( $empty ( $strVal ))
{
$strQuote = " " ;
}
else
{
$strQuote = " ' " ;
}
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
else
{
$strQuote = " " ;
$strEmpty = " NULL " ;
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
if ( empty ( $strVal ) && $strVal != " 0 " )
{
$strVal = $strEmpty ;
}
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$schema_vals .= " $strQuote $strVal $strQuote , " ;
2001-08-30 22:20:23 +00:00
$schema_fields .= " $aryName[$i] , " ;
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
$schema_vals = ereg_replace ( " , $ " , " " , $schema_vals );
$schema_vals = ereg_replace ( " ^ " , " " , $schema_vals );
$schema_fields = ereg_replace ( " , $ " , " " , $schema_fields );
$schema_fields = ereg_replace ( " ^ " , " " , $schema_fields );
2001-07-14 20:00:27 +00:00
2001-08-01 15:27:13 +00:00
//
// Take the ordered fields and their associated data and build it
// into a valid sql statement to recreate that field in the data.
//
2001-07-13 16:25:12 +00:00
$schema_insert = " INSERT INTO $table ( $schema_fields ) VALUES( $schema_vals ); " ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$handler ( trim ( $schema_insert ));
2001-07-14 20:00:27 +00:00
}
2001-07-13 16:25:12 +00:00
return ( true );
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
} // end function get_table_content_postgres...
2001-08-01 15:27:13 +00:00
//
// This function is for getting the data from a mysql table.
//
2001-07-13 16:25:12 +00:00
2001-07-14 20:00:27 +00:00
function get_table_content_mysql ( $table , $handler )
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
global $db ;
2001-08-01 15:27:13 +00:00
//
// Grab the data from the table.
//
2001-07-13 16:25:12 +00:00
$result = $db -> sql_query ( " SELECT * FROM $table " );
2001-07-14 20:00:27 +00:00
if ( ! $result )
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
message_die ( GENERAL_ERROR , " Faild in get_table_content (select *) " , " " , __LINE__ , __FILE__ , " SELECT * FROM $table " );
2001-07-13 16:25:12 +00:00
}
2001-07-14 20:00:27 +00:00
2001-08-30 22:20:23 +00:00
if ( $db -> sql_numrows ( $result ) > 0 )
2001-07-13 16:25:12 +00:00
{
$schema_insert = " \n # \n # Table Data for $table\n # \n " ;
}
else
{
$schema_insert = " " ;
}
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$handler ( $schema_insert );
2001-07-14 20:00:27 +00:00
2001-08-01 15:27:13 +00:00
//
// Loop through the resulting rows and build the sql statement.
//
2001-07-13 16:25:12 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
$table_list = '(' ;
$num_fields = $db -> sql_numfields ( $result );
2001-08-01 15:27:13 +00:00
//
// Grab the list of field names.
//
2001-07-13 16:25:12 +00:00
for ( $j = 0 ; $j < $num_fields ; $j ++ )
{
$table_list .= $db -> sql_fieldname ( $j , $result ) . ', ' ;
}
2001-08-01 15:27:13 +00:00
//
// Get rid of the last comma
//
2001-07-13 16:25:12 +00:00
$table_list = ereg_replace ( ', $' , '' , $table_list );
$table_list .= ')' ;
2001-08-01 15:27:13 +00:00
//
// Start building the SQL statement.
//
2001-07-13 16:25:12 +00:00
$schema_insert = " INSERT INTO $table $table_list VALUES( " ;
2001-08-01 15:27:13 +00:00
//
// Loop through the rows and fill in data for each column
//
2001-07-13 16:25:12 +00:00
for ( $j = 0 ; $j < $num_fields ; $j ++ )
{
if ( ! isset ( $row [ $j ]))
{
2001-08-01 15:27:13 +00:00
//
// If there is no data for the column set it to null.
// There was a problem here with an extra space causing the
2001-08-30 22:20:23 +00:00
// sql file not to reimport if the last column was null in
2001-08-01 15:27:13 +00:00
// any table. Should be fixed now :) JLH
//
$schema_insert .= ' NULL,' ;
2001-08-30 22:20:23 +00:00
}
elseif ( $row [ $j ] != '' )
2001-07-13 16:25:12 +00:00
{
$schema_insert .= ' \'' . addslashes ( $row [ $j ]) . '\',' ;
2001-08-30 22:20:23 +00:00
}
2001-07-13 16:25:12 +00:00
else
{
$schema_insert .= '\'\',' ;
}
}
2001-08-01 15:27:13 +00:00
//
2001-08-30 22:20:23 +00:00
// Get rid of the the last comma.
2001-08-01 15:27:13 +00:00
//
2001-07-13 16:25:12 +00:00
$schema_insert = ereg_replace ( ',$' , '' , $schema_insert );
$schema_insert .= ');' ;
2001-08-01 15:27:13 +00:00
//
// Go ahead and send the insert statement to the handler function.
//
2001-07-13 16:25:12 +00:00
$handler ( trim ( $schema_insert ));
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
}
return ( true );
}
function output_table_content ( $content )
{
2001-11-19 19:39:00 +00:00
global $tempfile ;
2001-07-14 20:00:27 +00:00
2001-11-20 20:33:15 +00:00
//fwrite($tempfile, $content . "\n");
2001-11-19 19:39:00 +00:00
//$backup_sql .= $content . "\n";
2001-11-20 20:33:15 +00:00
echo $content . " \n " ;
2001-07-13 16:25:12 +00:00
return ;
}
2001-08-30 22:20:23 +00:00
//
2001-07-13 16:25:12 +00:00
// End Functions
2001-07-14 20:00:27 +00:00
// -------------
2001-08-03 00:23:01 +00:00
2001-07-14 20:00:27 +00:00
//
// Begin program proper
2001-07-13 16:25:12 +00:00
//
2001-07-14 20:00:27 +00:00
if ( isset ( $HTTP_GET_VARS [ 'perform' ]) || isset ( $HTTP_POST_VARS [ 'perform' ]) )
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
$perform = ( isset ( $HTTP_POST_VARS [ 'perform' ])) ? $HTTP_POST_VARS [ 'perform' ] : $HTTP_GET_VARS [ 'perform' ];
2001-08-30 22:20:23 +00:00
2001-07-13 16:25:12 +00:00
switch ( $perform )
{
case 'backup' :
2001-07-29 23:26:40 +00:00
2001-07-14 20:00:27 +00:00
if ( SQL_LAYER == 'oracle' || SQL_LAYER == 'odbc' || SQL_LAYER == 'mssql' )
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
switch ( SQL_LAYER )
{
case 'oracle' :
$db_type = " Oracle " ;
break ;
2001-08-03 13:16:59 +00:00
case 'odbc' :
2001-07-14 20:00:27 +00:00
$db_type = " ODBC " ;
break ;
case 'mssql' :
$db_type = " MSSQL " ;
break ;
}
2001-08-03 13:16:59 +00:00
include ( 'page_header_admin.' . $phpEx );
2001-07-29 23:26:40 +00:00
$template -> set_filenames ( array (
" body " => " admin/admin_message_body.tpl " )
);
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$template -> assign_vars ( array (
2001-08-30 22:20:23 +00:00
" MESSAGE_TITLE " => $lang [ 'Information' ],
2001-07-29 23:26:40 +00:00
" MESSAGE_TEXT " => $lang [ 'Backups_not_supported' ])
2001-07-14 20:00:27 +00:00
);
2001-07-29 23:26:40 +00:00
2001-07-13 16:25:12 +00:00
$template -> pparse ( " body " );
2001-08-30 22:20:23 +00:00
2001-07-14 20:00:27 +00:00
break ;
2001-07-13 16:25:12 +00:00
}
2001-07-14 20:00:27 +00:00
2001-11-13 21:17:32 +00:00
$tables = array ( 'auth_access' , 'banlist' , 'categories' , 'config' , 'disallow' , 'forums' , 'forum_prune' , 'groups' , 'posts' , 'posts_text' , 'privmsgs' , 'privmsgs_text' , 'ranks' , 'search_results' , 'search_results' , 'search_wordlist' , 'search_wordmatch' , 'sessions' , 'smilies' , 'themes' , 'themes_name' , 'topics' , 'topics_watch' , 'user_group' , 'users' , 'vote_desc' , 'vote_results' , 'vote_voters' , 'words' );
2001-07-14 20:00:27 +00:00
2001-11-20 20:33:15 +00:00
2001-07-14 20:00:27 +00:00
$additional_tables = ( isset ( $HTTP_POST_VARS [ 'additional_tables' ])) ? $HTTP_POST_VARS [ 'additional_tables' ] : ( ( isset ( $HTTP_GET_VARS [ 'additional_tables' ])) ? $HTTP_GET_VARS [ 'additional_tables' ] : " " );
2001-08-03 13:16:59 +00:00
2001-07-14 20:00:27 +00:00
$backup_type = ( isset ( $HTTP_POST_VARS [ 'backup_type' ])) ? $HTTP_POST_VARS [ 'backup_type' ] : ( ( isset ( $HTTP_GET_VARS [ 'backup_type' ])) ? $HTTP_GET_VARS [ 'backup_type' ] : " " );
2001-08-03 13:16:59 +00:00
$gzipcompress = ( ! empty ( $HTTP_POST_VARS [ 'gzipcompress' ])) ? $HTTP_POST_VARS [ 'gzipcompress' ] : ( ( ! empty ( $HTTP_GET_VARS [ 'gzipcompress' ])) ? $HTTP_GET_VARS [ 'gzipcompress' ] : 0 );
2001-08-30 22:20:23 +00:00
if ( ! empty ( $additional_tables ))
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
if ( ereg ( " , " , $additional_tables ))
{
$additional_tables = split ( " , " , $additional_tables );
for ( $i = 0 ; $i < count ( $additional_tables ); $i ++ )
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
$tables [] = trim ( $additional_tables [ $i ]);
2001-07-13 16:25:12 +00:00
}
2001-07-14 20:00:27 +00:00
}
else
2001-07-13 16:25:12 +00:00
{
2001-07-14 20:00:27 +00:00
$tables [] = trim ( $additional_tables );
2001-07-13 16:25:12 +00:00
}
}
2001-07-14 20:00:27 +00:00
if ( ! isset ( $HTTP_POST_VARS [ 'backupstart' ]) && ! isset ( $HTTP_GET_VARS [ 'backupstart' ]))
2001-07-13 16:25:12 +00:00
{
2001-08-03 13:16:59 +00:00
include ( 'page_header_admin.' . $phpEx );
2001-07-29 23:26:40 +00:00
$template -> set_filenames ( array (
" body " => " admin/db_utils_backup_body.tpl " )
);
2001-08-03 13:16:59 +00:00
$s_hidden_fields = " <input type= \" hidden \" name= \" perform \" value= \" backup \" /><input type= \" hidden \" name= \" drop \" value= \" 1 \" /><input type= \" hidden \" name= \" perform \" value= \" $perform\ " /> " ;
2001-07-14 20:00:27 +00:00
$template -> assign_vars ( array (
2001-08-30 22:20:23 +00:00
" L_DATABASE_BACKUP " => $lang [ 'Database_Utilities' ] . " : " . $lang [ 'Backup' ],
" L_BACKUP_EXPLAIN " => $lang [ 'Backup_explain' ],
2001-07-29 23:26:40 +00:00
" L_FULL_BACKUP " => $lang [ 'Full_backup' ],
" L_STRUCTURE_BACKUP " => $lang [ 'Structure_backup' ],
" L_DATA_BACKUP " => $lang [ 'Data_backup' ],
" L_ADDITIONAL_TABLES " => $lang [ 'Additional_tables' ],
" L_START_BACKUP " => $lang [ 'Start_backup' ],
2001-08-30 22:20:23 +00:00
" L_BACKUP_OPTIONS " => $lang [ 'Backup_options' ],
" L_GZIP_COMPRESS " => $lang [ 'Gzip_compress' ],
" L_NO " => $lang [ 'No' ],
" L_YES " => $lang [ 'Yes' ],
2001-07-29 23:26:40 +00:00
2001-08-30 22:20:23 +00:00
" S_HIDDEN_FIELDS " => $s_hidden_fields ,
2001-07-29 23:26:40 +00:00
" S_DBUTILS_ACTION " => append_sid ( " admin_db_utilities. $phpEx " ))
2001-07-14 20:00:27 +00:00
);
$template -> pparse ( " body " );
break ;
2001-08-30 22:20:23 +00:00
2001-07-14 20:00:27 +00:00
}
else if ( ! isset ( $HTTP_POST_VARS [ 'startdownload' ]) && ! isset ( $HTTP_GET_VARS [ 'startdownload' ]) )
{
2001-07-29 23:26:40 +00:00
$template -> set_filenames ( array (
" body " => " admin/admin_message_body.tpl " )
);
2001-08-30 22:20:23 +00:00
2001-07-14 20:00:27 +00:00
$template -> assign_vars ( array (
2001-09-06 00:29:07 +00:00
" META " => " <meta http-equiv= \" refresh \" content= \" 0;url=admin_db_utilities. $phpEx ?perform=backup&additional_tables= " . quotemeta ( $additional_tables ) . " &backup_type= $backup_type &drop=1&backupstart=1&gzipcompress= $gzipcompress &startdownload=1 \" > " ,
2001-07-29 23:26:40 +00:00
2001-08-30 22:20:23 +00:00
" MESSAGE_TITLE " => $lang [ 'Database_Utilities' ] . " : " . $lang [ 'Backup' ],
2001-07-29 23:26:40 +00:00
" MESSAGE_TEXT " => $lang [ 'Backup_download' ])
2001-07-14 20:00:27 +00:00
);
2001-08-03 00:23:01 +00:00
include ( 'page_header_admin.php' );
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$template -> pparse ( " body " );
2001-07-14 20:00:27 +00:00
include ( 'page_footer_admin.' . $phpEx );
2001-07-13 16:25:12 +00:00
}
2001-11-20 20:33:15 +00:00
header ( " Pragma: no-cache " );
$do_gzip_compress = FALSE ;
if ( $gzipcompress )
{
$phpver = phpversion ();
if ( $phpver >= " 4.0 " )
{
if ( extension_loaded ( " zlib " ))
{
$do_gzip_compress = TRUE ;
}
}
}
if ( $do_gzip_compress )
{
@ ob_start ();
@ ob_implicit_flush ( 0 );
header ( " Content-Type: text/x-delimtext; name= \" phpbb_db_backup.sql.gz \" " );
header ( " Content-disposition: attachment; filename=phpbb_db_backup.sql.gz " );
}
else
{
header ( " Content-Type: text/x-delimtext; name= \" phpbb_db_backup.sql \" " );
header ( " Content-disposition: attachment; filename=phpbb_db_backup.sql " );
}
2001-07-14 20:00:27 +00:00
//
2001-07-13 16:25:12 +00:00
// Build the sql script file...
2001-07-14 20:00:27 +00:00
//
2001-11-20 20:33:15 +00:00
echo " # \n " ;
echo " # phpBB Backup Script \n " ;
echo " # Dump of tables for $dbname\n " ;
echo " # \n # DATE : " . gmdate ( " d-m-Y H:i:s " , time ()) . " GMT \n " ;
echo " # \n " ;
2001-07-14 20:00:27 +00:00
if ( SQL_LAYER == 'postgres' )
2001-07-13 16:25:12 +00:00
{
2001-11-20 20:33:15 +00:00
echo " \n " . pg_get_sequences ( " \n " , $backup_type );
2001-07-13 16:25:12 +00:00
}
for ( $i = 0 ; $i < count ( $tables ); $i ++ )
{
$table_name = $tables [ $i ];
2001-07-14 20:00:27 +00:00
$table_def_function = " get_table_def_ " . SQL_LAYER ;
$table_content_function = " get_table_content_ " . SQL_LAYER ;
2001-07-13 16:25:12 +00:00
if ( $backup_type != 'data' )
{
2001-11-20 20:33:15 +00:00
echo " # \n # TABLE: " . $table_prefix . $table_name . " \n # \n " ;
echo $table_def_function ( $table_prefix . $table_name , " \n " ) . " \n " ;
2001-08-30 22:20:23 +00:00
}
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( $backup_type != 'structure' )
{
2001-07-14 20:00:27 +00:00
$table_content_function ( $table_prefix . $table_name , " output_table_content " );
2001-07-13 16:25:12 +00:00
}
}
2001-11-19 19:39:00 +00:00
2001-08-03 13:16:59 +00:00
if ( $do_gzip_compress )
{
2001-11-20 20:33:15 +00:00
$Size = ob_get_length ();
$Crc = crc32 ( ob_get_contents ());
$contents = gzcompress ( ob_get_contents ());
ob_end_clean ();
echo " \x1f \x8b \x08 \x00 \x00 \x00 \x00 \x00 " . substr ( $contents , 0 , strlen ( $contents ) - 4 ) . gzip_PrintFourChars ( $Crc ) . gzip_PrintFourChars ( $Size );
2001-08-03 13:16:59 +00:00
}
2001-07-13 16:25:12 +00:00
exit ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
break ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
case 'restore' :
2001-08-30 22:20:23 +00:00
if ( ! isset ( $restore_start ))
{
//
2001-07-28 16:42:12 +00:00
// Define Template files...
//
2001-08-03 13:16:59 +00:00
include ( 'page_header_admin.' . $phpEx );
2001-07-28 16:42:12 +00:00
$template -> set_filenames ( array (
" body " => " admin/db_utils_restore_body.tpl " )
);
2001-08-03 16:24:20 +00:00
$s_hidden_fields = " <input type= \" hidden \" name= \" perform \" value= \" restore \" /><input type= \" hidden \" name= \" perform \" value= \" $perform\ " /> " ;
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
$template -> assign_vars ( array (
2001-08-30 22:20:23 +00:00
" L_DATABASE_RESTORE " => $lang [ 'Database_Utilities' ] . " : " . $lang [ 'Restore' ],
" L_RESTORE_EXPLAIN " => $lang [ 'Restore_explain' ],
" L_SELECT_FILE " => $lang [ 'Select_file' ],
" L_START_RESTORE " => $lang [ 'Start_Restore' ],
2001-07-29 23:26:40 +00:00
2001-08-30 22:20:23 +00:00
" S_DBUTILS_ACTION " => append_sid ( " admin_db_utilities. $phpEx " ),
2001-07-28 16:42:12 +00:00
" S_HIDDEN_FIELDS " => $s_hidden_fields )
2001-07-14 20:00:27 +00:00
);
2001-07-13 16:25:12 +00:00
$template -> pparse ( " body " );
2001-07-14 20:00:27 +00:00
break ;
}
2001-08-30 22:20:23 +00:00
else
{
2001-08-02 15:26:52 +00:00
//
2001-07-13 16:25:12 +00:00
// Handle the file upload ....
2001-08-02 15:26:52 +00:00
// If no file was uploaded report an error...
//
2001-08-03 16:24:20 +00:00
$backup_file_name = ( ! empty ( $HTTP_POST_FILES [ 'backup_file' ][ 'name' ])) ? $HTTP_POST_FILES [ 'backup_file' ][ 'name' ] : " " ;
$backup_file_tmpname = ( $HTTP_POST_FILES [ 'backup_file' ][ 'tmp_name' ] != " none " ) ? $HTTP_POST_FILES [ 'backup_file' ][ 'tmp_name' ] : " " ;
$backup_file_type = ( ! empty ( $HTTP_POST_FILES [ 'backup_file' ][ 'type' ])) ? $HTTP_POST_FILES [ 'backup_file' ][ 'type' ] : " " ;
if ( $backup_file_tmpname == " " || $backup_file_name == " " )
2001-07-13 16:25:12 +00:00
{
2001-08-03 13:16:59 +00:00
include ( 'page_header_admin.' . $phpEx );
2001-08-03 16:24:20 +00:00
message_die ( GENERAL_MESSAGE , $lang [ 'Restore_Error_no_file' ]);
2001-07-13 16:25:12 +00:00
}
2001-08-02 15:26:52 +00:00
//
2001-08-30 22:20:23 +00:00
// If I file was actually uploaded, check to make sure that we
2001-08-02 15:26:52 +00:00
// are actually passed the name of an uploaded file, and not
// a hackers attempt at getting us to process a local system
// file.
//
2001-08-03 16:24:20 +00:00
if ( file_exists ( $backup_file_tmpname ) )
2001-07-13 16:25:12 +00:00
{
2001-08-08 14:40:04 +00:00
if ( preg_match ( " /^(text \ /[a-zA-Z]+)|(application \ /(x \ -)?gzip \ -compressed)|(application \ /octet-stream) $ /is " , $backup_file_type ) )
2001-08-03 16:24:20 +00:00
{
if ( preg_match ( " / \ .gz $ /is " , $backup_file_name ) )
{
$do_gzip_compress = FALSE ;
$phpver = phpversion ();
if ( $phpver >= " 4.0 " )
{
if ( extension_loaded ( " zlib " ))
{
$do_gzip_compress = TRUE ;
}
}
if ( $do_gzip_compress )
{
2001-08-03 17:17:08 +00:00
$gz_ptr = gzopen ( $backup_file_tmpname , 'rb' );
$sql_query = " " ;
while ( ! gzeof ( $gz_ptr ) )
{
$sql_query .= gzgets ( $gz_ptr , 100000 );
}
2001-08-03 16:24:20 +00:00
}
else
{
include ( 'page_header_admin.' . $phpEx );
message_die ( GENERAL_ERROR , $lang [ 'Restore_Error_decompress' ]);
}
}
else
{
$sql_query = fread ( fopen ( $backup_file_tmpname , 'r' ), filesize ( $backup_file_tmpname ));
}
//
// Comment this line out to see if this fixes the stuff...
//
//$sql_query = stripslashes($sql_query);
}
else
{
include ( 'page_header_admin.' . $phpEx );
2001-08-08 14:40:04 +00:00
message_die ( GENERAL_ERROR , $lang [ 'Restore_Error_filename' ] );
2001-08-03 16:24:20 +00:00
}
2001-07-14 20:00:27 +00:00
}
else
2001-07-13 16:25:12 +00:00
{
2001-08-03 13:16:59 +00:00
include ( 'page_header_admin.' . $phpEx );
2001-08-03 16:24:20 +00:00
message_die ( GENERAL_ERROR , $lang [ 'Restore_Error_uploading' ]);
2001-07-13 16:25:12 +00:00
}
2001-07-14 20:00:27 +00:00
2001-08-30 22:20:23 +00:00
if ( $sql_query != " " )
2001-07-13 16:25:12 +00:00
{
// Strip out sql comments...
$sql_query = remove_remarks ( $sql_query );
$pieces = split_sql_file ( $sql_query , " ; " );
2001-07-14 20:00:27 +00:00
2001-09-24 07:53:08 +00:00
$sql_count = count ( $pieces );
for ( $i = 0 ; $i < $sql_count ; $i ++ )
2001-07-13 16:25:12 +00:00
{
$sql = trim ( $pieces [ $i ]);
2001-07-14 20:00:27 +00:00
2001-07-13 16:25:12 +00:00
if ( ! empty ( $sql ) and $sql [ 0 ] != " # " )
2001-08-30 22:20:23 +00:00
{
if ( VERBOSE == 1 )
2001-07-13 16:25:12 +00:00
{
echo " Executing: $sql\n <br> " ;
2001-08-02 15:26:52 +00:00
flush ();
2001-07-13 16:25:12 +00:00
}
2001-08-30 22:20:23 +00:00
2001-07-13 16:25:12 +00:00
$result = $db -> sql_query ( $sql );
2001-08-30 22:20:23 +00:00
2001-07-14 20:00:27 +00:00
if ( ! $result && ( ! ( SQL_LAYER == 'postgres' && eregi ( " drop table " , $sql ) ) ) )
2001-07-13 16:25:12 +00:00
{
2001-11-09 08:57:37 +00:00
//include('page_header_admin.'.$phpEx);
// echo "~~$sql~~";
2001-08-07 21:21:02 +00:00
message_die ( GENERAL_ERROR , " Error importing backup file " , " " , __LINE__ , __FILE__ , $sql );
2001-07-13 16:25:12 +00:00
}
}
}
}
2001-07-14 20:00:27 +00:00
2001-08-03 13:16:59 +00:00
include ( 'page_header_admin.' . $phpEx );
2001-07-29 23:26:40 +00:00
$template -> set_filenames ( array (
" body " => " admin/admin_message_body.tpl " )
);
2001-07-14 20:00:27 +00:00
2001-07-29 23:26:40 +00:00
$message = $lang [ 'Restore_success' ];
2001-08-30 22:20:23 +00:00
2001-07-13 16:25:12 +00:00
$template -> assign_vars ( array (
2001-08-30 22:20:23 +00:00
" MESSAGE_TITLE " => $lang [ 'Database_Utilities' ] . " : " . $lang [ 'Restore' ],
2001-07-29 23:26:40 +00:00
" MESSAGE_TEXT " => $message )
2001-07-14 20:00:27 +00:00
);
2001-07-13 16:25:12 +00:00
$template -> pparse ( " body " );
2001-07-14 20:00:27 +00:00
break ;
2001-07-13 16:25:12 +00:00
}
break ;
}
2001-08-30 22:20:23 +00:00
}
2001-07-14 20:00:27 +00:00
include ( 'page_footer_admin.' . $phpEx );
2001-09-18 19:01:58 +00:00
?>