From 1daa0d9019e45843739a74c2001deaa2950a55d1 Mon Sep 17 00:00:00 2001 From: Desal-Soul Date: Wed, 26 Mar 2025 10:22:20 +0100 Subject: [PATCH] module dolibarr Agefoddx version 1 --- ChangeLog.md | 17 + README_FR.md | 56 ++++ admin/.htaccess | 1 + admin/about.php | 112 +++++++ admin/setup.php | 133 ++++++++ classe/.htaccess | 1 + classe/Classe/GestionTexte.php | 15 + classe/Controleur/ControleurBd.php | 119 +++++++ classe/Controleur/ControleurGenerique.php | 24 ++ classe/Controleur/ControleurLigne.php | 208 ++++++++++++ classe/Controleur/ControleurTable.php | 183 ++++++++++ classe/GestionBD/bdExterneInteraction.php | 65 ++++ classe/GestionBD/bdExterneLigneGestion.php | 48 +++ classe/GestionBD/bdExterneTableGestion.php | 78 +++++ classe/GestionBD/bdGestion.php | 132 ++++++++ classe/GestionBD/ligneGestion.php | 255 ++++++++++++++ classe/GestionBD/tableGestion.php | 367 +++++++++++++++++++++ core/modules/modAgefoddx.class.php | 81 +++++ img/.htaccess | 1 + img/object_Agefoddx.png | Bin 0 -> 4187 bytes index.php | 1 + js/envoiePost.js | 33 ++ langs/en_EN/Agefoddx.lang | 145 ++++++++ langs/es_Es/Agefoddx.lang | 145 ++++++++ langs/fr_FR/Agefoddx.lang | 145 ++++++++ langs/oc_OC/Agefoddx.lang | 145 ++++++++ lib/.htaccess | 1 + lib/Agefoddx.lib.php | 75 +++++ lib/Psr4AutoloaderClass.php | 213 ++++++++++++ sql/.htaccess | 1 + sql/llx_desal_external_bd.sql | 7 + sql/llx_desal_external_row.key.sql | 2 + sql/llx_desal_external_row.sql | 9 + sql/llx_desal_external_table.key.sql | 1 + sql/llx_desal_external_table.sql | 6 + view/.htaccess | 1 + view/erreur.php | 9 + view/gestionBD/afficherListe.php | 62 ++++ view/gestionBD/ajouter.php | 88 +++++ view/gestionBD/modifier.php | 100 ++++++ view/gestionBD/supprimer.php | 63 ++++ view/gestionLigne/afficherListe.php | 65 ++++ view/gestionLigne/ajouter.php | 144 ++++++++ view/gestionLigne/supprimer.php | 71 ++++ view/gestionLigne/transition.php | 69 ++++ view/gestionTable/afficherListe.php | 70 ++++ view/gestionTable/ajouter.php | 80 +++++ view/gestionTable/importer.php | 96 ++++++ view/gestionTable/supprimer.php | 68 ++++ view/gestionTable/transition.php | 61 ++++ view/vueGenerale.php | 18 + 51 files changed, 3890 insertions(+) create mode 100644 ChangeLog.md create mode 100644 README_FR.md create mode 100644 admin/.htaccess create mode 100644 admin/about.php create mode 100644 admin/setup.php create mode 100644 classe/.htaccess create mode 100644 classe/Classe/GestionTexte.php create mode 100644 classe/Controleur/ControleurBd.php create mode 100644 classe/Controleur/ControleurGenerique.php create mode 100644 classe/Controleur/ControleurLigne.php create mode 100644 classe/Controleur/ControleurTable.php create mode 100644 classe/GestionBD/bdExterneInteraction.php create mode 100644 classe/GestionBD/bdExterneLigneGestion.php create mode 100644 classe/GestionBD/bdExterneTableGestion.php create mode 100644 classe/GestionBD/bdGestion.php create mode 100644 classe/GestionBD/ligneGestion.php create mode 100644 classe/GestionBD/tableGestion.php create mode 100644 core/modules/modAgefoddx.class.php create mode 100644 img/.htaccess create mode 100644 img/object_Agefoddx.png create mode 100644 index.php create mode 100644 js/envoiePost.js create mode 100644 langs/en_EN/Agefoddx.lang create mode 100644 langs/es_Es/Agefoddx.lang create mode 100644 langs/fr_FR/Agefoddx.lang create mode 100644 langs/oc_OC/Agefoddx.lang create mode 100644 lib/.htaccess create mode 100644 lib/Agefoddx.lib.php create mode 100644 lib/Psr4AutoloaderClass.php create mode 100644 sql/.htaccess create mode 100644 sql/llx_desal_external_bd.sql create mode 100644 sql/llx_desal_external_row.key.sql create mode 100644 sql/llx_desal_external_row.sql create mode 100644 sql/llx_desal_external_table.key.sql create mode 100644 sql/llx_desal_external_table.sql create mode 100644 view/.htaccess create mode 100644 view/erreur.php create mode 100644 view/gestionBD/afficherListe.php create mode 100644 view/gestionBD/ajouter.php create mode 100644 view/gestionBD/modifier.php create mode 100644 view/gestionBD/supprimer.php create mode 100644 view/gestionLigne/afficherListe.php create mode 100644 view/gestionLigne/ajouter.php create mode 100644 view/gestionLigne/supprimer.php create mode 100644 view/gestionLigne/transition.php create mode 100644 view/gestionTable/afficherListe.php create mode 100644 view/gestionTable/ajouter.php create mode 100644 view/gestionTable/importer.php create mode 100644 view/gestionTable/supprimer.php create mode 100644 view/gestionTable/transition.php create mode 100644 view/vueGenerale.php diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..88392ba --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,17 @@ +# CHANGELOG AGEFODDX + +## version 1 - 28 / 02 / 2025 +### Fonctionnalité +- Seconde version de l'application. +- Fonctionnalité d'importation et d'exportation de bases de données améliorée. +- Ajout de plus de commentaire pour détaillé le code +- Correction de bug mineur +- Modification du système d'import pour que celui-ci ne décale plus les id lors de la modification de valeurs + +## version 0.1 - 07 / 02 / 2025 +### Fonctionnalité +- Première version de l'application. +- Fonctionnalité d'importation et d'exportation de bases de données. +- Système de gestion des tables et des lignes avec compatibilité pour plusieurs bases externes. +- Interface de paramétrage pour les connexions aux bases de données. +- Gestion des clés étrangères et des conversions de données. diff --git a/README_FR.md b/README_FR.md new file mode 100644 index 0000000..d6cbf0e --- /dev/null +++ b/README_FR.md @@ -0,0 +1,56 @@ + + +
+

AGEFODDX

+
+
+

Table des Matières

+
    +
  1. A propos d'Agefoddx
  2. +
  3. Exigences du module
  4. +
  5. Installation
  6. +
  7. Comment l'utiliser
  8. +
+
+
+

A propos d'Agefoddx

+

Agefoddx est un module de dolibarr développer par Desal-Soul, pour CFPO.
+ Ce module a pour objectif la possiblité de permètre et facilité l'importation de donnée depuis
+ une base de donnée exterieurs à dolibarr vers celle d'agefodd

+
+
+

Exigences du module

+

Ce module necessite :

+ +
+
+

Installation

+ +
+
+

Comment l'utiliser

+

Avant de commencer pour utiliser Agefoddx, il faut être administrateur.

+
    +
  1. Pour commencer rendez-vous dans la section Configuration "Modules / Application"
  2. +
  3. Ensuite descender jusqu'à atteindre "Desal-Tools".
  4. +
  5. Une fois cela fait activer le module, puis appuyer sur l'engrenage
    + Vous êtes maintenant sur la page de configuration de Agefoddx,
    + toutes les actions possibles avec ce module sont uniquement accessibles + depuis cette page.
  6. +
  7. Maintenant sur cette page clicker sur le bouton plus.
  8. +
  9. Entrer les informations demandées
  10. +
  11. Vous avez réussi à lier votre première base de donnée, vous pouvez maitenant faire la même
    + chose pour les tables et les lignes. Et exporter toutes ces infos depuis l'interface des tables.
  12. +
+
+ + diff --git a/admin/.htaccess b/admin/.htaccess new file mode 100644 index 0000000..5d14b45 --- /dev/null +++ b/admin/.htaccess @@ -0,0 +1 @@ +Require all granted \ No newline at end of file diff --git a/admin/about.php b/admin/about.php new file mode 100644 index 0000000..870d75e --- /dev/null +++ b/admin/about.php @@ -0,0 +1,112 @@ + + * Copyright (C) ---Put here your own copyright and developer email--- + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ + +/** + * \file htdocs/modulebuilder/template/admin/about.php + * \ingroup Agefoddx + * \brief About page of module Agefoddx. + */ + +// Load Dolibarr environment +$res = 0; +// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) +if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { + $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; +} +// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { + $i--; + $j--; +} +if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { + $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; +} +if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { + $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; +} +// Try main.inc.php using relative path +if (!$res && file_exists("../../main.inc.php")) { + $res = @include "../../main.inc.php"; +} +if (!$res && file_exists("../../../main.inc.php")) { + $res = @include "../../../main.inc.php"; +} +if (!$res) { + die("Include of main fails"); +} + +// Libraries +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once '../lib/Agefoddx.lib.php'; + +// Translations +$langs->loadLangs(array("errors", "admin", "Agefoddx@Agefoddx")); + +// Access control +if (!$user->admin) { + accessforbidden(); +} + +// Parameters +$action = GETPOST('action', 'aZ09'); +$backtopage = GETPOST('backtopage', 'alpha'); + + +/* + * Actions + */ + +// None + + +/* + * View + */ + +$form = new Form($db); + +$help_url = ''; +$page_name = "AgefoddxAbout"; + +llxHeader('', $langs->trans($page_name), $help_url, '', 0, 0, '', '', '', 'mod-Agefoddx page-admin_about'); + +// Subheader +$linkback = ''.$langs->trans("BackToModuleList").''; + +print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup'); + +// Configuration header +$head = AgefoddxAdminPrepareHead(); +print dol_get_fiche_head($head, 'about', $langs->trans($page_name), 0, 'Agefoddx@Agefoddx'); + +dol_include_once('/Agefoddx/core/modules/modagefoddLink.classe.php'); +print " +
+

Agefoddx

+

".$langs->trans("AgefoddxAboutIntro")."

+

".$langs->trans("AgefoddxAboutP1")."

+

".$langs->trans("AgefoddxAboutP2")."

+

".$langs->trans("AgefoddxLogoSource")." : ".$langs->trans("AgefoddxSmashicons")."

+
+"; +// Page end +print dol_get_fiche_end(); +llxFooter(); +$db->close(); diff --git a/admin/setup.php b/admin/setup.php new file mode 100644 index 0000000..c4ce015 --- /dev/null +++ b/admin/setup.php @@ -0,0 +1,133 @@ + + * Copyright (C) ---Put here your own copyright and developer email--- + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see . + */ +use Module\Agefoddx\Classe\Controleur\ControleurGenerique; +use Module\Agefoddx\Classe\Controleur\ControleurBd; +use Module\Agefoddx\Classe\Controleur\ControleurTable; +use Module\Agefoddx\Classe\Controleur\ControleurLigne; +use Module\Agefoddx\Lib\Psr4AutoloaderClass; +require_once __DIR__ . '/../lib/Psr4AutoloaderClass.php'; +/** + * \file htdocs/modulebuilder/template/admin/setup.php + * \ingroup Agefoddx + * \brief Agefoddx setup page. + */ + +// Load Dolibarr environment +$res = 0; +global $db, $hookmanager, $conf; +// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) +if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";} +// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {$i--;$j--;} +if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";} +if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {$res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";} +// Try main.inc.php using relative path +if (!$res && file_exists("../../main.inc.php")) {$res = @include "../../main.inc.php";} +if (!$res && file_exists("../../../main.inc.php")) {$res = @include "../../../main.inc.php";} +if (!$res) {die("Include of main fails");} + +global $langs, $user; + +// Libraries +require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; +require_once '../lib/Agefoddx.lib.php'; +//require_once "../classe/myclass.classe.php"; + +// Translations +$langs->loadLangs(array("admin", "Agefoddx@Agefoddx")); + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('Agefoddxsetup', 'globalsetup')); + +// Access control +if (!$user->admin) {accessforbidden();} + +// Parameters +$action = GETPOST('action', 'aZ09'); +$backtopage = GETPOST('backtopage', 'alpha'); +$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php + +$value = GETPOST('value', 'alpha'); +$label = GETPOST('label', 'alpha'); +$scandir = GETPOST('scan_dir', 'alpha'); +$type = 'myobject'; + + +$error = 0; +$setupnotempty = 0; + +$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + + + +/* + * View + */ + +$form = new Form($db); + +$help_url = ''; +$page_name = "AgefoddxSetup"; + +llxHeader('', $langs->trans($page_name), $help_url, '', 0, 0, '', '', '', 'mod-Agefoddx page-admin'); + +// Subheader +$linkback = ''.$langs->trans("BackToModuleList").''; + +print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup'); + +// Configuration header +$head = AgefoddxAdminPrepareHead(); +print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "Agefoddx@Agefoddx"); + +// Setup page goes here +echo ''.$langs->trans("AgefoddxSetupPage").'

'; +/* Setup semi structure MVC*/ + +$chargeurDeClasse = new Psr4AutoloaderClass(false); +$chargeurDeClasse->register(); +$chargeurDeClasse->addNamespace('Module\Agefoddx','..'); +if (!isset($_POST['controleur'])){ + $controleur = 'bd'; +} else { + $controleur = $_POST['controleur']; +} +$nomDeClasseControleur = 'Module\Agefoddx\Classe\Controleur\Controleur'.ucfirst($controleur); +if (class_exists($nomDeClasseControleur)){ + if (isset($_POST['action'])){ + $action = $_POST['action']; + $methodes = get_class_methods($nomDeClasseControleur); + if (in_array($action, $methodes)){ + $nomDeClasseControleur::$action(); + }else { + $nomDeClasseControleur::afficherErreur("

Erreur 404

+

page not found

"); + } + }else { + ControleurBd::afficherListe(); + } +}else { + ControleurBd::afficherListe(); +} + +// Page end +print dol_get_fiche_end(); + +llxFooter(); +$db->close(); diff --git a/classe/.htaccess b/classe/.htaccess new file mode 100644 index 0000000..a7a56f7 --- /dev/null +++ b/classe/.htaccess @@ -0,0 +1 @@ +Require all denied \ No newline at end of file diff --git a/classe/Classe/GestionTexte.php b/classe/Classe/GestionTexte.php new file mode 100644 index 0000000..e2df759 --- /dev/null +++ b/classe/Classe/GestionTexte.php @@ -0,0 +1,15 @@ +getListeBD(); + $titre = $langs->trans("AgefoddxAfficherListeBD"); + self::afficherVue(["titre"=>"$titre", "cheminCorpsVue" => ControleurBd::$lien."/afficherListe.php", "listeBD" => $liste, "message" => $message]); + } + + /** + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void affiche la page d'ajout de base de données + */ + public static function ajouter(string $message = ""){ + global $langs; + $titre = $langs->trans("AgefoddxAjouterBD"); + self::afficherVue(["titre"=>"$titre", "cheminCorpsVue" => ControleurBd::$lien."/ajouter.php", "message"=>$message]); + } + + /** + * @return void gestion de l'insertion des liens vers des bases de données + */ + public static function insertion() { + global $langs; + $nom = $_POST["nomBD"]; + $lien = $_POST["lienBD"]; + $user = $_POST["user"]; + if (isset($_POST["port"])) { try { $port = intval($_POST["port"]); } catch (Exception $ex){ self::afficherListe($ex);} } + $mdp = $_POST["mdp"]; + if (isset($nom) && isset($lien) && isset($user) && isset($mdp)) $test_connection = new bdExterneInteraction(null, $nom, $lien, $user, $port); + $test_connection->setMdp($mdp); + if ($test_connection->connectionBD()){ + $value = (new bdGestion())->insertionBD($nom, $lien, $user, $port); + if ($value)self::afficherListe($langs->trans("AgefoddxInsertionTrueBD")); + else self::ajouter($langs->trans("AgefoddxInsertionFalseBD")); + }else self::ajouter($langs->trans("AgefoddxConnexionBDImp")); + } + + /** + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void affiche la page de modification de liens dans la table + */ + public static function modifier(string $message = "") { + global $langs; + $titre = $langs->trans("AgefoddxModifierBD"); + $id = $_POST["idBD"]; + $nom = $_POST["nomBD"]; + $liste = (new bdGestion())->getBdByPk($id); + self::afficherVue(["titre"=>"$titre $nom","cheminCorpsVue" => ControleurBd::$lien."/modifier.php", "idBD"=>$id, "nomBD" => $nom, "liste" => $liste, "message" => $message]); + } + + /** + * @return void met à jour les données récupéré dans la table + */ + public static function update() { + global $langs; + if (isset($_POST["idBD"])) {try {$id = intval($_POST["idBD"]);} catch (Exception $ex){ self::afficherListe($ex);}} + $nom = $_POST["nomBD"]; + $lien = $_POST["lienBD"]; + $user = $_POST["user"]; + if (isset($_POST["port"])) {try {$port = intval($_POST["port"]);} catch (Exception $ex){self::afficherListe($ex);}} + $mdp = $_POST["mdp"]; + + if (isset($nom) && isset($lien) && isset($user) && isset($mdp)) + $test_connection = new bdExterneInteraction($id, $nom, $lien, $user, $port); + $test_connection->setMdp($mdp); + if ($test_connection->connectionBD()){ + $value = (new bdGestion())->modificationBD($id, $nom, $lien, $user, $port); + if ($value)self::afficherListe($langs->trans("AgefoddxModificationTrueBD")); + else self::modifier($langs->trans("AgefoddxModificationFalseBD")); + }else self::modifier($langs->trans("AgefoddxConnexionBDImp")); + } + + /** + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void affiche la page de suppression bd + */ + public static function supprimer(string $message = ""){ + global $langs; + $titre = $langs->trans("AgefoddxSupprimerBD"); + $idBD = $_POST["idBD"]; + $nomBD = $_POST["nomBD"]; + self::afficherVue(["titre"=>"$titre $nomBD", "cheminCorpsVue" => ControleurBd::$lien."/supprimer.php", "nomBD" => $nomBD, "idBD"=>$idBD, "message"=>$message]); + } + + /** + * @return void supprime le lien avec la bd + */ + public static function suppression() { + global $langs; + $idBD = $_POST["idBD"]; + $nomBD = $_POST["nomBD"]; + $value = $_POST["ouiNon"]; + $gestion = (new GestionTexte()); + if ($value == "true" && $idBD && isset($nomBD)) { + $connexion_bd = new bdGestion(); + if ($connexion_bd->bdPossedeDesTables($idBD))self::afficherListe($gestion::tronquerParentheses($langs->trans("AgefoddxTableExistante"), $nomBD) ); + else { + $value = $connexion_bd->suppressionBD($idBD); + if ($value)self::afficherListe($gestion::tronquerParentheses($langs->trans("AgefoddxSuppressionTrueBD"), $nomBD)); + else self::afficherListe($gestion::tronquerParentheses($langs->trans("AgefoddxSuppressionFalseBD"), $nomBD)); + }} else self::afficherListe($gestion::tronquerParentheses($langs->trans("AgefoddxSuppressionAnnulerBD"), $nomBD) ); + } +} \ No newline at end of file diff --git a/classe/Controleur/ControleurGenerique.php b/classe/Controleur/ControleurGenerique.php new file mode 100644 index 0000000..abebed8 --- /dev/null +++ b/classe/Controleur/ControleurGenerique.php @@ -0,0 +1,24 @@ + "../view/erreur.php", "messageErreur" => $messageErreur]); + } +} \ No newline at end of file diff --git a/classe/Controleur/ControleurLigne.php b/classe/Controleur/ControleurLigne.php new file mode 100644 index 0000000..76811a5 --- /dev/null +++ b/classe/Controleur/ControleurLigne.php @@ -0,0 +1,208 @@ +getTableByPk($idTable); + $nomTableAgefodd = $infoTable["nomTableAgefodd"]; + $nomTableExterne = $infoTable["nomTableExterne"]; + $titre = GestionTexte::tronquerParentheses($langs->trans("AgefoddxTitreAfficherListeColonne"), "$nomTableExterne ".$langs->trans("AgefoddxEt")." $nomTableAgefodd"); + $liste = (new ligneGestion())->getListeLigneCorreler($idTable); + $addresse = "afficherListe"; + self::afficherVue(["titre" => $titre, "cheminCorpsVue"=>self::$lien."/".$addresse.".php","message"=>$message, + "idBD"=>$idBD,"nomBD"=>$nomBD, + "idTable"=>$idTable, "nomTableA"=>$nomTableAgefodd, "nomTableE"=>$nomTableExterne, + "liste"=>$liste, "mdp"=>$_POST["mdp"]]); + } + + /** + * @param string $titre titre de la page + * @param string $actionApres action a réalisé + * @param string $titreAction label de l'action + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void permet la connection avec la base de donnée extérieur + */ + public static function getMdp ($titre, $actionApres, $titreAction, $message = "") { + $idBD = $_POST["idBD"]; + $nomBD = $_POST["nomBD"]; + $idTable = $_POST["idTable"]; + $valeurBase = $_POST["valeurBase"] ?? $_POST["nomTableAgefodd"] ?? ""; + $infoTable = (new tableGestion())->getTableByPk($idTable); + $nomTableAgefodd = $infoTable["nomTableAgefodd"]; + $nomTableExterne = $infoTable["nomTableExterne"]; + $addresse = "transition"; + self::afficherVue(["titre" => $titre, "cheminCorpsVue"=>self::$lien."/".$addresse.".php","message"=>$message, + "idBD"=>$idBD,"nomBD"=>$nomBD, "valeurBase"=>$valeurBase, + "idTable"=>$idTable, "nomTableA"=>$nomTableAgefodd, "nomTableE"=>$nomTableExterne, + "actionApres"=>$actionApres, "titreAction"=>$titreAction]); + } + + /** + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void affichage de la page d'ajout de lien entre les lignes + */ + public static function ajouter ($message = "") { + global $langs; + $idBD = $_POST["idBD"]; + $nomBD = $_POST["nomBD"]; + $idTable = $_POST["idTable"]; + $valeurBase = $_POST["valeurBase"] ?? $_POST["nomTableAgefodd"] ?? $_POST["agefoddLigneFk"] ?? ""; + $infoTable = (new tableGestion())->getTableByPk($idTable); + $nomTableAgefodd = $infoTable["nomTableAgefodd"]; + $nomTableExterne = $infoTable["nomTableExterne"]; + $titre = $langs->trans("AgefoddxAjouterLien")." $nomTableAgefodd ".$langs->trans("AgefoddxEt")." $nomTableExterne"; + $tab = $_POST["tab"] ?? "tab1"; + + $addresse = "ajouter"; + $mdp = $_POST["mdp"]; + if ($mdp != "" && isset($mdp)){ + $bdE_connexion = bdExterneInteraction::construireDepuisSQL((new bdGestion())->getBdByPk($idBD), $mdp); + if ($bdE_connexion->connectionBD()){ + $listeE = bdExterneLigneGestion::getListeLigne($bdE_connexion, $nomTableExterne); + $listeA = (new ligneGestion())->getListeLigneAgefodd($nomTableAgefodd, $idTable); + $listeEFK = bdExterneLigneGestion::getListeFK($bdE_connexion, $nomTableExterne); + $listeAFK = (new ligneGestion())->getListeFK($nomTableAgefodd, $idTable); + if (in_array($valeurBase, $listeAFK[0])) $tab = "tab3"; + self::afficherVue(["titre" => $titre, "cheminCorpsVue"=>self::$lien."/".$addresse.".php","message"=>$message, + "idBD"=>$idBD,"nomBD"=>$nomBD, + "idTable"=>$idTable, "nomTableA"=>$nomTableAgefodd, "nomTableE"=>$nomTableExterne, + "listeE"=>$listeE, "listeA"=>$listeA,"valeurBase"=>$valeurBase, "listeEFK"=>$listeEFK, "listeAFK"=>$listeAFK,"mdp"=>$mdp, "tab"=>$tab]); + } else { + self::getMdp($titre, 'ajouter', $langs->trans("AgefoddxAjouter"), $langs->trans("AgefoddxMDPInc")); + } + } else { + self::getMdp($titre, 'ajouter', $langs->trans("AgefoddxAjouter")); + } + } + + /** + * @return void insertion de lien entre diver lignes + */ + public static function insertion() { + global $langs; + $idBD = $_POST["idBD"]; + $nomBD = $_POST["nomBD"]; + $idTable = $_POST["idTable"]; + $infoTable = (new tableGestion())->getTableByPk($idTable); + $nomTableAgefodd = $infoTable["nomTableAgefodd"]; + $nomTableExterne = $infoTable["nomTableExterne"]; + $agefoddLigne = $_POST["agefoddLigne"]; + $bdExterneLigne = $_POST["bdExterneLigne"]; + $valeurFixe = $_POST["valeurFixe"]; + $valeurBase = $_POST["valeurBase"] ?? $_POST["nomTableAgefodd"] ?? ""; + $agefoddFk = $_POST["agefoddLigneFk"]; + $externeFk = $_POST["bdExterneLigneFk"]; + + $mdp = $_POST["mdp"]; + $tab = $_POST["tab"]; + $gestionLigne = new ligneGestion(); + if (isset($idBD) && isset($nomBD) && isset($idTable) && isset($agefoddLigne) && isset($bdExterneLigne)){ + if ($bdExterneLigne != '' && $agefoddLigne != ''){ + if (!$gestionLigne->correlationEstDansTable($idTable, $agefoddLigne)){ + $bdE_connexion = bdExterneInteraction::construireDepuisSQL((new bdGestion())->getBdByPk($idBD), $mdp); + $typeE = (new GestionTexte())->tronquerParentheses(bdExterneLigneGestion::getTypeLigne($bdE_connexion, $nomTableExterne, $bdExterneLigne)); + $typeA = (new GestionTexte())->tronquerParentheses($gestionLigne->getTypeLigne($nomTableAgefodd, $agefoddLigne)); + if ($gestionLigne->sontCompatible($typeA, $typeE)){ + $value = $gestionLigne->insertion($idTable, $idBD, $agefoddLigne, $bdExterneLigne); + if ($value) self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxMessageLigneInsertionTrue"), "$agefoddLigne ".$langs->trans("AgefoddxEt")." $bdExterneLigne")); + else self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxMessageLigneInsertionFalse"), "$agefoddLigne ".$langs->trans("AgefoddxEt")." $bdExterneLigne")); + }else self::ajouter(GestionTexte::tronquerParentheses($langs->trans("AgefoddxMessageLigneInsertionInc"), "$agefoddLigne($typeA) ".$langs->trans("AgefoddxEtDe")." $bdExterneLigne($typeE) ")); + }else self::ajouter(GestionTexte::tronquerParentheses($langs->trans("AgefoddxMessageLigneInsertionDejaLiee"), $agefoddLigne)); + }else self::ajouter($langs->trans("AgefoddxMessageLigneInsertionDoitChoisirVal")); + }elseif (isset($idBD) && isset($nomBD) && isset($idTable) && isset($agefoddLigne) && $valeurFixe) { + if ($agefoddLigne != '') { + if (!$gestionLigne->correlationEstDansTable($idTable, $agefoddLigne)) { + $value = $gestionLigne->insertionValue($idTable, $idBD, $agefoddLigne, $valeurFixe); + if ($value) self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxMessageLigneInsertionTrue"), "$agefoddLigne " . $langs->trans("AgefoddxEtLaVal") . " $valeurFixe")); + else self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxMessageLigneInsertionTrue"), "$agefoddLigne " . $langs->trans("AgefoddxEtLaVal") . " $valeurFixe")); + } else self::ajouter(GestionTexte::tronquerParentheses($langs->trans("AgefoddxMessageLigneInsertionDejaLiee"), $agefoddLigne)); + } else self::ajouter($langs->trans("AgefoddxMessageLigneInsertionDoitChoisirVal")); + }elseif (isset($idBD) && isset($nomBD) && isset($idTable) && isset($agefoddFk) && isset($externeFk)) { + list($agefoddFk, $tableReferenceA) = explode('|', $agefoddFk); + list($externeFk, $tableReferenceE) = explode('|', $externeFk); + if ((new tableGestion())->tablesDejaEnregistrer($tableReferenceA, $tableReferenceE)) { + $bdE_connexion = bdExterneInteraction::construireDepuisSQL((new bdGestion())->getBdByPk($idBD), $mdp); + $typeE = (new GestionTexte())->tronquerParentheses(bdExterneLigneGestion::getTypeLigne($bdE_connexion, $nomTableExterne, $externeFk)); + $typeA = (new GestionTexte())->tronquerParentheses($gestionLigne->getTypeLigne($nomTableAgefodd, $agefoddFk)); + if ($gestionLigne->sontCompatible($typeA, $typeE)){ + $value = $gestionLigne->insertion($idTable, $idBD, $agefoddFk, $externeFk); + if ($value) self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxMessageLigneInsertionTrue"), "$agefoddFk " . $langs->trans("AgefoddxEt") . " $externeFk")); + else self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxMessageLigneInsertionTrue"), "$agefoddFk " . $langs->trans("AgefoddxEt") . " $externeFk")); + } + } else ControleurTable::ajouter(GestionTexte::tronquerParentheses($langs->trans("AgefoddxTableFkLierFalse"), "$tableReferenceA ".$langs->trans("AgefoddxEt")." $tableReferenceE")); + }else self::ajouter($langs->trans("AgefoddxMessageErreurSaisie")); + } + + /** + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void affichage de la page de suppression de lien entre les lignes + */ + public static function supprimer ($message = "") { + global $langs; + $idBD = $_POST["idBD"]; + $nomBD = $_POST["nomBD"]; + $idTable = $_POST["idTable"]; + $idLigne = $_POST["idLigne"]; + + $infoTable = (new tableGestion())->getTableByPk($idTable); + $nomTableAgefodd = $infoTable["nomTableAgefodd"]; + $nomTableExterne = $infoTable["nomTableExterne"]; + $infoLigne = (new ligneGestion())->getLigneByPk($idLigne); + $nomLigneExterne = $infoLigne["nomLigneE"]; + $nomLigneAgefodd = $infoLigne["nomLigneA"]; + + $titre = $langs->trans("AgefoddxSupprimerLienTable")." $nomLigneExterne ".$langs->trans("AgefoddxEt")." $nomLigneAgefodd"; + $addresse = "supprimer"; + self::afficherVue(["titre" => $titre, "cheminCorpsVue"=>self::$lien."/".$addresse.".php","message"=>$message, + "idBD"=>$idBD,"nomBD"=>$nomBD,"mdp"=>$_POST["mdp"], + "idTable"=>$idTable, "nomTableA"=>$nomTableAgefodd, "nomTablE"=>$nomTableExterne, + "nomLigneE"=>$nomLigneExterne, "nomLigneA"=>$nomLigneAgefodd, "idLigne"=>$idLigne]); + } + + /** + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void suppression des liens dans entre les lignes dans la bd + */ + public static function suppression ($message = "") { + global $langs; + $idBD = intval($_POST["idBD"]); + $nomBD = $_POST["nomBD"]; + $idTable = intval($_POST["idTable"]); + $idLigne = intval($_POST['idLigne']); + $mdp=$_POST["mdp"]; + $infoTable = (new tableGestion())->getTableByPk($idTable); + $nomTableAgefodd = $infoTable["nomTableAgefodd"]; + $nomTableExterne = $infoTable["nomTableExterne"]; + $infoLigne = (new ligneGestion())->getLigneByPk($idLigne); + $nomLigneExterne = $infoLigne["nomLigneE"]; + $nomLigneAgefodd = $infoLigne["nomLigneA"]; + $value = $_POST["ouiNon"]; + $et = " $nomLigneExterne ".$langs->trans("AgefoddxEt")." $nomLigneAgefodd "; + if ($value == "true" && $idLigne && isset($nomBD)){ + $connexion_ligne = new ligneGestion(); + $value = $connexion_ligne->suppression($idLigne); + if ($value)self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxSuppressionLienTrue"), $et)); + else self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxSuppressionLienFalse"), $et)); + } else self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxSuppressionLienAnnuler"), $et)); + } +} \ No newline at end of file diff --git a/classe/Controleur/ControleurTable.php b/classe/Controleur/ControleurTable.php new file mode 100644 index 0000000..a378a2d --- /dev/null +++ b/classe/Controleur/ControleurTable.php @@ -0,0 +1,183 @@ +trans("AgefoddxAfficherListeTable"), $nom); + if (isset($id)){ + $liste = (new tableGestion())->getListeTableCorreler($id); + self::afficherVue(["titre"=>"$titre","cheminCorpsVue" => ControleurTable::$lien."/afficherListe.php", "liste" => $liste, "idBD"=>$id ,"nomBD"=>$nom, "message" => $message,"mdp"=>$_POST["mdp"]]); + }else ControleurBd::afficherListe($langs->trans("AgefoddxAfficherListeTableError")); + } + + /** + * @param string $titre titre de la page + * @param string $actionApres action a réalisé + * @param string $titreAction label de l'action + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void permet la connection avec la base de donnée extérieur + */ + public static function connectionTr(string $titre, string $actionApres, string $titreAction, string $message = ""){ + $id = intval($_POST["idBD"]); + $nom = $_POST["nomBD"]; + $idT = $_POST["idTable"] ?? ""; + $nomA = $_POST["nomTableA"] ?? ""; + $nomE = $_POST["nomTableE"] ?? ""; + if (isset($id) && isset($nom)){ + $bd = (bdExterneInteraction::construireDepuisSQL((new bdGestion())->getBdByPk($id))); + self::afficherVue(["titre"=>$titre,"actionApres"=>$actionApres, "nomTableA"=>$nomA, "nomTableE"=>$nomE, "titreAction"=>$titreAction, "cheminCorpsVue" => ControleurTable::$lien."/transition.php", "idBD"=>$id ,"nomBD"=>$nom, "idTable"=>$idT, "message" => $message]); + } + } + + /** + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void affichage de la page d'ajout + */ + public static function ajouter(string $message = ""){ + global $langs; + $id = intval($_POST["idBD"]); + $nom = $_POST["nomBD"] ?? ""; + $mdp = $_POST["mdp"]; + if ($mdp != ""){ $bd = bdExterneInteraction::construireDepuisSQL((new bdGestion())->getBdByPk($id), $mdp); + if ($bd->connectionBD()) { + if (isset($id) && isset($nom)){ + $listeAgefodd = (new tableGestion())->getListeTableAgefodd(); + $listeBdExterne = bdExterneTableGestion::getListeTables($bd); + self::afficherVue(["titre"=>$langs->trans("AgefoddxAjouterLien")." Agefodd ".$langs->trans("AgefoddxEt")." $nom", "cheminCorpsVue" => ControleurTable::$lien."/ajouter.php", "idBD"=>$id ,"nomBD"=>$nom, "message" => $message, "listeAgefodd"=>$listeAgefodd, "listeBdExterne"=>$listeBdExterne ,"bdConnection"=>$bd, "mdp"=>$mdp]); + } + } else self::connectionTr($langs->trans("AgefoddxConnexion")." $nom", "ajouter", $langs->trans("AgefoddxAjouter"), $langs->trans("AgefoddxMDPInc")); + } else self::connectionTr($langs->trans("AgefoddxConnexion")." $nom", "ajouter", $langs->trans("AgefoddxAjouter")); + + } + + /** + * @return void insert les liens + */ + public static function insertion(){ + global $langs; + $id = intval($_POST["idBD"]); + $nom = $_POST["nomBD"]; + $mdp = $_POST["mdp"]; + $tableA = $_POST["agefoddTable"]; + $tableE = $_POST["bdExterneTable"]; + if ((isset($tableE) && isset($tableA)) && ($tableA!='' && $tableE!='')){ + $value = (new tableGestion())->tablesDejaEnregistrer($tableA, $tableE); + if ($value == true) self::afficherListe("$tableA ".$langs->trans("AgefoddxEt")." $tableE ".$langs->trans("AgefoddxTableDejaLiee")); + elseif ($value == false) {$ins = (new tableGestion)->insertionTable($id, $tableE, $tableA); + if ($ins) self::afficherListe($langs->trans("AgefoddxInsertionTrueTable")); + else self::ajouter($langs->trans("AgefoddxInsertionFalseTable")); + }else self::ajouter($langs->trans("AgefoddxPBConnexion")); + } else self::ajouter($langs->trans("AgefoddxTableNonSelect")); + } + + /** + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void affiche la page de suppression de lien entre les tables + */ + public static function supprimer(string $message = ""){ + global $langs; + $id = intval($_POST["idBD"]); + $idT = intval($_POST["idTable"]); + $nom = $_POST["nomBD"]; + $nomA = $_POST["nomTableA"]; + $nomE = $_POST["nomTableE"]; + $titre = $langs->trans("AgefoddxSupprimerLienTable")." $nomA ".$langs->trans("AgefoddxEt")." $nomE"; + self::afficherVue(["titre"=>"$titre","cheminCorpsVue" => ControleurTable::$lien."/supprimer.php", "idBD"=>$id, "idTable" => $idT ,"nomBD"=>$nom, "nomTableA"=>$nomA, "nomTableE"=>$nomE, "message" => $message, "mdp"=>$_POST["mdp"]]); + } + + /** + * @return void supprime les liens entre les tables + */ + public static function suppression() { + global $langs; + $idT = intval($_POST["idTable"]); + $nomBD = $_POST["nomBD"]; + $nomA = $_POST["nomTableA"]; + $nomE = $_POST["nomTableE"]; + $mdp=$_POST["mdp"]; + $value = $_POST["ouiNon"]; + $remp = $nomA . " " . $langs->trans("AgefoddxEt") . " " . $nomE; + if ($value == "true" && $idT && isset($nomBD) && isset($nomA) && isset($nomE)) { + $connexion_table = new tableGestion(); + if ($connexion_table->tablePossedeDesLignes($idT)) self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxSuppressionImpLigneLiee"), $remp)); + else {$value = $connexion_table->suppressionTable($idT); + if ($value)self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxSuppressionLienTrue"), $remp)); + else self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxSuppressionLienFalse"), $remp)); + } + }else self::afficherListe(GestionTexte::tronquerParentheses($langs->trans("AgefoddxSuppressionLienAnnuler"), $remp)); + } + + /** + * @param $message string message passable en parameter pour les interactions utilisateur + * @return void affiche la table d'importation des données + */ + public static function importer(string $message = "") { + global $langs; + $id = intval($_POST["idBD"]); + $idT = intval($_POST["idTable"]); + $nom = $_POST["nomBD"]; + $nomA = $_POST["nomTableA"]; + $nomE = $_POST["nomTableE"]; + $titre = $langs->trans("AgefoddxImporterDonnee")." $nomA ".$langs->trans("AgefoddxVers")." $nomE"; + $value = (new tableGestion())->getParametreObligatoireNonRempli($nomA, $nomE); + $importationPossible = false; + if ($value == []) $importationPossible = true; + self::afficherVue(["titre"=>$titre,"cheminCorpsVue" => ControleurTable::$lien."/importer.php", + "idBD"=>$id, "idTable" => $idT ,"nomBD"=>$nom, "nomTableA"=>$nomA, "nomTableE"=>$nomE, "valueImportation" => $importationPossible, "liste"=>$value,"message" => $message, "mdp"=>$_POST["mdp"]]); + } + + /** + * @return void importe les données en fonction des tables liée + */ + public static function importation(){ + global $langs; + $id = intval($_POST["idBD"]); + $idT = intval($_POST["idTable"]); + $nom = $_POST["nomBD"]; + $nomA = $_POST["nomTableA"]; + $nomE = $_POST["nomTableE"]; + $mdp = $_POST["mdp"] ?? ""; + $bd = bdExterneInteraction::construireDepuisSQL((new bdGestion())->getBdByPk($id), $mdp); + if ($mdp!=""){ + if ($bd->connectionBD()) { + $idTableE = bdExterneTableGestion::getPk($bd, $nomE); + $parametre = (new TableGestion())->getParametreExterne($idT); + $parametre[] = ["id_source"=>$idTableE, "fixe"=>"false"]; + + $liste = bdExterneTableGestion::getValeurAExporter($bd, $parametre, $nomE); + if ((new ligneGestion())->possedeFk($nomA, $idT)){ + $fkListe = (new ligneGestion())->getListeFKCorreler($nomA, $idT); + foreach ($fkListe as $ligne) { + $listeConvertion = (new tableGestion())->getTableConversionFK($ligne["TableReference"],(new ligneGestion())->getClefReferente($nomA, $ligne["NomLigne"])); + if ($listeConvertion != false ){ + for ($x=0; $ximporterTout($liste,$nomE, $idTableE, $nomA, $type); + self::afficherListe($message); + } else self::connectionTr($langs->trans("AgefoddxImporter"), "importation", $langs->trans("AgefoddxImporter"), "mot de passe incorrecte"); + } else self::connectionTr($langs->trans("AgefoddxImporter"), "importation", $langs->trans("AgefoddxImporter")); + } +} \ No newline at end of file diff --git a/classe/GestionBD/bdExterneInteraction.php b/classe/GestionBD/bdExterneInteraction.php new file mode 100644 index 0000000..0f902e8 --- /dev/null +++ b/classe/GestionBD/bdExterneInteraction.php @@ -0,0 +1,65 @@ +id = $id; + $this->nom = $nom; + $this->lien = $lien; + $this->user = $user; + $this->mdp = ""; + $this->port = $port; + $this->pdo = null; + } + + /** + * @return bool retourne la valeur de la connection avec la base de donnée et altère la variable pdo + */ + public function connectionBD(): bool { + try { + $this->pdo = new PDO("mysql:host=$this->lien;port=$this->port;dbname=$this->nom", $this->user, $this->mdp, + array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4")); + // On active le mode d'affichage des erreurs, et le lancement d'exception en cas d'erreur + $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } catch (Exception $ex) { return false; } + return true; + } + + public function setMdp($mdp) {$this->mdp = $mdp;} + + /** + * @return PDO|null si pdo est null essaye d'activer pdo sinon le return pdo + */ + public function getPdo(): ?PDO { + if ($this->pdo == null){ + $this->connectionBD(); + } return $this->pdo; + } + + /** + * @param array $listeInfo liste des infos nécessaires à la connection bd + * @param string $mdp mot de passe de la bd entré par l'utilisateur + * @return bdExterneInteraction renvoie un objet de lui-même + */ + public static function construireDepuisSQL(array $listeInfo,string $mdp = ""){ + $objet = (new bdExterneInteraction($listeInfo['idBD'], $listeInfo['nomBD'], $listeInfo['lienBD'], $listeInfo['user'], $listeInfo['port'])); + $objet->setMdp($mdp); + return $objet; + } + + /** + * @return string renvoie le nom de la bd + */ + public function getNomBd(){return $this->nom;} +} \ No newline at end of file diff --git a/classe/GestionBD/bdExterneLigneGestion.php b/classe/GestionBD/bdExterneLigneGestion.php new file mode 100644 index 0000000..69954c7 --- /dev/null +++ b/classe/GestionBD/bdExterneLigneGestion.php @@ -0,0 +1,48 @@ +getPdo(); + $list = []; + $resql= $pdo->query("SELECT column_name as 'row_name' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$nomTable';"); + foreach ($resql as $value){ + if (!in_array($value["row_name"], self::getListeFK($bd, $nomTable))) + $list[] = $value["row_name"]; + } return $list; + } + + /** + * @param bdExterneInteraction $bd bd externe qui permet le requêtage sql + * @param string $nomTable nom de la table + * @param string $nomLigne nom de la colonne + * @return string|null renvoie le type de la colonne + */ + public static function getTypeLigne(bdExterneInteraction $bd, string $nomTable, string $nomLigne) : ?string { + $pdo = $bd->getPdo(); + $resql = $pdo->query("SELECT COLUMN_TYPE as 'colType'FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$nomTable' AND COLUMN_NAME = '$nomLigne';"); + foreach ($resql as $value)$result = $value["colType"]; + if ($result != '') return $result; + else return null; + } + + /** + * @param bdExterneInteraction $bd bd externe qui permet le requêtage sql + * @param string $nomTable nom de la table + * @return array renvoie la liste des clefs étrangères de la table + */ + public static function getListeFK(bdExterneInteraction $bd, string $nomTable) { + $pdo = $bd->getPdo(); + $list = []; + $resql= $pdo->query("SELECT COLUMN_NAME as 'NomLigne', REFERENCED_TABLE_NAME AS 'TableReference' FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = '$nomTable' AND REFERENCED_TABLE_NAME IS NOT NULL;"); + foreach ($resql as $value){ + $list[] =["row_name" => $value["NomLigne"], "TableReference"=>$value['TableReference']]; + } + return $list; + } +} diff --git a/classe/GestionBD/bdExterneTableGestion.php b/classe/GestionBD/bdExterneTableGestion.php new file mode 100644 index 0000000..1c17a4d --- /dev/null +++ b/classe/GestionBD/bdExterneTableGestion.php @@ -0,0 +1,78 @@ +getPdo(); + $adresse = $bd->getNomBd(); + $list = []; + $resql= $pdo->query("SELECT table_name FROM information_schema.tables WHERE table_schema = '$adresse';"); + foreach ($resql as $value){ + $list[] = $value["table_name"]; + } return $list; + } + + /** + * @param bdExterneInteraction $bd bd externe qui permet le requêtage sql + * @param $table string nom de la table + * @return string return le type de la clef primaire + */ + public static function getTypePk(bdExterneInteraction $bd, string $table) : string { + $pdo = $bd->getPdo(); + $sql = "SELECT DATA_TYPE + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_NAME = '$table' + AND COLUMN_KEY = 'PRI';"; + $resql= $pdo->query($sql); + return $resql->fetch()[0]; + } + + /** + * @param bdExterneInteraction $bd bd externe qui permet le requêtage sql + * @param $table string nom de la table + * @return string return le nom de la colonne de la clef primaire + */ + public static function getPk(bdExterneInteraction $bd, string $table) { + $pdo = $bd->getPdo(); + $sql = "SELECT COLUMN_NAME + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_NAME = '$table' + AND COLUMN_KEY = 'PRI';"; + $nomClef = $pdo->query($sql); + $nomClef = $nomClef->fetch()["COLUMN_NAME"]; + return $nomClef; + } + + /** + * @param bdExterneInteraction $bd bd externe qui permet le requêtage sql + * @param $listeValue array liste des valeurs liée a récupéré + * @param $table string nom de la table + * @return array liste des valeurs récupérées + */ + public static function getValeurAExporter(bdExterneInteraction $bd, array $listeValue, string $table){ + $pdo = $bd->getPdo(); + $liste = []; + $parametreSelection = ""; + foreach ($listeValue as $value){ + if ($value["fixe"] == "false") $parametreSelection = $parametreSelection.", ".$value[key($value)]; + } + $parametreSelection = substr($parametreSelection, 2); + $sql = "SELECT $parametreSelection FROM $table;"; + $resql= $pdo->query($sql); + $ligne = []; + foreach ($resql as $row){ + foreach ($listeValue as $value){ + if ($value["fixe"] == "false") $ligne[key($value)] = $row[$value[key($value)]]; + else $ligne[key($value)] = $value[key($value)]; + } + $liste[] = $ligne; + } + return $liste; + } +} \ No newline at end of file diff --git a/classe/GestionBD/bdGestion.php b/classe/GestionBD/bdGestion.php new file mode 100644 index 0000000..fd561b5 --- /dev/null +++ b/classe/GestionBD/bdGestion.php @@ -0,0 +1,132 @@ +query("SET NAMES 'utf8mb4'"); + $list = []; + + $sql = "SELECT bdid as bdid, nom as nom FROM llx_desal_external_bd bd ORDER BY bdid, nom"; + $resql=$db->query($sql); + if ($resql) { + // Parcours des résultats avec fetch_array + while ($row = $db->fetch_array($resql)) { + // Accès aux colonnes via leur index ou alias + $row = ["bdid"=> htmlspecialchars($row['bdid']), "nom"=>htmlspecialchars($row['nom'])]; // Par alias (nom de la colonne) + // Affichage des résultats + $list[] = $row; + } + } else { + // Gestion de l'erreur + echo "Erreur SQL : " . $db->lasterror(); + return $list; + } + return $list; + } + + /** + * @param int $id id de la bd + * @return array renvoie les informations de la bd selectionné + */ + public function getBdByPk(int $id) { + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $id = $db->escape($id); + $sql = "SELECT bdid as idbd, nom, lien, user, port FROM llx_desal_external_bd WHERE bdid='$id'"; + $resql=$db->query($sql); + if ($resql) { + // Parcours des résultats avec fetch_array + $row = $db->fetch_array($resql); + // Accès aux colonnes via leur index ou alias + $list = ["idBD"=>htmlspecialchars($row['idbd']), "nomBD"=>htmlspecialchars($row["nom"]), "lienBD"=>htmlspecialchars($row["lien"]), "user"=>htmlspecialchars($row["user"]), "port"=>htmlspecialchars($row["port"])]; // Par alias (nom de la colonne) + // Affichage des résultats + } else { + // Gestion de l'erreur + echo "Erreur SQL : " . $db->lasterror(); + return $list; + } + return $list; + } + + /** + * @param string $nom nom de la bd + * @param string $lien url de la bd + * @param string $user utilisateur a utilisé + * @param int $port port de la bd + * @return bool renvoie si l'insertion fu effective + */ + public function insertionBD(string $nom, string $lien, string $user, int $port): bool { + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $nom = $db->escape($nom); // pour protéger contre l'injection sql + $lien = $db->escape($lien); // pour protéger contre l'injection sql + $user = $db->escape($user); // pour protéger contre l'injection sql + $port = $db->escape($port); // pour protéger contre l'injection sql + $sql = "INSERT INTO llx_desal_external_bd(nom, lien, user, port) VALUES ('$nom','$lien', '$user', $port);"; + $resql=$db->query($sql); + if ($resql) { return true; } + return false; + } + + /** + * @param int $idBD id de la base de donnée + * @param string $nom nom de la bd + * @param string $lien url de la bd + * @param string $user utilisateur a utilisé + * @param int $port port de la bd + * @return bool renvoie si la modification a pu être faite + */ + public function modificationBD(int $idBD, string $nom, string $lien, string $user, int $port): bool{ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $idBD = $db->escape($idBD); // pour protéger contre l'injection sql + $nom = $db->escape($nom); // pour protéger contre l'injection sql + $lien = $db->escape($lien); // pour protéger contre l'injection sql + $user = $db->escape($user); // pour protéger contre l'injection sql + $port = $db->escape($port); // pour protéger contre l'injection sql + + $sql = "UPDATE llx_desal_external_bd SET nom='$nom',lien='$lien',user='$user',port='$port' WHERE bdid='$idBD'"; + $resql=$db->query($sql); + if ($resql) { + return true; + } + return false; + } + + /** + * @param int $idBD id de la base de donnée + * @return bool renvoie si la suppression a été effectuer + */ + public function suppressionBD(int $idBD): bool { + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $idBD = $db->escape($idBD); // pour protéger contre l'injection sql + $sql = "DELETE FROM llx_desal_external_bd WHERE bdid = $idBD;"; + $resql=$db->query($sql); + if ($resql) { return true; } return false; + } + + /** + * @param $id int id de la base de donnée + * @return int renvoie le nombre de tables liées à cette base de donnée + */ + public function bdPossedeDesTables(int $id) : int { + global $db; + $res = 0; + $db->query("SET NAMES 'utf8mb4'"); + $id = $db->escape($id); // pour protéger contre l'injection sql + $sql = "SELECT COUNT(tid) as nbrow FROM llx_desal_external_table WHERE bdid = $id;"; + $resql=$db->query($sql); + if ($resql) { + $row = $db->fetch_array($resql); + $res = $row["nbrow"]; + } + return $res; + } +} \ No newline at end of file diff --git a/classe/GestionBD/ligneGestion.php b/classe/GestionBD/ligneGestion.php new file mode 100644 index 0000000..a966bf3 --- /dev/null +++ b/classe/GestionBD/ligneGestion.php @@ -0,0 +1,255 @@ +query("SET NAMES 'utf8mb4'"); + $nomTable = $db->escape($nomTable); // pour protéger contre l'injection sql + $list = []; + $sql = "SELECT column_name as 'NomLigne' FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_NAME = '$nomTable' AND column_name != 'id_source' + AND column_name != 'table_source' AND EXTRA != 'auto_increment';"; + $resql1=$db->query($sql); + $listeFk = array_column(self::getListeFK($nomTable, $tid), "NomLigne") ?? []; + $listeLigneECorreler = array_column(self::getListeLigneCorreler($tid), "nomLigneA"); + if ($resql1) { + while ($row = $db->fetch_array($resql1)) { + $rowid = htmlspecialchars($row['NomLigne']); // Par alias (nom de la colonne) + if(!in_array($rowid, $listeFk) && !in_array($rowid, $listeLigneECorreler)) $list[] = $rowid; + } + } else { return false; } + return $list; + } + + /** + * @param int $tid identifient de la table + * @return array renvoie la liste des lignes liées pour la table passée en paramètre + */ + public function getListeLigneCorreler(int $tid) : array{ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $tid = $db->escape($tid); // pour protéger contre l'injection sql + $sql = "SELECT rid, bdid, tid, nomligneexterne, nomligneagfodd FROM llx_desal_external_row WHERE tid = '$tid' "; + $resql=$db->query($sql); + if ($resql) { // Parcours des résultats avec fetch_array + while ($row = $db->fetch_array($resql)) { + $list[] = ["idBD"=>$row["bdid"], "idTable"=>$row["tid"],"idLigne"=>$row["rid"],"nomLigneE"=>$row["nomligneexterne"],"nomLigneA"=>$row["nomligneagfodd"]]; + } + } + return $list; + } + + /** + * @param int $rid id de la colonne + * @return array renvoie la ligne à partir de son id + */ + public function getLigneByPk(int $rid){ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $rid = $db->escape($rid); // pour protéger contre l'injection sql + $sql = "SELECT rid, bdid, tid, nomligneexterne, nomligneagfodd FROM llx_desal_external_row WHERE rid = '$rid';"; + $resql=$db->query($sql); + if ($resql) { + $row = $db->fetch_array($resql); + $list = ["idBD"=>$row["bdid"], "idTable"=>$row["tid"], "idLigne"=>$row["rid"], + "nomLigneE"=>$row["nomligneexterne"],"nomLigneA"=>$row["nomligneagfodd"]]; + } + return $list; + } + + /** + * @param int $idTable id de la table + * @param string $ligneA nom de la colonne d'agefodd + * @return bool renvoie-la si la ligne est déjà liée dans cette table + */ + public function correlationEstDansTable(int $idTable, string $ligneA): bool{ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $ligneA = $db->escape($ligneA); $idTable = $db->escape($idTable); // pour protéger contre l'injection sql + $sql = "SELECT COUNT(*) as nb FROM llx_desal_external_row WHERE tid = $idTable AND nomLigneAgfodd = '$ligneA'"; + $resql=$db->query($sql); $row = $db->fetch_array($resql); $nb = $row["nb"]; + if ($nb == 0) return false; return true; + } + + /** + * @param int $tid id de la table + * @param int $bdid id de la base de donnée + * @param string $nomLigneA nom de la ligne d'agefodd + * @param string $nomLigneE nom de la ligne externe + * @return bool renvoie si l'insertion à fonctionner + */ + public function insertion(int $tid, int $bdid, string $nomLigneA, string $nomLigneE) : bool{ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $tid = $db->escape($tid); $bdid = $db->escape($bdid); // pour protéger contre l'injection sql + $nomLigneA = $db->escape($nomLigneA); $nomLigneE = $db->escape($nomLigneE); // pour protéger contre l'injection sql + $sql = "INSERT INTO llx_desal_external_row( bdid, tid, nomLigneExterne, nomLigneAgfodd ) + VALUES ('$bdid','$tid','$nomLigneE','$nomLigneA')"; + $resql=$db->query($sql); + if ($resql) return true; + else return false; + } + + /** + * @param int $tid id de la table + * @param int $bdid id de la bd + * @param string $nomLigneA nom de la ligne d'agefodd + * @param mixed $valueFixe la valeur fixe à lier avec la ligne d'agefodd + * @return bool renvoie si l'insertion a bien été éffectuer + */ + public function insertionValue(int $tid, int $bdid, string $nomLigneA, $valueFixe){ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $tid = $db->escape($tid); $bdid = $db->escape($bdid); // pour protéger contre l'injection sql + $nomLigneA = $db->escape($nomLigneA); $valueFixe = $db->escape($valueFixe); // pour protéger contre l'injection sql + $sql = "INSERT INTO llx_desal_external_row( bdid, tid, valeurFixe, nomLigneAgfodd) + VALUES ('$bdid','$tid','$valueFixe','$nomLigneA')"; + $resql=$db->query($sql); + if ($resql) return true; else return false; + } + + /** + * @param int $rid id de la colonne + * @return bool renvoie la valeur de la suppression + */ + public function suppression(int $rid){ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $rid = $db->escape($rid); // pour protéger contre l'injection sql + $sql = "DELETE FROM llx_desal_external_row WHERE rid='$rid';"; + $resql=$db->query($sql); + if ($resql) { return true; } return false; + } + + /** + * @param string $typeA type de la ligne d'agefodd + * @param string $typeE type de la ligne en correlation + * @return bool renvoie si les deux lignes sont corrélées + */ + public function sontCompatible(string $typeA, string $typeE) : bool { + $compatible_types = [ + ['int', 'bigint', 'smallint', 'mediumint', 'tinyint'], + ['varchar', 'text', 'char'], + ['decimal', 'float', 'double'], + ['datetime', 'timestamp', 'date'] + ]; + $super_type = ['varchar', 'text']; + $lien_plus_peux_moins = [['decimal', 'float', 'double'], ['int', 'bigint', 'smallint', 'mediumint', 'tinyint']]; + if (in_array($typeA, $super_type)) return true; + if (in_array($typeA, $lien_plus_peux_moins[0]) && in_array($typeE, $lien_plus_peux_moins[1])) return true; + foreach ($compatible_types as $group) { + if (in_array($typeA, $group) && in_array($typeE, $group)) return true; + }return false; + } + + /** + * @param string $nomTable nom de la table + * @param string $nomLigne nom de la ligne + * @return string|null renvoie le type de la ligne + */ + public function getTypeLigne(string $nomTable, string $nomLigne) : ?string { + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $nomTable = $db->escape($nomTable); $nomLigne = $db->escape($nomLigne); + $sql = "SELECT COLUMN_TYPE as 'colType'FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_NAME = '$nomTable' AND COLUMN_NAME = '$nomLigne';"; + $resql=$db->query($sql); + if ($resql) { while ( $row = $db->fetch_array($resql) ) { $liste = $row['colType']; } return $liste; } + else return null; + } + + /** + * @param string $tableA nom de la table d'agefodd + * @param int $tid id de la table + * @return array|false renvoie la liste des clefs primaires + */ + public function getListeFK(string $tableA, int $tid){ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $tableA = $db->escape($tableA); // pour protéger contre l'injection sql + $tid = $db->escape($tid); + $sql = "SELECT COLUMN_NAME as 'NomLigne', REFERENCED_TABLE_NAME AS 'TableReference' + FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE + WHERE TABLE_NAME = '$tableA' AND REFERENCED_TABLE_NAME IS NOT NULL;"; + $listeLigneECorreler = array_column(self::getListeLigneCorreler($tid), "nomLigneA"); + $resql=$db->query($sql); + if ($resql) { // Parcours des résultats avec fetch_array + while ($row = $db->fetch_array($resql)) { + if(!in_array($row['NomLigne'], $listeLigneECorreler)) + $list[] = ["NomLigne"=>$row['NomLigne'], "TableReference"=>$row['TableReference']]; + } + } else { return false; }return $list; + } + + /** + * @param string $tableA nom table agefodd + * @param int $tid id de la table + * @return array|false renvoie la liste des clefs primaires corréler + */ + public function getListeFKCorreler(string $tableA, int $tid){ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $tableA = $db->escape($tableA); // pour protéger contre l'injection sql + $tid = $db->escape($tid); + $sql = "SELECT COLUMN_NAME as 'NomLigne', REFERENCED_TABLE_NAME AS 'TableReference' FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = '$tableA' AND REFERENCED_TABLE_NAME IS NOT NULL;"; + $listeLigneECorreler = array_column(self::getListeLigneCorreler($tid), "nomLigneA"); + $resql=$db->query($sql); + if ($resql) {// Parcours des résultats avec fetch_array + while ($row = $db->fetch_array($resql)) { + if(in_array($row['NomLigne'], $listeLigneECorreler))$list[] = ["NomLigne"=>$row['NomLigne'], "TableReference"=>$row['TableReference']]; + } + } else {return false; + }return $list; + } + + /** + * @param string $tableA nom de la table d'agefodd + * @param int $tid id de la table + * @return bool renvoie si la table possède une clef primaire non corréler + */ + public function possedeFk(string $tableA, int $tid){ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $tableA = $db->escape($tableA); // pour protéger contre l'injection sql + $tid = $db->escape($tid); + $sql = "SELECT COLUMN_NAME as 'NomLigne', REFERENCED_TABLE_NAME AS 'TableReference' FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = '$tableA' AND REFERENCED_TABLE_NAME IS NOT NULL;"; + $listeLigneECorreler = array_column(self::getListeLigneCorreler($tid), "nomLigneA"); + $resql=$db->query($sql); + if ($resql) {// Parcours des résultats avec fetch_array + while ($row = $db->fetch_array($resql)) { + $list[] = ["NomLigne"=>$row['NomLigne'], "TableReference"=>$row['TableReference']]; + } + } else { return false; } + return sizeof($list) > 0; + } + + /** + * @param string $table nom de la table + * @param string $clef nom de la clef + * @return false|string revoit la colonne de référence + */ + public function getClefReferente(string $table, string $clef) : string{ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $table = $db->escape($table); $clef = $db->escape($clef); + $sql = "SELECT REFERENCED_COLUMN_NAME AS 'fk' + FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE + WHERE TABLE_NAME = '$table' + AND COLUMN_NAME = '$clef';"; + $resql=$db->query($sql); + if ($resql) { $clef = $db->fetch_array($resql)['fk']; + } else { return false; } return $clef; + } + +} \ No newline at end of file diff --git a/classe/GestionBD/tableGestion.php b/classe/GestionBD/tableGestion.php new file mode 100644 index 0000000..7b032cd --- /dev/null +++ b/classe/GestionBD/tableGestion.php @@ -0,0 +1,367 @@ +query("SELECT DATABASE()"); + $adresse = $db->fetch_array($resql)[0]; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $sql = "SELECT table_name as 'NomTable' FROM information_schema.tables WHERE table_schema = '$adresse' AND table_name LIKE 'llx_agefodd_%';"; + $resql1=$db->query($sql); + if ($resql1) { + // Parcours des résultats avec fetch_array + while ($row = $db->fetch_array($resql1)) { + // Accès aux colonnes via leur index ou alias + $rowid = htmlspecialchars($row['NomTable']); // Par alias (nom de la colonne) + $list[] = $rowid; + } + } else { + return false; + } return $list; + } + + /** + * @param $id int identifient de la table à récupérer + * @return array|false renvoie la liste des infos de la table sous forme de dictionnaire (idTable, idBD, nomTableAgefodd, nomTableExterne) + */ + public function getTableByPk(int $id){ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $id = $db->escape($id); // pour protéger contre l'injection sql + $sql = "SELECT tid, bdid, nomTableExterne, nomTableAgfodd FROM llx_desal_external_table WHERE tid=$id;"; + $resql=$db->query($sql); + if ($resql) { + // Parcours des résultats avec fetch_array + $row = $db->fetch_array($resql); + $list = ['idTable'=>$row["tid"], "idBD"=>$row["bdid"],"nomTableExterne"=>$row["nomTableExterne"],"nomTableAgefodd"=>$row["nomTableAgfodd"]]; // Par alias (nom de la colonne) + + } else { + // Gestion de l'erreur + return false; + } + return $list; + } + + /** + * @param int $idBD id de la base de donnée + * @return array|false renvoie la liste des tables a lié + */ + public function getListeTableCorreler(int $idBD) { + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $idBD = $db->escape($idBD); + $sql = "SELECT bd.bdid as bdid, bd.nom as nom, t.tid as tid, t.nomTableExterne as te, t.nomTableAgfodd as ta, COUNT(rid) as nbr + FROM llx_desal_external_bd bd JOIN llx_desal_external_table t ON bd.bdid = t.bdid + LEFT JOIN llx_desal_external_row r ON r.tid = t.tid + WHERE bd.bdid = $idBD + GROUP BY bd.bdid, bd.nom, t.tid, t.nomTableExterne, t.nomTableAgfodd + ORDER BY bd.bdid, t.tid, bd.nom"; + $resql = $db->query($sql); + if ($resql) {// Parcours des résultats avec fetch_array + while ($row = $db->fetch_array($resql)) { + // Accès aux colonnes via leur index ou alias + $row = ["idBD" => htmlspecialchars($row["bdid"]), "nom"=>htmlspecialchars($row["nomBD"]), "idTable"=>htmlspecialchars($row["tid"]), "nomTableExterne"=>htmlspecialchars($row["te"]), "nomTableAgfodd"=>htmlspecialchars($row["ta"]), "nombreLigne"=>htmlspecialchars($row["nbr"])]; // Par alias (nom de la colonne) + // Affichage des résultats + $list[] = $row; + }} else {// Gestion de l'erreur + return false; + }return $list; + } + + /** + * @param int $idBD id de la base de donnée + * @param string $nomTableExterne nom de la table a lié + * @param string $nomTableAgefodd nom de la table d'Agefodd + * @return bool renvoie la valeur d'insertion dans la table + */ + public function insertionTable(int $idBD, string $nomTableExterne, string $nomTableAgefodd) : bool{ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $idBD = $db->escape($idBD); // pour protéger contre l'injection sql + $nomTableExterne = $db->escape($nomTableExterne); + $nomTableAgefodd = $db->escape($nomTableAgefodd); + $sql = "INSERT INTO llx_desal_external_table(bdid, nomTableExterne, nomTableAgfodd) VALUES ('$idBD', '$nomTableExterne', '$nomTableAgefodd');"; + $resql=$db->query($sql); + if ($resql) { + return true; + } return false; + } + + /** + * @param $idT int|string clef primaire de la table + * @return bool renvoie si la suppression a bien été efféctuer + */ + public function suppressionTable($idT) : bool { + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $idT = $db->escape($idT); // pour protéger contre l'injection sql + $sql = "DELETE FROM llx_desal_external_table WHERE tid='$idT';"; + $resql=$db->query($sql); + if ($resql) { + return true; + }return false; + } + + /** + * @param $tableA string nom de la table d'agefodd + * @param $tableE string nom de la table a lié + * @return bool|null renvoie si la table est déjà lié ou null en cas d'erreur sql + */ + public function tablesDejaEnregistrer(string $tableA, string $tableE) { + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $sql = "SELECT COUNT(tid) as nbTable FROM llx_desal_external_table WHERE nomTableAgfodd = '$tableA' AND nomTableExterne = '$tableE'"; + $resql=$db->query($sql); + if ($resql) { + $value = $db->fetch_array($resql)[0]; + if ($value == 0) { + return false; + } else { + return true; + } + } + return null; + } + + /** + * @param $id string|int identifient de la table + * @return int return le nombre de lignes present dans llx_desal_external_row + */ + public function tablePossedeDesLignes($id) : int { + global $db; + $res = 0; + $db->query("SET NAMES 'utf8mb4'"); + $id = $db->escape($id); // pour protéger contre l'injection sql + $sql = "SELECT COUNT(tid) as nbrow FROM llx_desal_external_row WHERE tid = $id;"; + $resql=$db->query($sql); + if ($resql) { + $row = $db->fetch_array($resql); + $res = $row["nbrow"]; + } + return $res; + } + + /** + * @param $tableA string nom de la table d'agefodd + * @param $type_id string nom du type d'id + * @return void modifie la table pour y inséré id_source & table_source + */ + private function alterTableAjout(string $tableA, string $type_id) { + global $db; + $tableA = $db->escape($tableA); // pour protéger contre l'injection sql + $type_id = $db->escape($type_id); + if ($type_id == 'varchar') {$type_id=$type_id.'(255)';} + $sql = "ALTER TABLE $tableA ADD COLUMN id_source $type_id, ADD COLUMN table_source VARCHAR(255)"; + $res = $db->query($sql); + } + + /** + * @param $tableA string nom de la table d'agefodd + * @param $type_id string type de la clef primaire de $tableA (varchar, integer, ...) + * @return void modifie la table $tableA si cela n'a pas déjà été fait + */ + public function alterTableAvantPremiereInsertion(string $tableA, string $type_id) : void { + global $db; + $tableA = $db->escape($tableA); // pour protéger contre l'injection sql + $sql = "SELECT id_source FROM $tableA ;"; + $resql=$db->query($sql); + if (!$resql) $this->alterTableAjout($tableA, $type_id); + } + + /** + * @param string $nomTableA nom de la table d'agefodd + * @param string $nomTableE nom de la table à lier + * @return array|false return la liste des parameters obligatoire non rempli ou faux en cas d'erreur sql + */ + public function getParametreObligatoireNonRempli(string $nomTableA,string $nomTableE) { + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $nomTableA = $db->escape($nomTableA); + $nomTableE = $db->escape($nomTableE); + $sql = "SELECT isc.COLUMN_NAME as 'cm', isc.IS_NULLABLE as 'value' + FROM INFORMATION_SCHEMA.COLUMNS isc + WHERE TABLE_NAME = '$nomTableA' + AND NOT EXISTS( + SELECT nomLigneAgfodd + FROM llx_desal_external_row as lder + JOIN llx_desal_external_table as ldet + ON lder.tid = ldet.tid + WHERE nomTableAgfodd = '$nomTableA' + AND nomTableExterne = '$nomTableE' + AND isc.COLUMN_NAME = nomLigneAgfodd + OR EXTRA = 'auto_increment' + );"; + $resql=$db->query($sql); + if ($resql) { + while ($row = $db->fetch_array($resql)) { + if ($row["value"] == "NO") { + $list[] = ["nom"=>$row['cm'], "type"=>(new ligneGestion())->getTypeLigne($nomTableA, $row['cm'])];} + } + if (sizeof($list) == 0) return []; + return $list; + } + else return false; + } + + /** + * @param $idTable int|string identifiant de la table + * @return array|false return la liste des paramètres ou faux en cas d'erreur sql + */ + public function getParametreExterne($idTable){ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $list = []; + $idTable = $db->escape($idTable); // pour protéger contre l'injection sql + $sql = "SELECT nomLigneExterne as 'nle', nomLigneAgfodd as 'nla', valeurFixe as 'vf' FROM llx_desal_external_row WHERE tid = $idTable;"; + $resql=$db->query($sql); + if ($resql) { + // Parcours des résultats avec fetch_array + while ($row = $db->fetch_array($resql)) { + if ($row['vf']=="") $list[] = [$row["nla"]=>$row['nle'], "fixe"=>"false"]; + else $list[] = [$row["nla"]=>$row['vf'], "fixe"=>"true"]; + } + } else return false; + return $list; + } + + /** + * @param $liste array liste des liaisons + * @param $tableE string nom de la table à lier + * @param $idTableE int|string identifient de la table à lier + * @param $tableA string nom de la table d'agefodd + * @param $type string type de la clef primaire + * @return string return le nombre d'insertions et le nombre d'erreurs sous format string + */ + public function importerTout(array $liste,string $tableE, $idTableE,string $tableA,string $type):string{ + self::alterTableAvantPremiereInsertion($tableA, $type); + global $db, $langs; + $liste_clef = ""; + $listeValeur = ""; + $lien = ""; + $enrg = 0; + $erreur = 0; + $idSource = ""; + foreach ($liste as $item){ + foreach (array_keys($item) as $clef){ + $clef = $db->escape($clef); + $valeur = $db->escape($item[$clef]); + $liste_clef = $liste_clef .", ".$clef; + $listeValeur = $listeValeur .", '".$valeur."'"; + if ($clef == "id_source") {$idSource = $valeur;} + } + $liste_clef = $liste_clef .", table_source"; + $listeValeur = $listeValeur .", '".$tableE."'"; + $liste_clef = substr($liste_clef, 1); + $listeValeur = substr($listeValeur, 1); + $value = self::importerUneLigne($tableA, $liste_clef, $listeValeur, $idSource, $tableE); + $liste_clef = ""; + $listeValeur = ""; + $lien = ""; + if ($value) $enrg ++; else $erreur ++; + } + return GestionTexte::tronquerParentheses("$enrg ".$langs->trans("AgefoddxImporterTout"), $erreur); + } + + /** + * @param $tableA string nom de la table en d'insertion + * @param $clef string|int nom de la colonne + * @param $valeur string valeur a inséré + * @param string $idSource + * @param string $tableE + * @return bool return si la ligne, c'est inséré + */ + private function importerUneLigne(string $tableA, $clef, string $valeur, string $idSource, string $tableE){ + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $tableA = $db->escape($tableA); // pour protéger contre l'injection sql + $id = $this->estDansLaTable($tableA, $idSource, $tableE); + if ($id) { + $sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE + WHERE TABLE_NAME = '$tableA' AND CONSTRAINT_NAME = 'PRIMARY';"; + $resql=$db->query($sql); + $nomId = $resql->fetch_array()["COLUMN_NAME"]; + $sqlTemp = ["SET FOREIGN_KEY_CHECKS = 0;", + "DELETE FROM $tableA WHERE $nomId = '$id'", + "SET FOREIGN_KEY_CHECKS = 1;"]; + foreach ($sqlTemp as $temp) { $resql=$db->query($temp);} + $sql = "INSERT INTO $tableA ($nomId, $clef) values ('$id', $valeur) "; + } else {$sql = "INSERT INTO $tableA ($clef) values ($valeur) ";} + //WHERE NOT EXISTS (SELECT 1 FROM $tableA WHERE $lien);"; + $resql=$db->query($sql); + if ($resql) return true; + else { + echo "Erreur SQL : " . $db->lasterror().'
'; // affichage des erreurs SQL + return false; + } + } + + /** + * @param string $tableA + * @param string $id_source + * @param string $table_source + * @return string renvoie si un lien est déjà présent dans la table + */ + public function estDansLaTable(string $tableA, string $id_source, string $table_source) : string { + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE + WHERE TABLE_NAME = '$tableA' AND CONSTRAINT_NAME = 'PRIMARY';"; + $resql=$db->query($sql); + $nomId = $resql->fetch_array()["COLUMN_NAME"]; + $sql = "Select $nomId as id FROM $tableA WHERE id_source = '$id_source' AND table_source = '$table_source'"; + $resql=$db->query($sql); + $resql = $resql->fetch_array()["id"]; + if ($resql) return $resql; + else {//echo "Erreur SQL : " . $db->lasterror().'
'; // affichage des erreurs SQL + return false; + } + } + + /** + * @param $nomTableRef string nom de la table + * @param $fk string nom de la clef étrangère + * @return array|false return la liste des valeurs étrangères + */ + public function getTableConversionFK(string $nomTableRef, string $fk) { + global $db; + $list = []; + $db->query("SET NAMES 'utf8mb4'"); + $nomTableRef = $db->escape($nomTableRef); // pour protéger contre l'injection sql + $fk = $db->escape($fk); // pour protéger contre l'injection sql + $sql = "SELECT $fk as fk, id_source FROM $nomTableRef;"; + $resql=$db->query($sql); + if ($resql) { + while ($row = $db->fetch_array($resql)) { + $list[] = [$row["id_source"]=>$row["fk"]]; + } + }else return false; + return $list; + } + + + /** + * @param $tableA string nom de la table d'agefodd + * @param $tableE string nom de la table exterieur + * @return bool return si la suppression, c'est effectuée + */ + public function vider(string $tableA, string $tableE) { + return true; + global $db; + $db->query("SET NAMES 'utf8mb4'"); + $tableA = $db->escape($tableA); // pour protéger contre l'injection sql + $tableE = $db->escape($tableE); // pour protéger contre l'injection sql + $sql = "DELETE FROM $tableA WHERE table_source = '$tableE';"; + $resql=$db->query($sql); + if ($resql) { return true; + } else { return false; } + } +} \ No newline at end of file diff --git a/core/modules/modAgefoddx.class.php b/core/modules/modAgefoddx.class.php new file mode 100644 index 0000000..7a74b6d --- /dev/null +++ b/core/modules/modAgefoddx.class.php @@ -0,0 +1,81 @@ +db = $db; // Chargement de la base de donnée + $langs->load('Agefoddx@Agefoddx'); // Chargement des informations pour la traduction dans template dolibarr + $this->numero = 340002; // numero unique pour l'identification du module + $this->editor_name = "Desal"; // nom du développeur ou de l'équipe de développement + $this->family = "Desal-Tools"; // lieu où le module est retrouvable + $this->name = preg_replace('/^mod/i', '', get_class($this)); // permet de récupérer le nom du module à partir du nom du fichier + $this->description = $langs->trans("AgefoddxDescription"); // description du module, permet une traduction grâce à la fonction traduction + $this->version = 1; // version actuelle du module + $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); // permet instantiation du module entent que module principal + $this->special = 2; // permet d'indiquer la position du module ? + $this->picto = 'Agefoddx.png@Agefoddx'; + $this->module_parts = array ( // permet la gestion et l'execution des triggers et du js + 'hooks'=>array(), + 'js'=>array() + ); + /** Création de répertoire dans la partie documentation **/ + $this->dirs = array(); // Exemple de composent : "/templateDolibarr/temp" + $r = 0; + /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/ + + /** Gestion des dépendances et des modules obligatoires **/ + $this->hidden = false; + $this->depends = array('modAgefodd'); // module obligatoire pour utilisation + $this->requireby = array(); // ne fonctionne plus ? + $this->conflictwith = array(); // liste des modules conflictuelle + $this->phpmin = array(7,0); // version minimum de php demander + $this->need_dolibarr_version = array(19,0,2); // version minimum de dolibarr demander + $this->langfiles = array($this->name.'@'.$this->name); // position du fichier de langue + /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/ + + $this->config_page_url = array("setup.php@".$this->name); // position du fichier de configuration + + $this->const = array(); // liste des constantes pour l'utilisation de ce module + + $tabArray = array(); // permet l'ajout d'onglet dans d'autre élément + $this->tabs = $tabArray; + + $this->boxes = array(); // permet un affichage sur la page d'accueil + $r = 0; + + /** ** ** Gestion des permissions ** ** **/ + $this->rights = array(); + $this->rights_class = $this->name; + $r=0; + + /** ** ** ** ** ** ** ** ** ** ** ** ** **/ + + $this->menus = array(); + global $dolibarr_main_url_root; + } + + /** + * @override + */ + function init($options=''){ + global $conf, $langs; + $result = $this->_load_tables('/Agefoddx/sql/'); + if ($result < 0) { + return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') + } + $this->remove($options); + $sql = array(); + return $this->_init($sql, $options); + } + + /** + * @override + */ + function remove($options=''){ + $sql = array(); + return $this->_remove($sql, $options); + } +} \ No newline at end of file diff --git a/img/.htaccess b/img/.htaccess new file mode 100644 index 0000000..5d14b45 --- /dev/null +++ b/img/.htaccess @@ -0,0 +1 @@ +Require all granted \ No newline at end of file diff --git a/img/object_Agefoddx.png b/img/object_Agefoddx.png new file mode 100644 index 0000000000000000000000000000000000000000..ff11d637d06018d25c7126dfddab1b077e2396d9 GIT binary patch literal 4187 zcmeHK^;gu5)BP;DfJ>Kj2}mOn!b*$4(w$3pcc)0XigYc~DJi+2AW|ZYw6GEaDJHC z27`aBX|LXuMBb{VegMEq^B+K99=D^r=6(NXCjR_&|r<s4fTs(XNLNF0A$vp@u z894gMj@>E-R?>*pU3 z7!({58WtWA85JE9`y%dTd_rPU@+-vaHz{vZ)6z3Cv$At?^YW1e?+S~GOG?YiD=Mq1 zYu?w^)i*RYeQ0iJZENp9b#{IH)ZO#B_e)>@z~Io=;cp|OW8)K(Q`6sPX6NP?7MFf3 zub_XfuB~tU+T7a4{NCB!+y8TL`1k1eQSo9Kh8q$qDu~a9O26ux{=nXfrvb@O@aC z`aAY&>T=KXl}{7F2T!-renYn*SB27HW<6aKXt%nbOS^2~A0>+p3k~d|Ll;mHo%=q=uUz#LC^t?K4NxON+ ztRd4`B^jHXr<-(Wp6gMWccbOitC;ITd%Akho=ckjkEa6@td4Lsxkztg_nAD5Tp&;R zyRJYVOi0_deXAlBKt~vGqOq5QYl76?$pPGZ+@yK~kJUaAJ{{7*3d zj~;AA3~y!2j|2`A*w0b5n7ZsPj&J;=Av!8x4?Cy))f`KrHQ$O*%#{~=$*+<~ z`oxD*)E;Vh5PpjCY}(4`qD78V%U&F$qJd6J@?{$FGlOOBXt!iOfXzIn3QIf>$6eAk zegMRSfZdmFF{GjOl$WZEfHf{N0C&m+4y_5uYbk-DT+m17Qk=`I)=?lhS6V&WOLve8 zH#*1^Hhd&Q^S2*o)l%HJCj1A^J3QcH-UFsh=Fj_aeOe@dUxIIKCf85qQwT~^1MpNX z0#L(&$=TyRT}ijy4fO#CfPDLr`^($BDZS!#NS}IRZgUsAEx<OOvU$u zIp>rs5pV&M*ksQ%&MI%XEX?l- zuu}g9oaVr!QB(?-MDD=h@P0-{1IJYS;Izz;gs^|}{`c83L5Hxa)<+`y=%5^9)$3|P zR^>j`gP_;sMe}aweYSJShlKm_Fk0W!wLC`lY36ynh2 zAhEJseLkQFBZJQxYQdAaw-Y9FQTk@!pm*T;^GD z1BMKIAd$pH{xcn-XnIGW!LWBiaChJ^R)6R2iia8kqH5CyAHqwSh(>uwG^&phx-(VB z_-MZ{hHrw!y-tX0Vsi5YKZj#ZY}AV!)0^6{Q)&o4mN!=EPfwt`? z)g>J5AkUrjEDjK>#dY?y^)dp`{PkkigRwa#8LMJ=tc0wlg|l#7n&&<_@+4Lowvq~; zzQ9%SYj{lj;qA8Cs{-j})U)q9vW~x}!WAM7^4H6GT9u|F&&mlXT#b-E&KqgfrS1Yz z)1^E70TIWtZ5xhp11!V5G$@67^}H&<(&zT8L2HC!V(;ttqO8oW&-%7^yhdH{H^YXK za_EZ4!xua4J)TOI(TNZDkM8)9CA=;QbAbnZ4ELxGS6t~8vlGIO!5>S?d9;RUZ$a!Z zyslm*Qso4s$L&@(?^h!PIjQO+uhwr-uVr!ViM-V|X#7qz1qoB~elgP1wt8qUAFv-+ zbV@^ZY-&fWRXi&C*30Tefay$w@E8`~Jp9k(M>HW4B+=HC@*2&6lqycgqyWHj%rlNz z_$#0)n1;t@u8U59pjP~&rGLhnT_n? zdvVeUur>7-+UYo16ZwmZSG9Pv_mLu=a!EIcHSR+y-2q${J7Es5Hwd0b#E5RLCUcw_ zn#XPOoRsH^yAxxNGeGhrZxM4`E?k7mL*ee4Ziw3YRIQ6sw%=lk+lkzz&L`(A9GJMJ zXf0ihxyf6Ofw2){R(4Cz+HM{0xJztv@3`yNmHC8PB%buCoy3qt^^AE;h4E09O!K(g z9!|UfCyP@mL$NGEB<;`Yq8d`JXgBwtrjA#)79`(#fa9Sb6oc3nWGJM|;UwunylfMd zk5ww!i2SIc91+zSCB1eof1Zll#klJ-Szzc<<=s@*hvGr*BYZ404|in)GcXh`+S30F znLsYJS7zkgMN(tMWC+3nC7XuqH9HOFY}sh+LBCm%(fHoTmj`Z_FibI16P-~UdM3yM z89!}G*is^ym?SY!LKuC_h#FBkR$mD-# zZ@)DQrmZUGb7*yqiPQV!;v{{G^{Ioz%xE7aQ(`a0?Jx_G<+J%1Cn29Zf zXf+E8tb;3kL2&#u;~KRdebx&%i)Ez7C4wxv1q4FX2gLgVjXZ{Z>N~m<{rgpCM2EqY zVMh;2L(q+1Sg#rRCMXxmx7IqRX~MRJd;4VQF0Av(N&|C1J1N84wC@6X{bhAX4y1>l z!ybp$B^1U}+X@8n@>Tr$)%nXfR)JELq-LE^?~Cb(!mJpoN81(m0ZLzsqjlA3lA%7{ zddu1^=fqF@k5~FXkW72wWc%h!q7Pd=4F}#RuhGY~&`d-IT`%XY0Lp&mikclOk=q`{ zzza!Djhy_tc4oenh9@gf0yQVx8>yRsnL&{yrO`ja%>6M?YL_*CRJRA{YPY)ak~)-t zqSTgwRJwuX#VU_XoTqiHGEsqb|JU4#V!A)ix=AInDC8f}%PJ}I@KlvxoIC#6LaA4R zeewi?ey6W#Wzp|{!&%9imM}%KGu1Ek!BzCWc@d`5Ih6<@6$n+*_V3A6{#N<9AQtoG z)w}*qj2Z}#es_N1duoK<@g=-$yDQO^u(V*v<* z*&BQ@TV2A6?XVAKVsyAD51^+IE`h}7R#TP@xoT3^16 zykV9KDG&a$^6hmzt$4)flPc*48GN7E5%&WM#tby^BD6ikI%>m|z=b+GfPqbFt@r$Xu2h9%E. + */ + +/** + * \file temp/lib/temp.lib.php + * \ingroup temp + * \brief Library files with common functions for Temp + */ + +/** + * Prepare admin pages header + * + * @return array + */ +function AgefoddxAdminPrepareHead() { + global $langs, $conf; + + // global $db; + // $extrafields = new ExtraFields($db); + // $extrafields->fetch_name_optionals_label('myobject'); + + $langs->load("Agefoddx@Agefoddx"); + + $h = 0; + $head = array(); + + $head[$h][0] = dol_buildpath("/Agefoddx/admin/setup.php", 1); + $head[$h][1] = $langs->trans("Settings"); + $head[$h][2] = 'settings'; + $h++; + + /* + $head[$h][0] = dol_buildpath("/temp/admin/myobject_extrafields.php", 1); + $head[$h][1] = $langs->trans("ExtraFields"); + $nbExtrafields = is_countable($extrafields->attributes['myobject']['label']) ? count($extrafields->attributes['myobject']['label']) : 0; + if ($nbExtrafields > 0) { + $head[$h][1] .= ' ' . $nbExtrafields . ''; + } + $head[$h][2] = 'myobject_extrafields'; + $h++; + */ + + $head[$h][0] = dol_buildpath("/Agefoddx/admin/about.php", 1); + $head[$h][1] = $langs->trans("About"); + $head[$h][2] = 'about'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + //$this->tabs = array( + // 'entity:+tabname:Title:@temp:/temp/mypage.php?id=__ID__' + //); // to add new tab + //$this->tabs = array( + // 'entity:-tabname:Title:@temp:/temp/mypage.php?id=__ID__' + //); // to remove a tab + complete_head_from_modules($conf, $langs, null, $head, $h, 'Agefoddx@Agefoddx'); + + complete_head_from_modules($conf, $langs, null, $head, $h, 'Agefoddx@Agefoddx', 'remove'); + + return $head; +} diff --git a/lib/Psr4AutoloaderClass.php b/lib/Psr4AutoloaderClass.php new file mode 100644 index 0000000..41fa05a --- /dev/null +++ b/lib/Psr4AutoloaderClass.php @@ -0,0 +1,213 @@ +register(); + * + * // register the base directories for the namespace prefix + * $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/src'); + * $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/tests'); + * + * The following line would cause the autoloader to attempt to load the + * \Foo\Bar\Qux\Quux classe from /path/to/packages/foo-bar/src/Qux/Quux.php: + * + * debug = $debug; + } + + private function affichageDebogage(string $message) : void + { + if ($this->debug) + echo $message; + } + + /** + * An associative array where the key is a namespace prefix and the value + * is an array of base directories for classes in that namespace. + * + * @var array + */ + protected array $prefixes = array(); + + /** + * Register loader with SPL autoloader stack. + * + * @return void + */ + public function register() : void + { + spl_autoload_register(array($this, 'loadClass')); + } + + /** + * Adds a base directory for a namespace prefix. + * + * @param string $prefix The namespace prefix. + * @param string $base_dir A base directory for classe files in the + * namespace. + * @param bool $prepend If true, prepend the base directory to the stack + * instead of appending it; this causes it to be searched first rather + * than last. + * @return void + */ + public function addNamespace(string $prefix, string $base_dir, bool $prepend = false) : void + { + // normalize namespace prefix + $prefix = trim($prefix, '\\') . '\\'; + + // normalize the base directory with a trailing separator + $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; + + // initialize the namespace prefix array + if (isset($this->prefixes[$prefix]) === false) { + $this->prefixes[$prefix] = array(); + } + + // retain the base directory for the namespace prefix + if ($prepend) { + array_unshift($this->prefixes[$prefix], $base_dir); + } else { + array_push($this->prefixes[$prefix], $base_dir); + } + } + + /** + * Loads the classe file for a given classe name. + * + * @param string $class The fully-qualified classe name. + * @return mixed The mapped file name on success, or boolean false on + * failure. + */ + public function loadClass(string $class) + { + $this->affichageDebogage("

Chargement automatique de classe $class

"); + // the current namespace prefix + $prefix = $class; + + // work backwards through the namespace names of the fully-qualified + // classe name to find a mapped file name + while (false !== $pos = strrpos($prefix, '\\')) { + + // retain the trailing namespace separator in the prefix + $prefix = substr($class, 0, $pos + 1); + + // the rest is the relative classe name + $relative_class = substr($class, $pos + 1); + + // try to load a mapped file for the prefix and relative classe + $mapped_file = $this->loadMappedFile($prefix, $relative_class); + if ($mapped_file) { + return $mapped_file; + } + + // remove the trailing namespace separator for the next iteration + // of strrpos() + $prefix = rtrim($prefix, '\\'); + } + + // never found a mapped file + $this->affichageDebogage("

Échec !

"); + return false; + } + + /** + * Load the mapped file for a namespace prefix and relative classe. + * + * @param string $prefix The namespace prefix. + * @param string $relative_class The relative classe name. + * @return mixed Boolean false if no mapped file can be loaded, or the + * name of the mapped file that was loaded. + */ + protected function loadMappedFile(string $prefix, string $relative_class) + { + // are there any base directories for this namespace prefix? + if (isset($this->prefixes[$prefix]) === false) { + return false; + } + + // look through base directories for this namespace prefix + foreach ($this->prefixes[$prefix] as $base_dir) { + + $this->affichageDebogage("Remplacement du préfixe $prefix par $base_dir
"); + + // replace the namespace prefix with the base directory, + // replace namespace separators with directory separators + // in the relative classe name, append with .php + $file = $base_dir + . str_replace('\\', '/', $relative_class) + . '.php'; + + // if the mapped file exists, require it + if ($this->requireFile($file)) { + // yes, we're done + return $file; + } + } + + // never found it + return false; + } + + /** + * If a file exists, require it from the file system. + * + * @param string $file The file to require. + * @return bool True if the file exists, false if not. + */ + protected function requireFile(string $file) : bool + { + if (file_exists($file)) { + $this->affichageDebogage("

Réussite : fichier chargé

$file

"); + require $file; + return true; + } + $this->affichageDebogage("

Échec : fichier introuvable

$file

"); + return false; + } +} \ No newline at end of file diff --git a/sql/.htaccess b/sql/.htaccess new file mode 100644 index 0000000..a7a56f7 --- /dev/null +++ b/sql/.htaccess @@ -0,0 +1 @@ +Require all denied \ No newline at end of file diff --git a/sql/llx_desal_external_bd.sql b/sql/llx_desal_external_bd.sql new file mode 100644 index 0000000..1c65c48 --- /dev/null +++ b/sql/llx_desal_external_bd.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS llx_desal_external_bd ( + bdid int NOT NULL auto_increment PRIMARY KEY, + nom varchar(64) NOT NULL, + lien varchar(256) NOT NULL, + user varchar(64) NOT NULL, + port int NOT NULL +); diff --git a/sql/llx_desal_external_row.key.sql b/sql/llx_desal_external_row.key.sql new file mode 100644 index 0000000..03ddc92 --- /dev/null +++ b/sql/llx_desal_external_row.key.sql @@ -0,0 +1,2 @@ +ALTER TABLE llx_desal_external_row ADD CONSTRAINT llx_fx_desal_ex_row_table FOREIGN KEY (tid) REFERENCES llx_desal_external_table (tid); +ALTER TABLE llx_desal_external_row ADD CONSTRAINT llx_fx_desal_ex_row_bd FOREIGN KEY (bdid) REFERENCES llx_desal_external_bd (bdid); diff --git a/sql/llx_desal_external_row.sql b/sql/llx_desal_external_row.sql new file mode 100644 index 0000000..cb55e95 --- /dev/null +++ b/sql/llx_desal_external_row.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS llx_desal_external_row ( + rid integer NOT NULL auto_increment PRIMARY KEY, + bdid integer NOT NULL, + tid integer NOT NULL, + nomLigneExterne varchar(64), + nomLigneAgfodd varchar(64) NOT NULL, + valeurFixe varchar(500) +); + diff --git a/sql/llx_desal_external_table.key.sql b/sql/llx_desal_external_table.key.sql new file mode 100644 index 0000000..dca4813 --- /dev/null +++ b/sql/llx_desal_external_table.key.sql @@ -0,0 +1 @@ +ALTER TABLE llx_desal_external_table ADD CONSTRAINT llx_fx_desal_ex_table_bd FOREIGN KEY (bdid) REFERENCES llx_desal_external_bd (bdid); \ No newline at end of file diff --git a/sql/llx_desal_external_table.sql b/sql/llx_desal_external_table.sql new file mode 100644 index 0000000..314efbd --- /dev/null +++ b/sql/llx_desal_external_table.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS llx_desal_external_table ( + tid integer NOT NULL auto_increment PRIMARY KEY, + bdid integer NOT NULL, + nomTableExterne varchar(64) NOT NULL, + nomTableAgfodd varchar(64) NOT NULL +); diff --git a/view/.htaccess b/view/.htaccess new file mode 100644 index 0000000..a7a56f7 --- /dev/null +++ b/view/.htaccess @@ -0,0 +1 @@ +Require all denied \ No newline at end of file diff --git a/view/erreur.php b/view/erreur.php new file mode 100644 index 0000000..2e8baac --- /dev/null +++ b/view/erreur.php @@ -0,0 +1,9 @@ + +
+ + +
+
+ diff --git a/view/gestionBD/afficherListe.php b/view/gestionBD/afficherListe.php new file mode 100644 index 0000000..483b851 --- /dev/null +++ b/view/gestionBD/afficherListe.php @@ -0,0 +1,62 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); + +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ if (!isset($titre)){ $titre = "Agefoddx"; } +?> + + + + + + + + + + +
+ trans("AgefoddxListeBD")?> +
+

+
+ + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + +
trans("AgefoddxIdBD") ?>trans("AgefoddxNomBD") ?>trans("AgefoddxListeTable") ?>trans("AgefoddxParametresBD") ?>
', nomBD:''}, 'setup.php', '')"> + trans("AgefoddxAfficherListeTable") ?> + ', nomBD:''}, 'setup.php', '')"> + trans("AgefoddxModifierBD") ?> + ', nomBD:''}, 'setup.php', '')"> + trans("AgefoddxSupprimerBD") ?> +
+
+ + diff --git a/view/gestionBD/ajouter.php b/view/gestionBD/ajouter.php new file mode 100644 index 0000000..104939c --- /dev/null +++ b/view/gestionBD/ajouter.php @@ -0,0 +1,88 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); + +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ +if (!isset($titre)){ + $titre = "Agefoddx"; +} + +?> + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + trans("AgefoddxAjoutBD")?> +
+

+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ " /> +
+

* trans("AgefoddxMentionMDP")?>

+
diff --git a/view/gestionBD/modifier.php b/view/gestionBD/modifier.php new file mode 100644 index 0000000..1201df6 --- /dev/null +++ b/view/gestionBD/modifier.php @@ -0,0 +1,100 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); + +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ +/** @var $nomBD */ +/** @var array $liste */ + +if (!isset($titre)){ + $titre = "Agefoddx"; +} + +?> + + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + trans("AgefoddxModifierBD")?> +
+

+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + " AUTOCOMPLETE="OFF" readonly> +
+ + + " AUTOCOMPLETE="OFF"> +
+ + + " AUTOCOMPLETE="OFF"> +
+ + + " AUTOCOMPLETE="OFF"> +
+ + + " AUTOCOMPLETE="OFF"> +
+ + + +
+ " /> +
+

* trans("AgefoddxMentionMDP")?>

+
+
diff --git a/view/gestionBD/supprimer.php b/view/gestionBD/supprimer.php new file mode 100644 index 0000000..233f644 --- /dev/null +++ b/view/gestionBD/supprimer.php @@ -0,0 +1,63 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); + +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ +/** @var $idBD */ +/** @var $nomBD */ +if (!isset($titre)){ + $titre = "Agefoddx"; +} +?> + + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + trans("AgefoddxSupprimer")?> +
+

+
+ +
+
+ + + + + +
+ + + + + + + + + + + +
+ trans("AgefoddxTexteDeSuppression")?> Agefodd trans("AgefoddxEt")?> ? +
+ + + + + +
+ +
+
+
\ No newline at end of file diff --git a/view/gestionLigne/afficherListe.php b/view/gestionLigne/afficherListe.php new file mode 100644 index 0000000..ad1b224 --- /dev/null +++ b/view/gestionLigne/afficherListe.php @@ -0,0 +1,65 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); +require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ /** @var $liste */ + +/** @var $idBD */ /** @var $nomBD */ /** @var $mdp */ + +/** @var $idTable */ /** @var $nomTableA */ /** @var $nomTableE */ + + +if (!isset($titre)) { + $titre = "Agefoddx"; +} + +?> + + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + \ + trans("AgefoddxListeLigne")?> +
+

+
+ + + +
+
+ + + + + + + + + + + + + + + + + + + +
trans("AgefoddxIdLigne") ?>trans("AgefoddxNomLigneExterne"). " " . $nomTableE?>trans("AgefoddxNomLigneAgefodd"). " " . $nomTableA?>trans("AgefoddxParametresLigne") ?>
trans("AgefoddxValeurFixeItem"))?>', nomBD:'', nomTableA:'', nomTableE:'', nomLigneE:'',nomLigneA:'', mdp:''}, 'setup.php', '')"> + trans("AgefoddxSupprimerLigne") ?> +
+
\ No newline at end of file diff --git a/view/gestionLigne/ajouter.php b/view/gestionLigne/ajouter.php new file mode 100644 index 0000000..5b6675c --- /dev/null +++ b/view/gestionLigne/ajouter.php @@ -0,0 +1,144 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); +require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ /** @var $listeA */ /** @var $listeE */ /** @var $listeAFK */ /** @var $listeEFK */ + +/** @var $idBD */ /** @var $nomBD */ /** @var $mdp */ + +/** @var $idTable */ /** @var $nomTableA */ /** @var $nomTableE */ +/** @var $valeurBase */ +$tabActif = $tab ?? $_POST['tab']; + +$tab1Css = ""; $tab1CssDiv = "tabunactive"; $tab1Lien = ""; +$tab2Css = ""; $tab2CssDiv = "tabunactive"; $tab2Lien = ""; +$tab3Css = ""; $tab3CssDiv = "tabunactive"; $tab3Lien = ""; +if ($tabActif == "tab1") { $titreSection = $langs->trans("AgefoddxLigne")." ".$nomBD; $tab1Css = "tabsElemActive"; $tab1CssDiv = "tabactive"; $tab1Lien = ""; $input = ''; +} else if ($tabActif == "tab2") { $titreSection = $langs->trans("AgefoddxValeurFixe"); $tab2Css = "tabsElemActive"; $tab2CssDiv = "tabactive"; $tab2Lien = ""; $input = ''; +} else if ($tabActif == "tab3") { $titreSection = $langs->trans("AgefoddxLienFK"); $tab3Css = "tabsElemActive"; $tab3CssDiv = "tabactive"; $tab3Lien = ""; $input = '';} + +if (!isset($titre)) $titre = "Agefoddx"; + +?> + + + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + \ + trans("AgefoddxListeLigne")?>\ + trans("AgefoddxAjouter")?> +
+

+
+ +
+
+ +
+
+ + trans("AgefoddxAjoutLienValFixe")?> + +
+
+
+
+ + trans("AgefoddxAjoutLienFK")?> + +
+
+
+ + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
trans("AgefoddxLigne")?> Agefodd
+ + + + + + + + + + + + + + " required> + + + + +
+ " /> +
+
+
diff --git a/view/gestionLigne/supprimer.php b/view/gestionLigne/supprimer.php new file mode 100644 index 0000000..e3a01d8 --- /dev/null +++ b/view/gestionLigne/supprimer.php @@ -0,0 +1,71 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); +require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ /** @var $nomLigneE */ /** @var $nomLigneA */ /** @var $idLigne */ + +/** @var $idBD */ /** @var $nomBD */ /** @var $mdp */ + +/** @var $idTable */ /** @var $nomTableA */ /** @var $nomTableE */ + +if (!isset($titre)) $titre = "Agefoddx"; + +?> + + + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + \ + trans("AgefoddxListeLigne")?>\ + trans("AgefoddxSupprimer")?> +
+

+
+
+
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ trans("AgefoddxTexteDeSuppression")?> trans("AgefoddxEt")?> ? +
+ + + + + +
+ +
+
+
\ No newline at end of file diff --git a/view/gestionLigne/transition.php b/view/gestionLigne/transition.php new file mode 100644 index 0000000..d6f780b --- /dev/null +++ b/view/gestionLigne/transition.php @@ -0,0 +1,69 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); +require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ /** @var $actionApres */ /** @var $titreAction */ + +/** @var $idBD */ /** @var $nomBD */ /** @var $mdp */ + +/** @var $idTable */ /** @var $nomTableA */ /** @var $nomTableE */ +/** @var $valeurBase */ + + +if (!isset($titre)) { + $titre = "Agefoddx"; +} + +?> + + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + \ + trans("AgefoddxListeLigne")?>\ + + +
+

+
+ +
+
+ + + + + + + + + + + + + + + + + + + +
+ + + +
+ " /> +
+
diff --git a/view/gestionTable/afficherListe.php b/view/gestionTable/afficherListe.php new file mode 100644 index 0000000..5c933ee --- /dev/null +++ b/view/gestionTable/afficherListe.php @@ -0,0 +1,70 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); + +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ +/** @var $nomBD */ /** @var $idBD */ /** @var $mdp */ +/** @var array $liste*/ + + +if (!isset($titre)){ + $titre = "Agefoddx"; +} + +?> + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + +
+

+
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
trans("AgefoddxIdTable") ?>trans("AgefoddxNomTableExterne") ?>trans("AgefoddxNomTableAgefodd") ?>trans("AgefoddxListeLigne") ?>trans("AgefoddxNBLigneTable") ?>trans("AgefoddxParametresTable") ?>
', idBD:'', nomBD:'', mdp:''}, 'setup.php', '')"> + trans("AgefoddxAfficherListeLigne") ?> + ', idBD:'', nomBD:'', mdp:'', nomTableA:'', nomTableE:''}, 'setup.php', '')"> + trans("AgefoddxImporterTable") ?> + ', idBD:'', nomBD:'', mdp:'', nomTableA:'', nomTableE:''}, 'setup.php', '')"> + trans("AgefoddxSupprimerTable") ?> +
+
\ No newline at end of file diff --git a/view/gestionTable/ajouter.php b/view/gestionTable/ajouter.php new file mode 100644 index 0000000..c288981 --- /dev/null +++ b/view/gestionTable/ajouter.php @@ -0,0 +1,80 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ +/** @var $nomBD */ +/** @var $idBD */ +/** @var $mdp */ +/** @var $listeAgefodd */ +/** @var $listeBdExterne */ +/** @var bdExterneInteraction $bdConnection */ + +if (!isset($titre)){ + $titre = "Agefoddx"; +} + +?> + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + \ + trans("AgefoddxAjouterTable")?> +
+

+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + +
trans("AgefoddxTable")?> Agefoddtrans("AgefoddxTable")?>
+ + + +
+ " /> +
+
\ No newline at end of file diff --git a/view/gestionTable/importer.php b/view/gestionTable/importer.php new file mode 100644 index 0000000..ae80041 --- /dev/null +++ b/view/gestionTable/importer.php @@ -0,0 +1,96 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); +require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ +/** @var $nomBD */ +/** @var $idBD */ +/** @var $valueImportation */ +/** @var $liste */ +/** @var $idTable */ /** @var $mdp */ +/** @var $nomTableA */ /** @var $nomTableE */ + +if (!isset($titre)) { + $titre = "Agefoddx"; +} + +/** Doit pouvoir réaliser divers importations si et seulement si touts les champs non null sont définis **/ +?> + + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + \ + trans("AgefoddxImporter")?> +
+

+
+
+ + + + +
+

trans("AgefoddxCLOAI")?>

+ + + + + + + + + + + + + + + + + +
+ trans("AgefoddxNom")?> + + trans("AgefoddxType")?> + + trans("AgefoddxAjouter")?> +
+ + + + + ', mdp:''}, 'setup.php', '')"> + trans("Agefoddxajouter")?> + +
+
+ + + + + diff --git a/view/gestionTable/supprimer.php b/view/gestionTable/supprimer.php new file mode 100644 index 0000000..2c741b0 --- /dev/null +++ b/view/gestionTable/supprimer.php @@ -0,0 +1,68 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); + +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +/** @var $titre */ +/** @var $nomBD */ /** @var $idBD */ /** @var $idTable */ +/** @var $nomTableA */ /** @var $nomTableE */ +if (!isset($titre)){ + $titre = "Agefoddx"; +} + +?> + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + \ + trans("AgefoddxSupprimer")?> + +
+

+
+
+
+ + + + + + + + + +
+ + + + + + + + + + + +
+ trans("AgefoddxTexteDeSuppression")?> trans("AgefoddxEt")?> ? +
+ + + + + +
+ +
+
+
\ No newline at end of file diff --git a/view/gestionTable/transition.php b/view/gestionTable/transition.php new file mode 100644 index 0000000..b8f57da --- /dev/null +++ b/view/gestionTable/transition.php @@ -0,0 +1,61 @@ +loadLangs(array("admin", "Agefoddx@Agefoddx")); +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; +$form = new Form($db); +$csrfToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; +?> + + + + + + + + + +
+ trans("AgefoddxListeBD")?>\ + \ + +
+

+
+ +
+
+ + + + + + + + + + + + + + + + + + +
+ + + +
+ " /> +
+
diff --git a/view/vueGenerale.php b/view/vueGenerale.php new file mode 100644 index 0000000..254b54a --- /dev/null +++ b/view/vueGenerale.php @@ -0,0 +1,18 @@ +"; + +/** @var $message */ +/** @var $popup */ + + if ($message != "") { + echo "

$message

"; + } else if ($popup != "") { + echo ''; + } if (isset($cheminCorpsVue)){ + require __DIR__ . "/{$cheminCorpsVue}"; + } +echo ""; +?> \ No newline at end of file