<?php


session_cache_expire(1440);
session_start();
session_name("insys");

include "include/config.php";
include "include/functions.php";

if(Getsecurity("backup_database")=='') {
    die("<script>alert('Anda tidak punya hak aksess ..');</script>");
}
@unlink("c:/isdmi.sql");
@unlink("c:/isdmi.sql.zip");

$filenamexx="ISDMI".date("Ymdhis").".sql";
$filenamex="c:/isdmi.sql";
exec(_APP_PATH."BackUp_DB_ISDMI.bat");
$fp      = fopen($filenamex, 'r');
$isiFile = fread($fp, filesize($filenamex));
fclose($fp);

$zip = new ZipArchive();
$fileKompresi = "c:/isdmi.sql.zip";

$kompresi = $zip->open($fileKompresi, ZIPARCHIVE::CREATE);
if ($kompresi)
{
   $zip->addFromString($filenamex, $isiFile);
   $zip->close();

}

if(file_exists($filenamex.".zip")) {
    $fileName=$filenamex.".zip";
    $mimeType = 'application/x-download';
    header('content-disposition: attachment; filename=' . $filenamexx.".zip");
    header('content-type: ' . $mimeType);
    header('content-length: ' . filesize($fileName));
    readfile($fileName);
}