function index()
 {
     $this->load->helper('notification');
     $this->load->helper('string');
     $emailconfig = Setting::first();
     if ($emailconfig->ticket_config_active == "1") {
         $emailconfig->ticket_config_timestamp = time();
         $emailconfig->save();
         // this shows basic IMAP, no TLS required
         $config['login'] = $emailconfig->ticket_config_login;
         $config['pass'] = $emailconfig->ticket_config_pass;
         $config['host'] = $emailconfig->ticket_config_host;
         $config['port'] = $emailconfig->ticket_config_port;
         $config['mailbox'] = $emailconfig->ticket_config_mailbox;
         if ($emailconfig->ticket_config_imap == "1") {
             $flags = "/imap";
         } else {
             $flags = "/pop3";
         }
         if ($emailconfig->ticket_config_ssl == "1") {
             $flags .= "/ssl";
         }
         $config['service_flags'] = $flags . $emailconfig->ticket_config_flags;
         $this->load->library('peeker', $config);
         //attachment folder
         $bool = $this->peeker->set_attachment_dir('files/media/');
         //Search Filter
         $this->peeker->set_search($emailconfig->ticket_config_search);
         if ($this->peeker->search_and_count_messages() != "0") {
             log_message('error', 'Postmaster fetched ' . $this->peeker->search_and_count_messages() . ' new email tickets.');
             $id_array = $this->peeker->get_ids_from_search();
             //walk trough emails
             foreach ($id_array as $email_id) {
                 $ticket = false;
                 $email = $this->peeker->get_message($email_id);
                 $email->rewrite_html_transform_img_tags('files/media/');
                 $emailbody = utf8_encode(nl2br($email->get_plain()));
                 $emailaddr = $email->get_from_array();
                 $emailaddr = $emailaddr[0]->mailbox . '@' . $emailaddr[0]->host;
                 //get next ticket number
                 $settings = Setting::first();
                 $ticket_reference = $settings->ticket_reference;
                 $settings->ticket_reference = $settings->ticket_reference + 1;
                 $settings->save();
                 if (preg_match('/(?<=\\[Ticket\\#)(.+)(?=\\])/is', $email->get_subject(), $matches)) {
                     $ticket = Ticket::find_by_reference($matches[1]);
                 }
                 if ($ticket) {
                     log_message('error', 'Fetched email merged to ticket #' . $matches[1]);
                     $article_attributes = array('ticket_id' => $ticket->id, 'internal' => '0', 'from' => $email->get_from() . ' - ' . $emailaddr, 'reply_to' => $emailaddr, 'to' => $email->get_to(), 'cc' => $email->get_cc(), 'subject' => htmlspecialchars($email->get_subject()), 'message' => $emailbody, 'datetime' => time());
                     if ($ticket->status == "closed") {
                         $ticket->status = 'reopened';
                         $ticket->updated = '1';
                         $ticket->save();
                     }
                     $ticket->updated = '1';
                     $ticket->save();
                     $article = TicketHasArticle::create($article_attributes);
                     if (isset($ticket->user->email)) {
                         send_ticket_notification($ticket->user->email, '[Ticket#' . $ticket->reference . '] - ' . $ticket->subject, $emailbody, $ticket->id);
                     }
                     //Attachments
                     $parts = $email->get_parts_array();
                     if ($email->has_attachment()) {
                         foreach ($parts as $part) {
                             $savename = $email->get_fingerprint() . random_string('alnum', 8) . $part->get_filename();
                             $orgname = $part->get_filename();
                             $part->filename = $savename;
                             $attributes = array('article_id' => $article->id, 'filename' => $orgname, 'savename' => $savename);
                             $attachment = ArticleHasAttachment::create($attributes);
                         }
                         $email->save_all_attachments('files/media/');
                     }
                 } else {
                     //Ticket Attributes
                     $ticket_attributes = array('reference' => $ticket_reference, 'from' => $email->get_from() . ' - ' . $emailaddr, 'subject' => $email->get_subject(), 'text' => $emailbody, 'updated' => "1", 'created' => time(), 'user_id' => $settings->ticket_default_owner, 'type_id' => $settings->ticket_default_type, 'status' => $settings->ticket_default_status, 'queue_id' => $settings->ticket_default_queue);
                     //check if sender is client
                     $client = Client::find_by_email($emailaddr);
                     if (isset($client)) {
                         $ticket_attributes['client_id'] = $client->id;
                         $ticket_attributes['company_id'] = $client->company->id;
                     }
                     //create Ticket
                     $ticket = Ticket::create($ticket_attributes);
                     //Attachments
                     $parts = $email->get_parts_array();
                     if ($email->has_attachment()) {
                         foreach ($parts as $part) {
                             $savename = $email->get_fingerprint() . random_string('alnum', 8) . $part->get_filename();
                             $orgname = $part->get_filename();
                             $part->filename = $savename;
                             $attributes = array('ticket_id' => $ticket->id, 'filename' => $orgname, 'savename' => $savename);
                             $attachment = TicketHasAttachment::create($attributes);
                         }
                         $email->save_all_attachments('files/media/');
                     }
                     send_ticket_notification($ticket->user->email, '[Ticket#' . $ticket->reference . '] - ' . $ticket->subject, $emailbody, $ticket->id);
                     log_message('error', 'New ticket created #' . $ticket->reference);
                 }
                 if ($emailconfig->ticket_config_delete == "1") {
                     $email->set_delete();
                     $email->expunge();
                     $this->peeker->delete_and_expunge($email_id);
                 }
             }
         }
         $this->peeker->close();
         // tell the story of the connection (only for debuging)
         //echo "<pre>"; print_r($this->peeker->trace()); echo "</pre>";
     }
     die;
 }
Beispiel #2
0
 function article($id = FALSE, $condition = FALSE, $article_id = FALSE)
 {
     $this->view_data['submenu'] = array($this->lang->line('application_back') => 'ctickets', $this->lang->line('application_overview') => 'ctickets/view/' . $id);
     switch ($condition) {
         case 'add':
             $this->content_view = 'tickets/client_views/_note';
             if ($_POST) {
                 $config['upload_path'] = './files/media/';
                 $config['encrypt_name'] = TRUE;
                 $config['allowed_types'] = '*';
                 $this->load->library('upload', $config);
                 $this->load->helper('notification');
                 unset($_POST['userfile']);
                 unset($_POST['file-name']);
                 unset($_POST['send']);
                 unset($_POST['_wysihtml5_mode']);
                 $ticket = Ticket::find_by_id($id);
                 $ticket->updated = "1";
                 $ticket->save();
                 if ($ticket->company_id != $this->client->company->id || $ticket->client_id != $this->client->id) {
                     redirect('ctickets');
                 }
                 send_ticket_notification($ticket->user->email, '[Ticket#' . $ticket->reference . '] - ' . $_POST['subject'], $_POST['message'], $ticket->id);
                 $_POST['internal'] = "0";
                 unset($_POST['notify']);
                 $_POST['subject'] = htmlspecialchars($_POST['subject']);
                 $_POST['datetime'] = time();
                 $_POST['ticket_id'] = $id;
                 $_POST['from'] = $this->client->firstname . " " . $this->client->lastname . ' - ' . $this->client->email;
                 $_POST['reply_to'] = $this->client->email;
                 $article = TicketHasArticle::create($_POST);
                 if (!$this->upload->do_upload()) {
                     $error = $this->upload->display_errors('', ' ');
                     $this->session->set_flashdata('message', 'error:' . $error);
                 } else {
                     $data = array('upload_data' => $this->upload->data());
                     $attributes = array('article_id' => $article->id, 'filename' => $data['upload_data']['orig_name'], 'savename' => $data['upload_data']['file_name']);
                     $attachment = ArticleHasAttachment::create($attributes);
                 }
                 if (!$article) {
                     $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_save_article_error'));
                 } else {
                     $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_save_article_success'));
                 }
                 redirect('ctickets/view/' . $id);
             } else {
                 $this->theme_view = 'modal';
                 $this->view_data['ticket'] = Ticket::find($id);
                 $this->view_data['title'] = $this->lang->line('application_add_note');
                 $this->view_data['form_action'] = 'ctickets/article/' . $id . '/add';
                 $this->content_view = 'tickets/client_views/_note';
             }
             break;
         default:
             redirect('ctickets');
             break;
     }
 }
Beispiel #3
0
 function bulk($action)
 {
     $this->load->helper('notification');
     if ($_POST) {
         if (empty($_POST['list'])) {
             redirect('tickets');
         }
         $list = explode(",", $_POST['list']);
         switch ($action) {
             case 'close':
                 $attr = array('status' => "closed");
                 $email_message = $this->lang->line('messages_bulk_ticket_closed');
                 $success_message = $this->lang->line('messages_bulk_ticket_closed_success');
                 break;
             default:
                 redirect('tickets');
                 break;
         }
         foreach ($list as $value) {
             $ticket = Ticket::find_by_id($value);
             $ticket->update_attributes($attr);
             send_ticket_notification($ticket->user->email, '[Ticket#' . $ticket->reference . '] - ' . $ticket->subject, $email_message, $ticket->id);
             if (!$ticket) {
                 $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_save_ticket_error'));
             } else {
                 $this->session->set_flashdata('message', 'success:' . $success_message);
             }
         }
         redirect('tickets');
         /*
         if(isset($ticket->client->email)){ $email = $ticket->client->email; } else {$emailex = explode(' - ', $ticket->from); $email = $emailex[1]; }
         if(isset($_POST['notify'])){
         	
         send_ticket_notification($email, '[Ticket#'.$ticket->reference.'] - '.$ticket->subject, $_POST['message'], $ticket->id);
         }
         send_ticket_notification($ticket->user->email, '[Ticket#'.$ticket->reference.'] - '.$ticket->subject, $_POST['message'], $ticket->id);
         $_POST['internal'] = "0";
         unset($_POST['notify']);
         $_POST['subject'] = htmlspecialchars($_POST['subject']);
         $_POST['datetime'] = time();
         $_POST['from'] = $this->user->firstname." ".$this->user->lastname.' - '.$this->user->email;
         $_POST['reply_to'] = $this->user->email;
         $_POST['ticket_id'] = $id;
         $_POST['to'] = $email;
         unset($_POST['client_id']);
         $article = TicketHasArticle::create($_POST);
                		if(!$ticket){$this->session->set_flashdata('message', 'error:'.$this->lang->line('messages_save_ticket_error'));}
                		else{$this->session->set_flashdata('message', 'success:'.$this->lang->line('messages_ticket_close_success'));}
         redirect('tickets');
         */
     } else {
         $this->view_data['ticket'] = Ticket::find($id);
         $this->theme_view = 'modal';
         $this->view_data['title'] = $this->lang->line('application_close');
         $this->view_data['form_action'] = 'tickets/close';
         $this->content_view = 'tickets/_close';
     }
 }