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

   1  <?PHP
   2  /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * 
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   *
  18   * $Id: ligneadsl.class.php,v 1.1 2005/03/23 16:39:37 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/adsl/ligneadsl.class.php,v $
  20   *
  21   */
  22  
  23  class LigneAdsl {
  24    var $db;
  25  
  26    var $id;
  27    var $ligne;
  28  
  29    function LigneAdsl($DB, $id=0)
  30    {
  31      global $config;
  32      $this->id = $id;
  33  
  34      $this->db = $DB;
  35      $this->error_message = '';
  36      $this->statuts[-1] = "En attente";
  37      $this->statuts[1] = "A commander";
  38      $this->statuts[2] = "Commandée chez le fournisseur";
  39      $this->statuts[3] = "Activée chez le fournisseur";
  40      $this->statuts[4] = "Installée chez le client";
  41      $this->statuts[5] = "A résilier";
  42      $this->statuts[6] = "Résiliation demandée";
  43      $this->statuts[7] = "Résiliée";
  44      $this->statuts[8] = "Rejetée";
  45  
  46      return 1;
  47    }
  48    /*
  49     *
  50     *
  51     */
  52    function update($user)
  53    {
  54  
  55      $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne";
  56      $sql .= " SET ";
  57      $sql .= " fk_client_comm = $this->client_comm, ";
  58      $sql .= " fk_soc = $this->client, ";
  59      $sql .= " ligne = '$this->numero', ";
  60      $sql .= " fk_soc_facture = $this->client_facture, ";
  61      $sql .= " fk_fournisseur = $this->fournisseur, ";
  62      $sql .= " fk_commercial = $this->commercial, ";
  63      $sql .= " fk_concurrent = $this->concurrent, ";
  64      $sql .= " note =  '$this->note',";
  65      $sql .= " remise = '$this->remise'";
  66      $sql .= " WHERE rowid = $this->id";
  67  
  68      if ( $this->db->query($sql) )
  69        {
  70      return 1;
  71        }
  72      else
  73        {
  74      print $this->db->error();
  75      print $sql ;
  76      return 0;
  77        }
  78    }
  79  
  80    /*
  81     *
  82     *
  83     */
  84    function create($user)
  85    {
  86      if (strlen(trim($this->numero)) == 10)
  87        {
  88      $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_adsl_ligne";
  89      $sql .= " (fk_client, fk_client_install, fk_client_facture, numero_ligne, fk_type, fk_fournisseur, note, fk_commercial, statut, fk_user_creat)";
  90      $sql .= " VALUES (";
  91      $sql .= " $this->client,$this->client_install,$this->client_facture,'$this->numero',$this->type,$this->fournisseur, '$this->note',$this->commercial, -1,$user->id)";
  92      
  93      if ( $this->db->query($sql) )
  94        {
  95          $this->id = $this->db->last_insert_id();
  96          return 0;
  97        }
  98      else
  99        {
 100          $lex = new LigneAdsl($this->db);
 101          if ($lex->fetch($this->numero) == 1)
 102            {
 103          $this->error_message = "Echec de la création de la ligne, cette ligne existe déjà !";
 104          dolibarr_syslog("LigneAdsl::Create Error -3");
 105          return -3;
 106            }
 107          else
 108            {
 109          $this->error_message = "Echec de la création de la ligne";
 110          dolibarr_syslog("LigneAdsl::Create Error -1");
 111          dolibarr_syslog("LigneAdsl::Create $sql");
 112          return -1;
 113            }
 114        }
 115        }
 116      else
 117        {
 118      $this->error_message = "Echec de la création de la ligne, le numéro de la ligne est incorrect !";
 119      dolibarr_syslog("LigneAdsl::Create Error -2");
 120      return -2;
 121        }
 122    }
 123    /*
 124     *
 125     *
 126     */
 127    function fetch_by_id($id)
 128    {
 129      return $this->fetch(0, $id);
 130    }
 131  
 132    function delete($id)
 133      {
 134        $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_adsl_ligne_statut";
 135        $sql .= " WHERE fk_ligne = ".$id;
 136  
 137        if ($this->db->query($sql))
 138      {
 139  
 140        $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_adsl_ligne";
 141        $sql .= " WHERE rowid = ".$id;
 142        
 143        if ($this->db->query($sql))
 144          {
 145            return 0;
 146          }
 147        else
 148          {
 149            dolibarr_syslog("LigneAdsl::Delete Error -1");
 150            return -1;
 151          }
 152      }
 153        else
 154      {
 155        dolibarr_syslog("LigneAdsl::Delete Error -2");
 156        return -2;
 157      }
 158      }
 159  
 160    function fetch($ligne, $id = 0)
 161      {
 162        $sql = "SELECT l.rowid, l.fk_client, l.fk_client_install, l.fk_client_facture, l.fk_fournisseur, l.numero_ligne, l.note, l.statut, l.fk_commercial";
 163        $sql .= ", l.ip, l.login, l.password";
 164        $sql .= " , t.intitule AS type";
 165        $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_adsl_ligne as l";
 166        $sql .= " , ".MAIN_DB_PREFIX."telephonie_adsl_type as t";
 167        $sql .= " WHERE t.rowid = l.fk_type";
 168  
 169        if ($id > 0)
 170      {
 171        $sql .= " AND l.rowid = ".$id;
 172      }
 173        else    
 174      {
 175        $sql .= " AND l.numero_ligne = ".$ligne;
 176      }
 177  
 178        if ($this->db->query($sql))
 179      {
 180        if ($this->db->num_rows())
 181          {
 182            $obj = $this->db->fetch_object();
 183  
 184            $this->id = $obj->rowid;
 185            $this->socid             = $obj->fk_soc;
 186            $this->numero            = $obj->numero_ligne;
 187            $this->remise            = $obj->remise;
 188            $this->client_id         = $obj->fk_client;
 189            $this->client_install_id = $obj->fk_client_install;
 190            $this->client_facture_id = $obj->fk_client_facture;
 191            $this->fournisseur_id    = $obj->fk_fournisseur;
 192            $this->commercial_id     = $obj->fk_commercial;
 193            $this->type              = $obj->type;
 194            $this->statut            = $obj->statut;
 195  
 196            $this->ip                = $obj->ip;
 197            $this->login             = $obj->login;
 198            $this->password          = $obj->password;
 199  
 200            $this->mode_paiement  = 'pre';
 201  
 202            $result = 1;
 203          }
 204        else
 205          {
 206            $result = -2;
 207          }
 208  
 209        $this->db->free();
 210      }
 211        else
 212      {
 213        /* Erreur select SQL */
 214        print $this->db->error();
 215        $result = -1;
 216      }
 217  
 218        return $result;
 219    }
 220  
 221    /**
 222     *
 223     *
 224     *
 225     */
 226  
 227    function update_info($ip, $login, $password)
 228    {
 229      $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_adsl_ligne";
 230      $sql .= " SET ip     = '".$ip ."'";
 231      $sql .= " , login    = '".$login."'" ;
 232      $sql .= " , password = '".$password."'" ;
 233  
 234      $sql .= " WHERE rowid =".$this->id;
 235      
 236      $this->db->query($sql);    
 237    }
 238  
 239    /**
 240     * Change le statut de la ligne
 241     *
 242     */
 243    function set_statut($user, $statut, $datea='', $commentaire='')
 244    {
 245      $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_adsl_ligne";
 246      $sql .= " SET statut = ".$statut ;
 247  
 248      $sql .= " WHERE rowid =".$this->id;
 249      
 250      $this->db->query($sql);
 251      
 252      if ($datea <> '')
 253        {
 254      $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_adsl_ligne_statut";
 255      $sql .= " (tms,fk_ligne, fk_user, statut, comment) ";
 256      $sql .= " VALUES ($datea,$this->id, $user->id, $statut, '$commentaire' )";
 257  
 258      $this->db->query($sql);
 259        }
 260      else
 261        {
 262      $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_adsl_ligne_statut";
 263      $sql .= " (tms, fk_ligne, fk_user, statut, comment) ";
 264      $sql .= " VALUES (now(), $this->id, $user->id, $statut, '$commentaire' )";
 265  
 266      $this->db->query($sql);
 267        }
 268  
 269      return 0;
 270    }
 271  
 272  }
 273  ?>


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