update v 1.0.7.5

This commit is contained in:
Sujit Prasad
2016-06-13 20:41:55 +05:30
parent aa9786d829
commit 283d97e3ea
5078 changed files with 339851 additions and 175995 deletions

View File

@@ -12,6 +12,7 @@ use App\Model\helpdesk\Agent_panel\Canned;
use App\User;
// classes
use Exception;
use Lang;
/**
* CannedController.
@@ -46,7 +47,11 @@ class CannedController extends Controller
*/
public function index()
{
return view('themes.default1.agent.helpdesk.canned.index');
try {
return view('themes.default1.agent.helpdesk.canned.index');
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
/**
@@ -56,7 +61,11 @@ class CannedController extends Controller
*/
public function create()
{
return view('themes.default1.agent.helpdesk.canned.create');
try {
return view('themes.default1.agent.helpdesk.canned.create');
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
/**
@@ -69,17 +78,17 @@ class CannedController extends Controller
*/
public function store(CannedRequest $request, Canned $canned)
{
// fetching all the requested inputs
$canned->user_id = \Auth::user()->id;
$canned->title = $request->input('title');
$canned->message = $request->input('message');
try {
// fetching all the requested inputs
$canned->user_id = \Auth::user()->id;
$canned->title = $request->input('title');
$canned->message = $request->input('message');
// saving inputs
$canned->save();
return redirect()->route('canned.list')->with('success', 'Added Successfully');
return redirect()->route('canned.list')->with('success', Lang::get('lang.added_successfully'));
} catch (Exception $e) {
return redirect()->route('canned.list')->with('fails', $e->errorInfo[2]);
return redirect()->route('canned.list')->with('fails', $e->getMessage());
}
}
@@ -93,10 +102,14 @@ class CannedController extends Controller
*/
public function edit($id, Canned $canned)
{
// fetching requested canned response
$canned = $canned->where('user_id', '=', \Auth::user()->id)->where('id', '=', $id)->first();
try {
// fetching requested canned response
$canned = $canned->where('user_id', '=', \Auth::user()->id)->where('id', '=', $id)->first();
return view('themes.default1.agent.helpdesk.canned.edit', compact('canned'));
return view('themes.default1.agent.helpdesk.canned.edit', compact('canned'));
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
/**
@@ -110,19 +123,19 @@ class CannedController extends Controller
*/
public function update($id, CannedUpdateRequest $request, Canned $canned)
{
/* select the field where id = $id(request Id) */
$canned = $canned->where('id', '=', $id)->where('user_id', '=', \Auth::user()->id)->first();
// fetching all the requested inputs
$canned->user_id = \Auth::user()->id;
$canned->title = $request->input('title');
$canned->message = $request->input('message');
try {
/* select the field where id = $id(request Id) */
$canned = $canned->where('id', '=', $id)->where('user_id', '=', \Auth::user()->id)->first();
// fetching all the requested inputs
$canned->user_id = \Auth::user()->id;
$canned->title = $request->input('title');
$canned->message = $request->input('message');
// saving inputs
$canned->save();
return redirect()->route('canned.list')->with('success', 'Updated Successfully');
return redirect()->route('canned.list')->with('success', Lang::get('lang.updated_successfully'));
} catch (Exception $e) {
return redirect()->route('canned.list')->with('fails', $e->errorInfo[2]);
return redirect()->route('canned.list')->with('fails', $e->getMessage());
}
}
@@ -136,17 +149,17 @@ class CannedController extends Controller
*/
public function destroy($id, Canned $canned)
{
/* select the field where id = $id(request Id) */
$canned = $canned->whereId($id)->first();
/* delete the selected field */
/* Check whether function success or not */
try {
/* select the field where id = $id(request Id) */
$canned = $canned->whereId($id)->first();
/* delete the selected field */
/* Check whether function success or not */
$canned->delete();
/* redirect to Index page with Success Message */
return redirect()->route('canned.list')->with('success', 'User Deleted Successfully');
return redirect()->route('canned.list')->with('success', Lang::get('lang.user_deleted_successfully'));
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect()->route('canned.list')->with('fails', $e->errorInfo[2]);
return redirect()->route('canned.list')->with('fails', $e->getMessage());
}
}

View File

@@ -100,4 +100,52 @@ class DashboardController extends Controller
// ->get();
// return $ticketlist;
}
public function userChartData($id, $date111 = '', $date122 = '')
{
$date11 = strtotime($date122);
$date12 = strtotime($date111);
if ($date11 && $date12) {
$date2 = $date12;
$date1 = $date11;
} else {
// generating current date
$date2 = strtotime(date('Y-m-d'));
$date3 = date('Y-m-d');
$format = 'Y-m-d';
// generating a date range of 1 month
$date1 = strtotime(date($format, strtotime('-1 month'.$date3)));
}
$return = '';
$last = '';
for ($i = $date1; $i <= $date2; $i = $i + 86400) {
$thisDate = date('Y-m-d', $i);
$user = User::whereId($id)->first();
if ($user->role == 'user') {
$created = \DB::table('tickets')->select('created_at')->where('user_id', '=', $id)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count();
$closed = \DB::table('tickets')->select('closed_at')->where('user_id', '=', $id)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count();
$reopened = \DB::table('tickets')->select('reopened_at')->where('user_id', '=', $id)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count();
} else {
$created = \DB::table('tickets')->select('created_at')->where('assigned_to', '=', $id)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count();
$closed = \DB::table('tickets')->select('closed_at')->where('assigned_to', '=', $id)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count();
$reopened = \DB::table('tickets')->select('reopened_at')->where('assigned_to', '=', $id)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count();
}
$value = ['date' => $thisDate, 'open' => $created, 'closed' => $closed, 'reopened' => $reopened];
$array = array_map('htmlentities', $value);
$json = html_entity_decode(json_encode($array));
$return .= $json.',';
}
$last = rtrim($return, ',');
$users = User::whereId($id)->first();
return '['.$last.']';
// $ticketlist = DB::table('tickets')
// ->select(DB::raw('MONTH(updated_at) as month'),DB::raw('SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END) as closed'),DB::raw('SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) as reopened'),DB::raw('SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) as open'),DB::raw('SUM(CASE WHEN status = 5 THEN 1 ELSE 0 END) as deleted'),
// DB::raw('count(*) as totaltickets'))
// ->groupBy('month')
// ->orderBy('month', 'asc')
// ->get();
// return $ticketlist;
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace App\Http\Controllers\Agent\helpdesk;
// controllers
use App\Http\Controllers\Controller;
// models
use App\User;
// classes
use Auth;
use DB;
use Exception;
use View;
/**
* DashboardController
* This controlleris used to fetch dashboard in the agent panel.
*
* @author Ladybird <info@ladybirdweb.com>
*/
class DashboardController2 extends Controller
{
/**
* Create a new controller instance.
* constructor to check
* 1. authentication
* 2. user roles
* 3. roles must be agent.
*
* @return void
*/
public function __construct()
{
// checking for authentication
$this->middleware('auth');
// checking if the role is agent
$this->middleware('role.agent');
}
/**
* Get the dashboard page.
*
* @return type view
*/
public function index()
{
// if(Auth::user()->role == "user"){
// return \Redirect::route('home');
// }
try {
return View::make('themes.default1.agent.helpdesk.dashboard.dashboard');
} catch (Exception $e) {
return View::make('themes.default1.agent.helpdesk.dashboard.dashboard');
}
}
/**
* Fetching dashboard graph data to implement graph.
*
* @return type Json
*/
public function ChartData($date111 = '', $date122 = '')
{
$date11 = strtotime($date122);
$date12 = strtotime($date111);
if ($date11 && $date12) {
$date2 = $date12;
$date1 = $date11;
} else {
// generating current date
$date2 = strtotime(date('Y-m-d'));
$date3 = date('Y-m-d');
$format = 'Y-m-d';
// generating a date range of 1 month
$date1 = strtotime(date($format, strtotime('-1 month'.$date3)));
}
$return = '';
$last = '';
for ($i = $date1; $i <= $date2; $i = $i + 86400) {
$thisDate = date('Y-m-d', $i);
$created = \DB::table('tickets')->select('created_at')->where('created_at', 'LIKE', '%'.$thisDate.'%')->count();
$closed = \DB::table('tickets')->select('closed_at')->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count();
$reopened = \DB::table('tickets')->select('reopened_at')->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count();
$value = ['date' => $thisDate, 'open' => $created, 'closed' => $closed, 'reopened' => $reopened];
$array = array_map('htmlentities', $value);
$json = html_entity_decode(json_encode($array));
$return .= $json.',';
}
$last = rtrim($return, ',');
return '['.$last.']';
// $ticketlist = DB::table('tickets')
// ->select(DB::raw('MONTH(updated_at) as month'),DB::raw('SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END) as closed'),DB::raw('SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) as reopened'),DB::raw('SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) as open'),DB::raw('SUM(CASE WHEN status = 5 THEN 1 ELSE 0 END) as deleted'),
// DB::raw('count(*) as totaltickets'))
// ->groupBy('month')
// ->orderBy('month', 'asc')
// ->get();
// return $ticketlist;
}
}

View File

@@ -27,16 +27,16 @@ use PhpImap\Mailbox as ImapMailbox;
*
* @author Ladybird <info@ladybirdweb.com>
*/
class MailController extends Controller
{
class MailController extends Controller {
/**
* constructor
* Create a new controller instance.
*
* @param type TicketController $TicketController
*/
public function __construct(TicketWorkflowController $TicketWorkflowController)
{
public function __construct(TicketWorkflowController $TicketWorkflowController) {
$this->middleware('board');
$this->TicketWorkflowController = $TicketWorkflowController;
}
@@ -45,8 +45,7 @@ class MailController extends Controller
*
* @return type
*/
public function readmails(Emails $emails, Email $settings_email, System $system, Ticket $ticket)
{
public function readmails(Emails $emails, Email $settings_email, System $system, Ticket $ticket) {
// $path_url = $system->first()->url;
if ($settings_email->first()->email_fetching == 1) {
if ($settings_email->first()->all_emails == 1) {
@@ -81,7 +80,7 @@ class MailController extends Controller
$protocol = $fetching_encryption2;
} else {
if ($e_mail->fetching_protocol) {
$fetching_protocol = '/'.$e_mail->fetching_protocol;
$fetching_protocol = '/' . $e_mail->fetching_protocol;
} else {
$fetching_protocol = '';
}
@@ -90,13 +89,13 @@ class MailController extends Controller
} else {
$fetching_encryption = '';
}
$protocol = $fetching_protocol.$fetching_encryption;
$protocol = $fetching_protocol . $fetching_encryption;
}
$imap_config = '{'.$host.':'.$port.$protocol.'}INBOX';
$imap_config = '{' . $host . ':' . $port . $protocol . '}INBOX';
$password = Crypt::decrypt($e_mail->password);
$mailbox = new ImapMailbox($imap_config, $e_mail->email_address, $password, __DIR__);
$mails = [];
$mailsIds = $mailbox->searchMailBox('SINCE '.date('d-M-Y', strtotime('-1 day')));
$mailsIds = $mailbox->searchMailBox('SINCE ' . date('d-M-Y', strtotime('-1 day')));
if (!$mailsIds) {
die('Mailbox is empty');
}
@@ -111,14 +110,32 @@ class MailController extends Controller
$collaborator = null;
}
$body = $mail->textHtml;
if ($body == null) {
$body = $mailbox->backup_getmail($mailId);
$body = str_replace('\r\n', '<br/>', $body);
if ($body != null) {
$body = self::trimTableTag($body);
}
// if mail body has no messages fetch backup mail
if ($body == null) {
$body = $mail->textPlain;
}
if ($body == null) {
$attach = $mail->getAttachments();
$path = $attach['html-body']->filePath;
if ($path == null) {
$path = $attach['text-body']->filePath;
}
$body = file_get_contents($path);
//dd($body);
$body = self::trimTableTag($body);
}
// if ($body == null) {
// $body = $mailbox->backup_getmail($mailId);
// $body = str_replace('\r\n', '<br/>', $body);
// }
$date = $mail->date;
$datetime = $overview[0]->date;
$date_time = explode(' ', $datetime);
$date = $date_time[1].'-'.$date_time[2].'-'.$date_time[3].' '.$date_time[4];
$date = $date_time[1] . '-' . $date_time[2] . '-' . $date_time[3] . ' ' . $date_time[4];
$date = date('Y-m-d H:i:s', strtotime($date));
if (isset($mail->subject)) {
$subject = $mail->subject;
@@ -130,19 +147,19 @@ class MailController extends Controller
$ticket_source = Ticket_source::where('name', '=', 'email')->first();
$source = $ticket_source->id;
$phone = '';
$phonecode = '';
$mobile_number = '';
$assign = $get_helptopic->auto_assign;
$form_data = null;
$team_assign = null;
$ticket_status = null;
$result = $this->TicketWorkflowController->workflow($fromaddress, $fromname, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response);
$result = $this->TicketWorkflowController->workflow($fromaddress, $fromname, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response);
// dd($result);
if ($result[1] == true) {
$ticket_table = Tickets::where('ticket_number', '=', $result[0])->first();
$thread_id = Ticket_Thread::where('ticket_id', '=', $ticket_table->id)->max('id');
// $thread_id = Ticket_Thread::whereRaw('id = (select max(`id`) from ticket_thread)')->first();
$thread_id = $thread_id;
foreach ($mail->getAttachments() as $attachment) {
$support = 'support';
// echo $_SERVER['DOCUMENT_ROOT'];
@@ -153,7 +170,7 @@ class MailController extends Controller
// var_dump($attachment->filePath);
// dd($filepath);
// $path = $dir_img_path[0]."/code/public/".$filepath[1];
$path = public_path().$filepath[1];
$path = public_path() . $filepath[1];
// dd($path);
$filesize = filesize($path);
$file_data = file_get_contents($path);
@@ -162,9 +179,8 @@ class MailController extends Controller
$string = str_replace('-', '', $attachment->name);
$filename = explode('src', $attachment->filePath);
$filename = str_replace('\\', '', $filename);
$body = str_replace('cid:'.$imageid, $filepath[1], $body);
$body = str_replace('cid:' . $imageid, $filepath[1], $body);
$pos = strpos($body, $filepath[1]);
if ($pos == false) {
if ($settings_email->first()->attachment == 1) {
$upload = new Ticket_attachments();
@@ -208,8 +224,7 @@ class MailController extends Controller
*
* @return type string
*/
public function separate_reply($body)
{
public function separate_reply($body) {
$body2 = explode('---Reply above this line---', $body);
$body3 = $body2[0];
@@ -223,8 +238,7 @@ class MailController extends Controller
*
* @return type string
*/
public function decode_imap_text($str)
{
public function decode_imap_text($str) {
$result = '';
$decode_header = imap_mime_header_decode($str);
foreach ($decode_header as $obj) {
@@ -239,8 +253,7 @@ class MailController extends Controller
*
* @return type
*/
public function fetch_attachments()
{
public function fetch_attachments() {
$uploads = Upload::all();
foreach ($uploads as $attachment) {
$image = @imagecreatefromstring($attachment->file);
@@ -248,8 +261,8 @@ class MailController extends Controller
imagejpeg($image, null, 80);
$data = ob_get_contents();
ob_end_clean();
$var = '<a href="" target="_blank"><img src="data:image/jpg;base64,'.base64_encode($data).'"/></a>';
echo '<br/><span class="mailbox-attachment-icon has-img">'.$var.'</span>';
$var = '<a href="" target="_blank"><img src="data:image/jpg;base64,' . base64_encode($data) . '"/></a>';
echo '<br/><span class="mailbox-attachment-icon has-img">' . $var . '</span>';
}
}
@@ -260,14 +273,42 @@ class MailController extends Controller
*
* @return type file
*/
public function get_data($id)
{
public function get_data($id) {
$attachments = App\Model\helpdesk\Ticket\Ticket_attachments::where('id', '=', $id)->get();
foreach ($attachments as $attachment) {
header('Content-type: application/'.$attachment->type.'');
header('Content-Disposition: inline; filename='.$attachment->name.'');
header('Content-type: application/' . $attachment->type . '');
header('Content-Disposition: inline; filename=' . $attachment->name . '');
header('Content-Transfer-Encoding: binary');
echo $attachment->file;
}
}
public static function trimTableTag($html) {
if (strpos('<table>', $html) != false) {
$first_pos = strpos($html, '<table');
$fist_string = substr_replace($html, '', 0, $first_pos);
$last_pos = strrpos($fist_string, '</table>', -1);
$total = strlen($fist_string);
$diff = $total - $last_pos;
$str = substr_replace($fist_string, '', $last_pos, -1);
$final_str = str_finish($str, '</table>');
return $final_str;
}
return $html;
}
public static function trim3D($html) {
$body = str_replace('=3D', '', $html);
return $body;
}
public static function trimInjections($html, $tags = ['<script>', '</script>', '<style>', '</style>', '<?php', '?>']) {
$replace = [];
foreach ($tags as $key => $tag) {
$replace[$key] = htmlspecialchars($tag);
}
$body = str_replace($tags, $replace, $html);
return $body;
}
}

View File

@@ -11,10 +11,12 @@ use App\Http\Requests\helpdesk\OrganizationUpdate;
// models
/* Define OrganizationRequest to validate the create form */
use App\Model\helpdesk\Agent_panel\Organization;
/* Define OrganizationUpdate to validate the create form */
use App\Model\helpdesk\Agent_panel\User_org;
/* Define OrganizationUpdate to validate the create form */
use App\User;
// classes
use Exception;
use Lang;
/**
* OrganizationController
@@ -54,7 +56,7 @@ class OrganizationController extends Controller
/* get all values of table organization */
return view('themes.default1.agent.helpdesk.organization.index');
} catch (Exception $e) {
return view('404');
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -131,7 +133,7 @@ class OrganizationController extends Controller
try {
return view('themes.default1.agent.helpdesk.organization.create');
} catch (Exception $e) {
return view('404');
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -150,14 +152,14 @@ class OrganizationController extends Controller
/* 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');
return redirect('organizations')->with('success', Lang::get('lang.organization_created_successfully'));
} else {
/* redirect to Index page with Fails Message */
return redirect('organizations')->with('fails', 'Organization can not Create');
return redirect('organizations')->with('fails', Lang::get('lang.organization_can_not_create'));
}
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('organizations')->with('fails', 'Organization can not Create');
return redirect('organizations')->with('fails', Lang::get('lang.organization_can_not_create'));
}
}
@@ -177,7 +179,7 @@ class OrganizationController extends Controller
/* To view page */
return view('themes.default1.agent.helpdesk.organization.show', compact('orgs'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -197,7 +199,7 @@ class OrganizationController extends Controller
/* To view page */
return view('themes.default1.agent.helpdesk.organization.edit', compact('orgs'));
} catch (Exception $e) {
return view('404');
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -212,22 +214,22 @@ class OrganizationController extends Controller
*/
public function update($id, Organization $org, OrganizationUpdate $request)
{
/* select the field by id */
$orgs = $org->whereId($id)->first();
/* update the organization table */
/* Check whether function success or not */
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');
return redirect('organizations')->with('success', Lang::get('lang.organization_updated_successfully'));
} else {
/* redirect to Index page with Fails Message */
return redirect('organizations')->with('fails', 'Organization can not Update');
return redirect('organizations')->with('fails', Lang::get('lang.organization_can_not_update'));
}
} catch (Exception $e) {
// dd($e);
/* redirect to Index page with Fails Message */
return redirect('organizations')->with('fails', $e->errorInfo[2]);
return redirect('organizations')->with('fails', $e->getMessage());
}
}
@@ -240,22 +242,21 @@ class OrganizationController extends Controller
*/
public function destroy($id, Organization $org, User_org $user_org)
{
/* select the field by id */
$orgs = $org->whereId($id)->first();
$user_orgs = $user_org->where('org_id', '=', $id)->get();
foreach ($user_orgs as $user_org) {
$user_org->delete();
}
/* Delete the field selected from the table */
/* Check whether function success or not */
try {
/* select the field by id */
$orgs = $org->whereId($id)->first();
$user_orgs = $user_org->where('org_id', '=', $id)->get();
foreach ($user_orgs as $user_org) {
$user_org->delete();
}
/* Delete the field selected from the table */
/* Check whether function success or not */
$orgs->delete();
/* redirect to Index page with Success Message */
return redirect('organizations')->with('success', 'Organization Deleted Successfully');
return redirect('organizations')->with('success', Lang::get('lang.organization_deleted_successfully'));
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('organizations')->with('fails', $e->errorInfo[2]);
return redirect('organizations')->with('fails', $e->getMessage());
}
}
@@ -278,4 +279,53 @@ class OrganizationController extends Controller
return 1;
}
/**
* get the report of organizations.
*
* @param type $id
* @param type $date111
* @param type $date122
*
* @return type array
*/
public function orgChartData($id, $date111 = '', $date122 = '')
{
$date11 = strtotime($date122);
$date12 = strtotime($date111);
if ($date11 && $date12) {
$date2 = $date12;
$date1 = $date11;
} else {
// generating current date
$date2 = strtotime(date('Y-m-d'));
$date3 = date('Y-m-d');
$format = 'Y-m-d';
// generating a date range of 1 month
$date1 = strtotime(date($format, strtotime('-1 month'.$date3)));
}
$return = '';
$last = '';
for ($i = $date1; $i <= $date2; $i = $i + 86400) {
$thisDate = date('Y-m-d', $i);
$user_orga_relation_id = '';
$user_orga_relations = User_org::where('org_id', '=', $id)->get();
foreach ($user_orga_relations as $user_orga_relation) {
$user_orga_relation_id[] = $user_orga_relation->user_id;
}
$created = \DB::table('tickets')->select('created_at')->whereIn('user_id', $user_orga_relation_id)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count();
$closed = \DB::table('tickets')->select('closed_at')->whereIn('user_id', $user_orga_relation_id)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count();
$reopened = \DB::table('tickets')->select('reopened_at')->whereIn('user_id', $user_orga_relation_id)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count();
$value = ['date' => $thisDate, 'open' => $created, 'closed' => $closed, 'reopened' => $reopened];
$array = array_map('htmlentities', $value);
$json = html_entity_decode(json_encode($array));
$return .= $json.',';
}
$last = rtrim($return, ',');
$users = User::whereId($id)->first();
return '['.$last.']';
}
}

View File

@@ -9,8 +9,8 @@ use App\Http\Controllers\Controller;
// requests
use App\Http\Requests\helpdesk\CreateTicketRequest;
use App\Http\Requests\helpdesk\TicketRequest;
// models
use App\Model\helpdesk\Agent\Department;
// models
use App\Model\helpdesk\Agent\Teams;
use App\Model\helpdesk\Email\Emails;
use App\Model\helpdesk\Form\Fields;
@@ -28,14 +28,18 @@ use App\Model\helpdesk\Ticket\Ticket_source;
use App\Model\helpdesk\Ticket\Ticket_Status;
use App\Model\helpdesk\Ticket\Ticket_Thread;
use App\Model\helpdesk\Ticket\Tickets;
use App\Model\helpdesk\Utility\CountryCode;
use App\Model\helpdesk\Utility\Date_time_format;
use App\Model\helpdesk\Utility\Timezones;
use App\User;
use Auth;
use DB;
use Exception;
use ForceUTF8\Encoding;
use GeoIP;
// classes
use Hash;
use Illuminate\Http\Request;
use Illuminate\support\Collection;
use Input;
use Lang;
@@ -160,6 +164,11 @@ class TicketController extends Controller
return view('themes.default1.agent.helpdesk.ticket.overdue');
}
/**
* Ajax response overdue tickets.
*
* @return type json
*/
public function getOverdueTickets()
{
if (Auth::user()->role == 'agent') {
@@ -242,9 +251,12 @@ class TicketController extends Controller
*
* @return type response
*/
public function newticket()
public function newticket(CountryCode $code)
{
return view('themes.default1.agent.helpdesk.ticket.new');
$location = GeoIP::getLocation();
$phonecode = $code->where('iso', '=', $location['isoCode'])->first();
return view('themes.default1.agent.helpdesk.ticket.new')->with('phonecode', $phonecode->phonecode);
}
/**
@@ -254,7 +266,7 @@ class TicketController extends Controller
*
* @return type response
*/
public function post_newticket(CreateTicketRequest $request)
public function post_newticket(CreateTicketRequest $request, CountryCode $code)
{
try {
$email = $request->input('email');
@@ -271,15 +283,41 @@ class TicketController extends Controller
$body = $request->input('body');
$priority = $request->input('priority');
$phone = $request->input('phone');
$phonecode = $request->input('code');
$mobile_number = $request->input('mobile');
$source = Ticket_source::where('name', '=', 'agent')->first();
$headers = null;
$help = Help_topic::where('id', '=', $helptopic)->first();
$form_data = null;
$auto_response = 0;
$status = 1;
if ($phone != null || $mobile_number != null) {
$location = GeoIP::getLocation();
$geoipcode = $code->where('iso', '=', $location['isoCode'])->first();
if ($phonecode == null) {
$data = [
'fails' => Lang::get('lang.country-code-required-error'),
'phonecode' => $geoipcode->phonecode,
'country_code_error' => 1,
];
return Redirect()->back()->with($data)->withInput($request->except('password'));
} else {
$code = CountryCode::select('phonecode')->where('phonecode', '=', $phonecode)->get();
if (!count($code)) {
$data = [
'fails' => Lang::get('lang.incorrect-country-code-error'),
'phonecode' => $geoipcode->phonecode,
'country_code_error' => 1,
];
return Redirect()->back()->with($data)->withInput($request->except('password'));
}
}
}
//create user
if ($this->create_user($email, $fullname, $subject, $body, $phone, $helptopic, $sla, $priority, $source->id, $headers, $help->department, $assignto, $form_data, $auto_response, $status)) {
return Redirect('newticket')->with('success', 'Ticket created successfully!');
if ($this->create_user($email, $fullname, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source->id, $headers, $help->department, $assignto, $form_data, $auto_response, $status)) {
return Redirect('newticket')->with('success', Lang::get('lang.Ticket-created-successfully'));
} else {
return Redirect('newticket')->with('fails', 'fails');
}
@@ -549,12 +587,11 @@ class TicketController extends Controller
*
* @return type bool
*/
public function create_user($emailadd, $username, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $from_data, $auto_response, $status)
public function create_user($emailadd, $username, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $from_data, $auto_response, $status)
{
// define global variables
$email;
$username;
// check emails
$ticket_creator = $username;
$checkemail = $this->checkEmail($emailadd);
@@ -571,6 +608,7 @@ class TicketController extends Controller
$user->email = $emailadd;
$user->password = Hash::make($password);
$user->phone_number = $phone;
$user->country_code = $phonecode;
$user->role = 'user';
$user->active = '1';
// mail user his/her password
@@ -607,7 +645,6 @@ class TicketController extends Controller
} else {
$sign = $company;
}
if ($source == 3) {
try {
if ($auto_response == 0) {
@@ -667,7 +704,7 @@ class TicketController extends Controller
$emails_to_be_sent = array_unique($set_mails, SORT_REGULAR);
foreach ($emails_to_be_sent as $email_data) {
try {
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['user' => $email_data['to_user'], 'email' => $email_data['to_email']], $message = ['subject' => $updated_subject, 'body' => $body, 'scenario' => $mail], $template_variables = ['ticket_agent_name' => $email_data['to_user_name'], 'ticket_client_name' => $username, 'ticket_client_email' => $emailadd, 'user' => $email_data['to_user_name'], 'ticket_number' => $ticket_number2, 'email_address' => $emailadd, 'name' => $ticket_creator]);
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['user' => $email_data['to_user'], 'email' => $email_data['to_email']], $message = ['subject' => $updated_subject, 'body' => Encoding::fixUTF8($body), 'scenario' => $mail], $template_variables = ['ticket_agent_name' => $email_data['to_user_name'], 'ticket_client_name' => $username, 'ticket_client_email' => $emailadd, 'user' => $email_data['to_user_name'], 'ticket_number' => $ticket_number2, 'email_address' => $emailadd, 'name' => $ticket_creator]);
} catch (\Exception $e) {
}
}
@@ -870,6 +907,7 @@ class TicketController extends Controller
$thread->title = $subject;
$thread->body = $body;
if ($thread->save()) {
\Event::fire('ticket.details', ['ticket' => $thread]); //get the ticket details
return true;
}
}
@@ -925,7 +963,6 @@ class TicketController extends Controller
$ticket_number = $ticket_status->ticket_number;
$system_from = $this->company();
$sending_emails = Emails::where('department', '=', $ticket_status->dept_id)->first();
if ($sending_emails == null) {
$from_email = $this->system_mail();
@@ -1409,9 +1446,9 @@ class TicketController extends Controller
$ticket_collaborator->role = 'ccc';
$ticket_collaborator->save();
return '<div id="alert11" class="alert alert-dismissable" style="color:#60B23C;background-color:#F2F2F2;"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-check"></i>Success!</h4><h4><i class="icon fa fa-user"></i>'.$data->user_name.'</h4><div id="message-success1">'.$data->email.'</div></div>';
return '<div id="alert11" class="alert alert-dismissable" style="color:#60B23C;background-color:#F2F2F2;"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-check"></i>Success!</h4><h4><i class="icon fa fa-user"></i>'.$data->user_name.'</h4><div id="message-success1">'.$data->email.'</div></div>';
} else {
return '<div id="alert11" class="alert alert-warning alert-dismissable"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-warning"></i>'.$data->user_name.'</h4><div id="message-success1">'.$data->email.'<br/>This user already Collaborated</div></div>';
return '<div id="alert11" class="alert alert-warning alert-dismissable"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-warning"></i>'.$data->user_name.'</h4><div id="message-success1">'.$data->email.'<br/>This user already Collaborated</div></div>';
}
}
@@ -1429,7 +1466,7 @@ class TicketController extends Controller
$ticket_id = Input::get('ticket_id');
$user_search = User::where('email', '=', $email)->first();
if (isset($user_serach)) {
return '<div id="alert11" class="alert alert-warning alert-dismissable" ><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-alert"></i>Alert!</h4><div id="message-success1">This user already Exists</div></div>';
return '<div id="alert11" class="alert alert-warning alert-dismissable" ><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-alert"></i>Alert!</h4><div id="message-success1">This user already Exists</div></div>';
} else {
$company = $this->company();
$user = new User();
@@ -1451,7 +1488,7 @@ class TicketController extends Controller
$ticket_collaborator->role = 'ccc';
$ticket_collaborator->save();
return '<div id="alert11" class="alert alert-dismissable" style="color:#60B23C;background-color:#F2F2F2;"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-user"></i>'.$user->user_name.'</h4><div id="message-success1">'.$user->email.'</div></div>';
return '<div id="alert11" class="alert alert-dismissable" style="color:#60B23C;background-color:#F2F2F2;"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-user"></i>'.$user->user_name.'</h4><div id="message-success1">'.$user->email.'</div></div>';
}
}
@@ -1495,7 +1532,7 @@ class TicketController extends Controller
$ticket->closed = 0;
$ticket->closed_at = null;
$ticket->save();
} elseif ($value == 'Clean up') {
} elseif ($value == 'Delete forever') {
$thread = Ticket_Thread::where('ticket_id', '=', $ticket->id)->get();
foreach ($thread as $th_id) {
// echo $th_id->id." ";
@@ -1560,9 +1597,9 @@ class TicketController extends Controller
}
/**
*adding offset to updated_at time.
* adding offset to updated_at time.
*
*@return date
* @return date
*/
public static function timeOffset($utc)
{
@@ -1578,7 +1615,7 @@ class TicketController extends Controller
/**
* to get user date time format.
*
*@return string
* @return string
*/
public static function getDateTimeFormat()
{
@@ -1664,9 +1701,32 @@ class TicketController extends Controller
*
* @return type Redirect
*/
public function rating($id, $rating)
public function rating($id, Request $request, \App\Model\helpdesk\Ratings\RatingRef $rating_ref)
{
Tickets::where('id', $id)->update(['rating' => $rating]);
foreach ($request->all() as $key => $value) {
if (strpos($key, '_') !== false) {
$ratName = str_replace('_', ' ', $key);
} else {
$ratName = $key;
}
$ratID = \App\Model\helpdesk\Ratings\Rating::where('name', '=', $ratName)->first();
$ratingrefs = $rating_ref->where('rating_id', '=', $ratID->id)->where('ticket_id', '=', $id)->first();
if ($ratingrefs !== null) {
$ratingrefs->rating_id = $ratID->id;
$ratingrefs->ticket_id = $id;
$ratingrefs->thread_id = '0';
$ratingrefs->rating_value = $value;
$ratingrefs->save();
} else {
$rating_ref->rating_id = $ratID->id;
$rating_ref->ticket_id = $id;
$rating_ref->thread_id = '0';
$rating_ref->rating_value = $value;
$rating_ref->save();
}
}
return redirect()->back()->with('Success', 'Thank you for your rating!');
}
@@ -1676,17 +1736,37 @@ class TicketController extends Controller
*
* @return type Redirect
*/
public function ratingReply($id, $rating)
public function ratingReply($id, Request $request, \App\Model\helpdesk\Ratings\RatingRef $rating_ref)
{
$thread = Ticket_Thread::whereId($id)->first();
// $last_average = $thread->reply_rating;
//$total_numbers = $thread->rating_count;
//$new_number = $rating;
//$new_average = (($last_average * $total_numbers) + $new_number) / ($total_numbers + 1);
//$thread->rating_count += 1;
$thread->reply_rating = $rating;
$thread->save();
// $thread->set('rating_count', 'rating_count+1', FALSE)->update(['ratingreply' => $new_average]);
foreach ($request->all() as $key => $value) {
$key1 = explode(',', $key);
if (strpos($key1[0], '_') !== false) {
$ratName = str_replace('_', ' ', $key1[0]);
} else {
$ratName = $key1[0];
}
$ratID = \App\Model\helpdesk\Ratings\Rating::where('name', '=', $ratName)->first();
$ratingrefs = $rating_ref->where('rating_id', '=', $ratID->id)->where('thread_id', '=', $key1[1])->first();
if ($ratingrefs !== null) {
$ratingrefs->rating_id = $ratID->id;
$ratingrefs->ticket_id = $id;
$ratingrefs->thread_id = $key1[1];
$ratingrefs->rating_value = $value;
$ratingrefs->save();
} else {
$rating_ref->rating_id = $ratID->id;
$rating_ref->ticket_id = $id;
$rating_ref->thread_id = $key1[1];
$rating_ref->rating_value = $value;
$rating_ref->save();
}
}
return redirect()->back()->with('Success', 'Thank you for your rating!');
}
@@ -1721,7 +1801,14 @@ $thread->reply_rating = $rating;
$diff = round(abs($to_time - $from_time) / 60, 2);
if ($diff < $cad && Auth::user()->id != $ticket->lock_by) {
return 0; //ticket is locked
$user_data = User::select('user_name', 'first_name', 'last_name')->where('id', '=', $ticket->lock_by)->first();
if ($user_data->first_name != '') {
$name = $user_data->first_name.' '.$user_data->last_name;
} else {
$name = $user_data->username;
}
return Lang::get('lang.locked-ticket')." <a href='".route('user.show', $ticket->lock_by)."'>".$name.'</a>&nbsp;'.$diff.'&nbsp'.Lang::get('lang.minutes-ago'); //ticket is locked
} elseif ($diff < $cad && Auth::user()->id == $ticket->lock_by) {
$ticket = Tickets::where('id', '=', $id)->first();
$ticket->lock_at = date('Y-m-d H:i:s');
@@ -1798,8 +1885,8 @@ $thread->reply_rating = $rating;
if (Alert::first()->internal_status == 1 || Alert::first()->internal_assigned_agent == 1) {
// ticket assigned send mail
Mail::send('emails.Ticket_assign', ['agent' => $agent, 'ticket_number' => $ticket_number, 'from' => $company, 'master' => $master, 'system' => $system], function ($message) use ($agent_email, $agent, $ticket_number, $ticket_subject) {
$message->to($agent_email, $agent)->subject($ticket_subject.'[#'.$ticket_number.']');
});
$message->to($agent_email, $agent)->subject($ticket_subject.'[#'.$ticket_number.']');
});
}
return 1;
@@ -1821,15 +1908,14 @@ $thread->reply_rating = $rating;
$email = $email;
$ticket_id = $ticket_id;
$validator = \Validator::make(
['email' => $email,
'name' => $name, ],
['email' => 'required|email',
]
['email' => $email,
'name' => $name, ], ['email' => 'required|email',
]
);
$user = User::where('email', '=', $email)->first();
$count = count($user);
if ($count === 1) {
return 0;
return 0;
} elseif ($validator->fails()) {
return 2;
} else {
@@ -1863,7 +1949,7 @@ $thread->reply_rating = $rating;
} else {
$ticket = Tickets::select('user_id')->where('id', '=', $id)->first();
$ticket_data = Tickets::select('ticket_number', 'id')
->where('user_id', '=', $ticket->user_id)->where('id', '!=', $id)->where('status', '=', 1)->get();
->where('user_id', '=', $ticket->user_id)->where('id', '!=', $id)->where('status', '=', 1)->get();
foreach ($ticket_data as $value) {
$title = Ticket_Thread::select('title')->where('ticket_id', '=', $value->id)->first();
echo "<option value='$value->id'>".$title->title.'</option>';
@@ -1896,9 +1982,9 @@ $thread->reply_rating = $rating;
} else {
$ticket = Tickets::select('user_id')->where('id', '=', $id)->first();
$ticket_data = Tickets::select('ticket_number', 'id')
->where('user_id', '=', $ticket->user_id)
->where('id', '!=', $id)
->where('status', '=', 1)->get();
->where('user_id', '=', $ticket->user_id)
->where('id', '!=', $id)
->where('status', '=', 1)->get();
if (isset($ticket_data) && count($ticket_data) >= 1) {
return 1;
} else {
@@ -1936,13 +2022,13 @@ $thread->reply_rating = $rating;
$thread = Ticket_thread::where('ticket_id', '=', $value)->first();
$ticket = Tickets::select('ticket_number')->where('id', '=', $value)->first();
Ticket_thread::where('ticket_id', '=', $value)
->update(['ticket_id' => $p_id]);
->update(['ticket_id' => $p_id]);
Ticket_Form_Data::where('ticket_id', '=', $value)
->update(['ticket_id' => $p_id]);
->update(['ticket_id' => $p_id]);
Ticket_Collaborator::where('ticket_id', '=', $value)
->update(['ticket_id' => $p_id]);
->update(['ticket_id' => $p_id]);
Tickets::where('id', '=', $value)
->update(['status' => 3]);
->update(['status' => 3]);
if (!empty(Input::get('reason'))) {
$reason = Input::get('reason');
} else {
@@ -1950,7 +2036,7 @@ $thread->reply_rating = $rating;
}
if (!empty(Input::get('title'))) {
Ticket_thread::where('ticket_id', '=', $p_id)->first()
->update(['title' => Input::get('title')]);
->update(['title' => Input::get('title')]);
}
$new_thread = new Ticket_thread();
@@ -1961,8 +2047,8 @@ $thread->reply_rating = $rating;
$new_thread->is_internal = 0;
$new_thread->title = $thread->title;
$new_thread->body = Lang::get('lang.get_merge_message').
"&nbsp;&nbsp;<a href='".route('ticket.thread', [$p_id]).
"'>#".$parent_ticket->ticket_number.'</a><br><br><b>'.Lang::get('lang.merge-reason').'</b>'.$reason;
"&nbsp;&nbsp;<a href='".route('ticket.thread', [$p_id]).
"'>#".$parent_ticket->ticket_number.'</a><br><br><b>'.Lang::get('lang.merge-reason').':</b>&nbsp;&nbsp;'.$reason;
$new_thread->format = $thread->format;
$new_thread->ip_address = $thread->ip_address;
@@ -1973,7 +2059,7 @@ $thread->reply_rating = $rating;
$new_parent_thread->source = $parent_thread->source;
$new_parent_thread->is_internal = 1;
$new_parent_thread->title = $thread->title;
$new_parent_thread->body = Lang::get('lang.ticket')."&nbsp;<a href='".route('ticket.thread', [$value])."'>#".$ticket->ticket_number.'</a>&nbsp'.Lang::get('lang.ticket_merged').'<br><br><b>'.Lang::get('lang.merge-reason').'</b>'.$reason;
$new_parent_thread->body = Lang::get('lang.ticket')."&nbsp;<a href='".route('ticket.thread', [$value])."'>#".$ticket->ticket_number.'</a>&nbsp'.Lang::get('lang.ticket_merged').'<br><br><b>'.Lang::get('lang.merge-reason').':</b>&nbsp;&nbsp;'.$reason;
$new_parent_thread->format = $parent_thread->format;
$new_parent_thread->ip_address = $parent_thread->ip_address;
if ($new_thread->save() && $new_parent_thread->save()) {
@@ -1998,16 +2084,17 @@ $thread->reply_rating = $rating;
}
/*
*chumper's function to return data to chumper datatable.
*@param Array-object $tickets
* chumper's function to return data to chumper datatable.
* @param Array-object $tickets
*
*@return Array-object
* @return Array-object
*/
public static function getTable($tickets)
{
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
@@ -2063,8 +2150,9 @@ $thread->reply_rating = $rating;
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
$url = route('user.show', $ticket->user_id);
return "<a href='../user/".$ticket->user_id."' title='".Lang::get('lang.see-profile1').' '.ucfirst($from->user_name).'&apos;'.Lang::get('lang.see-profile2')."'><span style='color:#508983'>".ucfirst($from->user_name).'</span></a>';
return "<a href='".$url."' title='".Lang::get('lang.see-profile1').' '.ucfirst($from->user_name).'&apos;'.Lang::get('lang.see-profile2')."'><span style='color:#508983'>".ucfirst($from->user_name).'</span></a>';
})
// ->addColumn('Last Replier', function ($ticket) {
// $TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->where('is_internal', '=', 0)->max('id');
@@ -2080,7 +2168,6 @@ $thread->reply_rating = $rating;
// $username = $LastResponse->user_name;
// }
// }
// return "<a href='' title=''><span style='color:".$rep."'>".ucfirst($username).'</span></a>';
// })
->addColumn('assigned_to', function ($ticket) {
@@ -2088,8 +2175,9 @@ $thread->reply_rating = $rating;
return "<span style='color:red'>Unassigned</span>";
} else {
$assign = DB::table('users')->where('id', '=', $ticket->assigned_to)->first();
$url = route('user.show', $ticket->assigned_to);
return "<a href='../user/".$ticket->assigned_to."' title='".Lang::get('lang.see-profile1').' '.ucfirst($assign->first_name).'&apos;'.Lang::get('lang.see-profile2')."'><span style='color:green'>".ucfirst($assign->first_name).' '.ucfirst($assign->last_name).'</span></a>';
return "<a href='".$url."' title='".Lang::get('lang.see-profile1').' '.ucfirst($assign->first_name).'&apos;'.Lang::get('lang.see-profile2')."'><span style='color:green'>".ucfirst($assign->first_name).' '.ucfirst($assign->last_name).'</span></a>';
}
})
->addColumn('Last', function ($ticket) {
@@ -2103,4 +2191,42 @@ $thread->reply_rating = $rating;
->orderColumns('subject', 'from', 'assigned_to', 'Last Replier', 'ticket_number', 'priority', 'Last')
->make();
}
//Auto-close tickets
public function autoCloseTickets()
{
$workflow = \App\Model\helpdesk\Workflow\WorkflowClose::whereId(1)->first();
if ($workflow->condition == 1) {
$overdues = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->orderBy('id', 'DESC')->get();
if (count($overdues) == 0) {
$tickets = null;
} else {
$i = 0;
foreach ($overdues as $overdue) {
// $sla_plan = Sla_plan::where('id', '=', $overdue->sla)->first();
$ovadate = $overdue->created_at;
$new_date = date_add($ovadate, date_interval_create_from_date_string($workflow->days.' days')).'<br/><br/>';
if (date('Y-m-d H:i:s') > $new_date) {
$i++;
$overdue->status = 3;
$overdue->closed = 1;
$overdue->closed_at = date('Y-m-d H:i:s');
$overdue->save();
// if($workflow->send_email == 1) {
// $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $overdue->dept_id), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => $ticket_subject.'[#'.$ticket_number.']', 'scenario' => 'close-ticket'], $template_variables = ['ticket_number' => $ticket_number]);
// }
}
}
// dd(count($value));
// if ($i > 0) {
// $tickets = new collection($value);
// } else {
// $tickets = null;
// }
}
} else {
}
}
}

View File

@@ -40,7 +40,7 @@ class TicketWorkflowController extends Controller
*
* @return type response
*/
public function workflow($fromaddress, $fromname, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response)
public function workflow($fromaddress, $fromname, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response)
{
$contact_details = ['email' => $fromaddress, 'email_name' => $fromname, 'subject' => $subject, 'message' => $body];
$ticket_settings_details = ['help_topic' => $helptopic, 'sla' => $sla, 'priority' => $priority, 'source' => $source, 'dept' => $dept, 'assign' => $assign, 'team' => $team_assign, 'status' => $ticket_status, 'reject' => false];
@@ -169,7 +169,7 @@ class TicketWorkflowController extends Controller
if ($ticket_settings_details['reject'] == true) {
return ['0' => false, '1' => false];
} else {
$create_ticket = $this->TicketController->create_user($contact_details['email'], $contact_details['email_name'], $contact_details['subject'], $contact_details['message'], $phone, $ticket_settings_details['help_topic'], $ticket_settings_details['sla'], $ticket_settings_details['priority'], $source, $collaborator, $ticket_settings_details['dept'], $ticket_settings_details['assign'], $form_data, $auto_response, $ticket_settings_details['status']);
$create_ticket = $this->TicketController->create_user($contact_details['email'], $contact_details['email_name'], $contact_details['subject'], $contact_details['message'], $phone, $phonecode, $mobile_number, $ticket_settings_details['help_topic'], $ticket_settings_details['sla'], $ticket_settings_details['priority'], $source, $collaborator, $ticket_settings_details['dept'], $ticket_settings_details['assign'], $form_data, $auto_response, $ticket_settings_details['status']);
return $create_ticket;
}

View File

@@ -16,12 +16,15 @@ use App\Http\Requests\helpdesk\Sys_userUpdate;
// models
use App\Model\helpdesk\Agent_panel\Organization;
use App\Model\helpdesk\Agent_panel\User_org;
use App\Model\helpdesk\Utility\CountryCode;
use App\User;
// classes
use Auth;
use Exception;
use GeoIP;
use Hash;
use Input;
use Lang;
use Redirect;
/**
@@ -62,7 +65,7 @@ class UserController extends Controller
/* get all values in Sys_user */
return view('themes.default1.agent.helpdesk.user.index');
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -75,24 +78,24 @@ class UserController extends Controller
{
// displaying list of users with chumper datatables
return \Datatable::collection(User::where('role', '!=', 'admin')->where('role', '!=', 'agent')->get())
/* searchable column username and email*/
/* searchable column username and email */
->searchColumns('user_name', 'email', 'phone')
/* order column username and email */
->orderColumns('user_name', 'email')
/* column username */
->addColumn('user_name', function ($model) {
if (strlen($model->user_name) > 20) {
$username = substr($model->user_name, 0, 30);
$username = substr($username, 0, strrpos($username, ' ')).' ...';
$string = strip_tags($model->user_name);
if (strlen($string) > 10) {
// truncate string
$stringCut = substr($string, 0, 10);
} else {
$username = "<a href='".route('user.edit', $model->id)."'>".$model->user_name.'</a>';
$stringCut = $model->user_name;
}
return $username;
return $stringCut;
})
/* column email */
->addColumn('email', function ($model) {
$email = "<a href='".route('user.edit', $model->id)."'>".$model->email.'</a>';
$email = "<a href='".route('user.show', $model->id)."'>".$model->email.'</a>';
return $email;
})
@@ -150,10 +153,13 @@ class UserController extends Controller
*
* @return type view
*/
public function create()
public function create(CountryCode $code)
{
try {
return view('themes.default1.agent.helpdesk.user.create');
$location = GeoIP::getLocation('');
$phonecode = $code->where('iso', '=', $location['isoCode'])->first();
return view('themes.default1.agent.helpdesk.user.create')->with('phonecode', $phonecode->phonecode);
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
@@ -176,16 +182,25 @@ class UserController extends Controller
$user->mobile = $request->input('mobile');
$user->ext = $request->input('ext');
$user->phone_number = $request->input('phone_number');
$user->country_code = $request->input('country_code');
$user->active = $request->input('active');
$user->internal_note = $request->input('internal_note');
$user->role = 'user';
try {
if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) {
return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput();
} else {
$code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get();
if (!count($code)) {
return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput();
}
}
$user->save();
/* redirect to Index page with Success Message */
return redirect('user')->with('success', 'User Created Successfully');
return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully'));
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', $e->errorInfo[2]);
return redirect('user')->with('fails', $e->getMessage());
}
}
@@ -197,15 +212,16 @@ class UserController extends Controller
*
* @return type view
*/
public function show($id, User $user)
public function show($id)
{
try {
$user = new User();
/* select the field where id = $id(request Id) */
$users = $user->whereId($id)->first();
return view('themes.default1.agent.helpdesk.user.show', compact('users'));
} catch (Exception $e) {
return view('404');
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -217,15 +233,18 @@ class UserController extends Controller
*
* @return type Response
*/
public function edit($id, User $user)
public function edit($id, CountryCode $code)
{
try {
$user = new User();
/* select the field where id = $id(request Id) */
$users = $user->whereId($id)->first();
$location = GeoIP::getLocation('');
$phonecode = $code->where('iso', '=', $location['isoCode'])->first();
return view('themes.default1.agent.helpdesk.user.edit', compact('users'));
return view('themes.default1.agent.helpdesk.user.edit', compact('users'))->with('phonecode', $phonecode->phonecode);
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -238,19 +257,31 @@ class UserController extends Controller
*
* @return type Response
*/
public function update($id, User $user, Sys_userUpdate $request)
public function update($id, Sys_userUpdate $request)
{
$user = new User();
/* 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 */
try {
if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) {
return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput();
} else {
$code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get();
if (!count($code)) {
return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput();
} else {
$users->country_code = $request->country_code;
}
}
// dd($request->input());
$users->fill($request->input())->save();
/* redirect to Index page with Success Message */
return redirect('user')->with('success', 'User Updated Successfully');
return redirect('user')->with('success', Lang::get('lang.User-profile-Updated-Successfully'));
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -265,7 +296,7 @@ class UserController extends Controller
try {
return view('themes.default1.agent.helpdesk.user.profile', compact('user'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -274,13 +305,15 @@ class UserController extends Controller
*
* @return type view
*/
public function getProfileedit()
public function getProfileedit(CountryCode $code)
{
$user = Auth::user();
$location = GeoIP::getLocation('');
$phonecode = $code->where('iso', '=', $location['isoCode'])->first();
try {
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user'));
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user'))->with('phonecode', $phonecode->phonecode);
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -324,15 +357,24 @@ class UserController extends Controller
$user->profile_pic = $fileName;
} else {
try {
if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) {
return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput();
} else {
$code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get();
if (!count($code)) {
return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput();
}
$user->country_code = $request->country_code;
}
$user->fill($request->except('profile_pic', 'gender'))->save();
return Redirect::route('profile')->with('success', 'Profile Updated sucessfully');
return Redirect::route('profile')->with('success', Lang::get('lang.Profile-Updated-sucessfully'));
} catch (Exception $e) {
return Redirect::route('profile')->with('success', $e->errorInfo[2]);
return Redirect::route('profile')->with('success', $e->getMessage());
}
}
if ($user->fill($request->except('profile_pic'))->save()) {
return Redirect::route('profile')->with('success', 'Profile Updated sucessfully');
return Redirect::route('profile')->with('success', Lang::get('lang.Profile-Updated-sucessfully'));
}
}
@@ -354,12 +396,12 @@ class UserController extends Controller
try {
$user->save();
return redirect('profile-edit')->with('success1', 'Password Updated sucessfully');
return redirect('profile-edit')->with('success1', Lang::get('lang.password_updated_sucessfully'));
} catch (Exception $e) {
return redirect('profile-edit')->with('fails', $e->errorInfo[2]);
return redirect('profile-edit')->with('fails', $e->getMessage());
}
} else {
return redirect('profile-edit')->with('fails1', 'Password was not Updated. Incorrect old password');
return redirect('profile-edit')->with('fails1', Lang::get('lang.password_was_not_updated_incorrect_old_password'));
}
}
@@ -381,6 +423,25 @@ class UserController extends Controller
return 1;
}
public function orgAssignUser($id)
{
$org = Input::get('org');
$user_org = new User_org();
$user_org->org_id = $id;
$user_org->user_id = $org;
$user_org->save();
return 1;
}
public function removeUserOrg($id)
{
$user_org = User_org::where('org_id', '=', $id)->first();
$user_org->delete();
return redirect()->back()->with('success1', Lang::get('lang.the_user_has_been_removed_from_this_organization'));
}
/**
* creating an organization in user profile page via modal popup.
*

View File

@@ -0,0 +1,427 @@
<?php
namespace App\Http\Controllers\Agent\helpdesk;
// controllers
use App\Http\Controllers\Controller;
// requests
/* Include Sys_user Model */
use App\Http\Requests\helpdesk\ProfilePassword;
/* For validation include Sys_userRequest in create */
use App\Http\Requests\helpdesk\ProfileRequest;
/* For validation include Sys_userUpdate in update */
use App\Http\Requests\helpdesk\Sys_userRequest;
/* include guest_note model */
use App\Http\Requests\helpdesk\Sys_userUpdate;
// models
use App\Model\helpdesk\Agent_panel\Organization;
use App\Model\helpdesk\Agent_panel\User_org;
use App\User;
// classes
use Auth;
use Exception;
use Hash;
use Input;
use Redirect;
/**
* UserController
* This controller is used to CRUD an User details, and proile management of an agent.
*
* @author Ladybird <info@ladybirdweb.com>
*/
class UserController2 extends Controller
{
/**
* Create a new controller instance.
* constructor to check
* 1. authentication
* 2. user roles
* 3. roles must be agent.
*
* @return void
*/
public function __construct()
{
// checking authentication
$this->middleware('auth');
// checking if role is agent
$this->middleware('role.agent');
}
/**
* Display all list of the users.
*
* @param type User $user
*
* @return type view
*/
public function index()
{
try {
/* get all values in Sys_user */
return view('themes.default1.agent.helpdesk.user.index');
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* This function is used to display the list of users using chumper datatables.
*
* @return datatable
*/
public function user_list()
{
// displaying list of users with chumper datatables
return \Datatable::collection(User::where('role', '!=', 'admin')->where('role', '!=', 'agent')->get())
/* searchable column username and email*/
->searchColumns('user_name', 'email', 'phone')
/* order column username and email */
->orderColumns('user_name', 'email')
/* column username */
->addColumn('user_name', function ($model) {
if (strlen($model->user_name) > 20) {
$username = substr($model->user_name, 0, 30);
$username = substr($username, 0, strrpos($username, ' ')).' ...';
} else {
$username = "<a href='".route('user.edit', $model->id)."'>".$model->user_name.'</a>';
}
return $username;
})
/* column email */
->addColumn('email', function ($model) {
$email = "<a href='".route('user.edit', $model->id)."'>".$model->email.'</a>';
return $email;
})
/* column phone */
->addColumn('phone', function ($model) {
$phone = '';
if ($model->phone_number) {
$phone = $model->ext.' '.$model->phone_number;
}
$mobile = '';
if ($model->mobile) {
$mobile = $model->mobile;
}
$phone = $phone.'&nbsp;&nbsp;&nbsp;'.$mobile;
return $phone;
})
/* column account status */
->addColumn('status', function ($model) {
$status = $model->active;
if ($status == 1) {
$stat = '<button class="btn btn-success btn-xs">Active</button>';
} else {
$stat = '<button class="btn btn-danger btn-xs">Inactive</button>';
}
return $stat;
})
/* column ban status */
->addColumn('ban', function ($model) {
$status = $model->ban;
if ($status == 1) {
$stat = '<button class="btn btn-danger btn-xs">Banned</button>';
} else {
$stat = '<button class="btn btn-success btn-xs">Active</button>';
}
return $stat;
})
/* column last login date */
->addColumn('lastlogin', function ($model) {
$t = $model->updated_at;
return TicketController::usertimezone($t);
})
/* column actions */
->addColumn('Actions', function ($model) {
return '<a href="'.route('user.edit', $model->id).'" class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp; <a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>';
})
->make();
}
/**
* Show the form for creating a new users.
*
* @return type view
*/
public function create()
{
try {
return view('themes.default1.agent.helpdesk.user.create');
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* Store a newly created users in storage.
*
* @param type User $user
* @param type Sys_userRequest $request
*
* @return type redirect
*/
public function store(User $user, Sys_userRequest $request)
{
/* insert the input request to sys_user table */
/* Check whether function success or not */
$user->email = $request->input('email');
$user->user_name = $request->input('full_name');
$user->mobile = $request->input('mobile');
$user->ext = $request->input('ext');
$user->phone_number = $request->input('phone_number');
$user->active = $request->input('active');
$user->internal_note = $request->input('internal_note');
$user->role = 'user';
try {
$user->save();
/* redirect to Index page with Success Message */
return redirect('user')->with('success', 'User Created Successfully');
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', $e->errorInfo[2]);
}
}
/**
* Display the specified users.
*
* @param type int $id
* @param type User $user
*
* @return type view
*/
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.helpdesk.user.show', compact('users'));
} catch (Exception $e) {
return view('404');
}
}
/**
* Show the form for editing the specified resource.
*
* @param type int $id
* @param type User $user
*
* @return type Response
*/
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.helpdesk.user.edit', compact('users'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* Update the specified user in storage.
*
* @param type int $id
* @param type User $user
* @param type Sys_userUpdate $request
*
* @return type Response
*/
public function update($id, User $user, Sys_userUpdate $request)
{
/* 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 */
try {
$users->fill($request->input())->save();
/* redirect to Index page with Success Message */
return redirect('user')->with('success', 'User Updated Successfully');
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* get agent profile page.
*
* @return type view
*/
public function getProfile()
{
$user = Auth::user();
try {
return view('themes.default1.agent.helpdesk.user.profile', compact('user'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* get profile edit page.
*
* @return type view
*/
public function getProfileedit()
{
$user = Auth::user();
try {
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* post profile edit.
*
* @param type int $id
* @param type ProfileRequest $request
*
* @return type Redirect
*/
public function postProfileedit(ProfileRequest $request)
{
// geet authenticated user details
$user = Auth::user();
$user->gender = $request->input('gender');
$user->save();
// checking availability of agent profile ppicture
if ($user->profile_pic == 'avatar5.png' || $user->profile_pic == 'avatar2.png') {
if ($request->input('gender') == 1) {
$name = 'avatar5.png';
$destinationPath = 'lb-faveo/media/profilepic';
$user->profile_pic = $name;
} elseif ($request->input('gender') == 0) {
$name = 'avatar2.png';
$destinationPath = 'lb-faveo/media/profilepic';
$user->profile_pic = $name;
}
}
// checking if the post system includes agent profile picture upload
if (Input::file('profile_pic')) {
// fetching picture name
$name = Input::file('profile_pic')->getClientOriginalName();
// fetching upload destination path
$destinationPath = 'lb-faveo/media/profilepic';
// adding a random value to profile picture filename
$fileName = rand(0000, 9999).'.'.$name;
// moving the picture to a destination folder
Input::file('profile_pic')->move($destinationPath, $fileName);
// saving filename to database
$user->profile_pic = $fileName;
} else {
try {
$user->fill($request->except('profile_pic', 'gender'))->save();
return Redirect::route('profile')->with('success', 'Profile Updated sucessfully');
} catch (Exception $e) {
return Redirect::route('profile')->with('success', $e->errorInfo[2]);
}
}
if ($user->fill($request->except('profile_pic'))->save()) {
return Redirect::route('profile')->with('success', 'Profile Updated sucessfully');
}
}
/**
* Post profile password.
*
* @param type int $id
* @param type ProfilePassword $request
*
* @return type Redirect
*/
public function postProfilePassword($id, ProfilePassword $request)
{
// get authenticated user
$user = Auth::user();
// checking if the old password matches the new password
if (Hash::check($request->input('old_password'), $user->getAuthPassword())) {
$user->password = Hash::make($request->input('new_password'));
try {
$user->save();
return redirect('profile-edit')->with('success1', 'Password Updated sucessfully');
} catch (Exception $e) {
return redirect('profile-edit')->with('fails', $e->errorInfo[2]);
}
} else {
return redirect('profile-edit')->with('fails1', 'Password was not Updated. Incorrect old password');
}
}
/**
* Assigning an user to an organization.
*
* @param type $id
*
* @return type boolean
*/
public function UserAssignOrg($id)
{
$org = Input::get('org');
$user_org = new User_org();
$user_org->org_id = $org;
$user_org->user_id = $id;
$user_org->save();
return 1;
}
/**
* creating an organization in user profile page via modal popup.
*
* @param type $id
*
* @return type
*/
public function User_Create_Org($id)
{
// checking if the entered value for website is available in database
if (Input::get('website') != null) {
// checking website
$check = Organization::where('website', '=', Input::get('website'))->first();
} else {
$check = null;
}
// checking if the name is unique
$check2 = Organization::where('name', '=', Input::get('name'))->first();
// if any of the fields is not available then return false
if (\Input::get('name') == null) {
return 'Name is required';
} elseif ($check2 != null) {
return 'Name should be Unique';
} elseif ($check != null) {
return 'Website should be Unique';
} else {
// storing organization details and assigning the current user to that organization
$org = new Organization();
$org->name = Input::get('name');
$org->phone = Input::get('phone');
$org->website = Input::get('website');
$org->address = Input::get('address');
$org->internal_notes = Input::get('internal');
$org->save();
$user_org = new User_org();
$user_org->org_id = $org->id;
$user_org->user_id = $id;
$user_org->save();
// for success return 0
return 0;
}
}
}

View File

@@ -3,7 +3,6 @@
namespace App\Http\Controllers\Agent\kb;
// Controllers
use App\Http\Controllers\Agent\helpdesk\TicketController;
use App\Http\Controllers\Controller;
// Requests
use App\Http\Requests\kb\ArticleRequest;
@@ -21,16 +20,17 @@ use Datatable;
use DB;
use Exception;
use Illuminate\Http\Request;
use Lang;
use Redirect;
/**
* ArticleController
* This controller is used to CRUD Articles.
*
* @author Ladybird <info@ladybirdweb.com>
* @author Ladybird <info@ladybirdweb.com>
*/
class ArticleController extends Controller
{
class ArticleController extends Controller {
/**
* Create a new controller instance.
* constructor to check
@@ -40,8 +40,7 @@ class ArticleController extends Controller
*
* @return void
*/
public function __construct()
{
public function __construct() {
// checking authentication
$this->middleware('auth');
// checking roles
@@ -49,8 +48,7 @@ class ArticleController extends Controller
SettingsController::language();
}
public function test()
{
public function test() {
//$table = $this->setDatatable();
return view('themes.default1.agent.kb.article.test');
}
@@ -60,29 +58,37 @@ class ArticleController extends Controller
*
* @return type void
*/
public function getData()
{
public function getData() {
$article = new Article();
// returns chumper datatable
return Datatable::collection(Article::All())
return Datatable::query($article)
/* searcable column name */
->searchColumns('name')
/* order column name and description */
->orderColumns('name', 'description')
/* add column name */
->addColumn('name', function ($model) {
return $model->name;
$string = strip_tags($model->name);
if (strlen($string) > 40) {
// truncate string
$stringCut = substr($string, 0, 40);
} else {
$stringCut = $model->name;
}
return $stringCut . '...';
})
/* add column Created */
->addColumn('Created', function ($model) {
$t = $model->created_at;
->addColumn('publish_time', function ($model) {
$t = $model->publish_time;
return TicketController::usertimezone($t);
return $t;
})
/* add column action */
->addColumn('Actions', function ($model) {
/* here are all the action buttons and modal popup to delete articles with confirmations */
return '<span data-toggle="modal" data-target="#deletearticle'.$model->id.'"><a href="#" ><button class="btn btn-danger btn-xs"></a> '.\Lang::get('lang.delete').' </button></span>&nbsp;<a href=article/'.$model->id.'/edit class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp;<a href=show/'.$model->slug.' class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>
<div class="modal fade" id="deletearticle'.$model->id.'">
return '<span data-toggle="modal" data-target="#deletearticle' . $model->id . '"><a href="#" ><button class="btn btn-danger btn-xs"></a> ' . \Lang::get('lang.delete') . ' </button></span>&nbsp;<a href=article/' . $model->id . '/edit class="btn btn-warning btn-xs">' . \Lang::get('lang.edit') . '</a>&nbsp;<a href=show/' . $model->slug . ' class="btn btn-primary btn-xs">' . \Lang::get('lang.view') . '</a>
<div class="modal fade" id="deletearticle' . $model->id . '">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
@@ -90,11 +96,11 @@ class ArticleController extends Controller
<h4 class="modal-title">Are You Sure ?</h4>
</div>
<div class="modal-body">
'.$model->name.'
' . $model->name . '
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
<a href="article/delete/'.$model->slug.'"><button class="btn btn-danger">delete</button></a>
<a href="article/delete/' . $model->slug . '"><button class="btn btn-danger">delete</button></a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
@@ -108,13 +114,12 @@ class ArticleController extends Controller
*
* @return type view
*/
public function index()
{
public function index() {
/* show article list */
try {
return view('themes.default1.agent.kb.article.index');
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -125,15 +130,14 @@ class ArticleController extends Controller
*
* @return type view
*/
public function create(Category $category)
{
public function create(Category $category) {
/* get the attributes of the category */
$category = $category->lists('id', 'name');
/* get the create page */
try {
return view('themes.default1.agent.kb.article.create', compact('category'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -145,12 +149,11 @@ class ArticleController extends Controller
*
* @return type redirect
*/
public function store(Article $article, ArticleRequest $request)
{
public function store(Article $article, ArticleRequest $request) {
// requesting the values to store article data
$publishTime = $request->input('year').'-'.$request->input('month').'-'.$request->input('day').' '.$request->input('hour').':'.$request->input('minute').':00';
$publishTime = $request->input('year') . '-' . $request->input('month') . '-' . $request->input('day') . ' ' . $request->input('hour') . ':' . $request->input('minute') . ':00';
$sl = $request->input('slug');
$sl = $request->input('name');
$slug = str_slug($sl, '-');
$article->slug = $slug;
$article->publish_time = $publishTime;
@@ -166,9 +169,9 @@ class ArticleController extends Controller
try {
$article->fill($request->except('slug'))->save();
return redirect('article')->with('success', 'Article Inserted Successfully');
return redirect('article')->with('success', Lang::get('lang.article_inserted_successfully'));
} catch (Exception $e) {
return redirect('article')->with('fails', 'Article Not Inserted'.'<li>'.$e->errorInfo[2].'</li>');
return redirect('article')->with('fails', Lang::get('lang.article_not_inserted') . '<li>' . $e->getMessage() . '</li>');
}
}
@@ -182,8 +185,10 @@ class ArticleController extends Controller
*
* @return view
*/
public function edit($slug, Article $article, Relationship $relation, Category $category)
{
public function edit($slug) {
$article = new Article();
$relation = new Relationship();
$category = new Category();
$aid = $article->where('id', $slug)->first();
$id = $aid->id;
/* define the selected fields */
@@ -197,7 +202,7 @@ class ArticleController extends Controller
try {
return view('themes.default1.agent.kb.article.edit', compact('assign', 'article', 'category'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -211,10 +216,11 @@ class ArticleController extends Controller
*
* @return Response
*/
public function update($slug, Article $article, Relationship $relation, ArticleUpdate $request)
{
public function update($slug, ArticleUpdate $request) {
$article = new Article();
$relation = new Relationship();
$aid = $article->where('id', $slug)->first();
$publishTime = $request->input('year').'-'.$request->input('month').'-'.$request->input('day').' '.$request->input('hour').':'.$request->input('minute').':00';
$publishTime = $request->input('year') . '-' . $request->input('month') . '-' . $request->input('day') . ' ' . $request->input('hour') . ':' . $request->input('minute') . ':00';
$id = $aid->id;
$sl = $request->input('slug');
@@ -239,9 +245,9 @@ class ArticleController extends Controller
$article->publish_time = $publishTime;
$article->save();
return redirect('article')->with('success', 'Article Updated Successfully');
return redirect('article')->with('success', Lang::get('lang.article_updated_successfully'));
} catch (Exception $e) {
return redirect('article')->with('fails', 'Article Not Updated'.'<li>'.$e->errorInfo[2].'</li>');
return redirect('article')->with('fails', Lang::get('lang.article_not_updated') . '<li>' . $e->getMessage() . '</li>');
}
}
@@ -253,8 +259,7 @@ class ArticleController extends Controller
*
* @return Response
*/
public function destroy($slug, Article $article, Relationship $relation, Comment $comment)
{
public function destroy($slug, Article $article, Relationship $relation, Comment $comment) {
/* delete the selected article from the table */
$article = $article->where('slug', $slug)->first(); //get the selected article via id
$id = $article->id;
@@ -271,12 +276,12 @@ class ArticleController extends Controller
}
if ($article) {
if ($article->delete()) {//true:redirect to index page with success message
return Redirect::back()->with('success', 'Article Deleted Successfully');
return Redirect::back()->with('success', Lang::get('lang.article_deleted_successfully'));
} else { //redirect to index page with fails message
return Redirect::back()->with('fails', 'Article Not Deleted');
return Redirect::back()->with('fails', Lang::get('lang.article_not_deleted'));
}
} else {
return Redirect::back()->with('fails', 'Article can Not Deleted');
return Redirect::back()->with('fails', Lang::get('lang.article_can_not_deleted'));
}
}
@@ -288,8 +293,7 @@ class ArticleController extends Controller
*
* @return type
*/
public static function usertimezone($utc)
{
public static function usertimezone($utc) {
$user = Auth::user();
$tz = $user->timezone;
$set = Settings::whereId('1')->first();
@@ -300,4 +304,5 @@ class ArticleController extends Controller
$date = date($format, strtotime($utc) + $offset);
echo $date;
}
}

View File

@@ -14,16 +14,17 @@ use App\Model\kb\Relationship;
// Classes
use Datatable;
use Exception;
use Lang;
use Redirect;
/**
* CategoryController
* This controller is used to CRUD category.
*
* @author Ladybird <info@ladybirdweb.com>
* @author Ladybird <info@ladybirdweb.com>
*/
class CategoryController extends Controller
{
class CategoryController extends Controller {
/**
* Create a new controller instance.
* constructor to check
@@ -33,8 +34,7 @@ class CategoryController extends Controller
*
* @return void
*/
public function __construct()
{
public function __construct() {
// checking authentication
$this->middleware('auth');
// checking roles
@@ -49,14 +49,13 @@ class CategoryController extends Controller
*
* @return Response
*/
public function index()
{
public function index() {
/* get the view of index of the catogorys with all attributes
of category model */
try {
return view('themes.default1.agent.kb.category.index');
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -65,8 +64,7 @@ class CategoryController extends Controller
*
* @return type chumper datatable
*/
public function getData()
{
public function getData() {
/* fetching chumper datatables */
return Datatable::collection(Category::All())
/* search column name */
@@ -75,7 +73,15 @@ class CategoryController extends Controller
->orderColumns('name', 'description')
/* add column name */
->addColumn('name', function ($model) {
return $model->name;
$string = strip_tags($model->name);
if (strlen($string) > 40) {
// truncate string
$stringCut = substr($string, 0, 40);
} else {
$stringCut = $model->name;
}
return $stringCut.'...';
})
/* add column Created */
->addColumn('Created', function ($model) {
@@ -86,20 +92,20 @@ class CategoryController extends Controller
/* add column Actions */
/* there are action buttons and modal popup to delete a data column */
->addColumn('Actions', function ($model) {
return '<span data-toggle="modal" data-target="#deletecategory'.$model->slug.'"><a href="#" ><button class="btn btn-danger btn-xs"></a>'.\Lang::get('lang.delete').'</button></span>&nbsp;<a href=category/'.$model->id.'/edit class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp;<a href=article-list class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>
<div class="modal fade" id="deletecategory'.$model->slug.'">
return '<span data-toggle="modal" data-target="#deletecategory' . $model->slug . '"><a href="#" ><button class="btn btn-danger btn-xs"></a>' . \Lang::get('lang.delete') . '</button></span>&nbsp;<a href=category/' . $model->id . '/edit class="btn btn-warning btn-xs">' . \Lang::get('lang.edit') . '</a>&nbsp;<a href=article-list class="btn btn-primary btn-xs">' . \Lang::get('lang.view') . '</a>
<div class="modal fade" id="deletecategory' . $model->slug . '">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Are You Sure ?</h4>
<h4 class="modal-title">' . Lang::get('lang.are_you_sure_you_want_to_delete') . '</h4>
</div>
<div class="modal-body">
'.$model->name.'
' . $model->name . '
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
<a href="category/delete/'.$model->id.'"><button class="btn btn-danger">delete</button></a>
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">' . Lang::get('lang.close') . '</button>
<a href="category/delete/' . $model->id . '"><button class="btn btn-danger">' . Lang::get('lang.delete') . '</button></a>
</div>
</div>
</div>
@@ -115,8 +121,7 @@ class CategoryController extends Controller
*
* @return type view
*/
public function create(Category $category)
{
public function create(Category $category) {
/* Get the all attributes in the category model */
$category = $category->get();
/* get the view page to create new category with all attributes
@@ -124,7 +129,7 @@ class CategoryController extends Controller
try {
return view('themes.default1.agent.kb.category.create', compact('category'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -136,8 +141,7 @@ class CategoryController extends Controller
*
* @return type Redirect
*/
public function store(Category $category, CategoryRequest $request)
{
public function store(Category $category, CategoryRequest $request) {
/* Get the whole request from the form and insert into table via model */
$sl = $request->input('slug');
$slug = str_slug($sl, '-');
@@ -146,9 +150,9 @@ class CategoryController extends Controller
try {
$category->fill($request->except('slug'))->save();
return Redirect::back()->with('success', 'Category Inserted Successfully');
return Redirect::back()->with('success', Lang::get('lang.category_inserted_successfully'));
} catch (Exception $e) {
return Redirect::back()->with('fails', 'Category Not Inserted'.'<li>'.$e->errorInfo[2].'</li>');
return Redirect::back()->with('fails', Lang::get('lang.category_not_inserted') . '<li>' . $e->getMessage() . '</li>');
}
}
@@ -160,13 +164,12 @@ class CategoryController extends Controller
*
* @return type view
*/
public function edit($slug, Category $category)
{
public function edit($slug) {
// fetch the category
$cid = $category->where('id', $slug)->first();
$cid = Category::where('id', $slug)->first();
$id = $cid->id;
/* get the atributes of the category model whose id == $id */
$category = $category->whereId($id)->first();
$category = Category::whereId($id)->first();
/* get the Edit page the selected category via id */
return view('themes.default1.agent.kb.category.edit', compact('category'));
}
@@ -180,11 +183,10 @@ class CategoryController extends Controller
*
* @return type redirect
*/
public function update($slug, Category $category, CategoryUpdate $request)
{
public function update($slug, CategoryUpdate $request) {
/* Edit the selected category via id */
$category = $category->where('id', $slug)->first();
$category = Category::where('id', $slug)->first();
$sl = $request->input('slug');
$slug = str_slug($sl, '-');
// dd($slug);
@@ -195,11 +197,10 @@ class CategoryController extends Controller
$category->fill($request->all())->save();
$category->slug = $slug;
$category->save();
return redirect('category')->with('success', 'Category Updated Successfully');
return redirect('category')->with('success', Lang::get('lang.category_updated_successfully'));
} catch (Exception $e) {
//redirect to index with fails message
return redirect('category')->with('fails', 'Category Not Updated'.'<li>'.$e->errorInfo[2].'</li>');
return redirect('category')->with('fails', Lang::get('lang.category_not_updated') . '<li>' . $e->getMessage() . '</li>');
}
}
@@ -212,11 +213,10 @@ class CategoryController extends Controller
*
* @return type Redirect
*/
public function destroy($id, Category $category, Relationship $relation)
{
public function destroy($id, Category $category, Relationship $relation) {
$relation = $relation->where('category_id', $id)->first();
if ($relation != null) {
return Redirect::back()->with('fails', 'Category Not Deleted');
return Redirect::back()->with('fails', Lang::get('lang.category_not_deleted'));
} else {
/* delete the category selected, id == $id */
$category = $category->whereId($id)->first();
@@ -224,10 +224,11 @@ class CategoryController extends Controller
try {
$category->delete();
return Redirect::back()->with('success', 'Category Deleted Successfully');
return Redirect::back()->with('success', Lang::get('lang.category_deleted_successfully'));
} catch (Exception $e) {
return Redirect::back()->with('fails', 'Category Not Deleted'.'<li>'.$e->errorInfo[2].'</li>');
return Redirect::back()->with('fails', Lang::get('lang.category_not_deleted') . '<li>' . $e->getMessage() . '</li>');
}
}
}
}

View File

@@ -2,7 +2,7 @@
namespace App\Http\Controllers\Agent\kb;
// controllersuse App\Http\Controllers\Agent\helpdesk\TicketController;
use App\Http\Controllers\Agent\helpdesk\TicketController;
use App\Http\Controllers\Controller;
// request
use App\Http\Requests\kb\PageRequest;
@@ -13,15 +13,16 @@ use Datatable;
// classes
use Exception;
use Illuminate\Http\Request;
use Lang;
/**
* PageController
* This controller is used to CRUD Pages.
*
* @author Ladybird <info@ladybirdweb.com>
* @author Ladybird <info@ladybirdweb.com>
*/
class PageController extends Controller
{
class PageController extends Controller {
/**
* Create a new controller instance.
* constructor to check
@@ -31,8 +32,7 @@ class PageController extends Controller
*
* @return void
*/
public function __construct(Page $page)
{
public function __construct(Page $page) {
// checking authentication
$this->middleware('auth');
// checking roles
@@ -46,14 +46,13 @@ class PageController extends Controller
*
* @return type
*/
public function index()
{
public function index() {
$pages = $this->page->paginate(3);
$pages->setPath('page');
try {
return view('themes.default1.agent.kb.pages.index', compact('pages'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -62,8 +61,7 @@ class PageController extends Controller
*
* @return type
*/
public function getData()
{
public function getData() {
/* fetching chumper datatables */
return Datatable::collection(Page::All())
/* search column name */
@@ -83,8 +81,8 @@ class PageController extends Controller
/* add column Actions */
/* there are action buttons and modal popup to delete a data column */
->addColumn('Actions', function ($model) {
return '<span data-toggle="modal" data-target="#deletepage'.$model->id.'"><a href="#" ><button class="btn btn-danger btn-xs"></a> '.\Lang::get('lang.delete').'</button></span>&nbsp;<a href=page/'.$model->slug.'/edit class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp;<a href=pages/'.$model->slug.' class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>
<div class="modal fade" id="deletepage'.$model->id.'">
return '<span data-toggle="modal" data-target="#deletepage' . $model->id . '"><a href="#" ><button class="btn btn-danger btn-xs"></a> ' . \Lang::get('lang.delete') . '</button></span>&nbsp;<a href=page/' . $model->slug . '/edit class="btn btn-warning btn-xs">' . \Lang::get('lang.edit') . '</a>&nbsp;<a href=pages/' . $model->slug . ' class="btn btn-primary btn-xs">' . \Lang::get('lang.view') . '</a>
<div class="modal fade" id="deletepage' . $model->id . '">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
@@ -92,11 +90,11 @@ class PageController extends Controller
<h4 class="modal-title">Are You Sure ?</h4>
</div>
<div class="modal-body">
'.$model->name.'
' . $model->name . '
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
<a href="page/delete/'.$model->id.'"><button class="btn btn-danger">delete</button></a>
<a href="page/delete/' . $model->id . '"><button class="btn btn-danger">delete</button></a>
</div>
</div>
</div>
@@ -110,8 +108,7 @@ class PageController extends Controller
*
* @return type view
*/
public function create()
{
public function create() {
return view('themes.default1.agent.kb.pages.create');
}
@@ -122,17 +119,16 @@ class PageController extends Controller
*
* @return type
*/
public function store(PageRequest $request)
{
public function store(PageRequest $request) {
$sl = $request->input('slug');
$slug = str_slug($sl, '-');
$this->page->slug = $slug;
try {
$this->page->fill($request->except('slug'))->save();
return redirect('page')->with('success', 'Page created successfully');
return redirect('page')->with('success', Lang::get('lang.page_created_successfully'));
} catch (Exception $e) {
return redirect('page')->with('fails', $e->errorInfo[2]);
return redirect('page')->with('fails', $e->getMessage());
}
}
@@ -143,14 +139,13 @@ class PageController extends Controller
*
* @return type view
*/
public function edit($slug)
{
public function edit($slug) {
try {
$page = $this->page->where('slug', $slug)->first();
return view('themes.default1.agent.kb.pages.edit', compact('page'));
} catch (Exception $e) {
return redirect('page')->with('fails', $e->errorInfo[2]);
return redirect('page')->with('fails', $e->getMessage());
}
}
@@ -162,8 +157,7 @@ class PageController extends Controller
*
* @return type redirect
*/
public function update($slug, PageUpdate $request)
{
public function update($slug, PageUpdate $request) {
// get pages with respect to slug
$pages = $this->page->where('slug', $slug)->first();
$sl = $request->input('slug');
@@ -174,9 +168,9 @@ class PageController extends Controller
$pages->slug = $slug;
$pages->save();
return redirect('page')->with('success', 'Your Page Updated Successfully');
return redirect('page')->with('success', Lang::get('lang.your_page_updated_successfully'));
} catch (Exception $e) {
return redirect('page')->with('fails', $e->errorInfo[2]);
return redirect('page')->with('fails', $e->getMessage());
}
}
@@ -187,16 +181,16 @@ class PageController extends Controller
*
* @return type redirect
*/
public function destroy($id)
{
public function destroy($id) {
try {
// get the page to be deleted
$page = $this->page->whereId($id)->first();
$page->delete();
return redirect('page')->with('success', 'Page Deleted Successfully');
return redirect('page')->with('success', Lang::get('lang.page_deleted_successfully'));
} catch (Exception $e) {
return redirect('page')->with('fails', $e->errorInfo[2]);
return redirect('page')->with('fails', $e->getMessage());
}
}
}

View File

@@ -22,12 +22,13 @@ use Hash;
use Illuminate\Http\Request;
use Image;
use Input;
use Lang;
/**
* SettingsController
* This controller is used to perform settings in the setting page of knowledgebase.
*
* @author Ladybird <info@ladybirdweb.com>
* @author Ladybird <info@ladybirdweb.com>
*/
class SettingsController extends Controller
{
@@ -106,14 +107,14 @@ class SettingsController extends Controller
/* Check whether function success or not */
if ($settings->fill($request->except('logo', 'background'))->save() == true) {
/* redirect to Index page with Success Message */
return redirect('settings')->with('success', 'Settings Updated Successfully');
return redirect()->back()->with('success', Lang::get('lang.settings_updated_successfully'));
} else {
/* redirect to Index page with Fails Message */
return redirect('settings')->with('fails', 'Settings can not Updated');
return redirect()->back()->with('fails', Lang::get('lang.settings_can_not_updated'));
}
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('settings')->with('fails', 'Settings can not Updated');
return redirect()->back()->with('fails', Lang::get('lang.settings_can_not_updated'));
}
}
@@ -181,9 +182,9 @@ class SettingsController extends Controller
$comment = $comment->whereId($id)->first();
$comment->status = 1;
if ($comment->save()) {
return redirect('comment')->with('success', $comment->name.'-'.'Comment Published');
return redirect('comment')->with('success', $comment->name.'-'.Lang::get('lang.comment_published'));
} else {
return redirect('comment')->with('fails', 'Can not Process');
return redirect('comment')->with('fails', Lang::get('lang.can_not_process'));
}
}
@@ -199,9 +200,9 @@ class SettingsController extends Controller
{
$comment = $comment->whereId($id)->first();
if ($comment->delete()) {
return redirect('comment')->with('success', $comment->name."'s!".'Comment Deleted');
return redirect('comment')->with('success', $comment->name."'s!".Lang::get('lang.comment_deleted'));
} else {
return redirect('comment')->with('fails', 'Can not Process');
return redirect('comment')->with('fails', Lang::get('lang.can_not_process'));
}
}