119 lines
5.5 KiB
PHP
119 lines
5.5 KiB
PHP
<?php
|
|
namespace Module\Agefoddx\Classe\Controleur;
|
|
use Exception;
|
|
use Module\Agefoddx\Classe\Classe\GestionTexte;
|
|
use Module\Agefoddx\Classe\GestionBD\bdGestion;
|
|
use Module\Agefoddx\Classe\GestionBD\bdExterneInteraction;
|
|
|
|
class ControleurBd extends ControleurGenerique {
|
|
/**
|
|
* @var string $lien represent le chemin relatif vers la vue
|
|
*/
|
|
protected static string $lien = "../view/gestionBD";
|
|
|
|
/**
|
|
* @param $message string message passable en parameter pour les interactions utilisateur
|
|
* @return void affiche la liste des bds
|
|
*/
|
|
public static function afficherListe(string $message = "") {
|
|
global $langs;
|
|
$liste = (new bdGestion())->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) );
|
|
}
|
|
} |