Subversion Repositories eFlore/Applications.cel

Rev

Rev 1720 | Blame | Last modification | View Log | RSS feed

<?php
// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //

/**
* PHP Version 5
*
* @category  PHP
* @package   jrest
* @author    David Delon <david@tela-botania.org>
* @author    Aurélien Peronnet <aurelien@tela-botania.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/
*/

/**
* in:utf8
* out:iso8859
* 
* Export vers feuille de calcul d'une selection de releves
* 
*/

set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
// la sortie est binaire (xls), mais OLE n'est pas compatible E_ALL en PHP-5.4
error_reporting(error_reporting() ^ E_STRICT);
require_once("lib/OLE.php");
require_once("lib/Spreadsheet/Excel/Writer.php");

class InventoryExport extends Cel  {

        private $extendSpreadsheetProductor;

        function InventoryExport($config) {

                parent::__construct($config);

                $this->extendSpreadsheetProductor = new SpreadsheetProductor();
                $this->extendSpreadsheetProductor->initSpreadsheet();
        }

        function getElement($uid){

                   // Controle detournement utilisateur
                        $this->controleUtilisateur($uid[0]);

                        $criteres = $_GET;      
                        $chercheur_observations = new RechercheObservation($this->config);

            // Creating a workbook
                        $workbook = new Spreadsheet_Excel_Writer();
                        $workbook->setVersion(8);

                        $workbook->send('liste.xls');

                        // Creating a worksheet
                        $worksheet = $workbook->addWorksheet('Liste');
                        $worksheet->setInputEncoding('utf-8');
                        
            $worksheet->write(0,0,'Espece');
            $worksheet->write(0,1,'Numero nomenclatural');
            $worksheet->write(0,2,'Nom retenu');
            $worksheet->write(0,3,'Numero nomenclatural nom retenu');
            $worksheet->write(0,4,'Numero taxonomique');
            $worksheet->write(0,5,'Famille');
            $worksheet->write(0,6,'Referentiel taxonomique');
            $worksheet->write(0,7,'Commune');
            $worksheet->write(0,8,'Identifiant Commune');
            $worksheet->write(0,9,'Date');
            $worksheet->write(0,10,'Lieu-dit');
            $worksheet->write(0,11,'Station');
            $worksheet->write(0,12,'Milieu');
            $worksheet->write(0,13,'Notes');
            $worksheet->write(0,14,'Latitude');
            $worksheet->write(0,15,'Longitude');
            $worksheet->write(0,16,'Referentiel Geographique');
            $worksheet->write(0,17,'Ordre');
            $worksheet->write(0,18,'Identifiant');
            
            $numero_page = isset($criteres['numero_page']) ? $criteres['numero_page'] : 0;
            $limite = isset($criteres['limite']) ? $criteres['limite'] : 0;

                        $observations = $chercheur_observations->rechercherObservations($uid[0], $criteres, $numero_page, $limite)->get();
                        if(!$observations) {
                                header('HTTP/1.0 204 No Content');
                                exit;
                        }

                        $ids_obs = array();
                        $indices_lignes_obs = array();
                        
                        $i=1;
                        foreach ($observations as &$obs) {

                                $obs = $this->denullifierTableauValeurCel($obs);
                                $ids_obs[] = $obs['id_observation'];
                                $indices_lignes_obs[$obs['id_observation']] = $i;
                                
                                if ($obs['date_observation'] != "0000-00-00 00:00:00") {
                        $obs['date_observation'] = $this->formaterDate($obs['date_observation']);
                        }
                        else {
                        $obs['date_observation']="00/00/0000";
                        }

                $worksheet->write($i,0,$obs['nom_sel']);
                $worksheet->write($i,1,$obs['nom_sel_nn']);
                $worksheet->write($i,2,$obs['nom_ret']);
                $worksheet->write($i,3,$obs['nom_ret_nn']);
                $worksheet->write($i,4,$obs['nt']);
                $worksheet->write($i,5,$obs['famille']);
                $worksheet->write($i,6,$obs['nom_referentiel']);
                $worksheet->write($i,7,$obs['zone_geo']);
                $worksheet->write($i,8,$this->convertirCodeZoneGeoVersDepartement($obs['ce_zone_geo']));
                $worksheet->write($i,9,$obs['date_observation']);
                $worksheet->write($i,10,$obs['lieudit']);
                $worksheet->write($i,11,$obs['station']);
                $worksheet->write($i,12,$obs['milieu']);
                $worksheet->write($i,13,$obs['commentaire']);
                $worksheet->write($i,14,$obs['latitude']);
                $worksheet->write($i,15,$obs['longitude']);
                $worksheet->write($i,16,$obs['geodatum']);
                $worksheet->write($i,17,$obs['ordre']);
                $worksheet->write($i,18,$obs['id_observation']);
                $i++;
            }
            
            $indice_dernier_champ_supp = 19;
            $indices_champs_supp = array();
            $gestion_champs_etendus = new GestionChampsEtendus($this->config, 'obs');
            $champs_supp_par_obs = $gestion_champs_etendus->consulterParLots($ids_obs);
            
            foreach($champs_supp_par_obs as $id_obs => &$champs_supp) {
                    foreach($champs_supp as  &$champ_etendu) {
                        $cle = $champ_etendu->cle;
                        $label = $champ_etendu->label;
                        $valeur = $champ_etendu->valeur;
                        if(!isset($indices_champs_supp[$cle])) {
                                $indices_champs_supp[$cle] = $indice_dernier_champ_supp;
                                $worksheet->write(0, $indice_dernier_champ_supp, utf8_decode($label));
                                $indice_dernier_champ_supp++;
                        }
                        $num_ligne_obs = $indices_lignes_obs[$id_obs];
                        $worksheet->write($num_ligne_obs,$indices_champs_supp[$cle],utf8_decode($valeur));
                    }
            }
            
                        $workbook->close();
                        exit();
        }
}
/* +--Fin du code ---------------------------------------------------------------------------------------+
* $Log$
* Revision 1.7  2008-11-13 11:29:12  ddelon
* Reecriture gwt-ext
*
* Revision 1.6  2008-01-30 08:57:28  ddelon
* fin mise en place mygwt
*
* Revision 1.5  2007-06-06 13:31:16  ddelon
* v0.09
*
* Revision 1.4  2007-05-22 12:54:09  ddelon
* Securisation acces utilisateur
*/
?>