From ae78a0b8702aa655e69af15628c4a850ca92be1d Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Thu, 11 May 2017 15:48:43 +0200 Subject: [PATCH] continuing --- .../AdminAntReturnprocess.php | 121 +++++++++++++++++- 1 file changed, 119 insertions(+), 2 deletions(-) diff --git a/modules/ant_returnprocess/AdminAntReturnprocess.php b/modules/ant_returnprocess/AdminAntReturnprocess.php index c78d7484..be529b23 100644 --- a/modules/ant_returnprocess/AdminAntReturnprocess.php +++ b/modules/ant_returnprocess/AdminAntReturnprocess.php @@ -57,6 +57,63 @@ class AdminAntReturnprocess extends AdminTab } else { HelperFormBootstrap::displayErrors(Tools::displayError('No order return ID.')); } + } elseif (Tools::isSubmit('submitReply')) { + if (($id_order_return = (int)(Tools::getValue('id_order_return'))) AND Validate::isUnsignedId($id_order_return)) + { + if (($id_customer_thread = (int)(Tools::getValue('id_customer_thread'))) AND Validate::isUnsignedId($id_customer_thread)) { + $ct = new CustomerThread($id_customer_thread); + $cm = new CustomerMessage(); + $cm->id_employee = (int)$cookie->id_employee; + $cm->id_customer_thread = $ct->id; + $cm->message = Tools::htmlentitiesutf8(nl2br2(Tools::getValue('reply_message'))); + $cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']); + + if (isset($_FILES) AND !empty($_FILES['joinFile']['name']) AND $_FILES['joinFile']['error'] != 0) { + HelperFormBootstrap::displayErrors(Tools::displayError('An error occurred with the file upload.')); + } elseif ($cm->add()) { + $fileAttachment = NULL; + if (!empty($_FILES['joinFile']['name'])) + { + $cm->file_name = $_FILES['joinFile']['name']; + $fileAttachment['content'] = file_get_contents($_FILES['joinFile']['tmp_name']); + $fileAttachment['name'] = $_FILES['joinFile']['name']; + $fileAttachment['mime'] = $_FILES['joinFile']['type']; + } + if($ct->id_contact == 9 || $ct->id_contact == 1) { + $id_reason = Db::getInstance()->getValue(' + SELECT sr.`id_reason` + FROM `'._DB_PREFIX_.'support_reason` sr + LEFT JOIN `'._DB_PREFIX_.'support_reason_customerthread` src ON (src.id_reason = sr.id_reason) + WHERE `id_customer_thread` = '.(int)($ct->id) + ); + $link_reply = ($ct->id_lang == 3 ? str_replace('com','es',Tools::getShopDomain(true).__PS_BASE_URI__):Tools::getShopDomain(true).__PS_BASE_URI__).'modules/ant_support_form/support.php?id_customer_thread='.(int)($ct->id).'&token='.$ct->token.(($ct->id_contact == 9 || $ct->id_contact == 1)?'&id_contact='.$ct->id_contact : '').((isset($id_reason) && $id_reason)?'&id_reason='.(int)$id_reason : ''); + } else { + $link_reply = $link->getPageLink('contact-form.php', true).'?id_customer_thread='.(int)($ct->id).'&token='.$ct->token; + if($ct->id_lang == 3) { + $link_reply = str_replace('com','es',$link_reply); + } + } + $params = array( + '{reply}' => nl2br2(Tools::getValue('reply_message')), + '{link}' => $link_reply); + if (Mail::Send($ct->id_lang, 'reply_msg', Mail::l('An answer to your message is available'), + $params, Tools::getValue('msg_email'), NULL, NULL, NULL, $fileAttachment, NULL, + _PS_MAIL_DIR_, true)) + { + $ct->status = 'closed'; + $ct->update(); + $cm->update(); + } + Tools::redirectAdmin($currentIndex.'&id_order_return='.(int)$id_order_return.'&updateorder_return&conf=4&token='.$this->token); + } else { + HelperFormBootstrap::displayErrors(Tools::displayError('An error occurred, your message was not sent. Please contact your system administrator.')); + } + } else { + HelperFormBootstrap::displayErrors(Tools::displayError('No conversation ID.')); + } + } else { + HelperFormBootstrap::displayErrors(Tools::displayError('No order return ID.')); + } } } @@ -135,6 +192,16 @@ class AdminAntReturnprocess extends AdminTab '); if($query_thread) { $thread = new CustomerThread((int)$query_thread); + $last_message = Db::getInstance()->getRow(' + SELECT ct.*, cm.*, cl.name subject, CONCAT(e.firstname, \' \', e.lastname) employee_name, CONCAT(c.firstname, \' \', c.lastname) customer_name, c.firstname + FROM '._DB_PREFIX_.'customer_thread ct + LEFT JOIN '._DB_PREFIX_.'customer_message cm ON (ct.id_customer_thread = cm.id_customer_thread) + LEFT JOIN '._DB_PREFIX_.'contact_lang cl ON (cl.id_contact = ct.id_contact AND cl.id_lang = '.(int)$cookie->id_lang.') + LEFT JOIN '._DB_PREFIX_.'employee e ON e.id_employee = cm.id_employee + LEFT JOIN '._DB_PREFIX_.'customer c ON (IFNULL(ct.id_customer, ct.email) = IFNULL(c.id_customer, c.email)) + WHERE ct.id_customer_thread = '.(int)($thread->id).' + ORDER BY cm.date_add DESC' + ); } $returnProducts = OrderReturn::getOrdersReturnProducts($orderReturn->id, $order); @@ -358,7 +425,7 @@ class AdminAntReturnprocess extends AdminTab AND pl.`id_lang` = 2' ); if($products && !empty($products)) { - $html .='
Produit(s) Concerné(s) :
'; + $html .='
Produit(s) Concerné(s)
'; foreach ($products as $product) { $img_path = ''; $img = Db::getInstance()->getRow(' @@ -378,7 +445,57 @@ class AdminAntReturnprocess extends AdminTab '; } } - $html .=''; + if($last_message){ + $html .='
Dernier Message
'; + $last_message['message'] = preg_replace('/(https?:\/\/[a-z0-9#%&_=\(\)\.\? \+\-@\/]{6,1000})([\s\n<])/Uui', '\1\2', html_entity_decode($last_message['message'], ENT_NOQUOTES, 'UTF-8')); + + if(!empty($last_message['employee_name'])) { + $html .=' +
+

Bébé Boutik - ('.Tools::displayDate($last_message['date_add'], (int)($cookie->id_lang), true).')

+

+ "'.$last_message['message'].'" +

+
'; + } else { + $html .=' +
+

'.$customer->firstname.' '.$customer->lastname.' - ('.Tools::displayDate($last_message['date_add'], (int)($cookie->id_lang), true).')

+

+ "'.$last_message['message'].'" +

+
'; + } + + $orderMessages = OrderMessage::getOrderMessages((int)($last_message['id_lang'])); + $html .=' +
+
Envoyer un message
+
+
+ +
+
+ +
+
+ +
+
+ + + + +
+
+
'; + } } else { $html .='

Pas de conversation en rapport avec cette commande !

'; }