noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 39/107: Code cleaning : split database into d


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 39/107: Code cleaning : split database into database (for noalyss) and databasecore , with the functions
Date: Mon, 26 Aug 2019 10:31:54 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 2e74ca5bdfdd9f3383e88a8611d8cae42d87433a
Author: Dany De Bontridder <address@hidden>
Date:   Wed Jul 24 22:47:32 2019 +0200

    Code cleaning : split database into database (for noalyss) and databasecore 
,
    with the functions
---
 dev/SQL/index.php                                  |   2 +-
 dev/SQL/template/script_sql.php                    |   2 +-
 html/ajax.php                                      |   2 +-
 html/ajax_misc.php                                 |   2 +-
 html/ajax_test.php                                 |   2 +-
 html/compute.php                                   |   2 +-
 html/direct.php                                    |   2 +-
 html/do.php                                        |   2 +-
 html/export.php                                    |   2 +-
 html/extension.raw.php                             |   2 +-
 html/fid.php                                       |   2 +-
 html/fid_card.php                                  |   2 +-
 html/install.php                                   |   2 +-
 html/login.php                                     |   2 +-
 html/logout.php                                    |   2 +-
 html/popup.php                                     |   2 +-
 html/recherche.php                                 |   2 +-
 html/test.php                                      |   2 +-
 html/user_login.php                                |   2 +-
 include/admin_repo.inc.php                         |   2 +-
 include/ajax/ajax_anc_search.php                   |   2 +-
 include/ajax/ajax_auto_anc_card.php                |   2 +-
 include/ajax/ajax_card.php                         |   2 +-
 include/ajax/ajax_get_receipt.php                  |   2 +-
 include/ajax/ajax_history.php                      |   2 +-
 include/ajax/ajax_ledger.php                       |   2 +-
 include/ajax/ajax_mod_document.php                 |   2 +-
 include/ajax/ajax_poste.php                        |   2 +-
 include/ajax/ajax_search_operation.php             |   2 +-
 include/ajax/ajax_todo_list.php                    |   2 +-
 include/ajax/ajax_update_predef.php                |   2 +-
 include/cfgfiche.inc.php                           |   2 +-
 include/cfgledger.inc.php                          |   2 +-
 include/class/acc_account.class.php                |   2 +-
 include/class/acc_account_ledger.class.php         |   2 +-
 include/class/acc_bilan.class.php                  |   2 +-
 include/class/acc_ledger_info.class.php            |   2 +-
 include/class/acc_reconciliation.class.php         |   2 +-
 include/class/acc_tva.class.php                    |   2 +-
 include/class/admin.class.php                      |   2 +-
 include/class/anc_group.class.php                  |   2 +-
 include/class/anc_group_operation.class.php        |   2 +-
 include/class/anc_plan.class.php                   |   2 +-
 include/class/anc_print.class.php                  |   2 +-
 include/class/bank.class.php                       |   2 +-
 include/class/customer.class.php                   |   2 +-
 include/class/database.class.php                   | 116 +++
 include/class/dossier.class.php                    |   2 +-
 include/class/exercice.class.php                   |   2 +-
 include/class/fiche_attr.class.php                 |   2 +-
 include/class/manager.class.php                    |   2 +-
 include/class/periode.class.php                    |   2 +-
 include/class/print_ledger.class.php               |   2 +-
 include/class/supplier.class.php                   |   2 +-
 include/class/user.class.php                       |   2 +-
 include/database/fiche_def_ref_sql.class.php       |   2 +-
 include/database/jrn_def_sql.class.php             |   2 +-
 include/database/jrn_periode_sql.class.php         |   2 +-
 include/database/menu_ref_sql.class.php            |   2 +-
 include/database/parm_periode_sql.class.php        |   2 +-
 include/database/poste_analytique_sql.class.php    |   2 +-
 include/database/profile_menu_sql.class.php        |   2 +-
 include/database/profile_sql.class.php             |   2 +-
 include/database/tag_sql.class.php                 |   2 +-
 include/database/tva_rate_sql.class.php            |   2 +-
 include/database/user_filter_sql.class.php         |   2 +-
 include/database/v_tva_rate_sql.class.php          |   2 +-
 include/export/export_balance_csv.php              |   2 +-
 include/export/export_balance_pdf.php              |   2 +-
 include/export/export_bilan_oth.php                |   2 +-
 include/export/export_document_template.php        |   2 +-
 include/export/export_fiche_balance_csv.php        |   2 +-
 include/export/export_fiche_balance_pdf.php        |   2 +-
 include/export/export_fiche_csv.php                |   2 +-
 include/export/export_fiche_detail_csv.php         |   2 +-
 include/export/export_fiche_detail_pdf.php         |   2 +-
 include/export/export_fiche_pdf.php                |   2 +-
 include/export/export_form_csv.php                 |   2 +-
 include/export/export_form_pdf.php                 |   2 +-
 include/export/export_gl_csv.php                   |   2 +-
 include/export/export_gl_pdf.php                   |   2 +-
 include/export/export_ledger_csv.php               |   2 +-
 include/export/export_ledger_pdf.php               |   2 +-
 include/export/export_poste_detail_csv.php         |   2 +-
 include/export/export_poste_detail_pdf.php         |   2 +-
 include/export/export_rec_csv.php                  |   2 +-
 include/export/export_receipt.php                  |   2 +-
 include/export/export_reportinit_csv.php           |   2 +-
 include/export/export_security_pdf.php             |   2 +-
 include/ext/dummy/dummy.php                        |   2 +-
 include/extension_choice.inc.php                   |   2 +-
 include/extension_get.inc.php                      |   2 +-
 include/fiche.inc.php                              |   2 +-
 include/header_print.php                           |   2 +-
 include/impress_bilan.inc.php                      |   2 +-
 include/impress_gl_comptes.inc.php                 |   2 +-
 include/impress_jrn.inc.php                        |   2 +-
 include/impress_poste.inc.php                      |   2 +-
 include/impress_rapport.inc.php                    |   2 +-
 include/lib/ac_common.php                          |   2 +-
 ...{database.class.php => database_core.class.php} | 871 +++++++++------------
 include/lib/single_record.class.php                |   2 +-
 include/lib/user_common.php                        |   2 +-
 include/param_pcmn.inc.php                         |   2 +-
 include/param_sec.inc.php                          |   2 +-
 include/preod.inc.php                              |   2 +-
 include/recover.php                                |   4 +-
 include/report.inc.php                             |   2 +-
 include/user_detail.inc.php                        |   2 +-
 109 files changed, 609 insertions(+), 594 deletions(-)

diff --git a/dev/SQL/index.php b/dev/SQL/index.php
index c6b1500..14a5a37 100644
--- a/dev/SQL/index.php
+++ b/dev/SQL/index.php
@@ -9,7 +9,7 @@ require_once '../../include/constant.php';
 const REPOSITORY_DB=1;
 const ACCOUNT_DB=2;
 
-require_once NOALYSS_INCLUDE."/lib/database.class.php";
+require_once NOALYSS_INCLUDE."/class/database.class.php";
 require_once NOALYSS_INCLUDE."/lib/iselect.class.php";
 require_once NOALYSS_INCLUDE."/lib/http_input.class.php";
 
diff --git a/dev/SQL/template/script_sql.php b/dev/SQL/template/script_sql.php
index f162dd1..f441edc 100644
--- a/dev/SQL/template/script_sql.php
+++ b/dev/SQL/template/script_sql.php
@@ -20,7 +20,7 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
 
 /**
diff --git a/html/ajax.php b/html/ajax.php
index 1a24adc..5bf6266 100644
--- a/html/ajax.php
+++ b/html/ajax.php
@@ -14,7 +14,7 @@
  */
 if ( ! defined ('ALLOWED') ) define ('ALLOWED',1);
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/icon_action.class.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/class/extension.class.php';
diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 39371f2..6cab5ad 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -38,7 +38,7 @@
 if ( ! defined('ALLOWED')) define ('ALLOWED',1);
 
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/class/fiche.class.php';
 require_once NOALYSS_INCLUDE.'/lib/iradio.class.php';
 require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
diff --git a/html/ajax_test.php b/html/ajax_test.php
index 01fd2b5..feb8dd1 100644
--- a/html/ajax_test.php
+++ b/html/ajax_test.php
@@ -31,7 +31,7 @@
 
 include_once  "../include/constant.php";
 include_once NOALYSS_INCLUDE."/lib/ac_common.php";
-require_once  NOALYSS_INCLUDE."/lib/database.class.php";
+require_once  NOALYSS_INCLUDE."/class/database.class.php";
 require_once  NOALYSS_INCLUDE."/class/dossier.class.php";
 require_once  NOALYSS_INCLUDE."/lib/html_input.class.php";
 require_once  NOALYSS_INCLUDE."/lib/http_input.class.php";
diff --git a/html/compute.php b/html/compute.php
index cb114da..b6114eb 100644
--- a/html/compute.php
+++ b/html/compute.php
@@ -31,7 +31,7 @@
  * Must return at least tva, htva and tvac
  */
 require_once '../include/constant.php';
-require_once  NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once  NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/class/acc_compute.class.php';
 require_once  NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once  NOALYSS_INCLUDE.'/class/acc_tva.class.php';
diff --git a/html/direct.php b/html/direct.php
index ed079f8..d08d460 100644
--- a/html/direct.php
+++ b/html/direct.php
@@ -19,7 +19,7 @@
  */
 
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 
 $cn=Dossier::connect();
diff --git a/html/do.php b/html/do.php
index be77861..532b9ca 100644
--- a/html/do.php
+++ b/html/do.php
@@ -23,7 +23,7 @@ define('ALLOWED',1);
  * \brief Main file
  */
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/user_common.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
diff --git a/html/export.php b/html/export.php
index 0d8cf6d..d32bc49 100644
--- a/html/export.php
+++ b/html/export.php
@@ -27,7 +27,7 @@
 define ('ALLOWED',1);
 require_once '../include/constant.php';
 global $g_user,$cn,$g_parameter;
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
 $gDossier=dossier::id();
diff --git a/html/extension.raw.php b/html/extension.raw.php
index 2d1eb93..728aafa 100644
--- a/html/extension.raw.php
+++ b/html/extension.raw.php
@@ -24,7 +24,7 @@
  * the security. Load several javascript files
  */
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
diff --git a/html/fid.php b/html/fid.php
index 124860c..005b11d 100644
--- a/html/fid.php
+++ b/html/fid.php
@@ -34,7 +34,7 @@
  */
 require_once '../include/constant.php';
 require_once NOALYSS_INCLUDE.'/class/noalyss_parameter_folder.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/user_common.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
diff --git a/html/fid_card.php b/html/fid_card.php
index 57577bb..0133dca 100644
--- a/html/fid_card.php
+++ b/html/fid_card.php
@@ -26,7 +26,7 @@
  */
 
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 /*!\brief
diff --git a/html/install.php b/html/install.php
index b9aa12b..75b2498 100644
--- a/html/install.php
+++ b/html/install.php
@@ -282,7 +282,7 @@ if ( ! file_exists(NOALYSS_INCLUDE.'/config.inc.php')) {
 // magic_quotes_sybase = Off
 // include_path
 require_once NOALYSS_INCLUDE.'/lib/config_file.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
 // we shouldn't use it 
 // if ( defined ("MULTI") && MULTI==1) { create_htaccess();}
diff --git a/html/login.php b/html/login.php
index e6ae4dd..0890408 100644
--- a/html/login.php
+++ b/html/login.php
@@ -25,7 +25,7 @@ include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
  * \brief Login page
  */
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 // Verif if User and Pass match DB
     // if no, then redirect to the login page
 $rep=new Database();
diff --git a/html/logout.php b/html/logout.php
index be049ff..19db731 100644
--- a/html/logout.php
+++ b/html/logout.php
@@ -22,7 +22,7 @@
  */
 require_once '../include/constant.php';
 require_once ("lib/ac_common.php");
-require_once('lib/database.class.php');
+require_once('class/database.class.php');
 session_unset();
 
 html_page_start("classic");
diff --git a/html/popup.php b/html/popup.php
index f1a3c8a..b985af5 100644
--- a/html/popup.php
+++ b/html/popup.php
@@ -23,7 +23,7 @@ require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
 require_once NOALYSS_INCLUDE.'/lib/html_input.class.php';
 require_once NOALYSS_INCLUDE.'/lib/icon_action.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/class/periode.class.php';
diff --git a/html/recherche.php b/html/recherche.php
index 03f35e2..b2ebdba 100644
--- a/html/recherche.php
+++ b/html/recherche.php
@@ -37,7 +37,7 @@ $http=new HttpInput();
 
 $gDossier=dossier::id();
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 /* Admin. Dossier */
 
 $cn=Dossier::connect();
diff --git a/html/test.php b/html/test.php
index bcb72c3..7fd9477 100644
--- a/html/test.php
+++ b/html/test.php
@@ -31,7 +31,7 @@
 
 include_once("../include/constant.php");
 include_once("lib/ac_common.php");
-require_once('lib/database.class.php');
+require_once('class/database.class.php');
 require_once ('class/dossier.class.php');
 require_once('lib/html_input.class.php');
 require_once('lib/icon_action.class.php');
diff --git a/html/user_login.php b/html/user_login.php
index d1f0376..6121be6 100644
--- a/html/user_login.php
+++ b/html/user_login.php
@@ -23,7 +23,7 @@
 // Copyright Author Dany De Bontridder address@hidden
 require_once '../include/constant.php';
 include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/itext.class.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
 require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
diff --git a/include/admin_repo.inc.php b/include/admin_repo.inc.php
index 821a81c..a18e4ab 100644
--- a/include/admin_repo.inc.php
+++ b/include/admin_repo.inc.php
@@ -27,7 +27,7 @@ if ( ! defined ('ALLOWED_ADMIN')) { die (_('Non autorisé'));}
 include_once NOALYSS_INCLUDE."/class/user.class.php";
 require_once NOALYSS_INCLUDE."/lib/user_common.php";
 include_once NOALYSS_INCLUDE."/lib/ac_common.php";
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE."/lib/user_menu.php";
 require_once NOALYSS_INCLUDE."/lib/http_input.class.php";
 require_once NOALYSS_INCLUDE."/lib/icon_action.class.php";
diff --git a/include/ajax/ajax_anc_search.php b/include/ajax/ajax_anc_search.php
index 071ac43..5a4711c 100644
--- a/include/ajax/ajax_anc_search.php
+++ b/include/ajax/ajax_anc_search.php
@@ -31,7 +31,7 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas 
permis');
 require_once NOALYSS_INCLUDE.'/lib/itext.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ibutton.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/class/anc_plan.class.php';
diff --git a/include/ajax/ajax_auto_anc_card.php 
b/include/ajax/ajax_auto_anc_card.php
index 917154d..a047326 100644
--- a/include/ajax/ajax_auto_anc_card.php
+++ b/include/ajax/ajax_auto_anc_card.php
@@ -6,7 +6,7 @@
    *@brief no used ?? 
    */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 $cn=Dossier::connect();
 
diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php
index d4a076b..1e7df81 100644
--- a/include/ajax/ajax_card.php
+++ b/include/ajax/ajax_card.php
@@ -56,7 +56,7 @@
  */
 if ( ! defined('ALLOWED')) die (_('Accès non autorisé'));
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/fiche.class.php';
 require_once NOALYSS_INCLUDE.'/lib/iradio.class.php';
 require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
diff --git a/include/ajax/ajax_get_receipt.php 
b/include/ajax/ajax_get_receipt.php
index 1e60193..00e5cf7 100644
--- a/include/ajax/ajax_get_receipt.php
+++ b/include/ajax/ajax_get_receipt.php
@@ -30,7 +30,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
diff --git a/include/ajax/ajax_history.php b/include/ajax/ajax_history.php
index 904b71f..b0eef4e 100644
--- a/include/ajax/ajax_history.php
+++ b/include/ajax/ajax_history.php
@@ -25,7 +25,7 @@
    */
 if ( ! defined('ALLOWED')) die (_('Accès interdit'));
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/class/periode.class.php';
diff --git a/include/ajax/ajax_ledger.php b/include/ajax/ajax_ledger.php
index 199e311..b475004 100644
--- a/include/ajax/ajax_ledger.php
+++ b/include/ajax/ajax_ledger.php
@@ -30,7 +30,7 @@
 */
 if ( ! defined('ALLOWED')) die(_('Non authorisé'));
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_operation.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
diff --git a/include/ajax/ajax_mod_document.php 
b/include/ajax/ajax_mod_document.php
index 88a48e9..384747b 100644
--- a/include/ajax/ajax_mod_document.php
+++ b/include/ajax/ajax_mod_document.php
@@ -23,7 +23,7 @@
  * \brief show the detail of a document and let you modify it
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/class/document_modele.class.php';
 
diff --git a/include/ajax/ajax_poste.php b/include/ajax/ajax_poste.php
index d7c96df..899dbad 100644
--- a/include/ajax/ajax_poste.php
+++ b/include/ajax/ajax_poste.php
@@ -36,7 +36,7 @@ if ( ! defined('ALLOWED')) die (_('Non authorisé'));
 
 require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
-require_once  NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once  NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
 require_once NOALYSS_INCLUDE.'/class/acc_account_ledger.class.php';
 mb_internal_encoding("UTF-8");
diff --git a/include/ajax/ajax_search_operation.php 
b/include/ajax/ajax_search_operation.php
index 446c9be..4b51987 100644
--- a/include/ajax/ajax_search_operation.php
+++ b/include/ajax/ajax_search_operation.php
@@ -30,7 +30,7 @@ require_once 
NOALYSS_INCLUDE.'/class/acc_ledger_search.class.php';
 global $http;
 $gDossier=dossier::id();
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 /* Admin. Dossier */
 
 $cn=Dossier::connect();
diff --git a/include/ajax/ajax_todo_list.php b/include/ajax/ajax_todo_list.php
index 430014b..95d9c25 100644
--- a/include/ajax/ajax_todo_list.php
+++ b/include/ajax/ajax_todo_list.php
@@ -36,7 +36,7 @@
 if ( ! defined ('ALLOWED') ) die (_('Aucun accès direct'));
 require_once  NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once  NOALYSS_INCLUDE.'/class/todo_list.class.php';
-require_once  NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once  NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/class/user.class.php';
 mb_internal_encoding("UTF-8");
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
diff --git a/include/ajax/ajax_update_predef.php 
b/include/ajax/ajax_update_predef.php
index 7979d60..335afb3 100644
--- a/include/ajax/ajax_update_predef.php
+++ b/include/ajax/ajax_update_predef.php
@@ -29,7 +29,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/class/pre_operation.class.php';
 
diff --git a/include/cfgfiche.inc.php b/include/cfgfiche.inc.php
index 1e87e9f..6955015 100644
--- a/include/cfgfiche.inc.php
+++ b/include/cfgfiche.inc.php
@@ -25,7 +25,7 @@ require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/lib/itext.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php';
 require_once NOALYSS_INCLUDE.'/class/fiche.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/user_menu.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/sort_table.class.php';
diff --git a/include/cfgledger.inc.php b/include/cfgledger.inc.php
index 1d4dbe5..9da41a3 100644
--- a/include/cfgledger.inc.php
+++ b/include/cfgledger.inc.php
@@ -29,7 +29,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/lib/user_menu.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
diff --git a/include/class/acc_account.class.php 
b/include/class/acc_account.class.php
index 4a41f69..8f41927 100644
--- a/include/class/acc_account.class.php
+++ b/include/class/acc_account.class.php
@@ -24,7 +24,7 @@
  * \brief Manage the account from the table tmp_pcmn
  */
 require_once NOALYSS_INCLUDE.'/lib/iselect.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/database/tmp_pcmn_sql.class.php';
 
diff --git a/include/class/acc_account_ledger.class.php 
b/include/class/acc_account_ledger.class.php
index 4d31139..a33d4d2 100644
--- a/include/class/acc_account_ledger.class.php
+++ b/include/class/acc_account_ledger.class.php
@@ -24,7 +24,7 @@
  * \brief Manage the account from the table jrn, jrnx or tmp_pcmn
  */
 require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 
 class Acc_Account_Ledger
diff --git a/include/class/acc_bilan.class.php 
b/include/class/acc_bilan.class.php
index 9585cfd..76ec7b8 100644
--- a/include/class/acc_bilan.class.php
+++ b/include/class/acc_bilan.class.php
@@ -24,7 +24,7 @@
  *
  */
 require_once NOALYSS_INCLUDE.'/lib/iselect.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/impress.class.php';
 require_once NOALYSS_INCLUDE.'/header_print.php';
diff --git a/include/class/acc_ledger_info.class.php 
b/include/class/acc_ledger_info.class.php
index 52cc71b..689879b 100644
--- a/include/class/acc_ledger_info.class.php
+++ b/include/class/acc_ledger_info.class.php
@@ -19,7 +19,7 @@
 
 // Copyright Author Dany De Bontridder address@hidden
 require_once  NOALYSS_INCLUDE.'/class/dossier.class.php';
-require_once  NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once  NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 
 /*!\file
diff --git a/include/class/acc_reconciliation.class.php 
b/include/class/acc_reconciliation.class.php
index e900f59..31dc07f 100644
--- a/include/class/acc_reconciliation.class.php
+++ b/include/class/acc_reconciliation.class.php
@@ -25,7 +25,7 @@
  *
  */
 require_once NOALYSS_INCLUDE.'/lib/iconcerned.class.php';
-require_once  NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once  NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/class/lettering.class.php';
 
diff --git a/include/class/acc_tva.class.php b/include/class/acc_tva.class.php
index ebbe095..27b4029 100644
--- a/include/class/acc_tva.class.php
+++ b/include/class/acc_tva.class.php
@@ -23,7 +23,7 @@
  * \brief this class is used for the table tva_rate
  */
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
 /*!\brief Acc_Tva is used for to map the table tva_rate
  * parameter are
diff --git a/include/class/admin.class.php b/include/class/admin.class.php
index f8fc8e2..7721669 100644
--- a/include/class/admin.class.php
+++ b/include/class/admin.class.php
@@ -18,7 +18,7 @@
 */
 // Copyright Author Dany De Bontridder address@hidden
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_parm_code.class.php';
 
 require_once NOALYSS_INCLUDE.'/class/fiche.class.php';
diff --git a/include/class/anc_group.class.php 
b/include/class/anc_group.class.php
index fd4a1dd..34f5cfb 100644
--- a/include/class/anc_group.class.php
+++ b/include/class/anc_group.class.php
@@ -23,7 +23,7 @@
  * \brief class for the group of the analytic account
  *
  */
-require_once  NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once  NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/constant.php';
 require_once  NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/class/anc_print.class.php';
diff --git a/include/class/anc_group_operation.class.php 
b/include/class/anc_group_operation.class.php
index 8c7e22d..05f5199 100644
--- a/include/class/anc_group_operation.class.php
+++ b/include/class/anc_group_operation.class.php
@@ -31,7 +31,7 @@ require_once NOALYSS_INCLUDE.'/lib/itext.class.php';
 require_once NOALYSS_INCLUDE.'/lib/iselect.class.php';
 require_once NOALYSS_INCLUDE.'/lib/icheckbox.class.php';
 require_once  NOALYSS_INCLUDE.'/class/anc_operation.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/class/anc_plan.class.php';
 require_once  NOALYSS_INCLUDE.'/class/dossier.class.php';
 
diff --git a/include/class/anc_plan.class.php b/include/class/anc_plan.class.php
index b55e8a9..93bb906 100644
--- a/include/class/anc_plan.class.php
+++ b/include/class/anc_plan.class.php
@@ -29,7 +29,7 @@
 require_once NOALYSS_INCLUDE.'/lib/itext.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php';
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/database/poste_analytique_sql.class.php';
 require_once  NOALYSS_INCLUDE.'/class/dossier.class.php';
 
diff --git a/include/class/anc_print.class.php 
b/include/class/anc_print.class.php
index 174fb1a..dedefcb 100644
--- a/include/class/anc_print.class.php
+++ b/include/class/anc_print.class.php
@@ -32,7 +32,7 @@ require_once NOALYSS_INCLUDE.'/lib/itext.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php';
 require_once NOALYSS_INCLUDE.'/lib/iselect.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ibutton.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/constant.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once  NOALYSS_INCLUDE.'/class/anc_plan.class.php';
diff --git a/include/class/bank.class.php b/include/class/bank.class.php
index 731b404..1429f87 100644
--- a/include/class/bank.class.php
+++ b/include/class/bank.class.php
@@ -18,7 +18,7 @@
 */
 // Copyright Author Dany De Bontridder address@hidden
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_parm_code.class.php';
 
 require_once NOALYSS_INCLUDE.'/class/fiche.class.php';
diff --git a/include/class/customer.class.php b/include/class/customer.class.php
index 4a7d10f..b6e8efc 100644
--- a/include/class/customer.class.php
+++ b/include/class/customer.class.php
@@ -18,7 +18,7 @@
 */
 // Copyright Author Dany De Bontridder address@hidden
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_parm_code.class.php';
 require_once NOALYSS_INCLUDE.'/class/periode.class.php';
 require_once NOALYSS_INCLUDE.'/class/fiche.class.php';
diff --git a/include/class/database.class.php b/include/class/database.class.php
new file mode 100644
index 0000000..23f67da
--- /dev/null
+++ b/include/class/database.class.php
@@ -0,0 +1,116 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS 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.
+ *
+ *   NOALYSS 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 NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * \file
+ * \brief contains the class for connecting to Noalyss
+ */
+
+require_once NOALYSS_INCLUDE . '/lib/database_core.class.php';
+
+class Database extends DatabaseCore
+{
+    /**\brief constructor
+     * \param $p_database_id is the id of the dossier, or the modele following 
the
+     * p_type if = 0 then connect to the repository
+     * \param $p_type is 'DOS' (defaut) for dossier or 'MOD'
+     */
+
+    function __construct($p_database_id = 0, $p_type = 'dos')
+    {
+        if (IsNumber($p_database_id) == false || strlen($p_database_id) > 10)
+            die("-->Dossier invalide [$p_database_id]");
+        $noalyss_user = (defined("noalyss_user")) ? noalyss_user : 
phpcompta_user;
+        $password = (defined("noalyss_password")) ? noalyss_password : 
phpcompta_password;
+        $port = (defined("noalyss_psql_port")) ? noalyss_psql_port : 
phpcompta_psql_port;
+        $host = (!defined("noalyss_psql_host")) ? '127.0.0.1' : 
noalyss_psql_host;
+        if (defined("MULTI") && MULTI == "0") {
+            $l_dossier = dbname;
+        } else {
+
+            if ($p_database_id == 0) { /* connect to the repository */
+                $l_dossier = sprintf("%saccount_repository", 
strtolower(domaine));
+            } else if ($p_type == 'dos') { /* connect to a folder (dossier) */
+                $l_dossier = sprintf("%sdossier%d", strtolower(domaine), 
$p_database_id);
+            } else if ($p_type == 'mod') { /* connect to a template (modele) */
+                $l_dossier = sprintf("%smod%d", strtolower(domaine), 
$p_database_id);
+            } else if ($p_type == 'template') {
+                $l_dossier = 'template1';
+            } else {
+                throw new Exception('Connection invalide');
+            }
+        }
+
+        parent::__construct($noalyss_user, $password, $l_dossier, $host, 
$port);
+
+        if ($this->exist_schema('comptaproc')) {
+            $this->exec_sql('set search_path to 
public,comptaproc,pg_catalog;');
+        }
+        $this->exec_sql('set DateStyle to ISO, MDY;');
+
+    }
+
+    /***
+     * \brief Save a "piece justificative" , the name must be pj
+     *
+     * \param $seq jr_grpt_id
+     * \return $oid of the lob file if success
+     *         null if a error occurs
+     *
+     */
+    function save_receipt($seq)
+    {
+        $oid = $this->upload('pj');
+        if ($oid == false) {
+            return false;
+        }
+        // Remove old document
+        $ret = $this->exec_sql("select jr_pj from jrn where jr_grpt_id=$seq");
+        if (pg_num_rows($ret) != 0) {
+            $r = pg_fetch_array($ret, 0);
+            $old_oid = $r['jr_pj'];
+            if (strlen($old_oid) != 0)
+                pg_lo_unlink($cn, $old_oid);
+        }
+        // Load new document
+        $this->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2,
+                                jr_pj_type=$3  where jr_grpt_id=$4",
+            array($oid, $_FILES['pj']['name'], $_FILES['pj']['type'], $seq));
+        return $oid;
+    }
+
+    /**
+     * \brief Get version of a database, the content of the
+     *        table version
+     *
+     * \return version number
+     *
+     */
+
+    function get_version()
+    {
+        $Res = $this->get_value("select max(val) from version");
+        return $Res;
+    }
+
+
+}
\ No newline at end of file
diff --git a/include/class/dossier.class.php b/include/class/dossier.class.php
index 5eea06b..d1eadd3 100644
--- a/include/class/dossier.class.php
+++ b/include/class/dossier.class.php
@@ -34,7 +34,7 @@
   "desc"=>"dos_description");
  *
  */
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 
diff --git a/include/class/exercice.class.php b/include/class/exercice.class.php
index 5048766..296d5d8 100644
--- a/include/class/exercice.class.php
+++ b/include/class/exercice.class.php
@@ -22,7 +22,7 @@
 /*!\file
  * \brief about the accountant exercice
  */
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/iselect.class.php';
 class Exercice
 {
diff --git a/include/class/fiche_attr.class.php 
b/include/class/fiche_attr.class.php
index eea1ed8..98cea2e 100644
--- a/include/class/fiche_attr.class.php
+++ b/include/class/fiche_attr.class.php
@@ -6,7 +6,7 @@
  *
  *
  */
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 
 class Fiche_Attr
diff --git a/include/class/manager.class.php b/include/class/manager.class.php
index a770dfe..03719b4 100644
--- a/include/class/manager.class.php
+++ b/include/class/manager.class.php
@@ -19,7 +19,7 @@
 
 // Copyright Author Dany De Bontridder address@hidden
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_parm_code.class.php';
 require_once NOALYSS_INCLUDE.'/class/periode.class.php';
 require_once NOALYSS_INCLUDE.'/class/fiche.class.php';
diff --git a/include/class/periode.class.php b/include/class/periode.class.php
index c4efd0c..dd63445 100644
--- a/include/class/periode.class.php
+++ b/include/class/periode.class.php
@@ -27,7 +27,7 @@
  * \brief For the periode tables parm_periode and jrn_periode
  */
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE."/database/parm_periode_sql.class.php";
 
 class Periode
diff --git a/include/class/print_ledger.class.php 
b/include/class/print_ledger.class.php
index ef43f9e..572a04d 100644
--- a/include/class/print_ledger.class.php
+++ b/include/class/print_ledger.class.php
@@ -23,7 +23,7 @@
  *
  * @author danydb
  */
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/print_ledger_detail.class.php';
 require_once NOALYSS_INCLUDE.'/class/print_ledger_simple.class.php';
 require_once 
NOALYSS_INCLUDE.'/class/print_ledger_simple_without_vat.class.php';
diff --git a/include/class/supplier.class.php b/include/class/supplier.class.php
index 51fc471..0400fa3 100644
--- a/include/class/supplier.class.php
+++ b/include/class/supplier.class.php
@@ -18,7 +18,7 @@
 */
 // Copyright Author Dany De Bontridder address@hidden
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_parm_code.class.php';
 require_once NOALYSS_INCLUDE.'/class/periode.class.php';
 require_once NOALYSS_INCLUDE.'/class/fiche.class.php';
diff --git a/include/class/user.class.php b/include/class/user.class.php
index 5b06677..ed0f716 100644
--- a/include/class/user.class.php
+++ b/include/class/user.class.php
@@ -1065,7 +1065,7 @@ class User
                        $Res = $cn->exec_sql("select distinct 
dos_id,dos_name,dos_description from ac_dossier
              where   dos_name ~* $1 or dos_description ~* $1 order by 
dos_name", array($p_filter));
                }
-               require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+               require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
                $max = Database::num_row($Res);
                if ($max == 0)
diff --git a/include/database/fiche_def_ref_sql.class.php 
b/include/database/fiche_def_ref_sql.class.php
index 5ad8b99..c952648 100644
--- a/include/database/fiche_def_ref_sql.class.php
+++ b/include/database/fiche_def_ref_sql.class.php
@@ -24,7 +24,7 @@
  * category of card
  */
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
 /**
  * @class
diff --git a/include/database/jrn_def_sql.class.php 
b/include/database/jrn_def_sql.class.php
index 4840fbc..4f7afc4 100644
--- a/include/database/jrn_def_sql.class.php
+++ b/include/database/jrn_def_sql.class.php
@@ -28,7 +28,7 @@
 
   @endcode
  */
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 
 /**
diff --git a/include/database/jrn_periode_sql.class.php 
b/include/database/jrn_periode_sql.class.php
index eb50639..9f44045 100644
--- a/include/database/jrn_periode_sql.class.php
+++ b/include/database/jrn_periode_sql.class.php
@@ -19,7 +19,7 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
 
 /**
diff --git a/include/database/menu_ref_sql.class.php 
b/include/database/menu_ref_sql.class.php
index f0eb8d6..5fa6982 100644
--- a/include/database/menu_ref_sql.class.php
+++ b/include/database/menu_ref_sql.class.php
@@ -25,7 +25,7 @@
  *
  *
  */
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
 
diff --git a/include/database/parm_periode_sql.class.php 
b/include/database/parm_periode_sql.class.php
index 2cbd080..18991e9 100644
--- a/include/database/parm_periode_sql.class.php
+++ b/include/database/parm_periode_sql.class.php
@@ -19,7 +19,7 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
 
 /**
diff --git a/include/database/poste_analytique_sql.class.php 
b/include/database/poste_analytique_sql.class.php
index af1184f..bbf11f8 100644
--- a/include/database/poste_analytique_sql.class.php
+++ b/include/database/poste_analytique_sql.class.php
@@ -28,7 +28,7 @@
  * 
  * @class
  * @brief abstract of the table public.poste_analytique */
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
 
diff --git a/include/database/profile_menu_sql.class.php 
b/include/database/profile_menu_sql.class.php
index a5979c8..6189fb9 100644
--- a/include/database/profile_menu_sql.class.php
+++ b/include/database/profile_menu_sql.class.php
@@ -28,7 +28,7 @@
 
   @endcode
  */
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
 
diff --git a/include/database/profile_sql.class.php 
b/include/database/profile_sql.class.php
index adbd7bf..33ecc49 100644
--- a/include/database/profile_sql.class.php
+++ b/include/database/profile_sql.class.php
@@ -28,7 +28,7 @@
 
   @endcode
  */
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
 
diff --git a/include/database/tag_sql.class.php 
b/include/database/tag_sql.class.php
index f66e9bc..13698f1 100644
--- a/include/database/tag_sql.class.php
+++ b/include/database/tag_sql.class.php
@@ -1,5 +1,5 @@
 <?php
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
 /*
diff --git a/include/database/tva_rate_sql.class.php 
b/include/database/tva_rate_sql.class.php
index 94e9b03..da6c95c 100644
--- a/include/database/tva_rate_sql.class.php
+++ b/include/database/tva_rate_sql.class.php
@@ -19,7 +19,7 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
 /**
  * class_tva_rate_sql.php
diff --git a/include/database/user_filter_sql.class.php 
b/include/database/user_filter_sql.class.php
index 084c632..4f5e569 100644
--- a/include/database/user_filter_sql.class.php
+++ b/include/database/user_filter_sql.class.php
@@ -20,7 +20,7 @@
  * author : Dec 2017 , Dany De Bontridder (address@hidden)
  */
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
 /**
  * class_user_filter_sql.php
diff --git a/include/database/v_tva_rate_sql.class.php 
b/include/database/v_tva_rate_sql.class.php
index 0bad221..701bdc3 100644
--- a/include/database/v_tva_rate_sql.class.php
+++ b/include/database/v_tva_rate_sql.class.php
@@ -19,7 +19,7 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
 /**
  * class_tva_rate_sql.php
diff --git a/include/export/export_balance_csv.php 
b/include/export/export_balance_csv.php
index 1948247..8ce8dd0 100644
--- a/include/export/export_balance_csv.php
+++ b/include/export/export_balance_csv.php
@@ -25,7 +25,7 @@ require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php';
 
 include_once ("lib/ac_common.php");
 include_once("class/acc_balance.class.php");
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 $gDossier=dossier::id();
 
diff --git a/include/export/export_balance_pdf.php 
b/include/export/export_balance_pdf.php
index e4d69df..f78fc39 100644
--- a/include/export/export_balance_pdf.php
+++ b/include/export/export_balance_pdf.php
@@ -31,7 +31,7 @@
 // Copyright Author Dany De Bontridder address@hidden
 if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
 include_once("lib/ac_common.php");
-require_once NOALYSS_INCLUDE . '/lib/database.class.php';
+require_once NOALYSS_INCLUDE . '/class/database.class.php';
 include_once("class/acc_balance.class.php");
 require_once NOALYSS_INCLUDE . '/header_print.php';
 require_once NOALYSS_INCLUDE . '/class/dossier.class.php';
diff --git a/include/export/export_bilan_oth.php 
b/include/export/export_bilan_oth.php
index acda328..720229f 100644
--- a/include/export/export_bilan_oth.php
+++ b/include/export/export_bilan_oth.php
@@ -23,7 +23,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 include_once("lib/ac_common.php");
 include_once("lib/impress.class.php");
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/header_print.php';
 require_once  NOALYSS_INCLUDE.'/class/acc_bilan.class.php';
 
diff --git a/include/export/export_document_template.php 
b/include/export/export_document_template.php
index 5f7163a..e8d1d52 100644
--- a/include/export/export_document_template.php
+++ b/include/export/export_document_template.php
@@ -21,7 +21,7 @@
 /*! \file
  * \brief send the document template
  */
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 
diff --git a/include/export/export_fiche_balance_csv.php 
b/include/export/export_fiche_balance_csv.php
index 535c592..6142ea7 100644
--- a/include/export/export_fiche_balance_csv.php
+++ b/include/export/export_fiche_balance_csv.php
@@ -28,7 +28,7 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas 
permis');
 
 // Security we check if user does exist and his privilege
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php';
diff --git a/include/export/export_fiche_balance_pdf.php 
b/include/export/export_fiche_balance_pdf.php
index d29ebf6..e25d87a 100644
--- a/include/export/export_fiche_balance_pdf.php
+++ b/include/export/export_fiche_balance_pdf.php
@@ -26,7 +26,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 // Security we check if user does exist and his privilege
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/pdf.class.php';
 require_once NOALYSS_INCLUDE.'/class/lettering.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
diff --git a/include/export/export_fiche_csv.php 
b/include/export/export_fiche_csv.php
index ac69820..d178ab9 100644
--- a/include/export/export_fiche_csv.php
+++ b/include/export/export_fiche_csv.php
@@ -23,7 +23,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 include_once NOALYSS_INCLUDE."/lib/ac_common.php";
 include_once NOALYSS_INCLUDE.'/class/fiche.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php';
 
diff --git a/include/export/export_fiche_detail_csv.php 
b/include/export/export_fiche_detail_csv.php
index 30061ac..20e7c93 100644
--- a/include/export/export_fiche_detail_csv.php
+++ b/include/export/export_fiche_detail_csv.php
@@ -22,7 +22,7 @@
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 include_once("lib/ac_common.php");
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/fiche.class.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
diff --git a/include/export/export_fiche_detail_pdf.php 
b/include/export/export_fiche_detail_pdf.php
index ff30dca..187d7bf 100644
--- a/include/export/export_fiche_detail_pdf.php
+++ b/include/export/export_fiche_detail_pdf.php
@@ -25,7 +25,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 include_once("class/acc_account_ledger.class.php");
 include_once("lib/ac_common.php");
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 include_once("lib/impress.class.php");
 require_once NOALYSS_INCLUDE.'/class/fiche.class.php';
 require_once  NOALYSS_INCLUDE.'/header_print.php';
diff --git a/include/export/export_fiche_pdf.php 
b/include/export/export_fiche_pdf.php
index 4931512..04ceae7 100644
--- a/include/export/export_fiche_pdf.php
+++ b/include/export/export_fiche_pdf.php
@@ -27,7 +27,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 // Security we check if user does exist and his privilege
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/pdf.class.php';
 require_once NOALYSS_INCLUDE.'/class/lettering.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
diff --git a/include/export/export_form_csv.php 
b/include/export/export_form_csv.php
index b18bb53..cc6fa97 100644
--- a/include/export/export_form_csv.php
+++ b/include/export/export_form_csv.php
@@ -22,7 +22,7 @@
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_report.class.php';
 require_once NOALYSS_INCLUDE.'/lib/impress.class.php';
diff --git a/include/export/export_form_pdf.php 
b/include/export/export_form_pdf.php
index a4a80bf..a6d5682 100644
--- a/include/export/export_form_pdf.php
+++ b/include/export/export_form_pdf.php
@@ -25,7 +25,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 include_once("class/acc_report.class.php");
 include_once("lib/ac_common.php");
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 include_once("lib/impress.class.php");
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 require_once  NOALYSS_INCLUDE.'/header_print.php';
diff --git a/include/export/export_gl_csv.php b/include/export/export_gl_csv.php
index 6a10e1e..a908c9a 100644
--- a/include/export/export_gl_csv.php
+++ b/include/export/export_gl_csv.php
@@ -41,7 +41,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 include_once NOALYSS_INCLUDE.'/class/acc_account_ledger.class.php';
 include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 include_once NOALYSS_INCLUDE.'/lib/impress.class.php';
 require_once NOALYSS_INCLUDE.'/class/noalyss_parameter_folder.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
diff --git a/include/export/export_gl_pdf.php b/include/export/export_gl_pdf.php
index 72ae7b5..a335fcc 100644
--- a/include/export/export_gl_pdf.php
+++ b/include/export/export_gl_pdf.php
@@ -25,7 +25,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 include_once('class/acc_account_ledger.class.php');
 include_once('lib/ac_common.php');
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 include_once('lib/impress.class.php');
 require_once NOALYSS_INCLUDE.'/class/noalyss_parameter_folder.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
diff --git a/include/export/export_ledger_csv.php 
b/include/export/export_ledger_csv.php
index 7e43512..f5b9109 100644
--- a/include/export/export_ledger_csv.php
+++ b/include/export/export_ledger_csv.php
@@ -36,7 +36,7 @@ require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 $gDossier=dossier::id();
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php';
 
diff --git a/include/export/export_ledger_pdf.php 
b/include/export/export_ledger_pdf.php
index cab3413..eb224b0 100644
--- a/include/export/export_ledger_pdf.php
+++ b/include/export/export_ledger_pdf.php
@@ -31,7 +31,7 @@ $gDossier = dossier::id();
 require_once NOALYSS_INCLUDE.'/lib/pdf.class.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/impress.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
 require_once NOALYSS_INCLUDE.'/class/noalyss_parameter_folder.class.php';
diff --git a/include/export/export_poste_detail_csv.php 
b/include/export/export_poste_detail_csv.php
index a7d0198..055fc67 100644
--- a/include/export/export_poste_detail_csv.php
+++ b/include/export/export_poste_detail_csv.php
@@ -22,7 +22,7 @@
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_account_ledger.class.php';
 require_once  NOALYSS_INCLUDE.'/class/acc_operation.class.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php';
diff --git a/include/export/export_poste_detail_pdf.php 
b/include/export/export_poste_detail_pdf.php
index 31207b7..edb91ce 100644
--- a/include/export/export_poste_detail_pdf.php
+++ b/include/export/export_poste_detail_pdf.php
@@ -25,7 +25,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 require_once NOALYSS_INCLUDE.'/class/acc_account_ledger.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/impress.class.php';
 require_once NOALYSS_INCLUDE.'/header_print.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
diff --git a/include/export/export_rec_csv.php 
b/include/export/export_rec_csv.php
index da23ecb..f20c7c2 100644
--- a/include/export/export_rec_csv.php
+++ b/include/export/export_rec_csv.php
@@ -11,7 +11,7 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas 
permis');
 
 require_once NOALYSS_INCLUDE.'/class/acc_reconciliation.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
diff --git a/include/export/export_receipt.php 
b/include/export/export_receipt.php
index 7388cdf..48e0b4a 100644
--- a/include/export/export_receipt.php
+++ b/include/export/export_receipt.php
@@ -25,7 +25,7 @@ if ( ! defined ('ALLOWED')) die (_('Non autorisé'));
 
 include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once  NOALYSS_INCLUDE.'/class/dossier.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
 $http=new HttpInput();
 
diff --git a/include/export/export_reportinit_csv.php 
b/include/export/export_reportinit_csv.php
index 378cabe..8ec7951 100644
--- a/include/export/export_reportinit_csv.php
+++ b/include/export/export_reportinit_csv.php
@@ -25,7 +25,7 @@
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 require_once   NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/lib/user_common.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_report.class.php';
diff --git a/include/export/export_security_pdf.php 
b/include/export/export_security_pdf.php
index ef05943..47ef7df 100755
--- a/include/export/export_security_pdf.php
+++ b/include/export/export_security_pdf.php
@@ -25,7 +25,7 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas 
permis');
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 $gDossier=dossier::id();
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/pdf.class.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
 $http=new HttpInput();
diff --git a/include/ext/dummy/dummy.php b/include/ext/dummy/dummy.php
index fc24258..5491313 100755
--- a/include/ext/dummy/dummy.php
+++ b/include/ext/dummy/dummy.php
@@ -1,7 +1,7 @@
 <?php
 require_once ('lib/icard.class.php');
 require_once('lib/ifile.class.php');
-require_once('lib/database.class.php');
+require_once('class/database.class.php');
 require_once('lib/iselect.class.php');
 require_once('class/dossier.class.php');
 require_once('class/fiche.class.php');
diff --git a/include/extension_choice.inc.php b/include/extension_choice.inc.php
index ca5eb97..afca411 100644
--- a/include/extension_choice.inc.php
+++ b/include/extension_choice.inc.php
@@ -3,7 +3,7 @@
 //see licence.txt
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/constant.php';
diff --git a/include/extension_get.inc.php b/include/extension_get.inc.php
index 86f1961..55525fd 100644
--- a/include/extension_get.inc.php
+++ b/include/extension_get.inc.php
@@ -3,7 +3,7 @@
 //see licence.txt
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/constant.php';
diff --git a/include/fiche.inc.php b/include/fiche.inc.php
index fcd2705..ecbae06 100644
--- a/include/fiche.inc.php
+++ b/include/fiche.inc.php
@@ -22,7 +22,7 @@
  * \brief printing of category of card  : balance, historic
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/fiche.class.php';
 require_once NOALYSS_INCLUDE.'/class/lettering.class.php';
 
diff --git a/include/header_print.php b/include/header_print.php
index d0e6eb9..de54db1 100644
--- a/include/header_print.php
+++ b/include/header_print.php
@@ -24,7 +24,7 @@
  *
  */
 
-require_once  NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once  NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/class/noalyss_parameter_folder.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 
diff --git a/include/impress_bilan.inc.php b/include/impress_bilan.inc.php
index 59e4b53..bde62b6 100644
--- a/include/impress_bilan.inc.php
+++ b/include/impress_bilan.inc.php
@@ -31,7 +31,7 @@ require_once NOALYSS_INCLUDE.'/class/exercice.class.php';
 //-----------------------------------------------------
 // Show the jrn and date
 //-----------------------------------------------------
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 global $g_user;
 //-----------------------------------------------------
 // Form
diff --git a/include/impress_gl_comptes.inc.php 
b/include/impress_gl_comptes.inc.php
index 52c2a9e..6a5bdfa 100644
--- a/include/impress_gl_comptes.inc.php
+++ b/include/impress_gl_comptes.inc.php
@@ -33,7 +33,7 @@ require_once NOALYSS_INCLUDE.'/class/acc_operation.class.php';
 //-----------------------------------------------------
 // Show the jrn and date
 //-----------------------------------------------------
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 global $g_user,$http;
 //-----------------------------------------------------
 // Form
diff --git a/include/impress_jrn.inc.php b/include/impress_jrn.inc.php
index 587a590..5fb703b 100644
--- a/include/impress_jrn.inc.php
+++ b/include/impress_jrn.inc.php
@@ -28,7 +28,7 @@ require_once NOALYSS_INCLUDE.'/lib/icheckbox.class.php';
 require_once NOALYSS_INCLUDE.'/class/exercice.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger_history.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 $gDossier = dossier::id();
 global $g_user,$http;
 
diff --git a/include/impress_poste.inc.php b/include/impress_poste.inc.php
index 5b5b6f4..45be822 100644
--- a/include/impress_poste.inc.php
+++ b/include/impress_poste.inc.php
@@ -33,7 +33,7 @@ require_once NOALYSS_INCLUDE.'/class/acc_operation.class.php';
 //-----------------------------------------------------
 // Show the jrn and date
 //-----------------------------------------------------
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ipopup.class.php';
 global $g_user;
 
diff --git a/include/impress_rapport.inc.php b/include/impress_rapport.inc.php
index f2ca279..a426db6 100644
--- a/include/impress_rapport.inc.php
+++ b/include/impress_rapport.inc.php
@@ -186,7 +186,7 @@ if ( isset( $_GET['bt_html'] ) )
 //-----------------------------------------------------
 // Show the jrn and date
 //-----------------------------------------------------
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 $ret=$cn->make_array("select fr_id,fr_label
                      from formdef
                      order by fr_label");
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index ca7d654..bf807cd 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -25,7 +25,7 @@
  * @brief common utilities for a lot of procedure, classe
  */
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/class/periode.class.php';
 require_once NOALYSS_INCLUDE.'/lib/html_input.class.php';
 require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
diff --git a/include/lib/database.class.php 
b/include/lib/database_core.class.php
similarity index 52%
rename from include/lib/database.class.php
rename to include/lib/database_core.class.php
index 993d7f8..a38725d 100644
--- a/include/lib/database.class.php
+++ b/include/lib/database_core.class.php
@@ -24,115 +24,61 @@
  * \file
  * \brief contains the class for connecting to a postgresql database
  */
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE . '/constant.php';
+require_once NOALYSS_INCLUDE . '/lib/ac_common.php';
 
 /**
  * \brief
  * This class allow you to connect to the postgresql database, execute sql, 
retrieve data
  *
  */
-
-class Database
+class DatabaseCore
 {
 
-    private $db;    /**< database connection */
-    private $ret;   /**< return value  */
+    private $db;
+    /**< database connection */
+    private $ret;
+    /**< return value  */
     private $is_open;                   /*!< true is connected */
-    /**\brief constructor
-     * \param $p_database_id is the id of the dossier, or the modele following 
the
-     * p_type if = 0 then connect to the repository
-     * \param $p_type is 'DOS' (defaut) for dossier or 'MOD'
+
+    /*** Connect to a database return an connx to db or false if it fails
+     *
+     * @param string $p_user Username
+     * @param type $p_password User's password
+     * @param $p_dbname name of the database to connect
+     * @param type $p_host Host of DB
+     * @param type $p_port Port of DB
      */
 
-    function __construct($p_database_id=0, $p_type='dos')
+    function __construct($p_user, $p_password, $p_dbname, $p_host, $p_port)
     {
-        if (IsNumber($p_database_id)==false||strlen($p_database_id)>10)
-            die("-->Dossier invalide [$p_database_id]");
-        $noalyss_user=(defined("noalyss_user"))?noalyss_user:phpcompta_user;
-        
$password=(defined("noalyss_password"))?noalyss_password:phpcompta_password;
-        
$port=(defined("noalyss_psql_port"))?noalyss_psql_port:phpcompta_psql_port;
-        $host=(!defined("noalyss_psql_host") )?'127.0.0.1':noalyss_psql_host;
-        if (defined("MULTI")&&MULTI=="0")
-        {
-            $l_dossier=dbname;
-        }
-        else
-        {
-
-            if ($p_database_id==0)
-            { /* connect to the repository */
-                $l_dossier=sprintf("%saccount_repository", 
strtolower(domaine));
-            }
-            else if ($p_type=='dos')
-            { /* connect to a folder (dossier) */
-                $l_dossier=sprintf("%sdossier%d", strtolower(domaine), 
$p_database_id);
-            }
-            else if ($p_type=='mod')
-            { /* connect to a template (modele) */
-                $l_dossier=sprintf("%smod%d", strtolower(domaine), 
$p_database_id);
-            }
-            else if ($p_type=='template')
-            {
-                $l_dossier='template1';
-            }
-            else
-            {
-                throw new Exception('Connection invalide');
-            }
-        }
-
-        ob_start();
-        $a=pg_connect("dbname=$l_dossier host='$host' user='$noalyss_user'
-                      password='$password' port=$port");
+        $this->db = pg_connect("dbname=$p_dbname host='$p_host' user='$p_user'
+                     password='$p_password' port=$p_port");
+        if ($this->db == false) {
+            if (DEBUG) {
 
-        if ($a==false)
-        {
-            if (DEBUG)
-            {
-                ob_end_clean();
                 echo '<h2 class="error">Impossible de se connecter &agrave; 
postgreSql !</h2>';
                 echo '<p>';
                 echo "Vos param&egrave;tres sont incorrectes : <br>";
                 echo "<br>";
-                echo "base de donn&eacute;e : $l_dossier<br>";
-                echo "Domaine : ".domaine."<br>";
-                echo "Port $port <br>";
-                echo "Utilisateur : $noalyss_user <br>";
+                echo "base de donn&eacute;e : $p_dbname<br>";
+                echo "Port $p_port <br>";
+                echo "Utilisateur : $p_user <br>";
                 echo '</p>';
 
                 die("Connection impossible : v&eacute;rifiez vos 
param&egrave;tres de base
                   de donn&eacute;es");
-            }
-            else
-            {
-                echo '<h2 class="error">Erreur de connexion !</h2>';
-                $this->is_open=false;
-                return;
+            } else {
+                echo '<h2 class="error">' . _('Erreur de connexion !') . 
'</h2>';
+                $this->is_open = false;
+                throw new Exception(_('Erreur Connexion'));
             }
         }
-        $this->db=$a;
-        $this->is_open=TRUE;
-        if ($this->exist_schema('comptaproc')){
-            pg_exec($this->db, 'set search_path to 
public,comptaproc,pg_catalog;');
-        }
-        pg_exec($this->db, 'set DateStyle to ISO, MDY;');
-        ob_end_clean();
-    }
-    /**
-     * Connect to a database return an connx to db or false if it fails
-     * 
-     * @param string $p_user Username 
-     * @param type $p_password User's password
-     * @param $p_dbname name of the database to connect
-     * @param type $p_host Host of DB
-     * @param type $p_port Port of DB
-     */
-    static function connect($p_user,$p_password,$p_dbname,$p_host,$p_port) {
-        $a=pg_connect("dbname=$p_dbname host='$p_host' user='$p_user'
-                      password='$p_password' port=$p_port");
-        return $a;
+
+        $this->is_open = TRUE;
+
     }
+
     public function verify()
     {
         // Verify that the elt we want to add is correct
@@ -142,6 +88,7 @@ class Database
     {
         pg_set_client_encoding($this->db, $p_charset);
     }
+
     function get_encoding()
     {
         return pg_client_encoding($this->db);
@@ -149,6 +96,54 @@ class Database
 
 
     /**
+     * @return mixed
+     */
+    public function get_db()
+    {
+        return $this->db;
+    }
+
+    /**
+     * @param mixed $db
+     */
+    public function set_db($db)
+    {
+        $this->db = $db;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function get_ret()
+    {
+        return $this->ret;
+    }
+
+    /**
+     * @param mixed $ret
+     */
+    public function set_ret($ret)
+    {
+        $this->ret = $ret;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function get_is_open()
+    {
+        return $this->is_open;
+    }
+
+    /**
+     * @param mixed $is_open
+     */
+    public function set_is_open($is_open)
+    {
+        $this->is_open = $is_open;
+    }
+
+    /**
      * \brief send a sql string to the database
      * \param $p_string     sql string
      * \param $p_array array for the SQL string (see pg_query_params)
@@ -156,43 +151,34 @@ class Database
      * error occured
      */
 
-    function exec_sql($p_string, $p_array=null)
+    function exec_sql($p_string, $p_array = null)
     {
-        try
-        {
-            if ( ! $this->is_open ) throw new Exception(' Database is closed');
-            $this->sql=$p_string;
-            $this->array=$p_array;
-
-            if ($p_array==null)
-            {
+        try {
+            if (!$this->is_open) throw new Exception(' Database is closed');
+            $this->sql = $p_string;
+            $this->array = $p_array;
+
+            if ($p_array == null) {
                 if (!DEBUG)
-                    $this->ret=pg_query($this->db, $p_string);
+                    $this->ret = pg_query($this->db, $p_string);
                 else
-                    $this->ret=@pg_query($this->db, $p_string);
-            }
-            else
-            {
-                $a=is_array($p_array);
-                if (!is_array($p_array))
-                {
+                    $this->ret = @pg_query($this->db, $p_string);
+            } else {
+                $a = is_array($p_array);
+                if (!is_array($p_array)) {
                     throw new Exception("Erreur : exec_sql attend un array");
                 }
-                if (!DEBUG) 
-                    $this->ret=pg_query_params($this->db, $p_string, $p_array);
+                if (!DEBUG)
+                    $this->ret = pg_query_params($this->db, $p_string, 
$p_array);
                 else
-                    $this->ret=@pg_query_params($this->db, $p_string, 
$p_array);
+                    $this->ret = @pg_query_params($this->db, $p_string, 
$p_array);
             }
-            if (!$this->ret)
-            {
-                
$str_error=pg_last_error($this->db).pg_result_error($this->ret);
-                throw new Exception("  SQL ERROR $p_string ".$str_error, 1);
+            if (!$this->ret) {
+                $str_error = pg_last_error($this->db) . 
pg_result_error($this->ret);
+                throw new Exception("  SQL ERROR $p_string " . $str_error, 1);
             }
-        }
-        catch (Exception $a)
-        {
-            if (DEBUG)
-            {
+        } catch (Exception $a) {
+            if (DEBUG) {
                 print_r($p_string);
                 print_r($p_array);
                 echo $a->getMessage();
@@ -201,23 +187,23 @@ class Database
             }
             record_log($a->getTraceAsString());
             $this->rollback();
-            
+
             throw ($a);
         }
 
         return $this->ret;
     }
 
-    /** 
+    /**
      * \brief Count the number of row returned by a sql statement
      *
      * \param $p_sql sql string
      * \param $p_array if not null we use the safer pg_query_params
      */
 
-    function count_sql($p_sql, $p_array=null)
+    function count_sql($p_sql, $p_array = null)
     {
-        $r_sql=$this->exec_sql($p_sql, $p_array);
+        $r_sql = $this->exec_sql($p_sql, $p_array);
         return pg_NumRows($r_sql);
     }
 
@@ -227,7 +213,7 @@ class Database
 
     function get_current_seq($p_seq)
     {
-        $Res=$this->get_value("select currval('$p_seq') as seq");
+        $Res = $this->get_value("select currval('$p_seq') as seq");
         return $Res;
     }
 
@@ -237,8 +223,8 @@ class Database
 
     function get_next_seq($p_seq)
     {
-        $Res=$this->exec_sql("select nextval('$p_seq') as seq");
-        $seq=pg_fetch_array($Res, 0);
+        $Res = $this->exec_sql("select nextval('$p_seq') as seq");
+        $seq = pg_fetch_array($Res, 0);
         return $seq['seq'];
     }
 
@@ -248,7 +234,7 @@ class Database
      */
     function start()
     {
-        $Res=$this->exec_sql("start transaction");
+        $Res = $this->exec_sql("start transaction");
     }
 
     /**
@@ -257,8 +243,8 @@ class Database
      */
     function commit()
     {
-        if ( ! $this->is_open) return;
-        $Res=$this->exec_sql("commit");
+        if (!$this->is_open) return;
+        $Res = $this->exec_sql("commit");
     }
 
     /**
@@ -266,8 +252,8 @@ class Database
      */
     function rollback()
     {
-        if ( ! $this->is_open) return;
-        $Res=$this->exec_sql("rollback");
+        if (!$this->is_open) return;
+        $Res = $this->exec_sql("rollback");
     }
 
     /**
@@ -277,9 +263,9 @@ class Database
      */
     function alter_seq($p_name, $min)
     {
-        if ($min<1)
-            $min=1;
-        $Res=$this->exec_sql("alter sequence $p_name restart $min");
+        if ($min < 1)
+            $min = 1;
+        $Res = $this->exec_sql("alter sequence $p_name restart $min");
     }
 
     /**
@@ -290,87 +276,74 @@ class Database
     function execute_script($script)
     {
 
-        if (!DEBUG)
-        {
+        if (!DEBUG) {
             ob_start();
         } else {
-            $debug=fopen("/tmp/debug.log","w+");
+            $debug = fopen("/tmp/debug.log", "w+");
         }
-        $hf=fopen($script, 'r');
-        if ($hf==false)
-        {
-            throw new Exception ( 'Ne peut ouvrir '.$script);
+        $hf = fopen($script, 'r');
+        if ($hf == false) {
+            throw new Exception ('Ne peut ouvrir ' . $script);
         }
-        $sql="";
-        $flag_function=false;
-        while (!feof($hf))
-        {
-            $buffer=fgets($hf);
-            $buffer=str_replace('$BODY$', '$_$', $buffer);
-            print $buffer."<br>";
+        $sql = "";
+        $flag_function = false;
+        while (!feof($hf)) {
+            $buffer = fgets($hf);
+            $buffer = str_replace('$BODY$', '$_$', $buffer);
+            print $buffer . "<br>";
             // comment are not execute
-            if (substr($buffer, 0, 2)=="--")
-            {
+            if (substr($buffer, 0, 2) == "--") {
                 //echo "comment $buffer";
                 continue;
             }
             // Blank Lines Are Skipped
-            If (Strlen($buffer)==0)
-            {
+            If (Strlen($buffer) == 0) {
                 //echo "Blank $buffer";
                 Continue;
             }
-            if (strpos(strtolower($buffer), "create function")===0)
-            {
+            if (strpos(strtolower($buffer), "create function") === 0) {
                 echo "found a function";
-                $flag_function=true;
-                $sql=$buffer;
+                $flag_function = true;
+                $sql = $buffer;
                 continue;
             }
-            if (strpos(strtolower($buffer), "create or replace function")===0)
-            {
+            if (strpos(strtolower($buffer), "create or replace function") === 
0) {
                 echo "found a function";
-                $flag_function=true;
-                $sql=$buffer;
+                $flag_function = true;
+                $sql = $buffer;
                 continue;
             }
             // No semi colon -> multiline command
-            if ($flag_function==false&&strpos($buffer, ';')==false)
-            {
-                $sql.=$buffer;
+            if ($flag_function == false && strpos($buffer, ';') == false) {
+                $sql .= $buffer;
                 continue;
             }
-            if ($flag_function)
-            {
-                if (    strpos(strtolower($buffer), "$$;")===false      &&
-                        strpos(strtolower($buffer), '$_$;')===false   &&
-                        strpos(strtolower($buffer), '$function$;')===false   &&
-                        strpos(strtolower($buffer), 'language 
plpgsql;')===false &&
-                        strpos(strtolower($buffer), 'language plpgsql 
;')===false 
-                    )
-                {
-                    $sql.=$buffer;
+            if ($flag_function) {
+                if (strpos(strtolower($buffer), "$$;") === false &&
+                    strpos(strtolower($buffer), '$_$;') === false &&
+                    strpos(strtolower($buffer), '$function$;') === false &&
+                    strpos(strtolower($buffer), 'language plpgsql;') === false 
&&
+                    strpos(strtolower($buffer), 'language plpgsql ;') === false
+                ) {
+                    $sql .= $buffer;
                     continue;
                 }
-            }
-            else
-            {
+            } else {
                 // cut the semi colon
-                $buffer=str_replace(';', '', $buffer);
+                $buffer = str_replace(';', '', $buffer);
             }
-            $sql.=$buffer;
-            if ( DEBUG ) fwrite($debug, $sql);
-            if ($this->exec_sql($sql)==false)
-            {
-                
+            $sql .= $buffer;
+            if (DEBUG) fwrite($debug, $sql);
+            if ($this->exec_sql($sql) == false) {
+
                 $this->rollback();
                 if (!DEBUG)
                     ob_end_clean();
                 print "ERROR : $sql";
                 throw new Exception("ERROR : $sql");
             }
-            $sql="";
-            $flag_function=false;
+            $sql = "";
+            $flag_function = false;
             print "<hr>";
         } // while (feof)
         fclose($hf);
@@ -378,19 +351,6 @@ class Database
             ob_end_clean();
     }
 
-    /**
-     * \brief Get version of a database, the content of the
-     *        table version
-     *
-     * \return version number
-     *
-     */
-
-    function get_version()
-    {
-        $Res=$this->get_value("select max(val) from version");
-        return $Res;
-    }
 
     /**
      * @brief fetch the $p_indice array from the last query
@@ -399,13 +359,13 @@ class Database
      */
     function fetch($p_indice)
     {
-        if ($this->ret==false)
+        if ($this->ret == false)
             throw new Exception('this->ret is empty');
         return pg_fetch_array($this->ret, $p_indice);
     }
 
     /**
-     * 
+     *
      * @brief return the number of rows found by the last query, or the number
      * of rows from $p_ret
      * @param $p_ret is the result of a query, the default value is null, in 
that case
@@ -413,19 +373,19 @@ class Database
      * @note synomym for count()
      */
 
-    function size($p_ret=null)
+    function size($p_ret = null)
     {
-        if ($p_ret==null)
+        if ($p_ret == null)
             return pg_NumRows($this->ret);
         else
             return pg_NumRows($p_ret);
     }
 
     /**
-     * @brief       synomym for size() 
+     * @brief       synomym for size()
      */
 
-    function count($p_ret=null)
+    function count($p_ret = null)
     {
         return $this->size($p_ret);
     }
@@ -439,113 +399,98 @@ class Database
 
     function apply_patch($p_name)
     {
-        if ( ! $this->exist_table('version')) {
+        if (!$this->exist_table('version')) {
             echo _('Base de donnée vide');
             return;
         }
-        $MaxVersion=DBVERSION-1;
-        $succeed="<span style=\"font-size:18px;color:green\">&#x2713;</span>";
+        $MaxVersion = DBVERSION - 1;
+        $succeed = "<span 
style=\"font-size:18px;color:green\">&#x2713;</span>";
         echo '<ul style="list-type-style:square">';
-        for ($i=4; $i<=$MaxVersion; $i++)
-        {
-            $to=$i+1;
-
-            if ($this->get_version()<=$i)
-            {
-                if ($this->get_version()==97)
-                {
-                    if ($this->exist_schema("amortissement"))
-                    {
+        for ($i = 4; $i <= $MaxVersion; $i++) {
+            $to = $i + 1;
+
+            if ($this->get_version() <= $i) {
+                if ($this->get_version() == 97) {
+                    if ($this->exist_schema("amortissement")) {
                         $this->exec_sql('ALTER TABLE 
amortissement.amortissement_histo
                                                        ADD CONSTRAINT 
internal_fk FOREIGN KEY (jr_internal) REFERENCES jrn (jr_internal)
                                                        ON UPDATE CASCADE ON 
DELETE SET NULL');
                     }
                 }
-                echo "<li>Patching ".$p_name.
-                " from the version ".$this->get_version()." to $to ";
+                echo "<li>Patching " . $p_name .
+                    " from the version " . $this->get_version() . " to $to ";
 
-                $this->execute_script 
(NOALYSS_INCLUDE.'/sql/patch/upgrade'.$i.'.sql');
+                $this->execute_script(NOALYSS_INCLUDE . '/sql/patch/upgrade' . 
$i . '.sql');
                 echo $succeed;
 
                 if (!DEBUG)
                     ob_start();
                 // specific for version 4
-                if ($i==4)
-                {
-                    $sql="select jrn_def_id from jrn_def ";
-                    $Res=$this->exec_sql($sql);
-                    $Max=$this->size();
-                    for ($seq=0; $seq<$Max; $seq++)
-                    {
-                        $row=pg_fetch_array($Res, $seq);
-                        $sql=sprintf("create sequence s_jrn_%d", 
$row['jrn_def_id']);
+                if ($i == 4) {
+                    $sql = "select jrn_def_id from jrn_def ";
+                    $Res = $this->exec_sql($sql);
+                    $Max = $this->size();
+                    for ($seq = 0; $seq < $Max; $seq++) {
+                        $row = pg_fetch_array($Res, $seq);
+                        $sql = sprintf("create sequence s_jrn_%d", 
$row['jrn_def_id']);
                         $this->exec_sql($sql);
                     }
                 }
                 // specific to version 7
-                if ($i==7)
-                {
+                if ($i == 7) {
                     // now we use sequence instead of computing a max
                     //
-                    $Res2=$this->exec_sql('select coalesce(max(jr_grpt_id),1) 
as l from jrn');
-                    $Max2=pg_NumRows($Res2);
-                    if ($Max2==1)
-                    {
-                        $Row=pg_fetch_array($Res2, 0);
+                    $Res2 = $this->exec_sql('select 
coalesce(max(jr_grpt_id),1) as l from jrn');
+                    $Max2 = pg_NumRows($Res2);
+                    if ($Max2 == 1) {
+                        $Row = pg_fetch_array($Res2, 0);
                         var_dump($Row);
-                        $M=$Row['l'];
+                        $M = $Row['l'];
                         $this->exec_sql("select setval('s_grpt',$M,true)");
                     }
                 }
                 // specific to version 17
-                if ($i==17)
-                {
-                    
$this->execute_script(NOALYSS_INCLUDE.'/sql/patch/upgrade17.sql');
-                    $max=$this->get_value('select last_value from 
s_jnt_fic_att_value');
-                    $this->alter_seq($p_cn, 's_jnt_fic_att_value', $max+1);
+                if ($i == 17) {
+                    $this->execute_script(NOALYSS_INCLUDE . 
'/sql/patch/upgrade17.sql');
+                    $max = $this->get_value('select last_value from 
s_jnt_fic_att_value');
+                    $this->alter_seq($p_cn, 's_jnt_fic_att_value', $max + 1);
                 } // version
                 // reset sequence in the modele
                 //--
-                if ($i==30&&$p_name=="mod")
-                {
-                    $a_seq=array('s_jrn', 's_jrn_op', 's_centralized',
+                if ($i == 30 && $p_name == "mod") {
+                    $a_seq = array('s_jrn', 's_jrn_op', 's_centralized',
                         's_stock_goods', 'c_order', 's_central');
-                    foreach ($a_seq as $seq)
-                    {
-                        $sql=sprintf("select setval('%s',1,false)", $seq);
-                        $Res=$this->exec_sql($sql);
+                    foreach ($a_seq as $seq) {
+                        $sql = sprintf("select setval('%s',1,false)", $seq);
+                        $Res = $this->exec_sql($sql);
                     }
-                    $sql="select jrn_def_id from jrn_def ";
-                    $Res=$this->exec_sql($sql);
-                    $Max=pg_NumRows($Res);
-                    for ($seq=0; $seq<$Max; $seq++)
-                    {
-                        $row=pg_fetch_array($Res, $seq);
-                        $sql=sprintf("select setval('s_jrn_%d',1,false)", 
$row['jrn_def_id']);
+                    $sql = "select jrn_def_id from jrn_def ";
+                    $Res = $this->exec_sql($sql);
+                    $Max = pg_NumRows($Res);
+                    for ($seq = 0; $seq < $Max; $seq++) {
+                        $row = pg_fetch_array($Res, $seq);
+                        $sql = sprintf("select setval('s_jrn_%d',1,false)", 
$row['jrn_def_id']);
                         $this->exec_sql($sql);
                     }
                 }
-                if ($i==36)
-                {
+                if ($i == 36) {
                     /* check the country and apply the path */
-                    $res=$this->exec_sql("select pr_value from parameter where 
pr_id='MY_COUNTRY'");
-                    $country=pg_fetch_result($res, 0, 0);
-                    
$this->execute_script(NOALYSS_INCLUDE."/sql/patch/upgrade36.".$country.".sql");
+                    $res = $this->exec_sql("select pr_value from parameter 
where pr_id='MY_COUNTRY'");
+                    $country = pg_fetch_result($res, 0, 0);
+                    $this->execute_script(NOALYSS_INCLUDE . 
"/sql/patch/upgrade36." . $country . ".sql");
                     $this->exec_sql('update tmp_pcmn set 
pcm_type=find_pcm_type(pcm_val)');
                 }
-                if ($i==59)
-                {
-                    $res=$this->exec_sql("select pr_value from parameter where 
pr_id='MY_COUNTRY'");
-                    $country=pg_fetch_result($res, 0, 0);
-                    if ($country=='BE')
+                if ($i == 59) {
+                    $res = $this->exec_sql("select pr_value from parameter 
where pr_id='MY_COUNTRY'");
+                    $country = pg_fetch_result($res, 0, 0);
+                    if ($country == 'BE')
                         $this->exec_sql("insert into parm_code values 
('SUPPLIER',440,'Poste par défaut pour les fournisseurs')");
-                    if ($country=='FR')
+                    if ($country == 'FR')
                         $this->exec_sql("insert into parm_code values 
('SUPPLIER',400,'Poste par défaut pour les fournisseurs')");
                 }
-                if ($i==61)
-                {
-                    $country=$this->get_value("select pr_value from parameter 
where pr_id='MY_COUNTRY'");
-                    
$this->execute_script(NOALYSS_INCLUDE."/sql/patch/upgrade61.".$country.".sql");
+                if ($i == 61) {
+                    $country = $this->get_value("select pr_value from 
parameter where pr_id='MY_COUNTRY'");
+                    $this->execute_script(NOALYSS_INCLUDE . 
"/sql/patch/upgrade61." . $country . ".sql");
                 }
 
                 if (!DEBUG)
@@ -556,11 +501,11 @@ class Database
     }
 
     /**
-     * 
+     *
      * \brief return the value of the sql, the sql will return only one value
      *        with the value
      * \param $p_sql the sql stmt example :select s_value from
-      document_state where s_id=2
+     * document_state where s_id=2
      * \param $p_array if array is not null we use the ExecSqlParm (safer)
      * \see exec_sql
      * \note print a warning if several value are found, if only the first 
value is needed
@@ -568,26 +513,26 @@ class Database
      * \return only the first value or an empty string if nothing is found
      */
 
-    function get_value($p_sql, $p_array=null)
+    function get_value($p_sql, $p_array = null)
     {
         try {
-            $this->ret=$this->exec_sql($p_sql, $p_array);
-            $r=pg_NumRows($this->ret);
-            if ($r==0)
+            $this->ret = $this->exec_sql($p_sql, $p_array);
+            $r = pg_NumRows($this->ret);
+            if ($r == 0)
                 return "";
-            if ($r>1)
-            {
-                $array=pg_fetch_all($this->ret);
-                throw new Exception("Attention $p_sql retourne 
".pg_NumRows($this->ret)."  valeurs ".
-                var_export($p_array, true)." values=".var_export($array, 
true));
+            if ($r > 1) {
+                $array = pg_fetch_all($this->ret);
+                throw new Exception("Attention $p_sql retourne " . 
pg_NumRows($this->ret) . "  valeurs " .
+                    var_export($p_array, true) . " values=" . 
var_export($array, true));
             }
-            $r=pg_fetch_row($this->ret, 0);
+            $r = pg_fetch_row($this->ret, 0);
             return $r[0];
-            
+
         } catch (Exception $ex) {
             throw($ex);
-         }
+        }
     }
+
     /**
      * @brief return the number of rows affected by the previous query
      */
@@ -604,15 +549,16 @@ class Database
      * \return false if nothing is found
      */
 
-    function get_array($p_sql, $p_array=null)
+    function get_array($p_sql, $p_array = null)
     {
-        $r=$this->exec_sql($p_sql, $p_array);
+        $r = $this->exec_sql($p_sql, $p_array);
 
-        if (pg_NumRows($r)==0)
+        if (pg_NumRows($r) == 0)
             return array();
-        $array=pg_fetch_all($r);
+        $array = pg_fetch_all($r);
         return $array;
     }
+
     /**
      * Returns only one row from a query
      * @param string $p_sql
@@ -620,22 +566,24 @@ class Database
      * @return array , idx = column of the table or null if nothing is found
      * @throws Exception if too many rows are found code 100
      */
-    function get_row($p_sql,$p_array=NULL) {
-        $array=$this->get_array($p_sql,$p_array);
-        if (empty($array) ) return null;
-        if (count($array)==1) return $array[0];
-        throw new Exception("Database:get_row retourne trop de lignes",100);
+    function get_row($p_sql, $p_array = NULL)
+    {
+        $array = $this->get_array($p_sql, $p_array);
+        if (empty($array)) return null;
+        if (count($array) == 1) return $array[0];
+        throw new Exception("Database:get_row retourne trop de lignes", 100);
     }
+
     /**
      * @brief Create a sequence
      * @param string $p_name Sequence Name
      * @param int $min starting value
      */
-    function create_sequence($p_name, $min=1)
+    function create_sequence($p_name, $min = 1)
     {
-        if ($min<1)
-            $min=1;
-        $sql="create sequence ".$p_name." minvalue $min";
+        if ($min < 1)
+            $min = 1;
+        $sql = "create sequence " . $p_name . " minvalue $min";
         $this->exec_sql($sql);
     }
 
@@ -646,8 +594,8 @@ class Database
 
     function exist_sequence($p_name)
     {
-        $r=$this->count_sql("select relname from pg_class where 
relname=lower($1)", array($p_name));
-        if ($r==0)
+        $r = $this->count_sql("select relname from pg_class where 
relname=lower($1)", array($p_name));
+        if ($r == 0)
             return false;
         return true;
     }
@@ -659,10 +607,10 @@ class Database
      * \return true if a table exist otherwise false
      */
 
-    function exist_table($p_name, $p_schema='public')
+    function exist_table($p_name, $p_schema = 'public')
     {
-        $r=$this->count_sql("select table_name from information_schema.tables 
where table_schema=$1 and table_name=lower($2)", array($p_schema, $p_name));
-        if ($r==0)
+        $r = $this->count_sql("select table_name from 
information_schema.tables where table_schema=$1 and table_name=lower($2)", 
array($p_schema, $p_name));
+        if ($r == 0)
             return false;
         return true;
     }
@@ -676,8 +624,8 @@ class Database
      */
     function exist_column($col, $table, $schema)
     {
-        $r=$this->get_value('select count(*) from information_schema.columns 
where table_name=lower($1) and column_name=lower($2) and 
table_schema=lower($3)', array($col, $table, $schema));
-        if ($r>0)
+        $r = $this->get_value('select count(*) from information_schema.columns 
where table_name=lower($1) and column_name=lower($2) and 
table_schema=lower($3)', array($col, $table, $schema));
+        if ($r > 0)
             return true;
         return false;
     }
@@ -690,17 +638,16 @@ class Database
      */
     function format_name($p_id, $p_type)
     {
-        switch ($p_type)
-        {
+        switch ($p_type) {
             case 'dos':
-                $sys_name=sprintf("%sdossier%d", strtolower(domaine), $p_id);
+                $sys_name = sprintf("%sdossier%d", strtolower(domaine), $p_id);
                 break;
             case 'mod':
-                $sys_name=sprintf("%smod%d", strtolower(domaine), $p_id);
+                $sys_name = sprintf("%smod%d", strtolower(domaine), $p_id);
                 break;
             default:
-                echo_error(__FILE__." format_name invalid type ".$p_type, 
__LINE__);
-                throw new Exception(__FILE__." format_name invalid type 
".$p_type. __LINE__);
+                echo_error(__FILE__ . " format_name invalid type " . $p_type, 
__LINE__);
+                throw new Exception(__FILE__ . " format_name invalid type " . 
$p_type . __LINE__);
         }
         return $sys_name;
     }
@@ -712,7 +659,7 @@ class Database
      */
     function exist_database($p_name)
     {
-        $database_exist=$this->get_value('select count(*)
+        $database_exist = $this->get_value('select count(*)
                 from pg_catalog.pg_database where datname = lower($1)', 
array($p_name));
         return $database_exist;
     }
@@ -724,9 +671,9 @@ class Database
      */
     function exist_blob($p_oid)
     {
-        $r=$this->get_value('select count(*) from pg_largeobject_metadata 
where oid=$1'
-                , array($p_oid));
-        if ($r>0)
+        $r = $this->get_value('select count(*) from pg_largeobject_metadata 
where oid=$1'
+            , array($p_oid));
+        if ($r > 0)
             return true;
         else
             return false;
@@ -739,8 +686,8 @@ class Database
 
     function exist_view($p_name)
     {
-        $r=$this->count_sql("select viewname from pg_views where 
viewname=lower($1)", array($p_name));
-        if ($r==0)
+        $r = $this->count_sql("select viewname from pg_views where 
viewname=lower($1)", array($p_name));
+        if ($r == 0)
             return false;
         return true;
     }
@@ -752,8 +699,8 @@ class Database
 
     function exist_schema($p_name)
     {
-        $r=$this->count_sql("select nspname from pg_namespace where 
nspname=lower($1)", array($p_name));
-        if ($r==0)
+        $r = $this->count_sql("select nspname from pg_namespace where 
nspname=lower($1)", array($p_name));
+        if ($r == 0)
             return false;
         return true;
     }
@@ -765,29 +712,25 @@ class Database
      * \see fid_card.php
      */
 
-    function make_list($sql, $p_array=null)
+    function make_list($sql, $p_array = null)
     {
-        if ($p_array==null)
-        {
-            $aArray=$this->get_array($sql);
-        }
-        else
-        {
-            $aArray=$this->get_array($sql, $p_array);
+        if ($p_array == null) {
+            $aArray = $this->get_array($sql);
+        } else {
+            $aArray = $this->get_array($sql, $p_array);
         }
         if (empty($aArray))
             return "";
-        $aIdx=array_keys($aArray[0]);
-        $idx=$aIdx[0];
-        $ret="";
-        $f="";
-        for ($i=0; $i<count($aArray); $i++)
-        {
-            $row=$aArray[$i];
-            $ret.=$f.$aArray[$i][$idx];
-            $f=',';
+        $aIdx = array_keys($aArray[0]);
+        $idx = $aIdx[0];
+        $ret = "";
+        $f = "";
+        for ($i = 0; $i < count($aArray); $i++) {
+            $row = $aArray[$i];
+            $ret .= $f . $aArray[$i][$idx];
+            $f = ',';
         }
-        $ret=trim($ret, ',');
+        $ret = trim($ret, ',');
         return $ret;
     }
 
@@ -801,87 +744,55 @@ class Database
      * \note this function is used with ISelect when it is needed to have a 
list of
      * options.
      * \return: a double array like
-      \verbatim
-      Array
-      (
-        [0] => Array
-                (
-                [value] => 1
-                [label] => Marchandise A
-               )
-
-      [1] => Array
-            (
-            [value] => 2
-            [label] => Marchandise B
-            )
-
-      [2] => Array
-            (
-            [value] => 3
-            [label] => Marchandise C
-            )
-      )
-      \endverbatim
+     * \verbatim
+     * Array
+     * (
+     * [0] => Array
+     * (
+     * [value] => 1
+     * [label] => Marchandise A
+     * )
+     *
+     * [1] => Array
+     * (
+     * [value] => 2
+     * [label] => Marchandise B
+     * )
+     *
+     * [2] => Array
+     * (
+     * [value] => 3
+     * [label] => Marchandise C
+     * )
+     * )
+     * \endverbatim
      * \see ISelect
      */
 
-    function make_array($p_sql, $p_null=0,$p_array=null)
+    function make_array($p_sql, $p_null = 0, $p_array = null)
     {
-        $a=$this->exec_sql($p_sql,$p_array);
-        $max=pg_NumRows($a);
-        if ($max==0&&$p_null==0)
+        $a = $this->exec_sql($p_sql, $p_array);
+        $max = pg_NumRows($a);
+        if ($max == 0 && $p_null == 0)
             return null;
-        for ($i=0; $i<$max; $i++)
-        {
-            $row=pg_fetch_row($a);
-            $r[$i]['value']=$row[0];
-            $r[$i]['label']=h($row[1]);
+        for ($i = 0; $i < $max; $i++) {
+            $row = pg_fetch_row($a);
+            $r[$i]['value'] = $row[0];
+            $r[$i]['label'] = h($row[1]);
         }
         // add a blank item ?
-        if ($p_null==1)
-        {
-            for ($i=$max; $i!=0; $i--)
-            {
-                $r[$i]['value']=$r[$i-1]['value'];
-                $r[$i]['label']=h($r[$i-1]['label']);
+        if ($p_null == 1) {
+            for ($i = $max; $i != 0; $i--) {
+                $r[$i]['value'] = $r[$i - 1]['value'];
+                $r[$i]['label'] = h($r[$i - 1]['label']);
             }
-            $r[0]['value']=-1;
-            $r[0]['label']=" ";
+            $r[0]['value'] = -1;
+            $r[0]['label'] = " ";
         } //   if ( $p_null == 1 )
 
         return $r;
     }
-    /***
-     * \brief Save a "piece justificative" , the name must be pj
-     *
-     * \param $seq jr_grpt_id
-     * \return $oid of the lob file if success
-     *         null if a error occurs
-     *
-     */
-    function save_receipt($seq)
-    {
-        $oid=$this->upload('pj');
-        if ($oid==false)
-        {
-                    return false;
-        }
-        // Remove old document
-        $ret=$this->exec_sql("select jr_pj from jrn where jr_grpt_id=$seq");
-        if (pg_num_rows($ret)!=0)
-        {
-            $r=pg_fetch_array($ret, 0);
-            $old_oid=$r['jr_pj'];
-            if (strlen($old_oid)!=0)
-                pg_lo_unlink($cn, $old_oid);
-        }
-        // Load new document
-       $this->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2,
-                                jr_pj_type=$3  where jr_grpt_id=$4",
-                                array($oid,$_FILES['pj']['name'] 
,$_FILES['pj']['type'],$seq));
-        return $oid;
-    }
+
     /***
      * \brief Save a document into the database , it just puts the file in the 
database
      * and returns the corresponding OID , the mimetype , size ... of the 
document
@@ -896,34 +807,27 @@ class Database
     function upload($p_name)
     {
         /* there is          no file to          upload */
-        if ($_FILES[$p_name]["error"]==UPLOAD_ERR_NO_FILE)
-        {
+        if ($_FILES[$p_name]["error"] == UPLOAD_ERR_NO_FILE) {
             return false;
         }
 
-        $new_name=tempnam($_ENV['TMP'], $p_name);
-        if ($_FILES[$p_name]["error"]>0)
-        {
+        $new_name = tempnam($_ENV['TMP'], $p_name);
+        if ($_FILES[$p_name]["error"] > 0) {
             print_r($_FILES);
-            echo_error(__FILE__.":".__LINE__."Error: 
".$_FILES[$p_name]["error"]);
+            echo_error(__FILE__ . ":" . __LINE__ . "Error: " . 
$_FILES[$p_name]["error"]);
             return false;
         }
-        if (strlen($_FILES[$p_name]['tmp_name'])!=0)
-        {
-            if (move_uploaded_file($_FILES[$p_name]['tmp_name'], $new_name))
-            {
+        if (strlen($_FILES[$p_name]['tmp_name']) != 0) {
+            if (move_uploaded_file($_FILES[$p_name]['tmp_name'], $new_name)) {
                 // echo "Image saved";
-                $oid=pg_lo_import($this->db, $new_name);
-                if ($oid==false)
-                {
+                $oid = pg_lo_import($this->db, $new_name);
+                if ($oid == false) {
                     echo_error(__FILE__, __LINE__, "cannot upload document");
                     $this->rollback();
                     return false;
                 }
                 return $oid;
-            }
-            else
-            {
+            } else {
                 echo "<H1>Error</H1>";
                 $this->rollback();
                 return false;
@@ -948,7 +852,7 @@ class Database
      * \return $array of column
      */
 
-    static function fetch_array($ret, $p_indice=0)
+    static function fetch_array($ret, $p_indice = 0)
     {
         return pg_fetch_array($ret, $p_indice);
     }
@@ -970,7 +874,7 @@ class Database
      * \return a string or an integer
      */
 
-    static function fetch_result($ret, $p_row=0, $p_col=0)
+    static function fetch_result($ret, $p_row = 0, $p_col = 0)
     {
         return pg_fetch_result($ret, $p_row, $p_col);
     }
@@ -993,7 +897,7 @@ class Database
 
     function lo_unlink($p_oid)
     {
-        if ( ! $this->exist_blob($p_oid)) return;
+        if (!$this->exist_blob($p_oid)) return;
         return pg_lo_unlink($this->db, $p_oid);
     }
 
@@ -1018,7 +922,7 @@ class Database
 
     function execute($p_string, $p_array)
     {
-        $this->ret=pg_execute($this->db, $p_string, $p_array);
+        $this->ret = pg_execute($this->db, $p_string, $p_array);
         return $this->ret;
     }
 
@@ -1060,8 +964,8 @@ class Database
 
     function close()
     {
-        if ( $this->is_open ) pg_close($this->db);
-        $this->is_open=FALSE;
+        if ($this->is_open) pg_close($this->db);
+        $this->is_open = FALSE;
     }
 
     /**\brief
@@ -1078,7 +982,7 @@ class Database
 
     static function test_me()
     {
-        
+
     }
 
     function status()
@@ -1086,86 +990,49 @@ class Database
         return pg_transaction_status($this->db);
     }
 
-    /**
-     * with the handle of a successull query, echo each row into CSV and
-     * send it directly
-     * @param type $ret handle to a query
-     * @param type $aheader  double array, each item of the array contains
-     * a key type (num) and a key title
-     */
-    function query_to_csv($ret, $aheader)
-    {
-        $csv=new Noalyss_Csv("db-query");
-        $a_header=[];
-        for ($i=0; $i<count($aheader); $i++)
-        {
-            $a_header[]=$aheader[$i]['title'];
-        }
-        $csv->write_header($a_header);
-        
-        // fetch all the rows
-        for ($i=0; $i<Database::num_row($ret); $i++)
-        {
-            $row=Database::fetch_array($ret, $i);
-            // for each rows, for each value
-            for ($e=0; $e<count($row)/2; $e++)
-            {
-                switch ($aheader[$e]['type'])
-                {
-                    case 'num':
-                        $csv->add($row[$e],"number");
-                        break;
-                    default:
-                        $csv->add($row[$e]);
-                }
-            }
-            $csv->write();
-        }
-    }
+
     /**
      * @brief Find all lob and remove those which are not used by any tables
-     * 
+     *
      */
     function clean_orphan_lob()
     {
         // find all columns of type lob
-        $sql =" 
+        $sql = " 
                 select table_schema,table_name,column_name 
                 from 
                     information_schema.columns 
                 where table_schema not in ('information_schema','pg_catalog') 
                 and data_type='oid'";
-        $all_lob= "
+        $all_lob = "
             select oid,'N' as used from pg_largeobject_metadata
             ";
-        $a_table=  $this->get_array($sql);
+        $a_table = $this->get_array($sql);
         $a_lob = $this->get_array($all_lob);
-        if ( $a_table == false || $a_lob == false ) return;
+        if ($a_table == false || $a_lob == false) return;
         // for each lob
-        $nb_lob=count($a_lob);
-        $nb_table=count($a_table);
-        for ($i=0;$i  < $nb_lob;$i++)
-        {
-            $lob=$a_lob[$i]['oid'];
-            if ( $a_lob[$i]['used']=='Y')                    continue;
-            for ($j=0;$j  < $nb_table;$j++)
-            {
-                if ( $a_lob[$i]['used']=='Y')                    continue;
-                $check = $this->get_value(" select count(*) from ".
-                        
$a_table[$j]['table_schema'].".".$a_table[$j]['table_name'].
-                        " where ".
-                        $a_table[$j]['column_name']."=$1",array($lob));
-                if ( $check != 0 ) 
-                    $a_lob[$i]['used']='Y';
-                     
+        $nb_lob = count($a_lob);
+        $nb_table = count($a_table);
+        for ($i = 0; $i < $nb_lob; $i++) {
+            $lob = $a_lob[$i]['oid'];
+            if ($a_lob[$i]['used'] == 'Y') continue;
+            for ($j = 0; $j < $nb_table; $j++) {
+                if ($a_lob[$i]['used'] == 'Y') continue;
+                $check = $this->get_value(" select count(*) from " .
+                    $a_table[$j]['table_schema'] . "." . 
$a_table[$j]['table_name'] .
+                    " where " .
+                    $a_table[$j]['column_name'] . "=$1", array($lob));
+                if ($check != 0)
+                    $a_lob[$i]['used'] = 'Y';
+
             }
         }
-        for ($i=0;$i  < $nb_lob;$i++)
-        {
-            if ( $a_lob[$i]['used']=='Y')                    continue;
-                $this->lo_unlink($a_lob[$i]['oid']);
+        for ($i = 0; $i < $nb_lob; $i++) {
+            if ($a_lob[$i]['used'] == 'Y') continue;
+            $this->lo_unlink($a_lob[$i]['oid']);
         }
     }
+
     /**
      * Check if a prepared statement already exists or not
      * @param string $query_name name of the prepared query
@@ -1173,11 +1040,43 @@ class Database
      */
     function is_prepare($query_name)
     {
-        $nb_prepared=$this->get_value("select count(*) from 
pg_prepared_statements where name=$1",[$query_name]);
-        if ( $nb_prepared==0)return FALSE;
+        $nb_prepared = $this->get_value("select count(*) from 
pg_prepared_statements where name=$1", [$query_name]);
+        if ($nb_prepared == 0) return FALSE;
         return TRUE;
     }
 
+    /**
+     * with the handle of a successull query, echo each row into CSV and
+     * send it directly
+     * @param type $ret handle to a query
+     * @param type $aheader double array, each item of the array contains
+     * a key type (num) and a key title
+     */
+    function query_to_csv($ret, $aheader)
+    {
+        $csv = new Noalyss_Csv("db-query");
+        $a_header = [];
+        for ($i = 0; $i < count($aheader); $i++) {
+            $a_header[] = $aheader[$i]['title'];
+        }
+        $csv->write_header($a_header);
+
+        // fetch all the rows
+        for ($i = 0; $i < Database::num_row($ret); $i++) {
+            $row = Database::fetch_array($ret, $i);
+            // for each rows, for each value
+            for ($e = 0; $e < count($row) / 2; $e++) {
+                switch ($aheader[$e]['type']) {
+                    case 'num':
+                        $csv->add($row[$e], "number");
+                        break;
+                    default:
+                        $csv->add($row[$e]);
+                }
+            }
+            $csv->write();
+        }
+    }
 }
 
 /* test::test_me(); */
diff --git a/include/lib/single_record.class.php 
b/include/lib/single_record.class.php
index 0405ed3..a807ba9 100644
--- a/include/lib/single_record.class.php
+++ b/include/lib/single_record.class.php
@@ -23,7 +23,7 @@
  */
 // Copyright Author Dany De Bontridder address@hidden
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 define ('CODE_EXCP_DUPLICATE',901);
 /**
  * @brief Objec to check a double insert into the database, this duplicate 
occurs after
diff --git a/include/lib/user_common.php b/include/lib/user_common.php
index c3166e7..5c77c61 100644
--- a/include/lib/user_common.php
+++ b/include/lib/user_common.php
@@ -23,7 +23,7 @@
 
 // Copyright Author Dany De Bontridder address@hidden
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/icheckbox.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php';
 require_once NOALYSS_INCLUDE.'/class/document.class.php';
diff --git a/include/param_pcmn.inc.php b/include/param_pcmn.inc.php
index 73b2a44..d9dc4e5 100644
--- a/include/param_pcmn.inc.php
+++ b/include/param_pcmn.inc.php
@@ -29,7 +29,7 @@ require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
 $http=new HttpInput();
 $gDossier=dossier::id();
 
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 
 /* Admin. Dossier */
 $cn=Dossier::connect();
diff --git a/include/param_sec.inc.php b/include/param_sec.inc.php
index 43d7af7..2447692 100644
--- a/include/param_sec.inc.php
+++ b/include/param_sec.inc.php
@@ -27,7 +27,7 @@ require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/lib/iselect.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once  NOALYSS_INCLUDE.'/class/user.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/sort_table.class.php';
 require_once NOALYSS_INCLUDE.'/lib/inplace_edit.class.php';
 require_once NOALYSS_INCLUDE.'/lib/inplace_switch.class.php';
diff --git a/include/preod.inc.php b/include/preod.inc.php
index 81a5a9c..f0bff97 100644
--- a/include/preod.inc.php
+++ b/include/preod.inc.php
@@ -26,7 +26,7 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas 
permis');
 require_once NOALYSS_INCLUDE.'/lib/iselect.class.php';
 require_once NOALYSS_INCLUDE.'/lib/icheckbox.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ihidden.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/class/pre_operation.class.php';
 global $http;
diff --git a/include/recover.php b/include/recover.php
index a1eaaa4..2d20a5f 100644
--- a/include/recover.php
+++ b/include/recover.php
@@ -64,7 +64,7 @@ if ($action=="") :
     <?php
 elseif ($action=="send_email") :
     require_once NOALYSS_INCLUDE.'/lib/sendmail.class.php';
-    require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+    require_once NOALYSS_INCLUDE.'/class/database.class.php';
     /*
      * Check if user exists, if yes save a recover request
      */
@@ -139,7 +139,7 @@ elseif ($action=="req") :
     $http=new HttpInput();
     $request_id=$http->request("req","string", "");
     if (strlen(trim($request_id))==SIZE_REQUEST) :
-        require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+        require_once NOALYSS_INCLUDE.'/class/database.class.php';
         $cn=new Database(0);
 
         $value=$cn->get_value("select password from recover_pass where 
request=$1 and created_on > now() - interval '12 hours' and recover_on is 
null", array($request_id));
diff --git a/include/report.inc.php b/include/report.inc.php
index 143444d..fc52126 100644
--- a/include/report.inc.php
+++ b/include/report.inc.php
@@ -29,7 +29,7 @@ require_once NOALYSS_INCLUDE.'/lib/ifile.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ibutton.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_report.class.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once  NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ipopup.class.php';
 global $http;
diff --git a/include/user_detail.inc.php b/include/user_detail.inc.php
index 8a37b1e..8740238 100644
--- a/include/user_detail.inc.php
+++ b/include/user_detail.inc.php
@@ -22,7 +22,7 @@
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/user_menu.php';
 require_once  NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';



reply via email to

[Prev in Thread] Current Thread [Next in Thread]