Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 1 | Blame | Last modification | View Log | RSS feed

<?
include("../modules/connect.php");

  $contenu = "";
  $entetes = array("sequence_id","mesure_id","mesure_annee","mesure_date","evenement_nom","code_bbch_numero",
                "espece_nom_scientifique","plateforme_nom","pltaforme_longitude",
                "plateforme_latitude","plateforme_latitude","plateforme_type_nom","erreur_standard","nb_individus");
  $requete_seqs = mysql_query("select distinct MAX(-SEQUENCE.SEQUENCE_ID), MAX(-MESURE.MESURE_ID), ".
                        "EXTRACT(YEAR from MESURE_DATE) AS ANNEE, ".
                        "DATE_FORMAT(FROM_UNIXTIME(AVG(UNIX_TIMESTAMP(MESURE_DATE))),'%d/%m/%Y'), EVENEMENT.EVENEMENT_NOM, NULL, ".
                        "ESPECE_NOM_SCIENTIFIQUE, STATION_NOM, STATION_LATITUDE, ".
                        "STATION_LONGITUDE, SEQUENCE_ALTITUDE, ENVIRONNEMENT_NOM, ".
                        "STD(UNIX_TIMESTAMP(MESURE_DATE))/86400, COUNT(MESURE_INDIVIDU) ".
                        "from MESURE, SEQUENCE, ESPECE, STATION, EVENEMENT, ENVIRONNEMENT ".
                        "where MESURE.SEQUENCE_ID=SEQUENCE.SEQUENCE_ID ".
                        "and SEQUENCE.ESPECE_ID=ESPECE.ESPECE_ID ".             
                        "and MESURE.EVENEMENT_ID=EVENEMENT.EVENEMENT_ID ".
                        "and STATION.STATION_ID=SEQUENCE.STATION_ID ".
                        "and ENVIRONNEMENT.ENVIRONNEMENT_ID=SEQUENCE.ENVIRONNEMENT_ID ".
                        "group by ESPECE.ESPECE_ID,EVENEMENT.EVENEMENT_ID,STATION.STATION_ID,ANNEE,SEQUENCE_ALTITUDE,ENVIRONNEMENT.ENVIRONNEMENT_ID ORDER BY MESURE_DATE ");
echo mysql_error();
  //on regarde chaque séquence pour moyenner les mesures 
  $num_seq = 0; 
  while ($seq_crt = mysql_fetch_row($requete_seqs)) { 
        $sequences[$num_seq] = $seq_crt;
        if ($seq_crt[13]!=1) {
          $racine = sqrt($seq_crt[13]/($seq_crt[13]-1));
          if ($racine)
            $sequences[$num_seq][12] = $seq_crt[12]*$racine; 
        } else
          $sequences[$num_seq][12] = 0;
        if (($icode = strpos($req_crt[4],"stade"))>0) { 
            $code_bbch = substr($req_crt[4],$icode+5); 
            $sequences[$num_seq][5] = $code_bbch; 
            $sequences[$num_seq][4] = substr($req_crt[4],0,$icode-1); 
        }
        $num_seq++; 
  } 


  $fichierc = implode(';',$entetes)."\n";
  foreach ($sequences as $util) {
    if (($icode = strpos($util[4],"stade"))>0) {
      $code_bbch = substr($util[4],$icode+5);
      $util[5] = $code_bbch;
      $util[4] = substr($util[4],0,$icode-1);
    }
    $fichierc .= implode(';',$util)."\n";
  }
  $fichier = "observations_export.csv";
  $handle = fopen($chemin.$fichier,'w');
  fwrite($handle,$fichierc);
  fclose($handle);

$contenue        = file_get_contents($fichier);
$tailledufichier = filesize($fichier);

@ob_end_clean();
@ini_set('zlib.output_compression','Off');

header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');

header('Content-Tranfer-Encoding: none');

header('Content-Type: application/octetstream; name="'.$fichier.'"');
header('Content-Disposition: attachement; filename="'.$fichier.'"');

header('Content-Length: '.$tailledufichier);

echo $contenue;
exit();
?>