<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.7

Copyright (C) 2006-2007  Sylvain FATOME
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.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr

Web : http://smitst.homelinux.com
****************************************************************************************/

session_start(); 
include_once("../inc/config.inc.php");
include_once("../inc/func_log.inc.php");
if (CheckURLLog(FALSE)==FALSE) header("Location: ../index.php");
if (CheckNivLog("9")==FALSE) header("Location: ../index.php");
include_once("../inc/func_date.inc.php");
include_once('../classes/mysqlbckup/mysql_backup.class.php');

Archivelog(@$_SESSION["code_log"]);

$typsvg = strip_tags(trim($_GET['td']));

$titre = "SAUVEGARDE DES DONNEES";

if (($typsvg == 1) OR ($typsvg == 2))
{

	$backup_obj = new MySQL_Backup();

	$backup_obj->server = DBHOST;
	$backup_obj->port = 3306;
	$backup_obj->username = DBUSER;
	$backup_obj->password = DBPASS;
	$backup_obj->database = DBNAME;

	// On autorise le DROP TABLES IF EXISTS avant CREATE TABLE 
	$backup_obj->drop_tables = true;

	// On autorise les commentaires
	$backup_obj->comments = true;

	// Répertoire où l'on sauve le fichier (inutilisé car téléchargement)
	$backup_obj->backup_dir = '/';

	// Format par défaut du fichier
	$backup_obj->fname_format = 'd_m_Y';

	// On sauve toutes les tables
	$backup_obj->tables = array();

	// On dit que l'on veut envoyer en mode download
	$task = MSB_DOWNLOAD;


	// On compresse
	$use_gzip = true;

	switch ($typsvg)
	{
	case 1 :
			// Nom du fichier de sauvegarde
			$filename = 'svg_smi_struct_'.date(d_m_Y).'-'.date(H_i_s).'.sql.gz';

			// On prend que la structure
			$backup_obj->struct_only = TRUE;
		break;
		
	case 2 :
			// Nom du fichier de sauvegarde
			$filename = 'svg_smi_all_'.date(d_m_Y).'-'.date(H_i_s).'.sql.gz';

			// On prend la structure et les données
			$backup_obj->struct_only = FALSE;
		break;
		
	default : break;
	}
	
	if (!$backup_obj->Execute($task, $filename, $use_gzip))
	{
		 $msg = $backup_obj->error;
	}
	else
	{
		$msg = "Sauvegarde effectuée le <b>".datefr($datea)."</b>";
	}
	
}
else
{
	header("Location: ../index.php");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Sauvegarde donn&eacute;es</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../css/smi.css" rel="stylesheet" type="text/css">

<!-- Feuille de style & Script pour le menu -->

<script language="JavaScript" src="../jscript/coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour fenêtres -->
<script language="JavaScript" src="../jscript/fen.js"></script>

</head>

<body>
<?php 
include_once("../inc/entete.inc.php"); 
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">&nbsp;</p>
<p align="center" class="annot_gras_it"><?PHP echo $msg ?></p>
<table width="100%"  border="0">
<tr>
	<td width="3%">&nbsp;</td>
	<td width="44%">&nbsp;</td>
	<td width="7%">&nbsp;</td>
	<td width="43%"><a href="index.php"><em><img src="../img/index.gif" width="48" height="48" border="0" align="absmiddle"> </em><span class="annot_gras_it">Revenir &agrave; l'accueil</span> </a></td>
	<td width="3%">&nbsp;</td>
</tr>
</table>
<?php 
include_once("pied.php");
?>
