Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1751 Rev 1765
1
<?php
1
<?php
2
/**
2
/**
3
 * Service fournissant des informations concernant COEL au format RSS1, RSS2 ou ATOM.
3
 * Service fournissant des informations concernant COEL au format RSS1, RSS2 ou ATOM.
4
 * Encodage en entrée : utf8
4
 * Encodage en entrée : utf8
5
 * Encodage en sortie : utf8
5
 * Encodage en sortie : utf8
6
 * 
6
 * 
7
 * Notes : pour les requêtes sur la table d'historique cela peut être assez compliqué!
7
 * Notes : pour les requêtes sur la table d'historique cela peut être assez compliqué!
8
 * Voir : http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/
8
 * Voir : http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/
9
 * 
9
 * 
10
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
11
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
11
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
12
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
12
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
13
 * @version $Id: CoelSyndication.php 381 2010-05-17 17:10:37Z jpm $
13
 * @version $Id: CoelSyndication.php 381 2010-05-17 17:10:37Z jpm $
14
 * @copyright 2009
14
 * @copyright 2009
15
 */
15
 */
16
class CoelSyndication extends Coel {
16
class CoelSyndication extends Coel {
17
	
17
	
18
	private $format = null;
18
	private $format = null;
19
	private $service = null;
19
	private $service = null;
20
	private $squelette = null;
20
	private $squelette = null;
21
	private $squelette_dossier = null;
21
	private $squelette_dossier = null;
22
	private $squelette_diff = null;
22
	private $squelette_diff = null;
23
	private $flux = array();
23
	private $flux = array();
24
	
24
	
25
	/**
25
	/**
26
	 * Méthode appelée avec une requête de type GET.
26
	 * Méthode appelée avec une requête de type GET.
27
	 */
27
	 */
28
	public function getElement($param = array()) {
28
	public function getElement($param = array()) {
29
		// Initialisation des variables
29
		// Initialisation des variables
30
		$info = array();
30
		$info = array();
31
		$contenu = '';
31
		$contenu = '';
32
			
32
			
33
		// Pré traitement des paramêtres
33
		// Pré traitement des paramêtres
34
		$pour_bdd = false;
34
		$pour_bdd = false;
35
		$p = $this->traiterParametresUrl(array('service', 'format'), $param, $pour_bdd);
35
		$p = $this->traiterParametresUrl(array('service', 'format'), $param, $pour_bdd);
36
		
36
		
37
		// Récupération de la liste des flux
37
		// Récupération de la liste des flux
38
		$this->chargerListeDesFlux();
38
		$this->chargerListeDesFlux();
39
		
39
		
40
		// Chargement du bon type de service demandé
40
		// Chargement du bon type de service demandé
41
		if (isset($p['service'])) {
41
		if (isset($p['service'])) {
42
			$this->service = strtolower($p['service']);
42
			$this->service = strtolower($p['service']);
43
			$methode = $this->getNomMethodeService();
43
			$methode = $this->getNomMethodeService();
44
			if (method_exists($this, $methode)) {
44
			if (method_exists($this, $methode)) {
45
				if ($this->service != 'liste_des_flux') {
45
				if ($this->service != 'liste_des_flux') {
46
					if (isset($p['format']) && preg_match('/^(?:rss1|rss2|atom)$/i', $p['format'])) {
46
					if (isset($p['format']) && preg_match('/^(?:rss1|rss2|atom)$/i', $p['format'])) {
47
						// Multiplication par deux de la limite car nous récupérons deux lignes par item
47
						// Multiplication par deux de la limite car nous récupérons deux lignes par item
48
						$this->limit = $this->limit*2;
48
						$this->limit = $this->limit*2;
49
						// Mise en minuscule de l'indication du format
49
						// Mise en minuscule de l'indication du format
50
						$this->format = strtolower($p['format']);
50
						$this->format = strtolower($p['format']);
51
						// Définition du fichier squelette demandé
51
						// Définition du fichier squelette demandé
52
						$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
52
						$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
53
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
53
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
54
						$this->squelette_diff = $this->squelette_dossier.'diff.tpl.html';
54
						$this->squelette_diff = $this->squelette_dossier.'diff.tpl.html';
55
					} else {
55
					} else {
56
						$this->format = '';
56
						$this->format = '';
57
						$this->messages[] = "Le service COEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
57
						$this->messages[] = "Le service COEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
58
					}
58
					}
59
				}
59
				}
60
				// Récupération du contenu à renvoyer
60
				// Récupération du contenu à renvoyer
61
				$contenu = $this->$methode();
61
				$contenu = $this->$methode();
62
			} else {
62
			} else {
63
				$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
63
				$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
64
			}
64
			}
65
		} else {
65
		} else {
66
			$this->messages[] = "Le service COEL Syndication nécessite d'indiquer en premier paramètre le type d'information demandé.";
66
			$this->messages[] = "Le service COEL Syndication nécessite d'indiquer en premier paramètre le type d'information demandé.";
67
		}
67
		}
68
		
68
		
69
		// Envoie sur la sortie standard
69
		// Envoie sur la sortie standard
70
		$encodage = 'utf-8';
70
		$encodage = 'utf-8';
71
		$mime = $this->getTypeMime();
71
		$mime = $this->getTypeMime();
72
		$formatage_json = $this->getFormatageJson();
72
		$formatage_json = $this->getFormatageJson();
73
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
73
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
74
	}
74
	}
75
	
75
	
76
	private function getUrlServiceBase() {
76
	private function getUrlServiceBase() {
77
		$url_service = $this->config['coel']['urlBaseJrest'].'CoelSyndication/'.$this->service.'/'.$this->format;
77
		$url_service = $this->config['coel']['urlBaseJrest'].'CoelSyndication/'.$this->service.'/'.$this->format;
78
		return $url_service;
78
		return $url_service;
79
	}
79
	}
80
	
80
	
81
	private function getNomMethodeService() {
81
	private function getNomMethodeService() {
82
		$methode = '';
82
		$methode = '';
83
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('_', $this->service))));
83
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('_', $this->service))));
84
		$methode = 'getService'.$service_formate;
84
		$methode = 'getService'.$service_formate;
85
		return $methode;
85
		return $methode;
86
	}
86
	}
87
	
87
	
88
	private function getTypeMime() {
88
	private function getTypeMime() {
89
		$mime = '';
89
		$mime = '';
90
		switch ($this->format) {
90
		switch ($this->format) {
91
			case 'atom' :
91
			case 'atom' :
92
				$mime = 'application/atom+xml';
92
				$mime = 'application/atom+xml';
93
				break;
93
				break;
94
			case 'rss1' :
94
			case 'rss1' :
95
			case 'rss2' :
95
			case 'rss2' :
96
				$mime = 'application/rss+xml';
96
				$mime = 'application/rss+xml';
97
				break;
97
				break;
98
			default:
98
			default:
99
				$mime = 'text/html';
99
				$mime = 'text/html';
100
		}
100
		}
101
		return $mime;
101
		return $mime;
102
	}
102
	}
103
	
103
	
104
	private function getFormatageJson() {
104
	private function getFormatageJson() {
105
		$json = false;
105
		$json = false;
106
		switch ($this->service) {
106
		switch ($this->service) {
107
			case 'liste_des_flux' :
107
			case 'liste_des_flux' :
108
				$json = true;
108
				$json = true;
109
				break;
109
				break;
110
			default:
110
			default:
111
				$json = false;
111
				$json = false;
112
		}
112
		}
113
		return $json;
113
		return $json;
114
	}
114
	}
115
	
115
	
116
	private function getFlux($nom) {
116
	private function getFlux($nom) {
117
		$nom = strtolower($nom);
117
		$nom = strtolower($nom);
118
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
118
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
119
	}
119
	}
120
 
120
 
121
	private function setFlux($nom, $titre, $description) {
121
	private function setFlux($nom, $titre, $description) {
122
		$url_base = $this->config['coel']['urlBaseJrest'].'CoelSyndication/';
122
		$url_base = $this->config['coel']['urlBaseJrest'].'CoelSyndication/';
123
		$formats = array('atom', 'rss2', 'rss1');
123
		$formats = array('atom', 'rss2', 'rss1');
124
		$flux = array();
124
		$flux = array();
125
		foreach ($formats as $format) {
125
		foreach ($formats as $format) {
126
			$url = $url_base.$nom.'/'.$format;
126
			$url = $url_base.$nom.'/'.$format;
127
			$flux[$format] = $url;
127
			$flux[$format] = $url;
128
		}
128
		}
129
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
129
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
130
	}
130
	}
131
	
131
	
132
	private function chargerListeDesFlux() {
132
	private function chargerListeDesFlux() {
133
		
-
 
134
		$this->setFlux('projet', 'Flux de syndication des projets', 
-
 
135
			'Ce flux fournit des informations sur les mises à jour des projets saisis dans COEL.');
-
 
136
		$this->setFlux('structure','Flux de syndication des institutions',
133
		$this->setFlux('structure','Flux de syndication des institutions',
137
			'Ce flux fournit des informations sur les mises à jour des institutions saisies dans COEL.');
134
			'Ce flux fournit des informations sur les mises à jour des institutions saisies dans COEL.');
138
		$this->setFlux('collection', 'Flux de syndication des Collections',
135
		$this->setFlux('collection', 'Flux de syndication des Collections',
139
			'Ce flux fournit des informations sur les mises à jour des collections saisies dans COEL.');
136
			'Ce flux fournit des informations sur les mises à jour des collections saisies dans COEL.');
140
		$this->setFlux('personne', 'Flux de syndication des personnes',
137
		$this->setFlux('personne', 'Flux de syndication des personnes',
141
			'Ce flux fournit des informations sur les mises à jour des personnes saisies dans COEL.');
138
			'Ce flux fournit des informations sur les mises à jour des personnes saisies dans COEL.');
142
		$this->setFlux('publication', 'Flux de syndication des publications',
139
		$this->setFlux('publication', 'Flux de syndication des publications',
143
			'Ce flux fournit des informations sur les mises à jour des publications saisies dans COEL.');
140
			'Ce flux fournit des informations sur les mises à jour des publications saisies dans COEL.');
144
		$this->setFlux('commentaire', 'Flux de syndication des notes',
141
		$this->setFlux('commentaire', 'Flux de syndication des notes',
145
			'Ce flux fournit des informations sur les mises à jour des notes saisies dans COEL.');
142
			'Ce flux fournit des informations sur les mises à jour des notes saisies dans COEL.');
146
	}
143
	}
147
	
144
	
148
	private function getServiceListeDesFlux() {
145
	private function getServiceListeDesFlux() {
149
		return $this->flux;
146
		return $this->flux;
150
	}
147
	}
151
	
-
 
152
	private function getServiceProjet() {
-
 
153
		// Construction de la requête
-
 
154
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
-
 
155
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, '.
-
 
156
			'	h1.cmhl_enregistrement, '.
-
 
157
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
-
 
158
			'	h1.cmhl_cle_ligne AS guid, '.
-
 
159
			"	'prj' AS guid_type, ".
-
 
160
			'	cp_fmt_nom_complet AS modifier_par '.
-
 
161
			'FROM coel_meta_historique_ligne AS h1 '. 
-
 
162
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
-
 
163
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
-
 
164
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
-
 
165
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
-
 
166
			'	LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
-
 
167
			'WHERE h1.cmhl_ce_table = 115 %s '.
-
 
168
			'GROUP BY h1.cmhl_cle_ligne, h1.cmhl_date_modification, h1.cmhl_date_modification '. 
-
 
169
			'HAVING COUNT(*) = %s '.
-
 
170
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
-
 
171
			"LIMIT $this->start,$this->limit ";
-
 
172
		
-
 
173
		$elements = $this->executerRequeteHistorique($requete);
-
 
174
		
-
 
175
		// Création du contenu
-
 
176
		$contenu = $this->executerService('cpr_nom', $elements);
-
 
177
		return $contenu;
-
 
178
	}
-
 
179
	
148
	
180
	private function getServiceStructure() {
149
	private function getServiceStructure() {
181
		$elements = array();
150
		$elements = array();
182
		$elements = array_merge($elements, $this->getHistoriqueTableStructure(120));
151
		$elements = array_merge($elements, $this->getHistoriqueTableStructure(120));
183
		$elements = array_merge($elements, $this->getHistoriqueTableStructure(122));
152
		$elements = array_merge($elements, $this->getHistoriqueTableStructure(122));
184
		$elements = array_merge($elements, $this->getHistoriqueTableStructure(123));
153
		$elements = array_merge($elements, $this->getHistoriqueTableStructure(123));
185
		$elements = array_merge($elements, $this->getHistoriqueStructureAPersonne());
154
		$elements = array_merge($elements, $this->getHistoriqueStructureAPersonne());
186
		krsort($elements);
155
		krsort($elements);
187
		$elements = array_slice($elements, 0, ($this->limit/2));
156
		$elements = array_slice($elements, 0, ($this->limit/2));
188
 
157
 
189
		// Création du contenu
158
		// Création du contenu
190
		$contenu = $this->executerService('cs_nom', $elements);
159
		$contenu = $this->executerService('cs_nom', $elements);
191
		return $contenu;
160
		return $contenu;
192
	}
161
	}
193
	
162
	
194
	private function getHistoriqueTableStructure($table_id) {
163
	private function getHistoriqueTableStructure($table_id) {
195
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
164
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
196
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
165
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
197
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
166
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
198
			'	h1.cmhl_cle_ligne AS guid, '.
167
			'	h1.cmhl_cle_ligne AS guid, '.
199
			"	'str' AS guid_type, ".
168
			"	'str' AS guid_type, ".
200
			(($table_id != 120) ? '	CONCAT(IF (h1.cmhl_ce_table = 122, "Conservation", "Valorisation"), " - ", cs_nom) AS titre, ' : '').
169
			(($table_id != 120) ? '	CONCAT(IF (h1.cmhl_ce_table = 122, "Conservation", "Valorisation"), " - ", cs_nom) AS titre, ' : '').
201
			'	cp_fmt_nom_complet AS modifier_par '.
170
			'	cp_fmt_nom_complet AS modifier_par '.
202
			'FROM coel_meta_historique_ligne AS h1 '. 
171
			'FROM coel_meta_historique_ligne AS h1 '. 
203
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
172
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
204
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
173
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
205
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
174
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
206
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
175
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
207
			'	LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
176
			'	LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
208
			(($table_id != 120) ? '	LEFT JOIN coel_structure ON (cs_id_structure = h1.cmhl_cle_ligne) ' : '').
177
			(($table_id != 120) ? '	LEFT JOIN coel_structure ON (cs_id_structure = h1.cmhl_cle_ligne) ' : '').
209
			"WHERE h1.cmhl_ce_table = $table_id %s ".
178
			"WHERE h1.cmhl_ce_table = $table_id %s ".
210
			(($table_id != 120) ? '	AND h1.cmhl_ce_etat != 3 ' : '').
179
			(($table_id != 120) ? '	AND h1.cmhl_ce_etat != 3 ' : '').
211
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
180
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
212
			'HAVING COUNT(*) = %s '.
181
			'HAVING COUNT(*) = %s '.
213
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
182
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
214
			"LIMIT $this->start,$this->limit ";
183
			"LIMIT $this->start,$this->limit ";
215
		
184
		
216
		$elements = $this->executerRequeteHistorique($requete);
185
		$elements = $this->executerRequeteHistorique($requete);
217
		return $elements;
186
		return $elements;
218
	}
187
	}
219
	
188
	
220
	private function getHistoriqueStructureAPersonne() {
189
	private function getHistoriqueStructureAPersonne() {
221
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
190
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
222
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
191
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
223
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
192
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
224
			'	h1.cmhl_cle_ligne AS guid, '.
193
			'	h1.cmhl_cle_ligne AS guid, '.
225
			"	'csap' AS guid_type, ".
194
			"	'csap' AS guid_type, ".
226
			'	p1.cp_fmt_nom_complet AS modifier_par, '.
195
			'	p1.cp_fmt_nom_complet AS modifier_par, '.
227
			'	CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une personne liée à «", s1.cs_nom, "»") AS titre, '.
196
			'	CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une personne liée à «", s1.cs_nom, "»") AS titre, '.
228
			'	CONCAT("Personne «", p2.cp_fmt_nom_complet, "» liée à «", s1.cs_nom, "» avec rôle «", lv1.cmlv_nom, "»") AS description '.
197
			'	CONCAT("Personne «", p2.cp_fmt_nom_complet, "» liée à «", s1.cs_nom, "» avec rôle «", lv1.cmlv_nom, "»") AS description '.
229
			'FROM coel_meta_historique_ligne AS h1 '. 
198
			'FROM coel_meta_historique_ligne AS h1 '. 
230
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
199
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
231
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
200
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
232
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
201
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
233
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
202
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
234
			'	LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
203
			'	LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
235
		  	'	LEFT JOIN coel_personne AS p2 '.
204
		  	'	LEFT JOIN coel_personne AS p2 '.
236
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = p2.cp_id_personne) ". 
205
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = p2.cp_id_personne) ". 
237
  			'	LEFT JOIN coel_structure AS s1 '.
206
  			'	LEFT JOIN coel_structure AS s1 '.
238
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = s1.cs_id_structure) ".
207
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = s1.cs_id_structure) ".
239
  			'	LEFT JOIN coel_meta_liste_valeur AS lv1 '.
208
  			'	LEFT JOIN coel_meta_liste_valeur AS lv1 '.
240
			"		ON (SUBSTRING_INDEX(SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 2), '-', -1) = lv1.cmlv_id_valeur) ".
209
			"		ON (SUBSTRING_INDEX(SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 2), '-', -1) = lv1.cmlv_id_valeur) ".
241
			'WHERE h1.cmhl_ce_table = 121 %s '.
210
			'WHERE h1.cmhl_ce_table = 121 %s '.
242
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
211
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
243
			'HAVING COUNT(*) = %s '.
212
			'HAVING COUNT(*) = %s '.
244
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
213
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
245
			"LIMIT $this->start,$this->limit ";
214
			"LIMIT $this->start,$this->limit ";
246
 
215
 
247
		$elements = $this->executerRequeteHistorique($requete);
216
		$elements = $this->executerRequeteHistorique($requete);
248
		return $elements;
217
		return $elements;
249
	}
218
	}
250
	
219
	
251
	private function getServiceCollection() {
220
	private function getServiceCollection() {
252
		$elements = array();
221
		$elements = array();
253
		$elements = array_merge($elements, $this->getHistoriqueTableCollection(101));
222
		$elements = array_merge($elements, $this->getHistoriqueTableCollection(101));
254
		$elements = array_merge($elements, $this->getHistoriqueTableCollection(106));
223
		$elements = array_merge($elements, $this->getHistoriqueTableCollection(106));
255
		$elements = array_merge($elements, $this->getHistoriqueCollectionAPersonne());
224
		$elements = array_merge($elements, $this->getHistoriqueCollectionAPersonne());
256
		$elements = array_merge($elements, $this->getHistoriqueCollectionAPublication());
225
		$elements = array_merge($elements, $this->getHistoriqueCollectionAPublication());
257
		$elements = array_merge($elements, $this->getHistoriqueCollectionACommentaire());
226
		$elements = array_merge($elements, $this->getHistoriqueCollectionACommentaire());
258
		krsort($elements);
227
		krsort($elements);
259
		$elements = array_slice($elements, 0, ($this->limit/2));
228
		$elements = array_slice($elements, 0, ($this->limit/2));
260
		//echo '<pre>'.print_r($elements, true).'</pre>';
229
		//echo '<pre>'.print_r($elements, true).'</pre>';
261
		// Création du contenu
230
		// Création du contenu
262
		$contenu = $this->executerService('cc_nom', $elements);
231
		$contenu = $this->executerService('cc_nom', $elements);
263
		return $contenu;
232
		return $contenu;
264
	}
233
	}
265
	
234
	
266
	private function getHistoriqueTableCollection($table_id) {
235
	private function getHistoriqueTableCollection($table_id) {
267
		// Reque générale avec paramêtres
236
		// Reque générale avec paramêtres
268
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
237
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
269
					'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
238
					'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
270
					'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
239
					'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
271
					'	h1.cmhl_cle_ligne AS guid, '.
240
					'	h1.cmhl_cle_ligne AS guid, '.
272
					"	'col' AS guid_type, ".
241
					"	'col' AS guid_type, ".
273
					(($table_id == 106) ? '	CONCAT("Botanique", " - ", cc_nom) AS titre, ' : '').
242
					(($table_id == 106) ? '	CONCAT("Botanique", " - ", cc_nom) AS titre, ' : '').
274
					'	cp_fmt_nom_complet AS modifier_par '.
243
					'	cp_fmt_nom_complet AS modifier_par '.
275
					'FROM coel_meta_historique_ligne AS h1 '. 
244
					'FROM coel_meta_historique_ligne AS h1 '. 
276
    				'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
245
    				'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
277
    				'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
246
    				'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
278
					'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
247
					'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
279
					'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
248
					'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
280
					'	LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
249
					'	LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
281
					(($table_id == 106) ? '	LEFT JOIN coel_collection ON (cc_id_collection = h1.cmhl_cle_ligne) ' : '').
250
					(($table_id == 106) ? '	LEFT JOIN coel_collection ON (cc_id_collection = h1.cmhl_cle_ligne) ' : '').
282
					"WHERE h1.cmhl_ce_table = $table_id %s ".
251
					"WHERE h1.cmhl_ce_table = $table_id %s ".
283
					(($table_id == 106) ? '	AND h1.cmhl_ce_etat != 3 ' : '').
252
					(($table_id == 106) ? '	AND h1.cmhl_ce_etat != 3 ' : '').
284
					'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
253
					'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
285
					'HAVING COUNT(*) = %s '.
254
					'HAVING COUNT(*) = %s '.
286
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
255
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
287
					"LIMIT $this->start,$this->limit ";
256
					"LIMIT $this->start,$this->limit ";
288
		$elements = $this->executerRequeteHistorique($requete);
257
		$elements = $this->executerRequeteHistorique($requete);
289
		return $elements;
258
		return $elements;
290
	}
259
	}
291
	
260
	
292
	private function getHistoriqueCollectionAPersonne() {
261
	private function getHistoriqueCollectionAPersonne() {
293
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
262
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
294
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
263
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
295
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
264
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
296
			'	p1.cp_fmt_nom_complet AS modifier_par, '.
265
			'	p1.cp_fmt_nom_complet AS modifier_par, '.
297
			'	h1.cmhl_cle_ligne AS guid, '.
266
			'	h1.cmhl_cle_ligne AS guid, '.
298
			"	'ccap' AS guid_type, ".
267
			"	'ccap' AS guid_type, ".
299
			'	CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une personne liée à «", c1.cc_nom, "»") AS titre, '.
268
			'	CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une personne liée à «", c1.cc_nom, "»") AS titre, '.
300
			'	CONCAT("Personne «", p2.cp_fmt_nom_complet, "» liée à «", c1.cc_nom, "» avec rôle «", lv1.cmlv_nom, "»") AS description '.
269
			'	CONCAT("Personne «", p2.cp_fmt_nom_complet, "» liée à «", c1.cc_nom, "» avec rôle «", lv1.cmlv_nom, "»") AS description '.
301
			'FROM coel_meta_historique_ligne AS h1 '. 
270
			'FROM coel_meta_historique_ligne AS h1 '. 
302
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
271
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
303
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
272
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
304
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
273
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
305
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
274
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
306
			'	LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
275
			'	LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
307
		  	'	LEFT JOIN coel_personne AS p2 '.
276
		  	'	LEFT JOIN coel_personne AS p2 '.
308
			"		ON (SUBSTRING_INDEX(SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 2), '-', -1) = p2.cp_id_personne) ". 
277
			"		ON (SUBSTRING_INDEX(SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 2), '-', -1) = p2.cp_id_personne) ". 
309
  			'	LEFT JOIN coel_collection AS c1 '.
278
  			'	LEFT JOIN coel_collection AS c1 '.
310
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = c1.cc_id_collection) ".
279
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = c1.cc_id_collection) ".
311
  			'	LEFT JOIN coel_meta_liste_valeur AS lv1 '.
280
  			'	LEFT JOIN coel_meta_liste_valeur AS lv1 '.
312
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = lv1.cmlv_id_valeur) ".
281
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = lv1.cmlv_id_valeur) ".
313
			'WHERE h1.cmhl_ce_table = 103 %s '.
282
			'WHERE h1.cmhl_ce_table = 103 %s '.
314
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
283
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
315
			'HAVING COUNT(*) = %s '.
284
			'HAVING COUNT(*) = %s '.
316
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
285
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
317
			"LIMIT $this->start,$this->limit ";
286
			"LIMIT $this->start,$this->limit ";
318
		
287
		
319
		$elements = $this->executerRequeteHistorique($requete);
288
		$elements = $this->executerRequeteHistorique($requete);
320
		return $elements;
289
		return $elements;
321
	}
290
	}
322
	
291
	
323
	private function getHistoriqueCollectionAPublication() {
292
	private function getHistoriqueCollectionAPublication() {
324
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
293
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
325
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
294
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
326
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
295
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
327
			'	p1.cp_fmt_nom_complet AS modifier_par, '.
296
			'	p1.cp_fmt_nom_complet AS modifier_par, '.
328
			'	h1.cmhl_cle_ligne AS guid, '.
297
			'	h1.cmhl_cle_ligne AS guid, '.
329
			"	'ccapu' AS guid_type, ".
298
			"	'ccapu' AS guid_type, ".
330
			'	CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une publication liée à «", c1.cc_nom, "»") AS titre, '.
299
			'	CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une publication liée à «", c1.cc_nom, "»") AS titre, '.
331
			'	CONCAT("Publication «", p2.cpu_fmt_nom_complet, "» liée à «", c1.cc_nom, "»") AS description '.
300
			'	CONCAT("Publication «", p2.cpu_fmt_nom_complet, "» liée à «", c1.cc_nom, "»") AS description '.
332
			'FROM coel_meta_historique_ligne AS h1 '. 
301
			'FROM coel_meta_historique_ligne AS h1 '. 
333
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
302
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
334
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
303
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
335
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
304
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
336
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
305
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
337
			'	LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
306
			'	LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
338
		  	'	LEFT JOIN coel_publication AS p2 '.
307
		  	'	LEFT JOIN coel_publication AS p2 '.
339
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = p2.cpu_id_publication) ". 
308
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = p2.cpu_id_publication) ". 
340
  			'	LEFT JOIN coel_collection AS c1 '.
309
  			'	LEFT JOIN coel_collection AS c1 '.
341
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = c1.cc_id_collection) ".
310
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = c1.cc_id_collection) ".
342
			'WHERE h1.cmhl_ce_table = 104 %s '.
311
			'WHERE h1.cmhl_ce_table = 104 %s '.
343
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
312
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
344
			'HAVING COUNT(*) = %s '.
313
			'HAVING COUNT(*) = %s '.
345
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
314
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
346
			"LIMIT $this->start,$this->limit ";
315
			"LIMIT $this->start,$this->limit ";
347
		
316
		
348
		$elements = $this->executerRequeteHistorique($requete);
317
		$elements = $this->executerRequeteHistorique($requete);
349
		return $elements;
318
		return $elements;
350
	}
319
	}
351
	
320
	
352
	private function getHistoriqueCollectionACommentaire() {
321
	private function getHistoriqueCollectionACommentaire() {
353
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
322
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
354
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
323
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
355
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
324
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
356
			'	p1.cp_fmt_nom_complet AS modifier_par, '.
325
			'	p1.cp_fmt_nom_complet AS modifier_par, '.
357
			'	h1.cmhl_cle_ligne AS guid, '.
326
			'	h1.cmhl_cle_ligne AS guid, '.
358
			"	'ccacm' AS guid_type, ".
327
			"	'ccacm' AS guid_type, ".
359
			'	CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'un commentaire lié à «", c1.cc_nom, "»") AS titre, '.
328
			'	CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'un commentaire lié à «", c1.cc_nom, "»") AS titre, '.
360
			'	CONCAT("Commentaire «", c.ccm_titre, "» liée à «", c1.cc_nom, "»") AS description '.
329
			'	CONCAT("Commentaire «", c.ccm_titre, "» liée à «", c1.cc_nom, "»") AS description '.
361
			'FROM coel_meta_historique_ligne AS h1 '. 
330
			'FROM coel_meta_historique_ligne AS h1 '. 
362
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
331
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
363
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
332
    		'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
364
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
333
			'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
365
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
334
			'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
366
			'	LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
335
			'	LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
367
		  	'	LEFT JOIN coel_commentaire AS c '.
336
		  	'	LEFT JOIN coel_commentaire AS c '.
368
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = c.ccm_id_commentaire) ". 
337
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = c.ccm_id_commentaire) ". 
369
  			'	LEFT JOIN coel_collection AS c1 '.
338
  			'	LEFT JOIN coel_collection AS c1 '.
370
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = c1.cc_id_collection) ".
339
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = c1.cc_id_collection) ".
371
			'WHERE h1.cmhl_ce_table = 102 %s '.
340
			'WHERE h1.cmhl_ce_table = 102 %s '.
372
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
341
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
373
			'HAVING COUNT(*) = %s '.
342
			'HAVING COUNT(*) = %s '.
374
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
343
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
375
			"LIMIT $this->start,$this->limit ";
344
			"LIMIT $this->start,$this->limit ";
376
		
345
		
377
		$elements = $this->executerRequeteHistorique($requete);
346
		$elements = $this->executerRequeteHistorique($requete);
378
		return $elements;
347
		return $elements;
379
	}
348
	}
380
	
349
	
381
	private function getServicePersonne() {
350
	private function getServicePersonne() {
382
		$elements = array();
351
		$elements = array();
383
		$elements = array_merge($elements, $this->getHistoriqueTable(113, 'per'));
352
		$elements = array_merge($elements, $this->getHistoriqueTable(113, 'per'));
384
		$elements = array_merge($elements, $this->getHistoriquePublicationAPersonne());
353
		$elements = array_merge($elements, $this->getHistoriquePublicationAPersonne());
385
		krsort($elements);
354
		krsort($elements);
386
		$elements = array_slice($elements, 0, ($this->limit/2));
355
		$elements = array_slice($elements, 0, ($this->limit/2));
387
		//echo '<pre>'.print_r($elements, true).'</pre>';
356
		//echo '<pre>'.print_r($elements, true).'</pre>';
388
		// Création du contenu
357
		// Création du contenu
389
		$contenu = $this->executerService('cp_fmt_nom_complet', $elements);
358
		$contenu = $this->executerService('cp_fmt_nom_complet', $elements);
390
		return $contenu;
359
		return $contenu;
391
	}
360
	}
392
	
361
	
393
	private function getHistoriquePublicationAPersonne() {
362
	private function getHistoriquePublicationAPersonne() {
394
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
363
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
395
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
364
			'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
396
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
365
			'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
397
			'	p1.cp_fmt_nom_complet AS modifier_par, '.
366
			'	p1.cp_fmt_nom_complet AS modifier_par, '.
398
			'	h1.cmhl_cle_ligne AS guid, '.
367
			'	h1.cmhl_cle_ligne AS guid, '.
399
			"	'cpap' AS guid_type, ".
368
			"	'cpap' AS guid_type, ".
400
			'	CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une publication liée à «", p2.cp_fmt_nom_complet, "»") AS titre, '.
369
			'	CONCAT(IF(h1.cmhl_ce_etat = 1, "Ajout", IF (h1.cmhl_ce_etat = 3, "Suppression", "Modification")), " d\'une publication liée à «", p2.cp_fmt_nom_complet, "»") AS titre, '.
401
			'	CONCAT("Publication «", pu.cpu_fmt_nom_complet, "» liée à «", p2.cp_fmt_nom_complet, "» avec rôle «", lv1.cmlv_nom, "»") AS description '.
370
			'	CONCAT("Publication «", pu.cpu_fmt_nom_complet, "» liée à «", p2.cp_fmt_nom_complet, "» avec rôle «", lv1.cmlv_nom, "»") AS description '.
402
			'FROM coel_meta_historique_ligne AS h1 '. 
371
			'FROM coel_meta_historique_ligne AS h1 '. 
403
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
372
    		'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
404
    		'		ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
373
    		'		ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
405
			'			AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
374
			'			AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
406
			'			AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
375
			'			AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
407
			'	LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
376
			'	LEFT JOIN coel_personne AS p1 ON (h1.cmhl_ce_modifier_par = p1.cp_id_personne) '.
408
		  	'	LEFT JOIN coel_publication AS pu '.
377
		  	'	LEFT JOIN coel_publication AS pu '.
409
			"		ON (SUBSTRING_INDEX(SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 2), '-', -1) = pu.cpu_id_publication) ". 
378
			"		ON (SUBSTRING_INDEX(SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 2), '-', -1) = pu.cpu_id_publication) ". 
410
  			'	LEFT JOIN coel_personne AS p2 '.
379
  			'	LEFT JOIN coel_personne AS p2 '.
411
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = p2.cp_id_personne) ".
380
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', 1) = p2.cp_id_personne) ".
412
			'	LEFT JOIN coel_meta_liste_valeur AS lv1 '.
381
			'	LEFT JOIN coel_meta_liste_valeur AS lv1 '.
413
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = lv1.cmlv_id_valeur) ".
382
			"		ON (SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) = lv1.cmlv_id_valeur) ".
414
			'WHERE h1.cmhl_ce_table = 119 '.
383
			'WHERE h1.cmhl_ce_table = 119 '.
415
			'	%s '.
384
			'	%s '.
416
			"	AND SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) IN (2361,2362,2363) ".
385
			"	AND SUBSTRING_INDEX(h1.cmhl_cle_ligne, '-', -1) IN (2361,2362,2363) ".
417
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
386
			'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
418
			'HAVING COUNT(*) = %s '.
387
			'HAVING COUNT(*) = %s '.
419
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
388
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
420
			"LIMIT $this->start,$this->limit ";
389
			"LIMIT $this->start,$this->limit ";
421
		
390
		
422
		$elements = $this->executerRequeteHistorique($requete);
391
		$elements = $this->executerRequeteHistorique($requete);
423
		return $elements;
392
		return $elements;
424
	}
393
	}
425
		
394
		
426
	private function getServicePublication() {
395
	private function getServicePublication() {
427
		$elements = array();
396
		$elements = array();
428
		$elements = $this->getHistoriqueTable(118, 'pub');
397
		$elements = $this->getHistoriqueTable(118, 'pub');
429
		krsort($elements);
398
		krsort($elements);
430
		$elements = array_slice($elements, 0, ($this->limit/2));
399
		$elements = array_slice($elements, 0, ($this->limit/2));
431
		//echo '<pre>'.print_r($elements, true).'</pre>';
400
		//echo '<pre>'.print_r($elements, true).'</pre>';
432
		// Création du contenu
401
		// Création du contenu
433
		$contenu = $this->executerService('cpu_fmt_nom_complet', $elements);
402
		$contenu = $this->executerService('cpu_fmt_nom_complet', $elements);
434
		return $contenu;
403
		return $contenu;
435
	}
404
	}
436
	
405
	
437
	private function getServiceCommentaire() {
406
	private function getServiceCommentaire() {
438
		$elements = array();
407
		$elements = array();
439
		$elements = $this->getHistoriqueTable(107, 'com');
408
		$elements = $this->getHistoriqueTable(107, 'com');
440
		krsort($elements);
409
		krsort($elements);
441
		$elements = array_slice($elements, 0, ($this->limit/2));
410
		$elements = array_slice($elements, 0, ($this->limit/2));
442
		//echo '<pre>'.print_r($elements, true).'</pre>';
411
		//echo '<pre>'.print_r($elements, true).'</pre>';
443
		// Création du contenu
412
		// Création du contenu
444
		$contenu = $this->executerService('ccm_titre', $elements);
413
		$contenu = $this->executerService('ccm_titre', $elements);
445
		return $contenu;
414
		return $contenu;
446
	}
415
	}
447
	
416
	
448
	private function getHistoriqueTable($table_id, $guid_type) {
417
	private function getHistoriqueTable($table_id, $guid_type) {
449
		// Reque générale avec paramêtres
418
		// Reque générale avec paramêtres
450
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
419
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' '.
451
					'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
420
					'	h1.cmhl_id_historique_ligne, h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_enregistrement, '.
452
					'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
421
					'	h1.cmhl_date_modification, h1.cmhl_ce_etat, h1.cmhl_ip, '.
453
					'	h1.cmhl_cle_ligne AS guid, '.
422
					'	h1.cmhl_cle_ligne AS guid, '.
454
					"	'$guid_type' AS guid_type, ".
423
					"	'$guid_type' AS guid_type, ".
455
					'	cp_fmt_nom_complet AS modifier_par '.
424
					'	cp_fmt_nom_complet AS modifier_par '.
456
					'FROM coel_meta_historique_ligne AS h1 '. 
425
					'FROM coel_meta_historique_ligne AS h1 '. 
457
    				'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
426
    				'	LEFT JOIN coel_meta_historique_ligne AS h2  '. 
458
    				'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
427
    				'	ON (h1.cmhl_ce_table = h2.cmhl_ce_table '.
459
					'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
428
					'		AND h1.cmhl_cle_ligne = h2.cmhl_cle_ligne '.
460
					'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
429
					'		AND h1.cmhl_date_modification <= h2.cmhl_date_modification ) '.
461
					'	LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
430
					'	LEFT JOIN coel_personne ON (h1.cmhl_ce_modifier_par = cp_id_personne) '.
462
					"WHERE h1.cmhl_ce_table = $table_id %s ".
431
					"WHERE h1.cmhl_ce_table = $table_id %s ".
463
					'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
432
					'GROUP BY h1.cmhl_ce_table, h1.cmhl_cle_ligne, h1.cmhl_date_modification '. 
464
					'HAVING COUNT(*) = %s '.
433
					'HAVING COUNT(*) = %s '.
465
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
434
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'h1.cmhl_date_modification DESC').' '.
466
					"LIMIT $this->start,$this->limit ";
435
					"LIMIT $this->start,$this->limit ";
467
		$elements = $this->executerRequeteHistorique($requete);
436
		$elements = $this->executerRequeteHistorique($requete);
468
		return $elements;
437
		return $elements;
469
	}
438
	}
470
	
439
	
471
	private function executerRequete($requete) {
440
	private function executerRequete($requete) {
472
		try {
441
		try {
473
			$infos = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
442
			$infos = $this->bdd->query($requete)->fetchAll(PDO::FETCH_ASSOC);
474
			if ($infos === false) {
443
			if ($infos === false) {
475
				$this->messages[] = "La requête a retourné aucun résultat.";
444
				$this->messages[] = "La requête a retourné aucun résultat.";
476
			}
445
			}
477
		} catch (PDOException $e) {
446
		} catch (PDOException $e) {
478
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
447
			$this->messages[] = sprintf($this->getTxt('sql_erreur'), $e->getFile(), $e->getLine(), $e->getMessage());
479
		}
448
		}
480
		return $infos;
449
		return $infos;
481
	}
450
	}
482
	
451
	
483
	private function fusionnerEnregistrements($infos) {
452
	private function fusionnerEnregistrements($infos) {
484
		// Fusion des lignes
453
		// Fusion des lignes
485
		$elements = array();
454
		$elements = array();
486
		foreach ($infos as $info) {
455
		foreach ($infos as $info) {
487
			$id = $info['cmhl_ce_table'].'|'.$info['cmhl_cle_ligne'];
456
			$id = $info['cmhl_ce_table'].'|'.$info['cmhl_cle_ligne'];
488
			if (!isset($elements[$id])) {
457
			if (!isset($elements[$id])) {
489
				$elements[$id] = $info;
458
				$elements[$id] = $info;
490
			} else {
459
			} else {
491
				if ($elements[$id]['cmhl_date_modification'] < $info['cmhl_date_modification']) {
460
				if ($elements[$id]['cmhl_date_modification'] < $info['cmhl_date_modification']) {
492
					$elements[$id] = $this->traiterInfosPrecedentes($info, $elements[$id]);
461
					$elements[$id] = $this->traiterInfosPrecedentes($info, $elements[$id]);
493
				} else {
462
				} else {
494
					$elements[$id] = $this->traiterInfosPrecedentes($elements[$id], $info);
463
					$elements[$id] = $this->traiterInfosPrecedentes($elements[$id], $info);
495
				}
464
				}
496
			}
465
			}
497
		}
466
		}
498
		
467
		
499
		// Nettoyage et utilisation de la date pour pouvoir trier le tableau
468
		// Nettoyage et utilisation de la date pour pouvoir trier le tableau
500
		$sortie = array();
469
		$sortie = array();
501
		foreach ($elements as $id => $element) {
470
		foreach ($elements as $id => $element) {
502
			$element = $this->nettoyerNomChamps($element);
471
			$element = $this->nettoyerNomChamps($element);
503
			$id_avec_date = $element['cmhl_date_modification'].'|'.$id;
472
			$id_avec_date = $element['cmhl_date_modification'].'|'.$id;
504
			$sortie[$id_avec_date] = $element;
473
			$sortie[$id_avec_date] = $element;
505
		}
474
		}
506
		
475
		
507
		return $sortie;
476
		return $sortie;
508
	}
477
	}
509
	
478
	
510
	private function executerRequeteHistorique($requete) {
479
	private function executerRequeteHistorique($requete) {
511
		$elements = array();
480
		$elements = array();
512
		
481
		
513
		// Récupération des 1er éléments
482
		// Récupération des 1er éléments
514
		$requete_elements_1er = sprintf($requete, '', '1');
483
		$requete_elements_1er = sprintf($requete, '', '1');
515
		$infos_elements_1er = $this->executerRequete($requete_elements_1er);
484
		$infos_elements_1er = $this->executerRequete($requete_elements_1er);
516
		
485
		
517
		// Construction de la requête pour récupérer les second éléments
486
		// Construction de la requête pour récupérer les second éléments
518
		$elements_1er_cle_ligne = array();
487
		$elements_1er_cle_ligne = array();
519
		foreach ($infos_elements_1er as $info) {
488
		foreach ($infos_elements_1er as $info) {
520
			$elements_1er_cle_ligne[] = $info['cmhl_cle_ligne'];
489
			$elements_1er_cle_ligne[] = $info['cmhl_cle_ligne'];
521
		}
490
		}
522
		$chaine_1er_elements = 'AND h1.cmhl_cle_ligne IN ('.str_replace(',,',',',implode(',', $elements_1er_cle_ligne)).') ';
491
		$chaine_1er_elements = 'AND h1.cmhl_cle_ligne IN ('.str_replace(',,',',',implode(',', $elements_1er_cle_ligne)).') ';
523
		$requete_elements_2nd = sprintf($requete, $chaine_1er_elements, '2');
492
		$requete_elements_2nd = sprintf($requete, $chaine_1er_elements, '2');
524
		
493
		
525
		// Récupération des 2nd éléments
494
		// Récupération des 2nd éléments
526
		$infos_elements_2nd = $this->executerRequete($requete_elements_2nd);
495
		$infos_elements_2nd = $this->executerRequete($requete_elements_2nd);
527
		
496
		
528
		// Fusion des 1er et 2nd éléments 
497
		// Fusion des 1er et 2nd éléments 
529
		$infos = array_merge($infos_elements_1er, $infos_elements_2nd);
498
		$infos = array_merge($infos_elements_1er, $infos_elements_2nd);
530
		
499
		
531
		$elements = $this->fusionnerEnregistrements($infos);
500
		$elements = $this->fusionnerEnregistrements($infos);
532
		return $elements;
501
		return $elements;
533
	}
502
	}
534
	
503
	
535
	private function executerService($champ_titre, $elements) {
504
	private function executerService($champ_titre, $elements) {
536
		// Prétraitement des données
505
		// Prétraitement des données
537
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
506
		$donnees = $this->construireDonneesCommunesAuFlux($elements);
538
		foreach ($elements as $element) {
507
		foreach ($elements as $element) {
539
			$xml = $this->getXmlHisto($element);
508
			$xml = $this->getXmlHisto($element);
540
			$enrg = $this->getTableauDepuisXmlHisto($xml);
509
			$enrg = $this->getTableauDepuisXmlHisto($xml);
541
			$diff = $this->getDiffInfos($element);
510
			$diff = $this->getDiffInfos($element);
542
			$diff['differences'] = $this->getDiff($element);
511
			$diff['differences'] = $this->getDiff($element);
543
			$diff_html = (!is_null($diff['differences'])) ? Coel::traiterSquelettePhp($this->squelette_diff, $diff) : '';
512
			$diff_html = (!is_null($diff['differences'])) ? Coel::traiterSquelettePhp($this->squelette_diff, $diff) : '';
544
			
513
			
545
			$item = $this->construireDonneesCommunesAuxItems($element);
514
			$item = $this->construireDonneesCommunesAuxItems($element);
546
			$item['titre'] = $this->creerTitre($champ_titre, $element, $enrg);
515
			$item['titre'] = $this->creerTitre($champ_titre, $element, $enrg);
547
			$item['guid'] = sprintf($this->config['coel']['guid'], 'coel', $element['guid_type'].$element['guid']);
516
			$item['guid'] = sprintf($this->config['coel']['guid'], 'coel', $element['guid_type'].$element['guid']);
548
			$item['lien'] = $this->config['coel']['urlBaseCoel'].'#'.urlencode($item['guid']);
517
			$item['lien'] = $this->config['coel']['urlBaseCoel'].'#'.urlencode($item['guid']);
549
			$item['description'] = '<p>'.$this->getMessageModif($item).'</p>';
518
			$item['description'] = '<p>'.$this->getMessageModif($item).'</p>';
550
			$item['description'] .= $this->creerDescription($element, $enrg);
519
			$item['description'] .= $this->creerDescription($element, $enrg);
551
			$item['description'] .= $diff_html;
520
			$item['description'] .= $diff_html;
552
			$item['description'] = $this->nettoyerTexte($item['description']);
521
			$item['description'] = $this->nettoyerTexte($item['description']);
553
			$item['description_encodee'] = htmlspecialchars($item['description']);
522
			$item['description_encodee'] = htmlspecialchars($item['description']);
554
			
523
			
555
			$donnees['items'][] = $item;
524
			$donnees['items'][] = $item;
556
		}
525
		}
557
		
526
		
558
		// Création du contenu à partir d'un template PHP
527
		// Création du contenu à partir d'un template PHP
559
		$contenu = Coel::traiterSquelettePhp($this->squelette, $donnees);
528
		$contenu = Coel::traiterSquelettePhp($this->squelette, $donnees);
560
		
529
		
561
		return $contenu;
530
		return $contenu;
562
	}
531
	}
563
	
532
	
564
	private function creerTitre($champ, $element, $enrg) {
533
	private function creerTitre($champ, $element, $enrg) {
565
		$titre = '';
534
		$titre = '';
566
		if (isset($element['titre'])) {
535
		if (isset($element['titre'])) {
567
			$titre = $element['titre'];
536
			$titre = $element['titre'];
568
		} else if (isset($element[$champ])) {
537
		} else if (isset($element[$champ])) {
569
			$titre = $element[$champ];
538
			$titre = $element[$champ];
570
		} else if (isset($enrg[$champ])) {
539
		} else if (isset($enrg[$champ])) {
571
			$titre = $enrg[$champ];
540
			$titre = $enrg[$champ];
572
		}
541
		}
573
		$titre = $this->nettoyerTexte($titre);
542
		$titre = $this->nettoyerTexte($titre);
574
		return $titre;
543
		return $titre;
575
	}
544
	}
576
	
545
	
577
	private function creerDescription($element, $enrg) {
546
	private function creerDescription($element, $enrg) {
578
		$description = '';
547
		$description = '';
579
		if (isset($element['description'])) {
548
		if (isset($element['description'])) {
580
			$description = $element['description'];
549
			$description = $element['description'];
581
		}
550
		}
582
		return $description;
551
		return $description;
583
	}
552
	}
584
	
553
	
585
	private function nettoyerNomChamps($infos) {
554
	private function nettoyerNomChamps($infos) {
586
		$sortie = array();
555
		$sortie = array();
587
		foreach ($infos as $champ => $valeur) {
556
		foreach ($infos as $champ => $valeur) {
588
			if (preg_match('/^__(.+)$/', $champ, $match)) {
557
			if (preg_match('/^__(.+)$/', $champ, $match)) {
589
				$sortie[$match[1]] = $valeur;
558
				$sortie[$match[1]] = $valeur;
590
			} else {
559
			} else {
591
				$sortie[$champ] = $valeur;
560
				$sortie[$champ] = $valeur;
592
			}
561
			}
593
		}
562
		}
594
		return $sortie;
563
		return $sortie;
595
	}
564
	}
596
	
565
	
597
	private function traiterInfosPrecedentes($infos_courantes, $infos_precedentes) {
566
	private function traiterInfosPrecedentes($infos_courantes, $infos_precedentes) {
598
		$infos_precedentes_traitees = array();
567
		$infos_precedentes_traitees = array();
599
		foreach ($infos_precedentes as $champ => $valeur) {
568
		foreach ($infos_precedentes as $champ => $valeur) {
600
			$infos_precedentes_traitees['enrg_prec'] = null;
569
			$infos_precedentes_traitees['enrg_prec'] = null;
601
			$infos_precedentes_traitees['date_prec'] = null;
570
			$infos_precedentes_traitees['date_prec'] = null;
602
			if ($champ == 'cmhl_date_modification') {
571
			if ($champ == 'cmhl_date_modification') {
603
				$infos_precedentes_traitees['date_prec'] = $valeur;
572
				$infos_precedentes_traitees['date_prec'] = $valeur;
604
			} else if ($champ == 'cmhl_enregistrement') {
573
			} else if ($champ == 'cmhl_enregistrement') {
605
				$infos_precedentes_traitees['enrg_prec'] = $valeur;
574
				$infos_precedentes_traitees['enrg_prec'] = $valeur;
606
			} else if (preg_match('/^__(.+)$/', $champ, $match)) {
575
			} else if (preg_match('/^__(.+)$/', $champ, $match)) {
607
				$infos_precedentes_traitees[$match[1].'_prec'] = $valeur;
576
				$infos_precedentes_traitees[$match[1].'_prec'] = $valeur;
608
			}
577
			}
609
		}
578
		}
610
		$sortie = array_merge($infos_courantes, $infos_precedentes_traitees);
579
		$sortie = array_merge($infos_courantes, $infos_precedentes_traitees);
611
		return $sortie;
580
		return $sortie;
612
	}
581
	}
613
	
582
	
614
	private function nettoyerTexte($txt) {
583
	private function nettoyerTexte($txt) {
615
		$txt = preg_replace('/&(?!amp;)/i', '&amp;', $txt, -1);
584
		$txt = preg_replace('/&(?!amp;)/i', '&amp;', $txt, -1);
616
		return $txt;
585
		return $txt;
617
	}
586
	}
618
	
587
	
619
	private function getMessageModif($item) {
588
	private function getMessageModif($item) {
620
		$message = $item['etat'].' le '.$item['date_maj_simple'].' par '.$item['modifier_par'].' depuis l\'IP '.$item['ip'];
589
		$message = $item['etat'].' le '.$item['date_maj_simple'].' par '.$item['modifier_par'].' depuis l\'IP '.$item['ip'];
621
		return $message;
590
		return $message;
622
	}
591
	}
623
	
592
	
624
	private function construireDonneesCommunesAuxItems($info) {
593
	private function construireDonneesCommunesAuxItems($info) {
625
		$item = array();
594
		$item = array();
626
		$date_modification_timestamp = strtotime($info['cmhl_date_modification']);
595
		$date_modification_timestamp = strtotime($info['cmhl_date_modification']);
627
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
596
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
628
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
597
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
629
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
598
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
630
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
599
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
631
		$item['guid'] = $info['cmhl_id_historique_ligne'];
600
		$item['guid'] = $info['cmhl_id_historique_ligne'];
632
		$item['cle'] = $info['cmhl_cle_ligne'];
601
		$item['cle'] = $info['cmhl_cle_ligne'];
633
		$item['ip'] = $info['cmhl_ip'];
602
		$item['ip'] = $info['cmhl_ip'];
634
		$item['modifier_par'] = $info['modifier_par'];
603
		$item['modifier_par'] = $info['modifier_par'];
635
		$item['etat'] = isset($info['cmhl_ce_etat']) ? $this->getTexteEtat($info['cmhl_ce_etat']) : '';
604
		$item['etat'] = isset($info['cmhl_ce_etat']) ? $this->getTexteEtat($info['cmhl_ce_etat']) : '';
636
		
605
		
637
		return $item;
606
		return $item;
638
	}
607
	}
639
	
608
	
640
	private function getXmlHisto($info) {
609
	private function getXmlHisto($info) {
641
		$xml = '';
610
		$xml = '';
642
		if ($info['cmhl_ce_etat'] == '3') {
611
		if ($info['cmhl_ce_etat'] == '3') {
643
			$xml = $info['enrg_prec'];
612
			$xml = $info['enrg_prec'];
644
		} else {
613
		} else {
645
			$xml = $info['cmhl_enregistrement'];
614
			$xml = $info['cmhl_enregistrement'];
646
		}
615
		}
647
		return $xml;
616
		return $xml;
648
	}
617
	}
649
	
618
	
650
	private function getDiff($info) {
619
	private function getDiff($info) {
651
		$diff = null;
620
		$diff = null;
652
		if ($info['cmhl_ce_etat'] == '1') {
621
		if ($info['cmhl_ce_etat'] == '1') {
653
			$nouveau = $this->getTableauDepuisXmlHisto($info['cmhl_enregistrement']);
622
			$nouveau = $this->getTableauDepuisXmlHisto($info['cmhl_enregistrement']);
654
			foreach ($nouveau as $cle => $valeur) {
623
			foreach ($nouveau as $cle => $valeur) {
655
				$diff[$cle] = array('type' => 'A', 'type_txt' => 'Ajout', 'nouveau' => $valeur, 'ancien' => ' ');
624
				$diff[$cle] = array('type' => 'A', 'type_txt' => 'Ajout', 'nouveau' => $valeur, 'ancien' => ' ');
656
			}
625
			}
657
		} else if ($info['cmhl_ce_etat'] == '2') {
626
		} else if ($info['cmhl_ce_etat'] == '2') {
658
			$nouveau = $this->getTableauDepuisXmlHisto($info['cmhl_enregistrement']);
627
			$nouveau = $this->getTableauDepuisXmlHisto($info['cmhl_enregistrement']);
659
			$ancien = $this->getTableauDepuisXmlHisto($info['enrg_prec']);
628
			$ancien = $this->getTableauDepuisXmlHisto($info['enrg_prec']);
660
			foreach ($nouveau as $cle => $valeur) {
629
			foreach ($nouveau as $cle => $valeur) {
661
				if (!isset($ancien[$cle])) {
630
				if (!isset($ancien[$cle])) {
662
					$diff[$cle] = array('type' => 'A', 'type_txt' => 'Ajout', 'nouveau' => $valeur, 'ancien' => ' ');
631
					$diff[$cle] = array('type' => 'A', 'type_txt' => 'Ajout', 'nouveau' => $valeur, 'ancien' => ' ');
663
				} else if (isset($ancien[$cle]) && $ancien[$cle] != $valeur) {
632
				} else if (isset($ancien[$cle]) && $ancien[$cle] != $valeur) {
664
					$diff[$cle] = array('type' => 'M', 'type_txt' => 'Modification', 'nouveau' => $valeur, 'ancien' => $ancien[$cle]);
633
					$diff[$cle] = array('type' => 'M', 'type_txt' => 'Modification', 'nouveau' => $valeur, 'ancien' => $ancien[$cle]);
665
				}
634
				}
666
			}
635
			}
667
			foreach ($ancien as $cle => $valeur) {
636
			foreach ($ancien as $cle => $valeur) {
668
				if (!isset($nouveau[$cle])) {
637
				if (!isset($nouveau[$cle])) {
669
					$diff[$cle] = array('type' => 'S', 'type_txt' => 'Suppression', 'nouveau' => ' ', 'ancien' => $valeur);
638
					$diff[$cle] = array('type' => 'S', 'type_txt' => 'Suppression', 'nouveau' => ' ', 'ancien' => $valeur);
670
				}
639
				}
671
			}
640
			}
672
		}
641
		}
673
		return $diff;
642
		return $diff;
674
	}
643
	}
675
	
644
	
676
	private function getDiffInfos($info) {
645
	private function getDiffInfos($info) {
677
		$diff = null;
646
		$diff = null;
678
		$format = '%d/%m/%Y à %H:%M:%S';
647
		$format = '%d/%m/%Y à %H:%M:%S';
679
		if ($info['cmhl_ce_etat'] == '1') {
648
		if ($info['cmhl_ce_etat'] == '1') {
680
			$diff['date_nouvelle'] = strftime($format, strtotime($info['cmhl_date_modification']));
649
			$diff['date_nouvelle'] = strftime($format, strtotime($info['cmhl_date_modification']));
681
			$diff['date_ancienne'] = '';
650
			$diff['date_ancienne'] = '';
682
			$diff['etat'] = 'A';
651
			$diff['etat'] = 'A';
683
		} else if ($info['cmhl_ce_etat'] == '2') {
652
		} else if ($info['cmhl_ce_etat'] == '2') {
684
			$diff['date_nouvelle'] = strftime($format, strtotime($info['cmhl_date_modification']));
653
			$diff['date_nouvelle'] = strftime($format, strtotime($info['cmhl_date_modification']));
685
			$diff['date_ancienne'] = strftime($format, strtotime($info['date_prec']));
654
			$diff['date_ancienne'] = strftime($format, strtotime($info['date_prec']));
686
			$diff['etat'] = 'M';
655
			$diff['etat'] = 'M';
687
		} else if ($info['cmhl_ce_etat'] == '3') {
656
		} else if ($info['cmhl_ce_etat'] == '3') {
688
			$diff['etat'] = 'S';
657
			$diff['etat'] = 'S';
689
		}
658
		}
690
		return $diff;
659
		return $diff;
691
	}
660
	}
692
	
661
	
693
	private function getTexteEtat($code) {
662
	private function getTexteEtat($code) {
694
		$etat = '';
663
		$etat = '';
695
		switch ($code) {
664
		switch ($code) {
696
			case '1' :
665
			case '1' :
697
				$etat = 'Ajouté';
666
				$etat = 'Ajouté';
698
				break;
667
				break;
699
			case '2' :
668
			case '2' :
700
				$etat = 'Modifié';
669
				$etat = 'Modifié';
701
				break;
670
				break;
702
			case '3' :
671
			case '3' :
703
				$etat = 'Supprimé';
672
				$etat = 'Supprimé';
704
				break;
673
				break;
705
			default :
674
			default :
706
				$etat = '!Problème!';
675
				$etat = '!Problème!';
707
				$e = "Le champ cmhl_ce_etat possède une valeur innatendue : $code";
676
				$e = "Le champ cmhl_ce_etat possède une valeur innatendue : $code";
708
				$this->messages[] = $e;
677
				$this->messages[] = $e;
709
		}
678
		}
710
		return $etat;
679
		return $etat;
711
	}
680
	}
712
	
681
	
713
	private function construireDonneesCommunesAuFlux($infos) {
682
	private function construireDonneesCommunesAuFlux($infos) {
714
		$donnees = $this->getFlux($this->service);
683
		$donnees = $this->getFlux($this->service);
715
		$donnees['guid'] = $this->getUrlServiceBase();
684
		$donnees['guid'] = $this->getUrlServiceBase();
716
		$donnees['lien_service'] = htmlentities($this->creerUrlService());
685
		$donnees['lien_service'] = htmlentities($this->creerUrlService());
717
		$donnees['lien_coel'] = $this->config['coel']['urlBaseCoel'];
686
		$donnees['lien_coel'] = $this->config['coel']['urlBaseCoel'];
718
		$donnees['editeur'] = $this->config['coel']['editeur'];
687
		$donnees['editeur'] = $this->config['coel']['editeur'];
719
		$derniere_info_en_date = reset($infos);
688
		$derniere_info_en_date = reset($infos);
720
		$date_modification_timestamp = strtotime($derniere_info_en_date['cmhl_date_modification']);
689
		$date_modification_timestamp = strtotime($derniere_info_en_date['cmhl_date_modification']);
721
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
690
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
722
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
691
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
723
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
692
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
724
		$donnees['annee_courante'] = date('Y');
693
		$donnees['annee_courante'] = date('Y');
725
		$donnees['generateur'] = 'COEL - Jrest';
694
		$donnees['generateur'] = 'COEL - Jrest';
726
		preg_match('/([0-9]+)/', '$Revision: 381 $', $match);
695
		preg_match('/([0-9]+)/', '$Revision: 381 $', $match);
727
		$donnees['generateur_version'] = $match[1];
696
		$donnees['generateur_version'] = $match[1];
728
		return $donnees; 
697
		return $donnees; 
729
	}
698
	}
730
	
699
	
731
	private function creerUrlService() {
700
	private function creerUrlService() {
732
		$url_service = $this->getUrlServiceBase();
701
		$url_service = $this->getUrlServiceBase();
733
		if (isset($this->start) || isset($this->limit)) {
702
		if (isset($this->start) || isset($this->limit)) {
734
			$arguments = array();
703
			$arguments = array();
735
			if (isset($this->start) && isset($_GET['start'])) {
704
			if (isset($this->start) && isset($_GET['start'])) {
736
				$arguments[] = 'start='.$this->start;
705
				$arguments[] = 'start='.$this->start;
737
			}
706
			}
738
			if (isset($this->limit) && isset($_GET['limit'])) {
707
			if (isset($this->limit) && isset($_GET['limit'])) {
739
				$arguments[] = 'limit='.($this->limit/2);
708
				$arguments[] = 'limit='.($this->limit/2);
740
			}
709
			}
741
			if (count($arguments) > 0) {
710
			if (count($arguments) > 0) {
742
				$url_service .= '?'.implode('&', $arguments);
711
				$url_service .= '?'.implode('&', $arguments);
743
			}
712
			}
744
		}
713
		}
745
		return $url_service;
714
		return $url_service;
746
	}
715
	}
747
}	
716
}