示例#1
1
 /**
  * Reademails
  * @return type
  */
 public function readmails(Emails $emails, Email $settings_email, System $system)
 {
     $path_url = $system->first()->url;
     if ($settings_email->first()->email_fetching == 1) {
         if ($settings_email->first()->all_emails == 1) {
             $helptopic = $this->TicketController->default_helptopic();
             $sla = $this->TicketController->default_sla();
             $email = $emails->get();
             foreach ($email as $e_mail) {
                 $dept = $e_mail->department;
                 $host = $e_mail->fetching_host;
                 $port = $e_mail->fetching_port;
                 $protocol = $e_mail->mailbox_protocol;
                 $imap_config = '{' . $host . ':' . $port . $protocol . '}INBOX';
                 $password = Crypt::decrypt($e_mail->password);
                 $mailbox = new ImapMailbox($imap_config, $e_mail->user_name, $password, __DIR__);
                 $mails = array();
                 $mailsIds = $mailbox->searchMailBox('SINCE ' . date('d-M-Y', strtotime("-1 day")));
                 if (!$mailsIds) {
                     die('Mailbox is empty');
                 }
                 // dd($mailsIds);
                 foreach ($mailsIds as $mailId) {
                     $overview = $mailbox->get_overview($mailId);
                     $var = $overview[0]->seen ? 'read' : 'unread';
                     if ($var == 'unread') {
                         $mail = $mailbox->getMail($mailId);
                         if ($settings_email->email_collaborator == 1) {
                             $collaborator = $mail->cc;
                         } else {
                             $collaborator = null;
                         }
                         $body = $mail->textHtml;
                         // dd($mailId);
                         if ($body == null) {
                             $body = $mailbox->backup_getmail($mailId);
                             $body = str_replace('\\r\\n', '<br/>', $body);
                             // var_dump($body);
                         }
                         // dd($body);
                         $date = $mail->date;
                         $datetime = $overview[0]->date;
                         $date_time = explode(" ", $datetime);
                         $date = $date_time[1] . "-" . $date_time[2] . "-" . $date_time[3] . " " . $date_time[4];
                         $date = date('Y-m-d H:i:s', strtotime($date));
                         if (isset($mail->subject)) {
                             $subject = $mail->subject;
                         } else {
                             $subject = "No Subject";
                         }
                         $fromname = $mail->fromName;
                         $fromaddress = $mail->fromAddress;
                         $source = "2";
                         $phone = "";
                         $priority = '1';
                         $assign = "";
                         $form_data = null;
                         if ($this->TicketController->create_user($fromaddress, $fromname, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $form_data) == true) {
                             $thread_id = Ticket_Thread::whereRaw('id = (select max(`id`) from ticket_thread)')->first();
                             $thread_id = $thread_id->id;
                             foreach ($mail->getAttachments() as $attachment) {
                                 $support = "support";
                                 // echo $_SERVER['DOCUMENT_ROOT'];
                                 $dir_img_paths = __DIR__;
                                 $dir_img_path = explode('/code', $dir_img_paths);
                                 $filepath = explode('../../../../../../public/', $attachment->filePath);
                                 // dd($filepath);
                                 // $path = $dir_img_path[0]."/public/".$filepath[1];
                                 $path = public_path() . '/' . $filepath[1];
                                 // dd($path);
                                 $filesize = filesize($path);
                                 $file_data = file_get_contents($path);
                                 $ext = pathinfo($attachment->filePath, PATHINFO_EXTENSION);
                                 $imageid = $attachment->id;
                                 $string = str_replace('-', '', $attachment->name);
                                 $filename = explode('src', $attachment->filePath);
                                 $filename = str_replace('\\', '', $filename);
                                 $body = str_replace("cid:" . $imageid, $filepath[1], $body);
                                 $pos = strpos($body, $filepath[1]);
                                 if ($pos == false) {
                                     if ($settings_email->first()->attachment == 1) {
                                         $upload = new Ticket_attachments();
                                         $upload->file = $file_data;
                                         $upload->thread_id = $thread_id;
                                         $upload->name = $filepath[1];
                                         $upload->type = $ext;
                                         $upload->size = $filesize;
                                         $upload->poster = "ATTACHMENT";
                                         $upload->save();
                                     }
                                 } else {
                                     $upload = new Ticket_attachments();
                                     $upload->file = $file_data;
                                     $upload->thread_id = $thread_id;
                                     $upload->name = $filepath[1];
                                     $upload->type = $ext;
                                     $upload->size = $filesize;
                                     $upload->poster = "INLINE";
                                     $upload->save();
                                 }
                                 unlink($path);
                             }
                             $body = Encoding::fixUTF8($body);
                             $thread = Ticket_Thread::where('id', '=', $thread_id)->first();
                             $thread->body = $this->separate_reply($body);
                             $thread->save();
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * reply
  * @param type $value 
  * @return type view
  */
 public function reply($id, Request $request)
 {
     $comment = $request->input('comment');
     if ($comment != null) {
         $tickets = Tickets::where('id', '=', $id)->first();
         $tickets->closed_at = null;
         $tickets->closed = 0;
         $tickets->reopened_at = date('Y-m-d H:i:s');
         $tickets->reopened = 1;
         $threads = new Ticket_Thread();
         $threads->user_id = Auth::user()->id;
         $threads->ticket_id = $tickets->id;
         $threads->poster = "client";
         $threads->body = $comment;
         try {
             $threads->save();
             $tickets->save();
             return \Redirect::back()->with('success1', 'Successfully replied');
         } catch (Exception $e) {
             return \Redirect::back()->with('fails1', $e->errorInfo[2]);
         }
     } else {
         return \Redirect::back()->with('fails1', 'Please fill some data!');
     }
 }
 /**
  * reply
  * @param type $value 
  * @return type view
  */
 public function reply($id, Request $request)
 {
     $comment = $request->input('comment');
     if ($comment != null) {
         $tickets = Tickets::where('id', '=', $id)->first();
         $threads = new Ticket_Thread();
         $threads->user_id = Auth::user()->id;
         $threads->ticket_id = $tickets->id;
         $threads->poster = "client";
         $threads->body = $comment;
         $threads->save();
         return \Redirect::back()->with('success1', 'Successfully replied');
     } else {
         return \Redirect::back()->with('fails1', 'Please fill some data!');
     }
 }
 public function get_unassigned()
 {
     if (Auth::user()->role == "admin") {
         // $tickets = Tickets::where('status', '=', 1)->where('assigned_to', '=', Auth::user()->id)->get();
         $tickets = Tickets::where('assigned_to', '=', null)->where('status', '1')->get();
     } else {
         $dept = Department::where('id', '=', Auth::user()->primary_dpt)->first();
         $tickets = Tickets::where('assigned_to', '=', null)->where('dept_id', '=', $dept->id)->get();
         // $dept = Department::where('name','=',Auth::user()->primary_dpt)->first();
         // $tickets = Tickets::where('status', '=', 1)->where('assigned_to', '=', Auth::user()->id)->get();
     }
     return \Datatable::collection(new Collection($tickets))->addColumn('id', function ($ticket) {
         return "<input type='checkbox' name='select_all[]' class='icheckbox_flat-blue' value='" . $ticket->id . "'></input>";
     })->addColumn('subject', function ($ticket) {
         $subject = DB::table('ticket_thread')->select('title')->where('ticket_id', "=", $ticket->id)->first();
         $string = $subject->title;
         if (strlen($string) > 20) {
             $stringCut = substr($string, 0, 30);
             $string = substr($stringCut, 0, strrpos($stringCut, ' ')) . ' ...';
         }
         //collabrations
         $collaborators = DB::table('ticket_collaborator')->where('ticket_id', '=', $ticket->id)->get();
         $collab = count($collaborators);
         if ($collab > 0) {
             $collabString = '&nbsp;<i class="fa fa-users"></i>';
         } else {
             $collabString = null;
         }
         $threads = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first();
         //Ticket_Thread::where('ticket_id', '=', $ticket->id)->get();
         $count = count($threads);
         $attachment = Ticket_attachments::where('thread_id', '=', $threads->id)->get();
         $attachCount = count($attachment);
         if ($attachCount > 0) {
             $attachString = '&nbsp;<i class="fa fa-paperclip"></i>';
         } else {
             $attachString = "";
         }
         //return $threads->id;
         return "<a href='" . route('ticket.thread', [$ticket->id]) . "' title='" . $subject->title . "'>" . $string . "&nbsp;<span style='color:green'>(" . $count . ")<i class='fa fa-comment'></i></span></a>" . $collabString . $attachString;
     })->addColumn('ticket_number', function ($ticket) {
         return "<a href='" . route('ticket.thread', [$ticket->id]) . "' title='" . $ticket->ticket_number . "'>#" . $ticket->ticket_number . "</a>";
     })->addColumn('priority', function ($ticket) {
         $priority = DB::table('ticket_priority')->select('priority', 'priority_color')->where('priority_id', "=", $ticket->priority_id)->first();
         return '<span class="btn btn-' . $priority->priority_color . ' btn-xs">' . $priority->priority . '</span>';
         //return "loda";
     })->addColumn('from', function ($ticket) {
         $from = DB::table('users')->select('user_name')->where('id', "=", $ticket->user_id)->first();
         return "<span style='color:#508983'>" . $from->user_name . "</span>";
     })->addColumn('Last Replier', function ($ticket) {
         $TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->where('is_internal', '!=', 1)->max('id');
         $TicketDatarow = Ticket_Thread::where('id', '=', $TicketData)->first();
         $LastResponse = User::where('id', '=', $TicketDatarow->user_id)->first();
         if ($LastResponse->role == "user") {
             $rep = "#F39C12";
             $username = $LastResponse->user_name;
         } else {
             $rep = "#000";
             $username = $LastResponse->first_name . " " . $LastResponse->last_name;
             if ($LastResponse->first_name == null || $LastResponse->last_name == null) {
                 $username = $LastResponse->user_name;
             }
         }
         return "<span style='color:" . $rep . "'>" . $username . "</span>";
     })->addColumn('assigned_to', function ($ticket) {
         if ($ticket->assigned_to == null) {
             return "<span style='color:red'>Unassigned</span>";
         } else {
             $assign = DB::table("users")->where('id', "=", $ticket->assigned_to)->first();
             return "<span style='color:green'>" . $assign->first_name . " " . $assign->last_name . "</span>";
         }
     })->addColumn('Last', function ($ticket) {
         $TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
         $TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
         return date('d F Y, H:i:s', strtotime($TicketDatarow->updated_at));
     })->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')->orderColumns('subject', 'from', 'assigned_to', 'Last Replier', 'ticket_number', 'priority', 'Last')->make();
 }
 /**
  * Ticekt reply
  * @param type Ticket_Thread $thread
  * @param type TicketRequest $request
  * @return type Response
  */
 public function reply(Ticket_Thread $thread, TicketRequest $request)
 {
     $thread->ticket_id = $request->input('ticket_ID');
     $thread->title = $request->input('To');
     $thread->user_id = Auth::user()->id;
     $thread->body = $request->input('ReplyContent');
     $thread->poster = 'user';
     $thread->save();
     $ticket_id = $request->input('ticket_ID');
     $tickets = Tickets::where('id', '=', $ticket_id)->first();
     $thread = Ticket_Thread::where('ticket_id', '=', $ticket_id)->first();
     return Redirect("thread/" . $ticket_id);
 }
 /**
  * Function to surrender a ticket
  * @param type $id
  * @return type bool
  */
 public function surrender($id)
 {
     $ticket = Tickets::where('id', '=', $id)->first();
     // if($ticket->assigned_to == Auth::user()->id)
     // {
     $InternalContent = Auth::user()->first_name . " " . Auth::user()->last_name . " has Surrendered the assigned Ticket";
     $thread = Ticket_Thread::where('ticket_id', '=', $id)->first();
     $NewThread = new Ticket_Thread();
     $NewThread->ticket_id = $thread->ticket_id;
     $NewThread->user_id = Auth::user()->id;
     $NewThread->is_internal = 1;
     $NewThread->poster = Auth::user()->role;
     $NewThread->title = $thread->title;
     $NewThread->body = $InternalContent;
     $NewThread->save();
     // }
     $ticket->assigned_to = 0;
     $ticket->save();
     return 1;
 }
 /**
  * Function to delete ticket
  * @param type $id
  * @param type Tickets $ticket
  * @return type string
  */
 public function delete($ids, $ticket)
 {
     try {
         foreach ($ids as $id) {
             $ticket_delete = $ticket->where('id', '=', $id)->first();
             if ($ticket_delete) {
                 if ($ticket_delete->status == 5) {
                     $ticket_delete->delete();
                     $ticket_threads = Ticket_Thread::where('ticket_id', '=', $id)->get();
                     if ($ticket_threads) {
                         foreach ($ticket_threads as $ticket_thread) {
                             if ($ticket_thread) {
                                 $ticket_thread->delete();
                             }
                         }
                     }
                     $ticket_attachments = Ticket_attachments::where('thread_id', '=', $id)->get();
                     if ($ticket_attachments) {
                         foreach ($ticket_attachments as $ticket_attachment) {
                             if ($ticket_attachment) {
                                 $ticket_attachment->delete();
                             }
                         }
                     }
                 } else {
                     $ticket_delete->is_deleted = 0;
                     $ticket_delete->status = 5;
                     $ticket_delete->save();
                     $ticket_status_message = Ticket_Status::where('id', '=', $ticket_delete->status)->first();
                     $thread = new Ticket_Thread();
                     $thread->ticket_id = $ticket_delete->id;
                     $thread->user_id = Auth::user()->id;
                     $thread->is_internal = 1;
                     $thread->body = $ticket_status_message->message . " " . Auth::user()->first_name . " " . Auth::user()->last_name;
                     $thread->save();
                 }
             } else {
                 return "ticket not found";
             }
         }
         return "your tickets has been deleted";
     } catch (\Exception $e) {
         return $e->getMessage();
     }
 }