Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1765 Rev 2450
Line 34... Line 34...
34
* Formatage pdf d'un releve (a revoir)
34
* Formatage pdf d'un releve (a revoir)
35
*/
35
*/
36
class InventoryPDF extends Cel  {
36
class InventoryPDF extends Cel  {
Line 37... Line 37...
37
 
37
 
38
	var $extendPDFProductor;
38
	var $extendPDFProductor;
39
	
39
 
Line 40... Line 40...
40
	function InventoryPDF($config) {
40
	function InventoryPDF($config) {
Line 41... Line 41...
41
 
41
 
42
		parent::__construct($config);
42
		parent::__construct($config);
43
 
43
 
44
		$this->config=$config;
44
		$this->config=$config;
45
		// Pas d'heritage multiple en php :(
45
		// Pas d'heritage multiple en php :(
46
		$this->extendPDFProductor = new PDFProductor();
46
		$this->extendPDFProductor = new PDFProductor();
47
		$this->extendPDFProductor->initPDF();
47
		$this->extendPDFProductor->initPDF();
48
	}
48
	}
49
	
49
 
50
	/**
50
	/**
51
	* uid[0] : utilisateur obligatoire
51
	* uid[0] : utilisateur obligatoire
52
	* uid[1] : si absent : valeur 'all' (commune)
52
	* uid[1] : si absent : valeur 'all' (commune)
53
	* uid[2] : si absent : valeur 'all' (date)
53
	* uid[2] : si absent : valeur 'all' (date)
54
	* uid[3] : si absent : valeur 'all' (recherche libre)
54
	* uid[3] : si absent : valeur 'all' (recherche libre)
55
	* uid[4] : si absent : valeur 'all' (station)
55
	* uid[4] : si absent : valeur 'all' (station)
56
	*/
56
	*/
57
	function getElement($uid){
57
	function getElement($uid){
58
		
58
 
59
	   // Controle detournement utilisateur 
59
	   // Controle detournement utilisateur
60
	 	$this->controleUtilisateur($uid[0]);
60
	 	$this->controleUtilisateur($uid[0]);
61
	 				 
61
 
62
		if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
62
		if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
63
			$uid[1]="all";
63
			$uid[1]="all";
64
			$requete_location="";
64
			$requete_location="";
65
		}
65
		}
66
		else {
66
		else {
67
			$requete_location=" AND location= ".Cel::db()->proteger($uid[1])." ";
67
			$requete_location=" AND location= ".Cel::db()->proteger($uid[1])." ";
68
		}
68
		}
69
		
69
 
70
		if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") {
70
		if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") {
71
			$uid[2]="all";
71
			$uid[2]="all";
72
			$requete_date="";
72
			$requete_date="";
73
		}
73
		}
74
		else {
74
		else {
75
			$requete_date=" AND date_observation= ".Cel::db()->proteger($uid[2])." ";
75
			$requete_date=" AND date_observation= ".Cel::db()->proteger($uid[2])." ";
76
		}
76
		}
77
		
77
 
78
		if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") {
78
		if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") {
79
			$uid[3]="all";
79
			$uid[3]="all";
Line 91... Line 91...
91
			$requete_station="";
91
			$requete_station="";
92
		}
92
		}
93
		else {
93
		else {
94
			$requete_station=" AND station= ".Cel::db()->proteger($uid[4])." ";
94
			$requete_station=" AND station= ".Cel::db()->proteger($uid[4])." ";
95
		}
95
		}
96
		
96
 
97
		$value=array();
97
		$value=array();
98
		
98
 
99
	   	$requete="SELECT ce_utilisateur, ordre, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille, zone_geo, date_observation," .
99
	   	$requete="SELECT ce_utilisateur, ordre, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille, zone_geo, date_observation, " .
100
	           " station, commentaire, transmission  FROM cel_obs WHERE ce_utilisateur = ".Cel::db()->proteger($uid[0])." " .
100
	           "station, commentaire, transmission  FROM cel_obs WHERE ce_utilisateur = ".Cel::db()->proteger($uid[0])." " .
101
				$requete_location.	
101
				$requete_location.
102
        		$requete_date.	
102
        		$requete_date.
103
        		$requete_libre.	
103
        		$requete_libre.
104
         		$requete_station.	
104
         		$requete_station.
105
          		" ORDER BY ordre ";
105
          		" ORDER BY ordre ";
106
		
106
 
107
		$resultat_requete = Cel::db()->requeter($requete);
107
		$resultat_requete = Cel::db()->requeter($requete);
108
		
108
 
109
		$observations = array();;
109
		$observations = array();;
110
		if(is_array($resultat_requete)) {
110
		if(is_array($resultat_requete)) {
111
			$observations = $resultat_requete;
111
			$observations = $resultat_requete;
112
		}
112
		}
113
		
113
 
114
		// Set up the pdf object.
114
		// Set up the pdf object.
115
		$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
115
		$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
116
		// DesActivate compression.
116
		// DesActivate compression.
117
		$pdf->setCompression(false);
117
		$pdf->setCompression(false);
118
		$pdf->setMargins(0, 0);
118
		$pdf->setMargins(0, 0);
Line 121... Line 121...
121
		// Start the document.
121
		// Start the document.
122
		$pdf->open();
122
		$pdf->open();
123
		// Start a page.
123
		// Start a page.
124
		$pdf->addPage();
124
		$pdf->addPage();
125
		$pdf->setFont('Times', '' , 12);
125
		$pdf->setFont('Times', '' , 12);
126
		
126
 
127
		$i=1;	
127
		$i=1;
128
	    $tempfn = tempnam("","");
128
	    $tempfn = tempnam("","");
129
		
129
 
130
		foreach ($observations as $obs) {
130
		foreach ($observations as $obs) {
131
			
131
 
132
		 	// Denullifiage   
132
		 	// Denullifiage
133
			foreach($obs as $k=>$v) {
133
			foreach($obs as $k=>$v) {
134
				if (($v=="null") || ($v=="000null")) {
134
				if (($v=="null") || ($v=="000null")) {
135
					$obs[$k]="";
135
					$obs[$k]="";
136
				}
136
				}
137
				else {
137
				else {
138
					$obs[$k]=utf8_decode($v);
138
					$obs[$k]=utf8_decode($v);
139
				}
139
				}
140
			} 
140
			}
141
			
141
 
142
		  	if ($obs['date_observation']!="0000-00-00 00:00:00") {
142
		  	if ($obs['date_observation']!="0000-00-00 00:00:00") {
143
                list($year,$month,$day)= explode('-',$obs['date_observation']);
143
                list($year,$month,$day)= explode('-',$obs['date_observation']);
144
	            list($day)= explode(' ',$day);
144
	            list($day)= explode(' ',$day);
145
                $obs['date_observation']=$day."/".$month."/".$year;
145
                $obs['date_observation']=$day."/".$month."/".$year;
146
        	}
146
        	}
147
        	else {
147
        	else {
148
                $obs['date_observation']="00/00/0000";
148
                $obs['date_observation']="00/00/0000";
149
        	}
149
        	}
150
      
150
 
151
            $text= $obs['nom_sel']." ".$obs['nom_sel_nn']." ".$obs['nom_ret']." ".$obs['nom_ret_nn']." ".$obs['nt']." ".
151
            $text= $obs['nom_sel']." ".$obs['nom_sel_nn']." ".$obs['nom_ret']." ".$obs['nom_ret_nn']." ".$obs['nt']." ".
152
            $obs['famille']." ".$obs['zone_geo']." ".$obs['ce_zone_geo']." ".$obs['date_observation']." ".$obs['station'];
152
            $obs['famille']." ".$obs['zone_geo']." ".$obs['ce_zone_geo']." ".$obs['date_observation']." ".$obs['station'];
153
            $obs['commentaire'];
153
            $obs['commentaire'];
154
            
154
 
155
			$pdf->write(10, $text."\n");
155
			$pdf->write(10, $text."\n");
156
			
156
 
157
			$projet_photo = 'photoflora';
157
			$projet_photo = 'photoflora';
158
	
158
 
159
			$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $obs['nt']));
159
			$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $obs['nt']));
160
	
160
 
161
	
161
 
162
	      	$url_miniature =''; 
162
	      	$url_miniature ='';
163
	      	
163
 
164
			foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
164
			foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
165
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) {
165
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) {
166
				$abreviation = $match[1];
166
				$abreviation = $match[1];
167
				$fichier = $match[2];
167
				$fichier = $match[2];
168
		      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
168
		      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
169
				
169
 
170
				// Priorite aux images en png
170
				// Priorite aux images en png
171
					if (strstr($fichier, '.png')) {
171
					if (strstr($fichier, '.png')) {
172
						break;
172
						break;
173
					}
173
					}
174
				}
174
				}
175
			}
175
			}
Line 176... Line 176...
176
 
176
 
177
			if ($url_miniature!='') {				
177
			if ($url_miniature!='') {
178
				list($debut,$ext)=explode("\.",basename($url_miniature));
178
				list($debut,$ext)=explode("\.",basename($url_miniature));
179
       		    $temp = fopen($tempfn, "w");
179
       		    $temp = fopen($tempfn, "w");
180
				$buf=file_get_contents($url_miniature);
180
				$buf=file_get_contents($url_miniature);
181
				fwrite($temp,$buf);
181
				fwrite($temp,$buf);
182
    			fclose($temp);
182
    			fclose($temp);
183
				$pdf->image($tempfn,10,($i*10),0,0,$ext);
183
				$pdf->image($tempfn,10,($i*10),0,0,$ext);
184
			}
184
			}
185
	
185
 
186
            $i++;
186
            $i++;
187
	    }
187
	    }
188
    			
188
 
189
		echo $pdf->output("Rapport");
189
		echo $pdf->output("Rapport");
190
	}
190
	}
Line 191... Line 191...
191
}
191
}
192
 
192
 
193
function chercherIllustrationsServiceXml($url)
193
function chercherIllustrationsServiceXml($url)
194
{
194
{
195
		return  analyserFichierRdf($url);
195
		return  analyserFichierRdf($url);
196
}
196
}
197
	
197
 
198
function analyserFichierRdf($chemin)
198
function analyserFichierRdf($chemin)
199
{
199
{
200
		$aso_info = array();
200
		$aso_info = array();
201
		$dom = new DOMDocument();
201
		$dom = new DOMDocument();
202
		$dom->validateOnParse = true;
202
		$dom->validateOnParse = true;
203
		if (preg_match('/^http:\/\//', $chemin)) {
203
		if (preg_match('/^http:\/\//', $chemin)) {
204
			$dom->loadXML(file_get_contents($chemin));
204
			$dom->loadXML(file_get_contents($chemin));
205
		} else {
205
		} else {
206
			$dom->load($chemin);
206
			$dom->load($chemin);
207
		}
207
		}
208
		
208
 
209
		$tab_infos = array();
209
		$tab_infos = array();
210
		foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
210
		foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
211
			$aso_info['about'] = $rdf_description->getAttribute('about');
211
			$aso_info['about'] = $rdf_description->getAttribute('about');
Line 218... Line 218...
218
			$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
218
			$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
219
			if (function_exists('date_default_timezone_set')) {
219
			if (function_exists('date_default_timezone_set')) {
220
				date_default_timezone_set('Europe/Paris');
220
				date_default_timezone_set('Europe/Paris');
221
			}
221
			}
222
			if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
222
			if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
223
				$aso_info['dcterms:created'] = date('j-m-Y � H:i:s', strtotime($rdf_description->getAttribute('created')));				
223
				$aso_info['dcterms:created'] = date('j-m-Y � H:i:s', strtotime($rdf_description->getAttribute('created')));
224
			} else {
224
			} else {
225
				$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
225
				$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
226
			}
226
			}
227
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
227
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
228
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
228
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
229
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
229
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
230
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
230
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info;
231
		}
231
		}
Line 232... Line 232...
232
 
232
 
233
		return $tab_infos;
233
		return $tab_infos;