149 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Modèle d'accès à la base de données des listes
|
|
|
5 |
* d'ontologies
|
|
|
6 |
*
|
|
|
7 |
* PHP Version 5
|
|
|
8 |
*
|
|
|
9 |
* @package Framework
|
|
|
10 |
* @category Class
|
|
|
11 |
* @author aurelien <aurelien@tela-botanica.org>
|
|
|
12 |
* @copyright 2009 Tela-Botanica
|
|
|
13 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
14 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
|
|
15 |
* @version SVN: $$Id: ListeAdmin.php 128 2009-09-02 12:20:55Z aurelien $$
|
|
|
16 |
* @link /doc/framework/
|
|
|
17 |
*
|
|
|
18 |
*/
|
|
|
19 |
class GestionAnnuaireModele extends Modele {
|
|
|
20 |
|
|
|
21 |
public function verifierPresenceTable($bdd, $nom_table) {
|
|
|
22 |
|
|
|
23 |
if(!$bdd || !$nom_table) {
|
|
|
24 |
return false;
|
|
|
25 |
}
|
162 |
aurelien |
26 |
|
167 |
aurelien |
27 |
$requete_presence_table = 'SELECT * FROM information_schema.tables
|
|
|
28 |
WHERE TABLE_SCHEMA = '.$this->proteger($bdd).' AND TABLE_NAME = '.$this->proteger($nom_table);
|
162 |
aurelien |
29 |
|
167 |
aurelien |
30 |
$presence_table = $this->requeteUn($requete_presence_table);
|
149 |
aurelien |
31 |
|
167 |
aurelien |
32 |
return $presence_table;
|
149 |
aurelien |
33 |
}
|
|
|
34 |
|
|
|
35 |
public function verifierPresenceChamps($bdd, $nom_table, $champs_a_verifier) {
|
|
|
36 |
|
162 |
aurelien |
37 |
$tableau_champs_table = $this->obtenirListeNomsChampsAnnuaireParBddNomTable($bdd, $nom_table);
|
|
|
38 |
|
|
|
39 |
foreach($champs_a_verifier as $champ) {
|
|
|
40 |
if(!in_array($champ, $tableau_champs_table)) {
|
|
|
41 |
return false;
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
return $resultat;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public function obtenirListeNomsChampsAnnuaireParBddNomTable($bdd, $nom_table) {
|
|
|
49 |
|
149 |
aurelien |
50 |
if(!$bdd || !$nom_table) {
|
|
|
51 |
return false;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
$requete = 'DESCRIBE '.$bdd.'.'.$nom_table;
|
|
|
55 |
|
|
|
56 |
$resultat = $this->requeteTous($requete);
|
|
|
57 |
|
|
|
58 |
if(!$resultat) {
|
|
|
59 |
return false;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
$tableau_champs_table = array();;
|
|
|
63 |
|
|
|
64 |
foreach($resultat as $champ_table) {
|
|
|
65 |
$tableau_champs_table[] = $champ_table['Field'];
|
|
|
66 |
}
|
|
|
67 |
|
162 |
aurelien |
68 |
return $tableau_champs_table;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public function obtenirListeNomsChampsAnnuaireParIdAnnuaire($id_annuaire) {
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
$requete_selection_bdd_table = 'SELECT aa_bdd, aa_table FROM annu_annuaire '.
|
|
|
75 |
' WHERE aa_id_annuaire = '.$this->proteger($id_annuaire);
|
|
|
76 |
|
|
|
77 |
$resultat_selection_bdd_table = $this->requeteUn($requete_selection_bdd_table);
|
|
|
78 |
|
|
|
79 |
if(!$resultat_selection_bdd_table) {
|
|
|
80 |
return array();
|
149 |
aurelien |
81 |
}
|
|
|
82 |
|
162 |
aurelien |
83 |
return $this->obtenirListeNomsChampsAnnuaireParBddNomTable($resultat_selection_bdd_table['aa_bdd'], $resultat_selection_bdd_table['aa_table']);
|
149 |
aurelien |
84 |
}
|
|
|
85 |
|
|
|
86 |
public function ajouterAnnuaire($informations) {
|
|
|
87 |
|
|
|
88 |
if(!$informations) {
|
|
|
89 |
return false;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
$valeurs_prot = array_map(array($this,'proteger'),$informations);
|
|
|
93 |
|
|
|
94 |
$valeurs = implode(',',$valeurs_prot);
|
|
|
95 |
$champs = implode(',',array_keys($informations));
|
|
|
96 |
|
|
|
97 |
$requete_insertion_annuaire = 'INSERT INTO annu_annuaire '.
|
|
|
98 |
'('.$champs.') '.
|
|
|
99 |
'VALUES ('.$valeurs.')';
|
|
|
100 |
|
|
|
101 |
$resultat_insertion_annuaire = $this->requete($requete_insertion_annuaire);
|
|
|
102 |
|
|
|
103 |
$id_annuaire = false;
|
|
|
104 |
|
|
|
105 |
if($resultat_insertion_annuaire) {
|
|
|
106 |
|
|
|
107 |
$requete_selection_annuaire = 'SELECT aa_id_annuaire FROM annu_annuaire '.
|
|
|
108 |
' WHERE aa_code = '.$this->proteger($informations['aa_code']);
|
|
|
109 |
|
|
|
110 |
$resultat_selection_annuaire = $this->requeteUn($requete_selection_annuaire);
|
|
|
111 |
|
|
|
112 |
if($resultat_selection_annuaire) {
|
|
|
113 |
$id_annuaire = $resultat_selection_annuaire['aa_id_annuaire'];
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
return $id_annuaire;
|
|
|
118 |
}
|
|
|
119 |
|
162 |
aurelien |
120 |
public function creerTableAnnuaire($informations_table, $informations_champs) {
|
167 |
aurelien |
121 |
|
|
|
122 |
$nom_bdd = $informations_table['aa_bdd'];
|
|
|
123 |
$nom_table = $informations_table['aa_table'];
|
162 |
aurelien |
124 |
|
167 |
aurelien |
125 |
$champ_id = $informations_champs['aa_champ_id'];
|
|
|
126 |
$champ_nom = $informations_champs['aa_champ_nom'];
|
|
|
127 |
$champ_mail = $informations_champs['aa_champ_mail'];
|
|
|
128 |
$champ_mot_de_passe = $informations_champs['aa_champ_pass'];
|
162 |
aurelien |
129 |
|
167 |
aurelien |
130 |
$requete_creation_table = 'CREATE TABLE '.$nom_bdd.'.'.$nom_table.' '.
|
162 |
aurelien |
131 |
'('.$champ_id.' INT NOT NULL AUTO_INCREMENT PRIMARY KEY,'.
|
167 |
aurelien |
132 |
$champ_nom.' VARCHAR(255) NOT NULL, '.
|
|
|
133 |
$champ_mail.' VARCHAR(255) NOT NULL, '.
|
|
|
134 |
$champ_mot_de_passe.' VARCHAR(255) NOT NULL)';
|
162 |
aurelien |
135 |
|
|
|
136 |
return $this->requete($requete_creation_table);
|
|
|
137 |
|
|
|
138 |
}
|
|
|
139 |
|
149 |
aurelien |
140 |
/**
|
|
|
141 |
* Charge la liste complète des champs d'un annuaire
|
|
|
142 |
* @param int $identifiant l'identifiant de l'annuaire demandé
|
|
|
143 |
* @param boolean $charger_liste_champs indique si l'on doit ou non charger la liste des noms des champs
|
|
|
144 |
* @return array un tableau contenant des objets d'informations sur les annuaires
|
|
|
145 |
*/
|
|
|
146 |
public function chargerAnnuaire($identifiant, $charger_liste_champs = true) {
|
|
|
147 |
|
|
|
148 |
$requete = 'SELECT * '.
|
|
|
149 |
'FROM annu_annuaire '.
|
|
|
150 |
'WHERE aa_id_annuaire = '.$identifiant.' ';
|
|
|
151 |
$resultat = $this->requeteTous($requete);
|
|
|
152 |
$annuaire = array();
|
|
|
153 |
foreach ($resultat as $ligne) {
|
|
|
154 |
$annuaire['informations'] = $ligne;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
if($charger_liste_champs) {
|
|
|
158 |
$requete = 'DESCRIBE '.$annuaire['informations']['aa_bdd'].'.'.$annuaire['informations']['aa_table'];
|
|
|
159 |
$resultat = $this->requeteTous($requete);
|
|
|
160 |
foreach ($resultat as $colonne) {
|
|
|
161 |
$annuaire['colonnes'][] = $colonne;
|
|
|
162 |
}
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
return $annuaire;
|
|
|
166 |
}
|
|
|
167 |
}
|