Subversion Repositories eFlore/Applications.cel

Rev

Rev 416 | Rev 996 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 416 Rev 885
Line 1... Line 1...
1
<?php
1
<?php
-
 
2
/**
-
 
3
* PHP Version 5
-
 
4
*
-
 
5
* @category  PHP
-
 
6
* @package   jrest
-
 
7
* @author    David Delon <david.delon@clapas.net>
-
 
8
* @copyright 2010 Tela-Botanica
-
 
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
-
 
10
* @version   SVN: <svn_id>
-
 
11
* @link      /doc/jrest/
-
 
12
*/
Line 2... Line -...
2
 
-
 
3
// In : utf8
-
 
4
// Out : iso8859
-
 
5
 
-
 
Line 6... Line 13...
6
// Formatage pdf d'un releve (a revoir)
13
 
7
 
14
 
8
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
15
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
9
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
16
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
Line 16... Line 23...
16
/** Constante stockant l'expression r.guli.re r.cup.rant l'abr.viation du photographe et le nom du fichier.*/
23
/** Constante stockant l'expression r.guli.re r.cup.rant l'abr.viation du photographe et le nom du fichier.*/
17
define('EF_URL_PHOTOFLORA_REGEXP', '/\/photos\/([^\/]+)\/max\/(.+)$/');
24
define('EF_URL_PHOTOFLORA_REGEXP', '/\/photos\/([^\/]+)\/max\/(.+)$/');
18
/** Constante stockant l'URL du service XML de Photoflora.*/
25
/** Constante stockant l'URL du service XML de Photoflora.*/
19
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
26
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
Line -... Line 27...
-
 
27
 
-
 
28
/**
-
 
29
* InventoryPDF.php
-
 
30
*
-
 
31
* in : utf8
-
 
32
* out : iso8859
-
 
33
*
-
 
34
* Formatage pdf d'un releve (a revoir)
-
 
35
*/
Line 20... Line -...
20
 
-
 
21
 
-
 
22
Class InventoryPDF extends DBAccessor  {
-
 
23
 
-
 
24
 
36
class InventoryPDF extends Cel  {
Line 25... Line 37...
25
	var $config;
37
 
Line -... Line 38...
-
 
38
	var $extendPDFProductor;
-
 
39
	
26
	var $extendPDFProductor;
40
	function InventoryPDF($config) {
27
	
41
 
28
	function InventoryPDF($config) {
42
		parent::__construct($config);
29
 
43
 
30
		$this->config=$config;
44
		$this->config=$config;
Line -... Line 45...
-
 
45
		// Pas d'heritage multiple en php :(
-
 
46
		$this->extendPDFProductor = new PDFProductor();
-
 
47
		$this->extendPDFProductor->initPDF();
-
 
48
	}
-
 
49
	
-
 
50
	/**
31
		// Pas d'heritage multiple en php :(
51
	* uid[0] : utilisateur obligatoire
32
		$this->extendPDFProductor = new PDFProductor();
52
	* uid[1] : si absent : valeur 'all' (commune)
Line 33... Line 53...
33
		$this->extendPDFProductor->initPDF();
53
	* uid[2] : si absent : valeur 'all' (date)
34
	}
54
	* uid[3] : si absent : valeur 'all' (recherche libre)
35
	
55
	* uid[4] : si absent : valeur 'all' (station)
36
 
-
 
37
	function getElement($uid){
-
 
38
		
-
 
39
		   // Controle detournement utilisateur 
-
 
40
		    session_start();
-
 
41
		 	$this->controleUtilisateur($uid[0]);
-
 
42
 
-
 
43
			// uid[0] : utilisateur obligatoire
-
 
44
			// uid[1] : si absent : valeur 'all' (commune)
56
	*/
45
			// uid[2] : si absent : valeur 'all' (date)
57
	function getElement($uid){
46
			// uid[3] : si absent : valeur 'all' (recherche libre)
58
		
47
			// uid[4] : si absent : valeur 'all' (station)
59
	   // Controle detournement utilisateur 
48
			
60
	    session_start();
49
			$DB=$this->connectDB($this->config,'database_cel');
61
	 	$this->controleUtilisateur($uid[0]);
50
			 
62
	 				 
51
			if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
-
 
52
				$uid[1]="all";
-
 
53
				$query_location="";
-
 
54
			}
-
 
55
			else {
-
 
56
				$query_location=" AND location='".$DB->escapeSimple($uid[1])."' ";
-
 
57
			}
-
 
58
			
-
 
59
			if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") {
-
 
60
				$uid[2]="all";
-
 
61
				$query_date="";
-
 
62
			}
-
 
63
			else {
-
 
64
				$query_date=" AND date_observation='".$DB->escapeSimple($uid[2])."' ";
-
 
65
			}
-
 
66
			
-
 
67
			if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") {
-
 
68
				$uid[3]="all";
-
 
69
				$query_libre="";
-
 
70
			}
-
 
71
			else {
-
 
72
				$query_libre=" AND (nom_sel like '%".$DB->escapeSimple($uid[3])."%' OR nom_ret like '%".$DB->escapeSimple($uid[3])."%' OR station like '%".$DB->escapeSimple($uid[3])."%' OR commentaire like '%".$DB->escapeSimple($uid[3])."%') ";
-
 
73
			}
-
 
74
 
-
 
75
			if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") {
-
 
76
				$uid[4]="all";
-
 
77
				$query_station="";
-
 
78
			}
-
 
79
			else {
-
 
80
				$query_station=" AND station='".$DB->escapeSimple($uid[4])."' ";
-
 
81
			}
-
 
82
			
-
 
83
 
-
 
84
			$value=array();
-
 
85
			
-
 
86
			
-
 
87
		   	$query="SELECT identifiant, ordre, nom_sel, num_nom_sel, nom_ret, num_nom_ret, num_taxon, famille, location, date_observation," .
-
 
88
		           " station, commentaire, transmission  FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' " .
-
 
89
					$query_location.	
-
 
90
	        		$query_date.	
-
 
91
	        		$query_libre.	
-
 
92
	         		$query_station.	
-
 
93
	          		" ORDER BY ordre ";
-
 
94
			     
63
		if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
95
       	    $res =& $DB->query($query);
-
 
Line 96... Line -...
96
   
-
 
97
    
64
			$uid[1]="all";
98
			if (DB::isError($res)) {
-
 
99
			     die($res->getMessage());
-
 
100
			}
-
 
101
					
-
 
102
		
-
 
103
			// Set up the pdf object.
-
 
104
			$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
65
			$requete_location="";
105
			// DesActivate compression.
-
 
106
			$pdf->setCompression(false);
66
		}
107
			$pdf->setMargins(0, 0);
-
 
108
			// Enable automatic page breaks.
-
 
109
			$pdf->setAutoPageBreak(true);
-
 
110
			// Start the document.
-
 
111
			$pdf->open();
-
 
112
			// Start a page.
-
 
113
			$pdf->addPage();
-
 
114
			$pdf->setFont('Times', '' , 12);
-
 
115
			
-
 
116
			$i=1;	
-
 
117
		    $tempfn = tempnam("","");
67
		else {
118
			
68
			$requete_location=" AND location= ".$this->proteger($uid[1])." ";
119
			 while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
69
		}
120
			 	// Denullifiage   
-
 
121
				foreach($row as $k=>$v) {
70
		
122
					if (($v=="null") || ($v=="000null")) {
-
 
123
						$row[$k]="";
-
 
124
					}
-
 
125
					else {
-
 
126
						$row[$k]=utf8_decode($v);
-
 
127
					}
-
 
128
				} 
-
 
129
				
-
 
130
			  	if ($row['date_observation']!="0000-00-00 00:00:00") {
-
 
131
	                list($year,$month,$day)= split ('-',$row['date_observation']);
-
 
132
    	            list($day)= split (' ',$day);
-
 
133
	                $row['date_observation']=$day."/".$month."/".$year;
-
 
134
	        	}
-
 
135
	        	else {
-
 
136
	                $row['date_observation']="00/00/0000";
-
 
137
	        	}
-
 
138
          
-
 
Line -... Line 71...
-
 
71
		if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") {
-
 
72
			$uid[2]="all";
-
 
73
			$requete_date="";
-
 
74
		}
-
 
75
		else {
-
 
76
			$requete_date=" AND date_observation= ".$this->proteger($uid[2])." ";
-
 
77
		}
-
 
78
		
-
 
79
		if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") {
-
 
80
			$uid[3]="all";
-
 
81
			$requete_libre="";
-
 
82
		}
-
 
83
		else {
-
 
84
			$requete_libre=" AND (nom_sel LIKE ".$this->proteger('%'.$uid[3].'%').
-
 
85
						" OR nom_ret LIKE ".$this->proteger('%'.$uid[3].'%').
-
 
86
						" OR station LIKE ".$this->proteger('%'.$uid[3].'%').
139
                $text= $row['nom_sel']." ".$row['num_nom_sel']." ".$row['nom_ret']." ".$row['num_nom_ret']." ".$row['num_taxon']." ".
87
						" OR commentaire LIKE ".$this->proteger('%'.$uid[3].'%');
-
 
88
		}
Line -... Line 89...
-
 
89
 
Line -... Line 90...
-
 
90
		if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") {
-
 
91
			$uid[4]="all";
-
 
92
			$requete_station="";
-
 
93
		}
140
                $row['famille']." ".$row['location']." ".$row['id_location']." ".$row['date_observation']." ".$row['station'];
94
		else {
-
 
95
			$requete_station=" AND station= ".$this->proteger($uid[4])." ";
-
 
96
		}
141
                $row['commentaire'];
97
		
142
                
98
		$value=array();
143
				$pdf->write(10, $text."\n");
-
 
-
 
99
		
144
				
100
	   	$requete="SELECT ce_utilisateur, ordre, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille, zone_geo, date_observation," .
145
				$projet_photo = 'photoflora';
101
	           " station, commentaire, transmission  FROM cel_obs WHERE ce_utilisateur = ".$this->proteger($uid[0])." " .
146
		
102
				$requete_location.	
-
 
103
        		$requete_date.	
147
				$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $row['num_taxon']));
104
        		$requete_libre.	
-
 
105
         		$requete_station.	
-
 
106
          		" ORDER BY ordre ";
148
		
107
		
-
 
108
		$resultat_requete = $this->requeter($requete);
-
 
109
		
149
		
110
		$observations = array();;
-
 
111
		if(is_array($resultat_requete)) {
-
 
112
			$observations = $resultat_requete;
150
		      	$url_miniature =''; 
113
		}
-
 
114
		
-
 
115
		// Set up the pdf object.
-
 
116
		$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
-
 
117
		// DesActivate compression.
151
		      	
118
		$pdf->setCompression(false);
-
 
119
		$pdf->setMargins(0, 0);
-
 
120
		// Enable automatic page breaks.
-
 
121
		$pdf->setAutoPageBreak(true);
-
 
122
		// Start the document.
-
 
123
		$pdf->open();
-
 
124
		// Start a page.
-
 
125
		$pdf->addPage();
152
				foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
126
		$pdf->setFont('Times', '' , 12);
153
					if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) {
127
		
154
					$abreviation = $match[1];
-
 
155
					$fichier = $match[2];
-
 
156
			      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
-
 
157
					
128
		$i=1;	
158
					// Priorite aux images en png
-
 
159
						if (strstr($fichier, '.png')) {
-
 
160
							break;
-
 
161
						}
129
	    $tempfn = tempnam("","");
162
					}
-
 
163
				}
-
 
164
 
130
		
165
 
-
 
166
 
-
 
167
				if ($url_miniature!='') {				
131
		foreach ($observations as $obs) {
168
					list($debut,$ext)=split("\.",basename($url_miniature));
-
 
169
	       		    $temp = fopen($tempfn, "w");
-
 
170
					$buf=file_get_contents($url_miniature);
-
 
Line -... Line 132...
-
 
132
			
-
 
133
		 	// Denullifiage   
-
 
134
			foreach($obs as $k=>$v) {
-
 
135
				if (($v=="null") || ($v=="000null")) {
-
 
136
					$obs[$k]="";
-
 
137
				}
-
 
138
				else {
-
 
139
					$obs[$k]=utf8_decode($v);
-
 
140
				}
-
 
141
			} 
-
 
142
			
-
 
143
		  	if ($obs['date_observation']!="0000-00-00 00:00:00") {
-
 
144
                list($year,$month,$day)= split ('-',$obs['date_observation']);
171
					fwrite($temp,$buf);
145
	            list($day)= split (' ',$day);
Line 172... Line -...
172
        			fclose($temp);
-
 
173
					$pdf->image($tempfn,10,($i*10),0,0,$ext);
-
 
-
 
146
                $obs['date_observation']=$day."/".$month."/".$year;
Line -... Line 147...
-
 
147
        	}
-
 
148
        	else {
-
 
149
                $obs['date_observation']="00/00/0000";
-
 
150
        	}
-
 
151
      
-
 
152
            $text= $obs['nom_sel']." ".$obs['nom_sel_nn']." ".$obs['nom_ret']." ".$obs['nom_ret_nn']." ".$obs['nt']." ".
-
 
153
            $obs['famille']." ".$obs['zone_geo']." ".$obs['ce_zone_geo']." ".$obs['date_observation']." ".$obs['station'];
-
 
154
            $obs['commentaire'];
-
 
155
            
-
 
156
			$pdf->write(10, $text."\n");
-
 
157
			
-
 
158
			$projet_photo = 'photoflora';
-
 
159
	
-
 
160
			$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $obs['nt']));
-
 
161
	
-
 
162
	
-
 
163
	      	$url_miniature =''; 
Line -... Line 164...
-
 
164
	      	
-
 
165
			foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
-
 
166
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) {
-
 
167
				$abreviation = $match[1];
-
 
168
				$fichier = $match[2];
-
 
169
		      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
-
 
170
				
-
 
171
				// Priorite aux images en png
-
 
172
					if (strstr($fichier, '.png')) {
-
 
173
						break;
-
 
174
					}
174
				}
175
				}
-
 
176
			}
-
 
177
 
175
		
178
			if ($url_miniature!='') {				
Line 176... Line 179...
176
                $i++;
179
				list($debut,$ext)=split("\.",basename($url_miniature));
177
    	    }
180
       		    $temp = fopen($tempfn, "w");
178
    	
181
				$buf=file_get_contents($url_miniature);
Line 225... Line 228...
225
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
228
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
226
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
229
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
227
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
230
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
228
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
231
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
229
		}
232
		}
230
		//echo '<pre>'.$chemin.print_r($tab_infos, true).'</pre>';
-
 
-
 
233
 
231
		return $tab_infos;
234
		return $tab_infos;
232
}
235
}
Line 233... Line -...
233
 
-
 
234
 
-
 
235
 
236
 
236
/* +--Fin du code ---------------------------------------------------------------------------------------+
237
/* +--Fin du code ---------------------------------------------------------------------------------------+
237
* $Log$
238
* $Log$
238
* Revision 1.2  2008-01-30 08:57:28  ddelon
239
* Revision 1.2  2008-01-30 08:57:28  ddelon
239
* fin mise en place mygwt
240
* fin mise en place mygwt
Line 242... Line 243...
242
* v0.09
243
* v0.09
243
*
244
*
244
* Revision 1.4  2007-05-22 12:54:09  ddelon
245
* Revision 1.4  2007-05-22 12:54:09  ddelon
245
* Securisation acces utilisateur
246
* Securisation acces utilisateur
246
*
247
*
247
*
-
 
248
* 
-
 
249
*/
248
*/
250
 
-
 
251
 
-
 
252
?>
249
?>
253
250