From 2e74ca5bdfdd9f3383e88a8611d8cae42d87433a Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Wed, 24 Jul 2019 22:47:32 +0200 Subject: [PATCH] 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 +- .../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 +- ...base.class.php => database_core.class.php} | 899 ++++++++---------- 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, 623 insertions(+), 608 deletions(-) create mode 100644 include/class/database.class.php rename include/lib/{database.class.php => database_core.class.php} (52%) diff --git a/dev/SQL/index.php b/dev/SQL/index.php index c6b1500f7..14a5a37cc 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 f162dd14c..f441edcc7 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 1a24adc7a..5bf62668d 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 39371f252..6cab5ad3b 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 01fd2b59e..feb8dd10f 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 cb114da51..b6114eb5a 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 ed079f898..d08d460f4 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 be778611a..532b9ca9c 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 0d8cf6dab..d32bc4975 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 2d1eb9355..728aafacc 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 124860ca7..005b11d30 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 57577bb18..0133dcafe 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 b9aa12bc5..75b2498bc 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 e6ae4ddaa..089040878 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 be049ff1f..19db731a2 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 f1a3c8a19..b985af528 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 03f35e294..b2ebdba50 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 bcb72c398..7fd947713 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 d1f037656..6121be652 100644 --- a/html/user_login.php +++ b/html/user_login.php @@ -23,7 +23,7 @@ // Copyright Author Dany De Bontridder danydb@aevalys.eu 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 821a81cce..a18e4ab0e 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 071ac43e1..5a4711ce1 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 917154d86..a04732662 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 d4a076b0f..1e7df81d4 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 1e6019324..00e5cf7a9 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 904b71fe9..b0eef4eb1 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 199e311c1..b475004be 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 88a48e931..384747bb2 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 d7c96dfd3..899dbadb8 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 446c9beb4..4b519878c 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 430014b9a..95d9c2597 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 7979d603a..335afb350 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 1e87e9f3b..6955015cc 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 1d4dbe57c..9da41a3a9 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 4a41f6915..8f4192712 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 4d31139d1..a33d4d20c 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 9585cfdee..76ec7b8bf 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 52cc71b1b..689879b06 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 danydb@aevalys.eu 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 e900f5963..31dc07f06 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 ebbe095ac..27b402990 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 f8fc8e20f..77216692b 100644 --- a/include/class/admin.class.php +++ b/include/class/admin.class.php @@ -18,7 +18,7 @@ */ // Copyright Author Dany De Bontridder danydb@aevalys.eu 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 fd4a1dda6..34f5cfba1 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 8c7e22dc1..05f519981 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 b55e8a951..93bb90608 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 174fb1a50..dedefcb2a 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 731b40466..1429f8778 100644 --- a/include/class/bank.class.php +++ b/include/class/bank.class.php @@ -18,7 +18,7 @@ */ // Copyright Author Dany De Bontridder danydb@aevalys.eu 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 4a7d10f15..b6e8efcd0 100644 --- a/include/class/customer.class.php +++ b/include/class/customer.class.php @@ -18,7 +18,7 @@ */ // Copyright Author Dany De Bontridder danydb@aevalys.eu 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 000000000..23f67dafa --- /dev/null +++ b/include/class/database.class.php @@ -0,0 +1,116 @@ + 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 5eea06b8b..d1eadd384 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 504876684..296d5d8d4 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 eea1ed8b3..98cea2e90 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 a770dfe88..03719b46d 100644 --- a/include/class/manager.class.php +++ b/include/class/manager.class.php @@ -19,7 +19,7 @@ // Copyright Author Dany De Bontridder danydb@aevalys.eu 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 c4efd0c2b..dd63445d7 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 ef43f9ea7..572a04d83 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 51fc47182..0400fa34f 100644 --- a/include/class/supplier.class.php +++ b/include/class/supplier.class.php @@ -18,7 +18,7 @@ */ // Copyright Author Dany De Bontridder danydb@aevalys.eu 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 5b066779a..ed0f7164a 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 5ad8b9939..c952648c4 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 4840fbc34..4f7afc406 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 eb50639fa..9f440455f 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 f0eb8d673..5fa6982f5 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 2cbd0806b..18991e97a 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 af1184f39..bbf11f865 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 a5979c8bb..6189fb91d 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 adbd7bf1d..33ecc49aa 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 f66e9bcec..13698f156 100644 --- a/include/database/tag_sql.class.php +++ b/include/database/tag_sql.class.php @@ -1,5 +1,5 @@ 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 ca7d65492..bf807cdb4 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 993d7f81f..a38725d29 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' - */ - 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'); - } - } - - ob_start(); - $a=pg_connect("dbname=$l_dossier host='$host' user='$noalyss_user' - password='$password' port=$port"); - - if ($a==false) - { - if (DEBUG) - { - ob_end_clean(); - echo '

Impossible de se connecter à postgreSql !

'; - echo '

'; - echo "Vos paramètres sont incorrectes :
"; - echo "
"; - echo "base de donnée : $l_dossier
"; - echo "Domaine : ".domaine."
"; - echo "Port $port
"; - echo "Utilisateur : $noalyss_user
"; - echo '

'; - - die("Connection impossible : vérifiez vos paramètres de base - de données"); - } - else - { - echo '

Erreur de connexion !

'; - $this->is_open=false; - return; - } - } - $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 + /*** 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; + + function __construct($p_user, $p_password, $p_dbname, $p_host, $p_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) { + + echo '

Impossible de se connecter à postgreSql !

'; + echo '

'; + echo "Vos paramètres sont incorrectes :
"; + echo "
"; + echo "base de donnée : $p_dbname
"; + echo "Port $p_port
"; + echo "Utilisateur : $p_user
"; + echo '

'; + + die("Connection impossible : vérifiez vos paramètres de base + de données"); + } else { + echo '

' . _('Erreur de connexion !') . '

'; + $this->is_open = false; + throw new Exception(_('Erreur Connexion')); + } + } + + $this->is_open = TRUE; + } + public function verify() { // Verify that the elt we want to add is correct @@ -142,12 +88,61 @@ class Database { pg_set_client_encoding($this->db, $p_charset); } + function get_encoding() { return pg_client_encoding($this->db); } + /** + * @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 @@ -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; + try { + if (!$this->is_open) throw new Exception(' Database is closed'); + $this->sql = $p_string; + $this->array = $p_array; - if ($p_array==null) - { + 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."
"; + $sql = ""; + $flag_function = false; + while (!feof($hf)) { + $buffer = fgets($hf); + $buffer = str_replace('$BODY$', '$_$', $buffer); + print $buffer . "
"; // 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 "
"; } // 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=""; + $MaxVersion = DBVERSION - 1; + $succeed = ""; echo '