private function getForm() { $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['text_enabled'] = $this->language->get('text_enabled'); $this->data['text_disabled'] = $this->language->get('text_disabled'); $this->data['text_none'] = $this->language->get('text_none'); $this->data['text_select'] = $this->language->get('text_select'); $this->data['entry_name'] = $this->language->get('entry_name'); $this->data['entry_parent'] = $this->language->get('entry_parent'); $this->data['entry_email'] = $this->language->get('entry_email'); $this->data['entry_url'] = $this->language->get('entry_url'); $this->data['entry_rating'] = $this->language->get('entry_rating'); $this->data['entry_status'] = $this->language->get('entry_status'); $this->data['entry_text'] = $this->language->get('entry_text'); $this->data['entry_good'] = $this->language->get('entry_good'); $this->data['entry_bad'] = $this->language->get('entry_bad'); $this->data['button_save'] = $this->language->get('button_save'); $this->data['button_cancel'] = $this->language->get('button_cancel'); if (isset($this->error['warning'])) { $this->data['error_warning'] = $this->error['warning']; } else { $this->data['error_warning'] = ''; } if (isset($this->error['name'])) { $this->data['error_name'] = $this->error['name']; } else { $this->data['error_name'] = ''; } if (isset($this->error['text'])) { $this->data['error_text'] = $this->error['text']; } else { $this->data['error_text'] = ''; } if (isset($this->error['rating'])) { $this->data['error_rating'] = $this->error['rating']; } else { $this->data['error_rating'] = ''; } $url = ''; if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => false); $this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('catalog/comment', 'token=' . $this->session->data['token'] . $url, 'SSL'), 'separator' => ' :: '); if (!isset($this->request->get['comment_id'])) { $this->data['action'] = $this->url->link('catalog/comment/insert', 'token=' . $this->session->data['token'] . $url, 'SSL'); } else { $this->data['action'] = $this->url->link('catalog/comment/update', 'token=' . $this->session->data['token'] . '&comment_id=' . $this->request->get['comment_id'] . $url, 'SSL'); } $this->data['cancel'] = $this->url->link('catalog/comment', 'token=' . $this->session->data['token'] . $url, 'SSL'); if (isset($this->request->get['url']) && $this->request->server['REQUEST_METHOD'] != 'POST') { $comment_info = $this->model_catalog_comment->getCommentURL($this->request->get['url']); } $this->data['token'] = $this->session->data['token']; $this->data['text_no_comments'] = $this->language->get('text_no_comments'); $this->data['text_reply'] = $this->language->get('text_reply'); $this->data['text_wait'] = $this->language->get('text_wait'); $this->data['text_qtv'] = $this->language->get('text_qtv'); $this->data['text_approval'] = $this->language->get('text_approval'); $this->data['text_unapproval'] = $this->language->get('text_unapproval'); $this->data['text_delete'] = $this->language->get('text_delete'); $this->data['text_update'] = $this->language->get('text_update'); $this->data['text_text_unapproval'] = $this->language->get('text_text_unapproval'); if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } $user_info = $this->db->query("SELECT * FROM `" . DB_PREFIX . "user` WHERE username = '******'")->row; $this->data['name_display'] = $user_info['name_display']; $this->data['url'] = $this->request->get['url']; $this->data['comments'] = array(); $url = $this->request->get['url']; $comment_total = $this->model_catalog_comment->getTotalCommentsByUrlParent($url); $results = $this->model_catalog_comment->getCommentsByUrlParent($url, ($page - 1) * 20, 20); foreach ($results as $result) { $child = array(); $childs = $this->model_catalog_comment->getCommentsByUrlByParent($result['comment_id']); if ($childs) { foreach ($childs as $child_info) { $child[] = array('comment_id' => $child_info['comment_id'], 'name' => $child_info['name'], 'email' => $child_info['email'], 'link_customer' => $this->url->link('sale/customer', '&filter_email=' . $child_info['email'] . '&token=' . $this->session->data['token']), 'phone' => $child_info['phone'], 'date' => $child_info['date'] != '0000-00-00' ? datedata_to_date($child_info['date']) : '', 'rank' => $child_info['rank'], 'text' => nl2br($child_info['text']), 'rating' => $child_info['rating'], 'status' => (int) $child_info['status'], 'date_added' => date($this->language->get('date_format_short') . ' H:i:s', strtotime($child_info['date_added']))); } } else { $child = false; } $this->data['comments'][] = array('comment_id' => $result['comment_id'], 'name' => $result['name'], 'email' => $result['email'], 'link_customer' => $this->url->link('sale/customer', 'filter_email=' . $result['email'] . '&token=' . $this->session->data['token']), 'phone' => $result['phone'], 'date' => $result['date'] != '0000-00-00' ? datedata_to_date($result['date']) : '', 'text' => nl2br($result['text']), 'child' => $child, 'rating' => (int) $result['rating'], 'status' => (int) $result['status'], 'comments' => sprintf($this->language->get('text_comments'), (int) $comment_total), 'date_added' => date($this->language->get('date_format_short') . ' H:i:s', strtotime($result['date_added']))); } $pagination_comment = new Pagination(); $pagination_comment->total = $comment_total; $pagination_comment->page = $page; $pagination_comment->limit = $this->config->get('config_admin_limit'); $pagination_comment->text = $this->language->get('text_pagination'); $pagination_comment->url = $this->url->link('comment/load', 'url=' . $url . '&page={page}'); $this->data['pagination_comment'] = $pagination_comment->render(); $this->template = 'catalog/comment_form.tpl'; $this->children = array('common/header', 'common/footer'); $this->response->setOutput($this->render()); }
public function send() { $this->language->load('sale/contact'); $json = array(); if ($this->request->server['REQUEST_METHOD'] == 'POST') { if (!$this->user->hasPermission('modify', 'sale/contact')) { $json['error']['warning'] = $this->language->get('error_permission'); } if (!$this->request->post['subject']) { $json['error']['subject'] = $this->language->get('error_subject'); } if (!$this->request->post['message']) { $json['error']['message'] = $this->language->get('error_message'); } if (!$this->request->post['mail_template']) { $json['error']['message'] = $this->language->get('error_message'); } if (!$json) { $this->load->model('setting/store'); $store_info = $this->model_setting_store->getStore($this->request->post['store_id']); if ($store_info) { $store_name = $store_info['name']; } else { $store_name = $this->config->get('config_name'); } $this->load->model('sale/customer'); $this->load->model('sale/customer_group'); $this->load->model('sale/affiliate'); $this->load->model('sale/order'); if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } $email_total = 0; $emails = array(); $total_number_mail = 0; switch ($this->request->post['to']) { case 'newsletter': $customer_data = array('filter_newsletter' => 1, 'start' => ($page - 1) * 10, 'limit' => 10); $email_total = $this->model_sale_customer->getTotalCustomers($customer_data); $results = $this->model_sale_customer->getCustomers($customer_data); foreach ($results as $result) { $emails[] = $result['email']; } break; case 'customer_all': $customer_data = array('start' => ($page - 1) * 10, 'limit' => 10); $email_total = $this->model_sale_customer->getTotalCustomers($customer_data); $results = $this->model_sale_customer->getCustomers($customer_data); foreach ($results as $result) { $emails[] = $result['email']; } break; case 'customer_group': $customer_data = array('filter_customer_group_id' => $this->request->post['customer_group_id'], 'start' => ($page - 1) * 10, 'limit' => 10); $email_total = $this->model_sale_customer->getTotalCustomers($customer_data); $results = $this->model_sale_customer->getCustomers($customer_data); foreach ($results as $result) { $emails[$result['customer_id']] = $result['email']; } break; case 'customer': if (!empty($this->request->post['customer'])) { foreach ($this->request->post['customer'] as $customer_id) { $customer_info = $this->model_sale_customer->getCustomer($customer_id); if ($customer_info) { $emails[] = $customer_info['email']; } } } break; case 'affiliate_all': $affiliate_data = array('start' => ($page - 1) * 10, 'limit' => 10); $email_total = $this->model_sale_affiliate->getTotalAffiliates($affiliate_data); $results = $this->model_sale_affiliate->getAffiliates($affiliate_data); foreach ($results as $result) { $emails[] = $result['email']; } break; case 'affiliate': if (!empty($this->request->post['affiliate'])) { foreach ($this->request->post['affiliate'] as $affiliate_id) { $affiliate_info = $this->model_sale_affiliate->getAffiliate($affiliate_id); if ($affiliate_info) { $emails[] = $affiliate_info['email']; } } } break; case 'product': if (isset($this->request->post['product'])) { $email_total = $this->model_sale_order->getTotalEmailsByProductsOrdered($this->request->post['product']); $results = $this->model_sale_order->getEmailsByProductsOrdered($this->request->post['product'], ($page - 1) * 10, 10); foreach ($results as $result) { $emails[] = $result['email']; } } break; case 'list_email': if (!empty($this->request->post['list_email'])) { $list_email = explode(',', $this->request->post['list_email']); foreach ($list_email as $email) { $emails[] = $email; } } break; } if ($emails) { $start = ($page - 1) * 10; $end = $start + 10; ///// if ($this->request->post['to'] != "list_email" && $this->request->post['to'] == "customer_group") { $this->load->model('sale/mail_template'); $id_status = $this->model_sale_mail_template->getMailStatusById($this->request->post['mail_template']); if (!empty($id_status['id_mail_status'])) { if (!empty($id_status['customer_group_id'])) { $group_id = explode("|", $id_status['customer_group_id']); $data_group = $this->request->post['customer_group_id']; foreach ($group_id as $key) { $data_group = $data_group . "|" . $key; } if (in_array($this->request->post['customer_group_id'], $group_id)) { } else { $this->model_sale_mail_template->updatetMailStatusById($this->request->post['mail_template'], $email_total, $data_group); } } } else { $this->model_sale_mail_template->addMailStatusById($this->request->post['mail_template'], $email_total, $this->request->post['customer_group_id']); } } ///// if ($end < $email_total) { $json['success'] = sprintf($this->language->get('text_sent'), $start, $email_total); } else { $json['success'] = $this->language->get('text_success'); } if ($end < $email_total) { $json['next'] = str_replace('&', '&', $this->url->link('sale/contact/send', 'token=' . $this->session->data['token'] . '&page=' . ($page + 1), 'SSL')); } else { $json['next'] = ''; } foreach ($emails as $email) { //Customer $data = array(); $info = $this->model_sale_customer->getCustomerByEmail($email); if ($info) { $data = array('firstname' => $info['firstname'], 'lastname' => $info['lastname'], 'fullname' => $info['lastname'] . ' ' . $info['firstname'], 'birthday' => datedata_to_date($info['birthday']), 'telephone' => $info['telephone'], 'customer_id' => $info['customer_id']); } if ($data['customer_id']) { $id_custom = base64_encode($data['customer_id'] . "+trungbt93"); } else { $id_custom = ""; } //Replace content $content = $this->request->post['message']; $content = str_replace('###id_custom###', trim("&im=" . $id_custom), $content); $content = str_replace('###id_mail###', trim("&id_mail=" . $data['customer_id']), $content); $content = str_replace('###email###', $email, $content); $content = str_replace('###firstname###', $data['firstname'], $content); $content = str_replace('###lastname###', $data['lastname'], $content); $content = str_replace('###fullname###', $data['fullname'] ? $data['fullname'] : $email, $content); $content = str_replace('###birthday###', $data['birthday'], $content); $content = str_replace('###telephone###', $data['telephone'], $content); $message = '<html dir="ltr" lang="en">' . "\n"; $message .= ' <head>' . "\n"; $message .= ' <title>' . $this->request->post['subject'] . '</title>' . "\n"; $message .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n"; $message .= ' </head>' . "\n"; $message .= ' <body>' . html_entity_decode($content, ENT_QUOTES, 'UTF-8') . '</body>' . "\n"; $message .= '</html>' . "\n"; //Send mail $mail = new Mail(); $mail->protocol = $this->config->get('config_mail_protocol'); $mail->parameter = $this->config->get('config_mail_parameter'); $mail->hostname = $this->config->get('config_smtp_host'); $mail->username = $this->config->get('config_smtp_username'); $mail->password = $this->config->get('config_smtp_password'); $mail->port = $this->config->get('config_smtp_port'); $mail->timeout = $this->config->get('config_smtp_timeout'); $mail->setTo($email); $mail->setFrom($this->config->get('config_email')); $mail->setSender($store_name); $mail->setSubject(html_entity_decode($this->request->post['subject'], ENT_QUOTES, 'UTF-8')); $mail->setHtml($message); $mail->send(); unset($data); unset($message); } } } } $this->response->setOutput(json_encode($json)); }