- | {$message['status']} |
+ {if $message['status'] == CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN}
+ {l s='Open'}
+ {elseif $message['status'] == CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED}
+ {l s='Closed'}
+ {elseif $message['status'] == CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1}
+ {l s='Pending 1'}
+ {elseif $message['status'] == CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2}
+ {l s='Pending 2'}
+ {/if}
+ |
{$message['message']}...
diff --git a/classes/CustomerMessage.php b/classes/CustomerMessage.php
index abc6df3ef..21798c993 100644
--- a/classes/CustomerMessage.php
+++ b/classes/CustomerMessage.php
@@ -100,21 +100,24 @@ class CustomerMessageCore extends ObjectModel
public static function getTotalCustomerMessages($where = null)
{
+ $sql = 'SELECT COUNT(*)
+ FROM '._DB_PREFIX_.'customer_message cm
+ LEFT JOIN `'._DB_PREFIX_.'customer_thread` ct ON (cm.`id_customer_thread` = ct.`id_customer_thread`) ';
if (is_null($where)) {
- return (int)Db::getInstance()->getValue('
- SELECT COUNT(*)
- FROM '._DB_PREFIX_.'customer_message
- LEFT JOIN `'._DB_PREFIX_.'customer_thread` ct ON (cm.`id_customer_thread` = ct.`id_customer_thread`)
- WHERE 1'.Shop::addSqlRestriction()
- );
- } else {
- return (int)Db::getInstance()->getValue('
- SELECT COUNT(*)
- FROM '._DB_PREFIX_.'customer_message cm
- LEFT JOIN `'._DB_PREFIX_.'customer_thread` ct ON (cm.`id_customer_thread` = ct.`id_customer_thread`)
- WHERE '.$where.Shop::addSqlRestriction()
+ $where = ' 1 ';
+ }
+
+ $employee = Context::getContext()->employee;
+ if (!$employee->isSuperAdmin()) {
+ $where .= (($acsHtls = HotelBranchInformation::getProfileAccessedHotels($employee->id_profile, 1, 1)) ?
+ ' AND ct.`id_order` IN (SELECT `id_order` FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE `id_hotel` IN ('.implode(',', $acsHtls).')) ' :
+ ' AND ct.`id_order` = 0 '
);
}
+
+ return (int)Db::getInstance()->getValue(
+ $sql.' WHERE '.$where.Shop::addSqlRestriction()
+ );
}
public function delete()
diff --git a/classes/CustomerThread.php b/classes/CustomerThread.php
index 04fb60851..e692dd724 100644
--- a/classes/CustomerThread.php
+++ b/classes/CustomerThread.php
@@ -210,7 +210,8 @@ class CustomerThreadCore extends ObjectModel
SELECT cl.*, COUNT(*) as total, (
SELECT id_customer_thread
FROM '._DB_PREFIX_.'customer_thread ct2
- WHERE status = "open" AND ct.id_contact = ct2.id_contact
+ WHERE status = '.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN.'
+ AND ct.id_contact = ct2.id_contact
'.Shop::addSqlRestriction().'
ORDER BY date_upd ASC
LIMIT 1
@@ -218,7 +219,7 @@ class CustomerThreadCore extends ObjectModel
FROM '._DB_PREFIX_.'customer_thread ct
LEFT JOIN '._DB_PREFIX_.'contact_lang cl
ON (cl.id_contact = ct.id_contact AND cl.id_lang = '.(int)Context::getContext()->language->id.')
- WHERE ct.status = "open"
+ WHERE ct.status = '.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN.'
AND ct.id_contact IS NOT NULL
AND cl.id_contact IS NOT NULL
'.Shop::addSqlRestriction().'
@@ -228,19 +229,19 @@ class CustomerThreadCore extends ObjectModel
public static function getTotalCustomerThreads($where = null)
{
+ $sql = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'customer_thread ';
if (is_null($where)) {
- return (int)Db::getInstance()->getValue('
- SELECT COUNT(*)
- FROM '._DB_PREFIX_.'customer_thread
- WHERE 1 '.Shop::addSqlRestriction()
- );
- } else {
- return (int)Db::getInstance()->getValue('
- SELECT COUNT(*)
- FROM '._DB_PREFIX_.'customer_thread
- WHERE '.$where.Shop::addSqlRestriction()
+ $where = ' 1 ';
+ }
+
+ $employee = Context::getContext()->employee;
+ if (!$employee->isSuperAdmin()) {
+ $where .= (($acsHtls = HotelBranchInformation::getProfileAccessedHotels($employee->id_profile, 1, 1)) ?
+ ' AND `id_order` IN (SELECT `id_order` FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE `id_hotel` IN ('.implode(',', $acsHtls).')) ' :
+ ' AND `id_order` = 0 '
);
}
+ return (int)Db::getInstance()->getValue($sql.' WHERE '.$where.Shop::addSqlRestriction());
}
public static function getMessageCustomerThreads($id_customer_thread)
diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php
index 7f2940ec1..21c6db2a1 100644
--- a/controllers/admin/AdminCustomerThreadsController.php
+++ b/controllers/admin/AdminCustomerThreadsController.php
@@ -107,7 +107,7 @@ class AdminCustomerThreadsControllerCore extends AdminController
'visible_default' => true,
),
'contact' => array(
- 'title' => $this->l('Type'),
+ 'title' => $this->l('Contact'),
'type' => 'select',
'list' => $contact_array,
'filter_key' => 'cl!id_contact',
@@ -143,6 +143,7 @@ class AdminCustomerThreadsControllerCore extends AdminController
'filter_key' => 'employee',
'tmpTableFilter' => true,
'optional' => true,
+ 'hint' => $this->l('The first employee to reply becomes responsible. They can then forward the message to another employee if needed.')
),
'last_employee' => array(
'title' => $this->l('Last Reply by'),
@@ -397,17 +398,17 @@ class AdminCustomerThreadsControllerCore extends AdminController
array(
'title' => $this->l('Threads pending'),
'val' => $pending = CustomerThread::getTotalCustomerThreads(
- 'status='.(int) CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1.'
- OR status='.(int) CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2
+ 'status='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1.'
+ OR status='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2
),
),
array(
'title' => $this->l('Total number of customer messages'),
- 'val' => CustomerMessage::getTotalCustomerMessages('ct.`id_employee` = 0'),
+ 'val' => CustomerMessage::getTotalCustomerMessages('cm.`id_employee` = 0'),
),
array(
'title' => $this->l('Total number of employee messages'),
- 'val' => CustomerMessage::getTotalCustomerMessages('ct.`id_employee` != 0'),
+ 'val' => CustomerMessage::getTotalCustomerMessages('cm.`id_employee` != 0'),
),
array(
'title' => $this->l('Unread threads'),
@@ -625,7 +626,7 @@ class AdminCustomerThreadsControllerCore extends AdminController
$this->context->link->getPageLink('contact', true, (int)$ct->id_lang, null, false, $ct->id_shop),
'token='.$ct->token
);
- $headingText = $this->l('Hi');
+ $headingText = $this->l('Hi') .' '.$ct->user_name;
$idShop = $ct->id_shop;
$params = array(
'{reply}' => Tools::nl2br(Tools::getValue('reply_message')),
@@ -633,7 +634,7 @@ class AdminCustomerThreadsControllerCore extends AdminController
'{headingtext}' => $headingText,
);
if (!empty(trim($ct->subject))) {
- $params['{subject}'] = $this->l('Title : ').$ct->subject;
+ $params['{subject}'] = $ct->subject;
}
$idLang = $ct->id_lang;
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 28c8001d9..e3f5be859 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -2490,13 +2490,15 @@ class AdminOrdersControllerCore extends AdminController
$helper->value = $objOrder->source;
$this->kpis[] = $helper;
+ $objCustomerThread = new CustomerThread();
+ $idCustomerThread = $objCustomerThread->getIdCustomerThreadByIdOrder($objOrder->id);
$helper = new HelperKpi();
$helper->id = 'box-messages';
$helper->icon = 'icon-comments';
$helper->color = 'color2';
$helper->title = $this->l('Messages');
$helper->tooltip = $this->l('Messages is the number of customer messages for this order.');
- $helper->href = $this->context->link->getAdminLink('AdminCustomerThreads').'&id_order='.$objOrder->id;
+ $helper->href = $this->context->link->getAdminLink('AdminCustomerThreads').((int) $idCustomerThread ? '&viewcustomer_thread&id_customer_thread='.(int) $idCustomerThread : '');
$helper->value = count(CustomerThread::getCustomerMessages($objOrder->id_customer, null, $objOrder->id, CustomerMessage::QLO_CUSTOMER_MESSAGE_BY_CUSTOMER));
$this->kpis[] = $helper;
diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php
index ea6bbb299..47f48394b 100644
--- a/controllers/admin/AdminStatsController.php
+++ b/controllers/admin/AdminStatsController.php
@@ -424,7 +424,15 @@ class AdminStatsControllerCore extends AdminStatsTabController
public static function getPendingMessages()
{
- return CustomerThread::getTotalCustomerThreads('status LIKE "%pending%" OR status = "open"'.Shop::addSqlRestriction());
+ $pendingStatuses = array(
+ CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN,
+ CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2,
+ CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1
+ );
+
+ return CustomerThread::getTotalCustomerThreads(
+ '`status` IN ('.implode(',', $pendingStatuses).')'.Shop::addSqlRestriction()
+ );
}
public static function getAverageMessageResponseTime($date_from, $date_to, $return_seconds = false)
@@ -455,13 +463,24 @@ class AdminStatsControllerCore extends AdminStatsTabController
public static function getMessagesPerThread($date_from, $date_to)
{
+ $accessWhere = '';
+ $employee = Context::getContext()->employee;
+ if (!$employee->isSuperAdmin()) {
+ $idProfile = $employee->id_profile;
+ if ($acsHtls = HotelBranchInformation::getProfileAccessedHotels($idProfile, 1, 1)) {
+ $accessWhere = ' AND ct.`id_order` IN (SELECT `id_order` FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE `id_hotel` IN ('.implode(',', $acsHtls).'))';
+ } else {
+ $accessWhere = ' AND ct.`id_order` = 0 ';
+ }
+ }
+
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT COUNT(*) as messages
FROM `'._DB_PREFIX_.'customer_thread` ct
LEFT JOIN `'._DB_PREFIX_.'customer_message` cm ON (ct.id_customer_thread = cm.id_customer_thread)
WHERE ct.`date_add` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
- '.Shop::addSqlRestriction().'
- AND status = "closed"
+ '.Shop::addSqlRestriction().$accessWhere.'
+ AND status = '.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED.'
GROUP BY ct.id_customer_thread');
$threads = $messages = 0;
foreach ($result as $row) {
diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php
index 329e71233..972aefd0c 100644
--- a/controllers/front/ContactController.php
+++ b/controllers/front/ContactController.php
@@ -60,7 +60,7 @@ class ContactControllerCore extends FrontController
} elseif (!Validate::isCleanHtml($message)) {
$this->errors[] = Tools::displayError('Invalid message');
} elseif (!$id_customer_thread && !$subject) {
- $this->errors[] = Tools::displayError('The subject cannot be blank.');
+ $this->errors[] = Tools::displayError('The title cannot be blank.');
} elseif (!$id_customer_thread && !Validate::isCleanHtml($subject)) {
$this->errors[] = Tools::displayError('Invalid subject$subject');
} else if (!$id_customer_thread && $nameRequired && !trim($userName)) {
@@ -72,7 +72,7 @@ class ContactControllerCore extends FrontController
} else if (!$id_customer_thread && trim($phone) && !Validate::isPhoneNumber($phone)) {
$this->errors[] = Tools::displayError('Invalid Phone number.');
} elseif (!Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id))) {
- $this->errors[] = Tools::displayError('Please select a subject from the list provided.');
+ $this->errors[] = Tools::displayError('Please choose who to send the message to.');
} elseif (!empty($file_attachment['name']) && $file_attachment['error'] != 0) {
$this->errors[] = Tools::displayError('An error occurred during the file-upload process.');
} elseif (!empty($file_attachment['name']) && !in_array(Tools::strtolower(substr($file_attachment['name'], -4)), $extension) && !in_array(Tools::strtolower(substr($file_attachment['name'], -5)), $extension)) {
@@ -160,7 +160,7 @@ class ContactControllerCore extends FrontController
if (!count($this->errors)) {
$var_list = array(
'{order_name}' => '-',
- '{attached_file}' => ' ',
+ '{attached_file}' => '-',
'{message}' => Tools::nl2br(stripslashes($message)),
'{email}' => $from,
'{product_name}' => '',
@@ -168,7 +168,7 @@ class ContactControllerCore extends FrontController
);
if (isset($file_attachment['name'])) {
- $var_list['{attached_file}'] = ''.$this->l('Attached file').':'.$file_attachment['name'];
+ $var_list['{attached_file}'] = $file_attachment['name'];
}
$id_product = (int)Tools::getValue('id_product');
|