0){ $crlf = "\n"; ob_start(); @ob_implicit_flush(0); echo "#----------------------------------------------------------".$crlf; echo "# PHP-Fusion SQL Data Dump".$crlf; echo "# Database Name: `$db_name`".$crlf; echo "# Table Prefix: `".$db_prefix."`".$crlf; echo "# Date: `".date("d/m/Y H:i")."`".$crlf; echo "#----------------------------------------------------------".$crlf; dbquery('SET SQL_QUOTE_SHOW_CREATE=1'); foreach($db_tables as $table){ @set_time_limit(1200); dbquery("OPTIMIZE TABLE $table"); echo $crlf."#".$crlf."# Structure for Table `".$table."`".$crlf."#".$crlf; echo "DROP TABLE IF EXISTS `$table`;$crlf"; $row=dbarraynum(dbquery("SHOW CREATE TABLE $table")); echo $row[1].";".$crlf; $result=dbquery("SELECT * FROM $table"); if($result&&dbrows($result)){ echo $crlf."#".$crlf."# Table Data for `".$table."`".$crlf."#".$crlf; $column_list=""; $num_fields=mysql_num_fields($result); for($i=0;$i<$num_fields;$i++){ $column_list.=(($column_list!="")?", ":"")."`".mysql_field_name($result,$i)."`"; } } while($row=dbarraynum($result)){ $dump="INSERT INTO `$table` ($column_list) VALUES ("; for($i=0;$i<$num_fields;$i++){ $dump.=($i>0)?", ":""; if(!isset($row[$i])){ $dump.="NULL"; }elseif($row[$i]=="0"||$row[$i]!=""){ $type=mysql_field_type($result,$i); if($type=="tinyint"||$type=="smallint"||$type=="mediumint"||$type=="int"||$type=="bigint"||$type=="timestamp"){ $dump.=$row[$i]; }else{ $search_array=array('\\','\'',"\x00","\x0a","\x0d","\x1a"); $replace_array=array('\\\\','\\\'','\0','\n','\r','\Z'); $row[$i]=str_replace($search_array,$replace_array,$row[$i]); $dump.="'$row[$i]'"; } }else{ $dump.="''"; } } $dump.=');'; echo $dump.$crlf; } } $contents = ob_get_contents(); ob_end_clean(); $file = stripinput($_POST['backup_filename']).".sql"; require_once INCLUDES."class.httpdownload.php"; $dl = new httpdownload; $dl->use_resume = false; if ($_POST['backup_type'] == ".gz") { $dl->set_mime("application/x-gzip gz tgz"); $dl->set_bydata(gzencode($contents,9)); $dl->set_filename($file.".gz"); } else { $dl->set_mime("text/plain"); $dl->set_bydata($contents); $dl->set_filename($file); } $dl->download(); exit; } fallback(FUSION_SELF.$aidlink); } require_once BASEDIR."subheader.php"; require_once ADMIN."navigation.php"; include LOCALE.LOCALESET."admin/db-backup.php"; if (!isset($action)) $action = ""; if (!isset($_POST['btn_do_restore']) && $action != "restore") { $backup_files = makefilelist(ADMIN."db_backups/", ".|..|index.php", true); if (is_array($backup_files) && count($backup_files) > 0) { for ($i=0;$i < count($backup_files);$i++) { @unlink(ADMIN."db_backups/".$backup_files[$i]); } } } if (isset($_POST['btn_cancel'])) { @unlink(ADMIN."db_backups/".$_POST['file']); redirect(FUSION_SELF.$aidlink); } if (isset($_POST['btn_do_restore'])) { $user_password = md5($_POST['user_password']); if ($user_password != $userdata['user_password']) { fallback(FUSION_SELF.$aidlink); } $result = gzfile(ADMIN."db_backups/".$_POST['file']); if((preg_match("/# Database Name: `(.+?)`/i", $result[2], $tmp1)<>0)&&(preg_match("/# Table Prefix: `(.+?)`/i", $result[3], $tmp2)<>0)){ $inf_dbname = $tmp1[1]; $inf_tblpre = $tmp2[1]; $result = array_slice($result,7); $results = preg_split("/;$/m",implode("",$result)); if (count($list_tbl) > 0) { foreach($results as $result){ $result = html_entity_decode($result, ENT_QUOTES); if (preg_match("/^DROP TABLE IF EXISTS `(.*?)`/im",$result,$tmp) <> 0) { $tbl = $tmp[1]; if (in_array($tbl, $list_tbl)) { $result = preg_replace("/^DROP TABLE IF EXISTS `$inf_tblpre(.*?)`/im","DROP TABLE IF EXISTS `$restore_tblpre\\1`",$result); mysql_unbuffered_query($result); } } if (preg_match("/^CREATE TABLE `(.*?)`/im",$result,$tmp) <> 0) { $tbl = $tmp[1]; if (in_array($tbl, $list_tbl)) { $result = preg_replace("/^CREATE TABLE `$inf_tblpre(.*?)`/im","CREATE TABLE `$restore_tblpre\\1`",$result); mysql_unbuffered_query($result); } } } } if (count($list_ins) > 0) { foreach($results as $result){ if (preg_match("/INSERT INTO `(.*?)`/i",$result,$tmp) <> 0) { $ins = $tmp[1]; if (in_array($ins, $list_ins)) { $result = preg_replace("/INSERT INTO `$inf_tblpre(.*?)`/i","INSERT INTO `$restore_tblpre\\1`",$result); mysql_unbuffered_query($result); } } } } @unlink(ADMIN."/db_backups/temp.txt"); redirect(FUSION_SELF.$aidlink); }else{ opentable($locale['400']); echo "