diff --git a/app/FaveoStorage/Controllers/StorageController.php b/app/FaveoStorage/Controllers/StorageController.php index 8a9e46e31..428381f0f 100644 --- a/app/FaveoStorage/Controllers/StorageController.php +++ b/app/FaveoStorage/Controllers/StorageController.php @@ -250,9 +250,9 @@ class StorageController extends Controller if ($disposition == 'INLINE' || $disposition == 'inline') { $id = str_replace('>', '', str_replace('<', '', $structure->id)); $body = $thread->body; - // dd($id,$filename,$body); + // dd($id,$filename,$body); $body = str_replace('cid:'.$id, $filename, $body); - // dd($body); + // dd($body); $thread->body = $body; $thread->save(); } diff --git a/app/Helper/Finder.php b/app/Helper/Finder.php index 1895f451d..8f0bb2d30 100644 --- a/app/Helper/Finder.php +++ b/app/Helper/Finder.php @@ -58,26 +58,26 @@ class Finder return $group->first()->name; } - /** - * STATUS TYPE - * This function is used for returning status type name with respect to id. - * - * @param $id type int - * @param $custom type array/null - * - * @return type string - */ - public static function statusType($id, $custom = null) - { - if ($custom == null) { - $status_type = TicketStatusType::whereId($id)->select(['name']); - } elseif (isset($custom)) { - $status_type = TicketStatusType::whereId($id)->select($custom); - } - - return $status_type->first()->name; + /** + * STATUS TYPE + * This function is used for returning status type name with respect to id. + * + * @param $id type int + * @param $custom type array/null + * + * @return type string + */ + public static function statusType($id, $custom = null) + { + if ($custom == null) { + $status_type = TicketStatusType::whereId($id)->select(['name']); + } elseif (isset($custom)) { + $status_type = TicketStatusType::whereId($id)->select($custom); } + return $status_type->first()->name; + } + /** * STATUS * This function is used for returning status name with respect to id. @@ -137,48 +137,48 @@ class Finder } } - /** - * ANY TYPE STATUS - * This function is used to return the set of status which are of any type passed in the param. - * - * @param type $id - * - * @return type array - */ - public static function anyTypeStatus($id) - { - $status_group = Ticket_Status::where('purpose_of_status', '=', $id)->select(['id'])->get(); - foreach ($status_group as $status) { - $status_group2[] = $status->id; - } - - return $status_group2; + /** + * ANY TYPE STATUS + * This function is used to return the set of status which are of any type passed in the param. + * + * @param type $id + * + * @return type array + */ + public static function anyTypeStatus($id) + { + $status_group = Ticket_Status::where('purpose_of_status', '=', $id)->select(['id'])->get(); + foreach ($status_group as $status) { + $status_group2[] = $status->id; } - /** - * RETURNS ALL STATUS - * This function is used to return all the status given in the system. - * - * @return type array - */ - public static function getAllStatus() - { - $status = Ticket_Status::where('purpose_of_status', '!=', 3)->orwhere('purpose_of_status', '!=', 4)->get(); + return $status_group2; + } - return $status; + /** + * RETURNS ALL STATUS + * This function is used to return all the status given in the system. + * + * @return type array + */ + public static function getAllStatus() + { + $status = Ticket_Status::where('purpose_of_status', '!=', 3)->orwhere('purpose_of_status', '!=', 4)->get(); + + return $status; + } + + /** + * VARIABLE REPLACEMENT + * This function is used to replace the replaceable variables form a given content for templates. + */ + public static function replaceTemplateVariables($variables, $data, $contents) + { + foreach ($variables as $key => $variable) { + $messagebody = str_replace($variables[$key], $data[$key], $contents); + $contents = $messagebody; } - /** - * VARIABLE REPLACEMENT - * This function is used to replace the replaceable variables form a given content for templates. - */ - public static function replaceTemplateVariables($variables, $data, $contents) - { - foreach ($variables as $key => $variable) { - $messagebody = str_replace($variables[$key], $data[$key], $contents); - $contents = $messagebody; - } - - return $contents; - } + return $contents; + } } diff --git a/app/Http/Controllers/Admin/helpdesk/AgentController.php b/app/Http/Controllers/Admin/helpdesk/AgentController.php index 9b94793bd..7fd17f8f9 100644 --- a/app/Http/Controllers/Admin/helpdesk/AgentController.php +++ b/app/Http/Controllers/Admin/helpdesk/AgentController.php @@ -271,10 +271,12 @@ class AgentController extends Controller $team_assign_agent = $team_assign_agent->where('agent_id', $id); $team_assign_agent->delete(); $user = $user->whereId($id)->first(); + try { $error = Lang::get('lang.this_staff_is_related_to_some_tickets'); $user->id; $user->delete(); + throw new \Exception($error); return redirect('agents')->with('success', Lang::get('lang.agent_deleted_sucessfully')); } catch (\Exception $e) { diff --git a/app/Http/Controllers/Admin/helpdesk/EmailsController.php b/app/Http/Controllers/Admin/helpdesk/EmailsController.php index 8c15c251e..7b9be5355 100644 --- a/app/Http/Controllers/Admin/helpdesk/EmailsController.php +++ b/app/Http/Controllers/Admin/helpdesk/EmailsController.php @@ -428,6 +428,7 @@ class EmailsController extends Controller return redirect('emails')->with('fails', Lang::get('lang.you_cannot_delete_system_default_email')); } } + try { // fetching the database instance of the current email $emails = $email->whereId($id)->first(); diff --git a/app/Http/Controllers/Admin/helpdesk/FormController.php b/app/Http/Controllers/Admin/helpdesk/FormController.php index 5a7d90d9b..c5005cc39 100644 --- a/app/Http/Controllers/Admin/helpdesk/FormController.php +++ b/app/Http/Controllers/Admin/helpdesk/FormController.php @@ -106,6 +106,7 @@ class FormController extends Controller return view('themes.default1.admin.helpdesk.manage.form.preview', compact('form', 'fields')); } + throw new Exception("Sorry we can't find your request"); } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); @@ -125,6 +126,7 @@ class FormController extends Controller 'name.*' => 'required', 'type.*' => 'required', ]); + try { $forms = new Forms(); $require = Input::get('required'); @@ -195,6 +197,7 @@ class FormController extends Controller //dd($fields); return view('themes.default1.admin.helpdesk.manage.form.edit', compact('form', 'fields', 'select_forms')); } + throw new Exception("Sorry we can't find your request"); } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); @@ -213,6 +216,7 @@ class FormController extends Controller //dd($fields); return view('themes.default1.admin.helpdesk.manage.form.add-child', compact('form', 'fields', 'select_forms')); } + throw new Exception("Sorry we can't find your request"); } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); @@ -227,6 +231,7 @@ class FormController extends Controller 'name.*' => 'required', 'type.*' => 'required', ]); + try { if (!$request->input('formname')) { throw new Exception(Lang::get('lang.please_fill_form_name')); @@ -391,6 +396,7 @@ class FormController extends Controller public function addChild($fieldid, Request $request) { $ids = $request->except('_token'); + try { foreach ($ids as $valueid => $formid) { $field_value = new \App\Model\helpdesk\Form\FieldValue(); diff --git a/app/Http/Controllers/Admin/helpdesk/PriorityController.php b/app/Http/Controllers/Admin/helpdesk/PriorityController.php index 2b999d298..7e0b39289 100644 --- a/app/Http/Controllers/Admin/helpdesk/PriorityController.php +++ b/app/Http/Controllers/Admin/helpdesk/PriorityController.php @@ -46,7 +46,7 @@ class PriorityController extends Controller $user_status = CommonSettings::where('option_name', '=', 'user_priority')->first(); // dd( $user_status); - return view('themes.default1.admin.helpdesk.manage.ticket_priority.index', compact('user_status')); + return view('themes.default1.admin.helpdesk.manage.ticket_priority.index', compact('user_status')); } /** @@ -172,7 +172,7 @@ class PriorityController extends Controller public function destroy($priority_id) { $default_priority = Ticket_Priority::where('is_default', '>', '0')->first(); -// dd($default_priority->is_default); + // dd($default_priority->is_default); $topic = DB::table('help_topic')->where('priority', '=', $priority_id)->update(['priority' => $default_priority->is_default]); // if ($topic > 0) { // if ($topic > 1) { diff --git a/app/Http/Controllers/Admin/helpdesk/SettingsController2.php b/app/Http/Controllers/Admin/helpdesk/SettingsController2.php index 9682941f2..0a18728a1 100644 --- a/app/Http/Controllers/Admin/helpdesk/SettingsController2.php +++ b/app/Http/Controllers/Admin/helpdesk/SettingsController2.php @@ -150,8 +150,8 @@ class SettingsController2 extends Controller public function createStatuses(\App\Model\helpdesk\Ticket\Ticket_Status $statuss) { // try { - /* fetch the values of company from company table */ - $statuss->name = Input::get('name'); + /* fetch the values of company from company table */ + $statuss->name = Input::get('name'); $statuss->icon_class = Input::get('icon_class'); $statuss->email_user = Input::get('email_user'); $statuss->sort = Input::get('sort'); @@ -164,7 +164,7 @@ class SettingsController2 extends Controller $statuss->sort = Input::get('sort'); $statuss->save(); /* Direct to Company Settings Page */ - return redirect()->back()->with('success', 'Status has been created!'); + return redirect()->back()->with('success', 'Status has been created!'); // } catch (Exception $ex) { // return redirect()->back()->with('fails', $ex->errorInfo[2]); // } @@ -175,9 +175,9 @@ class SettingsController2 extends Controller try { if ($id > 5) { /* fetch the values of company from company table */ - \App\Model\helpdesk\Ticket\Ticket_Status::whereId($id)->delete(); - /* Direct to Company Settings Page */ - return redirect()->back()->with('success', 'Status has been deleted'); + \App\Model\helpdesk\Ticket\Ticket_Status::whereId($id)->delete(); + /* Direct to Company Settings Page */ + return redirect()->back()->with('success', 'Status has been deleted'); } else { return redirect()->back()->with('failed', 'You cannot delete this status'); } @@ -446,12 +446,12 @@ class SettingsController2 extends Controller public function getSchedular(Email $email, Template $template, Emails $email1) { // try { - /* fetch the values of email from Email table */ - $emails = $email->whereId('1')->first(); - /* Fetch the values from Template table */ - $templates = $template->get(); - /* Fetch the values from Emails table */ - $emails1 = $email1->get(); + /* fetch the values of email from Email table */ + $emails = $email->whereId('1')->first(); + /* Fetch the values from Template table */ + $templates = $template->get(); + /* Fetch the values from Emails table */ + $emails1 = $email1->get(); return view('themes.default1.admin.helpdesk.settings.crone', compact('emails', 'templates', 'emails1')); // } catch { @@ -503,7 +503,7 @@ class SettingsController2 extends Controller // try { // /* fetch the values of access from access table */ // $accesses = $access->whereId('1')->first(); -// // Direct to Access Settings Page + // // Direct to Access Settings Page // return view('themes.default1.admin.helpdesk.settings.access', compact('accesses')); // } catch (Exception $e) { // return view('404'); diff --git a/app/Http/Controllers/Admin/helpdesk/SocialMedia/SocialMediaController.php b/app/Http/Controllers/Admin/helpdesk/SocialMedia/SocialMediaController.php index 0c8abfc65..64fa87207 100644 --- a/app/Http/Controllers/Admin/helpdesk/SocialMedia/SocialMediaController.php +++ b/app/Http/Controllers/Admin/helpdesk/SocialMedia/SocialMediaController.php @@ -32,6 +32,7 @@ class SocialMediaController extends Controller 'client_secret' => 'required', 'redirect' => 'required|url', ]); + try { $requests = $request->except('_token'); $this->insertProvider($provider, $requests); diff --git a/app/Http/Controllers/Admin/helpdesk/TeamController.php b/app/Http/Controllers/Admin/helpdesk/TeamController.php index d662875c1..b643bc915 100644 --- a/app/Http/Controllers/Admin/helpdesk/TeamController.php +++ b/app/Http/Controllers/Admin/helpdesk/TeamController.php @@ -143,16 +143,16 @@ class TeamController extends Controller { // dd($request); -// $id = $request->input('show_id'); + // $id = $request->input('show_id'); -// dd($id); + // dd($id); -$users = DB::table('team_assign_agent')->select('team_assign_agent.id', 'team_assign_agent.team_id', 'users.user_name', 'users.first_name', 'users.last_name', 'users.active', 'users.assign_group', 'users.primary_dpt', 'users.role') + $users = DB::table('team_assign_agent')->select('team_assign_agent.id', 'team_assign_agent.team_id', 'users.user_name', 'users.first_name', 'users.last_name', 'users.active', 'users.assign_group', 'users.primary_dpt', 'users.role') ->join('users', 'users.id', '=', 'team_assign_agent.agent_id') ->where('team_assign_agent.team_id', '=', $id); // ->get(); -// dd($users); - return \Datatable::query($users) + // dd($users); + return \Datatable::query($users) ->showColumns('user_name') ->addColumn('first_name', function ($model) { diff --git a/app/Http/Controllers/Admin/helpdesk/TemplateController.php b/app/Http/Controllers/Admin/helpdesk/TemplateController.php index 6158ac4ed..7103f7407 100644 --- a/app/Http/Controllers/Admin/helpdesk/TemplateController.php +++ b/app/Http/Controllers/Admin/helpdesk/TemplateController.php @@ -157,11 +157,11 @@ class TemplateController extends Controller $fname = Input::get('folder_name'); $filename = $directory.$fname; -// images folder creation using php -// $mydir = dirname( __FILE__ )."/html/images"; -// if(!is_dir($mydir)){ -// mkdir("html/images"); -// } + // images folder creation using php + // $mydir = dirname( __FILE__ )."/html/images"; + // if(!is_dir($mydir)){ + // mkdir("html/images"); + // } // Move all images files if (!file_exists($filename)) { diff --git a/app/Http/Controllers/Admin/helpdesk/UrlSettingController.php b/app/Http/Controllers/Admin/helpdesk/UrlSettingController.php index fd8d966b5..6e526bdae 100644 --- a/app/Http/Controllers/Admin/helpdesk/UrlSettingController.php +++ b/app/Http/Controllers/Admin/helpdesk/UrlSettingController.php @@ -91,7 +91,7 @@ RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n"; public function changeHttp() { //$string = "RewriteCond %{HTTPS} off -//RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n"; + //RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n"; $string = ''; return $string; diff --git a/app/Http/Controllers/Admin/helpdesk/WorkflowController.php b/app/Http/Controllers/Admin/helpdesk/WorkflowController.php index f0756bf77..809a276f8 100644 --- a/app/Http/Controllers/Admin/helpdesk/WorkflowController.php +++ b/app/Http/Controllers/Admin/helpdesk/WorkflowController.php @@ -149,6 +149,7 @@ class WorkflowController extends Controller $email_data["E-$key"] = $email; } $emails = $email_data; + try { return view('themes.default1.admin.helpdesk.manage.workflow.create', compact('emails')); } catch (Exception $e) { diff --git a/app/Http/Controllers/Agent/helpdesk/Filter/FilterController.php b/app/Http/Controllers/Agent/helpdesk/Filter/FilterController.php index 927787da4..2c065b1f7 100644 --- a/app/Http/Controllers/Agent/helpdesk/Filter/FilterController.php +++ b/app/Http/Controllers/Agent/helpdesk/Filter/FilterController.php @@ -232,7 +232,7 @@ class FilterController extends Controller public function table() { // if (Auth::user()->role == 'admin') { - $ticket = new Tickets(); + $ticket = new Tickets(); $tickets = $ticket ->leftJoin('ticket_thread', function ($join) { $join->on('tickets.id', '=', 'ticket_thread.ticket_id') diff --git a/app/Http/Controllers/Agent/helpdesk/TicketController.php b/app/Http/Controllers/Agent/helpdesk/TicketController.php index 732837cc6..7ebf415a4 100644 --- a/app/Http/Controllers/Agent/helpdesk/TicketController.php +++ b/app/Http/Controllers/Agent/helpdesk/TicketController.php @@ -284,24 +284,22 @@ class TicketController extends Controller if ($result[1]) { $status = $this->checkUserVerificationStatus(); if ($status == 1) { - if ($api != false) - { + if ($api != false) { $ticket = Tickets::where('ticket_number', '=', $result[0])->select('id')->first(); + return ['ticket_id' => $ticket->id, 'message' => Lang::get('lang.Ticket-created-successfully')]; } return Redirect('newticket')->with('success', Lang::get('lang.Ticket-created-successfully')); } else { - if ($api != false) - { + if ($api != false) { return response()->json(['success' => Lang::get('lang.Ticket-created-successfully')]); } return Redirect('newticket')->with('success', Lang::get('lang.Ticket-created-successfully2')); } } else { - if ($api != false) - { + if ($api != false) { return response()->json(['error' => Lang::get('lang.failed-to-create-user-tcket-as-mobile-has-been-taken')], 500); } @@ -309,8 +307,7 @@ class TicketController extends Controller } } catch (Exception $e) { dd($e); - if ($api != false) - { + if ($api != false) { return response()->json(['error' => $e->getMessage()], 500); } @@ -403,6 +400,7 @@ class TicketController extends Controller public function reply(Ticket_Thread $thread, Request $request, Ticket_attachments $ta, $mail = true, $system_reply = true, $user_id = '') { \Event::fire('reply.request', [$request]); + try { if (is_array($request->file('attachment'))) { } else { @@ -815,6 +813,7 @@ class TicketController extends Controller } // Event fire \Event::fire(new \App\Events\ReadMailEvent($user_id, $password)); + try { if ($auto_response == 0) { $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user->first_name, 'email' => $emailadd], $message = ['subject' => null, 'scenario' => 'registration-notification'], $template_variables = ['user' => $user->first_name, 'email_address' => $emailadd, 'user_password' => $password]); @@ -867,6 +866,7 @@ class TicketController extends Controller } } else { $body2 = null; + try { if ($auto_response == 0) { $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['name' => $username, 'email' => $emailadd], $message = ['subject' => $updated_subject, 'scenario' => 'create-ticket'], @@ -1234,10 +1234,10 @@ class TicketController extends Controller } else { $ticket_status = $ticket->where('id', '=', $id)->first(); } - // checking for unautherised access attempt on other than owner ticket id - if ($ticket_status == null) { - return redirect()->route('unauth'); - } + // checking for unautherised access attempt on other than owner ticket id + if ($ticket_status == null) { + return redirect()->route('unauth'); + } $ticket_status->status = 3; $ticket_status->closed = 1; $ticket_status->closed_at = date('Y-m-d H:i:s'); @@ -1265,6 +1265,7 @@ class TicketController extends Controller } else { $from_email = $sending_emails->id; } + try { $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticket_status->dept_id), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => $ticket_subject.'[#'.$ticket_number.']', 'scenario' => 'close-ticket'], $template_variables = ['ticket_number' => $ticket_number]); } catch (\Exception $e) { @@ -1501,6 +1502,7 @@ class TicketController extends Controller $agent_email = $user_detail->email; $ticket_link = route('ticket.thread', $id); $master = Auth::user()->first_name.' '.Auth::user()->last_name; + try { $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticket->dept_id), $to = ['name' => $agent, 'email' => $agent_email], $message = ['subject' => $ticket_subject.'[#'.$ticket_number.']', 'scenario' => 'assign-ticket'], $template_variables = ['ticket_agent_name' => $agent, 'ticket_number' => $ticket_number, 'ticket_assigner' => $master, 'ticket_link' => $ticket_link]); } catch (\Exception $e) { @@ -1634,6 +1636,7 @@ class TicketController extends Controller $create_user->password = Hash::make($password); $create_user->save(); $user_id = $create_user->id; + try { $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => 'password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]); } catch (\Exception $e) { @@ -2321,6 +2324,7 @@ class TicketController extends Controller $user->role = 'user'; if ($user->save()) { $user_id = $user->id; + try { $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => 'Password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]); } catch (\Exception $e) { diff --git a/app/Http/Controllers/Agent/helpdesk/UserController.php b/app/Http/Controllers/Agent/helpdesk/UserController.php index aeefbd717..a8fe00292 100644 --- a/app/Http/Controllers/Agent/helpdesk/UserController.php +++ b/app/Http/Controllers/Agent/helpdesk/UserController.php @@ -149,7 +149,7 @@ class UserController extends Controller } // displaying list of users with chumper datatables // return \Datatable::collection(User::where('role', "!=", "admin")->get()) - return \Datatables::of($users) + return \Datatables::of($users) /* column username */ ->removeColumn('id', 'last_name', 'country_code', 'phone_number') ->addColumn('user_name', function ($model) { @@ -218,14 +218,14 @@ class UserController extends Controller if (Auth::user()->role == 'admin') { // @if(Auth::user()->role == 'admin') - return ''.\Lang::get('lang.view').''; + return ''.\Lang::get('lang.view').''; } if (Auth::user()->role == 'agent') { // @if(Auth::user()->role == 'admin') - if ($model->role == 'user') { - return ''.\Lang::get('lang.view').''; - } + if ($model->role == 'user') { + return ''.\Lang::get('lang.view').''; + } } } }) @@ -235,7 +235,7 @@ class UserController extends Controller public function restoreUser($id) { // dd($id); - // $delete_all = Input::get('delete_all'); + // $delete_all = Input::get('delete_all'); $users = User::where('id', '=', $id)->first(); $users->is_delete = 0; $users->active = 1; @@ -298,6 +298,7 @@ class UserController extends Controller $password = $this->generateRandomString(); $user->password = Hash::make($password); $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(); @@ -514,19 +515,19 @@ class UserController extends Controller // $ticket_logic4 = User_org::where('user_id', '=', $id)->update(['user_id' => $assign_to[1]]); // } - // $thread2 = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first(); - // $thread2->body = 'This Ticket have been Reassigned to' .' '. $assignee; - // $thread2->save(); - // UserNotification::where('notification_id', '=', $ticket->id)->delete(); - // $users = User::where('id', '=', $id)->get(); - // $organization = User_org::where('user_id', '=', $id)->delete(); - // Assign_team_agent::where('agent_id', '=', $id)->update(['agent_id' => $assign_to[1]]); - $tickets = Tickets::where('assigned_to', '=', $id)->get(); + // $thread2 = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first(); + // $thread2->body = 'This Ticket have been Reassigned to' .' '. $assignee; + // $thread2->save(); + // UserNotification::where('notification_id', '=', $ticket->id)->delete(); + // $users = User::where('id', '=', $id)->get(); + // $organization = User_org::where('user_id', '=', $id)->delete(); + // Assign_team_agent::where('agent_id', '=', $id)->update(['agent_id' => $assign_to[1]]); + $tickets = Tickets::where('assigned_to', '=', $id)->get(); foreach ($tickets as $ticket) { // code... - $ticket->assigned_to = $assign_to[1]; + $ticket->assigned_to = $assign_to[1]; $user_detail = User::where('id', '=', $assign_to[1])->first(); $assignee = $user_detail->first_name.' '.$user_detail->last_name; $ticket_number = $ticket->ticket_number; @@ -561,20 +562,20 @@ class UserController extends Controller } elseif ($delete_all == 1) { if ($delete_all) { // dd('here'); - $tickets = Tickets::where('assigned_to', '=', $id)->get(); - // dd($tickets); - foreach ($tickets as $ticket) { - $ticket->assigned_to = null; - $ticket_number = $ticket->ticket_number; - $ticket->save(); + $tickets = Tickets::where('assigned_to', '=', $id)->get(); + // dd($tickets); + foreach ($tickets as $ticket) { + $ticket->assigned_to = null; + $ticket_number = $ticket->ticket_number; + $ticket->save(); - $thread = new Ticket_Thread(); - $thread->ticket_id = $ticket->id; - $thread->user_id = Auth::user()->id; - $thread->is_internal = 1; - $thread->body = 'This Ticket has been unassigned '; - $thread->save(); - } + $thread = new Ticket_Thread(); + $thread->ticket_id = $ticket->id; + $thread->user_id = Auth::user()->id; + $thread->is_internal = 1; + $thread->body = 'This Ticket has been unassigned '; + $thread->save(); + } // $users = User::where('id', '=', $id)->get(); $user = User::find($id); $users->is_delete = 1; @@ -708,6 +709,7 @@ class UserController extends Controller public function getProfile() { $user = Auth::user(); + try { return view('themes.default1.agent.helpdesk.user.profile', compact('user')); } catch (Exception $e) { @@ -727,6 +729,7 @@ class UserController extends Controller $phonecode = $code->where('iso', '=', $location->iso_code)->first(); $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); $status = $settings->status; + try { return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user')) ->with(['phonecode' => $phonecode->phonecode, @@ -766,13 +769,13 @@ class UserController extends Controller $name = Input::file('profile_pic')->getClientOriginalName(); // dd($name); // dd(str_replace(" ", "_", $name)); - // fetching upload destination path + // fetching upload destination path $destinationPath = 'uploads/profilepic'; - // adding a random value to profile picture filename + // adding a random value to profile picture filename $fileName = rand(0000, 9999).'.'.str_replace(' ', '_', $name); - // moving the picture to a destination folder + // moving the picture to a destination folder Input::file('profile_pic')->move($destinationPath, $fileName); - // saving filename to database + // saving filename to database $user->profile_pic = $fileName; } if ($request->get('mobile')) { @@ -805,6 +808,7 @@ class UserController extends Controller // 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(); diff --git a/app/Http/Controllers/Agent/kb/PageController.php b/app/Http/Controllers/Agent/kb/PageController.php index 92a74e1c3..104290086 100644 --- a/app/Http/Controllers/Agent/kb/PageController.php +++ b/app/Http/Controllers/Agent/kb/PageController.php @@ -51,6 +51,7 @@ class PageController extends Controller { $pages = $this->page->paginate(3); $pages->setPath('page'); + try { return view('themes.default1.agent.kb.pages.index', compact('pages')); } catch (Exception $e) { @@ -128,6 +129,7 @@ class PageController extends Controller $sl = $request->input('name'); $slug = str_slug($sl, '-'); $this->page->slug = $slug; + try { $this->page->fill($request->input())->save(); @@ -169,6 +171,7 @@ class PageController extends Controller $pages = $this->page->where('slug', $slug)->first(); $sl = $request->input('name'); $slug = str_slug($sl, '-'); + try { $pages->fill($request->all())->save(); $pages->slug = $slug; diff --git a/app/Http/Controllers/Api/v1/ApiController.php b/app/Http/Controllers/Api/v1/ApiController.php index 8dfb10630..b77369fb7 100644 --- a/app/Http/Controllers/Api/v1/ApiController.php +++ b/app/Http/Controllers/Api/v1/ApiController.php @@ -36,7 +36,6 @@ use Illuminate\Support\Collection; */ class ApiController extends Controller { - public $user; public $request; public $ticket; @@ -62,60 +61,54 @@ class ApiController extends Controller $this->middleware('jwt.auth'); $this->middleware('api', ['except' => 'GenerateApiKey']); - try - { - $user = \JWTAuth::parseToken()->authenticate(); + + try { + $user = \JWTAuth::parseToken()->authenticate(); $this->user = $user; - } - catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) - { - - } - catch (\Tymon\JWTAuth\Exceptions\JWTException $e) - { - + } catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) { + } catch (\Tymon\JWTAuth\Exceptions\JWTException $e) { } - $ticket = new TicketController(); + $ticket = new TicketController(); $this->ticket = $ticket; - $model = new Tickets(); + $model = new Tickets(); $this->model = $model; - $thread = new Ticket_Thread(); + $thread = new Ticket_Thread(); $this->thread = $thread; - $attach = new Ticket_attachments(); + $attach = new Ticket_attachments(); $this->attach = $attach; - $ticketRequest = new TicketRequest(); + $ticketRequest = new TicketRequest(); $this->ticketRequest = $ticketRequest; - $faveoUser = new User(); + $faveoUser = new User(); $this->faveoUser = $faveoUser; - $faveoUser = new User(); + $faveoUser = new User(); $this->user = $faveoUser; - $team = new Teams(); + $team = new Teams(); $this->team = $team; - $setting = new System(); + $setting = new System(); $this->setting = $setting; - $helptopic = new Help_topic(); + $helptopic = new Help_topic(); $this->helptopic = $helptopic; - $slaPlan = new Sla_plan(); + $slaPlan = new Sla_plan(); $this->slaPlan = $slaPlan; - $priority = new Priority(); + $priority = new Priority(); $this->priority = $priority; - $department = new Department(); + $department = new Department(); $this->department = $department; - $source = new Ticket_source(); + $source = new Ticket_source(); $this->source = $source; } @@ -130,37 +123,35 @@ class ApiController extends Controller */ public function createTicket(\App\Http\Requests\helpdesk\CreateTicketRequest $request, \App\Model\helpdesk\Utility\CountryCode $code) { - try - { + try { $user_id = $this->request->input('user_id'); - $subject = $this->request->input('subject'); - $body = $this->request->input('body'); + $subject = $this->request->input('subject'); + $body = $this->request->input('body'); $helptopic = $this->request->input('helptopic'); - $sla = $this->request->input('sla'); - $priority = $this->request->input('priority'); - $header = $this->request->input('cc'); - $dept = $this->request->input('dept'); + $sla = $this->request->input('sla'); + $priority = $this->request->input('priority'); + $header = $this->request->input('cc'); + $dept = $this->request->input('dept'); - $assignto = $this->request->input('assignto'); + $assignto = $this->request->input('assignto'); $form_data = $this->request->input('form_data'); - $source = $this->request->input('source'); - $attach = $this->request->input('attachments'); - $headers = []; - if ($header) - { + $source = $this->request->input('source'); + $attach = $this->request->input('attachments'); + $headers = []; + if ($header) { $headers = explode(',', $header); } //return $headers; /* * return s ticket number */ - $PhpMailController = new \App\Http\Controllers\Common\PhpMailController(); + $PhpMailController = new \App\Http\Controllers\Common\PhpMailController(); $NotificationController = new \App\Http\Controllers\Common\NotificationController(); - $core = new CoreTicketController($PhpMailController, $NotificationController); + $core = new CoreTicketController($PhpMailController, $NotificationController); $this->request->merge(['body' => preg_replace('/[ ](?=[^>]*(?:<|$))/', ' ', nl2br($this->request->get('body')))]); $request->replace($this->request->except('token', 'api_key')); - $response = $core->post_newticket($request, $code, true); + $response = $core->post_newticket($request, $code, true); //$response = $this->ticket->createTicket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data, $attach); //return $response; /* @@ -170,17 +161,13 @@ class ApiController extends Controller //$result = $this->thread->where('id', $response)->first(); //$result = $this->attach($result->id,$file); return response()->json(compact('response')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')) @@ -198,14 +185,12 @@ class ApiController extends Controller public function ticketReply() { //dd($this->request->all()); - try - { + try { $v = \Validator::make($this->request->all(), [ 'ticket_ID' => 'required|exists:tickets,id', 'reply_content' => 'required', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); @@ -218,17 +203,13 @@ class ApiController extends Controller ->first(); return response()->json(compact('result')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -242,8 +223,7 @@ class ApiController extends Controller */ public function editTicket() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'ticket_id' => 'required|exists:tickets,id', 'subject' => 'required', @@ -252,25 +232,21 @@ class ApiController extends Controller 'ticket_source' => 'required|exists:ticket_source,id', 'ticket_priority' => 'required|exists:ticket_priority,priority_id', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } $ticket_id = $this->request->input('ticket_id'); + return $this->ticket->ticketEditPost($ticket_id, $this->thread, $this->model); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -284,13 +260,11 @@ class ApiController extends Controller */ public function deleteTicket() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'ticket_id' => 'required|exists:tickets,id', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); @@ -300,17 +274,13 @@ class ApiController extends Controller $result = $this->ticket->delete(explode(',', $id), $this->model); return response()->json(compact('result')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -324,23 +294,20 @@ class ApiController extends Controller */ public function openedTickets() { - try - { + try { // $result = $this->model->where('status', '=', 1)->where('isanswered', '=', 0)->where('assigned_to', '=', null)->orderBy('id', 'DESC')->get(); // return response()->json(compact('result')); - $result = $this->user->join('tickets', function ($join) - { - $join->on('users.id', '=', 'tickets.user_id') + $result = $this->user->join('tickets', function ($join) { + $join->on('users.id', '=', 'tickets.user_id') ->where('isanswered', '=', 0)->where('status', '=', 1)->whereNull('assigned_to'); - }) + }) ->join('department', 'department.id', '=', 'tickets.dept_id') ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id') ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla') ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id') ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status') - ->join('ticket_thread', function ($join) - { + ->join('ticket_thread', function ($join) { $join->on('tickets.id', '=', 'ticket_thread.ticket_id') ->whereNotNull('title'); }) @@ -352,17 +319,13 @@ class ApiController extends Controller ->toJson(); return $result; - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -376,33 +339,28 @@ class ApiController extends Controller */ public function unassignedTickets() { - try - { + try { //dd('sdhjbc'); // $result = $this->model->where('assigned_to', '=', null)->where('status', '1')->orderBy('id', 'DESC')->get(); // return response()->json(compact('result')); - $user = \JWTAuth::parseToken()->authenticate(); - $unassigned = $this->user->join('tickets', function ($join) - { - $join->on('users.id', '=', 'tickets.user_id') + $user = \JWTAuth::parseToken()->authenticate(); + $unassigned = $this->user->join('tickets', function ($join) { + $join->on('users.id', '=', 'tickets.user_id') ->whereNull('assigned_to')->where('status', '=', 1); - }) + }) ->join('department', 'department.id', '=', 'tickets.dept_id') ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id') ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla') ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id') ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status') - ->leftJoin('ticket_thread', function ($join) - { + ->leftJoin('ticket_thread', function ($join) { $join->on('tickets.id', '=', 'ticket_thread.ticket_id'); }) ->leftJoin('ticket_attachment', 'ticket_attachment.thread_id', '=', 'ticket_thread.id'); - if ($user->role == 'agent') - { - $id = $user->id; - $dept = \DB::table('department_assign_agents')->where('agent_id', '=', $id)->pluck('department_id')->toArray(); - $unassigned = $unassigned->where(function ($query) use ($dept, $id) - { + if ($user->role == 'agent') { + $id = $user->id; + $dept = \DB::table('department_assign_agents')->where('agent_id', '=', $id)->pluck('department_id')->toArray(); + $unassigned = $unassigned->where(function ($query) use ($dept, $id) { $query->whereIn('tickets.dept_id', $dept) ->orWhere('assigned_to', '=', $id); }); @@ -415,17 +373,13 @@ class ApiController extends Controller ->toJson(); return $unassigned; - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -439,32 +393,27 @@ class ApiController extends Controller */ public function closeTickets() { - try - { + try { // $result = $this->model->where('status', '>', 1)->where('status', '<', 4)->orderBy('id', 'DESC')->get(); // return response()->json(compact('result')); - $user = \JWTAuth::parseToken()->authenticate(); - $result = $this->user->join('tickets', function ($join) - { - $join->on('users.id', '=', 'tickets.user_id') + $user = \JWTAuth::parseToken()->authenticate(); + $result = $this->user->join('tickets', function ($join) { + $join->on('users.id', '=', 'tickets.user_id') ->where('status', '=', 3)->orWhere('status', '=', 2); - }) + }) ->join('department', 'department.id', '=', 'tickets.dept_id') ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id') ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla') ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id') ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status') - ->leftJoin('ticket_thread', function ($join) - { + ->leftJoin('ticket_thread', function ($join) { $join->on('tickets.id', '=', 'ticket_thread.ticket_id'); }) ->leftJoin('ticket_attachment', 'ticket_attachment.thread_id', '=', 'ticket_thread.id'); - if ($user->role == 'agent') - { - $id = $user->id; - $dept = \DB::table('department_assign_agents')->where('agent_id', '=', $id)->pluck('department_id')->toArray(); - $result = $result->where(function ($query) use ($dept, $id) - { + if ($user->role == 'agent') { + $id = $user->id; + $dept = \DB::table('department_assign_agents')->where('agent_id', '=', $id)->pluck('department_id')->toArray(); + $result = $result->where(function ($query) use ($dept, $id) { $query->whereIn('tickets.dept_id', $dept) ->orWhere('assigned_to', '=', $id); }); @@ -477,17 +426,13 @@ class ApiController extends Controller ->toJson(); return $result; - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -501,22 +446,17 @@ class ApiController extends Controller */ public function getAgents() { - try - { + try { $result = $this->faveoUser->where('role', 'agent')->orWhere('role', 'admin')->where('active', 1)->get(); return response()->json(compact('result')); - } - catch (Exception $e) - { + } catch (Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -530,22 +470,17 @@ class ApiController extends Controller */ public function getTeams() { - try - { + try { $result = $this->team->get(); return response()->json(compact('result')); - } - catch (Exception $e) - { + } catch (Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -559,41 +494,32 @@ class ApiController extends Controller */ public function assignTicket() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'ticket_id' => 'required', 'user' => 'required', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } - $id = $this->request->input('ticket_id'); + $id = $this->request->input('ticket_id'); $response = $this->ticket->assign($id); - if ($response == 1) - { + if ($response == 1) { $result = 'success'; return response()->json(compact('result')); - } - else - { + } else { return response()->json(compact('response')); } - } - catch (Exception $e) - { + } catch (Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -607,33 +533,27 @@ class ApiController extends Controller */ public function getCustomers() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'search' => 'required', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } $search = $this->request->input('search'); - $result = $this->faveoUser->where('first_name', 'like', '%' . $search . '%')->orWhere('last_name', 'like', '%' . $search . '%')->orWhere('user_name', 'like', '%' . $search . '%')->orWhere('email', 'like', '%' . $search . '%')->get(); + $result = $this->faveoUser->where('first_name', 'like', '%'.$search.'%')->orWhere('last_name', 'like', '%'.$search.'%')->orWhere('user_name', 'like', '%'.$search.'%')->orWhere('email', 'like', '%'.$search.'%')->get(); return response()->json(compact('result')) ->header('X-Header-One', 'Header Value'); - } - catch (Exception $e) - { + } catch (Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')) @@ -648,8 +568,7 @@ class ApiController extends Controller */ public function getCustomersWith() { - try - { + try { $users = $this->user ->leftJoin('user_assign_organization', 'user_assign_organization.user_id', '=', 'users.id') ->leftJoin('organization', 'organization.id', '=', 'user_assign_organization.org_id') @@ -660,17 +579,13 @@ class ApiController extends Controller //dd($users); return $users; - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')) @@ -685,32 +600,26 @@ class ApiController extends Controller */ public function getCustomer() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'user_id' => 'required', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } - $id = $this->request->input('user_id'); + $id = $this->request->input('user_id'); $result = $this->faveoUser->where('id', $id)->where('role', 'user')->first(); return response()->json(compact('result')); - } - catch (Exception $e) - { + } catch (Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -724,32 +633,26 @@ class ApiController extends Controller */ public function searchTicket() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'search' => 'required', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } $search = $this->request->input('search'); - $result = $this->thread->select('ticket_id')->where('title', 'like', '%' . $search . '%')->orWhere('body', 'like', '%' . $search . '%')->get(); + $result = $this->thread->select('ticket_id')->where('title', 'like', '%'.$search.'%')->orWhere('body', 'like', '%'.$search.'%')->get(); return response()->json(compact('result')); - } - catch (Exception $e) - { + } catch (Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -763,18 +666,16 @@ class ApiController extends Controller */ public function ticketThreads() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'id' => 'required', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } - $id = $this->request->input('id'); + $id = $this->request->input('id'); $result = $this->user ->rightjoin('ticket_thread', 'ticket_thread.user_id', '=', 'users.id') ->select('ticket_thread.id', 'ticket_id', 'user_id', 'poster', 'source', 'title', 'body', 'is_internal', 'format', 'ip_address', 'ticket_thread.created_at', 'ticket_thread.updated_at', 'users.first_name', 'users.last_name', 'users.user_name', 'users.email', 'users.profile_pic') @@ -784,17 +685,13 @@ class ApiController extends Controller ->toJson(); return $result; - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -809,37 +706,30 @@ class ApiController extends Controller public function checkUrl() { //dd($this->request); - try - { + try { $v = \Validator::make($this->request->all(), [ 'url' => 'required|url', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } $url = $this->request->input('url'); - if (!str_is('*/', $url)) - { + if (!str_is('*/', $url)) { $url = str_finish($url, '/'); } - $url = $url . '/api/v1/helpdesk/check-url?api_key=' . $this->request->input('api_key') . '&token=' . \Config::get('app.token'); + $url = $url.'/api/v1/helpdesk/check-url?api_key='.$this->request->input('api_key').'&token='.\Config::get('app.token'); $result = $this->CallGetApi($url); //dd($result); return response()->json(compact('result')); - } - catch (\Exception $ex) - { + } catch (\Exception $ex) { $error = $e->getMessage(); return response()->json(compact('error')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -865,16 +755,15 @@ class ApiController extends Controller */ public function callGetApi($url) { - $curl = curl_init($url); + $curl = curl_init($url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); - if (curl_errno($curl)) - { - echo 'error:' . curl_error($curl); + if (curl_errno($curl)) { + echo 'error:'.curl_error($curl); } return $response; @@ -891,7 +780,7 @@ class ApiController extends Controller */ public function callPostApi($url, $data) { - $curl = curl_init($url); + $curl = curl_init($url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); @@ -899,9 +788,8 @@ class ApiController extends Controller curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $response = curl_exec($curl); - if (curl_errno($curl)) - { - echo 'error:' . curl_error($curl); + if (curl_errno($curl)) { + echo 'error:'.curl_error($curl); } return $response; @@ -915,36 +803,28 @@ class ApiController extends Controller */ public function generateApiKey() { - try - { + try { $set = $this->setting->where('id', '1')->first(); //dd($set); - if ($set->api_enable == 1) - { - $key = str_random(32); + if ($set->api_enable == 1) { + $key = str_random(32); $set->api_key = $key; $set->save(); - $result = $set->api_key; + $result = $set->api_key; return response()->json(compact('result')); - } - else - { + } else { $result = 'please enable api'; return response()->json(compact('result')); } - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -958,22 +838,17 @@ class ApiController extends Controller */ public function getHelpTopic() { - try - { + try { $result = $this->helptopic->get(); return response()->json(compact('result')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -987,22 +862,17 @@ class ApiController extends Controller */ public function getSlaPlan() { - try - { + try { $result = $this->slaPlan->get(); return response()->json(compact('result')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1016,22 +886,17 @@ class ApiController extends Controller */ public function getPriority() { - try - { + try { $result = $this->priority->select('priority as name', 'priority_id as id')->get(); return response()->json(compact('result')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1045,22 +910,17 @@ class ApiController extends Controller */ public function getDepartment() { - try - { + try { $result = $this->department->get(); return response()->json(compact('result')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1074,23 +934,18 @@ class ApiController extends Controller */ public function getTickets() { - try - { + try { $tickets = $this->model->orderBy('created_at', 'desc')->paginate(10); $tickets->toJson(); return $tickets; - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1104,31 +959,26 @@ class ApiController extends Controller */ public function inbox() { - try - { - $user = \JWTAuth::parseToken()->authenticate(); - $inbox = $this->user->join('tickets', function ($join) - { - $join->on('users.id', '=', 'tickets.user_id') + try { + $user = \JWTAuth::parseToken()->authenticate(); + $inbox = $this->user->join('tickets', function ($join) { + $join->on('users.id', '=', 'tickets.user_id') ->where('status', '=', 1); - }) + }) ->join('department', 'department.id', '=', 'tickets.dept_id') ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id') ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla') ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id') ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status') - ->leftJoin('ticket_thread', function ($join) - { + ->leftJoin('ticket_thread', function ($join) { $join->on('tickets.id', '=', 'ticket_thread.ticket_id'); }) ->leftJoin('ticket_attachment', 'ticket_attachment.thread_id', '=', 'ticket_thread.id') ->where('ticket_status.name', 'Open'); - if ($user->role == 'agent') - { - $id = $user->id; - $dept = \DB::table('department_assign_agents')->where('agent_id', '=', $id)->pluck('department_id')->toArray(); - $inbox = $inbox->where(function ($query) use ($dept, $id) - { + if ($user->role == 'agent') { + $id = $user->id; + $dept = \DB::table('department_assign_agents')->where('agent_id', '=', $id)->pluck('department_id')->toArray(); + $inbox = $inbox->where(function ($query) use ($dept, $id) { $query->whereIn('tickets.dept_id', $dept) ->orWhere('assigned_to', '=', $id); }); @@ -1141,17 +991,13 @@ class ApiController extends Controller ->toJson(); return $inbox; - } - catch (\Exception $ex) - { + } catch (\Exception $ex) { $error = $ex->getMessage(); - $line = $ex->getLine(); - $file = $ex->getFile(); + $line = $ex->getLine(); + $file = $ex->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1165,37 +1011,31 @@ class ApiController extends Controller */ public function internalNote() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'userid' => 'required|exists:users,id', 'ticketid' => 'required|exists:tickets,id', 'body' => 'required', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } - $userid = $this->request->input('userid'); + $userid = $this->request->input('userid'); $ticketid = $this->request->input('ticketid'); - $body = preg_replace('/[ ](?=[^>]*(?:<|$))/', ' ', nl2br($this->request->input('body'))); + $body = preg_replace('/[ ](?=[^>]*(?:<|$))/', ' ', nl2br($this->request->input('body'))); $thread = $this->thread->create(['ticket_id' => $ticketid, 'user_id' => $userid, 'is_internal' => 1, 'body' => $body]); return response()->json(compact('thread')); - } - catch (\Exception $ex) - { + } catch (\Exception $ex) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1204,30 +1044,25 @@ class ApiController extends Controller public function getTrash() { - try - { - $user = \JWTAuth::parseToken()->authenticate(); - $trash = $this->user->join('tickets', function ($join) - { - $join->on('users.id', '=', 'tickets.user_id') + try { + $user = \JWTAuth::parseToken()->authenticate(); + $trash = $this->user->join('tickets', function ($join) { + $join->on('users.id', '=', 'tickets.user_id') ->where('status', '=', 5); - }) + }) ->join('department', 'department.id', '=', 'tickets.dept_id') ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id') ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla') ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id') ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status') - ->leftJoin('ticket_thread', function ($join) - { + ->leftJoin('ticket_thread', function ($join) { $join->on('tickets.id', '=', 'ticket_thread.ticket_id'); }) ->leftJoin('ticket_attachment', 'ticket_attachment.thread_id', '=', 'ticket_thread.id'); - if ($user->role == 'agent') - { - $id = $user->id; - $dept = \DB::table('department_assign_agents')->where('agent_id', '=', $id)->pluck('department_id')->toArray(); - $trash = $trash->where(function ($query) use ($dept, $id) - { + if ($user->role == 'agent') { + $id = $user->id; + $dept = \DB::table('department_assign_agents')->where('agent_id', '=', $id)->pluck('department_id')->toArray(); + $trash = $trash->where(function ($query) use ($dept, $id) { $query->whereIn('tickets.dept_id', $dept) ->orWhere('assigned_to', '=', $id); }); @@ -1240,17 +1075,13 @@ class ApiController extends Controller ->toJson(); return $trash; - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1259,39 +1090,34 @@ class ApiController extends Controller public function getMyTicketsAgent() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'user_id' => 'required|exists:users,id', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } $id = $this->request->input('user_id'); - if ($this->user->where('id', $id)->first()->role == 'user') - { + if ($this->user->where('id', $id)->first()->role == 'user') { $error = 'This user is not an Agent or Admin'; return response()->json(compact('error')); } //$user = \JWTAuth::parseToken()->authenticate(); - $result = $this->user->join('tickets', function ($join) use ($id) - { - $join->on('users.id', '=', 'tickets.assigned_to') + $result = $this->user->join('tickets', function ($join) use ($id) { + $join->on('users.id', '=', 'tickets.assigned_to') ->where('status', '=', 1); - //->where('user_id', '=', $id); - }) + //->where('user_id', '=', $id); + }) ->join('users as client', 'tickets.user_id', '=', 'client.id') ->join('department', 'department.id', '=', 'tickets.dept_id') ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id') ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla') ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id') ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status') - ->leftJoin('ticket_thread', function ($join) - { + ->leftJoin('ticket_thread', function ($join) { $join->on('tickets.id', '=', 'ticket_thread.ticket_id'); }) ->leftJoin('ticket_attachment', 'ticket_attachment.thread_id', '=', 'ticket_thread.id') @@ -1306,17 +1132,13 @@ class ApiController extends Controller ->toJson(); return $result; - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1325,20 +1147,17 @@ class ApiController extends Controller public function getMyTicketsUser() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'user_id' => 'required|exists:users,id', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } $id = $this->request->input('user_id'); - if ($this->user->where('id', $id)->first()->role == 'admin' || $this->user->where('id', $id)->first()->role == 'agent') - { + if ($this->user->where('id', $id)->first()->role == 'admin' || $this->user->where('id', $id)->first()->role == 'agent') { $error = 'This is not a client'; return response()->json(compact('error')); @@ -1349,18 +1168,16 @@ class ApiController extends Controller ->select( 'users.first_name', 'users.last_name', 'users.user_name', 'users.email', 'users.id', 'users.profile_pic', 'users.ban', 'users.active', 'users.is_delete', 'users.phone_number', 'users.ext', 'users.country_code', 'users.mobile', 'organization.name as company' )->first()->toArray(); - $result = $this->user->join('tickets', function ($join) use ($id) - { - $join->on('users.id', '=', 'tickets.user_id') + $result = $this->user->join('tickets', function ($join) use ($id) { + $join->on('users.id', '=', 'tickets.user_id') ->where('user_id', '=', $id); - }) + }) ->join('department', 'department.id', '=', 'tickets.dept_id') ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id') ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla') ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id') ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status') - ->join('ticket_thread', function ($join) - { + ->join('ticket_thread', function ($join) { $join->on('tickets.id', '=', 'ticket_thread.ticket_id') ->whereNotNull('title'); }) @@ -1372,17 +1189,13 @@ class ApiController extends Controller ->toArray(); return response()->json(['tickets' => $result, 'requester' => $user]); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1391,26 +1204,22 @@ class ApiController extends Controller public function getTicketById() { - try - { + try { $v = \Validator::make($this->request->all(), [ 'id' => 'required|exists:tickets,id', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } $id = $this->request->input('id'); - if (!$this->model->where('id', $id)->first()) - { - $error = 'There is no Ticket as ticket id: ' . $id; + if (!$this->model->where('id', $id)->first()) { + $error = 'There is no Ticket as ticket id: '.$id; return response()->json(compact('error')); } - $query = $this->user->join('tickets', function ($join) use ($id) - { + $query = $this->user->join('tickets', function ($join) use ($id) { $join->on('users.id', '=', 'tickets.user_id') ->where('tickets.id', '=', $id); }); @@ -1427,17 +1236,13 @@ class ApiController extends Controller 'users.email', 'users.user_name', 'users.first_name', 'users.last_name', 'tickets.id', 'ticket_number', 'user_id', 'ticket_priority.priority_id', 'ticket_priority.priority as priority_name', 'department.name as dept_name', 'ticket_status.name as status_name', 'sla_plan.name as sla_name', 'ticket_source.name as source_name', 'sla_plan.id as sla', 'ticket_status.id as status', 'lock_by', 'lock_at', 'ticket_source.id as source', 'isoverdue', 'reopened', 'isanswered', 'is_deleted', 'closed', 'reopened_at', 'duedate', 'closed_at', 'tickets.created_at', 'tickets.updated_at')->first(); return response()->json(compact('result')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1446,8 +1251,7 @@ class ApiController extends Controller public function createPagination($array, $perPage) { - try - { + try { //Get current page form url e.g. &page=6 $currentPage = LengthAwarePaginator::resolveCurrentPage(); @@ -1461,17 +1265,13 @@ class ApiController extends Controller $paginatedResults = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage); return $paginatedResults; - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (\TokenExpiredException $e) - { + } catch (\TokenExpiredException $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1481,31 +1281,27 @@ class ApiController extends Controller public function collaboratorSearch() { $this->validate($this->request, ['term' => 'required']); - try - { + + try { $emails = $this->ticket->autosearch(); //return $emails; - $user = new User(); - if (count($emails) > 0) - { - foreach ($emails as $key => $email) - { - $user_model = $user->where('email', $email)->first(); + $user = new User(); + if (count($emails) > 0) { + foreach ($emails as $key => $email) { + $user_model = $user->where('email', $email)->first(); //return $user_model; - $users[$key]['name'] = $user_model->first_name . ' ' . $user_model->last_name; - $users[$key]['email'] = $email; + $users[$key]['name'] = $user_model->first_name.' '.$user_model->last_name; + $users[$key]['email'] = $email; $users[$key]['avatar'] = $this->avatarUrl($email); } } //return $users; return response()->json(compact('users')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); } @@ -1513,23 +1309,17 @@ class ApiController extends Controller public function avatarUrl($email) { - try - { + try { $user = new User(); $user = $user->where('email', $email)->first(); - if ($user->profile_pic) - { - $url = url('uploads/profilepic/' . $user->profile_pic); - } - else - { + if ($user->profile_pic) { + $url = url('uploads/profilepic/'.$user->profile_pic); + } else { $url = \Gravatar::src($email); } return $url; - } - catch (\Exception $ex) - { + } catch (\Exception $ex) { //return $ex->getMessage(); throw new \Exception($ex->getMessage()); } @@ -1537,15 +1327,13 @@ class ApiController extends Controller public function addCollaboratorForTicket() { - try - { + try { $v = \Validator::make(\Input::get(), [ 'email' => 'required|email|unique:users', 'ticket_id' => 'required', ] ); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->messages(); return response()->json(compact('error')); @@ -1553,20 +1341,16 @@ class ApiController extends Controller $collaborator = $this->ticket->useradd(); return response()->json(compact('collaborator')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $ex) - { + } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $ex) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); } @@ -1574,14 +1358,12 @@ class ApiController extends Controller public function getCollaboratorForTicket() { - try - { + try { $v = \Validator::make(\Input::get(), [ 'ticket_id' => 'required', ] ); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->messages(); return response()->json(compact('error')); @@ -1589,20 +1371,16 @@ class ApiController extends Controller $collaborator = $this->ticket->getCollaboratorForTicket(); return response()->json(compact('collaborator')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $ex) - { + } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $ex) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); } @@ -1610,15 +1388,13 @@ class ApiController extends Controller public function deleteCollaborator() { - try - { + try { $v = \Validator::make(\Input::get(), [ 'ticketid' => 'required', 'email' => 'required', ] ); - if ($v->fails()) - { + if ($v->fails()) { $result = $v->messages(); return response()->json(compact('result')); @@ -1626,12 +1402,10 @@ class ApiController extends Controller $collaborator = $this->ticket->userremove(); return response()->json(compact('collaborator')); - } - catch (\Exception $ex) - { + } catch (\Exception $ex) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); } @@ -1639,79 +1413,68 @@ class ApiController extends Controller public function dependency() { - try - { - $user = \JWTAuth::parseToken()->authenticate(); + try { + $user = \JWTAuth::parseToken()->authenticate(); $tickets = \DB::table('tickets'); - if ($user->role == 'agent') - { - $id = $user->id; - $dept = DepartmentAssignAgents::where('agent_id', '=', $id)->pluck('department_id')->toArray(); + if ($user->role == 'agent') { + $id = $user->id; + $dept = DepartmentAssignAgents::where('agent_id', '=', $id)->pluck('department_id')->toArray(); $tickets = $tickets->whereIn('tickets.dept_id', $dept)->orWhere('assigned_to', '=', $user->id); } $department = $this->department->select('name', 'id')->get()->toArray(); - $sla = $this->slaPlan->select('name', 'id')->get()->toArray(); - $staff = $this->user->where('role', 'agent')->select('email', 'id')->get()->toArray(); - $team = $this->team->select('name', 'id')->get()->toArray(); - $priority = \DB::table('ticket_priority')->select('priority', 'priority_id')->get(); - $helptopic = $this->helptopic->select('topic', 'id')->get()->toArray(); - $status = \DB::table('ticket_status')->select('name', 'id')->get(); - $source = \DB::table('ticket_source')->select('name', 'id')->get(); - $statuses = collect($tickets + $sla = $this->slaPlan->select('name', 'id')->get()->toArray(); + $staff = $this->user->where('role', 'agent')->select('email', 'id')->get()->toArray(); + $team = $this->team->select('name', 'id')->get()->toArray(); + $priority = \DB::table('ticket_priority')->select('priority', 'priority_id')->get(); + $helptopic = $this->helptopic->select('topic', 'id')->get()->toArray(); + $status = \DB::table('ticket_status')->select('name', 'id')->get(); + $source = \DB::table('ticket_source')->select('name', 'id')->get(); + $statuses = collect($tickets ->join('ticket_status', 'tickets.status', '=', 'ticket_status.id') ->select('ticket_status.name as status', \DB::raw('COUNT(tickets.id) as count')) ->groupBy('ticket_status.id') - ->get())->transform(function ($item) - { - return ['name' => ucfirst($item->status), 'count' => $item->count]; - }); - $unassigned = $this->user->leftJoin('tickets', function ($join) - { - $join->on('users.id', '=', 'tickets.user_id') + ->get())->transform(function ($item) { + return ['name' => ucfirst($item->status), 'count' => $item->count]; + }); + $unassigned = $this->user->leftJoin('tickets', function ($join) { + $join->on('users.id', '=', 'tickets.user_id') ->whereNull('assigned_to')->where('status', '=', 1); - }) - ->where(function($query) use($user) - { - if ($user->role != 'admin') - { + }) + ->where(function ($query) use ($user) { + if ($user->role != 'admin') { $query->where('tickets.dept_id', '=', $user->primary_dpt); } }) ->select(\DB::raw('COUNT(tickets.id) as unassined')) ->value('unassined'); - $mytickets = $this->user->leftJoin('tickets', function ($join) use ($user) - { - $join->on('users.id', '=', 'tickets.assigned_to') + $mytickets = $this->user->leftJoin('tickets', function ($join) use ($user) { + $join->on('users.id', '=', 'tickets.assigned_to') ->where('tickets.assigned_to', '=', $user->id)->where('status', '=', 1); - }) - ->where(function ($query) use ($user) - { - if ($user->role != 'admin') - { + }) + ->where(function ($query) use ($user) { + if ($user->role != 'admin') { $query->where('tickets.dept_id', '=', $user->primary_dpt)->orWhere('assigned_to', '=', $user->id); } }) ->select(\DB::raw('COUNT(tickets.id) as my_ticket')) ->value('my_ticket'); - $depend = collect([['name' => 'unassigned', 'count' => $unassigned], ['name' => 'mytickets', 'count' => $mytickets]]); + $depend = collect([['name' => 'unassigned', 'count' => $unassigned], ['name' => 'mytickets', 'count' => $mytickets]]); $collection = $statuses->merge($depend); - $result = ['departments' => $department, 'sla' => $sla, 'staffs' => $staff, 'teams' => $team, - 'priorities' => $priority, 'helptopics' => $helptopic, - 'status' => $status, - 'sources' => $source, - 'tickets_count' => $collection]; + $result = ['departments' => $department, 'sla' => $sla, 'staffs' => $staff, 'teams' => $team, + 'priorities' => $priority, 'helptopics' => $helptopic, + 'status' => $status, + 'sources' => $source, + 'tickets_count' => $collection, ]; return response()->json(compact('result')); // $result = ['departments' => $department, 'sla' => $sla, 'staffs' => $staff, 'teams' => $team, // 'priorities' => $priority, 'helptopics' => $helptopic, 'status' => $status, 'sources' => $source,]; return response()->json(compact('result')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); } @@ -1720,19 +1483,15 @@ class ApiController extends Controller public function differenciateHelpTopic($query) { $ticket = $query->first(); - $check = 'department'; - if ($ticket) - { - if ($ticket->dept_id && $ticket->help_topic_id) - { + $check = 'department'; + if ($ticket) { + if ($ticket->dept_id && $ticket->help_topic_id) { return $this->getSystem($check, $query); } - if (!$ticket->dept_id && $ticket->help_topic_id) - { + if (!$ticket->dept_id && $ticket->help_topic_id) { return $query->select('tickets.help_topic_id'); } - if ($ticket->dept_id && !$ticket->help_topic_id) - { + if ($ticket->dept_id && !$ticket->help_topic_id) { return $query->select('tickets.dept_id'); } } @@ -1742,8 +1501,7 @@ class ApiController extends Controller public function getSystem($check, $query) { - switch ($check) - { + switch ($check) { case 'department': return $query->select('tickets.dept_id'); case 'helpTopic': @@ -1762,38 +1520,33 @@ class ApiController extends Controller */ public function register(Request $request) { - try - { + try { $v = \Validator::make($request->all(), [ 'email' => 'required|email|unique:users', 'password' => 'required|min:6', ]); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->errors(); return response()->json(compact('error')); } - $auth = $this->user; - $email = $request->input('email'); + $auth = $this->user; + $email = $request->input('email'); $username = $request->input('email'); $password = \Hash::make($request->input('password')); - $role = $request->input('role'); - if ($auth->role == 'agent') - { + $role = $request->input('role'); + if ($auth->role == 'agent') { $role = 'user'; } - $user = new User(); - $user->password = $password; + $user = new User(); + $user->password = $password; $user->user_name = $username; - $user->email = $email; - $user->role = $role; + $user->email = $email; + $user->role = $role; $user->save(); return response()->json(compact('user')); - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); return response()->json(compact('error')); @@ -1802,54 +1555,46 @@ class ApiController extends Controller public function createUser() { - try - { + try { $v = \Validator::make( $this->request->all(), [ 'username' => 'required|unique:users,user_name', 'first_name' => 'required', ] ); - if ($v->fails()) - { + if ($v->fails()) { $error = $v->messages(); + return response()->json(compact('error')); } - $str = str_random(8); - $array = ['password' => $str, 'password_confirmation' => $str, 'email' => $this->request->input('email'), 'full_name' => $this->request->input('first_name')]; - $all = $this->request->input(); - $merged = $array + $all; + $str = str_random(8); + $array = ['password' => $str, 'password_confirmation' => $str, 'email' => $this->request->input('email'), 'full_name' => $this->request->input('first_name')]; + $all = $this->request->input(); + $merged = $array + $all; $request = new \App\Http\Requests\helpdesk\RegisterRequest(); $request->replace($merged); - if ($request->has('username')) - { + if ($request->has('username')) { $request->merge(['user_name' => $request->get('username')]); } \Route::dispatch($request); - $auth = new \App\Http\Controllers\Auth\AuthController(); - $user = new User(); + $auth = new \App\Http\Controllers\Auth\AuthController(); + $user = new User(); $register = $auth->postRegister($user, $request, true); - if ($register) - { + if ($register) { return response()->json(compact('register')); } - } - catch (\Exception $e) - { + } catch (\Exception $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); - } - catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) - { + } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) { $error = $e->getMessage(); - $line = $e->getLine(); - $file = $e->getFile(); + $line = $e->getLine(); + $file = $e->getFile(); return response()->json(compact('error', 'file', 'line')); } } - } diff --git a/app/Http/Controllers/Api/v1/TicketController.php b/app/Http/Controllers/Api/v1/TicketController.php index 24c5281f5..510c44857 100644 --- a/app/Http/Controllers/Api/v1/TicketController.php +++ b/app/Http/Controllers/Api/v1/TicketController.php @@ -32,7 +32,6 @@ use Mail; */ class TicketController extends Controller { - /** * Create a new controller instance. * @@ -40,7 +39,7 @@ class TicketController extends Controller */ public function __construct() { - $PhpMailController = new PhpMailController(); + $PhpMailController = new PhpMailController(); $this->PhpMailController = $PhpMailController; } @@ -58,51 +57,42 @@ class TicketController extends Controller */ public function createTicket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data, $attach = '') { - try - { + try { //return $headers; $max_number = Tickets::whereRaw('id = (select max(`id`) from tickets)')->first(); //dd($max_number); - if ($max_number == null) - { + if ($max_number == null) { $ticket_number = 'AAAA-9999-9999999'; - } - else - { - foreach ($max_number as $number) - { + } else { + foreach ($max_number as $number) { $ticket_number = $max_number->ticket_number; } } - $ticket = new Tickets(); + $ticket = new Tickets(); $ticket->ticket_number = $this->ticketNumber($ticket_number); //dd($this->ticketNumber($ticket_number)); - $ticket->user_id = $user_id; - $ticket->dept_id = $dept; + $ticket->user_id = $user_id; + $ticket->dept_id = $dept; $ticket->help_topic_id = $helptopic; - $ticket->sla = $sla; - $ticket->assigned_to = $assignto; - $ticket->status = '1'; - $ticket->priority_id = $priority; - $ticket->source = $source; + $ticket->sla = $sla; + $ticket->assigned_to = $assignto; + $ticket->status = '1'; + $ticket->priority_id = $priority; + $ticket->source = $source; $ticket->save(); //dd($ticket); - $ticket_number = $ticket->ticket_number; - $id = $ticket->id; - if ($form_data != null) - { + $ticket_number = $ticket->ticket_number; + $id = $ticket->id; + if ($form_data != null) { $help_topic = Help_topic::where('id', '=', $helptopic)->first(); - $forms = Fields::where('forms_id', '=', $help_topic->custom_form)->get(); - foreach ($form_data as $key => $form_details) - { - foreach ($forms as $from) - { - if ($from->name == $key) - { - $form_value = new Ticket_Form_Data(); + $forms = Fields::where('forms_id', '=', $help_topic->custom_form)->get(); + foreach ($form_data as $key => $form_details) { + foreach ($forms as $from) { + if ($from->name == $key) { + $form_value = new Ticket_Form_Data(); $form_value->ticket_id = $id; - $form_value->title = $from->label; - $form_value->content = $form_details; + $form_value->title = $from->label; + $form_value->content = $form_details; $form_value->save(); } } @@ -112,15 +102,12 @@ class TicketController extends Controller $this->storeCollaborators($headers, $id); $thread = $this->ticketThread($subject, $body, $id, $user_id); - if (!empty($attach)) - { + if (!empty($attach)) { $this->attach($thread, $attach); } return $thread; - } - catch (\Exception $e) - { + } catch (\Exception $e) { return $e->getMessage(); } } @@ -134,52 +121,44 @@ class TicketController extends Controller */ public function storeCollaborators($headers, $id) { - try - { + try { //return $headers; $company = $this->company(); - if (isset($headers)) - { - foreach ($headers as $email) - { - $name = $email; + if (isset($headers)) { + foreach ($headers as $email) { + $name = $email; $email = $email; - if ($this->checkEmail($email) == false) - { - $create_user = new User(); + if ($this->checkEmail($email) == false) { + $create_user = new User(); $create_user->user_name = $name; - $create_user->email = $email; - $create_user->active = 1; - $create_user->role = 'user'; - $password = $this->generateRandomString(); - $create_user->password = Hash::make($password); + $create_user->email = $email; + $create_user->active = 1; + $create_user->role = 'user'; + $password = $this->generateRandomString(); + $create_user->password = Hash::make($password); $create_user->save(); - $user_id = $create_user->id; + $user_id = $create_user->id; // Mail::send('emails.pass', ['password' => $password, 'name' => $name, 'from' => $company, 'emailadd' => $email], function ($message) use ($email, $name) { // $message->to($email, $name)->subject('password'); // }); - $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => 'password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]); - } - else - { - $user = $this->checkEmail($email); + $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => 'password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]); + } else { + $user = $this->checkEmail($email); $user_id = $user->id; } //return $user_id; - $collaborator_store = new Ticket_Collaborator(); - $collaborator_store->isactive = 1; + $collaborator_store = new Ticket_Collaborator(); + $collaborator_store->isactive = 1; $collaborator_store->ticket_id = $id; - $collaborator_store->user_id = $user_id; - $collaborator_store->role = 'ccc'; + $collaborator_store->user_id = $user_id; + $collaborator_store->role = 'ccc'; $collaborator_store->save(); } } return true; - } - catch (\Exception $e) - { + } catch (\Exception $e) { return $e->getMessage(); } } @@ -196,20 +175,17 @@ class TicketController extends Controller */ public function ticketThread($subject, $body, $id, $user_id) { - try - { - $thread = new Ticket_Thread(); - $thread->user_id = $user_id; + try { + $thread = new Ticket_Thread(); + $thread->user_id = $user_id; $thread->ticket_id = $id; - $thread->poster = 'client'; - $thread->title = $subject; - $thread->body = $body; + $thread->poster = 'client'; + $thread->title = $subject; + $thread->body = $body; $thread->save(); return $thread->id; - } - catch (\Exception $e) - { + } catch (\Exception $e) { return $e->getMessage(); } } @@ -223,24 +199,20 @@ class TicketController extends Controller */ public function ticketNumber($ticket_number) { - try - { + try { //dd($ticket_number); - $number = $ticket_number; - $number = explode('-', $number); + $number = $ticket_number; + $number = explode('-', $number); $number1 = $number[0]; - if ($number1 == 'ZZZZ') - { + if ($number1 == 'ZZZZ') { $number1 = 'AAAA'; } $number2 = $number[1]; - if ($number2 == '9999') - { + if ($number2 == '9999') { $number2 = '0000'; } $number3 = $number[2]; - if ($number3 == '9999999') - { + if ($number3 == '9999999') { $number3 = '0000000'; } $number1++; @@ -248,13 +220,11 @@ class TicketController extends Controller $number3++; $number2 = sprintf('%04s', $number2); $number3 = sprintf('%07s', $number3); - $array = [$number1, $number2, $number3]; - $number = implode('-', $array); + $array = [$number1, $number2, $number3]; + $number = implode('-', $array); return $number; - } - catch (\Exception $e) - { + } catch (\Exception $e) { dd($e); return $e->getMessage(); @@ -270,20 +240,16 @@ class TicketController extends Controller */ public function generateRandomString($length = 10) { - try - { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + try { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < $length; $i++) - { + $randomString = ''; + for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; - } - catch (\Exception $e) - { + } catch (\Exception $e) { return $e->getMessage(); } } @@ -298,71 +264,64 @@ class TicketController extends Controller */ public function reply($thread, $request, $ta, $attach = '') { - try - { + try { $check_attachment = null; - $eventthread = $thread->where('ticket_id', $request->input('ticket_ID'))->first(); + $eventthread = $thread->where('ticket_id', $request->input('ticket_ID'))->first(); //dd($request->input('ticket_ID')); //dd($eventthread); - $eventuserid = $eventthread->user_id; - $emailadd = User::where('id', $eventuserid)->first()->email; + $eventuserid = $eventthread->user_id; + $emailadd = User::where('id', $eventuserid)->first()->email; //dd($emailadd); - $source = $eventthread->source; + $source = $eventthread->source; - $form_data = $request->except('reply_content', 'ticket_ID', 'attachment'); + $form_data = $request->except('reply_content', 'ticket_ID', 'attachment'); \Event::fire(new \App\Events\ClientTicketFormPost($form_data, $emailadd, $source)); //dd('yes'); - $reply_content = $request->input('reply_content'); - $thread->ticket_id = $request->input('ticket_ID'); - $thread->poster = 'support'; - $thread->body = $request->input('reply_content'); - $thread->user_id = Auth::user()->id; - $ticket_id = $request->input('ticket_ID'); - $tickets = Tickets::where('id', '=', $ticket_id)->first(); + $reply_content = $request->input('reply_content'); + $thread->ticket_id = $request->input('ticket_ID'); + $thread->poster = 'support'; + $thread->body = $request->input('reply_content'); + $thread->user_id = Auth::user()->id; + $ticket_id = $request->input('ticket_ID'); + $tickets = Tickets::where('id', '=', $ticket_id)->first(); $tickets->isanswered = '1'; $tickets->save(); $ticket_user = User::where('id', '=', $tickets->user_id)->first(); - if ($tickets->assigned_to == 0) - { + if ($tickets->assigned_to == 0) { $tickets->assigned_to = Auth::user()->id; $tickets->save(); - $thread2 = new Ticket_Thread(); - $thread2->ticket_id = $thread->ticket_id; - $thread2->user_id = Auth::user()->id; + $thread2 = new Ticket_Thread(); + $thread2->ticket_id = $thread->ticket_id; + $thread2->user_id = Auth::user()->id; $thread2->is_internal = 1; - $thread2->body = 'This Ticket have been assigned to ' . Auth::user()->first_name . ' ' . Auth::user()->last_name; + $thread2->body = 'This Ticket have been assigned to '.Auth::user()->first_name.' '.Auth::user()->last_name; $thread2->save(); } - if ($tickets->status > 1) - { - $tickets->status = '1'; + if ($tickets->status > 1) { + $tickets->status = '1'; $tickets->isanswered = '1'; $tickets->save(); } $thread->save(); - if (!empty($attach)) - { + if (!empty($attach)) { $check_attachment = $this->attach($thread->id, $attach); } - $thread1 = Ticket_Thread::where('ticket_id', '=', $ticket_id)->first(); + $thread1 = Ticket_Thread::where('ticket_id', '=', $ticket_id)->first(); $ticket_subject = $thread1->title; - $user_id = $tickets->user_id; - $user = User::where('id', '=', $user_id)->first(); - $email = $user->email; - $user_name = $user->user_name; - $ticket_number = $tickets->ticket_number; - $company = $this->company(); - $username = $ticket_user->user_name; - if (!empty(Auth::user()->agent_sign)) - { + $user_id = $tickets->user_id; + $user = User::where('id', '=', $user_id)->first(); + $email = $user->email; + $user_name = $user->user_name; + $ticket_number = $tickets->ticket_number; + $company = $this->company(); + $username = $ticket_user->user_name; + if (!empty(Auth::user()->agent_sign)) { $agentsign = Auth::user()->agent_sign; - } - else - { + } else { $agentsign = null; } \Event::fire(new \App\Events\FaveoAfterReply($reply_content, $user->phone_number, $request, $tickets)); @@ -370,67 +329,54 @@ class TicketController extends Controller // Mail::send(array('html' => 'emails.ticket_re-reply'), ['content' => $reply_content, 'ticket_number' => $ticket_number, 'From' => $company, 'name' => $username, 'Agent_Signature' => $agentsign], function ($message) use ($email, $user_name, $ticket_number, $ticket_subject, $check_attachment) { // $message->to($email, $user_name)->subject($ticket_subject . '[#' . $ticket_number . ']'); // // if(isset($attachments)){ -// // if ($check_attachment == 1) { -// // $size = count($attach); -// // for ($i = 0; $i < $size; $i++) { -// // $message->attach($attachments[$i]->getRealPath(), ['as' => $attachments[$i]->getClientOriginalName(), 'mime' => $attachments[$i]->getClientOriginalExtension()]); -// // } -// // } + // // if ($check_attachment == 1) { + // // $size = count($attach); + // // for ($i = 0; $i < $size; $i++) { + // // $message->attach($attachments[$i]->getRealPath(), ['as' => $attachments[$i]->getClientOriginalName(), 'mime' => $attachments[$i]->getClientOriginalExtension()]); + // // } + // // } // }, true); //dd('reply'); /* * Getting the subject of the thread */ //dd($eventthread); - try - { - $re = $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $tickets->dept_id), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => $eventthread->title, 'scenario' => 'create-ticket-by-agent', 'body' => $thread->body], $template_variables = ['agent_sign' => Auth::user()->agent_sign, 'ticket_number' => $tickets->number]); + try { + $re = $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $tickets->dept_id), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => $eventthread->title, 'scenario' => 'create-ticket-by-agent', 'body' => $thread->body], $template_variables = ['agent_sign' => Auth::user()->agent_sign, 'ticket_number' => $tickets->number]); //dd($re); - } - catch (\Exception $e) - { + } catch (\Exception $e) { //throw new \Exception($e->getMessage()); } $collaborators = Ticket_Collaborator::where('ticket_id', '=', $ticket_id)->get(); - foreach ($collaborators as $collaborator) - { + foreach ($collaborators as $collaborator) { //mail to collaborators $collab_user_id = $collaborator->user_id; $user_id_collab = User::where('id', '=', $collab_user_id)->first(); - $collab_email = $user_id_collab->email; - if ($user_id_collab->role == 'user') - { + $collab_email = $user_id_collab->email; + if ($user_id_collab->role == 'user') { $collab_user_name = $user_id_collab->user_name; - } - else - { - $collab_user_name = $user_id_collab->first_name . ' ' . $user_id_collab->last_name; + } else { + $collab_user_name = $user_id_collab->first_name.' '.$user_id_collab->last_name; } // Mail::send('emails.ticket_re-reply', ['content' => $reply_content, 'ticket_number' => $ticket_number, 'From' => $company, 'name' => $collab_user_name, 'Agent_Signature' => $agentsign], function ($message) use ($collab_email, $collab_user_name, $ticket_number, $ticket_subject, $check_attachment) { // $message->to($collab_email, $collab_user_name)->subject($ticket_subject . '[#' . $ticket_number . ']'); -// // if ($check_attachment == 1) { -// // $size = sizeOf($attachments); -// // for ($i = 0; $i < $size; $i++) { -// // $message->attach($attachments[$i]->getRealPath(), ['as' => $attachments[$i]->getClientOriginalName(), 'mime' => $attachments[$i]->getClientOriginalExtension()]); -// // } -// // } + // // if ($check_attachment == 1) { + // // $size = sizeOf($attachments); + // // for ($i = 0; $i < $size; $i++) { + // // $message->attach($attachments[$i]->getRealPath(), ['as' => $attachments[$i]->getClientOriginalName(), 'mime' => $attachments[$i]->getClientOriginalExtension()]); + // // } + // // } // }, true); - try - { - $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['user' => $admin_user, 'email' => $admin_email], $message = ['subject' => $updated_subject, 'body' => $body, 'scenario' => $mail], $template_variables = ['ticket_agent_name' => $admin_user, 'ticket_client_name' => $username, 'ticket_client_email' => $emailadd, 'user' => $admin_user, 'ticket_number' => $ticket_number2, 'email_address' => $emailadd, 'name' => $ticket_creator]); - } - catch (\Exception $e) - { - + try { + $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['user' => $admin_user, 'email' => $admin_email], $message = ['subject' => $updated_subject, 'body' => $body, 'scenario' => $mail], $template_variables = ['ticket_agent_name' => $admin_user, 'ticket_client_name' => $username, 'ticket_client_email' => $emailadd, 'user' => $admin_user, 'ticket_number' => $ticket_number2, 'email_address' => $emailadd, 'name' => $ticket_creator]); + } catch (\Exception $e) { } } return $thread; - } - catch (\Exception $e) - { + } catch (\Exception $e) { //dd($e); return $e->getMessage(); } @@ -443,22 +389,16 @@ class TicketController extends Controller */ public function company() { - try - { + try { $company = Company::Where('id', '=', '1')->first(); - if ($company->company_name == null) - { + if ($company->company_name == null) { $company = 'Support Center'; - } - else - { + } else { $company = $company->company_name; } return $company; - } - catch (\Exception $e) - { + } catch (\Exception $e) { return $e->getMessage(); } } @@ -473,27 +413,26 @@ class TicketController extends Controller */ public function ticketEditPost($ticket_id, $thread, $ticket) { - try - { + try { $ticket = $ticket->where('id', '=', $ticket_id)->first(); - $ticket->sla = Input::get('sla_plan'); + $ticket->sla = Input::get('sla_plan'); $ticket->help_topic_id = Input::get('help_topic'); - $ticket->source = Input::get('ticket_source'); - $ticket->priority_id = Input::get('ticket_priority'); - $ticket->status = Input::get('status'); + $ticket->source = Input::get('ticket_source'); + $ticket->priority_id = Input::get('ticket_priority'); + $ticket->status = Input::get('status'); $ticket->save(); - $threads = $thread->where('ticket_id', '=', $ticket_id)->first(); + $threads = $thread->where('ticket_id', '=', $ticket_id)->first(); $threads->title = Input::get('subject'); $threads->save(); - } - catch (\Exception $ex) - { + } catch (\Exception $ex) { $result = $ex->getMessage(); + return response()->json(compact('result'), 500); } - $result = ["success" => "Edited successfully"]; + $result = ['success' => 'Edited successfully']; + return response()->json(compact('result')); } @@ -506,66 +445,56 @@ class TicketController extends Controller */ public function assign($id) { - try - { + try { $UserEmail = Input::get('user'); //dd($UserEmail); // $UserEmail = 'sujitprasad12@yahoo.in'; - $user = User::where('email', '=', $UserEmail)->first(); - if (!$user) - { + $user = User::where('email', '=', $UserEmail)->first(); + if (!$user) { return ['error' => 'No agent not found']; } $user_id = $user->id; - $ticket = Tickets::where('id', '=', $id)->first(); - if (!$ticket) - { + $ticket = Tickets::where('id', '=', $id)->first(); + if (!$ticket) { return ['error' => 'No ticket not found']; } - $ticket_number = $ticket->ticket_number; + $ticket_number = $ticket->ticket_number; $ticket->assigned_to = $user_id; $ticket->save(); - $ticket_thread = Ticket_Thread::where('ticket_id', '=', $id)->first(); - if (!$ticket_thread) - { + $ticket_thread = Ticket_Thread::where('ticket_id', '=', $id)->first(); + if (!$ticket_thread) { return ['error' => 'No thread not found']; } - $ticket_subject = $ticket_thread->title; - $thread = new Ticket_Thread(); - $thread->ticket_id = $ticket->id; - $thread->user_id = Auth::user()->id; + $ticket_subject = $ticket_thread->title; + $thread = new Ticket_Thread(); + $thread->ticket_id = $ticket->id; + $thread->user_id = Auth::user()->id; $thread->is_internal = 1; - $thread->body = 'This Ticket has been assigned to ' . $user->first_name . ' ' . $user->last_name; + $thread->body = 'This Ticket has been assigned to '.$user->first_name.' '.$user->last_name; $thread->save(); $company = $this->company(); - $system = $this->system(); + $system = $this->system(); - $agent = $user->first_name; + $agent = $user->first_name; $agent_email = $user->email; - $master = Auth::user()->first_name . ' ' . Auth::user()->last_name; - if (Alert::first()->internal_status == 1 || Alert::first()->internal_assigned_agent == 1) - { + $master = Auth::user()->first_name.' '.Auth::user()->last_name; + 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 . ']'); // }); - try - { - $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticket->dept_id), $to = ['name' => $agent, 'email' => $agent_email], $message = ['subject' => $ticket_subject . '[#' . $ticket_number . ']', 'scenario' => 'assign-ticket'], $template_variables = ['ticket_agent_name' => $agent, 'ticket_number' => $ticket_number, 'ticket_assigner' => $master]); - } - catch (\Exception $e) - { + try { + $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticket->dept_id), $to = ['name' => $agent, 'email' => $agent_email], $message = ['subject' => $ticket_subject.'[#'.$ticket_number.']', 'scenario' => 'assign-ticket'], $template_variables = ['ticket_agent_name' => $agent, 'ticket_number' => $ticket_number, 'ticket_assigner' => $master]); + } catch (\Exception $e) { return 0; } } return 1; - } - catch (\Exception $e) - { + } catch (\Exception $e) { return $e->getMessage(); } } @@ -580,63 +509,47 @@ class TicketController extends Controller */ public function delete($ids, $ticket) { - try - { - foreach ($ids as $id) - { + try { + foreach ($ids as $id) { $ticket_delete = $ticket->where('id', '=', $id)->first(); - if ($ticket_delete) - { - if ($ticket_delete->status == 5) - { + if ($ticket_delete) { + if ($ticket_delete->status == 5) { $ticket_delete->delete(); $ticket_threads = Ticket_Thread::where('ticket_id', '=', $id)->get(); - if ($ticket_threads) - { - foreach ($ticket_threads as $ticket_thread) - { - if ($ticket_thread) - { + if ($ticket_threads) { + foreach ($ticket_threads as $ticket_thread) { + if ($ticket_thread) { $ticket_thread->delete(); } } } $ticket_attachments = Ticket_attachments::where('thread_id', '=', $id)->get(); - if ($ticket_attachments) - { - foreach ($ticket_attachments as $ticket_attachment) - { - if ($ticket_attachment) - { + if ($ticket_attachments) { + foreach ($ticket_attachments as $ticket_attachment) { + if ($ticket_attachment) { $ticket_attachment->delete(); } } } - } - else - { + } else { $ticket_delete->is_deleted = 0; - $ticket_delete->status = 5; + $ticket_delete->status = 5; $ticket_delete->save(); - $ticket_status_message = Ticket_Status::where('id', '=', $ticket_delete->status)->first(); - $thread = new Ticket_Thread(); - $thread->ticket_id = $ticket_delete->id; - $thread->user_id = Auth::user()->id; - $thread->is_internal = 1; - $thread->body = $ticket_status_message->message . ' ' . Auth::user()->first_name . ' ' . Auth::user()->last_name; + $ticket_status_message = Ticket_Status::where('id', '=', $ticket_delete->status)->first(); + $thread = new Ticket_Thread(); + $thread->ticket_id = $ticket_delete->id; + $thread->user_id = Auth::user()->id; + $thread->is_internal = 1; + $thread->body = $ticket_status_message->message.' '.Auth::user()->first_name.' '.Auth::user()->last_name; $thread->save(); } - } - else - { + } else { return 'ticket not found'; } } return 'your tickets has been deleted'; - } - catch (\Exception $e) - { + } catch (\Exception $e) { return $e->getMessage(); } } @@ -650,20 +563,14 @@ class TicketController extends Controller */ public function checkEmail($email) { - try - { + try { $check = User::where('email', '=', $email)->first(); - if ($check) - { + if ($check) { return $check; - } - else - { + } else { return false; } - } - catch (\Exception $e) - { + } catch (\Exception $e) { return $e->getMessage(); } } @@ -675,22 +582,16 @@ class TicketController extends Controller */ public function system() { - try - { + try { $system = System::Where('id', '=', '1')->first(); - if ($system->name == null) - { + if ($system->name == null) { $system = 'Support Center'; - } - else - { + } else { $system = $system->name; } return $system; - } - catch (\Exception $e) - { + } catch (\Exception $e) { return $e->getMessage(); } } @@ -705,19 +606,15 @@ class TicketController extends Controller */ public function attach($thread, $attach) { - try - { + try { $ta = new Ticket_attachments(); - foreach ($attach as $file) - { + foreach ($attach as $file) { $ta->create(['thread_id' => $thread, 'name' => $file['name'], 'size' => $file['size'], 'type' => $file['type'], 'file' => $file['file'], 'poster' => 'ATTACHMENT']); } $ta->create(['thread_id' => $thread, 'name' => $name, 'size' => $size, 'type' => $type, 'file' => $file, 'poster' => 'ATTACHMENT']); return 1; - } - catch (\Exception $e) - { + } catch (\Exception $e) { return $e->getMessage(); } } @@ -730,7 +627,7 @@ class TicketController extends Controller public function autosearch() { $term = \Input::get('term'); - $user = \App\User::where('email', 'LIKE', '%' . $term . '%')->orWhere('first_name', 'LIKE', '%' . $term . '%')->orWhere('last_name', 'LIKE', '%' . $term . '%')->orWhere('user_name', 'LIKE', '%' . $term . '%')->lists('email'); + $user = \App\User::where('email', 'LIKE', '%'.$term.'%')->orWhere('first_name', 'LIKE', '%'.$term.'%')->orWhere('last_name', 'LIKE', '%'.$term.'%')->orWhere('user_name', 'LIKE', '%'.$term.'%')->lists('email'); return $user; } @@ -744,27 +641,26 @@ class TicketController extends Controller */ public function useradd() { - $email = Input::get('email'); - $ticket_id = Input::get('ticket_id'); - $company = $this->company(); - $user = new User(); + $email = Input::get('email'); + $ticket_id = Input::get('ticket_id'); + $company = $this->company(); + $user = new User(); $user->user_name = $email; - $user->email = $email; - $password = $this->generateRandomString(); - $user->password = \Hash::make($password); - $user->role = 'user'; - $user->active = 1; - if ($user->save()) - { - $user_id = $user->id; - $php_mailer = new PhpMailController(); - $php_mailer->sendmail($from = $php_mailer->mailfrom('1', '0'), $to = ['name' => $email, 'email' => $email], $message = ['subject' => 'Password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $email, 'email_address' => $email, 'user_password' => $password]); + $user->email = $email; + $password = $this->generateRandomString(); + $user->password = \Hash::make($password); + $user->role = 'user'; + $user->active = 1; + if ($user->save()) { + $user_id = $user->id; + $php_mailer = new PhpMailController(); + $php_mailer->sendmail($from = $php_mailer->mailfrom('1', '0'), $to = ['name' => $email, 'email' => $email], $message = ['subject' => 'Password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $email, 'email_address' => $email, 'user_password' => $password]); } - $ticket_collaborator = new Ticket_Collaborator(); - $ticket_collaborator->isactive = 1; + $ticket_collaborator = new Ticket_Collaborator(); + $ticket_collaborator->isactive = 1; $ticket_collaborator->ticket_id = $ticket_id; - $ticket_collaborator->user_id = $user->id; - $ticket_collaborator->role = 'ccc'; + $ticket_collaborator->user_id = $user->id; + $ticket_collaborator->role = 'ccc'; $ticket_collaborator->save(); $result = [$user->user_name => $user->email]; @@ -779,84 +675,67 @@ class TicketController extends Controller */ public function userremove() { - $email = Input::get('email'); - $ticketid = Input::get('ticketid'); - $user = new User(); - $user = $user->where('email', $email)->first(); + $email = Input::get('email'); + $ticketid = Input::get('ticketid'); + $user = new User(); + $user = $user->where('email', $email)->first(); $ticket_collaborator = Ticket_Collaborator::where('ticket_id', '=', $ticketid) ->where('user_id', $user->id) ->first(); - if ($ticket_collaborator) - { + if ($ticket_collaborator) { $ticket_collaborator->delete(); return 'deleted successfully'; - } - else - { + } else { return 'not found'; } } public function getCollaboratorForTicket() { - try - { + try { $ticketid = Input::get('ticket_id'); $ticket_collaborator = \DB::table('users') - ->join('ticket_collaborator', function ($join) use ($ticketid) - { + ->join('ticket_collaborator', function ($join) use ($ticketid) { $join->on('users.id', '=', 'ticket_collaborator.user_id') ->where('ticket_collaborator.ticket_id', '=', $ticketid); }) ->select('users.email', 'users.user_name') ->get(); - if (count($ticket_collaborator) > 0) - { - foreach ($ticket_collaborator as $key => $collaborator) - { - $collab[$key]['email'] = $collaborator->email; + if (count($ticket_collaborator) > 0) { + foreach ($ticket_collaborator as $key => $collaborator) { + $collab[$key]['email'] = $collaborator->email; $collab[$key]['user_name'] = $collaborator->user_name; - $collab[$key]['avatar'] = $this->avatarUrl($collaborator->email); + $collab[$key]['avatar'] = $this->avatarUrl($collaborator->email); } - } - else - { + } else { $collab = $ticket_collaborator; } return $collab; - } - catch (\Exception $ex) - { + } catch (\Exception $ex) { return $ex->getMessage(); + throw new \Exception('get collaborator for ticket fails'); } } public function avatarUrl($email) { - try - { + try { $user = new User(); $user = $user->where('email', $email)->first(); - if ($user->profile_pic) - { - $url = url('uploads/profilepic/' . $user->profile_pic); - } - else - { + if ($user->profile_pic) { + $url = url('uploads/profilepic/'.$user->profile_pic); + } else { $url = \Gravatar::src($email); } return $url; - } - catch (\Exception $ex) - { + } catch (\Exception $ex) { //return $ex->getMessage(); throw new \Exception($ex->getMessage()); } } - } diff --git a/app/Http/Controllers/Api/v1/TokenAuthController.php b/app/Http/Controllers/Api/v1/TokenAuthController.php index f5c38b722..3edead411 100644 --- a/app/Http/Controllers/Api/v1/TokenAuthController.php +++ b/app/Http/Controllers/Api/v1/TokenAuthController.php @@ -47,7 +47,7 @@ class TokenAuthController extends Controller $password = $request->input('password'); $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name'; -//$credentials = $request->only('email', 'password'); + //$credentials = $request->only('email', 'password'); try { if (!$token = JWTAuth::attempt([$field => $usernameinput, 'password' => $password, 'active'=>1])) { @@ -62,7 +62,7 @@ class TokenAuthController extends Controller } $user_id = \Auth::user(); -// if no errors are encountered we can return a JWT + // if no errors are encountered we can return a JWT return response()->json(compact('token', 'user_id')); } @@ -89,7 +89,7 @@ class TokenAuthController extends Controller return response()->json(compact('error')); } -//dd($user); + //dd($user); return response()->json(compact('user')); } @@ -172,7 +172,7 @@ class TokenAuthController extends Controller $password_reset_table = \DB::table('password_resets')->where('email', '=', $user->email)->first(); if (isset($password_reset_table)) { $password_reset_table = \DB::table('password_resets')->where('email', '=', $user->email)->update(['token' => $code, 'created_at' => $date]); - // $password_reset_table->token = $code; + // $password_reset_table->token = $code; // $password_reset_table->update(['token' => $code]); } else { $create_password_reset = \DB::table('password_resets')->insert(['email' => $user->email, 'token' => $code, 'created_at' => $date]); diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index cbba80e92..61cc14b67 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -38,17 +38,16 @@ use Socialite; */ class AuthController extends Controller { - use AuthenticatesAndRegistersUsers; /* to redirect after login */ // if auth is agent - protected $redirectTo = '/dashboard'; + protected $redirectTo = '/dashboard'; // if auth is user - protected $redirectToUser = '/profile'; + protected $redirectToUser = '/profile'; /* Direct After Logout */ protected $redirectAfterLogout = '/'; - protected $loginPath = '/auth/login'; + protected $loginPath = '/auth/login'; protected $social; /** @@ -69,8 +68,7 @@ class AuthController extends Controller public function redirectToProvider($provider, $redirect = '') { - if ($redirect !== '') - { + if ($redirect !== '') { $this->setSession($provider, $redirect); } //dd(\Config::get('services')); @@ -81,23 +79,19 @@ class AuthController extends Controller public function handleProviderCallback($provider) { - try - { + try { //notice we are not doing any validation, you should do it $this->changeRedirect(); $user = Socialite::driver($provider)->user(); - if ($user) - { + if ($user) { // stroing data to our use table and logging them in - $username = $user->getEmail(); + $username = $user->getEmail(); $first_name = $user->getName(); - if ($user->nickname) - { + if ($user->nickname) { $username = $user->nickname; } - if (!$first_name) - { + if (!$first_name) { $first_name = $username; } $data = [ @@ -108,21 +102,17 @@ class AuthController extends Controller 'active' => 1, ]; $user = User::where('email', $data['email'])->first(); - if (!$user) - { + if (!$user) { $user = User::where('user_name', $data['user_name'])->first(); } - if (!$user) - { + if (!$user) { $user = User::firstOrCreate($data); } Auth::login($user); } //after login redirecting to home page return redirect('/'); - } - catch (\Exception $ex) - { + } catch (\Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } @@ -135,23 +125,17 @@ class AuthController extends Controller public function getRegister(CommonSettings $settings) { // Event for login - $settings = $settings->select('status')->where('option_name', '=', 'send_otp')->first(); + $settings = $settings->select('status')->where('option_name', '=', 'send_otp')->first(); $email_mandatory = $settings->select('status')->where('option_name', '=', 'email_mandatory')->first(); //dd($settings->status); \Event::fire(new \App\Events\FormRegisterEvent()); - if (Auth::user()) - { - if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent') - { + if (Auth::user()) { + if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent') { return \Redirect::route('dashboard'); - } - elseif (Auth::user()->role == 'user') - { + } elseif (Auth::user()->role == 'user') { // return view('auth.register'); } - } - else - { + } else { return view('auth.register', compact('settings', 'email_mandatory')); } } @@ -167,99 +151,71 @@ class AuthController extends Controller public function postRegister(User $user, RegisterRequest $request, $api = false) { //dd($request->all()); - try - { - $request_array = $request->input(); - $password = Hash::make($request->input('password')); - $user->password = $password; - $name = $request->input('full_name'); + try { + $request_array = $request->input(); + $password = Hash::make($request->input('password')); + $user->password = $password; + $name = $request->input('full_name'); $user->first_name = $name; - if ($request_array['email'] == '') - { + if ($request_array['email'] == '') { $user->email = null; - } - else - { + } else { $user->email = $request->input('email'); } - if (!checkArray('mobile', $request_array)) - { + if (!checkArray('mobile', $request_array)) { $user->mobile = null; - } - else - { + } else { $user->mobile = $request->input('mobile'); } - if (!checkArray('code', $request_array)) - { + if (!checkArray('code', $request_array)) { $user->country_code = 0; - } - else - { + } else { $user->country_code = $request->input('code'); } - if (checkArray('username', $request_array)) - { + if (checkArray('username', $request_array)) { $user->user_name = checkArray('username', $request_array); - } - else - { + } else { $user->user_name = $request->input('email'); } - $user->role = 'user'; - $code = str_random(60); + $user->role = 'user'; + $code = str_random(60); $user->remember_token = $code; $user->save(); - $message12 = ''; - $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); - $sms = Plugin::select('status')->where('name', '=', 'SMS')->first(); + $message12 = ''; + $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); + $sms = Plugin::select('status')->where('name', '=', 'SMS')->first(); // Event for login \Event::fire(new \App\Events\LoginEvent($request)); - if ($request->input('email') !== '') - { - $var = $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $request->input('email')], $message = ['subject' => null, 'scenario' => 'registration'], $template_variables = ['user' => $name, 'email_address' => $request->input('email'), 'password_reset_link' => url('account/activate/' . $code)]); + if ($request->input('email') !== '') { + $var = $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $request->input('email')], $message = ['subject' => null, 'scenario' => 'registration'], $template_variables = ['user' => $name, 'email_address' => $request->input('email'), 'password_reset_link' => url('account/activate/'.$code)]); } - if ($settings->status == 1 || $settings->status == '1') - { - if (count($sms) > 0) - { - if ($sms->status == 1 || $sms->status == '1') - { + if ($settings->status == 1 || $settings->status == '1') { + if (count($sms) > 0) { + if ($sms->status == 1 || $sms->status == '1') { $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail_and_moble'); - } - else - { + } else { $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail_sms_plugin_inactive_or_not_setup'); } - } - else - { - if ($request->input('email') !== '') - { + } else { + if ($request->input('email') !== '') { $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail'); - } - else - { + } else { $message12 = Lang::get('lang.account-created-contact-admin-as-we-were-not-able-to-send-opt'); } } - } - else - { + } else { $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail'); } - if ($api == true) - { + if ($api == true) { return ['message' => $message12, 'user' => $user->toArray()]; } + return redirect('home')->with('success', $message12); - } - catch (\Exception $e) - { - if ($api == true) - { - throw new \Exception($e->getMessage()); + } catch (\Exception $e) { + if ($api == true) { + throw new \Exception($e->getMessage()); } + return redirect()->back()->with('fails', $e->getMessage()); } } @@ -274,17 +230,14 @@ class AuthController extends Controller public function accountActivate($token) { $user = User::where('remember_token', '=', $token)->first(); - if ($user) - { - $user->active = 1; + if ($user) { + $user->active = 1; $user->remember_token = null; $user->save(); $this->openTicketAfterVerification($user->id); return redirect('/auth/login')->with('status', 'Acount activated. Login to start'); - } - else - { + } else { return redirect('/auth/login')->with('fails', 'Invalid Token'); } } @@ -300,15 +253,12 @@ class AuthController extends Controller public function getMail($token, User $user) { $user = $user->where('remember_token', $token)->where('active', 0)->first(); - if ($user) - { + if ($user) { $user->active = 1; $user->save(); return redirect('auth/login'); - } - else - { + } else { return redirect('auth/login'); } } @@ -321,26 +271,17 @@ class AuthController extends Controller public function getLogin() { $directory = base_path(); - if (file_exists($directory . DIRECTORY_SEPARATOR . '.env')) - { - if (Auth::user()) - { - if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent') - { + if (file_exists($directory.DIRECTORY_SEPARATOR.'.env')) { + if (Auth::user()) { + if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent') { return \Redirect::route('dashboard'); - } - elseif (Auth::user()->role == 'user') - { + } elseif (Auth::user()->role == 'user') { return \Redirect::route('home'); } - } - else - { + } else { return view('auth.login'); } - } - else - { + } else { return Redirect::route('licence'); } } @@ -354,153 +295,119 @@ class AuthController extends Controller */ public function postLogin(LoginRequest $request) { - try - { + try { // dd($request->input()); \Event::fire('auth.login.event', []); //added 5/5/2016 // Set login attempts and login time - $value = $_SERVER['REMOTE_ADDR']; + $value = $_SERVER['REMOTE_ADDR']; $usernameinput = $request->input('email'); - $password = $request->input('password'); - if ($request->input('referer')) - { + $password = $request->input('password'); + if ($request->input('referer')) { $referer = 'form'; - } - else - { + } else { $referer = '/'; } - $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name'; + $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name'; $result = $this->confirmIPAddress($value, $usernameinput); // If attempts > 3 and time < 30 minutes $security = Security::whereId('1')->first(); - if ($result == 1) - { + if ($result == 1) { return redirect()->back()->withErrors('email', 'Incorrect details')->with(['error' => $security->lockout_message, 'referer' => $referer]); } $check_active = User::where('email', '=', $request->input('email'))->orwhere('user_name', '=', $request->input('email'))->first(); - if (!$check_active) - { //check if user exists or not + if (!$check_active) { //check if user exists or not //if user deos not exist then return back with error that user is not registered return redirect()->back() ->withInput($request->only('email', 'remember')) ->withErrors([ - 'email' => $this->getFailedLoginMessage(), - 'password' => $this->getFailedLoginMessage(), + 'email' => $this->getFailedLoginMessage(), + 'password' => $this->getFailedLoginMessage(), ])->with(['error' => Lang::get('lang.not-registered'), - 'referer' => $referer,]); + 'referer' => $referer, ]); } //if user exists $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); - if ($settings->status == '1' || $settings->status == 1) - { // check for otp verification setting + if ($settings->status == '1' || $settings->status == 1) { // check for otp verification setting // setting is enabled $sms = Plugin::select('status')->where('name', '=', 'SMS')->first(); - if ($sms) - { //check sms plugin installed or not + if ($sms) { //check sms plugin installed or not // plugin is installed - if ($sms->status == 1 || $sms->status === '1') - { //check plugin is active or not + if ($sms->status == 1 || $sms->status === '1') { //check plugin is active or not // plugin is active - if (!$check_active->active) - { //check account is active or not + if (!$check_active->active) { //check account is active or not // account is not active show verify otp window - if ($check_active->mobile) - { //check user has mobile or not + if ($check_active->mobile) { //check user has mobile or not // user has mobile number return verify OTP screen return \Redirect::route('otp-verification') ->withInput($request->input()) ->with(['values' => $request->input(), - 'referer' => $referer, - 'name' => $check_active->first_name, - 'number' => $check_active->mobile, - 'code' => $check_active->country_code,]); - } - else - { + 'referer' => $referer, + 'name' => $check_active->first_name, + 'number' => $check_active->mobile, + 'code' => $check_active->country_code, ]); + } else { goto a; //attenmpt login (be careful while using goto statements) } - } - else - { + } else { goto a; //attenmpt login (be careful while using goto statements) } - } - else - { + } else { goto a; //attenmpt login (be careful while using goto statements) } - } - else - { + } else { goto a; //attenmpt login (be careful while using goto statements) } - } - else - { + } else { // setting is disabled - a: if (!$check_active->active) - { //check account is active or not + a: if (!$check_active->active) { //check account is active or not // if accoutn is not active return back with error message that account is inactive return redirect()->back() ->withInput($request->only('email', 'remember')) ->withErrors([ - 'email' => $this->getFailedLoginMessage(), - 'password' => $this->getFailedLoginMessage(), + 'email' => $this->getFailedLoginMessage(), + 'password' => $this->getFailedLoginMessage(), ])->with(['error' => Lang::get('lang.this_account_is_currently_inactive'), - 'referer' => $referer,]); - } - else - { + 'referer' => $referer, ]); + } else { // try login $loginAttempts = 1; // If session has login attempts, retrieve attempts counter and attempts time - if (\Session::has('loginAttempts')) - { - $loginAttempts = \Session::get('loginAttempts'); + if (\Session::has('loginAttempts')) { + $loginAttempts = \Session::get('loginAttempts'); $loginAttemptTime = \Session::get('loginAttemptTime'); $this->addLoginAttempt($value, $usernameinput); // $credentials = $request->only('email', 'password'); - $usernameinput = $request->input('email'); - $password = $request->input('password'); - $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name'; + $usernameinput = $request->input('email'); + $password = $request->input('password'); + $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name'; // If attempts > 3 and time < 10 minutes - if ($loginAttempts > $security->backlist_threshold && (time() - $loginAttemptTime <= ($security->lockout_period * 60))) - { + if ($loginAttempts > $security->backlist_threshold && (time() - $loginAttemptTime <= ($security->lockout_period * 60))) { return redirect()->back()->withErrors('email', 'incorrect email')->with('error', $security->lockout_message); } // If time > 10 minutes, reset attempts counter and time in session - if (time() - $loginAttemptTime > ($security->lockout_period * 60)) - { + if (time() - $loginAttemptTime > ($security->lockout_period * 60)) { \Session::put('loginAttempts', 1); \Session::put('loginAttemptTime', time()); } - } - else - { // If no login attempts stored, init login attempts and time + } else { // If no login attempts stored, init login attempts and time \Session::put('loginAttempts', $loginAttempts); \Session::put('loginAttemptTime', time()); $this->clearLoginAttempts($value, $usernameinput); } // If auth ok, redirect to restricted area \Session::put('loginAttempts', $loginAttempts + 1); - if (Auth::Attempt([$field => $usernameinput, 'password' => $password], $request->has('remember'))) - { - if (Auth::user()->role == 'user') - { - if ($request->input('referer')) - { + if (Auth::Attempt([$field => $usernameinput, 'password' => $password], $request->has('remember'))) { + if (Auth::user()->role == 'user') { + if ($request->input('referer')) { return \Redirect::route($request->input('referer')); } return \Redirect::route('/'); - } - else - { + } else { return redirect()->intended($this->redirectPath()); } } @@ -510,14 +417,12 @@ class AuthController extends Controller return redirect()->back() ->withInput($request->only('email', 'remember')) ->withErrors([ - 'email' => $this->getFailedLoginMessage(), - 'password' => $this->getFailedLoginMessage(), + 'email' => $this->getFailedLoginMessage(), + 'password' => $this->getFailedLoginMessage(), ])->with(['error' => Lang::get('lang.invalid'), - 'referer' => $referer,]); + 'referer' => $referer, ]); // Increment login attempts - } - catch (\Exception $e) - { + } catch (\Exception $e) { return redirect()->back()->with('fails', $e->getMessage()); } } @@ -531,26 +436,20 @@ class AuthController extends Controller */ public function addLoginAttempt($value, $field) { - $result = DB::table('login_attempts')->where('IP', '=', $value)->first(); - $data = $result; + $result = DB::table('login_attempts')->where('IP', '=', $value)->first(); + $data = $result; $security = Security::whereId('1')->first(); - $apt = $security->backlist_threshold; - if ($data) - { + $apt = $security->backlist_threshold; + if ($data) { $attempts = $data->Attempts + 1; - if ($attempts == $apt) - { + if ($attempts == $apt) { // $result = DB::select('UPDATE login_attempts SET Attempts='.$attempts.", LastLogin=NOW() WHERE IP = '$value' OR User = '$field'"); $result = DB::table('login_attempts')->where('IP', '=', $value)->orWhere('User', '=', $field)->update(['Attempts' => $attempts, 'LastLogin' => date('Y-m-d H:i:s')]); - } - else - { + } else { $result = DB::table('login_attempts')->where('IP', '=', $value)->orWhere('User', '=', $field)->update(['Attempts' => $attempts]); // $result = DB::select("UPDATE login_attempts SET Attempts=".$attempts." WHERE IP = '$value' OR User = '$field'"); } - } - else - { + } else { // $result = DB::select("INSERT INTO login_attempts (Attempts,User,IP,LastLogin) values (1,'$field','$value', NOW())"); $result = DB::table('login_attempts')->update(['Attempts' => 1, 'User' => $field, 'IP' => $value, 'LastLogin' => date('Y-m-d H:i:s')]); } @@ -579,26 +478,21 @@ class AuthController extends Controller */ public function confirmIPAddress($value, $field) { - $security = Security::whereId('1')->first(); - $time = $security->lockout_period; + $security = Security::whereId('1')->first(); + $time = $security->lockout_period; $max_attempts = $security->backlist_threshold; - $table = 'login_attempts'; - $result = DB::select('SELECT Attempts, (CASE when LastLogin is not NULL and DATE_ADD(LastLogin, INTERVAL ' . $time . ' MINUTE)>NOW() then 1 else 0 end) as Denied ' . - ' FROM ' . $table . " WHERE IP = '$value' OR User = '$field'"); - $data = $result; + $table = 'login_attempts'; + $result = DB::select('SELECT Attempts, (CASE when LastLogin is not NULL and DATE_ADD(LastLogin, INTERVAL '.$time.' MINUTE)>NOW() then 1 else 0 end) as Denied '. + ' FROM '.$table." WHERE IP = '$value' OR User = '$field'"); + $data = $result; //Verify that at least one login attempt is in database - if (!$data) - { + if (!$data) { return 0; } - if ($data[0]->Attempts >= $max_attempts) - { - if ($data[0]->Denied == 1) - { + if ($data[0]->Attempts >= $max_attempts) { + if ($data[0]->Denied == 1) { return 1; - } - else - { + } else { $this->clearLoginAttempts($value, $field); return 0; @@ -627,12 +521,9 @@ class AuthController extends Controller */ public function getVerifyOTP() { - if (\Session::has('values')) - { + if (\Session::has('values')) { return view('auth.otp-verify'); - } - else - { + } else { return redirect('auth/login'); } } @@ -646,35 +537,26 @@ class AuthController extends Controller */ public function verifyOTP(LoginRequest $request) { - $user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email')) + $user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email')) ->orWhere('user_name', '=', $request->input('email'))->first(); $otp_length = strlen($request->input('otp')); - if (!\Schema::hasTable('user_verification')) - { + if (!\Schema::hasTable('user_verification')) { $message = Lang::get('lang.opt-can-not-be-verified'); - } - else - { + } else { $otp = Otp::select('otp', 'updated_at')->where('user_id', '=', $user->id) ->first(); - if ($otp != null) - { - if (($otp_length == 6 && !preg_match('/[a-z]/i', $request->input('otp')))) - { - $otp2 = Hash::make($request->input('otp')); - $date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa'); - $date2 = date('Y-m-d h:i:sa'); - $time1 = new DateTime($date2); - $time2 = new DateTime($date1); + if ($otp != null) { + if (($otp_length == 6 && !preg_match('/[a-z]/i', $request->input('otp')))) { + $otp2 = Hash::make($request->input('otp')); + $date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa'); + $date2 = date('Y-m-d h:i:sa'); + $time1 = new DateTime($date2); + $time2 = new DateTime($date1); $interval = $time1->diff($time2); - if ($interval->i > 30 || $interval->h > 0) - { + if ($interval->i > 30 || $interval->h > 0) { $message = Lang::get('lang.otp-expired'); - } - else - { - if (Hash::check($request->input('otp'), $otp->otp)) - { + } else { + if (Hash::check($request->input('otp'), $otp->otp)) { Otp::where('user_id', '=', $user->id) ->update(['otp' => '']); User::where('id', '=', $user->id) @@ -682,20 +564,14 @@ class AuthController extends Controller $this->openTicketAfterVerification($user->id); return $this->postLogin($request); - } - else - { + } else { $message = Lang::get('lang.otp-not-matched'); } } - } - else - { + } else { $message = Lang::get('lang.otp-invalid'); } - } - else - { + } else { $message = Lang::get('lang.otp-not-matched'); } } @@ -703,30 +579,24 @@ class AuthController extends Controller return \Redirect::route('otp-verification') ->withInput($request->input()) ->with(['values' => $request->input(), - 'number' => $user->mobile, - 'name' => $user->user_name, - 'fails' => $message,]); + 'number' => $user->mobile, + 'name' => $user->user_name, + 'fails' => $message, ]); } public function resendOTP(OtpVerifyRequest $request) { - if (!\Schema::hasTable('user_verification') || !\Schema::hasTable('sms')) - { + if (!\Schema::hasTable('user_verification') || !\Schema::hasTable('sms')) { $message = Lang::get('lang.opt-can-not-be-verified'); return $message; - } - else - { + } else { $sms = DB::table('sms')->get(); - if (count($sms) > 0) - { + if (count($sms) > 0) { \Event::fire(new \App\Events\LoginEvent($request)); return 1; - } - else - { + } else { $message = Lang::get('lang.opt-can-not-be-verified'); return $message; @@ -751,10 +621,8 @@ class AuthController extends Controller ->get(); Tickets::where(['user_id' => $id, 'status' => 6]) ->update(['status' => 1]); - if ($ticket != null) - { - foreach ($ticket as $value) - { + if ($ticket != null) { + foreach ($ticket as $value) { $ticket_id = $value->id; Ticket_Thread::where('ticket_id', '=', $ticket_id) ->update(['updated_at' => date('Y-m-d H:i:s')]); @@ -765,7 +633,7 @@ class AuthController extends Controller public function changeRedirect() { $provider = \Session::get('provider'); - $url = \Session::get($provider . 'redirect'); + $url = \Session::get($provider.'redirect'); \Config::set("services.$provider.redirect", $url); } @@ -773,8 +641,7 @@ class AuthController extends Controller { $url = url($redirect); \Session::set('provider', $provider); - \Session::set($provider . 'redirect', $url); + \Session::set($provider.'redirect', $url); $this->changeRedirect(); } - } diff --git a/app/Http/Controllers/Auth/PasswordController.php b/app/Http/Controllers/Auth/PasswordController.php index 978a41401..52e8dfe9d 100644 --- a/app/Http/Controllers/Auth/PasswordController.php +++ b/app/Http/Controllers/Auth/PasswordController.php @@ -57,12 +57,12 @@ class PasswordController extends Controller $user = User::where('email', '=', $request->only('email'))->orWhere('mobile', '=', $request->only('email'))->first(); if (isset($user)) { $user1 = $user->email; - //gen new code and pass - $code = str_random(60); + //gen new code and pass + $code = str_random(60); $password_reset_table = \DB::table('password_resets')->where('email', '=', $user->email)->first(); if (isset($password_reset_table)) { $password_reset_table = \DB::table('password_resets')->where('email', '=', $user->email)->update(['token' => $code, 'created_at' => $date]); - // $password_reset_table->token = $code; + // $password_reset_table->token = $code; // $password_reset_table->update(['token' => $code]); } else { $create_password_reset = \DB::table('password_resets')->insert(['email' => $user->email, 'token' => $code, 'created_at' => $date]); @@ -107,7 +107,7 @@ class PasswordController extends Controller $this->getResetValidationCustomAttributes() ); $credentials = $this->getResetCredentials($request); - // dd($credentials); + // dd($credentials); $email = $credentials['email']; $password = $credentials['password']; $token = $credentials['token']; diff --git a/app/Http/Controllers/Client/helpdesk/ClientTicketController.php b/app/Http/Controllers/Client/helpdesk/ClientTicketController.php index 05a262173..d39ee57e9 100644 --- a/app/Http/Controllers/Client/helpdesk/ClientTicketController.php +++ b/app/Http/Controllers/Client/helpdesk/ClientTicketController.php @@ -32,7 +32,7 @@ class ClientTicketController extends Controller $this->TicketWorkflowController = $TicketWorkflowController; // $this->middleware('auth'); // $this->middleware('role.user'); - $this->middleware('board'); + $this->middleware('board'); } /** diff --git a/app/Http/Controllers/Client/helpdesk/GuestController.php b/app/Http/Controllers/Client/helpdesk/GuestController.php index ae50f1c92..cdd03f0e6 100644 --- a/app/Http/Controllers/Client/helpdesk/GuestController.php +++ b/app/Http/Controllers/Client/helpdesk/GuestController.php @@ -98,13 +98,13 @@ class GuestController extends Controller if (Input::file('profile_pic')) { // fetching picture name $name = Input::file('profile_pic')->getClientOriginalName(); - // fetching upload destination path + // fetching upload destination path $destinationPath = 'uploads/profilepic'; - // adding a random value to profile picture filename + // adding a random value to profile picture filename $fileName = rand(0000, 9999).'.'.str_replace(' ', '_', $name); - // moving the picture to a destination folder + // moving the picture to a destination folder Input::file('profile_pic')->move($destinationPath, $fileName); - // saving filename to database + // saving filename to database $user->profile_pic = $fileName; } if ($request->get('mobile')) { @@ -237,6 +237,7 @@ class GuestController extends Controller //echo $user->password; if (Hash::check($request->input('old_password'), $user->getAuthPassword())) { $user->password = Hash::make($request->input('new_password')); + try { $user->save(); diff --git a/app/Http/Controllers/Client/helpdesk/UnAuthController.php b/app/Http/Controllers/Client/helpdesk/UnAuthController.php index 9af08b639..c41538b62 100644 --- a/app/Http/Controllers/Client/helpdesk/UnAuthController.php +++ b/app/Http/Controllers/Client/helpdesk/UnAuthController.php @@ -94,6 +94,7 @@ class UnAuthController extends Controller $ticket_token->token = $hashed_token; $ticket_token->save(); } + try { $this->PhpMailController->sendmail( $from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $username, 'email' => $user_details->email], $message = ['subject' => 'Ticket link Request ['.$ticket_number.']', 'scenario' => 'check-ticket'], $template_variables = ['user' => $username, 'ticket_link_with_number' => url('show-ticket/'.$ticket->id.'/'.$token)] @@ -270,6 +271,7 @@ class UnAuthController extends Controller } else { $from_email = $sending_emails->id; } + try { $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $tickets->dept_id), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => $ticket_subject.'[#'.$ticket_number.']', 'scenario' => 'close-ticket'], $template_variables = ['ticket_number' => $ticket_number]); } catch (\Exception $e) { @@ -347,11 +349,11 @@ class UnAuthController extends Controller } // Follow up tickets - public function followup() - { - $followup = Followup::whereId('1')->first(); - $condition = $followup->condition; - // dd($condition); + public function followup() + { + $followup = Followup::whereId('1')->first(); + $condition = $followup->condition; + // dd($condition); switch ($condition) { case 'everyMinute': @@ -383,34 +385,34 @@ class UnAuthController extends Controller break; } - if ($followup->status = 1) { - $tickets = Tickets::where('id', '>=', 1)->where('status', '!=', 5)->get(); - // dd( $tickets); - // $tickets=Tickets::where('id', '>=', 1)->where('status', '!=', 5)->pluck('id'); - // dd( $tickets); - // $id=1; - foreach ($tickets as $ticket) { + if ($followup->status = 1) { + $tickets = Tickets::where('id', '>=', 1)->where('status', '!=', 5)->get(); + // dd( $tickets); + // $tickets=Tickets::where('id', '>=', 1)->where('status', '!=', 5)->pluck('id'); + // dd( $tickets); // $id=1; - // $id++; - // $ticket=Tickets::where('status', '!=', 5)->get(); + foreach ($tickets as $ticket) { + // $id=1; + // $id++; + // $ticket=Tickets::where('status', '!=', 5)->get(); - // dd($ticket); - // if($ticket != null){ + // dd($ticket); + // if($ticket != null){ // dd('here'); - $ck = date('Y-m-d H:i:s', strtotime($ticket->updated_at.$followup_set)); - // dd($ck); - $current_time = date('Y-m-d H:i:s'); - if ($current_time > $ck) { - $ticket->follow_up = 1; - $ticket->save(); - // Tickets::where('id', '=',$id) + $ck = date('Y-m-d H:i:s', strtotime($ticket->updated_at.$followup_set)); + // dd($ck); + $current_time = date('Y-m-d H:i:s'); + if ($current_time > $ck) { + $ticket->follow_up = 1; + $ticket->save(); + // Tickets::where('id', '=',$id) // ->update(['follow_up' => 1]); // } - } - // if($id=2) + } + // if($id=2) // {dd($ticket);} + } } - } - } + } } diff --git a/app/Http/Controllers/Common/ApiSettings.php b/app/Http/Controllers/Common/ApiSettings.php index ddc844401..2276963b7 100644 --- a/app/Http/Controllers/Common/ApiSettings.php +++ b/app/Http/Controllers/Common/ApiSettings.php @@ -51,6 +51,7 @@ class ApiSettings extends Controller $this->validate($request, [ 'ticket_detail' => 'url', ]); + try { // dd($request->input()); DB::table('settings_system') @@ -91,6 +92,7 @@ class ApiSettings extends Controller $this->postHook($data); } catch (Exception $ex) { dd($ex); + throw new Exception($ex->getMessage()); } } @@ -106,6 +108,7 @@ class ApiSettings extends Controller } } catch (Exception $ex) { dd($ex); + throw new Exception($ex->getMessage()); } } diff --git a/app/Http/Controllers/Common/PhpMailController.php b/app/Http/Controllers/Common/PhpMailController.php index 3432c50f5..b90c22138 100644 --- a/app/Http/Controllers/Common/PhpMailController.php +++ b/app/Http/Controllers/Common/PhpMailController.php @@ -234,15 +234,15 @@ class PhpMailController extends Controller if ($cc != null) { foreach ($cc as $collaborator) { //mail to collaborators - $collab_user_id = $collaborator->user_id; + $collab_user_id = $collaborator->user_id; $user_id_collab = User::where('id', '=', $collab_user_id)->first(); $collab_email = $user_id_collab->email; $m->cc($collab_email); } } - // $mail->addBCC($bc); - $size = count($attach); + // $mail->addBCC($bc); + $size = count($attach); if ($size > 0) { for ($i = 0; $i < $size; $i++) { if (is_array($attach) && array_key_exists($i, $attach)) { diff --git a/app/Http/Controllers/Common/SettingsController.php b/app/Http/Controllers/Common/SettingsController.php index f71ebe2a8..4771d2e39 100644 --- a/app/Http/Controllers/Common/SettingsController.php +++ b/app/Http/Controllers/Common/SettingsController.php @@ -120,6 +120,7 @@ class SettingsController extends Controller $widget = $widgets->where('id', '=', $id)->first(); $widget->title = $request->title; $widget->value = $request->content; + try { $widget->save(); @@ -198,6 +199,7 @@ class SettingsController extends Controller $widget = $widgets->where('id', '=', $id)->first(); $widget->title = $request->title; $widget->value = $request->content; + try { $widget->save(); @@ -234,6 +236,7 @@ class SettingsController extends Controller $data->name = $request->input('name'); $data->email = $request->input('email'); $data->password = Crypt::encrypt($request->input('password')); + try { $data->save(); @@ -257,6 +260,7 @@ class SettingsController extends Controller $pass = $request->input('password'); $password = Crypt::encrypt($pass); $settings->password = $password; + try { $settings->save(); } catch (Exception $e) { @@ -270,6 +274,7 @@ class SettingsController extends Controller $settings->logo = $fileName; $settings->save(); } + try { $settings->fill($request->except('logo', 'password'))->save(); @@ -364,6 +369,7 @@ class SettingsController extends Controller public function PostPlugins(Request $request) { $this->validate($request, ['plugin' => 'required|mimes:application/zip,zip,Zip']); + try { if (!extension_loaded('zip')) { throw new Exception('Please enable zip extension in your php'); diff --git a/app/Http/Controllers/Installer/helpdesk/InstallController.php b/app/Http/Controllers/Installer/helpdesk/InstallController.php index b77173fbf..c1fe9ed05 100644 --- a/app/Http/Controllers/Installer/helpdesk/InstallController.php +++ b/app/Http/Controllers/Installer/helpdesk/InstallController.php @@ -364,7 +364,7 @@ class InstallController extends Controller $datacontent = File::get($install); $datacontent = str_replace('%0%', $value, $datacontent); File::put($install, $datacontent); -// setting email settings in route + // setting email settings in route $smtpfilepath = "\App\Http\Controllers\Common\SettingsController::smtp()"; $link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; @@ -375,6 +375,7 @@ class InstallController extends Controller $datacontent2 = str_replace('http://localhost', $link, $datacontent2); File::put($app_url, $datacontent2); $language = Cache::get('language'); + try { Cache::flush(); diff --git a/app/Http/Controllers/Job/MailController.php b/app/Http/Controllers/Job/MailController.php index 0801c26ac..bab160754 100644 --- a/app/Http/Controllers/Job/MailController.php +++ b/app/Http/Controllers/Job/MailController.php @@ -43,6 +43,7 @@ class MailController extends Controller public function getServiceForm($short_name) { $form = ''; + try { switch ($short_name) { case 'smtp': diff --git a/app/Http/Middleware/CheckUpdate.php b/app/Http/Middleware/CheckUpdate.php index a37e617e0..59fdfc97f 100644 --- a/app/Http/Middleware/CheckUpdate.php +++ b/app/Http/Middleware/CheckUpdate.php @@ -49,8 +49,8 @@ class CheckUpdate $notify = new BarNotification(); if (!\Schema::hasTable('bar_notifications')) { $url = url('database-upgrade'); - //$string = "Your Database is outdated please upgrade Now !"; - echo view('themes.default1.update.database', compact('url')); + //$string = "Your Database is outdated please upgrade Now !"; + echo view('themes.default1.update.database', compact('url')); exit; } $not = $notify->get(); diff --git a/app/Http/Requests/helpdesk/TicketRequest.php b/app/Http/Requests/helpdesk/TicketRequest.php index 3dd05d61e..de5d0e79c 100644 --- a/app/Http/Requests/helpdesk/TicketRequest.php +++ b/app/Http/Requests/helpdesk/TicketRequest.php @@ -29,6 +29,7 @@ class TicketRequest extends Request public function rules() { $error = ''; + try { $size = $this->size(); if ($size > 800 || $size == 0) { diff --git a/app/Http/routes.php b/app/Http/routes.php index 304be246f..880581963 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -28,7 +28,7 @@ Route::group(['middleware' => ['web']], function () { | Here is defining entire routes for the Admin Panel | */ - Route::get('password/email/{one?}/{two?}/{three?}/{four?}/{five?}', ['as' => 'password.email', 'uses' => 'Auth\PasswordController@getEmail']); + Route::get('password/email/{one?}/{two?}/{three?}/{four?}/{five?}', ['as' => 'password.email', 'uses' => 'Auth\PasswordController@getEmail']); Breadcrumbs::register('password.email', function ($breadcrumbs) { $breadcrumbs->parent('/'); $breadcrumbs->push('Login', url('auth/login')); @@ -36,15 +36,15 @@ Route::group(['middleware' => ['web']], function () { }); // register page - Route::get('auth/register/{one?}/{two?}/{three?}/{four?}/{five?}', ['as' => 'auth.register', 'uses' => 'Auth\AuthController@getRegister']); + Route::get('auth/register/{one?}/{two?}/{three?}/{four?}/{five?}', ['as' => 'auth.register', 'uses' => 'Auth\AuthController@getRegister']); Breadcrumbs::register('auth.register', function ($breadcrumbs) { $breadcrumbs->parent('/'); $breadcrumbs->push('Login', url('auth/login')); $breadcrumbs->push('Create Account', url('auth/register')); }); - // Auth login - Route::get('auth/login/{one?}/{two?}/{three?}/{four?}/{five?}', ['as' => 'auth.login', 'uses' => 'Auth\AuthController@getLogin']); + // Auth login + Route::get('auth/login/{one?}/{two?}/{three?}/{four?}/{five?}', ['as' => 'auth.login', 'uses' => 'Auth\AuthController@getLogin']); Breadcrumbs::register('auth.login', function ($breadcrumbs) { $breadcrumbs->parent('/'); $breadcrumbs->push('Create Account', url('auth/register')); @@ -83,10 +83,10 @@ Route::group(['middleware' => ['web']], function () { Route::resource('teams', 'Admin\helpdesk\TeamController'); // in teams module, for CRUD Route::get('/teams/show/{id}', ['as' => 'teams.show', 'uses' => 'Admin\helpdesk\TeamController@show']); /* Get Team View */ - Breadcrumbs::register('teams.show', function ($breadcrumbs) { - $breadcrumbs->parent('teams.index'); - $breadcrumbs->push(Lang::get('lang.show'), url('teams/{teams}/show')); - }); + Breadcrumbs::register('teams.show', function ($breadcrumbs) { + $breadcrumbs->parent('teams.index'); + $breadcrumbs->push(Lang::get('lang.show'), url('teams/{teams}/show')); + }); Route::get('getshow/{id}', ['as' => 'teams.getshow.list', 'uses' => 'Admin\helpdesk\TeamController@getshow']); Route::resource('agents', 'Admin\helpdesk\AgentController'); // in agents module, for CRUD @@ -428,7 +428,7 @@ Route::group(['middleware' => ['web']], function () { // route to get the data on change Route::post('help-topic-report/{date1}/{date2}/{id}', ['as' => 'report.helptopic', 'uses' => 'Agent\helpdesk\ReportController@chartdataHelptopic']); /* To show dashboard pages */ Route::post('help-topic-pdf', ['as' => 'help.topic.pdf', 'uses' => 'Agent\helpdesk\ReportController@helptopicPdf']); - // Route to get details of agents + // Route to get details of agents Route::post('get-agents', ['as' => 'get-agents', 'uses' => 'Agent\helpdesk\UserController@getAgentDetails']); /* @@ -446,12 +446,12 @@ Route::group(['middleware' => ['web']], function () { Route::get('get-tag', ['as'=>'tag.get', 'uses'=>'Agent\helpdesk\Filter\TagController@getTag']); }); - /* - * Followup tickets - */ - Route::get('/ticket/followup', ['as' => 'followup.ticket', 'uses' => 'Agent\helpdesk\TicketController@followupTicketList']); // Get Closed Ticket / + /* + * Followup tickets + */ + Route::get('/ticket/followup', ['as' => 'followup.ticket', 'uses' => 'Agent\helpdesk\TicketController@followupTicketList']); // Get Closed Ticket / - Route::get('/ticket/get-followup', ['as' => 'get.followup.ticket', 'uses' => 'Agent\helpdesk\TicketController@getFollowup']); // Get tickets in datatable / + Route::get('/ticket/get-followup', ['as' => 'get.followup.ticket', 'uses' => 'Agent\helpdesk\TicketController@getFollowup']); // Get tickets in datatable / Route::get('/ticket/close/get-approval/{id}', ['as' => 'get.close.approval.ticket', 'uses' => 'Agent\helpdesk\TicketController@getCloseapproval']); // Get tickets in datatable / /* |------------------------------------------------------------------ @@ -494,11 +494,11 @@ Route::group(['middleware' => ['web']], function () { Route::get('check_ticket/{id}', ['as' => 'check_ticket', 'uses' => 'Client\helpdesk\GuestController@get_ticket_email']); //detail ticket information -// show ticket via have a ticket + // show ticket via have a ticket Route::get('show-ticket/{id}/{code}', ['as' => 'show.ticket', 'uses' => 'Client\helpdesk\UnAuthController@showTicketCode']); //detail ticket information //testing ckeditor -//=================================================================================== + //=================================================================================== Route::group(['middleware' => 'role.user', 'middleware' => 'auth'], function () { Route::get('client-profile', ['as' => 'client.profile', 'uses' => 'Client\helpdesk\GuestController@getProfile']); /* User profile get */ @@ -511,7 +511,7 @@ Route::group(['middleware' => ['web']], function () { Route::post('verify-client-number2', ['as' => 'post-client-verify-number', 'uses' => 'Client\helpdesk\GuestController@verifyOTP']); }); -//==================================================================================== + //==================================================================================== Route::get('checkticket', 'Client\helpdesk\ClientTicketController@getCheckTicket'); /* Check your Ticket */ Route::get('myticket', ['as' => 'ticket', 'uses' => 'Client\helpdesk\GuestController@getMyticket']); /* Get my tickets */ Route::get('myticket/{id}', ['as' => 'ticket', 'uses' => 'Client\helpdesk\GuestController@thread']); /* Get my tickets */ @@ -705,7 +705,7 @@ Route::group(['middleware' => ['web']], function () { * @author Vijay Sebastian * @name Faveo */ - Route::group(['prefix' => 'api/v1'], function () { + Route::group(['prefix' => 'api/v1'], function () { Route::post('authenticate', 'Api\v1\TokenAuthController@authenticate'); Route::get('authenticate/user', 'Api\v1\TokenAuthController@getAuthenticatedUser'); Route::get('/database-config', ['as' => 'database-config', 'uses' => 'Api\v1\InstallerApiController@config_database']); @@ -816,8 +816,8 @@ Route::group(['middleware' => ['web']], function () { Route::post('ticket/priority/edit1', ['as' => 'priority.edit1', 'uses' => 'Admin\helpdesk\PriorityController@priorityEdit1']); Route::get('ticket/priority/{ticket_priority}/edit', ['as' => 'priority.edit', 'uses' => 'Admin\helpdesk\PriorityController@priorityEdit']); Route::get('ticket/priority/{ticket_priority}/destroy', ['as' => 'priority.destroy', 'uses' => 'Admin\helpdesk\PriorityController@destroy']); - // user---arindam - Route::post('rolechangeadmin/{id}', ['as' => 'user.post.rolechangeadmin', 'uses' =>'Agent\helpdesk\UserController@changeRoleAdmin']); + // user---arindam + Route::post('rolechangeadmin/{id}', ['as' => 'user.post.rolechangeadmin', 'uses' =>'Agent\helpdesk\UserController@changeRoleAdmin']); Route::post('rolechangeagent/{id}', ['as' => 'user.post.rolechangeagent', 'uses' =>'Agent\helpdesk\UserController@changeRoleAgent']); Route::post('rolechangeuser/{id}', ['as' => 'user.post.rolechangeuser', 'uses' =>'Agent\helpdesk\UserController@changeRoleUser']); Route::get('password', ['as' => 'user.changepassword', 'uses' =>'Agent\helpdesk\UserController@randomPassword']); @@ -825,15 +825,15 @@ Route::group(['middleware' => ['web']], function () { Route::post('delete/{id}', ['as' => 'user.post.delete', 'uses' =>'Agent\helpdesk\UserController@deleteAgent']); // deleted user list - Route::get('deleted/user', ['as' => 'user.deleted', 'uses' => 'Agent\helpdesk\UserController@deletedUser']); + Route::get('deleted/user', ['as' => 'user.deleted', 'uses' => 'Agent\helpdesk\UserController@deletedUser']); Route::post('restore/{id}', ['as' => 'user.restore', 'uses' => 'Agent\helpdesk\UserController@restoreUser']); - //due today ticket - Route::get('duetoday', ['as' => 'ticket.duetoday', 'uses' =>'Agent\helpdesk\TicketController@dueTodayTicketlist']); + //due today ticket + Route::get('duetoday', ['as' => 'ticket.duetoday', 'uses' =>'Agent\helpdesk\TicketController@dueTodayTicketlist']); - // Route::post('duetoday/list/ticket', ['as' => 'ticket.post.duetoday', 'uses' =>'Agent\helpdesk\TicketController@getDueToday']); - Route::get('duetoday/list/ticket', ['as' => 'ticket.post.duetoday', 'uses' =>'Agent\helpdesk\TicketController@getDueToday']); /* Get Open Ticket */ + // Route::post('duetoday/list/ticket', ['as' => 'ticket.post.duetoday', 'uses' =>'Agent\helpdesk\TicketController@getDueToday']); + Route::get('duetoday/list/ticket', ['as' => 'ticket.post.duetoday', 'uses' =>'Agent\helpdesk\TicketController@getDueToday']); /* Get Open Ticket */ // Breadcrumbs::register('open.ticket', function ($breadcrumbs) { // $breadcrumbs->parent('dashboard'); // $breadcrumbs->push(Lang::get('lang.tickets') . '  >  ' . Lang::get('lang.open'), route('open.ticket')); diff --git a/app/Model/helpdesk/Notification/Notification.php b/app/Model/helpdesk/Notification/Notification.php index 0dd581268..3345ef092 100644 --- a/app/Model/helpdesk/Notification/Notification.php +++ b/app/Model/helpdesk/Notification/Notification.php @@ -59,7 +59,7 @@ class Notification extends BaseModel public function delete() { $this->deleteUserNotification(); - // $this->dummyDelete(); + // $this->dummyDelete(); parent::delete(); } } diff --git a/config/app.php b/config/app.php index 73e432c26..6c74a4407 100644 --- a/config/app.php +++ b/config/app.php @@ -187,8 +187,6 @@ return [ App\FaveoLog\LaravelLogViewerServiceProvider::class, App\FaveoStorage\StorageServiceProvider::class, Yajra\Datatables\DatatablesServiceProvider::class, - - ], /* diff --git a/database/migrations/2016_04_18_115852_create_workflow_name_table.php b/database/migrations/2016_04_18_115852_create_workflow_name_table.php index 06db5cd4a..8b8db67cf 100644 --- a/database/migrations/2016_04_18_115852_create_workflow_name_table.php +++ b/database/migrations/2016_04_18_115852_create_workflow_name_table.php @@ -23,13 +23,13 @@ class CreateWorkflowNameTable extends Migration }); } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('workflow_name'); - } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('workflow_name'); + } } diff --git a/database/migrations/2016_04_18_115900_create_workflow_rule_table.php b/database/migrations/2016_04_18_115900_create_workflow_rule_table.php index 008d897bd..61c21b7e0 100644 --- a/database/migrations/2016_04_18_115900_create_workflow_rule_table.php +++ b/database/migrations/2016_04_18_115900_create_workflow_rule_table.php @@ -27,16 +27,16 @@ class CreateWorkflowRuleTable extends Migration }); } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('workflow_rules', function (Blueprint $table) { - $table->dropForeign('workflow_rules_1'); - }); - Schema::drop('workflow_rules'); - } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('workflow_rules', function (Blueprint $table) { + $table->dropForeign('workflow_rules_1'); + }); + Schema::drop('workflow_rules'); + } } diff --git a/database/migrations/2016_04_18_115908_create_workflow_action_table.php b/database/migrations/2016_04_18_115908_create_workflow_action_table.php index 24b8471aa..5fc03fb97 100644 --- a/database/migrations/2016_04_18_115908_create_workflow_action_table.php +++ b/database/migrations/2016_04_18_115908_create_workflow_action_table.php @@ -24,16 +24,16 @@ class CreateWorkflowActionTable extends Migration }); } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('workflow_action'); - Schema::table('workflow_action', function (Blueprint $table) { - $table->dropForeign('workflow_action_idfk_1'); - }); - } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('workflow_action'); + Schema::table('workflow_action', function (Blueprint $table) { + $table->dropForeign('workflow_action_idfk_1'); + }); + } } diff --git a/database/migrations/2016_05_10_102604_create_bar_notifications_table.php b/database/migrations/2016_05_10_102604_create_bar_notifications_table.php index c11bffd1a..7885818ee 100644 --- a/database/migrations/2016_05_10_102604_create_bar_notifications_table.php +++ b/database/migrations/2016_05_10_102604_create_bar_notifications_table.php @@ -20,7 +20,7 @@ class CreateBarNotificationsTable extends Migration }); $version = \Config::get('app.version'); $date = date('Y-m-d H:i:s'); - //\DB::table('bar_notifications')->insert(['key'=>'new-install','value'=>"Congrates ! You have installed $version",'created_at'=>$date]); + //\DB::table('bar_notifications')->insert(['key'=>'new-install','value'=>"Congrates ! You have installed $version",'created_at'=>$date]); } /** diff --git a/public/ckeditor/samples/old/assets/posteddata.php b/public/ckeditor/samples/old/assets/posteddata.php index 2baa84ed6..70b4952f2 100644 --- a/public/ckeditor/samples/old/assets/posteddata.php +++ b/public/ckeditor/samples/old/assets/posteddata.php @@ -41,7 +41,6 @@ if (!empty($_POST)) {