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

$ObjDbMod = new DbMod($MS_SP, 'dbuser');
$VarSql = $ObjDbMod->Backup('dbuser');
//$VarSql .= "ALTER TABLE ipsuser.`ipsuser_ndselection` ADD INDEX (`idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_prim` ADD INDEX (`idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ndlastopened` ADD INDEX (`idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ndselectiontree` ADD INDEX (`ndselectiontree_idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ndselectiontree` ADD INDEX (`users_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_userscard` ADD INDEX (`idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_userscard` ADD INDEX (`users_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_print` ADD INDEX (`ID`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_print` ADD INDEX (`users_id_who`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_print` ADD INDEX (`users_id_to`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ndvote` ADD INDEX (`idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_message` ADD INDEX (`users_id_to`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_message` ADD INDEX (`users_id_from`);\r\n---*-*-\r\n";
//$VarSql .= "ALTER TABLE ipsuser.`ipsuser_ndselection` ADD INDEX (`idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_prim` ADD INDEX (`idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ndlastopened` ADD INDEX (`idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ndselectiontree` ADD INDEX (`ndselectiontree_idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ndselectiontree` ADD INDEX (`ndselectiontree_parent_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ndselectiontree` ADD INDEX (`users_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_userscard` ADD INDEX (`idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_userscard` ADD INDEX (`users_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_print` ADD INDEX (`ID`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_print` ADD INDEX (`users_id_who`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_print` ADD INDEX (`users_id_to`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ndvote` ADD INDEX (`idglobal`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_message` ADD INDEX (`users_id_to`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_message` ADD INDEX (`users_id_from`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ourdocs` ADD INDEX (`users_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ourdocs` ADD INDEX (`userdoctype_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ourdocsfile` ADD INDEX (`ourdocs_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ourdocsfile` ADD INDEX (`users_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ourdocsfiledownload` ADD INDEX (`ourdocsfile_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ourdocsfiledownload` ADD INDEX (`users_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ourdocslinkstotnpa` ADD INDEX (`IDGLOBAL`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ourmksvalue` ADD INDEX (`KOD`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ourdocslinkstoourdocs` ADD INDEX (`ourdocs_id`);\r\n---*-*-\r\nALTER TABLE ipsuser.`ipsuser_ourdocslinkstoourdocs` ADD INDEX (`to_ourdocs_id`);\r\n---*-*-\r\n";
$ArrDsnInfo['dbuser'] = MDB2::parseDSN($MS_SP->Sp_DbConf['dbuser']['DbDsn']);
$VarFileName = $ArrDsnInfo['dbuser']['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;
?>