[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/ -> contact.class.php (source)

   1  <?php
   2  /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2004      Benoit Mortier       <benoit.mortier@opensides.be>
   4   * Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   5   * Copyright (C) 2005      Regis Houssin  <regis.houssin@cap-networks.com>
   6   *
   7   * This program is free software; you can redistribute it and/or modify
   8   * it under the terms of the GNU General Public License as published by
   9   * the Free Software Foundation; either version 2 of the License, or
  10   * (at your option) any later version.
  11   *
  12   * This program is distributed in the hope that it will be useful,
  13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15   * GNU General Public License for more details.
  16   *
  17   * You should have received a copy of the GNU General Public License
  18   * along with this program; if not, write to the Free Software
  19   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20   *
  21   * $Id: contact.class.php,v 1.71.2.1 2005/12/20 22:55:20 eldy Exp $
  22   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/contact.class.php,v $
  23   */
  24  
  25  /**
  26          \file       htdocs/contact.class.php
  27          \ingroup    societe
  28          \brief      Fichier de la classe des contacts
  29          \version    $Revision: 1.71.2.1 $
  30  */
  31  
  32  require_once  (DOL_DOCUMENT_ROOT."/lib/ldap.lib.php");
  33  
  34  
  35  
  36  /**
  37          \class      Contact
  38          \brief      Classe permettant la gestion des contacts
  39  */
  40  
  41  class Contact 
  42  {
  43      var $db;
  44      var $error;
  45      
  46      var $id;
  47      var $fullname;
  48      var $nom;
  49      var $prenom;
  50      var $name;
  51      var $firstname;
  52      var $address;
  53      var $cp;
  54      var $ville;
  55      var $fk_pays;
  56      
  57      var $code;
  58      var $email;
  59      var $birthday;
  60  
  61      var $ref_facturation;       // Nb de reference facture pour lequel il est contact
  62      var $ref_contrat;           // Nb de reference contrat pour lequel il est contact
  63      var $ref_commande;          // Nb de reference commande pour lequel il est contact
  64      var $ref_propal;            // Nb de reference propal pour lequel il est contact
  65  
  66      /**
  67       *      \brief      Constructeur de l'objet contact
  68       *      \param      DB      Habler d'accès base
  69       *      \param      id      Id contact
  70       */
  71      function Contact($DB, $id=0) 
  72      {
  73          $this->db = $DB;
  74          $this->id = $id;
  75          
  76          return 1;
  77      }
  78  
  79      /**
  80       *      \brief      Ajout d'un contact en base
  81       *      \param      user        Utilisateur qui effectue l'ajout
  82       *      \return     int         <0 si ko, >0 si ok
  83       */
  84      function create($user)
  85      {
  86          $this->name=trim($this->name);
  87          if (! $this->socid)
  88          {
  89              $this->socid = 0;
  90          }
  91  
  92          $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (datec, fk_soc, name, fk_user)";
  93          $sql.= " VALUES (now(),";
  94          if ($this->socid > 0) $sql.= " $this->socid,";
  95          else $sql.= "null,";
  96          $sql.= "'$this->name',$user->id)";
  97      
  98          if ($this->db->query($sql) )
  99          {
 100              $id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
 101      
 102              $ret=$this->update($id, $user);
 103              if ($ret < 0)
 104              {
 105                  $this->error=$this->db->error();
 106                  return -2;
 107              }                
 108              return $id;
 109          }
 110          else
 111          {
 112              $this->error=$this->db->error();
 113              return -1;
 114          }
 115      }
 116  
 117      /*
 118       *      \brief      Mise à jour des infos
 119       *      \param      id          id du contact à mettre à jour
 120       *      \param      user        Utilisateur qui effectue la mise à jour
 121       *      \return     int         <0 si erreur, >0 si ok
 122       */
 123      function update($id, $user=0)
 124      {
 125          dolibarr_syslog("Contact::Update id=".$id,LOG_DEBUG);
 126  
 127          $this->id = $id;
 128      
 129          $this->name=trim($this->name);
 130          $this->firstname=trim($this->firstname);
 131          $this->email=trim($this->email);
 132          $this->phone_pro=trim($this->phone_pro);
 133      
 134          if ($this->phone_pro && $this->socid > 0)
 135          {
 136              $soc = new Societe($this->db);
 137              $soc->fetch($this->socid);
 138              $this->phone_pro = $soc->tel;
 139          }
 140      
 141          $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET ";
 142          $sql .= "  civilite='$this->civilite_id'";
 143          $sql .= ", name='$this->name'";
 144          $sql .= ", firstname='$this->firstname'";
 145          $sql .= ", address='$this->address'";
 146          $sql .= ", cp='$this->cp'";
 147          $sql .= ", ville='$this->ville'";
 148          $sql .= ", fk_pays='$this->fk_pays'";
 149          $sql .= ", poste='$this->poste'";
 150          $sql .= ", fax='$this->fax'";
 151          $sql .= ", email='$this->email'";
 152          $sql .= ", note='$this->note'";
 153          $sql .= ", phone = '$this->phone_pro'";
 154          $sql .= ", phone_perso = '$this->phone_perso'";
 155          $sql .= ", phone_mobile = '$this->phone_mobile'";
 156          $sql .= ", jabberid = '$this->jabberid'";
 157          if ($user) $sql .= ", fk_user_modif='".$user->id."'";
 158          $sql .= " WHERE idp=".$id;
 159      
 160          $result = $this->db->query($sql);
 161          if (! $result)
 162          {
 163              $this->error=$this->db->error();
 164              return -1;
 165          }
 166      
 167          if ($conf->ldap->enabled)
 168          {
 169              if ($conf->global->LDAP_CONTACT_ACTIVE)
 170              {
 171                  $this->update_ldap($user);
 172              }
 173      
 174          }
 175          return 1;
 176      }
 177    
 178    /**
 179     *    \brief      Mise à jour de l'arbre ldap
 180     *    \param      user        Utilisateur qui effectue la mise à jour
 181     *
 182     */
 183    function update_ldap($user)
 184    {
 185      $info = array();
 186      dolibarr_syslog("Contact::update_ldap",LOG_DEBUG);
 187      
 188      $this->fetch($this->id);
 189      
 190      $ds = dolibarr_ldap_connect();
 191      
 192      if ($ds)
 193        {
 194      $ldapbind = dolibarr_ldap_bind($ds);
 195      
 196      if ($ldapbind)
 197        {
 198          if (LDAP_SERVER_TYPE == 'activedirectory') //enlever utf8 pour etre compatible Windows
 199           {
 200             $info["objectclass"][0] = "top";
 201             $info["objectclass"][1] = "person";
 202             $info["objectclass"][2] = "organizationalPerson";
 203             //$info["objectclass"][3] = "inetOrgPerson";
 204             $info["objectclass"][3] = "user";
 205             
 206             $info["cn"] = $this->firstname." ".$this->name;
 207             $info["sn"] = $this->name;
 208             $info["givenName"] = $this->firstname;
 209             
 210             if ($this->poste)
 211           $info["title"] = $this->poste;
 212             
 213             if ($this->socid > 0)
 214           {
 215             $soc = new Societe($this->db);
 216             $soc->fetch($this->socid);
 217             $info["o"] = $soc->nom;
 218             $info["company"] = $soc->nom;
 219             
 220             if ($soc->client == 1)
 221               $info["businessCategory"] = "Clients";
 222             elseif ($soc->client == 2)
 223               $info["businessCategory"] = "Prospects";
 224             
 225             if ($soc->fournisseur == 1)
 226               $info["businessCategory"] = "Fournisseurs";
 227             
 228             if ($soc->ville)
 229               {
 230                 if ($soc->adresse)
 231               $info["streetAddress"] = $soc->adresse;
 232                 
 233                 if ($soc->cp)
 234               $info["postalCode"] = $soc->cp;
 235                 
 236                 $info["l"] = $soc->ville;
 237               }
 238           }
 239             
 240             if ($this->phone_pro)
 241           $info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro);
 242             
 243             if ($this->phone_perso)
 244           $info["homePhone"] = dolibarr_print_phone($this->phone_perso);
 245             
 246             if ($this->phone_mobile)
 247           $info["mobile"] = dolibarr_print_phone($this->phone_mobile);
 248             
 249             if ($this->fax)
 250           $info["facsimileTelephoneNumber"] = dolibarr_print_phone($this->fax);
 251             
 252             if ($this->note)
 253           $info["description"] = ($this->note);
 254             if ($this->email)
 255           $info["mail"] = $this->email;
 256             
 257             $dn = "cn=".$info["cn"].",".LDAP_CONTACT_DN;
 258             
 259             $r = @ldap_delete($ds, $dn);       
 260             
 261             if (! @ldap_add($ds, $dn, $info))
 262           {
 263             $this->error[0] = ldap_err2str(ldap_errno($ds));
 264           }  
 265           }
 266          else
 267            {
 268          $info["objectclass"][0] = "top";
 269          $info["objectclass"][1] = "person";
 270          $info["objectclass"][2] = "organizationalPerson";
 271          $info["objectclass"][3] = "inetOrgPerson";
 272             
 273          $info["cn"] = utf8_encode($this->firstname." ".$this->name);
 274          $info["sn"] = utf8_encode($this->name);
 275          $info["givenName"] = utf8_encode($this->firstname);
 276          
 277          if ($this->poste)
 278            $info["title"] = utf8_encode($this->poste);
 279          
 280          if ($this->socid > 0)
 281            {
 282              $soc = new Societe($this->db);
 283              $soc->fetch($this->socid);
 284              $info["o"] = utf8_encode($soc->nom);
 285              
 286              if ($soc->client == 1)
 287                $info["businessCategory"] = utf8_encode("Clients");
 288              elseif ($soc->client == 2)
 289                $info["businessCategory"] = utf8_encode("Prospects");
 290              
 291              if ($soc->fournisseur == 1)
 292                $info["businessCategory"] = utf8_encode("Fournisseurs");
 293              
 294              if ($soc->ville)
 295                {
 296              if ($soc->adresse)
 297                $info["street"] = utf8_encode($soc->adresse);
 298              
 299              if ($soc->cp)
 300                $info["postalCode"] = utf8_encode($soc->cp);
 301              
 302              $info["l"] = utf8_encode($soc->ville);
 303                }
 304            }
 305          
 306          if ($this->phone_pro)
 307            $info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro);
 308          
 309          if ($this->phone_perso)
 310            $info["homePhone"] = dolibarr_print_phone($this->phone_perso);
 311          
 312          if ($this->phone_mobile)
 313            $info["mobile"] = dolibarr_print_phone($this->phone_mobile);
 314          
 315          if ($this->fax)
 316            $info["facsimileTelephoneNumber"] = dolibarr_print_phone($this->fax);
 317          
 318          if ($this->note)
 319            $info["description"] = ($this->note);
 320          
 321          if(LDAP_SERVER_TYPE == 'egroupware')
 322            {        
 323              $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware
 324              
 325              if ($this->email)
 326                $info["rfc822Mailbox"] = $this->email;
 327              
 328              $info['uidnumber'] = $this->id;
 329              
 330              $info['phpgwTz']      = 0;
 331              $info['phpgwMailType'] = 'INTERNET';
 332              $info['phpgwMailHomeType'] = 'INTERNET';
 333              
 334              $info["uid"] = $this->id. ":".$info["sn"];
 335              $info["phpgwContactTypeId"] = 'n';
 336              $info["phpgwContactCatId"] = 0;
 337              $info["phpgwContactAccess"] = "public";
 338              
 339              if (strlen($user->egroupware_id) == 0)
 340                {
 341              $user->egroupware_id = 1;
 342                }
 343              
 344              $info["phpgwContactOwner"] = $user->egroupware_id;
 345              
 346              if ($this->phone_mobile)
 347                $info["phpgwCellTelephoneNumber"] = dolibarr_print_phone($this->phone_mobile);
 348            }
 349          else
 350            {
 351              if ($this->email)
 352                $info["mail"] = $this->email;
 353            }
 354  
 355          $dn = "cn=".$info["cn"].",".LDAP_CONTACT_DN;
 356          
 357          dolibarr_syslog("Contact::update_ldap dn : ".$dn,LOG_DEBUG);
 358          
 359          $r = @ldap_delete($ds, $dn);       
 360          
 361          if (! @ldap_add($ds, $dn, $info))
 362            {
 363              $this->error[0] = ldap_err2str(ldap_errno($ds));
 364              dolibarr_syslog("Contact::update_ldap error : ".$this->error[0],LOG_ERR);
 365            }
 366            }
 367        }
 368      else
 369        {
 370          dolibarr_syslog("Contact::update_ldap bind failed",LOG_DEBUG);
 371        }
 372      
 373      dolibarr_ldap_unbind($ds);
 374      
 375        }
 376      else
 377        {
 378      dolibarr_syslog("Contact::update_ldap Connexion failed",LOG_DEBUG);
 379      echo "Impossible de se connecter au serveur LDAP !";
 380        }
 381    }
 382    
 383    
 384    /*
 385     *    \brief      Mise à jour des alertes
 386     *    \param      id          id du contact
 387     *    \param      user        Utilisateur qui demande l'alerte
 388     */
 389    function update_perso($id, $user=0)
 390      {
 391        // Mis a jour contact
 392        $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET idp=$id ";
 393  
 394        if ($this->birthday>0)
 395      {
 396        if (eregi('\-',$this->birthday))
 397          {
 398            // Si date = chaine
 399            $sql .= ", birthday='".$this->birthday."'";
 400          }        
 401        else
 402          {
 403            // Si date = timestamp
 404            $sql .= ", birthday=".$this->db->idate($this->birthday);
 405          }
 406      }
 407        $sql .= " WHERE idp=$id";
 408  
 409        $result = $this->db->query($sql);
 410        if (!$result) 
 411      {
 412        $this->error='Echec sql='.$sql;
 413      }
 414        
 415        // Mis a jour alerte birthday
 416        if ($this->birthday_alert)
 417      {
 418        $sql = "INSERT into ".MAIN_DB_PREFIX."user_alert(type,fk_contact,fk_user) ";
 419        $sql.= "values (1,".$id.",".$user->id.")";
 420      }
 421        else
 422      {
 423        $sql = "DELETE from ".MAIN_DB_PREFIX."user_alert ";
 424        $sql.= "where type=1 AND fk_contact=".$id." AND fk_user=".$user->id;
 425      }
 426        $result = $this->db->query($sql);
 427        if (!$result) 
 428      {
 429        $this->error='Echec sql='.$sql;
 430      }
 431   
 432        return $result;
 433      }
 434  
 435  
 436      /*
 437       *    \brief      Charge l'objet contact
 438       *    \param      id          id du contact
 439       *    \param      user        Utilisateur lié au contact pour une alerte
 440       *    \return     int         1 si ok, -1 si erreur
 441       */
 442      function fetch($id, $user=0)
 443      {
 444          $sql = "SELECT c.idp, c.fk_soc, c.civilite civilite_id, c.name, c.firstname,";
 445          $sql.= " c.address, c.cp, c.ville,";
 446          $sql.= " c.fk_pays, p.libelle as pays, p.code as pays_code,";
 447          $sql.= " c.birthday as birthday, c.poste,";
 448          $sql.= " c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid, c.note,";
 449          $sql.= " u.rowid as user_id, u.login as user_login";
 450          $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
 451          $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON c.fk_pays = p.rowid";
 452          $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.idp = u.fk_socpeople";
 453          $sql.= " WHERE c.idp = ". $id;
 454      
 455          $resql=$this->db->query($sql);
 456          if ($resql)
 457          {
 458              if ($this->db->num_rows($resql))
 459              {
 460                  $obj = $this->db->fetch_object($resql);
 461      
 462                  $this->id             = $obj->idp;
 463                  $this->civilite_id    = $obj->civilite_id;
 464                  $this->name           = $obj->name;
 465                  $this->firstname      = $obj->firstname;
 466                  $this->nom            = $obj->name;
 467                  $this->prenom         = $obj->firstname;
 468      
 469                  $this->address        = $obj->address;
 470                  $this->cp             = $obj->cp;
 471                  $this->ville          = $obj->ville;
 472                  $this->fk_pays        = $obj->fk_pays;
 473                  $this->pays_code      = $obj->fk_pays?$obj->pays_code:'';
 474                  $this->pays           = $obj->fk_pays?$obj->pays:'';
 475      
 476                  $this->societeid      = $obj->fk_soc;
 477                  $this->socid          = $obj->fk_soc;
 478                  $this->poste          = $obj->poste;
 479      
 480                  $this->fullname       = $this->firstname . ' ' . $this->name;
 481      
 482                  $this->phone_pro      = dolibarr_print_phone($obj->phone);
 483                  $this->fax            = dolibarr_print_phone($obj->fax);
 484                  $this->phone_perso    = dolibarr_print_phone($obj->phone_perso);
 485                  $this->phone_mobile   = dolibarr_print_phone($obj->phone_mobile);
 486      
 487                  $this->code           = $obj->code;
 488                  $this->email          = $obj->email;
 489                  $this->jabberid       = $obj->jabberid;
 490                  $this->mail           = $obj->email;
 491      
 492                  $this->birthday       = $obj->birthday;
 493                  $this->birthday_alert = $obj->birthday_alert;
 494                  $this->note           = $obj->note;
 495  
 496                  $this->user_id        = $obj->user_id;
 497                  $this->user_login     = $obj->user_login;
 498              }
 499              $this->db->free($resql);
 500      
 501      
 502              // Recherche le user Dolibarr lié à ce contact
 503              $sql = "SELECT u.rowid ";
 504              $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
 505              $sql .= " WHERE u.fk_socpeople = ". $id;
 506      
 507              $resql=$this->db->query($sql);
 508              if ($resql)
 509              {
 510                  if ($this->db->num_rows($resql))
 511                  {
 512                      $uobj = $this->db->fetch_object($resql);
 513      
 514                      $this->user_id = $uobj->rowid;
 515                  }
 516                  $this->db->free($resql);
 517              }
 518              else
 519              {
 520                  dolibarr_syslog("Error in Contact::fetch() selectuser sql=$sql");
 521                     $this->error="Error in Contact::fetch() selectuser - ".$this->db->error()." - ".$sql;
 522                  return -1;
 523              }
 524      
 525              // Charge alertes du user
 526              if ($user)
 527              {
 528                  $sql = "SELECT fk_user";
 529                  $sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
 530                  $sql .= " WHERE fk_user = $user->id AND fk_contact = ".$id;
 531      
 532                  $resql=$this->db->query($sql);
 533                  if ($resql)
 534                  {
 535                      if ($this->db->num_rows($resql))
 536                      {
 537                          $obj = $this->db->fetch_object($resql);
 538      
 539                          $this->birthday_alert = 1;
 540                      }
 541                      $this->db->free($resql);
 542                   }
 543                  else
 544                  {
 545                      dolibarr_syslog("Error in Contact::fetch() selectuseralert sql=$sql");
 546                      $this->error="Error in Contact::fetch() selectuseralert - ".$this->db->error()." - ".$sql;
 547                      return -1;
 548                  }
 549              }
 550              
 551              return 1;
 552          }
 553          else
 554          {
 555              dolibarr_syslog("Error in Contact::fetch() selectsocpeople sql=$sql");
 556                $this->error="Error in Contact::fetch() selectsocpeople - ".$this->db->error()." - ".$sql;
 557              return -1;
 558          }
 559      }
 560      
 561      
 562      /*
 563       *    \brief        Charge le nombre d'elements auquel est lié ce contact
 564       *                  ref_facturation
 565       *                  ref_contrat
 566       *                  ref_commande
 567       *                  ref_propale
 568       *    \return       int         0 si ok, -1 si erreur
 569       */
 570      function load_ref_elements()
 571      {
 572          // Compte les elements pour lesquels il est contact
 573          $sql ="SELECT tc.element, count(ec.rowid) as nb";
 574          $sql.=" FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc";
 575          $sql.=" WHERE ec.fk_c_type_contact = tc.rowid";
 576          $sql.=" AND ec.fk_socpeople = ". $this->id;
 577          $sql.=" GROUP BY tc.element";
 578          
 579          dolibarr_syslog("Contact::load_ref_elements sql=$sql");
 580          
 581          $resql=$this->db->query($sql);
 582          if ($resql)
 583          {
 584              $obj=$this->db->fetch_object($resql);
 585              if ($obj->nb)
 586              {
 587                  if ($obj->element=='facture')  $this->ref_facturation = $obj->nb;
 588                  if ($obj->element=='contrat')  $this->ref_contrat = $obj->nb;
 589                  if ($obj->element=='commande') $this->ref_commande = $obj->nb;
 590                  if ($obj->element=='propal')   $this->ref_propal = $obj->nb;
 591              }
 592              $this->db->free($resql);
 593              return 0;
 594          }
 595          else
 596          {
 597              dolibarr_syslog("Error in Contact::fetch() selectcontactfacture sql=$sql");
 598              $this->error="Error in Contact::fetch() selectcontactfacture - ".$this->db->error()." - ".$sql;
 599              return -1;
 600          }
 601      }
 602  
 603      /**
 604       *    \brief      Efface le contact de la base et éventuellement de l'annuaire LDAP
 605       *    \param      id      id du contact a effacer
 606       */
 607      function delete($id)
 608      {
 609          $sql = "SELECT c.name, c.firstname FROM ".MAIN_DB_PREFIX."socpeople as c";
 610        $sql .= " WHERE c.idp = ". $id;
 611        $resql=$this->db->query($sql);
 612          if ($resql)
 613          {
 614              if ($this->db->num_rows($resql))
 615              {
 616                  $obj = $this->db->fetch_object($resql);
 617      
 618                  $this->old_name           = $obj->name;
 619                  $this->old_firstname      = $obj->firstname;
 620              }
 621           }    
 622                  
 623        $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
 624        $sql .= " WHERE idp=$id";
 625  
 626        $result = $this->db->query($sql);
 627  
 628        if (!$result) 
 629      {
 630        print $this->db->error() . '<br>' . $sql;
 631      }
 632        
 633        if (defined('MAIN_MODULE_LDAP')  && MAIN_MODULE_LDAP)
 634      {
 635        if (defined('LDAP_CONTACT_ACTIVE')  && LDAP_CONTACT_ACTIVE == 1)
 636          {
 637            
 638            $ds = dolibarr_ldap_connect();
 639            
 640            if ($ds)
 641          {
 642            $ldapbind = dolibarr_ldap_bind($ds);
 643            
 644            if ($ldapbind)
 645              {          
 646                // delete from ldap directory
 647                if (LDAP_SERVER_TYPE == 'activedirectory')
 648              {
 649                $userdn = $this->old_firstname." ".$this->old_name; //enlever utf8 pour etre compatible Windows
 650              }
 651                else
 652              {
 653                $userdn = utf8_encode($this->old_firstname." ".$this->old_name);
 654              }              
 655                $dn = "cn=".$userdn.",".LDAP_CONTACT_DN;
 656                
 657                $r = @ldap_delete($ds, $dn);
 658                
 659              }
 660            else
 661              {
 662                echo "LDAP bind failed...";
 663              }                    
 664            ldap_close($ds);
 665            
 666          }
 667            else
 668          {
 669            echo "Unable to connect to LDAP server";
 670          }
 671            
 672            
 673            return $result;
 674          }
 675      }
 676      }
 677    
 678      /*
 679       *    \brief      Charge les informations sur le contact, depuis la base
 680       *    \param      id      id du contact à charger
 681       */
 682      function info($id)
 683      {
 684          $sql = "SELECT c.idp, ".$this->db->pdate("datec")." as datec, fk_user";
 685          $sql .= ", ".$this->db->pdate("tms")." as tms, fk_user_modif";
 686          $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
 687          $sql .= " WHERE c.idp = $id";
 688          
 689          $resql=$this->db->query($sql);
 690          if ($resql)
 691          {
 692              if ($this->db->num_rows($resql))
 693              {
 694                  $obj = $this->db->fetch_object($resql);
 695      
 696                  $this->id                = $obj->idp;
 697      
 698                  if ($obj->fk_user) {
 699                      $cuser = new User($this->db, $obj->fk_user);
 700                      $cuser->fetch();
 701                      $this->user_creation     = $cuser;
 702                  }
 703      
 704                  if ($obj->fk_user_modif) {
 705                      $muser = new User($this->db, $obj->fk_user_modif);
 706                      $muser->fetch();
 707                      $this->user_modification = $muser;
 708                  }
 709      
 710                  $this->date_creation     = $obj->datec;
 711                  $this->date_modification = $obj->tms;
 712      
 713              }
 714      
 715              $this->db->free($resql);
 716          }
 717          else
 718          {
 719              print $this->db->error();
 720          }
 721      }
 722      
 723      /*
 724       *    \brief        Renvoi nombre d'emailings reçu par le contact avec son email
 725       *    \return       int     Nombre d'emailings
 726       */
 727      function getNbOfEMailings()
 728      {
 729          $sql = "SELECT count(mc.email) as nb";
 730          $sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
 731          $sql.= " WHERE mc.email = '".$this->email."'";
 732          $sql.= " AND mc.statut=1";      // -1 erreur, 0 non envoyé, 1 envoyé avec succès
 733          $resql=$this->db->query($sql);
 734          if ($resql)
 735          {
 736              $obj = $this->db->fetch_object($resql);
 737              $nb=$obj->nb;
 738               
 739              $this->db->free($resql);
 740              return $nb;
 741          }
 742          else
 743          {
 744              $this->error=$this->db->error();
 745              return -1;
 746          }
 747      }    
 748      
 749  }
 750  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics