Example #1
0
 public static function useDefault($search_data = null, &$errors = array(), $defaults = null)
 {
     $search = new TicketsSearch($defaults);
     $search->addSearchField('id', 'ticket_#', 'equal');
     $search->addSearchField('internal_status_code', 'status_is', 'ticket_status', array('NEW', 'OPEN'));
     $user = new User();
     $user->loadBy('username', EGS_USERNAME);
     $search->addSearchField('originator_person_id', 'my_tickets_only', 'hide', false, 'advanced');
     $search->setOnValue('originator_person_id', $user->username);
     $search->addSearchField('summary', 'summary_contains', 'contains');
     $search->addSearchField('assigned_to', 'assigned_to', 'select', '');
     $options = array('' => 'all', EGS_USERNAME => 'me', 'NULL' => 'noone');
     if (isModuleAdmin()) {
         $users = User::getOtherUsers();
         $options = array_merge($options, $users);
     }
     $search->setOptions('assigned_to', $options);
     $search->addSearchField('originator_company', 'company_name', 'begins', null, 'advanced');
     $search->addSearchField('created', 'created_today', 'hide', false, 'advanced');
     $cc = new ConstraintChain();
     $cc->add(new Constraint('created', '>', date('Y-m-d', strtotime('yesterday'))));
     $cc->add(new Constraint('created', '<', date('Y-m-d', strtotime('tomorrow'))));
     $search->setConstraint('created', $cc);
     $queue = new TicketQueue();
     $queues = $queue->getAll();
     $search->addSearchField('ticket_queue_id', 'queue', 'multi_select', array_keys($queues), 'advanced');
     $search->setOptions('ticket_queue_id', $queues);
     $search->addSearchField('ticket_release_version_id', 'release_version', 'select', '', 'advanced');
     $releaseversion = new TicketReleaseVersion();
     $releaseversions = $releaseversion->getAll();
     $options = array('' => 'All');
     $options += $releaseversions;
     $search->setOptions('ticket_release_version_id', $options);
     $search->setSearchData($search_data, $errors);
     return $search;
 }
Example #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']));
 }
Example #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);
     }
 }
Example #4
0
 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;
 }