Subversion Repositories eFlore/Applications.cel

Rev

Rev 1610 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
416 aurelien 1
<?php
904 aurelien 2
// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //
416 aurelien 3
 
904 aurelien 4
/**
5
* PHP Version 5
6
*
7
* @category  PHP
8
* @package   jrest
9
* @author    David Delon <delon@tela-botanica.org>
10
* @copyright 2010 Tela-Botanica
11
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
* @version   SVN: <svn_id>
13
* @link      /doc/
14
*/
416 aurelien 15
 
904 aurelien 16
/**
17
*
18
* in=utf8
19
* out=iso3859
20
*
21
* Liste des Nouvelles observations par departement
22
* A voir avec David mais ne devrait plus être utilisé
23
* ou fait autrement
24
*
25
*/
1610 raphael 26
 
27
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
28
// la sortie est binaire (xls), mais OLE n'est pas compatible E_ALL en PHP-5.4
29
error_reporting(error_reporting() ^ E_STRICT);
30
require_once("lib/OLE.php");
31
require_once("lib/Spreadsheet/Excel/Writer.php");
32
 
904 aurelien 33
class InventoryByDept extends Cel {
416 aurelien 34
 
35
	var $extendSpreadsheetProductor;
36
 
37
	function InventoryByDept($config) {
38
 
904 aurelien 39
		parent::__construct($config);
40
 
416 aurelien 41
		// Pas d'heritage multiple en php :(
42
		$this->extendSpreadsheetProductor = new SpreadsheetProductor();
904 aurelien 43
		$this->extendSpreadsheetProductor->initSpreadsheet();
416 aurelien 44
	}
45
 
905 aurelien 46
	//TODO : faire une fonction qui prend en paramètre un departement
416 aurelien 47
	function getRessource(){
48
 
904 aurelien 49
		$requete_obs = "SELECT ce_zone_geo, ce_utilisateur, courriel_utilisateur, ordre, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille, zone_geo, date_observation," .
50
		    " lieudit, station, milieu, commentaire, transmission  FROM cel_obs ".
51
			"WHERE ce_zone_geo != '000null' AND ce_zone_geo != '' AND transmission = 1 AND nt!=0 ORDER BY ce_zone_geo, nom_ret LIMIT 50";
52
 
1765 raphael 53
		$resultat_obs = Cel::db()->executerRequete($requete_obs);
416 aurelien 54
 
904 aurelien 55
    	// Creating a workbook
56
		$workbook = new Spreadsheet_Excel_Writer();
1609 raphael 57
		$workbook->setVersion(8);
904 aurelien 58
		// Creating a worksheet
59
		$worksheet = $workbook->addWorksheet('Liste');
1609 raphael 60
		$worksheet->setInputEncoding('utf-8');
904 aurelien 61
 
62
        $worksheet->write(0,0,'Departement');
63
        $worksheet->write(0,1,'Nom saisi');
64
        $worksheet->write(0,2,'Numero nomenclatural');
65
        $worksheet->write(0,3,'Nom retenu');
66
        $worksheet->write(0,4,'Numero nomenclatural nom retenu');
67
        $worksheet->write(0,5,'Numero taxonomique');
68
        $worksheet->write(0,6,'Famille');
69
        $worksheet->write(0,7,'Commune');
70
        $worksheet->write(0,8,'Date Observation');
71
        $worksheet->write(0,9,'Lieu dit');
72
        $worksheet->write(0,10,'Station');
73
        $worksheet->write(0,11,'Milieu');
74
        $worksheet->write(0,12,'Commentaire');
75
        $worksheet->write(0,13,'Observateur');
76
 
77
		$i=1;
416 aurelien 78
 
904 aurelien 79
		$observations = array();
80
		$chercheur_infos_taxon = null;
81
		if (is_array($resultat_obs)) {
82
			$observations = &$resultat_obs;
1425 aurelien 83
			$chercheur_infos_taxon = new RechercheInfosTaxonBeta($this->config);
904 aurelien 84
		}
85
 
86
		foreach ($observations as $obs) {
416 aurelien 87
 
904 aurelien 88
			$code_departement = $this->convertirCodeZoneGeoVersDepartement($obs['ce_zone_geo']);
89
			$taxon_deja_vu = $chercheur_infos_taxon->taxonEstPresentDansDepartement($obs['nt'], $code_departement);
90
 
91
			if (!$taxon_deja_vu) {
92
			 	// Denullifiage
93
				foreach($obs as $k=>$v) {
94
					if (($v=="null") || ($v=="000null")) {
95
						$obs[$k]="";
96
					}
97
					else {
98
						$obs[$k]=utf8_decode($v);
99
					}
100
				}
416 aurelien 101
 
904 aurelien 102
				if ($obs['date_observation']!="0000-00-00 00:00:00") {
996 aurelien 103
                	list($year,$month,$day)= explode('-',$obs['date_observation']);
104
    	            list($day)= explode(' ',$day);
904 aurelien 105
	                $obs['date_observation']=$day."/".$month."/".$year;
106
    	    	}
107
        		else {
108
            	    $obs['date_observation']="00/00/0000";
109
	        	}
416 aurelien 110
 
904 aurelien 111
				$worksheet->write($i,0,$code_departement);
112
				$worksheet->write($i,1,$obs['nom_sel']);
113
                $worksheet->write($i,2,$obs['nom_sel_nn']);
114
		        $worksheet->write($i,3,$obs['nom_ret']);
115
                $worksheet->write($i,4,$obs['nom_ret_nn']);
116
		        $worksheet->write($i,5,$obs['nt']);
117
        		$worksheet->write($i,6,$obs['famille']);
118
                $worksheet->write($i,7,$obs['zone_geo']);
119
        		$worksheet->write($i,8,$obs['date_observation']);
120
                $worksheet->write($i,9,$obs['lieudit']);
121
		        $worksheet->write($i,10,$obs['station']);
122
		        $worksheet->write($i,11,$obs['milieu']);
123
        		$worksheet->write($i,12,$obs['commentaire']);
124
        		$worksheet->write($i,13,$obs['courriel_utilisateur']);
125
 
126
        		$i++;
127
			}
128
		}
129
 
130
		// sending HTTP headers
131
		$workbook->send('liste.xls');
132
		$workbook->close();
416 aurelien 133
 
904 aurelien 134
		exit();
135
	}
416 aurelien 136
}
137
 
138
/* +--Fin du code ---------------------------------------------------------------------------------------+
139
* $Log$
140
* Revision 1.1  2008-11-13 11:29:12  ddelon
141
* Reecriture gwt-ext
142
*
143
* Revision 1.2  2008-01-30 08:57:28  ddelon
144
* fin mise en place mygwt
145
*
146
* Revision 1.1  2007-06-06 13:31:16  ddelon
147
* v0.09
148
*
149
* Revision 1.3  2007-05-22 12:54:09  ddelon
150
* Securisation acces utilisateur
151
*
152
*
153
*
154
*/
904 aurelien 155
?>