private function notifyQueueOwner($ticket, $data) { // Needs to be Assigned To if present // otherwise Queue Owner $plateout = TicketingUtils::StatusPlate($ticket); $to = ''; if (!is_null($ticket->assigned_to)) { $user = new User(); $user->loadBy('username', $ticket->assigned_to); if (!is_null($user->person_id)) { $person = new Person(); $person->load($user->person_id); $to = $person->email->contactmethod; } if (empty($to)) { $to = $user->email; } } if (empty($to)) { $queue = new TicketQueue(); $queue->load($ticket->ticket_queue_id); if ($queue->isLoaded() && !is_null($queue->email_address)) { $to = $queue->email_address; } } if (!empty($to)) { $headers = array('From' => TicketingUtils::getReplyAddress($ticket), 'Reply-To' => $data['reply_address']); $header_string = ""; foreach ($headers as $header => $value) { $header_string .= $header . ': ' . $value . "\r\n"; } $body = $plateout . "\n" . $data['message'] . "\n"; mail($to, 're: [' . $ticket->ticket_queue_id . '-' . $ticket->id . '] ' . $ticket->summary, $body, $header_string, '-r ' . $to); } }
public function save_response() { parent::save('TicketResponse'); $ticket = new Ticket(); $ticket->load($this->_data['TicketResponse']['ticket_id']); $plateout = TicketingUtils::StatusPlate($ticket); $queue = new TicketQueue(); $queue->load($ticket->ticket_queue_id); $headers = array('From' => $queue->email_address); // FIXME: If someone forces a file upload... I guess that causes this code to randomly send the file? if ($_FILES['file']['size'] > 0) { // Send MIME mail $boundary = 'EGS-Ticketing-System-' . base_convert(rand(1000, 9000), 10, 2); $headers['Content-Type'] = 'multipart/mixed; boundary=' . $boundary; $base64 = base64_encode(file_get_contents($_FILES['file']['tmp_name'])); // Yay, hand written MIME email! $body = "--{$boundary}\r\n" . "Content-Transfer-Encoding: 8bit\r\n" . "Content-Type: text/plain; charset=ISO-8859-1\r\n" . "\r\n" . $plateout . $this->_data['TicketResponse']['body'] . "\r\n" . "\r\n" . "--{$boundary}\r\n" . 'Content-Type: octet/stream; name="' . $_FILES['file']['name'] . '"' . "\r\n" . "Content-Transfer-Encoding: base64\r\n" . 'Content-Disposition: attachment; filename="' . $_FILES['file']['name'] . '"' . "\r\n" . "\r\n" . chunk_split($base64) . "\r\n" . "\r\n" . "--{$boundary}--\r\n" . "."; $errors = array(); $file = File::Factory($_FILES['file'], $errors, new File()); $file->save(); $ticketAttachment = TicketAttachment::Factory(array('ticket_id' => $this->_data['TicketResponse']['ticket_id'], 'file_id' => $file->id), $errors, new TicketAttachment()); $ticketAttachment->save(); } else { // No attachment, send plain text mail $body = $plateout . $this->_data['TicketResponse']['body']; } $header_string = ""; foreach ($headers as $header => $value) { $header_string .= $header . ': ' . $value . "\r\n"; } // FIXME: Do this further up if (!isset($this->_data['TicketResponse']['internal']) || isset($this->_data['TicketResponse']['internal']) && $this->_data['TicketResponse']['internal'] != 'on') { $recipients = $recipients = TicketingUtils::GetRecipients($ticket); foreach ($recipients as $recipient) { mail($recipient, 're: [' . $ticket->ticket_queue_id . '-' . $ticket->id . '] ' . $ticket->summary, $body, $header_string); } } sendTo('Client', 'view', array('ticketing'), array('id' => $this->_data['TicketResponse']['ticket_id'])); }
public static function getReplyAddress($ticket) { $from = ''; $config = Config::Instance(); $ticket_support = $config->get('TICKET_SUPPORT'); if (!is_null($ticket->originator_company_id) && !empty($ticket_support)) { // use the ticket support email address for the company // TICKET_SUPPORT should be defined in the conf/config.php $from = $ticket->company->getContactDetail('E', $ticket_support); } if (empty($from)) { // no ticket support email address for the company // so use the queue email address $queue = new TicketQueue(); $queue->load($ticket->ticket_queue_id); $from = $queue->email_address; } return $from; }