/*
* This file is part of PhpCompta.
*
* PhpCompta 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.
*
* PhpCompta 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 PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* $Revision$
*/
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*! \file
* \brief Administration of the repository : creation of user, folder, security,
* templates... Accessible only by the administrator
*/
require_once("user_common.php");
include_once("ac_common.php");
include_once("postgres.php");
include_once("debug.php");
include_once("user_menu.php");
$rep=DbConnect();
include_once ("class_user.php");
$User=new cl_user($rep);
$User->Check();
html_page_start($User->theme);
echo_debug('admin_repo.php',__LINE__,"entering admin_repo");
if ($User->admin != 1) {
html_page_stop();
return;
}
echo '
Administration Globale
';
echo "
".MenuAdmin()."
";
?>
if ( isset ($_GET["action"]) ) {
if ( $_GET["action"]=="user_mgt" ) {
// Add user
if ( isset ($_POST["LOGIN"]) ) {
$cn=DbConnect();
$pass5=md5($_POST['PASS']);
$Res=ExecSql($cn,"insert into ac_users(use_first_name,use_name,use_login,use_active,use_pass)
values ('".$_POST["FNAME"]."','".$_POST["LNAME"]."','".$_POST["LOGIN"]."',1,'$pass5')");
} //SET login
// Show all the existing user on 7 columns
$cn=GetAllUser();
echo_debug('admin_repo.php',__LINE__,"Array = $cn");
$compteur=0;
?>
Gestion Utilisateurs
if ( $cn != null ) {
foreach ( $cn as $rUser) {
$compteur++;
if ( $compteur==0 ) echo "
';
?>
// check and add an user (see form below)
} // action=user_mgt
if ( $_GET["action"]=="dossier_mgt") {
echo '
';
// check and add an new folder
if ( isset ($_POST["DATABASE"]) ) {
$cn=DbConnect();
$dos=trim($_POST["DATABASE"]);
if (strlen($dos)==0) {
echo ("Dataname name is empty");
exit -1;
}
$desc=FormatString($_POST["DESCRIPTION"]);
$Res=ExecSql($cn,"insert into ac_dossier(dos_name,dos_description)
values ('".$dos."','$desc')");
// If the id is not null, name successfully inserted
// Database created
$l_id=GetDbId($dos);
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='ISO8859-1' TEMPLATE %sMOD%d",
domaine,
$l_id,
domaine,
$_POST["FMOD_ID"]);
echo_debug($Sql);
ob_start();
if ( pg_query($cn,$Sql)==false) {
ob_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);
//---
// Cleaning Action
//--
if ( isset($_POST['DOC'] ))
{
$Res=ExecSql($cn,"delete from action_gestion");
$Res=ExecSql($cn,"delete from document");
}
if ( isset($_POST['CARD']))
{
$Res=ExecSql($cn,"delete from attr_value");
$Res=ExecSql($cn,"delete from jnt_fic_att_value");
$Res=ExecSql($cn,"delete from fiche");
$Res=ExecSql($cn,"delete from action_gestion");
$Res=ExecSql($cn,"delete from document");
}
//--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);
}
} // if $l_id != 0
} // $_POST[DATABASE]
?>
';
// show all dossiers
if ( $Res != null ) {
foreach ( $Res as $Dossier) {
if ( $compteur%2 == 0 )
$cl='class="odd"';
else
$cl='class="even"';
echo "
$Dossier[dos_name]
".$Dossier['dos_description']."
";
$compteur++;
}
echo "";
}
// Load the available Templates
$Res=ExecSql($cn,"select mod_id,mod_name,mod_desc from
modeledef order by mod_name");
$count=pg_NumRows($Res);
if ( $count == 0 ) {
echo "No template available";
} else {
$template='";
}// if count = 0
$m_date=date('Y');
// Add a new folder
?>
',
$mod['mod_name'],
$mod['mod_desc']);
}// for
echo "
";
}// if count = 0
echo "Si vous voulez récupérer toutes les adaptations d'un dossier ".
" dans un autre dossier, vous pouvez en faire un modèle.".
" Seules les fiches, la structure des journaux, les périodes,... seront reprises ".
"et aucune données du dossier sur lequel le dossier est basé.";
// Show All available folder
$Res=ExecSql($cn,"select dos_id, dos_name,dos_description from ac_dossier
order by dos_name");
$count=pg_NumRows($Res);
$available="";
if ( $count != 0 ) {
$available='';
}//if count !=0
?>
}// action = modele_mgt
} // action is set
?>