Rev 1 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<script language="javascript">function gotoEtape (numetape) {document.navigation.etape.value=numetape;document.navigation.submit();}</script><?include("login.php");if (!function_exists("redirect")) {function redirect($filename) {if (!headers_sent())header('Location: '.$filename);else {echo '<script type="text/javascript">';echo 'window.location.href="'.$filename.'";';echo '</script>';echo '<noscript>';echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />';echo '</noscript>';}}}$url_page = $_SERVER['REQUEST_URI'];while (is_numeric($i = strpos($url_page,"/"))) {$url_page = substr($url_page, $i+1);}function estDate($j,$m,$a) {return (is_numeric($j) && strlen($j)==2) &&(is_numeric($m) && strlen($m)==2) &&(is_numeric($a) && strlen($a)==4);}function estDateEnAttente($j,$m,$a) {return ($j=='jj' && $m=='mm') || (sizeof($j)==0 && sizeof($m)==0);}function etape($nom_etape,$num_etape) {global $url_page;return"<a href='javascript:gotoEtape($num_etape);'>$nom_etape</a>";}function afficherErreurs($tab_erreurs) {if (sizeof($tab_erreurs)>0) {echo "<div class='erreurs'>";foreach ($tab_erreurs as $err)echo $err."<br>";echo "</div><br>";}}if ($_SESSION['participant']) {$erreurs = array();include("connect.php");include("messages.php");$choixCommune = false;$nbEtapes = 4;if (isset($_POST['etape']))$etape = $_POST['etape'];else if (isset($_GET['etape']))$etape = $_GET['etape'];else$etape = 1;if (isset($_SESSION['obsOK'])) {echo "<div class='erreurs'>Vos informations ont bien été prises en compte!</div>";unset($_SESSION['obsOK']);}//echo "Proposez de nouvelles observations ci-dessous...<br>";echo "<form name='navigation' method='post' action='$url_page'><input type='hidden' name='etape'></form>";if (isset($_POST['annul_modif'])) {$etape = 1;redirect("article.php3?id_article=2");exit;}if ($etape==1) {//si on arrive à peine sur la page$tableau_flippe=array_flip($_POST);if (!isset($_GET['station_id']) && !isset($tableau_flippe['Modifier']) ) {//si on n'a pas posté de séquence (=observation) à modifierif (!isset($_GET['sequence_id'])) {} else //on a posté une séquence (=observation) à modifier$numseq = $_GET['sequence_id'];if ($numseq) {$query_seq="select STATION_NOM, ESPECE_NOM_VERNACULAIRE, ENVIRONNEMENT_NOM , STATION_ALTITUDE, " ." CARACTERISTIQUE_ESP_VALEUR_LIB " ." from ESPECE, STATION, SEQUENCE , ENVIRONNEMENT, CARACTERISTIQUE_ESP_LIEN, CARACTERISTIQUE_ESP_VALEUR where SEQUENCE.STATION_ID=STATION.STATION_ID " ."and STATION_ENVIRONNEMENT_ID=ENVIRONNEMENT.ENVIRONNEMENT_ID and ESPECE.ESPECE_ID=SEQUENCE.ESPECE_ID " ."and ESPECE.ESPECE_ID=CARACTERISTIQUE_ESP_LIEN.ESPECE_ID " ."and CARACTERISTIQUE_ESP_LIEN.CARACTERISTIQUE_ESP_VALEUR_ID=CARACTERISTIQUE_ESP_VALEUR.CARACTERISTIQUE_ESP_VALEUR_ID " ."and SEQUENCE.SEQUENCE_ID=$numseq";$requete_seq = mysql_query($query_seq);$seq = mysql_fetch_row($requete_seq);$_SESSION['observation']['station']=$seq[0];$_SESSION['observation']['environnement']=$seq[2];$_SESSION['observation']['altitude']=$seq[3];$_SESSION['observation']['espece']=$seq[1];$_SESSION['observation']['type_espece']=$seq[4];echo "<div class='recap'>";echo "Station d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['station']."</a><br>";echo "Environnement d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['environnement']."</a><br>";echo "Altitude d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['altitude']."</a><br>";echo "Type d'espèce observé: ".$_SESSION['observation']['type_espece']."<br>";echo "Espèce observée: ".$_SESSION['observation']['espece']."<br>";echo "</div><br>";include("observations/modif_encours.php");}else{ // Affiché la premiere fois//include("observations/commune.php");// DDinclude("observations/station.php");// include("observations/encours.php");}} // valid_station presentelse {// TODO : supprimer de ici jusqua/*if (strlen($_POST['commune'])==0) { // Pas de commune choisi, commune par defaut.$requete_comm = mysql_query("select COMMUNE.COMMUNE_ID, COMMUNE_NOM from COMMUNE,PARTICIPANT where COMMUNE.COMMUNE_ID=PARTICIPANT.COMMUNE_ID and PARTICIPANT_ID=".$_SESSION['participant']);//$requete_comm = mysql_query("select COMMUNE_ID, COMMUNE_NOM from COMMUNE where COMMUNE_CODEPOSTAL=".$_POST['code_postal']);$comm_ligne = mysql_fetch_row($requete_comm);$_SESSION['observation']['commune_id'] = $comm_ligne[0];$_SESSION['observation']['commune'] = $comm_ligne[1];} else {$requete_comm = mysql_query("select COMMUNE_NOM from COMMUNE where COMMUNE_ID=".$_POST['commune']);$comm_ligne = mysql_fetch_row($requete_comm);$_SESSION['observation']['commune_id'] = $_POST['commune'];$_SESSION['observation']['commune'] = $comm_ligne[0];}*/// Jusqu'a ici// Recuperation identifiant station (il est unique)$station_choisie=$_GET['station_id'];if (isset($station_choisie)) { // choix d'une station pour ajout d'espece$requete_station = mysql_query("select STATION_NOM, STATION_ALTITUDE, STATION_ENVIRONNEMENT_ID, ENVIRONNEMENT_NOM from STATION,ENVIRONNEMENT where STATION.STATION_ENVIRONNEMENT_ID=ENVIRONNEMENT.ENVIRONNEMENT_ID AND STATION_ID=".$station_choisie);$comm_station = mysql_fetch_row($requete_station);$_SESSION['observation']['station_id'] = $station_choisie;$_SESSION['observation']['station'] = $comm_station[0];$_SESSION['observation']['altitude'] = $comm_station[1];$_SESSION['observation']['environnement_id'] = $comm_station[2];$_SESSION['observation']['environnement'] = $comm_station[3];$etape++; // passage à l'etape 2}else { //modification de station sans observation pour deplacement$requete_station = mysql_query("select STATION_NOM from STATION where STATION_ID=".$tableau_flippe['Modifier']);$comm_station = mysql_fetch_row($requete_station);$_SESSION['observation']['station_id'] = $tableau_flippe['Modifier'];$_SESSION['observation']['station'] = $comm_station[0];include("observations/modif_station.php");}// $_SESSION['observation']['commune'] = $comm_ligne[0];}} // etape 1if ($etape >1)echo "<div class='erreurs'>Pour revenir en arrière, n'utilisez pas le bouton \"précédent\" de votre navigateur, mais cliquez sur le nom à modifier.</div>";/*if ($etape==3) {if (isset($_POST['valid_alt'])) {if (strlen($_POST['altitude'])==0)$erreurs[] = $altitude_manquant;else if (!is_numeric(str_replace(",",".",$_POST['altitude'])))$erreurs[] = $altitude_invalide;}if (!isset($_POST['valid_alt']) || sizeof($erreurs)>0) {echo "<div class='recap'>";echo "Station d'observation : ".etape($_SESSION['observation']['station'],1)."<br>";echo "Environnement d'observation : ".etape($_SESSION['observation']['environnement'],2)."<br>";echo "</div><br>";include("observations/altitude.php");}else {$_SESSION['observation']['altitude'] = $_POST['altitude'];$etape++;}}*/if ($etape==2) {if (!isset($_POST['valid_typesp'])) {echo "<div class='recap'>";echo "Station d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['station']."</a><br>";echo "Environnement d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['environnement']."</a><br>";echo "Altitude d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['altitude']."</a><br>";echo "</div><br>";include("observations/type_espece.php");}else {$requete_comm = mysql_query("select CARACTERISTIQUE_ESP_VALEUR_LIB from CARACTERISTIQUE_ESP_VALEUR where CARACTERISTIQUE_ESP_VALEUR_ID=".$_POST['typespece']);$comm_ligne = mysql_fetch_row($requete_comm);$_SESSION['observation']['type_espece_id'] = $_POST['typespece'];$_SESSION['observation']['type_espece'] = $comm_ligne[0];$etape++;}}if ($etape==3) {if (isset($_POST['valid_espece'])) {//on vérifie qu'il n'y a pas déjà d'observations de ce participant sur la même espèce et la même la même année// $requete_verif = mysql_query("select SEQUENCE.SEQUENCE_ID FROM SEQUENCE,MESURE where COMMUNE_ID=".$_SESSION['observation']['commune_id']." and MESURE.SEQUENCE_ID=SEQUENCE.SEQUENCE_ID and SEQUENCE.PARTICIPANT_ID=".$_SESSION['participant']." and ESPECE_ID=".$_POST['espece']." and DATE_FORMAT(MESURE_DATE,'%Y')=DATE_FORMAT(NOW(),'%Y')");$annee = date('Y');$requete_verif = mysql_query("select distinct SEQUENCE.SEQUENCE_ID from SEQUENCE,MESURE "."where ESPECE_ID=".$_POST['espece']." and SEQUENCE.PARTICIPANT_ID=".$_SESSION['participant']." and MESURE.SEQUENCE_ID=SEQUENCE.SEQUENCE_ID"." and STATION_ID=".$_SESSION['observation']['station_id']." and MESURE.SEQUENCE_ID=SEQUENCE.SEQUENCE_ID"." AND MESURE_DATE!='0000-00-00' and MESURE_DATE>'".$annee."-$mois-01'"." and MESURE_DATE<'".($annee+1)."-$mois-01'");if ($obs_verif = mysql_fetch_row($requete_verif))$erreurs[] = $observation_existant;}if (!isset($_POST['valid_espece']) || sizeof($erreurs)>0) {echo "<div class='recap'>";echo "Station d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['station']."</a><br>";echo "Environnement d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['environnement']."</a><br>";echo "Altitude d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['altitude']."</a><br>";echo "Type d'espèce observé: ".etape($_SESSION['observation']['type_espece'],2)."<br>";echo "</div><br>";include("observations/espece.php");}else {$requete_comm = mysql_query("select ESPECE_NOM_VERNACULAIRE from ESPECE where ESPECE_ID=".$_POST['espece']);$comm_ligne = mysql_fetch_row($requete_comm);$_SESSION['observation']['espece_id'] = $_POST['espece'];$_SESSION['observation']['espece'] = $comm_ligne[0];$etape++;}}if ($etape==4) {if (isset($_POST['valid_saisie'])) {$evenements = $_POST['evenements'];/* foreach ($evenements as $numev => $individu) {echo "e".$numev;if (is_array($individu)) {foreach ($individu as $numind => $datev) {echo "i".$numind;}}}for ($i=0; $i<sizeof($evenements); $i++) {echo $evenements[$i];for ($j=0; $j<sizeof($evenements[$i]); $j++) {echo $evenements[$i][$j]."<br>";}/*foreach ($evenements[$i] as $n => $d)echo "$n -> $d";}exit();*/$nbCases = 0;$nbDatesNulles = 0;foreach ($evenements as $numind => $individu) {if (is_array($individu)) {$numev = 1;foreach ($individu as $indev => $datev) {if (is_numeric($indev)) {//soit on a une vraie date, soit on a un jjmmaaaaif (!estDate($datev[0],$datev[1],$datev[2]) && !estDateEnAttente($datev[0],$datev[1],$datev[2])) {/*if (!is_numeric($datev[0]) || strlen($datev[0])!=2)$erreurs[] = "Jour du ".$numev."e évènement inscrit : ".$jour_invalide;if (!is_numeric($datev[1]) || strlen($datev[1])!=2)$erreurs[] = "Mois du ".$numev."e évènement inscrit : ".$mois_invalide;if (!is_numeric($datev[2]) || strlen($datev[2])!=4)$erreurs[] = "Année du ".$numev."e évènement inscrit : ".$annee_invalide;*/$erreurs[] = "Le ".$numind."e évènement inscrit pour le ".$numev."e individu n'est pas une date valide.";} else if (estDateEnAttente($datev[0],$datev[1],$datev[2]))$nbsDatesNulles++;$numev++; $nbCases++;}}}}//echo $nbCases.",".$nbsDatesNulles;if ($nbCases == $nbsDatesNulles)$erreurs[] = "Il faut entrer au moins une date.";}if (!isset($_POST['valid_saisie']) || sizeof($erreurs)>0) {echo "<div class='recap'>";echo "Station d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['station']."</a><br>";echo "Environnement d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['environnement']."</a><br>";echo "Altitude d'observation : <a href=\"article.php3?id_article=2\">".$_SESSION['observation']['altitude']."</a><br>";echo "Type d'espèce observé: ".etape($_SESSION['observation']['type_espece'],2)."<br>";echo "Espèce observée: ".etape($_SESSION['observation']['espece'],3)."<br>";echo "</div><br>";include("observations/saisie.php");}else {$evenements = $_POST['evenements'];//on vérifie une ultime fois que la séquence n'a pas déjà été saisie// $requete_verif = mysql_query("select SEQUENCE.SEQUENCE_ID FROM SEQUENCE,MESURE where COMMUNE_ID=".$_SESSION['observation']['commune_id']." and MESURE.SEQUENCE_ID=SEQUENCE.SEQUENCE_ID and SEQUENCE.PARTICIPANT_ID=".$_SESSION['participant']." and ESPECE_ID=".$_SESSION['observation']['espece_id']." and DATE_FORMAT(MESURE_DATE,'%Y')=DATE_FORMAT(NOW(),'%Y')");//$requete_verif = mysql_query("select SEQUENCE_ID from SEQUENCE where ESPECE_ID=".$_SESSION['observation']['espece_id'].$annee = date('Y');$requete_verif = mysql_query("select distinct SEQUENCE.SEQUENCE_ID from SEQUENCE,MESURE "."where ESPECE_ID=".$_SESSION['observation']['espece_id']." and SEQUENCE.PARTICIPANT_ID=".$_SESSION['participant']." and MESURE.SEQUENCE_ID=SEQUENCE.SEQUENCE_ID"." and STATION_ID=".$_SESSION['observation']['station_id']." and MESURE.SEQUENCE_ID=SEQUENCE.SEQUENCE_ID"." AND MESURE_DATE!='0000-00-00' and MESURE_DATE>='$annee-01-01'"." and MESURE_DATE<'".($annee+1)."-01-01'");//" and COMMUNE_ID=".$_SESSION['observation']['commune_id'].//" and PARTICIPANT_ID=".$_SESSION['participant']);if ($verif = mysql_fetch_row($requete_verif)) {$erreurs[] = "$observation_existant";}//c'est bon, cette séquence n'a pas encore été introduiteelse {$requete_seq = mysql_query("insert into SEQUENCE (ESPECE_ID, STATION_ID, ENVIRONNEMENT_ID, PARTICIPANT_ID, SEQUENCE_ALTITUDE) values (".$_SESSION['observation']['espece_id'].",".$_SESSION['observation']['station_id'].",".$_SESSION['observation']['environnement_id'].",".$_SESSION['participant'].", ".str_replace(",",".",$_SESSION['observation']['altitude']).")");//on récupère l'identifiant de la séquence qui vient d'être introduite$requete_idseq = mysql_query("select SEQUENCE_ID from SEQUENCE where ESPECE_ID=".$_SESSION['observation']['espece_id']." and STATION_ID=".$_SESSION['observation']['station_id']." and PARTICIPANT_ID=".$_SESSION['participant']);$idseq_ligne = mysql_fetch_row($requete_idseq);if ($idseq_ligne)$idseq = $idseq_ligne[0];foreach ($evenements as $numind => $individu) {if (is_array($individu)) {foreach ($individu as $numev => $datev) {if (is_numeric($numev) && !estDateEnAttente($datev[0],$datev[1],$datev[2])) {if (!mysql_query("insert into MESURE (SEQUENCE_ID, EVENEMENT_ID, MESURE_DATE, MESURE_INDIVIDU) values ($idseq, $numind, '".$datev[2]."-".$datev[1]."-".$datev[0]."',($numev+1))"))$erreurs[] = "La prise en compte de vos observations a échoué, merci de réessayer.";}}}}}if (sizeof($erreurs)==0) {$_SESSION['obsOK'] = 'ok';redirect("article.php3?id_article=2");//header("Location: article.php3?id_article=3");}// echo "Tes dates d'observation ont bien été prises en compte.";else {foreach($erreurs as $err)echo $err."<br>";}}}}?>