update 1.0.8.0

Commits for version update
This commit is contained in:
Manish Verma
2016-10-17 12:02:27 +05:30
parent dec927987b
commit 76e85db070
9674 changed files with 495757 additions and 58922 deletions

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Controllers\Agent\helpdesk;
use PhpImap\Mailbox;
class ImapMail extends Mailbox
{
public function get_overview($mailId)
{
$overview = imap_fetch_overview($this->getImapStream(), $mailId, FT_UID);
return $overview;
}
/**
* This function uses imap_search() to perform a search on the mailbox currently opened in the given IMAP stream.
* For example, to match all unanswered mails sent by Mom, you'd use: "UNANSWERED FROM mom".
*
* @param string $criteria See http://php.net/imap_search for a complete list of available criteria
*
* @return array mailsIds (or empty array)
*/
public function searchMailbox($criteria = 'ALL')
{
//dd($this->getImapStream());
$mailsIds = imap_search($this->getImapStream(), $criteria, SE_UID);
//dd($mailsIds);
return $mailsIds ? $mailsIds : [];
}
}

View File

@@ -2,9 +2,8 @@
namespace App\Http\Controllers\Agent\helpdesk;
// controllers
use App;
// 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;
@@ -14,13 +13,8 @@ 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;
use App\Model\helpdesk\Ticket\Tickets;
// classes
use App\Model\helpdesk\Utility\MailboxProtocol;
use Crypt;
use File;
use ForceUTF8\Encoding;
use PhpImap\Mailbox as ImapMailbox;
use App\Model\helpdesk\Ticket\Tickets;
/**
* MailController.
@@ -48,200 +42,13 @@ class MailController extends Controller
*/
public function readmails(Emails $emails, Email $settings_email, System $system, Ticket $ticket)
{
// $path_url = $system->first()->url;
//dd($emails);
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) {
if ($e_mail->fetching_status == 1) {
$auto_response = $e_mail->auto_response;
$priority = $e_mail->priority;
$dept = $e_mail->department;
$helptopic = $e_mail->help_topic;
if ($priority == null) {
$priority = $ticket->first()->priority;
}
if ($dept == null) {
$dept = $system->first()->department;
}
if ($helptopic == null) {
$helptopic = $ticket->first()->help_topic;
}
$get_helptopic = Help_topic::where('id', '=', $helptopic)->first();
$sla = $get_helptopic->sla_plan;
$host = $e_mail->fetching_host;
$port = $e_mail->fetching_port;
if ($e_mail->mailbox_protocol) {
$protocol_value = $e_mail->mailbox_protocol;
$get_mailboxprotocol = MailboxProtocol::where('id', '=', $protocol_value)->first();
$protocol = $get_mailboxprotocol->value;
} elseif ($e_mail->fetching_encryption == '/none') {
$fetching_encryption2 = '/novalidate-cert';
$protocol = $fetching_encryption2;
} else {
if ($e_mail->fetching_protocol) {
$fetching_protocol = '/'.$e_mail->fetching_protocol;
} else {
$fetching_protocol = '';
}
if ($e_mail->fetching_encryption) {
$fetching_encryption = $e_mail->fetching_encryption;
} else {
$fetching_encryption = '';
}
$protocol = $fetching_protocol.$fetching_encryption;
}
$imap_config = '{'.$host.':'.$port.$protocol.'}INBOX';
$password = Crypt::decrypt($e_mail->password);
try {
$mailbox = new ImapMailbox($imap_config, $e_mail->email_address, $password, __DIR__);
} catch (\PhpImap\Exception $e) {
echo 'Connection error';
}
$mails = [];
try {
$mailsIds = $mailbox->searchMailBox('SINCE '.date('d-M-Y', strtotime('-1 day')));
} catch (\PhpImap\Exception $e) {
echo 'Connection error';
}
if (!$mailsIds) {
die('Mailbox is empty');
}
foreach ($mailsIds as $mailId) {
try {
$overview = $mailbox->get_overview($mailId);
} catch (Exception $e) {
return \Lang::get('lang.unable_to_fetch_emails');
}
$var = $overview[0]->seen ? 'read' : 'unread';
if ($var == 'unread') {
$mail = $mailbox->getMail($mailId);
try {
$mail = $mailbox->getMail($mailId);
} catch (\PhpImap\Exception $e) {
echo 'Connection error';
}
if ($settings_email->first()->email_collaborator == 1) {
$collaborator = $mail->cc;
} else {
$collaborator = null;
}
$body = $mail->textHtml;
if ($body != null) {
$body = self::trimTableTag($body);
}
// if mail body has no messages fetch backup mail
if ($body == null) {
$body = $mail->textPlain;
}
if ($body == null) {
$attach = $mail->getAttachments();
if (is_array($attach)) {
if (array_key_exists('html-body', $attach)) {
$path = $attach['html-body']->filePath;
}
if ($path == null) {
if (array_key_exists('text-body', $attach)) {
$path = $attach['text-body']->filePath;
}
}
if ($path) {
$body = file_get_contents($path);
}
if ($body) {
$body = self::trimTableTag($body);
} else {
$body = '';
}
}
}
// if ($body == null) {
// $body = $mailbox->backup_getmail($mailId);
// $body = str_replace('\r\n', '<br/>', $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';
}
$to = $mail->to;
$fromname = $mail->fromName;
$fromaddress = $mail->fromAddress;
$ticket_source = Ticket_source::where('name', '=', 'email')->first();
$source = $ticket_source->id;
$phone = '';
$phonecode = '';
$mobile_number = '';
$assign = $get_helptopic->auto_assign;
$form_data = null;
$team_assign = null;
$ticket_status = null;
$result = $this->TicketWorkflowController->workflow($fromaddress, $fromname, $to, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response, $mail->getAttachments());
if ($result[1] == true) {
$ticket_table = Tickets::where('ticket_number', '=', $result[0])->first();
$thread_id = Ticket_Thread::where('ticket_id', '=', $ticket_table->id)->max('id');
$thread_id = $thread_id;
foreach ($mail->getAttachments() as $attachment) {
$support = 'support';
$dir_img_paths = __DIR__;
$dir_img_path = explode('/code', $dir_img_paths);
$filepath = explode('..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'public', $attachment->filePath);
if ($filepath[1]) {
$path = public_path().$filepath[1];
$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 = $body;
$thread = Ticket_Thread::where('id', '=', $thread_id)->first();
$thread->body = $this->separate_reply($body);
$thread->save();
}
}
}
if ($email->count() > 0) {
foreach ($email as $e_mail) {
$this->fetch($e_mail);
}
}
}
@@ -264,40 +71,263 @@ class MailController extends Controller
}
/**
* Decode Imap text.
* @param object $email
*
* @param type $str
*
* @return type string
* @return int
*/
public function decode_imap_text($str)
public function priority($email)
{
$result = '';
$decode_header = imap_mime_header_decode($str);
foreach ($decode_header as $obj) {
$result .= htmlspecialchars(rtrim($obj->text, "\t"));
$priority = $email->priority;
if (!$priority) {
$priority = $this->ticketController()->getSystemDefaultPriority();
}
return $result;
return $priority;
}
/**
* fetch_attachments.
* get department.
*
* @return type
* @param object $email
*
* @return int
*/
public function fetch_attachments()
public function department($email)
{
$uploads = Upload::all();
foreach ($uploads as $attachment) {
$image = @imagecreatefromstring($attachment->file);
ob_start();
imagejpeg($image, null, 80);
$data = ob_get_contents();
ob_end_clean();
$var = '<a href="" target="_blank"><img src="data:image/jpg;base64,'.base64_encode($data).'"/></a>';
echo '<br/><span class="mailbox-attachment-icon has-img">'.$var.'</span>';
$department = $email->department;
if (!$department) {
$department = $this->ticketController()->getSystemDefaultDepartment();
}
return $department;
}
/**
* get help topic.
*
* @param object $email
*
* @return int
*/
public function helptopic($email)
{
//dd($email);
$helptopic = $email->help_topic;
if (!$helptopic) {
$helptopic = $this->ticketController()->getSystemDefaultHelpTopic();
}
return $helptopic;
}
/**
* get sla.
*
* @param object $email
*
* @return int
*/
public function sla($email)
{
$helptopic = $this->helptopic($email);
$help = Help_topic::where('id', '=', $helptopic)->first();
if ($help) {
$sla = $help->sla_plan;
}
if (!$sla) {
$sla = $this->ticketController()->getSystemDefaultSla();
}
return $sla;
}
/**
* get ticket controller.
*
* @return \App\Http\Controllers\Agent\helpdesk\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)
{
// dd($email);
if ($email) {
$username = $email->email_address;
$password = $email->password;
$service = $email->fetching_protocol;
$host = $email->fetching_host;
$port = $email->fetching_port;
$encryption = $email->fetching_encryption;
$cert = $email->mailbox_protocol;
$server = new Fetch($host, $port, $service);
if ($encryption != null || $encryption != '') {
$server->setFlag($encryption);
}
$server->setFlag($cert);
$server->setAuthentication($username, $password);
$messages = $server->search('UNSEEN', 10);
$this->message($messages, $email);
}
}
public function message($messages, $email)
{
foreach ($messages as $message) {
$this->getMessageContent($message, $email);
}
}
public function getMessageContent($message, $email)
{
$body = $message->getMessageBody(true);
if (!$body) {
$body = $message->getMessageBody();
}
$subject = $message->getSubject();
$address = $message->getAddresses('reply-to');
if (!$address) {
$address = $message->getAddresses('from');
}
$collaborators = $this->collaburators($message, $email);
$attachments = $message->getAttachments();
//dd(['body' => $body, 'subject' => $subject, 'address' => $address, 'cc' => $collaborator, 'attachments' => $attachments]);
$this->workflow($address, $subject, $body, $collaborators, $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);
$sla = $this->sla($email);
$priority = $this->priority($email);
$ticket_source = Ticket_source::where('name', '=', 'email')->first();
$source = $ticket_source->id;
$dept = $this->department($email);
$get_helptopic = Help_topic::where('id', '=', $helptopic)->first();
$assign = $get_helptopic->auto_assign;
$form_data = null;
$team_assign = null;
$ticket_status = null;
$auto_response = $email->auto_response;
$result = $this->TicketWorkflowController->workflow($fromaddress, $fromname, $subject, $body, $phone = '', $phonecode = '', $mobile_number = '', $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data = [], $auto_response);
if ($result[1] == true) {
$this->updateThread($result[0], $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]);
}
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();
$type = $attachment->getMimeType();
$size = $attachment->getSize();
$data = $attachment->getData();
$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)
{
$upload = new Ticket_attachments();
$upload->file = $data;
$upload->thread_id = $thread_id;
$upload->name = $filename;
$upload->type = $type;
$upload->size = $size;
$upload->poster = $disposition;
if ($data && $size && $disposition) {
$upload->save();
}
}
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));
//$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);
$thread->body = $body;
$thread->save();
$attachment->saveToDirectory($path);
}
}
public function collaburators($message, $email)
{
$this_address = $email->email_address;
$collaborator_cc = $message->getAddresses('cc');
//dd($collaborator_cc);
$collaborator_bcc = $message->getAddresses('bcc');
$collaborator_to = $message->getAddresses('to');
$cc_array = [];
$bcc_array = [];
$to_array = [];
if ($collaborator_cc) {
foreach ($collaborator_cc as $cc) {
$name = checkArray('name', $cc);
$address = checkArray('address', $cc);
$cc_array[$address] = $name;
}
}
if ($collaborator_bcc) {
foreach ($collaborator_bcc as $bcc) {
$name = checkArray('name', $bcc);
$address = checkArray('address', $bcc);
$bcc_array[$address] = $name;
}
}
if ($collaborator_to) {
foreach ($collaborator_to as $to) {
$name = checkArray('name', $to);
$address = checkArray('address', $to);
$to_array[$address] = $name;
}
}
$array = array_merge($bcc_array, $cc_array);
$array = array_merge($array, $to_array);
if (array_key_exists($this_address, $array)) {
unset($array[$this_address]);
}
return $array;
}
/**
@@ -309,47 +339,22 @@ class MailController extends Controller
*/
public function get_data($id)
{
$attachments = App\Model\helpdesk\Ticket\Ticket_attachments::where('id', '=', $id)->get();
$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');
echo $attachment->file;
$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 static function trimTableTag($html)
{
if (strpos('<table>', $html) != false) {
$first_pos = strpos($html, '<table');
$fist_string = substr_replace($html, '', 0, $first_pos);
$last_pos = strrpos($fist_string, '</table>', -1);
$total = strlen($fist_string);
$diff = $total - $last_pos;
$str = substr_replace($fist_string, '', $last_pos, -1);
$final_str = str_finish($str, '</table>');
return $final_str;
}
return $html;
}
public static function trim3D($html)
{
$body = str_replace('=3D', '', $html);
return $body;
}
public static function trimInjections($html, $tags = ['<script>', '</script>', '<style>', '</style>', '<?php', '?>'])
{
$replace = [];
foreach ($tags as $key => $tag) {
$replace[$key] = htmlspecialchars($tag);
}
$body = str_replace($tags, $replace, $html);
return $body;
}
}

View File

@@ -34,28 +34,37 @@ class NotificationController extends Controller
* */
public function send_notification()
{
// dd('sdckjdsc');
//fetching email settings
$email = Email::where('id', '=', '1')->first();
//dd('yes');
$send = 0;
$date = [0];
// dd($date);
// checking if the daily notification is enabled or not
if ($email->notification_cron == 1) {
// checking if current date is equal to the last entered daily notification log
$notification = Log_notification::where('log', '=', 'NOT-1')->orderBy('id', 'DESC')->first();
$date = explode(' ', $notification->created_at);
if (date('Y-m-d') == $date[0]) {
} else {
if ($notification) {
$date = explode(' ', $notification->created_at);
}
// if (date('Y-m-d') !== $date[0]) {
// creating a daily notification log
Log_notification::create(['log' => 'NOT-1']);
$company = $this->company();
// Send notification details to admin
$this->send_notification_to_admin($company);
$send += $this->send_notification_to_admin($company);
// Send notification details to team lead
//$this->send_notification_to_team_lead($company);
$send += $this->send_notification_to_team_lead($company);
// Send notification details to manager of a department
//$this->send_notification_to_manager($company);
$send += $this->send_notification_to_manager($company);
// Send notification details to all the agents
//$this->send_notification_to_agent($company);
}
$send += $this->send_notification_to_agent($company);
//}
Log_notification::create(['log' => 'NOT-1']);
}
return $send;
}
/**
@@ -79,14 +88,17 @@ class NotificationController extends Controller
$to = [
'name' => $user_name,
'email' => $email,
];
];
$message = [
'subject' => 'Daily Report',
'scenario' => null,
'body' => $contents,
];
$this->dispatch((new \App\Jobs\SendEmail($from, $to, $message))->onQueue('emails'));
//$this->PhpMailController->sendEmail($from,$to,$message);
];
$job = new \App\Jobs\SendEmail($from, $to, $message);
$dispatch = $this->dispatch($job);
return $dispatch;
//return $this->PhpMailController->sendEmail($from,$to,$message);
}
}
@@ -109,7 +121,19 @@ class NotificationController extends Controller
$user_name = $user->first_name.' '.$user->last_name;
$view = View::make('emails.notifications.manager', ['company' => $company, 'name' => $user_name]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
$from = $this->PhpMailController->mailfrom('1', '0');
$to = [
'name' => $user_name,
'email' => $email,
];
$message = [
'subject' => 'Daily Report',
'scenario' => null,
'body' => $contents,
];
return $this->dispatch((new \App\Jobs\SendEmail($from, $to, $message)));
//$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
}
}
}
@@ -134,7 +158,19 @@ class NotificationController extends Controller
$user_name = $user->first_name.' '.$user->last_name;
$view = View::make('emails.notifications.lead', ['company' => $company, 'name' => $user_name, 'team_id' => $team->id]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
$from = $this->PhpMailController->mailfrom('1', '0');
$to = [
'name' => $user_name,
'email' => $email,
];
$message = [
'subject' => 'Daily Report',
'scenario' => null,
'body' => $contents,
];
return $this->dispatch((new \App\Jobs\SendEmail($from, $to, $message)));
//$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
}
}
}
@@ -155,7 +191,19 @@ class NotificationController extends Controller
$user_name = $user->first_name.' '.$user->last_name;
$view = View::make('emails.notifications.agent', ['company' => $company, 'name' => $user_name, 'user_id' => $user->id]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
$from = $this->PhpMailController->mailfrom('1', '0');
$to = [
'name' => $user_name,
'email' => $email,
];
$message = [
'subject' => 'Daily Report',
'scenario' => null,
'body' => $contents,
];
return $this->dispatch((new \App\Jobs\SendEmail($from, $to, $message)));
//$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
}
}

View File

@@ -16,6 +16,7 @@ use App\Model\helpdesk\Agent_panel\User_org;
use App\User;
// classes
use Exception;
use Illuminate\Http\Request;
use Lang;
/**
@@ -328,4 +329,16 @@ class OrganizationController extends Controller
return '['.$last.']';
}
public function getOrgAjax(Request $request)
{
$org = new Organization();
$q = $request->input('term');
$orgs = $org->where('name', 'LIKE', '%'.$q.'%')
->select('name as label', 'id as value')
->get()
->toJson();
return $orgs;
}
}

View File

@@ -0,0 +1,269 @@
<?php
namespace App\Http\Controllers\Agent\helpdesk;
// controllers
use App\Http\Controllers\Controller;
use App\Model\helpdesk\Manage\Help_topic;
// request
use App\Model\helpdesk\Ticket\Tickets;
// Model
use Illuminate\Http\Request;
// classes
use PDF;
/**
* ReportController
* This controlleris used to fetch reports in the agent panel.
*
* @author Ladybird <info@ladybirdweb.com>
*/
class ReportController extends Controller
{
/**
* Create a new controller instance.
* constructor to check
* 1. authentication
* 2. user roles
* 3. roles must be agent.
*
* @return void
*/
public function __construct()
{
// checking for authentication
$this->middleware('auth');
// checking if the role is agent
$this->middleware('role.agent');
}
/**
* Get the Report page.
*
* @return type view
*/
public function index()
{
try {
return view('themes.default1.agent.helpdesk.report.index');
} catch (Exception $e) {
}
}
/**
* function to get help_topic graph.
*
* @param type $date111
* @param type $date122
* @param type $helptopic
*/
public function chartdataHelptopic(Request $request, $date111 = '', $date122 = '', $helptopic = '')
{
$date11 = strtotime($date122);
$date12 = strtotime($date111);
$help_topic = $helptopic;
$duration = $request->input('duration');
if ($date11 && $date12 && $help_topic) {
$date2 = $date12;
$date1 = $date11;
$duration = null;
if ($request->input('open') == null || $request->input('closed') == null || $request->input('reopened') == null || $request->input('overdue') == null || $request->input('deleted') == null) {
$duration = 'day';
}
} else {
// generating current date
$date2 = strtotime(date('Y-m-d'));
$date3 = date('Y-m-d');
$format = 'Y-m-d';
// generating a date range of 1 month
if ($request->input('duration') == 'day') {
$date1 = strtotime(date($format, strtotime('-15 day'.$date3)));
} elseif ($request->input('duration') == 'week') {
$date1 = strtotime(date($format, strtotime('-69 days'.$date3)));
} elseif ($request->input('duration') == 'month') {
$date1 = strtotime(date($format, strtotime('-179 days'.$date3)));
} else {
$date1 = strtotime(date($format, strtotime('-30 days'.$date3)));
}
// $help_topic = Help_topic::where('status', '=', '1')->min('id');
}
$return = '';
$last = '';
$j = 0;
$created1 = '';
$closed1 = '';
$reopened1 = '';
$in_progress = \DB::table('tickets')->where('help_topic_id', '=', $help_topic)->where('status', '=', 1)->count();
for ($i = $date1; $i <= $date2; $i = $i + 86400) {
$j++;
$thisDate = date('Y-m-d', $i);
$thisDate1 = date('jS F', $i);
$open_array = [];
$closed_array = [];
$reopened_array = [];
if ($request->input('open') || $request->input('closed') || $request->input('reopened')) {
if ($request->input('open') && $request->input('open') == 'on') {
$created = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count();
$open_array = ['open' => $created];
}
if ($request->input('closed') && $request->input('closed') == 'on') {
$closed = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count();
$closed_array = ['closed' => $closed];
}
if ($request->input('reopened') && $request->input('reopened') == 'on') {
$reopened = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count();
$reopened_array = ['reopened' => $reopened];
}
// if ($request->input('overdue') && $request->input('overdue') == 'on') {
// $overdue = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->where('dept_id', '=', $dept->id)->orderBy('id', 'DESC')->get();
// }
// $open_array = ['open'=>$created1];
// $closed_array = ['closed'=>$closed1];
// $reopened_array = ['reopened'=>$reopened1];
$value = ['date' => $thisDate1];
// if($open_array) {
$value = array_merge($value, $open_array);
$value = array_merge($value, $closed_array);
$value = array_merge($value, $reopened_array);
$value = array_merge($value, ['inprogress' => $in_progress]);
// } else {
// $value = "";
// }
$array = array_map('htmlentities', $value);
$json = html_entity_decode(json_encode($array));
$return .= $json.',';
} else {
if ($duration == 'week') {
$created = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count();
$created1 += $created;
$closed = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count();
$closed1 += $closed;
$reopened = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count();
$reopened1 += $reopened;
if ($j % 7 == 0) {
$open_array = ['open' => $created1];
$created1 = 0;
$closed_array = ['closed' => $closed1];
$closed1 = 0;
$reopened_array = ['reopened' => $reopened1];
$reopened1 = 0;
$value = ['date' => $thisDate1];
// if($open_array) {
$value = array_merge($value, $open_array);
$value = array_merge($value, $closed_array);
$value = array_merge($value, $reopened_array);
$value = array_merge($value, ['inprogress' => $in_progress]);
// } else {
// $value = "";
// }
$array = array_map('htmlentities', $value);
$json = html_entity_decode(json_encode($array));
$return .= $json.',';
}
} elseif ($duration == 'month') {
$created_month = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count();
$created1 += $created_month;
$closed_month = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count();
$closed1 += $closed_month;
$reopened_month = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count();
$reopened1 += $reopened_month;
if ($j % 30 == 0) {
$open_array = ['open' => $created1];
$created1 = 0;
$closed_array = ['closed' => $closed1];
$closed1 = 0;
$reopened_array = ['reopened' => $reopened1];
$reopened1 = 0;
$value = ['date' => $thisDate1];
$value = array_merge($value, $open_array);
$value = array_merge($value, $closed_array);
$value = array_merge($value, $reopened_array);
$value = array_merge($value, ['inprogress' => $in_progress]);
$array = array_map('htmlentities', $value);
$json = html_entity_decode(json_encode($array));
$return .= $json.',';
}
} else {
if ($request->input('default') == null) {
$help_topic = Help_topic::where('status', '=', '1')->min('id');
}
$created = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count();
$open_array = ['open' => $created];
$closed = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count();
$closed_array = ['closed' => $closed];
$reopened = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count();
$reopened_array = ['reopened' => $reopened];
if ($j % 1 == 0) {
$open_array = ['open' => $created];
$created = 0;
$closed_array = ['closed' => $closed];
$closed = 0;
$reopened_array = ['reopened' => $reopened];
$reopened = 0;
$value = ['date' => $thisDate1];
if ($request->input('default') == null) {
$value = array_merge($value, $open_array);
$value = array_merge($value, $closed_array);
$value = array_merge($value, $reopened_array);
$value = array_merge($value, ['inprogress' => $in_progress]);
} else {
if ($duration == null) {
if ($request->input('open') == 'on') {
$value = array_merge($value, $open_array);
}
if ($request->input('closed') == 'on') {
$value = array_merge($value, $closed_array);
}
if ($request->input('reopened') == 'on') {
$value = array_merge($value, $reopened_array);
}
} else {
$value = array_merge($value, $open_array);
$value = array_merge($value, $closed_array);
$value = array_merge($value, $reopened_array);
$value = array_merge($value, ['inprogress' => $in_progress]);
}
}
// } else {
// $value = "";
// }
$array = array_map('htmlentities', $value);
$json = html_entity_decode(json_encode($array));
$return .= $json.',';
}
}
}
// $value = ['date' => $thisDate];
// if($open_array) {
// $value = array_merge($value,$open_array);
// }
// if($closed_array) {
// $value = array_merge($value,$closed_array);
// }
// if($reopened_array) {
// $value = array_merge($value,$reopened_array);
// }
}
$last = rtrim($return, ',');
return '['.$last.']';
}
public function helptopicPdf(Request $request)
{
$table_datas = json_decode($request->input('pdf_form'));
$table_help_topic = json_decode($request->input('pdf_form_help_topic'));
$html = view('themes.default1.agent.helpdesk.report.pdf', compact('table_datas', 'table_help_topic'))->render();
$html1 = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
return PDF::load($html1)->show();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -40,35 +40,33 @@ class TicketWorkflowController extends Controller
*
* @return type response
*/
public function workflow($fromaddress, $fromname, $to, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response, $mail)
public function workflow($fromaddress, $fromname, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response)
{
$contact_details = ['email' => $fromaddress, 'email_name' => $fromname, 'email_to' => $to, 'subject' => $subject, 'message' => $body];
$contact_details = ['email' => $fromaddress, 'email_name' => $fromname, 'subject' => $subject, 'message' => $body];
$ticket_settings_details = ['help_topic' => $helptopic, 'sla' => $sla, 'priority' => $priority, 'source' => $source, 'dept' => $dept, 'assign' => $assign, 'team' => $team_assign, 'status' => $ticket_status, 'reject' => false];
// get all the workflow common to the entire system which includes any type of ticket creation where the execution order of the workflow should be starting with ascending order
$workflows = WorkflowName::where('target', '=', 'A-0')->where('status', '=', '1')->orderBy('order', 'asc')->get();
foreach ($workflows as $workflow) {
// checking if any workflow defined in the system
if ($workflow) {
// get all the rules of workflow which has a foreign key of those workflow which are applied to creating any ticket from any source
$workflow_rules = WorkflowRules::where('workflow_id', '=', $workflow->id)->get();
foreach ($workflow_rules as $workflow_rule) {
$worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflow->id)->get();
foreach ($worklfow_rules as $worklfow_rule) {
// checking for the workflow rules to which workflow rule type it is
if ($workflow_rule->matching_scenario == 'email') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
if ($worklfow_rule->matching_scenario == 'email') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'email_name') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'email_name') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'subject') {
} elseif ($worklfow_rule->matching_scenario == 'subject') {
if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'message') {
if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'message') {
if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
}
}
@@ -80,24 +78,24 @@ class TicketWorkflowController extends Controller
$workflows_webs = WorkflowName::where('target', '=', 'A-1')->where('status', '=', '1')->orderBy('order', 'asc')->get();
foreach ($workflows_webs as $workflows_web) {
if ($workflows_web) {
$workflow_rules = WorkflowRules::where('workflow_id', '=', $workflows_web->id)->get();
foreach ($workflow_rules as $workflow_rule) {
if ($workflow_rule) {
$worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflows_web->id)->get();
foreach ($worklfow_rules as $worklfow_rule) {
if ($worklfow_rule) {
// checking for the workflow rules to which workflow rule type it is
if ($workflow_rule->matching_scenario == 'email') {
if ($this->checkRuleCondition($contact_details['email'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
if ($worklfow_rule->matching_scenario == 'email') {
if ($this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'email_name') {
if ($this->checkRuleCondition($contact_details['email_name'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'email_name') {
if ($this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'subject') {
if ($this->checkRuleCondition($contact_details['subject'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'subject') {
if ($this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'message') {
if ($this->checkRuleCondition($contact_details['message'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'message') {
if ($this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
}
}
@@ -111,31 +109,24 @@ class TicketWorkflowController extends Controller
$workflows_emails = WorkflowName::where('target', '=', 'A-2')->where('status', '=', '1')->orderBy('order', 'asc')->get();
foreach ($workflows_emails as $workflows_email) {
if ($workflows_email) {
$workflow_rules = WorkflowRules::where('workflow_id', '=', $workflows_email->id)->get();
foreach ($workflow_rules as $workflow_rule) {
if ($workflow_rule) {
$worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflows_email->id)->get();
foreach ($worklfow_rules as $worklfow_rule) {
if ($worklfow_rule) {
// checking for the workflow rules to which workflow rule type it is
if ($workflow_rule->matching_scenario == 'email') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
if ($worklfow_rule->matching_scenario == 'email') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'email_name') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'email_name') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'email_to') {
foreach ($contact_details['email_to'] as $email_toaddress => $email_toname) {
if ($rule_condition = $this->checkRuleCondition($email_toaddress, $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
break;
}
}
} elseif ($workflow_rule->matching_scenario == 'subject') {
if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'subject') {
if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'message') {
if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'message') {
if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
}
}
@@ -149,28 +140,24 @@ class TicketWorkflowController extends Controller
$workflows_apis = WorkflowName::where('target', '=', 'A-4')->where('status', '=', '1')->orderBy('order', 'asc')->get();
foreach ($workflows_apis as $workflows_api) {
if ($workflows_api) {
$workflow_rules = WorkflowRules::where('workflow_id', '=', $workflows_api->id)->get();
foreach ($workflow_rules as $workflow_rule) {
if ($workflow_rule) {
$worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflows_api->id)->get();
foreach ($worklfow_rules as $worklfow_rule) {
if ($worklfow_rule) {
// checking for the workflow rules to which workflow rule type it is
if ($workflow_rule->matching_scenario == 'email') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
if ($worklfow_rule->matching_scenario == 'email') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'email_to') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'email_name') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'email_name') {
if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'subject') {
if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'subject') {
if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
}
} elseif ($workflow_rule->matching_scenario == 'message') {
if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $workflow_rule->matching_relation, $workflow_rule->matching_value) == true) {
} elseif ($worklfow_rule->matching_scenario == 'message') {
if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
$ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
}
}
@@ -179,10 +166,12 @@ class TicketWorkflowController extends Controller
}
}
}
//dd($form_data);
if ($ticket_settings_details['reject'] == true) {
return ['0' => false, '1' => false];
} else {
$create_ticket = $this->TicketController->create_user($contact_details['email'], $contact_details['email_name'], $contact_details['subject'], $contact_details['message'], $phone, $phonecode, $mobile_number, $ticket_settings_details['help_topic'], $ticket_settings_details['sla'], $ticket_settings_details['priority'], $source, $collaborator, $ticket_settings_details['dept'], $ticket_settings_details['assign'], $form_data, $auto_response, $ticket_settings_details['status'], $mail);
$create_ticket = $this->TicketController->create_user($contact_details['email'], $contact_details['email_name'], $contact_details['subject'], $contact_details['message'], $phone, $phonecode, $mobile_number, $ticket_settings_details['help_topic'], $ticket_settings_details['sla'], $ticket_settings_details['priority'], $source, $collaborator, $ticket_settings_details['dept'], $ticket_settings_details['assign'], $form_data, $auto_response, $ticket_settings_details['status']);
return $create_ticket;
}
@@ -217,7 +206,6 @@ class TicketWorkflowController extends Controller
// } elseif($condition == 'not_match') {
//
// }
return $return;
}

View File

@@ -7,23 +7,39 @@ use App\Http\Controllers\Common\PhpMailController;
use App\Http\Controllers\Controller;
// requests
/* Include Sys_user Model */
use App\Http\Requests\helpdesk\ProfilePassword;
use App\Http\Requests\helpdesk\ChangepasswordRequest;
/* For validation include Sys_userRequest in create */
use App\Http\Requests\helpdesk\ProfileRequest;
use App\Http\Requests\helpdesk\OtpVerifyRequest;
/* For validation include Sys_userUpdate in update */
use App\Http\Requests\helpdesk\Sys_userRequest;
use App\Http\Requests\helpdesk\ProfilePassword;
/* include guest_note model */
use App\Http\Requests\helpdesk\ProfileRequest;
use App\Http\Requests\helpdesk\Sys_userRequest;
// change password request
use App\Http\Requests\helpdesk\Sys_userUpdate;
// models
use App\Model\helpdesk\Agent\Assign_team_agent;
use App\Model\helpdesk\Agent_panel\Organization;
use App\Model\helpdesk\Agent_panel\User_org;
use App\Model\helpdesk\Notification\Notification;
use App\Model\helpdesk\Notification\UserNotification;
use App\Model\helpdesk\Settings\CommonSettings;
use App\Model\helpdesk\Settings\Email;
use App\Model\helpdesk\Ticket\Ticket_attachments;
use App\Model\helpdesk\Ticket\Ticket_Collaborator;
use App\Model\helpdesk\Ticket\Ticket_Thread;
use App\Model\helpdesk\Ticket\Tickets;
use App\Model\helpdesk\Utility\CountryCode;
use App\Model\helpdesk\Utility\Otp;
use App\User;
// classes
use Auth;
use DateTime;
use DB;
use Exception;
use GeoIP;
use Hash;
use Illuminate\Http\Request;
use Input;
use Lang;
use Redirect;
@@ -79,19 +95,23 @@ class UserController extends Controller
public function user_list()
{
// displaying list of users with chumper datatables
return \Datatable::collection(User::where('role', '=', 'user')->get())
return \Datatable::collection(User::where('role', '!=', 'admin')->get())
/* searchable column username and email */
->searchColumns('user_name', 'email', 'phone')
/* order column username and email */
->orderColumns('user_name', 'email')
/* column username */
->addColumn('user_name', function ($model) {
$string = strip_tags($model->user_name);
if (strlen($string) > 10) {
// truncate string
$stringCut = substr($string, 0, 10);
if ($model->first_name) {
$string = strip_tags($model->first_name.' '.$model->last_name);
} else {
$stringCut = $model->user_name;
$string = strip_tags($model->user_name);
}
if (strlen($string) > 20) {
// truncate string
$stringCut = substr($string, 0, 20);
} else {
$stringCut = $string;
}
return $stringCut;
@@ -133,7 +153,7 @@ class UserController extends Controller
if ($status == 1) {
$stat = '<button class="btn btn-danger btn-xs">Banned</button>';
} else {
$stat = '<button class="btn btn-success btn-xs">Active</button>';
$stat = '<button class="btn btn-success btn-xs">Not Banned</button>';
}
return $stat;
@@ -144,6 +164,12 @@ class UserController extends Controller
return TicketController::usertimezone($t);
})
/* column Role */
->addColumn('role', function ($model) {
$role = $model->role;
return $role;
})
/* column actions */
->addColumn('Actions', function ($model) {
return '<a href="'.route('user.edit', $model->id).'" class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp; <a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>';
@@ -159,10 +185,13 @@ class UserController extends Controller
public function create(CountryCode $code)
{
try {
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first();
$location = GeoIP::getLocation();
$phonecode = $code->where('iso', '=', $location['isoCode'])->first();
$org = Organization::lists('name', 'id')->toArray();
return view('themes.default1.agent.helpdesk.user.create')->with('phonecode', $phonecode->phonecode);
return view('themes.default1.agent.helpdesk.user.create', compact('org', 'settings', 'email_mandatory'))->with('phonecode', $phonecode->phonecode);
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
@@ -180,11 +209,20 @@ class UserController extends Controller
{
/* insert the input request to sys_user table */
/* Check whether function success or not */
$user->email = $request->input('email');
if ($request->input('email') != '') {
$user->email = $request->input('email');
} else {
$user->email = null;
}
$user->first_name = $request->input('first_name');
$user->last_name = $request->input('last_name');
$user->user_name = $request->input('user_name');
$user->mobile = $request->input('mobile');
if ($request->input('mobile') != '') {
$user->mobile = $request->input('mobile');
} else {
$user->mobile = null;
}
$user->ext = $request->input('ext');
$user->phone_number = $request->input('phone_number');
$user->country_code = $request->input('country_code');
@@ -204,6 +242,8 @@ class UserController extends Controller
}
// save user credentails
if ($user->save() == true) {
$orgid = $request->input('org_id');
$this->storeUserOrgRelation($user->id, $orgid);
// fetch user credentails to send mail
$name = $user->first_name;
$email = $user->email;
@@ -217,6 +257,12 @@ class UserController extends Controller
}
}
// returns for the success case
// returns for the success case
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first();
if (($request->input('active') == '0' || $request->input('active') == 0) || ($email_mandatory->status == '0') || $email_mandatory->status == 0) {
\Event::fire(new \App\Events\LoginEvent($request));
}
return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully'));
}
// $user->save();
@@ -228,6 +274,266 @@ class UserController extends Controller
}
}
/**
* Random Password Genetor for users.
*
* @param type int $id
* @param type User $user
*
* @return type view
*/
public function randomPassword()
{
try {
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*(){}[]';
$pass = []; //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 10; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass);
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', $e->getMessage());
}
}
/**
* Random Password Genetor for users.
*
* @param type int $id
* @param type User $user
*
* @return type view
*/
public function randomPostPassword($id, ChangepasswordRequest $request)
{
try {
$changepassword = $request->change_password;
$user = User::whereId($id)->first();
$password = $request->change_password;
$user->password = Hash::make($password);
$user->save();
$name = $user->first_name;
$email = $user->email;
$this->PhpMailController->sendmail($from = $this->PhpMailController
->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'reset_new_password'], $template_variables = ['user' => $name, 'user_password' => $password]);
return redirect('user')->with('success', Lang::get('lang.password_change_successfully'));
} catch (Exception $e) {
return redirect('user')->with('fails', $e->getMessage());
}
}
/**
* @param type $id
* @param Request $request
*
* @return type
*/
public function changeRoleAdmin($id, Request $request)
{
try {
$user = User::whereId($id)->first();
$user->role = 'admin';
$user->assign_group = $request->group;
$user->primary_dpt = $request->primary_department;
$user->save();
return redirect('user')->with('success', Lang::get('lang.role_change_successfully'));
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', $e->getMessage());
}
}
/**
* @param type $id
* @param Request $request
*
* @return type
*/
public function changeRoleAgent($id, Request $request)
{
try {
$user = User::whereId($id)->first();
$user->role = 'agent';
$user->assign_group = $request->group;
$user->primary_dpt = $request->primary_department;
$user->save();
return redirect('user')->with('success', Lang::get('lang.role_change_successfully'));
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', $e->getMessage());
}
}
/**
* @param type $id
*
* @return type
*/
public function changeRoleUser($id)
{
try {
$ticket = Tickets::where('assigned_to', '=', $id)->where('status', '=', '1')->get();
if ($ticket) {
$ticket = Tickets::where('assigned_to', '=', $id)->update(['assigned_to' => null]);
}
$user = User::whereId($id)->first();
$user->role = 'user';
$user->assign_group = null;
$user->primary_dpt = null;
$user->remember_token = null;
$user->save();
return redirect('user')->with('success', Lang::get('lang.role_change_successfully'));
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', $e->getMessage());
}
// return 'Agent Role Successfully Change to User';
}
/**
* @param type $id
*
* @return type
*/
public function deleteAgent($id)
{
// try {
$delete_all = Input::get('delete_all');
$users = User::where('id', '=', $id)->first();
if ($users->role == 'user') {
if ($delete_all == null || $delete_all == 1) {
$tickets = Tickets::where('user_id', '=' ,$id)->get();
if(count($tickets) > 0) {
foreach ($tickets as $ticket) {
$notification = Notification::select('id')->where('model_id', '=', $ticket->id)->get();
foreach ($notification as $id) {
$user_notification = UserNotification::where(
'notification_id', '=', $id->id);
$user_notification->delete();
}
$notification = Notification::select('id')->where('model_id', '=', $ticket->id);
$notification->delete();
$thread = Ticket_Thread::where('ticket_id', '=', $ticket->id)->get();
foreach ($thread as $th_id) {
// echo $th_id->id." ";
$attachment = Ticket_attachments::where('thread_id', '=', $th_id->id)->get();
if (count($attachment)) {
foreach ($attachment as $a_id) {
Ticket_attachments::where('id','=', $a_id->id)
->delete();
}
// echo "<br>";
}
$thread = Ticket_Thread::find($th_id->id);
// dd($thread);
$thread->delete();
}
$collaborators = Ticket_Collaborator::where('ticket_id', '=', $ticket->id)->get();
if (count($collaborators)) {
foreach ($collaborators as $collab_id) {
echo $collab_id->id;
$collab = Ticket_Collaborator::where('id', '=', $collab_id->id)
->delete();
}
}
$tickets = Tickets::find($ticket->id);
$tickets->delete();
}
}
$organization = User_org::where('user_id', '=', $users->id)->delete();
$user = User::where('id', '=', $users->id)
->delete();
return redirect('user')->with('success', Lang::get('lang.user_delete_successfully'));
}
}
if ($users->role == 'agent') {
if ($delete_all == null) {
$UserEmail = Input::get('assign_to');
$assign_to = explode('_', $UserEmail);
$ticket = Tickets::where('assigned_to', '=', $id)->where('status', '=', '1')->get();
if ($assign_to[0] == 'user') {
if ($users->id == $assign_to[1]) {
return redirect('user')->with('warning', Lang::get('lang.select_another_user'));
}
$user_detail = User::where('id', '=', $assign_to[1])->first();
$assignee = $user_detail->first_name.' '.$user_detail->last_name;
$ticket_logic1 = Tickets::where('assigned_to', '=', $id)
->update(['assigned_to' => $assign_to[1]]);
if ($ticket_logic2 = Tickets::where('user_id', '=', $id)->get()) {
$ticket_logic2 = Tickets::where('user_id', '=', $id)->update(['user_id' => $assign_to[1]]);
}
if ($ticket_logic3 = Ticket_Thread::where('user_id', '=', $id)->get()) {
$ticket_logic3 = Ticket_Thread::where('user_id', '=', $id)->update(['user_id' => $assign_to[1]]);
}
if ($ticket_logic4 = User_org::where('user_id', '=', $id)->get()) {
$ticket_logic4 = User_org::where('user_id', '=', $id)->update(['user_id' => $assign_to[1]]);
}
// $thread2 = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first();
// $thread2->body = 'This Ticket have been Reassigned to' .' '. $assignee;
// $thread2->save();
// UserNotification::where('notification_id', '=', $ticket->id)->delete();
// $users = User::where('id', '=', $id)->get();
// $organization = User_org::where('user_id', '=', $id)->delete();
Assign_team_agent::where('agent_id', '=', $id)->update(['agent_id' => $assign_to[1]]);
$user = User::find($id);
$user->delete();
return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully_and_ticket_assign_to_another_user'));
}
if (User_org::where('user_id', '=', $id)) {
DB::table('user_assign_organization')->where('user_id', '=', $id)->delete();
}
$user = User::find($id);
$user->delete();
return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully'));
} elseif ($delete_all == 1) {
if ($ticket = Tickets::where('user_id', '=', $id)->first()) {
$ticket_assign = $ticket->assigned_to;
Ticket_Thread::where('ticket_id', '=', $ticket->id)->delete();
if ($ticket->user_id = $id) {
Tickets::where('user_id', '=', $id)->delete();
}
if ($ticket_assign) {
UserNotification::where('notification_id', '=', $ticket_assign)->delete();
}
UserNotification::where('notification_id', '=', $ticket->id)->delete();
$users = User::where('id', '=', $id)->get();
$user = User::find($id);
$user->delete();
return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully'));
} else {
Assign_team_agent::where('agent_id', '=', $id)->delete();
User_org::where('user_id', '=', $id)->delete();
$user = User::find($id);
$user->delete();
return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully'));
}
} else {
}
}
// } catch (Exception $e) {
/* redirect to Index page with Fails Message */
// return redirect('user')->with('fails', $e->getMessage());
// }
}
/**
* Display the specified users.
*
@@ -239,11 +545,12 @@ class UserController extends Controller
public function show($id)
{
try {
$user = new User();
/* select the field where id = $id(request Id) */
$users = $user->whereId($id)->first();
return view('themes.default1.agent.helpdesk.user.show', compact('users'));
$users = User::where('id', '=', $id)->first();
if (count($users) > 0) {
return view('themes.default1.agent.helpdesk.user.show', compact('users'));
} else {
return redirect()->back()->with('fails', Lang::get('lang.user-not-found'));
}
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());
}
@@ -260,13 +567,17 @@ class UserController extends Controller
public function edit($id, CountryCode $code)
{
try {
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first();
$user = new User();
/* select the field where id = $id(request Id) */
$users = $user->whereId($id)->first();
$location = GeoIP::getLocation();
$phonecode = $code->where('iso', '=', $location['isoCode'])->first();
$org = Organization::lists('name', 'id')->toArray();
return view('themes.default1.agent.helpdesk.user.edit', compact('users'))->with('phonecode', $phonecode->phonecode);
return view('themes.default1.agent.helpdesk.user.edit', compact('users', 'org', '$settings', '$email_mandatory'))->with('phonecode', $phonecode->phonecode);
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());
}
@@ -302,6 +613,8 @@ class UserController extends Controller
}
// dd($request->input());
$users->fill($request->input())->save();
$orgid = $request->input('org_id');
$this->storeUserOrgRelation($users->id, $orgid);
/* redirect to Index page with Success Message */
return redirect('user')->with('success', Lang::get('lang.User-profile-Updated-Successfully'));
} catch (Exception $e) {
@@ -335,8 +648,12 @@ class UserController extends Controller
$user = Auth::user();
$location = GeoIP::getLocation();
$phonecode = $code->where('iso', '=', $location['isoCode'])->first();
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
$status = $settings->status;
try {
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user'))->with('phonecode', $phonecode->phonecode);
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user'))
->with(['phonecode' => $phonecode->phonecode,
'verify' => $status, ]);
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());
}
@@ -391,7 +708,13 @@ class UserController extends Controller
}
$user->country_code = $request->country_code;
}
$user->fill($request->except('profile_pic', 'gender'))->save();
$user->fill($request->except('profile_pic', 'gender', 'mobile'))->save();
if ($request->get('mobile')) {
$user->mobile = $request->get('mobile');
} else {
$user->mobile = null;
}
$user->save();
return Redirect::route('profile')->with('success', Lang::get('lang.Profile-Updated-sucessfully'));
} catch (Exception $e) {
@@ -533,4 +856,126 @@ class UserController extends Controller
// return random string
return $randomString;
}
public function storeUserOrgRelation($userid, $orgid)
{
$org_relations = new User_org();
$org_relation = $org_relations->where('user_id', $userid)->first();
if ($org_relation) {
$org_relation->delete();
}
$org_relations->create([
'user_id' => $userid,
'org_id' => $orgid,
]);
}
public function getExportUser()
{
try {
return view('themes.default1.agent.helpdesk.user.export');
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
public function exportUser(Request $request)
{
try {
$date = $request->input('date');
$date = str_replace(' ', '', $date);
$date_array = explode(':', $date);
$first = $date_array[0].' 00:00:00';
$second = $date_array[1].' 23:59:59';
$first_date = $this->convertDate($first);
$second_date = $this->convertDate($second);
$users = $this->getUsers($first_date, $second_date);
$excel_controller = new \App\Http\Controllers\Common\ExcelController();
$filename = 'users'.$date;
$excel_controller->export($filename, $users);
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
public function convertDate($date)
{
$converted_date = date('Y-m-d H:i:s', strtotime($date));
return $converted_date;
}
public function getUsers($first, $last)
{
$user = new User();
$users = $user->leftJoin('user_assign_organization', 'users.id', '=', 'user_assign_organization.user_id')
->leftJoin('organization', 'user_assign_organization.org_id', '=', 'organization.id')
->whereBetween('users.created_at', [$first, $last])
->where('role', 'user')
->where('active', 1)
->select('users.user_name as Username', 'users.email as Email', 'users.first_name as Fisrtname', 'users.last_name as Lastname', 'organization.name as Organization')
->get()
->toArray();
return $users;
}
public function resendOTP(OtpVerifyRequest $request)
{
if (\Schema::hasTable('sms')) {
$sms = DB::table('sms')->get();
if (count($sms) > 0) {
\Event::fire(new \App\Events\LoginEvent($request));
return 1;
}
} else {
return 'Plugin has not been setup successfully.';
}
}
public function verifyOTP()
{
// dd(Input::all());
// $user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email'))->first();
$otp = Otp::select('otp', 'updated_at')->where('user_id', '=', Input::get('u_id'))
->first();
if ($otp != null) {
$otp_length = strlen(Input::get('otp'));
if (($otp_length == 6 && !preg_match('/[a-z]/i', Input::get('otp')))) {
$otp2 = Hash::make(Input::get('otp'));
$date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa');
$date2 = date('Y-m-d h:i:sa');
$time1 = new DateTime($date2);
$time2 = new DateTime($date1);
$interval = $time1->diff($time2);
if ($interval->i > 10 || $interval->h > 0) {
$message = Lang::get('lang.otp-expired');
return $message;
} else {
if (Hash::check(Input::get('otp'), $otp->otp)) {
Otp::where('user_id', '=', Input::get('u_id'))
->update(['otp' => '']);
// User::where('id', '=', $user->id)
// ->update(['active' => 1]);
// $this->openTicketAfterVerification($user->id);
return 1;
} else {
$message = Lang::get('lang.otp-not-matched');
return $message;
}
}
} else {
$message = Lang::get('lang.otp-invalid');
return $message;
}
} else {
$message = Lang::get('lang.otp-not-matched');
return $message;
}
}
}

View File

@@ -138,19 +138,20 @@ class SettingsController extends Controller
public function getData()
{
return \Datatable::collection(Comment::All())
->searchColumns('name', 'email', 'comment', 'created')
->orderColumns('name')
->addColumn('name', function ($model) {
return $model->name;
})
->addColumn('email', function ($model) {
return $model->email;
})
->addColumn('website', function ($model) {
return $model->website;
->searchColumns('details', 'comment', 'created')
->orderColumns('details')
->addColumn('details', function ($model) {
$name = "<p>$model->name</p><br>";
$email = "<p>$model->email</p><br>";
$website = "<p>$model->website</p><br>";
return $name.$email.$website;
})
->addColumn('comment', function ($model) {
return $model->comment;
$created = TicketController::usertimezone(date($model->created_at));
return $model->comment."<p>$created</p>";
})
->addColumn('status', function ($model) {
$status = $model->status;
@@ -160,11 +161,9 @@ class SettingsController extends Controller
return '<p style="color:red"">'.\Lang::get('lang.not_published');
}
})
->addColumn('Created', function ($model) {
return TicketController::usertimezone(date($model->created_at));
})
->addColumn('Actions', function ($model) {
return '<a href=comment/delete/'.$model->id.' class="btn btn-danger btn-xs">'.\Lang::get('lang.delete').'</a>&nbsp;<a href=published/'.$model->id.' class="btn btn-warning btn-xs">'.\Lang::get('lang.publish').'</a>';
return '<div class="row"><div class="col-md-12"><a href=comment/delete/'.$model->id.' class="btn btn-danger btn-xs">'.\Lang::get('lang.delete').'</a></div><div class="col-md-12"><a href=published/'.$model->id.' class="btn btn-warning btn-xs">'.\Lang::get('lang.publish').'</a></div></div>';
})
->make();
}