Subversion Repositories Applications.referentiel

Rev

Rev 225 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 225 Rev 305
1
<?php
1
<?php
2
// Encodage : UTF-8
2
// Encodage : UTF-8
3
// +-------------------------------------------------------------------------------------------------------------------+
3
// +-------------------------------------------------------------------------------------------------------------------+
4
/**
4
/**
5
* Versionnage de référentiels de nomenclature et taxonomie
5
* Versionnage de référentiels de nomenclature et taxonomie
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 versionnage -p bdnff -a tout
8
* Utilisation : php script.php versionnage -p bdnff -a tout
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
// TODO : lors de la génération de la version 2 de la BDTFX tester les diff! Il se peut que la mémoire soit dépassée.
18
// TODO : lors de la génération de la version 2 de la BDTFX tester les diff! Il se peut que la mémoire soit dépassée.
19
class Versionnage extends ScriptCommande {
19
class Versionnage extends ScriptCommande {
20
	
20
	
21
	const SCRIPT_NOM = 'versionnage';
21
	const SCRIPT_NOM = 'versionnage';
22
	const MANUEL_VERSION = '4.3';
22
	const MANUEL_VERSION = '4.4';
23
	
23
	
24
	private $projet = null;
24
	private $projet = null;
25
	private $traitement = null;
25
	private $traitement = null;
26
	private $meta = null;
26
	private $meta = null;
27
	private $version_courante = null;
27
	private $version_courante = null;
28
	private $messages = null;
28
	private $messages = null;
29
	private $manuel = null;
29
	private $manuel = null;
30
	private $manuel_nom = null;
30
	private $manuel_nom = null;
31
	private $manuel_chemin = null;
31
	private $manuel_chemin = null;
32
	private $zip_chemin_dossier = null;
32
	private $zip_chemin_dossier = null;
33
	private $zip_chemin_fichier = null;
33
	private $zip_chemin_fichier = null;
34
	private $zip_chemin_dossier_partiel = null;
34
	private $zip_chemin_dossier_partiel = null;
35
	private $zip_chemin_fichier_partiel = null;
35
	private $zip_chemin_fichier_partiel = null;
36
	
36
	
37
	private $noms = null;
37
	private $noms = null;
38
	private $noms_precedents = null;
38
	private $noms_precedents = null;
39
	private $noms_supprimes = null;
39
	private $noms_supprimes = null;
40
	private $noms_stat = null;
40
	private $noms_stat = null;
41
	private $noms_stat_partiel = null;
41
	private $noms_stat_partiel = null;
42
	private $champs_ordre = null;
42
	private $champs_ordre = null;
43
	private $champs_nom = null;
43
	private $champs_nom = null;
44
	private $champs_nom_partiel = null;
44
	private $champs_nom_partiel = null;
45
	private $champs_courants = null;
45
	private $champs_courants = null;
46
	private $champs_diff = null;
46
	private $champs_diff = null;
47
	private $diff_champs_nom = null;
47
	private $diff_champs_nom = null;
48
	private $diff_modif_types = null;
48
	private $diff_modif_types = null;
49
	private $signature_md5 = null;
49
	private $signature_md5 = null;
50
	private $signature_md5_partiel = null;
50
	private $signature_md5_partiel = null;
51
	private $derniere_meta = null;
51
	private $derniere_meta = null;
52
	private $rangs_bdnt_taxref = null;
52
	private $rangs_bdnt_taxref = null;
53
	private $statuts_bdnt_taxref = null;
53
	private $statuts_bdnt_taxref = null;
54
	
54
	
55
	private $resultatDao = null;
55
	private $resultatDao = null;
56
	private $traitementDao = null;
56
	private $traitementDao = null;
57
	private $metaDao = null;
57
	private $metaDao = null;
58
	private $tableStructureDao = null;
58
	private $tableStructureDao = null;
59
	private $referentielDao = null;
59
	private $referentielDao = null;
60
	
60
	
61
	public function executer() {
61
	public function executer() {
62
		// Récupération du dernier traitement demandé
62
		// Récupération du dernier traitement demandé
63
		$this->traitementDao = new TraitementDao();
63
		$this->traitementDao = new TraitementDao();
64
		$this->traitement = $this->traitementDao->getDernierTraitement('tout', self::SCRIPT_NOM);
64
		$this->traitement = $this->traitementDao->getDernierTraitement('tout', self::SCRIPT_NOM);
65
		if (isset($this->traitement)) {
65
		if (isset($this->traitement)) {
66
			$this->projet = $this->traitement['referentiel_code']; // Récupération du nom de projet
66
			$this->projet = $this->traitement['referentiel_code']; // Récupération du nom de projet
67
			Debug::printr($this->traitement);
67
			Debug::printr($this->traitement);
68
			// Écriture de la date de début du traitement
68
			// Écriture de la date de début du traitement
69
			Debug::printr('Debute:'.$this->traitementDao->debuterTraitement($this->traitement['id_traitement']));
69
			Debug::printr('Debute:'.$this->traitementDao->debuterTraitement($this->traitement['id_traitement']));
70
			
70
			
71
			// Nettoyage des traitements obsolètes
71
			// Nettoyage des traitements obsolètes
72
			$traitements_obsoletes = $this->traitementDao->getTraitementsObsoletes($this->projet, self::SCRIPT_NOM);
72
			$traitements_obsoletes = $this->traitementDao->getTraitementsObsoletes($this->projet, self::SCRIPT_NOM);
73
			if (isset($traitements_obsoletes)) {
73
			if (isset($traitements_obsoletes)) {
74
				Debug::printr('Supp. obsoletes:'.$this->traitementDao->supprimer($traitements_obsoletes));
74
				Debug::printr('Supp. obsoletes:'.$this->traitementDao->supprimer($traitements_obsoletes));
75
			}
75
			}
76
			
76
			
77
			// Lancement du test demandé
77
			// Lancement du test demandé
78
			$cmd = $this->getParam('a');
78
			$cmd = $this->getParam('a');
79
	    	switch ($cmd) {
79
	    	switch ($cmd) {
80
				case 'tout' :
80
				case 'tout' :
81
					$this->initialiserScript();
81
					$this->initialiserScript();
82
					Debug::printr('Départ lancement versionnage:');
82
					Debug::printr('Départ lancement versionnage:');
83
					$this->lancerVersionnage();
83
					$this->lancerVersionnage();
84
					break;
84
					break;
85
				default :
85
				default :
86
					$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
86
					$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
87
			}
87
			}
88
			// Écriture de la date de fin du traitement
88
			// Écriture de la date de fin du traitement
89
			Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
89
			Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
90
		}
90
		}
91
    }
91
    }
92
	
92
	
93
    private function initialiserScript() {
93
    private function initialiserScript() {
94
		$this->metaDao = new MetaDao();
94
		$this->metaDao = new MetaDao();
95
		$this->resultatDao = new ResultatDao();
95
		$this->resultatDao = new ResultatDao();
96
		$this->referentielDao = new ReferentielDao();
96
		$this->referentielDao = new ReferentielDao();
97
		
97
		
98
		$this->manuel_nom = 'mtpr_v'.str_replace('.', '_', self::MANUEL_VERSION).'.pdf';
98
		$this->manuel_nom = 'mtpr_v'.str_replace('.', '_', self::MANUEL_VERSION).'.pdf';
99
		$this->manuel_chemin = Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS;
99
		$this->manuel_chemin = Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS;
100
		
100
		
101
		$manuel_config_nom = 'referentiel_v'.self::MANUEL_VERSION.'.ini';
101
		$manuel_config_nom = 'referentiel_v'.self::MANUEL_VERSION.'.ini';
102
		$this->manuel = parse_ini_file($this->manuel_chemin.$manuel_config_nom);
102
		$this->manuel = parse_ini_file($this->manuel_chemin.$manuel_config_nom);
103
	}
103
	}
104
	
104
	
105
    public function lancerVersionnage() {
105
    public function lancerVersionnage() {
106
		$this->chargerTraitementParametre();
106
		$this->chargerTraitementParametre();
107
		$this->initialiserNomVersionCOurante();
107
		$this->initialiserNomVersionCOurante();
108
		$this->initialiserCheminsZip();
108
		$this->initialiserCheminsZip();
109
		$this->creerDossiersZip();
109
		$this->creerDossiersZip();
110
		$this->archiver();
110
		$this->archiver();
111
    	$this->chargerNomsATraiter();
111
    	$this->chargerNomsATraiter();
112
    	$this->analyserNomsATraiter();
112
    	$this->analyserNomsATraiter();
113
		$this->creerFichiers();
113
		$this->creerFichiers();
114
		$this->nettoyerFichiers();
114
		$this->nettoyerFichiers();
115
		$this->traiterMessages();
115
		$this->traiterMessages();
116
	}
116
	}
117
	
117
	
118
	private function chargerTraitementParametre() {
118
	private function chargerTraitementParametre() {
119
		$this->meta = unserialize($this->traitement['script_parametres']);
119
		$this->meta = unserialize($this->traitement['script_parametres']);
120
	}
120
	}
121
	
121
	
122
	private function archiver() {
122
	private function archiver() {
123
		$ok = $this->referentielDao->archiver($this->projet, $this->meta['version']);
123
		$ok = $this->referentielDao->archiver($this->projet, $this->meta['version']);
124
		if ($ok) {
124
		if ($ok) {
125
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a réussi";
125
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a réussi";
126
			$this->ajouterMessage($m);
126
			$this->ajouterMessage($m);
127
		} else {
127
		} else {
128
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a échoué";
128
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a échoué";
129
			$this->ajouterMessage($m);
129
			$this->ajouterMessage($m);
130
		}
130
		}
131
	}
131
	}
132
	
132
	
133
	private function initialiserNomVersionCOurante() {
133
	private function initialiserNomVersionCOurante() {
134
		$this->version_courante = strtolower($this->projet).'_v'.str_replace('.', '_', $this->meta['version']);
134
		$this->version_courante = strtolower($this->projet).'_v'.str_replace('.', '_', $this->meta['version']);
135
		Debug::printr("Nom archive courante :".$this->version_courante);
135
		Debug::printr("Nom archive courante :".$this->version_courante);
136
	}
136
	}
137
	
137
	
138
	private function initialiserCheminsZip() {
138
	private function initialiserCheminsZip() {
139
		$this->zip_chemin_dossier = Config::get('chemin_referentiel_zip').$this->version_courante.DIRECTORY_SEPARATOR;
139
		$this->zip_chemin_dossier = Config::get('chemin_referentiel_zip').$this->version_courante.DIRECTORY_SEPARATOR;
140
		$this->zip_chemin_fichier = Config::get('chemin_referentiel_zip').$this->version_courante.'.zip';
140
		$this->zip_chemin_fichier = Config::get('chemin_referentiel_zip').$this->version_courante.'.zip';
141
		$this->zip_chemin_dossier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.$this->manuel['suffixe_partiel'].DIRECTORY_SEPARATOR;
141
		$this->zip_chemin_dossier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.$this->manuel['suffixe_partiel'].DIRECTORY_SEPARATOR;
142
		$this->zip_chemin_fichier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.$this->manuel['suffixe_partiel'].'.zip';
142
		$this->zip_chemin_fichier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.$this->manuel['suffixe_partiel'].'.zip';
143
	}
143
	}
144
	
144
	
145
	private function creerDossiersZip() {
145
	private function creerDossiersZip() {
146
		$recursivite = true;
146
		$recursivite = true;
147
		if (mkdir($this->zip_chemin_dossier, 0777, $recursivite) === false) {
147
		if (mkdir($this->zip_chemin_dossier, 0777, $recursivite) === false) {
148
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier' devant contenir les fichiers a échouée.");
148
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier' devant contenir les fichiers a échouée.");
149
		}
149
		}
150
		if (mkdir($this->zip_chemin_dossier_partiel, 0777, $recursivite) === false) {
150
		if (mkdir($this->zip_chemin_dossier_partiel, 0777, $recursivite) === false) {
151
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier_partiel' devant contenir les fichiers partiels a échouée.");
151
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier_partiel' devant contenir les fichiers partiels a échouée.");
152
		}
152
		}
153
	}
153
	}
154
	
154
	
155
	private function chargerNomsATraiter() {
155
	private function chargerNomsATraiter() {
156
		$this->noms = $this->referentielDao->getTout($this->version_courante);
156
		$this->noms = $this->referentielDao->getTout($this->version_courante);
157
	}
157
	}
158
	
158
	
159
	private function analyserNomsATraiter() {
159
	private function analyserNomsATraiter() {
160
		$this->noms_stat['combinaison'] = $this->getNombreCombinaison();
160
		$this->noms_stat['combinaison'] = $this->getNombreCombinaison();
161
		$this->noms_stat['taxon'] = $this->getNombreTaxon();
161
		$this->noms_stat['taxon'] = $this->getNombreTaxon();
162
		Debug::printr("Stats :".print_r($this->noms_stat, true));
162
		Debug::printr("Stats :".print_r($this->noms_stat, true));
163
		$this->noms_stat_partiel = $this->getStatsPartiel();
163
		$this->noms_stat_partiel = $this->getStatsPartiel();
164
		Debug::printr("Stats partiel:".print_r($this->noms_stat_partiel, true));
164
		Debug::printr("Stats partiel:".print_r($this->noms_stat_partiel, true));
165
	}
165
	}
166
	
166
	
167
	private function getNombreCombinaison() {
167
	private function getNombreCombinaison() {
168
		return count($this->noms);
168
		return count($this->noms);
169
	}
169
	}
170
	
170
	
171
	private function getNombreTaxon() {
171
	private function getNombreTaxon() {
172
		$nbre = 0;
172
		$nbre = 0;
173
		foreach ($this->noms as $nom) {
173
		foreach ($this->noms as $nom) {
174
			if ($nom['num_nom_retenu'] == $nom['num_nom']) {
174
			if ($nom['num_nom_retenu'] == $nom['num_nom']) {
175
				$nbre++;
175
				$nbre++;
176
			}
176
			}
177
		}
177
		}
178
		return $nbre;
178
		return $nbre;
179
	}
179
	}
180
	
180
	
181
	private function getStatsPartiel() {
181
	private function getStatsPartiel() {
182
		$stat['combinaison'] = 0;
182
		$stat['combinaison'] = 0;
183
		$stat['taxon'] = 0;
183
		$stat['taxon'] = 0;
184
		foreach ($this->noms as $nom) {
184
		foreach ($this->noms as $nom) {
185
			if ($nom['exclure_taxref'] != '1') {
185
			if ($nom['exclure_taxref'] != '1') {
186
				$stat['combinaison']++;
186
				$stat['combinaison']++;
187
				if ($nom['num_nom_retenu'] == $nom['num_nom']) {
187
				if ($nom['num_nom_retenu'] == $nom['num_nom']) {
188
					$stat['taxon']++;
188
					$stat['taxon']++;
189
				}
189
				}
190
			}
190
			}
191
		}
191
		}
192
		return $stat;
192
		return $stat;
193
	}
193
	}
194
	
194
	
195
	private function creerFichiers() {
195
	private function creerFichiers() {
196
		// Respecter l'ordre de traitement : BDNT puis DIFF puis META
196
		// Respecter l'ordre de traitement : BDNT puis DIFF puis META
197
		$donnees =& $this->creerFichierBdnt();
197
		$donnees =& $this->creerFichierBdnt();
198
		$this->creerFichierBdntPartiel($donnees);
198
		$this->creerFichierBdntPartiel($donnees);
199
		$donnees = null;
199
		$donnees = null;
200
		$donnees =& $this->creerFichierDiff();
200
		$donnees =& $this->creerFichierDiff();
201
		$this->creerFichierDiffPartiel($donnees);
201
		$this->creerFichierDiffPartiel($donnees);
202
		$donnees = null;
202
		$donnees = null;
203
		$donnees =& $this->creerFichierMeta();
203
		$donnees =& $this->creerFichierMeta();
204
		$this->creerFichierMetaPartiel($donnees);
204
		$this->creerFichierMetaPartiel($donnees);
205
		$donnees = null;
205
		$donnees = null;
206
		$this->nettoyerMemoire();
206
		$this->nettoyerMemoire();
207
		$this->copierManuel();
207
		$this->copierManuel();
208
		$this->creerFichiersZip();
208
		$this->creerFichiersZip();
209
	}
209
	}
210
	
210
	
211
	private function creerFichierBdnt() {
211
	private function creerFichierBdnt() {
212
		reset($this->noms);
212
		reset($this->noms);
213
		Debug::printr("Element courrant du tableau des noms : ".count($this->noms).'-'.print_r(current($this->noms),true));
213
		Debug::printr("Element courrant du tableau des noms : ".count($this->noms).'-'.print_r(current($this->noms),true));
214
		
214
		
215
		$this->determinerOrdreDesChamps();
215
		$this->determinerOrdreDesChamps();
216
		$this->definirNomDesChamps();
216
		$this->definirNomDesChamps();
217
		$this->definirNomDesChampsDiff();
217
		$this->definirNomDesChampsDiff();
218
		
218
		
219
		$donnees = array();
219
		$donnees = array();
220
		$donnees['champs'] = $this->champs_nom;
220
		$donnees['champs'] = $this->champs_nom;
221
		
221
		
222
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_bdnt'].$this->manuel['ext_fichier'];
222
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_bdnt'].$this->manuel['ext_fichier'];
223
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
223
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
224
		$bdnt_tsv_entete = $this->getVue('versionnage/squelettes/bdnt_entete', array('champs' => $donnees['champs']), '.tpl.tsv');
224
		$bdnt_tsv_entete = $this->getVue('versionnage/squelettes/bdnt_entete', array('champs' => $donnees['champs']), '.tpl.tsv');
225
		$this->ecrireFichier($fichier_chemin, $bdnt_tsv_entete);
225
		$this->ecrireFichier($fichier_chemin, $bdnt_tsv_entete);
226
			
226
			
227
		foreach ($this->noms as $id => &$nom) {
227
		foreach ($this->noms as $id => &$nom) {
228
			$infos = array();
228
			$infos = array();
229
			foreach ($this->champs_ordre as $champ => $ordre) {
229
			foreach ($this->champs_ordre as $champ => $ordre) {
230
				if (array_key_exists($champ, $nom)) {
230
				if (array_key_exists($champ, $nom)) {
231
					$infos[$champ] = trim($nom[$champ]);
231
					$infos[$champ] = trim($nom[$champ]);
232
				} else {
232
				} else {
233
					$e = "Le champ '$champ' n'a pas été trouvé dans les données du nom : $id.";
233
					$e = "Le champ '$champ' n'a pas été trouvé dans les données du nom : $id.";
234
					$this->ajouterMessage($e);
234
					$this->ajouterMessage($e);
235
				}
235
				}
236
			}
236
			}
237
			$infos = $this->remplacerTabulation($infos);
237
			$infos = $this->remplacerTabulation($infos);
238
			$infos = $this->remplacerSautsDeLigne($infos);
238
			$infos = $this->remplacerSautsDeLigne($infos);
239
			$this->noms[$id] = $infos;
239
			$this->noms[$id] = $infos;
240
			
240
			
241
			$bdnt_tsv_ligne = $this->getVue('versionnage/squelettes/bdnt_ligne', array('nom_infos' => $infos), '.tpl.tsv');
241
			$bdnt_tsv_ligne = $this->getVue('versionnage/squelettes/bdnt_ligne', array('nom_infos' => $infos), '.tpl.tsv');
242
			$this->ajouterAuFichier($fichier_chemin, $bdnt_tsv_ligne);
242
			$this->ajouterAuFichier($fichier_chemin, $bdnt_tsv_ligne);
243
		}
243
		}
244
		$this->ecrireComplementFichierBdnt($fichier_chemin);
244
		$this->ecrireComplementFichierBdnt($fichier_chemin);
245
		return $donnees;
245
		return $donnees;
246
	}
246
	}
247
	
247
	
248
	private function determinerOrdreDesChamps() {
248
	private function determinerOrdreDesChamps() {
249
		$champs_ordre = explode(',', $this->manuel['champs']);
249
		$champs_ordre = explode(',', $this->manuel['champs']);
250
		$champs_ordre = array_flip($champs_ordre);
250
		$champs_ordre = array_flip($champs_ordre);
251
		$nom_courant = current($this->noms);
251
		$nom_courant = current($this->noms);
252
		$champs_ordre = $this->attribuerOrdreChampsSupplémentaires($champs_ordre, $nom_courant);
252
		$champs_ordre = $this->attribuerOrdreChampsSupplémentaires($champs_ordre, $nom_courant);
253
		asort($champs_ordre);
253
		asort($champs_ordre);
254
		$this->champs_ordre = $champs_ordre;
254
		$this->champs_ordre = $champs_ordre;
255
		Debug::printr("Ordre des champs : ".print_r($this->champs_ordre,true));
255
		Debug::printr("Ordre des champs : ".print_r($this->champs_ordre,true));
256
	}
256
	}
257
	
257
	
258
	private function attribuerOrdreChampsSupplémentaires($champs_ordre, $nom) {
258
	private function attribuerOrdreChampsSupplémentaires($champs_ordre, $nom) {
259
		foreach ($nom as $champ => $info) {
259
		foreach ($nom as $champ => $info) {
260
			if (!isset($champs_ordre[$champ])) {
260
			if (!isset($champs_ordre[$champ])) {
261
				$champs_ordre[$champ] = count($champs_ordre);
261
				$champs_ordre[$champ] = count($champs_ordre);
262
			}
262
			}
263
		}
263
		}
264
		return $champs_ordre;
264
		return $champs_ordre;
265
	}
265
	}
266
	
266
	
267
	private function definirNomDesChamps() {
267
	private function definirNomDesChamps() {
268
		$this->champs_nom = array_flip($this->champs_ordre);
268
		$this->champs_nom = array_flip($this->champs_ordre);
269
	}
269
	}
270
	
270
	
271
	private function definirNomDesChampsDiff() {
271
	private function definirNomDesChampsDiff() {
272
		$this->champs_diff = explode(',', $this->manuel['champs_diff']);
272
		$this->champs_diff = explode(',', $this->manuel['champs_diff']);
273
		$this->diff_champs_nom = array_merge($this->champs_nom, $this->champs_diff);
273
		$this->diff_champs_nom = array_merge($this->champs_nom, $this->champs_diff);
274
	}
274
	}
275
	
275
	
276
	private function ajouterMessage($message) {
276
	private function ajouterMessage($message) {
277
		$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
277
		$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
278
		$this->messages[] = array('message' => $message, 'resultat' => true);
278
		$this->messages[] = array('message' => $message, 'resultat' => true);
279
	}
279
	}
280
	
280
	
281
	private function remplacerTabulation($doc) {
281
	private function remplacerTabulation($doc) {
282
		if (is_string($doc)) {
282
		if (is_string($doc)) {
283
			$doc = str_replace("\t", ' ', $doc);
283
			$doc = str_replace("\t", ' ', $doc);
284
		} else if (is_array($doc) && count($doc) > 0) {
284
		} else if (is_array($doc) && count($doc) > 0) {
285
			foreach ($doc as $cle => $valeur) {
285
			foreach ($doc as $cle => $valeur) {
286
				$doc[$cle] = $this->remplacerTabulation($valeur);
286
				$doc[$cle] = $this->remplacerTabulation($valeur);
287
			}
287
			}
288
		}
288
		}
289
		return $doc;
289
		return $doc;
290
	}
290
	}
291
	
291
	
292
	private function remplacerSautsDeLigne($doc) {
292
	private function remplacerSautsDeLigne($doc) {
293
		if (is_string($doc)) {
293
		if (is_string($doc)) {
294
			$a_remplacer = array("\r", "\n");
294
			$a_remplacer = array("\r", "\n");
295
			$doc = str_replace($a_remplacer, ' ', $doc);
295
			$doc = str_replace($a_remplacer, ' ', $doc);
296
		} else if (is_array($doc) && count($doc) > 0) {
296
		} else if (is_array($doc) && count($doc) > 0) {
297
			foreach ($doc as $cle => $valeur) {
297
			foreach ($doc as $cle => $valeur) {
298
				$doc[$cle] = $this->remplacerSautsDeLigne($valeur);
298
				$doc[$cle] = $this->remplacerSautsDeLigne($valeur);
299
			}
299
			}
300
		}
300
		}
301
		return $doc;
301
		return $doc;
302
	}
302
	}
303
	
303
	
304
	private function ecrireComplementFichierBdnt($fichier_chemin) {
304
	private function ecrireComplementFichierBdnt($fichier_chemin) {
305
		if (file_exists($fichier_chemin)) {
305
		if (file_exists($fichier_chemin)) {
306
			$this->ajouterMessage("Écriture du fichier bdnt réussie.");
306
			$this->ajouterMessage("Écriture du fichier bdnt réussie.");
307
			$this->signature_md5 = md5_file($fichier_chemin);
307
			$this->signature_md5 = md5_file($fichier_chemin);
308
			$this->ajouterMessage("Signature MD5 du fichier bdnt :".$this->signature_md5);
308
			$this->ajouterMessage("Signature MD5 du fichier bdnt :".$this->signature_md5);
309
			$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
309
			$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
310
		}
310
		}
311
	}
311
	}
312
	
312
	
313
	private function getBaseNomFichier() {
313
	private function getBaseNomFichier() {
314
		return strtolower($this->meta['acronyme'].'_v'.str_replace('.', '_', $this->meta['version']));
314
		return strtolower($this->meta['acronyme'].'_v'.str_replace('.', '_', $this->meta['version']));
315
	}
315
	}
316
		
316
		
317
	private function creerFichierBdntPartiel(&$donnees) {
317
	private function creerFichierBdntPartiel(&$donnees) {
318
		$this->definirChampsPartiel();
318
		$this->definirChampsPartiel();
319
		$this->creerCorrespondanceRangBdntTaxref();
319
		$this->creerCorrespondanceRangBdntTaxref();
320
		$this->creerCorrespondanceStatutBdntTaxref();
320
		$this->creerCorrespondanceStatutBdntTaxref();
321
		Debug::printr(current($donnees['noms']));
321
		Debug::printr(current($donnees['noms']));
322
		$donnees['champs_partiel'] = $this->champs_nom_partiel;
322
		$donnees['champs_partiel'] = $this->champs_nom_partiel;
323
		$donnees['dernier_champ'] = end($this->champs_nom_partiel);
323
		$donnees['dernier_champ'] = end($this->champs_nom_partiel);
324
		$this->ecrireFichierBdntPartielle($donnees);
324
		$this->ecrireFichierBdntPartielle($donnees);
325
	}
325
	}
326
	
326
	
327
	private function definirChampsPartiel() {
327
	private function definirChampsPartiel() {
328
		$this->champs_nom_partiel = explode(',', $this->manuel['champs_partiel']);
328
		$this->champs_nom_partiel = explode(',', $this->manuel['champs_partiel']);
329
		$champs_taxref = explode(',', $this->manuel['champs_taxref']);
329
		$champs_taxref = explode(',', $this->manuel['champs_taxref']);
330
		$this->champs_nom_partiel = array_merge($this->champs_nom_partiel, $champs_taxref);
330
		$this->champs_nom_partiel = array_merge($this->champs_nom_partiel, $champs_taxref);
331
		Debug::printr("Champs partiels : ".print_r($this->champs_nom_partiel,true));
331
		Debug::printr("Champs partiels : ".print_r($this->champs_nom_partiel,true));
332
	}
332
	}
333
	
333
	
334
	private function creerCorrespondanceRangBdntTaxref() {
334
	private function creerCorrespondanceRangBdntTaxref() {
335
		$rangs = explode(',', $this->manuel['rangs_bdnt_taxref']);
335
		$rangs = explode(',', $this->manuel['rangs_bdnt_taxref']);
336
		foreach ($rangs as $rang) {
336
		foreach ($rangs as $rang) {
337
			list($id_bdnt, $code_taxref) = explode(':', trim($rang));
337
			list($id_bdnt, $code_taxref) = explode(':', trim($rang));
338
			$this->rangs_bdnt_taxref[$id_bdnt] = $code_taxref;
338
			$this->rangs_bdnt_taxref[$id_bdnt] = $code_taxref;
339
		}
339
		}
340
	}
340
	}
341
	
341
	
342
	private function creerCorrespondanceStatutBdntTaxref() {
342
	private function creerCorrespondanceStatutBdntTaxref() {
343
		$statuts = explode(',', $this->manuel['statuts_bdnt_taxref']);
343
		$statuts = explode(',', $this->manuel['statuts_bdnt_taxref']);
344
		foreach ($statuts as $statut) {
344
		foreach ($statuts as $statut) {
345
			list($code_taxref, $champ_et_code_bdnt) = explode('=', trim($statut));
345
			list($code_taxref, $champ_et_code_bdnt) = explode('=', trim($statut));
346
			list($nom_champ_bdnt, $code_bdnt) = explode(':', trim($champ_et_code_bdnt));
346
			list($nom_champ_bdnt, $code_bdnt) = explode(':', trim($champ_et_code_bdnt));
347
			$this->statuts_bdnt_taxref[$nom_champ_bdnt][$code_bdnt] = $code_taxref;
347
			$this->statuts_bdnt_taxref[$nom_champ_bdnt][$code_bdnt] = $code_taxref;
348
		}
348
		}
349
		Debug::printr($this->statuts_bdnt_taxref);
349
		Debug::printr($this->statuts_bdnt_taxref);
350
	}
350
	}
351
	
351
	
352
	private function ecrireFichierBdntPartielle(&$donnees) {
352
	private function ecrireFichierBdntPartielle(&$donnees) {
353
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_bdnt'].$this->manuel['suffixe_partiel'].$this->manuel['ext_fichier'];
353
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_bdnt'].$this->manuel['suffixe_partiel'].$this->manuel['ext_fichier'];
354
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
354
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
355
		$bdnt_tsv_entete = $this->getVue('versionnage/squelettes/bdnt_partiel_entete', array('champs_partiel' => $donnees['champs_partiel']), '.tpl.tsv');
355
		$bdnt_tsv_entete = $this->getVue('versionnage/squelettes/bdnt_partiel_entete', array('champs_partiel' => $donnees['champs_partiel']), '.tpl.tsv');
356
		$this->ecrireFichier($fichier_chemin, $bdnt_tsv_entete);
356
		$this->ecrireFichier($fichier_chemin, $bdnt_tsv_entete);
357
			
357
			
358
		foreach ($this->noms as $id => &$nom) {
358
		foreach ($this->noms as $id => &$nom) {
359
			$donnees['nom_infos'] = $nom;
359
			$donnees['nom_infos'] = $nom;
360
			
360
			
361
			// Ajout de champs spécifique à Taxref généré depuis les données BDNT
361
			// Ajout de champs spécifique à Taxref généré depuis les données BDNT
362
			$donnees['nom_infos']['taxref_rang'] = $this->attribuerRangTaxref($nom['rang']);
362
			$donnees['nom_infos']['taxref_rang'] = $this->attribuerRangTaxref($nom['rang']);
363
			$donnees['nom_infos']['taxref_statut'] = $this->attribuerStatutTaxref($nom);
363
			$donnees['nom_infos']['taxref_statut'] = $this->attribuerStatutTaxref($nom);
364
			
364
			
365
			$bdnt_tsv_ligne = $this->getVue('versionnage/squelettes/bdnt_partiel_ligne', $donnees, '.tpl.tsv');
365
			$bdnt_tsv_ligne = $this->getVue('versionnage/squelettes/bdnt_partiel_ligne', $donnees, '.tpl.tsv');
366
			if ($bdnt_tsv_ligne != '') {
366
			if ($bdnt_tsv_ligne != '') {
367
				$this->ajouterAuFichier($fichier_chemin, $bdnt_tsv_ligne);
367
				$this->ajouterAuFichier($fichier_chemin, $bdnt_tsv_ligne);
368
			}
368
			}
369
		}
369
		}
370
		
370
		
371
		if (file_exists($fichier_chemin)) {
371
		if (file_exists($fichier_chemin)) {
372
			$this->ajouterMessage("Écriture du fichier de la bdnt partielle réussie.");
372
			$this->ajouterMessage("Écriture du fichier de la bdnt partielle réussie.");
373
			$this->signature_md5_partiel = md5_file($fichier_chemin);
373
			$this->signature_md5_partiel = md5_file($fichier_chemin);
374
			$this->ajouterMessage("Signature MD5 du fichier bdnt partiel :".$this->signature_md5_partiel);
374
			$this->ajouterMessage("Signature MD5 du fichier bdnt partiel :".$this->signature_md5_partiel);
375
			$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
375
			$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
376
		}
376
		}
377
	}
377
	}
378
	
378
	
379
	private function attribuerRangTaxref($rang) {
379
	private function attribuerRangTaxref($rang) {
380
		$rang_taxref = '';
380
		$rang_taxref = '';
381
		if (isset($this->rangs_bdnt_taxref[$rang])) {
381
		if (isset($this->rangs_bdnt_taxref[$rang])) {
382
			$rang_taxref = $this->rangs_bdnt_taxref[$rang];
382
			$rang_taxref = $this->rangs_bdnt_taxref[$rang];
383
		}
383
		}
384
		return $rang_taxref;
384
		return $rang_taxref;
385
	}
385
	}
386
	
386
	
387
	private function attribuerStatutTaxref($nom) {
387
	private function attribuerStatutTaxref($nom) {
388
		$statut_taxref = '';
388
		$statut_taxref = '';
389
		$champs_statuts = array('presence', 'statut_origine', 'statut_introduction', 'statut_culture');
389
		$champs_statuts = array('presence', 'statut_origine', 'statut_introduction', 'statut_culture');
390
		foreach ($champs_statuts as $champ) {
390
		foreach ($champs_statuts as $champ) {
391
			$valeur = trim($nom[$champ]);
391
			$valeur = trim($nom[$champ]);
392
			if (isset($this->statuts_bdnt_taxref[$champ][$valeur])) {
392
			if (isset($this->statuts_bdnt_taxref[$champ][$valeur])) {
393
				$statut_taxref = $this->statuts_bdnt_taxref[$champ][$valeur];
393
				$statut_taxref = $this->statuts_bdnt_taxref[$champ][$valeur];
394
			}
394
			}
395
		}
395
		}
396
		return $statut_taxref;
396
		return $statut_taxref;
397
	}
397
	}
398
	
398
	
399
	private function ecrireFichier($fichier_chemin, &$contenu) {
399
	private function ecrireFichier($fichier_chemin, &$contenu) {
400
		$retour = true;
400
		$retour = true;
401
		if (file_put_contents($fichier_chemin, $contenu) == false) {
401
		if (file_put_contents($fichier_chemin, $contenu) == false) {
402
			$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier_chemin";
402
			$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier_chemin";
403
			$this->ajouterMessage($e);
403
			$this->ajouterMessage($e);
404
			$retour = false;
404
			$retour = false;
405
		}
405
		}
406
		$contenu = null;
406
		$contenu = null;
407
		return $retour;
407
		return $retour;
408
	}
408
	}
409
	
409
	
410
	private function ajouterAuFichier($fichier_chemin, &$contenu) {
410
	private function ajouterAuFichier($fichier_chemin, &$contenu) {
411
		$retour = true;
411
		$retour = true;
412
		if (file_put_contents($fichier_chemin, $contenu, FILE_APPEND) == false) {
412
		if (file_put_contents($fichier_chemin, $contenu, FILE_APPEND) == false) {
413
			$e = "Une erreur est survenu lors de l'ajout de données dans le fichier : $fichier_chemin";
413
			$e = "Une erreur est survenu lors de l'ajout de données dans le fichier : $fichier_chemin";
414
			$this->ajouterMessage($e);
414
			$this->ajouterMessage($e);
415
			$retour = false;
415
			$retour = false;
416
		}
416
		}
417
		$contenu = null;
417
		$contenu = null;
418
		return $retour;
418
		return $retour;
419
	}	
419
	}	
420
	
420
	
421
	private function creerFichierDiff() {
421
	private function creerFichierDiff() {
422
		$donnees = array();
422
		$donnees = array();
423
		$this->derniere_meta = $this->metaDao->getDerniere($this->projet);
423
		$this->derniere_meta = $this->metaDao->getDerniere($this->projet);
424
		if (is_null($this->derniere_meta === false)) {
424
		if (is_null($this->derniere_meta === false)) {
425
			$this->ajouterMessage("Un problème est survenu lors de la récupération des métadonnées précédentes.");
425
			$this->ajouterMessage("Un problème est survenu lors de la récupération des métadonnées précédentes.");
426
		} else if (is_null($this->derniere_meta)) {
426
		} else if (is_null($this->derniere_meta)) {
427
			$this->ajouterMessage("Premier versionnage pour ce projet, aucun fichier différentiel ne sera créé.");
427
			$this->ajouterMessage("Premier versionnage pour ce projet, aucun fichier différentiel ne sera créé.");
428
		} else {
428
		} else {
429
			$code_projet_precedent = strtolower($this->derniere_meta['code']).'_v'.str_replace('.', '_', $this->derniere_meta['version']);
429
			$code_projet_precedent = strtolower($this->derniere_meta['code']).'_v'.str_replace('.', '_', $this->derniere_meta['version']);
430
			if ($code_projet_precedent == $this->version_courante) {
430
			if ($code_projet_precedent == $this->version_courante) {
431
				$e = "La code de la version préalablement versionnée ($code_projet_precedent) est le même que celui ".
431
				$e = "La code de la version préalablement versionnée ($code_projet_precedent) est le même que celui ".
432
					"de la demande actuel ({$this->version_courante}) pour ce projet, aucun fichier différentiel ne sera créé.";
432
					"de la demande actuel ({$this->version_courante}) pour ce projet, aucun fichier différentiel ne sera créé.";
433
				$this->ajouterMessage($e);
433
				$this->ajouterMessage($e);
434
			} else {
434
			} else {
435
				$this->noms_precedents = $this->referentielDao->getTout($code_projet_precedent);
435
				$this->noms_precedents = $this->referentielDao->getTout($code_projet_precedent);
436
				$donnees['diff'] = $this->realiserDiff();
436
				$donnees['diff'] = $this->realiserDiff();
437
				$donnees['champs'] = $this->diff_champs_nom;
437
				$donnees['champs'] = $this->diff_champs_nom;
438
				$diff_tsv =& $this->getVue('versionnage/squelettes/diff', &$donnees, '.tpl.tsv');
438
				$diff_tsv =& $this->getVue('versionnage/squelettes/diff', &$donnees, '.tpl.tsv');
439
				$this->ecrireFichierDiff($diff_tsv);
439
				$this->ecrireFichierDiff($diff_tsv);
440
			}
440
			}
441
		}
441
		}
442
		return $donnees;
442
		return $donnees;
443
	}
443
	}
444
	
444
	
445
	private function realiserDiff() {
445
	private function realiserDiff() {
446
		$this->chargerTableauChampsModifTypes();
446
		$this->chargerTableauChampsModifTypes();
447
		$this->noms_stat['modification'] = 0;
447
		$this->noms_stat['modification'] = 0;
448
		
448
		
449
		$this->verifierNomsSupprimes();
449
		$this->verifierNomsSupprimes();
450
		$this->champs_courants = $this->champs_nom; 
450
		$this->champs_courants = $this->champs_nom; 
451
		$diff = array();
451
		$diff = array();
452
		foreach ($this->noms as $id => $nom) {
452
		foreach ($this->noms as $id => $nom) {
453
			$this->supprimerNomAExclurePartiel($this->noms, $id);
453
			$this->supprimerNomAExclurePartiel($this->noms, $id);
454
			$infos = array();
454
			$infos = array();
455
			if ($this->etreSupprime($id)) {
455
			if ($this->etreSupprime($id)) {
456
				$infos = $this->traiterDiffSuppression($nom);
456
				$infos = $this->traiterDiffSuppression($nom);
457
			} else if ($this->etreAjoute($id)) {
457
			} else if ($this->etreAjoute($id)) {
458
				$infos = $this->traiterDiffAjout($nom);
458
				$infos = $this->traiterDiffAjout($nom);
459
			} else {
459
			} else {
460
				$nom_precedent = $this->noms_precedents[$id];
460
				$nom_precedent = $this->noms_precedents[$id];
461
				$this->supprimerNomAExclurePartiel($this->noms_precedents, $id);
461
				$this->supprimerNomAExclurePartiel($this->noms_precedents, $id);
462
				$nom_precedent = $this->nettoyerEspacesTableau($nom_precedent);
462
				$nom_precedent = $this->nettoyerEspacesTableau($nom_precedent);
463
				$infos = $this->traiterDiffModif($nom, $nom_precedent);
463
				$infos = $this->traiterDiffModif($nom, $nom_precedent);
464
			}
464
			}
465
			
465
			
466
			if (count($infos) > 0) {
466
			if (count($infos) > 0) {
467
				$this->noms_stat['modification']++;
467
				$this->noms_stat['modification']++;
468
				$infos = $this->remplacerTabulation($infos);
468
				$infos = $this->remplacerTabulation($infos);
469
				$infos = $this->remplacerSautsDeLigne($infos);
469
				$infos = $this->remplacerSautsDeLigne($infos);
470
				$diff[$id] = $infos;
470
				$diff[$id] = $infos;
471
			}
471
			}
472
		}
472
		}
473
		
473
		
474
		return $diff;
474
		return $diff;
475
	}
475
	}
476
	
476
	
477
	private function verifierNomsSupprimes($edition = '«Complète»') {
477
	private function verifierNomsSupprimes($edition = '«Complète»') {
478
		$this->noms_supprimes = array_diff_key($this->noms_precedents, $this->noms);
478
		$this->noms_supprimes = array_diff_key($this->noms_precedents, $this->noms);
479
		$e = count($this->noms_supprimes)." lignes ont été supprimées vis à vis de la version ".
479
		$e = count($this->noms_supprimes)." lignes ont été supprimées vis à vis de la version ".
480
			"précédentes pour l'édition $edition. Cela concerne les noms : ".implode(', ', array_keys($this->noms_supprimes));
480
			"précédentes pour l'édition $edition. Cela concerne les noms : ".implode(', ', array_keys($this->noms_supprimes));
481
		Debug::printr($e);
481
		Debug::printr($e);
482
		$this->ajouterMessage($e);
482
		$this->ajouterMessage($e);
483
	}
483
	}
484
	
484
	
485
	private function supprimerNomAExclurePartiel(&$tableau, $id) {
485
	private function supprimerNomAExclurePartiel(&$tableau, $id) {
486
		if ($tableau[$id]['exclure_taxref'] == '1') {
486
		if ($tableau[$id]['exclure_taxref'] == '1') {
487
			unset($tableau[$id]);
487
			unset($tableau[$id]);
488
		}
488
		}
489
	}
489
	}
490
	
490
	
491
	private function nettoyerNomAExclurePartiel($nom) {
491
	private function nettoyerNomAExclurePartiel($nom) {
492
		foreach ($nom as $champ => $valeur) {
492
		foreach ($nom as $champ => $valeur) {
493
			if (! in_array($champ, $this->champs_nom_partiel)) {
493
			if (! in_array($champ, $this->champs_nom_partiel)) {
494
				unset($nom[$champ]);
494
				unset($nom[$champ]);
495
			}
495
			}
496
		}
496
		}
497
		return $nom;
497
		return $nom;
498
	}
498
	}
499
	
499
	
500
	private function etreSupprime($id) {
500
	private function etreSupprime($id) {
501
		$supprime = false;
501
		$supprime = false;
502
		if (array_key_exists($id, $this->noms_supprimes)) {
502
		if (array_key_exists($id, $this->noms_supprimes)) {
503
			$supprime = true;
503
			$supprime = true;
504
		}
504
		}
505
		return $supprime;
505
		return $supprime;
506
	}
506
	}
507
	
507
	
508
	private function traiterDiffSuppression(&$nom) {
508
	private function traiterDiffSuppression(&$nom) {
509
		$infos = $nom;
509
		$infos = $nom;
510
		$infos['modification_type'] = 'S';
510
		$infos['modification_type'] = 'S';
511
		$infos['modification_type_1'] = '0';
511
		$infos['modification_type_1'] = '0';
512
		$infos['modification_type_2'] = '0';
512
		$infos['modification_type_2'] = '0';
513
		$infos['modification_type_3'] = '0';
513
		$infos['modification_type_3'] = '0';
514
		return $infos;
514
		return $infos;
515
	}
515
	}
516
	
516
	
517
	private function etreAjoute($id) {
517
	private function etreAjoute($id) {
518
		$ajoute = false;
518
		$ajoute = false;
519
		if (! array_key_exists($id, $this->noms_precedents)) {
519
		if (! array_key_exists($id, $this->noms_precedents)) {
520
			$ajoute = true;
520
			$ajoute = true;
521
		}
521
		}
522
		return $ajoute;
522
		return $ajoute;
523
	}
523
	}
524
		
524
		
525
	private function nettoyerEspacesTableau($tableau) {
525
	private function nettoyerEspacesTableau($tableau) {
526
		array_walk($tableau, create_function('&$val', '$val = trim($val);'));
526
		array_walk($tableau, create_function('&$val', '$val = trim($val);'));
527
		return $tableau;
527
		return $tableau;
528
	}
528
	}
529
	
529
	
530
	private function traiterDiffAjout(&$nom) {
530
	private function traiterDiffAjout(&$nom) {
531
		$infos = $nom;
531
		$infos = $nom;
532
		$infos['modification_type'] = 'A';
532
		$infos['modification_type'] = 'A';
533
		$infos['modification_type_1'] = '0';
533
		$infos['modification_type_1'] = '0';
534
		$infos['modification_type_2'] = '0';
534
		$infos['modification_type_2'] = '0';
535
		$infos['modification_type_3'] = '0';
535
		$infos['modification_type_3'] = '0';
536
		return $infos;
536
		return $infos;
537
	}
537
	}
538
	
538
	
539
	private function traiterDiffModif(&$nom, &$nom_precedent) {
539
	private function traiterDiffModif(&$nom, &$nom_precedent) {
540
		$infos = array();
540
		$infos = array();
541
		$nom_diff = array_diff_assoc($nom, $nom_precedent);
541
		$nom_diff = array_diff_assoc($nom, $nom_precedent);
542
		
542
		
543
		if (count($nom_diff) > 0) {
543
		if (count($nom_diff) > 0) {
544
			$modif['modification_type'] = 'M';
544
			$modif['modification_type'] = 'M';
545
			$modif['modification_type_1'] = '0';
545
			$modif['modification_type_1'] = '0';
546
			$modif['modification_type_2'] = '0';
546
			$modif['modification_type_2'] = '0';
547
			$modif['modification_type_3'] = '0';
547
			$modif['modification_type_3'] = '0';
548
			
548
			
549
			foreach ($this->champs_courants as $champ) {
549
			foreach ($this->champs_courants as $champ) {
550
				if (isset($nom_diff[$champ])) {
550
				if (isset($nom_diff[$champ])) {
551
					// Si le champ modifié est vide nous retournons le mot clé "NULL" pour identifier le champ modifié
551
					// Si le champ modifié est vide nous retournons le mot clé "NULL" pour identifier le champ modifié
552
					$infos[$champ] = ($nom_diff[$champ] != '') ? $nom_diff[$champ] : 'NULL';
552
					$infos[$champ] = ($nom_diff[$champ] != '') ? $nom_diff[$champ] : 'NULL';
553
					$type = $this->getDiffType($champ);
553
					$type = $this->getDiffType($champ);
554
					$modif['modification_type_'.$type] = '1';
554
					$modif['modification_type_'.$type] = '1';
555
				} else {
555
				} else {
556
					if ($champ == 'num_nom') {
556
					if ($champ == 'num_nom') {
557
						$infos[$champ] = $nom[$champ];
557
						$infos[$champ] = $nom[$champ];
558
					} else {
558
					} else {
559
						$infos[$champ] = '';
559
						$infos[$champ] = '';
560
					}
560
					}
561
				}
561
				}
562
			}
562
			}
563
			
563
			
564
			foreach ($modif as $cle => $val) {
564
			foreach ($modif as $cle => $val) {
565
				$infos[$cle] = $val;
565
				$infos[$cle] = $val;
566
			}
566
			}
567
		}
567
		}
568
		return $infos;
568
		return $infos;
569
	}
569
	}
570
	
570
	
571
	private function chargerTableauChampsModifTypes() {
571
	private function chargerTableauChampsModifTypes() {
572
		$champs = explode(',', $this->manuel['champs_diff_type']);
572
		$champs = explode(',', $this->manuel['champs_diff_type']);
573
		foreach ($champs as $champ) {
573
		foreach ($champs as $champ) {
574
			list($champ_nom, $type) = explode('=', trim($champ));
574
			list($champ_nom, $type) = explode('=', trim($champ));
575
			$this->diff_modif_types[$champ_nom] = $type;
575
			$this->diff_modif_types[$champ_nom] = $type;
576
		}
576
		}
577
	}
577
	}
578
	
578
	
579
	private function getDiffType($champ_nom) {
579
	private function getDiffType($champ_nom) {
580
		$type = isset($this->diff_modif_types[$champ_nom]) ? $this->diff_modif_types[$champ_nom] : '3';
580
		$type = isset($this->diff_modif_types[$champ_nom]) ? $this->diff_modif_types[$champ_nom] : '3';
581
		return $type;
581
		return $type;
582
	}
582
	}
583
	
583
	
584
	private function ecrireFichierDiff(&$contenu) {
584
	private function ecrireFichierDiff(&$contenu) {
585
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_diff'].$this->manuel['ext_fichier'];
585
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_diff'].$this->manuel['ext_fichier'];
586
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
586
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
587
		
587
		
588
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
588
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
589
			$this->ajouterMessage("Écriture du fichier diff réussie.");
589
			$this->ajouterMessage("Écriture du fichier diff réussie.");
590
		}
590
		}
591
	}
591
	}
592
	
592
	
593
	private function creerFichierDiffPartiel(&$donnees) {
593
	private function creerFichierDiffPartiel(&$donnees) {
594
		$this->noms_stat_partiel['modification'] = 0;
594
		$this->noms_stat_partiel['modification'] = 0;
595
		if (! is_null($this->derniere_meta) && $this->derniere_meta !== false) {
595
		if (! is_null($this->derniere_meta) && $this->derniere_meta !== false) {
596
			$donnees['diff_partiel'] = $this->realiserDiffPartiel();
596
			$donnees['diff_partiel'] = $this->realiserDiffPartiel();
597
			$donnees['champs_partiel_diff'] = array_merge($this->champs_nom_partiel, $this->champs_diff);
597
			$donnees['champs_partiel_diff'] = array_merge($this->champs_nom_partiel, $this->champs_diff);
598
			$donnees['dernier_champ'] = end($donnees['champs_partiel_diff']);
598
			$donnees['dernier_champ'] = end($donnees['champs_partiel_diff']);
599
			$diff_tsv_partiel =& $this->getVue('versionnage/squelettes/diff_partiel', &$donnees, '.tpl.tsv');
599
			$diff_tsv_partiel =& $this->getVue('versionnage/squelettes/diff_partiel', &$donnees, '.tpl.tsv');
600
			$this->ecrireFichierDiffPartiel($diff_tsv_partiel);
600
			$this->ecrireFichierDiffPartiel($diff_tsv_partiel);
601
		} else {
601
		} else {
602
			$this->ajouterMessage("Aucun fichier différentiel pour l'édition «Partielle» ne sera créé.");
602
			$this->ajouterMessage("Aucun fichier différentiel pour l'édition «Partielle» ne sera créé.");
603
		}
603
		}
604
	}
604
	}
605
	
605
	
606
	private function realiserDiffPartiel() {
606
	private function realiserDiffPartiel() {
607
		$this->noms_stat_partiel['modification'] = 0;
607
		$this->noms_stat_partiel['modification'] = 0;
608
		
608
		
609
		$this->champs_courants = $this->champs_nom_partiel;
609
		$this->champs_courants = $this->champs_nom_partiel;
610
		$this->verifierNomsSupprimes('«Partielle»');
610
		$this->verifierNomsSupprimes('«Partielle»');
611
		$diff = array();
611
		$diff = array();
612
		foreach ($this->noms as $id => $nom) {
612
		foreach ($this->noms as $id => $nom) {
613
			unset($this->noms[$id]);
613
			unset($this->noms[$id]);
614
			
614
			
615
			// Ajout de champs spécifique à Taxref généré depuis les données BDNT
615
			// Ajout de champs spécifique à Taxref généré depuis les données BDNT
616
			$nom['taxref_rang'] = $this->attribuerRangTaxref($nom['rang']);
616
			$nom['taxref_rang'] = $this->attribuerRangTaxref($nom['rang']);
617
			$nom['taxref_statut'] = $this->attribuerStatutTaxref($nom);
617
			$nom['taxref_statut'] = $this->attribuerStatutTaxref($nom);
618
			$nom = $this->nettoyerNomAExclurePartiel($nom);
618
			$nom = $this->nettoyerNomAExclurePartiel($nom);
619
			$infos = array();
619
			$infos = array();
620
			if ($this->etreSupprime($id)) {
620
			if ($this->etreSupprime($id)) {
621
				$infos = $this->traiterDiffSuppression($nom);
621
				$infos = $this->traiterDiffSuppression($nom);
622
			} elseif ($this->etreAjoute($id)) {
622
			} elseif ($this->etreAjoute($id)) {
623
				$infos = $this->traiterDiffAjout($nom);
623
				$infos = $this->traiterDiffAjout($nom);
624
			} else {
624
			} else {
625
				$nom_precedent = $this->noms_precedents[$id];
625
				$nom_precedent = $this->noms_precedents[$id];
626
				unset($this->noms_precedents[$id]);
626
				unset($this->noms_precedents[$id]);
627
				
627
				
628
				// Ajout de champs spécifique à Taxref généré depuis les données BDNT
628
				// Ajout de champs spécifique à Taxref généré depuis les données BDNT
629
				$nom_precedent['taxref_rang'] = $this->attribuerRangTaxref($nom_precedent['rang']);
629
				$nom_precedent['taxref_rang'] = $this->attribuerRangTaxref($nom_precedent['rang']);
630
				$nom_precedent['taxref_statut'] = $this->attribuerStatutTaxref($nom_precedent);
630
				$nom_precedent['taxref_statut'] = $this->attribuerStatutTaxref($nom_precedent);
631
				$nom_precedent = $this->nettoyerNomAExclurePartiel($nom_precedent);
631
				$nom_precedent = $this->nettoyerNomAExclurePartiel($nom_precedent);
632
				$nom_precedent = $this->nettoyerEspacesTableau($nom_precedent); 
632
				$nom_precedent = $this->nettoyerEspacesTableau($nom_precedent); 
633
				$infos = $this->traiterDiffModif($nom, $nom_precedent);
633
				$infos = $this->traiterDiffModif($nom, $nom_precedent);
634
			}
634
			}
635
			
635
			
636
			if (count($infos) > 0) {
636
			if (count($infos) > 0) {
637
				$this->noms_stat_partiel['modification']++;
637
				$this->noms_stat_partiel['modification']++;
638
				$infos = $this->remplacerTabulation($infos);
638
				$infos = $this->remplacerTabulation($infos);
639
				$infos = $this->remplacerSautsDeLigne($infos);
639
				$infos = $this->remplacerSautsDeLigne($infos);
640
				$diff[$id] = $infos;
640
				$diff[$id] = $infos;
641
			}
641
			}
642
		}
642
		}
643
		
643
		
644
		return $diff;
644
		return $diff;
645
	}
645
	}
646
	
646
	
647
	private function ecrireFichierDiffPartiel(&$contenu) {
647
	private function ecrireFichierDiffPartiel(&$contenu) {
648
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_diff'].$this->manuel['suffixe_partiel'].$this->manuel['ext_fichier'];
648
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_diff'].$this->manuel['suffixe_partiel'].$this->manuel['ext_fichier'];
649
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
649
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
650
		
650
		
651
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
651
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
652
			$this->ajouterMessage("Écriture du fichier diff partiel réussie.");
652
			$this->ajouterMessage("Écriture du fichier diff partiel réussie.");
653
		}
653
		}
654
	}
654
	}
655
	
655
	
656
	private function creerFichierMeta() {
656
	private function creerFichierMeta() {
657
		$donnees = array();
657
		$donnees = array();
658
		$donnees = $this->meta;
658
		$donnees = $this->meta;
659
		$donnees['stats'] = $this->noms_stat;
659
		$donnees['stats'] = $this->noms_stat;
660
		$donnees['signature'] = $this->signature_md5;
660
		$donnees['signature'] = $this->signature_md5;
661
		
661
		
662
		$donnees = $this->remplacerTabulation($donnees);
662
		$donnees = $this->remplacerTabulation($donnees);
663
		$donnees = $this->remplacerSautsDeLigne($donnees);
663
		$donnees = $this->remplacerSautsDeLigne($donnees);
664
		
664
		
665
		$meta_tsv =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
665
		$meta_tsv =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
666
		$this->ecrireFichierMeta($meta_tsv);
666
		$this->ecrireFichierMeta($meta_tsv);
667
		return $donnees;
667
		return $donnees;
668
	}
668
	}
669
	
669
	
670
	private function ecrireFichierMeta(&$contenu) {
670
	private function ecrireFichierMeta(&$contenu) {
671
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_meta'].$this->manuel['ext_fichier'];
671
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_meta'].$this->manuel['ext_fichier'];
672
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
672
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
673
		
673
		
674
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
674
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
675
			$this->ajouterMessage("Écriture du fichier meta réussie.");
675
			$this->ajouterMessage("Écriture du fichier meta réussie.");
676
			$this->archiverMetadonnees();
676
			$this->archiverMetadonnees();
677
		}
677
		}
678
	}
678
	}
679
	
679
	
680
	private function creerFichierMetaPartiel(&$donnees) {
680
	private function creerFichierMetaPartiel(&$donnees) {
681
		$donnees['signature'] = $this->signature_md5_partiel;
681
		$donnees['signature'] = $this->signature_md5_partiel;
682
		$donnees['stats'] = $this->noms_stat_partiel;
682
		$donnees['stats'] = $this->noms_stat_partiel;
683
		$donnees['notes'] = trim($this->manuel['notes_partiel'].' '.$donnees['notes']);
683
		$donnees['notes'] = trim($this->manuel['notes_partiel'].' '.$donnees['notes']);
684
		$meta_tsv_partiel =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
684
		$meta_tsv_partiel =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
685
		$this->ecrireFichierMetaPartiel($meta_tsv_partiel);
685
		$this->ecrireFichierMetaPartiel($meta_tsv_partiel);
686
	}
686
	}
687
	
687
	
688
	private function ecrireFichierMetaPartiel(&$contenu) {
688
	private function ecrireFichierMetaPartiel(&$contenu) {
689
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_meta'].$this->manuel['suffixe_partiel'].$this->manuel['ext_fichier'];
689
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['suffixe_meta'].$this->manuel['suffixe_partiel'].$this->manuel['ext_fichier'];
690
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
690
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
691
		
691
		
692
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
692
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
693
			$this->ajouterMessage("Écriture du fichier meta partiel réussie.");
693
			$this->ajouterMessage("Écriture du fichier meta partiel réussie.");
694
		}
694
		}
695
	}
695
	}
696
	
696
	
697
	private function archiverMetadonnees() {
697
	private function archiverMetadonnees() {
698
		$metadonnees = $this->meta;
698
		$metadonnees = $this->meta;
699
		$metadonnees['code'] = $this->meta['acronyme'];
699
		$metadonnees['code'] = $this->meta['acronyme'];
700
		unset($metadonnees['acronyme']);
700
		unset($metadonnees['acronyme']);
701
		$metadonnees['domaine_taxo'] = $this->meta['dom_tax'];
701
		$metadonnees['domaine_taxo'] = $this->meta['dom_tax'];
702
		unset($metadonnees['dom_tax']);
702
		unset($metadonnees['dom_tax']);
703
		$metadonnees['domaine_geo'] = $this->meta['dom_geo'];
703
		$metadonnees['domaine_geo'] = $this->meta['dom_geo'];
704
		unset($metadonnees['dom_geo']);
704
		unset($metadonnees['dom_geo']);
705
		$metadonnees['domaine_nom'] = $this->meta['dom_code'];
705
		$metadonnees['domaine_nom'] = $this->meta['dom_code'];
706
		unset($metadonnees['dom_code']);
706
		unset($metadonnees['dom_code']);
707
		$metadonnees['auteur'] = $this->meta['auteur_principal'];
707
		$metadonnees['auteur'] = $this->meta['auteur_principal'];
708
		unset($metadonnees['auteur_principal']);
708
		unset($metadonnees['auteur_principal']);
709
		$metadonnees['date_production'] = $this->meta['date_prod'];
709
		$metadonnees['date_production'] = $this->meta['date_prod'];
710
		unset($metadonnees['date_prod']);
710
		unset($metadonnees['date_prod']);
711
		$metadonnees['droit'] = $this->meta['copyright'];
711
		$metadonnees['droit'] = $this->meta['copyright'];
712
		unset($metadonnees['copyright']);
712
		unset($metadonnees['copyright']);
713
		
713
		
714
		$ok = $this->metaDao->ajouter($metadonnees);
714
		$ok = $this->metaDao->ajouter($metadonnees);
715
		if ($ok === false) {
715
		if ($ok === false) {
716
			$this->ajouterMessage("L'archivage des métadonnées a échoué.");
716
			$this->ajouterMessage("L'archivage des métadonnées a échoué.");
717
		}
717
		}
718
	}
718
	}
719
	
719
	
720
	private function nettoyerMemoire() {
720
	private function nettoyerMemoire() {
721
		$this->noms = null;
721
		$this->noms = null;
722
		$this->noms_precedents = null;
722
		$this->noms_precedents = null;
723
		$this->noms_stat = null; 
723
		$this->noms_stat = null; 
724
	}
724
	}
725
	
725
	
726
	private function copierManuel() {
726
	private function copierManuel() {
727
		$fichier_source = $this->manuel_chemin.$this->manuel_nom;
727
		$fichier_source = $this->manuel_chemin.$this->manuel_nom;
728
		$fichiers_destination[] = $this->zip_chemin_dossier.$this->manuel_nom;
728
		$fichiers_destination[] = $this->zip_chemin_dossier.$this->manuel_nom;
729
		$fichiers_destination[] = $this->zip_chemin_dossier_partiel.$this->manuel_nom;
729
		$fichiers_destination[] = $this->zip_chemin_dossier_partiel.$this->manuel_nom;
730
		foreach ($fichiers_destination as $destination) {
730
		foreach ($fichiers_destination as $destination) {
731
			if (copy($fichier_source, $destination) === false) {
731
			if (copy($fichier_source, $destination) === false) {
732
				$this->ajouterMessage("La copie du manuel vers '$destination' a échouée.");
732
				$this->ajouterMessage("La copie du manuel vers '$destination' a échouée.");
733
			}
733
			}
734
		}
734
		}
735
	}
735
	}
736
	
736
	
737
	private function creerFichiersZip() {
737
	private function creerFichiersZip() {
738
		$this->zipper($this->zip_chemin_fichier, $this->zip_chemin_dossier);
738
		$this->zipper($this->zip_chemin_fichier, $this->zip_chemin_dossier);
739
		$this->zipper($this->zip_chemin_fichier_partiel, $this->zip_chemin_dossier_partiel);
739
		$this->zipper($this->zip_chemin_fichier_partiel, $this->zip_chemin_dossier_partiel);
740
	}
740
	}
741
	
741
	
742
	private function zipper($fichier_zip, $dossier_a_zipper) {
742
	private function zipper($fichier_zip, $dossier_a_zipper) {
743
		$zip = new PclZip($fichier_zip);
743
		$zip = new PclZip($fichier_zip);
744
		if ($zip->add($dossier_a_zipper, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
744
		if ($zip->add($dossier_a_zipper, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
745
			$e = "La création du fichier zip '$fichier_zip' a échoué avec l'erreur : ".$zip->errorInfo(true);
745
			$e = "La création du fichier zip '$fichier_zip' a échoué avec l'erreur : ".$zip->errorInfo(true);
746
			$this->ajouterMessage($e);
746
			$this->ajouterMessage($e);
747
		}
747
		}
748
	}
748
	}
749
	
749
	
750
	private function nettoyerFichiers() {
750
	private function nettoyerFichiers() {
751
		Fichier::supprimerDossier($this->zip_chemin_dossier);
751
		Fichier::supprimerDossier($this->zip_chemin_dossier);
752
		Fichier::supprimerDossier($this->zip_chemin_dossier_partiel);
752
		Fichier::supprimerDossier($this->zip_chemin_dossier_partiel);
753
	}
753
	}
754
	
754
	
755
	private function traiterMessages() {
755
	private function traiterMessages() {
756
		if (isset($this->messages)) {
756
		if (isset($this->messages)) {
757
			$num_message = 1;
757
			$num_message = 1;
758
			foreach ($this->messages as $message) {
758
			foreach ($this->messages as $message) {
759
				$message['nom'] = 'Message #'.$num_message++;
759
				$message['nom'] = 'Message #'.$num_message++;
760
				$this->resultatDao->ajouter($this->traitement['id_traitement'], $message);
760
				$this->resultatDao->ajouter($this->traitement['id_traitement'], $message);
761
			}
761
			}
762
		}
762
		}
763
	}
763
	}
764
}
764
}
765
?>
765
?>