* @copyright 2010 Tela-Botanica * @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL * @version SVN: * @link /doc/papyrus_bp/ */ Class Resume extends DBAccessor { function Resume($config) { $this->config=$config; } function getElement($uid){ $DB=$this->connectDB($this->config,'cel_db'); $query = 'SELECT * FROM cel_inventory'. ' WHERE identifiant = "'.$uid[1].'"'. /*' AND ordre IN (SELECT coi_ce_observation FROM cel_obs_images WHERE coi_ce_utilisateur ="'.$uid[1].'" )'.*/ ' AND transmission = 1'. ' ORDER BY date_modification DESC LIMIT 0,5'; $res =& $DB->query($query); if (DB::isError($res)) { die($res->getMessage()); } $resume = array(); $resume['titre'] = 'Vos dernières observations publiées'; $resume['lien_appli'] = ' Accéder au carnet en ligne '; if(!$res || $res->numRows() == 0) { $resume['message'] = 'Aucune observation saisie pour le moment'; } while ($obs =& $res->fetchrow(DB_FETCHMODE_ASSOC)) { $chemin_sur_serveur = $this->config['cel_db']['url_images']; $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'].'"' ; $res_liaison =& $DB->query($req_liaison); if (DB::isError($res_liaison)) { die($res_liaison->getMessage()); } $date = 'Datée du '.$obs['date_modification'].'
' ; $lieu = 'Lieu : '.trim($obs['location'],'000null').' ('.trim($obs['id_location'],'000null').') '.trim($obs['station'],'000null').' '.trim($obs['lieudit'],'000null').'
' ; $image =''; $cible_lien = ''; $row = null; while ($img =& $res_liaison->fetchrow(DB_FETCHMODE_ASSOC)) { $row = $img; } if($row != null) { $row['ci_nom_original'] = htmlspecialchars($row['ci_nom_original']); $row['ci_id_image'] = htmlspecialchars($row['ci_id_image']); $id = $row['ci_id_image']; $tailleXY = $this->calculerDimensions(array($row['ci_meta_width'], $row['ci_meta_height'])); $id = sprintf('%09s', $id) ; $id = wordwrap($id, 3 , '_', true) ; $id_fichier = $id.".jpg" ; $niveauDossier = split("_", $id) ; $dossierNiveau1 = $niveauDossier[0] ; $dossierNiveau2 = $niveauDossier[1] ; $chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ; $chemin_fichier = $chemin_sur_serveur_final.'/L/'.$id."_L.jpg" ; $chemin_fichier_s = $chemin_sur_serveur_final.'/M/'.$id."_M.jpg" ; $image = ''.$row['ci_nom_original'].''; $cible_lien = $chemin_fichier; } $resume_item = array('element' => $obs['nom_ret'].$date.$lieu, 'lien' => $cible_lien,'image' => $image); $resume['elements'][] = $resume_item; } header("Content-Type: text/html; charset=UTF-8"); print json_encode($resume); exit; } public function calculerDimensions($tailleXY) { $tailleOr = 75 ; if($tailleXY[1] == 0) { $tailleXY[1] = $tailleOr; } if($tailleXY[0] == 0) { $tailleXY[0] = $tailleOr; } $maxTaille = max($tailleXY[1],$tailleXY[0]) ; if($maxTaille == $tailleXY[1]) { $rapport = $tailleXY[1]/$tailleXY[0] ; $tailleXY[1] = 75 ; $tailleXY[0] = round($tailleXY[1]/$rapport,0) ; }else { $rapport = $tailleXY[0]/$tailleXY[1] ; $tailleXY[0] = 75 ; $tailleXY[1] = round($tailleXY[0]/$rapport,0) ; } return $tailleXY ; } } ?>