function addComment($data) { $user = JFactory::getUser(); $config = HelpdeskProHelper::getConfig(); if (isset($data['message_id'])) { $row = JTable::getInstance('helpdeskpro', 'message'); if ($data['comment' . $data['message_id']] == '') { $row->delete($data['message_id']); return true; } $row->load($data['message_id']); $row->message = $data['comment' . $data['message_id']]; $row->store(); return true; } $ticket = JTable::getInstance('helpdeskpro', 'ticket'); $row = JTable::getInstance('helpdeskpro', 'message'); $allowedFileTypes = explode('|', $config->allowed_file_types); for ($i = 0, $n = count($allowedFileTypes); $i < $n; $i++) { $allowedFileTypes[$i] = trim(strtoupper($allowedFileTypes[$i])); } $row->bind($data); $row->message = $data['comment']; $ticket->load($row->ticket_id); if ($user->id) { $row->user_id = $user->get('id'); } else { if (isset($data['ticket_code'])) { $row->user_id = $ticket->user_id; } } $row->date_added = gmdate('Y-m-d H:i:s'); $uploadedFiles = $this->_storeAttachment($allowedFileTypes); if (count($uploadedFiles['names'])) { $row->attachments = implode('|', $uploadedFiles['names']); $row->original_filenames = implode('|', $uploadedFiles['original_names']); } $row->store(); if ($row->user_id == $ticket->user_id || isset($data['ticket_code'])) { $isCustomerAddComment = true; } else { $isCustomerAddComment = false; } //Update ticket status if ($isCustomerAddComment) { if ($config->ticket_status_when_customer_add_comment) { $ticket->status_id = $config->ticket_status_when_customer_add_comment; } } else { if ($config->ticket_status_when_admin_add_comment) { $ticket->status_id = $config->ticket_status_when_admin_add_comment; } } $ticket->modified_date = gmdate('Y-m-d H:i:s'); $ticket->store(); //Need to send email to users if ($isCustomerAddComment) { HelpdeskProHelper::sendTicketUpdatedEmailToManagers($row, $ticket, $config); } else { HelpdeskProHelper::sendTicketUpdatedEmailToCustomer($row, $ticket, $config); } return true; }