Subversion Repositories eFlore/Applications.cel

Compare Revisions

Regard whitespace Rev 624 → Rev 947

/trunk/jrest/services/InventoryExport.php
1,27 → 1,36
<?php
/**
* 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
/**
* in:utf8
* out:iso8859
*
* Export vers feuille de calcul d'une selection de releves
*
*/
class InventoryExport extends Cel {
 
// Export vers feuille de calcul d'une selection de releves
private $extendSpreadsheetProductor;
 
Class InventoryExport extends DBAccessor {
 
 
var $config;
var $extendSpreadsheetProductor;
 
function InventoryExport($config) {
 
$this->config=$config;
// Pas d'heritage multiple en php :(
parent::__construct($config);
 
 
$this->extendSpreadsheetProductor = new SpreadsheetProductor();
$this->extendSpreadsheetProductor->initSpreadsheet();
}
 
 
function getElement($uid){
 
// Controle detournement utilisateur
28,111 → 37,18
session_start();
$this->controleUtilisateur($uid[0]);
 
$DB=$this->connectDB($this->config,'database_cel');
$criteres = array();
 
$chercheur_observations = new RechercheObservation($this->config);
 
$criteres = array() ;
 
if(isset($uid[1]))
{
$criteres = explode("&", $uid[1]) ;
$criteres = $chercheur_observations->parserRequeteCriteres($uid[1]);
}
 
$query="SELECT identifiant, ordre, nom_sel, num_nom_sel, nom_ret, num_nom_ret, num_taxon, famille, location, id_location, date_observation," .
" lieudit, station, milieu, commentaire, transmission, coord_x, coord_y, ref_geo FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' AND " ;
 
 
 
foreach($criteres as $pair)
{
$nom_valeur = explode("=",$pair) ;
 
 
if(sizeof($nom_valeur) != 0) {
 
if($nom_valeur[0] == 'limite')
{
$limite = $DB->escapeSimple($nom_valeur[1]) ;
}
elseif($nom_valeur[0] == 'numero_page') {
$numero_page = $DB->escapeSimple($nom_valeur[1]) ;
}
elseif($nom_valeur[0] == 'annee') {
$query .= "year(date_observation) = '".$DB->escapeSimple($nom_valeur[1])."'" ;
$query .= ' AND ' ;
}
elseif($nom_valeur[0] == 'mois') {
$query .= "month(date_observation) = '".$DB->escapeSimple($nom_valeur[1])."'" ;
$query .= ' AND ' ;
}
elseif($nom_valeur[0] == 'jour') {
$query .= "day(date_observation) = '".$DB->escapeSimple($nom_valeur[1])."'" ;
$query .= ' AND ' ;
}
elseif($nom_valeur[0] == 'mots_cles') {
$liste_mc = explode(";",$nom_valeur[1]);
$query .= '(' ;
foreach($liste_mc as $mot) {
if(trim($mot) != '')
{
$query .= "mots_cles LIKE '%".$DB->escapeSimple($mot)."%' OR " ;
}
}
$query = rtrim($query,' OR ');
$query .= ') AND ' ;
}
elseif ($nom_valeur[0] == 'nom_taxon') {
$nom_valeur[1] = str_replace("*","%",$nom_valeur[1]);
$query .= "(nom_sel LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR identifiant LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR ordre LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR nom_sel LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR num_nom_sel LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR nom_ret LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR num_nom_ret LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR num_taxon LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR location LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR id_location LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR date_observation LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR lieudit LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR station LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR milieu LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR commentaire LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR transmission LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR coord_x LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%' OR coord_y LIKE '%".$DB->escapeSimple($nom_valeur[1]).
"%')";
 
//"%' OR famille LIKE '%".$DB->escapeSimple($nom_valeur[1]).
}
else {
if(trim($nom_valeur[0]) != '')
{
$query .= $nom_valeur[0]." = '".$DB->escapeSimple($nom_valeur[1])."'" ;
$query .= ' AND ' ;
}
}
}
}
 
$query = rtrim($query,' AND ') ;
 
 
$query .=" ORDER BY ordre ";
 
$res =& $DB->query($query);
 
 
if (DB::isError($res)) {
die($res->getMessage());
}
 
 
 
// Creating a workbook
$workbook = new Spreadsheet_Excel_Writer();
 
 
$workbook->send('liste.xls');
 
// Creating a worksheet
155,48 → 71,39
$worksheet->write(0,14,'Longitude');
$worksheet->write(0,15,'Referentiel Geographique');
 
$numero_page = isset($criteres['numero_page']) ? $criteres['numero_page'] : 0;
$limite = isset($criteres['limite']) ? $criteres['limite'] : 50;
 
$observations = $chercheur_observations->rechercherObservations($uid[0], $criteres, $numero_page, $limite);
 
$i=1;
while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
foreach ($observations as $obs) {
 
// Denullifiage
foreach($row as $k=>$v) {
if (($v=="null") || ($v=="000null")) {
$row[$k]="";
}
else {
$row[$k]=utf8_decode($v);
}
}
$obs = $this->denullifierTableauValeurCel(&$obs);
 
 
if ($row['date_observation']!="0000-00-00 00:00:00") {
list($year,$month,$day)= split ('-',$row['date_observation']);
list($day)= split (' ',$day);
$row['date_observation']=$day."/".$month."/".$year;
if ($obs['date_observation'] != "0000-00-00 00:00:00") {
$obs['date_observation'] = $this->formaterDate($obs['date_observation']);
}
else {
$row['date_observation']="00/00/0000";
$obs['date_observation']="00/00/0000";
}
 
 
$worksheet->write($i,0,$row['nom_sel']);
$worksheet->write($i,1,$row['num_nom_sel']);
$worksheet->write($i,2,$row['nom_ret']);
$worksheet->write($i,3,$row['num_nom_ret']);
$worksheet->write($i,4,$row['num_taxon']);
$worksheet->write($i,5,$row['famille']);
$worksheet->write($i,6,$row['location']);
$worksheet->write($i,7,$row['id_location']);
$worksheet->write($i,8,$row['date_observation']);
$worksheet->write($i,9,$row['lieudit']);
$worksheet->write($i,10,$row['station']);
$worksheet->write($i,11,$row['milieu']);
$worksheet->write($i,12,$row['commentaire']);
$worksheet->write($i,13,$row['coord_x']);
$worksheet->write($i,14,$row['coord_y']);
$worksheet->write($i,15,$row['ref_geo']);
$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['zone_geo']);
$worksheet->write($i,7,$this->convertirCodeZoneGeoVersDepartement($obs['ce_zone_geo']));
$worksheet->write($i,8,$obs['date_observation']);
$worksheet->write($i,9,$obs['lieudit']);
$worksheet->write($i,10,$obs['station']);
$worksheet->write($i,11,$obs['milieu']);
$worksheet->write($i,12,$obs['commentaire']);
$worksheet->write($i,13,$obs['latitude']);
$worksheet->write($i,14,$obs['longitude']);
$worksheet->write($i,15,$obs['geodatum']);
$i++;
}
 
203,15 → 110,8
$workbook->close();
 
exit();
 
 
}
 
 
 
}
 
 
/* +--Fin du code ---------------------------------------------------------------------------------------+
* $Log$
* Revision 1.7 2008-11-13 11:29:12 ddelon
225,10 → 125,5
*
* Revision 1.4 2007-05-22 12:54:09 ddelon
* Securisation acces utilisateur
*
*
*
*/
 
 
?>
?>