AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / docs / include / classes / phpmailer / transformablemailer.class.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12
13 if (!defined('TR_INCLUDE_PATH')) { exit; }
14
15 require(dirname(__FILE__) . '/class.phpmailer.php');
16
17 /**
18 * TransformableMailer is modified from TransformableMailer
19 *
20 * TransformableMailer extends PHPMailer and sets all the default values
21 * that are common for Transformable.
22 * @access  public
23 * @see     include/classes/phpmailer/class.phpmailer.php
24 * @since   Transformable 0.1
25 * @author  Cindy Li
26 */
27 class TransformableMailer extends PHPMailer {
28
29         /**
30         * The constructor sets whether to use SMTP or Sendmail depending
31         * on the value of MAIL_USE_SMTP defined in the config.inc.php file.
32         * @access  public
33         * @since   AContent 0.2
34         * @author  Joel Kronenberg
35         */
36         function TransformableMailer() {
37                 if (MAIL_USE_SMTP) {
38                         $this->IsSMTP(); // set mailer to use SMTP
39                         $this->Host = ini_get('SMTP');  // specify main and backup server
40                 } else {
41                         $this->IsSendmail(); // use sendmail
42                         $this->Sendmail = ini_get('sendmail_path');
43                 }
44
45                 $this->SMTPAuth = false;  // turn on SMTP authentication
46                 $this->IsHTML(false);
47
48                 // send the email in the current encoding:
49                 global $myLang;
50                 $this->CharSet = $myLang->getCharacterSet();
51         }
52
53         /**
54         * Appends a custom AContent footer to all outgoing email then sends the email.
55         * If mail_queue is enabled then instead of sending the mail out right away, it 
56         * places it in the database and waits for the cron to send it using SendQueue().
57         * The mail queue does not support reply-to, or attachments, and converts all BCCs
58         * to regular To emails.
59         * @access  public
60         * @return  boolean      whether or not the mail was sent (or queued) successfully.
61         * @see     parent::send()
62         * @since   AContent 0.1
63         * @author  Joel Kronenberg
64         */
65         function Send() {
66                 global $_config;
67
68                 // attach the AContent footer to the body first:
69                 $this->Body .=  "\n\n".'----------------------------------------------'."\n";
70                 $this->Body .= _AT(array('sent_via_transformable', TR_BASE_HREF));
71
72                 $this->Body .= "\n"._AT('home').': http://atutor.ca';
73
74                 // if this email has been queued then don't send it. instead insert it in the db
75                 // for each bcc or to or cc
76                 if ($_config['enable_mail_queue'] && !$this->attachment) 
77                 {
78                         require_once(TR_INCLUDE_PATH.'classes/DAO/MailQueueDAO.class.php');
79                         $mailQueueDAO = new MailQueueDAO();
80                         
81                         for ($i = 0; $i < count($this->to); $i++) {
82                                 $mailQueueDAO->Create(addslashes($this->to[$i][0]), addslashes($this->to[$i][1]), addslashes($this->From), addslashes($this->FromName), addslashes($this->Subject), addslashes($this->Body), addslashes($this->CharSet));
83                         }
84                         for($i = 0; $i < count($this->cc); $i++) {
85                                 $mailQueueDAO->Create(addslashes($this->cc[$i][0]), addslashes($this->cc[$i][1]), addslashes($this->From), addslashes($this->FromName), addslashes($this->Subject), addslashes($this->Body), addslashes($this->CharSet));
86                         }
87                         for($i = 0; $i < count($this->bcc); $i++) {
88                                 $mailQueueDAO->Create(addslashes($this->bcc[$i][0]), addslashes($this->bcc[$i][1]), addslashes($this->From), addslashes($this->FromName), addslashes($this->Subject), addslashes($this->Body), addslashes($this->CharSet));
89                         }
90                         return true;
91                 } else {
92                         return parent::Send();
93                 }
94         }
95
96         /**
97         * Sends all the queued mail. Called by ./admin/cron.php.
98         * @access public
99         * @return void
100         * @since AContent 0.2
101         * @author Joel Kronenberg
102         */
103         function SendQueue() {
104                 global $db;
105
106                 require_once(TR_INCLUDE_PATH.'classes/DAO/MailQueueDAO.class.php');
107                 $mailQueueDAO = new MailQueueDAO();
108                 $rows = $mailQueueDAO->getAll();
109
110                 $mail_ids = '';
111                 
112                 if (is_array($rows))
113                 {
114                         foreach ($rows as $id => $row) 
115                         {
116                                 $this->ClearAllRecipients();
117         
118                                 $this->AddAddress($row['to_email'], $row['to_name']);
119                                 $this->From     = $row['from_email'];
120                                 $this->FromName = $row['from_name'];
121                                 $this->CharSet  = $row['char_set'];
122                                 $this->Subject  = $row['subject'];
123                                 $this->Body     = $row['body'];
124         
125                                 parent::Send();
126         
127                                 $mail_ids .= $row['mail_id'].',';
128                         }
129                         if ($mail_ids) 
130                         {
131                                 include(TR_INCLUDE_PATH.'classes/DAO/MailQueueDAO.class.php');
132                                 $mailQueueDAO = new MailQueueDAO();
133         
134                                 $mail_ids = substr($mail_ids, 0, -1); // remove the last comma
135                                 $mailQueueDAO->DeleteByIDs($mail_ids);
136                         }
137                 }
138         }
139
140 }
141
142 ?>