[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: mailing.class.php,v 1.11 2005/08/11 18:54:01 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/comm/mailing/mailing.class.php,v $ 21 * 22 */ 23 24 /** 25 \file htdocs/comm/mailing/mailing.class.php 26 \ingroup mailing 27 \brief Fichier de la classe de gestion des mailings 28 \version $Revision: 1.11 $ 29 */ 30 31 32 /** 33 \class Mailing 34 \brief Classe permettant la gestion des mailings 35 */ 36 class Mailing 37 { 38 var $id; 39 var $error; 40 41 var $statut; 42 var $titre; 43 var $sujet; 44 var $body; 45 var $nbemail; 46 47 var $email_from; 48 var $email_replyto; 49 var $email_errorsto; 50 51 var $user_creat; 52 var $user_valid; 53 var $user_appro; 54 55 var $date_creat; 56 var $date_valid; 57 var $date_appro; 58 59 60 /** 61 * \brief Constructeur de la classe 62 * \param DB handler accès base de données 63 */ 64 function Mailing($DB) 65 { 66 global $langs; 67 $langs->load("mails"); 68 69 $this->db = $DB ; 70 $this->db_table = MAIN_DB_PREFIX."mailing"; 71 72 $this->statuts[0] = $langs->trans("MailingStatusDraft"); 73 $this->statuts[1] = $langs->trans("MailingStatusValidated"); 74 $this->statuts[2] = $langs->trans("MailingStatusSentPartialy"); 75 $this->statuts[3] = $langs->trans("MailingStatusSentCompletely"); 76 } 77 78 /** 79 * \brief Création du mailing 80 * \param user object utilisateur qui crée 81 * \return -1 si erreur, >0 sinon 82 * 83 */ 84 function create($user) 85 { 86 global $langs; 87 88 dolibarr_syslog("Mailing::Create"); 89 90 $this->db->begin(); 91 92 $this->titre=trim($this->titre); 93 $this->email_from=trim($this->email_from); 94 95 if (! $this->email_from) 96 { 97 $this->error = $langs->trans("ErrorMailFromRequired"); 98 return -1; 99 } 100 101 $sql = "INSERT INTO ".$this->db_table; 102 $sql .= " (date_creat, fk_user_creat)"; 103 $sql .= " VALUES (now(), ".$user->id.")"; 104 105 if (! $this->titre) 106 { 107 $this->titre = $langs->trans("NoTitle"); 108 } 109 110 $result=$this->db->query($sql); 111 if ($result) 112 { 113 $this->id = $this->db->last_insert_id($this->db_table); 114 115 if ($this->update() > 0) 116 { 117 $this->db->commit(); 118 } 119 else 120 { 121 $this->db->rollback(); 122 $this->error=$langs->trans("ErrorUnknown"); 123 return -1; 124 } 125 126 return $this->id; 127 } 128 else 129 { 130 $this->db->rollback(); 131 132 dolibarr_syslog("Mailing::Create Erreur -1"); 133 $this->error=$langs->trans("UnknownError"); 134 return -1; 135 } 136 137 } 138 139 /** 140 * \brief Update les infos du mailing 141 * \return < 0 si erreur, > 0 si ok 142 */ 143 function update() 144 { 145 dolibarr_syslog("Mailing::Update"); 146 147 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing "; 148 $sql .= " SET titre = '".addslashes($this->titre)."'"; 149 $sql .= " , sujet = '".addslashes($this->sujet)."'"; 150 $sql .= " , body = '".addslashes($this->body)."'"; 151 $sql .= " , email_from = '".$this->email_from."'"; 152 $sql .= " WHERE rowid = ".$this->id; 153 154 $result=$this->db->query($sql); 155 if ($result) 156 { 157 return 1; 158 } 159 else 160 { 161 dolibarr_syslog("Mailing::Update Erreur -1"); 162 return -1; 163 } 164 } 165 166 /** 167 * \brief Recupére l'objet mailing 168 * \param rowid id du mailing 169 */ 170 function fetch($rowid) 171 { 172 $sql = "SELECT m.rowid, m.titre, m.sujet, m.body"; 173 $sql .= " , m.email_from, m.email_replyto, m.email_errorsto"; 174 $sql .= " , m.statut, m.nbemail"; 175 $sql .= ", m.fk_user_creat, m.fk_user_valid, m.fk_user_appro"; 176 $sql .= ", ".$this->db->pdate("m.date_creat") . " as date_creat"; 177 $sql .= ", ".$this->db->pdate("m.date_valid") . " as date_valid"; 178 $sql .= ", ".$this->db->pdate("m.date_envoi") . " as date_envoi"; 179 $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m"; 180 $sql .= " WHERE m.rowid = ".$rowid; 181 182 if ($this->db->query($sql) ) 183 { 184 if ($this->db->num_rows()) 185 { 186 $obj = $this->db->fetch_object(); 187 188 $this->id = $obj->rowid; 189 $this->statut = $obj->statut; 190 $this->nbemail = $obj->nbemail; 191 $this->titre = stripslashes($obj->titre); 192 $this->sujet = stripslashes($obj->sujet); 193 $this->body = stripslashes($obj->body); 194 195 $this->email_from = $obj->email_from; 196 $this->email_replyto = $obj->email_replyto; 197 $this->email_errorsto = $obj->email_errorsto; 198 199 $this->user_creat = $obj->fk_user_creat; 200 $this->user_valid = $obj->fk_user_valid; 201 $this->user_appro = $obj->fk_user_appro; 202 203 $this->date_creat = $obj->date_creat; 204 $this->date_valid = $obj->date_valid; 205 $this->date_appro = $obj->date_appro; 206 $this->date_envoi = $obj->date_envoi; 207 208 return 0; 209 } 210 else 211 { 212 dolibarr_syslog("Mailing::Fetch Erreur -1"); 213 return -1; 214 } 215 } 216 else 217 { 218 dolibarr_syslog("Mailing::Fetch Erreur -2"); 219 return -2; 220 } 221 } 222 223 224 /** 225 * \brief Valide le mailing 226 * \param user objet user qui valide 227 */ 228 function valid($user) 229 { 230 dolibarr_syslog("Mailing::Valid"); 231 232 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing "; 233 $sql .= " SET statut = 1, date_valid = now(), fk_user_valid=".$user->id; 234 235 $sql .= " WHERE rowid = ".$this->id." AND statut = 0 ;"; 236 237 if ($this->db->query($sql) ) 238 { 239 return 0; 240 } 241 else 242 { 243 dolibarr_syslog("Mailing::Valid Erreur -1"); 244 return -1; 245 } 246 } 247 248 /** 249 * \brief Approuve le mailing 250 * \param user objet user qui approuve 251 */ 252 function approve($user) 253 { 254 $sql = "UPDATE ".MAIN_DB_PREFIX."mailing "; 255 $sql .= " SET statut = 2, date_appro = now(), fk_user_appro=".$user->id; 256 257 $sql .= " WHERE rowid = ".$this->id." AND statut = 1 ;"; 258 259 if ($this->db->query($sql) ) 260 { 261 return 0; 262 } 263 else 264 { 265 dolibarr_syslog("Mailing::Valid Erreur -1"); 266 return -1; 267 } 268 } 269 270 271 /** 272 * \brief Supprime le mailing 273 * \param rowid id du mailing à supprimer 274 * \return int 1 en cas de succès 275 */ 276 function delete($rowid) 277 { 278 $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing"; 279 $sql .= " WHERE rowid = ".$rowid; 280 281 $this->db->query($sql); 282 return 1; 283 } 284 285 } 286 287 ?>
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 |
![]() |