[ 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/fournisseur/commande/ -> commande.textp.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: commande.textp.class.php,v 1.3 2005/06/15 14:02:08 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/fournisseur/commande/commande.textp.class.php,v $
  20   *
  21   * Classe de commande de ligne au format Texte
  22   *
  23   *
  24   */
  25  require_once DOL_DOCUMENT_ROOT."/lib/dolibarrmail.class.php";
  26  require_once DOL_DOCUMENT_ROOT."/telephonie/fournisseur/commande/methode.commande.class.php";
  27  
  28  define ('COMMANDETEXT_NOEMAIL', -3);
  29  
  30  class CommandeMethodeTextP extends CommandeMethode
  31  {
  32  
  33    function CommandeMethodeTextP ($DB, $USER=0, $fourn=0)
  34    {
  35      $this->nom = "Méthode texte, variante sur le nom de fichier";
  36      $this->db = $DB;
  37      $this->user = $USER;
  38      $this->fourn = $fourn;
  39    }
  40  
  41    function info()
  42    {
  43      return "Envoi un fichier texte contenant la liste des lignes à commander";
  44    }
  45  
  46    function Create()
  47    {
  48      $this->date = time();
  49  
  50      $this->datef = "ndi-premium-".strftime("%d%b%y-%HH%M", $this->date);
  51  
  52      $this->filename = $this->datef.".txt";
  53  
  54      $fname = DOL_DATA_ROOT ."/telephonie/ligne/commande/".$this->filename;
  55  
  56      if (strlen(trim($this->fourn->email_commande)) == 0)
  57        {
  58      return -3;
  59        }
  60  
  61      if (file_exists($fname))
  62        {
  63      return 2;
  64        }
  65      else
  66        {
  67      $res = $this->CreateFile($fname);
  68  
  69      if ($res == 0)
  70        {
  71          $res = $res + $this->LogSql();
  72          $res = $res + $this->MailFile($fname);
  73        }
  74  
  75      return $res;
  76        }
  77    }
  78    /**
  79     *
  80     *
  81     */
  82    function MailFile($filename)
  83    {
  84      $subject = "Commande de Lignes Numero : ".$this->commande_id;
  85  
  86      $sendto = $this->fourn->email_commande;
  87  
  88      $from = TELEPHONIE_LIGNE_COMMANDE_EMAIL_BCC;
  89  
  90      $message = "Bonjour,\n\nVeuillez trouver ci-joint notre commande num : ".$this->commande_id.".\n\n";
  91      $message .= "\n\nCordialement,\n\n";
  92  
  93      $message .= "-- \n";
  94      $message .= $this->user->fullname."\n";
  95  
  96  
  97      $mailfile = new DolibarrMail($subject,
  98                   $sendto,
  99                   $from,
 100                   $message);
 101  
 102      $mailfile->addr_bcc = TELEPHONIE_LIGNE_COMMANDE_EMAIL_BCC;
 103  
 104      $mailfile->PrepareFile(array($filename),
 105                 array("plain/text"),
 106                 array($this->datef.".txt"));
 107  
 108      if ( $mailfile->sendfile() )
 109        {
 110      return 0;
 111        }
 112  
 113    }
 114  
 115    /**
 116     * Creation du fichier
 117     *
 118     */
 119  
 120    function CreateFile($fname)
 121    {
 122      $fp = fopen($fname, "w");
 123  
 124      if ($fp)
 125        {
 126      fwrite ($fp, "Numcli;");
 127      fwrite ($fp, "nomclient;");
 128      fwrite ($fp, "NDI\n");
 129  
 130      $this->ligneids = array();
 131      
 132      $sqlall = "SELECT s.nom, s.idp as socid, l.ligne, l.statut, l.rowid";
 133      $sqlall .= " , comm.name, comm.firstname";
 134      
 135      $sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s";
 136      $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
 137      $sqlall .= " , ".MAIN_DB_PREFIX."user as comm";
 138      $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
 139  
 140      $sqlall .= " WHERE l.fk_soc = s.idp AND l.fk_fournisseur = f.rowid";
 141  
 142      $sqlall .= " AND l.fk_commercial = comm.rowid ";
 143      $sqlall .= " AND f.rowid =".$this->fourn->id;
 144      /*
 145       *
 146       */
 147      $sql = $sqlall;
 148      
 149      $sql .= " AND l.statut in (1,4,8)";
 150      $sql .= " ORDER BY l.statut ASC";
 151      
 152      $resql = $this->db->query($sql);
 153  
 154      if ($resql)
 155        {
 156          $i = 0;
 157          $num = $this->db->num_rows($resql);
 158          
 159          while ($i < $num)
 160            {
 161          $obj = $this->db->fetch_object($resql);    
 162          
 163          if (strlen($obj->ligne)== 10)
 164            {            
 165              $soc = new Societe($this->db);
 166              $soc->fetch($obj->socid);
 167              
 168              fwrite ($fp, $this->fourn->num_client);
 169              fwrite ($fp, ";");
 170              fwrite ($fp, $obj->nom);
 171              fwrite ($fp, ";");
 172              fwrite ($fp, $obj->ligne);
 173              fwrite ($fp, "\n");
 174              
 175              array_push($this->ligneids, $obj->rowid);
 176            }
 177          $i++;
 178            }
 179          
 180          $this->db->free($resql);
 181        }
 182      else 
 183        {
 184          print $this->db->error() . ' ' . $sql;
 185        }
 186  
 187      fclose($fp);
 188      
 189      /*
 190       *
 191       *
 192       */
 193      
 194      foreach ($this->ligneids as $lid)
 195        {
 196          
 197          $lint = new LigneTel($this->db);
 198          $lint->fetch_by_id($lid);
 199          if ($lint->statut == 1)
 200            {
 201          $lint->set_statut($this->user, 2);
 202            }
 203          if ($lint->statut == 4)
 204            {
 205          $lint->set_statut($this->user, 5);
 206            }
 207          if ($lint->statut == 8)
 208            {
 209          $lint->set_statut($this->user, 2);
 210            }
 211        }
 212      
 213      return 0;
 214      
 215        }
 216      else
 217        {
 218      return -1;
 219        }
 220    }
 221  }


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