Esempio n. 1
0
 public function save_response()
 {
     // sort the data out
     if (isset($this->_data['response'])) {
         $this->_data['TicketResponse']['body'] = $this->_data['response'];
         $this->_data['TicketResponse']['ticket_id'] = $this->_data['ticket_id'];
         $this->_data['TicketResponse']['type'] = 'site';
     }
     $save = parent::save('TicketResponse', $this->_data['TicketResponse']);
     $ticket = new Ticket();
     $ticket->load($this->_data['TicketResponse']['ticket_id']);
     $plateout = TicketingUtils::StatusPlate($ticket);
     $headers = array('From' => TicketingUtils::getReplyAddress($ticket));
     $hours_data =& $this->_data['Hour'];
     if (isset($hours_data['duration']) && $hours_data['duration'] != 0) {
         if ($hours_data['duration_unit'] == 'days') {
             $hours_data['duration'] = $hours_data['duration'] * SystemCompanySettings::DAY_LENGTH;
         }
         // Calculate start time by working backward NB: Needs changing with date_format?
         $hours_data['start_time'] = date("d/m/Y H:i", time() - $hours_data['duration'] * 60 * 60);
         $hours_data['duration'] .= ' hours';
         parent::save('Hour');
     }
     // 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 = TicketingUtils::GetRecipients($ticket);
         foreach ($recipients as $recipient) {
             mail($recipient, 're: [' . $ticket->ticket_queue_id . '-' . $ticket->id . '] ' . $ticket->summary, $body, $header_string);
         }
     }
     if (is_ajax()) {
         echo json_encode(array('success' => $save));
         exit;
     } else {
         sendTo('Tickets', 'view', array('ticketing'), array('id' => $this->_data['TicketResponse']['ticket_id']));
     }
 }
Esempio n. 2
0
 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']));
 }
Esempio n. 3
0
 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);
     }
 }