';
// check and add an new folder
if ( isset ($_POST["DATABASE"]) ) {
$cn=DbConnect();
$dos=trim($_POST["DATABASE"]);
$dos=FormatString($dos);
if (strlen($dos)==0) {
echo ("Le nom du dossier est vide");
exit -1;
}
$encoding=getDbValue($cn,"select encoding from pg_database where ".
" datname='".domaine.'mod'.FormatString($_POST["FMOD_ID"])."'");
if ( $encoding != 6 ) {
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 widget::button_href('Retour','admin_repo.php?action=dossier_mgt');
exit();
}
$desc=FormatString($_POST["DESCRIPTION"]);
try {
StartSql($cn);
$Res=ExecSql($cn,"insert into ac_dossier(dos_name,dos_description)
values ('".$dos."','$desc')");
$l_id=GetSequence($cn,'dossier_id');
Commit($cn);
} catch (Exception $e) {
$msg="Desole la creation de ce dossier a echoue, la cause la plus probable est".
' deux fois le même nom de dossier';
echo '';
echo_debug(__FILE__.':'.__LINE__.'- echec ','Echec creation ',$e);
$l_id=0;
Rollback($cn);
}
// If the id is not null, name successfully inserted
// Database created
if ( $l_id != 0) {
//--
// setting the year
//--
$year=FormatString($_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=ExecSql($cn,"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,
FormatString($_POST["FMOD_ID"]));
echo_debug("[".$Sql."]");
ob_start();
if ( pg_query($cn,$Sql)==false) {
echo "[".$Sql."]";
ob_end_clean();
ExecSql($cn,"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();
$Res=ExecSql($cn,"insert into jnt_use_dos (use_id,dos_id) values (1,$l_id)");
// Connect to the new database
$cn=DbConnect($l_id);
//--year --
$Res=ExecSql($cn,"delete from parm_periode");
if ( ($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0 )
$fev=29;
else
$fev=28;
$Res=ExecSql($cn,"delete from user_local_pref where parameter_type='PERIODE'");
$nb_day=array(31,$fev,31,30,31,30,31,31,30,31,30,30);
$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=ExecSql($cn,$sql);
$m++;
}
$sql=sprintf("insert into parm_periode (p_start,p_end,p_exercice)
values (to_date('31-12-%s','DD-MM-YYYY'),to_date('31-12-%s','DD-MM-YYYY'),'%s')",
$year,$year,$year);
$Res=ExecSql($cn,$sql);
$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=ExecSql($cn,$sql);
}
} // if $l_id != 0
} // $_POST[DATABASE]
?>
Dossier Management
';
// show all dossiers
if ( $Res != null ) {
foreach ( $Res as $Dossier) {
if ( $compteur%2 == 0 )
$cl='class="odd"';
else
$cl='class="even"';
echo "
Base de donnée ".domaine."dossier".$_REQUEST['d']." est accèdée, déconnectez-vous d'abord
";
exit;
}
ob_flush();
$sql="delete from priv_user where priv_id in (select jnt_id from jnt_use_dos where dos_id=$1)";
ExecSqlParam($cn,$sql,array($_REQUEST['d']));
$sql="delete from jnt_use_dos where dos_id=$1";
ExecSqlParam($cn,$sql,array($_REQUEST['d']));
$sql="delete from ac_dossier where dos_id=$1";
ExecSqlParam($cn,$sql,array($_REQUEST['d']));
print '
';
print "Voilà le dossier ".h($name)." est effacé