コード例 #1
0
ファイル: contact.php プロジェクト: siddht1/abantecart-src
 private function _send_email($email, $data)
 {
     if (!$email || !$data) {
         $error = new AError('Error: Cannot send email. Unknown address or empty message.');
         $error->toLog()->toMessages();
         return false;
     }
     // HTML Mail
     $template = new ATemplate();
     $template->data['lang_direction'] = $this->language->get('direction');
     $template->data['lang_code'] = $this->language->get('code');
     $text_subject = $data['subject'];
     $template->data['subject'] = $text_subject;
     $text_unsubscribe = $this->language->get('text_unsubscribe');
     $text_message = $data['message'];
     $mail = new AMail($this->config);
     $mail->setTo($email);
     $mail->setFrom($data['from']);
     $mail->setSender($data['sender']);
     $mail->setSubject($text_subject);
     $message_body = $text_message;
     if ($data['subscriber']) {
         $customer_info = $this->model_sale_customer->getCustomersByEmails(array($email));
         $customer_id = $customer_info[0]['customer_id'];
         if ($customer_id) {
             $message_body .= "\n\n<br><br>" . sprintf($text_unsubscribe, $email, $this->html->getCatalogURL('account/notification', '&email=' . $email . '&customer_id=' . $customer_id));
         }
     }
     $template->data['body'] = html_entity_decode($message_body, ENT_QUOTES, 'UTF-8');
     $html = $template->fetch('mail/contact.tpl');
     $mail->setHtml($html);
     $mail->send();
     if ($mail->error) {
         return false;
     }
     return true;
 }
コード例 #2
0
ファイル: im.php プロジェクト: siddht1/abantecart-src
 public function send($to, $text)
 {
     $this->load->language('common/im');
     $to = trim($to);
     $text = trim($text);
     if (!$to || !$text) {
         return false;
     }
     $mail = new AMail($this->config);
     $mail->setTo($to);
     $mail->setFrom($this->config->get('store_main_email'));
     $mail->setSender($this->config->get('store_name'));
     $mail->setSubject($this->config->get('store_name') . ' ' . $this->language->get('im_text_notification'));
     $mail->setHtml($text);
     $mail->setText($text);
     $mail->send();
     unset($mail);
     return true;
 }
コード例 #3
0
ファイル: order.php プロジェクト: Cali-gula/abantecart-src
 /**
  * @param int $order_id
  * @param int $order_status_id
  * @param string $comment
  */
 public function _confirm($order_id, $order_status_id, $comment = '')
 {
     $order_query = $this->db->query("SELECT *,\n\t\t\t\t\t\t\t\t\t\t\t\tl.filename AS filename,\n\t\t\t\t\t\t\t\t\t\t\t\tl.directory AS directory\n\t\t\t\t\t\t\t\t\t\t FROM `" . $this->db->table("orders") . "` o\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN " . $this->db->table("languages") . " l ON (o.language_id = l.language_id)\n\t\t\t\t\t\t\t\t\t\t WHERE o.order_id = '" . (int) $order_id . "'\n\t\t\t\t\t\t\t\t\t\t        AND o.order_status_id = '0'");
     if ($order_query->num_rows) {
         $order_row = $this->dcrypt->decrypt_data($order_query->row, 'orders');
         //if promotions applied - updates total and add row to order_total for promo type
         $update = array();
         $update[] = "order_status_id = '" . (int) $order_status_id . "'";
         $sql = "UPDATE `" . $this->db->table("orders") . "`\n\t\t\t\t    SET " . implode(", ", $update) . "\n\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'";
         $this->db->query($sql);
         $this->db->query("INSERT INTO " . $this->db->table("order_history") . "\n\t\t\t\t\t\t\t   SET order_id = '" . (int) $order_id . "',\n\t\t\t\t\t\t\t        order_status_id = '" . (int) $order_status_id . "',\n\t\t\t\t\t\t\t        notify = '1',\n\t\t\t\t\t\t\t        comment = '" . $this->db->escape($comment) . "',\n\t\t\t\t\t\t\t        date_added = NOW()");
         $order_row['comment'] = $order_row['comment'] . ' ' . $comment;
         $order_product_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\t FROM " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE order_id = '" . (int) $order_id . "'");
         foreach ($order_product_query->rows as $product) {
             $this->db->query("UPDATE " . $this->db->table("products") . "\n\t\t\t\t\t\t\t\t\t  SET quantity = (quantity - " . (int) $product['quantity'] . ")\n\t\t\t\t\t\t\t\t\t  WHERE product_id = '" . (int) $product['product_id'] . "' AND subtract = 1");
             $order_option_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_options") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND order_product_id = '" . (int) $product['order_product_id'] . "'");
             foreach ($order_option_query->rows as $option) {
                 $this->db->query("UPDATE " . $this->db->table("product_option_values") . "\n\t\t\t\t\t\t\t\t\t  SET quantity = (quantity - " . (int) $product['quantity'] . ")\n\t\t\t\t\t\t\t\t\t  WHERE product_option_value_id = '" . (int) $option['product_option_value_id'] . "'\n\t\t\t\t\t\t\t\t\t        AND subtract = 1");
             }
             $this->cache->delete('product');
         }
         $language = new ALanguage($this->registry, $order_row['code']);
         $language->load($order_row['filename']);
         $language->load('mail/order_confirm');
         $this->load->model('localisation/currency');
         $order_status_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_statuses") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_status_id = '" . (int) $order_status_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND language_id = '" . (int) $order_row['language_id'] . "'");
         $order_product_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'");
         $order_total_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_totals") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY sort_order ASC");
         $order_download_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_downloads") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'");
         $subject = sprintf($language->get('text_subject'), $order_row['store_name'], $order_id);
         // HTML Mail
         $template = new ATemplate();
         $template->data['title'] = sprintf($language->get('text_subject'), html_entity_decode($order_row['store_name'], ENT_QUOTES, 'UTF-8'), $order_id);
         $template->data['text_greeting'] = sprintf($language->get('text_greeting'), html_entity_decode($order_row['store_name'], ENT_QUOTES, 'UTF-8'));
         $template->data['text_order_detail'] = $language->get('text_order_detail');
         $template->data['text_order_id'] = $language->get('text_order_id');
         $template->data['text_invoice'] = $language->get('text_invoice');
         $template->data['text_date_added'] = $language->get('text_date_added');
         $template->data['text_telephone'] = $language->get('text_telephone');
         $template->data['text_email'] = $language->get('text_email');
         $template->data['text_ip'] = $language->get('text_ip');
         $template->data['text_fax'] = $language->get('text_fax');
         $template->data['text_shipping_address'] = $language->get('text_shipping_address');
         $template->data['text_payment_address'] = $language->get('text_payment_address');
         $template->data['text_shipping_method'] = $language->get('text_shipping_method');
         $template->data['text_payment_method'] = $language->get('text_payment_method');
         $template->data['text_comment'] = $language->get('text_comment');
         $template->data['text_powered_by'] = $language->get('text_powered_by');
         $template->data['text_project_label'] = $language->get('text_powered_by') . ' ' . project_base();
         $template->data['column_product'] = $language->get('column_product');
         $template->data['column_model'] = $language->get('column_model');
         $template->data['column_quantity'] = $language->get('column_quantity');
         $template->data['column_price'] = $language->get('column_price');
         $template->data['column_total'] = $language->get('column_total');
         $template->data['order_id'] = $order_id;
         $template->data['customer_id'] = $order_row['customer_id'];
         $template->data['date_added'] = dateISO2Display($order_row['date_added'], $language->get('date_format_short'));
         $template->data['logo'] = 'cid:' . md5(pathinfo($this->config->get('config_logo'), PATHINFO_FILENAME)) . '.' . pathinfo($this->config->get('config_logo'), PATHINFO_EXTENSION);
         $template->data['store_name'] = $order_row['store_name'];
         $template->data['address'] = nl2br($this->config->get('config_address'));
         $template->data['telephone'] = $this->config->get('config_telephone');
         $template->data['fax'] = $this->config->get('config_fax');
         $template->data['email'] = $this->config->get('store_main_email');
         $template->data['store_url'] = $order_row['store_url'];
         $template->data['invoice'] = $order_row['store_url'] . 'index.php?rt=account/invoice&order_id=' . $order_id;
         $template->data['firstname'] = $order_row['firstname'];
         $template->data['lastname'] = $order_row['lastname'];
         $template->data['shipping_method'] = $order_row['shipping_method'];
         $template->data['payment_method'] = $order_row['payment_method'];
         $template->data['customer_email'] = $order_row['email'];
         $template->data['customer_telephone'] = $order_row['telephone'];
         $template->data['customer_ip'] = $order_row['ip'];
         $template->data['comment'] = trim(nl2br($order_row['comment']));
         //override with the data from the before hooks
         if ($this->data) {
             $template->data = array_merge($template->data, $this->data);
         }
         $this->load->model('localisation/zone');
         $zone_row = $this->model_localisation_zone->getZone($order_row['shipping_zone_id']);
         if ($zone_row) {
             $zone_code = $zone_row['code'];
         } else {
             $zone_code = '';
         }
         $shipping_data = array('firstname' => $order_row['shipping_firstname'], 'lastname' => $order_row['shipping_lastname'], 'company' => $order_row['shipping_company'], 'address_1' => $order_row['shipping_address_1'], 'address_2' => $order_row['shipping_address_2'], 'city' => $order_row['shipping_city'], 'postcode' => $order_row['shipping_postcode'], 'zone' => $order_row['shipping_zone'], 'zone_code' => $zone_code, 'country' => $order_row['shipping_country']);
         $template->data['shipping_address'] = $this->customer->getFormatedAdress($shipping_data, $order_row['shipping_address_format']);
         $zone_row = $this->model_localisation_zone->getZone($order_row['payment_zone_id']);
         if ($zone_row) {
             $zone_code = $zone_row['code'];
         } else {
             $zone_code = '';
         }
         $payment_data = array('firstname' => $order_row['payment_firstname'], 'lastname' => $order_row['payment_lastname'], 'company' => $order_row['payment_company'], 'address_1' => $order_row['payment_address_1'], 'address_2' => $order_row['payment_address_2'], 'city' => $order_row['payment_city'], 'postcode' => $order_row['payment_postcode'], 'zone' => $order_row['payment_zone'], 'zone_code' => $zone_code, 'country' => $order_row['payment_country']);
         $template->data['payment_address'] = $this->customer->getFormatedAdress($payment_data, $order_row['payment_address_format']);
         if (!has_value($this->data['products'])) {
             $this->data['products'] = array();
         }
         foreach ($order_product_query->rows as $product) {
             $option_data = array();
             $order_option_query = $this->db->query("SELECT oo.*, po.element_type\n\t\t\t\t\t\tFROM " . $this->db->table("order_options") . " oo\n\t\t\t\t\t\tLEFT JOIN " . $this->db->table("product_option_values") . " pov\n\t\t\t\t\t\t\tON pov.product_option_value_id = oo.product_option_value_id\n\t\t\t\t\t\tLEFT JOIN " . $this->db->table("product_options") . " po\n\t\t\t\t\t\t\tON po.product_option_id = pov.product_option_id\n\t\t\t\t\t\tWHERE oo.order_id = '" . (int) $order_id . "' AND oo.order_product_id = '" . (int) $product['order_product_id'] . "'");
             foreach ($order_option_query->rows as $option) {
                 if ($option['element_type'] == 'H') {
                     continue;
                 } elseif ($option['element_type'] == 'C' && in_array($option['value'], array(0, 1, ''))) {
                     $option['value'] = '';
                 }
                 $option_data[] = array('name' => $option['name'], 'value' => $option['value']);
             }
             $this->data['products'][] = array('name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $this->currency->format($product['price'], $order_row['currency'], $order_row['value']), 'total' => $this->currency->format($product['total'], $order_row['currency'], $order_row['value']));
         }
         $template->data['products'] = $this->data['products'];
         $template->data['totals'] = $order_total_query->rows;
         $html = $template->fetch('mail/order_confirm.tpl');
         // Text Mail
         $text = sprintf($language->get('text_greeting'), html_entity_decode($order_row['store_name'], ENT_QUOTES, 'UTF-8')) . "\n\n";
         $text .= $language->get('text_order_id') . ' ' . $order_id . "\n";
         $text .= $language->get('text_date_added') . ' ' . dateISO2Display($order_row['date_added'], $language->get('date_format_short')) . "\n";
         $text .= $language->get('text_order_status') . ' ' . $order_status_query->row['name'] . "\n\n";
         $text .= $language->get('text_product') . "\n";
         foreach ($order_product_query->rows as $result) {
             $text .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $order_row['currency'], $order_row['value']), ENT_NOQUOTES, 'UTF-8') . "\n";
             $order_option_query = $this->db->query("SELECT * FROM " . $this->db->table("order_options") . " WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . $result['order_product_id'] . "'");
             foreach ($order_option_query->rows as $option) {
                 $text .= chr(9) . '-' . $option['name'] . ' ' . $option['value'] . "\n";
             }
         }
         $text .= "\n";
         $text .= $language->get('text_total') . "\n";
         foreach ($order_total_query->rows as $result) {
             $text .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
         }
         $order_total = $result['text'];
         $text .= "\n";
         if ($order_row['customer_id']) {
             $text .= $language->get('text_invoice') . "\n";
             $text .= $order_row['store_url'] . 'index.php?rt=account/invoice&order_id=' . $order_id . "\n\n";
         }
         if ($order_download_query->num_rows) {
             $text .= $language->get('text_download') . "\n";
             $text .= $order_row['store_url'] . 'index.php?rt=account/download' . "\n\n";
         }
         if ($order_row['comment'] != '') {
             $comment = $order_row['comment'] . "\n\n" . $comment;
         }
         if ($comment) {
             $text .= $language->get('text_comment') . "\n\n";
             $text .= $comment . "\n\n";
         }
         $text .= $language->get('text_footer');
         $mail = new AMail($this->config);
         $mail->setTo($order_row['email']);
         $mail->setFrom($this->config->get('store_main_email'));
         $mail->setSender($order_row['store_name']);
         $mail->setSubject($subject);
         $mail->setHtml($html);
         $mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
         $mail->addAttachment(DIR_RESOURCE . $this->config->get('config_logo'), md5(pathinfo($this->config->get('config_logo'), PATHINFO_FILENAME)) . '.' . pathinfo($this->config->get('config_logo'), PATHINFO_EXTENSION));
         $mail->send();
         if ($this->config->get('config_alert_mail')) {
             // HTML
             $template->data['text_greeting'] = $language->get('text_received') . "\n\n";
             $template->data['invoice'] = '';
             $template->data['text_invoice'] = '';
             $html = $template->fetch('mail/order_confirm.tpl');
             $subject = sprintf($language->get('text_subject'), html_entity_decode($this->config->get('store_name'), ENT_QUOTES, 'UTF-8'), $order_id . ' (' . $order_total . ')');
             $mail->setSubject($subject);
             $mail->setTo($this->config->get('store_main_email'));
             $mail->setHtml($html);
             $mail->send();
             // Send to additional alert emails
             $emails = explode(',', $this->config->get('config_alert_emails'));
             foreach ($emails as $email) {
                 if (trim($email)) {
                     $mail->setTo($email);
                     $mail->send();
                 }
             }
         }
         $msg_text = sprintf($language->get('text_new_order_text'), $order_row['firstname'] . ' ' . $order_row['lastname']);
         $msg_text .= "<br/><br/>";
         foreach ($template->data['totals'] as $total) {
             $msg_text .= $total['title'] . ' - ' . $total['text'] . "<br/>";
         }
         $msg = new AMessage();
         $msg->saveNotice($language->get('text_new_order') . $order_id, $msg_text);
     }
 }
コード例 #4
0
ファイル: contact.php プロジェクト: harshzalavadiya/fatak
 public function sendNewsletter()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     // this method can process only posting.
     if ($this->request->server['REQUEST_METHOD'] != 'POST') {
         $this->redirect($this->html->getSecureURL('sale/contact'));
     }
     if (!$this->_validate()) {
         $this->main();
         return null;
     }
     $this->loadModel('sale/customer');
     $this->loadModel('setting/store');
     $store_info = $this->model_setting_store->getStore($this->request->post['store_id']);
     if ($store_info) {
         $store_name = $store_info['store_name'];
     } else {
         $store_name = $this->config->get('store_name');
     }
     $emails = array();
     // All customers by group
     if (isset($this->request->post['recipient'])) {
         $customers = $results = array();
         if ($this->request->post['recipient'] == 'all_subscribers') {
             $all_subscribers = $this->model_sale_customer->getAllSubscribers();
             $results = $this->_unify_customer_list($all_subscribers);
         } else {
             if ($this->request->post['recipient'] == 'only_subscribers') {
                 $only_subscribers = $this->model_sale_customer->getOnlyNewsletterSubscribers();
                 $results = $this->_unify_customer_list($only_subscribers);
             } else {
                 if ($this->request->post['recipient'] == 'only_customers') {
                     $only_customers = $this->model_sale_customer->getOnlyCustomers(array('status' => 1, 'approved' => 1));
                     $results = $this->_unify_customer_list($only_customers);
                 }
             }
         }
         foreach ($results as $result) {
             $customer_id = $result['customer_id'];
             $emails[$customer_id] = $customers[$customer_id] = trim($result['email']);
         }
     }
     // All customers by name/email
     if (isset($this->request->post['to']) && $this->request->post['to']) {
         foreach ($this->request->post['to'] as $customer_id) {
             $customer_info = $this->model_sale_customer->getCustomer($customer_id);
             if ($customer_info) {
                 $emails[] = trim($customer_info['email']);
             }
         }
     }
     // All customers by product
     if (isset($this->request->post['product'])) {
         foreach ($this->request->post['product'] as $product_id) {
             $results = $this->model_sale_customer->getCustomersByProduct($product_id);
             if ($customers) {
                 $emails = array();
             }
             foreach ($results as $result) {
                 if ($customers && in_array($result['email'], $customers)) {
                     $emails[] = trim($result['email']);
                 }
             }
         }
     }
     // Prevent Duplicates
     $emails = array_unique($emails);
     if ($emails) {
         $message_html = '<html dir="ltr" lang="en">' . "\n";
         $message_html .= '<head>' . "\n";
         $message_html .= '<title>' . $this->request->post['subject'] . '</title>' . "\n";
         $message_html .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n";
         $message_html .= '</head>' . "\n";
         $message_html .= '<body>%MESSAGEBODY%</body>' . "\n";
         $message_html .= '</html>' . "\n";
         $text_unsubscribe = $this->language->get('text_unsubscribe');
         $text_subject = $this->request->post['subject'];
         $text_message = $this->request->post['message'];
         $from = $this->config->get('store_main_email');
         foreach ($emails as $email) {
             $mail = new AMail($this->config);
             $mail->setTo($email);
             $mail->setFrom($from);
             $mail->setSender($store_name);
             $mail->setSubject($text_subject);
             $message_body = $text_message;
             if ($this->request->post['recipient'] == 'newsletter') {
                 if ($customer_id = array_search($email, $customers)) {
                     $message_body .= "\n\n<br><br>" . sprintf($text_unsubscribe, $email, $this->html->getCatalogURL('account/unsubscribe', '&email=' . $email . '&customer_id=' . $customer_id));
                 }
             }
             $message_body = html_entity_decode($message_body, ENT_QUOTES, 'UTF-8');
             $html = str_replace('%MESSAGEBODY%', $message_body, $message_html);
             $mail->setHtml($html);
             $mail->send();
             if ($mail->error) {
                 $this->error[] = 'Error: Emails does not sent! Please see error log for details.';
                 $this->main();
                 return null;
             }
             unset($mail);
         }
     }
     if (!$mail->error) {
         $this->session->data['success'] = $this->language->get('text_success');
         $this->redirect($this->html->getSecureURL('sale/contact'));
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
コード例 #5
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->document->setTitle($this->language->get('heading_title'));
     $this->form = new AForm('ContactUsFrm');
     $this->form->loadFromDb('ContactUsFrm');
     $form = $this->form->getForm();
     if ($this->request->is_POST() && $this->_validate()) {
         // move all uploaded files to their directories
         $file_pathes = $this->form->processFileUploads($this->request->files);
         $template = new ATemplate();
         $subject = sprintf($this->language->get('email_subject'), $this->request->post['name']);
         $template->data['subject'] = $subject;
         $mail = new AMail($this->config);
         $mail->setTo($this->config->get('store_main_email'));
         $mail->setFrom($this->request->post['email']);
         $mail->setSender($this->request->post['first_name']);
         $mail->setSubject($subject);
         $store_logo = md5(pathinfo($this->config->get('config_logo'), PATHINFO_FILENAME)) . '.' . pathinfo($this->config->get('config_logo'), PATHINFO_EXTENSION);
         $template->data['logo'] = 'cid:' . $store_logo;
         $template->data['store_name'] = $this->config->get('store_name');
         $template->data['store_url'] = $this->config->get('config_url');
         $template->data['text_project_label'] = project_base();
         $template->data['entry_enquiry'] = $msg = $this->language->get('entry_enquiry');
         $msg .= "\r\n" . $this->request->post['enquiry'] . "\r\n";
         $template->data['enquiry'] = nl2br($this->request->post['enquiry'] . "\r\n");
         $form_fields = $this->form->getFields();
         $template->data['form_fields'] = array();
         foreach ($form_fields as $field_name => $field_info) {
             if (has_value($this->request->post[$field_name]) && !in_array($field_name, array('first_name', 'email', 'enquiry', 'captcha'))) {
                 $field_details = $this->form->getField($field_name);
                 $msg .= "\r\n" . rtrim($field_details['name'], ':') . ":\t" . $this->request->post[$field_name];
                 $template->data['form_fields'][rtrim($field_details['name'], ':')] = $this->request->post[$field_name];
             }
         }
         if ($file_pathes) {
             $msg .= "\r\n" . $this->language->get('entry_attached') . ": \r\n";
             foreach ($file_pathes as $file_info) {
                 $basename = pathinfo(str_replace(' ', '_', $file_info['path']), PATHINFO_BASENAME);
                 $msg .= "\t" . $file_info['display_name'] . ': ' . $basename . " (" . round(filesize($file_info['path']) / 1024, 2) . "Kb)\r\n";
                 $mail->addAttachment($file_info['path'], $basename);
                 $template->data['form_fields'][$file_info['display_name']] = $basename . " (" . round(filesize($file_info['path']) / 1024, 2) . "Kb)";
             }
         }
         $mail_html = $template->fetch('mail/contact.tpl');
         $mail->setHtml($mail_html);
         $mail->addAttachment(DIR_RESOURCE . $this->config->get('config_logo'), $store_logo);
         $mail->setText(strip_tags(html_entity_decode($msg, ENT_QUOTES, 'UTF-8')));
         $mail->send();
         //get success_page
         if ($form['success_page']) {
             $success_url = $this->html->getSecureURL($form['success_page']);
         } else {
             $success_url = $this->html->getSecureURL('content/contact/success');
         }
         $this->redirect($success_url);
     }
     if ($this->request->is_POST()) {
         foreach ($this->request->post as $name => $value) {
             $this->form->assign($name, $value);
         }
     }
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => false));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('content/contact'), 'text' => $this->language->get('heading_title'), 'separator' => $this->language->get('text_separator')));
     $this->view->assign('form_output', $this->form->getFormHtml());
     $this->view->assign('action', $this->html->getURL('content/contact'));
     $this->view->assign('store', $this->config->get('store_name'));
     $this->view->assign('address', nl2br($this->config->get('config_address')));
     $this->view->assign('telephone', $this->config->get('config_telephone'));
     $this->view->assign('fax', $this->config->get('config_fax'));
     $this->processTemplate('pages/content/contact.tpl');
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
コード例 #6
0
 public function validate()
 {
     if ($this->user->isLogged()) {
         $this->user->logout();
         unset($this->session->data['token']);
     }
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('common/forgot_password');
     $this->document->setTitle($this->language->get('heading_title'));
     if ($this->request->is_POST() && $this->_validateCaptcha()) {
         //generate password
         $password = AUser::generatePassword(8);
         $this->model_user_user->editUser($this->user_data['user_id'], array('password' => $password));
         $mail = new AMail($this->config);
         $mail->setTo($this->user_data['email']);
         $mail->setFrom($this->config->get('store_main_email'));
         $mail->setSender($this->config->get('config_owner'));
         $mail->setSubject(sprintf($this->language->get('reset_email_subject'), $this->config->get('store_name')));
         $mail->setHtml(sprintf($this->language->get('new_password_email_body'), $password));
         $mail->setText(sprintf($this->language->get('new_password_email_body'), $password));
         $mail->send();
         $this->redirect($this->html->getSecureURL('index/forgot_password/validate', '&mail=sent'));
     }
     $this->data['text_heading'] = $this->language->get('text_heading_reset');
     $this->data['login'] = $this->html->getSecureURL('index/login');
     if (isset($this->request->get['mail']) && $this->request->get['mail'] == 'sent') {
         $this->data['show_instructions'] = true;
         $this->data['text_instructions'] = $this->language->get('text_instructions_reset');
     } else {
         $this->data['error'] = $this->error;
         $this->data['action'] = $this->html->getSecureURL('index/forgot_password/validate', '&hash=' . $this->request->get['hash']);
         $this->data['update'] = '';
         $form = new AForm('ST');
         $form->setForm(array('form_name' => 'forgotFrm', 'update' => $this->data['update']));
         $this->data['form']['id'] = 'forgotFrm';
         $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'forgotFrm', 'action' => $this->data['action']));
         $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('text_please_confirm'), 'style' => 'button3'));
         $this->data['form']['fields']['username'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'username', 'value' => $this->request->post['username'], 'required' => true, 'placeholder' => $this->language->get('entry_username')));
         if ($this->config->get('config_recaptcha_site_key')) {
             $this->data['form']['fields']['captcha'] = $form->getFieldHtml(array('type' => 'recaptcha', 'name' => 'captcha', 'recaptcha_site_key' => $this->config->get('config_recaptcha_site_key'), 'language_code' => $this->language->getLanguageCode()));
         } else {
             $this->data['form']['fields']['captcha'] = $form->getFieldHtml(array('type' => 'captcha', 'name' => 'captcha', 'value' => $this->data['captcha'], 'required' => true, 'placeholder' => $this->language->get('entry_captcha')));
         }
     }
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/index/forgot_password.tpl');
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
コード例 #7
0
ファイル: create.php プロジェクト: siddht1/abantecart-src
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if ($this->customer->isLogged()) {
         $this->redirect($this->html->getSecureURL('account/account'));
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->loadModel('account/customer');
     $request_data = $this->request->post;
     if ($this->request->is_POST()) {
         $this->errors = array_merge($this->errors, $this->model_account_customer->validateRegistrationData($request_data));
         if (!$this->errors) {
             //if allow login as email, need to set loginname = email
             if (!$this->config->get('prevent_email_as_login')) {
                 $request_data['loginname'] = $request_data['email'];
             }
             $this->data['customer_id'] = $this->model_account_customer->addCustomer($request_data);
             $this->model_account_customer->editCustomerNotifications($request_data, $this->data['customer_id']);
             unset($this->session->data['guest']);
             //login customer after create account is approvement and email activation are disabled in settings
             if (!$this->config->get('config_customer_approval') && !$this->config->get('config_customer_email_activation')) {
                 $this->customer->login($request_data['loginname'], $request_data['password']);
             }
             $template = new ATemplate();
             $this->loadLanguage('mail/account_create');
             $subject = sprintf($this->language->get('text_subject'), $this->config->get('store_name'));
             $message = sprintf($this->language->get('text_welcome'), $this->config->get('store_name')) . "\n\n";
             $template->data['text_welcome'] = $message;
             $activation = false;
             if (!$this->config->get('config_customer_approval')) {
                 //add account activation link if required
                 if ($this->config->get('config_customer_email_activation')) {
                     $activation = true;
                     // sign of activation email
                     $code = md5(mt_rand(1, 3000));
                     $email = $this->request->post['email'];
                     $this->session->data['activation'] = array('customer_id' => $this->data['customer_id'], 'code' => $code, 'email' => $email);
                     $activate_url = $this->html->getSecureURL('account/login', '&activation=' . $code . '&email=' . $email);
                     $message .= sprintf($this->language->get('text_activate'), $activate_url . "\n") . "\n";
                     $template->data['text_activate'] = sprintf($this->language->get('text_activate'), '<a href="' . $activate_url . '">' . $activate_url . '</a>');
                 } else {
                     $message .= $this->language->get('text_login') . "\n";
                     $template->data['text_login'] = $this->language->get('text_login');
                 }
             } else {
                 $message .= $this->language->get('text_approval') . "\n";
                 $template->data['text_approval'] = $this->language->get('text_approval');
             }
             if (!$activation) {
                 $login_url = $this->html->getSecureURL('account/login');
                 $message .= $login_url . "\n\n";
                 $message .= $this->language->get('text_services') . "\n\n";
                 $template->data['text_login_later'] = '<a href="' . $login_url . '">' . $login_url . '</a><br>' . $this->language->get('text_services');
             }
             $message .= $this->language->get('text_thanks') . "\n";
             $message .= $this->config->get('store_name');
             $template->data['text_thanks'] = $this->language->get('text_thanks');
             $mail = new AMail($this->config);
             $mail->setTo($this->request->post['email']);
             $mail->setFrom($this->config->get('store_main_email'));
             $mail->setSender($this->config->get('store_name'));
             $mail->setSubject($subject);
             $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
             $store_logo = md5(pathinfo($this->config->get('config_logo'), PATHINFO_FILENAME)) . '.' . pathinfo($this->config->get('config_logo'), PATHINFO_EXTENSION);
             $template->data['logo'] = 'cid:' . $store_logo;
             $template->data['store_name'] = $this->config->get('store_name');
             $template->data['store_url'] = $this->config->get('config_url');
             $template->data['text_project_label'] = project_base();
             $mail_html = $template->fetch('mail/account_create.tpl');
             $mail->addAttachment(DIR_RESOURCE . $this->config->get('config_logo'), $store_logo);
             $mail->setHtml($mail_html);
             $mail->send();
             $this->extensions->hk_UpdateData($this, __FUNCTION__);
             //set success text for non-approved customers on login page after redirect
             if ($this->config->get('config_customer_approval')) {
                 $this->loadLanguage('account/success');
                 $this->session->data['success'] = sprintf($this->language->get('text_approval', 'account/success'), $this->config->get('store_name'), $this->html->getSecureURL('content/contact'));
             }
             if ($this->config->get('config_customer_email_activation') || !$this->session->data['redirect']) {
                 $redirect_url = $this->html->getSecureURL('account/success');
             } else {
                 $redirect_url = $this->session->data['redirect'];
             }
             $this->redirect($redirect_url);
         } else {
             if (!$this->errors['warning']) {
                 $this->errors['warning'] = implode('<br>', $this->errors);
             }
         }
     }
     $this->document->initBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => false));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('account/account'), 'text' => $this->language->get('text_account'), 'separator' => $this->language->get('text_separator')));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('account/create'), 'text' => $this->language->get('text_create'), 'separator' => $this->language->get('text_separator')));
     if ($this->config->get('prevent_email_as_login')) {
         $this->data['noemaillogin'] = true;
     }
     $form = new AForm();
     $form->setForm(array('form_name' => 'AccountFrm'));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'AccountFrm', 'action' => $this->html->getSecureURL('account/create')));
     if ($this->config->get('prevent_email_as_login')) {
         // require login name
         $this->data['form']['fields']['general']['loginname'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'loginname', 'value' => $this->request->post['loginname'], 'required' => true));
     }
     $this->data['form']['fields']['general']['firstname'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'firstname', 'value' => $this->request->post['firstname'], 'required' => true));
     $this->data['form']['fields']['general']['lastname'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'lastname', 'value' => $this->request->post['lastname'], 'required' => true));
     $this->data['form']['fields']['general']['email'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'email', 'value' => $this->request->get_or_post('email'), 'required' => true));
     $this->data['form']['fields']['general']['telephone'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'telephone', 'value' => $this->request->post['telephone']));
     $this->data['form']['fields']['general']['fax'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'fax', 'value' => $this->request->post['fax'], 'required' => false));
     //get only active IM drivers
     $im_drivers = $this->im->getIMDriverObjects();
     if ($im_drivers) {
         foreach ($im_drivers as $protocol => $driver_obj) {
             if (!is_object($driver_obj) || $protocol == 'email') {
                 continue;
             }
             $fld = $driver_obj->getURIField($form, $this->request->post[$protocol]);
             $this->data['form']['fields']['general'][$protocol] = $fld;
             $this->data['entry_' . $protocol] = $fld->label_text;
         }
     }
     $this->data['form']['fields']['address']['company'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'company', 'value' => $this->request->post['company'], 'required' => false));
     $this->data['form']['fields']['address']['address_1'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'address_1', 'value' => $this->request->post['address_1'], 'required' => true));
     $this->data['form']['fields']['address']['address_2'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'address_2', 'value' => $this->request->post['address_2'], 'required' => false));
     $this->data['form']['fields']['address']['city'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'city', 'value' => $this->request->post['city'], 'required' => true));
     $this->view->assign('zone_id', $this->request->post['zone_id'], 'FALSE');
     $this->data['form']['fields']['address']['zone'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'zone_id', 'required' => true));
     $this->data['form']['fields']['address']['postcode'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'postcode', 'value' => $this->request->post['postcode'], 'required' => true));
     $this->loadModel('localisation/country');
     $countries = $this->model_localisation_country->getCountries();
     $options = array("FALSE" => $this->language->get('text_select'));
     foreach ($countries as $item) {
         $options[$item['country_id']] = $item['name'];
     }
     $this->data['form']['fields']['address']['country'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'country_id', 'options' => $options, 'value' => isset($this->request->post['country_id']) ? $this->request->post['country_id'] : $this->config->get('config_country_id'), 'required' => true));
     $this->data['form']['fields']['password']['password'] = $form->getFieldHtml(array('type' => 'password', 'name' => 'password', 'value' => $this->request->post['password'], 'required' => true));
     $this->data['form']['fields']['password']['confirm'] = $form->getFieldHtml(array('type' => 'password', 'name' => 'confirm', 'value' => $this->request->post['confirm'], 'required' => true));
     $this->data['form']['fields']['newsletter']['newsletter'] = $form->getFieldHtml(array('type' => 'radio', 'name' => 'newsletter', 'value' => !is_null($this->request->get_or_post('newsletter')) ? $this->request->get_or_post('newsletter') : -1, 'options' => array('1' => $this->language->get('text_yes'), '0' => $this->language->get('text_no'))));
     //If captcha enabled, validate
     if ($this->config->get('config_account_create_captcha')) {
         if ($this->config->get('config_recaptcha_site_key')) {
             $this->data['form']['fields']['newsletter']['captcha'] = $form->getFieldHtml(array('type' => 'recaptcha', 'name' => 'recaptcha', 'recaptcha_site_key' => $this->config->get('config_recaptcha_site_key'), 'language_code' => $this->language->getLanguageCode()));
         } else {
             $this->data['form']['fields']['newsletter']['captcha'] = $form->getFieldHtml(array('type' => 'captcha', 'name' => 'captcha', 'attr' => ''));
         }
     }
     //TODO: REMOVE THIS IN 1.3!!!
     // backward compatibility code
     $deprecated = $this->data['form']['fields'];
     foreach ($deprecated as $section => $fields) {
         foreach ($fields as $name => $fld) {
             if (in_array($name, array('country', 'zone'))) {
                 $name .= '_id';
             }
             $this->data['form'][$name] = $fld;
         }
     }
     //end of trick
     $agree = isset($this->request->post['agree']) ? $this->request->post['agree'] : false;
     $this->data['form']['agree'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'agree', 'value' => 1, 'checked' => $agree));
     $this->data['form']['continue'] = $form->getFieldHtml(array('type' => 'submit', 'name' => $this->language->get('button_continue')));
     $this->data['error_warning'] = $this->errors['warning'];
     $this->data['error_loginname'] = $this->errors['loginname'];
     $this->data['error_firstname'] = $this->errors['firstname'];
     $this->data['error_lastname'] = $this->errors['lastname'];
     $this->data['error_email'] = $this->errors['email'];
     $this->data['error_telephone'] = $this->errors['telephone'];
     $this->data['error_password'] = $this->errors['password'];
     $this->data['error_confirm'] = $this->errors['confirm'];
     $this->data['error_address_1'] = $this->errors['address_1'];
     $this->data['error_city'] = $this->errors['city'];
     $this->data['error_postcode'] = $this->errors['postcode'];
     $this->data['error_country'] = $this->errors['country'];
     $this->data['error_zone'] = $this->errors['zone'];
     $this->data['error_captcha'] = $this->errors['captcha'];
     $this->data['action'] = $this->html->getSecureURL('account/create');
     $this->data['newsletter'] = $this->request->post['newsletter'];
     if ($this->config->get('config_account_id')) {
         $this->loadModel('catalog/content');
         $content_info = $this->model_catalog_content->getContent($this->config->get('config_account_id'));
         if ($content_info) {
             $text_agree = $this->language->get('text_agree');
             $this->data['text_agree_href'] = $this->html->getURL('r/content/content/loadInfo', '&content_id=' . $this->config->get('config_account_id'));
             $this->data['text_agree_href_text'] = $content_info['title'];
         } else {
             $text_agree = '';
         }
     } else {
         $text_agree = '';
     }
     $this->data['text_agree'] = $text_agree;
     $text_account_already = sprintf($this->language->get('text_account_already'), $this->html->getSecureURL('account/login'));
     $this->data['text_account_already'] = $text_account_already;
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/account/create.tpl');
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
コード例 #8
0
 public function sendNewsletter()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     // this method can process only posting.
     if ($this->request->is_GET()) {
         $this->redirect($this->html->getSecureURL('sale/contact'));
     }
     if (!$this->_validate()) {
         $this->main();
         return null;
     }
     $this->loadModel('sale/customer');
     $this->loadModel('setting/store');
     $store_info = $this->model_setting_store->getStore($this->request->post['store_id']);
     if ($store_info) {
         $store_name = $store_info['store_name'];
     } else {
         $store_name = $this->config->get('store_name');
     }
     $emails = array();
     // All customers by group
     if (isset($this->request->post['recipient'])) {
         $customers = $results = array();
         if ($this->request->post['recipient'] == 'all_subscribers') {
             $all_subscribers = $this->model_sale_customer->getAllSubscribers();
             $results = $this->_unify_customer_list($all_subscribers);
         } else {
             if ($this->request->post['recipient'] == 'only_subscribers') {
                 $only_subscribers = $this->model_sale_customer->getOnlyNewsletterSubscribers();
                 $results = $this->_unify_customer_list($only_subscribers);
             } else {
                 if ($this->request->post['recipient'] == 'only_customers') {
                     $only_customers = $this->model_sale_customer->getOnlyCustomers(array('status' => 1, 'approved' => 1));
                     $results = $this->_unify_customer_list($only_customers);
                 }
             }
         }
         foreach ($results as $result) {
             $customer_id = $result['customer_id'];
             $emails[$customer_id] = $customers[$customer_id] = trim($result['email']);
         }
     }
     // All customers by name/email
     if (isset($this->request->post['to']) && $this->request->post['to']) {
         foreach ($this->request->post['to'] as $customer_id) {
             $customer_info = $this->model_sale_customer->getCustomer($customer_id);
             if ($customer_info) {
                 $emails[] = trim($customer_info['email']);
             }
         }
     }
     // All customers by product
     if (isset($this->request->post['product'])) {
         foreach ($this->request->post['product'] as $product_id) {
             $results = $this->model_sale_customer->getCustomersByProduct($product_id);
             if ($customers) {
                 $emails = array();
             }
             foreach ($results as $result) {
                 if ($customers && in_array($result['email'], $customers)) {
                     $emails[] = trim($result['email']);
                 }
             }
         }
     }
     // Prevent Duplicates
     $emails = array_unique($emails);
     if ($emails) {
         // HTML Mail
         $template = new ATemplate();
         $template->data['lang_direction'] = $this->language->get('direction');
         $template->data['lang_code'] = $this->language->get('code');
         $template->data['subject'] = $this->request->post['subject'];
         $text_unsubscribe = $this->language->get('text_unsubscribe');
         $text_subject = $this->request->post['subject'];
         $text_message = $this->request->post['message'];
         $from = $this->config->get('store_main_email');
         $mail = new AMail($this->config);
         foreach ($emails as $email) {
             $mail->setTo($email);
             $mail->setFrom($from);
             $mail->setSender($store_name);
             $mail->setSubject($text_subject);
             $message_body = $text_message;
             if ($this->request->post['recipient'] == 'newsletter') {
                 if ($customer_id = array_search($email, $customers)) {
                     $message_body .= "\n\n<br><br>" . sprintf($text_unsubscribe, $email, $this->html->getCatalogURL('account/unsubscribe', '&email=' . $email . '&customer_id=' . $customer_id));
                 }
             }
             $template->data['body'] = html_entity_decode($message_body, ENT_QUOTES, 'UTF-8');
             $html = $template->fetch('mail/contact.tpl');
             $mail->setHtml($html);
             $mail->send();
             if ($mail->error) {
                 $this->error[] = 'Error: Emails does not sent! Please see error log for details.';
                 $this->main();
                 return null;
             }
         }
         unset($mail);
     }
     $this->session->data['success'] = $this->language->get('text_success');
     $this->redirect($this->html->getSecureURL('sale/contact'));
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }