';
/*
* check and add an new folder
*/
if ( isset ($_POST["DATABASE"]) )
{
$repo=new Database();
try {
$dos=$http->post('DATABASE');
$template=$http->post("FMOD_ID","number");
} catch (Exception $ex) {
echo $ex->getMessage();
return;
}
$dos=sql_string($dos);
if (strlen($dos)==0)
{
echo _("Le nom du dossier est vide");
exit -1;
}
/*
* check template encoding
*/
// Get the modeledef.mod_id
/*
* If template is not empty
*/
if ( $template != 0 )
{
// compute template name
$template_name=domaine.'mod'.$template;
$encoding=$repo->get_value("select encoding from pg_database where ".
" datname=$1",array($template_name));
if ( $encoding != 6 )
{
alert(_('Désolé vous devez migrer ce modèle en unicode'));
echo '';
echo _('le modele ').domaine.'mod'.$_POST["FMOD_ID"]._(" doit être migré en unicode.");
echo _('Pour le passer en unicode, faites-en un backup puis restaurez le fichier reçu').'';
echo HtmlInput::button_anchor('Retour','admin-noalyss.php?action=dossier_mgt');
return;
}
}
/*
* Insert new dossier with description
*/
$desc=$http->post("DESCRIPTION");
$max_email=$http->post("max_email","number");
try
{
$repo->start();
if (isNumber($max_email) == 0) $max_email=-1;
$Res=$repo->exec_sql("insert into ac_dossier(dos_name,dos_description,dos_email)
values ($1,$2,$3)",array($dos,$desc,$max_email));
$l_id=$repo->get_current_seq('dossier_id');
$repo->commit();
}
catch (Exception $e)
{
$msg=_("Desole la creation de ce dossier a echoue,\n la cause la plus probable est".
' deux fois le même nom de dossier');
alert($msg);
$l_id=0;
$repo->rollback();
}
// If the id is not null, name successfully inserted
// Database created
if ( $l_id != 0)
{
/*
* We don't create and empty database
*/
if ($template != 0 )
{
//--
// setting the year
//--
$year=sql_string($_POST['YEAR']);
if ( strlen($year) != 4 || isNumber($year) == 0 || $year > 2100 || $year < 2000 || $year != round($year,0))
{
echo "$year"._(" est une année invalide");
$Res=$repo->exec_sql("delete from ac_dossier where dos_id=$l_id");
}
else
{
$Sql=sprintf("CREATE DATABASE %sDOSSIER%d encoding='UTF8' TEMPLATE %sMOD%d",
domaine,
$l_id,
domaine,
sql_string($_POST["FMOD_ID"]));
ob_start();
if ( $repo->exec_sql($Sql)==false)
{
echo "[".$Sql."]";
//ob_end_clean();
$repo->exec_sql("delete from ac_dossier where dos_id=$l_id");
echo "
"._(" Base de donnée ").domaine."mod".$_POST['FMOD_ID']." ".
_("est accèdée, déconnectez-vous d'abord")."
";
exit;
}
ob_flush();
// Connect to the new database
$cn=new Database($l_id);
//--year --
$Res=$cn->exec_sql("delete from parm_periode");
if ( ($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0 )
$fev=29;
else
$fev=28;
$Res=$cn->exec_sql("delete from user_local_pref where parameter_type='PERIODE'");
$nb_day=array(31,$fev,31,30,31,30,31,31,30,31,30,31);
$m=1;
foreach ($nb_day as $day)
{
$p_start=sprintf("01-%d-%s",$m,$year);
$p_end=sprintf("%d-%d-%s",$day,$m,$year);
$sql=sprintf("insert into parm_periode (p_start,p_end,p_exercice)
values (to_date('%s','DD-MM-YYYY'),to_date('%s','DD-MM-YYYY'),'%s')",
$p_start,$p_end,$year);
$Res=$cn->exec_sql($sql);
$m++;
}
$sql=" insert into jrn_periode(p_id,jrn_def_id,status) ".
"select p_id,jrn_def_id, 'OP'".
" from parm_periode cross join jrn_def";
$Res=$cn->exec_sql($sql);
Dossier::synchro_admin($l_id);
User::remove_inexistant_user($l_id);
}
}
else {
/*
* An empty database is asked, it is created
*/
$Sql=sprintf("CREATE DATABASE %sDOSSIER%d encoding='UTF8' ",
domaine,
$l_id,
domaine
);
ob_start();
if ( $repo->exec_sql($Sql)==false)
{
echo "[".$Sql."]";
//ob_end_clean();
$repo->exec_sql("delete from ac_dossier where dos_id=$l_id");
echo _("Echec création ");
exit;
}
ob_flush();
}
} // if $l_id != 0
} // $_POST[DATABASE]
?>
';
echo HtmlInput::button(_('Ajouter'),_('Ajouter un dossier')," onclick=\$('folder_add_id').show()");
echo '';
$header=new Sort_Table();
$url=$_SERVER['PHP_SELF']."?sa=list&action=".$_REQUEST['action'];
$header->add(_("id"),$url," order by dos_id asc"," order by dos_id desc","da","dd");
$header->add(_("Nom"),$url," order by dos_name asc"," order by dos_name desc","na","nd");
$header->add(_("Description"),$url," order by dos_description asc"," order by dos_description desc","da","dd");
$repo=new Dossier(0);
$repocn=new Database();
$ord=(isset($_REQUEST['ord']))?$_REQUEST['ord']:'na';
$sql_order=$header->get_sql_order($ord);
$Res=$repocn->get_array("select * from ac_dossier $sql_order");
$compteur=1;
$template="";
echo '
exec_sql("select mod_id,mod_name,mod_desc from
modeledef order by mod_name");
$count=Database::num_row($Res);
if ( $count == 0 )
{
echo _("pas de modèle disponible");
}
else
{
$template='";
}// if count = 0
$m_date=date('Y');
?>
get_value("select dos_name from ac_dossier where dos_id=$1",array($dossier_id));
if ( strlen(trim($name)) == 0 )
{
echo "
$msg "._('inexistant')."
";
return;
}
/**
* Check if db exists
*/
$str_name=sql_string(domaine.'dossier'.$dossier_id);
$database_exist=$cn->exist_database($str_name);
// if db exists for postgres then drop it
if ( $database_exist == 1)
{
$sql="drop database ".$str_name;
ob_start();
if ( $cn->exec_sql($sql)==false)
{
ob_end_clean();
echo "
";
echo _('Base de donnée ').domaine."dossier".$_REQUEST['d'].
_("est accèdée, déconnectez-vous d'abord")."
";
exit;
}
ob_flush();
}
// clean tables about this dossier
$sql="delete from jnt_use_dos where dos_id=$1";
$cn->exec_sql($sql,array($dossier_id));
$sql="delete from ac_dossier where dos_id=$1";
$cn->exec_sql($sql,array($dossier_id));
print '