hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
mattice
|
151
|
3
|
$Id: newsletter.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
|
|
|
8
|
Copyright (c) 2004 osCommerce
|
|
9
|
|
|
10
|
Released under the GNU General Public License
|
|
11
|
*/
|
|
12
|
|
|
13
|
class osC_Newsletter_newsletter {
|
|
14
|
|
|
15
|
/* Private methods */
|
|
16
|
|
|
17
|
var $_title,
|
|
18
|
$_has_audience_selection = false,
|
|
19
|
$_newsletter_title,
|
|
20
|
$_newsletter_content,
|
|
21
|
$_newsletter_id,
|
|
22
|
$_audience_size = 0;
|
|
23
|
|
|
24
|
/* Class constructor */
|
|
25
|
|
|
26
|
function osC_Newsletter_newsletter($title = '', $content = '', $newsletter_id = '') {
|
|
27
|
$this->_title = MODULE_NEWSLETTER_NEWSLETTER_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
|
return false;
|
|
50
|
}
|
|
51
|
|
|
52
|
function showConfirmation() {
|
|
53
|
global $osC_Database;
|
|
54
|
|
|
55
|
$Qrecipients = $osC_Database->query('select count(*) 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 c.customers_newsletter = 1 and nl.email_address is null');
|
|
56
|
$Qrecipients->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
57
|
$Qrecipients->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG);
|
|
58
|
$Qrecipients->bindInt(':newsletters_id', $this->_newsletter_id);
|
|
59
|
$Qrecipients->execute();
|
|
60
|
|
|
61
|
$this->_audience_size = $Qrecipients->valueInt('total');
|
|
62
|
|
|
63
|
$confirmation_string = '<p><font color="#ff0000"><b>' . sprintf(MODULE_NEWSLETTER_NEWSLETTER_TEXT_TOTAL_RECIPIENTS, $this->_audience_size) . '</b></font></p>' .
|
|
64
|
'<p><b>' . $this->_newsletter_title . '</b></p>' .
|
hpdl
|
758
|
65
|
'<p>' . nl2br(osc_output_string_protected($this->_newsletter_content)) . '</p>' .
|
hpdl
|
1
|
66
|
'<p align="right">';
|
|
67
|
|
|
68
|
if ($this->_audience_size > 0) {
|
hpdl
|
1076
|
69
|
$confirmation_string .= '<input type="button" value="' . BUTTON_SEND . '" onclick="document.location.href=\'' . osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $_GET['nmID'] . '&action=nmSendConfirm') . '\';" class="operationButton"> ';
|
hpdl
|
1
|
70
|
}
|
|
71
|
|
hpdl
|
1076
|
72
|
$confirmation_string .= '<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
|
73
|
|
|
74
|
return $confirmation_string;
|
|
75
|
}
|
|
76
|
|
|
77
|
function sendEmail() {
|
|
78
|
global $osC_Database;
|
|
79
|
|
|
80
|
$max_execution_time = 0.8 * (int)ini_get('max_execution_time');
|
|
81
|
$time_start = explode(' ', PAGE_PARSE_START_TIME);
|
|
82
|
|
|
83
|
$Qrecipients = $osC_Database->query('select c.customers_firstname, c.customers_lastname, c.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 c.customers_newsletter = 1 and nl.email_address is null');
|
|
84
|
$Qrecipients->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
85
|
$Qrecipients->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG);
|
|
86
|
$Qrecipients->bindInt(':newsletters_id', $this->_newsletter_id);
|
|
87
|
$Qrecipients->execute();
|
|
88
|
|
|
89
|
if ($Qrecipients->numberOfRows() > 0) {
|
|
90
|
$mimemessage = new email(array(base64_decode('WC1NYWlsZXI6IG9zQ29tbWVyY2UgKGh0dHA6Ly93d3cub3Njb21tZXJjZS5jb20p')));
|
|
91
|
$mimemessage->add_text($this->_newsletter_content);
|
|
92
|
$mimemessage->build_message();
|
|
93
|
|
|
94
|
while ($Qrecipients->next()) {
|
|
95
|
$mimemessage->send($Qrecipients->value('customers_firstname') . ' ' . $Qrecipients->value('customers_lastname'), $Qrecipients->value('customers_email_address'), '', EMAIL_FROM, $this->_newsletter_title);
|
|
96
|
|
|
97
|
$Qlog = $osC_Database->query('insert into :table_newsletters_log (newsletters_id, email_address, date_sent) values (:newsletters_id, :email_address, now())');
|
|
98
|
$Qlog->bindTable(':table_newsletters_log', TABLE_NEWSLETTERS_LOG);
|
|
99
|
$Qlog->bindInt(':newsletters_id', $this->_newsletter_id);
|
|
100
|
$Qlog->bindValue(':email_address', $Qrecipients->value('customers_email_address'));
|
|
101
|
$Qlog->execute();
|
|
102
|
|
|
103
|
$time_end = explode(' ', microtime());
|
|
104
|
$timer_total = number_format(($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0])), 3);
|
|
105
|
|
|
106
|
if ($timer_total > $max_execution_time) {
|
|
107
|
echo '<p><font color="#38BB68"><b>' . TEXT_REFRESHING_PAGE . '</b></font></p>' .
|
hpdl
|
1076
|
108
|
'<p>' . osc_link_object(osc_href_link_admin(FILENAME_DEFAULT, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $this->_newsletter_id . '&action=nmSendConfirm'), TEXT_CONTINUE_MANUALLY) . '</p>' .
|
|
109
|
'<META HTTP-EQUIV="refresh" content="2; URL=' . osc_href_link_admin(FILENAME_DEFAULTS, 'newsletters&page=' . $_GET['page'] . '&nmID=' . $this->_newsletter_id . '&action=nmSendConfirm') . '">';
|
hpdl
|
1
|
110
|
exit;
|
|
111
|
}
|
|
112
|
}
|
|
113
|
|
|
114
|
$Qrecipients->freeResult();
|
|
115
|
}
|
|
116
|
|
|
117
|
$Qupdate = $osC_Database->query('update :table_newsletters set date_sent = now(), status = 1 where newsletters_id = :newsletters_id');
|
|
118
|
$Qupdate->bindTable(':table_newsletters', TABLE_NEWSLETTERS);
|
|
119
|
$Qupdate->bindInt(':newsletters_id', $this->_newsletter_id);
|
|
120
|
$Qupdate->execute();
|
|
121
|
}
|
|
122
|
}
|
|
123
|
?>
|