* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminMessages extends AdminTab { public function __construct() { global $cookie; $this->table = 'order'; $this->className = 'Order'; $this->view = 'noActionColumn'; $this->colorOnBackground = true; $start = 0; $this->_defaultOrderBy = 'date_add'; /* Manage default params values */ if (empty($limit)) $limit = ((!isset($cookie->{$this->table.'_pagination'})) ? $this->_pagination[0] : $limit = $cookie->{$this->table.'_pagination'}); if (!Validate::isTableOrIdentifier($this->table)) die (Tools::displayError('Table name is invalid:').' "'.$this->table.'"'); if (empty($orderBy)) $orderBy = Tools::getValue($this->table.'Orderby', $this->_defaultOrderBy); elseif ($orderBy == 'id_order') $orderBy = 'm.id_order'; if (empty($orderWay)) $orderWay = Tools::getValue($this->table.'Orderway', 'ASC'); $limit = (int)(Tools::getValue('pagination', $limit)); $cookie->{$this->table.'_pagination'} = $limit; /* Check params validity */ if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay) OR !is_numeric($start) OR !is_numeric($limit)) die(Tools::displayError('get list params is not valid')); if ($orderBy == 'id_order') $orderBy = 'm.id_order'; /* Determine offset from current page */ if ((isset($_POST['submitFilter'.$this->table]) OR isset($_POST['submitFilter'.$this->table.'_x']) OR isset($_POST['submitFilter'.$this->table.'_y'])) AND !empty($_POST['submitFilter'.$this->table]) AND is_numeric($_POST['submitFilter'.$this->table])) $start = (int)($_POST['submitFilter'.$this->table] - 1) * $limit; $this->_list = Db::getInstance()->ExecuteS(' SELECT SQL_CALC_FOUND_ROWS m.id_message, m.id_cart, m.id_employee, IF(m.id_order > 0, m.id_order, \'--\') id_order, m.message, m.private, m.date_add, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS customer, c.id_customer, count(m.id_message) nb_messages, (SELECT message FROM '._DB_PREFIX_.'message WHERE id_order = m.id_order ORDER BY date_add DESC LIMIT 1) last_message, (SELECT COUNT(m2.id_message) FROM '._DB_PREFIX_.'message m2 WHERE 1 AND m2.id_customer != 0 AND m2.id_order = m.id_order AND m2.id_message NOT IN (SELECT mr2.id_message FROM '._DB_PREFIX_.'message_readed mr2 WHERE mr2.id_employee = '.(int)($cookie->id_employee).') GROUP BY m2.id_order) nb_messages_not_read_by_me FROM '._DB_PREFIX_.'message m LEFT JOIN '._DB_PREFIX_.'orders o ON (o.id_order = m.id_order) LEFT JOIN '._DB_PREFIX_.'customer c ON (c.id_customer = m.id_customer) GROUP BY m.id_order ORDER BY '.(isset($orderBy) ? pSQL($orderBy) : 'date_add') .' '.(isset($orderWay) ? pSQL($orderWay) : 'DESC').' LIMIT '.(int)($start).','.(int)($limit)); $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS()'); $this->fieldsDisplay = array( 'id_order' => array('title' => $this->l('Order ID'), 'align' => 'center', 'width' => 30), 'id_customer' => array('title' => $this->l('Customer ID'), 'align' => 'center', 'width' => 30), 'customer' => array('title' => $this->l('Customer'), 'width' => 100, 'filter_key' => 'customer', 'tmpTableFilter' => true), 'last_message' => array('title' => $this->l('Last message'), 'width' => 400, 'orderby' => false), 'nb_messages_not_read_by_me' => array('title' => $this->l('Unread message(s)'), 'width' =>30, 'align' => 'center'), 'nb_messages' => array('title' => $this->l('Number of messages'), 'width' => 30, 'align' => 'center')); parent::__construct(); } public function display() { global $cookie, $currentIndex; if (isset($_GET['ajax']) && !empty($_GET['id_cart'])) { ob_clean(); $messages = Message::getMessagesByCartId(Tools::getValue('id_cart'), true); echo '
'.$this->l('This customer has not finalized their order, however here are their messages:').'
'; foreach ($messages AS $message) { echo ''.$this->l('Cart ID:').' | '.(int)$message['id_cart'].' |
'.$this->l('Customer ID:').' | '.(int)$message['id_customer'].' |
'.$this->l('Date:').' | '.Tools::displayDate($message['date_add'], (int)$cookie->id_lang, true).' |
'.$this->l('Message:').' '.Tools::htmlentitiesUTF8($message['message']).'
'. Tools::displayError('Cannot display this message because the customer has not finalized their order.').'
'; } foreach ($this->_list AS $k => &$item) if (Tools::strlen($item['last_message']) > 150 + Tools::strlen('...')) $this->_list[$k]['last_message'] = Tools::substr(html_entity_decode($item['last_message'], ENT_QUOTES, 'UTF-8'), 0, 150, 'UTF-8').'...'; foreach ($this->_list AS $k => &$item) if ($item['id_order'] == '--') $this->_list[$k]['last_message'] .= ' '; echo ' '; $this->displayList(); $this->displayOptionsList(); } } }