Agenceweb_Mailpro - Version 1.0.1

Version Notes

This is a stable release.

Download this release

Release Info

Developer Hugues Martinelli
Extension Agenceweb_Mailpro
Version 1.0.1
Comparing to
See all releases


Code changes from version 1.0.0 to 1.0.1

app/code/local/Agenceweb/Mailpro/Helper/Data.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Created on July 13, 2011
4
+ * Author Ivan Proskuryakov - volgodark@gmail.com - Magazento.com
5
+ * Copyright Proskuryakov Ivan. Magazento.com © 2011. All Rights Reserved.
6
+ * Single Use, Limited Licence and Single Use No Resale Licence ["Single Use"]
7
+ */
8
+ ?>
9
+ <?php
10
+
11
+ class Agenceweb_Mailpro_Helper_Data extends Mage_Core_Helper_Abstract
12
+ {
13
+
14
+
15
+ }
app/code/local/Agenceweb/Mailpro/Model/Mailpro.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Agenceweb_Mailpro_Model_Mailpro extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('mailpro/mailpro');
9
+ }
10
+ public function AddressBookList()
11
+ {
12
+ $array = array();
13
+ $client_id = Mage::getStoreConfig('mailpro/options/mailpro_client_id');
14
+ $api_key = Mage::getStoreConfig('mailpro/options/mailpro_api_key');
15
+ $mailpro_enabled = Mage::getStoreConfig('mailpro/options/enable');
16
+ if($mailpro_enabled != 0 && $client_id != NULL && $api_key != NULL)
17
+ {
18
+ $api_url = "https://api.mailpro.com/v2/addressbook/list.json?IDClient=$client_id&APIKEY=".$api_key."&type=1";
19
+ $result = file_get_contents("$api_url");
20
+ if($result)
21
+ {
22
+ $new_result = substr($result, 19);
23
+ $new_result = substr_replace($new_result ,"",-15);
24
+ $array = json_decode($new_result);
25
+ return $array;
26
+ }
27
+ }
28
+ else
29
+ {
30
+ '';
31
+ }
32
+ }
33
+
34
+ public function CustomersGroup()
35
+ {
36
+ $groups = Mage::getResourceModel('customer/group_collection')
37
+ ->addFieldToFilter('customer_group_id', array('gt'=> 0))
38
+ ->load()
39
+ ->toOptionArray();
40
+ return $groups;
41
+ }
42
+ }
app/code/local/Agenceweb/Mailpro/controllers/AccountController.php ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Customer
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer account controller
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Customer
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ include_once("Mage/Customer/controllers/AccountController.php");
35
+ class Agenceweb_Mailpro_AccountController extends Mage_Customer_AccountController
36
+ {
37
+ /**
38
+ * Create customer account action
39
+ */
40
+ public function createPostAction()
41
+ {
42
+ $session = $this->_getSession();
43
+ if ($session->isLoggedIn()) {
44
+ $this->_redirect('*/*/');
45
+ return;
46
+ }
47
+ $session->setEscapeMessages(true); // prevent XSS injection in user input
48
+ if ($this->getRequest()->isPost()) {
49
+ $errors = array();
50
+
51
+ if (!$customer = Mage::registry('current_customer')) {
52
+ $customer = Mage::getModel('customer/customer')->setId(null);
53
+ }
54
+
55
+ /* @var $customerForm Mage_Customer_Model_Form */
56
+ $customerForm = Mage::getModel('customer/form');
57
+ $customerForm->setFormCode('customer_account_create')
58
+ ->setEntity($customer);
59
+
60
+ $customerData = $customerForm->extractData($this->getRequest());
61
+
62
+ if ($this->getRequest()->getParam('is_subscribed', false)) {
63
+ $customer->setIsSubscribed(1);
64
+ }
65
+
66
+ /**
67
+ * Initialize customer group id
68
+ */
69
+ $customer->getGroupId();
70
+
71
+ if ($this->getRequest()->getPost('create_address')) {
72
+ /* @var $address Mage_Customer_Model_Address */
73
+ $address = Mage::getModel('customer/address');
74
+ /* @var $addressForm Mage_Customer_Model_Form */
75
+ $addressForm = Mage::getModel('customer/form');
76
+ $addressForm->setFormCode('customer_register_address')
77
+ ->setEntity($address);
78
+
79
+ $addressData = $addressForm->extractData($this->getRequest(), 'address', false);
80
+ $addressErrors = $addressForm->validateData($addressData);
81
+ if ($addressErrors === true) {
82
+ $address->setId(null)
83
+ ->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
84
+ ->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
85
+ $addressForm->compactData($addressData);
86
+ $customer->addAddress($address);
87
+
88
+ $addressErrors = $address->validate();
89
+ if (is_array($addressErrors)) {
90
+ $errors = array_merge($errors, $addressErrors);
91
+ }
92
+ } else {
93
+ $errors = array_merge($errors, $addressErrors);
94
+ }
95
+ }
96
+
97
+ try {
98
+ $customerErrors = $customerForm->validateData($customerData);
99
+ if ($customerErrors !== true) {
100
+ $errors = array_merge($customerErrors, $errors);
101
+ } else {
102
+ $customerForm->compactData($customerData);
103
+ $customer->setPassword($this->getRequest()->getPost('password'));
104
+ $customer->setConfirmation($this->getRequest()->getPost('confirmation'));
105
+ $customerErrors = $customer->validate();
106
+ if (is_array($customerErrors)) {
107
+ $errors = array_merge($customerErrors, $errors);
108
+ }
109
+ }
110
+
111
+ $validationResult = count($errors) == 0;
112
+
113
+ if (true === $validationResult) {
114
+ $customer->save();
115
+
116
+ Mage::dispatchEvent('customer_register_success',
117
+ array('account_controller' => $this, 'customer' => $customer)
118
+ );
119
+
120
+ if ($customer->isConfirmationRequired()) {
121
+ $customer->sendNewAccountEmail(
122
+ 'confirmation',
123
+ $session->getBeforeAuthUrl(),
124
+ Mage::app()->getStore()->getId()
125
+ );
126
+ $session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
127
+ $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
128
+ return;
129
+ } else {
130
+ $session->setCustomerAsLoggedIn($customer);
131
+ ///// mailpro code
132
+ $mailpro_enabled = Mage::getStoreConfig('mailpro/options/enable');
133
+ $client_id = Mage::getStoreConfig('mailpro/options/mailpro_client_id');
134
+ $api_key = Mage::getStoreConfig('mailpro/options/mailpro_api_key');
135
+ $book_id = Mage::getStoreConfig('mailpro/options/mailpro_addid');
136
+ $email = $customer->getEmail();
137
+ $customer_firstName = $customer->getFirstname();
138
+ $customer_lastName = $customer->getLastname();
139
+ $email_list = "$email,$customer_firstName,$customer_lastName,,,,,,,,,,,,,,,,,,,,,,,";
140
+ if($mailpro_enabled == 1 && $client_id != NULL && $api_key != NULL && $book_id != 0)
141
+ {
142
+
143
+ $param = "APIKey=$api_key&IDClient=$client_id&AddressBookID=$book_id&force=2&emailList=$email_list";
144
+
145
+ $api_url = "https://api.mailpro.com/v2/email/add.xml";
146
+ $proxy = '10.0.0.20:80';
147
+ $ch = curl_init();
148
+
149
+ //echo $api_url;
150
+ curl_setopt($ch, CURLOPT_URL, $api_url);
151
+ curl_setopt($ch, CURLOPT_PROXY, $proxy);
152
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
153
+ curl_setopt($ch, CURLOPT_POST, true);
154
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
155
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
156
+ curl_exec($ch);
157
+ /*
158
+ if( ! $result = curl_exec($ch))
159
+ {
160
+ trigger_error(curl_error($ch));
161
+ }*/
162
+ /*
163
+ curl_close($ch);
164
+ print_r($result);
165
+ $arr_date = json_decode($result);
166
+ print_r($arr_date);
167
+ exit;*/
168
+ }
169
+ ///// mailpro code end /////////
170
+
171
+ $url = $this->_welcomeCustomer($customer);
172
+ $this->_redirectSuccess($url);
173
+ return;
174
+ }
175
+ } else {
176
+ $session->setCustomerFormData($this->getRequest()->getPost());
177
+ if (is_array($errors)) {
178
+ foreach ($errors as $errorMessage) {
179
+ $session->addError($errorMessage);
180
+ }
181
+ } else {
182
+ $session->addError($this->__('Invalid customer data'));
183
+ }
184
+ }
185
+ } catch (Mage_Core_Exception $e) {
186
+ $session->setCustomerFormData($this->getRequest()->getPost());
187
+ if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
188
+ $url = Mage::getUrl('customer/account/forgotpassword');
189
+ $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
190
+ $session->setEscapeMessages(false);
191
+ } else {
192
+ $message = $e->getMessage();
193
+ }
194
+ $session->addError($message);
195
+ } catch (Exception $e) {
196
+ $session->setCustomerFormData($this->getRequest()->getPost())
197
+ ->addException($e, $this->__('Cannot save the customer.'));
198
+ }
199
+ }
200
+
201
+ $this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true)));
202
+ }
203
+
204
+ /**
205
+ * Confirm customer account by id and confirmation key
206
+ */
207
+ public function confirmAction()
208
+ {
209
+ if ($this->_getSession()->isLoggedIn()) {
210
+ $this->_redirect('*/*/');
211
+ return;
212
+ }
213
+ try {
214
+ $id = $this->getRequest()->getParam('id', false);
215
+ $key = $this->getRequest()->getParam('key', false);
216
+ $backUrl = $this->getRequest()->getParam('back_url', false);
217
+ if (empty($id) || empty($key)) {
218
+ throw new Exception($this->__('Bad request.'));
219
+ }
220
+
221
+ // load customer by id (try/catch in case if it throws exceptions)
222
+ try {
223
+ $customer = Mage::getModel('customer/customer')->load($id);
224
+ if ((!$customer) || (!$customer->getId())) {
225
+ throw new Exception('Failed to load customer by id.');
226
+ }
227
+ }
228
+ catch (Exception $e) {
229
+ throw new Exception($this->__('Wrong customer account specified.'));
230
+ }
231
+
232
+ // check if it is inactive
233
+ if ($customer->getConfirmation()) {
234
+ if ($customer->getConfirmation() !== $key) {
235
+ throw new Exception($this->__('Wrong confirmation key.'));
236
+ }
237
+
238
+ // activate customer
239
+ try {
240
+ $customer->setConfirmation(null);
241
+ $customer->save();
242
+ ///// mailpro code
243
+ $mailpro_enabled = Mage::getStoreConfig('mailpro/options/enable');
244
+ $client_id = Mage::getStoreConfig('mailpro/options/mailpro_client_id');
245
+ $api_key = Mage::getStoreConfig('mailpro/options/mailpro_api_key');
246
+ $book_id = Mage::getStoreConfig('mailpro/options/mailpro_addid');
247
+ $email = $customer->getEmail();
248
+ $customer_firstName = $customer->getFirstname();
249
+ $customer_lastName = $customer->getLastname();
250
+ $email_list = "$email,$customer_firstName,$customer_lastName,,,,,,,,,,,,,,,,,,,,,,,";
251
+ if($mailpro_enabled == 1 && $client_id != NULL && $api_key != NULL && $book_id != 0)
252
+ {
253
+ $param = "APIKey=$api_key&IDClient=$client_id&AddressBookID=$book_id&force=2&emailList=$email_list";
254
+
255
+ $api_url = "https://api.mailpro.com/v2/email/add.xml";
256
+ $proxy = '10.0.0.20:80';
257
+ $ch = curl_init();
258
+
259
+ //echo $api_url;
260
+ curl_setopt($ch, CURLOPT_URL, $api_url);
261
+ curl_setopt($ch, CURLOPT_PROXY, $proxy);
262
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
263
+ curl_setopt($ch, CURLOPT_POST, true);
264
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
265
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
266
+ curl_exec($ch);
267
+ /*
268
+ if( ! $result = curl_exec($ch))
269
+ {
270
+ trigger_error(curl_error($ch));
271
+ }*/
272
+ /*
273
+ curl_close($ch);
274
+ print_r($result);
275
+ $arr_date = json_decode($result);
276
+ print_r($arr_date);
277
+ exit;*/
278
+ }
279
+ ///// mailpro code end /////////
280
+ }
281
+ catch (Exception $e) {
282
+ throw new Exception($this->__('Failed to confirm customer account.'));
283
+ }
284
+
285
+ // log in and send greeting email, then die happy
286
+ $this->_getSession()->setCustomerAsLoggedIn($customer);
287
+ $successUrl = $this->_welcomeCustomer($customer, true);
288
+ $this->_redirectSuccess($backUrl ? $backUrl : $successUrl);
289
+ return;
290
+ }
291
+
292
+ // die happy
293
+ $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
294
+ return;
295
+ }
296
+ catch (Exception $e) {
297
+ // die unhappy
298
+ $this->_getSession()->addError($e->getMessage());
299
+ $this->_redirectError(Mage::getUrl('*/*/index', array('_secure'=>true)));
300
+ return;
301
+ }
302
+ }
303
+ }
app/code/local/Agenceweb/Mailpro/controllers/SynchronizeController.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Customer
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Customer account controller
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Customer
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ /*
35
+ */
36
+ class Agenceweb_Mailpro_SynchronizeController extends Mage_Adminhtml_Controller_Action
37
+ {
38
+
39
+ public function indexAction()
40
+ {
41
+ $this->loadLayout();
42
+ $this->_setActiveMenu('mailpro/config');
43
+ $block = $this->getLayout()->createBlock(
44
+ 'core/template',
45
+ 'mailpro',
46
+ array('template' => 'mailpro/index.phtml')
47
+ );
48
+
49
+ $this->getLayout()->getBlock('content')->append($block);
50
+
51
+ //Release layout stream... lol... sounds fancy
52
+ $this->renderLayout();
53
+
54
+
55
+ }
56
+
57
+ public function postAction()
58
+ {
59
+ $session = $this->_getSession();
60
+ $postData = Mage::app()->getRequest()->getPost();
61
+ $add_book_id = $postData['mailpro_addid'];
62
+ $group_id = $postData['customer_group'];
63
+ $newsletter_yes = $postData['chkYes'];
64
+ $newsletter_no = $postData['chkNo'];
65
+
66
+ $mailpro_enabled = Mage::getStoreConfig('mailpro/options/enable');
67
+ $client_id = Mage::getStoreConfig('mailpro/options/mailpro_client_id');
68
+ $api_key = Mage::getStoreConfig('mailpro/options/mailpro_api_key');
69
+
70
+ if($add_book_id == 0 || $add_book_id == '')
71
+ {
72
+ $session->addError($this->__('Address Book required.'));
73
+ }
74
+ else
75
+ {
76
+ $email_list = '';
77
+ $collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
78
+ $subscriber = Mage::getModel('newsletter/subscriber');
79
+ $counter = 0;
80
+ foreach ($collection as $customer)
81
+ {
82
+ $email = $customer->getEmail();
83
+ $customer_group_id = $customer->getGroupId();
84
+
85
+ if($group_id == 0 && $newsletter_yes == 1 && $newsletter_no == 1)
86
+ {
87
+ $counter++;
88
+ $customer_firstName = $customer->getFirstname();
89
+ $customer_lastName = $customer->getLastname();
90
+ $email_list .= "$email,$customer_firstName,$customer_lastName,,,,,,,,,,,,,,,,,,,,,,,".'%0D%0A';
91
+ }
92
+ else if($group_id == 0 && $newsletter_yes == 1 && $newsletter_no == 0)
93
+ {
94
+ $is_subscribe_customer = $subscriber->loadByEmail($email);
95
+ $sub_status = $is_subscribe_customer->getStatus();
96
+ if($sub_status == 1)
97
+ {
98
+ $counter++;
99
+ $customer_firstName = $customer->getFirstname();
100
+ $customer_lastName = $customer->getLastname();
101
+ $email_list .= "$email,$customer_firstName,$customer_lastName,,,,,,,,,,,,,,,,,,,,,,,".'%0D%0A';
102
+ }
103
+ }
104
+ else if($group_id == 0 && $newsletter_yes == 0 && $newsletter_no == 1)
105
+ {
106
+ $is_subscribe_customer = $subscriber->loadByEmail($email);
107
+ $sub_status = $is_subscribe_customer->getStatus();
108
+ if($sub_status == 3 || $sub_status == '')
109
+ {
110
+ $counter++;
111
+ $customer_firstName = $customer->getFirstname();
112
+ $customer_lastName = $customer->getLastname();
113
+ $email_list .= "$email,$customer_firstName,$customer_lastName,,,,,,,,,,,,,,,,,,,,,,,".'%0D%0A';
114
+ }
115
+ }
116
+ else if($group_id == 0 && $newsletter_yes == 0 && $newsletter_no == 0)
117
+ {
118
+ $counter++;
119
+ $customer_firstName = $customer->getFirstname();
120
+ $customer_lastName = $customer->getLastname();
121
+ $email_list .= "$email,$customer_firstName,$customer_lastName,,,,,,,,,,,,,,,,,,,,,,,".'%0D%0A';
122
+ }
123
+ else if($group_id > 0 && $newsletter_yes == 1 && $newsletter_no == 0)
124
+ {
125
+ $is_subscribe_customer = $subscriber->loadByEmail($email);
126
+ $sub_status = $is_subscribe_customer->getStatus();
127
+ if($customer_group_id == $group_id && $sub_status == 1)
128
+ {
129
+ $counter++;
130
+ $customer_firstName = $customer->getFirstname();
131
+ $customer_lastName = $customer->getLastname();
132
+ $email_list .= "$email,$customer_firstName,$customer_lastName,,,,,,,,,,,,,,,,,,,,,,,".'%0D%0A';
133
+ }
134
+ }
135
+ else if($group_id > 0 && $newsletter_yes == 0 && $newsletter_no == 1)
136
+ {
137
+ $is_subscribe_customer = $subscriber->loadByEmail($email);
138
+ $sub_status = $is_subscribe_customer->getStatus();
139
+ if($customer_group_id == $group_id && ($sub_status == 3 || $sub_status == ''))
140
+ {
141
+ $counter++;
142
+ $customer_firstName = $customer->getFirstname();
143
+ $customer_lastName = $customer->getLastname();
144
+ $email_list .= "$email,$customer_firstName,$customer_lastName,,,,,,,,,,,,,,,,,,,,,,,".'%0D%0A';
145
+ }
146
+ }
147
+ else if($group_id > 0 && $newsletter_yes == 0 && $newsletter_no == 0)
148
+ {
149
+ if($customer_group_id == $group_id)
150
+ {
151
+ $counter++;
152
+ $customer_firstName = $customer->getFirstname();
153
+ $customer_lastName = $customer->getLastname();
154
+ $email_list .= "$email,$customer_firstName,$customer_lastName,,,,,,,,,,,,,,,,,,,,,,,".'%0D%0A';
155
+ }
156
+ }
157
+ }
158
+ if($email_list != '')
159
+ {
160
+ $param = "APIKey=$api_key&IDClient=$client_id&AddressBookID=$add_book_id&force=2&emailList=$email_list";
161
+ $api_url = "https://api.mailpro.com/v2/email/add.xml";
162
+ $ch = curl_init();
163
+
164
+ curl_setopt($ch, CURLOPT_URL, $api_url);
165
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
166
+ curl_setopt($ch, CURLOPT_POST, true);
167
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
168
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
169
+ if( ! $result = curl_exec($ch))
170
+ {
171
+ trigger_error(curl_error($ch));
172
+ }
173
+ curl_close($ch);
174
+ }
175
+ $session->addSuccess($this->__('Synchronization process complete.'.' ('.$counter.' records affected)'));
176
+ }
177
+ $this->_redirectReferer();
178
+ }
179
+ }
app/code/local/Agenceweb/Mailpro/etc/adminhtml.xml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <mailpro module="mailpro">
5
+ <title>Mailpro</title>
6
+ <sort_order>71</sort_order>
7
+ <children>
8
+ <config translate="title" module="mailpro">
9
+ <title>Configuration</title>
10
+ <sort_order>0</sort_order>
11
+ <action>adminhtml/system_config/edit/section/mailpro/</action>
12
+ </config>
13
+ <synchronize translate="title" module="mailpro">
14
+ <title>Synchronize Customers</title>
15
+ <sort_order>1</sort_order>
16
+ <action>mailpro/synchronize/index</action>
17
+ </synchronize>
18
+ </children>
19
+ </mailpro>
20
+ </menu>
21
+ <acl>
22
+ <resources>
23
+ <all>
24
+ <title>Allow Everything</title>
25
+ </all>
26
+ <admin>
27
+ <children>
28
+ <Agenceweb_Mailpro>
29
+ <title>Mailpro Module</title>
30
+ <sort_order>10</sort_order>
31
+ </Agenceweb_Mailpro>
32
+ <system>
33
+ <children>
34
+ <config>
35
+ <children>
36
+ <mailpro translate="title" module="mailpro">
37
+ <title>Mailpro</title>
38
+ <sort_order>50</sort_order>
39
+ </mailpro>
40
+ </children>
41
+ </config>
42
+ </children>
43
+ </system>
44
+ </children>
45
+ </admin>
46
+ </resources>
47
+ </acl>
48
+ </config>
app/code/local/Agenceweb/Mailpro/etc/config.xml ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <config>
3
+ <modules>
4
+ <Agenceweb_Mailpro>
5
+ <version>1.0.0</version>
6
+ </Agenceweb_Mailpro>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <mailpro>
11
+ <class>Agenceweb_Mailpro_Block</class>
12
+ </mailpro>
13
+ </blocks>
14
+ <models>
15
+ <mailpro>
16
+ <class>Agenceweb_Mailpro_Model</class>
17
+ <resourceModel>mailpro_mysql4</resourceModel>
18
+ </mailpro>
19
+ </models>
20
+ <helpers>
21
+ <mailpro>
22
+ <class>Agenceweb_Mailpro_Helper</class>
23
+ </mailpro>
24
+ </helpers>
25
+ <resources>
26
+ <mailpro_setup>
27
+ <setup>
28
+ <module>Agenceweb_Mailpro</module>
29
+ </setup>
30
+ <connection>
31
+ <use>core_setup</use>
32
+ </connection>
33
+ </mailpro_setup>
34
+ <mailpro_write>
35
+ <connection>
36
+ <use>core_write</use>
37
+ </connection>
38
+ </mailpro_write>
39
+ <mailpro_read>
40
+ <connection>
41
+ <use>core_read</use>
42
+ </connection>
43
+ </mailpro_read>
44
+ </resources>
45
+ </global>
46
+ <adminhtml>
47
+ <acl>
48
+ <resources>
49
+ <admin>
50
+ <children>
51
+ <system>
52
+ <children>
53
+ <config>
54
+ <children>
55
+ <mailpro translate="title" module="mailpro">
56
+ <title>Mailpro</title>
57
+ </mailpro>
58
+ </children>
59
+ </config>
60
+ </children>
61
+ </system>
62
+ </children>
63
+ </admin>
64
+ </resources>
65
+ </acl>
66
+ <layout>
67
+ <updates>
68
+ <mailpro>
69
+ <file>mailpro.xml</file>
70
+ </mailpro>
71
+ </updates>
72
+ </layout>
73
+ </adminhtml>
74
+ <admin>
75
+ <routers>
76
+ <agenceweb_mailpro>
77
+ <use>admin</use>
78
+ <args>
79
+ <module>Agenceweb_Mailpro</module>
80
+ <frontName>mailpro</frontName>
81
+ </args>
82
+ </agenceweb_mailpro>
83
+ </routers>
84
+ </admin>
85
+ <frontend>
86
+ <routers>
87
+ <customer>
88
+ <args>
89
+ <modules>
90
+ <Agenceweb_Mailpro before="Mage_Customer">Agenceweb_Mailpro</Agenceweb_Mailpro>
91
+ </modules>
92
+ </args>
93
+ </customer>
94
+ </routers>
95
+ </frontend>
96
+ <default>
97
+ <mailpro>
98
+ <options>
99
+ <enable>0</enable>
100
+ </options>
101
+ </mailpro>
102
+ </default>
103
+ </config>
app/code/local/Agenceweb/Mailpro/etc/system.xml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <mailpro translate="label">
5
+ <label>Mailpro</label>
6
+ <sort_order>500</sort_order>
7
+ </mailpro>
8
+ </tabs>
9
+ <sections>
10
+ <mailpro module="mailpro">
11
+ <label>Mailpro Configuration</label>
12
+ <tab>mailpro</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>100</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <options translate="label">
20
+ <label>Settings</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>1</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <enable translate="label">
28
+ <label>Enable</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>0</show_in_website>
34
+ <show_in_store>0</show_in_store>
35
+ </enable>
36
+ <mailpro_client_id translate="label">
37
+ <label>Mailpro Client Id</label>
38
+ <frontend_type>text</frontend_type>
39
+ <sort_order>2</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>0</show_in_website>
42
+ <show_in_store>0</show_in_store>
43
+ </mailpro_client_id>
44
+ <mailpro_api_key translate="label">
45
+ <label>Mailpro Api Key</label>
46
+ <frontend_type>text</frontend_type>
47
+ <sort_order>3</sort_order>
48
+ <show_in_default>1</show_in_default>
49
+ <show_in_website>0</show_in_website>
50
+ <show_in_store>0</show_in_store>
51
+ </mailpro_api_key>
52
+ </fields>
53
+ </options>
54
+ </groups>
55
+ </mailpro>
56
+ </sections>
57
+ </config>
app/design/adminhtml/default/default/template/mailpro/index.phtml ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ $mailpro_model = Mage::getModel('mailpro/mailpro');
29
+ $addressBook_data = $mailpro_model->AddressBookList();
30
+ $groups = $mailpro_model->CustomersGroup();
31
+ ?>
32
+ <div class="content-header">
33
+ <h3 class="icon-head head-system-account">Mailpro Synchronize Customers</h3>
34
+ <p class="form-buttons">
35
+ <button id="id_923f18bcddd9ac229ab39746cffe47d5" class="scalable " style="" onclick="setLocation(window.location.href)" type="button">
36
+ <span>Reset</span>
37
+ </button>
38
+ <button id="id_9d1f27cfd05e163eace5f9bda17624f1" class="scalable save" style="" onclick="showLoader();editForm.submit();" type="button">
39
+ <span>Synchronize</span>
40
+ </button>
41
+ </p>
42
+ </div>
43
+ <div class="entry-edit">
44
+ <form id="edit_form" name="edit_form" method="post" action="<?php echo Mage::getUrl('mailpro/synchronize/post/'); ?>">
45
+ <div>
46
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
47
+ </div>
48
+ <div class="entry-edit-head">
49
+ <h4 class="icon-head head-edit-form fieldset-legend">Synchronize Customers</h4>
50
+ <div class="form-buttons"></div>
51
+ </div>
52
+ <div id="base_fieldset" class="fieldset ">
53
+ <div class="hor-scroll">
54
+ <table class="form-list" cellspacing="0">
55
+ <tbody>
56
+ <tr>
57
+ <td class="label">
58
+ <label for="customerGroup"><?php echo $this->__('Select Customers Group');?><span class="required">*</span></label>
59
+ </td>
60
+ <td class="value">
61
+ <select name="customer_group" title="<?php echo $this->__('Customer Group') ?>" class="validate-select">
62
+ <option value="0"><?php echo $this->__('All') ?></option>
63
+ <?php
64
+ if(count($groups) > 0):
65
+ foreach ($groups as $a){
66
+ echo "<option value='".$a['value']."'>".$a['label']."</option>";
67
+ }
68
+ endif;
69
+ ?>
70
+ </select>
71
+ </td>
72
+ </tr>
73
+ <tr>
74
+ <td class="label">
75
+ <label for="newsletterSubscriber">Newsletter Subscriber<span class="required">*</span></label>
76
+ </td>
77
+ <td class="value">
78
+ <input type="checkbox" onclick="this.value = this.checked ? 1 : 0;" name="chkYes">&nbsp;<?php echo $this->__('Yes');?>&nbsp;</input>&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" onclick="this.value = this.checked ? 1 : 0;" name="chkNo">&nbsp;<?php echo $this->__('No');?>&nbsp;</input>
79
+ </td>
80
+ </tr>
81
+ <tr>
82
+ <td class="label">
83
+ <label for="addressBook"><?php echo $this->__('Select Address Book')?><span class="required">*</span></label>
84
+ </td>
85
+ <td class="value">
86
+ <select id="mailpro_addid" class=" select" name="mailpro_addid">
87
+ <?php if(count($addressBook_data) > 0):?>
88
+ <option selected="selected" value="0"><?php echo $this->__('Please select address book');?></option>
89
+ <?php
90
+ for($i = 0;$i< count($addressBook_data);$i++)
91
+ {
92
+ if($addressBook_data[$i]->{"Title"} != '')
93
+ {
94
+ $title = $addressBook_data[$i]->{"Title"};
95
+ $id = $addressBook_data[$i]->{"AddressBookId"};
96
+ }
97
+ ?>
98
+ <option value="<?php echo $id;?>"><?php echo $title;?></option>
99
+ <?php
100
+ }
101
+ ?>
102
+ <?php endif;?>
103
+ </select>
104
+ </td>
105
+ </tr>
106
+ </tbody>
107
+ </table>
108
+ </div>
109
+ </div>
110
+ </form>
111
+ </div>
112
+ <script type="text/javascript">
113
+ editForm = new varienForm('edit_form', '');
114
+ function showLoader()
115
+ {
116
+ document.getElementById('loading-mask').style.display = '';
117
+ }
118
+ </script
119
+ </div>
app/etc/modules/Agenceweb_Mailpro.xml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_PageCache
24
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+ -->
28
+ <config>
29
+ <modules>
30
+ <Agenceweb_Mailpro>
31
+ <active>true</active>
32
+ <codePool>local</codePool>
33
+ </Agenceweb_Mailpro>
34
+ </modules>
35
+ </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Agenceweb_Mailpro</name>
4
- <version>1.0.0</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
@@ -13,9 +13,9 @@ campaign.</summary>
13
  <description>Use our Magento Email Marketing plug-in to synchronize your customer database in order to send professional newsletter with high delivery rates. Use our powerful solution to analyze your openings, clic rates and much more. Create your account now for free to try our Magento Emailing Plug-in and use for free one of our 400 Free templates.</description>
14
  <notes>This is a stable release.</notes>
15
  <authors><author><name>Hugues Martinelli</name><user>mailpro</user><email>h.martinelli@agenceweb.com</email></author><author><name>Bilal Bin Ishtiaque</name><user>bilalishtiaque</user><email>bilal.ishtiaque@wibs-group.com</email></author></authors>
16
- <date>2012-08-22</date>
17
- <time>07:03:55</time>
18
- <contents><target name="magecommunity"><dir name="."><dir name="app"><dir name="code"><file name="community" hash=""/></dir></dir></dir></target><target name="magelib"><dir name="."><file name="lib" hash=""/></dir></target><target name="magelocale"><dir name="."><dir name="app"><file name="locale" hash=""/></dir></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Agenceweb_Mailpro</name>
4
+ <version>1.0.1</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
13
  <description>Use our Magento Email Marketing plug-in to synchronize your customer database in order to send professional newsletter with high delivery rates. Use our powerful solution to analyze your openings, clic rates and much more. Create your account now for free to try our Magento Emailing Plug-in and use for free one of our 400 Free templates.</description>
14
  <notes>This is a stable release.</notes>
15
  <authors><author><name>Hugues Martinelli</name><user>mailpro</user><email>h.martinelli@agenceweb.com</email></author><author><name>Bilal Bin Ishtiaque</name><user>bilalishtiaque</user><email>bilal.ishtiaque@wibs-group.com</email></author></authors>
16
+ <date>2012-08-23</date>
17
+ <time>07:17:31</time>
18
+ <contents><target name="magelocal"><dir name="Agenceweb"><dir name="Mailpro"><dir name="Helper"><file name="Data.php" hash="7d8f910182a51989da4e6c253721e4f1"/></dir><dir name="Model"><file name="Mailpro.php" hash="31c6127e387aa576bcc69df9ec0e4979"/></dir><dir name="controllers"><file name="AccountController.php" hash="78091ae631eeb419794ca149a3ddc4de"/><file name="SynchronizeController.php" hash="ae3df937a4e33d59e251da4197d760b7"/></dir><dir name="etc"><file name="adminhtml.xml" hash="cbf1c50315350339a94e49dadad9b16c"/><file name="config.xml" hash="3ce00c048ca04146f09bdb25ef8fe498"/><file name="system.xml" hash="b8ce3abd9061134810573f4c4ec9e0b1"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="mailpro"><file name="index.phtml" hash="ce002d0fa26f8d872e55cd9e5b589a69"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Agenceweb_Mailpro.xml" hash="1e85cb12cb64819d177cdef0f764f805"/></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
21
  </package>