Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 372 Rev 373
1
<?php
1
<?php
2
/** Exemple lancement:
2
/** Exemple lancement:
3
 * /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php baseflor -a chargerTous
3
 * /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php baseflor -a chargerTous
4
*/
4
*/
5
class Baseflor extends EfloreScript {
5
class Baseflor extends EfloreScript {
6
	
6
	
7
	private $table = null;
7
	private $table = null;
8
	private $nb_erreurs; 
8
	private $nb_erreurs; 
9
	private $erreurs_ligne;
9
	private $erreurs_ligne;
10
	private $ligne_num;
10
	private $ligne_num;
11
	private $colonne_valeur;
11
	private $colonne_valeur;
12
	private $colonne_num;
12
	private $colonne_num;
13
	private $type_bio = array(
13
	private $type_bio = array(
14
		"A","a","B","b","C","c","Cfru","cfru","Csuf","csuf","Ccou","ccou","H","h","Heri",
14
		"A","a","B","b","C","c","Cfru","cfru","Csuf","csuf","Ccou","ccou","H","h","Heri",
15
		"heri","Hsto","hsto","Hces","hces","Hros","hros","Hrub","hrub","Hbis","hbis","G",
15
		"heri","Hsto","hsto","Hces","hces","Hros","hros","Hrub","hrub","Hbis","hbis","G",
16
		"g","Gbul","gbul","Gtub","gtub","Grhi","grhi","T","t","Tver","tver","Test","test");
16
		"g","Gbul","gbul","Gtub","gtub","Grhi","grhi","T","t","Tver","tver","Test","test");
17
	private $ss_type_bio = array("aqua", "lia", "épi", "hpar", "par", "suc", "semp", "cad", "car");
17
	private $ss_type_bio = array("aqua", "lia", "épi", "hpar", "par", "suc", "semp", "cad", "car");
18
	//les deux suivants basés sur valeurs trouvées (--> pas de légende !)
18
	//les deux suivants basés sur valeurs trouvées (--> pas de légende !)
19
	private $signes_seuls = array("?", "x", "x~", "x=","xb","xB","-"); 
19
	private $signes_seuls = array("?", "x", "x~", "x=","xb","xB","-"); 
20
	private $signes_nn_seuls = array("~", "=","b","B");
20
	private $signes_nn_seuls = array("~", "=","b","B");
21
	//paramètres pour lancement de fonctions sur colonnes
21
	//paramètres pour lancement de fonctions sur colonnes
22
	private $verifierIntervalle = array(23 => array(1,9), 24 => array(1,9), 25 => array(1,9),
22
	private $verifierIntervalle = array(23 => array(1,9), 24 => array(1,9), 25 => array(1,9),
23
		26 => array(1,9), 27 => array(1,12), 28 => array(1,9), 29 => array(1,9), 30 => array(0,9),
23
		26 => array(1,9), 27 => array(1,12), 28 => array(1,9), 29 => array(1,9), 30 => array(0,9),
24
		31 => array(1,9), 32 => array(1,9), 33 => array(1,9), 34 => array(1,9), 35 => array(1,9),
24
		31 => array(1,9), 32 => array(1,9), 33 => array(1,9), 34 => array(1,9), 35 => array(1,9),
25
		36 => array(1,12), 37 => array(1,9), 38 => array(1,9), 39 => array(0,9),);
25
		36 => array(1,12), 37 => array(1,9), 38 => array(1,9), 39 => array(0,9),);
26
	private $verifierColonnesBasiques = array(1 =>"/(^[0-9]*\/)|(inconnu)/", 2 => "/(^[AB]?[0-9]+$)|(^nc$)/",
26
	private $verifierColonnesBasiques = array(1 =>"/(^[0-9]*\/)|(inconnu)/", 2 => "/(^[AB]?[0-9]+$)|(^nc$)/",
27
		3 => "/(^[AB]?[0-9]+$)|(^nc$)/", 4 => "/[^0-9]+/", 5 => "/[^0-9]+/", 6 => "/[^0-9]+/", 7 => "/[^0-9]+/",
27
		3 => "/(^[AB]?[0-9]+$)|(^nc$)/", 4 => "/[^0-9]+/", 5 => "/[^0-9]+/", 6 => "/[^0-9]+/", 7 => "/[^0-9]+/",
28
		8 => "/[^0-9]+/", 9 => "/[^0-9]+/", 10 => "/[^0-9]+/", 11 => "/[^0-9]+/", 12 => "/[^0-9]+/",
28
		8 => "/[^0-9]+/", 9 => "/[^0-9]+/", 10 => "/[^0-9]+/", 11 => "/[^0-9]+/", 12 => "/[^0-9]+/",
29
		13 => "/[^0-9]+/", 14 => "/^([1-9]|1[0-2])(\-([1-9]|1[0-2]))*$/", 16 => "/[^0-9]+/", 19 => "/[^0-9]+/", 
29
		13 => "/[^0-9]+/", 14 => "/^([1-9]|1[0-2])(\-([1-9]|1[0-2]))*$/", 16 => "/[^0-9]+/", 19 => "/[^0-9]+/", 
30
		20 => "/[^0-9]+/", 21 => "/[^0-9]+/", 22 => "/[^0-9]+/",  40 => "/[^0-9]+/", 
30
		20 => "/[^0-9]+/", 21 => "/[^0-9]+/", 22 => "/[^0-9]+/",  40 => "/[^0-9]+/", 
31
		41 => "/[^0-9]+/", 42 => "/[^0-9]+/", 43 => "/[^0-9]+/", 44 => "/[^0-9]+/", 45 => "/[^0-9]+/", 
31
		41 => "/[^0-9]+/", 42 => "/[^0-9]+/", 43 => "/[^0-9]+/", 44 => "/[^0-9]+/", 45 => "/[^0-9]+/", 
32
		46 => "/[^0-9]+/", 47 => "/[^0-9]+/", 48 => "/[^0-9]+/", 49 => "/[^0-9]+/", 50 => "/[^0-9]+/", 
32
		46 => "/[^0-9]+/", 47 => "/[^0-9]+/", 48 => "/[^0-9]+/", 49 => "/[^0-9]+/", 50 => "/[^0-9]+/", 
33
		51 => "/[^0-9]+/", 52 => "/[^0-9]+/", 53 => "/[^0-9]+/", 54 => "/[^0-9]+/", 55 => "/[^0-9]+/"
33
		51 => "/[^0-9]+/", 52 => "/[^0-9]+/", 53 => "/[^0-9]+/", 54 => "/[^0-9]+/", 55 => "/[^0-9]+/"
34
		);
34
		);
35
 
35
 
36
	
36
	
37
	public function executer() {
37
	public function executer() {
38
		// Lancement de l'action demandée
38
		// Lancement de l'action demandée
39
		try {
39
		try {
40
			$this->initialiserProjet('baseflor');
40
			$this->initialiserProjet('baseflor');
41
			$cmd = $this->getParametre('a');
41
			$cmd = $this->getParametre('a');
42
		    switch ($cmd) {
42
		    switch ($cmd) {
43
		    	case 'chargerTous' :
43
		    	case 'chargerTous' :
44
		    		$this->supprimerTous();
44
		    		$this->supprimerTous();
45
		    		$this->chargerStructureSql();
45
		    		$this->chargerStructureSql();
46
		    		$this->chargerOntologies();
46
		    		$this->chargerOntologies();
47
		    		$this->verifFichier();
47
		    		$this->verifFichier();
48
	    			if ($this->$nb_erreurs == 0){
48
	    			if ($this->$nb_erreurs == 0){
49
		    			$this->chargerDonnees();
49
		    			$this->chargerDonnees();
50
		    			$This->genererChamps();
50
		    			$This->genererChamps();
51
	    			} else {
51
	    			} else {
52
	    				echo "je ne peux pas charger les données car le fichier comporte des erreurs. 
52
	    				echo "je ne peux pas charger les données car le fichier comporte des erreurs. 
53
	    					Voir le fichier baseflor_verif.txt\n";
53
	    					Voir le fichier baseflor_verif.txt\n";
54
	    			}
54
	    			}
55
	    			break;
55
	    			break;
56
	    		case 'chargerStructureSql' :
56
	    		case 'chargerStructureSql' :
57
	    			$this->chargerStructureSql();
57
	    			$this->chargerStructureSql();
58
	    			break;
58
	    			break;
59
	    		case 'chargerDonnees' :
59
	    		case 'chargerDonnees' :
60
	    			$this->verifFichier();
60
	    			$this->verifFichier();
61
	    			if($this->$nb_erreurs == 0){
61
	    			if($this->$nb_erreurs == 0){
62
	    				$this->chargerDonnees();
62
	    				$this->chargerDonnees();
63
	    			} else {
63
	    			} else {
64
	    				echo "je ne peux pas charger les données car le fichier comporte des erreurs.
64
	    				echo "je ne peux pas charger les données car le fichier comporte des erreurs.
65
	    				Voir le fichier baseflor_verif.txt\n";
65
	    				Voir le fichier baseflor_verif.txt\n";
66
	    			}
66
	    			}
67
	    			break;
67
	    			break;
68
				case 'supprimerTous' :
68
				case 'supprimerTous' :
69
					$this->supprimerTous();
69
					$this->supprimerTous();
70
					break;
70
					break;
71
				case 'chargerOntologies' :
71
				case 'chargerOntologies' :
72
					$this->chargerOntologies();
72
					$this->chargerOntologies();
73
					break;
73
					break;
74
				case 'verifierDonnees' :
74
				case 'verifierDonnees' :
75
					 $this->verifFichier();
75
					 $this->verifFichier();
76
					 break;
76
					 break;
77
				case 'genererChamps' :
77
				case 'genererChamps' :
78
					 $this->genererChpsBDNT();
78
					 $this->genererChpsBDNT();
79
					 $this->genererChpsNumTaxon();
79
					 $this->genererChpsNumTaxon();
80
					 $this->genererChpsNumNomen();
80
					 $this->genererChpsNumNomen();
81
					 break;
81
					 break;
82
				default :
82
				default :
83
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
83
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
84
			}
84
			}
85
		} catch (Exception $e) {
85
		} catch (Exception $e) {
86
			$this->traiterErreur($e->getMessage());
86
			$this->traiterErreur($e->getMessage());
87
		}
87
		}
88
    }
88
    }
89
    
89
    
90
   //-- génération de champs --// 
90
   //-- génération de champs --// 
91
    private function genererChamps(){
91
    private function genererChamps(){
92
    	$this->genererChpsBDNT();
92
    	$this->genererChpsBDNT();
93
    	$this->genererChpsNumTaxon();
93
    	$this->genererChpsNumTaxon();
94
    	$this->genererChpsNumNomen();
94
    	$this->genererChpsNumNomen();
95
    }
95
    }
96
    
96
    
97
    private function genererChpsBDNT(){
97
    private function genererChpsBDNT(){
98
    	$this->initialiserGenerationChamps();
98
    	$this->initialiserGenerationChamps();
99
    	$this->preparerTablePrChpsBDNT();
99
    	$this->preparerTablePrChpsBDNT();
100
    	$resultats = $this->recupererTuplesNumsOriginels();
100
    	$resultats = $this->recupererTuplesNumsOriginels();
101
    	$bdnt = array();
101
    	$bdnt = array();
102
    	foreach ($resultats as $chps => $res) {
102
    	foreach ($resultats as $chps => $res) {
103
    		$cle = $res['cle'];
103
    		$cle = $res['cle'];
104
    		$nno = $res['num_nomen_originel'];
104
    		$nno = $res['num_nomen_originel'];
105
    		$nto = $res['num_taxon_originel'];
105
    		$nto = $res['num_taxon_originel'];
106
    		if ( (preg_match("/^([AB])[0-9]+$/", $nno, $retour)) || (preg_match("/^([AB])[0-9]+$/", $nto, $retour)) ){
106
    		if ( (preg_match("/^([AB])[0-9]+$/", $nno, $retour)) || (preg_match("/^([AB])[0-9]+$/", $nto, $retour)) ){
107
    			if($retour[1]=='A'){
107
    			if($retour[1]=='A'){
108
    				$bdnt[$cle]= "BDAFX";
108
    				$bdnt[$cle]= "BDAFX";
109
    			}else{
109
    			}else{
110
    				$bdnt[$cle]= "BDBFX";
110
    				$bdnt[$cle]= "BDBFX";
111
    			}
111
    			}
112
    			
112
    			
113
    		}elseif(($nno == 'nc') && ($nto == 'nc')){
113
    		}elseif(($nno == 'nc') && ($nto == 'nc')){
114
    			$bdnt[$cle]= "nc";
114
    			$bdnt[$cle]= "nc";
115
    		}else{
115
    		}else{
116
    			$bdnt[$cle]= "BDTFX";
116
    			$bdnt[$cle]= "BDTFX";
117
    		}
117
    		}
118
    		
118
    		
119
    	}
119
    	}
120
    	$this->remplirChamps($bdnt, "BDNT");
120
    	$this->remplirChamps($bdnt, "BDNT");
121
    }
121
    }
122
    
122
    
123
    private function genererChpsNumTaxon(){
123
    private function genererChpsNumTaxon(){
124
    	$this->initialiserGenerationChamps();
124
    	$this->initialiserGenerationChamps();
125
    	$this->preparerTablePrChpsNumTaxon();
125
    	$this->preparerTablePrChpsNumTaxon();
126
    	$resultats = $this->recupererTuplesNumsOriginels();
126
    	$resultats = $this->recupererTuplesNumsOriginels();
127
    	$num_taxon= array();
127
    	$num_taxon= array();
128
    	foreach ($resultats as $chps => $res) {
128
    	foreach ($resultats as $chps => $res) {
129
    		$cle = $res['cle'];
129
    		$cle = $res['cle'];
130
    	  	$nto = $res['num_taxon_originel'];
130
    	  	$nto = $res['num_taxon_originel'];
131
    		if  (preg_match("/^[AB]([0-9]+)$/", $nto, $retour)){
131
    		if  (preg_match("/^[AB]([0-9]+)$/", $nto, $retour)){
132
    			$num_taxon[$cle]= intval($retour[1]);
132
    			$num_taxon[$cle]= intval($retour[1]);
133
    		}elseif($nto == 'nc'){
133
    		}elseif($nto == 'nc'){
134
    			$num_taxon[$cle]= 0;
134
    			$num_taxon[$cle]= 0;
135
    		}else{
135
    		}else{
136
    			$num_taxon[$cle]= intval($nto);
136
    			$num_taxon[$cle]= intval($nto);
137
    		}
137
    		}
138
    
138
    
139
    	}
139
    	}
140
    	$this->remplirChamps($num_taxon, "num_taxon");
140
    	$this->remplirChamps($num_taxon, "num_taxon");
141
    }
141
    }
142
    
142
    
143
    private function genererChpsNumNomen(){
143
    private function genererChpsNumNomen(){
144
    	$this->initialiserGenerationChamps();
144
    	$this->initialiserGenerationChamps();
145
    	$this->preparerTablePrChpsNumNomen();
145
    	$this->preparerTablePrChpsNumNomen();
146
    	$resultats = $this->recupererTuplesNumsOriginels();
146
    	$resultats = $this->recupererTuplesNumsOriginels();
147
    	$num_nomen= array();
147
    	$num_nomen= array();
148
    	foreach ($resultats as $chps => $res) {
148
    	foreach ($resultats as $chps => $res) {
149
    		$cle = $res['cle'];
149
    		$cle = $res['cle'];
150
    		$nno = $res['num_nomen_originel'];
150
    		$nno = $res['num_nomen_originel'];
151
    		if  (preg_match("/^[AB]([0-9]+)$/", $nno, $retour)){
151
    		if  (preg_match("/^[AB]([0-9]+)$/", $nno, $retour)){
152
				$num_nomen[$cle]= intval($retour[1]);
152
				$num_nomen[$cle]= intval($retour[1]);
153
    		}elseif($nno == 'nc'){
153
    		}elseif($nno == 'nc'){
154
    			$num_nomen[$cle]= 0;
154
    			$num_nomen[$cle]= 0;
155
    		}else{
155
    		}else{
156
    			$num_nomen[$cle]=intval($nno);
156
    			$num_nomen[$cle]=intval($nno);
157
    		}
157
    		}
158
    	}
158
    	}
159
    	$this->remplirChamps($num_nomen, "num_nomen");
159
    	$this->remplirChamps($num_nomen, "num_nomen");
160
    }
160
    }
161
    
161
    
162
     private function remplirChamps($champs, $nom_colonne) {
162
     private function remplirChamps($champs, $nom_colonne) {
163
    	foreach ($champs as $cle => $val) {
163
    	foreach ($champs as $cle => $val) {
164
    		$val = $this->getBdd()->proteger($val);
164
    		$val = $this->getBdd()->proteger($val);
165
    		$requete = "UPDATE {$this->table} SET $nom_colonne = $val WHERE cle = $cle ";
165
    		$requete = "UPDATE {$this->table} SET $nom_colonne = $val WHERE cle = $cle ";
166
    		$resultat = $this->getBdd()->requeter($requete);
166
    		$resultat = $this->getBdd()->requeter($requete);
167
    		if ($resultat === false) {
167
    		if ($resultat === false) {
168
    			throw new Exception("Erreur d'insertion pour le tuple clé = ".$cle);
168
    			throw new Exception("Erreur d'insertion pour le tuple clé = ".$cle);
169
    		}
169
    		}
170
    		$this->afficherAvancement("Insertion des valeurs pour ".$nom_colonne." dans la base en cours");
170
    		$this->afficherAvancement("Insertion des valeurs pour ".$nom_colonne." dans la base en cours");
171
    	}
171
    	}
172
    	echo "\n";
172
    	echo "\n";
173
    }
173
    }
174
    
174
    
175
    
175
    
176
 
176
 
177
    
177
    
178
    private function initialiserGenerationChamps() {
178
    private function initialiserGenerationChamps() {
179
    	$this->table = Config::get('tables.donnees');
179
    	$this->table = Config::get('tables.donnees');
180
    }
180
    }
181
    
181
    
182
    private function preparerTablePrChpsBDNT() {
182
    private function preparerTablePrChpsBDNT() {
183
    	$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'BDNT' ";
183
    	$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'BDNT' ";
184
    	$resultat = $this->getBdd()->recuperer($requete);
184
    	$resultat = $this->getBdd()->recuperer($requete);
185
    	if ($resultat === false) {
185
    	if ($resultat === false) {
186
    		$requete = 	"ALTER TABLE {$this->table} ".
186
    		$requete = 	"ALTER TABLE {$this->table} ".
187
    				'ADD BDNT VARCHAR( 6 ) '.
187
    				'ADD BDNT VARCHAR( 6 ) '.
188
    				'CHARACTER SET utf8 COLLATE utf8_general_ci'.
188
    				'CHARACTER SET utf8 COLLATE utf8_general_ci'.
189
    				' NOT NULL AFTER catminat_code ';
189
    				' NOT NULL AFTER catminat_code ';
190
    		$this->getBdd()->requeter($requete);
190
    		$this->getBdd()->requeter($requete);
191
    	}
191
    	}
192
    }
192
    }
193
    
193
    
194
    private function preparerTablePrChpsNumTaxon() {
194
    private function preparerTablePrChpsNumTaxon() {
195
    	$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'num_taxon' ";
195
    	$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'num_taxon' ";
196
    	$resultat = $this->getBdd()->recuperer($requete);
196
    	$resultat = $this->getBdd()->recuperer($requete);
197
    	if ($resultat === false) {
197
    	if ($resultat === false) {
198
    		$requete = 	"ALTER TABLE {$this->table} ".
198
    		$requete = 	"ALTER TABLE {$this->table} ".
199
        				'ADD num_taxon INT( 10 ) NOT NULL'.
199
        				'ADD num_taxon INT( 10 ) NOT NULL'.
200
        				'BEFORE num_taxon_originel';
200
        				'BEFORE num_taxon_originel';
201
    		$this->getBdd()->requeter($requete);
201
    		$this->getBdd()->requeter($requete);
202
    	}
202
    	}
203
    }
203
    }
204
    
204
    
205
    private function preparerTablePrChpsNumNomen() {
205
    private function preparerTablePrChpsNumNomen() {
206
    	$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'num_nomen' ";
206
    	$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'num_nomen' ";
207
    	$resultat = $this->getBdd()->recuperer($requete);
207
    	$resultat = $this->getBdd()->recuperer($requete);
208
    	if ($resultat === false) {
208
    	if ($resultat === false) {
209
    		$requete = 	"ALTER TABLE {$this->table} ".
209
    		$requete = 	"ALTER TABLE {$this->table} ".
210
            				'ADD num_nomen INT( 10 ) NOT NULL'.
210
            				'ADD num_nomen INT( 10 ) NOT NULL'.
211
            				'BEFORE num_taxon_originel';
211
            				'BEFORE num_taxon_originel';
212
    		$this->getBdd()->requeter($requete);
212
    		$this->getBdd()->requeter($requete);
213
    	}
213
    	}
214
    }
214
    }
215
    private function recupererTuplesNumsOriginels(){
215
    private function recupererTuplesNumsOriginels(){
216
    	$requete = 'SELECT cle, num_taxon_originel, num_nomen_originel '.
216
    	$requete = 'SELECT cle, num_taxon_originel, num_nomen_originel '.
217
    					"FROM {$this->table} ";
217
    					"FROM {$this->table} ";
218
    	$resultat = $this->getBdd()->recupererTous($requete);
218
    	$resultat = $this->getBdd()->recupererTous($requete);
219
    	return $resultat;
219
    	return $resultat;
220
    }
220
    }
221
    
221
    
222
    //-- chargements, suppression, exécution  --//
222
    //-- chargements, suppression, exécution  --//
223
    
223
    
224
    private function chargerOntologies() {
224
    private function chargerOntologies() {
225
    	$chemin = Config::get('chemins.ontologies');
225
    	$chemin = Config::get('chemins.ontologies');
226
    	$table = Config::get('tables.ontologies');
226
    	$table = Config::get('tables.ontologies');
227
    	$requete = "LOAD DATA INFILE '$chemin' ".
227
    	$requete = "LOAD DATA INFILE '$chemin' ".
228
    			"REPLACE INTO TABLE $table ".
228
    			"REPLACE INTO TABLE $table ".
229
    			'CHARACTER SET utf8 '.
229
    			'CHARACTER SET utf8 '.
230
    			'FIELDS '.
230
    			'FIELDS '.
231
    			"	TERMINATED BY '\t' ".
231
    			"	TERMINATED BY '\t' ".
232
    			"	ENCLOSED BY '' ".
232
    			"	ENCLOSED BY '' ".
233
    			"	ESCAPED BY '\\\' "
233
    			"	ESCAPED BY '\\\' "
234
    			;
234
    			;
235
    	$this->getBdd()->requeter($requete);
235
    	$this->getBdd()->requeter($requete);
236
    }
236
    }
237
    
237
    
238
    protected function chargerStructureSql() {
238
    protected function chargerStructureSql() {
239
    	$contenuSql = $this->recupererContenu(Config::get('chemins.structureSql'));
239
    	$contenuSql = $this->recupererContenu(Config::get('chemins.structureSql'));
240
    	$this->executerScripSql($contenuSql);
240
    	$this->executerScripSql($contenuSql);
241
    }
241
    }
242
    
242
    
243
    
243
    
244
    protected function executerScripSql($sql) {
244
    protected function executerScripSql($sql) {
245
    	$requetes = Outils::extraireRequetes($sql);
245
    	$requetes = Outils::extraireRequetes($sql);
246
    	foreach ($requetes as $requete) {
246
    	foreach ($requetes as $requete) {
247
    		$this->getBdd()->requeter($requete);
247
    		$this->getBdd()->requeter($requete);
248
    	}
248
    	}
249
    }
249
    }
250
 
250
 
251
    private function chargerDonnees() {
251
    private function chargerDonnees() {
252
    	$table = Config::get('tables.donnees');
252
    	$table = Config::get('tables.donnees');
253
    	$requete = "LOAD DATA INFILE '".Config::get('chemins.donnees')."' ".
253
    	$requete = "LOAD DATA INFILE '".Config::get('chemins.donnees')."' ".
254
        				"REPLACE INTO TABLE $table ".
254
        				"REPLACE INTO TABLE $table ".
255
        				'CHARACTER SET utf8 '.
255
        				'CHARACTER SET utf8 '.
256
        				'FIELDS '.
256
        				'FIELDS '.
257
        				"	TERMINATED BY '\t' ".
257
        				"	TERMINATED BY '\t' ".
258
        				"	ENCLOSED BY '' ".
258
        				"	ENCLOSED BY '' ".
259
        				"	ESCAPED BY '\\\'";
259
        				"	ESCAPED BY '\\\'";
260
    	$this->getBdd()->requeter($requete);
260
    	$this->getBdd()->requeter($requete);
261
    }
261
    }
262
    
262
    
263
    private function supprimerTous() {
263
    private function supprimerTous() {
264
    	$requete = "DROP TABLE IF EXISTS baseflor_meta, baseflor_v2012_03_19";
264
    	$requete = "DROP TABLE IF EXISTS baseflor_meta, baseflor_v2012_03_19";
265
    	$this->getBdd()->requeter($requete);
265
    	$this->getBdd()->requeter($requete);
266
    }
266
    }
267
	
267
	
268
    
268
    
269
    //-- vérifications de données  --//
269
    //-- vérifications de données  --//
270
    
270
    
271
    private function verifierSiVide(){
271
    private function verifierSiVide(){
272
    	$bool=false;
272
    	$bool=false;
273
    	if ( $this->colonne_valeur  == "" ){
273
    	if ( $this->colonne_valeur  == "" ){
274
    		$bool=true;
274
    		$bool=true;
275
    	}
275
    	}
276
    	return $bool;
276
    	return $bool;
277
    }
277
    }
278
    
278
    
279
    
279
    
280
    private function verifierIntervallesTous($valeur){
280
    private function verifierIntervallesTous($valeur){
281
    	$intervalle=$this->verifierIntervalle[$this->colonne_num];
281
    	$intervalle=$this->verifierIntervalle[$this->colonne_num];
282
      	$this->verifierIntervalleChiffres($intervalle[0], $intervalle[1],$valeur);
282
      	$this->verifierIntervalleChiffres($intervalle[0], $intervalle[1],$valeur);
283
    }
283
    }
284
    
284
    
285
 
285
 
286
    private function verifierIntervalleChiffres($mini, $max, $valeur){
286
    private function verifierIntervalleChiffres($mini, $max, $valeur){
287
    	 if (( ($valeur < $mini) || ($valeur > $max) ) && ($valeur != "")){
287
    	 if (( ($valeur < $mini) || ($valeur > $max) ) && ($valeur != "")){
288
    		$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
288
    		$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
289
   			$this->nb_erreurs++;
289
   			$this->nb_erreurs++;
290
    	}
290
    	}
291
    	
291
    	
292
    }
292
    }
293
 
293
 
294
  
294
  
295
    private function verifierValeursIndic(){
295
    private function verifierValeursIndic(){
296
    	if (( preg_match("/^([^0-9])*([0-9]+)([^0-9])*$/", $this->colonne_valeur,$retour) == 1  )){
296
    	if (( preg_match("/^([^0-9])*([0-9]+)([^0-9])*$/", $this->colonne_valeur,$retour) == 1  )){
297
    		$this->verifierIntervallesTous($retour[2]);
297
    		$this->verifierIntervallesTous($retour[2]);
298
    		if((isset($retour[3]))&&(!(in_array($retour[3], $this->signes_nn_seuls))) ){
298
    		if((isset($retour[3]))&&(!(in_array($retour[3], $this->signes_nn_seuls))) ){
299
    			$this->erreurs_ligne[$this->colonne_num] =$this->colonne_valeur;
299
    			$this->erreurs_ligne[$this->colonne_num] =$this->colonne_valeur;
300
    			$this->nb_erreurs++;
300
    			$this->nb_erreurs++;
301
    		}	
301
    		}	
302
    		if(($retour[1] != "-")&&($retour[1]!="") ){
302
    		if(($retour[1] != "-")&&($retour[1]!="") ){
303
    			$this->erreurs_ligne[$this->colonne_num] =$this->colonne_valeur;
303
    			$this->erreurs_ligne[$this->colonne_num] =$this->colonne_valeur;
304
    			$this->nb_erreurs++;
304
    			$this->nb_erreurs++;
305
    			if($this->ligne_num==3){
305
    			if($this->ligne_num==3){
306
    			}
306
    			}
307
    		}	
307
    		}	
308
    	}elseif(!(in_array( $this->colonne_valeur, $this->signes_seuls))&& !($this->verifierSiVide())) {
308
    	}elseif(!(in_array( $this->colonne_valeur, $this->signes_seuls))&& !($this->verifierSiVide())) {
309
    			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
309
    			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
310
    			$this->nb_erreurs++;
310
    			$this->nb_erreurs++;
311
    		}
311
    		}
312
    }
312
    }
313
 
313
 
314
 private function verifierTypeBio(){
314
 private function verifierTypeBio(){
315
 	if (( preg_match("/(.+)\((.+)\)$/", $this->colonne_valeur,$retour) == 1  )){
315
 	if (( preg_match("/(.+)\((.+)\)$/", $this->colonne_valeur,$retour) == 1  )){
316
 		$this->verifType_SsType($retour[1]);
316
 		$this->verifType_SsType($retour[1]);
317
 		$this->verifType_SsType($retour[2]);
317
 		$this->verifType_SsType($retour[2]);
318
 	}else{
318
 	}else{
319
 		$this->verifType_SsType($this->colonne_valeur);
319
 		$this->verifType_SsType($this->colonne_valeur);
320
 	}
320
 	}
321
 }
321
 }
322
 
322
 
323
    private function verifType_SsType($chaine_a_verif){
323
    private function verifType_SsType($chaine_a_verif){
324
    	//verifie type
324
    	//verifie type
325
    	if(( preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé]+[^\-])$/", $chaine_a_verif, $retour) == 1  )){
325
    	if(( preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé]+[^\-])$/", $chaine_a_verif, $retour) == 1  )){
326
    		$type=$retour[1];
326
    		$type=$retour[1];
327
    		if(isset($retour[3])){
327
    		if(isset($retour[3])){
328
    			$type=$retour[3];
328
    			$type=$retour[3];
329
    		}
329
    		}
330
    		 if(!(in_array($type, $this->type_bio))) {
330
    		 if(!(in_array($type, $this->type_bio))) {
331
    			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
331
    			$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
332
    			$this->nb_erreurs++;
332
    			$this->nb_erreurs++;
333
    		}
333
    		}
334
    		//verifie sous_type(s)
334
    		//verifie sous_type(s)
335
    		if ($retour[2]!=""){
335
    		if ($retour[2]!=""){
336
    			$ss_type[0]=$retour[2];
336
    			$ss_type[0]=$retour[2];
337
    			if (( preg_match("/\-/", $ss_type[0])) == 1 ){
337
    			if (( preg_match("/\-/", $ss_type[0])) == 1 ){
338
    				$ss_type = preg_split("/\-/", $retour[2]);
338
    				$ss_type = preg_split("/\-/", $retour[2]);
339
    			}
339
    			}
340
    			foreach($ss_type as $sst){
340
    			foreach($ss_type as $sst){
341
    				if(!(in_array($sst, $this->ss_type_bio))) {
341
    				if(!(in_array($sst, $this->ss_type_bio))) {
342
    					$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
342
    					$this->erreurs_ligne[$this->colonne_num] = $this->colonne_valeur;
343
    					$this->nb_erreurs++;
343
    					$this->nb_erreurs++;
344
    				}
344
    				}
345
    			}
345
    			}
346
    		}
346
    		}
347
    	}
347
    	}
348
    }
348
    }
349
 
349
 
350
    private function verifierColonne($chaine){
350
    private function verifierColonne($chaine){
351
    	if ( ( preg_match($chaine, $this->colonne_valeur) == 0 ) && !($this->verifierSiVide()) ){
351
    	if ( ( preg_match($chaine, $this->colonne_valeur) == 0 ) && !($this->verifierSiVide()) ){
352
    		$this->erreurs_ligne[$this->colonne_num]=$this->colonne_valeur;
352
    		$this->erreurs_ligne[$this->colonne_num]=$this->colonne_valeur;
353
    		$this->nb_erreurs++;
353
    		$this->nb_erreurs++;
354
    	}
354
    	}
355
    }
355
    }
356
    
356
    
357
    //vérifie par colonnes les erreurs d'une ligne 
357
    //vérifie par colonnes les erreurs d'une ligne 
358
   private function verifErreursLignes($colonne_array){
358
   private function verifErreursLignes($colonne_array){
359
   	$this->erreurs_ligne=array();
359
   	$this->erreurs_ligne=array();
360
     for ($this->colonne_num = 0; $this->colonne_num < count($colonne_array); $this->colonne_num++){
360
     for ($this->colonne_num = 0; $this->colonne_num < count($colonne_array); $this->colonne_num++){
361
     	 if ( isset($colonne_array) ){
361
     	 if ( isset($colonne_array) ){
362
     	 	$this->colonne_valeur = $colonne_array[$this->colonne_num];
362
     	 	$this->colonne_valeur = $colonne_array[$this->colonne_num];
363
   			if ( (( ($this->colonne_num > 0) && ($this->colonne_num < 15) ) || ( $this->colonne_num == 16 )  
363
   			if ( (( ($this->colonne_num > 0) && ($this->colonne_num < 15) ) || ( $this->colonne_num == 16 )  
364
   				|| (($this->colonne_num > 18 ) && ( $this->colonne_num < 23 ) ) 
364
   				|| (($this->colonne_num > 18 ) && ( $this->colonne_num < 23 ) ) 
365
   				||  ( $this->colonne_num > 39 ))  ){
365
   				||  ( $this->colonne_num > 39 ))  ){
366
   				$motif = $this->verifierColonnesBasiques[$this->colonne_num];
366
   				$motif = $this->verifierColonnesBasiques[$this->colonne_num];
367
   			  	$this->verifierColonne($motif);
367
   			  	$this->verifierColonne($motif);
368
   			}elseif ( $this->colonne_num == 15 ){
368
   			}elseif ( $this->colonne_num == 15 ){
369
   				$this->verifierTypeBio();
369
   				$this->verifierTypeBio();
370
   			} elseif (($this->colonne_num > 22 ) && ( $this->colonne_num < 33 )){
370
   			} elseif (($this->colonne_num > 22 ) && ( $this->colonne_num < 33 )){
371
   				$this->verifierIntervallesTous($this->colonne_valeur);   				
371
   				$this->verifierIntervallesTous($this->colonne_valeur);   				
372
   			}elseif (( $this->colonne_num > 32) && ( $this->colonne_num < 41)){
372
   			}elseif (( $this->colonne_num > 32) && ( $this->colonne_num < 41)){
373
   				  $this->verifierValeursIndic();
373
   				  $this->verifierValeursIndic();
374
   			}
374
   			}
375
   		} else {
375
   		} else {
376
   			echo "ligne ".$this->ligne_num.": pas de tabulation  \n ";
376
   			echo "ligne ".$this->ligne_num.": pas de tabulation  \n ";
377
   		}	
377
   		}	
378
   }
378
   }
379
   
379
   
380
}
380
}
381
    
381
    
382
    //verifie la cohérence des valeurs des colonnes 
382
    //verifie la cohérence des valeurs des colonnes 
383
    private function verifFichier(){
383
    private function verifFichier(){
384
    	$dernier_nb_erreur =0;
384
    	$dernier_nb_erreur =0;
-
 
385
    	if (file_exists(Config::get('chemins.donnees_verif'))) {
385
    	unlink(Config::get('chemins.donnees_verif'));
386
    		unlink(Config::get('chemins.donnees_verif'));
-
 
387
    	}
386
    	$fichier = fopen(Config::get('chemins.donnees'), "r");
388
    	$fichier = fopen(Config::get('chemins.donnees'), "r");
387
    	$fichier2 = fopen(Config::get('chemins.donnees_verif'), "w");
389
    	$fichier2 = fopen(Config::get('chemins.donnees_verif'), "w");
388
    	$this->valeurs=array();
390
    	$this->valeurs=array();
389
    	$this->nb_erreurs=0;
391
    	$this->nb_erreurs=0;
390
    	if ( ($fichier != false) && ($fichier2 != false) ){
392
    	if ( ($fichier != false) && ($fichier2 != false) ){
391
    		$this->ligne_num=1;
393
    		$this->ligne_num=1;
392
    		while ( !feof($fichier) ) {
394
    		while ( !feof($fichier) ) {
393
    			if ($this->ligne_num == 1){
395
    			if ($this->ligne_num == 1){
394
    				fputs($fichier2," !!! REGARDEZ LES COLONNES DANS NUMERO_COLONNES_IMPORTANT.TXT.\n");
396
    				fputs($fichier2," !!! REGARDEZ LES COLONNES DANS NUMERO_COLONNES_IMPORTANT.TXT.\n");
395
    			}
397
    			}
396
    			$this->ligne_num++;
398
    			$this->ligne_num++;
397
    			$ligne = fgets($fichier);
399
    			$ligne = fgets($fichier);
398
    			$col = preg_split("/	/", $ligne);
400
    			$col = preg_split("/	/", $ligne);
399
    			$this->verifErreursLignes($col);
401
    			$this->verifErreursLignes($col);
400
    			//rédaction du fichier de vérif
402
    			//rédaction du fichier de vérif
401
    			if(count($this->nb_erreurs)!= 0){
403
    			if(count($this->nb_erreurs)!= 0){
402
    				if($dernier_nb_erreur != $this->nb_erreurs){
404
    				if($dernier_nb_erreur != $this->nb_erreurs){
403
    					$dernier_nb_erreur = $this->nb_erreurs;
405
    					$dernier_nb_erreur = $this->nb_erreurs;
404
    					fputs($fichier2," \n erreurs sur la ligne".$this->ligne_num."\n");
406
    					fputs($fichier2," \n erreurs sur la ligne".$this->ligne_num."\n");
405
    					foreach ($this->erreurs_ligne as $cle => $v){
407
    					foreach ($this->erreurs_ligne as $cle => $v){
406
    						fputs($fichier2,"colonne ".$cle." : ".$v." - ");
408
    						fputs($fichier2,"colonne ".$cle." : ".$v." - ");
407
    					}
409
    					}
408
    				}
410
    				}
409
    			} 
411
    			} 
410
    		}  
412
    		}  
411
    	}
413
    	}
412
    	if ($this->nb_erreurs == 0){
414
    	if ($this->nb_erreurs == 0){
413
    		fputs($fichier2,"/n il n'y a pas d'erreurs./n");
415
    		fputs($fichier2,"/n il n'y a pas d'erreurs./n");
414
    	}
416
    	}
415
    	echo $this->nb_erreurs."erreurs";
417
    	echo $this->nb_erreurs."erreurs";
416
    	fclose($fichier);
418
    	fclose($fichier);
417
    	fclose($fichier2);
419
    	fclose($fichier2);
418
    }
420
    }
419
 
421
 
420
 
422
 
421
    
423
    
422
}
424
}
423
 
425
 
424
?>
426
?>