[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/scripts/ -> mailing-send.php (source)

   1  #!/usr/bin/php
   2  <?PHP
   3  /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   4   * Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   5   *
   6   * This program is free software; you can redistribute it and/or modify
   7   * it under the terms of the GNU General Public License as published by
   8   * the Free Software Foundation; either version 2 of the License, or
   9   * (at your option) any later version.
  10   *
  11   * This program is distributed in the hope that it will be useful,
  12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14   * GNU General Public License for more details.
  15   *
  16   * You should have received a copy of the GNU General Public License
  17   * along with this program; if not, write to the Free Software
  18   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19   *
  20   * $Id: mailing-send.php,v 1.6 2005/09/02 21:34:22 eldy Exp $
  21   * $Source: /cvsroot/dolibarr/dolibarr/scripts/mailing-send.php,v $
  22   *
  23   *
  24   * !!! Envoi mailing !!!
  25   *
  26   * L'utilisation d'adresses de courriers électroniques dans les opérations
  27   * de prospection commerciale est subordonnée au recueil du consentement 
  28   * préalable des personnes concernées.
  29   *
  30   * Le dispositif juridique applicable a été introduit par l'article 22 de 
  31   * la loi du 21 juin 2004  pour la confiance dans l'économie numérique.
  32   *
  33   * Les dispositions applicables sont définies par les articles L. 34-5 du 
  34   * code des postes et des télécommunications et L. 121-20-5 du code de la 
  35   * consommation. L'application du principe du consentement préalable en 
  36   * droit français résulte de la transposition de l'article 13 de la Directive 
  37   * européenne du 12 juillet 2002 « Vie privée et communications électroniques ». 
  38   */
  39  
  40  
  41  /**
  42          \file       scripts/mailing-send.php
  43          \ingroup    mailing
  44          \brief      Script d'envoi d'un mailing préparé et validé
  45  */
  46  
  47  
  48  // Test si mode batch
  49  $sapi_type = php_sapi_name();
  50  if (substr($sapi_type, 0, 3) == 'cgi') {
  51      echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
  52      exit;
  53  }
  54  
  55  if (! isset($argv[1]) || ! $argv[1]) {
  56      print "Usage:  mailing-send.php ID_MAILING\n";   
  57      exit;
  58  }
  59  $id=$argv[1];
  60  
  61  // Recupere root dolibarr
  62  $path=eregi_replace('mailing-send.php','',$_SERVER["PHP_SELF"]);
  63  
  64  
  65  require_once  ($path."../htdocs/master.inc.php");
  66  require_once (DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
  67  
  68  
  69  $error = 0;
  70  
  71  
  72  // On récupère données du mail
  73  $sql = "SELECT m.rowid, m.titre, m.sujet, m.body";
  74  $sql .= " , m.email_from, m.email_replyto, m.email_errorsto";
  75  $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
  76  $sql .= " WHERE m.statut >= 1";
  77  $sql .= " AND m.rowid= ".$id;
  78  $sql .= " LIMIT 1";
  79  
  80  $resql=$db->query($sql);
  81  if ($resql) 
  82  {
  83    $num = $db->num_rows($resql);
  84    $i = 0;
  85    
  86    if ($num == 1)
  87      {
  88        $obj = $db->fetch_object($resql);
  89  
  90        dolibarr_syslog("mailing-send: mailing ".$id);
  91  
  92        $id       = $obj->rowid;
  93        $subject  = $obj->sujet;
  94        $message  = $obj->body;
  95        $from     = $obj->email_from;
  96        $errorsto = $obj->email_errorsto;
  97  
  98        $i++;
  99      }
 100  }
 101  
 102  
 103  $nbok=0; $nbko=0;
 104  
 105  // On choisit les mails non déjà envoyés pour ce mailing (statut=0)
 106  // ou envoyés en erreur (statut=-1)
 107  $sql = "SELECT mc.rowid, mc.nom, mc.prenom, mc.email";
 108  $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
 109  $sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
 110  
 111  $resql=$db->query($sql);
 112  if ($resql)
 113  {
 114      $num = $db->num_rows($resql);
 115  
 116      if ($num) 
 117      {
 118          dolibarr_syslog("mailing-send: target number = $num");
 119  
 120          // Positionne date debut envoi
 121          $sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi=SYSDATE() WHERE rowid=".$id;
 122          $resql2=$db->query($sql);
 123          if (! $resql2)
 124          {
 125              dolibarr_print_error($db);
 126          }
 127      
 128          // Boucle sur chaque adresse et envoie le mail
 129          $i = 0;
 130          while ($i < $num )
 131          {
 132              $obj = $db->fetch_object($resql);
 133  
 134              $sendto = stripslashes($obj->prenom). " ".stripslashes($obj->nom) ."<".$obj->email.">";
 135              $mail = new CMailFile($subject, $sendto, $from, $message, array(), array(), array());
 136              $mail->errors_to = $errorsto;
 137      
 138              if ( $mail->sendfile() )
 139              {
 140                  // Mail envoye avec succes
 141                  $nbok++;
 142      
 143                  $sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=1, date_envoi=SYSDATE() WHERE rowid=".$obj->rowid;
 144                  $resql2=$db->query($sql);
 145                  if (! $resql2)
 146                  {
 147                      dolibarr_print_error($db);   
 148                  }
 149              }
 150              else
 151              {
 152                  // Mail en echec
 153                  $nbko++;
 154      
 155                  $sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=-1, date_envoi=SYSDATE() WHERE rowid=".$obj->rowid;
 156                  $resql2=$db->query($sql);
 157                  if (! $resql2)
 158                  {
 159                      dolibarr_print_error($db);   
 160                  }
 161              }
 162      
 163              $i++;
 164          }
 165      }
 166  
 167      // Met a jour statut global du mail
 168      $statut=2;
 169      if (! $nbko) $statut=3;
 170  
 171      $sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
 172      $resql2=$db->query($sql);
 173      if (! $resql2)
 174      {
 175          dolibarr_print_error($db);
 176      }
 177  }
 178  else
 179  {
 180      dolibarr_syslog($db->error());
 181      dolibarr_print_error($db);
 182  }
 183  
 184  ?>


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