Ejemplo n.º 1
0
 public function save()
 {
     $errors = array();
     $file = File::Factory($_FILES['file'], $errors, new File());
     $file->save();
     $ticketAttachment = TicketAttachment::Factory(array('ticket_id' => $this->_data['ticket_id'], 'file_id' => $file->id), $errors, new TicketAttachment());
     $ticketAttachment->save();
     sendTo('Attachments', 'view', array('ticketing'), array('id' => $ticketAttachment->id));
 }
Ejemplo n.º 2
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']));
     }
 }
Ejemplo n.º 3
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']));
 }
Ejemplo n.º 4
0
 private function saveAttachments($data, $db, &$errors)
 {
     $attachment_errors = array();
     foreach ($data['attachments'] as $attachment) {
         $encoding = $attachment['encoding']->scalarval();
         $type = $attachment['type']->scalarval();
         $subtype = $attachment['subtype']->scalarval();
         $content = $attachment['content']->scalarval();
         if ($encoding == 3) {
             $content = base64_decode($content);
         }
         if (isset($attachment['filename'])) {
             $data['name'] = $attachment['filename']->scalarval();
         } else {
             $data['name'] = 'attachment';
         }
         $fname = FILE_ROOT . 'data/tmp/' . $data['name'];
         $types = array(0 => 'text', 1 => 'multipart', 2 => 'message', 3 => 'application', 4 => 'audio', 5 => 'image', 6 => 'video', 7 => 'other');
         $data['type'] = $types[$type] . '/' . strtolower($subtype);
         $fd = fopen($fname, 'w');
         $data['size'] = fwrite($fd, $content);
         fclose($fd);
         if (!chmod($fname, 0655)) {
             $errors[] = 'Error changing permission of uploaded file, contact the server admin';
         }
         if ($data['size']) {
             $file = DataObject::Factory($data, $attachment_errors, new File());
             $file->tmp_name = $fname;
         } else {
             $file = false;
         }
         if (count($attachment_errors) > 0 || !$file || !$file->save()) {
             $attachment_errors[] = 'Failed to create attachment';
         }
         if (count($attachment_errors) == 0) {
             $ticketAttachment = TicketAttachment::Factory(array('ticket_id' => $data['TicketResponse']['ticket_id'], 'file_id' => $file->id), $attachment_errors, new TicketAttachment());
             if (count($attachment_errors) > 0 || !$ticketAttachment || !$ticketAttachment->save()) {
                 $attachment_errors[] = 'Error saving Ticket Attachment';
             }
         }
     }
     if (count($attachment_errors) > 0) {
         $errors += $attachment_errors;
         return false;
     } else {
         return true;
     }
 }