contact.php (8116B)
1 <?php 2 class ControllerMarketingContact extends Controller { 3 private $error = array(); 4 5 public function index() { 6 $this->load->language('marketing/contact'); 7 8 $this->document->setTitle($this->language->get('heading_title')); 9 10 $data['user_token'] = $this->session->data['user_token']; 11 12 $data['breadcrumbs'] = array(); 13 14 $data['breadcrumbs'][] = array( 15 'text' => $this->language->get('text_home'), 16 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 17 ); 18 19 $data['breadcrumbs'][] = array( 20 'text' => $this->language->get('heading_title'), 21 'href' => $this->url->link('marketing/contact', 'user_token=' . $this->session->data['user_token'], true) 22 ); 23 24 $data['cancel'] = $this->url->link('marketing/contact', 'user_token=' . $this->session->data['user_token'], true); 25 26 $this->load->model('setting/store'); 27 28 $data['stores'] = $this->model_setting_store->getStores(); 29 30 $this->load->model('customer/customer_group'); 31 32 $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); 33 34 $data['header'] = $this->load->controller('common/header'); 35 $data['column_left'] = $this->load->controller('common/column_left'); 36 $data['footer'] = $this->load->controller('common/footer'); 37 38 $this->response->setOutput($this->load->view('marketing/contact', $data)); 39 } 40 41 public function send() { 42 $this->load->language('marketing/contact'); 43 44 $json = array(); 45 46 if ($this->request->server['REQUEST_METHOD'] == 'POST') { 47 if (!$this->user->hasPermission('modify', 'marketing/contact')) { 48 $json['error']['warning'] = $this->language->get('error_permission'); 49 } 50 51 if (!$this->request->post['subject']) { 52 $json['error']['subject'] = $this->language->get('error_subject'); 53 } 54 55 if (!$this->request->post['message']) { 56 $json['error']['message'] = $this->language->get('error_message'); 57 } 58 59 if (!$json) { 60 $this->load->model('setting/store'); 61 62 $store_info = $this->model_setting_store->getStore($this->request->post['store_id']); 63 64 if ($store_info) { 65 $store_name = $store_info['name']; 66 } else { 67 $store_name = $this->config->get('config_name'); 68 } 69 70 $this->load->model('setting/setting'); 71 $setting = $this->model_setting_setting->getSetting('config', $this->request->post['store_id']); 72 $store_email = isset($setting['config_email']) ? $setting['config_email'] : $this->config->get('config_email'); 73 74 $this->load->model('customer/customer'); 75 76 $this->load->model('customer/customer_group'); 77 78 $this->load->model('sale/order'); 79 80 if (isset($this->request->get['page'])) { 81 $page = $this->request->get['page']; 82 } else { 83 $page = 1; 84 } 85 86 $email_total = 0; 87 88 $emails = array(); 89 90 switch ($this->request->post['to']) { 91 case 'newsletter': 92 $customer_data = array( 93 'filter_newsletter' => 1, 94 'start' => ($page - 1) * 10, 95 'limit' => 10 96 ); 97 98 $email_total = $this->model_customer_customer->getTotalCustomers($customer_data); 99 100 $results = $this->model_customer_customer->getCustomers($customer_data); 101 102 foreach ($results as $result) { 103 $emails[] = $result['email']; 104 } 105 break; 106 case 'customer_all': 107 $customer_data = array( 108 'start' => ($page - 1) * 10, 109 'limit' => 10 110 ); 111 112 $email_total = $this->model_customer_customer->getTotalCustomers($customer_data); 113 114 $results = $this->model_customer_customer->getCustomers($customer_data); 115 116 foreach ($results as $result) { 117 $emails[] = $result['email']; 118 } 119 break; 120 case 'customer_group': 121 $customer_data = array( 122 'filter_customer_group_id' => $this->request->post['customer_group_id'], 123 'start' => ($page - 1) * 10, 124 'limit' => 10 125 ); 126 127 $email_total = $this->model_customer_customer->getTotalCustomers($customer_data); 128 129 $results = $this->model_customer_customer->getCustomers($customer_data); 130 131 foreach ($results as $result) { 132 $emails[$result['customer_id']] = $result['email']; 133 } 134 break; 135 case 'customer': 136 if (!empty($this->request->post['customer'])) { 137 foreach ($this->request->post['customer'] as $customer_id) { 138 $customer_info = $this->model_customer_customer->getCustomer($customer_id); 139 140 if ($customer_info) { 141 $emails[] = $customer_info['email']; 142 } 143 } 144 } 145 break; 146 case 'affiliate_all': 147 $affiliate_data = array( 148 'filter_affiliate' => 1, 149 'start' => ($page - 1) * 10, 150 'limit' => 10 151 ); 152 153 $email_total = $this->model_customer_customer->getTotalCustomers($affiliate_data); 154 155 $results = $this->model_customer_customer->getCustomers($affiliate_data); 156 157 foreach ($results as $result) { 158 $emails[] = $result['email']; 159 } 160 break; 161 case 'affiliate': 162 if (!empty($this->request->post['affiliate'])) { 163 foreach ($this->request->post['affiliate'] as $affiliate_id) { 164 $affiliate_info = $this->model_customer_customer->getCustomer($affiliate_id); 165 166 if ($affiliate_info) { 167 $emails[] = $affiliate_info['email']; 168 } 169 } 170 } 171 break; 172 case 'product': 173 if (isset($this->request->post['product'])) { 174 $email_total = $this->model_sale_order->getTotalEmailsByProductsOrdered($this->request->post['product']); 175 176 $results = $this->model_sale_order->getEmailsByProductsOrdered($this->request->post['product'], ($page - 1) * 10, 10); 177 178 foreach ($results as $result) { 179 $emails[] = $result['email']; 180 } 181 } 182 break; 183 } 184 185 if ($emails) { 186 $json['success'] = $this->language->get('text_success'); 187 188 $start = ($page - 1) * 10; 189 $end = $start + 10; 190 191 $json['success'] = sprintf($this->language->get('text_sent'), $start, $email_total); 192 193 if ($end < $email_total) { 194 $json['next'] = str_replace('&', '&', $this->url->link('marketing/contact/send', 'user_token=' . $this->session->data['user_token'] . '&page=' . ($page + 1), true)); 195 } else { 196 $json['next'] = ''; 197 } 198 199 $message = '<html dir="ltr" lang="en">' . "\n"; 200 $message .= ' <head>' . "\n"; 201 $message .= ' <title>' . $this->request->post['subject'] . '</title>' . "\n"; 202 $message .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n"; 203 $message .= ' </head>' . "\n"; 204 $message .= ' <body>' . html_entity_decode($this->request->post['message'], ENT_QUOTES, 'UTF-8') . '</body>' . "\n"; 205 $message .= '</html>' . "\n"; 206 207 foreach ($emails as $email) { 208 if (filter_var($email, FILTER_VALIDATE_EMAIL)) { 209 $mail = new Mail($this->config->get('config_mail_engine')); 210 $mail->parameter = $this->config->get('config_mail_parameter'); 211 $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); 212 $mail->smtp_username = $this->config->get('config_mail_smtp_username'); 213 $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); 214 $mail->smtp_port = $this->config->get('config_mail_smtp_port'); 215 $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); 216 217 $mail->setTo($email); 218 $mail->setFrom($store_email); 219 $mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8')); 220 $mail->setSubject(html_entity_decode($this->request->post['subject'], ENT_QUOTES, 'UTF-8')); 221 $mail->setHtml($message); 222 $mail->send(); 223 } 224 } 225 } else { 226 $json['error']['email'] = $this->language->get('error_email'); 227 } 228 } 229 } 230 231 $this->response->addHeader('Content-Type: application/json'); 232 $this->response->setOutput(json_encode($json)); 233 } 234 }