'.HtmlInput::button_anchor(_("Retour"),"?action=restore","","smallbutton");
if ( ! isset($_REQUEST['t']))
{
echo '
';
echo (""._("Vous devez préciser s'il s'agit d'un modèle ou d'un dossier")."");
echo $retour;
echo '
';
exit();
}
if ( empty ($_FILES['file']['name']) ||
strlen(trim($_FILES['file']['name']))==0
)
{
echo '';
echo (""._('Vous devez donner un fichier')." ");
echo $retour;
echo '
';
exit();
}
//---------------------------------------------------------------------------
// Restore a folder (dossier)
if ( $_REQUEST['t']=='d')
{
echo '';
$cn=new Database();
$id=$cn->get_next_seq('dossier_id');
if ( strlen(trim($_REQUEST['database'])) == 0 )
{
$lname=$id." Restauration :".sql_string($_FILES['file']['name']);
}
else
{
$lname=$id." ".$_REQUEST['database'];
}
if (strlen(trim($_REQUEST['desc']))==0)
{
$ldesc=$lname;
}
else
{
$ldesc=sql_string($_REQUEST['desc']);
}
$sql="insert into ac_dossier (dos_id,dos_name,dos_description) values ($1,$2,$3)";
$cn->start();
try
{
$cn->get_value($sql,array($id,$lname,$ldesc));
}
catch ( Exception $e)
{
echo ''._("Echec de la restauration ").'';
$cn->rollback();
exit();
}
$cn->commit();
$name=domaine."dossier".$id;
echo $name;
$cn->exec_sql("create database ".$name." encoding='utf8'");
$args=" --no-owner -d $name ".$_FILES['file']['tmp_name'];
$cmd= escapeshellcmd(PG_RESTORE);
exec($cmd.$args);
$test=new Database($id);
if ( $test->exist_table('version') )
{
echo '
'._('Restauration réussie du dossier ').$lname.'
';
$test->close();
}
else
{
$test->close();
echo ' '._('Problème lors de la restauration ').$lname.'
';
$cn->exec_sql('delete from ac_dossier where dos_id=$1',array($id));
$cn->exec_sql('drop database '.$name);
exit();
}
$new_cn=new Database($id);
$new_cn->apply_patch($name,0);
echo ''._('Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus').'';
Dossier::synchro_admin($id);
echo $retour;
echo '';
}
//---------------------------------------------------------------------------
// Restore a modele
if ( $_REQUEST['t']=='m')
{
echo '';
$cn=new Database();
$id=$cn->get_next_seq('s_modid');
if ( strlen(trim($_REQUEST['database'])) == 0 )
$lname=$id." Restauration :".sql_string($_FILES['file']['name']);
else
$lname=$id." ".$_REQUEST['database'];
$sql="insert into modeledef (mod_id,mod_name,mod_desc) values (".$id.",'Restauration".$lname."','".$ldesc."') ";
$cn->start();
try
{
$cn->get_value($sql);
}
catch ( Exception $e)
{
echo ''._("Echec de la restauration ").'';
$cn->rollback();
exit();
}
$cn->commit();
$name=domaine."mod".$id;
$cn->exec_sql("create database ".$name." encoding='utf8'");
$args=" -d $name ".$_FILES['file']['tmp_name'];
$status=exec(PG_RESTORE.$args);
$test=new Database($id,'mod');
if ( $test->exist_table('version') )
{
echo '
'._('Restauration réussie du dossier ').$lname.'
';
$test->close();
}
else
{
$test->close();
echo ' '._('Problème lors de la restauration ').$lname.'
';
$cn->exec_sql('delete from modeledef where mod_id=$1',array($id));
$cn->exec_sql('drop database '.$name);
exit();
}
$new_cn=new Database($id,'mod');
$new_cn->apply_patch($name,0);
echo ''._('Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus').'';
echo $retour;
echo '';
}
}
else
{
echo '';
}