Subversion Repositories eFlore/Applications.cel

Rev

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

<?php


// In :  utf8 
// Out : utf8

Class InventoryItemList extends DBAccessor {


        var $config;
        
        function InventoryItemList($config) {

                $this->config=$config;
        }
        

        function getElement($uid){
                
                 // Controle detournement utilisateur 
                    session_start();
                        $this->controleUtilisateur($uid[0]);
                
                        // uid[0] : utilisateur obligatoire
                        // uid[1] : si absent : valeur 'all' (departement)
                        // uid[2] : si absent : valeur 'all' (commune)
                        // uid[3] : si absent : valeur 'all' (annee)
                        // uid[4] : si absent : valeur 'all' (mois)
                        // uid[5] : si absent : valeur 'all' (jour)
                        // uid[6] : si absent : valeur 'all' (recherche libre)
                        // uid[7] : si absent : valeur 'all' (lieudit)
                        // uid[8] et uid[9] : selection intervalle
                        
                        $DB=$this->connectDB($this->config,'database_cel');


                        if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
                                $uid[1]="all";
                                $query_id_location="";
                        }
                        else {
                                $query_id_location=" AND id_location='".$DB->escapeSimple($uid[1])."' ";
                        }

                         
                        if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all" ) {
                                $uid[2]="all";
                                $query_location="";
                        }
                        else {
                                $query_location=" AND location='".$DB->escapeSimple($uid[2])."' ";
                        }
                        
                        if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") {
                                $uid[3]="all";
                                $query_year="";
                        }
                        else {
                                $query_year=" AND year(date_observation)='".$DB->escapeSimple($uid[3])."' ";
                        }
                        

                        if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") {
                                $uid[4]="all";
                                $query_month="";
                        }
                        else {
                                $query_month=" AND month(date_observation)='".$DB->escapeSimple($uid[4])."' ";
                        }

                        if (!isset($uid[5]) || $uid[5]=="" || $uid[5]=="all") {
                                $uid[5]="all";
                                $query_day="";
                        }
                        else {
                                $query_day=" AND day(date_observation)='".$DB->escapeSimple($uid[5])."' ";
                        }
                        
                        
                        if (!isset($uid[6]) || $uid[6]=="" || $uid[6]=="all") {
                                $uid[6]="all";
                                $query_libre="";
                        }
                        else {
                                $query_libre=" AND (nom_sel like '%".$DB->escapeSimple($uid[6])."%' OR nom_ret like '%".$DB->escapeSimple($uid[6])."%' OR station like '%".$DB->escapeSimple($uid[6])."%'  OR milieu like '%".$DB->escapeSimple($uid[6])."%' OR commentaire like '%".$DB->escapeSimple($uid[6])."%') ";
                        }

                        if (!isset($uid[7]) || $uid[7]=="" || $uid[7]=="all") {
                                $uid[7]="all";
                                $query_lieudit="";
                        }
                        else {
                                $query_lieudit=" AND lieudit='".$DB->escapeSimple($uid[7])."' ";
                        }
                        

                        $value=array();
                        
                        
                        if (isset($uid[8]) && isset($uid[9])) {
                        $query="SELECT identifiant, ordre, nom_sel, num_nom_sel, nom_ret, num_nom_ret, num_taxon, famille, location, date_observation," .
                                        " lieudit, station, milieu, commentaire, transmission  FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' " .
                                        $query_id_location.     
                                        $query_location.        
                                        $query_year.    
                                        $query_month.   
                                        $query_day.     
                                        $query_libre.   
                                        $query_lieudit. 
                                        " ORDER BY ordre LIMIT ".$uid[8].",".$uid[9];
                        }
                        
                        else {
                                if (isset($uid[8])) {
                                                // les n derniers                                       
                                        $query="SELECT identifiant, ordre, nom_sel, num_nom_sel, nom_ret, num_nom_ret, num_taxon, famille, location, date_observation," .
                                        " lieudit, station, milieu, commentaire, transmission  FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' " .
                                        $query_id_location.     
                                        $query_location.        
                                    $query_year.        
                                        $query_month.   
                                        $query_day.     
                                        $query_libre.   
                                        $query_lieudit. 
                                        " ORDER BY ordre LIMIT ".$uid[8].",18446744073709551615";
                                }
                                else {
                                        $query="SELECT count(*) as count FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."'" .
                                        $query_id_location.     
                                                $query_location.        
                                        $query_year.    
                                        $query_month.   
                                        $query_day.     
                                        $query_libre.   
                                        $query_lieudit; 

                                    $res =& $DB->query($query);
   
    
                                        if (DB::isError($res)) {
                                        die($res->getMessage());
                                        }
                                        while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
                                        $value=$row['count'];
                                    }
                                        
                                                $output = json_encode((integer)$value);
                                                print($output);
                                                
                                                return true;    
                                        
                                }
                        }

             
                    $res =& $DB->query($query);
                    
                if (DB::isError($res)) {
                die($res->getMessage());
                }
                while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
                        if ($row['date_observation']!="0000-00-00 00:00:00") {
                        list($year,$month,$day)= split ('-',$row['date_observation']);
                    list($day)= split (' ',$day);
                        $row['date_observation']=$day."/".$month."/".$year;
                        }
                $value[]=array($row['nom_sel'], $row['num_nom_sel'],$row['nom_ret'],$row['num_nom_ret'],$row['num_taxon'],$row['famille'], $row['location'], $row['ordre'], $row['date_observation'], $row['lieudit'], $row['station'], $row['milieu'], $row['commentaire'], $row['transmission']);
                
            }
                
                        $output = json_encode($value);
                        print($output);
                        
                        return true;    


        }
        


}

/* +--Fin du code ---------------------------------------------------------------------------------------+
* $Log$
* Revision 1.7  2008-11-13 11:29:12  ddelon
* Reecriture gwt-ext
*
* Revision 1.6  2008-01-30 08:57:28  ddelon
* fin mise en place mygwt
*
* Revision 1.5  2007-05-22 12:54:08  ddelon
* Securisation acces utilisateur
*
*
* 
*/

 
?>