Subversion Repositories eFlore/Applications.cel

Rev

Rev 416 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
// in utf8
// out utf8

// List des stations par utilisateur et par commune

Class InventoryStationList extends DBAccessor {


        var $config;
        
        function InventoryStationList($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' (commune)
                        // uid[2] et uid[3] : selection intervalle

                
                        $DB=$this->connectDB($this->config,'database_cel');
                         
                        if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
                                $uid[1]="all";
                                $query_location="";
                        }
                        else {
                                $query_location=" AND location='".$DB->escapeSimple($uid[1])."' ";
                        }
                

                        $value=array();
        
                
                        if (isset($uid[3]) && isset($uid[2])) {
                                    // les n � partir de x
                                $query="SELECT DISTINCT station  FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."'" .
                                $query_location.
                                " ORDER BY station LIMIT ".$uid[2].",".$uid[3];
                        }
                        else {
                                if (isset($uid[2])) {
                                        $query="SELECT DISTINCT station  FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' " .
                                        $query_location.
                                        "ORDER BY station LIMIT ".$uid[2].",18446744073709551615";
                                }
                                else {
                                        // le nombre total
                                         $query="SELECT count(DISTINCT station) as count FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' " .
                                         $query_location;
                                                
                                    $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)) {
                    $value[]=array($row['station']);
            }
                
                        $output = json_encode($value);
                        print($output);
                        
                        return true;    


        }
        


}


/* +--Fin du code ---------------------------------------------------------------------------------------+
* $Log$
* Revision 1.3  2008-01-30 08:57:28  ddelon
* fin mise en place mygwt
*
* Revision 1.2  2007-05-22 12:54:09  ddelon
* Securisation acces utilisateur
*
*
* 
*/

 
?>