public function renderView()
 {
     if (!($id_customer_thread = (int) Tools::getValue('id_customer_thread'))) {
         return;
     }
     $this->context = Context::getContext();
     if (!($thread = $this->loadObject())) {
         return;
     }
     $this->context->cookie->{'customer_threadFilter_cl!id_contact'} = $thread->id_contact;
     $employees = Employee::getEmployees();
     $messages = CustomerThread::getMessageCustomerThreads($id_customer_thread);
     foreach ($messages as $key => $mess) {
         if ($mess['id_employee']) {
             $employee = new Employee($mess['id_employee']);
             $messages[$key]['employee_image'] = $employee->getImage();
         }
         if (isset($mess['file_name']) && $mess['file_name'] != '') {
             $messages[$key]['file_name'] = _THEME_PROD_PIC_DIR_ . $mess['file_name'];
         } else {
             unset($messages[$key]['file_name']);
         }
         if ($mess['id_product']) {
             $product = new Product((int) $mess['id_product'], false, $this->context->language->id);
             if (Validate::isLoadedObject($product)) {
                 $messages[$key]['product_name'] = $product->name;
                 $messages[$key]['product_link'] = $this->context->link->getAdminLink('AdminProducts') . '&updateproduct&id_product=' . (int) $product->id;
             }
         }
     }
     $next_thread = CustomerThread::getNextThread((int) $thread->id);
     $contacts = Contact::getContacts($this->context->language->id);
     $actions = array();
     if ($next_thread) {
         $next_thread = array('href' => self::$currentIndex . '&id_customer_thread=' . (int) $next_thread . '&viewcustomer_thread&token=' . $this->token, 'name' => $this->l('Reply to the next unanswered message in this thread'));
     }
     if ($thread->status != 'closed') {
         $actions['closed'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=2&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Mark as "handled"'), 'name' => 'setstatus', 'value' => 2);
     } else {
         $actions['open'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Re-open'), 'name' => 'setstatus', 'value' => 1);
     }
     if ($thread->status != 'pending1') {
         $actions['pending1'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=3&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Mark as "pending 1" (will be answered later)'), 'name' => 'setstatus', 'value' => 3);
     } else {
         $actions['pending1'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Disable pending status'), 'name' => 'setstatus', 'value' => 1);
     }
     if ($thread->status != 'pending2') {
         $actions['pending2'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=4&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Mark as "pending 2" (will be answered later)'), 'name' => 'setstatus', 'value' => 4);
     } else {
         $actions['pending2'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'label' => $this->l('Disable pending status'), 'name' => 'setstatus', 'value' => 1);
     }
     if ($thread->id_customer) {
         $customer = new Customer($thread->id_customer);
         $orders = Order::getCustomerOrders($customer->id);
         if ($orders && count($orders)) {
             $total_ok = 0;
             $orders_ok = array();
             foreach ($orders as $key => $order) {
                 if ($order['valid']) {
                     $orders_ok[] = $order;
                     $total_ok += $order['total_paid_real'];
                 }
                 $orders[$key]['date_add'] = Tools::displayDate($order['date_add']);
                 $orders[$key]['total_paid_real'] = Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency']));
             }
         }
         $products = $customer->getBoughtProducts();
         if ($products && count($products)) {
             foreach ($products as $key => $product) {
                 $products[$key]['date_add'] = Tools::displayDate($product['date_add'], null, true);
             }
         }
     }
     $timeline_items = $this->getTimeline($messages, $thread->id_order);
     $first_message = $messages[0];
     if (!$messages[0]['id_employee']) {
         unset($messages[0]);
     }
     $contact = '';
     foreach ($contacts as $c) {
         if ($c['id_contact'] == $thread->id_contact) {
             $contact = $c['name'];
         }
     }
     $this->tpl_view_vars = array('id_customer_thread' => $id_customer_thread, 'thread' => $thread, 'actions' => $actions, 'employees' => $employees, 'current_employee' => $this->context->employee, 'messages' => $messages, 'first_message' => $first_message, 'contact' => $contact, 'next_thread' => $next_thread, 'orders' => isset($orders) ? $orders : false, 'customer' => isset($customer) ? $customer : false, 'products' => isset($products) ? $products : false, 'total_ok' => isset($total_ok) ? Tools::displayPrice($total_ok, $this->context->currency) : false, 'orders_ok' => isset($orders_ok) ? $orders_ok : false, 'count_ok' => isset($orders_ok) ? count($orders_ok) : false, 'PS_CUSTOMER_SERVICE_SIGNATURE' => str_replace('\\r\\n', "\n", Configuration::get('PS_CUSTOMER_SERVICE_SIGNATURE', (int) $thread->id_lang)), 'timeline_items' => $timeline_items);
     if ($next_thread) {
         $this->tpl_view_vars['next_thread'] = $next_thread;
     }
     return parent::renderView();
 }
 public function renderView()
 {
     if (!($id_customer_thread = (int) Tools::getValue('id_customer_thread'))) {
         return;
     }
     $this->context = Context::getContext();
     if (!($thread = $this->loadObject())) {
         return;
     }
     $this->context->cookie->{'customer_threadFilter_cl!id_contact'} = $thread->id_contact;
     $employees = Employee::getEmployees();
     $messages = CustomerThread::getMessageCustomerThreads($id_customer_thread);
     $next_thread = CustomerThread::getNextThread((int) $thread->id);
     $actions = array();
     if ($next_thread) {
         $actions['next_thread'] = array('href' => self::$currentIndex . '&id_customer_thread=' . (int) $next_thread . '&viewcustomer_thread&token=' . $this->token, 'name' => $this->l('Reply to the next unanswered message in this category.'));
     } else {
         $actions['next_thread'] = array('href' => false, 'name' => $this->l('All other messages in this category have been answered.'));
     }
     if ($thread->status != 'closed') {
         $actions['closed'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=2&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'name' => $this->l('Mark this message as handled.'));
     }
     if ($thread->status != 'pending1') {
         $actions['pending1'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=3&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'name' => $this->l('Mark this message as "pending 1" (will be answered later).'));
     } else {
         $actions['pending1'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'name' => $this->l('Disable pending status.'));
     }
     if ($thread->status != 'pending2') {
         $actions['pending2'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=4&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'name' => $this->l('Mark this message as "pending 2" (will be answered later).'));
     } else {
         $actions['pending2'] = array('href' => self::$currentIndex . '&viewcustomer_thread&setstatus=1&id_customer_thread=' . (int) Tools::getValue('id_customer_thread') . '&viewmsg&token=' . $this->token, 'name' => $this->l('Disable pending status.'));
     }
     if ($thread->id_customer) {
         $customer = new Customer($thread->id_customer);
         $orders = Order::getCustomerOrders($customer->id);
         if ($orders && count($orders)) {
             $total_ok = 0;
             $orders_ok = array();
             foreach ($orders as $key => $order) {
                 if ($order['valid']) {
                     $orders_ok[] = $order;
                     $total_ok += $order['total_paid_real'];
                 }
                 $orders[$key]['date_add'] = Tools::displayDate($order['date_add']);
                 $orders[$key]['total_paid_real'] = Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency']));
             }
         }
         $products = $customer->getBoughtProducts();
         if ($products && count($products)) {
             foreach ($products as $key => $product) {
                 $products[$key]['date_add'] = Tools::displayDate($product['date_add'], null, true);
             }
         }
     }
     foreach ($messages as $key => $message) {
         $messages[$key] = $this->displayMessage($message);
     }
     $this->tpl_view_vars = array('id_customer_thread' => $id_customer_thread, 'thread' => $thread, 'actions' => $actions, 'employees' => $employees, 'messages' => $messages, 'next_thread' => $next_thread, 'orders' => isset($orders) ? $orders : false, 'customer' => isset($customer) ? $customer : false, 'products' => isset($products) ? $products : false, 'total_ok' => isset($total_ok) ? Tools::displayPrice($total_ok, $this->context->currency) : false, 'orders_ok' => isset($orders_ok) ? $orders_ok : false, 'count_ok' => isset($orders_ok) ? count($orders_ok) : false);
     return parent::renderView();
 }