[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2003 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: newsletter.class.php,v 1.7 2005/07/09 14:34:44 eldy Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/boutique/newsletter/newsletter.class.php,v $ 20 * 21 */ 22 23 class Newsletter { 24 var $db ; 25 26 var $id ; 27 var $email_from_name; 28 var $email_from_email; 29 var $email_replyto; 30 var $email_body; 31 var $status; 32 33 function Newsletter($DB, $id=0) { 34 $this->db = $DB; 35 $this->id = $id ; 36 37 $statustext[0] = "Rédaction"; 38 $statustext[1] = "Validé"; 39 $statustext[2] = "Envoi en cours"; 40 $statustext[3] = "Envoyé"; 41 $statustext[4] = "Non envoyé (erreur)"; 42 43 } 44 /* 45 * 46 * 47 * 48 */ 49 function create($user) { 50 51 $sql = "INSERT INTO ".MAIN_DB_PREFIX."newsletter (fk_user_author, datec, nbsent) VALUES (".$user->id.",now(), 0)"; 52 53 if ($this->db->query($sql) ) 54 { 55 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."newsletter"); 56 57 if ( $this->update($id, $user) ) 58 { 59 return $id; 60 } 61 } 62 } 63 64 /* 65 * 66 * 67 */ 68 function update($id, $user) 69 { 70 71 if (strlen(trim($this->email_replyto))==0) 72 { 73 $this->email_replyto = $this->email_from_email; 74 } 75 $this->target = 1; 76 77 $this->target_sql = $this->build_sql($this->target); 78 79 $sql = "UPDATE ".MAIN_DB_PREFIX."newsletter "; 80 $sql .= " SET email_subject = '" . trim($this->email_subject) ."'"; 81 $sql .= ", email_from_name = '" . trim($this->email_from_name) ."'"; 82 $sql .= ", email_from_email = '" . trim($this->email_from_email) ."'"; 83 $sql .= ", email_replyto = '" . trim($this->email_replyto) ."'"; 84 $sql .= ", email_body= '" . trim($this->email_body) ."'"; 85 $sql .= ", target = ".$this->target; 86 $sql .= ", sql_target = '".$this->target_sql."'"; 87 $sql .= " WHERE rowid = " . $id; 88 89 if ( $this->db->query($sql) ) { 90 return 1; 91 } else { 92 print $this->db->error() . ' in ' . $sql; 93 } 94 } 95 /* 96 * 97 * 98 * 99 */ 100 function fetch ($id) { 101 102 $sql = "SELECT rowid, email_subject, email_from_name, email_from_email, email_replyto, email_body, target, sql_target, status, date_send_request,".$this->db->pdate("date_send_begin")." as date_send_begin,".$this->db->pdate("date_send_end")." as date_send_end, nbsent, nberror"; 103 $sql .= " FROM ".MAIN_DB_PREFIX."newsletter WHERE rowid=$id"; 104 105 $result = $this->db->query($sql) ; 106 107 if ( $result ) 108 { 109 $result = $this->db->fetch_array(); 110 111 $this->id = $result["rowid"]; 112 $this->email_subject = stripslashes($result["email_subject"]); 113 $this->email_from_name = stripslashes($result["email_from_name"]); 114 $this->email_from_email = stripslashes($result["email_from_email"]); 115 $this->email_replyto = stripslashes($result["email_replyto"]); 116 $this->email_body = stripslashes($result["email_body"]); 117 $this->status = $result["status"]; 118 $this->nbsent = $result["nbsent"]; 119 $this->nberror = $result["nberror"]; 120 $this->date_send_end = $result["date_send_end"]; 121 $this->date_send_begin = $result["date_send_begin"]; 122 123 $this->status_text = $statustext[$this->status]; 124 125 $this->db->free(); 126 } 127 else 128 { 129 print $this->db->error(); 130 } 131 132 return $result; 133 } 134 /* 135 * 136 * 137 * 138 */ 139 function liste_array () 140 { 141 $ga = array(); 142 143 $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."editeur ORDER BY nom"; 144 145 if ($this->db->query($sql) ) 146 { 147 $nump = $this->db->num_rows(); 148 149 if ($nump) 150 { 151 $i = 0; 152 while ($i < $nump) 153 { 154 $obj = $this->db->fetch_object(); 155 156 $ga[$obj->rowid] = $obj->nom; 157 $i++; 158 } 159 } 160 return $ga; 161 } 162 else 163 { 164 print $this->db->error(); 165 } 166 167 } 168 /* 169 * 170 * 171 * 172 */ 173 function validate($user) { 174 175 $sql = "UPDATE ".MAIN_DB_PREFIX."newsletter SET status=1, fk_user_valid = $user->id WHERE rowid = $this->id"; 176 $return = $this->db->query($sql) ; 177 178 } 179 /* 180 * 181 * 182 */ 183 function send($user) { 184 185 $sql = "UPDATE ".MAIN_DB_PREFIX."newsletter SET status=2, date_send_request=now() WHERE rowid = $this->id"; 186 $return = $this->db->query($sql) ; 187 188 } 189 /* 190 * 191 * 192 */ 193 function build_sql($target) 194 { 195 if ($target == 1) 196 { 197 198 $sql = "SELECT c.customers_lastname as name, c.customers_firstname as firstname, c.customers_email_address as email"; 199 $sql .= " FROM ".OSC_DB_NAME.".customers as c"; 200 $sql .= " WHERE c.customers_newsletter=1"; 201 202 } 203 204 return $sql; 205 } 206 /* 207 * 208 * 209 */ 210 function delete() { 211 212 $sql = "DELETE FROM ".MAIN_DB_PREFIX."newsletter WHERE rowid = $this->id "; 213 $return = $this->db->query($sql) ; 214 215 } 216 } 217 ?>
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 |
![]() |