This commit is contained in:
Manish Verma
2016-12-13 18:18:25 +05:30
parent fc98add11c
commit 2d8e640e9b
2314 changed files with 97798 additions and 75664 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Http\Controllers\Agent\helpdesk;
// models
use App\Http\Controllers\Admin\MailFetch as Fetch;
use App\Http\Controllers\Controller;
use App\Model\helpdesk\Email\Emails;
use App\Model\helpdesk\Manage\Help_topic;
@@ -13,24 +12,24 @@ use App\Model\helpdesk\Settings\Ticket;
use App\Model\helpdesk\Ticket\Ticket_attachments;
use App\Model\helpdesk\Ticket\Ticket_source;
use App\Model\helpdesk\Ticket\Ticket_Thread;
// classes
use App\Model\helpdesk\Ticket\Tickets;
// classes
use App\Http\Controllers\Admin\MailFetch as Fetch;
/**
* MailController.
*
* @author Ladybird <info@ladybirdweb.com>
*/
class MailController extends Controller
{
class MailController extends Controller {
/**
* constructor
* Create a new controller instance.
*
* @param type TicketController $TicketController
*/
public function __construct(TicketWorkflowController $TicketWorkflowController)
{
public function __construct(TicketWorkflowController $TicketWorkflowController) {
$this->middleware('board');
$this->TicketWorkflowController = $TicketWorkflowController;
}
@@ -40,8 +39,7 @@ class MailController extends Controller
*
* @return type
*/
public function readmails(Emails $emails, Email $settings_email, System $system, Ticket $ticket)
{
public function readmails(Emails $emails, Email $settings_email, System $system, Ticket $ticket) {
//dd($emails);
if ($settings_email->first()->email_fetching == 1) {
if ($settings_email->first()->all_emails == 1) {
@@ -62,8 +60,7 @@ class MailController extends Controller
*
* @return type string
*/
public function separate_reply($body)
{
public function separate_reply($body) {
$body2 = explode('---Reply above this line---', $body);
$body3 = $body2[0];
@@ -71,64 +68,51 @@ class MailController extends Controller
}
/**
*
* @param object $email
*
* @return int
* @return integer
*/
public function priority($email)
{
public function priority($email) {
$priority = $email->priority;
if (!$priority) {
$priority = $this->ticketController()->getSystemDefaultPriority();
}
return $priority;
}
/**
* get department.
*
* get department
* @param object $email
*
* @return int
* @return integer
*/
public function department($email)
{
public function department($email) {
$department = $email->department;
if (!$department) {
$department = $this->ticketController()->getSystemDefaultDepartment();
}
return $department;
}
/**
* get help topic.
*
* get help topic
* @param object $email
*
* @return int
* @return integer
*/
public function helptopic($email)
{
public function helptopic($email) {
//dd($email);
$helptopic = $email->help_topic;
if (!$helptopic) {
$helptopic = $this->ticketController()->getSystemDefaultHelpTopic();
}
return $helptopic;
}
/**
* get sla.
*
* get sla
* @param object $email
*
* @return int
* @return integer
*/
public function sla($email)
{
public function sla($email) {
$helptopic = $this->helptopic($email);
$help = Help_topic::where('id', '=', $helptopic)->first();
if ($help) {
@@ -137,26 +121,21 @@ class MailController extends Controller
if (!$sla) {
$sla = $this->ticketController()->getSystemDefaultSla();
}
return $sla;
}
/**
* get ticket controller.
*
* get ticket controller
* @return \App\Http\Controllers\Agent\helpdesk\TicketController
*/
public function ticketController()
{
public function ticketController() {
$PhpMailController = new \App\Http\Controllers\Common\PhpMailController();
$NotificationController = new \App\Http\Controllers\Common\NotificationController();
$controller = new TicketController($PhpMailController, $NotificationController);
return $controller;
}
public function fetch($email)
{
public function fetch($email) {
// dd($email);
if ($email) {
$username = $email->email_address;
@@ -167,30 +146,31 @@ class MailController extends Controller
$encryption = $email->fetching_encryption;
$cert = $email->mailbox_protocol;
$server = new Fetch($host, $port, $service);
if ($encryption != null || $encryption != '') {
if ($encryption != null || $encryption != "") {
$server->setFlag($encryption);
}
$server->setFlag($cert);
$server->setAuthentication($username, $password);
$date = date('d M Y', strtotime('-1 days'));
$date = date("d M Y", strToTime("-1 days"));
$messages = $server->search("SINCE \"$date\" UNSEEN");
$this->message($messages, $email);
}
}
public function message($messages, $email)
{
foreach ($messages as $message) {
$this->getMessageContent($message, $email);
public function message($messages, $email) {
if (count($messages) > 0) {
foreach ($messages as $message) {
$this->getMessageContent($message, $email);
}
}
}
public function getMessageContent($message, $email)
{
public function getMessageContent($message, $email) {
$body = $message->getMessageBody(true);
if (!$body) {
$body = $message->getMessageBody();
}
$body = $this->separateReply($body);
$subject = $message->getSubject();
$address = $message->getAddresses('reply-to');
if (!$address) {
@@ -202,8 +182,7 @@ class MailController extends Controller
$this->workflow($address, $subject, $body, $collaborators, $attachments, $email);
}
public function workflow($address, $subject, $body, $collaborator, $attachments, $email)
{
public function workflow($address, $subject, $body, $collaborator, $attachments, $email) {
$fromaddress = checkArray('address', $address[0]);
$fromname = checkArray('name', $address[0]);
$helptopic = $this->helptopic($email);
@@ -224,39 +203,49 @@ class MailController extends Controller
}
}
public function updateThread($ticket_number, $body, $attachments)
{
public function updateThread($ticket_number, $body, $attachments) {
$ticket_table = Tickets::where('ticket_number', '=', $ticket_number)->first();
$thread_id = Ticket_Thread::where('ticket_id', '=', $ticket_table->id)->max('id');
$thread = Ticket_Thread::where('id', '=', $thread_id)->first();
$thread->body = $this->separate_reply($body);
$thread->save();
$this->saveAttachments($thread->id, $attachments);
\Log::info('Ticket has created : ', ['id' => $thread->ticket_id]);
if (file_exists(app_path('/FaveoStorage/Controllers/StorageController.php'))) {
try {
$storage = new \App\FaveoStorage\Controllers\StorageController();
$storage->saveAttachments($thread->id, $attachments);
} catch (\Exception $ex) {
loging('attachment', $ex->getMessage());
}
} else {
loging('attachment', 'FaveoStorage not installed');
}
\Log::info("Ticket has created : ", ['id' => $thread->ticket_id]);
}
public function saveAttachments($thread_id, $attachments = [])
{
public function saveAttachments($thread_id, $attachments = []) {
if (is_array($attachments) && count($attachments) > 0) {
foreach ($attachments as $attachment) {
$structure = $attachment->getStructure();
$disposition = 'ATTACHMENT';
if (isset($structure->disposition)) {
$disposition = $structure->disposition;
}
$filename = str_random(16).'-'.$attachment->getFileName();
$filename = str_random(16) . '-' . $attachment->getFileName();
$type = $attachment->getMimeType();
$size = $attachment->getSize();
$data = $attachment->getData();
//$path = storage_path('/');
//$attachment->saveToDirectory($path);
$this->manageAttachment($data, $filename, $type, $size, $disposition, $thread_id);
$this->updateBody($attachment, $thread_id, $filename);
}
}
}
public function manageAttachment($data, $filename, $type, $size, $disposition, $thread_id)
{
public function manageAttachment($data, $filename, $type, $size, $disposition, $thread_id) {
$upload = new Ticket_attachments();
$upload->file = $data;
$upload->thread_id = $thread_id;
@@ -269,30 +258,25 @@ class MailController extends Controller
}
}
public function updateBody($attachment, $thread_id, $filename)
{
public function updateBody($attachment, $thread_id, $filename) {
$structure = $attachment->getStructure();
$disposition = 'ATTACHMENT';
if (isset($structure->disposition)) {
$disposition = $structure->disposition;
}
if ($disposition == 'INLINE') {
$id = str_replace('>', '', str_replace('<', '', $structure->id));
if ($disposition == 'INLINE' || $disposition == 'inline') {
$id = str_replace(">", "", str_replace("<", "", $structure->id));
//$filename = $attachment->getFileName();
$path = public_path('attachments');
$filepath = asset('attachments/'.$filename);
$threads = new Ticket_Thread();
$thread = $threads->find($thread_id);
$body = $thread->body;
$body = str_replace('cid:'.$id, $filename, $body);
$body = str_replace('cid:' . $id, $filename, $body);
$thread->body = $body;
$thread->save();
$attachment->saveToDirectory($path);
}
}
public function collaburators($message, $email)
{
public function collaburators($message, $email) {
$this_address = $email->email_address;
$collaborator_cc = $message->getAddresses('cc');
//dd($collaborator_cc);
@@ -327,7 +311,6 @@ class MailController extends Controller
if (array_key_exists($this_address, $array)) {
unset($array[$this_address]);
}
return $array;
}
@@ -338,21 +321,35 @@ class MailController extends Controller
*
* @return type file
*/
public function get_data($id)
{
public function get_data($id) {
$attachment = \App\Model\helpdesk\Ticket\Ticket_attachments::where('id', '=', $id)->first();
if (mime($attachment->type) == true) {
echo "<img src=data:$attachment->type;base64,".$attachment->file.'>';
echo "<img src=data:$attachment->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-Disposition', 'attachment; filename=' . $attachment->name)
->header('Content-Transfer-Encoding', 'binary');
}
}
/**
* separate reply.
*
* @param type $body
*
* @return type string
*/
public function separateReply($body) {
$body2 = explode('---Reply above this line---', $body);
if (is_array($body2) && array_key_exists(0, $body2)) {
$body = $body2[0];
}
return $body;
}
}