416 |
aurelien |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* PHP Version 5
|
|
|
4 |
*
|
|
|
5 |
* @category PHP
|
|
|
6 |
* @package papyrus_bp
|
|
|
7 |
* @author aurelien <aurelien@tela-botanica.org>
|
|
|
8 |
* @copyright 2010 Tela-Botanica
|
|
|
9 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
10 |
* @version SVN: <svn_id>
|
|
|
11 |
* @link /doc/papyrus_bp/
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
Class Resume extends DBAccessor {
|
|
|
15 |
|
|
|
16 |
function Resume($config) {
|
|
|
17 |
|
|
|
18 |
$this->config=$config;
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
function getElement($uid){
|
|
|
22 |
|
|
|
23 |
$DB=$this->connectDB($this->config,'cel_db');
|
|
|
24 |
|
|
|
25 |
$query = 'SELECT * FROM cel_inventory'.
|
|
|
26 |
' WHERE identifiant = "'.$uid[1].'"'.
|
|
|
27 |
/*' AND ordre IN (SELECT coi_ce_observation
|
|
|
28 |
FROM cel_obs_images
|
|
|
29 |
WHERE coi_ce_utilisateur ="'.$uid[1].'" )'.*/
|
|
|
30 |
' AND transmission = 1'.
|
|
|
31 |
' ORDER BY date_modification DESC LIMIT 0,5';
|
|
|
32 |
|
|
|
33 |
$res =& $DB->query($query);
|
|
|
34 |
|
|
|
35 |
if (DB::isError($res)) {
|
|
|
36 |
die($res->getMessage());
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
$resume = array();
|
|
|
40 |
|
|
|
41 |
$resume['titre'] = 'Vos dernières observations publiées';
|
|
|
42 |
$resume['lien_appli'] = '<a href="www.tela-botanica.org/appli:cel2"> Accéder au carnet en ligne </a>';
|
|
|
43 |
|
|
|
44 |
if(!$res || $res->numRows() == 0) {
|
|
|
45 |
$resume['message'] = 'Aucune observation saisie pour le moment';
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
while ($obs =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
49 |
|
|
|
50 |
$chemin_sur_serveur = $this->config['cel_db']['url_images'];
|
|
|
51 |
|
|
|
52 |
$req_liaison = 'SELECT * FROM cel_images WHERE ci_id_image IN (SELECT coi_ce_image FROM cel_obs_images WHERE coi_ce_observation = "'.$obs['ordre'].'") AND ci_ce_utilisateur = "'.$obs['identifiant'].'"' ;
|
|
|
53 |
|
|
|
54 |
$res_liaison =& $DB->query($req_liaison);
|
|
|
55 |
|
|
|
56 |
if (DB::isError($res_liaison)) {
|
|
|
57 |
die($res_liaison->getMessage());
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
$date = 'Datée du '.$obs['date_modification'].'<br/>' ;
|
|
|
62 |
$lieu = 'Lieu : '.trim($obs['location'],'000null').' ('.trim($obs['id_location'],'000null').') '.trim($obs['station'],'000null').' '.trim($obs['lieudit'],'000null').'<br/>' ;
|
|
|
63 |
|
|
|
64 |
$image ='';
|
|
|
65 |
$cible_lien = '';
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
$row = null;
|
|
|
69 |
|
|
|
70 |
while ($img =& $res_liaison->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
71 |
$row = $img;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
if($row != null) {
|
|
|
75 |
|
|
|
76 |
$row['ci_nom_original'] = htmlspecialchars($row['ci_nom_original']);
|
|
|
77 |
$row['ci_id_image'] = htmlspecialchars($row['ci_id_image']);
|
|
|
78 |
$id = $row['ci_id_image'];
|
|
|
79 |
|
|
|
80 |
$tailleXY = $this->calculerDimensions(array($row['ci_meta_width'], $row['ci_meta_height']));
|
|
|
81 |
|
|
|
82 |
$id = sprintf('%09s', $id) ;
|
|
|
83 |
$id = wordwrap($id, 3 , '_', true) ;
|
|
|
84 |
|
|
|
85 |
$id_fichier = $id.".jpg" ;
|
|
|
86 |
|
|
|
87 |
$niveauDossier = split("_", $id) ;
|
|
|
88 |
|
|
|
89 |
$dossierNiveau1 = $niveauDossier[0] ;
|
|
|
90 |
$dossierNiveau2 = $niveauDossier[1] ;
|
|
|
91 |
|
|
|
92 |
$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
|
|
|
93 |
|
|
|
94 |
$chemin_fichier = $chemin_sur_serveur_final.'/L/'.$id."_L.jpg" ;
|
|
|
95 |
$chemin_fichier_s = $chemin_sur_serveur_final.'/M/'.$id."_M.jpg" ;
|
|
|
96 |
|
|
|
97 |
$image = '<img src="'.$chemin_fichier_s.'" alt="'.$row['ci_nom_original'].'" height="'.$tailleXY[1].'px" width="'.$tailleXY[0].'px"></img>';
|
|
|
98 |
$cible_lien = $chemin_fichier;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
$resume_item = array('element' => $obs['nom_ret'].$date.$lieu, 'lien' => $cible_lien,'image' => $image);
|
|
|
102 |
$resume['elements'][] = $resume_item;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
header("Content-Type: text/html; charset=UTF-8");
|
|
|
106 |
print json_encode($resume);
|
|
|
107 |
exit;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
public function calculerDimensions($tailleXY) {
|
|
|
111 |
|
|
|
112 |
$tailleOr = 75 ;
|
|
|
113 |
|
|
|
114 |
if($tailleXY[1] == 0) {
|
|
|
115 |
$tailleXY[1] = $tailleOr;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
if($tailleXY[0] == 0) {
|
|
|
119 |
$tailleXY[0] = $tailleOr;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
$maxTaille = max($tailleXY[1],$tailleXY[0]) ;
|
|
|
123 |
|
|
|
124 |
if($maxTaille == $tailleXY[1]) {
|
|
|
125 |
|
|
|
126 |
$rapport = $tailleXY[1]/$tailleXY[0] ;
|
|
|
127 |
$tailleXY[1] = 75 ;
|
|
|
128 |
$tailleXY[0] = round($tailleXY[1]/$rapport,0) ;
|
|
|
129 |
|
|
|
130 |
}else {
|
|
|
131 |
$rapport = $tailleXY[0]/$tailleXY[1] ;
|
|
|
132 |
$tailleXY[0] = 75 ;
|
|
|
133 |
$tailleXY[1] = round($tailleXY[0]/$rapport,0) ;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
return $tailleXY ;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
}
|
|
|
140 |
?>
|