Subversion Repositories Applications.referentiel

Rev

Rev 267 | Rev 273 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 267 Rev 269
1
<?php
1
<?php
2
// Encodage : UTF-8
2
// Encodage : UTF-8
3
// +-------------------------------------------------------------------------------------------------------------------+
3
// +-------------------------------------------------------------------------------------------------------------------+
4
/**
4
/**
5
* Importation d'un fichier ref-tax dans une bdnt
5
* Importation d'un fichier ref-tax dans une bdnt
6
*
6
*
7
* Description : classe permettant de versionner les référentiels selon le manuel technique
7
* Description : classe permettant de versionner les référentiels selon le manuel technique
8
* Utilisation : php script.php comparaison -r bdnff -a tout -f fichier.txt
8
* Utilisation : php script.php comparaison -r bdnff -a tout -f fichier.txt
9
*
9
*
10
//Auteur original :
10
//Auteur original :
11
* @author       Jean-Pascal MILCENT <jpm@tela-botanica.org>
11
* @author       Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
* @copyright	Tela-Botanica 1999-2010
12
* @copyright	Tela-Botanica 1999-2010
13
* @link			http://www.tela-botanica.org/wikini/RTaxMethodo/wakka.php?wiki=MaNuel
13
* @link			http://www.tela-botanica.org/wikini/RTaxMethodo/wakka.php?wiki=MaNuel
14
* @licence		GPL v3 & CeCILL v2
14
* @licence		GPL v3 & CeCILL v2
15
* @version		$Id$
15
* @version		$Id$
16
*/
16
*/
17
// +-------------------------------------------------------------------------------------------------------------------+
17
// +-------------------------------------------------------------------------------------------------------------------+
18
class Importation extends ScriptCommande {
18
class Importation extends ScriptCommande {
19
	
19
	
20
	const SCRIPT_NOM = 'importation';
20
	const SCRIPT_NOM = 'importation';
21
	const MANUEL_VERSION = '4.3';
21
	const MANUEL_VERSION = '4.3';
22
	
22
	
23
	private $referentiel = null;
23
	private $referentiel = null;
24
	/*public $parametres = array(
24
	/*public $parametres = array(
25
		'-r' => array(true, true, 'referentiel de base'),
25
		'-r' => array(true, true, 'referentiel de base'),
26
		'-f' => array(true, true, 'fichier à comparer'));*/
26
		'-f' => array(true, true, 'fichier à comparer'));*/
27
	private $noms_supprimes = null;
27
	private $noms_supprimes = null;
28
	private $noms_colonnes = array();
28
	private $noms_colonnes = array();
29
	private $rangs_bdnt_taxref = null;
29
	private $rangs_bdnt_taxref = null;
30
	private $statuts_bdnt_taxref = null;
30
	private $statuts_bdnt_taxref = null;
31
	private $correspondance_colonnes = array("CD_NOM" => "", "CD_SUP" => "", "CD_REF" => "",
31
	private $correspondance_colonnes = array("CD_NOM" => "", "CD_SUP" => "", "CD_REF" => "",
32
		"RANG" => "rang", "LB_NOM" => "nom_sci", "LB_AUTEUR" => array("auteur","annee"),
32
		"RANG" => "rang", "LB_NOM" => "nom_sci", "LB_AUTEUR" => array("auteur","annee"),
33
		"FR" => "presence",
33
		"FR" => "presence",
34
		"FR-FRA" => "presence_Ga", "FR-COR" => "presence_Co", "REU" => "presence",
34
		"FR-FRA" => "presence_Ga", "FR-COR" => "presence_Co", "REU" => "presence",
35
		"GUA" => "presence_Guadeloupe", "SMSB" => array("presence_Saint_Martin", "presence_Saint_Barthelemy"), 
35
		"GUA" => "presence_Guadeloupe", "SMSB" => array("presence_Saint_Martin", "presence_Saint_Barthelemy"), 
36
		"MAR" => "presence_Martinique",
36
		"MAR" => "presence_Martinique",
37
		"GF" => "presence", "MAY" => "presence_Mayotte", "TAAF" => "presence_Taaf",
37
		"GF" => "presence", "MAY" => "presence_Mayotte", "TAAF" => "presence_Taaf",
38
		"SPM" => "presence_Guadeloupe", "PF" => "presence_Polynesie", "NC" => "presence_Nouvelle_Caledonie",
38
		"SPM" => "presence_Guadeloupe", "PF" => "presence_Polynesie", "NC" => "presence_Nouvelle_Caledonie",
39
		"BIBLIO" => "biblio_origine", "BDNGM" => "num_nom" );
39
		"BIBLIO" => "biblio_origine", "BDNGM" => "num_nom" );
40
	
40
	
41
	private $sans_correspondance = array(
41
	private $sans_correspondance = array(
42
			"FG_VALIDITE", "habitat", "WF", "CLI", "EPA",
42
			"FG_VALIDITE", "habitat", "WF", "CLI", "EPA",
43
			"EU", "WLD", "ORACLE",
43
			"EU", "WLD", "ORACLE",
44
			"DATE_CREA", "ORIGINE_CREA",
44
			"DATE_CREA", "ORIGINE_CREA",
45
			"NOM_COMPLET", "NOM_COMPLET_HTML",
45
			"NOM_COMPLET", "NOM_COMPLET_HTML",
46
			"GENRE", "ESPECE", "SOUS_ESPECE", "ANNEE");
46
			"GENRE", "ESPECE", "SOUS_ESPECE", "ANNEE");
47
	
47
	
48
	/*public function executer() {
48
	/*public function executer() {
49
		$this->referentiel = $this->getParam('r');
49
		$this->referentiel = $this->getParam('r');
50
		// Lancement du test demandé
50
		// Lancement du test demandé
51
		$fichier = $this->getParam('f');
51
		$fichier = $this->getParam('f');
52
		if (file_exists($fichier)) {
52
		if (file_exists($fichier)) {
53
			$manuel_chemin = Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS;
53
			$manuel_chemin = Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS;
54
			$manuel_config_nom = 'referentiel_v'.self::MANUEL_VERSION.'.ini';
54
			$manuel_config_nom = 'referentiel_v'.self::MANUEL_VERSION.'.ini';
55
			$this->manuel = parse_ini_file($manuel_chemin.$manuel_config_nom);
55
			$this->manuel = parse_ini_file($manuel_chemin.$manuel_config_nom);
56
			$this->creerCorrespondanceRangBdntTaxref();
56
			$this->creerCorrespondanceRangBdntTaxref();
57
			$donnees = $this->traiterFichierTaxref($fichier);
57
			$donnees = $this->traiterFichierTaxref($fichier);
58
			Debug::printr("Fin du traitement du fichier.");
58
			Debug::printr("Fin du traitement du fichier.");
59
			$this->connecterPDO();
59
			$this->connecterPDO();
60
			$this->creerTableTaxref();
60
			$this->creerTableTaxref();
61
			$this->ajouterColonneCDNOM();
61
			$this->ajouterColonneCDNOM();
62
			Debug::printr("Fin de la création de la table.");
62
			Debug::printr("Fin de la création de la table.");
63
			$this->ajouterDonneesTaxRef($donnees);
63
			$this->ajouterDonneesTaxRef($donnees);
64
			Debug::printr("Fin de l'insertion des données.");
64
			Debug::printr("Fin de l'insertion des données.");
65
			$this->creerTableComparaison();
65
			$this->creerTableComparaison();
66
			Debug::printr("Fin de la création de la table comparaison.");
66
			Debug::printr("Fin de la création de la table comparaison.");
67
		}
67
		}
68
	}*/
68
	}*/
69
	
69
	
70
	public function executer() {
70
	public function executer() {
71
		// Récupération du dernier traitement demandé
71
		// Récupération du dernier traitement demandé
72
		$this->traitementDao = new TraitementDao();
72
		$this->traitementDao = new TraitementDao();
73
		$this->traitement = $this->traitementDao->getDernierTraitement('tout', self::SCRIPT_NOM);
73
		$this->traitement = $this->traitementDao->getDernierTraitement('tout', self::SCRIPT_NOM);
74
		if (isset($this->traitement)) {
74
		if (isset($this->traitement)) {
75
			$this->referentiel = $this->traitement['referentiel_code']; // Récupération du nom de projet
75
			$this->referentiel = $this->traitement['referentiel_code']; // Récupération du nom de projet
76
			$fichier = $this->traitement['script_parametres'];
76
			$fichier = $this->traitement['script_parametres'];
77
			if (file_exists($fichier)) {
77
			if (file_exists($fichier)) {
78
				Debug::printr('Debute:'.$this->traitementDao->debuterTraitement($this->traitement['id_traitement']));
78
				Debug::printr('Debute:'.$this->traitementDao->debuterTraitement($this->traitement['id_traitement']));
79
				// Nettoyage des traitements obsolètes
79
				// Nettoyage des traitements obsolètes
80
				$traitements_obsoletes = $this->traitementDao->getTraitementsObsoletes($this->referentiel, self::SCRIPT_NOM);
80
				$traitements_obsoletes = $this->traitementDao->getTraitementsObsoletes($this->referentiel, self::SCRIPT_NOM);
81
				if (isset($traitements_obsoletes)) {
81
				if (isset($traitements_obsoletes)) {
82
					Debug::printr('Supp. obsoletes:'.$this->traitementDao->supprimer($traitements_obsoletes));
82
					Debug::printr('Supp. obsoletes:'.$this->traitementDao->supprimer($traitements_obsoletes));
83
				}
83
				}
-
 
84
				Debug::printr("Début du traitement du fichier.");
84
				$manuel_chemin = Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS;
85
				$manuel_chemin = Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS;
85
				$manuel_config_nom = 'referentiel_v'.self::MANUEL_VERSION.'.ini';
86
				$manuel_config_nom = 'referentiel_v'.self::MANUEL_VERSION.'.ini';
86
				$this->manuel = parse_ini_file($manuel_chemin.$manuel_config_nom);
87
				$this->manuel = parse_ini_file($manuel_chemin.$manuel_config_nom);
87
				$this->creerCorrespondanceRangBdntTaxref();
88
				$this->creerCorrespondanceRangBdntTaxref();
88
				$donnees = $this->traiterFichierTaxref($fichier);
89
				$donnees = $this->traiterFichierTaxref($fichier);
89
				Debug::printr("Fin du traitement du fichier.");
90
				Debug::printr("Fin du traitement du fichier.");
90
				$this->connecterPDO();
91
				$this->connecterPDO();
91
				$this->creerTableTaxref();
92
				$this->creerTableTaxref();
92
				$this->ajouterColonneCDNOM();
93
				$this->ajouterColonneCDNOM();
93
				Debug::printr("Fin de la création de la table.");
94
				Debug::printr("Fin de la création de la table.");
94
				$this->ajouterDonneesTaxRef($donnees);
95
				$this->ajouterDonneesTaxRef($donnees);
95
				Debug::printr("Fin de l'insertion des données.");
96
				Debug::printr("Fin de l'insertion des données.");
96
				$this->creerTableComparaison();
97
				$this->creerTableComparaison();
97
				Debug::printr("Fin de la création de la table comparaison.");
98
				Debug::printr("Fin de la création de la table comparaison.");
98
				Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
99
				Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
99
			} else {
100
			} else {
100
				Debug::printr("Fichier introuvable".$fichier);
101
				Debug::printr("Fichier introuvable".$fichier);
101
				Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
102
				Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
102
			}
103
			}
-
 
104
		} else {
-
 
105
			Debug::printr("Pas de traitement");
103
		}
106
		}
104
	}
107
	}
105
	
108
	
106
	private function creerTableTaxref() {
109
	private function creerTableTaxref() {
107
		$requete = "DROP TABLE IF EXISTS {$this->referentiel}_taxref; ".
110
		$requete = "DROP TABLE IF EXISTS {$this->referentiel}_taxref; ".
108
			"CREATE TABLE  {$this->referentiel}_taxref AS SELECT * FROM {$this->referentiel};".
111
			"CREATE TABLE  {$this->referentiel}_taxref AS SELECT * FROM {$this->referentiel};".
109
			"ALTER TABLE  {$this->referentiel}_taxref ADD PRIMARY KEY (num_nom);";
112
			"ALTER TABLE  {$this->referentiel}_taxref ADD PRIMARY KEY (num_nom);";
110
		$resultat = $this->executerRequeter($requete);
113
		$resultat = $this->executerRequeter($requete);
111
	}
114
	}
112
	private function ajouterColonneCDNOM() {
115
	private function ajouterColonneCDNOM() {
113
		$requete = "ALTER TABLE  {$this->referentiel}_taxref ADD ".
116
		$requete = "ALTER TABLE  {$this->referentiel}_taxref ADD ".
114
			"`num_taxref` INT( 15 ) NULL DEFAULT NULL COMMENT 'numéro correspondant dans la base taxref.';";
117
			"`num_taxref` INT( 15 ) NULL DEFAULT NULL COMMENT 'numéro correspondant dans la base taxref.';";
115
		$resultat = $this->executerRequeter($requete);
118
		$resultat = $this->executerRequeter($requete);
116
	}
119
	}
117
	private function ajouterDonneesTaxRef($liste_noms) {
120
	private function ajouterDonneesTaxRef($liste_noms) {
118
		$i = 0; $j = 0; $requete = "";
121
		$i = 0; $j = 0; $requete = "";
119
		foreach ($liste_noms as $nom) { $i++;
122
		foreach ($liste_noms as $nom) { $i++;
120
			$requete .= "UPDATE  {$this->referentiel}_taxref SET ".implode(' , ', $nom).
123
			$requete .= "UPDATE  {$this->referentiel}_taxref SET ".implode(' , ', $nom).
121
					" WHERE {$nom['num_nom']} ;";//echo $requete;
124
					" WHERE {$nom['num_nom']} ;";//echo $requete;
122
			if ($i == 1000 || ($j*1000+$i) == count($liste_noms) ) { $j++;
125
			if ($i == 1000 || ($j*1000+$i) == count($liste_noms) ) { $j++;
123
				$resultat = $this->executerRequeter($requete.'commit;');
126
				$resultat = $this->executerRequeter($requete.'commit;');
124
				if ($resultat == null) {
127
				if ($resultat == null) {
125
					$resultat = $this->executerRequeter($requete.'commit;');
128
					$resultat = $this->executerRequeter($requete.'commit;');
126
				}
129
				}
127
				$i = 0; $requete = "";
130
				$i = 0; $requete = "";
128
			}
131
			}
129
		}
132
		}
130
	}
133
	}
131
	private function creerTableComparaison() {
134
	private function creerTableComparaison() {
132
		foreach ($this->noms_colonnes as $colonne) {
135
		foreach ($this->noms_colonnes as $colonne) {
133
			if (isset($this->correspondance_colonnes[$colonne]) && $this->correspondance_colonnes[$colonne] != "") {
136
			if (isset($this->correspondance_colonnes[$colonne]) && $this->correspondance_colonnes[$colonne] != "") {
134
				$nom_champ = $this->correspondance_colonnes[$colonne];
137
				$nom_champ = $this->correspondance_colonnes[$colonne];
135
				if (is_array($nom_champ)) {
138
				if (is_array($nom_champ)) {
136
					foreach ($nom_champ as $nom) {
139
					foreach ($nom_champ as $nom) {
137
						$champs_tax[] = "t.{$nom} AS tax_{$nom}";
140
						$champs_tax[] = "t.{$nom} AS tax_{$nom}";
138
						$champs_tax[] = "b.{$nom} AS {$nom}";
141
						$champs_tax[] = "b.{$nom} AS {$nom}";
139
						$concat[] = "IF(t.{$nom} != b.{$nom}, '{$nom}, ', '')";
142
						$concat[] = "IF(t.{$nom} != b.{$nom}, '{$nom}, ', '')";
140
					}
143
					}
141
				} else {
144
				} else {
142
					$champs_tax[] = "t.{$nom_champ} AS tax_{$nom_champ}";
145
					$champs_tax[] = "t.{$nom_champ} AS tax_{$nom_champ}";
143
					$champs_tax[] = "b.{$nom_champ} AS {$nom_champ}";
146
					$champs_tax[] = "b.{$nom_champ} AS {$nom_champ}";
144
					$concat[] = "IF(t.{$nom_champ} != b.{$nom_champ}, '{$nom_champ}, ', '')";
147
					$concat[] = "IF(t.{$nom_champ} != b.{$nom_champ}, '{$nom_champ}, ', '')";
145
				}
148
				}
146
			}
149
			}
147
		}
150
		}
148
		$requete = "CREATE TABLE  {$this->referentiel}_comparaison_".date("Y_m_d_H_i_s")." AS".
151
		$requete = "CREATE TABLE  {$this->referentiel}_comparaison_".date("Y_m_d_H_i_s")." AS".
149
					" SELECT CONCAT(".implode(', ', $concat).") AS difference, ".implode(', ', $champs_tax).
152
					" SELECT CONCAT(".implode(', ', $concat).") AS difference, ".implode(', ', $champs_tax).
150
					" FROM {$this->referentiel} b, {$this->referentiel}_taxref t".
153
					" FROM {$this->referentiel} b, {$this->referentiel}_taxref t".
151
					" WHERE b.num_nom = t.num_nom AND (b.nom_sci != t.nom_sci or b.auteur != t.auteur or b.annee != t.annee);";
154
					" WHERE b.num_nom = t.num_nom AND (b.nom_sci != t.nom_sci or b.auteur != t.auteur or b.annee != t.annee);";
152
		echo $requete;
155
		echo $requete;
153
		$resultat = $this->executerRequeter($requete);
156
		$resultat = $this->executerRequeter($requete);
154
	}
157
	}
155
	
158
	
156
	private function traiterFichierTaxref($fichier) {
159
	private function traiterFichierTaxref($fichier) {
157
		$donnees = array();
160
		$donnees = array();
158
		if (($pointeur = fopen($fichier, "r")) !== FALSE) {
161
		if (($pointeur = fopen($fichier, "r")) !== FALSE) {
159
			$this->noms_colonnes = fgetcsv($pointeur, 1000, chr(9));
162
			$this->noms_colonnes = fgetcsv($pointeur, 1000, chr(9));
160
			while (($ligne = fgetcsv($pointeur, 1000, chr(9))) !== FALSE) {
163
			while (($ligne = fgetcsv($pointeur, 1000, chr(9))) !== FALSE) {
161
				$nombreChamps = count($ligne);
164
				$nombreChamps = count($ligne);
162
				$taxref[$ligne[0]] = $ligne;
165
				$taxref[$ligne[0]] = $ligne;
163
				for ($c=0; $c < $nombreChamps; $c++) {
166
				for ($c=0; $c < $nombreChamps; $c++) {
164
					if (isset($this->correspondance_colonnes[$this->noms_colonnes[$c]])) {
167
					if (isset($this->correspondance_colonnes[$this->noms_colonnes[$c]])) {
165
						if (is_array($this->correspondance_colonnes[$this->noms_colonnes[$c]])) {
168
						if (is_array($this->correspondance_colonnes[$this->noms_colonnes[$c]])) {
166
							if ($this->noms_colonnes[$c] == 'LB_AUTEUR') {//echo $ligne[$c];
169
							if ($this->noms_colonnes[$c] == 'LB_AUTEUR') {//echo $ligne[$c];
167
								$valeur = explode(',', $ligne[$c]);
170
								$valeur = explode(',', $ligne[$c]);
168
								if (count($valeur) > 1) {//print_r($matches);
171
								if (count($valeur) > 1) {//print_r($matches);
169
									$nom['auteur'] = 'auteur="'.$valeur[0].'"';
172
									$nom['auteur'] = 'auteur="'.$valeur[0].'"';
170
									$nom['annee'] = 'annee="'.trim($valeur[1]).'"';
173
									$nom['annee'] = 'annee="'.trim($valeur[1]).'"';
171
								} else {
174
								} else {
172
									$nom['auteur'] = 'auteur="'.$ligne[$c].'"';
175
									$nom['auteur'] = 'auteur="'.$ligne[$c].'"';
173
									$nom['annee'] = 'annee=""';
176
									$nom['annee'] = 'annee=""';
174
								}
177
								}
175
							} else {
178
							} else {
176
								foreach ($this->correspondance_colonnes[$this->noms_colonnes[$c]] as $a=>$nom_colonne) {
179
								foreach ($this->correspondance_colonnes[$this->noms_colonnes[$c]] as $a=>$nom_colonne) {
177
									$nom[$nom_colonne] = $nom_colonne.'="'.$ligne[$c].'"';
180
									$nom[$nom_colonne] = $nom_colonne.'="'.$ligne[$c].'"';
178
								}
181
								}
179
							}
182
							}
180
						} elseif ($this->correspondance_colonnes[$this->noms_colonnes[$c]] == "") {
183
						} elseif ($this->correspondance_colonnes[$this->noms_colonnes[$c]] == "") {
181
							$nom[$this->noms_colonnes[$c]] = $ligne[$c];
184
							$nom[$this->noms_colonnes[$c]] = $ligne[$c];
182
						} else {
185
						} else {
183
							if ($this->correspondance_colonnes[$this->noms_colonnes[$c]] == "rang") {
186
							if ($this->correspondance_colonnes[$this->noms_colonnes[$c]] == "rang") {
184
								$nom[$this->correspondance_colonnes[$this->noms_colonnes[$c]]] = 
187
								$nom[$this->correspondance_colonnes[$this->noms_colonnes[$c]]] = 
185
									$this->correspondance_colonnes[$this->noms_colonnes[$c]].'="'.$this->rangs_bdnt_taxref[$ligne[$c]].'"';
188
									$this->correspondance_colonnes[$this->noms_colonnes[$c]].'="'.$this->rangs_bdnt_taxref[$ligne[$c]].'"';
186
							} elseif ($this->correspondance_colonnes[$this->noms_colonnes[$c]] == "num_nom") {
189
							} elseif ($this->correspondance_colonnes[$this->noms_colonnes[$c]] == "num_nom") {
187
								$num_nom = $ligne[$c];
190
								$num_nom = $ligne[$c];
188
								$nom[$this->correspondance_colonnes[$this->noms_colonnes[$c]]] = 
191
								$nom[$this->correspondance_colonnes[$this->noms_colonnes[$c]]] = 
189
									$this->correspondance_colonnes[$this->noms_colonnes[$c]].'="'.$ligne[$c].'"';
192
									$this->correspondance_colonnes[$this->noms_colonnes[$c]].'="'.$ligne[$c].'"';
190
							} else  {
193
							} else  {
191
								$nom[$this->correspondance_colonnes[$this->noms_colonnes[$c]]] = 
194
								$nom[$this->correspondance_colonnes[$this->noms_colonnes[$c]]] = 
192
									$this->correspondance_colonnes[$this->noms_colonnes[$c]].'="'.$ligne[$c].'"';;
195
									$this->correspondance_colonnes[$this->noms_colonnes[$c]].'="'.$ligne[$c].'"';;
193
							}
196
							}
194
						}
197
						}
195
					}
198
					}
196
				}
199
				}
197
				$nom['exclure_taxref'] = 'exclure_taxref="0"';
200
				$nom['exclure_taxref'] = 'exclure_taxref="0"';
198
				$donnees[$num_nom] = $nom;
201
				$donnees[$num_nom] = $nom;
199
				$correspondance_taxref_bdnt[$nom['CD_NOM']] = $num_nom;
202
				$correspondance_taxref_bdnt[$nom['CD_NOM']] = $num_nom;
200
			}
203
			}
201
			fclose($pointeur);
204
			fclose($pointeur);
202
			$donnees = $this->changerNumerotation($donnees, $correspondance_taxref_bdnt, $taxref);
205
			$donnees = $this->changerNumerotation($donnees, $correspondance_taxref_bdnt, $taxref);
203
		}
206
		}
204
		return $donnees;
207
		return $donnees;
205
	}
208
	}
206
	
209
	
207
	private function changerNumerotation($donnees, $correspondance, $taxref) {
210
	private function changerNumerotation($donnees, $correspondance, $taxref) {
208
		$i=0;$j=0;$k=0;
211
		$i=0;$j=0;$k=0;
209
		foreach ($donnees as $num_nom=>$infos) {
212
		foreach ($donnees as $num_nom=>$infos) {
210
			if (isset($correspondance[$infos['CD_SUP']])) {
213
			if (isset($correspondance[$infos['CD_SUP']])) {
211
				$donnees[$num_nom]['num_tax_sup'] = "num_tax_sup=".$correspondance[$infos['CD_SUP']];
214
				$donnees[$num_nom]['num_tax_sup'] = "num_tax_sup=".$correspondance[$infos['CD_SUP']];
212
				$i++;
215
				$i++;
213
			} elseif ($infos['CD_SUP'] != '') {
216
			} elseif ($infos['CD_SUP'] != '') {
214
				$donnees[$num_nom]['num_tax_sup'] = "num_tax_sup=''";
217
				$donnees[$num_nom]['num_tax_sup'] = "num_tax_sup=''";
215
				$sup[$infos['CD_NOM']] = $taxref[$infos['CD_NOM']];
218
				$sup[$infos['CD_NOM']] = $taxref[$infos['CD_NOM']];
216
			}
219
			}
217
			unset($donnees[$num_nom]['CD_SUP']);
220
			unset($donnees[$num_nom]['CD_SUP']);
218
			if (isset($correspondance[$infos['CD_REF']])) {
221
			if (isset($correspondance[$infos['CD_REF']])) {
219
				$donnees[$num_nom]['num_nom_retenu'] = "num_nom_retenu=".$correspondance[$infos['CD_REF']];
222
				$donnees[$num_nom]['num_nom_retenu'] = "num_nom_retenu=".$correspondance[$infos['CD_REF']];
220
				$j++;
223
				$j++;
221
			} elseif ($infos['CD_REF'] != '') {$k++;
224
			} elseif ($infos['CD_REF'] != '') {$k++;
222
				$donnees[$num_nom]['num_nom_retenu'] = "num_nom_retenu=''";
225
				$donnees[$num_nom]['num_nom_retenu'] = "num_nom_retenu=''";
223
				$ref[$infos['CD_NOM']] = $taxref[$infos['CD_NOM']];
226
				$ref[$infos['CD_NOM']] = $taxref[$infos['CD_NOM']];
224
			} else {
227
			} else {
225
				Debug::printr($infos['CD_NOM']."n'a pas de valeur pour CD_REF");
228
				Debug::printr($infos['CD_NOM']."n'a pas de valeur pour CD_REF");
226
			}
229
			}
227
			unset($donnees[$num_nom]['CD_REF']);
230
			unset($donnees[$num_nom]['CD_REF']);
228
			$donnees[$num_nom]['CD_NOM'] = 'num_taxref='.$donnees[$num_nom]['CD_NOM'];
231
			$donnees[$num_nom]['CD_NOM'] = 'num_taxref='.$donnees[$num_nom]['CD_NOM'];
229
		}
232
		}
230
		$this->ecrireFichierCsv($ref, './retenu_absent.csv');
233
		//$this->ecrireFichierCsv($ref, './retenu_absent.csv');
231
		$this->ecrireFichierCsv($sup, './superieur_absent.csv');
234
		//$this->ecrireFichierCsv($sup, './superieur_absent.csv');
232
		echo "$j correspondance pour nom retenu $i correspondance pour nom sup $k non pas de correspondance retenu";
235
		echo "$j correspondance pour nom retenu $i correspondance pour nom sup $k non pas de correspondance retenu";
233
		return $donnees;
236
		return $donnees;
234
	}
237
	}
235
	
238
	
236
	private function ecrireFichierCsv(&$contenu, $fichier) {
239
	private function ecrireFichierCsv(&$contenu, $fichier) {
237
		$retour = true;
240
		$retour = true;
238
		$fichier = fopen($fichier, "w");
241
		$fichier = fopen($fichier, "w");
239
		fputcsv($fichier, $this->noms_colonnes, chr('9'));
242
		fputcsv($fichier, $this->noms_colonnes, chr('9'));
240
		foreach ($contenu as $ligne) {
243
		foreach ($contenu as $ligne) {
241
			if (fputcsv($fichier, $ligne, chr('9')) == false) {
244
			if (fputcsv($fichier, $ligne, chr('9')) == false) {
242
				$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier";
245
				$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier";
243
				Debug::printr($e);
246
				Debug::printr($e);
244
				$retour = false;
247
				$retour = false;
245
			}
248
			}
246
		}
249
		}
247
		$contenu = null;
250
		$contenu = null;
248
		return $retour;
251
		return $retour;
249
	}
252
	}
250
	
253
	
251
	private function creerCorrespondanceRangBdntTaxref() {
254
	private function creerCorrespondanceRangBdntTaxref() {
252
		$rangs = explode(',', $this->manuel['rangs_bdnt_taxref']);
255
		$rangs = explode(',', $this->manuel['rangs_bdnt_taxref']);
253
		foreach ($rangs as $rang) {
256
		foreach ($rangs as $rang) {
254
			list($id_bdnt, $code_taxref) = explode(':', trim($rang));
257
			list($id_bdnt, $code_taxref) = explode(':', trim($rang));
255
			$this->rangs_bdnt_taxref[$code_taxref] = $id_bdnt;
258
			$this->rangs_bdnt_taxref[$code_taxref] = $id_bdnt;
256
		}
259
		}
257
	}
260
	}
258
	
261
	
259
	private function connecterPDO() {
262
	private function connecterPDO() {
260
		Config::charger('./configurations/bdd.ini');
263
		Config::charger('./configurations/bdd.ini');
261
		try {
264
		try {
-
 
265
			$dsn = Config::get('bdd_type').':dbname='.Config::get('bdd_nom').';host='.
-
 
266
				Config::get('bdd_hote');
262
			$this->bdd = new PDO(Config::get('bdd_dsn'), Config::get('bdd_utilisateur'), Config::get('bdd_mot_de_passe'));
267
			$this->bdd = new PDO($dsn, Config::get('bdd_utilisateur'), Config::get('bdd_mot_de_passe'));
263
		} catch (PDOException $e) {
268
		} catch (PDOException $e) {
264
			print_r($e);
269
			print_r($e);
265
			echo 'La connexion à la base de donnée via PDO a échouée : ' . $e->getMessage();
270
			echo 'La connexion à la base de donnée via PDO a échouée : ' . $e->getMessage();
266
		}
271
		}
267
		// Passe en UTF-8 la connexion à la BDD
272
		// Passe en UTF-8 la connexion à la BDD
268
		$this->bdd->exec("SET NAMES 'utf8'");
273
		$this->bdd->exec("SET NAMES 'utf8'");
269
		// Affiche les erreurs détectées par PDO (sinon mode silencieux => aucune erreur affiché)
274
		// Affiche les erreurs détectées par PDO (sinon mode silencieux => aucune erreur affiché)
270
		$this->bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
275
		$this->bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
271
	}
276
	}
272
	
277
	
273
	protected function executerRequeter($requete) {
278
	protected function executerRequeter($requete) {
274
		$infos = null;
279
		$infos = null;
275
		try {
280
		try {
276
			$infos = $this->bdd->query($requete);
281
			$infos = $this->bdd->query($requete);
277
			if ($infos === false) {
282
			if ($infos === false) {
278
				echo $requete;
283
				echo $requete;
279
			}
284
			}
280
		} catch (PDOException $e) {
285
		} catch (PDOException $e) {
281
			//print_r($this->bdd->errorInfo());
286
			//print_r($this->bdd->errorInfo());
282
			echo sprintf($e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode()); //echo $requete;
287
			echo sprintf($e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode()); //echo $requete;
283
		}
288
		}
284
		return $infos;
289
		return $infos;
285
	}
290
	}
286
}
291
}
287
?>
292
?>