[ 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/ -> societe.class.php (source)

   1  <?php
   2  /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   4   * Copyright (C) 2004      Eric Seigne          <eric.seigne@ryxeo.com>
   5   * Copyright (C) 2003      Brian Fraval         <brian@fraval.org>
   6   *
   7   *
   8   * This program is free software; you can redistribute it and/or modify
   9   * it under the terms of the GNU General Public License as published by
  10   * the Free Software Foundation; either version 2 of the License, or
  11   * (at your option) any later version.
  12   *
  13   * This program is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16   * GNU General Public License for more details.
  17   *
  18   * You should have received a copy of the GNU General Public License
  19   * along with this program; if not, write to the Free Software
  20   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21   *
  22   * $Id: societe.class.php,v 1.108 2005/12/07 23:36:47 eldy Exp $
  23   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/societe.class.php,v $
  24   */
  25  
  26  /**
  27          \file       htdocs/societe.class.php
  28          \ingroup    societe
  29          \brief      Fichier de la classe des societes
  30          \version    $Revision: 1.108 $
  31  */
  32  
  33  
  34  /**
  35          \class         Societe
  36          \brief         Classe permettant la gestion des societes
  37  */
  38  
  39  class Societe {
  40    var $db;
  41  
  42    var $id;
  43    var $nom;
  44    var $adresse;
  45    var $cp;
  46    var $ville;
  47    var $departement_id;
  48    var $pays_id;
  49    var $pays_code;
  50    var $tel;
  51    var $fax;
  52    var $url;
  53    var $siren;
  54    var $siret;
  55    var $ape;
  56  
  57    var $prefix_comm;
  58  
  59    var $tva_intra;
  60    var $capital;
  61    var $typent_id;
  62    var $effectif_id;
  63    var $forme_juridique_code;
  64    var $forme_juridique;
  65  
  66    var $remise_client;
  67  
  68    var $client;
  69    var $prospect;
  70    var $fournisseur;
  71  
  72    var $code_client;
  73    var $code_fournisseur;
  74    var $code_compta;
  75    var $code_compta_fournisseur;
  76  
  77    var $note;
  78  
  79    var $stcomm_id;
  80    var $statut_commercial;
  81  
  82  
  83    /**
  84     *    \brief  Constructeur de la classe
  85     *    \param  DB     handler accès base de données
  86     *    \param  id     id societe (0 par defaut)
  87     */
  88  
  89    function Societe($DB, $id=0)
  90    {
  91      $this->db = $DB;
  92      $this->creation_bit = 0;
  93  
  94      $this->id = $id;
  95      $this->client = 0;
  96      $this->prospect = 0;
  97      $this->fournisseur = 0;
  98      $this->typent_id  = 0;
  99      $this->effectif_id  = 0;
 100      $this->forme_juridique_code  = 0;
 101  
 102      // definit module code client
 103      if (defined('CODECLIENT_ADDON') && strlen(CODECLIENT_ADDON) > 0) $var = CODECLIENT_ADDON;
 104      else $var = "mod_codeclient_leopard";
 105      require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$var.'.php';
 106  
 107      $this->mod_codeclient = new $var;
 108      $this->codeclient_modifiable = $this->mod_codeclient->code_modifiable;
 109  
 110      // definit module code fournisseur
 111      if (defined('CODEFOURNISSEUR_ADDON') && strlen(CODEFOURNISSEUR_ADDON) > 0) $var = CODEFOURNISSEUR_ADDON;
 112      else $var = "mod_codeclient_leopard";
 113      require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$var.'.php';
 114  
 115      $this->mod_codefournisseur = new $var;
 116      $this->codeclient_modifiable = $this->mod_codeclient->code_modifiable;
 117  
 118      return 1;
 119    }
 120  
 121    /**
 122     *    \brief      Crée la societe en base
 123     *    \param      user        Objet utilisateur qui demande la création
 124     *    \return     int         0 si ok, < 0 si erreur
 125     */
 126  
 127      function create($user='')
 128      {
 129          global $langs,$conf;
 130  
 131          // Nettoyage paramètres
 132          $this->nom=trim($this->nom);
 133  
 134          dolibarr_syslog("societe.class.php::create ".$this->nom);
 135  
 136          $this->db->begin();
 137  
 138          $result = $this->verify();
 139  
 140          if ($result >= 0)
 141          {
 142              $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, datec, datea, fk_user_creat) ";
 143              $sql .= " VALUES ('".addslashes($this->nom)."', now(), now(), '".$user->id."')";
 144  
 145              $result=$this->db->query($sql);
 146              if ($result)
 147              {
 148                  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
 149  
 150                  $this->creation_bit = 1;
 151  
 152                  $ret = $this->update($this->id,$user,0);
 153  
 154                  if ($ret >= 0)
 155                  {
 156                      $this->use_webcal=($conf->global->PHPWEBCALENDAR_COMPANYCREATE=='always'?1:0);
 157  
 158                      // Appel des triggers
 159                      include_once (DOL_DOCUMENT_ROOT . "/interfaces.class.php");
 160                      $interface=new Interfaces($this->db);
 161                      $result=$interface->run_triggers('COMPANY_CREATE',$this,$user,$langs,$conf);
 162                      // Fin appel triggers
 163  
 164                      dolibarr_syslog("Societe::Create success id=".$this->id);
 165                      $this->db->commit();
 166                      return 0;
 167                  }
 168                  else
 169                  {
 170                      dolibarr_syslog("Societe::Create echec update");
 171                      $this->db->rollback();
 172                      return -3;
 173                  }
 174              }
 175              else
 176  
 177              {
 178                  if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 179                  {
 180  
 181                      $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->nom);
 182                  }
 183                  else
 184                  {
 185                      dolibarr_syslog("Societe::Create echec insert sql=$sql");
 186                  }
 187                  $this->db->rollback();
 188                  return -2;
 189              }
 190  
 191          }
 192          else
 193          {
 194              $this->db->rollback();
 195              dolibarr_syslog("Societe::Create echec verify sql=$sql");
 196              return -1;
 197          }
 198      }
 199  
 200    /**
 201     *    \brief      Verification lors de la modification
 202     *    \return     0 si ok, < 0 en cas d'erreur
 203     */
 204  	function verify()
 205      {
 206          $this->nom=trim($this->nom);
 207          $result = 0;
 208          if (! $this->nom)
 209          {
 210              $this->error = "Le nom de la société ne peut être vide.\n";
 211              $result = -2;
 212          }
 213          if ($this->client && $this->codeclient_modifiable == 1)
 214          {
 215              // On ne vérifie le code client que si la société est un client / prospect et que le code est modifiable
 216              // Si il n'est pas modifiable il n'est pas mis à jour lors de l'update
 217              $rescode = $this->verif_codeclient();
 218              if ($rescode <> 0)
 219              {
 220                  if ($rescode == -1)
 221                  {
 222                      $this->error .= "La syntaxe du code client est incorrecte.\n";
 223                  }
 224                  if ($rescode == -2)
 225                  {
 226                      $this->error .= "Vous devez saisir un code client.\n";
 227                  }
 228                  if ($rescode == -3)
 229                  {
 230                      $this->error .= "Ce code client est déjà utilisé.\n";
 231                  }
 232                  $result = -3;
 233              }
 234          }
 235          return $result;
 236      }
 237  
 238      /**
 239       *      \brief      Mise a jour des paramètres de la sociét
 240       *      \param      id              id societe
 241       *      \param      user            Utilisateur qui demande la mise à jour
 242       *      \param      call_trigger    0=non, 1=oui
 243       *      \return     int             <0 si ko, >=0 si ok
 244       */
 245      function update($id, $user='', $call_trigger=1)
 246      {
 247          global $langs;
 248  
 249          dolibarr_syslog("Societe::Update");
 250  
 251          $this->id=$id;
 252          $this->capital=trim($this->capital);
 253          $this->nom=trim($this->nom);
 254          $this->adresse=trim($this->adresse);
 255          $this->cp=trim($this->cp);
 256          $this->ville=trim($this->ville);
 257          $this->departement_id=trim($this->departement_id);
 258          $this->pays_id=trim($this->pays_id);
 259          $this->tel=trim($this->tel);
 260          $this->fax=trim($this->fax);
 261          $this->url=trim($this->url);
 262          $this->siren=trim($this->siren);
 263          $this->siret=trim($this->siret);
 264          $this->ape=trim($this->ape);
 265          $this->prefix_comm=trim($this->prefix_comm);
 266          $this->tva_intra=trim($this->tva_intra);
 267          $this->capital=trim($this->capital);
 268          $this->effectif_id=trim($this->effectif_id);
 269          $this->forme_juridique_code=trim($this->forme_juridique_code);
 270  
 271          $result = $this->verify();
 272  
 273          if ($result >= 0)
 274          {
 275              dolibarr_syslog("Societe::Update verify ok");
 276          
 277              if (strlen($this->capital) == 0)
 278              {
 279                  $this->capital = 0;
 280              }
 281          
 282              $this->tel = ereg_replace(" ","",$this->tel);
 283              $this->tel = ereg_replace("\.","",$this->tel);
 284              $this->fax = ereg_replace(" ","",$this->fax);
 285              $this->fax = ereg_replace("\.","",$this->fax);
 286          
 287              /*
 288              * Supression des if (trim(valeur)) pour construire la requete
 289              * sinon il est impossible de vider les champs
 290              */
 291          
 292              $sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
 293              $sql .= " SET nom = '" . addslashes($this->nom) ."'"; // Champ obligatoire
 294              $sql .= ", datea = now()";
 295              $sql .= ",address = '" . addslashes($this->adresse) ."'";
 296          
 297              if ($this->cp)
 298              { $sql .= ",cp = '" . $this->cp ."'"; }
 299          
 300              if ($this->ville)
 301              { $sql .= ",ville = '" . addslashes($this->ville) ."'"; }
 302          
 303              $sql .= ",fk_departement = '" . ($this->departement_id?$this->departement_id:'0') ."'";
 304              $sql .= ",fk_pays = '" . ($this->pays_id?$this->pays_id:'0') ."'";
 305          
 306              $sql .= ",tel = ".($this->tel?"'".addslashes($this->tel)."'":"null");
 307              $sql .= ",fax = ".($this->fax?"'".addslashes($this->fax)."'":"null");
 308              $sql .= ",url = ".($this->url?"'".addslashes($this->url)."'":"null");
 309          
 310              $sql .= ",siren = '". addslashes($this->siren) ."'";
 311              $sql .= ",siret = '". addslashes($this->siret) ."'";
 312              $sql .= ",ape   = '". addslashes($this->ape)   ."'";
 313          
 314              $sql .= ",tva_intra = '" . addslashes($this->tva_intra) ."'";
 315              $sql .= ",capital = '" .   addslashes($this->capital) ."'";
 316          
 317              if ($this->prefix_comm) $sql .= ",prefix_comm = '" . $this->prefix_comm ."'";
 318          
 319              if ($this->effectif_id) $sql .= ",fk_effectif = '" . $this->effectif_id ."'";
 320          
 321              if ($this->typent_id)   $sql .= ",fk_typent = '" . $this->typent_id ."'";
 322          
 323              if ($this->forme_juridique_code) $sql .= ",fk_forme_juridique = '".$this->forme_juridique_code."'";
 324          
 325              $sql .= ",client = " . $this->client;
 326              $sql .= ",fournisseur = " . $this->fournisseur;
 327          
 328              if ($this->creation_bit || $this->codeclient_modifiable)
 329              {
 330                  // Attention check_codeclient peut modifier le code
 331                  // suivant le module utilis
 332          
 333                  $this->check_codeclient();
 334          
 335                  $sql .= ", code_client = ".($this->code_client?"'".$this->code_client."'":"null");
 336          
 337                  // Attention check_codecompta_client peut modifier le code
 338                  // suivant le module utilis
 339          
 340                  $this->check_codecompta_client();
 341          
 342                  $sql .= ", code_compta = ".($this->code_compta?"'".$this->code_compta."'":"null");
 343              }
 344          
 345              if ($this->creation_bit || $this->codefournisseur_modifiable)
 346              {
 347                  // Attention check_codefournisseur peut modifier le code
 348                  // suivant le module utilis
 349          
 350                  $this->check_codefournisseur();
 351          
 352                  $sql .= ", code_fournisseur = ".($this->code_fournisseur?"'".$this->code_fournisseur."'":"null");
 353          
 354                  // Attention check_codecompta_fournisseur peut modifier le code
 355                  // suivant le module utilis
 356          
 357                  $this->check_codecompta_fournisseur();
 358          
 359                  $sql .= ", code_compta_fournisseur = ".($this->code_compta_fournisseur?"'".$this->code_compta_fournisseur."'":"null");
 360              }
 361              if ($user) $sql .= ",fk_user_modif = '".$user->id."'";
 362              $sql .= " WHERE idp = '" . $id ."'";
 363          
 364              $resql=$this->db->query($sql);
 365              if ($resql)
 366              {
 367                  if ($call_trigger)
 368                  {
 369                      // Appel des triggers
 370                      include_once (DOL_DOCUMENT_ROOT . "/interfaces.class.php");
 371                      $interface=new Interfaces($this->db);
 372                      $result=$interface->run_triggers('COMPANY_MODIFY',$this,$user,$langs,$conf);
 373                      // Fin appel triggers
 374                  }
 375          
 376                  $result = 1;
 377              }
 378              else
 379              {
 380                  if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 381                  {
 382                      // Doublon
 383                      $this->error = $langs->trans("ErrorPrefixAlreadyExists",$this->prefix_comm);
 384                      $result =  -1;
 385                  }
 386                  else
 387                  {
 388          
 389                      $this->error = $langs->trans("Error sql=$sql");
 390                      dolibarr_syslog("Societe::Update echec sql=$sql");
 391                      $result =  -2;
 392                  }
 393              }
 394          }
 395  
 396          return $result;
 397  
 398      }
 399  
 400      /**
 401       *    \brief      Charge depuis la base l'objet societe
 402       *    \param      socid       Id de la société à charger en mémoire
 403       *    \param      user        Objet de l'utilisateur
 404       *    \return     int         >0 si ok, <0 si ko
 405       */
 406      function fetch($socid, $user=0)
 407      {
 408          global $langs;
 409  
 410          /* Lecture des permissions */
 411          if ($user <> 0)
 412          {
 413              $sql = "SELECT p.pread, p.pwrite, p.pperms";
 414              $sql .= " FROM ".MAIN_DB_PREFIX."societe_perms as p";
 415              $sql .= " WHERE p.fk_user = '".$user->id."'";
 416              $sql .= " AND p.fk_soc = '".$socid."';";
 417              $resql=$this->db->query($sql);
 418              if ($resql)
 419              {
 420                  if ($row = $this->db->fetch_row($resql))
 421                  {
 422                      $this->perm_read  = $row[0];
 423                      $this->perm_write = $row[1];
 424                      $this->perm_perms = $row[2];
 425                  }
 426              }
 427          }
 428  
 429          $sql = 'SELECT s.idp, s.nom, s.address,'.$this->db->pdate('s.datec').' as dc, prefix_comm';
 430          $sql .= ','. $this->db->pdate('s.tms').' as date_update';
 431          $sql .= ', s.tel, s.fax, s.url,s.cp,s.ville, s.note, s.siren, client, fournisseur';
 432          $sql .= ', s.siret, s.capital, s.ape, s.tva_intra, s.rubrique';
 433          $sql .= ', s.fk_typent as typent_id';
 434          $sql .= ', s.fk_effectif as effectif_id, e.libelle as effectif';
 435          $sql .= ', s.fk_forme_juridique as forme_juridique_code, fj.libelle as forme_juridique';
 436          $sql .= ', s.code_client, s.code_compta, s.code_fournisseur, s.parent';
 437          $sql .= ', s.fk_departement, s.fk_pays, s.fk_stcomm, s.remise_client';
 438          $sql .= ', p.code as pays_code, p.libelle as pays';
 439          $sql .= ', d.code_departement as departement_code, d.nom as departement';
 440          $sql .= ', st.libelle as stcomm';
 441          $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
 442          $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as e ON s.fk_effectif = e.id';
 443          $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON s.fk_pays = p.rowid';
 444          $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
 445          $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
 446          $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
 447          $sql .= ' WHERE s.idp = '.$socid;
 448          $resql=$this->db->query($sql);
 449          if ($resql)
 450          {
 451              if ($this->db->num_rows($resql))
 452              {
 453                  $obj = $this->db->fetch_object($resql);
 454  
 455                  $this->id = $obj->idp;
 456  
 457                  $this->date_update = $obj->date_update;
 458  
 459                  $this->nom = stripslashes($obj->nom);
 460                  $this->adresse =  stripslashes($obj->address);
 461                  $this->cp = $obj->cp;
 462                  $this->ville =  stripslashes($obj->ville);
 463                  $this->adresse_full =  stripslashes($obj->address) . "\n". $obj->cp . ' '. stripslashes($obj->ville);
 464  
 465                  $this->pays_id = $obj->fk_pays;
 466                  $this->pays_code = $obj->fk_pays?$obj->pays_code:'';
 467                  $this->pays = $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?$langs->trans('Country'.$obj->pays_code):$obj->pays):'';
 468  
 469                  $this->departement_id = $obj->fk_departement;
 470                  $this->departement= $obj->fk_departement?$obj->departement:'';
 471  
 472                  $transcode=$langs->trans('StatusProspect'.$obj->fk_stcomm);
 473                  $libelle=($transcode!='StatusProspect'.$obj->fk_stcomm?$transcode:$obj->stcomm);
 474                  $this->stcomm_id = $obj->fk_stcomm;     // id statut commercial
 475                  $this->statut_commercial = $libelle;    // libelle statut commercial
 476  
 477                  $this->url = $obj->url;
 478                  $this->tel = $obj->tel;
 479                  $this->fax = $obj->fax;
 480  
 481                  $this->parent    = $obj->parent;
 482  
 483                  $this->siren     = $obj->siren;
 484                  $this->siret     = $obj->siret;
 485                  $this->ape       = $obj->ape;
 486                  $this->capital   = $obj->capital;
 487  
 488                  $this->code_client = $obj->code_client;
 489                  $this->code_fournisseur = $obj->code_fournisseur;
 490  
 491                  if (! $this->code_client && $this->mod_codeclient->code_modifiable_null == 1)
 492                  {
 493                      $this->codeclient_modifiable = 1;
 494                  }
 495  
 496                  if (! $this->code_fournisseur && $this->mod_codefournisseur->code_modifiable_null == 1)
 497                  {
 498                      $this->codefournisseur_modifiable = 1;
 499                  }
 500  
 501                  $this->code_compta = $obj->code_compta;
 502                  $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
 503  
 504                  $this->tva_intra      = $obj->tva_intra;
 505                  $this->tva_intra_code = substr($obj->tva_intra,0,2);
 506                  $this->tva_intra_num  = substr($obj->tva_intra,2);
 507  
 508                  $this->typent_id      = $obj->typent_id;
 509                  //$this->typent         = $obj->fk_typent?$obj->typeent:'';
 510  
 511                  $this->effectif_id    = $obj->effectif_id;
 512                  $this->effectif       = $obj->effectif_id?$obj->effectif:'';
 513  
 514                  $this->forme_juridique_code= $obj->forme_juridique_code;
 515                  $this->forme_juridique     = $obj->forme_juridique_code?$obj->forme_juridique:'';
 516  
 517                  $this->prefix_comm = $obj->prefix_comm;
 518  
 519                  $this->remise_client = $obj->remise_client;
 520  
 521                  $this->client      = $obj->client;
 522                  $this->fournisseur = $obj->fournisseur;
 523  
 524                  if ($this->client == 1)
 525                  {
 526                      $this->nom_url = '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$this->id.'">'.$obj->nom.'</a>';
 527                  }
 528                  elseif($this->client == 2)
 529                  {
 530                      $this->nom_url = '<a href="'.DOL_URL_ROOT.'/comm/prospect/fiche.php?id='.$this->id.'">'.$obj->nom.'</a>';
 531                  }
 532                  else
 533                  {
 534                      $this->nom_url = '<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$this->id.'">'.$obj->nom.'</a>';
 535                  }
 536  
 537                  $this->rubrique = $obj->rubrique;
 538                  $this->note = $obj->note;
 539  
 540                  $result = 1;
 541              }
 542              else
 543              {
 544                  dolibarr_syslog('Erreur Societe::Fetch aucune societe avec id='.$this->id.' - '.$sql);
 545                  $this->error='Erreur Societe::Fetch aucune societe avec id='.$this->id.' - '.$sql;
 546                  $result = -2;
 547              }
 548  
 549              $this->db->free($resql);
 550          }
 551          else
 552          {
 553              dolibarr_syslog('Erreur Societe::Fetch echec sql='.$sql);
 554              dolibarr_syslog('Erreur Societe::Fetch '.$this->db->error());
 555              $this->error=$this->db->error();
 556              $result = -3;
 557          }
 558  
 559          return $result;
 560      }
 561  
 562      /**
 563       *    \brief      Suppression d'une societe de la base avec ses dépendances (contacts, rib...)
 564       *    \param      id      id de la societe à supprimer
 565       */
 566      function delete($id)
 567      {
 568          dolibarr_syslog("Societe::Delete");
 569          $sqr = 0;
 570  
 571          if ( $this->db->begin())
 572          {
 573              $sql = "DELETE from ".MAIN_DB_PREFIX."socpeople ";
 574              $sql .= " WHERE fk_soc = " . $id .";";
 575  
 576              if ($this->db->query($sql))
 577              {
 578                  $sqr++;
 579              }
 580              else
 581              {
 582                  $this->error .= "Impossible de supprimer les contacts.\n";
 583                  dolibarr_syslog("Societe::Delete erreur -1");
 584              }
 585  
 586              $sql = "DELETE from ".MAIN_DB_PREFIX."societe_rib ";
 587              $sql .= " WHERE fk_soc = " . $id .";";
 588  
 589              if ($this->db->query($sql))
 590              {
 591                  $sqr++;
 592              }
 593              else
 594              {
 595                  $this->error .= "Impossible de supprimer le RIB.\n";
 596                  dolibarr_syslog("Societe::Delete erreur -2");
 597              }
 598  
 599              $sql = "DELETE from ".MAIN_DB_PREFIX."societe ";
 600              $sql .= " WHERE idp = " . $id .";";
 601  
 602              if ($this->db->query($sql))
 603              {
 604                  $sqr++;
 605              }
 606              else
 607              {
 608                  $this->error .= "Impossible de supprimer la société.\n";
 609                  dolibarr_syslog("Societe::Delete erreur -3");
 610              }
 611  
 612              if ($sqr == 3)
 613              {
 614                  // Appel des triggers
 615                  include_once (DOL_DOCUMENT_ROOT . "/interfaces.class.php");
 616                  $interface=new Interfaces($this->db);
 617                  $result=$interface->run_triggers('COMPANY_DELETE',$this,$user,$langs,$conf);
 618                  // Fin appel triggers
 619  
 620                  $this->db->commit();
 621  
 622                  // Suppression du répertoire document
 623                  $docdir = $conf->societe->dir_output . "/" . $id;
 624  
 625                  if (file_exists ($docdir))
 626                  {
 627                      $this->deldir($docdir);
 628                  }
 629  
 630                  return 0;
 631              }
 632              else
 633              {
 634                  $this->db->rollback();
 635                  return -1;
 636              }
 637          }
 638  
 639      }
 640  
 641      /**
 642       *    \brief      Cette fonction permet de supprimer le répertoire de la societe
 643       *                et sous répertoire, meme s'ils contiennent des documents.
 644       *    \param      dir     repertoire a supprimer
 645       */
 646      function deldir($dir)
 647      {
 648          $current_dir = opendir($dir);
 649  
 650          while($entryname = readdir($current_dir))
 651          {
 652              if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!=".."))
 653              {
 654                  deldir("$dir}/$entryname}");
 655              }
 656              elseif($entryname != "." and $entryname!="..")
 657              {
 658                  unlink("$dir}/$entryname}");
 659              }
 660          }
 661          closedir($current_dir);
 662          rmdir($dir});
 663      }
 664  
 665    /**
 666     *    \brief     Retournes les factures impayées de la société
 667     *    \return    array   tableau des id de factures impayées
 668     *
 669     */
 670    function factures_impayes()
 671    {
 672      $facimp = array();
 673      /*
 674       * Lignes
 675       */
 676      $sql = "SELECT f.rowid";
 677      $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = '".$this->id . "'";
 678      $sql .= " AND f.fk_statut = '1' AND f.paye = '0'";
 679  
 680      if ($this->db->query($sql))
 681        {
 682      $num = $this->db->num_rows();
 683      $i = 0;
 684  
 685      while ($i < $num)
 686        {
 687          $objp = $this->db->fetch_object();
 688          $array_push($facimp, $objp->rowid);
 689          $i++;
 690          print $i;
 691        }
 692  
 693      $this->db->free();
 694        }
 695      return $facimp;
 696    }
 697  
 698    /**
 699     *    \brief      Attribut le prefix de la société en base
 700     *
 701     */
 702    function attribute_prefix()
 703    {
 704      $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE idp = '$this->id'";
 705      if ( $this->db->query( $sql) )
 706        {
 707      if ( $this->db->num_rows() )
 708        {
 709          $nom = preg_replace("/[[:punct:]]/","",$this->db->result(0,0));
 710          $this->db->free();
 711  
 712          $prefix = $this->genprefix($nom,4);
 713  
 714          $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."societe WHERE prefix_comm = '$prefix'";
 715          if ( $this->db->query( $sql) )
 716            {
 717          if ( $this->db->result(0, 0) )
 718            {
 719              $this->db->free();
 720            }
 721          else
 722            {
 723              $this->db->free();
 724  
 725              $sql = "UPDATE ".MAIN_DB_PREFIX."societe set prefix_comm='$prefix' WHERE idp='$this->id'";
 726  
 727              if ( $this->db->query( $sql) )
 728                {
 729  
 730                }
 731              else
 732                {
 733              dolibarr_print_error($this->db);
 734                }
 735            }
 736            }
 737          else
 738            {
 739              dolibarr_print_error($this->db);
 740            }
 741        }
 742        }
 743      else
 744        {
 745      dolibarr_print_error($this->db);
 746        }
 747      return $prefix;
 748    }
 749  
 750    /**
 751     *    \brief      Génère le préfix de la société
 752     *    \param      nom         nom de la société
 753     *    \param      taille      taille du prefix à retourner
 754     *    \param      mot         l'indice du mot à utiliser
 755     *
 756     */
 757    function genprefix($nom, $taille=4,$mot=0)
 758    {
 759      $retour = "";
 760      $tab = explode(" ",$nom);
 761      if($mot < count($tab)) {
 762        $prefix = strtoupper(substr($tab[$mot],0,$taille));
 763        //On vérifie que ce prefix n'a pas déjà été pris ...
 764        $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."societe WHERE prefix_comm = '$prefix'";
 765        if ( $this->db->query( $sql) )
 766      {
 767        if ( $this->db->result(0, 0) )
 768          {
 769            $this->db->free();
 770            $retour = $this->genprefix($nom,$taille,$mot+1);
 771          }
 772        else
 773          {
 774            $retour = $prefix;
 775          }
 776      }
 777      }
 778      return $retour;
 779    }
 780  
 781    /**
 782     *    \brief     Définit la société comme un client
 783     *
 784     */
 785    function set_as_client()
 786    {
 787      if ($this->id)
 788        {
 789      $sql  = "UPDATE ".MAIN_DB_PREFIX."societe ";
 790      $sql .= " SET client = 1";
 791      $sql .= " WHERE idp = " . $this->id .";";
 792  
 793      return $this->db->query($sql);
 794        }
 795    }
 796  
 797    /**
 798     *    \brief      Définit la société comme un client
 799     *    \param      remise      montant de la remise
 800     *    \param      user        utilisateur qui place la remise
 801     */
 802    function set_remise_client($remise, $user)
 803    {
 804      if ($this->id)
 805        {
 806      $sql  = "UPDATE ".MAIN_DB_PREFIX."societe ";
 807      $sql .= " SET remise_client = '".$remise."'";
 808      $sql .= " WHERE idp = " . $this->id .";";
 809  
 810      $this->db->query($sql);
 811  
 812      $sql  = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise ";
 813      $sql .= " ( datec, fk_soc, remise_client, fk_user_author )";
 814      $sql .= " VALUES (now(),".$this->id.",'".$remise."',".$user->id.")";
 815  
 816      if (! $this->db->query($sql) )
 817        {
 818          dolibarr_print_error($this->db);
 819        }
 820  
 821        }
 822    }
 823  
 824    /**
 825     *    \brief      Définit la société comme un client
 826     *    \param      remise      montant de la remise
 827     *    \param      user        utilisateur qui place la remise
 828     *
 829     */
 830    function set_remise_except($remise, $user)
 831    {
 832      if ($this->id)
 833        {
 834      $remise = ereg_replace(",",".",$remise);
 835  
 836      $sql  = "DELETE FROM  ".MAIN_DB_PREFIX."societe_remise_except ";
 837      $sql .= " WHERE fk_soc = " . $this->id ." AND fk_facture IS NULL;";
 838  
 839      $this->db->query($sql);
 840  
 841      $sql  = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except ";
 842      $sql .= " ( datec, fk_soc, amount_ht, fk_user )";
 843      $sql .= " VALUES (now(),".$this->id.",'".$remise."',".$user->id.")";
 844  
 845      if (! $this->db->query($sql) )
 846        {
 847          dolibarr_print_error($this->db);
 848        }
 849  
 850        }
 851    }
 852  
 853    /**
 854     *
 855     *
 856     */
 857    function add_commercial($user, $commid)
 858    {
 859      if ($this->id > 0 && $commid > 0)
 860        {
 861      $sql  = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux ";
 862      $sql .= " WHERE fk_soc = " . $this->id ." AND fk_user =".$commid;
 863  
 864      $this->db->query($sql);
 865  
 866      $sql  = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux ";
 867      $sql .= " ( fk_soc, fk_user )";
 868      $sql .= " VALUES (".$this->id.",".$commid.")";
 869  
 870      if (! $this->db->query($sql) )
 871        {
 872          dolibarr_syslog("Societe::add_commercial Erreur");
 873        }
 874  
 875        }
 876    }
 877  
 878    /**
 879     *
 880     *
 881     *
 882     */
 883    function del_commercial($user, $commid)
 884    {
 885      if ($this->id > 0 && $commid > 0)
 886        {
 887      $sql  = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux ";
 888      $sql .= " WHERE fk_soc = " . $this->id ." AND fk_user =".$commid;
 889  
 890      if (! $this->db->query($sql) )
 891        {
 892          dolibarr_syslog("Societe::del_commercial Erreur");
 893        }
 894  
 895        }
 896    }
 897  
 898    /**
 899     *    \brief      Renvoie le nom d'une societe a partir d'un id
 900     *    \param      id      id de la société recherchée
 901     *
 902     */
 903    function get_nom($id)
 904    {
 905  
 906      $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE idp='$id';";
 907  
 908      $result = $this->db->query($sql);
 909  
 910      if ($result)
 911        {
 912          if ($this->db->num_rows())
 913            {
 914              $obj = $this->db->fetch_object($result);
 915              return $obj->nom;
 916            }
 917          $this->db->free();
 918        }
 919      else {
 920        dolibarr_print_error($this->db);
 921      }
 922  
 923    }
 924  
 925    /**
 926     *    \brief      Renvoie la liste des contacts emails existant pour la société
 927     *    \return     array       tableau des contacts emails
 928     */
 929    function contact_email_array()
 930    {
 931      $contact_email = array();
 932  
 933      $sql = "SELECT idp, email, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = '$this->id'";
 934  
 935      if ($this->db->query($sql) )
 936        {
 937      $nump = $this->db->num_rows();
 938  
 939      if ($nump)
 940        {
 941          $i = 0;
 942          while ($i < $nump)
 943            {
 944          $obj = $this->db->fetch_object();
 945  
 946          $contact_email[$obj->idp] = "$obj->firstname $obj->name &lt;$obj->email&gt;";
 947          $i++;
 948            }
 949        }
 950      return $contact_email;
 951        }
 952      else
 953        {
 954      dolibarr_print_error($this->db);
 955        }
 956  
 957    }
 958  
 959    /**
 960     *    \brief      Renvoie la liste des contacts de cette société
 961     *    \return     array      tableau des contacts
 962     */
 963    function contact_array()
 964    {
 965      $contacts = array();
 966  
 967      $sql = "SELECT idp, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = '$this->id'";
 968  
 969      if ($this->db->query($sql) )
 970        {
 971      $nump = $this->db->num_rows();
 972  
 973      if ($nump)
 974        {
 975          $i = 0;
 976          while ($i < $nump)
 977            {
 978          $obj = $this->db->fetch_object();
 979  
 980          $contacts[$obj->idp] = "$obj->firstname $obj->name";
 981          $i++;
 982            }
 983        }
 984      return $contacts;
 985        }
 986      else
 987        {
 988      dolibarr_print_error($this->db);
 989        }
 990  
 991    }
 992  
 993      /**
 994       *    \brief      Renvoie l'email d'un contact par son id
 995       *    \param      rowid       id du contact
 996       *    \return     string      email du contact
 997       */
 998      function contact_get_email($rowid)
 999      {
1000  
1001          $sql = "SELECT idp, email, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE idp = '$rowid'";
1002  
1003          if ($this->db->query($sql) )
1004          {
1005              $nump = $this->db->num_rows();
1006  
1007              if ($nump)
1008              {
1009  
1010                  $obj = $this->db->fetch_object();
1011  
1012                  $contact_email = "$obj->firstname $obj->name <$obj->email>";
1013  
1014              }
1015              return $contact_email;
1016          }
1017          else
1018          {
1019              dolibarr_print_error($this->db);
1020          }
1021  
1022      }
1023  
1024  
1025      /**
1026       *    \brief      Renvoie la liste des libellés traduits types actifs de sociétés
1027       *    \return     array      tableau des types
1028       */
1029      function typent_array()
1030      {
1031          global $langs;
1032  
1033          $effs = array();
1034  
1035          $sql  = "SELECT id, code, libelle";
1036          $sql .= " FROM ".MAIN_DB_PREFIX."c_typent";
1037          $sql .= " WHERE active = 1";
1038          $sql .= " ORDER by id";
1039          $result=$this->db->query($sql);
1040          if ($result)
1041          {
1042              $num = $this->db->num_rows($result);
1043              $i = 0;
1044  
1045              while ($i < $num)
1046              {
1047                  $objp = $this->db->fetch_object($result);
1048                  if ($langs->trans($objp->code) != $objp->code)
1049                      $effs[$objp->id] = $langs->trans($objp->code);
1050                  else
1051                      $effs[$objp->id] = $objp->libelle!='-'?$objp->libelle:'';
1052                  $i++;
1053              }
1054              $this->db->free($result);
1055          }
1056  
1057          return $effs;
1058      }
1059  
1060  
1061      /**
1062       *    \brief      Renvoie la liste des types d'effectifs possibles (pas de traduction car nombre)
1063       *    \return     array      tableau des types d'effectifs
1064       */
1065      function effectif_array()
1066      {
1067          $effs = array();
1068  
1069          $sql = "SELECT id, libelle";
1070          $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif";
1071          $sql .= " ORDER BY id ASC";
1072          if ($this->db->query($sql))
1073          {
1074              $num = $this->db->num_rows();
1075              $i = 0;
1076  
1077              while ($i < $num)
1078              {
1079                  $objp = $this->db->fetch_object();
1080                  $effs[$objp->id] = $objp->libelle!='-'?$objp->libelle:'';
1081                  $i++;
1082              }
1083              $this->db->free();
1084          }
1085          return $effs;
1086      }
1087  
1088      /**
1089       *    \brief      Renvoie la liste des formes juridiques existantes (pas de traduction car unique au pays)
1090       *    \return     array      tableau des formes juridiques
1091       */
1092      function forme_juridique_array()
1093      {
1094          $fj = array();
1095  
1096          $sql = "SELECT code, libelle";
1097          $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique";
1098          $sql .= " ORDER BY code ASC";
1099          if ($this->db->query($sql))
1100          {
1101              $num = $this->db->num_rows();
1102              $i = 0;
1103  
1104              while ($i < $num)
1105              {
1106                  $objp = $this->db->fetch_object();
1107                  $fj[$objp->code] = $objp->libelle!='-'?$objp->libelle:'';
1108                  $i++;
1109              }
1110              $this->db->free();
1111          }
1112          return $fj;
1113      }
1114  
1115  
1116    /**
1117     *    \brief      Affiche le rib
1118     */
1119    function display_rib()
1120    {
1121      global $langs;
1122  
1123      require_once  DOL_DOCUMENT_ROOT . "/companybankaccount.class.php";
1124  
1125      $bac = new CompanyBankAccount($this->db, $this->id);
1126      $bac->fetch();
1127  
1128      if ($bac->code_banque || $bac->code_guichet || $bac->number || $bac->cle_rib)
1129      {
1130          $rib = $bac->code_banque." ".$bac->code_guichet." ".$bac->number." (".$bac->cle_rib.")";
1131      }
1132      else
1133      {
1134          $rib=$langs->trans("NoRIB");
1135      }
1136      return $rib;
1137    }
1138  
1139  
1140    function rib()
1141    {
1142      require_once  DOL_DOCUMENT_ROOT . "/companybankaccount.class.php";
1143  
1144      $bac = new CompanyBankAccount($this->db, $this->id);
1145      $bac->fetch();
1146  
1147      $this->bank_account = $bac;
1148  
1149      return 1;
1150    }
1151  
1152  
1153    function verif_rib()
1154    {
1155      $this->rib();
1156      return $this->bank_account->verif();
1157    }
1158  
1159    /**
1160     *    \brief      Verifie code client
1161     *    \return     Renvoie 0 si ok, peut modifier le code client suivant le module utilisé
1162     */
1163    function verif_codeclient()
1164    {
1165      if (defined('CODECLIENT_ADDON') && strlen(CODECLIENT_ADDON) > 0)
1166        {
1167  
1168      require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.CODECLIENT_ADDON.'.php';
1169  
1170      $var = CODECLIENT_ADDON;
1171  
1172      $mod = new $var;
1173  
1174      return $mod->verif($this->db, $this->code_client, $this->id);
1175        }
1176      else
1177        {
1178      return 0;
1179        }
1180    }
1181  
1182    function check_codeclient()
1183    {
1184      if (defined('CODECLIENT_ADDON') && strlen(CODECLIENT_ADDON) > 0)
1185        {
1186  
1187      require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.CODECLIENT_ADDON.'.php';
1188  
1189      $var = CODECLIENT_ADDON;
1190  
1191      $mod = new $var;
1192  
1193      return $mod->verif($this->db, $this->code_client);
1194        }
1195      else
1196        {
1197      return 0;
1198        }
1199    }
1200  
1201    function check_codefournisseur()
1202    {
1203      if (defined('CODEFOURNISSEUR_ADDON') && strlen(CODEFOURNISSEUR_ADDON) > 0)
1204        {
1205  
1206      require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.CODEFOURNISSEUR_ADDON.'.php';
1207  
1208      $var = CODEFOURNISSEUR_ADDON;
1209  
1210      $mod = new $var;
1211  
1212      return $mod->verif($this->db, $this->code_fournisseur);
1213        }
1214      else
1215        {
1216      return 0;
1217        }
1218    }
1219  
1220    /**
1221     *    \brief  Renvoie un code compta, suivant le module le code compta renvoyé
1222     *            peut être identique à celui saisit ou généré automatiquement
1223     *
1224     *            A ce jour seul la génération automatique est implémentée
1225     */
1226    function check_codecompta_client()
1227    {
1228      if (defined('CODECOMPTA_ADDON') && strlen(CODECOMPTA_ADDON) > 0)
1229      {
1230          require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.CODECOMPTA_ADDON.'.php';
1231  
1232          $var = CODECOMPTA_ADDON;
1233  
1234          $mod = new $var;
1235  
1236          $result = $mod->get_code($this->db, $this);
1237  
1238          $this->code_compta = $mod->code;
1239  
1240          return $result;
1241      }
1242      else
1243      {
1244          $this->code_compta = '';
1245          return 0;
1246      }
1247    }
1248  
1249  
1250    /**
1251     *    \brief  Renvoie un code compta, suivant le module le code compta renvoyé
1252     *            peut être identique à celui saisit ou généré automatiquement
1253     *
1254     *            A ce jour seul la génération automatique est implémentée
1255     */
1256    function check_codecompta_fournisseur()
1257    {
1258      if (defined('CODECOMPTAFOURN_ADDON') && strlen(CODECOMPTAFOURN_ADDON) > 0)
1259      {
1260          require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.CODECOMPTAFOURN_ADDON.'.php';
1261  
1262          $var = CODECOMPTAFOURN_ADDON;
1263  
1264          $mod = new $var;
1265  
1266          $result = $mod->get_code($this->db, $this);
1267  
1268          $this->code_compta_fournisseur = $mod->code;
1269  
1270          return $result;
1271      }
1272      else
1273      {
1274          $this->code_compta = '';
1275          return 0;
1276      }
1277    }
1278  
1279  
1280      /**
1281       *    \brief      Défini la société mère pour les filiales
1282       *    \param      id      id compagnie mère à positionner
1283       *    \return     int     <0 si ko, >0 si ok
1284       */
1285      function set_parent($id)
1286      {
1287          if ($this->id)
1288          {
1289              $sql  = "UPDATE ".MAIN_DB_PREFIX."societe ";
1290              $sql .= " SET parent = ".$id;
1291              $sql .= " WHERE idp = " . $this->id .";";
1292  
1293              if ( $this->db->query($sql) )
1294              {
1295                  return 1;
1296              }
1297              else
1298              {
1299                  return -1;
1300              }
1301          }
1302      }
1303  
1304      /**
1305       *    \brief      Supprime la société mère
1306       *    \param      id      id compagnie mère à effacer
1307       *    \return     int     <0 si ko, >0 si ok
1308       */
1309      function remove_parent($id)
1310      {
1311          if ($this->id)
1312          {
1313              $sql  = "UPDATE ".MAIN_DB_PREFIX."societe ";
1314              $sql .= " SET parent = null";
1315              $sql .= " WHERE idp = " . $this->id .";";
1316  
1317              if ( $this->db->query($sql) )
1318              {
1319                  return 1;
1320              }
1321              else
1322              {
1323                  return -1;
1324              }
1325          }
1326      }
1327  
1328      /**
1329       *      \brief      Verifie la validite d'un identifiant professionnel en
1330       *                  fonction du pays de la societe (siren, siret, ...)
1331       *      \param      idprof          1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
1332       *      \param      soc             Objet societe
1333       *      \return     int             <0 si ko, >0 si ok
1334       */
1335      function id_prof_check($idprof,$soc)
1336      {
1337          $ok=1;
1338  
1339          // Verifie SIREN si pays FR
1340          if ($idprof == 1 && $soc->pays_code == 'FR')
1341          {
1342              $chaine=trim($this->siren);
1343              $chaine=eregi_replace(' ','',$chaine);
1344  
1345              if (strlen($chaine) != 9) return -1;
1346  
1347              $sum = 0;
1348  
1349              for ($i = 0 ; $i < 10 ; $i = $i+2)
1350              {
1351                  $sum = $sum + substr($this->siren, (8 - $i), 1);
1352              }
1353  
1354              for ($i = 1 ; $i < 9 ; $i = $i+2)
1355              {
1356                  $ps = 2 * substr($this->siren, (8 - $i), 1);
1357  
1358                  if ($ps > 9)
1359                  {
1360                      $ps = substr($ps, 0,1) + substr($ps, 1 ,1);
1361                  }
1362                  $sum = $sum + $ps;
1363              }
1364  
1365              if (substr($sum, -1) != 0) return -1;
1366          }
1367  
1368          // Verifie SIRET si pays FR
1369          if ($idprof == 2 && $soc->pays_code == 'FR')
1370          {
1371              $chaine=trim($this->siret);
1372              $chaine=eregi_replace(' ','',$chaine);
1373  
1374              if (strlen($chaine) != 14) return -1;
1375          }
1376  
1377          return $ok;
1378      }
1379  
1380      /**
1381       *      \brief      Renvoi url de vérification d'un identifiant professionnal
1382       *      \param      idprof          1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
1383       *      \param      soc             Objet societe
1384       *      \return     string          url ou chaine vide si aucune url connue
1385       */
1386      function id_prof_url($idprof,$soc)
1387      {
1388          global $langs;
1389  
1390          $url='';
1391          if ($idprof == 1 && $soc->pays_code == 'FR') $url='http://www.societe.com/cgi-bin/recherche?rncs='.$soc->siren;
1392          if ($idprof == 1 && $soc->pays_code == 'GB') $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/';
1393  
1394          if ($url) return '<a target="_blank" href="'.$url.'">['.$langs->trans("Check").']</a>';
1395          return '';
1396      }
1397  
1398      /**
1399       *      \brief      Indique si la société a des projets
1400       *      \return     bool       true si la société a des projets, false sinon
1401       */
1402      function has_projects()
1403      {
1404          $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;
1405          $resql = $this->db->query($sql);
1406          if ($resql)
1407          {
1408              $nump = $this->db->num_rows($resql);
1409              $obj = $this->db->fetch_object();
1410              $count = $obj->numproj;
1411          }
1412          else
1413          {
1414              $count = 0;
1415              print $this->db->error();
1416          }
1417          $this->db->free($resql);
1418          return ($count > 0);
1419      }
1420  
1421  
1422      function AddPerms($user_id, $read, $write, $perms)
1423      {
1424          $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_perms";
1425          $sql .= " (fk_soc, fk_user, pread, pwrite, pperms) ";
1426          $sql .= " VALUES (".$this->id.",".$user_id.",".$read.",".$write.",".$perms.");";
1427  
1428          $resql=$this->db->query($sql);
1429          if ($resql)
1430          {
1431  
1432          }
1433      }
1434  
1435     /*
1436      *       \brief     Charge les informations d'ordre info dans l'objet societe
1437      *       \param     id     id de la societe a charger
1438      */
1439      function info($id)
1440      {
1441          $sql = "SELECT s.idp, s.nom, ".$this->db->pdate("datec")." as datec, ".$this->db->pdate("datea")." as datea,";
1442          $sql.= " fk_user_creat, fk_user_modif";
1443          $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
1444          $sql.= " WHERE s.idp = ".$id;
1445  
1446          $result=$this->db->query($sql);
1447          if ($result)
1448          {
1449              if ($this->db->num_rows($result))
1450              {
1451                  $obj = $this->db->fetch_object($result);
1452  
1453                  $this->id = $obj->idp;
1454  
1455                  if ($obj->fk_user_creat) {
1456                      $cuser = new User($this->db, $obj->fk_user_creat);
1457                      $cuser->fetch();
1458                      $this->user_creation     = $cuser;
1459                  }
1460  
1461                  if ($obj->fk_user_modif) {
1462                      $muser = new User($this->db, $obj->fk_user_modif);
1463                      $muser->fetch();
1464                      $this->user_modification = $muser;
1465                  }
1466                  $this->ref                 = $obj->nom;
1467                  $this->date_creation     = $obj->datec;
1468                  $this->date_modification = $obj->datea;
1469              }
1470  
1471              $this->db->free($result);
1472  
1473          }
1474          else
1475          {
1476              dolibarr_print_error($this->db);
1477          }
1478      }
1479  
1480  }
1481  
1482  ?>


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