diff --git a/html/fiche_search.php b/html/fiche_search.php
index c787e992a..ce7b84c39 100644
--- a/html/fiche_search.php
+++ b/html/fiche_search.php
@@ -34,12 +34,6 @@ $rep=DbConnect();
include_once ("class_user.php");
$User=new cl_user($rep);
$User->Check();
-include_once ("postgres.php");
-/* Admin. Dossier */
-$rep=DbConnect();
-include_once ("class_user.php");
-$User=new cl_user($rep);
-$User->Check();
include_once ("check_priv.php");
// Get The priv on the selected folder
@@ -80,8 +74,7 @@ function SetData (name_ctl,value,value_2,value_3,value_4,value_5,value_6) {
}
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
$r="";
foreach ($HTTP_GET_VARS as $key=>$element) {
diff --git a/html/form.php b/html/form.php
index a7fd378fb..d634c6d49 100644
--- a/html/form.php
+++ b/html/form.php
@@ -52,8 +52,7 @@ if ( $g_UserProperty['use_admin'] == 0 ) {
ShowMenuComptaForm($g_dossier);
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
if ( isset($_GET["PHPSESSID"] )) {
$sessid=$_GET["PHPSESSID"];
}
diff --git a/html/jrn_add.php b/html/jrn_add.php
index 44e0d065c..14e3498bb 100644
--- a/html/jrn_add.php
+++ b/html/jrn_add.php
@@ -50,8 +50,7 @@ if ( $g_UserProperty['use_admin'] == 0 ) {
//echo '';
echo JS_SEARCH_POSTE;
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
If ( isset ($_POST["JRN_ADD"]) ) {
if ( !isset($_POST["p_jrn_name"]) || ! isset($_POST["p_jrn_type"] )) {
diff --git a/html/jrn_csv.php b/html/jrn_csv.php
index 82abb4d0a..75bfd0bb0 100644
--- a/html/jrn_csv.php
+++ b/html/jrn_csv.php
@@ -25,8 +25,7 @@ include_once ("ac_common.php");
include_once ("postgres.php");
include("class_jrn.php");
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
include ('class_user.php');
diff --git a/html/jrn_detail.php b/html/jrn_detail.php
index 58f82cd23..b6456c0b4 100644
--- a/html/jrn_detail.php
+++ b/html/jrn_detail.php
@@ -55,8 +55,7 @@ if ( isset( $_GET['p_jrn'] )) {
}
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
If ( isset ($_POST["JRN_UPD"] )) {
if ( !isset($_POST["p_jrn_name"]) ) {
diff --git a/html/jrn_op_detail.php b/html/jrn_op_detail.php
index e5653f773..e80e1e4f0 100644
--- a/html/jrn_op_detail.php
+++ b/html/jrn_op_detail.php
@@ -39,8 +39,7 @@ if ( isset( $p_jrn )) {
session_register("g_jrn");
$g_jrn=$p_jrn;
}
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
$jrn_op=$_GET['jrn_op'];
list ($l_array,$max_deb,$max_cred)=GetData($cn,$jrn_op);
foreach ($l_array as $key=>$element) {
diff --git a/html/jrn_pdf.php b/html/jrn_pdf.php
index df903a902..5cbbbb5be 100644
--- a/html/jrn_pdf.php
+++ b/html/jrn_pdf.php
@@ -35,8 +35,7 @@ include_once("impress_inc.php");
include_once("preference.php");
include_once("class_jrn.php");
echo_debug(__FILE__,__LINE__,"imp pdf journaux");
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
$l_type="JRN";
$centr=" Non centralisé";
$l_centr=0;
diff --git a/html/jrn_search.php b/html/jrn_search.php
index 30b6e2e53..934a7fd78 100644
--- a/html/jrn_search.php
+++ b/html/jrn_search.php
@@ -50,10 +50,9 @@ $c_comment="";
$c_montant="";
$c_internal="";
$c_date="";
-$l_Db=sprintf("dossier%d",$g_dossier);
$condition="";
$part=" where ";
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
// if search then build the condition
if ( isset ($_POST["search"]) ) {
$c1=0;
diff --git a/html/login.php b/html/login.php
index 19f9163b3..9295a6fad 100644
--- a/html/login.php
+++ b/html/login.php
@@ -31,7 +31,7 @@ if ( isset ($_POST["p_user"] ) ) {
session_register("g_user");
session_register("g_pass");
//$cn=pg_connect("dbname=account_repository user='phpcompta' ");
- $cn=DbConnect("account_repository");
+ $cn=DbConnect();
// Verif if User and Pass match DB
// if no, then redirect to the login page
$rep=DbConnect();
diff --git a/html/modify_op.php b/html/modify_op.php
index 365cbbc3b..a01695f90 100644
--- a/html/modify_op.php
+++ b/html/modify_op.php
@@ -38,8 +38,7 @@ include_once ("class_user.php");
$User=new cl_user($rep);
$User->Check();
-$dossier=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($dossier);
+$cn=DbConnect($g_dossier);
if ( isset( $p_jrn )) {
session_register("g_jrn");
diff --git a/html/pcmn_update.php b/html/pcmn_update.php
index adde7118f..ea3dd5312 100644
--- a/html/pcmn_update.php
+++ b/html/pcmn_update.php
@@ -64,8 +64,7 @@ if ( isset ($p_start)) {
}
ShowMenuPcmn($g_start);
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
echo '
';
/* Analyse ce qui est demandé */
/* Effacement d'une ligne */
diff --git a/html/poste_csv.php b/html/poste_csv.php
index 6d102f1a1..bd7811038 100644
--- a/html/poste_csv.php
+++ b/html/poste_csv.php
@@ -26,8 +26,7 @@ header('Content-type: application/csv');
header('Content-Disposition: attachment;filename="poste.csv"',FALSE);
/* Admin. Dossier */
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
$User=new cl_user($cn);
@@ -67,4 +66,4 @@ echo "\"Code interne\"\t ".
sprintf("%8.4f",$tot_cred)."\n";
exit;
-?>
\ No newline at end of file
+?>
diff --git a/html/poste_pdf.php b/html/poste_pdf.php
index 94ac12669..cf058f35b 100644
--- a/html/poste_pdf.php
+++ b/html/poste_pdf.php
@@ -28,8 +28,7 @@ include_once("class.ezpdf.php");
include_once("impress_inc.php");
include("poste.php");
- $l_Db=sprintf("dossier%d",$g_dossier);
- $cn=DbConnect($l_Db);
+ $cn=DbConnect($g_dossier);
foreach ($HTTP_POST_VARS as $key=>$element) {
${"$key"}=$element;
}
diff --git a/html/poste_search.php b/html/poste_search.php
index b6248adf1..027778098 100644
--- a/html/poste_search.php
+++ b/html/poste_search.php
@@ -39,9 +39,8 @@ if ( ! isset ( $g_dossier ) ) {
$c_comment="";
$c_class="";
-$l_Db=sprintf("dossier%d",$g_dossier);
$condition="";
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
if ( isset($_POST['search']) ) {
$c1=0;
foreach( $HTTP_POST_VARS as $key=>$element){
diff --git a/html/print_balance.php b/html/print_balance.php
index 91739b2e4..474e8be4e 100644
--- a/html/print_balance.php
+++ b/html/print_balance.php
@@ -37,8 +37,7 @@ include_once("poste.php");
include_once("class_balance.php");
include_once("preference.php");
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
$bal=new Balance($cn);
diff --git a/html/print_invoice.php b/html/print_invoice.php
index dc2c54b63..38d99f325 100644
--- a/html/print_invoice.php
+++ b/html/print_invoice.php
@@ -38,8 +38,7 @@ include_once("impress_inc.php");
include_once("fiche_inc.php");
include_once("user_common.php");
echo_debug(__FILE__,__LINE__,"imp pdf journaux");
-$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
foreach ($HTTP_POST_VARS as $key=>$element) {
${"$key"}=$element;
echo_debug(__FILE__,__LINE__,"key => $key element $element");
diff --git a/html/rate_chg.php b/html/rate_chg.php
index 0a1acfb5e..00ae2f472 100644
--- a/html/rate_chg.php
+++ b/html/rate_chg.php
@@ -26,8 +26,7 @@ include_once("postgres.php");
function SaveRate(p_code,p_rate)
{
- $dossier=sprintf("dossier%d",$g_dossier);
- $cn=DbConnect($dossier);
+ $cn=DbConnect($g_dossier);
$Res=ExecSql($cn,"update parm_money set pm_rate=$f_rate where pm_code='$f_code'");
?>
// this.location.reload();
@@ -41,7 +40,7 @@ $User=new cl_user($rep);
$User->Check();
if ( $g_UserProperty['use_admin'] ) return;
$dossier=sprint("dossier%d",$g_dossier);
-$cn=DbConnect($dossier);
+$cn=DbConnect($g_dossier);
$Res=ExecSql($cn,"select pm_code, pm_rate from parm_money where pm_code='$p_code'");
$l_line=pg_fetch_array($Res,0);
diff --git a/html/recherche.php b/html/recherche.php
index 009578601..abf4df2af 100644
--- a/html/recherche.php
+++ b/html/recherche.php
@@ -36,7 +36,7 @@ include_once ("check_priv.php");
$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
include ('class_user.php');
$User=new cl_user($cn);
$User->Check();
diff --git a/html/send.php b/html/send.php
index b55c4f2b3..e4b9435e1 100644
--- a/html/send.php
+++ b/html/send.php
@@ -24,8 +24,7 @@
include_once("class.ezpdf.php");
include_once("impress_inc.php");
echo_debug(__FILE__,__LINE__,"imp pdf journaux");
- $l_Db=sprintf("dossier%d",$g_dossier);
- $cn=DbConnect($l_Db);
+ $cn=DbConnect($g_dossier);
$name_jrn=GetJrnName($cn,$_POST["p_id"]);
$ret="";
diff --git a/html/send_jrn_pdf.php b/html/send_jrn_pdf.php
index 72217a6b8..936897b2f 100644
--- a/html/send_jrn_pdf.php
+++ b/html/send_jrn_pdf.php
@@ -35,7 +35,7 @@ include_once("impress_inc.php");
include_once("preference.php");
echo_debug(__FILE__,__LINE__,"imp pdf journaux");
$l_Db=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
$l_type="JRN";
$centr=" Non centralisé";
$l_centr=0;
diff --git a/html/send_poste_pdf.php b/html/send_poste_pdf.php
index f73451daf..c5241400f 100644
--- a/html/send_poste_pdf.php
+++ b/html/send_poste_pdf.php
@@ -28,8 +28,7 @@
include_once("impress_inc.php");
include("poste.php");
echo_debug(__FILE__,__LINE__,"imp pdf journaux");
- $l_Db=sprintf("dossier%d",$g_dossier);
- $cn=DbConnect($l_Db);
+ $cn=DbConnect($g_dossier);
foreach ($HTTP_POST_VARS as $key=>$element) {
${"$key"}=$element;
}
diff --git a/html/show_tva.php b/html/show_tva.php
index 73745f3d0..80013007e 100644
--- a/html/show_tva.php
+++ b/html/show_tva.php
@@ -42,9 +42,8 @@ function GetIt(ctl,tva_id) {
-$l_Db=sprintf("dossier%d",$g_dossier);
$condition="";
-$cn=DbConnect($l_Db);
+$cn=DbConnect($g_dossier);
$Res=ExecSql($cn,"select * from tva_rate order by tva_rate desc");
$Max=pg_NumRows($Res);
echo "
";
diff --git a/html/stock.php b/html/stock.php
index 33dd66837..ead20e211 100644
--- a/html/stock.php
+++ b/html/stock.php
@@ -52,8 +52,7 @@ if ( $g_UserProperty['use_admin'] == 0 ) {
}
}
-$l_dossier=sprintf("dossier%d",$g_dossier);
-$cn=DbConnect($l_dossier);
+$cn=DbConnect($g_dossier);
//Show the top menu
include_once ("user_menu.php");
@@ -62,9 +61,9 @@ ShowMenuCompta($g_dossier,$g_UserProperty);
// Show Menu Left
$left_menu=ShowMenuAdvanced();
-echo '';
$action= ( isset ($_GET['action']))? $_GET['action']:"";
include_once("stock_inc.php");
diff --git a/include/check_priv.php b/include/check_priv.php
index 9d5fa32a6..9725715da 100644
--- a/include/check_priv.php
+++ b/include/check_priv.php
@@ -43,8 +43,7 @@ include_once("postgres.php");
function CheckJrn($p_dossier,$p_user,$p_jrn)
{
if ( CheckIsAdmin( $p_user) == 1 ) return 2;
- $l_Db=sprintf("dossier%d",$p_dossier);
- $cn=DbConnect($l_Db);
+ $cn=DbConnect($p_dossier);
// Special
// p_jrn = 0 ==> grand livre access if there is no uj_prix=X
if ( $p_jrn == 0 ) {
@@ -134,8 +133,7 @@ function CheckJrn($p_dossier,$p_user,$p_jrn)
function CheckAction ( $p_dossier,$p_login,$p_action_id)
{
if ( CheckIsAdmin ($p_login) ) return 1;
- $l_Db=sprintf("dossier%d",$p_dossier);
- $cn=DbConnect($l_Db);
+ $cn=DbConnect($p_dossier);
$Res=ExecSql($cn,"select * from user_sec_act where ua_login='$p_login' and ua_act_id=$p_action_id");
$Count=pg_NumRows($Res);
if ( $Count == 0 ) return 0;
diff --git a/include/class_user.php b/include/class_user.php
index 767bc3bb8..f91a037ac 100644
--- a/include/class_user.php
+++ b/include/class_user.php
@@ -53,7 +53,7 @@ class cl_user {
$res=0;
$pass5=md5($this->pass);
if ( $this->valid == 1 ) { return; }
- $cn=DbConnect("account_repository");
+ $cn=DbConnect();
if ( $cn != false ) {
$sql="select ac_users.use_login,ac_users.use_active, ac_users.use_pass
from ac_users
diff --git a/include/compta_menu.php b/include/compta_menu.php
index 9e7b9b29f..1ab6f1ed7 100644
--- a/include/compta_menu.php
+++ b/include/compta_menu.php
@@ -110,8 +110,7 @@ function c_ShowMenuJrnUser($p_dossier,$p_user)
include_once("postgres.php");
include_once("class_user.php");
- $l_jrn=sprintf("dossier%d",$p_dossier);
- $Cn=DbConnect($l_jrn);
+ $Cn=DbConnect($p_dossier);
$User=new cl_user($Cn);
if ( $User->Admin() ==0) {
$Ret=ExecSql($Cn,"select jrn_def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc,uj_priv,
diff --git a/include/jrn.php b/include/jrn.php
index 041909c3c..5464ed401 100644
--- a/include/jrn.php
+++ b/include/jrn.php
@@ -46,8 +46,7 @@ function RecordJrn($p_dossier,$p_user,$p_jrn,$p_MaxDeb,$p_MaxCred,$p_array = nul
${"e_class_cred$i"}=0;
${"e_mont_cred$i"}=0;
}
- $l_dossier=sprintf("dossier%d",$p_dossier);
- $cn=DbConnect($l_dossier);
+ $cn=DbConnect($p_dossier);
// userPref contient la periode par default
$userPref=GetUserPeriode($cn,$p_user);
list ($l_date_start,$l_date_end)=GetPeriode($cn,$userPref);
@@ -531,8 +530,7 @@ function GetJrnProperty($p_cn,$p_jrn)
*/
function GetJrnProp($p_dossier,$p_jrn)
{
- $l_dossier=sprintf("dossier%d",$p_dossier);
- $cn=DbConnect($l_dossier);
+ $cn=DbConnect($p_dossier);
$Res=ExecSql($cn,"select jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type,
jrn_deb_max_line,jrn_cred_max_line,jrn_def_ech,jrn_def_ech_lib,jrn_def_code,
jrn_def_fiche_deb,jrn_def_fiche_deb
@@ -608,7 +606,7 @@ function ViewJrn($p_dossier,$p_user,$p_jrn,$p_url,$p_array=null) {
$db=sprintf("dossier%d",$p_dossier);
$l_prop=GetJrnProp($p_dossier,$p_jrn);
echo "".$l_prop['jrn_def_name']."( ".$l_prop['jrn_def_code'].")"."
";
- $cn=DbConnect($db);
+ $cn=DbConnect($p_dossier);
if ( $p_array == null) {
include_once("preference.php");
$l_periode=GetUserPeriode($cn,$p_user);
diff --git a/include/poste.php b/include/poste.php
index ce40f8dce..8b8c480a4 100644
--- a/include/poste.php
+++ b/include/poste.php
@@ -39,8 +39,7 @@ function GetPosteLibelle($p_dossier,$p_id,$is_cn=0)
include_once("postgres.php");
if ( ! isset($is_cn) ) $is_cn=0;
if ( $is_cn == 0) {
- $l_dossier=sprintf("dossier%d",$p_dossier);
- $cn=DbConnect($l_dossier);
+ $cn=DbConnect($p_dossier);
} else {
$cn=$p_dossier;
}
@@ -63,8 +62,7 @@ function GetPosteLibelle($p_dossier,$p_id,$is_cn=0)
*/
function GetNumberLine($p_dossier,$p_jrn)
{
- $l_dossier=sprintf("dossier%d",$p_jrn);
- $cn=DbConnect($l_dossier);
+ $cn=DbConnect($p_dossier);
$Res=ExecSql($cn,"select jrn_deb_max_line,jrn_cred_max_line from jrn_def where jrn_def_id=$p_jrn");
if ( pg_NumRows($Res) == 0 ) {
echo " Journal non trouvé
";
diff --git a/include/postgres.php b/include/postgres.php
index 61aca6066..c3d9d7053 100644
--- a/include/postgres.php
+++ b/include/postgres.php
@@ -138,9 +138,14 @@ function ShowDossier($p_type,$p_first=0,$p_max=10,$p_Num=0) {
* todo : replace hardcoded by variable placed in
* constant.php
*/
-function DbConnect($p_db="account_repository") {
+function DbConnect($p_db=-1) {
+ if ( $p_db==-1)
+ $l_dossier="account_repository";
+ else
+ $l_dossier=sprintf("dossier%d",$p_db);
+
$password=phpcompta_password;
- $a=pg_connect("dbname=$p_db host=127.0.0.1 user='phpcompta' password='$password'");
+ $a=pg_connect("dbname=$l_dossier host=127.0.0.1 user='phpcompta' password='$password'");
echo_debug ("connect to $p_db");
return $a;
}
@@ -338,8 +343,8 @@ function GetLogin($p_uid)
function SyncRight($p_dossier,$p_user) {
$priv=GetPriv($p_dossier,$p_user);
$right=$priv[0];
- $ldb=sprintf("dossier%d",$p_dossier);
- $cn=DbConnect($ldb);
+
+ $cn=DbConnect($p_dossier);
$sql="insert into user_sec_jrn(uj_login,uj_jrn_id,uj_priv) ".
"select '".$p_user."',jrn_def_id,'".$right."' from jrn_def ".
diff --git a/include/top_menu_compta.php b/include/top_menu_compta.php
index 26f843a81..d7ec6a80d 100644
--- a/include/top_menu_compta.php
+++ b/include/top_menu_compta.php
@@ -209,8 +209,7 @@ function ShowMenuJrn($p_dossier)
echo '';
echo '| Création |
';
include_once("postgres.php");
- $l_jrn=sprintf("dossier%d",$p_dossier);
- $Cn=DbConnect($l_jrn);
+ $Cn=DbConnect($p_dossier);
$Ret=ExecSql($Cn,"select jrn_def_id,jrn_def_name,
jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc
from jrn_def join jrn_type on jrn_def_type=jrn_type_id");
@@ -329,8 +328,7 @@ function ShowMenuRecherche($p_dossier,$p_jrn,$p_array=null)
*/
function ShowMenuComptaForm($p_dossier) {
include_once("postgres.php");
- $l_dossier=sprintf("dossier%d",$p_dossier);
- $cn=DbConnect($l_dossier);
+ $cn=DbConnect($p_dossier);
echo '