| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2003-2004 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 * 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 * or see http://www.gnu.org/ 20 * 21 * $Id: modules_mailings.php,v 1.6 2005/09/15 22:45:11 eldy Exp $ 22 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/includes/modules/mailings/modules_mailings.php,v $ 23 * 24 */ 25 26 /** 27 \file htdocs/includes/modules/mailings/modules_mailings.php 28 \ingroup mailing 29 \brief Fichier contenant la classe mère des classes de liste de destinataires mailing 30 \version $Revision: 1.6 $ 31 */ 32 33 34 /** 35 \class MailingTargets 36 \brief Classe mère des classes de liste de destinataires mailing 37 */ 38 39 class MailingTargets 40 { 41 var $db=''; 42 var $error=''; 43 44 function MailingTargets($DB) 45 { 46 $this->db=$DB; 47 } 48 49 /** \brief Renvoi un exemple de numérotation 50 * \return string Retourne la traduction de la clé MailingModuleDescXXX ou XXX nom du module, ou $this->desc si non trouvé 51 */ 52 function getDesc() 53 { 54 global $langs; 55 $langs->load("mails"); 56 $transstring="MailingModuleDesc".$this->name; 57 if ($langs->trans($transstring) != $transstring) return $langs->trans($transstring); 58 else return $this->desc; 59 } 60 61 /** \brief Renvoi un exemple de numérotation 62 * \return string Example 63 */ 64 function getNbOfRecords() 65 { 66 return 0; 67 } 68 69 /** 70 * \brief Retourne nombre de destinataires 71 * \param sql Requete sql de comptage 72 * \return int Nb de destinataires si ok, < 0 si erreur 73 */ 74 function getNbOfRecipients($sql) 75 { 76 $result=$this->db->query($sql); 77 if ($result) 78 { 79 $obj = $this->db->fetch_object($result); 80 return $obj->nb; 81 } 82 else 83 { 84 return -1; 85 } 86 } 87 88 /** 89 * \brief Affiche formulaire de filtre qui apparait dans page de selection 90 * des destinataires de mailings 91 * \return string Retourne zone select 92 */ 93 function formFilter() 94 { 95 return ' '; 96 } 97 98 /** 99 * \brief Met a jour nombre de destinataires 100 * \param mailing_id Id du mailing concerné 101 * \return int < 0 si erreur, nb destinataires si ok 102 */ 103 function update_nb($mailing_id) 104 { 105 // Mise a jour nombre de destinataire dans table des mailings 106 $sql = "SELECT COUNT(*) nb FROM ".MAIN_DB_PREFIX."mailing_cibles"; 107 $sql .= " WHERE fk_mailing = ".$mailing_id; 108 $result=$this->db->query($sql); 109 if ($result) 110 { 111 $obj=$this->db->fetch_object($result); 112 $nb=$obj->nb; 113 114 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing"; 115 $sql .= " SET nbemail = ".$nb." WHERE rowid = ".$mailing_id; 116 if (!$this->db->query($sql)) 117 { 118 dolibarr_syslog($this->db->error()); 119 $this->error=$this->db->error(); 120 return -1; 121 } 122 } 123 else { 124 return -1; 125 } 126 return $nb; 127 } 128 129 /** 130 * \brief Ajoute destinataires dans table des cibles 131 * \param mailing_id Id du mailing concerné 132 * \param sql Requete sql de selection des destinataires 133 * \return int < 0 si erreur, nb ajout si ok 134 */ 135 function add_to_target($mailing_id, $sql) 136 { 137 $cibles = array(); 138 139 // Stocke destinataires dans cibles 140 $result=$this->db->query($sql); 141 if ($result) 142 { 143 $num = $this->db->num_rows($result); 144 $i = 0; 145 $j = 0; 146 147 dolibarr_syslog("mailing-prepare: mailing $num cibles trouvées"); 148 149 $old = ''; 150 while ($i < $num) 151 { 152 $obj = $this->db->fetch_object($result); 153 if ($old <> $obj->email) 154 { 155 $cibles[$j] = array($obj->email,$obj->fk_contact,$obj->name,$obj->firstname,$this->url($obj->id)); 156 $old = $obj->email; 157 $j++; 158 } 159 160 $i++; 161 } 162 } 163 else 164 { 165 dolibarr_syslog($this->db->error()); 166 $this->error=$this->db->error(); 167 return -1; 168 } 169 170 $this->db->begin(); 171 172 // Insère destinataires de cibles dans table 173 $j = 0; 174 $num = sizeof($cibles); 175 for ($i = 0 ; $i < $num ; $i++) 176 { 177 $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles"; 178 $sql .= " (fk_mailing, "; 179 if ($cibles[$i][1]) $sql .= "fk_contact, "; 180 $sql .= "nom, prenom, email, url)"; 181 $sql .= " VALUES (".$mailing_id.","; 182 if ($cibles[$i][1]) $sql .= $cibles[$i][1] .","; 183 $sql .= "'".addslashes($cibles[$i][2])."',"; 184 $sql .= "'".addslashes($cibles[$i][3])."',"; 185 $sql .= "'".addslashes($cibles[$i][0])."',"; 186 $sql .= "'".addslashes($cibles[$i][4])."')"; 187 188 $result=$this->db->query($sql); 189 if ($result) 190 { 191 $j++; 192 } 193 else 194 { 195 if ($this->db->errno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') 196 { 197 // Si erreur autre que doublon 198 dolibarr_syslog($this->db->error()); 199 $this->error=$this->db->error(); 200 $this->db->rollback(); 201 return -1; 202 } 203 } 204 } 205 206 dolibarr_syslog("mailing-prepare: mailing $j cibles ajoutées"); 207 208 $this->update_nb($mailing_id); 209 210 $this->db->commit(); 211 return $j; 212 } 213 214 /** 215 * \brief Supprime tous les destinataires de la table des cibles 216 * \param mailing_id Id du mailing concerné 217 */ 218 function clear_target($mailing_id) 219 { 220 $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles"; 221 $sql .= " WHERE fk_mailing = ".$mailing_id; 222 223 if (! $this->db->query($sql)) 224 { 225 dolibarr_syslog($this->db->error()); 226 } 227 228 $this->update_nb($mailing_id); 229 } 230 231 } 232 233 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
|