Subversion Repositories eFlore/Applications.cel

Rev

Rev 866 | Rev 951 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 866 Rev 943
Line 15... Line 15...
15
 */
15
 */
16
abstract class Cel {
16
abstract class Cel {
17
	const TYPE_OBS = 'observation';
17
	const TYPE_OBS = 'observation';
18
	const TYPE_IMG = 'image';
18
	const TYPE_IMG = 'image';
19
	const SQL_MODE_ASSOC = PDO::FETCH_ASSOC;
19
	const SQL_MODE_ASSOC = PDO::FETCH_ASSOC;
-
 
20
	const SQL_MODE_OBJET = PDO::FETCH_OBJ;
20
	const SQL_RETOUR_COMPLET = 'All';
21
	const SQL_RETOUR_COMPLET = 'All';
21
	const SQL_RETOUR_LIGNE = 'Row';
22
	const SQL_RETOUR_LIGNE = 'Row';
22
	const SQL_RETOUR_COLONNE = 'Column';
23
	const SQL_RETOUR_COLONNE = 'Column';
23
	const SQL_RETOUR_BRUT = 'Raw';
24
	const SQL_RETOUR_BRUT = 'Raw';
Line 274... Line 275...
274
			$sortie = $donnees;
275
			$sortie = $donnees;
275
			if (is_null($donnees)) {
276
			if (is_null($donnees)) {
276
				$sortie = 'OK';
277
				$sortie = 'OK';
277
			}
278
			}
278
		}
279
		}
-
 
280
		
279
		// Gestion de l'envoie du déboguage
281
		// Gestion de l'envoie du déboguage
280
		$this->envoyerDebogage();
282
		$this->envoyerDebogage();
Line 281... Line 283...
281
 
283
 
282
		// Encodage au format et JSON et envoie sur la sortie standard
284
		// Encodage au format et JSON et envoie sur la sortie standard
-
 
285
		$contenu = $json ? json_encode($sortie) : $sortie;
283
		$contenu = $json ? json_encode($sortie) : $sortie;
286
		
284
		$this->envoyerContenu($encodage, $mime, $contenu);
287
		$this->envoyerContenu($encodage, $mime, $contenu);
Line 285... Line 288...
285
	}
288
	}
286
 
289
 
Line 314... Line 317...
314
		print $message_echec;
317
		print $message_echec;
315
		exit(0);
318
		exit(0);
316
	}
319
	}
Line 317... Line 320...
317
	
320
	
318
	//+----------------------------------------------------------------------------------------------------------------+
321
	//+----------------------------------------------------------------------------------------------------------------+
Line 319... Line 322...
319
	// GESTION DU DAO
322
	// GESTION DES CLASSES CHARGÉES À LA DEMANDE
320
	
-
 
321
	protected function getDao() {
-
 
322
		if (isset($this->dao)) {
-
 
323
			return $this->dao;	
-
 
324
		} else {
-
 
325
			$e = "Le DAO n'a pas été initialisé. Utiliser la méthode initialiserDao().";
-
 
326
			trigger_error($e, E_USER_WARNING);
-
 
327
		}
-
 
328
	}
-
 
329
	
323
	
330
	protected function initialiserDao($url_services_distant) {
-
 
331
		if (!isset($this->dao)) {
-
 
332
			$this->dao = new CelDao($url_services_distant);
324
	protected function getRestClient() {
333
		} else {
325
		if (!isset($this->restClient)) {
-
 
326
			$this->restClient = new CelRestClient();
334
			$this->dao->url_jrest = $url_services_distant;
327
		}
Line 335... Line 328...
335
		}
328
		return $this->restClient;
336
	}
329
	}
Line 417... Line 410...
417
		}
410
		}
418
		return true;
411
		return true;
419
	} 
412
	} 
Line 420... Line 413...
420
    
413
    
421
	public function etreUtilisateurAutorise() {
-
 
422
		$this->initialiserDao('http://www.tela-botanica.org/client/annuaire_nouveau/actuelle/jrest/');
414
	public function etreUtilisateurAutorise() {
423
		$identifiant = $this->getAuthIdentifiant();
415
		$identifiant = $this->getAuthIdentifiant();
424
		$mdp = md5($this->getAuthMotDePasse());
416
		$mdp = md5($this->getAuthMotDePasse());
-
 
417
		$service = "TestLoginMdp/$identifiant/$mdp";
425
		$url = $this->getDao()->url_jrest."TestLoginMdp/$identifiant/$mdp";
418
		$url = sprintf($this->config['settings']['baseURLServicesAnnuaireTpl'], $service);
426
		$json = $this->getDao()->envoyerRequeteConsultation($url);
419
		$json = $this->getRestClient()->consulter($url);
Line 427... Line 420...
427
		$existe = json_decode($json);
420
		$existe = json_decode($json);
428
		
421
		
429
		$autorisation = (isset($existe) && $existe) ? true :false;
422
		$autorisation = (isset($existe) && $existe) ? true :false;
Line 487... Line 480...
487
		$id = sprintf('%09s', $id).$format;
480
		$id = sprintf('%09s', $id).$format;
488
		$url = sprintf($url_tpl, $id); 
481
		$url = sprintf($url_tpl, $id); 
489
		return $url;
482
		return $url;
490
	}
483
	}
Line -... Line 484...
-
 
484
	
491
	
485
	/**
492
	protected function creerAuteur($courriel, $pourAdmin = false) {
486
	 * Prend en paramêtre un tableau de courriels et retourne après avoir interrogé un service de l'annuaire
493
		$auteur = ($pourAdmin) ? $courriel : $this->tronquerCourriel($courriel);
-
 
494
		return $auteur;
487
	 * une tableau avec en clé le courriel et en valeur l'intitulé de la personne à afficher.
-
 
488
	 *  
495
	}
489
	 * @param array $courriels un tableau de courriels pour lesquels il faut rechercher les infos d'identité
496
	
490
	 */
-
 
491
	protected function creerAuteurs(Array $courriels) {
497
	protected function creerAuteurs(array $courriels, $pourAdmin = false) {
492
		$auteurs = array();
-
 
493
		if ($identites = $this->recupererUtilisateursIdentite($courriels)) {
-
 
494
			foreach ($identites as $courriel => $infos) {
-
 
495
				$auteurs[$courriel] = $info['identite'];
-
 
496
			}
498
		$auteurs = ($pourAdmin) ? $courriels : $this->recupererUtilisateursNomPrenom($courriels);
497
		}
499
		return $auteurs;
498
		return $auteurs;
Line 500... Line 499...
500
	}
499
	}
501
	
500
	
502
	protected function recupererUtilisateursNomPrenom(array $courriels) {
501
	protected function recupererUtilisateursIdentite(Array $courriels) {
503
		// Récupération des données au format Json
502
		// Récupération des données au format Json
504
		$service = "utilisateur/prenom-nom-par-courriel/".implode(',', $courriels);
503
		$service = "utilisateur/identite-par-courriel/".implode(',', $courriels);
505
		$url = sprintf($this->config['settings']['baseURLServicesAnnuaireTpl'], $service);
504
		$url = sprintf($this->config['settings']['baseURLServicesAnnuaireTpl'], $service);
506
		$json = file_get_contents($url);
505
		$json = file_get_contents($url);
-
 
506
		$utilisateurs = json_decode($json);
507
		$utilisateurs = json_decode($json);
507
		foreach ($courriels as $courriel) {
508
		foreach ($courriels as $courriel) {
508
			$info = array('id' => null, 'identite' => '');
-
 
509
			if (isset($utilisateurs->$courriel)) {
509
			if (isset($utilisateurs->$courriel)) {
510
				$info['intitule'] = $utilisateurs->$courriel->intitule;
510
				$noms[$courriel] = $utilisateurs->$courriel->prenom.' '.$utilisateurs->$courriel->nom;
511
				$info['id'] = $utilisateurs->$courriel->id;
511
			} else {
512
			} else {
-
 
513
				$info['intitule'] = $this->tronquerCourriel($courriel);
512
				$noms[$courriel] = $this->tronquerCourriel($courriel);
514
			}
513
			}	
515
			$noms[$courriel] = $info;
514
		}	
516
		}	
Line 515... Line 517...
515
		return $noms;
517
		return $noms;
Line 581... Line 583...
581
		}
583
		}
582
		return $date_formatee;
584
		return $date_formatee;
583
	}
585
	}
Line 584... Line 586...
584
	
586
	
585
	protected function encoderMotCle($mot_cle) {
587
	protected function encoderMotCle($mot_cle) {
586
		return md5(mb_strtolower($mot_cle));
588
		return md5(mb_strtolower(trim($mot_cle)));
Line 587... Line 589...
587
	}
589
	}
588
	
590
	
589
	protected function decoderMotsClesObs($utilisateur_id, $mots_cles) {
591
	protected function decoderMotsClesObs($utilisateur_id, $mots_cles) {
Line 601... Line 603...
601
			
603
			
602
			$mots_cles = $this->protegerMotsCles($mots_cles, $type);
604
			$mots_cles = $this->protegerMotsCles($mots_cles, $type);
603
			if (! $this->etreNull($mots_cles)) {
605
			if (! $this->etreNull($mots_cles)) {
Line 604... Line 606...
604
				$table = ($type == self::TYPE_IMG) ? 'cel_mots_cles_images' : 'cel_mots_cles_obs' ;
606
				$table = ($type == self::TYPE_IMG) ? 'cel_mots_cles_images' : 'cel_mots_cles_obs' ;
605
				
607
				
606
				$requete = 'SELECT mot_cle '.
608
				$requete = 'SELECT cmc_mot_cle '.
607
					"FROM $table ".
609
					"FROM $table ".
Line 608... Line 610...
608
					"WHERE id_mot_cle_utilisateur IN ($mots_cles) ".
610
					"WHERE cmc_id_mot_cle_utilisateur IN ($mots_cles) ".
609
					"AND ce_utilisateur = $utilisateur_id ";
-
 
-
 
611
					"AND cmc_id_proprietaire = $utilisateur_id ";
610
				
612
				
611
				$elements = $this->executerRequete($requete);
613
				$elements = $this->executerRequete($requete);
-
 
614
				if (is_array($elements)) {
612
				
615
					foreach ($elements as $mot) {
613
				foreach ($elements as $mot) {
616
						$mots[] = $mot['mot_cle'];
614
					$mots[] = $mot['mot_cle'];
617
					}
615
				}
618
				}
616
			}
619
			}