Subversion Repositories Sites.obs-saisons.fr

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 aurelien 1
<?
2
include("../modules/connect.php");
3
 
4
  $contenu = "";
5
  $entetes = array("sequence_id","mesure_id","mesure_annee","mesure_date","evenement_nom","code_bbch_numero",
6
  		"espece_nom_scientifique","plateforme_nom","pltaforme_longitude",
7
  		"plateforme_latitude","plateforme_latitude","plateforme_type_nom","erreur_standard","nb_individus");
8
  $requete_seqs = mysql_query("select distinct MAX(-SEQUENCE.SEQUENCE_ID), MAX(-MESURE.MESURE_ID), ".
9
			"EXTRACT(YEAR from MESURE_DATE) AS ANNEE, ".
10
			"DATE_FORMAT(FROM_UNIXTIME(AVG(UNIX_TIMESTAMP(MESURE_DATE))),'%d/%m/%Y'), EVENEMENT.EVENEMENT_NOM, NULL, ".
11
			"ESPECE_NOM_SCIENTIFIQUE, STATION_NOM, STATION_LATITUDE, ".
12
			"STATION_LONGITUDE, SEQUENCE_ALTITUDE, ENVIRONNEMENT_NOM, ".
13
			"STD(UNIX_TIMESTAMP(MESURE_DATE))/86400, COUNT(MESURE_INDIVIDU) ".
14
                        "from MESURE, SEQUENCE, ESPECE, STATION, EVENEMENT, ENVIRONNEMENT ".
15
			"where MESURE.SEQUENCE_ID=SEQUENCE.SEQUENCE_ID ".
16
			"and SEQUENCE.ESPECE_ID=ESPECE.ESPECE_ID ".
17
			"and MESURE.EVENEMENT_ID=EVENEMENT.EVENEMENT_ID ".
18
			"and STATION.STATION_ID=SEQUENCE.STATION_ID ".
19
			"and ENVIRONNEMENT.ENVIRONNEMENT_ID=SEQUENCE.ENVIRONNEMENT_ID ".
20
			"group by ESPECE.ESPECE_ID,EVENEMENT.EVENEMENT_ID,STATION.STATION_ID,ANNEE,SEQUENCE_ALTITUDE,ENVIRONNEMENT.ENVIRONNEMENT_ID ORDER BY MESURE_DATE ");
21
echo mysql_error();
22
  //on regarde chaque séquence pour moyenner les mesures
23
  $num_seq = 0;
24
  while ($seq_crt = mysql_fetch_row($requete_seqs)) {
25
        $sequences[$num_seq] = $seq_crt;
26
	if ($seq_crt[13]!=1) {
27
	  $racine = sqrt($seq_crt[13]/($seq_crt[13]-1));
28
	  if ($racine)
29
	    $sequences[$num_seq][12] = $seq_crt[12]*$racine;
30
	} else
31
	  $sequences[$num_seq][12] = 0;
32
        if (($icode = strpos($req_crt[4],"stade"))>0) {
33
            $code_bbch = substr($req_crt[4],$icode+5);
34
            $sequences[$num_seq][5] = $code_bbch;
35
            $sequences[$num_seq][4] = substr($req_crt[4],0,$icode-1);
36
        }
37
        $num_seq++;
38
  }
39
 
40
 
41
  $fichierc = implode(';',$entetes)."\n";
42
  foreach ($sequences as $util) {
43
    if (($icode = strpos($util[4],"stade"))>0) {
44
      $code_bbch = substr($util[4],$icode+5);
45
      $util[5] = $code_bbch;
46
      $util[4] = substr($util[4],0,$icode-1);
47
    }
48
    $fichierc .= implode(';',$util)."\n";
49
  }
50
  $fichier = "observations_export.csv";
51
  $handle = fopen($chemin.$fichier,'w');
52
  fwrite($handle,$fichierc);
53
  fclose($handle);
54
 
55
$contenue        = file_get_contents($fichier);
56
$tailledufichier = filesize($fichier);
57
 
58
@ob_end_clean();
59
@ini_set('zlib.output_compression','Off');
60
 
61
header('Pragma: public');
62
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
63
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
64
 
65
header('Content-Tranfer-Encoding: none');
66
 
67
header('Content-Type: application/octetstream; name="'.$fichier.'"');
68
header('Content-Disposition: attachement; filename="'.$fichier.'"');
69
 
70
header('Content-Length: '.$tailledufichier);
71
 
72
echo $contenue;
73
exit();
74
?>