Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 1447 Rev 1478
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Service de recherche dans eflore, permettant d'intégrer le moteur dans une page donnée
4
 * Service de recherche dans eflore, permettant d'intégrer le moteur dans une page donnée
5
 * Encodage en entrée : utf8
5
 * Encodage en entrée : utf8
6
 * Encodage en sortie : utf8
6
 * Encodage en sortie : utf8
7
 *
7
 *
8
 * Cas d'utilisation et documentation :
8
 * Cas d'utilisation et documentation :
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideEfloreWidgetRecherche
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideEfloreWidgetRecherche
10
 *
10
 *
11
 *
11
 *
12
 * @author		Aurélien PERONNET <aurelien@tela-botanica.org>
12
 * @author		Aurélien PERONNET <aurelien@tela-botanica.org>
13
 * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
 * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
14
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
15
 * @version	$Id$
15
 * @version	$Id$
16
 * @copyright	Copyright (c) 2013, Tela Botanica (accueil@tela-botanica.org)
16
 * @copyright	Copyright (c) 2013, Tela Botanica (accueil@tela-botanica.org)
17
 */
17
 */
18
class Chorodep extends WidgetCommun {
18
class Chorodep extends WidgetCommun {
19
	const DS = DIRECTORY_SEPARATOR;
19
	const DS = DIRECTORY_SEPARATOR;
20
	/**
20
	/**
21
	* Méthode appelée par défaut pour charger ce widget.
21
	* Méthode appelée par défaut pour charger ce widget.
22
	*/
22
	*/
23
	public function executer() {
23
	public function executer() {
24
		$retour = null; 
24
		$retour = null; 
25
		$methode = $this->traiterNomMethodeExecuter($this->ressources[0]);
25
		$methode = $this->traiterNomMethodeExecuter($this->ressources[0]);
26
		if (method_exists($this, $methode)) {
26
		if (method_exists($this, $methode)) {
27
			$retour = $this->$methode();
27
			$retour = $this->$methode();
28
		} else {
28
		} else {
29
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
29
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
30
		}
30
		}
31
		if (is_null($retour)) {
31
		if (is_null($retour)) {
32
			$info = 'Un problème est survenu : '.print_r($this->messages, true);
32
			$info = 'Un problème est survenu : '.print_r($this->messages, true);
33
			$this->envoyer($info);
33
			$this->envoyer($info);
34
		} else {
34
		} else {
35
			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
35
			$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
36
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
36
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
37
			if (isset($_GET['callback'])) {
37
			if (isset($_GET['callback'])) {
38
				$this->envoyerJsonp(array('contenu' => $contenu));
38
				$this->envoyerJsonp(array('contenu' => $contenu));
39
			} else {
39
			} else {
40
				$this->envoyer($contenu);
40
				$this->envoyer($contenu);
41
			}
41
			}
42
		}
42
		}
43
	}
43
	}
44
	/*
44
	/*
45
	 * dans validation
45
	 * dans validation
46
	 *  reflechir comment gérer prop refusee
46
	 *  reflechir comment gérer prop refusee
47
	 * quand prop validée/refusée changée dans chorodep_prop et chorodep_version
47
	 * quand prop validée/refusée changée dans chorodep_prop et chorodep_version
48
	 */
48
	 */
49
	
49
	
50
	
50
	
51
	
51
	
52
	public function executerFormulaire() {
52
	public function executerFormulaire() {
53
		$widget['donnees'] = array();
53
		$widget['donnees'] = array();
54
		if ($this->parametres != array()) {
54
		if ($this->parametres != array()) {
55
			$widget['donnees'] = $this->parametres;
55
			$widget['donnees'] = $this->parametres;
56
			$this->ajouterProposition();
56
			$this->ajouterProposition();
57
		}
57
		}
58
		
58
		
59
		$l = json_decode(file_get_contents("http://api.tela-botanica.org/service:eflore:0.1/insee-d/zone-geo?retour.format=liste"), true);
59
		$l = json_decode(file_get_contents("https://api.tela-botanica.org/service:eflore:0.1/insee-d/zone-geo?retour.format=liste"), true);
60
		$widget['donnees']['liste_dept'] = $l["resultat"];
60
		$widget['donnees']['liste_dept'] = $l["resultat"];
61
		
61
		
62
		$widget['donnees']['efloreScriptUrl'] = $this->config['url']['efloreScriptUrl'];
62
		$widget['donnees']['efloreScriptUrl'] = $this->config['url']['efloreScriptUrl'];
63
		
63
		
64
		$widget['squelette'] = 'formulaire';
64
		$widget['squelette'] = 'formulaire';
65
		return $widget;
65
		return $widget;
66
	}
66
	}
67
	
67
	
68
	private function ajouterProposition() {
68
	private function ajouterProposition() {
69
		$params_obli = array("dept",/*"num_nom",*/"statut","nom_sci","sources","notes");
69
		$params_obli = array("dept",/*"num_nom",*/"statut","nom_sci","sources","notes");
70
		$donnees[] = "provenance=form";
70
		$donnees[] = "provenance=form";
71
		$donnees[] = "num_nom=24545"; // à modifier avec javascript
71
		$donnees[] = "num_nom=24545"; // à modifier avec javascript
72
		$url_propo = "http://localhost/service:eflore:0.1/chorodep/propositions/";
72
		$url_propo = "http://localhost/service:eflore:0.1/chorodep/propositions/";
73
		foreach ($params_obli as $param) {
73
		foreach ($params_obli as $param) {
74
			if (isset($this->parametres[$param])) {
74
			if (isset($this->parametres[$param])) {
75
				$donnees[] = $param."=".$this->parametres[$param];
75
				$donnees[] = $param."=".$this->parametres[$param];
76
			} else {
76
			} else {
77
				$donnees[] = $param."=";
77
				$donnees[] = $param."=";
78
			}
78
			}
79
		}
79
		}
80
		$contexte = stream_context_create(array(
80
		$contexte = stream_context_create(array(
81
				'http' => array(
81
				'http' => array(
82
      				'method' => 'PUT',
82
      				'method' => 'PUT',
83
					'header' => "Content-type: application/x-www-form-urlencoded\r\n",
83
					'header' => "Content-type: application/x-www-form-urlencoded\r\n",
84
      				'content' => implode("&", $donnees))));
84
      				'content' => implode("&", $donnees))));
85
			$flux = fopen($url_propo, 'r', false, $contexte);
85
			$flux = fopen($url_propo, 'r', false, $contexte);
86
			if (!$flux) {
86
			if (!$flux) {
87
				$this->reponse_entetes = $http_response_header;
87
				$this->reponse_entetes = $http_response_header;
88
				$e = "Echec requête 'PUT' : {$url_propo}\n".
88
				$e = "Echec requête 'PUT' : {$url_propo}\n".
89
						"Paramètres requête : implode("&", $donnees) \n".
89
						"Paramètres requête : implode("&", $donnees) \n".
90
						"Entêtes réponse :  \n";
90
						"Entêtes réponse :  \n";
91
				trigger_error($e, E_USER_WARNING);
91
				trigger_error($e, E_USER_WARNING);
92
			} else {
92
			} else {
93
				// Informations sur les en-têtes et métadonnées du flux
93
				// Informations sur les en-têtes et métadonnées du flux
94
				$this->reponse_entetes = stream_get_meta_data($flux);
94
				$this->reponse_entetes = stream_get_meta_data($flux);
95
			
95
			
96
				// Contenu actuel de $url
96
				// Contenu actuel de $url
97
				$contenu = stream_get_contents($flux);
97
				$contenu = stream_get_contents($flux);
98
			
98
			
99
				fclose($flux);
99
				fclose($flux);
100
			}
100
			}
101
	}
101
	}
102
	
102
	
103
	public function executerValidation() {
103
	public function executerValidation() {
104
		$widget['donnees'] = array();
104
		$widget['donnees'] = array();
105
		if ($this->parametres != array()) {
105
		if ($this->parametres != array()) {
106
			$this->modifierProposition();
106
			$this->modifierProposition();
107
		}
107
		}
108
		$widget['donnees']['liste_prop'] = json_decode(file_get_contents("http://localhost/service:eflore:0.1/chorodep/propositions/"), true);
108
		$widget['donnees']['liste_prop'] = json_decode(file_get_contents("http://localhost/service:eflore:0.1/chorodep/propositions/"), true);
109
		
109
		
110
		$widget['squelette'] = 'tableau_validation';
110
		$widget['squelette'] = 'tableau_validation';
111
		return $widget;
111
		return $widget;
112
	}
112
	}
113
	
113
	
114
	private function modifierProposition() {
114
	private function modifierProposition() {
115
		$url_propo = "http://localhost/service:eflore:0.1/chorodep/propositions/";
115
		$url_propo = "http://localhost/service:eflore:0.1/chorodep/propositions/";
116
		foreach ($this->parametres as $id => $prop) {
116
		foreach ($this->parametres as $id => $prop) {
117
			$donnees[] = $id."=".$prop;
117
			$donnees[] = $id."=".$prop;
118
		}
118
		}
119
		$contexte = stream_context_create(array(
119
		$contexte = stream_context_create(array(
120
				'http' => array(
120
				'http' => array(
121
						'method' => 'POST',
121
						'method' => 'POST',
122
						'header' => "Content-type: application/x-www-form-urlencoded\r\n",
122
						'header' => "Content-type: application/x-www-form-urlencoded\r\n",
123
						'content' => implode("&", $donnees))));
123
						'content' => implode("&", $donnees))));
124
		$flux = fopen($url_propo, 'r', false, $contexte);
124
		$flux = fopen($url_propo, 'r', false, $contexte);
125
		if (!$flux) {
125
		if (!$flux) {
126
			$this->reponse_entetes = $http_response_header;
126
			$this->reponse_entetes = $http_response_header;
127
			$e = "Echec requête 'POST' : {$url_propo}\n".
127
			$e = "Echec requête 'POST' : {$url_propo}\n".
128
					"Paramètres requête : implode("&", $donnees) \n".
128
					"Paramètres requête : implode("&", $donnees) \n".
129
					"Entêtes réponse :  \n";
129
					"Entêtes réponse :  \n";
130
			trigger_error($e, E_USER_WARNING);
130
			trigger_error($e, E_USER_WARNING);
131
		} else {
131
		} else {
132
			// Informations sur les en-têtes et métadonnées du flux
132
			// Informations sur les en-têtes et métadonnées du flux
133
			$this->reponse_entetes = stream_get_meta_data($flux);
133
			$this->reponse_entetes = stream_get_meta_data($flux);
134
				
134
				
135
			// Contenu actuel de $url
135
			// Contenu actuel de $url
136
			$contenu = stream_get_contents($flux);
136
			$contenu = stream_get_contents($flux);
137
				
137
				
138
			fclose($flux);
138
			fclose($flux);
139
		}
139
		}
140
	}
140
	}
141
	
141
	
142
	/*"1","0","presenceChorologie","Tableau des présences pour le projet de chorologie départementale","presenceChorologie",
142
	/*"1","0","presenceChorologie","Tableau des présences pour le projet de chorologie départementale","presenceChorologie",
143
	 "2","1","non renseignée","Zone géographique non renseignée.",,"legende=#808080"
143
	 "2","1","non renseignée","Zone géographique non renseignée.",,"legende=#808080"
144
	 "3","1","présence",,"1","legende=#A0FF7D,priorite=6"
144
	 "3","1","présence",,"1","legende=#A0FF7D,priorite=6"
145
	 "4","1","présence à confimer",,"1?","legende=#FFFF32,priorite=5"
145
	 "4","1","présence à confimer",,"1?","legende=#FFFF32,priorite=5"
146
	 "5","1","douteux",,"?","legende=#FFCB30,priorite=4"
146
	 "5","1","douteux",,"?","legende=#FFCB30,priorite=4"
147
	 "6","1","disparu",,"-|-","legende=#F88017,priorite=3"
147
	 "6","1","disparu",,"-|-","legende=#F88017,priorite=3"
148
	 "7","1","erreur",,"#","legende=#FF2850,priorite=2"
148
	 "7","1","erreur",,"#","legende=#FF2850,priorite=2"
149
	 "8","1","erreur à confirmer",,"#?","legende=#9F0016,priorite=1"*/
149
	 "8","1","erreur à confirmer",,"#?","legende=#9F0016,priorite=1"*/
150
	
150
	
151
 
151
 
152
}
152
}
153
?> 
153
?>