00001 <?php
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once FASTFRAME_ROOT . 'lib/FastFrame/Model.php';
00026
00027
00028
00029
00042
00043 class FF_Model_Massmail extends FF_Model {
00044
00045
00050 var $sender;
00051
00056 var $senderEmail;
00057
00062 var $subject;
00063
00068 var $emailBody;
00069
00074 var $addresses;
00075
00080 var $sentCount = 0;
00081
00082
00083
00084
00091 function reset()
00092 {
00093 $this->id = null;
00094 $this->sender = null;
00095 $this->sender_email = null;
00096 $this->subject = null;
00097 $this->emailBody = null;
00098 $this->addresses = null;
00099 $this->sentCount = 0;
00100 }
00101
00102
00103
00104
00113 function importFromArray($in_data)
00114 {
00115 $this->setId($in_data['id']);
00116 $this->setSender($in_data['sender']);
00117 $this->setSenderEmail($in_data['sender_email']);
00118 $this->setSubject($in_data['subject']);
00119 $this->setEmailBody($in_data['email_body']);
00120 $this->setAddresses($in_data['addresses']);
00121 $this->setSentCount($in_data['sent_count']);
00122 }
00123
00124
00125
00126
00135 function exportToArray()
00136 {
00137 $a_data = array();
00138 $a_data['id'] = $this->getId();
00139 $a_data['sender'] = $this->getSender();
00140 $a_data['sender_email'] = $this->getSenderEmail();
00141 $a_data['subject'] = $this->getSubject();
00142 $a_data['email_body'] = $this->getEmailBody();
00143 $a_data['addresses'] = $this->getAddresses();
00144 $a_data['sent_count'] = $this->getSentCount();
00145 return $a_data;
00146 }
00147
00148
00149
00150
00158 function sendEmails()
00159 {
00160 $a_errors[] = _('Sending email is disabled in demo version.');
00161 return array($a_errors, false);
00162 require_once 'Mail.php';
00163 $a_errors = array();
00164 $s_success = 0;
00165 $o_registry =& FF_Registry::singleton();
00166 $o_mail =& Mail::factory($o_registry->getConfigParam('mailer/type'), $o_registry->getConfigParam('mailer/params'));
00167 if (PEAR::isError($o_mail)) {
00168 $a_errors[] = $o_mail->getMessage();
00169 return array($a_errors, $s_success);
00170 }
00171
00172 $a_headers = array();
00173 $a_headers['Subject'] = $this->getSubject();
00174 $a_headers['From'] = $this->getFullSender();
00175
00176 if (preg_match('/<[^>]+>/', $this->getEmailBody())) {
00177 require_once 'Mail/mime.php';
00178 $o_mime =& new Mail_mime();
00179 $o_mime->setTxtBody(strip_tags($this->getEmailBody()));
00180 $o_mime->setHtmlBody($this->getEmailBody());
00181 $s_body = $o_mime->get();
00182 $a_headers = $o_mime->headers($a_headers);
00183 }
00184 else {
00185 $s_body = $this->getEmailBody();
00186 }
00187
00188 $a_addresses = preg_split('/[\n,]/', $this->getAddresses(), -1, PREG_SPLIT_NO_EMPTY);
00189 foreach ($a_addresses as $s_address) {
00190 set_time_limit(10);
00191 $result = $o_mail->send($s_address, $a_headers, $s_body);
00192 if (PEAR::isError($result)) {
00193 $a_errors[] = sprintf(_('Error sending email message to %s (%s)'), $s_address, $result->getMessage());
00194 }
00195 else {
00196 $s_success++;
00197
00198 if ($s_success == 1) {
00199 $this->o_dataAccess->incrementSentCount();
00200 }
00201 }
00202 }
00203
00204 return array($a_errors, $s_success);
00205 }
00206
00207
00208
00209
00216 function getFullSender()
00217 {
00218 return $this->getSender() . ' <' . $this->getSenderEmail() . '>';
00219 }
00220
00221
00222
00223
00224 function getSender()
00225 {
00226 return $this->sender;
00227 }
00228
00229
00230
00231
00232 function setSender($in_value)
00233 {
00234 $this->sender = $in_value;
00235 }
00236
00237
00238
00239
00240 function getSenderEmail()
00241 {
00242 return $this->senderEmail;
00243 }
00244
00245
00246
00247
00248 function setSenderEmail($in_value)
00249 {
00250 $this->senderEmail = $in_value;
00251 }
00252
00253
00254
00255
00256 function getSubject()
00257 {
00258 return $this->subject;
00259 }
00260
00261
00262
00263
00264 function setSubject($in_value)
00265 {
00266 $this->subject = $in_value;
00267 }
00268
00269
00270
00271
00272 function getEmailBody()
00273 {
00274 return $this->emailBody;
00275 }
00276
00277
00278
00279
00280 function setEmailBody($in_value)
00281 {
00282 $this->emailBody = $in_value;
00283 }
00284
00285
00286
00287
00288 function getAddresses()
00289 {
00290 return $this->addresses;
00291 }
00292
00293
00294
00295
00296 function setAddresses($in_value)
00297 {
00298 $this->addresses = $in_value;
00299 }
00300
00301
00302
00303
00304 function getSentCount()
00305 {
00306 return $this->sentCount;
00307 }
00308
00309
00310
00311
00312 function setSentCount($in_value)
00313 {
00314 $this->sentCount = $in_value;
00315 }
00316
00317
00318
00319
00326 function _initDataAccess()
00327 {
00328 $this->o_dataAccess =& FF_DataAccess::factory('Massmail');
00329 }
00330
00331
00332 }
00333 ?>