<?php

class Personne
{
    var $id;
    var $login;
    var $motDePasse;
    var $nom;
    var $prenom;    
		var $droits;
    var $email;

  function Personne($id=-1,$photo='Defaut.gif')
  {
    $this->id     = $id;
    $this->photo  = $photo;
  }


  function getNom( )
  {
    return $this->nom;
  }

  function load( &$mdb2 )
  {
    $ret=-1;
    $req="select * from webcal_user where cal_login=".$this->login;
    $result=mysql_query($req,$mdb2);
    if ($result==false) {
      $ret=-1;
    } else {
      $data=mysql_fetch_object($result);
      $this->nom          =$data->cal_lastname;
      $this->prenom       =$data->cal_firstname;
      //$this->login        =$data->login;
      $this->motDePasse   =$data->motDePasse;
      //$this->droits       =$data->droits;
      $this->email        =$data->cal_email;
    }
    return $ret;
  }


  /**
    * Charge la liste des centrales depuis la BDD.
    * @param db
    *      Référence à la BDD.
    */
  function loadList( &$mdb2, &$tab, $ordreCol='nom', $ordreSens='ASC' )
  {
    $ret=-1;
    $req="select distinct cal_login from webcal_user order by ";
    if ($ordreCol=="") {
      $ordreCol="cal_firstname";
    }
    if ($ordreSens=="ASC") {
      $ordreSens="DESC";
    } else {
      $ordreSens="ASC";
    }

    $req.="$ordreCol";
    $req.=" $ordreSens";

    $result=mysql_query($req,$mdb2);
    if ($result==false) {
      $ret=-1;
    } else {
      $i=0;
      while ($data=mysql_fetch_object($result)) {
        $tab[]=new Personne;
        $tab[$i]->initAttributes();
        $tab[$i]->login=$data->cal_login;
        $ret=$tab[$i]->load($mdb2);
        if ($ret<0) {
          return $ret;
        }
        $i++;
      }
      $ret=$i;
    }
    return $ret;
  }

  /**
    * initAttributes sets all Personne attributes to its default 		               value
    * make sure to call this method within your class constructor
    */
  function initAttributes($id=-1,$photo='Defaut.gif')
  {
    $this->id     = -1;
    $this->photo  = 'Defaut.gif';
  }

}
?>
