<?php
ob_start();
ini_set('memory_limit', '-1');
include($_SERVER['DOCUMENT_ROOT'] .'/script/HeaderInc.php');

$ObjDbMod = new DbMod($MS_SP, 'dbconfig');
$VarSql = $ObjDbMod->Backup('dbconfig');
$ArrDsnInfo['dbconfig'] = MDB2::parseDSN($MS_SP->Sp_DbConf['dbconfig']['DbDsn']);
$VarFileName = $ArrDsnInfo['dbconfig']['database'] .'_'. date("d_m_Y_H_i_s");
$VarFileNameZip = $VarFileName .'.zip';
$VarFileNameSql = $VarFileName .'.sql';
$VarFileNameZipPath = $_SERVER['DOCUMENT_ROOT'] .'/../tmp/'. $VarFileNameZip;
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
ob_clean();
//echo $VarSql;
$zip = new ZipArchive();
if ($zip->open($VarFileNameZipPath, ZIPARCHIVE::CREATE)!==TRUE) {
  exit($MS_SP->Sp_LangMessage['error']['ErrCannotOpenFile'] .' <'. $VarFileNameZip .">\n");
}
$zip->addFromString($VarFileNameSql, $VarSql);
$zip->close();
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename='. $VarFileNameZip);
header('Content-Length: '. filesize($VarFileNameZipPath));
readfile($VarFileNameZipPath);
unlink($VarFileNameZipPath);
exit;
?>