Subversion Repositories Applications.gtt

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

<?php
// +------------------------------------------------------------------------------------------------------+
// | 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                            |
// +------------------------------------------------------------------------------------------------------+

// |@author ABDOOL RAHEEM shaheen   shaheenar50@hotmail.com                                                 |
// |@version 3                                                                                            |


/**
*classe servant d'interface
*avec la base de données pour éditer les statut 
entant qu'administrateur*/



class Statut
{

  /**Attributes: */

    var $_id_statut= null;
    var $_libelle_statut = null;

  /*
  *constructeur : @param no identifiant du statut
  */
  function Statut($id)
  {
    $this->_id_statut =$id;  
  }
  
  /*met à jour le libelle */
  function setLibelleStatut($lib)
  {
      $this->_libelle_statut= $lib;
  }
  
  /*enregistre un nouveau statut dans la base de donnees*/
  
  function enregistrerStatut( )
  {
    $table=GEST_STATUT;
    $d=$this->nextId();
    $this->_id_statut=$d;
    $champs =array (
           GEST_CHAMPS_ID_STATUT => $this->_id_statut,
           GEST_CHAMPS_LIBELLE_STATUT=> "$this->_libelle_statut");
           
    $resultat = $GLOBALS['db']->autoExecute($table, $champs,DB_AUTOQUERY_INSERT);
    
    if (DB::isError($resultat)) {
         die($resultat->getMessage());
       }           
  }
  
    /**
   *recupere l'identifiant de la base de donnees
   */
   
   function nextId()
   {
    $requete = 'SELECT MAX('.GEST_CHAMPS_ID_STATUT.') AS maxi FROM '.GEST_STATUT;
    $resultat = $GLOBALS['db']->query($requete);
    if (DB::isError($resultat) || $resultat->numRows() > 1) {
        return false;
    }
    
    $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT);
    return $ligne->maxi + 1;  
   }
   
   
  
  
  /*
  *retourne un tableau contenant tous les statuts et leurs identifiants
  */
  
  function recupererTableauStatut( )
  {
    $tableau= array();
    $i=0;
    $requete="SELECT ".GEST_CHAMPS_ID_STATUT." , ".GEST_CHAMPS_LIBELLE_STATUT.
             " FROM ".GEST_STATUT."";
   $resultat = $GLOBALS['db']->query($requete);  
   
   (DB::isError($resultat)) ? 
         die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
     
     while ($ligne= $resultat->fetchRow(DB_FETCHMODE_ASSOC))
     {
         $case = array(GEST_CHAMPS_ID_STATUT => $ligne[GEST_CHAMPS_ID_STATUT],
                       GEST_CHAMPS_LIBELLE_STATUT =>$ligne[GEST_CHAMPS_LIBELLE_STATUT]);
         $tableau[$i]=$case;
        $i=$i+1;
     }
     
     return $tableau;     
            
  }

  /**
  *recuperer tableau libelle
  */
  function recupererTableauLibelleStatut()
  {
      $tableau= array();
      $requete="SELECT ".GEST_CHAMPS_LIBELLE_STATUT.
             " FROM ".GEST_STATUT."";
           
      $resultat = $GLOBALS['db']->query($requete);  
   
   (DB::isError($resultat)) ? 
         die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
     
     while ($ligne= $resultat->fetchRow(DB_FETCHMODE_ASSOC))
     {
         array_push($tableau,$ligne[GEST_CHAMPS_LIBELLE_STATUT]);
     }
     return $tableau;
  }
  
  /*supprime une categorie
  *renvoie 1 si suppression effectuee
  *0 si rien
  *-1 si erreur
  */
  function supprimerStatut($id)
  {
    $requete= "DELETE FROM ".GEST_STATUT.
              " WHERE ".GEST_CHAMPS_ID_STATUT." =$id ";

    $resultat = $GLOBALS['db'] ->query($requete);
    
    (DB::isError($resultat)) ?
          die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;
    
    $int=$GLOBALS['db']->affectedRows();
    
    if($int==1)
    { 
        return 1;
    }elseif($int==0){
        return 0;
    }else return -1;    
              
  }
 /**
 *fonction verifiant si le statut est utilise
 *renvoie 1 si statut utilise
 *-1 sinon 
 */
 function statutUtilise($id)
{
   $requete="SELECT ".GEST_CHAMPS_ID_UTILISATEUR.
                " FROM ".GEST_UTILISATEUR.
                " WHERE ". GEST_CHAMPS_ID_STATUT."=$id";
    $ligne= $GLOBALS['db']->query($requete);
   
   (DB::isError($ligne)) ?
           die (BOG_afficherErreurSql(__FILE__, __LINE__, $ligne->getMessage(), $requete)) : '' ;
 
   $j= $ligne->numRows();
    if ($j==0){
        return -1;
    }else {
        return 1;
    }  
}
  
  function afficherStatut()
  {
      echo "Statut : \n";
      echo "id : ";
      echo "$this->_id_statut <BR>";
      echo "libelle_statut : ";
      echo "$this->_libelle_statut <BR>";
  }


}
?>