hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
121
|
3
|
$Id: product_notification.php 1076 2006-10-25 15:37:50Z hpdl $
|
hpdl
|
1
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
hpdl
|
121
|
8
|
Copyright (c) 2005 osCommerce
|
hpdl
|
1
|
9
|
|
|
10
|
Released under the GNU General Public License
|
|
11
|
*/
|
|
12
|
|
|
13
|
class osC_Newsletter_product_notification {
|
|
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_product_notification($title = '', $content = '', $newsletter_id = '') {
|
|
27
|
$this->_title = MODULE_NEWSLETTER_PRODUCT_NOTIFICATION_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() {
|
hpdl
|
121
|
49
|
global $osC_Database, $osC_Language;
|
hpdl
|
1
|
50
|
|
|
51
|
$products_array = array();
|
|
52
|
|
|
53
|
$Qproducts = $osC_Database->query('select pd.products_id, pd.products_name from :table_products p, :table_products_description pd where pd.language_id = :language_id and pd.products_id = p.products_id and p.products_status = 1 order by pd.products_name');
|
|
54
|
$Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
|
|
55
|
$Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
|
hpdl
|
121
|
56
|
$Qproducts->bindInt(':language_id', $osC_Language->getID());
|
hpdl
|
1
|
57
|
$Qproducts->execute();
|
|
58
|
|
|
59
|
while ($Qproducts->next()) {
|
|
60
|
$products_array[] = array('id' => $Qproducts->valueInt('products_id'),
|
|
61
|
'text' => $Qproducts->value('products_name'));
|
|
62
|
}
|
|
63
|
|
|
64
|
$Qproducts->freeResult();
|
|
65
|
|
hpdl
|
365
|
66
|
$audience_form = '<script type="text/javascript">
|
hpdl
|
1
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
|
|
72
|
|
|
73
|
|
|
74
|
|
|
75
|
|
|
76
|
|
|
77
|
|
|
78
|
|
|
79
|
|
|
80
|
|
|
81
|
|
|
82
|
|
|
83
|
|
|
84
|
|
|
85
|
|
|
86
|
|
|
87
|
|
|
88
|
|
|
89
|
|
|
90
|
|
|
91
|
|
|
92
|
|
|
93
|
|
|
94
|
|
|
95
|
|
|
96
|
|
|
97
|
|
|
98
|
|
|
99
|
|
|
100
|
|
|
101
|
|
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
</script>';
|
|
109
|
|
hpdl
|
1076
|
110
|
$audience_form .= '<form name="notifications" action="' . osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $_GET['nmID'] . '&action=nmConfirm') . '" method="post" onsubmit="return selectAll(\'notifications\', \'chosen[]\');">' .
|
hpdl
|
1
|
111
|
' <table border="0" width="100%" cellspacing="0" cellpadding="2">' .
|
|
112
|
' <tr>' .
|
hpdl
|
755
|
113
|
' <td align="center" class="main"><b>' . MODULE_NEWSLETTER_PRODUCT_NOTIFICATION_TABLE_HEADING_PRODUCTS . '</b><br />' . osc_draw_pull_down_menu('products', $products_array, null, 'size="20" style="width: 20em;" multiple') . '</td>' .
|
hpdl
|
1076
|
114
|
' <td align="center" class="main"> <br /><input type="button" value="' . MODULE_NEWSLETTER_PRODUCT_NOTIFICATION_BUTTON_GLOBAL . '" style="width: 90px;" onclick="document.location=\'' . osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $_GET['nmID'] . '&action=nmConfirm&global=true') . '\';" class="operationButton"><br /><br /><br /><input type="button" value="' . MODULE_NEWSLETTER_PRODUCT_NOTIFICATION_BUTTON_SELECT . '" style="width: 90px;" onclick="mover(\'remove\');" class="infoBoxButton"><br /><br /><input type="button" value="' . MODULE_NEWSLETTER_PRODUCT_NOTIFICATION_BUTTON_UNSELECT . '" style="width: 90px;" onclick="mover(\'add\');" class="infoBoxButton"><br /><br /><br /><input type="submit" value="' . BUTTON_OK . '" style="width: 90px;" class="operationButton"><br /><br /><input type="button" value="' . BUTTON_CANCEL . '" style="width: 90px;" onclick="document.location=\'' . osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $_GET['nmID']) . '\';" class="operationButton"></td>' .
|
hpdl
|
755
|
115
|
' <td align="center" class="main"><b>' . MODULE_NEWSLETTER_PRODUCT_NOTIFICATION_TABLE_HEADING_SELECTED_PRODUCTS . '</b><br />' . osc_draw_pull_down_menu('chosen[]', null, null, 'size="20" style="width: 20em;" multiple') . '</td>' .
|
hpdl
|
1
|
116
|
' </tr>' .
|
|
117
|
' </table>' .
|
|
118
|
'</form>';
|
|
119
|
|
|
120
|
return $audience_form;
|
|
121
|
}
|
|
122
|
|
|
123
|
function showConfirmation() {
|
|
124
|
global $osC_Database;
|
|
125
|
|
|
126
|
if ( (isset($_POST['chosen']) && !empty($_POST['chosen'])) || (isset($_GET['global']) && ($_GET['global'] == 'true')) ) {
|
hpdl
|
814
|
127
|
$Qcustomers = $osC_Database->query('select count(customers_id) as total from :table_customers where global_product_notifications = 1');
|
|
128
|
$Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS);
|
hpdl
|
1
|
129
|
$Qcustomers->execute();
|
|
130
|
|
|
131
|
$this->_audience_size = $Qcustomers->valueInt('total');
|
|
132
|
|
|
133
|
$Qcustomers = $osC_Database->query('select count(distinct pn.customers_id) as total from :table_products_notifications pn, :table_customers c left join :table_newsletters_log nl on (c.customers_email_address = nl.email_address and nl.newsletters_id = :newsletters_id) where pn.customers_id = c.customers_id and nl.email_address is null');
|
|
134
|
$Qcustomers->bindTable(':table_products_notifications', TABLE_PRODUCTS_NOTIFICATIONS);
|
|
135
|
$Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
136
|
$Qcustomers->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG);
|
|
137
|
$Qcustomers->bindInt(':newsletters_id', $this->_newsletter_id);
|
|
138
|
|
|
139
|
if (isset($_POST['chosen']) && !empty($_POST['chosen'])) {
|
|
140
|
$Qcustomers->appendQuery('and pn.products_id in (:products_id)');
|
|
141
|
$Qcustomers->bindRaw(':products_id', implode(', ', $_POST['chosen']));
|
|
142
|
}
|
|
143
|
|
|
144
|
$Qcustomers->execute();
|
|
145
|
|
|
146
|
$this->_audience_size =+ $Qcustomers->valueInt('total');
|
|
147
|
}
|
|
148
|
|
|
149
|
$confirmation_string = '<p><font color="#ff0000"><b>' . sprintf(MODULE_NEWSLETTER_PRODUCT_NOTIFICATION_TEXT_TOTAL_RECIPIENTS, $this->_audience_size) . '</b></font></p>' .
|
|
150
|
'<p><b>' . $this->_newsletter_title . '</b></p>' .
|
hpdl
|
758
|
151
|
'<p>' . nl2br(osc_output_string_protected($this->_newsletter_content)) . '</p>' .
|
hpdl
|
1076
|
152
|
'<form name="confirm" action="'. osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $_GET['nmID'] . '&action=nmSendConfirm') . '" method="post">' .
|
hpdl
|
1
|
153
|
'<p align="right">';
|
|
154
|
|
|
155
|
if ($this->_audience_size > 0) {
|
|
156
|
if (isset($_GET['global']) && ($_GET['global'] == 'true')) {
|
|
157
|
$confirmation_string .= osc_draw_hidden_field('global', 'true');
|
|
158
|
} elseif (isset($_POST['chosen']) && !empty($_POST['chosen'])) {
|
|
159
|
for ($i=0, $n=sizeof($_POST['chosen']); $i<$n; $i++) {
|
|
160
|
$confirmation_string .= osc_draw_hidden_field('chosen[]', $_POST['chosen'][$i]);
|
|
161
|
}
|
|
162
|
}
|
|
163
|
|
|
164
|
$confirmation_string .= '<input type="submit" value="' . BUTTON_SEND . '" class="operationButton"> ';
|
|
165
|
}
|
|
166
|
|
hpdl
|
1076
|
167
|
$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"> <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
|
168
|
'</form>';
|
|
169
|
|
|
170
|
return $confirmation_string;
|
|
171
|
}
|
|
172
|
|
|
173
|
function sendEmail() {
|
|
174
|
global $osC_Database;
|
|
175
|
|
|
176
|
$max_execution_time = 0.8 * (int)ini_get('max_execution_time');
|
|
177
|
$time_start = explode(' ', PAGE_PARSE_START_TIME);
|
|
178
|
|
|
179
|
if (isset($_POST['chosen'])) {
|
|
180
|
$chosen = $_POST['chosen'];
|
|
181
|
} elseif (isset($_GET['chosen'])) {
|
|
182
|
$chosen = $_GET['chosen'];
|
|
183
|
} elseif (isset($_POST['global'])) {
|
|
184
|
$global = $_POST['global'];
|
|
185
|
} elseif (isset($_GET['global'])) {
|
|
186
|
$global = $_GET['global'];
|
|
187
|
}
|
|
188
|
|
|
189
|
$chosen_get_string = '';
|
|
190
|
if (isset($chosen) && !empty($chosen)) {
|
|
191
|
foreach ($chosen as $id) {
|
|
192
|
$chosen_get_string .= 'chosen[]=' . $id . '&';
|
|
193
|
}
|
|
194
|
}
|
|
195
|
|
|
196
|
$audience = array();
|
|
197
|
|
hpdl
|
814
|
198
|
$Qcustomers = $osC_Database->query('select customers_id, customers_firstname, customers_lastname, customers_email_address from :table_customers where global_product_notifications = 1');
|
hpdl
|
1
|
199
|
$Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
200
|
$Qcustomers->execute();
|
|
201
|
|
|
202
|
while ($Qcustomers->next()) {
|
|
203
|
if (!isset($audience[$Qcustomers->valueInt('customers_id')])) {
|
|
204
|
$audience[$Qcustomers->valueInt('customers_id')] = array('firstname' => $Qcustomers->value('customers_firstname'),
|
|
205
|
'lastname' => $Qcustomers->value('customers_lastname'),
|
|
206
|
'email_address' => $Qcustomers->value('customers_email_address'));
|
|
207
|
}
|
|
208
|
}
|
|
209
|
|
|
210
|
$Qcustomers = $osC_Database->query('select distinct pn.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from :table_products_notifications pn, :table_customers c left join :table_newsletters_log nl on (c.customers_email_address = nl.email_address and nl.newsletters_id = :newsletters_id) where pn.customers_id = c.customers_id and nl.email_address is null');
|
|
211
|
$Qcustomers->bindTable(':table_products_notifications', TABLE_PRODUCTS_NOTIFICATIONS);
|
|
212
|
$Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
213
|
$Qcustomers->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG);
|
|
214
|
$Qcustomers->bindInt(':newsletters_id', $this->_newsletter_id);
|
|
215
|
|
|
216
|
if (isset($chosen) && !empty($chosen)) {
|
|
217
|
$Qcustomers->appendQuery('and pn.products_id in (:products_id)');
|
|
218
|
$Qcustomers->bindRaw(':products_id', implode(', ', $chosen));
|
|
219
|
}
|
|
220
|
|
|
221
|
$Qcustomers->execute();
|
|
222
|
|
|
223
|
while ($Qcustomers->next()) {
|
|
224
|
if (!isset($audience[$Qcustomers->valueInt('customers_id')])) {
|
|
225
|
$audience[$Qcustomers->valueInt('customers_id')] = array('firstname' => $Qcustomers->value('customers_firstname'),
|
|
226
|
'lastname' => $Qcustomers->value('customers_lastname'),
|
|
227
|
'email_address' => $Qcustomers->value('customers_email_address'));
|
|
228
|
}
|
|
229
|
}
|
|
230
|
|
|
231
|
if (sizeof($audience) > 0) {
|
|
232
|
$mimemessage = new email(array(base64_decode('WC1NYWlsZXI6IG9zQ29tbWVyY2UgKGh0dHA6Ly93d3cub3Njb21tZXJjZS5jb20p')));
|
|
233
|
$mimemessage->add_text($this->_newsletter_content);
|
|
234
|
$mimemessage->build_message();
|
|
235
|
|
|
236
|
foreach ($audience as $key => $value) {
|
|
237
|
$mimemessage->send($value['firstname'] . ' ' . $value['lastname'], $value['email_address'], '', EMAIL_FROM, $this->_newsletter_title);
|
|
238
|
|
|
239
|
$Qlog = $osC_Database->query('insert into :table_newsletters_log (newsletters_id, email_address, date_sent) values (:newsletters_id, :email_address, now())');
|
|
240
|
$Qlog->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG);
|
|
241
|
$Qlog->bindInt(':newsletters_id', $this->_newsletter_id);
|
|
242
|
$Qlog->bindValue(':email_address', $value['email_address']);
|
|
243
|
$Qlog->execute();
|
|
244
|
|
|
245
|
$time_end = explode(' ', microtime());
|
|
246
|
$timer_total = number_format(($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0])), 3);
|
|
247
|
|
|
248
|
if ($timer_total > $max_execution_time) {
|
|
249
|
echo '<p><font color="#38BB68"><b>' . TEXT_REFRESHING_PAGE . '</b></font></p>' .
|
hpdl
|
1076
|
250
|
'<p>' . osc_link_object(osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $this->_newsletter_id . '&action=nmSendConfirm&' . ((isset($global) && ($global == 'true')) ? 'global=true' : $chosen_get_string)), TEXT_CONTINUE_MANUALLY) . '</p>' .
|
|
251
|
'<META HTTP-EQUIV="refresh" content="2; URL=' . osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $this->_newsletter_id . '&action=nmSendConfirm&' . ((isset($global) && ($global == 'true')) ? 'global=true' : $chosen_get_string)) . '">';
|
hpdl
|
1
|
252
|
exit;
|
|
253
|
}
|
|
254
|
}
|
|
255
|
}
|
|
256
|
|
|
257
|
$Qupdate = $osC_Database->query('update :table_newsletters set date_sent = now(), status = 1 where newsletters_id = :newsletters_id');
|
|
258
|
$Qupdate->bindTable(':table_newsletters', TABLE_NEWSLETTERS);
|
|
259
|
$Qupdate->bindInt(':newsletters_id', $this->_newsletter_id);
|
|
260
|
$Qupdate->execute();
|
|
261
|
}
|
|
262
|
}
|
|
263
|
?>
|