| 417 | aurelien | 1 | <?php
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 | // In : utf8
 | 
        
           |  |  | 4 | // Out : utf8
 | 
        
           |  |  | 5 |   | 
        
           | 483 | david | 6 |   | 
        
           |  |  | 7 | // TODO : traiter image multilignes
 | 
        
           | 540 | david | 8 | // TODO : doublons
 | 
        
           | 483 | david | 9 |   | 
        
           | 480 | david | 10 | /*
 | 
        
           | 417 | aurelien | 11 |   | 
        
           | 480 | david | 12 | Octobre 2010 David Delon.
 | 
        
           |  |  | 13 | Import d'observations dans le carnet en ligne à partir d'un fichier excel chargé par l'utilisateur
 | 
        
           |  |  | 14 | et liaison d'images déjà chargee aux observations ainsi crées.
 | 
        
           | 417 | aurelien | 15 |   | 
        
           | 480 | david | 16 | Nom des colonnes imposé, mais présence de toutes les colonnes non obligatoires, ordre non imposé
 | 
        
           |  |  | 17 | Aucune valeur dans les colonnes n'est obligatoire
 | 
        
           |  |  | 18 | Pour une ligne donnée, si tous les champs vides on ne fait rien, ou si seul le champ image est présent.
 | 
        
           |  |  | 19 | Si la seule différence entre deux lignes est la valeur de la colonne image, on considère que c'est la même observation à laquelle on associe plusieurs images.
 | 
        
           |  |  | 20 | Si au moins deux lignes (ou plus) sont complètement identiques on prend en compte une seule ligne (les doublons sont éliminés).
 | 
        
           | 445 | david | 21 |   | 
        
           | 480 | david | 22 | */
 | 
        
           | 445 | david | 23 |   | 
        
           | 480 | david | 24 |   | 
        
           |  |  | 25 | // Nom des colonnes
 | 
        
           |  |  | 26 |   | 
        
           | 445 | david | 27 | define('COMMUNE','commune'); // soit un nom de commune, soit un code INSEE (5 chiffres), ou "nom de commune (numero departement)"
 | 
        
           |  |  | 28 | define('LIEUDIT','lieu-dit'); // Texte libre
 | 
        
           |  |  | 29 | define('STATION','station'); // Texte libre
 | 
        
           |  |  | 30 | define('MILIEU','milieu'); // Texte libre
 | 
        
           |  |  | 31 | define('LATITUDE','latitude'); // En decimal systeme WGS84
 | 
        
           |  |  | 32 | define('LONGITUDE','longitude'); // En decimal systeme WGS84
 | 
        
           |  |  | 33 | define('NOTES','notes'); // Texte libre
 | 
        
           |  |  | 34 | define('DATEOBS','date'); // date au format jj/mm/aaaa
 | 
        
           |  |  | 35 | define('ESPECE','espece'); // texte libre, nom latin, ou code nomenclatural (format BDNFFnn999999)
 | 
        
           |  |  | 36 | define('IMAGE','image'); //  nom des fichiers images préalablement uploadés sur le CEL séparés par des "/"
 | 
        
           | 540 | david | 37 | define('DEPARTEMENT','departement'); //  Texte libre
 | 
        
           | 760 | aurelien | 38 | define('TRANSMETTRE','transmettre'); //  "1" ou "oui", toute autre valeur (y compris vide) sera consideree comme "non""
 | 
        
           | 445 | david | 39 |   | 
        
           | 540 | david | 40 |   | 
        
           | 480 | david | 41 | // Resultat de l'analyse d'une ligne
 | 
        
           | 445 | david | 42 | define('LIGNE_VIDE',1); //
 | 
        
           |  |  | 43 | define('LIGNE_NORMALE',2); //
 | 
        
           |  |  | 44 | define('LIGNE_IMAGE_SEULEMENT',3); //
 | 
        
           |  |  | 45 |   | 
        
           | 540 | david | 46 | // Parser de Nom
 | 
        
           |  |  | 47 | include('NameParser.php');
 | 
        
           | 445 | david | 48 |   | 
        
           | 417 | aurelien | 49 | Class InventoryImportExcel extends DBAccessor  {
 | 
        
           |  |  | 50 |   | 
        
           | 445 | david | 51 | // Element constituant une observation
 | 
        
           | 417 | aurelien | 52 |   | 
        
           | 760 | aurelien | 53 | 	var $format_observation=array(COMMUNE ,LIEUDIT ,STATION , DEPARTEMENT, MILIEU ,LATITUDE ,LONGITUDE ,NOTES ,DATEOBS ,ESPECE ,TRANSMETTRE, IMAGE );
 | 
        
           | 480 | david | 54 |   | 
        
           |  |  | 55 | // Fichier configuration
 | 
        
           | 417 | aurelien | 56 | 	var $config;
 | 
        
           | 480 | david | 57 |   | 
        
           |  |  | 58 | // Encapsulation classe lecture fichier excel
 | 
        
           | 417 | aurelien | 59 | 	var $extendExcelReader;
 | 
        
           |  |  | 60 |   | 
        
           | 540 | david | 61 | // Dernier numero d'ordre utilise
 | 
        
           |  |  | 62 | 	var $dernier_ordre=1;
 | 
        
           | 760 | aurelien | 63 |   | 
        
           |  |  | 64 | 	var $cpt_images_liees=0;
 | 
        
           | 540 | david | 65 |   | 
        
           | 480 | david | 66 | /**
 | 
        
           |  |  | 67 |  Constructeur
 | 
        
           |  |  | 68 | **/
 | 
        
           | 417 | aurelien | 69 | 	function InventoryImportExcel($config) {
 | 
        
           |  |  | 70 |   | 
        
           |  |  | 71 | 		$this->config=$config;
 | 
        
           |  |  | 72 | 		// Pas d'heritage multiple en php :(
 | 
        
           |  |  | 73 |   | 
        
           |  |  | 74 | 		$this->extendExcelReader = new ExcelReader();
 | 
        
           |  |  | 75 | 		$this->extendExcelReader->initExcelReader();
 | 
        
           |  |  | 76 | 	}
 | 
        
           |  |  | 77 |   | 
        
           | 480 | david | 78 | /**
 | 
        
           |  |  | 79 |  Sur post
 | 
        
           |  |  | 80 | **/
 | 
        
           | 445 | david | 81 | 	function createElement($pairs) {
 | 
        
           | 417 | aurelien | 82 |   | 
        
           |  |  | 83 |   | 
        
           | 480 | david | 84 | 		$pairs['utilisateur']=$_POST['identifiant'];
 | 
        
           | 417 | aurelien | 85 |   | 
        
           | 540 | david | 86 |         session_start();
 | 
        
           |  |  | 87 |         $this->controleUtilisateur($pairs['utilisateur']);
 | 
        
           | 480 | david | 88 |   | 
        
           | 417 | aurelien | 89 |   | 
        
           | 540 | david | 90 |         foreach($_FILES as $file) { // C'est le plus simple
 | 
        
           |  |  | 91 |             $infos_fichier = $file ;
 | 
        
           |  |  | 92 |         }
 | 
        
           | 417 | aurelien | 93 |   | 
        
           | 480 | david | 94 |   | 
        
           |  |  | 95 | // Chargement tableau en memoire
 | 
        
           | 445 | david | 96 | 		$data = new Spreadsheet_Excel_Reader($infos_fichier['tmp_name'], false); // false : pour menager la memoire.
 | 
        
           | 480 | david | 97 | 		$arr = array();
 | 
        
           | 445 | david | 98 |   | 
        
           |  |  | 99 | 		$rowcount=$data->rowcount(0);
 | 
        
           |  |  | 100 | 		$colcount=$data->colcount(0);
 | 
        
           |  |  | 101 |   | 
        
           |  |  | 102 | 		if ($rowcount<=1) { // TODO : retour erreur
 | 
        
           |  |  | 103 | 			print "Tableau vide";
 | 
        
           |  |  | 104 | 			exit;
 | 
        
           |  |  | 105 | 		}
 | 
        
           |  |  | 106 |   | 
        
           | 540 | david | 107 | // Chargement tableau
 | 
        
           |  |  | 108 |         for($row=1;$row<=$rowcount;$row++)
 | 
        
           |  |  | 109 |             for($col=1;$col<=$colcount;$col++)
 | 
        
           |  |  | 110 |                 $arr[$col][$row] = $data->val($row,$col,0); // Attention, inversion voulue
 | 
        
           | 760 | aurelien | 111 |   | 
        
           | 540 | david | 112 | // 1 : Traitement intitules
 | 
        
           | 417 | aurelien | 113 |   | 
        
           | 445 | david | 114 | 		$line = array();
 | 
        
           | 417 | aurelien | 115 |   | 
        
           | 445 | david | 116 | /* Les colonnes ne sont pas forcemment dans l'ordre  : on les extrait pour traitement futur  */
 | 
        
           |  |  | 117 |   | 
        
           | 540 | david | 118 |         for($col=1;$col<=$colcount;$col++) {
 | 
        
           |  |  | 119 |             $colonne=strtolower($arr[$col][1]);
 | 
        
           |  |  | 120 |             $colonne=trim($colonne);
 | 
        
           |  |  | 121 |             $colonne=cp1252_to_utf8($colonne);
 | 
        
           |  |  | 122 |             $colonne=remove_accent($colonne);
 | 
        
           |  |  | 123 |             switch ($colonne) {  // On ne garde que les colonnes que l'on souhaite traiter
 | 
        
           |  |  | 124 |                 case COMMUNE:
 | 
        
           |  |  | 125 |                 case LIEUDIT:
 | 
        
           |  |  | 126 |                 case STATION:
 | 
        
           |  |  | 127 |                 case MILIEU:
 | 
        
           |  |  | 128 |                 case DEPARTEMENT:
 | 
        
           |  |  | 129 |                 case LATITUDE:
 | 
        
           |  |  | 130 |                 case LONGITUDE:
 | 
        
           |  |  | 131 |                 case NOTES:
 | 
        
           |  |  | 132 |                 case DATEOBS:
 | 
        
           |  |  | 133 |                 case ESPECE:
 | 
        
           | 760 | aurelien | 134 |                 case TRANSMETTRE:
 | 
        
           | 540 | david | 135 |                 case IMAGE:
 | 
        
           |  |  | 136 |                     $selection=array_values($arr[$col]);
 | 
        
           |  |  | 137 |                     array_shift($selection); // On ne garde pas la premiere ligne, qui contient les intitules
 | 
        
           |  |  | 138 |                     $line[$colonne]=$selection;
 | 
        
           |  |  | 139 |                     break;
 | 
        
           | 445 | david | 140 |   | 
        
           | 540 | david | 141 |             }
 | 
        
           |  |  | 142 |         }
 | 
        
           | 760 | aurelien | 143 |   | 
        
           | 540 | david | 144 | //	print_r($line[COMMUNE]);
 | 
        
           |  |  | 145 | //		print_r($line[LIEUDIT]);
 | 
        
           |  |  | 146 | //		print_r($line[STATION]);
 | 
        
           |  |  | 147 | //		print_r($line[MILIEU]);
 | 
        
           |  |  | 148 | //		print_r($line[DEPARTEMENT]);
 | 
        
           |  |  | 149 | //		print_r($line[LATITUDE]);
 | 
        
           |  |  | 150 | //		print_r($line[LONGITUDE]);
 | 
        
           |  |  | 151 | //		print_r($line[NOTES]);
 | 
        
           |  |  | 152 | //		print_r($line[DATEOBS]);
 | 
        
           |  |  | 153 | //		print_r($line[ESPECE]);
 | 
        
           |  |  | 154 | //		print_r($line[IMAGE]);
 | 
        
           |  |  | 155 |   | 
        
           |  |  | 156 |   | 
        
           | 445 | david | 157 | // 1 : Traitement lignes
 | 
        
           |  |  | 158 |   | 
        
           | 483 | david | 159 | 		$cpt_obs=0;
 | 
        
           | 760 | aurelien | 160 | 		$cpt_img=0;
 | 
        
           | 540 | david | 161 |   | 
        
           |  |  | 162 |   | 
        
           |  |  | 163 |         /* Recherche dernier numero d'ordre utilise : pas de mise a jour concurente a priori */
 | 
        
           |  |  | 164 |   | 
        
           |  |  | 165 |   | 
        
           |  |  | 166 |         $DB=$this->connectDB($this->config,'database_cel');
 | 
        
           |  |  | 167 |         $query="SELECT MAX(ordre) AS ordre FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($pairs['utilisateur'])."' ";
 | 
        
           |  |  | 168 |   | 
        
           |  |  | 169 |         $res =& $DB->query($query);
 | 
        
           |  |  | 170 |         if (DB::isError($res)) {
 | 
        
           |  |  | 171 |             die($res->getMessage());
 | 
        
           |  |  | 172 |         }
 | 
        
           |  |  | 173 |   | 
        
           |  |  | 174 |         while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
 | 
        
           |  |  | 175 |             $this->dernier_ordre=$row['ordre']; // 1  par defaut
 | 
        
           |  |  | 176 |         }
 | 
        
           |  |  | 177 |   | 
        
           | 480 | david | 178 | 		for ($i=0;$i<=$rowcount-1;$i++) {
 | 
        
           | 540 | david | 179 | 			// On saute les eventuelles lignes vides du debut et les lignes contenant des information sur image uniquement
 | 
        
           | 480 | david | 180 | 			while ((in_array($retour_analyse=$this->analyserLigne($line,$i),array(LIGNE_IMAGE_SEULEMENT, LIGNE_VIDE))) && ($i<=$rowcount)) {
 | 
        
           |  |  | 181 | 				if  ($retour_analyse==LIGNE_IMAGE_SEULEMENT) {
 | 
        
           |  |  | 182 | 	//				print "image non rattachee a une observation";
 | 
        
           |  |  | 183 | 				}
 | 
        
           |  |  | 184 | 				else {
 | 
        
           |  |  | 185 | 	//				print "vide";
 | 
        
           |  |  | 186 | 				}
 | 
        
           | 445 | david | 187 | 				$i++;
 | 
        
           |  |  | 188 | 			}
 | 
        
           | 480 | david | 189 | 			while (($this->analyserLigne($line,$i)==LIGNE_NORMALE) && ($i<=$rowcount)) {
 | 
        
           | 540 | david | 190 | 				$ordre=$this->traiterLigne($line,$i,$pairs['utilisateur'],$DB);
 | 
        
           | 483 | david | 191 | 				if ($ordre>0) {
 | 
        
           |  |  | 192 | 					$cpt_obs++; // Compteur d'observations crees
 | 
        
           |  |  | 193 | 				}
 | 
        
           | 445 | david | 194 | 				$i++;
 | 
        
           | 480 | david | 195 | 				// On saute les lignes vide ou on traite les lignes suivantes contenant des informations sur image seulement
 | 
        
           |  |  | 196 | 				while ((in_array($retour_analyse=$this->analyserLigne($line,$i),array(LIGNE_IMAGE_SEULEMENT, LIGNE_VIDE))) && ($i<=$rowcount)) {
 | 
        
           | 445 | david | 197 | 					if  ($retour_analyse==LIGNE_IMAGE_SEULEMENT) {
 | 
        
           | 480 | david | 198 | 						$this->traiterLigneComplement($line,$i,$pairs['utilisateur'],$ordre); // images supplementaires
 | 
        
           | 445 | david | 199 | 					}
 | 
        
           |  |  | 200 | 					else {
 | 
        
           | 480 | david | 201 | 	//					print "vide";
 | 
        
           | 445 | david | 202 | 					}
 | 
        
           |  |  | 203 | 					$i++;
 | 
        
           |  |  | 204 | 				}
 | 
        
           |  |  | 205 | 			}
 | 
        
           |  |  | 206 |   | 
        
           |  |  | 207 |   | 
        
           |  |  | 208 | 		}
 | 
        
           | 540 | david | 209 | 		//print $cpt_obs ." nouvelle(s) observation(s) !";
 | 
        
           | 760 | aurelien | 210 | 		$message = '';
 | 
        
           |  |  | 211 |   | 
        
           |  |  | 212 | 		if($this->cpt_images_liees > 0) {
 | 
        
           |  |  | 213 | 			$message = $this->cpt_images_liees.' images liees pour ';
 | 
        
           |  |  | 214 | 		}
 | 
        
           |  |  | 215 |   | 
        
           |  |  | 216 | 		$message .= $cpt_obs;
 | 
        
           |  |  | 217 | 		print $message;
 | 
        
           | 445 | david | 218 |   | 
        
           | 417 | aurelien | 219 | 	}
 | 
        
           |  |  | 220 |   | 
        
           | 445 | david | 221 | function analyserLigne($line,$i) {
 | 
        
           | 760 | aurelien | 222 |   | 
        
           | 445 | david | 223 | 	$ligne_vide=true;
 | 
        
           |  |  | 224 | 	$ligne_image_seulement=true;
 | 
        
           |  |  | 225 | 	$ligne_normale=true;
 | 
        
           | 760 | aurelien | 226 |   | 
        
           |  |  | 227 | 	$ligne_identique_sauf_image = true;
 | 
        
           |  |  | 228 |   | 
        
           | 445 | david | 229 | 	foreach ($this->format_observation as $colonne) {
 | 
        
           | 760 | aurelien | 230 |   | 
        
           |  |  | 231 | 		if($i < 1) {
 | 
        
           |  |  | 232 | 			$ligne_identique_sauf_image = false;
 | 
        
           |  |  | 233 | 		} else {
 | 
        
           |  |  | 234 |   | 
        
           |  |  | 235 | 			if($colonne!= IMAGE && $line[$colonne][$i - 1] != $line[$colonne][$i] && $line[$colonne][$i] != '') {
 | 
        
           |  |  | 236 | 				$ligne_identique_sauf_image = false;
 | 
        
           |  |  | 237 | 			}
 | 
        
           |  |  | 238 | 		}
 | 
        
           |  |  | 239 |   | 
        
           | 445 | david | 240 | 		if (isset ($line[$colonne][$i]) && $line[$colonne][$i]!='') {
 | 
        
           |  |  | 241 | 			if ($colonne!=IMAGE) {
 | 
        
           |  |  | 242 | 				$ligne_image_seulement=false;
 | 
        
           |  |  | 243 | 				$ligne_vide=false;
 | 
        
           |  |  | 244 | 			}
 | 
        
           |  |  | 245 | 			$ligne_vide=false;
 | 
        
           | 760 | aurelien | 246 | 		}
 | 
        
           | 445 | david | 247 | 	}
 | 
        
           | 760 | aurelien | 248 |   | 
        
           | 445 | david | 249 | 	if ($ligne_vide) {
 | 
        
           |  |  | 250 | 		return LIGNE_VIDE;
 | 
        
           |  |  | 251 | 	}
 | 
        
           |  |  | 252 | 	else {
 | 
        
           | 760 | aurelien | 253 | 		if ($ligne_image_seulement || $ligne_identique_sauf_image) {
 | 
        
           | 445 | david | 254 | 			return LIGNE_IMAGE_SEULEMENT;
 | 
        
           |  |  | 255 | 		}
 | 
        
           |  |  | 256 | 		else {
 | 
        
           |  |  | 257 | 			return LIGNE_NORMALE;
 | 
        
           |  |  | 258 | 		}
 | 
        
           |  |  | 259 | 	}
 | 
        
           |  |  | 260 |   | 
        
           | 417 | aurelien | 261 |   | 
        
           | 445 | david | 262 | }
 | 
        
           | 417 | aurelien | 263 |   | 
        
           | 540 | david | 264 | function traiterLigne($line,$i,$utilisateur,$DB) { // Controle donnee et insertion
 | 
        
           | 760 | aurelien | 265 |   | 
        
           | 480 | david | 266 | 	$info_image=array();
 | 
        
           | 760 | aurelien | 267 | 	$info_transmettre = "0";
 | 
        
           |  |  | 268 |   | 
        
           | 445 | david | 269 | 	foreach ($this->format_observation as $colonne) {
 | 
        
           |  |  | 270 | 		if (isset ($line[$colonne][$i]) && $line[$colonne][$i]!='') {
 | 
        
           |  |  | 271 | 			switch ($colonne) {  // On ne garde que les colonnes que l'on souhaite traiter
 | 
        
           |  |  | 272 | 				case COMMUNE:
 | 
        
           |  |  | 273 | 					$info_commune=$this->traiterCommune($line[COMMUNE][$i]);
 | 
        
           |  |  | 274 | 					break;
 | 
        
           |  |  | 275 | 				case LIEUDIT:
 | 
        
           | 480 | david | 276 | 					$info_lieudit=$this->traiterLieudit($line[LIEUDIT][$i]);
 | 
        
           | 445 | david | 277 | 					break;
 | 
        
           |  |  | 278 | 				case STATION:
 | 
        
           | 480 | david | 279 | 					$info_station=$this->traiterStation($line[STATION][$i]);
 | 
        
           | 445 | david | 280 | 					break;
 | 
        
           |  |  | 281 | 				case MILIEU:
 | 
        
           | 480 | david | 282 | 					$info_milieu=$this->traiterMilieu($line[MILIEU][$i]);
 | 
        
           | 445 | david | 283 | 					break;
 | 
        
           | 540 | david | 284 |                 case DEPARTEMENT:
 | 
        
           |  |  | 285 | 					$info_commune['code']=$this->traiterDepartement($line[DEPARTEMENT][$i]);
 | 
        
           |  |  | 286 | 					break;
 | 
        
           | 445 | david | 287 | 				case LATITUDE:
 | 
        
           | 480 | david | 288 | 					$info_latitude=$this->traiterLatitude($line[LATITUDE][$i]);
 | 
        
           | 445 | david | 289 | 					break;
 | 
        
           |  |  | 290 | 				case LONGITUDE:
 | 
        
           | 480 | david | 291 | 					$info_longitude=$this->traiterLongitude($line[LONGITUDE][$i]);
 | 
        
           | 445 | david | 292 | 					break;
 | 
        
           |  |  | 293 | 				case NOTES:
 | 
        
           | 480 | david | 294 | 					$info_notes=$this->traiterNotes($line[NOTES][$i]);
 | 
        
           | 445 | david | 295 | 					break;
 | 
        
           |  |  | 296 | 				case DATEOBS:
 | 
        
           | 480 | david | 297 | 					$info_dateobs=$this->traiterDateObs($line[DATEOBS][$i]);
 | 
        
           | 445 | david | 298 | 					break;
 | 
        
           | 760 | aurelien | 299 | 				case TRANSMETTRE:
 | 
        
           |  |  | 300 | 					$info_transmettre=$this->traiterTransmettre($line[TRANSMETTRE][$i]);
 | 
        
           |  |  | 301 | 				break;
 | 
        
           | 445 | david | 302 | 				case ESPECE:
 | 
        
           | 480 | david | 303 | 					$info_espece=$this->traiterEspece($line[ESPECE][$i]);
 | 
        
           | 540 | david | 304 |                     if (isset($info_espece['en_id_nom']) && $info_espece['en_id_nom']!='') {
 | 
        
           |  |  | 305 |                         $complement=$this->rechercherInformationsComplementaires($info_espece['en_id_nom']);
 | 
        
           |  |  | 306 |                         $info_espece['nom_ret']=$complement['Nom_Retenu'];
 | 
        
           |  |  | 307 |                         $info_espece['num_nom_ret']=$complement['Num_Nom_Retenu'];
 | 
        
           |  |  | 308 |                         $info_espece['num_taxon']=$complement['Num_Taxon'];
 | 
        
           |  |  | 309 |                         $info_espece['famille']=$complement['Famille'];
 | 
        
           |  |  | 310 |                     }
 | 
        
           |  |  | 311 |                     break;
 | 
        
           | 445 | david | 312 | 				case IMAGE:
 | 
        
           | 480 | david | 313 | 					$info_image=$this->traiterImage($line[IMAGE][$i],$utilisateur); // Image separee par des / +  utilisateur
 | 
        
           | 445 | david | 314 | 					break;
 | 
        
           |  |  | 315 | 			}
 | 
        
           |  |  | 316 | 		}
 | 
        
           | 480 | david | 317 | 		else {
 | 
        
           |  |  | 318 | 		 	switch($colonne) {
 | 
        
           |  |  | 319 | 				case COMMUNE:
 | 
        
           |  |  | 320 | 					$info_commune['name']="000null";
 | 
        
           |  |  | 321 | 					$info_commune['code']="000null";
 | 
        
           |  |  | 322 | 					break;
 | 
        
           |  |  | 323 | 				case LIEUDIT:
 | 
        
           |  |  | 324 | 					$info_lieudit="000null";
 | 
        
           |  |  | 325 | 					break;
 | 
        
           |  |  | 326 | 				case STATION:
 | 
        
           |  |  | 327 | 					$info_station="000null";
 | 
        
           |  |  | 328 | 					break;
 | 
        
           |  |  | 329 | 				case MILIEU:
 | 
        
           |  |  | 330 | 					$info_milieu="000null";
 | 
        
           |  |  | 331 | 					break;
 | 
        
           | 540 | david | 332 | 				case DEPARTEMENT:
 | 
        
           | 582 | david | 333 | 		            /*if (!isset ($info_commune['code']) || $info_commune['code']=='') {
 | 
        
           |  |  | 334 | 					    $info_commune['code']="000null";
 | 
        
           |  |  | 335 |                     }*/
 | 
        
           | 540 | david | 336 | 					break;
 | 
        
           | 480 | david | 337 | 				case LATITUDE:
 | 
        
           |  |  | 338 | 					$info_latitude="000null";
 | 
        
           |  |  | 339 | 					break;
 | 
        
           |  |  | 340 | 				case LONGITUDE:
 | 
        
           |  |  | 341 | 					$info_longitude="000null";
 | 
        
           |  |  | 342 | 					break;
 | 
        
           | 760 | aurelien | 343 |   | 
        
           |  |  | 344 | 				case TRANSMETTRE:
 | 
        
           |  |  | 345 | 					$info_transmettre = "0";
 | 
        
           |  |  | 346 | 				break;
 | 
        
           | 480 | david | 347 |   | 
        
           |  |  | 348 | 			}
 | 
        
           |  |  | 349 |   | 
        
           |  |  | 350 | 		}
 | 
        
           | 445 | david | 351 | 	}
 | 
        
           |  |  | 352 |   | 
        
           | 540 | david | 353 |                 $this->dernier_ordre++;
 | 
        
           | 480 | david | 354 |   | 
        
           |  |  | 355 |                 list($jour,$mois,$annee)=split("/",$info_dateobs);
 | 
        
           |  |  | 356 |                 $info_dateobs=$annee."-".$mois."-".$jour." 0:0:0";
 | 
        
           | 760 | aurelien | 357 |                 $query  = "INSERT INTO cel_inventory (identifiant,ordre,nom_sel,num_nom_sel,nom_ret,num_nom_ret,num_taxon,famille,location,id_location,date_observation,lieudit,station, milieu, commentaire, transmission, date_creation,date_modification,coord_x,coord_y) " .
 | 
        
           | 540 | david | 358 |                     " VALUES('".$DB->escapeSimple($utilisateur)."','".
 | 
        
           |  |  | 359 |                     $DB->escapeSimple($this->dernier_ordre)."','".
 | 
        
           |  |  | 360 |                     $DB->escapeSimple($info_espece['nom_sel'])."','".
 | 
        
           |  |  | 361 |                     $DB->escapeSimple($info_espece['en_id_nom'])."','".
 | 
        
           |  |  | 362 |                     $DB->escapeSimple($info_espece['nom_ret'])."','".
 | 
        
           |  |  | 363 |                     $DB->escapeSimple($info_espece['num_nom_ret'])."','".
 | 
        
           |  |  | 364 |                     $DB->escapeSimple($info_espece['num_taxon'])."','".
 | 
        
           |  |  | 365 |                     $DB->escapeSimple($info_espece['famille'])."','".
 | 
        
           |  |  | 366 |                     $DB->escapeSimple($info_commune['name'])."','".
 | 
        
           |  |  | 367 |                     $DB->escapeSimple($info_commune['code'])."','".
 | 
        
           |  |  | 368 |                     $DB->escapeSimple($info_dateobs)."','".
 | 
        
           |  |  | 369 |                     $DB->escapeSimple($info_lieudit)."','".
 | 
        
           |  |  | 370 |                     $DB->escapeSimple($info_station)."','".
 | 
        
           |  |  | 371 |                     $DB->escapeSimple($info_milieu)."','".
 | 
        
           | 760 | aurelien | 372 |                     $DB->escapeSimple($info_notes)."','".
 | 
        
           |  |  | 373 |                     $DB->escapeSimple($info_transmettre)."',".
 | 
        
           | 540 | david | 374 |                     "now() , now(),'".
 | 
        
           |  |  | 375 |                     $DB->escapeSimple($info_latitude)."','".
 | 
        
           |  |  | 376 |                     $DB->escapeSimple($info_longitude)."')";
 | 
        
           | 480 | david | 377 | //		print "\n";
 | 
        
           |  |  | 378 | 		   $res =& $DB->query($query);
 | 
        
           |  |  | 379 |   | 
        
           |  |  | 380 |                 if (PEAR::isError($res)) {
 | 
        
           |  |  | 381 |                         return false;
 | 
        
           |  |  | 382 |                 }
 | 
        
           | 760 | aurelien | 383 |   | 
        
           | 480 | david | 384 | 	// creation lien image
 | 
        
           |  |  | 385 | 	foreach ($info_image as $pic) {
 | 
        
           |  |  | 386 |   | 
        
           | 760 | aurelien | 387 | 		$query = 'INSERT INTO cel_obs_images (coi_ce_image, coi_ce_utilisateur, coi_ce_observation ) VALUES ("'.$DB->escapeSimple($pic['ci_id_image']).'","'.$DB->escapeSimple($utilisateur).'",    "'.$DB->escapeSimple($this->dernier_ordre).'") ON DUPLICATE KEY UPDATE coi_ce_image = coi_ce_image' ;
 | 
        
           | 480 | david | 388 |   | 
        
           |  |  | 389 | 		$res =& $DB->query($query);
 | 
        
           |  |  | 390 |   | 
        
           |  |  | 391 |                 if (PEAR::isError($res)) {
 | 
        
           |  |  | 392 |                         return false;
 | 
        
           | 760 | aurelien | 393 |                 } else {
 | 
        
           |  |  | 394 |                 	$this->cpt_images_liees++;
 | 
        
           | 480 | david | 395 |                 }
 | 
        
           |  |  | 396 | 	}
 | 
        
           |  |  | 397 |   | 
        
           |  |  | 398 |   | 
        
           |  |  | 399 |   | 
        
           | 540 | david | 400 | 		return $this->dernier_ordre;
 | 
        
           | 480 | david | 401 |   | 
        
           |  |  | 402 |   | 
        
           | 417 | aurelien | 403 | }
 | 
        
           |  |  | 404 |   | 
        
           | 760 | aurelien | 405 | function traiterLigneComplement($line,$i,$utilisateur, $ordre = null) {
 | 
        
           | 417 | aurelien | 406 |   | 
        
           | 760 | aurelien | 407 | 	$info_image=$this->traiterImage($line[IMAGE][$i],$utilisateur); // Image separee par des / +  utilisateur
 | 
        
           |  |  | 408 |   | 
        
           |  |  | 409 | 	// creation lien image
 | 
        
           |  |  | 410 | 	foreach ($info_image as $pic) {
 | 
        
           | 480 | david | 411 |   | 
        
           | 760 | aurelien | 412 | 		$DB=$this->connectDB($this->config,'cel_db');
 | 
        
           |  |  | 413 | 		$query = 'INSERT INTO cel_obs_images (coi_ce_image, coi_ce_utilisateur, coi_ce_observation) VALUES ("'.$DB->escapeSimple($pic['ci_id_image']).'","'.$DB->escapeSimple($utilisateur).'",    "'.$DB->escapeSimple($this->dernier_ordre).'") ON DUPLICATE KEY UPDATE coi_ce_image = coi_ce_image' ;
 | 
        
           |  |  | 414 |   | 
        
           |  |  | 415 | 		$res =& $DB->query($query);
 | 
        
           |  |  | 416 |   | 
        
           |  |  | 417 |     	if (PEAR::isError($res)) {
 | 
        
           |  |  | 418 |             return false;
 | 
        
           |  |  | 419 |     	} else {
 | 
        
           |  |  | 420 |     		$this->cpt_images_liees++;
 | 
        
           |  |  | 421 |     	}
 | 
        
           |  |  | 422 | 	}
 | 
        
           | 445 | david | 423 | }
 | 
        
           |  |  | 424 | function traiterCommune($identifiant_commune) {  // Recherche correspondance sur nom, si pas unique, correspondance dep. sinon code insee
 | 
        
           |  |  | 425 |   | 
        
           |  |  | 426 |   | 
        
           | 540 | david | 427 |         $identifiant_commune=trim($identifiant_commune);
 | 
        
           | 445 | david | 428 |   | 
        
           |  |  | 429 |         $identifiant_commune=utf8_encode($identifiant_commune); // FIXME : devrait deja etre en utf8 a ce niveau
 | 
        
           |  |  | 430 |   | 
        
           | 760 | aurelien | 431 | 		preg_match('/(.*) \(([0-9][0-9]*)\)/',$identifiant_commune,$elements);
 | 
        
           | 445 | david | 432 |   | 
        
           |  |  | 433 |         $DB=$this->connectDB($this->config,'database_cel'); // FIXME regarder si opportun ici
 | 
        
           |  |  | 434 |   | 
        
           | 540 | david | 435 | 	if ($elements[1]) { // commune + departement : montpellier (34)
 | 
        
           | 445 | david | 436 | 		$nom_commune=$elements[1];
 | 
        
           |  |  | 437 | 		$code_commune=$elements[2];
 | 
        
           |  |  | 438 |   | 
        
           | 480 | david | 439 |  	        $query="SELECT DISTINCT name, code  FROM locations WHERE name = '".$DB->escapeSimple($nom_commune)."' AND code ='".$DB->escapeSimple($code_commune)."'";
 | 
        
           | 445 | david | 440 |   | 
        
           |  |  | 441 | 	}
 | 
        
           | 540 | david | 442 | 	else { // Code insee seul
 | 
        
           |  |  | 443 |         preg_match('/([0-9][0-9]*)|(2A[0-9][0-9]*)|(2B[0-9][0-9]*)/',$identifiant_commune,$elements);
 | 
        
           |  |  | 444 |         if ($elements[1]) { // code insee  commune
 | 
        
           |  |  | 445 |             $code_insee_commune=$elements[1];
 | 
        
           |  |  | 446 |             $query="SELECT DISTINCT name, code  FROM locations WHERE insee_code ='".$DB->escapeSimple($code_insee_commune)."'";
 | 
        
           |  |  | 447 |         }
 | 
        
           |  |  | 448 |         else { // Commune seule (le departement sera recupere dans la colonne departement si elle est presente, on prend le risque ici de retourner une mauvaise
 | 
        
           |  |  | 449 |                // Commune
 | 
        
           |  |  | 450 |             preg_match('/(.*)/',$identifiant_commune,$elements);
 | 
        
           |  |  | 451 |             if ($elements[1]) { // commune
 | 
        
           |  |  | 452 |                 $nom_commune=$elements[1];
 | 
        
           | 541 | david | 453 |                 $nom_commune=trim($nom_commune);
 | 
        
           |  |  | 454 |                 $nom_commune=utf8_decode($nom_commune);
 | 
        
           |  |  | 455 |                 $nom_commune=cp1252_to_utf8($nom_commune);
 | 
        
           |  |  | 456 |                 $nom_commune=remove_accent($nom_commune);
 | 
        
           |  |  | 457 |                 $nom_commune=preg_replace("/ /","%",$nom_commune);
 | 
        
           |  |  | 458 |                 $query="SELECT DISTINCT name, code  FROM locations WHERE name like '".$DB->escapeSimple($nom_commune)."'";
 | 
        
           | 540 | david | 459 |             }
 | 
        
           |  |  | 460 |         }
 | 
        
           | 445 | david | 461 | 	}
 | 
        
           |  |  | 462 |   | 
        
           |  |  | 463 | 	$res =& $DB->query($query);
 | 
        
           |  |  | 464 |   | 
        
           |  |  | 465 |         if (DB::isError($res)) {
 | 
        
           |  |  | 466 | 		 die($res->getMessage());
 | 
        
           |  |  | 467 | 	}
 | 
        
           |  |  | 468 |   | 
        
           |  |  | 469 | 	return $res->fetchrow(DB_FETCHMODE_ASSOC);
 | 
        
           |  |  | 470 |   | 
        
           |  |  | 471 |   | 
        
           |  |  | 472 |   | 
        
           |  |  | 473 |   | 
        
           |  |  | 474 | }
 | 
        
           |  |  | 475 |   | 
        
           |  |  | 476 | function traiterLieudit($lieudit) { // texte libre
 | 
        
           |  |  | 477 |   | 
        
           | 480 | david | 478 | 	//echo "traitement lieudit";
 | 
        
           | 582 | david | 479 |     $lieudit=fix_latin($lieudit);
 | 
        
           |  |  | 480 | 	return trim($lieudit);
 | 
        
           | 445 | david | 481 | }
 | 
        
           |  |  | 482 |   | 
        
           |  |  | 483 | function traiterStation($station) { // texte libre
 | 
        
           | 480 | david | 484 | //	echo "traitement station";
 | 
        
           | 582 | david | 485 |     $station=fix_latin($station);
 | 
        
           |  |  | 486 | 	return trim($station);
 | 
        
           | 445 | david | 487 | }
 | 
        
           |  |  | 488 |   | 
        
           |  |  | 489 | function traiterMilieu($milieu) { // texte libre
 | 
        
           | 480 | david | 490 | //	echo "traitement milieu";
 | 
        
           | 582 | david | 491 |     $milieu=fix_latin($milieu);
 | 
        
           |  |  | 492 | 	return trim($milieu);
 | 
        
           | 445 | david | 493 | }
 | 
        
           |  |  | 494 |   | 
        
           | 540 | david | 495 | function traiterDepartement($departement) { // texte libre
 | 
        
           | 760 | aurelien | 496 |   | 
        
           |  |  | 497 | 	if(is_numeric($departement) && strlen($departement) == 5) {
 | 
        
           |  |  | 498 | 		$departement = substr($departement,0,2);
 | 
        
           |  |  | 499 | 	}
 | 
        
           |  |  | 500 |   | 
        
           |  |  | 501 | 	if(is_numeric($departement) && strlen($departement) == 4) {
 | 
        
           |  |  | 502 | 		$departement = substr($departement,0,1);
 | 
        
           |  |  | 503 | 		$departement = "0"+$departement;
 | 
        
           |  |  | 504 | 	}
 | 
        
           | 540 | david | 505 | 	return utf8_encode(trim($departement));
 | 
        
           |  |  | 506 | }
 | 
        
           |  |  | 507 |   | 
        
           | 445 | david | 508 | function traiterLatitude($latitude) {	//  verifier formal decimal + limite france ? TODO
 | 
        
           | 480 | david | 509 | //	echo "traitement latitude";
 | 
        
           | 540 | david | 510 | 	return trim($latitude);
 | 
        
           | 445 | david | 511 | }
 | 
        
           |  |  | 512 |   | 
        
           |  |  | 513 | function traiterLongitude($longitude) { // verifier format decimal + limite france ? TODO
 | 
        
           | 480 | david | 514 | //	echo "traitement longitude";
 | 
        
           | 540 | david | 515 | 	return trim($longitude);
 | 
        
           | 445 | david | 516 | }
 | 
        
           |  |  | 517 |   | 
        
           |  |  | 518 | function traiterNotes($notes) { // texte libre
 | 
        
           | 480 | david | 519 | //	echo "traitement notes";
 | 
        
           | 582 | david | 520 |     $notes=remove_accent($notes);
 | 
        
           | 540 | david | 521 | 	return utf8_encode(trim($notes));
 | 
        
           | 445 | david | 522 | }
 | 
        
           |  |  | 523 |   | 
        
           |  |  | 524 | function traiterDateObs($dateobs) { // verifier jj/mm/aaaa sinon date vide TODO
 | 
        
           | 480 | david | 525 | //	echo "traitement dateobs";
 | 
        
           | 540 | david | 526 | 	return trim($dateobs);
 | 
        
           | 445 | david | 527 | }
 | 
        
           |  |  | 528 |   | 
        
           | 760 | aurelien | 529 | function traiterTransmettre($transmettre) {
 | 
        
           |  |  | 530 |   | 
        
           |  |  | 531 | 	$transmission = '0';
 | 
        
           |  |  | 532 |   | 
        
           |  |  | 533 | 	if (trim($transmettre) == "1" || trim($transmettre) == "oui") {
 | 
        
           |  |  | 534 | 		$transmission = '1';
 | 
        
           |  |  | 535 | 	}
 | 
        
           |  |  | 536 |   | 
        
           |  |  | 537 | 	return $transmission;
 | 
        
           |  |  | 538 | }
 | 
        
           |  |  | 539 |   | 
        
           | 540 | david | 540 | function traiterEspece($identifiant_espece) {  // texte libre, nom scientifique , ou code nomenclatural (format BDNFFnn999999) ou code taxonomique (format BDNFFnt999999)
 | 
        
           | 449 | david | 541 |   | 
        
           | 480 | david | 542 | //	echo "traitement  espece";
 | 
        
           | 540 | david | 543 |         $identifiant_espece=trim($identifiant_espece);
 | 
        
           | 445 | david | 544 |   | 
        
           |  |  | 545 |         $identifiant_espece=utf8_encode($identifiant_espece); // FIXME : devrait deja etre en utf8 a ce niveau
 | 
        
           |  |  | 546 |   | 
        
           | 540 | david | 547 | 	    preg_match('/BDNFFnn([0-9][0-9]*)/',$identifiant_espece,$elements);
 | 
        
           |  |  | 548 |   | 
        
           | 449 | david | 549 | 		if ($elements[1]) { // Numero nomenclatural
 | 
        
           | 445 | david | 550 |   | 
        
           | 449 | david | 551 |   | 
        
           | 540 | david | 552 |             // Recherche du nom associe
 | 
        
           |  |  | 553 |             $DB=$this->connectDB($this->config); // FIXME : gerer cache de connection
 | 
        
           |  |  | 554 |             $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
 | 
        
           |  |  | 555 |                 "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
 | 
        
           |  |  | 556 |                 " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
 | 
        
           |  |  | 557 |                 " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
 | 
        
           |  |  | 558 |                 " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
 | 
        
           |  |  | 559 |                 " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
 | 
        
           |  |  | 560 |                 " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom a,  " .
 | 
        
           |  |  | 561 |                 " eflore_naturaliste_intitule_abreviation AS auteur_bex ".
 | 
        
           |  |  | 562 |                 " , eflore_naturaliste_intitule_abreviation AS auteur_b ".
 | 
        
           |  |  | 563 |                 " , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
 | 
        
           |  |  | 564 |                 " , eflore_naturaliste_intitule_abreviation AS auteur_m ".
 | 
        
           |  |  | 565 |                 " WHERE a.esn_id_nom= '".$elements[1]. "'".
 | 
        
           |  |  | 566 |                 " AND a.esn_id_version_projet_taxon = 25 ".
 | 
        
           |  |  | 567 |                 " AND en_ce_rang = enrg_id_rang" .
 | 
        
           |  |  | 568 |                 " AND en_id_nom = a.esn_id_nom" .
 | 
        
           |  |  | 569 |                 " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 570 |                 " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
 | 
        
           |  |  | 571 |                 " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 572 |                 " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 573 |                 " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
 | 
        
           | 480 | david | 574 |   | 
        
           | 540 | david | 575 |             $res =& $DB->query($query);
 | 
        
           | 480 | david | 576 |   | 
        
           |  |  | 577 |   | 
        
           | 540 | david | 578 |             if (DB::isError($res)) {
 | 
        
           |  |  | 579 |                 die($res->getMessage());
 | 
        
           |  |  | 580 |             }
 | 
        
           | 480 | david | 581 |   | 
        
           | 540 | david | 582 |             $row =& $res->fetchrow(DB_FETCHMODE_ASSOC);
 | 
        
           |  |  | 583 |             return array("nom_sel"=>$this->formaterNom($row),"en_id_nom"=>$elements[1]);
 | 
        
           |  |  | 584 |   | 
        
           | 449 | david | 585 | 		}
 | 
        
           |  |  | 586 |   | 
        
           | 540 | david | 587 | 		else { //  Numero taxonomique ou nom scientifique
 | 
        
           |  |  | 588 | 	        preg_match('/BDNFFnt([0-9][0-9]*)/',$identifiant_espece,$elements);
 | 
        
           | 449 | david | 589 |   | 
        
           | 540 | david | 590 | 		    if ($elements[1]) { // Numero taxonomique
 | 
        
           |  |  | 591 |   | 
        
           |  |  | 592 |                 $DB=$this->connectDB($this->config);
 | 
        
           | 449 | david | 593 |   | 
        
           | 540 | david | 594 |                 $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
 | 
        
           |  |  | 595 |                     "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
 | 
        
           |  |  | 596 |                     " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
 | 
        
           |  |  | 597 |                     " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
 | 
        
           |  |  | 598 |                     " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
 | 
        
           |  |  | 599 |                     " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
 | 
        
           |  |  | 600 |                     " FROM eflore_nom, eflore_nom_rang," .
 | 
        
           |  |  | 601 |                     "     eflore_naturaliste_intitule_abreviation AS auteur_bex ".
 | 
        
           |  |  | 602 |                     "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
 | 
        
           |  |  | 603 |                     "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
 | 
        
           |  |  | 604 |                     "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
 | 
        
           |  |  | 605 |                     " , eflore_selection_nom ".
 | 
        
           |  |  | 606 |                     " WHERE esn_id_taxon = '".$elements[1]. "'".
 | 
        
           |  |  | 607 |                     " AND esn_id_version_projet_taxon = 25 ".
 | 
        
           |  |  | 608 |                     " AND esn_ce_statut=3 ".
 | 
        
           |  |  | 609 |                     " AND en_id_nom = esn_id_nom" .
 | 
        
           |  |  | 610 |                     " AND en_ce_rang = enrg_id_rang" .
 | 
        
           |  |  | 611 |                     " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 612 |                     " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
 | 
        
           |  |  | 613 |                     " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 614 |                     " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 615 |                     " AND esn_id_version_projet_taxon=en_id_version_projet_nom ";
 | 
        
           | 449 | david | 616 |   | 
        
           | 540 | david | 617 |                 $res =& $DB->query($query);
 | 
        
           | 449 | david | 618 |   | 
        
           | 540 | david | 619 |                 if (DB::isError($res)) {
 | 
        
           |  |  | 620 |                     die($res->getMessage());
 | 
        
           |  |  | 621 |                 }
 | 
        
           | 449 | david | 622 |   | 
        
           | 540 | david | 623 |                 $row =& $res->fetchrow(DB_FETCHMODE_ASSOC);
 | 
        
           |  |  | 624 |                 return array("nom_sel"=>$this->formaterNom($row),"en_id_nom"=>$row['en_id_nom']);
 | 
        
           | 449 | david | 625 |   | 
        
           |  |  | 626 |   | 
        
           | 540 | david | 627 |             }
 | 
        
           | 480 | david | 628 |   | 
        
           | 540 | david | 629 |             else { // Nom scientifique
 | 
        
           |  |  | 630 |                 $nameparser=new NameParser();
 | 
        
           |  |  | 631 |                 $nom_latin_decoupe=$nameparser->parse($identifiant_espece);
 | 
        
           | 480 | david | 632 |   | 
        
           | 540 | david | 633 | //print_r($nom_latin_decoupe);
 | 
        
           |  |  | 634 |                     $DB=$this->connectDB($this->config); // FIXME regarder si opportun ici
 | 
        
           | 480 | david | 635 |   | 
        
           | 540 | david | 636 |                         // requete sous espece (on privilegie les noms retenu cf tri par esn_ce_statut)
 | 
        
           |  |  | 637 |                         if (isset($nom_latin_decoupe['infra']) && $nom_latin_decoupe['infra']!="") {
 | 
        
           |  |  | 638 |                             $query="SELECT DISTINCT en_id_nom, esn_ce_statut" .
 | 
        
           |  |  | 639 |                                             " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom " .
 | 
        
           |  |  | 640 |                                             " WHERE en_id_version_projet_nom = '25' AND en_nom_genre = '".$DB->escapeSimple($nom_latin_decoupe['genus'])."' " .
 | 
        
           |  |  | 641 |                                             " AND enrg_abreviation_rang = '".$DB->escapeSimple($nom_latin_decoupe['infra_type'])."' " .
 | 
        
           |  |  | 642 |                                             " AND en_epithete_infra_specifique = '".$DB->escapeSimple($nom_latin_decoupe['infra'])."' " .
 | 
        
           |  |  | 643 |                                             " AND esn_id_nom= en_id_nom ".
 | 
        
           |  |  | 644 |                                             " AND esn_id_version_projet_taxon=en_id_version_projet_nom " .
 | 
        
           |  |  | 645 |                                             " AND en_epithete_espece =  '".$DB->escapeSimple($nom_latin_decoupe['species'])."' AND en_ce_rang = enrg_id_rang " .
 | 
        
           |  |  | 646 |                                             " ORDER BY esn_ce_statut ".
 | 
        
           |  |  | 647 |                                             " LIMIT 1";
 | 
        
           |  |  | 648 |                         }
 | 
        
           |  |  | 649 |                         else { // espece  (on privilegie les noms retenu cf tri par esn_ce_statut)
 | 
        
           |  |  | 650 |                              $query="SELECT DISTINCT en_id_nom, esn_ce_statut" .
 | 
        
           |  |  | 651 |                                             " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom " .
 | 
        
           |  |  | 652 |                                             " WHERE en_id_version_projet_nom = '25' AND en_nom_genre = '".$DB->escapeSimple($nom_latin_decoupe['genus'])."' " .
 | 
        
           |  |  | 653 |                                             " AND enrg_abreviation_rang = 'sp.' " .
 | 
        
           |  |  | 654 |                                             " AND esn_id_nom= en_id_nom ".
 | 
        
           |  |  | 655 |                                             " AND esn_id_version_projet_taxon=en_id_version_projet_nom " .
 | 
        
           |  |  | 656 |                                             " AND en_epithete_espece =  '".$DB->escapeSimple($nom_latin_decoupe['species'])."' AND en_ce_rang = enrg_id_rang " .
 | 
        
           |  |  | 657 |                                             " ORDER BY esn_ce_statut ".
 | 
        
           |  |  | 658 |                                             " LIMIT 1";
 | 
        
           |  |  | 659 |   | 
        
           |  |  | 660 |                         }
 | 
        
           |  |  | 661 |                 $res =& $DB->query($query);
 | 
        
           |  |  | 662 |                 if (DB::isError($res)) {
 | 
        
           |  |  | 663 |                      die($res->getMessage());
 | 
        
           |  |  | 664 |                 }
 | 
        
           | 480 | david | 665 |   | 
        
           | 540 | david | 666 |                 $id_nom=$res->fetchrow(DB_FETCHMODE_ASSOC);
 | 
        
           | 480 | david | 667 |   | 
        
           | 540 | david | 668 |                 // Recherche du nom associe
 | 
        
           |  |  | 669 |                 $DB=$this->connectDB($this->config); // FIXME : gerer cache de connection
 | 
        
           |  |  | 670 |                 $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
 | 
        
           |  |  | 671 |                     "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
 | 
        
           |  |  | 672 |                     " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
 | 
        
           |  |  | 673 |                     " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
 | 
        
           |  |  | 674 |                     " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
 | 
        
           |  |  | 675 |                     " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
 | 
        
           |  |  | 676 |                     " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom a,  " .
 | 
        
           |  |  | 677 |                     "         eflore_naturaliste_intitule_abreviation AS auteur_bex ".
 | 
        
           |  |  | 678 |                     "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
 | 
        
           |  |  | 679 |                     "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
 | 
        
           |  |  | 680 |                     "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
 | 
        
           |  |  | 681 |                     " WHERE a.esn_id_nom= '".$id_nom['en_id_nom']. "'".
 | 
        
           |  |  | 682 |                     " AND a.esn_id_version_projet_taxon = 25 ".
 | 
        
           |  |  | 683 |                     " AND en_ce_rang = enrg_id_rang" .
 | 
        
           |  |  | 684 |                     " AND en_id_nom = a.esn_id_nom" .
 | 
        
           |  |  | 685 |                     " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 686 |                     " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
 | 
        
           |  |  | 687 |                     " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 688 |                     " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 689 |                     " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
 | 
        
           |  |  | 690 |                 $res =& $DB->query($query);
 | 
        
           | 480 | david | 691 |   | 
        
           |  |  | 692 |   | 
        
           | 540 | david | 693 |                 if (DB::isError($res)) {
 | 
        
           |  |  | 694 |                     die($res->getMessage());
 | 
        
           |  |  | 695 |                 }
 | 
        
           | 445 | david | 696 |   | 
        
           | 540 | david | 697 |                 if ($res->numRows() > 0 ) {
 | 
        
           |  |  | 698 |                     $row =& $res->fetchrow(DB_FETCHMODE_ASSOC);
 | 
        
           |  |  | 699 |                     return array("nom_sel"=>$this->formaterNom($row),"en_id_nom"=>$id_nom['en_id_nom']);
 | 
        
           |  |  | 700 |                 }
 | 
        
           |  |  | 701 |                 else {
 | 
        
           |  |  | 702 |                     return array("nom_sel"=>$identifiant_espece);
 | 
        
           |  |  | 703 |                 }
 | 
        
           | 445 | david | 704 |   | 
        
           | 480 | david | 705 |   | 
        
           | 540 | david | 706 |                 }
 | 
        
           |  |  | 707 |             }
 | 
        
           | 480 | david | 708 |   | 
        
           |  |  | 709 |   | 
        
           | 445 | david | 710 | }
 | 
        
           |  |  | 711 |   | 
        
           |  |  | 712 |   | 
        
           |  |  | 713 |   | 
        
           | 480 | david | 714 | function traiterImage($images,$utilisateur) { // recherche id image de ce nom
 | 
        
           |  |  | 715 |   | 
        
           |  |  | 716 |         $DB=$this->connectDB($this->config,'cel_db');
 | 
        
           |  |  | 717 |   | 
        
           |  |  | 718 | 	$liste_images = explode("/",$images) ;
 | 
        
           |  |  | 719 |   | 
        
           |  |  | 720 | 	$row =array();
 | 
        
           |  |  | 721 |         foreach($liste_images as $image) {
 | 
        
           |  |  | 722 |   | 
        
           |  |  | 723 | 		$query="SELECT * FROM cel_images WHERE ci_ce_utilisateur='".$DB->escapeSimple($utilisateur)."' AND ci_nom_original='".$DB->escapeSimple($image)."'";
 | 
        
           |  |  | 724 |   | 
        
           |  |  | 725 | 	        $res  =& $DB->query($query);
 | 
        
           |  |  | 726 | 		$row [] =& $res->fetchrow(DB_FETCHMODE_ASSOC);
 | 
        
           |  |  | 727 |   | 
        
           |  |  | 728 | 	        if (DB::isError($res)) {
 | 
        
           |  |  | 729 |         	    die($res->getMessage());
 | 
        
           |  |  | 730 | 	        }
 | 
        
           |  |  | 731 |   | 
        
           |  |  | 732 | 	}
 | 
        
           |  |  | 733 | 	return $row;
 | 
        
           |  |  | 734 |   | 
        
           |  |  | 735 |   | 
        
           | 445 | david | 736 | }
 | 
        
           |  |  | 737 |   | 
        
           | 540 | david | 738 |        function rechercherInformationsComplementaires($numNom) { // Num taxon, Num retenu ...
 | 
        
           | 445 | david | 739 |   | 
        
           | 480 | david | 740 |                 $DB=$this->connectDB($this->config);
 | 
        
           |  |  | 741 |   | 
        
           |  |  | 742 |                 $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
 | 
        
           | 540 | david | 743 |                     "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
 | 
        
           |  |  | 744 |                     " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
 | 
        
           |  |  | 745 |                     " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
 | 
        
           |  |  | 746 |                     " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
 | 
        
           |  |  | 747 |                     " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, b.esn_id_taxon, b.esn_id_nom" .
 | 
        
           |  |  | 748 |                     " FROM eflore_nom, eflore_nom_rang," .
 | 
        
           |  |  | 749 |                     "     eflore_naturaliste_intitule_abreviation AS auteur_bex ".
 | 
        
           |  |  | 750 |                     "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
 | 
        
           |  |  | 751 |                     "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
 | 
        
           |  |  | 752 |                     "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
 | 
        
           |  |  | 753 |                     " ,eflore_selection_nom a, eflore_selection_nom b".
 | 
        
           |  |  | 754 |                     " WHERE a.esn_id_nom= ".$numNom.
 | 
        
           |  |  | 755 |                     " AND a.esn_id_version_projet_taxon = 25 ".
 | 
        
           |  |  | 756 |                     " AND a.esn_id_taxon=b.esn_id_taxon ".
 | 
        
           |  |  | 757 |                     " AND b.esn_ce_statut=3 ".
 | 
        
           |  |  | 758 |                     " AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
 | 
        
           |  |  | 759 |                     " AND en_ce_rang = enrg_id_rang" .
 | 
        
           |  |  | 760 |                     " AND en_id_nom = b.esn_id_nom" .
 | 
        
           |  |  | 761 |                     " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 762 |                     " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
 | 
        
           |  |  | 763 |                     " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 764 |                     " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
 | 
        
           |  |  | 765 |                     " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
 | 
        
           | 480 | david | 766 |   | 
        
           |  |  | 767 |   | 
        
           | 540 | david | 768 |                 $res =& $DB->query($query);
 | 
        
           | 480 | david | 769 |   | 
        
           |  |  | 770 |   | 
        
           |  |  | 771 |   | 
        
           | 540 | david | 772 |                 if (DB::isError($res)) {
 | 
        
           |  |  | 773 |                     die($res->getMessage());
 | 
        
           |  |  | 774 |                 }
 | 
        
           | 480 | david | 775 |   | 
        
           | 540 | david | 776 |                 // Nom retenu, Num Nomenclatural nom retenu, Num Taxon,
 | 
        
           | 480 | david | 777 |   | 
        
           |  |  | 778 |                 $value=array('Nom_Retenu'=>"",'Num_Nom_Retenu'=>"0",'Num_Taxon'=>"0",'Famille'=>"");
 | 
        
           |  |  | 779 |   | 
        
           |  |  | 780 |                 while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
 | 
        
           | 540 | david | 781 |                     $fam=$this->rechercherFamille($row['esn_id_taxon'],$DB);
 | 
        
           |  |  | 782 |   | 
        
           |  |  | 783 |                     // Recherche Famille
 | 
        
           |  |  | 784 |                     while (($fam['en_ce_rang']!='fin') && ($fam['en_ce_rang'] !=120)) {
 | 
        
           | 480 | david | 785 |                         $fam=$this->rechercherFamille($fam['etr_id_taxon_2'],$DB);
 | 
        
           | 540 | david | 786 |                     }
 | 
        
           |  |  | 787 |                     if ($fam['en_ce_rang']==120) {
 | 
        
           | 480 | david | 788 |                         $famille=$fam['en_nom_supra_generique'];
 | 
        
           | 540 | david | 789 |                     }
 | 
        
           |  |  | 790 |                     else {
 | 
        
           | 480 | david | 791 |                         $famille="Famille inconnue";
 | 
        
           | 540 | david | 792 |                     }
 | 
        
           |  |  | 793 |   | 
        
           |  |  | 794 |                     $value=array('Nom_Retenu'=>$this->formaterNom($row),'Num_Nom_Retenu'=>$row['esn_id_nom'],'Num_Taxon'=>$row['esn_id_taxon'],'Famille'=>$famille);
 | 
        
           | 480 | david | 795 |                 }
 | 
        
           |  |  | 796 |   | 
        
           | 540 | david | 797 |                 return $value;
 | 
        
           | 480 | david | 798 |   | 
        
           |  |  | 799 |   | 
        
           |  |  | 800 |   | 
        
           |  |  | 801 |         }
 | 
        
           |  |  | 802 |   | 
        
           | 449 | david | 803 | function formaterNom($rawnom) {
 | 
        
           | 480 | david | 804 |   | 
        
           |  |  | 805 |   | 
        
           | 449 | david | 806 |                 // Constitution du nom:
 | 
        
           |  |  | 807 |                 $nom = '';
 | 
        
           | 445 | david | 808 |   | 
        
           | 449 | david | 809 |                 if ($rawnom['en_nom_supra_generique'] != '') {
 | 
        
           |  |  | 810 |                     $nom .= $rawnom['en_nom_supra_generique'];
 | 
        
           |  |  | 811 |                 } else if ($rawnom['en_epithete_infra_generique'] != '') {
 | 
        
           |  |  | 812 |                     $nom .= $rawnom['en_epithete_infra_generique'];
 | 
        
           |  |  | 813 |                 } else {
 | 
        
           |  |  | 814 |                         if ($rawnom['en_nom_genre'] != '') {
 | 
        
           |  |  | 815 |                             $nom .=  $rawnom['en_nom_genre'];
 | 
        
           |  |  | 816 |                         }
 | 
        
           |  |  | 817 |                         if ($rawnom['en_epithete_espece']!= '') {
 | 
        
           |  |  | 818 |                             $nom .= ' '.$rawnom['en_epithete_espece'];
 | 
        
           |  |  | 819 |                         }
 | 
        
           |  |  | 820 |                         if ($rawnom['en_epithete_infra_specifique'] != '') {
 | 
        
           |  |  | 821 |                                 if (!empty($rawnom['enrg_abreviation_rang'])) {
 | 
        
           |  |  | 822 |                                         $nom .= ' '.$rawnom['enrg_abreviation_rang'].'';
 | 
        
           |  |  | 823 |                                 }
 | 
        
           |  |  | 824 |                                 $nom .= ' '.$rawnom['en_epithete_infra_specifique'];
 | 
        
           |  |  | 825 |                         }
 | 
        
           |  |  | 826 |   | 
        
           |  |  | 827 |                 }
 | 
        
           | 480 | david | 828 |   | 
        
           |  |  | 829 |                 return $nom .$this->retournerAuteur($rawnom) ;
 | 
        
           |  |  | 830 |   | 
        
           |  |  | 831 |  }
 | 
        
           |  |  | 832 |   | 
        
           |  |  | 833 |   | 
        
           |  |  | 834 | function rechercherFamille($taxon,&$DB) {
 | 
        
           |  |  | 835 |   | 
        
           | 540 | david | 836 |     $row=array();
 | 
        
           | 480 | david | 837 |   | 
        
           | 540 | david | 838 |     $query="SELECT DISTINCT en_ce_rang, etr_id_taxon_2, en_id_nom, en_nom_supra_generique ".
 | 
        
           | 480 | david | 839 |         " FROM eflore_taxon_relation, eflore_selection_nom, eflore_nom ".
 | 
        
           |  |  | 840 |         " WHERE etr_id_taxon_1 = ".$taxon.
 | 
        
           |  |  | 841 |         " AND etr_id_version_projet_taxon_1 = 25 ".
 | 
        
           |  |  | 842 |         " AND etr_id_categorie_taxon = 3 ".
 | 
        
           |  |  | 843 |         " AND etr_id_valeur_taxon = 3 ".
 | 
        
           |  |  | 844 |         " AND esn_id_taxon =  etr_id_taxon_2 ".
 | 
        
           |  |  | 845 |         " AND esn_ce_statut = 3 ".
 | 
        
           |  |  | 846 |         " AND esn_id_version_projet_taxon = etr_id_version_projet_taxon_1 ".
 | 
        
           |  |  | 847 |         " AND en_id_nom = esn_id_nom ".
 | 
        
           |  |  | 848 |         " AND esn_id_version_projet_taxon=en_id_version_projet_nom  ";
 | 
        
           | 540 | david | 849 |     $res =& $DB->query($query);
 | 
        
           | 480 | david | 850 |   | 
        
           | 540 | david | 851 |     if (DB::isError($res)) {
 | 
        
           |  |  | 852 |         die($res->getMessage());
 | 
        
           |  |  | 853 |     }
 | 
        
           | 480 | david | 854 |   | 
        
           | 540 | david | 855 |     if ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
 | 
        
           |  |  | 856 |         return $row;
 | 
        
           | 480 | david | 857 |     }
 | 
        
           |  |  | 858 |     else {
 | 
        
           |  |  | 859 |         $row['en_ce_rang']='fin';
 | 
        
           |  |  | 860 |         return $row;
 | 
        
           |  |  | 861 |     }
 | 
        
           |  |  | 862 |   | 
        
           | 445 | david | 863 | }
 | 
        
           |  |  | 864 |   | 
        
           | 480 | david | 865 |   | 
        
           | 449 | david | 866 | function retournerAuteur($rawnom) {
 | 
        
           | 445 | david | 867 |   | 
        
           | 540 | david | 868 |     $auteurs = '';
 | 
        
           |  |  | 869 |     $auteur_basio = '';
 | 
        
           |  |  | 870 |     $auteur_modif = '';
 | 
        
           |  |  | 871 |     if (!empty($rawnom['abreviation_auteur_basio_ex']) && $rawnom['abreviation_auteur_basio_ex']!='-' )  {
 | 
        
           |  |  | 872 |         $auteur_basio .= $rawnom['abreviation_auteur_basio_ex'];
 | 
        
           |  |  | 873 |         if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') {
 | 
        
           |  |  | 874 |             $auteur_basio .= ' ex '.$rawnom['abreviation_auteur_basio'];
 | 
        
           |  |  | 875 |         }
 | 
        
           |  |  | 876 |     } else if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') {
 | 
        
           |  |  | 877 |         $auteur_basio .= $rawnom['abreviation_auteur_basio'];
 | 
        
           |  |  | 878 |     }
 | 
        
           | 445 | david | 879 |   | 
        
           | 540 | david | 880 |     if (!empty($rawnom['abreviation_auteur_modif_ex']) && $rawnom['abreviation_auteur_modif_ex']!='-') {
 | 
        
           |  |  | 881 |         $auteur_modif .= $rawnom['abreviation_auteur_modif_ex'];
 | 
        
           |  |  | 882 |         if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-') {
 | 
        
           |  |  | 883 |             $auteur_modif .= ' ex '.$rawnom['abreviation_auteur_modif'];
 | 
        
           |  |  | 884 |         }
 | 
        
           |  |  | 885 |     } else if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-')  {
 | 
        
           |  |  | 886 |         $auteur_modif .= $rawnom['abreviation_auteur_modif'];
 | 
        
           |  |  | 887 |     }
 | 
        
           | 449 | david | 888 |   | 
        
           | 540 | david | 889 |     if (!empty($auteur_modif)) {
 | 
        
           |  |  | 890 |         $auteurs = ' ('.$auteur_basio.') '.$auteur_modif;
 | 
        
           |  |  | 891 |     } elseif (!empty($auteur_basio)) {
 | 
        
           |  |  | 892 |         $auteurs = ' '.$auteur_basio;
 | 
        
           |  |  | 893 |     }
 | 
        
           |  |  | 894 |   | 
        
           |  |  | 895 |     return $auteurs ;
 | 
        
           | 449 | david | 896 | }
 | 
        
           |  |  | 897 |   | 
        
           |  |  | 898 |   | 
        
           |  |  | 899 |   | 
        
           | 480 | david | 900 |   | 
        
           | 449 | david | 901 | }
 | 
        
           |  |  | 902 |   | 
        
           | 582 | david | 903 | function init_byte_map(){
 | 
        
           | 606 | aurelien | 904 |     $byte_map = array();
 | 
        
           | 582 | david | 905 |     for($x=128;$x<256;++$x){
 | 
        
           |  |  | 906 |         $byte_map[chr($x)]=utf8_encode(chr($x));
 | 
        
           |  |  | 907 |     }
 | 
        
           |  |  | 908 |     $cp1252_map=array(
 | 
        
           |  |  | 909 |             "\x80"=>"\xE2\x82\xAC",    // EURO SIGN
 | 
        
           |  |  | 910 |             "\x82" => "\xE2\x80\x9A",  // SINGLE LOW-9 QUOTATION MARK
 | 
        
           |  |  | 911 |             "\x83" => "\xC6\x92",      // LATIN SMALL LETTER F WITH HOOK
 | 
        
           |  |  | 912 |             "\x84" => "\xE2\x80\x9E",  // DOUBLE LOW-9 QUOTATION MARK
 | 
        
           |  |  | 913 |             "\x85" => "\xE2\x80\xA6",  // HORIZONTAL ELLIPSIS
 | 
        
           |  |  | 914 |             "\x86" => "\xE2\x80\xA0",  // DAGGER
 | 
        
           |  |  | 915 |             "\x87" => "\xE2\x80\xA1",  // DOUBLE DAGGER
 | 
        
           |  |  | 916 |             "\x88" => "\xCB\x86",      // MODIFIER LETTER CIRCUMFLEX ACCENT
 | 
        
           |  |  | 917 |             "\x89" => "\xE2\x80\xB0",  // PER MILLE SIGN
 | 
        
           |  |  | 918 |             "\x8A" => "\xC5\xA0",      // LATIN CAPITAL LETTER S WITH CARON
 | 
        
           |  |  | 919 |             "\x8B" => "\xE2\x80\xB9",  // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
 | 
        
           |  |  | 920 |             "\x8C" => "\xC5\x92",      // LATIN CAPITAL LIGATURE OE
 | 
        
           |  |  | 921 |             "\x8E" => "\xC5\xBD",      // LATIN CAPITAL LETTER Z WITH CARON
 | 
        
           |  |  | 922 |             "\x91" => "\xE2\x80\x98",  // LEFT SINGLE QUOTATION MARK
 | 
        
           |  |  | 923 |             "\x92" => "\xE2\x80\x99",  // RIGHT SINGLE QUOTATION MARK
 | 
        
           |  |  | 924 |             "\x93" => "\xE2\x80\x9C",  // LEFT DOUBLE QUOTATION MARK
 | 
        
           |  |  | 925 |             "\x94" => "\xE2\x80\x9D",  // RIGHT DOUBLE QUOTATION MARK
 | 
        
           |  |  | 926 |             "\x95" => "\xE2\x80\xA2",  // BULLET
 | 
        
           |  |  | 927 |             "\x96" => "\xE2\x80\x93",  // EN DASH
 | 
        
           |  |  | 928 |             "\x97" => "\xE2\x80\x94",  // EM DASH
 | 
        
           |  |  | 929 |             "\x98" => "\xCB\x9C",      // SMALL TILDE
 | 
        
           |  |  | 930 |             "\x99" => "\xE2\x84\xA2",  // TRADE MARK SIGN
 | 
        
           |  |  | 931 |             "\x9A" => "\xC5\xA1",      // LATIN SMALL LETTER S WITH CARON
 | 
        
           |  |  | 932 |             "\x9B" => "\xE2\x80\xBA",  // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
 | 
        
           |  |  | 933 |             "\x9C" => "\xC5\x93",      // LATIN SMALL LIGATURE OE
 | 
        
           |  |  | 934 |             "\x9E" => "\xC5\xBE",      // LATIN SMALL LETTER Z WITH CARON
 | 
        
           |  |  | 935 |             "\x9F" => "\xC5\xB8"       // LATIN CAPITAL LETTER Y WITH DIAERESIS
 | 
        
           |  |  | 936 |                 );
 | 
        
           |  |  | 937 |     foreach($cp1252_map as $k=>$v){
 | 
        
           |  |  | 938 |         $byte_map[$k]=$v;
 | 
        
           |  |  | 939 |     }
 | 
        
           | 606 | aurelien | 940 |   | 
        
           |  |  | 941 |     return $byte_map;
 | 
        
           | 582 | david | 942 | }
 | 
        
           | 449 | david | 943 |   | 
        
           | 602 | aurelien | 944 | function fix_latin($instr){
 | 
        
           |  |  | 945 |   | 
        
           | 606 | aurelien | 946 |     $byte_map = init_byte_map();
 | 
        
           |  |  | 947 |   | 
        
           | 602 | aurelien | 948 |     $ascii_char='[\x00-\x7F]';
 | 
        
           |  |  | 949 |     $cont_byte='[\x80-\xBF]';
 | 
        
           |  |  | 950 |     $utf8_2='[\xC0-\xDF]'.$cont_byte;
 | 
        
           |  |  | 951 |     $utf8_3='[\xE0-\xEF]'.$cont_byte.'{2}';
 | 
        
           |  |  | 952 |     $utf8_4='[\xF0-\xF7]'.$cont_byte.'{3}';
 | 
        
           |  |  | 953 |     $utf8_5='[\xF8-\xFB]'.$cont_byte.'{4}';
 | 
        
           | 606 | aurelien | 954 |   | 
        
           | 602 | aurelien | 955 |     $nibble_good_chars = "@^($ascii_char+|$utf8_2|$utf8_3|$utf8_4|$utf8_5)(.*)$@s";
 | 
        
           | 601 | aurelien | 956 |   | 
        
           | 582 | david | 957 |     if(mb_check_encoding($instr,'UTF-8'))return $instr; // no need for the rest if it's all valid UTF-8 already
 | 
        
           |  |  | 958 |     $outstr='';
 | 
        
           |  |  | 959 |     $char='';
 | 
        
           |  |  | 960 |     $rest='';
 | 
        
           |  |  | 961 |     while((strlen($instr))>0){
 | 
        
           | 602 | aurelien | 962 |         if(1==@preg_match($nibble_good_chars,$instr,$match)){
 | 
        
           | 582 | david | 963 |             $char=$match[1];
 | 
        
           |  |  | 964 |             $rest=$match[2];
 | 
        
           |  |  | 965 |             $outstr.=$char;
 | 
        
           | 602 | aurelien | 966 |         }elseif(1==@preg_match('@^(.)(.*)$@s',$instr,$match)){
 | 
        
           | 582 | david | 967 |             $char=$match[1];
 | 
        
           |  |  | 968 |             $rest=$match[2];
 | 
        
           |  |  | 969 |             $outstr.=$byte_map[$char];
 | 
        
           |  |  | 970 |         }
 | 
        
           |  |  | 971 |         $instr=$rest;
 | 
        
           |  |  | 972 |     }
 | 
        
           |  |  | 973 |     return $outstr;
 | 
        
           |  |  | 974 | }
 | 
        
           |  |  | 975 |   | 
        
           |  |  | 976 |   | 
        
           | 540 | david | 977 | function remove_accent($str)
 | 
        
           |  |  | 978 | {
 | 
        
           |  |  | 979 |   $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î',
 | 
        
           |  |  | 980 |              'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß',
 | 
        
           |  |  | 981 |              'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î',
 | 
        
           |  |  | 982 |              'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā',
 | 
        
           |  |  | 983 |              'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď',
 | 
        
           |  |  | 984 |              'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ',
 | 
        
           |  |  | 985 |              'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ',
 | 
        
           |  |  | 986 |              'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ',
 | 
        
           |  |  | 987 |              'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ',
 | 
        
           |  |  | 988 |              'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ',
 | 
        
           |  |  | 989 |              'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ',
 | 
        
           |  |  | 990 |              'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż',
 | 
        
           |  |  | 991 |              'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ',
 | 
        
           |  |  | 992 |              'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ');
 | 
        
           |  |  | 993 |   | 
        
           |  |  | 994 |   $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I',
 | 
        
           |  |  | 995 |              'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's',
 | 
        
           |  |  | 996 |              'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i',
 | 
        
           |  |  | 997 |              'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a',
 | 
        
           |  |  | 998 |              'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd',
 | 
        
           |  |  | 999 |              'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g',
 | 
        
           |  |  | 1000 |              'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i',
 | 
        
           |  |  | 1001 |              'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l',
 | 
        
           |  |  | 1002 |              'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R',
 | 
        
           |  |  | 1003 |              'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't',
 | 
        
           |  |  | 1004 |              'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y',
 | 
        
           |  |  | 1005 |              'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I',
 | 
        
           |  |  | 1006 |              'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
 | 
        
           |  |  | 1007 |   return str_replace($a, $b, $str);
 | 
        
           |  |  | 1008 | }
 | 
        
           | 449 | david | 1009 |   | 
        
           | 540 | david | 1010 |   | 
        
           |  |  | 1011 | function cp1252_to_utf8($str) {
 | 
        
           |  |  | 1012 | $cp1252_map = array ("\xc2\x80" => "\xe2\x82\xac",
 | 
        
           |  |  | 1013 | "\xc2\x82" => "\xe2\x80\x9a",
 | 
        
           |  |  | 1014 | "\xc2\x83" => "\xc6\x92",
 | 
        
           |  |  | 1015 | "\xc2\x84" => "\xe2\x80\x9e",
 | 
        
           |  |  | 1016 | "\xc2\x85" => "\xe2\x80\xa6",
 | 
        
           |  |  | 1017 | "\xc2\x86" => "\xe2\x80\xa0",
 | 
        
           |  |  | 1018 | "\xc2\x87" => "\xe2\x80\xa1",
 | 
        
           |  |  | 1019 | "\xc2\x88" => "\xcb\x86",
 | 
        
           |  |  | 1020 | "\xc2\x89" => "\xe2\x80\xb0",
 | 
        
           |  |  | 1021 | "\xc2\x8a" => "\xc5\xa0",
 | 
        
           |  |  | 1022 | "\xc2\x8b" => "\xe2\x80\xb9",
 | 
        
           |  |  | 1023 | "\xc2\x8c" => "\xc5\x92",
 | 
        
           |  |  | 1024 | "\xc2\x8e" => "\xc5\xbd",
 | 
        
           |  |  | 1025 | "\xc2\x91" => "\xe2\x80\x98",
 | 
        
           |  |  | 1026 | "\xc2\x92" => "\xe2\x80\x99",
 | 
        
           |  |  | 1027 | "\xc2\x93" => "\xe2\x80\x9c",
 | 
        
           |  |  | 1028 | "\xc2\x94" => "\xe2\x80\x9d",
 | 
        
           |  |  | 1029 | "\xc2\x95" => "\xe2\x80\xa2",
 | 
        
           |  |  | 1030 | "\xc2\x96" => "\xe2\x80\x93",
 | 
        
           |  |  | 1031 | "\xc2\x97" => "\xe2\x80\x94",
 | 
        
           |  |  | 1032 |   | 
        
           |  |  | 1033 | "\xc2\x98" => "\xcb\x9c",
 | 
        
           |  |  | 1034 | "\xc2\x99" => "\xe2\x84\xa2",
 | 
        
           |  |  | 1035 | "\xc2\x9a" => "\xc5\xa1",
 | 
        
           |  |  | 1036 | "\xc2\x9b" => "\xe2\x80\xba",
 | 
        
           |  |  | 1037 | "\xc2\x9c" => "\xc5\x93",
 | 
        
           |  |  | 1038 | "\xc2\x9e" => "\xc5\xbe",
 | 
        
           |  |  | 1039 | "\xc2\x9f" => "\xc5\xb8"
 | 
        
           |  |  | 1040 | );
 | 
        
           |  |  | 1041 | return strtr ( utf8_encode ( $str ), $cp1252_map );
 | 
        
           |  |  | 1042 | }
 | 
        
           |  |  | 1043 |   | 
        
           | 417 | aurelien | 1044 | /* +--Fin du code ---------------------------------------------------------------------------------------+
 | 
        
           |  |  | 1045 | * $Log$
 | 
        
           |  |  | 1046 | *
 | 
        
           |  |  | 1047 | *
 | 
        
           |  |  | 1048 | */
 | 
        
           |  |  | 1049 |   | 
        
           |  |  | 1050 |   | 
        
           |  |  | 1051 | ?>
 |