<?
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
// +------------------------------------------------------------------------------------------------------+
// | PHP version 4.1                                                                                      |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
// +------------------------------------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or                                        |
// | modify it under the terms of the GNU Lesser General Public                                           |
// | License as published by the Free Software Foundation; either                                         |
// | version 2.1 of the License, or (at your option) any later version.                                   |
// |                                                                                                      |
// | This library is distributed in the hope that it will be useful,                                      |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
// | Lesser General Public License for more details.                                                      |
// |                                                                                                      |
// | You should have received a copy of the GNU Lesser General Public                                     |
// | License along with this library; if not, write to the Free Software                                  |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id$
/**
* Titre
*
* Description
*
*@package nom_du_paquetage
*@subpackage nom_du_sous-paquetage_si_necessaire
//Auteur original :
*@author        linda ANGAMA<linda_angama@yahoo.fr>
//Autres auteurs :
*@author        Aucun
*@copyright     Tela-Botanica 2000-2004
*@version       $Revision$ $Date$
// +------------------------------------------------------------------------------------------------------+
*/
function SQL_obtenirNouveauId($db, $table, $colonne_identifiant){
    $requete = 'SELECT MAX('.$colonne_identifiant.') AS maxi FROM '.$table;
    $resultat = $db->query($requete);
    if (DB::isError($resultat) || $resultat->numRows() > 1) {
        return false;
    }
    $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT);
    return $ligne->maxi + 1;
}

function construireArray($id){
    $req_img='select * from eflore_info_image, eflore_info_txt_a_taxon, eflore_inventaire_observation, eflore_licence, eflore_personne_contributeur';
    $req_img.=' LEFT JOIN eflore_projet ON eio_autre_flore like epr_abreviation_projet';
    $req_img.=' where eii_id_image=eitat_id_taxon_ref and eii_id_version_projet_img=eitat_id_version_projet_taxon_ref and eio_ce_image=eii_id_image';
    $req_img.=' and eii_id_version_projet_img=eio_ce_version_projet_img and eii_ce_licence_img=eli_id_licence and eitat_id_texte='.N_TAXON;
    $req_img.=' and eitat_id_version_projet_txt='.N_VERSION_PROJET_TAXON.' and epc_id_contributeur=eii_ce_contributeur_image';
    $req_img.=' and eii_id_image='.$id;
    $resultat_img=$GLOBALS['db_eflore']->query($req_img);
        (DB::isError($resultat_img)) ?
            die (BOG_afficherErreurSql(__FILE__, __LINE__, 'img:'.$resultat_img->getMessage(), $req_img)) : '' ;
    $ligne=& $resultat_img->fetchRow(DB_FETCHMODE_ASSOC);
    $a=array('EN_ID_NOM' =>NULL,'EIO_AUTRE_FLORE' => -1,'autre_flore'=>NULL, 'EII_AUTEUR_IMG' =>NULL,
            'EIO_AUTRE_AUTEUR_DETERMINATION' => NULL, 'NATURE' => -1, 'EIS_LIEUDIT' =>'', 'UPLOADED_FILE' => NULL, 'EII_LIEN_VERS_IMG' => 'http://', 'FICHIER_IMAGE' => '',
            'SUJET' => -1, 'DEVELOPPEMENT' => -1, 'EII_DESCRIPTION_IMG' =>'');

    $a['EIO_DATE_OBSERVATION']['date_1']['d']=0;
    $a['EIO_DATE_OBSERVATION']['date_1']['F']=0;
    $a['EIO_DATE_OBSERVATION']['AN']='';
    if ($ligne['eio_ce_autre_nom_latin']!=0){
        $a['EN_ID_NOM']=$ligne['eio_ce_autre_nom_latin'];
        $req_flo='select * from eflore_projet where epr_abreviation_projet like \''.$ligne['eio_autre_flore'].'\'';
        $resultat_flo=$GLOBALS['db_eflore']->query($req_flo);
        (DB::isError($resultat_flo)) ?
            die (BOG_afficherErreurSql(__FILE__, __LINE__, 'flore:'.$resultat_flo->getMessage(), $req_flo)) : '' ;
        $autre_flore='';
        if ($resultat_flo->numRows()==0){
            $a['EIO_AUTRE_FLORE'] = -1;
            $a['autre_flore'] = $ligne['eio_autre_flore'];
        }
        else {
            $a['EIO_AUTRE_FLORE'] = $ligne['epr_id_projet'];
        }
    }
    else {
        $a['EN_ID_NOM']=selectNom();
    }

    if ($ligne['eii_lien_vers_img']==EFLORE_CHEMIN_IMG_PLTE){
        $a['FICHIER_IMAGE']=$ligne['eii_nom_fichier_img'];
    }
    else {
        $a['FICHIER_IMAGE']=$ligne['eii_lien_vers_img'].$ligne['eii_nom_fichier_img'];
    }

    if ($ligne['eii_auteur_img']==$ligne['epc_nom_principal']){
        $a['EII_AUTEUR_IMG']='';
    }
    else {
        $a['EII_AUTEUR_IMG']=$ligne['eii_auteur_img'];
    }
    if ($ligne['eio_ce_contributeur']==0){
        $a['EIO_AUTRE_AUTEUR_DETERMINATION']=$ligne['eio_autre_auteur_determination'];
    }
    $a['EIS_LIEUDIT']='aaaa';
    $a['EIO_DATE_OBSERVATION']['date_1']['d']=substr($ligne['eio_date_observation'],8,2);
    $a['EIO_DATE_OBSERVATION']['date_1']['F']=substr($ligne['eio_date_observation'],5,2);
    $a['EIO_DATE_OBSERVATION']['AN']=substr($ligne['eio_date_observation'],0,4);
    switch ($ligne['eli_id_licence']) {
        case 1 :
            $a['LICENCE']['EII_CE_LICENCE_IMG_AUCUN']=true;
            break;
        case 2 :
            $a['LICENCE']['EII_CE_LICENCE_IMG_COM']=true;
            break;
        case 4 :
            $a['LICENCE']['EII_CE_LICENCE_IMG_MOD']=true;
            break;
        case 6 :
            $a['LICENCE']['EII_CE_LICENCE_IMG_COM']=true;
            $a['LICENCE']['EII_CE_LICENCE_IMG_MOD']=true;
            break;
    }
    $ligne['eii_description_courte_img']==NULL ? $a['EII_DESCRIPTION_IMG']=$ligne['eii_description_longue_img']
                                                : $a['EII_DESCRIPTION_IMG']=$ligne['eii_description_courte_img'];
    $req_cat=REQ_CAT.', eflore_info_image_posseder_valeur where eiipv_id_valeur_categorie_img=eiiv_id_valeur_categorie_img
                        and eiipv_id_image='.$_GET['id'];
    $resultat_cat=$GLOBALS['db_eflore']->query($req_cat);
        (DB::isError($resultat_cat)) ?
            die (BOG_afficherErreurSql(__FILE__, __LINE__, 'cat:'.$resultat_cat->getMessage(), $req_cat)) : '' ;
    while ($ligne_cat=& $resultat_cat->fetchRow(DB_FETCHMODE_ASSOC)) {
        switch ($ligne_cat['eiiv_ce_categorie_img']) {
            case 1 :
                $a['NATURE']=$ligne_cat['eiiv_id_valeur_categorie_img'];
                break;
            case 2 :
                $a['DEVELOPPEMENT']=$ligne_cat['eiiv_id_valeur_categorie_img'];
                break;
            case 3 :
                $a['SUJET']=$ligne_cat['eiiv_id_valeur_categorie_img'];
                break;
            default :
                break;
        }
    }
    return ($a);
}

function construireForm(&$form,&$tab_index,$default_value_array,$param=NULL){
$squelette =& $form->defaultRenderer();
$squelette->setFormTemplate("\n".'<form{attributes}>'."\n".'{content}'."\n".'</form>'."\n");
$squelette->setElementTemplate( '<li>'."\n".'{label}'."\n".'{element}'."\n".
                                '<!-- BEGIN required --><span class="symbole_obligatoire">*</span><!-- END required -->'."\n".
                                '<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'."\n".
                                '</li>'."\n");
$squelette->setRequiredNoteTemplate("\n".'<p>'."\n".'<span class="symbole_obligatoire">*</span> {requiredNote}'."\n".'</p>'."\n");
$squelette->setGroupElementTemplate("\n".'<br /><span class="groupe_label">{label}{element}</span>','LICENCE');
$form->setJsWarnings(SAISIE_INCORRECTE,CORRIGER);

    $fieldset_fin ='      </ul>'."\n";
    $fieldset_fin.='    </fieldset><br>'."\n";

        //informations sur la dénomination
        $fieldset_nom_deb='    <fieldset id="denomination">'."\n";
        $fieldset_nom_deb.='      <legend>'.DENOMINATION.'</legend>'."\n";
        $fieldset_nom_deb.='      <ul class="liste">'."\n";
        $form->addElement('html',$fieldset_nom_deb);

            $id='EN_ID_NOM';
            $label='<label for="'.$id.'">'.EN_ID_NOM.'</label>';
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++);
            $req='select *';
            $req.=' from eflore_selection_nom , eflore_nom ';
            $req.=' LEFT JOIN eflore_botaniste_intitule_abreviation ON en_ce_auteur_basio= ebia_id_intitule_botaniste_abrege';
            $req.=' where esn_id_taxon='.N_TAXON;
            $req.=' and esn_id_version_projet_taxon='.N_VERSION_PROJET_TAXON;
            $req.=' and esn_id_nom=en_id_nom';
            $resultat=$GLOBALS['db_eflore']->query($req);
            $tab=array();
            while ($ligne =& $resultat->fetchRow(DB_FETCHMODE_ASSOC)){
                $tab[$ligne['en_id_nom']]=$ligne['en_nom_genre'].' '.$ligne['en_epithete_espece'].' '.$ligne['ebia_intitule_botaniste_abrege'];
            }
            $form->addElement('select',$id,$label,$tab,$asso_array);

            $id='EIO_AUTRE_FLORE';
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++);
            $label='<label for="'.$id.'">'.EIO_AUTRE_FLORE.'</label>';
            $resultat=$GLOBALS['db_eflore']->query(REQ_EIO_AUTRE_FLORE);
            $tab=array();
            while ($ligne =& $resultat->fetchRow(DB_FETCHMODE_ASSOC)){
                $tab[$ligne['epr_id_projet']]=$ligne['epr_abreviation_projet'];
            }
            $flore=& $form->createElement('select',$id,$label,$tab,$asso_array);
            $flore->addOption('&nbsp;',-1);
            //$flore->setValue(-1);
            
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++, 'size'=>30);
            $autre_flore=& $form->createElement('text','autre_flore',$asso_array);
            
            $group_array=array($flore,$autre_flore);
            $form->addElement('group','group_0',$label,$group_array,' Autre ',false);

        $form->addElement('html',$fieldset_fin);


        //photo sur le serveur central ou sur un serveur partenaire
        $fieldset_loc_deb='    <fieldset id="stockage">'."\n";
        $fieldset_loc_deb.='      <legend>'.LOCALISATION.'</legend>'."\n";
        $fieldset_loc_deb.='      <ul class="liste">'."\n";
        $form->addElement('html',$fieldset_loc_deb);
        if ($param==1){
            $id='FICHIER_IMAGE';
            $label='<label for="'.$id.'">Nom du fichier image :</label>';
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++, 'size' =>50);
            $form->addElement('text', $id, $label, $asso_array);
        }
            $id='loc';
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++,
                                'onclick'=>'javascript:
                                this.form.EII_LIEN_VERS_IMG.disabled=1;
                                this.form.UPLOADED_FILE.disabled=0'
                                );
            $label='';
            $radio1= & $form->createElement('radio',$id,$label,RADIO_1,0,$asso_array);
                
            $id1='UPLOADED_FILE';
            $asso_array1 =array('class'=> $id1, 'tabindex' => $tab_index++);
            $fic_trans=& $form->createElement('file',$id1,'',$asso_array1);
            $group_array_1=array($radio1,$fic_trans);
            $form->addElement('group','group_1','',$group_array_1,' ',false);

            
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++,
                                'onclick'=>'javascript:
                                this.form.EII_LIEN_VERS_IMG.disabled=0;
                                this.form.UPLOADED_FILE.disabled=1');
            $label='';
            $radio2= & $form->createElement('radio',$id,$label,RADIO_2,1,$asso_array);
            $form->addElement($radio2);
        
            $id2='EII_LIEN_VERS_IMG';
            $asso_array2 =array('class'=> $id2, 'tabindex' => $tab_index++, 'size' =>67);
            $path_fic= & $form->createElement('text', $id2, '', $asso_array2);
            $form->addElement($path_fic);
            $form->addElement('html','<script type="text/javascript">'."\n".'<!--/*--><![CDATA[//><!--'."\n".'cacherLien()'.'//--><!]]>'."\n".'</script>');
        
        $form->addElement('html',$fieldset_fin);


            
        //informations sur la prise de vue et autres champs obligatoires
        $fieldset_pdv_deb='    <fieldset id="infos">'."\n";
        $fieldset_pdv_deb.='      <legend>'.INFO.'</legend>'."\n";
        $fieldset_pdv_deb.='      <ul class="liste">'."\n";
        $form->addElement('html',$fieldset_pdv_deb);
            
            $id='EII_CE_CONTRIBUTEUR';
            $label='<label for="'.$id.'">'.EII_CE_CONTRIBUTEUR.'</label>';
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++);
            $auteur=& $form->createElement('text',$id,$label,$asso_array);
            $auteur->setValue(CONTRIBUTEUR);
            $form->addElement($auteur);
            $form->addElement('html','<span class="eflore_libelle">'.LIB_EII_AUTEUR_IMG.'</span>');
            $id='EII_AUTEUR_IMG';
            $label='<label for="'.$id.'">'.EII_AUTEUR_IMG.'</label>';
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++, 'size'=>50);
            $auteur_img=& $form->createElement('text',$id,$label,$asso_array);
            $form->addElement($auteur_img);
            
            $form->addElement('html','<span class="eflore_libelle">'.LIB_EIO_AUTRE_AUTEUR_DETERMINATION.'</span>');
            $id='EIO_AUTRE_AUTEUR_DETERMINATION';
            $label='<label for="'.$id.'">'.EIO_AUTRE_AUTEUR_DETERMINATION.'</label>';
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++, 'size'=>50);
            $auteur_det=& $form->createElement('text',$id,$label,$asso_array);
            $form->addElement($auteur_det);

            $id='NATURE';
            $label='<label for="'.$id.'">'.NATURE.'</label>';
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++);
            $resultat=$GLOBALS['db_eflore']->query(REQ_NATURE);
            $tab=array();
            while ($ligne =& $resultat->fetchRow(DB_FETCHMODE_ASSOC)){
                $tab[$ligne['eiiv_id_valeur_categorie_img']]=$ligne['eiiv_intitule_valeur_categorie_img'];
            }
            $nature=& $form->createElement('select',$id,$label,$tab,$asso_array);
            $nature->addOption('&nbsp;',-1);
            $form->addElement($nature);

            $id='EIS_LIEUDIT';
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++, 'size' =>26);
            $label='<label for="'.$id.'">'.EIS_LIEUDIT.'</label>';
            $form->addElement('text',$id,$label,$asso_array);
            
            $option=array('language'=>EFLORE_LANGUE, 'format' => 'dF', 'addEmptyOption' => true, 'emptyOptionValue' => 0);
            $groupe_date= & $form->createElement('date','date_1','',$option);
            
            $id='AN';
            $asso_array=array('class'=> $id, 'tabindex' => $tab_index++, 'size' =>4);
            $annee=& $form->createElement('text',$id,'',$asso_array);
            
            $id='EIO_DATE_OBSERVATION';
            $label='<label for="'.$id.'">'.EIO_DATE_OBSERVATION.'</label>';
            $group_date_array=array($groupe_date,$annee);
            $form->addElement('group',$id,$label,$group_date_array,'');

            
            $id='EII_CE_LICENCE_IMG_COM';
            $label='<label for="'.$id.'">'.EII_CE_LICENCE_IMG_COM.'</label>';
            $asso_array=array('class'=> $id, 'tabindex' => $tab_index++, 'onclick' =>'afficherLicence(this.form);');
            $licence_com=& $form->createElement('checkbox', $id,$label,'',$asso_array);
            
            $id='EII_CE_LICENCE_IMG_MOD';
            $label='<label for="'.$id.'">'.EII_CE_LICENCE_IMG_MOD.'</label>';
            $asso_array=array('class'=> $id, 'tabindex' => $tab_index++, 'onclick' =>'afficherLicence(this.form);');
            $licence_mod=& $form->createElement('checkbox', $id,$label,'',$asso_array);
            
            $id='EII_CE_LICENCE_IMG_AUCUN';
            $label='<label for="'.$id.'">'.EII_CE_LICENCE_IMG_AUCUN.'</label>';
            $asso_array=array('class'=> $id, 'tabindex' => $tab_index++, 'onclick' =>'afficherLicence(this.form);');
            $licence_auc=& $form->createElement('checkbox', $id,$label,'',$asso_array);
            
            $id='LICENCE';
            $label='<label for="'.$id.'">'.LIB_LICENCE.'</label>';
            $group_lic_array=array($licence_com,$licence_mod,$licence_auc);
            $form->addElement('group',$id,$label,$group_lic_array,'');
            
            $req='select * from eflore_licence';
            $resultat=$GLOBALS['db_eflore']->query($req);
            $tab=array();
            while ($ligne=& $resultat->fetchRow(DB_FETCHMODE_ASSOC)){
                $tab[$ligne['eli_id_licence']]=$ligne['eli_description_licence'];
            }
            $id='LIC_1';
            $lic_1='<p id="'.$id.'">'.LICENCE_CHOIX_1.'<br />'.$tab[6].'</p>';
            $id='LIC_2';
            $lic_1.='<p id="'.$id.'">'.LICENCE_CHOIX_2.'<br />'.$tab[2].'</p>';
            $id='LIC_3';
            $lic_1.='<p id="'.$id.'">'.LICENCE_CHOIX_3.'<br />'.$tab[4].'</p>';
            $id='LIC_4';
            $lic_1.='<p id="'.$id.'">'.LICENCE_CHOIX_4.'<br />'.$tab[1].'</p>';
            $form->addElement('html',$lic_1);
            $form->addElement('html','<script type="text/javascript">'."\n".'<!--/*--><![CDATA[//><!--'."\n".'cacherLicence();'.'//--><!]]>'."\n".'</script>');
            
            
            
            //Contenu de l'illustration
            $id='SUJET';
            $label='<label for="'.$id.'">'.SUJET.'</label>';
            $resultat=$GLOBALS['db_eflore']->query(REQ_SUJET);
            $tab=array();
            while ($ligne =& $resultat->fetchRow(DB_FETCHMODE_ASSOC)){
                $tab[$ligne['eiiv_id_valeur_categorie_img']]=$ligne['eiiv_intitule_valeur_categorie_img'];
            }
            $select_cont=& $form->createElement('select',$id,$label,$tab);
            $select_cont->addOption('&nbsp;',-1);
            $form->addElement($select_cont);
            
            //stade de développement
            $id='DEVELOPPEMENT';
            $label='<label for="'.$id.'">'.DEVELOPPEMENT.'</label>';
            $resultat=$GLOBALS['db_eflore']->query(REQ_DEVELOPPEMENT);
            $tab=array();
            while ($ligne =& $resultat->fetchRow(DB_FETCHMODE_ASSOC)){
                $tab[$ligne['eiiv_id_valeur_categorie_img']]=$ligne['eiiv_intitule_valeur_categorie_img'];
            }
            $devpt=& $form->createElement('select',$id,$label,$tab);
            $devpt->addOption('&nbsp;',-1);
            $form->addElement($devpt);
            
            $id='EII_DESCRIPTION_IMG';
            $asso_array =array('class'=> $id, 'tabindex' => $tab_index++, 'rows'=>7, 'cols'=>45, 'wrap' => 'off');
            $label='<label for="'.$id.'">'.EII_DESCRIPTION_IMG.'</label>';
            $form->addElement('textarea',$id,$label,$asso_array);
            $form->addElement('html',$fieldset_fin);
        $form->addElement('html',$fieldset_fin);
        $form->setConstants($default_value_array);
}

function insertionImg(){
    $id_photo=SQL_obtenirNouveauId($GLOBALS['db_eflore'], 'eflore_info_image', 'eii_id_image');
    isset($_POST['EIO_AUTRE_FLORE'])        ? '' : $_POST['EIO_AUTRE_FLORE']        = NULL;
    $file='';
    $dir='';
    $insert='';
    dirFile($dir,$file);
    $insert1='insert into eflore_info_image (eii_id_image, eii_id_version_projet_img, eii_ce_contributeur_image, eii_ce_citation_biblio,
                                        eii_ce_licence_img, eii_lien_vers_img, eii_nom_fichier_img, eii_auteur_img, eii_date_ajout_img)';
    $insert1.=' values ('.$id_photo.',2,'.CONTRIBUTEUR.',0,'.validLicence().',\''.$dir.'\',\''.$file.'\',\''.auteurImg().'\',\''.date('Y-m-d').'\')';
    $insert.=$insert1;
    
    $insert2='';
    if (isset($_POST['EII_DESCRIPTION_IMG'])){
        if (strlen($_POST['EII_DESCRIPTION_IMG'])<=255 && $_POST['EII_DESCRIPTION_IMG']!=''){
            $insert2='update eflore_info_image set eii_description_courte_img=\''.$_POST['EII_DESCRIPTION_IMG'].'\' where eii_id_image='.$id_photo;
        }
        elseif($_POST['EII_DESCRIPTION_IMG']>255){
            $insert2='update eflore_info_image set eii_description_longue_img=\''.$_POST['EII_DESCRIPTION_IMG'].'\' where eii_id_image='.$id_photo;
        }
    }

    $insert3='insert into eflore_info_txt_a_taxon (eitat_id_texte,eitat_id_version_projet_txt,eitat_id_taxon_ref,eitat_id_version_projet_taxon_ref)';
    $insert3.=' values ('.N_TAXON.','.N_VERSION_PROJET_TAXON.','.$id_photo.',2)';
    
    $insert4='insert into eflore_inventaire_observation (eio_id_observation, eio_id_version_projet_inventaire, eio_ce_image, eio_ce_version_projet_img,
                                                        eio_ce_taxon_ref, eio_ce_version_projet_taxon_ref, eio_ce_autre_nom_latin, eio_autre_flore,
                                                        eio_ce_station, eio_date_observation)';
    $id_observation=SQL_obtenirNouveauId($GLOBALS['db_eflore'], 'eflore_inventaire_observation', 'eio_id_observation');
    $autre_nom_latin='';
    if ($_POST['EN_ID_NOM']==selectNom()){$autre_nom_latin=0;}
    else {$autre_nom_latin=$_POST['EN_ID_NOM'];}
    
    $aut_flore=NULL;
    if (($autre_nom_latin!=0) && $_POST['EIO_AUTRE_FLORE']==-1){
        $aut_flore=$_POST['autre_flore'];
    }
    elseif ($autre_nom_latin!=0){
        $req='select * from eflore_projet where epr_id_projet='.$_POST['EIO_AUTRE_FLORE'];
        $resultat=$GLOBALS['db_eflore']->query($req);
        $ligne=& $resultat->fetchRow(DB_FETCHMODE_ASSOC);
        $aut_flore=$ligne['epr_abreviation_projet'];
    }
    $insert4.=' values ('.$id_observation.',2,'.$id_photo.',2,'.N_TAXON.','.N_VERSION_PROJET_TAXON.','.$autre_nom_latin.
                        ',\''.$aut_flore.'\',0,\''
                        .$_POST['EIO_DATE_OBSERVATION']['AN'].'-'.$_POST['EIO_DATE_OBSERVATION']['date_1']['F'].'-'.$_POST['EIO_DATE_OBSERVATION']['date_1']['d'].'\')';
    
    $autre_det='';
    if($_POST['EIO_AUTRE_AUTEUR_DETERMINATION']!=''){
        $insert5='update eflore_inventaire_observation set eio_autre_auteur_determination=\''.$_POST['EIO_AUTRE_AUTEUR_DETERMINATION'].'\' where eio_id_observation='.$id_observation;
    }
    else{
        $insert5='update eflore_inventaire_observation set eio_ce_contributeur='.$_POST['EII_CE_CONTRIBUTEUR'].' where eio_id_observation='.$id_observation;
    }
    
    $resultat=$GLOBALS['db_eflore']->query($insert1);
    (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, 'Insertion 1 :'.$resultat->getMessage(), $insert1)) : '' ;
    if ($insert2!=''){
        $resultat=$GLOBALS['db_eflore']->query($insert2);
        (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, 'Insertion 2 :'.$resultat->getMessage(), $insert2)) : '' ;
    }
    
    $resultat=$GLOBALS['db_eflore']->query($insert3);
    (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, 'Insertion 3 :'.$resultat->getMessage(), $insert3)) : '' ;
    $resultat=$GLOBALS['db_eflore']->query($insert4);
    (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, 'Insertion 4 :'.$resultat->getMessage(), $insert4)) : '' ;
    $resultat=$GLOBALS['db_eflore']->query($insert5);
    (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, 'Insertion 5 :'.$resultat->getMessage(), $insert5)) : '' ;
    
    $cat=$_POST['NATURE'];
    $insert6='insert into eflore_info_image_posseder_valeur values ('.$cat.','.$id_photo.',2)';
    $resultat=$GLOBALS['db_eflore']->query($insert6);
    (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, 'Insertion 6 :'.$resultat->getMessage(), $insert6)) : '' ;
    
    if ($_POST['SUJET']!=-1){
        $cat=$_POST['SUJET'];
        $insert6='insert into eflore_info_image_posseder_valeur values ('.$cat.','.$id_photo.',2)';
        $resultat=$GLOBALS['db_eflore']->query($insert6);
        (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, 'Insertion 6 :'.$resultat->getMessage(), $insert6)) : '' ;
    }
    
    if ($_POST['DEVELOPPEMENT']!=-1){
        $cat=$_POST['DEVELOPPEMENT'];
        $insert6='insert into eflore_info_image_posseder_valeur values ('.$cat.','.$id_photo.',2)';
        $resultat=$GLOBALS['db_eflore']->query($insert6);
        (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, 'Insertion 6 :'.$resultat->getMessage(), $insert6)) : '' ;
    }
    if ($_POST['loc']==0){
    $poids=intval(filesize(EFLORE_CHEMIN_IMG_PLTE.$id_photo.'.jpg')/1024);
            list($long,$larg,$type,$attr)=getimagesize(EFLORE_CHEMIN_IMG_PLTE.$id_photo.'.jpg');
            $req='update eflore_info_image set eii_poids_img='.$poids.', eii_long_img='.$long.', eii_larg_img='.$larg;
            $req.=' where eii_id_image='.$id_photo;
            $resultat=$GLOBALS['db_eflore']->query($req);
            (DB::isError($resultat)) ?
                die (BOG_afficherErreurSql(__FILE__, __LINE__, 'copyFile:'.$resultat->getMessage(), $req)) : '' ;
    }
}

function majImage($id, $nbre_update, $trans_fic){
    $a=construireArray($id);
    $nbre_update=0;
    $update1='';
    $test_lic_com=false;
    $test_lic_mod=false;
    $test_lic_aucun=false;
    if (isset($a['LICENCE']['EII_CE_LICENCE_IMG_COM']) && !isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_COM'])){
        $test_lic_com=true;
    }
    if (isset($a['LICENCE']['EII_CE_LICENCE_IMG_MOD']) && !isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_MOD'])){
        $test_lic_mod=true;
    }
    if (isset($a['LICENCE']['EII_CE_LICENCE_IMG_AUCUN']) && !isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_AUCUN'])){
        $test_lic_aucun=true;
    }
    if ($a['EII_AUTEUR_IMG']!=$_POST['EII_AUTEUR_IMG']|| $test_lic_com || $test_lic_mod || $test_lic_aucun){
        $update1='update eflore_info_image set eii_ce_licence_img='.validLicence().', eii_auteur_img=\''.auteurImg().'\', eii_date_ajout_img=\''
        .date('Y-m-d').'\' where eii_id_image='.$id;
        $resultat=$GLOBALS['db_eflore']->query($update1);
        (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, 'update 1 :'.$resultat->getMessage(), $update1)) : '' ;
        $nbre_update++;
    }
    $update1b='';
    if (verifSelection0() && verifSelection1() && copyFile($id)){
        $dir='';
        $file='';
        dirFile($dir,$file);
        $update1b='update eflore_info_image set eii_lien_vers_img=\''.$dir.'\', eii_nom_fichier_img=\''.$file.'\' where eii_id_image='.$id;
        $resultat=$GLOBALS['db_eflore']->query($update1b);
        (DB::isError($resultat)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, 'update 1b :'.$resultat->getMessage(), $update1b)) : '' ;
        $nbre_update++;
        $trans_fic=true;
        if ($_POST['loc']==0){
            $poids=intval(filesize(EFLORE_CHEMIN_IMG_PLTE.$id.'.jpg')/1024);
            list($long,$larg,$type,$attr)=getimagesize(EFLORE_CHEMIN_IMG_PLTE.$id.'.jpg');
            $req='update eflore_info_image set eii_poids_img='.$poids.', eii_long_img='.$long.', eii_larg_img='.$larg;
            $req.=' where eii_id_image='.$id;
            $resultat=$GLOBALS['db_eflore']->query($req);
            (DB::isError($resultat)) ?
                die (BOG_afficherErreurSql(__FILE__, __LINE__, 'copyFile:'.$resultat->getMessage(), $req)) : '' ;
        }
    }
    elseif (verifSelection0() && verifSelection1() && !copyFile($id)){
        $trans_fic=false;
    }
    $update1t='';
    if ($a['EII_DESCRIPTION_IMG']!=$_POST['EII_DESCRIPTION_IMG']){
        if ($_POST['EII_DESCRIPTION_IMG']!=''){
            if (strlen($_POST['EII_DESCRIPTION_IMG'])<=255 && $_POST['EII_DESCRIPTION_IMG']!=''){
                $update1t='update eflore_info_image set eii_description_courte_img=\''.$_POST['EII_DESCRIPTION_IMG'].'\' where eii_id_image='.$id;
                $resultat=$GLOBALS['db_eflore']->query($update1t);
                (DB::isError($resultat)) ?
                         die (BOG_afficherErreurSql(__FILE__, __LINE__, 'update 1t :'.$resultat->getMessage(), $update1t)) : '' ;
                $nbre_update++;
            }
            elseif($_POST['EII_DESCRIPTION_IMG']>255){
                $update1t='update eflore_info_image set eii_description_longue_img=\''.$_POST['EII_DESCRIPTION_IMG'].'\' where eii_id_image='.$id;
                $nbre_update++;
            }
        }
        else{
            $update1t='update eflore_info_image set eii_description_courte_img=NULL, eii_description_longue_img=NULL where eii_id_image='.$id;
            $resultat=$GLOBALS['db_eflore']->query($update1t);
                (DB::isError($resultat)) ?
                         die (BOG_afficherErreurSql(__FILE__, __LINE__, 'update 1t :'.$resultat->getMessage(), $update1t)) : '' ;
            $nbre_update++;
        }
    }
    $update2='';
    if ($a['EN_ID_NOM']!=$_POST['EN_ID_NOM'] || $a['EIO_AUTRE_FLORE']!=$_POST['EIO_AUTRE_FLORE'] || $a['autre_flore']!=$_POST['autre_flore']){
        $autre_nom_latin='';
        if ($_POST['EN_ID_NOM']==selectNom()){$autre_nom_latin=0;}
        else {$autre_nom_latin=$_POST['EN_ID_NOM'];}
        $aut_flore=NULL;
        if (($autre_nom_latin!=0) && $_POST['EIO_AUTRE_FLORE']==-1){
            $aut_flore=$_POST['autre_flore'];
        }
        elseif ($autre_nom_latin!=0){
            $req='select * from eflore_projet where epr_id_projet='.$_POST['EIO_AUTRE_FLORE'];
            $resultat=$GLOBALS['db_eflore']->query($req);
            $ligne=& $resultat->fetchRow(DB_FETCHMODE_ASSOC);
            $aut_flore=$ligne['epr_abreviation_projet'];
        }
        $update2='update eflore_inventaire_observation set eio_ce_autre_nom_latin=\''.$autre_nom_latin.'\', eio_autre_flore=\''.$aut_flore.'\' where eio_ce_image='.$id;
        $resultat=$GLOBALS['db_eflore']->query($update2);
                (DB::isError($resultat)) ?
                         die (BOG_afficherErreurSql(__FILE__, __LINE__, 'update 2 :'.$resultat->getMessage(), $update2)) : '' ;
        $nbre_update++;
    }
    $update2b='';
    if ($a['EIO_AUTRE_AUTEUR_DETERMINATION']!=$_POST['EIO_AUTRE_AUTEUR_DETERMINATION']){
        if($_POST['EIO_AUTRE_AUTEUR_DETERMINATION']!=''){
            $update2b='update eflore_inventaire_observation set eio_autre_auteur_determination=\''.$_POST['EIO_AUTRE_AUTEUR_DETERMINATION'].'\',
             eio_ce_contributeur=0 where eio_ce_image='.$id;
            $resultat=$GLOBALS['db_eflore']->query($update2b);
            (DB::isError($resultat)) ?
                die (BOG_afficherErreurSql(__FILE__, __LINE__, 'update 2b :'.$resultat->getMessage(), $update2b)) : '' ;
            $nbre_update++;
        }
        else{
            $update2b='update eflore_inventaire_observation set eio_ce_contributeur='.$_POST['EII_CE_CONTRIBUTEUR'].' ,
            eio_autre_auteur_determination=NULL where eio_ce_image='.$id;
            $resultat=$GLOBALS['db_eflore']->query($update2b);
            (DB::isError($resultat)) ?
                die (BOG_afficherErreurSql(__FILE__, __LINE__, 'update 2b :'.$resultat->getMessage(), $update2b)) : '' ;
            $nbre_update++;
        }
    }
    //if ($a['EIS_LIEUDIT']!=$_POST['EIS_LIEUDIT'])
    $update2t='';
    if ((int)$a['EIO_DATE_OBSERVATION']['date_1']['d']!=$_POST['EIO_DATE_OBSERVATION']['date_1']['d'] ||
        (int)$a['EIO_DATE_OBSERVATION']['date_1']['F']!=$_POST['EIO_DATE_OBSERVATION']['date_1']['F'] ||
        (int)$a['EIO_DATE_OBSERVATION']['AN']!=$_POST['EIO_DATE_OBSERVATION']['AN']){
        $update2t='update eflore_inventaire_observation set eio_date_observation=\''
                .$_POST['EIO_DATE_OBSERVATION']['AN'].'-'.$_POST['EIO_DATE_OBSERVATION']['date_1']['F'].'-'.$_POST['EIO_DATE_OBSERVATION']['date_1']['d'].'\' where eio_ce_image='.$id;
        $resultat=$GLOBALS['db_eflore']->query($update2t);
            (DB::isError($resultat)) ?
                die (BOG_afficherErreurSql(__FILE__, __LINE__, 'update 2t :'.$resultat->getMessage(), $update2t)) : '' ;
        $nbre_update++;
        }
    $delete1='';
    $insert1='';
    $insert1t='';
    $insert1b='';
    $cat='';
    $update3='update eflore_info_image_posseder_valeur set eiipv_id_valeur_categorie_img='.$cat.' where eiipv_id_image='.$id.
                ' and eiipv_id_valeur_categorie_img in (select \'eiiv_ce_categorie_img\' from eflore_info_image_valeur where eiiv_ce_categorie_img=';
    $update3b='';
    $update3t='';
    $update3q='';
    if ($a['NATURE']!=$_POST['NATURE'] || $a['SUJET']!=$_POST['SUJET'] || $a['DEVELOPPEMENT']!=$_POST['DEVELOPPEMENT']){
        $delete1='delete from eflore_info_image_posseder_valeur  where eiipv_id_image='.$id;
        $resultat=$GLOBALS['db_eflore']->query($delete1);
            (DB::isError($resultat)) ?
                die (BOG_afficherErreurSql(__FILE__, __LINE__, 'delete 1 :'.$resultat->getMessage(), $delete1)) : '' ;
        $cat=$_POST['NATURE'];
        $insert1='insert delayed into eflore_info_image_posseder_valeur values ('.$cat.','.$id.',2)';
        $resultat=$GLOBALS['db_eflore']->query($insert1);
            (DB::isError($resultat)) ?
                die (BOG_afficherErreurSql(__FILE__, __LINE__, 'insert 1 :'.$resultat->getMessage(), $insert1)) : '' ;
        if ($a['NATURE']!= $_POST['NATURE']){$nbre_update++;}
        $cat=$_POST['SUJET'];
        if ($cat!=-1){
            if ($a['SUJET'] != $_POST['SUJET']){$nbre_update++;}
            $insert1b='insert delayed into eflore_info_image_posseder_valeur values ('.$cat.','.$id.',2)';
            $resultat=$GLOBALS['db_eflore']->query($insert1b);
            (DB::isError($resultat)) ?
                die (BOG_afficherErreurSql(__FILE__, __LINE__, 'insert 1b :'.$resultat->getMessage(), $insert1b)) : '' ;
        }
        $cat=$_POST['DEVELOPPEMENT'];
        if ($cat!=-1){
            if ($a['DEVELOPPEMENT'] != $_POST['DEVELOPPEMENT']){$nbre_update++;}
            $insert1t='insert delayed into eflore_info_image_posseder_valeur values ('.$cat.','.$id.',2)';
            $resultat=$GLOBALS['db_eflore']->query($insert1t);
            (DB::isError($resultat)) ?
                die (BOG_afficherErreurSql(__FILE__, __LINE__, 'insert 1t :'.$resultat->getMessage(), $insert1t)) : '' ;
        }
    }
}

function supprImg($id){
    $delete1='delete from eflore_info_image_posseder_valeur where eiipv_id_image='.$id;
    $delete2='delete from eflore_inventaire_observation where eio_ce_image='.$id;
    $delete3='delete from eflore_info_txt_a_taxon where eitat_id_taxon_ref='.$id;
    $delete4='delete from eflore_info_image where eii_id_image='.$id;
    $resultat=$GLOBALS['db_eflore']->query($delete1);
    (DB::isError($resultat)) ?
            die (BOG_afficherErreurSql(__FILE__, __LINE__, 'delete 1 :'.$resultat->getMessage(), $delete1)) : '' ;
    $resultat=$GLOBALS['db_eflore']->query($delete2);
    (DB::isError($resultat)) ?
        die (BOG_afficherErreurSql(__FILE__, __LINE__, 'delete 2 :'.$resultat->getMessage(), $delete2)) : '' ;
    $resultat=$GLOBALS['db_eflore']->query($delete3);
    (DB::isError($resultat)) ?
        die (BOG_afficherErreurSql(__FILE__, __LINE__, 'delete 3 :'.$resultat->getMessage(), $delete3)) : '' ;
    $resultat=$GLOBALS['db_eflore']->query($delete4);
    (DB::isError($resultat)) ?
        die (BOG_afficherErreurSql(__FILE__, __LINE__, 'delete 4 :'.$resultat->getMessage(), $delete4)) : '' ;
    unlink(EFLORE_CHEMIN_IMG_PLTE.'mini_photos_plte/mini_'.$id.'.jpg');
    if (file_exists(EFLORE_CHEMIN_RDF.$id.'.rdf')){
        unlink(EFLORE_CHEMIN_RDF.$id.'.rdf');
    }
    if (file_exists(EFLORE_CHEMIN_IMG_PLTE.$id.'.jpg')){
        unlink(EFLORE_CHEMIN_IMG_PLTE.$id.'.jpg');
    }
}

function generationRdf($ligne){
    $url_img=$ligne['eii_lien_vers_img'];
    $url_img_mini=EFLORE_CHEMIN_IMG_PLTE.'mini_photos_plte/mini_';
    $url_img_mini .=$ligne['eii_id_image'].'.jpg';
    if ($ligne['eii_lien_vers_img']!=EFLORE_CHEMIN_IMG_PLTE){
        $url_img .=$ligne['eii_nom_fichier_img'];
    }
    else{
        $url_img .=$ligne['eii_id_image'].'.jpg';
    }
    $sep="\"\n";
    //en-tete commune a tous les fichiers rdf
    $en_tete='<rdf=RDF';
    $en_tete .="\n";
    $en_tete .='xmls:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"';
    $en_tete .=$sep;
    $en_tete .='xmls:dc="http://purl.org/dc/elements/1.1/"'.$sep;
    $en_tete .='xmls:dcterms="http://purl.org/dc/terms"'.$sep;
    $en_tete .='>'."\n\n"; 
    //g&eacute;n&eacute;ration d'un fichier rdf pour chaque resultat de la requete
    $fic=EFLORE_CHEMIN_RDF;
    $fic .=$ligne['eii_id_image'];
    $fic .='.rdf';
    if(!file_exists($fic)){
        $fp=fopen($fic,"w+");
        $text_rdf="";
        if(!$fp){
            $res.='erreur de cr&eacute;ation du fichier rdf';
            exit;
            }
        $text_rdf .=$en_tete;
        $text_rdf .='<rdf:Description  rdf:about="';
        $text_rdf .=$url_img .$sep;
        $text_rdf .='dc:identifier="';
        $text_rdf .=$ligne['eii_id_image'];
        $text_rdf .=$sep;
        /*$text_rdf .='dc:title="';
        $text_rdf .=$ligne[1];
        $text_rdf .=$sep;*/
        $text_rdf .='dc:creator="';
        $text_rdf .=$ligne['eii_auteur_img'];
        $text_rdf .=$sep;
        $text_rdf .='dc:type="image'.$sep;
        $text_rdf .='dcterms:created="';
        $text_rdf .=$ligne['eio_date_observation'];
        $text_rdf .=$sep;
        $text_rdf .='>'."\n".'</rdf:Description>'."\n".'</rdf:RDF>'."\n";
        $i=fwrite($fp,$text_rdf);
        fclose($fp);
    }
}

function auteurImg(){
    if($_POST['EII_AUTEUR_IMG']==''){
        $req='select * from eflore_personne_contributeur where epc_id_contributeur='.CONTRIBUTEUR;
        $resultat=$GLOBALS['db_eflore']->query($req);
        $ligne=& $resultat->fetchRow(DB_FETCHMODE_ASSOC);
        return ($ligne['epc_nom_principal']);
    }
    else{return ($_POST['EII_AUTEUR_IMG']);}
}

function copyFile($id_photo){
    $cmde='/usr/bin/convert -size 150x150 /home/telabotap/sd/testv4/'.EFLORE_CHEMIN_IMG_PLTE.$id_photo.'.jpg 
                    -resize 150x150 -quality 25 /home/telabotap/sd/testv4/'.EFLORE_CHEMIN_IMG_PLTE.'mini_photos_plte/mini_'.$id_photo.'.jpg';
    if ($_POST['loc']==0){
        if ($_FILES['UPLOADED_FILE']['type']!='image/jpeg'){
            return (false);
        }
        elseif (!move_uploaded_file($_FILES['UPLOADED_FILE']['tmp_name'], EFLORE_CHEMIN_IMG_PLTE.$id_photo.'.jpg')){
            return (false);
        }
        else{
            system($cmde);
            return(true);
        }
    }
    else{
        if (copy($_POST['EII_LIEN_VERS_IMG'],EFLORE_CHEMIN_IMG_PLTE.$id_photo.'.jpg')){
            list($long,$larg,$type,$attr)=getimagesize(EFLORE_CHEMIN_IMG_PLTE.$id_photo.'.jpg');
            $poids=intval(filesize(EFLORE_CHEMIN_IMG_PLTE.$id_photo.'.jpg')/1024);
            if ($type==2){
                system($cmde);
                $req='update eflore_info_image set eii_poids_img='.$poids.', eii_long_img='.$long.', eii_larg_img='.$larg;
                $req.=' where eii_id_image='.$id_photo;
                echo $req;
                $resultat=$GLOBALS['db_eflore']->query($req);
                (DB::isError($resultat)) ?
                    die (BOG_afficherErreurSql(__FILE__, __LINE__, 'copyFile:'.$resultat->getMessage(), $req)) : '' ;
                unlink(EFLORE_CHEMIN_IMG_PLTE.$id_photo.'.jpg');
                return (true);
            }
            else{
                unlink(EFLORE_CHEMIN_IMG_PLTE.$id_photo.'.jpg');
                return (false);
            }
        }
        else{return (false);}
    }
}

function dirFile( &$dir,&$file){
    if ($_POST['loc']==0){
        $dir=EFLORE_CHEMIN_IMG_PLTE;
        $file=$_FILES['UPLOADED_FILE']['name'];
    }
    else{
        $dir=dirname($_POST['EII_LIEN_VERS_IMG']).'/';
        $file=basename($_POST['EII_LIEN_VERS_IMG']);
    }
}

function selectNom(){
    $req='select * from eflore_selection_nom where esn_id_taxon='.N_TAXON.' and esn_id_version_projet_taxon='.N_VERSION_PROJET_TAXON.' and esn_ce_statut=5';
    $resultat=$GLOBALS['db_eflore']->query($req);
    $ligne=& $resultat->fetchRow(DB_FETCHMODE_ASSOC);
    return ($ligne['esn_id_nom']);
}

function validLicence(){
    $id_lic=0;
    if (isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_COM'])){
        if (isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_MOD'])){$id_lic=6;}
        else{$id_lic=2;}
    }
    elseif (isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_MOD'])){$id_lic=4;}
    else{$id_lic=1;}
    return ($id_lic);
}

function verifAuteur(){
    if($_POST['EII_AUTEUR_IMG']==''){
        $req='select * from eflore_personne_contributeur where epc_id_contributeur='.CONTRIBUTEUR;
        $resultat=$GLOBALS['db_eflore']->query($req);
        $ligne=& $resultat->fetchRow(DB_FETCHMODE_ASSOC);
        if($ligne['epc_ce_personne']==0){
            return(false);
        }
        else{
            return(true);
        }
    }
    else{
        return(true);
    }
}

function verifDate(){
    $retour=false;
    if ($_POST['EIO_DATE_OBSERVATION']['date_1']['F']==0 && $_POST['EIO_DATE_OBSERVATION']['date_1']['d']!=0){
        $retour=false;
    }
    else{
        if($_POST['EIO_DATE_OBSERVATION']['date_1']['F']!=0 && $_POST['EIO_DATE_OBSERVATION']['date_1']['d']==0){
            $retour=true;
        }
        else{
            $d=getDate();
            if ($d['year'] < $_POST['EIO_DATE_OBSERVATION']['AN']){$retour=false;}
            elseif ($d['month'] < $_POST['EIO_DATE_OBSERVATION']['date_1']['F'] && $d['year']==$_POST['EIO_DATE_OBSERVATION']['AN']){
                $retour=false;
            }
            elseif ($d['mday'] < $_POST['EIO_DATE_OBSERVATION']['date_1']['d'] && 
                    $d['month']==$_POST['EIO_DATE_OBSERVATION']['date_1']['F'] && 
                    $d['year']==$_POST['EIO_DATE_OBSERVATION']['AN']){
                $retour=false;
            }
            elseif ($_POST['EIO_DATE_OBSERVATION']['date_1']['F']==0 
                    && $_POST['EIO_DATE_OBSERVATION']['date_1']['d']==0 
                    && $_POST['EIO_DATE_OBSERVATION']['AN']!=0){
                    $retour=true;
                }
            else{
                $retour=checkdate($_POST['EIO_DATE_OBSERVATION']['date_1']['F'],$_POST['EIO_DATE_OBSERVATION']['date_1']['d'],$_POST['EIO_DATE_OBSERVATION']['AN']);
            }
        }
    }
    return($retour);
}

function verifFlore(){
    $autre_nom_latin=1;
    if ($_POST['EN_ID_NOM']==selectNom()){$autre_nom_latin=0;}
    if (($autre_nom_latin!=0) && $_POST['EIO_AUTRE_FLORE']==-1 && $_POST['autre_flore']==''){
        return(false);
    }
    else{
        return(true);
    }
}

function verifLicence(){
    $retour=true;
    if (!isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_COM']) && 
        !isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_MOD']) && 
        !isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_AUCUN'])){
        $retour=false;
    }
    elseif(isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_COM']) || isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_MOD'])){
        if (isset($_POST['LICENCE']['EII_CE_LICENCE_IMG_AUCUN'])){$retour=false;}
    }
    return ($retour);
}



function verifSelection0(){
    if ($_POST['loc']==0 && ($_FILES['UPLOADED_FILE']['name'])==NULL){
        return (false);
    }
    else {return (true);}
}

function verifSelection1(){
    if ($_POST['loc']==1 && (($_POST['EII_LIEN_VERS_IMG']=='http://')||($_POST['EII_LIEN_VERS_IMG']==''))){
        return (false);
    }
    else {return (true);}
}
?>
