416 |
aurelien |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
Class ImageRss extends DBAccessor {
|
|
|
5 |
|
|
|
6 |
var $config;
|
|
|
7 |
|
|
|
8 |
function ImageRss($config) {
|
|
|
9 |
|
|
|
10 |
$this->config=$config;
|
|
|
11 |
}
|
|
|
12 |
|
|
|
13 |
function getElement($uid){
|
|
|
14 |
|
|
|
15 |
$this->authentifier();
|
|
|
16 |
|
|
|
17 |
$rss = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n";
|
|
|
18 |
$rss .= "<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
|
|
|
19 |
$rss .='
|
|
|
20 |
<channel>
|
|
|
21 |
<title>Carnet en ligne</title>
|
|
|
22 |
<link>http://www.tela-botanica.org/cel/jrest/ImageRss</link>
|
|
|
23 |
<description>Carnet en ligne</description>
|
|
|
24 |
<language>fr</language>';
|
|
|
25 |
|
|
|
26 |
$DB=$this->connectDB($this->config,'cel_db');
|
|
|
27 |
|
|
|
28 |
$query_id_id_img = 'SELECT cmc_id_mot_cle_utilisateur, cmc_id_proprietaire FROM cel_mots_cles WHERE cmc_id_mot_cle_general = md5("'.$DB->escapeSimple($uid[0]).'")' ;
|
|
|
29 |
|
|
|
30 |
$res =& $DB->query($query_id_id_img);
|
|
|
31 |
|
|
|
32 |
if (DB::isError($res)) {
|
|
|
33 |
|
|
|
34 |
die($res->getMessage());
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
$query='SELECT * FROM cel_images';
|
|
|
38 |
|
|
|
39 |
$premier_item = true ;
|
|
|
40 |
while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
41 |
|
|
|
42 |
if($premier_item) {
|
|
|
43 |
$query .= ' WHERE ';
|
|
|
44 |
$premier_item = false ;
|
|
|
45 |
}
|
|
|
46 |
else{
|
|
|
47 |
$query .= ' OR ';
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
$query .= '(ci_meta_mots_cles LIKE "%'.$row['cmc_id_mot_cle_utilisateur'].'%" AND ci_ce_utilisateur ="'.$row['cmc_id_proprietaire'].'")' ;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
$query .= ' ORDER BY ci_meta_date_ajout DESC LIMIT 0,100' ;
|
|
|
54 |
|
|
|
55 |
$res =& $DB->query($query);
|
|
|
56 |
|
|
|
57 |
if (DB::isError($res)) {
|
|
|
58 |
die($res->getMessage());
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
62 |
$row['ci_nom_original'] = htmlspecialchars($row['ci_nom_original']);
|
|
|
63 |
$row['ci_id_image'] = htmlspecialchars($row['ci_id_image']);
|
|
|
64 |
$row['ci_meta_date_ajout'] = htmlspecialchars($row['ci_meta_date_ajout']);
|
|
|
65 |
$row['ci_ce_utilisateur'] = htmlspecialchars($row['ci_ce_utilisateur']);
|
|
|
66 |
$row['ci_meta_user_comment'] = htmlspecialchars($row['ci_meta_user_comment']);
|
|
|
67 |
$row['ci_note_image'] = htmlspecialchars($row['ci_note_image']);
|
|
|
68 |
$tailleXY = $this->calculerDimensions(array($row['ci_meta_width'], $row['ci_meta_height']));
|
|
|
69 |
|
|
|
70 |
$id = $row['ci_id_image'];
|
|
|
71 |
$chemin_sur_serveur = $this->config['cel_db']['url_images'];
|
|
|
72 |
|
|
|
73 |
$req_liaison = 'SELECT * FROM cel_inventory WHERE ordre IN (SELECT coi_ce_observation FROM cel_obs_images WHERE coi_ce_image = "'.$row['ci_id_image'].'") AND identifiant = "'.$row['ci_ce_utilisateur'].'"' ;
|
|
|
74 |
$res_liaison =& $DB->query($req_liaison);
|
|
|
75 |
|
|
|
76 |
if (DB::isError($res_liaison)) {
|
|
|
77 |
die($res_liaison->getMessage());
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
if (DB::isError($res_liaison)) {
|
|
|
81 |
die($res_liaison->getMessage());
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
$id = sprintf('%09s', $id) ;
|
|
|
85 |
$id = wordwrap($id, 3 , '_', true) ;
|
|
|
86 |
|
|
|
87 |
$id_fichier = $id.".jpg" ;
|
|
|
88 |
|
|
|
89 |
$niveauDossier = split("_", $id) ;
|
|
|
90 |
|
|
|
91 |
$dossierNiveau1 = $niveauDossier[0] ;
|
|
|
92 |
$dossierNiveau2 = $niveauDossier[1] ;
|
|
|
93 |
|
|
|
94 |
$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
|
|
|
95 |
|
|
|
96 |
$chemin_fichier = $chemin_sur_serveur_final.'/L/'.$id."_L.jpg" ;
|
|
|
97 |
$chemin_fichier_m = $chemin_sur_serveur_final.'/M/'.$id."_M.jpg" ;
|
|
|
98 |
|
|
|
99 |
$rss.= ' <item>
|
|
|
100 |
<title>'.$row['ci_nom_original']." (".$row['ci_id_image'].") ". ' par ' . $row['ci_ce_utilisateur'].'</title>
|
|
|
101 |
<author>'.$row['ci_ce_utilisateur'].'</author>
|
|
|
102 |
<link>'.$chemin_fichier.'</link>
|
|
|
103 |
<description>'.
|
|
|
104 |
' <![CDATA[<img src="'.$chemin_fichier_m.'" alt="'.$row['ci_nom_original'].'" height="'.$tailleXY[1].'px" width="'.$tailleXY[0].'px"></img><br/>'.
|
|
|
105 |
$row['ci_nom_original']. ' modifie le ' .$row['ci_meta_date_ajout'] . ' par ' . $row['ci_ce_utilisateur'].'<br/>' ;
|
|
|
106 |
|
|
|
107 |
if(trim($row['ci_meta_mots_cles']) != '') {
|
|
|
108 |
$row['ci_meta_mots_cles'] = rtrim($row['ci_meta_mots_cles'],',');
|
|
|
109 |
|
|
|
110 |
$mots_cles_chaine = '' ;
|
|
|
111 |
$mots_cles_tab = split(',',$row['ci_meta_mots_cles']);
|
|
|
112 |
foreach($mots_cles_tab as $item) {
|
|
|
113 |
$mots_cles_chaine .= '\''.$item.'\',';
|
|
|
114 |
}
|
|
|
115 |
$mots_cles_chaine = rtrim($mots_cles_chaine,',');
|
|
|
116 |
|
|
|
117 |
$req_mots_cles = 'SELECT cmc_mot_cle FROM cel_mots_cles WHERE cmc_id_mot_cle_utilisateur IN ('.$mots_cles_chaine.') AND cmc_id_proprietaire = "'.$row['ci_ce_utilisateur'].'"' ;
|
|
|
118 |
$res_mots_cles =& $DB->query($req_mots_cles);
|
|
|
119 |
|
|
|
120 |
if (DB::isError($res_mots_cles)) {
|
|
|
121 |
die($res_mots_cles->getMessage());
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
$mots_cles = '' ;
|
|
|
126 |
|
|
|
127 |
while($mot_cle = & $res_mots_cles->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
128 |
$mots_cles .= $mot_cle['cmc_mot_cle'].' , ' ;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
$mots_cles = rtrim($mots_cles,', ');
|
|
|
132 |
|
|
|
133 |
if(trim($mots_cles) != '') {
|
|
|
134 |
$rss .= 'Mot clés : '.htmlentities($mots_cles).' <br/>' ;
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
while($ligne = & $res_liaison->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
139 |
$rss .= '<p> Liée à l\'observation '.$ligne['id'].'<br/>' ;
|
|
|
140 |
$rss .= 'Nom saisi : '.$ligne['nom_sel'].'<br/>' ;
|
|
|
141 |
$rss .= 'Nom retenu : '.$ligne['nom_ret'].'<br/>' ;
|
|
|
142 |
$rss .= 'Datée du '.$ligne['date_observation'].'<br/>' ;
|
|
|
143 |
$rss .= 'Lieu : '.trim($ligne['location'],'000null').' ('.trim($ligne['id_location'],'000null').') '.trim($ligne['station'],'000null').' '.trim($ligne['lieudit'],'000null').'<br/></p>' ;
|
|
|
144 |
}
|
|
|
145 |
$rss .= ']]>' ;
|
|
|
146 |
$rss .= '</description>
|
|
|
147 |
<dc:format>text/html</dc:format>
|
|
|
148 |
</item>';
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
$rss.= '</channel> </rss>';
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
header("Content-Type: text/xml; charset=UTF-8");
|
|
|
155 |
print $rss;
|
|
|
156 |
exit;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
function getRessource(){
|
|
|
161 |
|
|
|
162 |
$this->authentifier();
|
|
|
163 |
$DB=$this->connectDB($this->config,'cel_db');
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
$rss = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n";
|
|
|
167 |
$rss .= "<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
|
|
|
168 |
$rss .='
|
|
|
169 |
<channel>
|
|
|
170 |
<title>Carnet en ligne</title>
|
|
|
171 |
<link>http://www.tela-botanica.org/cel/jrest/ImageRss</link>
|
|
|
172 |
<description>Carnet en ligne</description>
|
|
|
173 |
<language>fr</language>';
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
$query='SELECT * FROM cel_images order by ci_meta_date_ajout DESC LIMIT 0,100';
|
|
|
177 |
|
|
|
178 |
$res =& $DB->query($query);
|
|
|
179 |
|
|
|
180 |
if (DB::isError($res)) {
|
|
|
181 |
die($res->getMessage());
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
185 |
$row['ci_nom_original'] = htmlspecialchars($row['ci_nom_original']);
|
|
|
186 |
$row['ci_id_image'] = htmlspecialchars($row['ci_id_image']);
|
|
|
187 |
$row['ci_meta_date_ajout'] = htmlspecialchars($row['ci_meta_date_ajout']);
|
|
|
188 |
$row['ci_ce_utilisateur'] = htmlspecialchars($row['ci_ce_utilisateur']);
|
|
|
189 |
$row['ci_meta_user_comment'] = htmlspecialchars($row['ci_meta_user_comment']);
|
|
|
190 |
$row['ci_note_image'] = htmlspecialchars($row['ci_note_image']);
|
|
|
191 |
$tailleXY = $this->calculerDimensions(array($row['ci_meta_width'], $row['ci_meta_height']));
|
|
|
192 |
|
|
|
193 |
$id = $row['ci_id_image'];
|
|
|
194 |
$chemin_sur_serveur = $this->config['cel_db']['url_images'];
|
|
|
195 |
|
|
|
196 |
$req_liaison = 'SELECT * FROM cel_inventory WHERE ordre IN (SELECT coi_ce_observation FROM cel_obs_images WHERE coi_ce_image = "'.$row['ci_id_image'].'") AND identifiant = "'.$row['ci_ce_utilisateur'].'"' ;
|
|
|
197 |
$res_liaison =& $DB->query($req_liaison);
|
|
|
198 |
|
|
|
199 |
if (DB::isError($res_liaison)) {
|
|
|
200 |
die($res_liaison->getMessage());
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
$id = sprintf('%09s', $id) ;
|
|
|
204 |
$id = wordwrap($id, 3 , '_', true) ;
|
|
|
205 |
|
|
|
206 |
$id_fichier = $id.".jpg" ;
|
|
|
207 |
|
|
|
208 |
$niveauDossier = split("_", $id) ;
|
|
|
209 |
|
|
|
210 |
$dossierNiveau1 = $niveauDossier[0] ;
|
|
|
211 |
$dossierNiveau2 = $niveauDossier[1] ;
|
|
|
212 |
|
|
|
213 |
$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
|
|
|
214 |
|
|
|
215 |
$chemin_fichier = $chemin_sur_serveur_final.'/L/'.$id."_L.jpg" ;
|
|
|
216 |
$chemin_fichier_m = $chemin_sur_serveur_final.'/M/'.$id."_M.jpg" ;
|
|
|
217 |
|
|
|
218 |
$rss.= ' <item>
|
|
|
219 |
<title>'.$row['ci_nom_original']." (".$row['ci_id_image'].") ". ' par ' . $row['ci_ce_utilisateur'].'</title>
|
|
|
220 |
<author>'.$row['ci_ce_utilisateur'].'</author>
|
|
|
221 |
<link>'.$chemin_fichier.'</link>
|
|
|
222 |
<description>'.
|
|
|
223 |
' <![CDATA[<img src="'.$chemin_fichier_m.'" alt="'.$row['ci_nom_original'].'" height="'.$tailleXY[1].'px" width="'.$tailleXY[0].'px"></img><br/>'.
|
|
|
224 |
$row['ci_nom_original']. ' modifie le ' .$row['ci_meta_date_ajout'] . ' par ' . $row['ci_ce_utilisateur'].'<br/>' ;
|
|
|
225 |
|
|
|
226 |
if(trim($row['ci_meta_mots_cles']) != '') {
|
|
|
227 |
$row['ci_meta_mots_cles'] = rtrim($row['ci_meta_mots_cles'],',');
|
|
|
228 |
|
|
|
229 |
$mots_cles_chaine = '' ;
|
|
|
230 |
$mots_cles_tab = split(',',$row['ci_meta_mots_cles']);
|
|
|
231 |
foreach($mots_cles_tab as $item) {
|
|
|
232 |
$mots_cles_chaine .= '\''.$item.'\',';
|
|
|
233 |
}
|
|
|
234 |
$mots_cles_chaine = rtrim($mots_cles_chaine,',');
|
|
|
235 |
|
|
|
236 |
$req_mots_cles = 'SELECT cmc_mot_cle FROM cel_mots_cles WHERE cmc_id_mot_cle_utilisateur IN ('.$mots_cles_chaine.') AND cmc_id_proprietaire = "'.$row['ci_ce_utilisateur'].'"' ;
|
|
|
237 |
$res_mots_cles =& $DB->query($req_mots_cles);
|
|
|
238 |
|
|
|
239 |
if (DB::isError($res_mots_cles)) {
|
|
|
240 |
die($res_mots_cles->getMessage());
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
$mots_cles = '' ;
|
|
|
245 |
|
|
|
246 |
while($mot_cle = & $res_mots_cles->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
247 |
$mots_cles .= $mot_cle['cmc_mot_cle'].' , ' ;
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
$mots_cles = rtrim($mots_cles,', ');
|
|
|
251 |
|
|
|
252 |
if(trim($mots_cles) != '') {
|
|
|
253 |
$rss .= 'Mot clés : '.htmlentities($mots_cles).' <br/>' ;
|
|
|
254 |
}
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
while($ligne = & $res_liaison->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
258 |
$rss .= '<p> Liée à l\'observation '.$ligne['id'].'<br/>' ;
|
|
|
259 |
$rss .= 'Nom saisi : '.$ligne['nom_sel'].'<br/>' ;
|
|
|
260 |
$rss .= 'Nom retenu : '.$ligne['nom_ret'].'<br/>' ;
|
|
|
261 |
$rss .= 'Datée du '.$ligne['date_observation'].'<br/>' ;
|
|
|
262 |
$rss .= 'Lieu : '.trim($ligne['location'],'000null').' ('.trim($ligne['id_location'],'000null').') '.trim($ligne['station'],'000null').' '.trim($ligne['lieudit'],'000null').'<br/></p>' ;
|
|
|
263 |
}
|
|
|
264 |
$rss .= ']]>' ;
|
|
|
265 |
$rss .= '</description>
|
|
|
266 |
<dc:format>text/html</dc:format>
|
|
|
267 |
</item>';
|
|
|
268 |
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
$rss.= '</channel> </rss>';
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
header("Content-Type: text/xml; charset=UTF-8");
|
|
|
275 |
print $rss;
|
|
|
276 |
exit;
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
function calculerDimensions($tailleXY) {
|
|
|
280 |
|
|
|
281 |
$tailleOr = 300 ;
|
|
|
282 |
|
|
|
283 |
if($tailleXY[1] == 0) {
|
|
|
284 |
$tailleXY[1] = $tailleOr;
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
if($tailleXY[0] == 0) {
|
|
|
288 |
$tailleXY[0] = $tailleOr;
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
$maxTaille = max($tailleXY[1],$tailleXY[0]) ;
|
|
|
292 |
|
|
|
293 |
if($maxTaille == $tailleXY[1]) {
|
|
|
294 |
|
|
|
295 |
$rapport = $tailleXY[1]/$tailleXY[0] ;
|
|
|
296 |
$tailleXY[1] = 300 ;
|
|
|
297 |
$tailleXY[0] = round($tailleXY[1]/$rapport,0) ;
|
|
|
298 |
|
|
|
299 |
}else {
|
|
|
300 |
$rapport = $tailleXY[0]/$tailleXY[1] ;
|
|
|
301 |
$tailleXY[0] = 300 ;
|
|
|
302 |
$tailleXY[1] = round($tailleXY[0]/$rapport,0) ;
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
return $tailleXY ;
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
|
|
|
309 |
public function authentifier() {
|
|
|
310 |
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
|
311 |
header('WWW-Authenticate: Basic realm="www.tela-botanica.org"');
|
|
|
312 |
header('HTTP/1.0 401 Unauthorized');
|
|
|
313 |
header('Content-type: text/html; charset=UTF-8');
|
|
|
314 |
echo 'Accès interdit';
|
|
|
315 |
exit;
|
|
|
316 |
} else {
|
|
|
317 |
if($this->verifierAcces($_SERVER['PHP_AUTH_USER'])) {
|
|
|
318 |
return ;
|
|
|
319 |
}
|
|
|
320 |
else
|
|
|
321 |
{
|
|
|
322 |
header('WWW-Authenticate: Basic realm="www.tela-botanica.org"');
|
|
|
323 |
header('HTTP/1.0 401 Unauthorized');
|
|
|
324 |
header('Content-type: text/html; charset=UTF-8');
|
|
|
325 |
echo 'Accès interdit';
|
|
|
326 |
exit ;
|
|
|
327 |
}
|
|
|
328 |
}
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
public function verifierAcces($id) {
|
|
|
332 |
|
|
|
333 |
$DB=$this->connectDB($this->config,'database_ident');
|
|
|
334 |
$query="SELECT ".$this->config['database_ident']['ann_id']." as name FROM ".$this->config['database_ident']['annuaire']." WHERE ".$this->config['database_ident']['ann_id']." ='".$DB->escapeSimple($id)
|
|
|
335 |
."' AND ".$this->config['database_ident']['ann_pwd']." = ".$this->config['database_ident']['pass_crypt_funct']."('".$DB->escapeSimple($_SERVER['PHP_AUTH_PW'])."')" ;
|
|
|
336 |
|
|
|
337 |
$res =& $DB->getOne($query);
|
|
|
338 |
|
|
|
339 |
if($res == "") {
|
|
|
340 |
return false ;
|
|
|
341 |
}
|
|
|
342 |
|
|
|
343 |
if (DB::isError($res)) {
|
|
|
344 |
die($res->getMessage());
|
|
|
345 |
}
|
|
|
346 |
|
|
|
347 |
return $this->isAdmin($id) ;
|
|
|
348 |
|
|
|
349 |
}
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
|
|
|
353 |
/* +--Fin du code ---------------------------------------------------------------------------------------+
|
|
|
354 |
* $Log$
|
|
|
355 |
* Revision 1.5 2008-11-13 11:29:12 ddelon
|
|
|
356 |
* Reecriture gwt-ext
|
|
|
357 |
*
|
|
|
358 |
* Revision 1.4 2007-06-06 13:31:16 ddelon
|
|
|
359 |
* v0.09
|
|
|
360 |
*
|
|
|
361 |
* Revision 1.3 2007-05-22 12:54:09 ddelon
|
|
|
362 |
* Securisation acces utilisateur
|
|
|
363 |
*
|
|
|
364 |
*
|
|
|
365 |
*
|
|
|
366 |
*/
|
|
|
367 |
|
|
|
368 |
?>
|