updated commit

This commit is contained in:
sujitprasad
2015-05-08 16:25:40 +05:30
parent ef834c58dc
commit 267467725e
73 changed files with 2748 additions and 2938 deletions

View File

@@ -1,25 +1,44 @@
<?php
namespace App\Http\Controllers\Agent;
<?php namespace App\Http\Controllers\Agent;
use App;
use App\Http\Controllers\Agent\TicketController;
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;
/**
* MailController
*
* @package Controllers
* @subpackage Controller
* @author Ladybird <info@ladybirdweb.com>
*/
class MailController extends Controller {
/**
* @var string
*/
public $email = "";
/**
* @var string
*/
public $stream = "";
// public function fetchEmails(Emails $email)
// {
// $emails = $email->get();
// $mailboxes = $emails;
// return $mailboxes;
// }
/**
* constructor
* Create a new controller instance.
* @param type TicketController $TicketController
*/
public function __construct(TicketController $TicketController) {
$this->TicketController = $TicketController;
}
/**
* Decode Imap text
* @param type $str
* @return type string
*/
function decode_imap_text($str) {
$result = '';
$decode_header = imap_mime_header_decode($str);
@@ -29,29 +48,75 @@ class MailController extends Controller {
return $result;
}
/**
* get Imap data
*/
function getdata() {
/**
* fetching all the emails allowed to
* check for mails to read tickets
*/
$email = new Emails;
$mailboxes = $email->get();
//check for any value in $mailbox
if (count($mailboxes) >= 0) {
foreach ($mailboxes as $current_mailbox) {
//checking for fetching status of the emails
if ($current_mailbox['fetching_status']) {
/**
*@imap_open requres three arguments for
* reading mails in each emails
*
* 1. Host
* 2. email address
* 3. password
*/
$stream = @imap_open($current_mailbox['fetching_host'], $current_mailbox['email_address'], $current_mailbox['password']);
/**
* @var $testvar type string
*/
$testvar = "";
// checking for any result in imap_open with value
if ($stream >= 0) {
$emails = imap_search($stream, 'SINCE ' . date('d-M-Y', strtotime("-10 day")));
/**
* @imap_search requires two arguments to check
* from when to check for mails
*
* 1. result of @imap_open $stream
* 2. date in negative
*/
$emails = imap_search($stream, 'SINCE ' . date('d-M-Y', strtotime("-1 day")));
// checking if $emails has received any value
if ($emails != false) {
// count for mails
if (count($emails) >= 0) {
rsort($emails);
foreach ($emails as $email_id) {
/**
* @imap_fetch_overview requires three arguments to check
* the overview of each mails
*
* 1. result of @imap_open $stream
* 2. emails numbers $emails_id
* 3. and a 0 value
*/
$overview = imap_fetch_overview($stream, $email_id, 0);
$var = $overview[0]->seen ? 'read' : 'unread';
if ($var == 'unread') {
// check for unread messages
if ($var == 'read') {
$testvar = 'set';
/**
* fetching overview details fo each mails
*
* 1. from address
* 2. subject
* 3. date and time
*/
$from = $this->decode_imap_text($overview[0]->from);
$subject = $this->decode_imap_text($overview[0]->subject);
$datetime = $overview[0]->date;
// separate date and time
$date_time = explode(" ", $datetime);
$date = $date_time[1] . "-" . $date_time[2] . "-" . $date_time[3] . " " . $date_time[4];
@@ -68,26 +133,31 @@ class MailController extends Controller {
// {
// 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();
$helptopic = $this->TicketController->default_helptopic();
$sla = $this->TicketController->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
//=================================================
/**
* There are 5 types of mail readable formats
*
* 1. Html
* 2. Alternative
* 3. Related
* 4. Mixed
*/
// checking if the format is Html
if ($structure->subtype == 'HTML') {
$body2 = imap_fetchbody($stream, $email_id, 1);
if ($body2 == null) {
@@ -98,10 +168,7 @@ class MailController extends Controller {
// echo $body;
// echo "0";
}
//=================================================
// ALTERNATIVE
//=================================================
// checking if the format is Alternative
if ($structure->subtype == 'ALTERNATIVE') {
if (isset($structure->parts)) {
$body2 = imap_fetchbody($stream, $email_id, 1.2);
@@ -113,10 +180,7 @@ class MailController extends Controller {
// echo $body[0];
}
}
//=================================================
// RELATED
//=================================================
// checking if the format is related
if ($structure->subtype == 'RELATED') {
if (isset($structure->parts)) {
$parts = $structure->parts;
@@ -126,10 +190,8 @@ class MailController extends Controller {
$body2 = imap_fetchbody($stream, $email_id, 1);
}
$body = quoted_printable_decode($body2);
foreach ($parts as $part) {
if ($parts[$i]) {
}
$i++;
if (isset($parts[$i])) {
@@ -142,7 +204,6 @@ class MailController extends Controller {
if (strtolower($object->attribute) == 'filename') {
$filename = $object->value;
}
}
}
if ($parts[$i]->ifparameters == 1) {
@@ -150,7 +211,6 @@ class MailController extends Controller {
if (strtolower($object->attribute) == 'name') {
$name = $object->value;
}
}
}
$body = str_replace($imageid, $filename, $body);
@@ -170,10 +230,7 @@ class MailController extends Controller {
}
}
}
//=================================================
// MIXED
//=================================================
//checking if the format is mixed
elseif ($structure->subtype == 'MIXED') {
if (isset($structure->parts)) {
$parts = $structure->parts;
@@ -188,7 +245,6 @@ class MailController extends Controller {
$body = quoted_printable_decode($body2);
}
}
// subtype = RELATED
if ($parts[0]->subtype == 'RELATED') {
if (isset($parts[0]->parts)) {
@@ -203,7 +259,6 @@ class MailController extends Controller {
$name = "";
foreach ($parts as $part) {
if ($parts[0]) {
}
$i++;
if (isset($parts[$i])) {
@@ -249,8 +304,8 @@ class MailController extends Controller {
// $ticket->body = $body2;
// $ticket->date = $datetime;
// $ticket->save();
if ($this->create_user($emailadd, $username, $subject, $body, $phone, $helptopic, $sla, $system) == true) {
$priority = '1';
if ($this->TicketController->create_user($emailadd, $username, $subject, $body, $phone, $helptopic, $sla, $priority, $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) {
@@ -270,10 +325,16 @@ class MailController extends Controller {
}
}
//======================================
// ATTACHMENT |Incomplete
//======================================
/**
* Get attachments data from mail
* @param type $structure
* @param type $stream
* @param type $email_id
* @param type $thread_id
* @return type bool
*/
public function get_attachment($structure, $stream, $email_id, $thread_id) {
// checking if the mails has attachments
if (isset($structure->parts) && count($structure->parts)) {
for ($i = 0; $i < count($structure->parts); $i++) {
$attachments[$i] = array(
@@ -281,7 +342,7 @@ class MailController extends Controller {
'filename' => '',
'name' => '',
'attachment' => '');
// checking for files
if ($structure->parts[$i]->ifdparameters) {
foreach ($structure->parts[$i]->dparameters as $object) {
if (strtolower($object->attribute) == 'filename') {
@@ -290,6 +351,7 @@ class MailController extends Controller {
}
}
}
// checking for files
if ($structure->parts[$i]->ifparameters) {
foreach ($structure->parts[$i]->parameters as $object) {
if (strtolower($object->attribute) == 'name') {
@@ -298,8 +360,12 @@ class MailController extends Controller {
}
}
}
/**
* All over again checking for the availability of attachment
*/
if ($attachments[$i]['is_attachment']) {
$attachments[$i]['attachment'] = imap_fetchbody($stream, $email_id, $i + 1);
// decoding if encoded in base64_encode format else quoted_printable_encode
if ($structure->parts[$i]->encoding == 3) {
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
} elseif ($structure->parts[$i]->encoding == 4) {
@@ -307,15 +373,19 @@ class MailController extends Controller {
}
}
}
// calling the save method to save each attachments
if ($this->save_attcahments($attachments, $thread_id) == true) {
return true;
}
}
}
//=====================================
// SAVE ATTACHMENT | Incomplete
//=====================================
/**
* Function to save attachments
* @param type $attachments
* @param type $thread_id
* @return type bool
*/
public function save_attcahments($attachments, $thread_id) {
if (count($attachments) != 0) {
foreach ($attachments as $at) {
@@ -324,7 +394,6 @@ class MailController extends Controller {
$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']);
@@ -334,300 +403,11 @@ class MailController extends Controller {
$ticket_Thread->name = $filename;
$ticket_Thread->size = $filesize;
$ticket_Thread->type = $ext;
$ticket_Thread->content = $fp; //$content;
$ticket_Thread->content = $fp;
$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;
// }
}

View File

@@ -1,4 +1,6 @@
<?php namespace App\Http\Controllers\Agent;
<?php
namespace App\Http\Controllers\Agent;
use App\Http\Controllers\Controller;
use App\Http\Requests\OrganizationRequest;
@@ -11,10 +13,24 @@ use App\Model\Agent_panel\Organization;
/* Define OrganizationUpdate to validate the create form */
/**
* OrganizationController
*
* @package Controllers
* @subpackage Controller
* @author Ladybird <info@ladybirdweb.com>
*/
class OrganizationController extends Controller {
/* Define constructor for authentication checking */
/**
* Create a new controller instance.
* constructor to check
* 1. authentication
* 2. user roles
* 3. roles must be agent
*
* @return void
*/
public function __construct() {
$this->middleware('auth');
$this->middleware('role.agent');
@@ -24,14 +40,13 @@ class OrganizationController extends Controller {
/**
* Display a listing of the resource.
*
* @return Response
* @param type Organization $org
* @return type Response
*/
public function index(Organization $org) {
try
{
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');
@@ -41,11 +56,10 @@ class OrganizationController extends Controller {
/**
* Show the form for creating a new resource.
*
* @return Response
* @return type Response
*/
public function create() {
try
{
try {
return view('themes.default1.agent.organization.create');
} catch (Exception $e) {
return view('404');
@@ -54,12 +68,12 @@ class OrganizationController extends Controller {
/**
* Store a newly created resource in storage.
*
* @return Response
* @param type Organization $org
* @param type OrganizationRequest $request
* @return type Response
*/
public function store(Organization $org, OrganizationRequest $request) {
try
{
try {
/* Insert the all input request to organization table */
/* Check whether function success or not */
@@ -79,15 +93,14 @@ class OrganizationController extends Controller {
/**
* Display the specified resource.
*
* @param int $id
* @return Response
* @param type $id
* @param type Organization $org
* @return type Response
*/
public function show($id, Organization $org) {
try
{
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) {
@@ -98,12 +111,12 @@ class OrganizationController extends Controller {
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
* @param type $id
* @param type Organization $org
* @return type Response
*/
public function edit($id, Organization $org) {
try
{
try {
/* select the field by id */
$orgs = $org->whereId($id)->first();
@@ -117,18 +130,17 @@ class OrganizationController extends Controller {
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
* @param type $id
* @param type Organization $org
* @param type OrganizationUpdate $request
* @return type Response
*/
public function update($id, Organization $org, OrganizationUpdate $request) {
try
{
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');
@@ -140,24 +152,20 @@ class OrganizationController extends Controller {
/* 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
* @param type int $id
* @return type Response
*/
public function destroy($id) {
try
{
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');

View File

@@ -1,4 +1,5 @@
<?php
namespace App\Http\Controllers\Agent;
use App\Http\Controllers\Controller;
@@ -6,89 +7,92 @@ 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;
/**
* TicketController
*
* @package Controllers
* @subpackage Controller
* @author Ladybird <info@ladybirdweb.com>
*/
class TicketController extends Controller {
/* Define constructor for Authentication Checking */
/**
* Create a new controller instance.
* @return type response
*/
public function __construct() {
$this->middleware('auth');
}
//============================================
// Ticket List | Incomplete
//============================================
/**
* Show the ticket list page
* @return type response
*/
public function ticket_list() {
// $tickets = Tickets::all();
// $threads = Ticket_Thread::all();
return view('themes.default1.agent.ticket.ticket');
}
//============================================
// Open Ticket List | Incomplete
//============================================
/**
* Show the Open ticket list page
* @return type response
*/
public function open_ticket_list() {
// $tickets = Tickets::all();
// $threads = Ticket_Thread::all();
return view('themes.default1.agent.ticket.open');
}
//============================================
// Open Ticket List | Incomplete
//============================================
/**
* Show the answered ticket list page
* @return type response
*/
public function answered_ticket_list() {
// $tickets = Tickets::all();
// $threads = Ticket_Thread::all();
return view('themes.default1.agent.ticket.answered');
}
//============================================
// Open Ticket List | Incomplete
//============================================
/**
* Show the Myticket list page
* @return type response
*/
public function myticket_ticket_list() {
// $tickets = Tickets::all();
// $threads = Ticket_Thread::all();
return view('themes.default1.agent.ticket.myticket');
}
//============================================
// Open Ticket List | Incomplete
//============================================
/**
* Show the Overdue ticket list page
* @return type response
*/
public function overdue_ticket_list() {
// $tickets = Tickets::all();
// $threads = Ticket_Thread::all();
return view('themes.default1.agent.ticket.overdue');
}
//============================================
// Open Ticket List | Incomplete
//============================================
/**
* Show the Closed ticket list page
* @return type response
*/
public function closed_ticket_list() {
// $tickets = Tickets::all();
// $threads = Ticket_Thread::all();
return view('themes.default1.agent.ticket.closed');
}
//============================================
// create Ticket | Incomplete
//============================================
/**
* Show the New ticket page
* @return type response
*/
public function newticket() {
// $tickets = Tickets::all();
// $threads = Ticket_Thread::all();
return view('themes.default1.agent.ticket.new');
}
//============================================
// post create ticket | Incomplete
//============================================
/**
* Save the data of new ticket and show the New ticket page with result
* @param type CreateTicketRequest $request
* @return type response
*/
public function post_newticket(CreateTicketRequest $request) {
$email = $request->input('email');
$fullname = $request->input('fullname');
@@ -103,26 +107,31 @@ class TicketController extends Controller {
$priority = $request->input('priority');
$phone = "";
$system = "";
//create user
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');
return Redirect('newticket')->with('fails', 'fails');
}
// echo $priority;
}
//============================================
// Thread | Incomplete
//============================================
/**
* Shows the ticket thread details
* @param type $id
* @return type response
*/
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
//============================================
/**
* Replying a ticket
* @param type Ticket_Thread $thread
* @param type TicketRequest $request
* @return type bool
*/
public function reply(Ticket_Thread $thread, TicketRequest $request) {
$thread->ticket_id = $request->input('ticket_ID');
$thread->poster = 'support';
@@ -131,27 +140,17 @@ class TicketController extends Controller {
$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
//============================================
/**
* Ticket edit and save ticket data
* @param type $ticket_id
* @param type Ticket_Thread $thread
* @return type bool
*/
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');
@@ -164,9 +163,11 @@ class TicketController extends Controller {
return 0;
}
//============================================
// Ticket print | Incomplete
//============================================
/**
* Print Ticket Details
* @param type $id
* @return type respponse
*/
public function ticket_print($id) {
$tickets = Tickets::where('id', '=', $id)->first();
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first();
@@ -174,9 +175,11 @@ class TicketController extends Controller {
return PDF::load($html)->show();
}
//============================================
// Generate Ticket Number | Incomplete
//============================================
/**
* Generates Ticket Number
* @param type $ticket_number
* @return type integer
*/
public function ticket_number($ticket_number) {
$number = $ticket_number;
$number = explode('-', $number);
@@ -202,9 +205,11 @@ class TicketController extends Controller {
return $number;
}
//=============================================
// Checking email availability | Complete
//=============================================
/**
* check email for dublicate entry
* @param type $email
* @return type bool
*/
public function check_email($email) {
$check = User::where('email', '=', $email)->first();
if ($check == true) {
@@ -214,37 +219,49 @@ class TicketController extends Controller {
}
}
//===============================================
// Create User | InComplete
//===============================================
/**
* Create User while creating ticket
* @param type $emailadd
* @param type $username
* @param type $subject
* @param type $body
* @param type $phone
* @param type $helptopic
* @param type $sla
* @param type $priority
* @param type $system
* @return type bool
*/
public function create_user($emailadd, $username, $subject, $body, $phone, $helptopic, $sla, $priority, $system) {
// define global variables
$email;
$username;
// check emails
$checkemail = $this->check_email($emailadd);
if ($checkemail == false) {
// Generate password
$password = $this->generateRandomString();
// create user
$user = new User;
$user->user_name = $username;
$user->email = $emailadd;
$user->password = Hash::make($password);
// mail user his/her 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');
})) {
// need to do something here....
}
}
} else {
$username = $checkemail->username;
$user_id = $checkemail->id;
}
$ticket_number = $this->check_ticket($user_id, $subject, $body, $helptopic, $sla, $priority);
// send ticket create details to user
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 . ']');
})) {
@@ -252,33 +269,43 @@ class TicketController extends Controller {
}
}
//============================================
// Select Default help_topic | Incomplete
//============================================
/**
* Default helptopic
* @return type string
*/
public function default_helptopic() {
$helptopic = "Support";
$helptopic = "1";
return $helptopic;
}
//============================================
// Select Default sla | Incomplete
//============================================
/**
* Default SLA plan
* @return type string
*/
public function default_sla() {
$sla = "12hours";
$sla = "1";
return $sla;
}
//============================================
// Select Default priority | Incomplete
//============================================
/**
* Default Priority
* @return type string
*/
public function default_priority() {
$priority = "important";
return $helptopic;
$priority = "1";
return $prioirty;
}
//============================================
// check ticket | Incomplete
//============================================
/**
* Check the response of the ticket
* @param type $user_id
* @param type $subject
* @param type $body
* @param type $helptopic
* @param type $sla
* @param type $priority
* @return type string
*/
public function check_ticket($user_id, $subject, $body, $helptopic, $sla, $priority) {
$read_ticket_number = substr($subject, 0, 6);
if ($read_ticket_number == 'Re: [~') {
@@ -305,9 +332,16 @@ class TicketController extends Controller {
}
}
//============================================
// Create Ticket | Incomplete
//============================================
/**
* Create Ticket
* @param type $user_id
* @param type $subject
* @param type $body
* @param type $helptopic
* @param type $sla
* @param type $priority
* @return type string
*/
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) {
@@ -328,9 +362,14 @@ class TicketController extends Controller {
}
}
//============================================
// Create Ticket | Incomplete
//============================================
/**
* Generate Ticket Thread
* @param type $subject
* @param type $body
* @param type $id
* @param type $user_id
* @return type
*/
public function ticket_thread($subject, $body, $id, $user_id) {
$thread = new Ticket_Thread;
$thread->user_id = $user_id;
@@ -343,9 +382,11 @@ class TicketController extends Controller {
}
}
//============================================
// Generate Random password | Incomplete
//============================================
/**
* Generate a random string for password
* @param type $length
* @return type string
*/
public function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
@@ -356,9 +397,12 @@ class TicketController extends Controller {
return $randomString;
}
//============================================
// Ticket Close | Incomplete
//============================================
/**
* function to Ticket Close
* @param type $id
* @param type Tickets $ticket
* @return type string
*/
public function close($id, Tickets $ticket) {
$ticket_status = $ticket->where('id', '=', $id)->first();
$ticket_status->status = 3;
@@ -366,9 +410,12 @@ class TicketController extends Controller {
return "your ticket" . $ticket_status->ticket_number . " has been closed";
}
//============================================
// Ticket resolve | Incomplete
//============================================
/**
* function to Ticket resolved
* @param type $id
* @param type Tickets $ticket
* @return type string
*/
public function resolve($id, Tickets $ticket) {
$ticket_status = $ticket->where('id', '=', $id)->first();
$ticket_status->status = 2;
@@ -376,9 +423,12 @@ class TicketController extends Controller {
return "your ticket" . $ticket_status->ticket_number . " has been resolved";
}
//============================================
// Ticket open | Incomplete
//============================================
/**
* function to Open Ticket
* @param type $id
* @param type Tickets $ticket
* @return type
*/
public function open($id, Tickets $ticket) {
$ticket_status = $ticket->where('id', '=', $id)->first();
$ticket_status->status = 1;
@@ -386,9 +436,12 @@ class TicketController extends Controller {
return "your ticket" . $ticket_status->ticket_number . " has been opened";
}
//============================================
// Ticket open | Incomplete
//============================================
/**
* Function to delete ticket
* @param type $id
* @param type Tickets $ticket
* @return type string
*/
public function delete($id, Tickets $ticket) {
$ticket_delete = $ticket->where('id', '=', $id)->first();
$ticket_delete->is_deleted = 0;
@@ -397,9 +450,12 @@ class TicketController extends Controller {
return "your ticket" . $ticket_delete->ticket_number . " has been delete";
}
//============================================
// ban email | Incomplete
//============================================
/**
* Function to ban an email
* @param type $id
* @param type Tickets $ticket
* @return type string
*/
public function ban($id, Tickets $ticket) {
$ticket_ban = $ticket->where('id', '=', $id)->first();
$ban_email = $ticket_ban->user_id;
@@ -417,9 +473,11 @@ class TicketController extends Controller {
return "the user has been banned";
}
//============================================
// Ticket Assign | Incomplete
//============================================
/**
* function to assign ticket
* @param type $id
* @return type bool
*/
public function assign($id) {
$UserEmail = Input::get('user');
// $UserEmail = 'sujitprasad12@yahoo.in';
@@ -431,12 +489,13 @@ class TicketController extends Controller {
return 1;
}
//============================================
// Internal Note | Incomplete
//============================================
/**
* Function to post internal note
* @param type $id
* @return type bool
*/
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;
@@ -449,9 +508,11 @@ class TicketController extends Controller {
return 1;
}
//============================================
// Surrender ticket | Incomplete
//============================================
/**
* Function to surrender a ticket
* @param type $id
* @return type bool
*/
public function surrender($id) {
$ticket = Tickets::where('id', '=', $id)->first();
$ticket->assigned_to = 0;
@@ -459,41 +520,57 @@ class TicketController extends Controller {
return 1;
}
public function search() {
$product = Input::get('type');
$word = Input::get('name_startsWith');
/**
* function to search
* @return type
*/
// 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') {
// $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));
}
}
// 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));
// }
// }
/**
* shows trashed tickets
* @return type response
*/
public function trash() {
return view('themes.default1.agent.ticket.trash');
}
/**
* shows unassigned tickets
* @return type
*/
public function unassigned() {
return view('themes.default1.agent.ticket.unassigned');
}
/**
* shows tickets assigned to Auth::user()
* @return type
*/
public function myticket() {
return view('themes.default1.agent.ticket.myticket');
}

View File

@@ -1,4 +1,6 @@
<?php namespace App\Http\Controllers\Agent;
<?php
namespace App\Http\Controllers\Agent;
use App\Http\Controllers\Controller;
@@ -15,7 +17,6 @@ use App\Http\Requests\Sys_userRequest;
use App\Http\Requests\Sys_userUpdate;
/* include User Model */
use App\Model\Agent_panel\Sys_user;
/* include Help_topic Model */
/* Profile validator */
@@ -34,10 +35,24 @@ use Hash;
/* Validate post check ticket */
use Input;
/**
* UserController
*
* @package Controllers
* @subpackage Controller
* @author Ladybird <info@ladybirdweb.com>
*/
class UserController extends Controller {
/* Define constructor for Authentication Checking */
/**
* Create a new controller instance.
* constructor to check
* 1. authentication
* 2. user roles
* 3. roles must be agent
*
* @return void
*/
public function __construct() {
$this->middleware('auth');
$this->middleware('role.agent');
@@ -46,15 +61,13 @@ class UserController extends Controller {
/**
* Display a listing of the resource.
*
* @return Response
* @param type User $user
* @return type Response
*/
public function index(Sys_user $user) {
try
{
public function index(User $user) {
try {
/* get all values in Sys_user */
$users = $user->get();
$users = $user->where('role', '=', 'user')->get();
return view('themes.default1.agent.user.index', compact('users'));
} catch (Exception $e) {
return view('404');
@@ -63,12 +76,10 @@ class UserController extends Controller {
/**
* Show the form for creating a new resource.
*
* @return Response
* @return type Response
*/
public function create() {
try
{
try {
return view('themes.default1.agent.user.create');
} catch (Exception $e) {
return view('404');
@@ -77,17 +88,19 @@ class UserController extends Controller {
/**
* Store a newly created resource in storage.
*
* @return Response
* @param type User $user
* @param type Sys_userRequest $request
* @return type Response
*/
public function store(Sys_user $user, Sys_userRequest $request) {
try
{
public function store(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) {
$user->email = $request->input('email');
$user->user_name = $request->input('full_name');
$user->phone_number = $request->input('phone');
$user->role = 'user';
if ($user->save() == true) {
/* redirect to Index page with Success Message */
return redirect('user')->with('success', 'User Created Successfully');
} else {
@@ -98,21 +111,18 @@ class UserController extends Controller {
/* 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
* @param type int $id
* @param type User $user
* @return type Response
*/
public function show($id, Sys_user $user) {
try
{
public function show($id, 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');
@@ -121,38 +131,33 @@ class UserController extends Controller {
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
* @param type int $id
* @param type User $user
* @return type Response
*/
public function edit($id, Sys_user $user) {
try
{
public function edit($id, 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
* @param type int $id
* @param type User $user
* @param type Sys_userUpdate $request
* @return type Response
*/
public function update($id, Sys_user $user, Sys_userUpdate $request) {
try
{
public function update($id, 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');
@@ -164,24 +169,20 @@ class UserController extends Controller {
/* 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
* @param type int $id
* @param type User $user
* @return type Response
*/
public function destroy($id, Sys_user $user) {
try
{
public function destroy($id, 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');
@@ -194,57 +195,63 @@ class UserController extends Controller {
return redirect('user')->with('fails', 'User can not Delete');
}
}
/**
* get profile page
* @return type Response
*/
public function getProfile() {
$user = Auth::user();
return view('themes.default1.agent.user.profile', compact('user'));
}
/**
* post profile page
* @param type int $id
* @param type ProfileRequest $request
* @return type Response
*/
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');
}
}
/**
* Post profile password
* @param type int $id
* @param type ProfilePassword $request
* @return type Response
*/
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();
@@ -253,5 +260,4 @@ class UserController extends Controller {
return redirect('guest')->with('fails', 'Password was not Updated');
}
}
}