From 0bc1e99fab73c548a8c1bd951ce77076affaf749 Mon Sep 17 00:00:00 2001 From: Vijay Sebastian Date: Wed, 2 Nov 2016 18:45:09 +0530 Subject: [PATCH] Unread criteria, iframe reload issue, attachment issue and replace example email with username --- .gitignore | 2 + .../Admin/helpdesk/EmailsController.php | 4 +- .../Agent/helpdesk/MailController.php | 37 +++-- app/Model/helpdesk/Ticket/Ticket_Thread.php | 2 +- .../helpdesk/Ticket/Ticket_attachments.php | 17 +++ .../agent/helpdesk/ticket/timeline.blade.php | 136 ++++-------------- 6 files changed, 69 insertions(+), 129 deletions(-) diff --git a/.gitignore b/.gitignore index c9d24e72e..75847b355 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ Homestead.json /public/uploads /public/photos/ /app/FaveoJob + +.env diff --git a/app/Http/Controllers/Admin/helpdesk/EmailsController.php b/app/Http/Controllers/Admin/helpdesk/EmailsController.php index 7b2f65df9..3563a808a 100644 --- a/app/Http/Controllers/Admin/helpdesk/EmailsController.php +++ b/app/Http/Controllers/Admin/helpdesk/EmailsController.php @@ -252,12 +252,10 @@ class EmailsController extends Controller $this->emailService($driver, $service_request); $this->setMailConfig($driver, $username, $name, $password, $enc, $host, $port); $controller = new \App\Http\Controllers\Common\PhpMailController(); - $to = 'example@ladybirdweb.com'; - $toname = 'test'; $subject = 'test'; $data = 'test'; //dd(\Config::get('mail'),\Config::get('services')); - $send = $controller->laravelMail($to, $toname, $subject, $data, [], []); + $send = $controller->laravelMail($username, $name, $subject, $data, [], []); return $send; } diff --git a/app/Http/Controllers/Agent/helpdesk/MailController.php b/app/Http/Controllers/Agent/helpdesk/MailController.php index 727367713..4138f351f 100644 --- a/app/Http/Controllers/Agent/helpdesk/MailController.php +++ b/app/Http/Controllers/Agent/helpdesk/MailController.php @@ -172,7 +172,8 @@ class MailController extends Controller } $server->setFlag($cert); $server->setAuthentication($username, $password); - $messages = $server->search('UNSEEN', 10); + $date = date("d M Y", strToTime("-1 days")); + $messages = $server->search("SINCE \"$date\" UNSEEN"); $this->message($messages, $email); } } @@ -257,7 +258,7 @@ class MailController extends Controller public function manageAttachment($data, $filename, $type, $size, $disposition, $thread_id) { $upload = new Ticket_attachments(); - $upload->file = $data; + $upload->file = base64_encode($data); $upload->thread_id = $thread_id; $upload->name = $filename; $upload->type = $type; @@ -337,24 +338,20 @@ class MailController extends Controller * * @return type file */ - public function get_data($id) - { - $attachments = \App\Model\helpdesk\Ticket\Ticket_attachments::where('id', '=', $id)->get(); - foreach ($attachments as $attachment) { - header('Content-type: application/'.$attachment->type.''); - header('Content-Disposition: inline; filename='.$attachment->name.''); - header('Content-Transfer-Encoding: binary'); - $headers = [ - 'Content-type: application/'.$attachment->type.'', - 'Content-Disposition: inline; filename='.$attachment->name.'', - 'Content-Transfer-Encoding: binary', - ]; - $file = $attachment->file; - echo $file; -// return response($file) -// ->header('Content-Type', $attachment->type) -// ->header('Content-Disposition', 'inline; filename='.$attachment->name.'') -// ->header('Content-Transfer-Encoding', 'binary'); + public function get_data($id) { + $attachment = \App\Model\helpdesk\Ticket\Ticket_attachments::where('id', '=', $id)->first(); + if (mime($attachment->type) == true) { + echo "type;base64," . $attachment->file . ">"; + } else { + $file = base64_decode($attachment->file); + return response($file) + ->header('Cache-Control', 'no-cache private') + ->header('Content-Description', 'File Transfer') + ->header('Content-Type', $attachment->type) + ->header('Content-length', strlen($file)) + ->header('Content-Disposition', 'attachment; filename=' . $attachment->name) + ->header('Content-Transfer-Encoding', 'binary'); } } + } diff --git a/app/Model/helpdesk/Ticket/Ticket_Thread.php b/app/Model/helpdesk/Ticket/Ticket_Thread.php index e822dc3df..54f4c219e 100644 --- a/app/Model/helpdesk/Ticket/Ticket_Thread.php +++ b/app/Model/helpdesk/Ticket/Ticket_Thread.php @@ -118,7 +118,7 @@ class Ticket_Thread extends Model if ($this->attach()->where('poster', 'INLINE')->get()->count() > 0) { $search = $this->attach()->where('poster', 'INLINE')->lists('name')->toArray(); foreach ($this->attach()->where('poster', 'INLINE')->get() as $key => $attach) { - $replace[$key] = "data:$attach->type;base64,".base64_encode($attach->file); + $replace[$key] = "data:$attach->type;base64,".$attach->file; } $body = str_replace($search, $replace, $body); } diff --git a/app/Model/helpdesk/Ticket/Ticket_attachments.php b/app/Model/helpdesk/Ticket/Ticket_attachments.php index 33de6ad66..e2addb4a8 100644 --- a/app/Model/helpdesk/Ticket/Ticket_attachments.php +++ b/app/Model/helpdesk/Ticket/Ticket_attachments.php @@ -10,4 +10,21 @@ class Ticket_attachments extends Model protected $fillable = [ 'id', 'thread_id', 'name', 'size', 'type', 'file', 'data', 'poster', 'updated_at', 'created_at', ]; + + public function getFile() { + $size = $this->size; + $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); + $power = $size > 0 ? floor(log($size, 1024)) : 0; + $value = number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power]; + if ($this->poster == 'ATTACHMENT') { + if (mime($this->type) == true) { + $var = ''; + return '
  • ' . $var . '
    ' . $this->name . '

    ' . $value . '

  • '; + } else { + //$var = ''; + $var = '' . strtoupper($this->type) . '
    ' . $this->name . '

    ' . $value . '

    '; + return '
  • ' . $var . '
  • '; + } + } + } } diff --git a/resources/views/themes/default1/agent/helpdesk/ticket/timeline.blade.php b/resources/views/themes/default1/agent/helpdesk/ticket/timeline.blade.php index 4b34db387..aefc61f5d 100644 --- a/resources/views/themes/default1/agent/helpdesk/ticket/timeline.blade.php +++ b/resources/views/themes/default1/agent/helpdesk/ticket/timeline.blade.php @@ -566,65 +566,7 @@ if ($thread->title != "") { id)->first(); - if ($attachment == null) { - $body = $conversation->body; - $body = $conversation->thread($body); - } else { - // dd($attachment->file); - // print $attachment->file; - // header("Content-type: image/jpeg"); - // echo " "; - $body = $conversation->body; - $body = $conversation->thread($body); - $attachments = App\Model\helpdesk\Ticket\Ticket_attachments::where('thread_id', '=', $conversation->id)->orderBy('id', 'DESC')->get(); - // $i = 0; - foreach ($attachments as $attachment) { - // $i++; - if (mime($attachment->type)==true) { - $image = @imagecreatefromstring($attachment->file); - ob_start(); - imagejpeg($image, null, 80); - $data = ob_get_contents(); - ob_end_clean(); - $var = ''; - // echo $var; - // echo $attachment->name; - // $body = explode($attachment->name, $body); - $body = str_replace($attachment->name, "data:image/" . $attachment->type . ";base64," . base64_encode($data), $body); - - $string = $body; - $start = ""; - $end = ""; - if (strpos($string, $start) == false || strpos($string, $start) == false) { - - } else { - $ini = strpos($string, $start); - $ini += strlen($start); - $len = strpos($string, $end, $ini) - $ini; - $parsed = substr($string, $ini, $len); - $body2 = $parsed; - $body = str_replace($body2, " ", $body); - } - } else { - } - } - // echo $body; - // $body = explode($attachment->file, $body); - // $body = $body[0]; - } - $string = $body; - $start = ""; - $end = ""; - if (strpos($string, $start) == false || strpos($string, $start) == false) { - } else { - $ini = strpos($string, $start); - $ini += strlen($start); - $len = strpos($string, $end, $ini) - $ini; - $parsed = substr($string, $ini, $len); - $body2 = $parsed; - $body = str_replace($body2, " ", $body); - } + if($conversation->user_id != null) { if ($conversation->is_internal) { $color = '#A19CFF'; @@ -713,7 +655,7 @@ if ($thread->title != "") { $('#loader_frame{{$conversation->id}}')[0].contentDocument.body.innerHTML = '{!!$conversation->purify()!!}'; @else - {!! $body !!} + {!! $conversation->body !!} @endif @if($conversation->id == $ij->id) @@ -755,29 +697,11 @@ if ($thread->title != "") { } ?> @@ -1891,28 +1815,30 @@ if ($thread->title != "") { } if (response == 1) { - $("#refresh1").load("../thread/{{$tickets->id}} #refresh1"); - var message = "{{ Lang::get('lang.you_have_successfully_replied_to_your_ticket') }}"; - $("#alert21").show(); - $('#message-success2').html(message); - setInterval(function(){$("#alert21").hide(); }, 4000); - $("#newtextarea").empty(); - var div = document.getElementById('newtextarea'); - div.innerHTML = div.innerHTML + ''; - $("#newtextarea1").empty(); - var div1 = document.getElementById('newtextarea1'); - div1.innerHTML = div1.innerHTML + ''; - var wysihtml5Editor = $('textarea').wysihtml5().data("wysihtml5").editor; - setInterval(function(){ - var head= document.getElementsByTagName('head')[0]; - var script= document.createElement('script'); - script.type= 'text/javascript'; - script.src= '{{asset("lb-faveo/js/jquery.rating.pack.js")}}'; - head.appendChild(script); -// $('.rating-cancel').hide(); -// $(".star-rating-control").attr("disabled", "disabled").off('hover'); -// $(".star-rating-control").addClass("disabled") - }, 4000); + location.reload(); +// $("#refresh1").load("../thread/{{$tickets->id}} #refresh1"); +// var message = "{{ Lang::get('lang.you_have_successfully_replied_to_your_ticket') }}"; +// $("#alert21").show(); +// $('#message-success2').html(message); +// setInterval(function(){$("#alert21").hide(); }, 4000); +// $("#newtextarea").empty(); +// var div = document.getElementById('newtextarea'); +// div.innerHTML = div.innerHTML + ''; +// $("#newtextarea1").empty(); +// var div1 = document.getElementById('newtextarea1'); +// div1.innerHTML = div1.innerHTML + ''; +// var wysihtml5Editor = $('textarea').wysihtml5().data("wysihtml5").editor; +// setInterval(function(){ +// var head= document.getElementsByTagName('head')[0]; +// var script= document.createElement('script'); +// script.type= 'text/javascript'; +// script.src= '{{asset("lb-faveo/js/jquery.rating.pack.js")}}'; +// head.appendChild(script); +//// $('.rating-cancel').hide(); +//// $(".star-rating-control").attr("disabled", "disabled").off('hover'); +//// $(".star-rating-control").addClass("disabled") +// }, 4000); + } else { // alert('fail'); // $( "#dismis4" ).trigger( "click" );