@@ -1,633 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
// use App\Model\Ticket\Ticket;
|
||||
use App\Model\Email\Emails;
|
||||
use App\Model\Ticket\Ticket_attachments;
|
||||
use App\Model\Ticket\Ticket_Thread;
|
||||
|
||||
class MailController extends Controller {
|
||||
|
||||
public $email = "";
|
||||
public $stream = "";
|
||||
|
||||
// public function fetchEmails(Emails $email)
|
||||
// {
|
||||
// $emails = $email->get();
|
||||
// $mailboxes = $emails;
|
||||
// return $mailboxes;
|
||||
// }
|
||||
|
||||
function decode_imap_text($str) {
|
||||
$result = '';
|
||||
$decode_header = imap_mime_header_decode($str);
|
||||
foreach ($decode_header AS $obj) {
|
||||
$result .= htmlspecialchars(rtrim($obj->text, "\t"));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getdata() {
|
||||
$email = new Emails;
|
||||
$mailboxes = $email->get();
|
||||
|
||||
if (count($mailboxes) >= 0) {
|
||||
foreach ($mailboxes as $current_mailbox) {
|
||||
if ($current_mailbox['fetching_status']) {
|
||||
$stream = @imap_open($current_mailbox['fetching_host'], $current_mailbox['email_address'], $current_mailbox['password']);
|
||||
$testvar = "";
|
||||
if ($stream >= 0) {
|
||||
$emails = imap_search($stream, 'SINCE ' . date('d-M-Y', strtotime("-10 day")));
|
||||
if ($emails != false) {
|
||||
if (count($emails) >= 0) {
|
||||
rsort($emails);
|
||||
foreach ($emails as $email_id) {
|
||||
$overview = imap_fetch_overview($stream, $email_id, 0);
|
||||
$var = $overview[0]->seen ? 'read' : 'unread';
|
||||
if ($var == 'unread') {
|
||||
$testvar = 'set';
|
||||
|
||||
$from = $this->decode_imap_text($overview[0]->from);
|
||||
$subject = $this->decode_imap_text($overview[0]->subject);
|
||||
$datetime = $overview[0]->date;
|
||||
$date_time = explode(" ", $datetime);
|
||||
$date = $date_time[1] . "-" . $date_time[2] . "-" . $date_time[3] . " " . $date_time[4];
|
||||
|
||||
//=======================================================================
|
||||
// check user
|
||||
//=======================================================================
|
||||
// $subject = $subject;
|
||||
// $match = '/^[[A-Z]{4}-[0-9]{4}-[0-9]{7}]][A-z0-9]$/';
|
||||
// if(preg_match($match, $subject))
|
||||
// {
|
||||
// echo "success";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// echo "fail";
|
||||
// }
|
||||
|
||||
$emailadd = explode('&', $from);
|
||||
$username = $emailadd[0];
|
||||
$emailadd = substr($emailadd[1], 3);
|
||||
$date = date('Y-m-d H:i:s', strtotime($date));
|
||||
|
||||
$system = "Email";
|
||||
$phone = "";
|
||||
$helptopic = $this->default_helptopic();
|
||||
$sla = $this->default_sla();
|
||||
|
||||
$structure = imap_fetchstructure($stream, $email_id);
|
||||
// $image1 = $structure->parts[0]->parts[1]->parameters[0]->value;
|
||||
// $image = $structure->parts[1]->parameters[0]->value;
|
||||
// echo '<img src="'.$image1.'">';
|
||||
// echo '<img src="'.$image.'">';
|
||||
// dd($structure);
|
||||
//=================================================
|
||||
// HTML
|
||||
//=================================================
|
||||
if ($structure->subtype == 'HTML') {
|
||||
$body2 = imap_fetchbody($stream, $email_id, 1);
|
||||
if ($body2 == null) {
|
||||
$body2 = imap_fetchbody($stream, $email_id, 1);
|
||||
}
|
||||
$body = quoted_printable_decode($body2);
|
||||
// $body = explode("---Reply above this line---", $body);
|
||||
// echo $body;
|
||||
// echo "0";
|
||||
}
|
||||
|
||||
//=================================================
|
||||
// ALTERNATIVE
|
||||
//=================================================
|
||||
if ($structure->subtype == 'ALTERNATIVE') {
|
||||
if (isset($structure->parts)) {
|
||||
$body2 = imap_fetchbody($stream, $email_id, 1.2);
|
||||
if ($body2 == null) {
|
||||
$body2 = imap_fetchbody($stream, $email_id, 1);
|
||||
}
|
||||
$body = quoted_printable_decode($body2);
|
||||
// $body = explode("---Reply above this line---", $body);
|
||||
// echo $body[0];
|
||||
}
|
||||
}
|
||||
|
||||
//=================================================
|
||||
// RELATED
|
||||
//=================================================
|
||||
if ($structure->subtype == 'RELATED') {
|
||||
if (isset($structure->parts)) {
|
||||
$parts = $structure->parts;
|
||||
$i = 0;
|
||||
$body2 = imap_fetchbody($stream, $email_id, 1.2);
|
||||
if ($body2 == null) {
|
||||
$body2 = imap_fetchbody($stream, $email_id, 1);
|
||||
}
|
||||
$body = quoted_printable_decode($body2);
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if ($parts[$i]) {
|
||||
|
||||
}
|
||||
$i++;
|
||||
if (isset($parts[$i])) {
|
||||
if ($parts[$i]->ifid == 1) {
|
||||
$id = $parts[$i]->id;
|
||||
$imageid = substr($id, 1, -1);
|
||||
$imageid = "cid:" . $imageid;
|
||||
if ($parts[$i]->ifdparameters == 1) {
|
||||
foreach ($parts[$i]->dparameters as $object) {
|
||||
if (strtolower($object->attribute) == 'filename') {
|
||||
$filename = $object->value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if ($parts[$i]->ifparameters == 1) {
|
||||
foreach ($parts[$i]->parameters as $object) {
|
||||
if (strtolower($object->attribute) == 'name') {
|
||||
$name = $object->value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$body = str_replace($imageid, $filename, $body);
|
||||
|
||||
// $ticket_Thread = new Ticket_attachments;
|
||||
// // $ticket_Thread->thread_id = $thread_id;
|
||||
// $ticket_Thread->name = $filename;
|
||||
// // $ticket_Thread->size = $filesize;
|
||||
// // $ticket_Thread->type = $ext;
|
||||
// $ticket_Thread->content = '<img src="'.$name.'">';
|
||||
// $ticket_Thread->save();
|
||||
// // $body = explode("---Reply above this line---", $body);
|
||||
// echo $body[0];
|
||||
// echo "2";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=================================================
|
||||
// MIXED
|
||||
//=================================================
|
||||
elseif ($structure->subtype == 'MIXED') {
|
||||
if (isset($structure->parts)) {
|
||||
$parts = $structure->parts;
|
||||
|
||||
// subtype = ALTERNATIVE
|
||||
if ($parts[0]->subtype == 'ALTERNATIVE') {
|
||||
if (isset($structure->parts)) {
|
||||
$body2 = imap_fetchbody($stream, $email_id, 1.2);
|
||||
if ($body2 == null) {
|
||||
$body2 = imap_fetchbody($stream, $email_id, 1);
|
||||
}
|
||||
$body = quoted_printable_decode($body2);
|
||||
}
|
||||
}
|
||||
|
||||
// subtype = RELATED
|
||||
if ($parts[0]->subtype == 'RELATED') {
|
||||
if (isset($parts[0]->parts)) {
|
||||
$parts = $parts[0]->parts;
|
||||
$i = 0;
|
||||
|
||||
$body2 = imap_fetchbody($stream, $email_id, 1.1);
|
||||
if ($body2 == null) {
|
||||
$body2 = imap_fetchbody($stream, $email_id, 1);
|
||||
}
|
||||
$body = quoted_printable_decode($body2);
|
||||
$name = "";
|
||||
foreach ($parts as $part) {
|
||||
if ($parts[0]) {
|
||||
|
||||
}
|
||||
$i++;
|
||||
if (isset($parts[$i])) {
|
||||
if ($parts[$i]->ifid == 1) {
|
||||
$id = $parts[$i]->id;
|
||||
$imageid = substr($id, 1, -1);
|
||||
$imageid = "cid:" . $imageid;
|
||||
if ($parts[$i]->ifdparameters == 1) {
|
||||
foreach ($parts[$i]->dparameters as $object) {
|
||||
if (strtolower($object->attribute) == 'filename') {
|
||||
$filename = $object->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($parts[$i]->ifparameters == 1) {
|
||||
foreach ($parts[$i]->parameters as $object) {
|
||||
if (strtolower($object->attribute) == 'name') {
|
||||
$name = $object->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$body = str_replace($imageid, $name, $body);
|
||||
// $body = explode("---Reply above this line---", $body);
|
||||
// echo $body[0];
|
||||
// echo '3'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// dd($structure);
|
||||
}
|
||||
// $ticket = new Tickets;
|
||||
// $ticket->name = $from;
|
||||
// $ticket->subject = $subject;
|
||||
// $ticket->body = $body2;
|
||||
// $ticket->date = $datetime;
|
||||
// $ticket->save();
|
||||
// $ticket = new Ticket_Thread;
|
||||
// $ticket->name = $from;
|
||||
// $ticket->subject = $subject;
|
||||
// $ticket->body = $body2;
|
||||
// $ticket->date = $datetime;
|
||||
// $ticket->save();
|
||||
|
||||
if ($this->create_user($emailadd, $username, $subject, $body, $phone, $helptopic, $sla, $system) == true) {
|
||||
$thread_id = Ticket_Thread::whereRaw('id = (select max(`id`) from ticket_thread)')->first();
|
||||
$thread_id = $thread_id->id;
|
||||
if ($this->get_attachment($structure, $stream, $email_id, $thread_id) == true) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
imap_close($stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//======================================
|
||||
// ATTACHMENT |Incomplete
|
||||
//======================================
|
||||
public function get_attachment($structure, $stream, $email_id, $thread_id) {
|
||||
if (isset($structure->parts) && count($structure->parts)) {
|
||||
for ($i = 0; $i < count($structure->parts); $i++) {
|
||||
$attachments[$i] = array(
|
||||
'is_attachment' => false,
|
||||
'filename' => '',
|
||||
'name' => '',
|
||||
'attachment' => '');
|
||||
|
||||
if ($structure->parts[$i]->ifdparameters) {
|
||||
foreach ($structure->parts[$i]->dparameters as $object) {
|
||||
if (strtolower($object->attribute) == 'filename') {
|
||||
$attachments[$i]['is_attachment'] = true;
|
||||
$attachments[$i]['filename'] = $object->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($structure->parts[$i]->ifparameters) {
|
||||
foreach ($structure->parts[$i]->parameters as $object) {
|
||||
if (strtolower($object->attribute) == 'name') {
|
||||
$attachments[$i]['is_attachment'] = true;
|
||||
$attachments[$i]['name'] = $object->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($attachments[$i]['is_attachment']) {
|
||||
$attachments[$i]['attachment'] = imap_fetchbody($stream, $email_id, $i + 1);
|
||||
if ($structure->parts[$i]->encoding == 3) {
|
||||
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
|
||||
} elseif ($structure->parts[$i]->encoding == 4) {
|
||||
$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->save_attcahments($attachments, $thread_id) == true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=====================================
|
||||
// SAVE ATTACHMENT | Incomplete
|
||||
//=====================================
|
||||
public function save_attcahments($attachments, $thread_id) {
|
||||
if (count($attachments) != 0) {
|
||||
foreach ($attachments as $at) {
|
||||
if ($at['is_attachment'] == 1) {
|
||||
$str = str_shuffle('abcdefghijjklmopqrstuvwxyz');
|
||||
$filename = $at['filename'];
|
||||
$ext = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
$tmpName = $at['filename'];
|
||||
// echo '<img src="'.$tmpName.'">';
|
||||
$fp = fopen($tmpName, 'r');
|
||||
$content = fread($fp, filesize($tmpName));
|
||||
$content2 = file_put_contents($at['filename'], $at['attachment']);
|
||||
$filesize = $content2;
|
||||
$ticket_Thread = new Ticket_attachments;
|
||||
$ticket_Thread->thread_id = $thread_id;
|
||||
$ticket_Thread->name = $filename;
|
||||
$ticket_Thread->size = $filesize;
|
||||
$ticket_Thread->type = $ext;
|
||||
$ticket_Thread->content = $fp; //$content;
|
||||
$ticket_Thread->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// // public function part($part)
|
||||
// // {
|
||||
// // $structure = $part->parts;
|
||||
// // return $structure;
|
||||
// // }
|
||||
// // public function fetchdata()
|
||||
// // {
|
||||
// // $tickets = Tickets::all();
|
||||
// // foreach ($tickets as $ticket)
|
||||
// // {
|
||||
// // echo $ticket->body.'<hr/>';
|
||||
// // }
|
||||
// // }
|
||||
// public function ticket_list()
|
||||
// {
|
||||
// $tickets = Tickets::all();
|
||||
// $threads = Ticket_Thread::all();
|
||||
// return view('themes.default1.agent.ticket.ticket',compact('tickets'),compact('threads'));
|
||||
// }
|
||||
// public function thread($id)
|
||||
// {
|
||||
// $tickets = Tickets::where('id','=',$id)->first();
|
||||
// $thread = Ticket_Thread::where('ticket_id','=',$id)->first();
|
||||
// return view('themes.default1.agent.ticket.timeline',compact('tickets'),compact('thread'));
|
||||
// }
|
||||
// //============================================
|
||||
// // Create Ticket | Incomplete
|
||||
// //============================================
|
||||
// public function reply(Ticket_Thread $thread, TicketRequest $request)
|
||||
// {
|
||||
// $thread->ticket_id = $request->input('ticket_ID');
|
||||
// $thread->title = $request->input('To');
|
||||
// $thread->body = $request->input('ReplyContent');
|
||||
// $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 'success';
|
||||
// return Redirect("thread/".$ticket_id);
|
||||
// }
|
||||
// //============================================
|
||||
// // Ticket Edit get | Incomplete
|
||||
// //============================================
|
||||
// public function ticket_edit_get($id, Tickets $ticket , Ticket_Thread $thread)
|
||||
// {
|
||||
// $ticket_id = $ticket->where('id' , '=' , $id)->first();
|
||||
// $thread_id = $thread->where('ticket_id' , '=' , $id)->first();
|
||||
// $user = User::where('id' , '=' , $ticket_id->user_id)->first();
|
||||
// return view("themes.default1.agent.ticket.edit",compact('ticket_id','thread_id','user'));
|
||||
// }
|
||||
// //============================================
|
||||
// // Ticket Edit post | Incomplete
|
||||
// //============================================
|
||||
// public function ticket_edit_post($ticket_id,Ticket_Thread $thread)
|
||||
// {
|
||||
// dd($ticket_id);
|
||||
// // return Redirect("");
|
||||
// }
|
||||
// //============================================
|
||||
// // Ticket print | Incomplete
|
||||
// //============================================
|
||||
// public function ticket_print($id)
|
||||
// {
|
||||
// return pdf();
|
||||
// // return Redirect("");
|
||||
// }
|
||||
// //============================================
|
||||
// // Generate Ticket Number | Incomplete
|
||||
// //============================================
|
||||
// public function ticket_number($ticket_number)
|
||||
// {
|
||||
// $number = $ticket_number;
|
||||
// $number = explode('-',$number);
|
||||
// $number1 = $number[0];
|
||||
// if($number1 == 'ZZZZ'){
|
||||
// $number1 = 'AAAA';
|
||||
// }
|
||||
// $number2 = $number[1];
|
||||
// if($number2 == '9999'){
|
||||
// $number2 = '0000';
|
||||
// }
|
||||
// $number3 = $number[2];
|
||||
// if($number3 == '9999999'){
|
||||
// $number3 = '0000000';
|
||||
// }
|
||||
// $number1++;
|
||||
// $number2++;
|
||||
// $number3++;
|
||||
// $number2 = sprintf('%04s', $number2);
|
||||
// $number3 = sprintf('%07s', $number3);
|
||||
// $array = array($number1,$number2,$number3);
|
||||
// $number = implode('-', $array);
|
||||
// return $number;
|
||||
// }
|
||||
// //=============================================
|
||||
// // Checking email availability | Complete
|
||||
// //=============================================
|
||||
// public function check_email($email)
|
||||
// {
|
||||
// $check = User::where('email','=',$email)->first();
|
||||
// if($check == true)
|
||||
// {
|
||||
// return $check;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// //===============================================
|
||||
// // Create User | InComplete
|
||||
// //===============================================
|
||||
// public function create_user($emailadd, $username, $subject, $body, $phone, $helptopic, $sla, $system)
|
||||
// {
|
||||
// $email;
|
||||
// $username;
|
||||
// $checkemail = $this->check_email($emailadd);
|
||||
// if($checkemail == false )
|
||||
// {
|
||||
// $password = $this->generateRandomString();
|
||||
// $user = new User;
|
||||
// $user->user_name = $username;
|
||||
// $user->email = $emailadd;
|
||||
// $user->password = Hash::make($password);
|
||||
// if($user->save())
|
||||
// {
|
||||
// $user_id = $user->id;
|
||||
// if(Mail::send('emails.pass', ['password' => $password, 'name' => $username],
|
||||
// function($message)use($emailadd, $username)
|
||||
// {
|
||||
// $message->to($emailadd, $username)->subject('password');
|
||||
// }))
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $username = $checkemail->username;
|
||||
// $user_id = $checkemail->id;
|
||||
// }
|
||||
// $ticket_number = $this->check_ticket($user_id, $subject, $body, $helptopic, $sla);
|
||||
// if(Mail::send('emails.Ticket_Create', ['name' => $username, 'ticket_number' => $ticket_number],
|
||||
// function($message)use($emailadd, $username, $ticket_number)
|
||||
// {
|
||||
// $message->to($emailadd, $username)->subject('[~'.$ticket_number.']');
|
||||
// }))
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// //============================================
|
||||
// // Select Default help_topic | Incomplete
|
||||
// //============================================
|
||||
// public function default_helptopic()
|
||||
// {
|
||||
// $helptopic = "Support";
|
||||
// return $helptopic;
|
||||
// }
|
||||
// //============================================
|
||||
// // Select Default sla | Incomplete
|
||||
// //============================================
|
||||
// public function default_sla()
|
||||
// {
|
||||
// $sla = "12hours";
|
||||
// return $sla;
|
||||
// }
|
||||
// //============================================
|
||||
// // Select Default priority | Incomplete
|
||||
// //============================================
|
||||
// public function default_priority()
|
||||
// {
|
||||
// $priority = "important";
|
||||
// return $helptopic;
|
||||
// }
|
||||
// //============================================
|
||||
// // check ticket | Incomplete
|
||||
// //============================================
|
||||
// public function check_ticket($user_id, $subject, $body, $helptopic, $sla)
|
||||
// {
|
||||
// $read_ticket_number = substr($subject, 0, 6);
|
||||
// if($read_ticket_number == 'Re: [~')
|
||||
// {
|
||||
// $separate = explode("]", $subject);
|
||||
// $new_subject = substr($separate[0] , 6 , 20);
|
||||
// $find_number = Tickets::where('ticket_number', '=', $new_subject)->first();
|
||||
// $thread_body = explode("---Reply above this line---", $body);
|
||||
// $body = $thread_body[0];
|
||||
// if(count($find_number) > 0)
|
||||
// {
|
||||
// $id = $find_number->id;
|
||||
// $ticket_number = $find_number->ticket_number;
|
||||
// if(isset($id))
|
||||
// {
|
||||
// if($this->ticket_thread($subject, $body, $id, $user_id))
|
||||
// {
|
||||
// return $ticket_number;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $ticket_number = $this->create_ticket($user_id, $subject, $body, $helptopic, $sla);
|
||||
// return $ticket_number;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $ticket_number = $this->create_ticket($user_id, $subject, $body, $helptopic, $sla);
|
||||
// return $ticket_number;
|
||||
// }
|
||||
// }
|
||||
// //============================================
|
||||
// // Create Ticket | Incomplete
|
||||
// //============================================
|
||||
// public function create_ticket($user_id, $subject, $body, $helptopic, $sla)
|
||||
// {
|
||||
// $max_number = Tickets::whereRaw('id = (select max(`id`) from tickets)')->get();
|
||||
// foreach($max_number as $number)
|
||||
// {
|
||||
// $ticket_number = $number->ticket_number;
|
||||
// }
|
||||
// $ticket = new Tickets;
|
||||
// $ticket->ticket_number = $this->ticket_number($ticket_number);
|
||||
// $ticket->user_id = $user_id;
|
||||
// $ticket->save();
|
||||
// $ticket_number = $ticket->ticket_number;
|
||||
// $id = $ticket->id;
|
||||
// if($this->ticket_thread($subject, $body, $id, $user_id)==true)
|
||||
// {
|
||||
// return $ticket_number;
|
||||
// }
|
||||
// }
|
||||
// //============================================
|
||||
// // Create Ticket | Incomplete
|
||||
// //============================================
|
||||
// public function ticket_thread($subject, $body, $id, $user_id)
|
||||
// {
|
||||
// $thread = new Ticket_Thread;
|
||||
// $thread->user_id = $user_id;
|
||||
// $thread->ticket_id = $id;
|
||||
// $thread->poster = 'client';
|
||||
// $thread->title = $subject;
|
||||
// $thread->body = $body;
|
||||
// if($thread->save())
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// //============================================
|
||||
// // Generate Random password | Incomplete
|
||||
// //============================================
|
||||
// public function generateRandomString($length = 10)
|
||||
// {
|
||||
// $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
// $charactersLength = strlen($characters);
|
||||
// $randomString = '';
|
||||
// for ($i = 0; $i < $length; $i++)
|
||||
// {
|
||||
// $randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
// }
|
||||
// return $randomString;
|
||||
// }
|
||||
// public function close($id, Tickets $ticket)
|
||||
// {
|
||||
// $ticket_status = $ticket->where('id','=',$id)->first();
|
||||
// $ticket_status->status = 3;
|
||||
// $ticket_status->save();
|
||||
// return "your ticket".$ticket_status->ticket_number." has been closed";
|
||||
// }
|
||||
// public function resolve($id, Tickets $ticket)
|
||||
// {
|
||||
// $ticket_status = $ticket->where('id','=',$id)->first();
|
||||
// $ticket_status->status = 2;
|
||||
// $ticket_status->save();
|
||||
// return "your ticket".$ticket_status->ticket_number." has been resolved";
|
||||
// }
|
||||
// public function open($id, Tickets $ticket)
|
||||
// {
|
||||
// $ticket_status = $ticket->where('id','=',$id)->first();
|
||||
// $ticket_status->status = 1;
|
||||
// $ticket_status->save();
|
||||
// return "your ticket".$ticket_status->ticket_number." has been opened";
|
||||
// }
|
||||
// public function assign($id)
|
||||
// {
|
||||
// return $id;
|
||||
// }
|
||||
}
|
@@ -1,174 +0,0 @@
|
||||
<?php namespace App\Http\Controllers\Agent;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\OrganizationRequest;
|
||||
|
||||
/* include organization model */
|
||||
use App\Http\Requests\OrganizationUpdate;
|
||||
|
||||
/* Define OrganizationRequest to validate the create form */
|
||||
use App\Model\Agent_panel\Organization;
|
||||
|
||||
/* Define OrganizationUpdate to validate the create form */
|
||||
|
||||
class OrganizationController extends Controller {
|
||||
|
||||
/* Define constructor for authentication checking */
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('role.agent');
|
||||
$this->middleware('roles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(Organization $org) {
|
||||
try
|
||||
{
|
||||
/* get all values of table organization */
|
||||
$orgs = $org->get();
|
||||
|
||||
return view('themes.default1.agent.organization.index', compact('orgs'));
|
||||
} catch (Exception $e) {
|
||||
return view('404');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create() {
|
||||
try
|
||||
{
|
||||
return view('themes.default1.agent.organization.create');
|
||||
} catch (Exception $e) {
|
||||
return view('404');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function store(Organization $org, OrganizationRequest $request) {
|
||||
try
|
||||
{
|
||||
/* Insert the all input request to organization table */
|
||||
/* Check whether function success or not */
|
||||
|
||||
if ($org->fill($request->input())->save() == true) {
|
||||
/* redirect to Index page with Success Message */
|
||||
return redirect('organizations')->with('success', 'Organization Created Successfully');
|
||||
} else {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('organizations')->with('fails', 'Organization can not Create');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('organizations')->with('fails', 'Organization can not Create');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function show($id, Organization $org) {
|
||||
try
|
||||
{
|
||||
/* select the field by id */
|
||||
$orgs = $org->whereId($id)->first();
|
||||
|
||||
/* To view page */
|
||||
return view('themes.default1.agent.organization.show', compact('orgs'));
|
||||
} catch (Exception $e) {
|
||||
return view('404');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function edit($id, Organization $org) {
|
||||
try
|
||||
{
|
||||
/* select the field by id */
|
||||
$orgs = $org->whereId($id)->first();
|
||||
|
||||
/* To view page */
|
||||
return view('themes.default1.agent.organization.edit', compact('orgs'));
|
||||
} catch (Exception $e) {
|
||||
return view('404');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function update($id, Organization $org, OrganizationUpdate $request) {
|
||||
try
|
||||
{
|
||||
/* select the field by id */
|
||||
$orgs = $org->whereId($id)->first();
|
||||
|
||||
/* update the organization table */
|
||||
/* Check whether function success or not */
|
||||
|
||||
if ($orgs->fill($request->input())->save() == true) {
|
||||
/* redirect to Index page with Success Message */
|
||||
return redirect('organizations')->with('success', 'Organization Updated Successfully');
|
||||
} else {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('organizations')->with('fails', 'Organization can not Update');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('organizations')->with('fails', 'Organization can not Update');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy($id) {
|
||||
try
|
||||
{
|
||||
/* select the field by id */
|
||||
$orgs = $org->whereId($id)->first();
|
||||
|
||||
/* Delete the field selected from the table */
|
||||
/* Check whether function success or not */
|
||||
|
||||
if ($orgs->delete() == true) {
|
||||
/* redirect to Index page with Success Message */
|
||||
return redirect('organizations')->with('success', 'Organization Deleted Successfully');
|
||||
} else {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('organizations')->with('fails', 'Organization can not Delete');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('organizations')->with('fails', 'Organization can not Delete');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,501 +0,0 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Agent;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\CreateTicketRequest;
|
||||
use App\Http\Requests\TicketRequest;
|
||||
use App\Model\Email\Banlist;
|
||||
use App\Model\Ticket\Tickets;
|
||||
// use App\Http\Requests\Ticket_EditRequest;
|
||||
use App\Model\Ticket\Ticket_Thread;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Hash;
|
||||
use Input;
|
||||
use Mail;
|
||||
use PDF;
|
||||
|
||||
class TicketController extends Controller {
|
||||
/* Define constructor for Authentication Checking */
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Ticket List | Incomplete
|
||||
//============================================
|
||||
public function ticket_list() {
|
||||
// $tickets = Tickets::all();
|
||||
// $threads = Ticket_Thread::all();
|
||||
return view('themes.default1.agent.ticket.ticket');
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Open Ticket List | Incomplete
|
||||
//============================================
|
||||
public function open_ticket_list() {
|
||||
// $tickets = Tickets::all();
|
||||
// $threads = Ticket_Thread::all();
|
||||
return view('themes.default1.agent.ticket.open');
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Open Ticket List | Incomplete
|
||||
//============================================
|
||||
public function answered_ticket_list() {
|
||||
// $tickets = Tickets::all();
|
||||
// $threads = Ticket_Thread::all();
|
||||
return view('themes.default1.agent.ticket.answered');
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Open Ticket List | Incomplete
|
||||
//============================================
|
||||
public function myticket_ticket_list() {
|
||||
// $tickets = Tickets::all();
|
||||
// $threads = Ticket_Thread::all();
|
||||
return view('themes.default1.agent.ticket.myticket');
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Open Ticket List | Incomplete
|
||||
//============================================
|
||||
public function overdue_ticket_list() {
|
||||
// $tickets = Tickets::all();
|
||||
// $threads = Ticket_Thread::all();
|
||||
return view('themes.default1.agent.ticket.overdue');
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Open Ticket List | Incomplete
|
||||
//============================================
|
||||
public function closed_ticket_list() {
|
||||
// $tickets = Tickets::all();
|
||||
// $threads = Ticket_Thread::all();
|
||||
return view('themes.default1.agent.ticket.closed');
|
||||
}
|
||||
|
||||
//============================================
|
||||
// create Ticket | Incomplete
|
||||
//============================================
|
||||
public function newticket() {
|
||||
// $tickets = Tickets::all();
|
||||
// $threads = Ticket_Thread::all();
|
||||
return view('themes.default1.agent.ticket.new');
|
||||
}
|
||||
|
||||
//============================================
|
||||
// post create ticket | Incomplete
|
||||
//============================================
|
||||
public function post_newticket(CreateTicketRequest $request) {
|
||||
$email = $request->input('email');
|
||||
$fullname = $request->input('fullname');
|
||||
$notice = $request->input('notice');
|
||||
$helptopic = $request->input('helptopic');
|
||||
$dept = $request->input('dept');
|
||||
$sla = $request->input('sla');
|
||||
$duedate = $request->input('duedate');
|
||||
$assignto = $request->input('assignto');
|
||||
$subject = $request->input('subject');
|
||||
$body = $request->input('body');
|
||||
$priority = $request->input('priority');
|
||||
$phone = "";
|
||||
$system = "";
|
||||
if ($this->create_user($email, $fullname, $subject, $body, $phone, $helptopic, $sla, $priority, $system)) {
|
||||
return Redirect('newticket')->with('success', 'success');
|
||||
} else {
|
||||
return Redirect('newticket')->with('success', 'success');
|
||||
}
|
||||
// echo $priority;
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Thread | Incomplete
|
||||
//============================================
|
||||
public function thread($id) {
|
||||
$tickets = Tickets::where('id', '=', $id)->first();
|
||||
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first();
|
||||
return view('themes.default1.agent.ticket.timeline', compact('tickets'), compact('thread'));
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Ticket reply | Incomplete
|
||||
//============================================
|
||||
public function reply(Ticket_Thread $thread, TicketRequest $request) {
|
||||
$thread->ticket_id = $request->input('ticket_ID');
|
||||
$thread->poster = 'support';
|
||||
$thread->body = $request->input('ReplyContent');
|
||||
$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 'success';
|
||||
return 1;
|
||||
}
|
||||
|
||||
// //============================================
|
||||
// // Ticket Edit get | Incomplete
|
||||
// //============================================
|
||||
// public function ticket_edit_get($id, Tickets $ticket , Ticket_Thread $thread)
|
||||
// {
|
||||
// $ticket_id = $ticket->where('id' , '=' , $id)->first();
|
||||
// $thread_id = $thread->where('ticket_id' , '=' , $id)->first();
|
||||
// $user = User::where('id' , '=' , $ticket_id->user_id)->first();
|
||||
// return view("themes.default1.agent.ticket.edit",compact('ticket_id','thread_id','user'));
|
||||
// }
|
||||
//============================================
|
||||
// Ticket Edit post | Incomplete
|
||||
//============================================
|
||||
public function ticket_edit_post($ticket_id, Ticket_Thread $thread) {
|
||||
// echo $ticket_id;
|
||||
$threads = $thread->where('ticket_id', '=', $ticket_id)->first();
|
||||
// // echo $threads->title;
|
||||
if (Input::get('subject') != null && Input::get('body') != null) {
|
||||
$threads->title = Input::get('subject');
|
||||
$threads->body = Input::get('body');
|
||||
if ($threads->save()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Ticket print | Incomplete
|
||||
//============================================
|
||||
public function ticket_print($id) {
|
||||
$tickets = Tickets::where('id', '=', $id)->first();
|
||||
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first();
|
||||
$html = view('themes.default1.agent.ticket.pdf', compact('id', 'tickets', 'thread'))->render();
|
||||
return PDF::load($html)->show();
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Generate Ticket Number | Incomplete
|
||||
//============================================
|
||||
public function ticket_number($ticket_number) {
|
||||
$number = $ticket_number;
|
||||
$number = explode('-', $number);
|
||||
$number1 = $number[0];
|
||||
if ($number1 == 'ZZZZ') {
|
||||
$number1 = 'AAAA';
|
||||
}
|
||||
$number2 = $number[1];
|
||||
if ($number2 == '9999') {
|
||||
$number2 = '0000';
|
||||
}
|
||||
$number3 = $number[2];
|
||||
if ($number3 == '9999999') {
|
||||
$number3 = '0000000';
|
||||
}
|
||||
$number1++;
|
||||
$number2++;
|
||||
$number3++;
|
||||
$number2 = sprintf('%04s', $number2);
|
||||
$number3 = sprintf('%07s', $number3);
|
||||
$array = array($number1, $number2, $number3);
|
||||
$number = implode('-', $array);
|
||||
return $number;
|
||||
}
|
||||
|
||||
//=============================================
|
||||
// Checking email availability | Complete
|
||||
//=============================================
|
||||
public function check_email($email) {
|
||||
$check = User::where('email', '=', $email)->first();
|
||||
if ($check == true) {
|
||||
return $check;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//===============================================
|
||||
// Create User | InComplete
|
||||
//===============================================
|
||||
public function create_user($emailadd, $username, $subject, $body, $phone, $helptopic, $sla, $priority, $system) {
|
||||
$email;
|
||||
$username;
|
||||
$checkemail = $this->check_email($emailadd);
|
||||
|
||||
if ($checkemail == false) {
|
||||
$password = $this->generateRandomString();
|
||||
|
||||
$user = new User;
|
||||
$user->user_name = $username;
|
||||
$user->email = $emailadd;
|
||||
$user->password = Hash::make($password);
|
||||
|
||||
if ($user->save()) {
|
||||
$user_id = $user->id;
|
||||
if (Mail::send('emails.pass', ['password' => $password, 'name' => $username], function ($message) use ($emailadd, $username) {
|
||||
$message->to($emailadd, $username)->subject('password');
|
||||
})) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$username = $checkemail->username;
|
||||
$user_id = $checkemail->id;
|
||||
}
|
||||
|
||||
$ticket_number = $this->check_ticket($user_id, $subject, $body, $helptopic, $sla, $priority);
|
||||
|
||||
if (Mail::send('emails.Ticket_Create', ['name' => $username, 'ticket_number' => $ticket_number], function ($message) use ($emailadd, $username, $ticket_number) {
|
||||
$message->to($emailadd, $username)->subject('[~' . $ticket_number . ']');
|
||||
})) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Select Default help_topic | Incomplete
|
||||
//============================================
|
||||
public function default_helptopic() {
|
||||
$helptopic = "Support";
|
||||
return $helptopic;
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Select Default sla | Incomplete
|
||||
//============================================
|
||||
public function default_sla() {
|
||||
$sla = "12hours";
|
||||
return $sla;
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Select Default priority | Incomplete
|
||||
//============================================
|
||||
public function default_priority() {
|
||||
$priority = "important";
|
||||
return $helptopic;
|
||||
}
|
||||
|
||||
//============================================
|
||||
// check ticket | Incomplete
|
||||
//============================================
|
||||
public function check_ticket($user_id, $subject, $body, $helptopic, $sla, $priority) {
|
||||
$read_ticket_number = substr($subject, 0, 6);
|
||||
if ($read_ticket_number == 'Re: [~') {
|
||||
$separate = explode("]", $subject);
|
||||
$new_subject = substr($separate[0], 6, 20);
|
||||
$find_number = Tickets::where('ticket_number', '=', $new_subject)->first();
|
||||
$thread_body = explode("---Reply above this line---", $body);
|
||||
$body = $thread_body[0];
|
||||
if (count($find_number) > 0) {
|
||||
$id = $find_number->id;
|
||||
$ticket_number = $find_number->ticket_number;
|
||||
if (isset($id)) {
|
||||
if ($this->ticket_thread($subject, $body, $id, $user_id)) {
|
||||
return $ticket_number;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ticket_number = $this->create_ticket($user_id, $subject, $body, $helptopic, $sla, $priority);
|
||||
return $ticket_number;
|
||||
}
|
||||
} else {
|
||||
$ticket_number = $this->create_ticket($user_id, $subject, $body, $helptopic, $sla, $priority);
|
||||
return $ticket_number;
|
||||
}
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Create Ticket | Incomplete
|
||||
//============================================
|
||||
public function create_ticket($user_id, $subject, $body, $helptopic, $sla, $priority) {
|
||||
$max_number = Tickets::whereRaw('id = (select max(`id`) from tickets)')->get();
|
||||
foreach ($max_number as $number) {
|
||||
$ticket_number = $number->ticket_number;
|
||||
}
|
||||
$ticket = new Tickets;
|
||||
$ticket->ticket_number = $this->ticket_number($ticket_number);
|
||||
$ticket->user_id = $user_id;
|
||||
$ticket->help_topic_id = $helptopic;
|
||||
$ticket->sla = $sla;
|
||||
$ticket->status = '1';
|
||||
$ticket->priority_id = $priority;
|
||||
$ticket->save();
|
||||
$ticket_number = $ticket->ticket_number;
|
||||
$id = $ticket->id;
|
||||
if ($this->ticket_thread($subject, $body, $id, $user_id) == true) {
|
||||
return $ticket_number;
|
||||
}
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Create Ticket | Incomplete
|
||||
//============================================
|
||||
public function ticket_thread($subject, $body, $id, $user_id) {
|
||||
$thread = new Ticket_Thread;
|
||||
$thread->user_id = $user_id;
|
||||
$thread->ticket_id = $id;
|
||||
$thread->poster = 'client';
|
||||
$thread->title = $subject;
|
||||
$thread->body = $body;
|
||||
if ($thread->save()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Generate Random password | Incomplete
|
||||
//============================================
|
||||
public function generateRandomString($length = 10) {
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Ticket Close | Incomplete
|
||||
//============================================
|
||||
public function close($id, Tickets $ticket) {
|
||||
$ticket_status = $ticket->where('id', '=', $id)->first();
|
||||
$ticket_status->status = 3;
|
||||
$ticket_status->save();
|
||||
return "your ticket" . $ticket_status->ticket_number . " has been closed";
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Ticket resolve | Incomplete
|
||||
//============================================
|
||||
public function resolve($id, Tickets $ticket) {
|
||||
$ticket_status = $ticket->where('id', '=', $id)->first();
|
||||
$ticket_status->status = 2;
|
||||
$ticket_status->save();
|
||||
return "your ticket" . $ticket_status->ticket_number . " has been resolved";
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Ticket open | Incomplete
|
||||
//============================================
|
||||
public function open($id, Tickets $ticket) {
|
||||
$ticket_status = $ticket->where('id', '=', $id)->first();
|
||||
$ticket_status->status = 1;
|
||||
$ticket_status->save();
|
||||
return "your ticket" . $ticket_status->ticket_number . " has been opened";
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Ticket open | Incomplete
|
||||
//============================================
|
||||
public function delete($id, Tickets $ticket) {
|
||||
$ticket_delete = $ticket->where('id', '=', $id)->first();
|
||||
$ticket_delete->is_deleted = 0;
|
||||
$ticket_delete->status = 5;
|
||||
$ticket_delete->save();
|
||||
return "your ticket" . $ticket_delete->ticket_number . " has been delete";
|
||||
}
|
||||
|
||||
//============================================
|
||||
// ban email | Incomplete
|
||||
//============================================
|
||||
public function ban($id, Tickets $ticket) {
|
||||
$ticket_ban = $ticket->where('id', '=', $id)->first();
|
||||
$ban_email = $ticket_ban->user_id;
|
||||
$user = User::where('id', '=', $ban_email)->first();
|
||||
$user->is_ban = 1;
|
||||
$user->save();
|
||||
$Email = $user->email;
|
||||
$ban = Banlist::where('email_address', '=', $Email)->first();
|
||||
if ($ban == null) {
|
||||
$banlist = new Banlist;
|
||||
$banlist->ban_status = 1;
|
||||
$banlist->email_address = $user->email;
|
||||
$banlist->save();
|
||||
}
|
||||
return "the user has been banned";
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Ticket Assign | Incomplete
|
||||
//============================================
|
||||
public function assign($id) {
|
||||
$UserEmail = Input::get('user');
|
||||
// $UserEmail = 'sujitprasad12@yahoo.in';
|
||||
$user = User::where('email', '=', $UserEmail)->first();
|
||||
$user_id = $user->id;
|
||||
$ticket = Tickets::where('id', '=', $id)->first();
|
||||
$ticket->assigned_to = $user_id;
|
||||
$ticket->save();
|
||||
return 1;
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Internal Note | Incomplete
|
||||
//============================================
|
||||
public function InternalNote($id) {
|
||||
$InternalContent = Input::get('InternalContent');
|
||||
// $InternalContent = 'hello';
|
||||
$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->thread_type = 'M';
|
||||
$NewThread->poster = Auth::user()->role;
|
||||
$NewThread->title = $thread->title;
|
||||
$NewThread->body = $InternalContent;
|
||||
$NewThread->save();
|
||||
return 1;
|
||||
}
|
||||
|
||||
//============================================
|
||||
// Surrender ticket | Incomplete
|
||||
//============================================
|
||||
public function surrender($id) {
|
||||
$ticket = Tickets::where('id', '=', $id)->first();
|
||||
$ticket->assigned_to = 0;
|
||||
$ticket->save();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function search() {
|
||||
$product = Input::get('type');
|
||||
$word = Input::get('name_startsWith');
|
||||
|
||||
if ($product == 'product') {
|
||||
$starts_with = strtoupper($word);
|
||||
$rows = DB::table('users')->select('user_name')->where('name', 'LIKE', $starts_with . '%')->get();
|
||||
$data = array();
|
||||
foreach ($rows as $row) {
|
||||
array_push($data, $row->name);
|
||||
}
|
||||
print_r(json_encode($data));
|
||||
}
|
||||
|
||||
if ($product == 'product_table') {
|
||||
$row_num = Input::get('row_num');
|
||||
$starts_with = strtoupper($word);
|
||||
$rows = DB::table('product')->select('name', 'description', 'cost_price')->where('name', 'LIKE', $starts_with . '%')->get();
|
||||
$data = array();
|
||||
foreach ($rows as $row) {
|
||||
$name = $row->name . '|' . $row->description . '|' . $row->cost_price . '|' . $row_num;
|
||||
array_push($data, $name);
|
||||
}
|
||||
print_r(json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
public function trash() {
|
||||
return view('themes.default1.agent.ticket.trash');
|
||||
}
|
||||
|
||||
public function unassigned() {
|
||||
return view('themes.default1.agent.ticket.unassigned');
|
||||
}
|
||||
|
||||
public function myticket() {
|
||||
return view('themes.default1.agent.ticket.myticket');
|
||||
}
|
||||
|
||||
}
|
@@ -1,257 +0,0 @@
|
||||
<?php namespace App\Http\Controllers\Agent;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
/* Include Sys_user Model */
|
||||
use App\Http\Requests\ProfilePassword;
|
||||
|
||||
/* For validation include Sys_userRequest in create */
|
||||
use App\Http\Requests\ProfileRequest;
|
||||
|
||||
/* For validation include Sys_userUpdate in update */
|
||||
use App\Http\Requests\Sys_userRequest;
|
||||
|
||||
/* include guest_note model */
|
||||
use App\Http\Requests\Sys_userUpdate;
|
||||
|
||||
/* include User Model */
|
||||
use App\Model\Agent_panel\Sys_user;
|
||||
/* include Help_topic Model */
|
||||
|
||||
/* Profile validator */
|
||||
|
||||
/* Profile Password validator */
|
||||
use App\User;
|
||||
|
||||
/* include ticket_thred model */
|
||||
use Auth;
|
||||
|
||||
/* include tickets model */
|
||||
use Hash;
|
||||
|
||||
/* TicketRequest to validate the ticket response */
|
||||
|
||||
/* Validate post check ticket */
|
||||
use Input;
|
||||
|
||||
class UserController extends Controller {
|
||||
|
||||
/* Define constructor for Authentication Checking */
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('role.agent');
|
||||
$this->middleware('roles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(Sys_user $user) {
|
||||
try
|
||||
{
|
||||
/* get all values in Sys_user */
|
||||
$users = $user->get();
|
||||
|
||||
return view('themes.default1.agent.user.index', compact('users'));
|
||||
} catch (Exception $e) {
|
||||
return view('404');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create() {
|
||||
try
|
||||
{
|
||||
return view('themes.default1.agent.user.create');
|
||||
} catch (Exception $e) {
|
||||
return view('404');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function store(Sys_user $user, Sys_userRequest $request) {
|
||||
try
|
||||
{
|
||||
/* insert the input request to sys_user table */
|
||||
|
||||
/* Check whether function success or not */
|
||||
|
||||
if ($user->fill($request->input())->save() == true) {
|
||||
/* redirect to Index page with Success Message */
|
||||
return redirect('user')->with('success', 'User Created Successfully');
|
||||
} else {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('user')->with('fails', 'User can not Create');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('user')->with('fails', 'User can not Create');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function show($id, Sys_user $user) {
|
||||
try
|
||||
{
|
||||
/* select the field where id = $id(request Id) */
|
||||
$users = $user->whereId($id)->first();
|
||||
|
||||
return view('themes.default1.agent.user.show', compact('users'));
|
||||
} catch (Exception $e) {
|
||||
return view('404');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function edit($id, Sys_user $user) {
|
||||
try
|
||||
{
|
||||
/* select the field where id = $id(request Id) */
|
||||
$users = $user->whereId($id)->first();
|
||||
|
||||
return view('themes.default1.agent.user.edit', compact('users'));
|
||||
} catch (Exception $e) {
|
||||
return view('404');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function update($id, Sys_user $user, Sys_userUpdate $request) {
|
||||
try
|
||||
{
|
||||
/* select the field where id = $id(request Id) */
|
||||
$users = $user->whereId($id)->first();
|
||||
|
||||
/* Update the value by selected field */
|
||||
/* Check whether function success or not */
|
||||
|
||||
if ($users->fill($request->input())->save() == true) {
|
||||
/* redirect to Index page with Success Message */
|
||||
return redirect('user')->with('success', 'User Updated Successfully');
|
||||
} else {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('user')->with('fails', 'User can not Update');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('user')->with('fails', 'User can not Update');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy($id, Sys_user $user) {
|
||||
try
|
||||
{
|
||||
/* select the field where id = $id(request Id) */
|
||||
$users = $user->whereId($id)->first();
|
||||
|
||||
/* delete the selected field */
|
||||
/* Check whether function success or not */
|
||||
|
||||
if ($users->delete() == true) {
|
||||
/* redirect to Index page with Success Message */
|
||||
return redirect('user')->with('success', 'User Deleted Successfully');
|
||||
} else {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('user')->with('fails', 'User can not Delete');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* redirect to Index page with Fails Message */
|
||||
return redirect('user')->with('fails', 'User can not Delete');
|
||||
}
|
||||
}
|
||||
public function getProfile() {
|
||||
$user = Auth::user();
|
||||
return view('themes.default1.agent.user.profile', compact('user'));
|
||||
}
|
||||
|
||||
public function postProfile($id, ProfileRequest $request) {
|
||||
$user = Auth::user();
|
||||
$user->gender = $request->input('gender');
|
||||
$user->save();
|
||||
|
||||
if ($user->profile_pic == 'avatar5.png' || $user->profile_pic == 'avatar2.png') {
|
||||
if ($request->input('gender') == 1) {
|
||||
|
||||
$name = 'avatar5.png';
|
||||
$destinationPath = 'dist/img';
|
||||
$user->profile_pic = $name;
|
||||
} elseif ($request->input('gender') == 0) {
|
||||
|
||||
$name = 'avatar2.png';
|
||||
$destinationPath = 'dist/img';
|
||||
$user->profile_pic = $name;
|
||||
}
|
||||
}
|
||||
|
||||
if (Input::file('profile_pic')) {
|
||||
//$extension = Input::file('profile_pic')->getClientOriginalExtension();
|
||||
$name = Input::file('profile_pic')->getClientOriginalName();
|
||||
|
||||
$destinationPath = 'dist/img';
|
||||
$fileName = rand(0000, 9999) . '.' . $name;
|
||||
//echo $fileName;
|
||||
|
||||
Input::file('profile_pic')->move($destinationPath, $fileName);
|
||||
|
||||
$user->profile_pic = $fileName;
|
||||
|
||||
} else {
|
||||
$user->fill($request->except('profile_pic', 'gender'))->save();
|
||||
return redirect('guest')->with('success', 'Profile Updated sucessfully');
|
||||
|
||||
}
|
||||
|
||||
if ($user->fill($request->except('profile_pic'))->save()) {
|
||||
return redirect('guest')->with('success', 'Profile Updated sucessfully');
|
||||
}
|
||||
}
|
||||
|
||||
public function postProfilePassword($id, ProfilePassword $request) {
|
||||
$user = Auth::user();
|
||||
//echo $user->password;
|
||||
|
||||
if (Hash::check($request->input('old_password'), $user->getAuthPassword())) {
|
||||
$user->password = Hash::make($request->input('new_password'));
|
||||
$user->save();
|
||||
return redirect('guest')->with('success', 'Password Updated sucessfully');
|
||||
} else {
|
||||
return redirect('guest')->with('fails', 'Password was not Updated');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user