Quick Search:

View

Revision:

Diff

Diff from 1169 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/frank/osc-tickets/admin/includes/modules/newsletters/email.php

Annotated File View

hpdl
1
1 <?php
2 /*
mattice
151
3   $Id: email.php 1169 2006-12-14 22:19:51Z frank $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
1076
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
13   class osC_Newsletter_email {
14
15 /* Private methods */
16
17     var $_title,
18         $_has_audience_selection = true,
19         $_newsletter_title,
20         $_newsletter_content,
21         $_newsletter_id,
22         $_audience_size = 0;
23
24 /* Class constructor */
25
26     function osC_Newsletter_email($title = '', $content = '', $newsletter_id = '') {
27       $this->_title = MODULE_NEWSLETTER_EMAIL_TITLE;
28
29       $this->_newsletter_title = $title;
30       $this->_newsletter_content = $content;
31       $this->_newsletter_id = $newsletter_id;
32     }
33
34 /* Public methods */
35
36     function getTitle() {
37       return $this->_title;
38     }
39
40     function hasAudienceSelection() {
41       if ($this->_has_audience_selection === true) {
42         return true;
43       }
44
45       return false;
46     }
47
48     function showAudienceSelectionForm() {
49       global $osC_Database;
50
51       $customers_array = array(array('id' => '***', 'text' => MODULE_NEWSLETTER_EMAIL_TEXT_ALL_CUSTOMERS));
52
53       $Qcustomers = $osC_Database->query('select customers_id, customers_firstname, customers_lastname, customers_email_address from :table_customers order by customers_lastname');
54       $Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS);
55       $Qcustomers->execute();
56
57       while ($Qcustomers->next()) {
58         $customers_array[] = array('id' => $Qcustomers->valueInt('customers_id'),
59                                    'text' => $Qcustomers->value('customers_lastname') . ', ' . $Qcustomers->value('customers_firstname') . ' (' . $Qcustomers->value('customers_email_address') . ')');
60       }
61
62       $Qcustomers->freeResult();
63
hpdl
1076
64       $audience_form = '<form name="customers" action="' . osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $_GET['nmID'] . '&action=nmConfirm') . '" method="post">' .
hpdl
755
65                        '  <p align="center">' . osc_draw_pull_down_menu('customer', $customers_array, null, 'size="20" style="width: 100%;"') . '</p>' .
hpdl
1076
66                        '  <p align="right"><input type="submit" value="' . BUTTON_OK . '" class="operationButton">&nbsp;<input type="button" value="' . BUTTON_CANCEL . '" onclick="document.location.href=\'' . osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $_GET['nmID']) . '\';" class="operationButton"></p>' .
hpdl
1
67                        '</form>';
68
69       return $audience_form;
70     }
71
72     function showConfirmation() {
73       global $osC_Database;
74
75       if (isset($_POST['customer']) && !empty($_POST['customer'])) {
76         $Qcustomers = $osC_Database->query('select count(customers_id) as total from :table_customers c left join :table_newsletters_log nl on (c.customers_email_address = nl.email_address and nl.newsletters_id = :newsletters_id) where nl.email_address is null');
77         $Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS);
78         $Qcustomers->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG);
79         $Qcustomers->bindInt(':newsletters_id', $this->_newsletter_id);
80
81         if (is_numeric($_POST['customer'])) {
82           $Qcustomers->appendQuery('and c.customers_id = :customers_id');
83           $Qcustomers->bindInt(':customers_id', $_POST['customer']);
84         }
85
86         $Qcustomers->execute();
87
frank
1169
88         $this->_audience_size += $Qcustomers->valueInt('total');
hpdl
1
89       }
90
91       $confirmation_string = '<p><font color="#ff0000"><b>' . sprintf(MODULE_NEWSLETTER_EMAIL_TEXT_TOTAL_RECIPIENTS, $this->_audience_size) . '</b></font></p>' .
92                              '<p><b>' . $this->_newsletter_title . '</b></p>' .
hpdl
758
93                              '<p>' . nl2br(osc_output_string_protected($this->_newsletter_content)) . '</p>' .
hpdl
1076
94                              '<form name="confirm" action="' . osc_href_link(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $_GET['nmID'] . '&action=nmSendConfirm') . '" method="post">' .
hpdl
1
95                              '<p align="right">';
96
97       if ($this->_audience_size > 0) {
98         $confirmation_string .= osc_draw_hidden_field('customer', $_POST['customer']) .
99                                 '<input type="submit" value="' . BUTTON_SEND . '" class="operationButton">&nbsp;';
100       }
101
hpdl
1076
102       $confirmation_string .= '<input type="button" value="' . BUTTON_BACK . '" onclick="document.location.href=\'' . osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $_GET['nmID'] . '&action=nmSend') . '\'" class="operationButton">&nbsp;<input type="button" value="' . BUTTON_CANCEL . '" onclick="document.location.href=\'' . osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $_GET['nmID']) . '\'" class="operationButton"></p>' .
hpdl
1
103                               '</form>';
104
105       return $confirmation_string;
106     }
107
108     function sendEmail() {
109       global $osC_Database;
110
111       $max_execution_time = 0.8 * (int)ini_get('max_execution_time');
112       $time_start = explode(' ', PAGE_PARSE_START_TIME);
113
114       $audience = array();
115
116       $customer = '';
117       if (isset($_POST['customer']) && !empty($_POST['customer'])) {
118         $customer = $_POST['customer'];
119       } elseif (isset($_GET['customer']) && !empty($_GET['customer'])) {
120         $customer = $_GET['customer'];
121       }
122
123       if (!empty($customer)) {
124         $Qcustomers = $osC_Database->query('select customers_id, customers_firstname, customers_lastname, customers_email_address from :table_customers c left join :table_newsletters_log nl on (c.customers_email_address = nl.email_address and nl.newsletters_id = :newsletters_id) where nl.email_address is null');
125         $Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS);
126         $Qcustomers->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG);
127         $Qcustomers->bindInt(':newsletters_id', $this->_newsletter_id);
128
129         if (is_numeric($customer)) {
130           $Qcustomers->appendQuery('and c.customers_id = :customers_id');
131           $Qcustomers->bindInt(':customers_id', $customer);
132         }
133
134         $Qcustomers->execute();
135
136         while ($Qcustomers->next()) {
137           if (!isset($audience[$Qcustomers->valueInt('customers_id')])) {
138             $audience[$Qcustomers->valueInt('customers_id')] = array('firstname' => $Qcustomers->value('customers_firstname'),
139                                                                      'lastname' => $Qcustomers->value('customers_lastname'),
140                                                                      'email_address' => $Qcustomers->value('customers_email_address'));
141           }
142         }
143
144         $Qcustomers->freeResult();
145
146         if (sizeof($audience) > 0) {
147           $mimemessage = new email(array(base64_decode('WC1NYWlsZXI6IG9zQ29tbWVyY2UgKGh0dHA6Ly93d3cub3Njb21tZXJjZS5jb20p')));
148           $mimemessage->add_text($this->_newsletter_content);
149           $mimemessage->build_message();
150
151           foreach ($audience as $key => $value) {
152             $mimemessage->send($value['firstname'] . ' ' . $value['lastname'], $value['email_address'], '', EMAIL_FROM, $this->_newsletter_title);
153
154             $Qlog = $osC_Database->query('insert into :table_newsletters_log (newsletters_id, email_address, date_sent) values (:newsletters_id, :email_address, now())');
155             $Qlog->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG);
156             $Qlog->bindInt(':newsletters_id', $this->_newsletter_id);
157             $Qlog->bindValue(':email_address', $value['email_address']);
158             $Qlog->execute();
159
160             $time_end = explode(' ', microtime());
161             $timer_total = number_format(($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0])), 3);
162
163             if ($timer_total > $max_execution_time) {
164               echo '<p><font color="#38BB68"><b>' . TEXT_REFRESHING_PAGE . '</b></font></p>' .
hpdl
1076
165                    '<p>' . osc_link_object(osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $this->_newsletter_id . '&action=nmSendConfirm&customer=' . $customer), TEXT_CONTINUE_MANUALLY) . '</p>' .
166                    '<META HTTP-EQUIV="refresh" content="2; URL=' . osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $this->_newsletter_id . '&action=nmSendConfirm&customer=' . $customer) . '">';
hpdl
1
167               exit;
168             }
169           }
170         }
171
172         $Qupdate = $osC_Database->query('update :table_newsletters set date_sent = now(), status = 1 where newsletters_id = :newsletters_id');
173         $Qupdate->bindTable(':table_newsletters', TABLE_NEWSLETTERS);
174         $Qupdate->bindInt(':newsletters_id', $this->_newsletter_id);
175         $Qupdate->execute();
176       }
177     }
178   }
179 ?>