Subversion Repositories eFlore/Applications.cel

Rev

Rev 416 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/**
* PHP Version 5
*
* @category  PHP
* @package   jrest
* @author    aurelien <aurelien@tela-botanica.org>
* @copyright 2010 Tela-Botanica
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version   SVN: <svn_id>
* @link      /doc/jrest/
*/

Class ImageContribution extends DBAccessor {

        var $config;

    function ImageContribution($config) {

        $this->config=$config;
    }

        function getElement($uid){

        $DB=$this->connectDB($this->config,'cel_db');

       /* $query='SELECT * FROM cel_images';
        $query .= ' WHERE ci_ce_utilisateur ="'.$uid[0].'"' ;
        $query .= ' ORDER BY ci_meta_date_ajout DESC LIMIT 0,5' ;*/

        $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());
        }

        $html = '<div id="resume_cel">';

        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());
            }

           while ($img =& $res_liaison->fetchrow(DB_FETCHMODE_ASSOC)) {
                                $row = $img;
           }

           $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" ;

            $html .= '<div class="item_resume_cel">';

                $html .= '<h4><a href="'.$chemin_fichier.'">'.$obs['nom_ret'].'</a></h4>'.
                '<img src="'.$chemin_fichier_s.'" alt="'.$row['ci_nom_original'].'" height="'.$tailleXY[1].'px" width="'.$tailleXY[0].'px"></img><br/>';
            $html .= '<span>Datée du '.$obs['date_modification'].'<br/>'  ;
            $html .= 'Lieu : '.trim($obs['location'],'000null').' ('.trim($obs['id_location'],'000null').') '.trim($obs['station'],'000null').' '.trim($obs['lieudit'],'000null').'<br/></p>'  ;
                        $html .= '</span>';

                 $html .= '</div>';
        }

        $html.= '</div>';


        header("Content-Type: text/html; charset=UTF-8");
        print $html;
        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 ;
    }

}
?>