From 88f3df2180e6b7b828cf36a630956fd14f375688 Mon Sep 17 00:00:00 2001 From: Manish Verma Date: Tue, 13 Dec 2016 13:14:54 +0000 Subject: [PATCH] Apply fixes from StyleCI --- app/Console/Commands/CloseWork.php | 15 +- app/Console/Commands/SendReport.php | 24 +- app/Console/Commands/TicketFetch.php | 22 +- app/Console/Kernel.php | 51 +- app/Events/FaveoAfterReply.php | 2 +- app/Exceptions/Handler.php | 26 +- app/FaveoLog/LaravelLogViewer.php | 107 ++- .../LaravelLogViewerServiceProvider.php | 27 +- .../controllers/LogViewerController.php | 16 +- app/FaveoLog/lang/en/lang.php | 2 +- app/FaveoLog/routes.php | 3 +- .../Controllers/SettingsController.php | 59 +- .../Controllers/StorageController.php | 127 ++- app/FaveoStorage/StorageServiceProvider.php | 17 +- app/FaveoStorage/breadcrumbs.php | 6 +- ...16_11_30_122809_alter_attachment_table.php | 2 +- app/FaveoStorage/lang/en/lang.php | 25 +- app/FaveoStorage/routes.php | 14 +- app/Helper/Finder.php | 243 ++--- app/Http/Controllers/Admin/MailFetch.php | 9 +- .../Admin/helpdesk/AgentController.php | 12 +- .../Admin/helpdesk/DepartmentController.php | 52 +- .../Admin/helpdesk/EmailsController.php | 146 +-- .../Admin/helpdesk/FormController.php | 353 +++---- .../Admin/helpdesk/HelptopicController.php | 5 +- .../Admin/helpdesk/LanguageController.php | 13 +- .../Admin/helpdesk/PriorityController.php | 109 +-- .../Admin/helpdesk/SettingsController.php | 266 +++--- .../SocialMedia/SocialMediaController.php | 47 +- .../Admin/helpdesk/TeamController.php | 88 +- .../Admin/helpdesk/TemplateController.php | 86 +- .../Admin/helpdesk/UrlSettingController.php | 84 +- .../helpdesk/Filter/FilterController.php | 247 ++--- .../Controllers/Agent/helpdesk/ImapMail.php | 15 +- .../Agent/helpdesk/MailController.php | 116 ++- .../Agent/helpdesk/NotificationController.php | 74 +- .../Agent/helpdesk/OrganizationController.php | 24 +- .../Agent/helpdesk/ReportController.php | 74 +- .../Agent/helpdesk/TicketController.php | 872 ++++++++++-------- .../helpdesk/TicketWorkflowController.php | 7 +- .../Agent/helpdesk/UserController.php | 468 +++++----- .../Agent/kb/ArticleController.php | 2 +- .../Agent/kb/CategoryController.php | 9 +- .../Agent/kb/SettingsController.php | 8 +- app/Http/Controllers/Api/v1/ApiController.php | 284 +++--- .../Api/v1/InstallerApiController.php | 2 +- .../Api/v1/TokenAuthController.php | 2 +- app/Http/Controllers/Auth/AuthController.php | 244 ++--- .../Controllers/Auth/PasswordController.php | 75 +- .../Client/helpdesk/FormController.php | 124 +-- .../Client/helpdesk/GuestController.php | 153 +-- .../Client/helpdesk/UnAuthController.php | 83 +- .../Controllers/Client/kb/UserController.php | 100 +- .../Controllers/Common/ExcelController.php | 16 +- .../Common/FileuploadController.php | 15 +- .../Common/NotificationController.php | 87 +- .../Controllers/Common/PhpMailController.php | 132 +-- .../Controllers/Common/SettingsController.php | 187 ++-- app/Http/Controllers/Common/Socialite.php | 8 +- .../Common/TemplateSetController.php | 2 +- app/Http/Controllers/HomeController.php | 2 +- app/Http/Controllers/Job/MailController.php | 78 +- app/Http/Controllers/Job/QueueController.php | 111 ++- .../Controllers/Update/UpgradeController.php | 125 +-- .../Controllers/Utility/LibraryController.php | 36 +- app/Http/Middleware/Authenticate.php | 1 + app/Http/Requests/helpdesk/AgentRequest.php | 18 +- .../helpdesk/ChangepasswordRequest.php | 2 +- app/Http/Requests/helpdesk/ClientRequest.php | 77 +- .../Requests/helpdesk/CreateTicketRequest.php | 38 +- .../Requests/helpdesk/Job/TaskRequest.php | 38 +- app/Http/Requests/helpdesk/LableUpdate.php | 7 +- .../Requests/helpdesk/Mail/MailRequest.php | 52 +- .../Requests/helpdesk/PriorityRequest.php | 18 +- app/Http/Requests/helpdesk/ProfileRequest.php | 2 +- .../Requests/helpdesk/Queue/QueueRequest.php | 13 +- .../Requests/helpdesk/RegisterRequest.php | 10 +- .../Requests/helpdesk/Sys_userRequest.php | 46 +- app/Http/Requests/helpdesk/Sys_userUpdate.php | 9 +- app/Http/Requests/helpdesk/TicketRequest.php | 35 +- app/Http/Requests/kb/CategoryRequest.php | 1 + app/Http/Requests/kb/PageRequest.php | 3 +- app/Http/ViewComposers/AgentLayout.php | 83 +- app/Http/ViewComposers/AuthUser.php | 27 +- app/Http/ViewComposers/UpdateNotification.php | 15 +- app/Http/breadcrumbs.php | 36 +- app/Http/helpers.php | 61 +- app/Http/routes.php | 367 ++++---- app/Jobs/SendEmail.php | 23 +- app/Model/MailJob/Condition.php | 34 +- app/Model/MailJob/FaveoMail.php | 9 +- app/Model/MailJob/FaveoQueue.php | 9 +- app/Model/MailJob/MailService.php | 4 +- app/Model/MailJob/QueueService.php | 66 +- .../helpdesk/Agent/Assign_team_agent.php | 2 +- .../helpdesk/Agent_panel/Organization.php | 23 +- app/Model/helpdesk/Agent_panel/User_org.php | 7 +- app/Model/helpdesk/Email/Emails.php | 58 +- app/Model/helpdesk/Filters/Filter.php | 48 +- app/Model/helpdesk/Filters/Label.php | 36 +- app/Model/helpdesk/Filters/Tag.php | 4 +- app/Model/helpdesk/Form/FieldValue.php | 23 +- app/Model/helpdesk/Form/Fields.php | 57 +- app/Model/helpdesk/Form/Forms.php | 55 +- app/Model/helpdesk/Manage/Help_topic.php | 6 +- .../helpdesk/Notification/Notification.php | 47 +- .../Notification/UserNotification.php | 18 +- .../helpdesk/Settings/CommonSettings.php | 35 +- app/Model/helpdesk/Settings/Followup.php | 2 +- app/Model/helpdesk/Settings/SocialMedia.php | 42 +- .../helpdesk/Ticket/Ticket_Form_Data.php | 24 +- app/Model/helpdesk/Ticket/Ticket_Priority.php | 4 +- app/Model/helpdesk/Ticket/Ticket_Thread.php | 76 +- .../helpdesk/Ticket/Ticket_ThreadOld.php | 72 +- .../helpdesk/Ticket/Ticket_attachments.php | 36 +- app/Model/helpdesk/Ticket/Ticket_source.php | 2 +- app/Model/helpdesk/Ticket/Tickets.php | 55 +- app/Model/helpdesk/Utility/Limit_Login.php | 4 +- app/Providers/AppServiceProvider.php | 12 +- app/Providers/ComposerServiceProvider.php | 2 +- app/User.php | 90 +- app/UserAdditionalInfo.php | 5 +- config/app.php | 115 ++- config/datatables.php | 26 +- config/debugbar.php | 54 +- config/excel.php | 234 ++--- config/lfm.php | 5 +- config/mail.php | 2 +- config/queue.php | 24 +- config/services.php | 45 +- .../2016_02_16_140450_create_users_table.php | 2 +- .../2016_06_28_141613_version1079table.php | 11 +- .../2016_07_02_051247_create_jobs_table.php | 2 +- ..._07_02_051439_create_failed_jobs_table.php | 2 +- ...07_19_071910_create_field_values_table.php | 2 +- ..._07_26_084458_create_faveo_mails_table.php | 2 +- ...07_26_090201_create_faveo_queues_table.php | 2 +- ...7_26_094753_create_mail_services_table.php | 18 +- ..._26_095020_create_queue_services_table.php | 24 +- ...6_07_29_113012_create_conditions_table.php | 2 +- ...08_08_095744_create_social_media_table.php | 2 +- ...410_create_user_additional_infos_table.php | 2 +- ...08_16_104539_alter_ticket_source_table.php | 30 +- ..._07_26_084458_create_faveo_mails_table.php | 2 +- ...07_26_090201_create_faveo_queues_table.php | 2 +- ...7_26_094753_create_mail_services_table.php | 18 +- ..._26_095020_create_queue_services_table.php | 20 +- ...6_07_29_113012_create_conditions_table.php | 2 +- ...08_08_095744_create_social_media_table.php | 2 +- ...410_create_user_additional_infos_table.php | 2 +- ...08_16_104539_alter_ticket_source_table.php | 26 +- ...08_16_104539_alter_ticket_source_table.php | 26 +- database/seeds/DatabaseSeeder.php | 16 +- .../samples/old/assets/posteddata.php | 9 +- resources/lang/de/lang.php | 6 +- resources/lang/en/lang.php | 56 +- resources/lang/fr/lang.php | 10 +- resources/lang/it/lang.php | 4 +- resources/lang/nl/lang.php | 4 +- resources/lang/pt/lang.php | 4 +- resources/lang/ru/lang.php | 4 +- 161 files changed, 4729 insertions(+), 3879 deletions(-) diff --git a/app/Console/Commands/CloseWork.php b/app/Console/Commands/CloseWork.php index 66af8bf7c..c3a0e7c5a 100644 --- a/app/Console/Commands/CloseWork.php +++ b/app/Console/Commands/CloseWork.php @@ -2,11 +2,11 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; use App\Http\Controllers\Client\helpdesk\UnAuthController; +use Illuminate\Console\Command; -class CloseWork extends Command { - +class CloseWork extends Command +{ /** * The name and signature of the console command. * @@ -26,7 +26,8 @@ class CloseWork extends Command { * * @return void */ - public function __construct() { + public function __construct() + { parent::__construct(); } @@ -35,15 +36,15 @@ class CloseWork extends Command { * * @return mixed */ - public function handle() { + public function handle() + { if (env('DB_INSTALL') == 1) { $PhpMailController = new \App\Http\Controllers\Common\PhpMailController(); $controller = new UnAuthController($PhpMailController); $controller->autoCloseTickets(); - loging('ticket-close-workflow', 'Close ticket workflow executed','info'); + loging('ticket-close-workflow', 'Close ticket workflow executed', 'info'); //\Log::info('Close ticket workflow executed'); $this->info('Close ticket workflow executed'); } } - } diff --git a/app/Console/Commands/SendReport.php b/app/Console/Commands/SendReport.php index fdaf343fb..ede097a70 100644 --- a/app/Console/Commands/SendReport.php +++ b/app/Console/Commands/SendReport.php @@ -2,13 +2,13 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; use App\Http\Controllers\Agent\helpdesk\NotificationController; use App\Http\Controllers\Common\PhpMailController; use Exception; +use Illuminate\Console\Command; -class SendReport extends Command { - +class SendReport extends Command +{ /** * The name and signature of the console command. * @@ -28,8 +28,8 @@ class SendReport extends Command { * * @return void */ - public function __construct() { - + public function __construct() + { parent::__construct(); } @@ -38,21 +38,22 @@ class SendReport extends Command { * * @return mixed */ - public function handle() { + public function handle() + { try { if (env('DB_INSTALL') == 1) { $mail = new PhpMailController(); $mail->setQueue(); $this_report = new NotificationController($mail); $report = $this_report->send_notification(); - + if ($report !== 0) { - loging('sending-mail-report', 'Report has send','info'); + loging('sending-mail-report', 'Report has send', 'info'); //\Log::info("Report has send"); - $this->info("Report has send"); + $this->info('Report has send'); } else { - loging('sending-mail-report', 'Nothing to send','info'); - $this->info("Nothing to send"); + loging('sending-mail-report', 'Nothing to send', 'info'); + $this->info('Nothing to send'); } } } catch (Exception $ex) { @@ -60,5 +61,4 @@ class SendReport extends Command { $this->error($ex->getMessage()); } } - } diff --git a/app/Console/Commands/TicketFetch.php b/app/Console/Commands/TicketFetch.php index c0e7788a6..a90f10129 100644 --- a/app/Console/Commands/TicketFetch.php +++ b/app/Console/Commands/TicketFetch.php @@ -2,13 +2,13 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; use App\Http\Controllers\Agent\helpdesk\MailController; -use Event; use App\Http\Controllers\Agent\helpdesk\TicketWorkflowController; +use Event; +use Illuminate\Console\Command; -class TicketFetch extends Command { - +class TicketFetch extends Command +{ /** * The name and signature of the console command. * @@ -28,7 +28,8 @@ class TicketFetch extends Command { * * @return void */ - public function __construct() { + public function __construct() + { parent::__construct(); } @@ -37,9 +38,9 @@ class TicketFetch extends Command { * * @return mixed */ - public function handle() { + public function handle() + { if (env('DB_INSTALL') == 1) { - $controller = $this->mailController(); $emails = new \App\Model\helpdesk\Email\Emails(); $settings_email = new \App\Model\helpdesk\Settings\Email(); @@ -47,19 +48,20 @@ class TicketFetch extends Command { $ticket = new \App\Model\helpdesk\Settings\Ticket(); $controller->readmails($emails, $settings_email, $system, $ticket); Event::fire('ticket.fetch', ['event' => '']); - loging('fetching-ticket', 'Ticket has read','info'); + loging('fetching-ticket', 'Ticket has read', 'info'); //\Log::info('Ticket has read'); $this->info('Ticket has read'); } } - public function mailController() { + public function mailController() + { $PhpMailController = new \App\Http\Controllers\Common\PhpMailController(); $NotificationController = new \App\Http\Controllers\Common\NotificationController(); $ticket = new \App\Http\Controllers\Agent\helpdesk\TicketController($PhpMailController, $NotificationController); $work = new TicketWorkflowController($ticket); $controller = new MailController($work); + return $controller; } - } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ab579e13d..72588767d 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,12 +2,12 @@ namespace App\Console; +use App\Model\MailJob\Condition; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; -use App\Model\MailJob\Condition; - -class Kernel extends ConsoleKernel { +class Kernel extends ConsoleKernel +{ /** * The Artisan commands provided by your application. * @@ -27,7 +27,8 @@ class Kernel extends ConsoleKernel { * * @return void */ - protected function schedule(Schedule $schedule) { + protected function schedule(Schedule $schedule) + { if (env('DB_INSTALL') == 1) { $queue = $this->getCurrentQueue(); $schedule->command('queue:listen '.$queue, ['--tries' => 1])->everyMinute(); @@ -37,75 +38,79 @@ class Kernel extends ConsoleKernel { } } - public function execute($schedule, $task) { + public function execute($schedule, $task) + { $condition = new Condition(); $command = $condition->getConditionValue($task); switch ($task) { - case "fetching": + case 'fetching': $this->getCondition($schedule->command('ticket:fetch'), $command); break; - case "notification": + case 'notification': $this->getCondition($schedule->command('report:send'), $command); break; - case "work": + case 'work': $this->getCondition($schedule->command('ticket:close'), $command); break; } } - public function getCondition($schedule, $command) { + public function getCondition($schedule, $command) + { $condition = $command['condition']; $at = $command['at']; switch ($condition) { - case "everyMinute": + case 'everyMinute': $schedule->everyMinute()->withoutOverlapping(); break; - case "everyFiveMinutes": + case 'everyFiveMinutes': $schedule->everyFiveMinutes()->withoutOverlapping(); break; - case "everyTenMinutes": + case 'everyTenMinutes': $schedule->everyTenMinutes()->withoutOverlapping(); break; - case "everyThirtyMinutes": + case 'everyThirtyMinutes': $schedule->everyThirtyMinutes()->withoutOverlapping(); break; - case "hourly": + case 'hourly': $schedule->hourly()->withoutOverlapping(); break; - case "daily": + case 'daily': $schedule->daily()->withoutOverlapping(); break; - case "dailyAt": + case 'dailyAt': $this->getConditionWithOption($schedule, $condition, $at); break; - case "weekly": + case 'weekly': $schedule->weekly()->withoutOverlapping(); break; - case "monthly": + case 'monthly': $schedule->monthly()->withoutOverlapping(); break; - case "yearly": + case 'yearly': $schedule->yearly()->withoutOverlapping(); break; } } - public function getConditionWithOption($schedule, $command, $at) { + public function getConditionWithOption($schedule, $command, $at) + { switch ($command) { - case "dailyAt": + case 'dailyAt': $schedule->dailyAt($at)->withoutOverlapping(); break; } } - public function getCurrentQueue() { + public function getCurrentQueue() + { $queue = 'database'; $services = new \App\Model\MailJob\QueueService(); $current = $services->where('status', 1)->first(); if ($current) { $queue = $current->short_name; } + return $queue; } - } diff --git a/app/Events/FaveoAfterReply.php b/app/Events/FaveoAfterReply.php index 3cd2e523b..6e4f7f708 100644 --- a/app/Events/FaveoAfterReply.php +++ b/app/Events/FaveoAfterReply.php @@ -19,7 +19,7 @@ class FaveoAfterReply extends Event * * @return void */ - public function __construct($para1 = '', $para2 = '', $para3 = '', $para4 = '', $para5 = '',$para6='') + public function __construct($para1 = '', $para2 = '', $para3 = '', $para4 = '', $para5 = '', $para6 = '') { $this->para1 = $para1; $this->para2 = $para2; diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7329c88fc..d5b0dc49c 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -1,5 +1,7 @@ common($request, $e); } } + /** * Function to render 500 error page. * @@ -83,12 +90,14 @@ class Handler extends ExceptionHandler { if (config('app.debug') == true) { return parent::render($request, $e); - }elseif($e instanceof ValidationException){ + } elseif ($e instanceof ValidationException) { return parent::render($request, $e); } + return response()->view('errors.500'); //return redirect()->route('error500', []); } + /** * Function to render 404 error page. * @@ -99,21 +108,23 @@ class Handler extends ExceptionHandler */ public function render404($request, $e) { - $seg = $request->segments(); if (in_array('api', $seg)) { return response()->json(['status' => '404']); } if (config('app.debug') == true) { - if($e->getStatusCode() == '404') { + if ($e->getStatusCode() == '404') { return redirect()->route('error404', []); } + return parent::render($request, $e); } + return redirect()->route('error404', []); } + /** - * Function to render database connection failed + * Function to render database connection failed. * * @param type $request * @param type $e @@ -129,8 +140,10 @@ class Handler extends ExceptionHandler if (config('app.debug') == true) { return parent::render($request, $e); } + return redirect()->route('error404', []); } + /** * Common finction to render both types of codes. * @@ -147,7 +160,7 @@ class Handler extends ExceptionHandler case $e instanceof NotFoundHttpException: return $this->render404($request, $e); case $e instanceof PDOException: - if(strpos('1045', $e->getMessage()) == true) { + if (strpos('1045', $e->getMessage()) == true) { return $this->renderDB($request, $e); } else { return $this->render500($request, $e); @@ -161,6 +174,7 @@ class Handler extends ExceptionHandler default: return $this->render500($request, $e); } + return parent::render($request, $e); } -} \ No newline at end of file +} diff --git a/app/FaveoLog/LaravelLogViewer.php b/app/FaveoLog/LaravelLogViewer.php index 9fc18111f..e635e4a15 100644 --- a/app/FaveoLog/LaravelLogViewer.php +++ b/app/FaveoLog/LaravelLogViewer.php @@ -8,33 +8,32 @@ use ReflectionClass; use UTC; /** - * Class LaravelLogViewer - * @package Rap2hpoutre\LaravelLogViewer + * Class LaravelLogViewer. */ -class LaravelLogViewer { - +class LaravelLogViewer +{ /** * @var string file */ private static $file; private static $levels_classes = [ - 'debug' => 'info', - 'info' => 'info', - 'notice' => 'info', - 'warning' => 'warning', - 'error' => 'danger', - 'critical' => 'danger', - 'alert' => 'danger', + 'debug' => 'info', + 'info' => 'info', + 'notice' => 'info', + 'warning' => 'warning', + 'error' => 'danger', + 'critical' => 'danger', + 'alert' => 'danger', 'emergency' => 'danger', ]; private static $levels_imgs = [ - 'debug' => 'info', - 'info' => 'info', - 'notice' => 'info', - 'warning' => 'warning', - 'error' => 'warning', - 'critical' => 'warning', - 'alert' => 'warning', + 'debug' => 'info', + 'info' => 'info', + 'notice' => 'info', + 'warning' => 'warning', + 'error' => 'warning', + 'critical' => 'warning', + 'alert' => 'warning', 'emergency' => 'warning', ]; @@ -43,7 +42,8 @@ class LaravelLogViewer { /** * @param string $file */ - public static function setFile($file) { + public static function setFile($file) + { $file = self::pathToLogFile($file); if (File::exists($file)) { @@ -51,14 +51,15 @@ class LaravelLogViewer { } } - public static function pathToLogFile($file) { + public static function pathToLogFile($file) + { $logsPath = storage_path('logs'); if (File::exists($file)) { // try the absolute path return $file; } - $file = $logsPath . '/' . $file; + $file = $logsPath.'/'.$file; // check if requested file is really in the logs directory if (dirname($file) !== $logsPath) { @@ -71,15 +72,17 @@ class LaravelLogViewer { /** * @return string */ - public static function getFileName() { + public static function getFileName() + { return basename(self::$file); } /** * @return array */ - public static function all() { - $log = array(); + public static function all() + { + $log = []; $log_levels = self::getLogLevels(); @@ -93,15 +96,17 @@ class LaravelLogViewer { self::$file = $log_file[0]; } - if (File::size(self::$file) > self::MAX_FILE_SIZE) - return null; + if (File::size(self::$file) > self::MAX_FILE_SIZE) { + return; + } $file = File::get(self::$file); preg_match_all($pattern, $file, $headings); - if (!is_array($headings)) + if (!is_array($headings)) { return $log; + } $log_data = preg_split($pattern, $file); @@ -112,38 +117,38 @@ class LaravelLogViewer { foreach ($headings as $h) { for ($i = 0, $j = count($h); $i < $j; $i++) { foreach ($log_levels as $level_key => $level_value) { - if (strpos(strtolower($h[$i]), '.' . $level_value)) { + if (strpos(strtolower($h[$i]), '.'.$level_value)) { + preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?(\w+)\.'.$level_key.': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current); - preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?(\w+)\.' . $level_key . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current); - - if (!isset($current[3])) + if (!isset($current[3])) { continue; + } $array = explode(':-:-:-', $current[3]); $message = $current[3]; $context = $current[2]; - + if (is_array($array)) { if (array_key_exists(0, $array)) { $message = $array[0]; } if (array_key_exists(1, $array)) { $context = $array[1]; - }else{ + } else { $context = $current[2]; } } //dd($current); - $log[] = array( - 'context' => $context, - 'level' => $level_value, + $log[] = [ + 'context' => $context, + 'level' => $level_value, 'level_class' => self::$levels_classes[$level_value], - 'level_img' => self::$levels_imgs[$level_value], - 'date' => self::date($current[1]), - 'text' => $message, - 'in_file' => isset($current[4]) ? $current[4] : null, - 'stack' => preg_replace("/^\n*/", '', $log_data[$i]) - ); + 'level_img' => self::$levels_imgs[$level_value], + 'date' => self::date($current[1]), + 'text' => $message, + 'in_file' => isset($current[4]) ? $current[4] : null, + 'stack' => preg_replace("/^\n*/", '', $log_data[$i]), + ]; } } } @@ -154,10 +159,12 @@ class LaravelLogViewer { /** * @param bool $basename + * * @return array */ - public static function getFiles($basename = false) { - $files = glob(storage_path() . '/logs/*'); + public static function getFiles($basename = false) + { + $files = glob(storage_path().'/logs/*'); $files = array_reverse($files); $files = array_filter($files, 'is_file'); if ($basename && is_array($files)) { @@ -165,20 +172,24 @@ class LaravelLogViewer { $files[$k] = basename($file); } } + return array_values($files); } /** * @return array */ - private static function getLogLevels() { - $class = new ReflectionClass(new LogLevel); + private static function getLogLevels() + { + $class = new ReflectionClass(new LogLevel()); + return $class->getConstants(); } - public static function date($utc) { + public static function date($utc) + { $system_date = UTC::usertimezone($utc); + return $system_date; } - } diff --git a/app/FaveoLog/LaravelLogViewerServiceProvider.php b/app/FaveoLog/LaravelLogViewerServiceProvider.php index dc3e59182..e55a135a9 100644 --- a/app/FaveoLog/LaravelLogViewerServiceProvider.php +++ b/app/FaveoLog/LaravelLogViewerServiceProvider.php @@ -4,8 +4,8 @@ namespace App\FaveoLog; use Illuminate\Support\ServiceProvider; -class LaravelLogViewerServiceProvider extends ServiceProvider { - +class LaravelLogViewerServiceProvider extends ServiceProvider +{ /** * Indicates if loading of the provider is deferred. * @@ -18,17 +18,17 @@ class LaravelLogViewerServiceProvider extends ServiceProvider { * * @return void */ - public function boot() { + public function boot() + { if (method_exists($this, 'package')) { - $this->package('rap2hpoutre/laravel-log-viewer', 'laravel-log-viewer', __DIR__ . '/../../'); + $this->package('rap2hpoutre/laravel-log-viewer', 'laravel-log-viewer', __DIR__.'/../../'); } - - $view_path = app_path() . DIRECTORY_SEPARATOR . 'FaveoLog' . DIRECTORY_SEPARATOR . 'views'; + $view_path = app_path().DIRECTORY_SEPARATOR.'FaveoLog'.DIRECTORY_SEPARATOR.'views'; $this->loadViewsFrom($view_path, 'log'); - - $lang_path = app_path() . DIRECTORY_SEPARATOR . 'FaveoLog' . DIRECTORY_SEPARATOR . 'lang'; - $this->loadTranslationsFrom($lang_path, "log"); + + $lang_path = app_path().DIRECTORY_SEPARATOR.'FaveoLog'.DIRECTORY_SEPARATOR.'lang'; + $this->loadTranslationsFrom($lang_path, 'log'); } /** @@ -36,7 +36,8 @@ class LaravelLogViewerServiceProvider extends ServiceProvider { * * @return void */ - public function register() { + public function register() + { // Add routes $routes = app_path('/FaveoLog/routes.php'); if (file_exists($routes)) { @@ -49,8 +50,8 @@ class LaravelLogViewerServiceProvider extends ServiceProvider { * * @return array */ - public function provides() { - return array(); + public function provides() + { + return []; } - } diff --git a/app/FaveoLog/controllers/LogViewerController.php b/app/FaveoLog/controllers/LogViewerController.php index 0a605e90c..0c1ea8d44 100644 --- a/app/FaveoLog/controllers/LogViewerController.php +++ b/app/FaveoLog/controllers/LogViewerController.php @@ -1,40 +1,38 @@ $logs, - 'files' => LaravelLogViewer::getFiles(true), - 'current_file' => LaravelLogViewer::getFileName() + 'logs' => $logs, + 'files' => LaravelLogViewer::getFiles(true), + 'current_file' => LaravelLogViewer::getFileName(), ]); } } diff --git a/app/FaveoLog/lang/en/lang.php b/app/FaveoLog/lang/en/lang.php index b759dc7d3..0633fcfa7 100644 --- a/app/FaveoLog/lang/en/lang.php +++ b/app/FaveoLog/lang/en/lang.php @@ -1,5 +1,5 @@ 'Logs', + 'logs'=> 'Logs', ]; diff --git a/app/FaveoLog/routes.php b/app/FaveoLog/routes.php index 852948516..89f37e71d 100644 --- a/app/FaveoLog/routes.php +++ b/app/FaveoLog/routes.php @@ -4,7 +4,6 @@ Breadcrumbs::register('logs', function ($breadcrumbs) { $breadcrumbs->parent('setting'); $breadcrumbs->push('System Logs', route('logs')); }); -Route::group(['middleware' => ['web', 'auth', 'roles']], function() { +Route::group(['middleware' => ['web', 'auth', 'roles']], function () { Route::get('logs', ['as' => 'logs', 'uses' => 'App\FaveoLog\controllers\LogViewerController@index']); }); - diff --git a/app/FaveoStorage/Controllers/SettingsController.php b/app/FaveoStorage/Controllers/SettingsController.php index 60bf35a9c..e7e8685cb 100644 --- a/app/FaveoStorage/Controllers/SettingsController.php +++ b/app/FaveoStorage/Controllers/SettingsController.php @@ -3,32 +3,34 @@ namespace App\FaveoStorage\Controllers; use App\Http\Controllers\Controller; -use Illuminate\Http\Request; use App\Model\helpdesk\Settings\CommonSettings; -use Exception; -use RecursiveIteratorIterator; -use RecursiveDirectoryIterator; use Artisan; +use Exception; +use Illuminate\Http\Request; use Lang; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; -class SettingsController extends Controller { - - public function settingsIcon() { +class SettingsController extends Controller +{ + public function settingsIcon() + { return '
-

'.Lang::get("storage::lang.storage").'

+

'.Lang::get('storage::lang.storage').'

'; } - public function settings() { + public function settings() + { try { $settings = new CommonSettings(); $directories = $this->directories(); @@ -42,13 +44,15 @@ class SettingsController extends Controller { if ($ro) { $root = $ro->option_value; } + return view('storage::settings', compact('default', 'root', 'directories')); } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } - public function postSettings(Request $request) { + public function postSettings(Request $request) + { try { $requests = $request->except('_token'); $this->delete(); @@ -59,13 +63,15 @@ class SettingsController extends Controller { } } } + return redirect()->back()->with('success', 'Updated'); } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } - public function delete() { + public function delete() + { $settings = CommonSettings::where('option_name', 'storage')->get(); if ($settings->count() > 0) { foreach ($settings as $setting) { @@ -74,16 +80,18 @@ class SettingsController extends Controller { } } - public function save($key, $value) { + public function save($key, $value) + { CommonSettings::create([ - 'option_name' => 'storage', + 'option_name' => 'storage', 'optional_field' => $key, - 'option_value' => $value, + 'option_value' => $value, ]); } - public function directories($root = "") { - if ($root == "") { + public function directories($root = '') + { + if ($root == '') { $root = base_path(); } @@ -91,7 +99,7 @@ class SettingsController extends Controller { new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied" ); - $paths = array($root); + $paths = [$root]; foreach ($iter as $path => $dir) { if ($dir->isDir()) { $paths[$path] = $path; @@ -101,17 +109,18 @@ class SettingsController extends Controller { return $paths; } - public function attachment() { + public function attachment() + { $storage = new StorageController(); $storage->upload(); } - - public function activate(){ - $path = "app".DIRECTORY_SEPARATOR."FaveoStorage".DIRECTORY_SEPARATOR."database".DIRECTORY_SEPARATOR."migrations"; - Artisan::call('migrate', [ + + public function activate() + { + $path = 'app'.DIRECTORY_SEPARATOR.'FaveoStorage'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations'; + Artisan::call('migrate', [ '--path' => $path, - '--force'=>true, + '--force'=> true, ]); } - } diff --git a/app/FaveoStorage/Controllers/StorageController.php b/app/FaveoStorage/Controllers/StorageController.php index 0daa41bc3..7c6178377 100644 --- a/app/FaveoStorage/Controllers/StorageController.php +++ b/app/FaveoStorage/Controllers/StorageController.php @@ -2,15 +2,15 @@ namespace App\FaveoStorage\Controllers; -use Storage; -use App\Model\helpdesk\Settings\CommonSettings; use App\Http\Controllers\Controller; -use Config; +use App\Model\helpdesk\Settings\CommonSettings; use App\Model\helpdesk\Ticket\Ticket_attachments; use App\Model\helpdesk\Ticket\Ticket_Thread; +use Config; +use Storage; -class StorageController extends Controller { - +class StorageController extends Controller +{ protected $default; protected $driver; protected $root; @@ -25,7 +25,8 @@ class StorageController extends Controller { protected $rackspace_endpoint; protected $rackspace_url_type; - public function __construct() { + public function __construct() + { $this->default = $this->defaults(); $this->driver = $this->driver(); $this->root = $this->root(); @@ -40,77 +41,95 @@ class StorageController extends Controller { $this->rackspace_username = $this->rackspaceUsername(); } - protected function settings($option) { + protected function settings($option) + { $settings = new CommonSettings(); $setting = $settings->getOptionValue('storage', $option); - $value = ""; + $value = ''; if ($setting) { $value = $setting->option_value; } + return $value; } - public function defaults() { - $default = "local"; + public function defaults() + { + $default = 'local'; if ($this->settings('default')) { $default = $this->settings('default'); } + return $default; } - public function driver() { + public function driver() + { return $this->settings('default'); } - public function root() { + public function root() + { $root = storage_path('app'); if ($this->settings('root')) { $root = $this->settings('root'); } + return $root; } - public function s3Key() { + public function s3Key() + { return $this->settings('s3_key'); } - public function s3Region() { + public function s3Region() + { return $this->settings('s3_region'); } - public function s3Secret() { + public function s3Secret() + { return $this->settings('s3_secret'); } - public function s3Bucket() { + public function s3Bucket() + { return $this->settings('s3_bucket'); } - public function rackspaceKey() { + public function rackspaceKey() + { return $this->settings('root'); } - public function rackspaceRegion() { + public function rackspaceRegion() + { return $this->settings('rackspace_region'); } - public function rackspaceUsername() { + public function rackspaceUsername() + { return $this->settings('rackspace_username'); } - public function rackspaceContainer() { + public function rackspaceContainer() + { return $this->settings('rackspace_container'); } - public function rackspaceEndpoint() { + public function rackspaceEndpoint() + { return $this->settings('rackspace_endpoint'); } - public function rackspaceUrlType() { + public function rackspaceUrlType() + { return $this->settings('rackspace_url_type'); } - protected function setFileSystem() { + protected function setFileSystem() + { $config = $this->config(); //dd($config); foreach ($config as $key => $con) { @@ -121,43 +140,47 @@ class StorageController extends Controller { } Config::set("filesystem.$key", $con); } + return Config::get('filesystem'); } - protected function config() { + protected function config() + { return [ 'default' => $this->default, - 'cloud' => 's3', - 'disks' => $this->disks(), + 'cloud' => 's3', + 'disks' => $this->disks(), ]; } - protected function disks() { + protected function disks() + { return [ - "local" => [ - 'driver' => "local", - 'root' => $this->root . '/attachments', + 'local' => [ + 'driver' => 'local', + 'root' => $this->root.'/attachments', ], - "s3" => [ - 'driver' => "s3", - 'key' => $this->s3_key, + 's3' => [ + 'driver' => 's3', + 'key' => $this->s3_key, 'secret' => $this->s3_secret, 'region' => $this->s3_region, 'bucket' => $this->s3_bucket, ], - "rackspace" => [ - 'driver' => "rackspace", - 'username' => $this->rackspace_username, - 'key' => $this->rackspace_key, + 'rackspace' => [ + 'driver' => 'rackspace', + 'username' => $this->rackspace_username, + 'key' => $this->rackspace_key, 'container' => $this->rackspace_container, - 'endpoint' => $this->rackspace_endpoint, - 'region' => $this->rackspace_region, - 'url_type' => $this->rackspace_url_type, + 'endpoint' => $this->rackspace_endpoint, + 'region' => $this->rackspace_region, + 'url_type' => $this->rackspace_url_type, ], ]; } - public function upload($data, $filename, $type, $size, $disposition, $thread_id) { + public function upload($data, $filename, $type, $size, $disposition, $thread_id) + { $upload = new Ticket_attachments(); $upload->thread_id = $thread_id; $upload->name = $filename; @@ -166,7 +189,7 @@ class StorageController extends Controller { $upload->poster = $disposition; $upload->driver = $this->default; $upload->path = $this->root; - if ($this->default !== "database") { + if ($this->default !== 'database') { $this->setFileSystem(); Storage::disk($this->default)->put($filename, $data); } else { @@ -177,7 +200,8 @@ class StorageController extends Controller { } } - public function saveAttachments($thread_id, $attachments = []) { + public function saveAttachments($thread_id, $attachments = []) + { if (is_array($attachments) && count($attachments) > 0) { foreach ($attachments as $attachment) { $structure = $attachment->getStructure(); @@ -185,7 +209,7 @@ class StorageController extends Controller { if (isset($structure->disposition)) { $disposition = $structure->disposition; } - $filename = str_random(16) . '-' . $attachment->getFileName(); + $filename = str_random(16).'-'.$attachment->getFileName(); $type = $attachment->getMimeType(); $size = $attachment->getSize(); $data = $attachment->getData(); @@ -195,31 +219,32 @@ class StorageController extends Controller { } } - public function updateBody($attachment, $thread_id, $filename) { + public function updateBody($attachment, $thread_id, $filename) + { $structure = $attachment->getStructure(); $disposition = 'ATTACHMENT'; if (isset($structure->disposition)) { $disposition = $structure->disposition; } if ($disposition == 'INLINE' || $disposition == 'inline') { - $id = str_replace(">", "", str_replace("<", "", $structure->id)); + $id = str_replace('>', '', str_replace('<', '', $structure->id)); $threads = new Ticket_Thread(); $thread = $threads->find($thread_id); $body = $thread->body; - $body = str_replace('cid:' . $id, $filename, $body); + $body = str_replace('cid:'.$id, $filename, $body); $thread->body = $body; $thread->save(); } } - public function getFile($drive, $name) { + public function getFile($drive, $name) + { //dd($drive,$name); - if ($drive != "database") { + if ($drive != 'database') { $this->setFileSystem(); - if(Storage::disk($this->default)->exists($name)){ + if (Storage::disk($this->default)->exists($name)) { return Storage::disk($this->default)->get($name); } } } - } diff --git a/app/FaveoStorage/StorageServiceProvider.php b/app/FaveoStorage/StorageServiceProvider.php index 4173bb2e6..35150154f 100644 --- a/app/FaveoStorage/StorageServiceProvider.php +++ b/app/FaveoStorage/StorageServiceProvider.php @@ -4,20 +4,20 @@ namespace App\FaveoStorage; use Illuminate\Support\ServiceProvider; -class StorageServiceProvider extends ServiceProvider { - +class StorageServiceProvider extends ServiceProvider +{ /** * Bootstrap the application events. * * @return void */ - public function boot() { - - $view_path = app_path() . DIRECTORY_SEPARATOR . 'FaveoStorage' . DIRECTORY_SEPARATOR . 'views'; + public function boot() + { + $view_path = app_path().DIRECTORY_SEPARATOR.'FaveoStorage'.DIRECTORY_SEPARATOR.'views'; $this->loadViewsFrom($view_path, 'storage'); - $lang_path = app_path() . DIRECTORY_SEPARATOR . 'FaveoStorage' . DIRECTORY_SEPARATOR . 'lang'; - $this->loadTranslationsFrom($lang_path, "storage"); + $lang_path = app_path().DIRECTORY_SEPARATOR.'FaveoStorage'.DIRECTORY_SEPARATOR.'lang'; + $this->loadTranslationsFrom($lang_path, 'storage'); if (isInstall()) { $controller = new Controllers\SettingsController(); @@ -25,7 +25,7 @@ class StorageServiceProvider extends ServiceProvider { } if (class_exists('Breadcrumbs')) { - require __DIR__ . '/breadcrumbs.php'; + require __DIR__.'/breadcrumbs.php'; } } @@ -44,5 +44,4 @@ class StorageServiceProvider extends ServiceProvider { } } } - } diff --git a/app/FaveoStorage/breadcrumbs.php b/app/FaveoStorage/breadcrumbs.php index 9f34fef57..5f28c0b6a 100644 --- a/app/FaveoStorage/breadcrumbs.php +++ b/app/FaveoStorage/breadcrumbs.php @@ -1,6 +1,6 @@ parent('setting'); $breadcrumbs->push('Storage', route('storage')); -}); \ No newline at end of file +}); diff --git a/app/FaveoStorage/database/migrations/2016_11_30_122809_alter_attachment_table.php b/app/FaveoStorage/database/migrations/2016_11_30_122809_alter_attachment_table.php index c928072de..503ce095f 100644 --- a/app/FaveoStorage/database/migrations/2016_11_30_122809_alter_attachment_table.php +++ b/app/FaveoStorage/database/migrations/2016_11_30_122809_alter_attachment_table.php @@ -1,7 +1,7 @@ 'Settings', - 'storage'=>'Storage', - 'default'=>'Default', - 'root'=>'Root', - 'region'=>'Region', - 'key'=>'Key', - 'secret'=>'Secret', - 'bucket'=>'Bucket', - 'username'=>'Username', - 'container'=>'Container', - 'endpoint'=>'End Point', - 'url_type'=>'Url Type', + 'settings' => 'Settings', + 'storage' => 'Storage', + 'default' => 'Default', + 'root' => 'Root', + 'region' => 'Region', + 'key' => 'Key', + 'secret' => 'Secret', + 'bucket' => 'Bucket', + 'username' => 'Username', + 'container'=> 'Container', + 'endpoint' => 'End Point', + 'url_type' => 'Url Type', ]; - diff --git a/app/FaveoStorage/routes.php b/app/FaveoStorage/routes.php index 25869a26b..8a0a07f52 100644 --- a/app/FaveoStorage/routes.php +++ b/app/FaveoStorage/routes.php @@ -1,16 +1,12 @@ settingsIcon(); }); - -Route::group(['middleware'=>['web']],function(){ - Route::get('storage',['as'=>'storage','uses'=>'App\FaveoStorage\Controllers\SettingsController@settings']); - Route::post('storage',['as'=>'post.storage','uses'=>'App\FaveoStorage\Controllers\SettingsController@postSettings']); - Route::get('attachment',['as'=>'attach','uses'=>'App\FaveoStorage\Controllers\SettingsController@attachment']); - +Route::group(['middleware'=>['web']], function () { + Route::get('storage', ['as'=>'storage', 'uses'=>'App\FaveoStorage\Controllers\SettingsController@settings']); + Route::post('storage', ['as'=>'post.storage', 'uses'=>'App\FaveoStorage\Controllers\SettingsController@postSettings']); + Route::get('attachment', ['as'=>'attach', 'uses'=>'App\FaveoStorage\Controllers\SettingsController@attachment']); }); - - diff --git a/app/Helper/Finder.php b/app/Helper/Finder.php index 18bfc80cc..1895f451d 100644 --- a/app/Helper/Finder.php +++ b/app/Helper/Finder.php @@ -4,156 +4,181 @@ namespace App\Helper; use App\Model\helpdesk\Agent\Department; use App\Model\helpdesk\Agent\Groups; -use App\Model\helpdesk\Ticket\TicketStatusType; use App\Model\helpdesk\Ticket\Ticket_Status; +use App\Model\helpdesk\Ticket\TicketStatusType; /** *------------------------------------------------------------------ * Class Finder *------------------------------------------------------------------ - * Description: This class is used for defining some common functions + * Description: This class is used for defining some common functions * used in the project. - * + * * @author */ class Finder { - - /** - * DEPARTMENT - * This function is used for returning department name with respect to id - * @param $id type int - * @param $custom type array/null - * @return type string - */ - public static function department($id, $custom = null) { - if($custom == null) { - $department = Department::whereId($id)->select(['name']); - } elseif(isset($custom)) { - $department = Department::whereId($id)->select($custom); - } - return $department->first()->name; - } + /** + * DEPARTMENT + * This function is used for returning department name with respect to id. + * + * @param $id type int + * @param $custom type array/null + * + * @return type string + */ + public static function department($id, $custom = null) + { + if ($custom == null) { + $department = Department::whereId($id)->select(['name']); + } elseif (isset($custom)) { + $department = Department::whereId($id)->select($custom); + } + + return $department->first()->name; + } + + /** + * GROUP + * This function is used for returning group name with respect to id. + * + * @param $id type int + * @param $custom type array/null + * + * @return type string + */ + public static function group($id, $custom = null) + { + if ($custom == null) { + $group = Groups::whereId($id)->select(['name']); + } elseif (isset($custom)) { + $group = Groups::whereId($id)->select($custom); + } + + return $group->first()->name; + } - /** - * GROUP - * This function is used for returning group name with respect to id - * @param $id type int - * @param $custom type array/null - * @return type string - */ - public static function group($id, $custom = null) { - if($custom == null) { - $group = Groups::whereId($id)->select(['name']); - } elseif(isset($custom)) { - $group = Groups::whereId($id)->select($custom); - } - 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 - * This function is used for returning status name with respect to id - * @param $id type int - * @param $custom type array/null - * @return type string - */ - public static function status($id, $custom = null) { - if($custom == null) { - $status = Ticket_Status::whereId($id)->first(); - } elseif(isset($custom)) { - $status = Ticket_Status::whereId($id)->select($custom); - } - return $status; - } + * 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); + } - /** - * USER ROLES IN A GROUP FOR STATUS LIST - * This function is used to return roles of users from a given value. - * If the value is 1 the response is client - * If the value is 2 the response is agent - * If the value is 4 the response is admin - * If the value is 1+2 = 3 the response is client, agent - * If the value is 1+4 = 5 the response is client, admin - * If the value is 2+4 = 6 the response is agent, admin - * If the value is 1+2+4 = 7 the response is client, agent, admin - * @param $id type int - * @return type string - */ - public static function rolesGroup($id) { - - switch ($id) { + return $status_type->first()->name; + } + + /** + * STATUS + * This function is used for returning status name with respect to id. + * + * @param $id type int + * @param $custom type array/null + * + * @return type string + */ + public static function status($id, $custom = null) + { + if ($custom == null) { + $status = Ticket_Status::whereId($id)->first(); + } elseif (isset($custom)) { + $status = Ticket_Status::whereId($id)->select($custom); + } + + return $status; + } + + /** + * USER ROLES IN A GROUP FOR STATUS LIST + * This function is used to return roles of users from a given value. + * If the value is 1 the response is client + * If the value is 2 the response is agent + * If the value is 4 the response is admin + * If the value is 1+2 = 3 the response is client, agent + * If the value is 1+4 = 5 the response is client, admin + * If the value is 2+4 = 6 the response is agent, admin + * If the value is 1+2+4 = 7 the response is client, agent, admin. + * + * @param $id type int + * + * @return type string + */ + public static function rolesGroup($id) + { + switch ($id) { case null: return \Lang::get('lang.none'); case 1: - return "Client"; + return 'Client'; case 2: - return "Agent"; + return 'Agent'; case 4: - return "Admin"; + return 'Admin'; case 3: - return "Client,Agent"; + return 'Client,Agent'; case 5: - return "Client,Admin"; + return 'Client,Admin'; case 6: - return "Agent,Admin"; + return 'Agent,Admin'; case 7: - return "Client,Agent,Admin"; + return 'Client,Agent,Admin'; default: - return "Undefined!"; + return 'Undefined!'; } - } + } /** * ANY TYPE STATUS - * This function is used to return the set of status which are of any type passed in the param + * 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; + 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; } - + /** * RETURNS ALL STATUS - * This function is used to return all the status given in the system + * 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; + 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 - * + * VARIABLE REPLACEMENT + * This function is used to replace the replaceable variables form a given content for templates. */ - public static function replaceTemplateVariables($variables, $data, $contents) { + public static function replaceTemplateVariables($variables, $data, $contents) + { foreach ($variables as $key => $variable) { - $messagebody = str_replace($variables[$key], $data[$key], $contents); - $contents = $messagebody; + $messagebody = str_replace($variables[$key], $data[$key], $contents); + $contents = $messagebody; } + return $contents; } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Admin/MailFetch.php b/app/Http/Controllers/Admin/MailFetch.php index 97d98b1f6..f2c3765c1 100644 --- a/app/Http/Controllers/Admin/MailFetch.php +++ b/app/Http/Controllers/Admin/MailFetch.php @@ -1,10 +1,13 @@ serverPath = $serverPath; $this->port = $port; diff --git a/app/Http/Controllers/Admin/helpdesk/AgentController.php b/app/Http/Controllers/Admin/helpdesk/AgentController.php index 968fd78de..9b94793bd 100644 --- a/app/Http/Controllers/Admin/helpdesk/AgentController.php +++ b/app/Http/Controllers/Admin/helpdesk/AgentController.php @@ -3,8 +3,8 @@ namespace App\Http\Controllers\Admin\helpdesk; // controller -use App\Http\Controllers\Controller; use App\Http\Controllers\Common\PhpMailController; +use App\Http\Controllers\Controller; // request use App\Http\Requests\helpdesk\AgentRequest; use App\Http\Requests\helpdesk\AgentUpdate; @@ -92,6 +92,7 @@ class AgentController extends Controller $phonecode = $code->where('iso', '=', $location->iso_code)->first(); // returns to the page with all the variables and their datas $send_otp = DB::table('common_settings')->select('status')->where('option_name', '=', 'send_otp')->first(); + return view('themes.default1.admin.helpdesk.agent.agents.create', compact('assign', 'teams', 'agents', 'timezones', 'groups', 'departments', 'team', 'send_otp'))->with('phonecode', $phonecode->phonecode); } catch (Exception $e) { // returns if try fails with exception meaagse @@ -120,10 +121,9 @@ class AgentController extends Controller } // fixing the user role to agent $user->fill($request->except(['group', 'primary_department', 'agent_time_zone', 'mobile']))->save(); - if ($request->get('mobile')) - { + if ($request->get('mobile')) { $user->mobile = $request->get('mobile'); - } else{ + } else { $user->mobile = null; } $user->assign_group = $request->group; @@ -146,7 +146,7 @@ class AgentController extends Controller // fetch user credentails to send mail $name = $user->first_name; $email = $user->email; - if($request->input('send_email')) { + if ($request->input('send_email')) { try { // send mail on registration $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]); @@ -159,6 +159,7 @@ class AgentController extends Controller if ($request->input('active') == '0' || $request->input('active') == 0) { \Event::fire(new \App\Events\LoginEvent($request)); } + return redirect('agents')->with('success', Lang::get('lang.agent_creation_success')); } else { // returns if fails @@ -275,7 +276,6 @@ class AgentController extends Controller $user->id; $user->delete(); throw new \Exception($error); - return redirect('agents')->with('success', Lang::get('lang.agent_deleted_sucessfully')); } catch (\Exception $e) { return redirect('agents')->with('fails', $error); diff --git a/app/Http/Controllers/Admin/helpdesk/DepartmentController.php b/app/Http/Controllers/Admin/helpdesk/DepartmentController.php index adbc7108d..781b59427 100644 --- a/app/Http/Controllers/Admin/helpdesk/DepartmentController.php +++ b/app/Http/Controllers/Admin/helpdesk/DepartmentController.php @@ -29,14 +29,15 @@ use Lang; * * @author Ladybird */ -class DepartmentController extends Controller { - +class DepartmentController extends Controller +{ /** * Create a new controller instance. * * @return void */ - public function __construct() { + public function __construct() + { $this->middleware('auth'); $this->middleware('roles'); } @@ -48,9 +49,11 @@ class DepartmentController extends Controller { * * @return type Response */ - public function index(Department $department) { + public function index(Department $department) + { try { $departments = $department->get(); + return view('themes.default1.admin.helpdesk.agent.departments.index', compact('departments')); } catch (Exception $e) { return view('404'); @@ -70,14 +73,15 @@ class DepartmentController extends Controller { * * @return type Response */ - public function create(User $user, Group_assign_department $group_assign_department, Department $department, Sla_plan $sla, Template $template, Emails $email, Groups $group) { + public function create(User $user, Group_assign_department $group_assign_department, Department $department, Sla_plan $sla, Template $template, Emails $email, Groups $group) + { try { $slas = $sla->where('status', '=', 1) - ->select('grace_period','id')->get(); + ->select('grace_period', 'id')->get(); $user = $user->where('role', '<>', 'user') ->where('active', '=', 1) ->get(); - $emails = $email->select('email_name','id')->get(); + $emails = $email->select('email_name', 'id')->get(); $templates = $template->get(); $department = $department->get(); $groups = $group->lists('id', 'name'); @@ -96,7 +100,8 @@ class DepartmentController extends Controller { * * @return type Response */ - public function store(Department $department, DepartmentRequest $request) { + public function store(Department $department, DepartmentRequest $request) + { try { $department->fill($request->except('group_id', 'manager', 'sla'))->save(); if ($request->sla) { @@ -119,6 +124,7 @@ class DepartmentController extends Controller { ->where('id', 1) ->update(['department' => $department->id]); } + return redirect('departments')->with('success', Lang::get('lang.department_created_sucessfully')); } else { return redirect('departments')->with('fails', Lang::get('lang.failed_to_create_department')); @@ -143,18 +149,19 @@ class DepartmentController extends Controller { * * @return type Response */ - public function edit($id, User $user, Group_assign_department $group_assign_department, Template $template, Teams $team, Department $department, Sla_plan $sla, Emails $email, Groups $group) { + public function edit($id, User $user, Group_assign_department $group_assign_department, Template $template, Teams $team, Department $department, Sla_plan $sla, Emails $email, Groups $group) + { try { $sys_department = \DB::table('settings_system') ->select('department') ->where('id', '=', 1) ->first(); $slas = $sla->where('status', '=', 1) - ->select('grace_period','id')->get(); + ->select('grace_period', 'id')->get(); $user = $user->where('primary_dpt', $id) ->where('active', '=', 1) - ->get(); - $emails = $email->select('email_name','id')->get(); + ->get(); + $emails = $email->select('email_name', 'id')->get(); $templates = $template->get(); $departments = $department->whereId($id)->first(); //$groups = $group->lists('id', 'name'); @@ -176,7 +183,8 @@ class DepartmentController extends Controller { * * @return type Response */ - public function update($id, Group_assign_department $group_assign_department, Department $department, DepartmentUpdate $request) { + public function update($id, Group_assign_department $group_assign_department, Department $department, DepartmentUpdate $request) + { // dd($id); try { $table = $group_assign_department->where('department_id', $id); @@ -224,9 +232,10 @@ class DepartmentController extends Controller { * * @return type Response */ - public function destroy($id, Department $department, Group_assign_department $group_assign_department, System $system, Tickets $tickets) { + public function destroy($id, Department $department, Group_assign_department $group_assign_department, System $system, Tickets $tickets) + { // try { - + $system = $system->where('id', '=', '1')->first(); if ($system->department == $id) { return redirect('departments')->with('fails', Lang::get('lang.you_cannot_delete_default_department')); @@ -238,7 +247,7 @@ class DepartmentController extends Controller { } else { $text_tickets = 'Ticket'; } - $ticket = '
  • ' . $tickets . ' ' . $text_tickets . Lang::get('lang.have_been_moved_to_default_department') . '
  • '; + $ticket = '
  • '.$tickets.' '.$text_tickets.Lang::get('lang.have_been_moved_to_default_department').'
  • '; } else { $ticket = ''; } @@ -249,7 +258,7 @@ class DepartmentController extends Controller { } else { $text_user = 'User'; } - $user = '
  • ' . $users . ' ' . $text_user . Lang::get('lang.have_been_moved_to_default_department') . '
  • '; + $user = '
  • '.$users.' '.$text_user.Lang::get('lang.have_been_moved_to_default_department').'
  • '; } else { $user = ''; } @@ -260,28 +269,27 @@ class DepartmentController extends Controller { } else { $text_emails = 'Email'; } - $email = '
  • ' . $emails . ' System ' . $text_emails . Lang::get('lang.have_been_moved_to_default_department') . '
  • '; + $email = '
  • '.$emails.' System '.$text_emails.Lang::get('lang.have_been_moved_to_default_department').'
  • '; } else { $email = ''; } $helptopic = DB::table('help_topic')->where('department', '=', $id)->update(['department' => null], ['status' => '1']); if ($helptopic > 0) { - $helptopic = '
  • ' . Lang::get('lang.the_associated_helptopic_has_been_deactivated') . '
  • '; + $helptopic = '
  • '.Lang::get('lang.the_associated_helptopic_has_been_deactivated').'
  • '; } else { $helptopic = ''; } - $message = $ticket . $user . $email . $helptopic; + $message = $ticket.$user.$email.$helptopic; /* Becouse of foreign key we delete group_assign_department first */ $group_assign_department = $group_assign_department->where('department_id', $id); $group_assign_department->delete(); $departments = $department->whereId($id)->first(); /* Check the function is Success or Fail */ if ($departments->delete() == true) { - return redirect('departments')->with('success', Lang::get('lang.department_deleted_sucessfully') . $message); + return redirect('departments')->with('success', Lang::get('lang.department_deleted_sucessfully').$message); } else { return redirect('departments')->with('fails', Lang::get('lang.department_can_not_delete')); } } } - } diff --git a/app/Http/Controllers/Admin/helpdesk/EmailsController.php b/app/Http/Controllers/Admin/helpdesk/EmailsController.php index 2ac96c622..8c15c251e 100644 --- a/app/Http/Controllers/Admin/helpdesk/EmailsController.php +++ b/app/Http/Controllers/Admin/helpdesk/EmailsController.php @@ -3,21 +3,21 @@ namespace App\Http\Controllers\Admin\helpdesk; // controllers +use App\Http\Controllers\Admin\MailFetch as Fetch; use App\Http\Controllers\Controller; use App\Http\Requests\helpdesk\EmailsRequest; -use App\Model\helpdesk\Agent\Department; // model +use App\Http\Requests\helpdesk\Mail\MailRequest; +use App\Model\helpdesk\Agent\Department; use App\Model\helpdesk\Email\Emails; use App\Model\helpdesk\Manage\Help_topic; use App\Model\helpdesk\Settings\Email; use App\Model\helpdesk\Ticket\Ticket_Priority; +// classes use App\Model\helpdesk\Utility\MailboxProtocol; use Crypt; -// classes use Exception; use Lang; -use App\Http\Requests\helpdesk\Mail\MailRequest; -use App\Http\Controllers\Admin\MailFetch as Fetch; /** * ====================================== @@ -27,14 +27,15 @@ use App\Http\Controllers\Admin\MailFetch as Fetch; * * @author Ladybird */ -class EmailsController extends Controller { - +class EmailsController extends Controller +{ /** * Defining constructor variables. * * @return type */ - public function __construct() { + public function __construct() + { $this->middleware('auth'); $this->middleware('roles'); } @@ -46,7 +47,8 @@ class EmailsController extends Controller { * * @return type view */ - public function index(Emails $email) { + public function index(Emails $email) + { try { // fetch all the emails from emails table $emails = $email->get(); @@ -67,7 +69,8 @@ class EmailsController extends Controller { * * @return type Response */ - public function create(Department $department, Help_topic $help, Ticket_Priority $ticket_priority, MailboxProtocol $mailbox_protocol) { + public function create(Department $department, Help_topic $help, Ticket_Priority $ticket_priority, MailboxProtocol $mailbox_protocol) + { try { // fetch all the departments from the department table $departments = $department->get(); @@ -96,7 +99,8 @@ class EmailsController extends Controller { * * @return int */ - public function validatingEmailSettings(MailRequest $request, $id = "") { + public function validatingEmailSettings(MailRequest $request, $id = '') + { //dd($request->all()); try { $service_request = $request->except('sending_status', '_token', 'email_address', 'email_name', 'password', 'department', 'priority', 'help_topic', 'fetching_protocol', 'fetching_host', 'fetching_port', 'fetching_encryption', 'imap_authentication', 'sending_protocol', 'sending_host', 'sending_port', 'sending_encryption', 'smtp_authentication', 'internal_notes', '_wysihtml5_mode', 'code'); @@ -114,8 +118,10 @@ class EmailsController extends Controller { } if ($send == 1 && $fetch == 1) { $this->store($request, $service_request, $id); + return $this->jsonResponse('success', Lang::get('lang.success')); } + return $this->validateEmailError($send, $fetch); } catch (Exception $ex) { $message = $ex->getMessage(); @@ -123,11 +129,13 @@ class EmailsController extends Controller { $message = imap_last_error(); } loging('mail-config', $message); + return $this->jsonResponse('fails', $message); } } - public function validateEmailError($out, $in) { + public function validateEmailError($out, $in) + { if ($out !== 1) { return $this->jsonResponse('fails', Lang::get('lang.outgoing_email_connection_failed')); } @@ -136,13 +144,15 @@ class EmailsController extends Controller { } } - public function jsonResponse($type, $message) { + public function jsonResponse($type, $message) + { if ($type == 'fails') { $result = ['fails' => $message]; } if ($type == 'success') { $result = ['success' => $message]; } + return response()->json(compact('result')); } @@ -154,9 +164,10 @@ class EmailsController extends Controller { * * @return type Redirect */ - public function store($request, $service_request = [], $id = "") { + public function store($request, $service_request = [], $id = '') + { $email = new Emails(); - if ($id !== "") { + if ($id !== '') { $email = $email->find($id); } @@ -208,7 +219,7 @@ class EmailsController extends Controller { if ($request->input('fetching_status')) { $this->fetch($email); } - if ($id === "") { + if ($id === '') { // Creating a default system email as the first email is inserted to the system $email_settings = Email::where('id', '=', '1')->first(); $email_settings->sys_email = $email->id; @@ -222,10 +233,12 @@ class EmailsController extends Controller { if ($request->input('fetching_status')) { $this->fetch($email); } + return 1; } - public function checkMail($request) { + public function checkMail($request) + { $mailservice_id = $request->input('sending_protocol'); $driver = $this->getDriver($mailservice_id); $username = $request->input('email_address'); @@ -243,10 +256,12 @@ class EmailsController extends Controller { $transport->setPassword($password); $mailer = \Swift_Mailer::newInstance($transport); $mailer->getTransport()->start(); + return 1; } - public function sendDiagnoEmail($request) { + public function sendDiagnoEmail($request) + { $mailservice_id = $request->input('sending_protocol'); $driver = $this->getDriver($mailservice_id); $username = $request->input('email_address'); @@ -260,41 +275,45 @@ class EmailsController extends Controller { $this->emailService($driver, $service_request); $this->setMailConfig($driver, $username, $name, $password, $enc, $host, $port); $controller = new \App\Http\Controllers\Common\PhpMailController(); - $subject = "test"; - $data = "test"; + $subject = 'test'; + $data = 'test'; //dd(\Config::get('mail'),\Config::get('services')); $send = $controller->laravelMail($username, $name, $subject, $data, [], []); + return $send; } - public function setMailConfig($driver, $username, $name, $password, $enc, $host, $port) { + public function setMailConfig($driver, $username, $name, $password, $enc, $host, $port) + { $configs = [ - 'username' => $username, - 'from' => ['address' => $username, 'name' => $name,], - 'password' => $password, + 'username' => $username, + 'from' => ['address' => $username, 'name' => $name], + 'password' => $password, 'encryption' => $enc, - 'host' => $host, - 'port' => $port, - 'driver' => $driver, + 'host' => $host, + 'port' => $port, + 'driver' => $driver, ]; foreach ($configs as $key => $config) { if (is_array($config)) { foreach ($config as $from) { - \Config::set('mail.' . $key, $config); + \Config::set('mail.'.$key, $config); } } else { - \Config::set('mail.' . $key, $config); + \Config::set('mail.'.$key, $config); } } } - public function getDriver($driver_id) { - $short = ""; + public function getDriver($driver_id) + { + $short = ''; $email_drivers = new \App\Model\MailJob\MailService(); $email_driver = $email_drivers->find($driver_id); if ($email_driver) { $short = $email_driver->short_name; } + return $short; } @@ -310,7 +329,8 @@ class EmailsController extends Controller { * * @return type Response */ - public function edit($id, Department $department, Help_topic $help, Emails $email, Ticket_Priority $ticket_priority, MailboxProtocol $mailbox_protocol) { + public function edit($id, Department $department, Help_topic $help, Emails $email, Ticket_Priority $ticket_priority, MailboxProtocol $mailbox_protocol) + { try { $sys_email = \DB::table('settings_email')->select('sys_email')->where('id', '=', 1)->first(); // dd($sys_email); @@ -345,7 +365,8 @@ class EmailsController extends Controller { * * @return int */ - public function validatingEmailSettingsUpdate($id, MailRequest $request) { + public function validatingEmailSettingsUpdate($id, MailRequest $request) + { try { return $this->validatingEmailSettings($request, $id); } catch (Exception $ex) { @@ -369,9 +390,9 @@ class EmailsController extends Controller { * * @return type Response */ - public function update($id, $request) { + public function update($id, $request) + { try { - if ($request->sys_email == 'on') { $system = \DB::table('settings_email') ->where('id', '=', 1) @@ -397,7 +418,8 @@ class EmailsController extends Controller { * * @return type Redirect */ - public function destroy($id, Emails $email) { + public function destroy($id, Emails $email) + { // fetching the details on the basis of the $id passed to the function $default_system_email = Email::where('id', '=', '1')->first(); if ($default_system_email->sys_email) { @@ -411,6 +433,7 @@ class EmailsController extends Controller { $emails = $email->whereId($id)->first(); // checking if deleting the email is success or if it's carrying any dependencies $emails->delete(); + return redirect('emails')->with('success', Lang::get('lang.email_deleted_sucessfully')); } catch (Exception $e) { // returns if the try fails @@ -425,7 +448,8 @@ class EmailsController extends Controller { * * @return type int */ - public function getImapStream($request) { + public function getImapStream($request) + { $host = $request->input('fetching_host'); $port = $request->input('fetching_port'); $service = $request->input('fetching_protocol'); @@ -435,7 +459,7 @@ class EmailsController extends Controller { $password = $request->input('password'); $server = new Fetch($host, $port, $service); //$server->setFlag('novalidate-cert'); - if ($encryption != "") { + if ($encryption != '') { $server->setFlag($encryption); } if (!$validate) { @@ -446,6 +470,7 @@ class EmailsController extends Controller { $server->setAuthentication($username, $password); $server->getImapStream(); + return 1; } @@ -456,7 +481,8 @@ class EmailsController extends Controller { * * @return type int */ - public function checkImapStream($imap_stream) { + public function checkImapStream($imap_stream) + { $check_imap_stream = imap_check($imap_stream); if ($check_imap_stream) { $imap_stream = 1; @@ -474,7 +500,8 @@ class EmailsController extends Controller { * * @return int */ - public function getSmtp($request) { + public function getSmtp($request) + { $sending_status = $request->input('sending_status'); // cheking for the sending protocol if ($request->input('sending_protocol') == 'smtp') { @@ -490,8 +517,8 @@ class EmailsController extends Controller { $mail->SMTPAuth = true; // Enable SMTP authentication $mail->SMTPOptions = [ 'ssl' => [ - 'verify_peer' => false, - 'verify_peer_name' => false, + 'verify_peer' => false, + 'verify_peer_name' => false, 'allow_self_signed' => true, ], ]; @@ -523,7 +550,8 @@ class EmailsController extends Controller { * * @return type string or null */ - public function departmentValue($dept) { + public function departmentValue($dept) + { if ($dept) { $email_department = $dept; } else { @@ -540,7 +568,8 @@ class EmailsController extends Controller { * * @return type string or null */ - public function priorityValue($priority) { + public function priorityValue($priority) + { if ($priority) { $email_priority = $priority; } else { @@ -557,7 +586,8 @@ class EmailsController extends Controller { * * @return type string or null */ - public function helpTopicValue($help_topic) { + public function helpTopicValue($help_topic) + { if ($help_topic) { $email_help_topic = $help_topic; } else { @@ -567,18 +597,20 @@ class EmailsController extends Controller { return $email_help_topic; } - public function emailService($service, $value = []) { + public function emailService($service, $value = []) + { switch ($service) { - case "mailgun": + case 'mailgun': $this->setServiceConfig($service, $value); - case "mandrill": + case 'mandrill': $this->setServiceConfig($service, $value); - case "ses": + case 'ses': $this->setServiceConfig($service, $value); } } - public function setServiceConfig($service, $value) { + public function setServiceConfig($service, $value) + { //dd($service); if (count($value) > 0) { foreach ($value as $k => $v) { @@ -587,7 +619,8 @@ class EmailsController extends Controller { } } - public function saveMailService($emailid, $request, $driver) { + public function saveMailService($emailid, $request, $driver) + { $mail_service = new \App\Model\MailJob\FaveoMail(); $mails = $mail_service->where('email_id', $emailid)->get(); if (count($request) > 0) { @@ -596,16 +629,17 @@ class EmailsController extends Controller { } foreach ($request as $key => $value) { $mail_service->create([ - 'drive' => $driver, - 'key' => $key, - 'value' => $value, + 'drive' => $driver, + 'key' => $key, + 'value' => $value, 'email_id' => $emailid, ]); } } } - public function readMails() { + public function readMails() + { $PhpMailController = new \App\Http\Controllers\Common\PhpMailController(); $NotificationController = new \App\Http\Controllers\Common\NotificationController(); $TicketController = new \App\Http\Controllers\Agent\helpdesk\TicketController($PhpMailController, $NotificationController); @@ -618,7 +652,8 @@ class EmailsController extends Controller { $controller->readmails($emails, $settings_email, $system, $ticket); } - public function fetch($email) { + public function fetch($email) + { $PhpMailController = new \App\Http\Controllers\Common\PhpMailController(); $NotificationController = new \App\Http\Controllers\Common\NotificationController(); $TicketController = new \App\Http\Controllers\Agent\helpdesk\TicketController($PhpMailController, $NotificationController); @@ -626,5 +661,4 @@ class EmailsController extends Controller { $controller = new \App\Http\Controllers\Agent\helpdesk\MailController($TicketWorkflowController); $controller->fetch($email); } - } diff --git a/app/Http/Controllers/Admin/helpdesk/FormController.php b/app/Http/Controllers/Admin/helpdesk/FormController.php index 9a6bee349..5a7d90d9b 100644 --- a/app/Http/Controllers/Admin/helpdesk/FormController.php +++ b/app/Http/Controllers/Admin/helpdesk/FormController.php @@ -9,13 +9,13 @@ use App\Model\helpdesk\Form\Fields; use App\Model\helpdesk\Form\Forms; use App\Model\helpdesk\Manage\Help_topic; // Request -use Illuminate\Http\Request; +use Exception; // Class +use Form; +use Illuminate\Http\Request; use Input; use Lang; use Redirect; -use Exception; -use Form; /** * FormController @@ -23,12 +23,13 @@ use Form; * * @author Ladybird */ -class FormController extends Controller { - +class FormController extends Controller +{ private $fields; private $forms; - public function __construct(Fields $fields, Forms $forms) { + public function __construct(Fields $fields, Forms $forms) + { $this->fields = $fields; $this->forms = $forms; $this->middleware('auth', [ @@ -43,7 +44,7 @@ class FormController extends Controller { 'jqueryScript', 'jqueryCheckboxScript', 'jquerySelectScript', - ] + ], ]); } @@ -52,7 +53,8 @@ class FormController extends Controller { * * @return type */ - public function home() { + public function home() + { return view('forms.home'); } @@ -63,7 +65,8 @@ class FormController extends Controller { * * @return Response */ - public function index(Forms $forms) { + public function index(Forms $forms) + { try { return view('themes.default1.admin.helpdesk.manage.form.index', compact('forms')); } catch (Exception $e) { @@ -76,7 +79,8 @@ class FormController extends Controller { * * @return Response */ - public function create() { + public function create() + { try { return view('themes.default1.admin.helpdesk.manage.form.form'); } catch (Exception $e) { @@ -91,13 +95,15 @@ class FormController extends Controller { * * @return Response */ - public function show($id) { + public function show($id) + { try { $forms = new Forms(); $form = $forms->find($id); //dd($form); if ($form) { $fields = $form->fields(); + return view('themes.default1.admin.helpdesk.manage.form.preview', compact('form', 'fields')); } throw new Exception("Sorry we can't find your request"); @@ -111,12 +117,13 @@ class FormController extends Controller { * * @return Response */ - public function store(Request $request) { + public function store(Request $request) + { $this->validate($request, [ 'formname' => 'required|unique:custom_forms,formname', - 'label.*' => 'required', - 'name.*' => 'required', - 'type.*' => 'required', + 'label.*' => 'required', + 'name.*' => 'required', + 'type.*' => 'required', ]); try { $forms = new Forms(); @@ -131,19 +138,20 @@ class FormController extends Controller { $name = str_slug(Input::get('name')[$i], '_'); $field = Fields::create([ 'forms_id' => $forms->id, - 'label' => Input::get('label')[$i], - 'name' => $name, - 'type' => Input::get('type')[$i], + 'label' => Input::get('label')[$i], + 'name' => $name, + 'type' => Input::get('type')[$i], 'required' => $require[$i], ]); $field_id = $field->id; - $this->createValues($field_id, Input::get('value')[$i],null,$name); + $this->createValues($field_id, Input::get('value')[$i], null, $name); } } return Redirect::back()->with('success', Lang::get('lang.successfully_created_form')); } catch (Exception $ex) { dd($ex); + return redirect()->back()->with('fails', $ex->getMessage()); } } @@ -158,7 +166,8 @@ class FormController extends Controller { * * @return type redirect */ - public function delete($id, Forms $forms, Fields $field, Help_topic $help_topic) { + public function delete($id, Forms $forms, Fields $field, Help_topic $help_topic) + { $fields = $field->where('forms_id', $id)->get(); $help_topics = $help_topic->where('custom_form', '=', $id)->get(); foreach ($help_topics as $help_topic) { @@ -174,7 +183,8 @@ class FormController extends Controller { return redirect()->back()->with('success', Lang::get('lang.form_deleted_successfully')); } - public function edit($id) { + public function edit($id) + { try { $forms = new Forms(); $form = $forms->find($id); @@ -187,12 +197,12 @@ class FormController extends Controller { } throw new Exception("Sorry we can't find your request"); } catch (Exception $ex) { - return redirect()->back()->with('fails', $ex->getMessage()); } } - public function addChildForm($id) { + public function addChildForm($id) + { try { $forms = new Forms(); $form = $forms->find($id); @@ -205,17 +215,17 @@ class FormController extends Controller { } throw new Exception("Sorry we can't find your request"); } catch (Exception $ex) { - return redirect()->back()->with('fails', $ex->getMessage()); } } - public function update($id, Request $request) { + public function update($id, Request $request) + { $this->validate($request, [ - 'formname' => 'required|unique:custom_forms,formname,' . $id, - 'label.*' => 'required', - 'name.*' => 'required', - 'type.*' => 'required', + 'formname' => 'required|unique:custom_forms,formname,'.$id, + 'label.*' => 'required', + 'name.*' => 'required', + 'type.*' => 'required', ]); try { if (!$request->input('formname')) { @@ -224,7 +234,7 @@ class FormController extends Controller { $form = new Forms(); $forms = $form->find($id); if (!$forms) { - throw new Exception("Sorry we can not find your request"); + throw new Exception('Sorry we can not find your request'); } $forms->formname = Input::get('formname'); $forms->save(); @@ -241,23 +251,26 @@ class FormController extends Controller { $name = str_slug(Input::get('name')[$i], '_'); $field = $field->create([ 'forms_id' => $forms->id, - 'label' => Input::get('label')[$i], - 'name' => $name, - 'type' => Input::get('type')[$i], + 'label' => Input::get('label')[$i], + 'name' => $name, + 'type' => Input::get('type')[$i], 'required' => Input::get('required')[$i], ]); $field_id = $field->id; - $this->createValues($field_id, Input::get('value')[$i],null,$name); + $this->createValues($field_id, Input::get('value')[$i], null, $name); } + return redirect()->back()->with('success', 'updated'); } catch (Exception $ex) { dd($ex); + return redirect()->back()->with('fails', $ex->getMessage()); } } - public function renderForm($formid) { - $html = ""; + public function renderForm($formid) + { + $html = ''; $forms = new Forms(); $form = $forms->find($formid); if ($form) { @@ -266,54 +279,58 @@ class FormController extends Controller { $html .= self::getForm($field); } } - return self::requiredStyle() . $html; + + return self::requiredStyle().$html; } - public static function getType($type) { + public static function getType($type) + { switch ($type) { - case "select": - return "select"; - case "text": - return "text"; - case "email": - return "email"; - case "textarea": - return "textarea"; - case "select": - return "select"; - case "radio": - return "radio"; - case "checkbox": - return "checkbox"; - case "hidden": - return "hidden"; - case "password": - return "password"; + case 'select': + return 'select'; + case 'text': + return 'text'; + case 'email': + return 'email'; + case 'textarea': + return 'textarea'; + case 'select': + return 'select'; + case 'radio': + return 'radio'; + case 'checkbox': + return 'checkbox'; + case 'hidden': + return 'hidden'; + case 'password': + return 'password'; } } - public static function getAttribute($type) { + public static function getAttribute($type) + { switch ($type) { - case "select": + case 'select': return "null,['class'=>'form-control']"; - case "text": + case 'text': return "['class'=>'form-control']"; - case "email": + case 'email': return "['class'=>'form-control']"; - case "textarea": + case 'textarea': return "['class'=>'form-control']"; - case "radio": - return ""; - case "checkbox": - return ""; - case "hidden": - return ""; - case "password": + case 'radio': + return ''; + case 'checkbox': + return ''; + case 'hidden': + return ''; + case 'password': return "['class'=>'form-control']"; } } - public static function getForm($field) { + public static function getForm($field) + { $required = false; $required_class = self::requiredClass($field->required); if ($field->required === '1') { @@ -322,32 +339,33 @@ class FormController extends Controller { $type = $field->type; $field_type = self::getType($type); switch ($field_type) { - case "select": + case 'select': return self::selectForm($field_type, $field, $required, $required_class); - case "text": - return Form::label($field->label, $field->label, ['class' => $required_class]) . - Form::$field_type($field->name, NULL, ['class' => "form-control $field->id", 'id' => $field->id, 'required' => $required]); - case "email": - return Form::label($field->label, $field->label, ['class' => $required_class]) . - Form::$field_type($field->name, NULL, ['class' => "form-control $field->id", 'id' => $field->id, 'required' => $required]); - case "password": - return Form::label($field->label, $field->label, ['class' => $required_class]) . + case 'text': + return Form::label($field->label, $field->label, ['class' => $required_class]). + Form::$field_type($field->name, null, ['class' => "form-control $field->id", 'id' => $field->id, 'required' => $required]); + case 'email': + return Form::label($field->label, $field->label, ['class' => $required_class]). + Form::$field_type($field->name, null, ['class' => "form-control $field->id", 'id' => $field->id, 'required' => $required]); + case 'password': + return Form::label($field->label, $field->label, ['class' => $required_class]). Form::$field_type($field->name, ['class' => "form-control $field->id", 'id' => $field->id, 'required' => $required]); - case "textarea": - return Form::label($field->label, $field->label, ['class' => $required_class]) . - Form::$field_type($field->name, NULL, ['class' => "form-control $field->id", 'id' => $field->id, 'required' => $required]); - case "radio": + case 'textarea': + return Form::label($field->label, $field->label, ['class' => $required_class]). + Form::$field_type($field->name, null, ['class' => "form-control $field->id", 'id' => $field->id, 'required' => $required]); + case 'radio': return self::radioForm($field_type, $field, $required, $required_class); - case "checkbox": + case 'checkbox': return self::checkboxForm($field_type, $field, $required, $required_class); - case "hidden": - return Form::$field_type($field->name, NULL, ['id' => $field->id]); + case 'hidden': + return Form::$field_type($field->name, null, ['id' => $field->id]); } } - public function createValues($fieldid, $values, $childid = NULL, $key = "") { + public function createValues($fieldid, $values, $childid = null, $key = '') + { if ($values) { $values_array = explode(',', $values); $field_values = new \App\Model\helpdesk\Form\FieldValue(); @@ -360,9 +378,9 @@ class FormController extends Controller { if (count($values_array) > 0) { foreach ($values_array as $value) { $field_values->create([ - 'field_id' => $fieldid, - 'child_id' => $childid, - 'field_key' => $key, + 'field_id' => $fieldid, + 'child_id' => $childid, + 'field_key' => $key, 'field_value' => str_slug($value, '_'), ]); } @@ -370,7 +388,8 @@ class FormController extends Controller { } } - public function addChild($fieldid, Request $request) { + public function addChild($fieldid, Request $request) + { $ids = $request->except('_token'); try { foreach ($ids as $valueid => $formid) { @@ -384,86 +403,91 @@ class FormController extends Controller { //} } } + return redirect()->back()->with('success', 'Updated'); } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } - public function renderChild(Request $request) { + public function renderChild(Request $request) + { self::setSession(); - $render = ""; + $render = ''; $value = $request->input('valueid'); $fieldid = $request->input('fieldid'); $field_values = new \App\Model\helpdesk\Form\FieldValue(); $field_value = $field_values->where('field_id', $fieldid)->where('field_value', $value)->first(); - $child = ""; + $child = ''; if ($field_value) { $child = $field_value->child_id; } - if ($child !== "") { + if ($child !== '') { $render = $this->renderForm($child); } return $render; } - public static function jqueryScript($value, $fieldid, $fieldname, $type = "", $index = "") { - if ($type == "select") { + public static function jqueryScript($value, $fieldid, $fieldname, $type = '', $index = '') + { + if ($type == 'select') { return self::jquerySelectScript($fieldid); } - if ($type == "checkbox") { + if ($type == 'checkbox') { return self::jqueryCheckboxScript($fieldid, $index); } + return ''; } - public static function jqueryCheckboxScript($fieldid, $index) { + public static function jqueryCheckboxScript($fieldid, $index) + { $session = self::getSession(); $fields = new Fields(); $field = $fields->find($fieldid); if ($field) { return '"; } - public function getTooltip(Request $request) { + public function getTooltip(Request $request) + { $ticketid = $request->input('ticketid'); $ticket = Tickets::find($ticketid); $firstThread = $ticket->thread()->select('user_id', 'poster', 'body')->first(); $lastThread = $ticket->thread()->select('user_id', 'poster', 'body')->orderBy('id', 'desc')->first(); - return "" . $firstThread->user->user_name . " (" . $firstThread->poster . ")
    " - . $firstThread->purify() . "

    " - . "" . $lastThread->user->user_name . "(" . $lastThread->poster . ")" - . $lastThread->purify() . "

    "; + + return ''.$firstThread->user->user_name.' ('.$firstThread->poster.')
    ' + .$firstThread->purify().'

    ' + .''.$lastThread->user->user_name.'('.$lastThread->poster.')' + .$lastThread->purify().'

    '; } //Auto-close tickets - public function autoCloseTickets() { + public function autoCloseTickets() + { $workflow = \App\Model\helpdesk\Workflow\WorkflowClose::whereId(1)->first(); if ($workflow->condition == 1) { @@ -2499,7 +2606,7 @@ class TicketController extends Controller { // $sla_plan = Sla_plan::where('id', '=', $overdue->sla)->first(); $ovadate = $overdue->created_at; - $new_date = date_add($ovadate, date_interval_create_from_date_string($workflow->days . ' days')) . '

    '; + $new_date = date_add($ovadate, date_interval_create_from_date_string($workflow->days.' days')).'

    '; if (date('Y-m-d H:i:s') > $new_date) { $i++; $overdue->status = 3; @@ -2519,20 +2626,22 @@ class TicketController extends Controller { // } } } else { - } } /** * @category function to chech if user verifcaition required for creating tickets or not + * * @param null + * * @return int 0/1 */ - public function checkUserVerificationStatus() { + public function checkUserVerificationStatus() + { $status = CommonSettings::select('status') ->where('option_name', '=', 'send_otp') ->first(); - if ($status->status == 0 || $status->status == "0") { + if ($status->status == 0 || $status->status == '0') { return 1; } else { return 0; @@ -2540,14 +2649,17 @@ class TicketController extends Controller { } /** - * This function is used for auto filling in new ticket + * This function is used for auto filling in new ticket. + * * @return type view */ - public function autofill() { + public function autofill() + { return view('themes.default1.agent.helpdesk.ticket.getautocomplete'); } - public function pdfThread($threadid) { + public function pdfThread($threadid) + { try { $threads = new Ticket_Thread(); $thread = $threads->leftJoin('tickets', 'ticket_thread.ticket_id', '=', 'tickets.id') @@ -2563,64 +2675,80 @@ class TicketController extends Controller { $ticket = Tickets::where('id', $thread->ticket_id)->first(); $html = view('themes.default1.agent.helpdesk.ticket.thread-pdf', compact('thread', 'system', 'company', 'ticket'))->render(); $html1 = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); + return PDF::load($html1)->show(); } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } - public static function getSourceByname($name) { + public static function getSourceByname($name) + { $sources = new Ticket_source(); $source = $sources->where('name', $name)->first(); + return $source; } - public static function getSourceById($sourceid) { + public static function getSourceById($sourceid) + { $sources = new Ticket_source(); $source = $sources->where('id', $sourceid)->first(); + return $source; } - public static function getSourceCssClass($sourceid) { - $css = "fa fa-comment"; + public static function getSourceCssClass($sourceid) + { + $css = 'fa fa-comment'; $source = self::getSourceById($sourceid); if ($source) { $css = $source->css_class; } + return $css; } - public function getSystemDefaultHelpTopic() { + public function getSystemDefaultHelpTopic() + { $ticket_settings = new \App\Model\helpdesk\Settings\Ticket(); $ticket_setting = $ticket_settings->find(1); $help_topicid = $ticket_setting->help_topic; + return $help_topicid; } - public function getSystemDefaultSla() { + public function getSystemDefaultSla() + { $ticket_settings = new \App\Model\helpdesk\Settings\Ticket(); $ticket_setting = $ticket_settings->find(1); $sla = $ticket_setting->sla; + return $sla; } - public function getSystemDefaultPriority() { + public function getSystemDefaultPriority() + { $ticket_settings = new \App\Model\helpdesk\Settings\Ticket(); $ticket_setting = $ticket_settings->find(1); $priority = $ticket_setting->priority; + return $priority; } - public function getSystemDefaultDepartment() { + public function getSystemDefaultDepartment() + { $systems = new \App\Model\helpdesk\Settings\System(); $system = $systems->find(1); $department = $system->department; + return $department; } - public function findTicketFromTicketCreateUser($result = []) { + public function findTicketFromTicketCreateUser($result = []) + { $ticket_number = $this->checkArray('0', $result); - if ($ticket_number !== "") { + if ($ticket_number !== '') { $tickets = new \App\Model\helpdesk\Ticket\Tickets(); $ticket = $tickets->where('ticket_number', $ticket_number)->first(); if ($ticket) { @@ -2629,29 +2757,36 @@ class TicketController extends Controller { } } - public function findUserFromTicketCreateUserId($result = []) { + public function findUserFromTicketCreateUserId($result = []) + { $ticket = $this->findTicketFromTicketCreateUser($result); if ($ticket) { $userid = $ticket->user_id; + return $userid; } } - public function checkArray($key, $array) { - $value = ""; + public function checkArray($key, $array) + { + $value = ''; if (array_key_exists($key, $array)) { $value = $array[$key]; } + return $value; } - public function getAdmin() { + public function getAdmin() + { $users = new \App\User(); $admin = $users->where('role', 'admin')->first(); + return $admin; } - public function attachmentSeperateOld($attach) { + public function attachmentSeperateOld($attach) + { $attacment = []; if ($attach != null) { $size = count($attach); @@ -2664,10 +2799,12 @@ class TicketController extends Controller { $attacment[$i]['mime'] = $mime; } } + return $attacment; } - public function attachmentSeperate($thread_id) { + public function attachmentSeperate($thread_id) + { if ($thread_id) { $array = []; $attachment = new Ticket_attachments(); @@ -2679,77 +2816,84 @@ class TicketController extends Controller { $array[$key]['mime'] = $attach->type; $array[$key]['mode'] = 'data'; } + return $array; } } } /** - * * @return type */ - public function followupTicketList() { + public function followupTicketList() + { try { $table = \Datatable::table() ->addColumn( - "", Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) + '', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) ->noScript(); + return view('themes.default1.agent.helpdesk.followup.followup', compact('table')); } catch (Exception $e) { return Redirect()->back()->with('fails', $e->getMessage()); } } - public static function getSubject($subject) { + public static function getSubject($subject) + { //$subject = $this->attributes['title']; $array = imap_mime_header_decode($subject); - $title = ""; + $title = ''; if (is_array($array) && count($array) > 0) { foreach ($array as $text) { $title .= $text->text; } + return wordwrap($title, 70, "
    \n"); } + return wordwrap($subject, 70, "
    \n"); } - public function replyContent($content) { + public function replyContent($content) + { preg_match_all('/]+>/i', $content, $result); $url = []; $encode = []; - $img = array(); + $img = []; foreach ($result as $key=>$img_tag) { //dd($img_tag); preg_match_all('/(src)=("[^"]*")/i', $img_tag[$key], $img[$key]); } - for($i=0;$idivideUrl($img[$i][2][0]); } - + return str_replace($url, $encode, $content); - - } - - - public function divideUrl($url){ - $baseurl = url('/'); - $trim = str_replace($baseurl,"",$url); - $trim = str_replace('"','',$trim); - $trim = substr_replace($trim,"",0,1); - $path = public_path($trim); - return $this->fileContent($path); - } - - public function fileContent($path){ - $exist = \File::exists($path); - $base64 = ""; - if($exist){ - $content = \File::get($path); - $type = \File::extension($path); - $base64 = 'data:image/' . $type . ';base64,' . base64_encode($content); - } - return $base64; } + public function divideUrl($url) + { + $baseurl = url('/'); + $trim = str_replace($baseurl, '', $url); + $trim = str_replace('"', '', $trim); + $trim = substr_replace($trim, '', 0, 1); + $path = public_path($trim); + + return $this->fileContent($path); + } + + public function fileContent($path) + { + $exist = \File::exists($path); + $base64 = ''; + if ($exist) { + $content = \File::get($path); + $type = \File::extension($path); + $base64 = 'data:image/'.$type.';base64,'.base64_encode($content); + } + + return $base64; + } } diff --git a/app/Http/Controllers/Agent/helpdesk/TicketWorkflowController.php b/app/Http/Controllers/Agent/helpdesk/TicketWorkflowController.php index fe6c1ae85..0e7ab2eb8 100644 --- a/app/Http/Controllers/Agent/helpdesk/TicketWorkflowController.php +++ b/app/Http/Controllers/Agent/helpdesk/TicketWorkflowController.php @@ -166,7 +166,7 @@ class TicketWorkflowController extends Controller } } } - + //dd($form_data); if ($ticket_settings_details['reject'] == true) { return ['0' => false, '1' => false]; @@ -287,7 +287,7 @@ class TicketWorkflowController extends Controller */ public function checkStarts($statement, $to_check) { - if (substr($to_check, 0, strlen($statement)) == $statement) { + if (substr($to_check, 0, strlen($statement)) == $statement) { return true; } else { return false; @@ -305,7 +305,7 @@ class TicketWorkflowController extends Controller public function checkEnds($statement, $to_check) { $to_check = strip_tags($to_check); - if (substr($to_check, -strlen($statement)) == $statement) { + if (substr($to_check, -strlen($statement)) == $statement) { return true; } else { return false; @@ -352,6 +352,7 @@ class TicketWorkflowController extends Controller $ticket_settings_details = $this->changeStatus($workflow_action, $ticket_settings_details); } } + return $ticket_settings_details; } diff --git a/app/Http/Controllers/Agent/helpdesk/UserController.php b/app/Http/Controllers/Agent/helpdesk/UserController.php index b98e5fe07..9ba440655 100644 --- a/app/Http/Controllers/Agent/helpdesk/UserController.php +++ b/app/Http/Controllers/Agent/helpdesk/UserController.php @@ -3,49 +3,44 @@ namespace App\Http\Controllers\Agent\helpdesk; // controllers -use App\Http\Controllers\Controller; use App\Http\Controllers\Common\PhpMailController; +use App\Http\Controllers\Controller; // requests /* Include Sys_user Model */ -use App\Http\Requests\helpdesk\ProfilePassword; -/* For validation include Sys_userRequest in create */ -use App\Http\Requests\helpdesk\ProfileRequest; -/* For validation include Sys_userUpdate in update */ -use App\Http\Requests\helpdesk\Sys_userRequest; -/* include guest_note model */ -use App\Http\Requests\helpdesk\Sys_userUpdate; -use App\Http\Requests\helpdesk\OtpVerifyRequest; -// change password request use App\Http\Requests\helpdesk\ChangepasswordRequest; +/* For validation include Sys_userRequest in create */ +use App\Http\Requests\helpdesk\OtpVerifyRequest; +/* For validation include Sys_userUpdate in update */ +use App\Http\Requests\helpdesk\ProfilePassword; +/* include guest_note model */ +use App\Http\Requests\helpdesk\ProfileRequest; +use App\Http\Requests\helpdesk\Sys_userRequest; +// change password request +use App\Http\Requests\helpdesk\Sys_userUpdate; // models +use App\Model\helpdesk\Agent\Assign_team_agent; use App\Model\helpdesk\Agent_panel\Organization; use App\Model\helpdesk\Agent_panel\User_org; +use App\Model\helpdesk\Notification\Notification; +use App\Model\helpdesk\Notification\UserNotification; use App\Model\helpdesk\Settings\CommonSettings; +use App\Model\helpdesk\Settings\Email; +use App\Model\helpdesk\Ticket\Ticket_Thread; +use App\Model\helpdesk\Ticket\Tickets; use App\Model\helpdesk\Utility\CountryCode; use App\Model\helpdesk\Utility\Otp; -use App\Model\helpdesk\Email\Emails; -use App\Model\helpdesk\Settings\Email; -use App\Model\helpdesk\Ticket\Tickets; -use App\Model\helpdesk\Agent\Assign_team_agent; -use App\Model\helpdesk\Ticket\Ticket_Thread; -use App\Model\helpdesk\Notification\UserNotification; -use App\Model\helpdesk\Notification\Notification; -use App\Model\helpdesk\Ticket\Ticket_Collaborator; -use App\Model\helpdesk\Agent\Teams; -use App\Model\helpdesk\Ticket\Ticket_attachments; - use App\User; // classes use Auth; +use DateTime; +use DB; use Exception; use GeoIP; use Hash; +use Illuminate\Http\Request; use Input; use Lang; use Redirect; -use Illuminate\Http\Request; -use DateTime; -use DB; /** * UserController @@ -53,8 +48,8 @@ use DB; * * @author Ladybird */ -class UserController extends Controller { - +class UserController extends Controller +{ /** * Create a new controller instance. * constructor to check @@ -64,7 +59,8 @@ class UserController extends Controller { * * @return void */ - public function __construct(PhpMailController $PhpMailController) { + public function __construct(PhpMailController $PhpMailController) + { $this->PhpMailController = $PhpMailController; // checking authentication $this->middleware('auth'); @@ -79,7 +75,8 @@ class UserController extends Controller { * * @return type view */ - public function index() { + public function index() + { try { /* get all values in Sys_user */ @@ -93,13 +90,15 @@ class UserController extends Controller { Lang::get('lang.role'), Lang::get('lang.action')) // these are the column headings to be shown ->noScript(); - return view('themes.default1.agent.helpdesk.user.index',compact('table')); + + return view('themes.default1.agent.helpdesk.user.index', compact('table')); } catch (Exception $e) { return redirect()->back()->with('fails', $e->getMessage()); } } - public function deletedUser() { + public function deletedUser() + { try { // dd('here'); /* get all values in Sys_user */ @@ -109,30 +108,20 @@ class UserController extends Controller { } } - - /** * This function is used to display the list of users using chumper datatables. * * @return datatable */ - public function user_list(Request $request) { - - $type = $request->input('profiletype'); - -if($type=="active"){ - -$users=User::where('role', "!=", "admin")->where('is_delete','=',0)->get(); -} -else{ - $users=User::where('role', "!=", "admin")->where('is_delete','=',1)->get(); - -} - - - - + public function user_list(Request $request) + { + $type = $request->input('profiletype'); + if ($type == 'active') { + $users = User::where('role', '!=', 'admin')->where('is_delete', '=', 0)->get(); + } else { + $users = User::where('role', '!=', 'admin')->where('is_delete', '=', 1)->get(); + } // displaying list of users with chumper datatables // return \Datatable::collection(User::where('role', "!=", "admin")->get()) @@ -144,7 +133,7 @@ else{ /* column username */ ->addColumn('user_name', function ($model) { if ($model->first_name) { - $string = strip_tags($model->first_name . ' ' . $model->last_name); + $string = strip_tags($model->first_name.' '.$model->last_name); } else { $string = strip_tags($model->user_name); } @@ -154,11 +143,12 @@ else{ } else { $stringCut = $string; } - return "id) . "' title='".$string."''>".$stringCut.""; + + return "id)."' title='".$string."''>".$stringCut.''; }) /* column email */ ->addColumn('email', function ($model) { - $email = "id) . "'>" . $model->email . ''; + $email = "id)."'>".$model->email.''; return $email; }) @@ -166,13 +156,13 @@ else{ ->addColumn('phone', function ($model) { $phone = ''; if ($model->phone_number) { - $phone = $model->ext . ' ' . $model->phone_number; + $phone = $model->ext.' '.$model->phone_number; } $mobile = ''; if ($model->mobile) { $mobile = $model->mobile; } - $phone = $phone . '   ' . $mobile; + $phone = $phone.'   '.$mobile; return $phone; }) @@ -207,46 +197,42 @@ else{ /* column Role */ ->addColumn('role', function ($model) { $role = $model->role; + return $role; }) /* column actions */ ->addColumn('Actions', function ($model) { - if($model->is_delete==0){ - return '' . \Lang::get('lang.edit') . '  ' . \Lang::get('lang.view') . ''; + if ($model->is_delete == 0) { + return ''.\Lang::get('lang.edit').'  '.\Lang::get('lang.view').''; + } else { + if (Auth::user()->role == 'admin') { + // @if(Auth::user()->role == 'admin') + + return ''.\Lang::get('lang.view').''; + } + + if (Auth::user()->role == 'agent') { + // @if(Auth::user()->role == 'admin') + if ($model->role == 'user') { + return ''.\Lang::get('lang.view').''; + } + } } - else{ - - - if(Auth::user()->role == 'admin'){ - // @if(Auth::user()->role == 'admin') - - return '' . \Lang::get('lang.view') . ''; - } - - if(Auth::user()->role == 'agent'){ - // @if(Auth::user()->role == 'admin') - if($model->role=="user"){ - return '' . \Lang::get('lang.view') . ''; - } - } - - - } - }) ->make(); } - public function restoreUser($id) + public function restoreUser($id) { // dd($id); // $delete_all = Input::get('delete_all'); $users = User::where('id', '=', $id)->first(); - $users->is_delete=0; - $users->active=1; - $users->ban=0; + $users->is_delete = 0; + $users->active = 1; + $users->ban = 0; $users->save(); - return redirect('user')->with('success', Lang::get('lang.user_restore_successfully')); + + return redirect('user')->with('success', Lang::get('lang.user_restore_successfully')); } /** @@ -254,13 +240,15 @@ else{ * * @return type view */ - public function create(CountryCode $code) { + public function create(CountryCode $code) + { try { $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); $email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first(); $location = GeoIP::getLocation(); $phonecode = $code->where('iso', '=', $location->iso_code)->first(); $org = Organization::lists('name', 'id')->toArray(); + return view('themes.default1.agent.helpdesk.user.create', compact('org', 'settings', 'email_mandatory'))->with('phonecode', $phonecode->phonecode); } catch (Exception $e) { return redirect()->back()->with('fails', $e->errorInfo[2]); @@ -275,7 +263,8 @@ else{ * * @return type redirect */ - public function store(User $user, Sys_userRequest $request) { + public function store(User $user, Sys_userRequest $request) + { /* insert the input request to sys_user table */ /* Check whether function success or not */ if ($request->input('email') != '') { @@ -310,9 +299,9 @@ else{ } // save user credentails if ($user->save() == true) { - if ($request->input('org_id') != "") { + if ($request->input('org_id') != '') { $orgid = $request->input('org_id'); - $this->storeUserOrgRelation($user->id, $orgid); + $this->storeUserOrgRelation($user->id, $orgid); } // fetch user credentails to send mail $name = $user->first_name; @@ -332,6 +321,7 @@ else{ if (($request->input('active') == '0' || $request->input('active') == 0) || ($email_mandatory->status == '0') || $email_mandatory->status == 0) { \Event::fire(new \App\Events\LoginEvent($request)); } + return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully')); } // $user->save(); @@ -344,17 +334,18 @@ else{ } /** - * Random Password Genetor for users + * Random Password Genetor for users. * * @param type int $id * @param type User $user * * @return type view */ - public function randomPassword() { + public function randomPassword() + { try { $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*(){}[]'; - $pass = array(); //remember to declare $pass as an array + $pass = []; //remember to declare $pass as an array $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache for ($i = 0; $i < 10; $i++) { $n = rand(0, $alphaLength); @@ -369,14 +360,15 @@ else{ } /** - * Random Password Genetor for users + * Random Password Genetor for users. * * @param type int $id * @param type User $user * * @return type view */ - public function randomPostPassword($id, ChangepasswordRequest $request) { + public function randomPostPassword($id, ChangepasswordRequest $request) + { try { $changepassword = $request->change_password; $user = User::whereId($id)->first(); @@ -391,24 +383,25 @@ else{ return redirect('user')->with('success', Lang::get('lang.password_change_successfully')); } catch (Exception $e) { - return redirect('user')->with('fails', $e->getMessage()); } } /** - * - * @param type $id + * @param type $id * @param Request $request + * * @return type */ - public function changeRoleAdmin($id, Request $request) { + public function changeRoleAdmin($id, Request $request) + { try { $user = User::whereId($id)->first(); $user->role = 'admin'; $user->assign_group = $request->group; $user->primary_dpt = $request->primary_department; $user->save(); + return redirect('user')->with('success', Lang::get('lang.role_change_successfully')); } catch (Exception $e) { /* redirect to Index page with Fails Message */ @@ -417,14 +410,14 @@ else{ } /** - * - * @param type $id + * @param type $id * @param Request $request + * * @return type */ - public function changeRoleAgent($id, Request $request) { + public function changeRoleAgent($id, Request $request) + { try { - $user = User::whereId($id)->first(); $user->role = 'agent'; $user->assign_group = $request->group; @@ -439,22 +432,22 @@ else{ } /** - * * @param type $id + * * @return type */ - public function changeRoleUser($id) { + public function changeRoleUser($id) + { try { $ticket = Tickets::where('assigned_to', '=', $id)->where('status', '=', '1')->get(); if ($ticket) { - - $ticket = Tickets::where('assigned_to', '=', $id)->update(array("assigned_to" => NULL)); + $ticket = Tickets::where('assigned_to', '=', $id)->update(['assigned_to' => null]); } $user = User::whereId($id)->first(); $user->role = 'user'; - $user->assign_group = NULL; - $user->primary_dpt = NULL; - $user->remember_token = NULL; + $user->assign_group = null; + $user->primary_dpt = null; + $user->remember_token = null; $user->save(); return redirect('user')->with('success', Lang::get('lang.role_change_successfully')); @@ -466,32 +459,28 @@ else{ } /** - * * @param type $id + * * @return type */ public function deleteAgent($id) { // try { $delete_all = Input::get('delete_all'); - - $delete_all = Input::get('delete_all'); $users = User::where('id', '=', $id)->first(); - if ($users->role == 'user') { + if ($users->role == 'user') { + $users = User::where('id', '=', $id)->first(); + $users->is_delete = 1; + $users->active = 0; + $users->ban = 1; + $users->save(); - $users = User::where('id', '=', $id)->first(); - $users->is_delete=1; - $users->active=0; - $users->ban=1; - $users->save(); - - return redirect('user')->with('success', Lang::get('lang.user_delete_successfully')); - } + return redirect('user')->with('success', Lang::get('lang.user_delete_successfully')); + } // } - if ($users->role == 'agent') { if ($delete_all == null) { $UserEmail = Input::get('assign_to'); @@ -524,68 +513,62 @@ else{ // 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... + foreach ($tickets as $ticket) { + // code... $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; - $ticket->save(); - + $user_detail = User::where('id', '=', $assign_to[1])->first(); + $assignee = $user_detail->first_name.' '.$user_detail->last_name; + $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 assigned to ' . $assignee; - $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 assigned to '.$assignee; + $thread->save(); + } $user = User::find($id); - $users->is_delete=1; - $users->active=0; - $users->ban=1; + $users->is_delete = 1; + $users->active = 0; + $users->ban = 1; $users->save(); - return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully_and_ticket_assign_to_another_agent')); } - // if (User_org::where('user_id', '=', $id)) { // DB::table('user_assign_organization')->where('user_id', '=', $id)->delete(); // } $user = User::find($id); - $users->is_delete=1; - $users->active=0; - $users->ban=1; - $users->save(); + $users->is_delete = 1; + $users->active = 0; + $users->ban = 1; + $users->save(); return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully')); } elseif ($delete_all == 1) { - - if ($delete_all) { - // dd('here'); + 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(); - + 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; - $users->active=0; + $users->is_delete = 1; + $users->active = 0; $users->save(); return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully')); @@ -593,8 +576,8 @@ foreach ($tickets as $ticket ) { // Assign_team_agent::where('agent_id', '=', $id)->delete(); // User_org::where('user_id', '=', $id)->delete(); $user = User::find($id); - $users->is_delete=1; - $users->active=0; + $users->is_delete = 1; + $users->active = 0; $users->save(); return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully')); @@ -616,10 +599,11 @@ foreach ($tickets as $ticket ) { * * @return type view */ - public function show($id) { + public function show($id) + { try { - $users = User::where('id','=', $id)->first(); - if (count($users)>0) { + $users = User::where('id', '=', $id)->first(); + if (count($users) > 0) { return view('themes.default1.agent.helpdesk.user.show', compact('users')); } else { return redirect()->back()->with('fails', Lang::get('lang.user-not-found')); @@ -637,10 +621,10 @@ foreach ($tickets as $ticket ) { * * @return type Response */ - public function edit($id, CountryCode $code) { + public function edit($id, CountryCode $code) + { try { - // dd('here'); $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); $email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first(); @@ -652,12 +636,12 @@ foreach ($tickets as $ticket ) { $phonecode = $code->where('iso', '=', $location->iso_code)->first(); $orgs = Organization::all(); // dd($org); - $organization_id=User_org::where('user_id','=',$id)->lists('org_id')->first(); + $organization_id = User_org::where('user_id', '=', $id)->lists('org_id')->first(); // $org_name=Organization::where('id','=',$org_id)->lists('name')->first(); // dd($org_name); - return view('themes.default1.agent.helpdesk.user.edit', compact('users', 'orgs', '$settings', '$email_mandatory','organization_id'))->with('phonecode', $phonecode->phonecode); + return view('themes.default1.agent.helpdesk.user.edit', compact('users', 'orgs', '$settings', '$email_mandatory', 'organization_id'))->with('phonecode', $phonecode->phonecode); } catch (Exception $e) { return redirect()->back()->with('fails', $e->getMessage()); } @@ -672,8 +656,8 @@ foreach ($tickets as $ticket ) { * * @return type Response */ - public function update($id, Sys_userUpdate $request) { - + public function update($id, Sys_userUpdate $request) + { $user = new User(); /* select the field where id = $id(request Id) */ $users = $user->whereId($id)->first(); @@ -693,10 +677,10 @@ foreach ($tickets as $ticket ) { $users->mobile = ($request->input('mobile') == '') ? null : $request->input('mobile'); $users->fill($request->except('mobile')); $users->save(); - if ($request->input('org_id') != "") { + if ($request->input('org_id') != '') { $orgid = $request->input('org_id'); - - $this->storeUserOrgRelation($id, $orgid); + + $this->storeUserOrgRelation($id, $orgid); } /* redirect to Index page with Success Message */ return redirect('user')->with('success', Lang::get('lang.User-profile-Updated-Successfully')); @@ -711,7 +695,8 @@ foreach ($tickets as $ticket ) { * * @return type view */ - public function getProfile() { + public function getProfile() + { $user = Auth::user(); try { return view('themes.default1.agent.helpdesk.user.profile', compact('user')); @@ -725,7 +710,8 @@ foreach ($tickets as $ticket ) { * * @return type view */ - public function getProfileedit(CountryCode $code) { + public function getProfileedit(CountryCode $code) + { $user = Auth::user(); $location = GeoIP::getLocation(); $phonecode = $code->where('iso', '=', $location->iso_code)->first(); @@ -734,7 +720,7 @@ foreach ($tickets as $ticket ) { try { return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user')) ->with(['phonecode' => $phonecode->phonecode, - 'verify' => $status]); + 'verify' => $status, ]); } catch (Exception $e) { return redirect()->back()->with('fails', $e->getMessage()); } @@ -748,7 +734,8 @@ foreach ($tickets as $ticket ) { * * @return type Redirect */ - public function postProfileedit(ProfileRequest $request) { + public function postProfileedit(ProfileRequest $request) + { try { // geet authenticated user details $user = Auth::user(); @@ -758,14 +745,14 @@ foreach ($tickets as $ticket ) { $code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get(); if (!count($code)) { return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput(); - } + } $user->country_code = $request->country_code; } $user->fill($request->except('profile_pic', 'mobile')); $user->gender = $request->input('gender'); $user->save(); if (Input::file('profile_pic')) { - // fetching picture name + // fetching picture name $name = Input::file('profile_pic')->getClientOriginalName(); // fetching upload destination path $destinationPath = 'uploads/profilepic'; @@ -782,11 +769,10 @@ foreach ($tickets as $ticket ) { $user->mobile = null; } if ($user->save()) { - return Redirect::route('profile')->with('success', Lang::get('lang.Profile-Updated-sucessfully')); + return Redirect::route('profile')->with('success', Lang::get('lang.Profile-Updated-sucessfully')); } else { return Redirect::route('profile')->with('fails', Lang::get('lang.Profile-Updated-sucessfully')); } - } catch (Exception $e) { return Redirect::route('profile')->with('fails', $e->getMessage()); } @@ -826,49 +812,50 @@ foreach ($tickets as $ticket ) { * * @return type boolean */ - public function UserAssignOrg($id) { + public function UserAssignOrg($id) + { $org_name = Input::get('org'); - -if ($org_name) { - $org = Organization::where('name', '=', $org_name)->lists('id')->first(); - if ($org) { - $user_org = new User_org(); - $user_org->org_id = $org; - $user_org->user_id = $id; - $user_org->save(); + if ($org_name) { + $org = Organization::where('name', '=', $org_name)->lists('id')->first(); + if ($org) { + $user_org = new User_org(); + $user_org->org_id = $org; + $user_org->user_id = $id; + $user_org->save(); - return 1; - } else { - return 0; + return 1; + } else { + return 0; } - } else { - return 2; + } else { + return 2; } - } + } - public function UsereditAssignOrg($id) - { - $org_name = Input::get('org'); - - if ($org_name) { - $org = Organization::where('name', '=', $org_name)->lists('id')->first(); - if ($org) { - $user_org = User_org::where('user_id', '=', $id)->first(); - $user_org->org_id = $org; - $user_org->user_id = $id; - $user_org->save(); + public function UsereditAssignOrg($id) + { + $org_name = Input::get('org'); - return 1; - } else { - return 0; + if ($org_name) { + $org = Organization::where('name', '=', $org_name)->lists('id')->first(); + if ($org) { + $user_org = User_org::where('user_id', '=', $id)->first(); + $user_org->org_id = $org; + $user_org->user_id = $id; + $user_org->save(); + + return 1; + } else { + return 0; } - } else { - return 2; + } else { + return 2; } - } + } - public function orgAssignUser($id) { + public function orgAssignUser($id) + { $org = Input::get('org'); $user_org = new User_org(); $user_org->org_id = $id; @@ -878,7 +865,8 @@ if ($org_name) { return 1; } - public function removeUserOrg($id) { + public function removeUserOrg($id) + { $user_org = User_org::where('org_id', '=', $id)->first(); $user_org->delete(); @@ -892,7 +880,8 @@ if ($org_name) { * * @return type */ - public function User_Create_Org($id) { + public function User_Create_Org($id) + { // checking if the entered value for website is available in database if (Input::get('website') != null) { // checking website @@ -935,7 +924,8 @@ if ($org_name) { * * @return string */ - public function generateRandomString($length = 10) { + public function generateRandomString($length = 10) + { // list of supported characters $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; // character length checked @@ -950,7 +940,8 @@ if ($org_name) { return $randomString; } - public function storeUserOrgRelation($userid, $orgid) { + public function storeUserOrgRelation($userid, $orgid) + { $org_relations = new User_org(); $org_relation = $org_relations->where('user_id', $userid)->first(); if ($org_relation) { @@ -958,11 +949,12 @@ if ($org_name) { } $org_relations->create([ 'user_id' => $userid, - 'org_id' => $orgid, + 'org_id' => $orgid, ]); } - public function getExportUser() { + public function getExportUser() + { try { return view('themes.default1.agent.helpdesk.user.export'); } catch (Exception $ex) { @@ -970,30 +962,34 @@ if ($org_name) { } } - public function exportUser(Request $request) { + public function exportUser(Request $request) + { try { $date = $request->input('date'); $date = str_replace(' ', '', $date); $date_array = explode(':', $date); - $first = $date_array[0] . " 00:00:00"; - $second = $date_array[1] . " 23:59:59"; + $first = $date_array[0].' 00:00:00'; + $second = $date_array[1].' 23:59:59'; $first_date = $this->convertDate($first); $second_date = $this->convertDate($second); $users = $this->getUsers($first_date, $second_date); $excel_controller = new \App\Http\Controllers\Common\ExcelController(); - $filename = "users" . $date; + $filename = 'users'.$date; $excel_controller->export($filename, $users); } catch (Exception $ex) { return redirect()->back()->with('fails', $ex->getMessage()); } } - public function convertDate($date) { + public function convertDate($date) + { $converted_date = date('Y-m-d H:i:s', strtotime($date)); + return $converted_date; } - public function getUsers($first, $last) { + public function getUsers($first, $last) + { $user = new User(); $users = $user->leftJoin('user_assign_organization', 'users.id', '=', 'user_assign_organization.user_id') ->leftJoin('organization', 'user_assign_organization.org_id', '=', 'organization.id') @@ -1003,37 +999,42 @@ if ($org_name) { ->select('users.user_name as Username', 'users.email as Email', 'users.first_name as Fisrtname', 'users.last_name as Lastname', 'organization.name as Organization') ->get() ->toArray(); + return $users; } - public function resendOTP(OtpVerifyRequest $request) { + public function resendOTP(OtpVerifyRequest $request) + { if (\Schema::hasTable('sms')) { $sms = DB::table('sms')->get(); if (count($sms) > 0) { \Event::fire(new \App\Events\LoginEvent($request)); + return 1; } } else { - return "Plugin has not been setup successfully."; + return 'Plugin has not been setup successfully.'; } } - public function verifyOTP() { + public function verifyOTP() + { // dd(Input::all()); // $user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email'))->first(); $otp = Otp::select('otp', 'updated_at')->where('user_id', '=', Input::get('u_id')) ->first(); if ($otp != null) { $otp_length = strlen(Input::get('otp')); - if (($otp_length == 6 && !preg_match("/[a-z]/i", Input::get('otp')))) { + if (($otp_length == 6 && !preg_match('/[a-z]/i', Input::get('otp')))) { $otp2 = Hash::make(Input::get('otp')); - $date1 = date_format($otp->updated_at, "Y-m-d h:i:sa"); - $date2 = date("Y-m-d h:i:sa"); + $date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa'); + $date2 = date('Y-m-d h:i:sa'); $time1 = new DateTime($date2); $time2 = new DateTime($date1); $interval = $time1->diff($time2); if ($interval->i > 10 || $interval->h > 0) { $message = Lang::get('lang.otp-expired'); + return $message; } else { if (Hash::check(Input::get('otp'), $otp->otp)) { @@ -1045,26 +1046,27 @@ if ($org_name) { return 1; } else { $message = Lang::get('lang.otp-not-matched'); + return $message; } } } else { $message = Lang::get('lang.otp-invalid'); + return $message; } } else { $message = Lang::get('lang.otp-not-matched'); + return $message; } } - /** - */ public function getAgentDetails() { $users = User::where('role', '<>', 'user')->where('active', '=', 1)->get(); foreach ($users as $user) { - echo "'; + echo "'; } } } diff --git a/app/Http/Controllers/Agent/kb/ArticleController.php b/app/Http/Controllers/Agent/kb/ArticleController.php index d718c2c55..cc61d8b74 100644 --- a/app/Http/Controllers/Agent/kb/ArticleController.php +++ b/app/Http/Controllers/Agent/kb/ArticleController.php @@ -65,7 +65,7 @@ class ArticleController extends Controller $article = new Article(); $articles = $article ->select('id', 'name', 'description', 'publish_time', 'slug') - ->orderBy('publish_time','desc') + ->orderBy('publish_time', 'desc') ->get(); // returns chumper datatable return Datatable::Collection($articles) diff --git a/app/Http/Controllers/Agent/kb/CategoryController.php b/app/Http/Controllers/Agent/kb/CategoryController.php index ca426d87f..87f54e767 100644 --- a/app/Http/Controllers/Agent/kb/CategoryController.php +++ b/app/Http/Controllers/Agent/kb/CategoryController.php @@ -77,6 +77,7 @@ class CategoryController extends Controller /* add column name */ ->addColumn('name', function ($model) { $string = strip_tags($model->name); + return str_limit($string, 20); }) /* add column Created */ @@ -120,7 +121,7 @@ class CategoryController extends Controller public function create(Category $category) { /* Get the all attributes in the category model */ - $category = $category->lists('name','id')->toArray(); + $category = $category->lists('name', 'id')->toArray(); /* get the view page to create new category with all attributes of category model */ try { @@ -147,6 +148,7 @@ class CategoryController extends Controller // send success message to index page try { $category->fill($request->input())->save(); + return Redirect::back()->with('success', Lang::get('lang.category_inserted_successfully')); } catch (Exception $e) { return Redirect::back()->with('fails', Lang::get('lang.category_not_inserted').'
  • '.$e->getMessage().'
  • '); @@ -165,9 +167,9 @@ class CategoryController extends Controller { /* get the atributes of the category model whose id == $id */ $category = Category::whereId($id)->first(); - $categories = Category::lists('name','id')->toArray(); + $categories = Category::lists('name', 'id')->toArray(); /* get the Edit page the selected category via id */ - return view('themes.default1.agent.kb.category.edit', compact('category','categories')); + return view('themes.default1.agent.kb.category.edit', compact('category', 'categories')); } /** @@ -191,6 +193,7 @@ class CategoryController extends Controller try { $category->slug = $slug; $category->fill($request->input())->save(); + return redirect('category')->with('success', Lang::get('lang.category_updated_successfully')); } catch (Exception $e) { //redirect to index with fails message diff --git a/app/Http/Controllers/Agent/kb/SettingsController.php b/app/Http/Controllers/Agent/kb/SettingsController.php index 4e7c2d9ef..4293949cf 100644 --- a/app/Http/Controllers/Agent/kb/SettingsController.php +++ b/app/Http/Controllers/Agent/kb/SettingsController.php @@ -144,11 +144,13 @@ class SettingsController extends Controller $name = "

    $model->name


    "; $email = "

    $model->email


    "; $website = "

    $model->website


    "; + return $name.$email.$website; }) - + ->addColumn('comment', function ($model) { - $created = TicketController::usertimezone(date($model->created_at)); + $created = TicketController::usertimezone(date($model->created_at)); + return $model->comment."

    $created

    "; }) ->addColumn('status', function ($model) { @@ -159,7 +161,7 @@ class SettingsController extends Controller return '

    '.\Lang::get('lang.not_published'); } }) - + ->addColumn('Actions', function ($model) { return '

    '; }) diff --git a/app/Http/Controllers/Api/v1/ApiController.php b/app/Http/Controllers/Api/v1/ApiController.php index 949693d2d..6878c510c 100644 --- a/app/Http/Controllers/Api/v1/ApiController.php +++ b/app/Http/Controllers/Api/v1/ApiController.php @@ -2,9 +2,10 @@ namespace App\Http\Controllers\Api\v1; +use App\Http\Controllers\Agent\helpdesk\TicketController as CoreTicketController; use App\Http\Controllers\Controller; -use App\Http\Requests\helpdesk\TicketRequest; //use Illuminate\Support\Facades\Request as Value; +use App\Http\Requests\helpdesk\TicketRequest; use App\Model\helpdesk\Agent\Department; use App\Model\helpdesk\Agent\Teams; use App\Model\helpdesk\Manage\Help_topic; @@ -20,7 +21,6 @@ use Exception; use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; -use App\Http\Controllers\Agent\helpdesk\TicketController as CoreTicketController; /** * ----------------------------------------------------------------------------- @@ -34,8 +34,8 @@ use App\Http\Controllers\Agent\helpdesk\TicketController as CoreTicketController * * @version v1 */ -class ApiController extends Controller { - +class ApiController extends Controller +{ public $user; public $request; public $ticket; @@ -55,7 +55,8 @@ class ApiController extends Controller { /** * @param Request $request */ - public function __construct(Request $request) { + public function __construct(Request $request) + { $this->request = $request; $this->middleware('jwt.auth'); @@ -64,9 +65,7 @@ class ApiController extends Controller { $user = \JWTAuth::parseToken()->authenticate(); $this->user = $user; } catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) { - } catch (\Tymon\JWTAuth\Exceptions\JWTException $e) { - } $ticket = new TicketController(); @@ -121,7 +120,8 @@ class ApiController extends Controller { * * @return json */ - public function createTicket(\App\Http\Requests\helpdesk\CreateTicketRequest $request, \App\Model\helpdesk\Utility\CountryCode $code) { + public function createTicket(\App\Http\Requests\helpdesk\CreateTicketRequest $request, \App\Model\helpdesk\Utility\CountryCode $code) + { try { $user_id = $this->request->input('user_id'); @@ -148,7 +148,7 @@ class ApiController extends Controller { $PhpMailController = new \App\Http\Controllers\Common\PhpMailController(); $NotificationController = new \App\Http\Controllers\Common\NotificationController(); $core = new CoreTicketController($PhpMailController, $NotificationController); - $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; /* @@ -179,11 +179,12 @@ class ApiController extends Controller { * * @return json */ - public function ticketReply() { + public function ticketReply() + { //dd($this->request->all()); try { $v = \Validator::make($this->request->all(), [ - 'ticket_ID' => 'required|exists:tickets,id', + 'ticket_ID' => 'required|exists:tickets,id', 'reply_content' => 'required', ]); if ($v->fails()) { @@ -193,9 +194,10 @@ class ApiController extends Controller { } $attach = $this->request->input('attachments'); $result = $this->ticket->reply($this->thread, $this->request, $this->attach, $attach); - $result = $result->join('users','ticket_thread.user_id','=','users.id') - ->select('ticket_thread.*','users.first_name as first_name') + $result = $result->join('users', 'ticket_thread.user_id', '=', 'users.id') + ->select('ticket_thread.*', 'users.first_name as first_name') ->first(); + return response()->json(compact('result')); } catch (\Exception $e) { $error = $e->getMessage(); @@ -215,14 +217,15 @@ class ApiController extends Controller { * * @return json */ - public function editTicket() { + public function editTicket() + { try { $v = \Validator::make($this->request->all(), [ - 'ticket_id' => 'required|exists:tickets,id', - 'subject' => 'required', - 'sla_plan' => 'required|exists:sla_plan,id', - 'help_topic' => 'required|exists:help_topic,id', - 'ticket_source' => 'required|exists:ticket_source,id', + 'ticket_id' => 'required|exists:tickets,id', + 'subject' => 'required', + 'sla_plan' => 'required|exists:sla_plan,id', + 'help_topic' => 'required|exists:help_topic,id', + 'ticket_source' => 'required|exists:ticket_source,id', 'ticket_priority' => 'required|exists:ticket_priority,priority_id', ]); if ($v->fails()) { @@ -252,7 +255,8 @@ class ApiController extends Controller { * * @return json */ - public function deleteTicket() { + public function deleteTicket() + { try { $v = \Validator::make($this->request->all(), [ 'ticket_id' => 'required|exists:tickets,id', @@ -285,15 +289,16 @@ class ApiController extends Controller { * * @return json */ - public function openedTickets() { + public function openedTickets() + { 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') + $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') @@ -329,16 +334,17 @@ class ApiController extends Controller { * * @return json */ - public function unassignedTickets() { + public function unassignedTickets() + { 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') + $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') @@ -349,7 +355,7 @@ class ApiController extends Controller { ->whereNotNull('title'); }) ->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name') - ->where(function($query) use($user) { + ->where(function ($query) use ($user) { if ($user->role != 'admin') { $query->where('tickets.dept_id', '=', $user->primary_dpt); } @@ -379,15 +385,16 @@ class ApiController extends Controller { * * @return json */ - public function closeTickets() { + public function closeTickets() + { 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') + $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') @@ -398,7 +405,7 @@ class ApiController extends Controller { ->whereNotNull('title'); }) ->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name') - ->where(function($query) use($user) { + ->where(function ($query) use ($user) { if ($user->role != 'admin') { $query->where('tickets.dept_id', '=', $user->primary_dpt); } @@ -428,7 +435,8 @@ class ApiController extends Controller { * * @return json */ - public function getAgents() { + public function getAgents() + { try { $result = $this->faveoUser->where('role', 'agent')->orWhere('role', 'admin')->where('active', 1)->get(); @@ -451,7 +459,8 @@ class ApiController extends Controller { * * @return json */ - public function getTeams() { + public function getTeams() + { try { $result = $this->team->get(); @@ -474,11 +483,12 @@ class ApiController extends Controller { * * @return json */ - public function assignTicket() { + public function assignTicket() + { try { $v = \Validator::make($this->request->all(), [ 'ticket_id' => 'required', - 'user' => 'required', + 'user' => 'required', ]); if ($v->fails()) { $error = $v->errors(); @@ -512,7 +522,8 @@ class ApiController extends Controller { * * @return json */ - public function getCustomers() { + public function getCustomers() + { try { $v = \Validator::make($this->request->all(), [ 'search' => 'required', @@ -523,7 +534,7 @@ class ApiController extends Controller { 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'); @@ -546,7 +557,8 @@ class ApiController extends Controller { * * @return json */ - public function getCustomersWith() { + public function getCustomersWith() + { try { $users = $this->user ->leftJoin('user_assign_organization', 'user_assign_organization.user_id', '=', 'users.id') @@ -577,7 +589,8 @@ class ApiController extends Controller { * * @return json */ - public function getCustomer() { + public function getCustomer() + { try { $v = \Validator::make($this->request->all(), [ 'user_id' => 'required', @@ -609,7 +622,8 @@ class ApiController extends Controller { * * @return json */ - public function searchTicket() { + public function searchTicket() + { try { $v = \Validator::make($this->request->all(), [ 'search' => 'required', @@ -620,7 +634,7 @@ class ApiController extends Controller { 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) { @@ -641,7 +655,8 @@ class ApiController extends Controller { * * @return json */ - public function ticketThreads() { + public function ticketThreads() + { try { $v = \Validator::make($this->request->all(), [ 'id' => 'required', @@ -678,7 +693,8 @@ class ApiController extends Controller { * * @return json */ - public function checkUrl() { + public function checkUrl() + { //dd($this->request); try { $v = \Validator::make($this->request->all(), [ @@ -695,7 +711,7 @@ class ApiController extends Controller { $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')); @@ -715,7 +731,8 @@ class ApiController extends Controller { * * @return string */ - public function urlResult() { + public function urlResult() + { return 'success'; } @@ -726,7 +743,8 @@ class ApiController extends Controller { * * @return type int|string|json */ - public function callGetApi($url) { + public function callGetApi($url) + { $curl = curl_init($url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_URL, $url); @@ -735,7 +753,7 @@ class ApiController extends Controller { $response = curl_exec($curl); if (curl_errno($curl)) { - echo 'error:' . curl_error($curl); + echo 'error:'.curl_error($curl); } return $response; @@ -750,7 +768,8 @@ class ApiController extends Controller { * * @return type int|string|json */ - public function callPostApi($url, $data) { + public function callPostApi($url, $data) + { $curl = curl_init($url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_URL, $url); @@ -760,7 +779,7 @@ class ApiController extends Controller { $response = curl_exec($curl); if (curl_errno($curl)) { - echo 'error:' . curl_error($curl); + echo 'error:'.curl_error($curl); } return $response; @@ -772,7 +791,8 @@ class ApiController extends Controller { * * @return type | json */ - public function generateApiKey() { + public function generateApiKey() + { try { $set = $this->setting->where('id', '1')->first(); //dd($set); @@ -806,7 +826,8 @@ class ApiController extends Controller { * * @return json */ - public function getHelpTopic() { + public function getHelpTopic() + { try { $result = $this->helptopic->get(); @@ -829,7 +850,8 @@ class ApiController extends Controller { * * @return json */ - public function getSlaPlan() { + public function getSlaPlan() + { try { $result = $this->slaPlan->get(); @@ -852,7 +874,8 @@ class ApiController extends Controller { * * @return json */ - public function getPriority() { + public function getPriority() + { try { $result = $this->priority->get(); @@ -875,7 +898,8 @@ class ApiController extends Controller { * * @return json */ - public function getDepartment() { + public function getDepartment() + { try { $result = $this->department->get(); @@ -898,7 +922,8 @@ class ApiController extends Controller { * * @return type json */ - public function getTickets() { + public function getTickets() + { try { $tickets = $this->model->orderBy('created_at', 'desc')->paginate(10); $tickets->toJson(); @@ -922,13 +947,14 @@ class ApiController extends Controller { * * @return type json */ - public function inbox() { + public function inbox() + { try { $user = \JWTAuth::parseToken()->authenticate(); $inbox = $this->user->join('tickets', function ($join) { - $join->on('users.id', '=', 'tickets.user_id') + $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') @@ -939,7 +965,7 @@ class ApiController extends Controller { ->whereNotNull('ticket_thread.title'); }) ->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'ticket_thread.title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name', 'department.id as department_id', 'users.primary_dpt as user_dpt') - ->where(function($query) use($user) { + ->where(function ($query) use ($user) { if ($user->role != 'admin') { $query->where('tickets.dept_id', '=', $user->primary_dpt); } @@ -949,6 +975,7 @@ class ApiController extends Controller { ->distinct() ->paginate(10) ->toJson(); + return $inbox; } catch (\Exception $ex) { $error = $ex->getMessage(); @@ -968,12 +995,13 @@ class ApiController extends Controller { * * @return type json */ - public function internalNote() { + public function internalNote() + { try { $v = \Validator::make($this->request->all(), [ - 'userid' => 'required|exists:users,id', + 'userid' => 'required|exists:users,id', 'ticketid' => 'required|exists:tickets,id', - 'body' => 'required', + 'body' => 'required', ]); if ($v->fails()) { $error = $v->errors(); @@ -1000,13 +1028,14 @@ class ApiController extends Controller { } } - public function getTrash() { + public function getTrash() + { try { $user = \JWTAuth::parseToken()->authenticate(); $trash = $this->user->join('tickets', function ($join) { - $join->on('users.id', '=', 'tickets.user_id') + $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') @@ -1017,7 +1046,7 @@ class ApiController extends Controller { ->whereNotNull('title'); }) ->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name') - ->where(function($query) use($user) { + ->where(function ($query) use ($user) { if ($user->role != 'admin') { $query->where('tickets.dept_id', '=', $user->primary_dpt); } @@ -1042,7 +1071,8 @@ class ApiController extends Controller { } } - public function getMyTicketsAgent() { + public function getMyTicketsAgent() + { try { $v = \Validator::make($this->request->all(), [ 'user_id' => 'required|exists:users,id', @@ -1060,10 +1090,10 @@ class ApiController extends Controller { } //$user = \JWTAuth::parseToken()->authenticate(); $result = $this->user->join('tickets', function ($join) use ($id) { - $join->on('users.id', '=', 'tickets.assigned_to') + $join->on('users.id', '=', 'tickets.assigned_to') ->where('status', '=', 1); //->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') @@ -1100,7 +1130,8 @@ class ApiController extends Controller { } } - public function getMyTicketsUser() { + public function getMyTicketsUser() + { try { $v = \Validator::make($this->request->all(), [ 'user_id' => 'required|exists:users,id', @@ -1117,9 +1148,9 @@ class ApiController extends Controller { return response()->json(compact('error')); } $result = $this->user->join('tickets', function ($join) use ($id) { - $join->on('users.id', '=', 'tickets.user_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') @@ -1151,7 +1182,8 @@ class ApiController extends Controller { } } - public function getTicketById() { + public function getTicketById() + { try { $v = \Validator::make($this->request->all(), [ 'id' => 'required|exists:tickets,id', @@ -1163,7 +1195,7 @@ class ApiController extends Controller { } $id = $this->request->input('id'); if (!$this->model->where('id', $id)->first()) { - $error = 'There is no Ticket as ticket id: ' . $id; + $error = 'There is no Ticket as ticket id: '.$id; return response()->json(compact('error')); } @@ -1171,44 +1203,43 @@ class ApiController extends Controller { $join->on('users.id', '=', 'tickets.user_id') ->where('tickets.id', '=', $id); }); - - + $response = $this->differenciateHelpTopic($query) - ->leftJoin('department','tickets.dept_id','=',"department.id") - ->leftJoin('ticket_priority','tickets.priority_id','=','ticket_priority.priority_id') - ->leftJoin('ticket_status','tickets.status','=','ticket_status.id') - ->leftJoin('sla_plan','tickets.sla','=','sla_plan.id') - ->leftJoin('ticket_source','tickets.source','=','ticket_source.id'); + ->leftJoin('department', 'tickets.dept_id', '=', 'department.id') + ->leftJoin('ticket_priority', 'tickets.priority_id', '=', 'ticket_priority.priority_id') + ->leftJoin('ticket_status', 'tickets.status', '=', 'ticket_status.id') + ->leftJoin('sla_plan', 'tickets.sla', '=', 'sla_plan.id') + ->leftJoin('ticket_source', 'tickets.source', '=', 'ticket_source.id'); //$select = 'users.email','users.user_name','users.first_name','users.last_name','tickets.id','ticket_number','num_sequence','user_id','priority_id','sla','max_open_ticket','captcha','status','lock_by','lock_at','source','isoverdue','reopened','isanswered','is_deleted', 'closed','is_transfer','transfer_at','reopened_at','duedate','closed_at','last_message_at'; $result = $response->addSelect( - 'users.email', - 'users.user_name', - 'users.first_name', - 'users.last_name', - 'tickets.id', - 'ticket_number', - 'user_id', + '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', + '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')); @@ -1225,7 +1256,8 @@ class ApiController extends Controller { } } - public function createPagination($array, $perPage) { + public function createPagination($array, $perPage) + { try { //Get current page form url e.g. &page=6 $currentPage = LengthAwarePaginator::resolveCurrentPage(); @@ -1253,7 +1285,8 @@ class ApiController extends Controller { } } - public function collaboratorSearch() { + public function collaboratorSearch() + { $this->validate($this->request, ['term' => 'required']); try { $emails = $this->ticket->autosearch(); @@ -1263,7 +1296,7 @@ class ApiController extends Controller { 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]['name'] = $user_model->first_name.' '.$user_model->last_name; $users[$key]['email'] = $email; $users[$key]['avatar'] = $this->avatarUrl($email); } @@ -1280,12 +1313,13 @@ class ApiController extends Controller { } } - public function avatarUrl($email) { + public function avatarUrl($email) + { try { $user = new User(); $user = $user->where('email', $email)->first(); if ($user->profile_pic) { - $url = url('uploads/profilepic/' . $user->profile_pic); + $url = url('uploads/profilepic/'.$user->profile_pic); } else { $url = \Gravatar::src($email); } @@ -1297,10 +1331,11 @@ class ApiController extends Controller { } } - public function addCollaboratorForTicket() { + public function addCollaboratorForTicket() + { try { $v = \Validator::make(\Input::get(), [ - 'email' => 'required|email|unique:users', + 'email' => 'required|email|unique:users', 'ticket_id' => 'required', ] ); @@ -1327,7 +1362,8 @@ class ApiController extends Controller { } } - public function getCollaboratorForTicket() { + public function getCollaboratorForTicket() + { try { $v = \Validator::make(\Input::get(), [ 'ticket_id' => 'required', @@ -1356,11 +1392,12 @@ class ApiController extends Controller { } } - public function deleteCollaborator() { + public function deleteCollaborator() + { try { $v = \Validator::make(\Input::get(), [ 'ticketid' => 'required', - 'email' => 'required', + 'email' => 'required', ] ); if ($v->fails()) { @@ -1380,7 +1417,8 @@ class ApiController extends Controller { } } - public function dependency() { + public function dependency() + { try { $department = $this->department->select('name', 'id')->get()->toArray(); $sla = $this->slaPlan->select('name', 'id')->get()->toArray(); @@ -1391,7 +1429,7 @@ class ApiController extends Controller { $status = \DB::table('ticket_status')->select('name', 'id')->get(); $source = \DB::table('ticket_source')->select('name', 'id')->get(); $result = ['departments' => $department, 'sla' => $sla, 'staffs' => $staff, 'teams' => $team, - 'priorities' => $priority, 'helptopics' => $helptopic, 'status' => $status, 'sources' => $source,]; + 'priorities' => $priority, 'helptopics' => $helptopic, 'status' => $status, 'sources' => $source, ]; return response()->json(compact('result')); } catch (\Exception $e) { @@ -1403,7 +1441,8 @@ class ApiController extends Controller { } } - public function differenciateHelpTopic($query) { + public function differenciateHelpTopic($query) + { $ticket = $query->first(); $check = 'department'; if ($ticket) { @@ -1417,16 +1456,18 @@ class ApiController extends Controller { return $query->select('tickets.dept_id'); } } + return $query; } - public function getSystem($check, $query) { + public function getSystem($check, $query) + { switch ($check) { case 'department': return $query->select('tickets.dept_id'); case 'helpTopic': return $query->select('tickets.help_topic_id'); - default : + default: return $query->select('tickets.dept_id'); } } @@ -1438,10 +1479,11 @@ class ApiController extends Controller { * * @return type json */ - public function register(Request $request) { + public function register(Request $request) + { try { $v = \Validator::make($request->all(), [ - 'email' => 'required|email|unique:users', + 'email' => 'required|email|unique:users', 'password' => 'required|min:6', ]); if ($v->fails()) { @@ -1455,7 +1497,7 @@ class ApiController extends Controller { $password = \Hash::make($request->input('password')); $role = $request->input('role'); if ($auth->role == 'agent') { - $role = "user"; + $role = 'user'; } $user = new User(); $user->password = $password; @@ -1463,6 +1505,7 @@ class ApiController extends Controller { $user->email = $email; $user->role = $role; $user->save(); + return response()->json(compact('user')); } catch (\Exception $e) { $error = $e->getMessage(); @@ -1470,5 +1513,4 @@ class ApiController extends Controller { return response()->json(compact('error')); } } - } diff --git a/app/Http/Controllers/Api/v1/InstallerApiController.php b/app/Http/Controllers/Api/v1/InstallerApiController.php index 60855d60b..a4d82c4b2 100644 --- a/app/Http/Controllers/Api/v1/InstallerApiController.php +++ b/app/Http/Controllers/Api/v1/InstallerApiController.php @@ -98,7 +98,7 @@ class InstallerApiController extends Controller $ENV['QUEUE_DRIVER'] = 'sync'; $config = ''; - + foreach ($ENV as $key => $val) { $config .= "{$key}={$val}\n"; } diff --git a/app/Http/Controllers/Api/v1/TokenAuthController.php b/app/Http/Controllers/Api/v1/TokenAuthController.php index c1974518e..f08d0346d 100644 --- a/app/Http/Controllers/Api/v1/TokenAuthController.php +++ b/app/Http/Controllers/Api/v1/TokenAuthController.php @@ -50,7 +50,7 @@ class TokenAuthController extends Controller //$credentials = $request->only('email', 'password'); try { - if (!$token = JWTAuth::attempt([$field => $usernameinput, 'password' => $password,'active'=>1])) { + if (!$token = JWTAuth::attempt([$field => $usernameinput, 'password' => $password, 'active'=>1])) { return response()->json(['error' => 'invalid_credentials', 'status_code' => 401]); } } catch (JWTException $e) { diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index 7d8093bba..971ebc449 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -3,31 +3,29 @@ namespace App\Http\Controllers\Auth; // controllers +use App\Http\Controllers\Admin\helpdesk\SocialMedia\SocialMediaController; use App\Http\Controllers\Common\PhpMailController; -use App\Http\Controllers\Common\SettingsController; -use App\Http\Controllers\Controller; // requests +use App\Http\Controllers\Controller; use App\Http\Requests\helpdesk\LoginRequest; -use App\Http\Requests\helpdesk\RegisterRequest; use App\Http\Requests\helpdesk\OtpVerifyRequest; -use App\Model\helpdesk\Settings\Security; +use App\Http\Requests\helpdesk\RegisterRequest; use App\Model\helpdesk\Settings\CommonSettings; -use App\Model\helpdesk\Ticket\Ticket_Thread; -use App\Model\helpdesk\Ticket\Tickets; use App\Model\helpdesk\Settings\Plugin; - +use App\Model\helpdesk\Settings\Security; +use App\Model\helpdesk\Ticket\Ticket_Thread; // classes -use App\User; +use App\Model\helpdesk\Ticket\Tickets; use App\Model\helpdesk\Utility\Otp; +use App\User; use Auth; +use DateTime; use DB; use Hash; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; -use Lang; -use DateTime; use Input; +use Lang; use Socialite; -use App\Http\Controllers\Admin\helpdesk\SocialMedia\SocialMediaController; /** * --------------------------------------------------- @@ -39,8 +37,8 @@ use App\Http\Controllers\Admin\helpdesk\SocialMedia\SocialMediaController; * * @author Ladybird */ -class AuthController extends Controller { - +class AuthController extends Controller +{ use AuthenticatesAndRegistersUsers; /* to redirect after login */ @@ -61,14 +59,15 @@ class AuthController extends Controller { * * @return void */ - public function __construct(PhpMailController $PhpMailController, SocialMediaController $social) { + public function __construct(PhpMailController $PhpMailController, SocialMediaController $social) + { $this->PhpMailController = $PhpMailController; $social->configService(); $this->middleware('guest', ['except' => ['getLogout', 'verifyOTP', 'redirectToProvider']]); } - public function redirectToProvider($provider, $redirect = '') { - + public function redirectToProvider($provider, $redirect = '') + { if ($redirect !== '') { $this->setSession($provider, $redirect); } @@ -78,7 +77,8 @@ class AuthController extends Controller { return $s; } - public function handleProviderCallback($provider) { + public function handleProviderCallback($provider) + { try { //notice we are not doing any validation, you should do it $this->changeRedirect(); @@ -91,25 +91,24 @@ class AuthController extends Controller { if ($user->nickname) { $username = $user->nickname; } - if(!$first_name){ + if (!$first_name) { $first_name = $username; } $data = [ 'first_name' => $first_name, - 'email' => $user->getEmail(), - 'user_name' => $username, - 'role' => 'user', - 'active' => 1, + 'email' => $user->getEmail(), + 'user_name' => $username, + 'role' => 'user', + 'active' => 1, ]; - $user = User::where('email',$data['email'])->first(); - if(!$user){ - $user = User::where('user_name',$data['user_name'])->first(); + $user = User::where('email', $data['email'])->first(); + if (!$user) { + $user = User::where('user_name', $data['user_name'])->first(); } - if(!$user){ - $user = User::firstOrCreate($data); + if (!$user) { + $user = User::firstOrCreate($data); } Auth::login($user); - } //after login redirecting to home page return redirect('/'); @@ -123,7 +122,8 @@ class AuthController extends Controller { * * @return type Response */ - public function getRegister(CommonSettings $settings) { + public function getRegister(CommonSettings $settings) + { // Event for login $settings = $settings->select('status')->where('option_name', '=', 'send_otp')->first(); $email_mandatory = $settings->select('status')->where('option_name', '=', 'email_mandatory')->first(); @@ -148,46 +148,47 @@ class AuthController extends Controller { * * @return type Response */ - public function postRegister(User $user, RegisterRequest $request) { + public function postRegister(User $user, RegisterRequest $request) + { 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'] == '') { - $user->email = null; - } else { - $user->email = $request->input('email'); - } - if ($request_array['mobile'] == '') { - $user->mobile = null; - } else { - $user->mobile = $request->input('mobile'); - } - if ($request_array['code'] == '') { - $user->country_code = 0; - } else { - $user->country_code = $request->input('code'); - } - if ($request_array['email'] != '') { - $user->user_name = $request->input('email'); - } else { - $user->user_name = $request->input('mobile'); - } - $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(); + $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'] == '') { + $user->email = null; + } else { + $user->email = $request->input('email'); + } + if ($request_array['mobile'] == '') { + $user->mobile = null; + } else { + $user->mobile = $request->input('mobile'); + } + if ($request_array['code'] == '') { + $user->country_code = 0; + } else { + $user->country_code = $request->input('code'); + } + if ($request_array['email'] != '') { + $user->user_name = $request->input('email'); + } else { + $user->user_name = $request->input('mobile'); + } + $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(); // Event for login \Event::fire(new \App\Events\LoginEvent($request)); - $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)]); + $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 (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 { $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail_sms_plugin_inactive_or_not_setup'); @@ -198,9 +199,10 @@ class AuthController extends Controller { } else { $message12 = Lang::get('lang.activate_your_account_click_on_Link_that_send_to_your_mail'); } - return redirect('home')->with('success', $message12); + + return redirect('home')->with('success', $message12); } catch (\Exception $e) { - return redirect()->back()->with('fails', $e->getMessage()); + return redirect()->back()->with('fails', $e->getMessage()); } } @@ -211,13 +213,15 @@ class AuthController extends Controller { * * @return type redirect */ - public function accountActivate($token) { + public function accountActivate($token) + { $user = User::where('remember_token', '=', $token)->first(); 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 { return redirect('/auth/login')->with('fails', 'Invalid Token'); @@ -232,7 +236,8 @@ class AuthController extends Controller { * * @return type Response */ - public function getMail($token, User $user) { + public function getMail($token, User $user) + { $user = $user->where('remember_token', $token)->where('active', 0)->first(); if ($user) { $user->active = 1; @@ -249,9 +254,10 @@ class AuthController extends Controller { * * @return type Response */ - public function getLogin() { + public function getLogin() + { $directory = base_path(); - if (file_exists($directory . DIRECTORY_SEPARATOR . '.env')) { + if (file_exists($directory.DIRECTORY_SEPARATOR.'.env')) { if (Auth::user()) { if (Auth::user()->role == 'admin' || Auth::user()->role == 'agent') { return \Redirect::route('dashboard'); @@ -288,7 +294,7 @@ class AuthController extends Controller { } $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) { @@ -301,15 +307,15 @@ class AuthController extends Controller { return redirect()->back() ->withInput($request->only('email', 'remember')) ->withErrors([ - 'email' => $this->getFailedLoginMessage(), - 'password' => $this->getFailedLoginMessage(), - ])->with(['error' => Lang::get('lang.not-registered'), + 'email' => $this->getFailedLoginMessage(), + 'password' => $this->getFailedLoginMessage(), + ])->with(['error' => Lang::get('lang.not-registered'), '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 // setting is enabled $sms = Plugin::select('status')->where('name', '=', 'SMS')->first(); @@ -320,7 +326,7 @@ class AuthController extends Controller { 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 - // user has mobile number return verify OTP screen + // user has mobile number return verify OTP screen return \Redirect::route('otp-verification') ->withInput($request->input()) ->with(['values' => $request->input(), @@ -329,7 +335,7 @@ class AuthController extends Controller { 'number' => $check_active->mobile, 'code' => $check_active->country_code, ]); } else { - goto a; //attenmpt login (be careful while using goto statements) + goto a; //attenmpt login (be careful while using goto statements) } } else { goto a; //attenmpt login (be careful while using goto statements) @@ -384,14 +390,15 @@ class AuthController extends Controller { if ($request->input('referer')) { return \Redirect::route($request->input('referer')); } + return \Redirect::route('/'); } else { return redirect()->intended($this->redirectPath()); } } - } } + return redirect()->back() ->withInput($request->only('email', 'remember')) ->withErrors([ @@ -409,7 +416,8 @@ class AuthController extends Controller { * * @return type Response */ - public function addLoginAttempt($value, $field) { + public function addLoginAttempt($value, $field) + { $result = DB::table('login_attempts')->where('IP', '=', $value)->first(); $data = $result; $security = Security::whereId('1')->first(); @@ -417,15 +425,15 @@ class AuthController extends Controller { if ($data) { $attempts = $data->Attempts + 1; 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')]); + // $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 { $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 { -// $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')]); + // $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')]); } } @@ -436,7 +444,8 @@ class AuthController extends Controller { * * @return type Response */ - public function clearLoginAttempts($value, $field) { + public function clearLoginAttempts($value, $field) + { $data = DB::table('login_attempts')->where('IP', '=', $value)->orWhere('User', '=', $field)->update(['attempts' => '0']); return $data; @@ -449,13 +458,14 @@ class AuthController extends Controller { * * @return type Response */ - public function confirmIPAddress($value, $field) { + public function confirmIPAddress($value, $field) + { $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'"); + $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) { @@ -466,6 +476,7 @@ class AuthController extends Controller { return 1; } else { $this->clearLoginAttempts($value, $field); + return 0; } } @@ -478,16 +489,20 @@ class AuthController extends Controller { * * @return type string */ - protected function getFailedLoginMessage() { + protected function getFailedLoginMessage() + { return Lang::get('lang.this_field_do_not_match_our_records'); } /** *@category function to show verify OTP page + * *@param null + * *@return response|view */ - public function getVerifyOTP() { + public function getVerifyOTP() + { if (\Session::has('values')) { return view('auth.otp-verify'); } else { @@ -497,10 +512,13 @@ class AuthController extends Controller { /** *@category function to verify OTP + * *@param $request + * *@return int|string */ - public function verifyOTP(LoginRequest $request) { + public function verifyOTP(LoginRequest $request) + { $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')); @@ -510,10 +528,10 @@ class AuthController extends Controller { $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')))) { + 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"); + $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); @@ -526,6 +544,7 @@ class AuthController extends Controller { User::where('id', '=', $user->id) ->update(['active' => 1]); $this->openTicketAfterVerification($user->id); + return $this->postLogin($request); } else { $message = Lang::get('lang.otp-not-matched'); @@ -538,37 +557,46 @@ class AuthController extends Controller { $message = Lang::get('lang.otp-not-matched'); } } + 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) { + public function resendOTP(OtpVerifyRequest $request) + { if (!\Schema::hasTable('user_verification') || !\Schema::hasTable('sms')) { $message = Lang::get('lang.opt-can-not-be-verified'); + return $message; } else { - $sms =DB::table('sms')->get(); + $sms = DB::table('sms')->get(); if (count($sms) > 0) { \Event::fire(new \App\Events\LoginEvent($request)); + return 1; } else { $message = Lang::get('lang.opt-can-not-be-verified'); + return $message; - } + } } } /** * @category function to change ticket status when user verifies his account + * * @param int $id => user_id + * * @return null + * * @author manish.verma@ladybirdweb.com */ - public function openTicketAfterVerification($id) { + public function openTicketAfterVerification($id) + { // dd($id); $ticket = Tickets::select('id') ->where(['user_id' => $id, 'status' => 6]) @@ -579,23 +607,23 @@ class AuthController extends Controller { 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')]); + ->update(['updated_at' => date('Y-m-d H:i:s')]); } } } - - public function changeRedirect() { + public function changeRedirect() + { $provider = \Session::get('provider'); - $url = \Session::get($provider . 'redirect'); + $url = \Session::get($provider.'redirect'); \Config::set("services.$provider.redirect", $url); } - public function setSession($provider, $redirect) { + public function setSession($provider, $redirect) + { $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 900265f78..978a41401 100644 --- a/app/Http/Controllers/Auth/PasswordController.php +++ b/app/Http/Controllers/Auth/PasswordController.php @@ -4,7 +4,6 @@ namespace App\Http\Controllers\Auth; // controllers use App\Http\Controllers\Common\PhpMailController; -use App\Http\Controllers\Common\SettingsController; use App\Http\Controllers\Controller; // request use App\User; @@ -51,41 +50,42 @@ class PasswordController extends Controller */ public function postEmail(Request $request) { - try{ - $date = date('Y-m-d H:i:s'); - $this->validate($request, ['email' => 'required']); - \Event::fire('reset.password',array()); - $user = User::where('email', '=', $request->only('email'))->orWhere('mobile', '=', $request->only('email'))->first(); - if (isset($user)) { - $user1 = $user->email; + try { + $date = date('Y-m-d H:i:s'); + $this->validate($request, ['email' => 'required']); + \Event::fire('reset.password', []); + $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); - $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 = \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->update(['token' => $code]); - } else { - $create_password_reset = \DB::table('password_resets')->insert(['email' => $user->email, 'token' => $code, 'created_at' => $date]); - } - $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user->user_name, 'email' => $user->email], $message = ['subject' => 'Your Password Reset Link', 'scenario' => 'reset-password'], $template_variables = ['user' => $user->first_name, 'email_address' => $user->email, 'password_reset_link' => url('password/reset/'.$code)],true); - if ($user->mobile != '' && $user->mobile != null) { - if($user->first_name) { - $name = $user->first_name; } else { - $name = $user->user_name; + $create_password_reset = \DB::table('password_resets')->insert(['email' => $user->email, 'token' => $code, 'created_at' => $date]); } - $value = [ + $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user->user_name, 'email' => $user->email], $message = ['subject' => 'Your Password Reset Link', 'scenario' => 'reset-password'], $template_variables = ['user' => $user->first_name, 'email_address' => $user->email, 'password_reset_link' => url('password/reset/'.$code)], true); + if ($user->mobile != '' && $user->mobile != null) { + if ($user->first_name) { + $name = $user->first_name; + } else { + $name = $user->user_name; + } + $value = [ 'url' => url('password/reset/'.$code), 'name' => $name, 'mobile' => $user->mobile, - 'code' => $user->country_code]; - \Event::fire('reset.password2',array($value)); + 'code' => $user->country_code, ]; + \Event::fire('reset.password2', [$value]); + } + + return redirect()->back()->with('status', Lang::get('lang.we_have_e-mailed_your_password_reset_link')); + } else { + return redirect()->back()->with('fails', Lang::get("lang.we_can't_find_a_user_with_that_e-mail_address")); } - return redirect()->back()->with('status', Lang::get('lang.we_have_e-mailed_your_password_reset_link')); - } else { - return redirect()->back()->with('fails', Lang::get("lang.we_can't_find_a_user_with_that_e-mail_address")); - } } catch (\Exception $e) { return redirect()->back()->with('fails', $e->getMessage()); } @@ -94,12 +94,12 @@ class PasswordController extends Controller /** * Reset the given user's password. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request + * * @return \Illuminate\Http\Response */ public function reset(Request $request) { - $this->validate( $request, $this->getResetValidationRules(), @@ -111,26 +111,25 @@ class PasswordController extends Controller $email = $credentials['email']; $password = $credentials['password']; $token = $credentials['token']; - $response = "fails"; - $password_tokens = \DB::table('password_resets')->where('email','=',$email)->first(); - if($password_tokens){ - if($password_tokens->token == $token){ + $response = 'fails'; + $password_tokens = \DB::table('password_resets')->where('email', '=', $email)->first(); + if ($password_tokens) { + if ($password_tokens->token == $token) { $users = new User(); - $user = $users->where('email',$email)->first(); - if($user){ + $user = $users->where('email', $email)->first(); + if ($user) { $user->password = \Hash::make($password); $user->save(); - $response = "success"; + $response = 'success'; } else { - $response = "fails"; + $response = 'fails'; } } } - if ($response == "success") { + if ($response == 'success') { return redirect('/auth/login')->with('status', Lang::get('lang.password-reset-successfully')); } else { return redirect('/home')->with('fails', Lang::get('lang.password-can-not-reset')); } } - } diff --git a/app/Http/Controllers/Client/helpdesk/FormController.php b/app/Http/Controllers/Client/helpdesk/FormController.php index 8f387aa07..5c6d061df 100644 --- a/app/Http/Controllers/Client/helpdesk/FormController.php +++ b/app/Http/Controllers/Client/helpdesk/FormController.php @@ -11,15 +11,14 @@ use App\Model\helpdesk\Agent\Department; // models use App\Model\helpdesk\Form\Fields; use App\Model\helpdesk\Manage\Help_topic; - +use App\Model\helpdesk\Settings\CommonSettings; use App\Model\helpdesk\Settings\System; use App\Model\helpdesk\Settings\Ticket; -use App\Model\helpdesk\Settings\CommonSettings; use App\Model\helpdesk\Ticket\Ticket_attachments; +use App\Model\helpdesk\Ticket\Ticket_Priority; use App\Model\helpdesk\Ticket\Ticket_source; use App\Model\helpdesk\Ticket\Ticket_Thread; use App\Model\helpdesk\Ticket\Tickets; -use App\Model\helpdesk\Ticket\Ticket_Priority; use App\Model\helpdesk\Utility\CountryCode; use App\User; use Exception; @@ -36,15 +35,16 @@ use Redirect; * * @author Ladybird */ -class FormController extends Controller { - +class FormController extends Controller +{ /** * Create a new controller instance. * Constructor to check. * * @return void */ - public function __construct(TicketWorkflowController $TicketWorkflowController) { + public function __construct(TicketWorkflowController $TicketWorkflowController) + { $this->middleware('board'); // creating a TicketController instance $this->TicketWorkflowController = $TicketWorkflowController; @@ -57,29 +57,31 @@ class FormController extends Controller { * * @return type */ - public function getForm(Help_topic $topic, CountryCode $code) { + public function getForm(Help_topic $topic, CountryCode $code) + { if (\Config::get('database.install') == '%0%') { return \Redirect::route('licence'); } $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); - $email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first(); + $email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first(); if (!\Auth::check() && ($settings->status == 1 || $settings->status == '1')) { return redirect('auth/login')->with(['login_require'=> 'Please login to your account for submitting a ticket', 'referer' => 'form']); } - $location = GeoIP::getLocation(); - $phonecode = $code->where('iso', '=', $location->iso_code)->first(); - if (System::first()->status == 1) { - $topics = $topic->get(); - $codes = $code->get(); - if ($phonecode->phonecode) { - $phonecode = $phonecode->phonecode; - } else { - $phonecode = ""; - } - return view('themes.default1.client.helpdesk.form', compact('topics', 'codes', 'email_mandatory'))->with('phonecode', $phonecode); + $location = GeoIP::getLocation(); + $phonecode = $code->where('iso', '=', $location->iso_code)->first(); + if (System::first()->status == 1) { + $topics = $topic->get(); + $codes = $code->get(); + if ($phonecode->phonecode) { + $phonecode = $phonecode->phonecode; } else { - return \Redirect::route('home'); + $phonecode = ''; } + + return view('themes.default1.client.helpdesk.form', compact('topics', 'codes', 'email_mandatory'))->with('phonecode', $phonecode); + } else { + return \Redirect::route('home'); + } } /** @@ -90,43 +92,43 @@ class FormController extends Controller { * * @return type string */ - public function postForm($id, Help_topic $topic) { + public function postForm($id, Help_topic $topic) + { if ($id != 0) { $helptopic = $topic->where('id', '=', $id)->first(); $custom_form = $helptopic->custom_form; $values = Fields::where('forms_id', '=', $custom_form)->get(); if (!$values) { - } if ($values) { foreach ($values as $form_data) { - if ($form_data->type == "select") { + if ($form_data->type == 'select') { $form_fields = explode(',', $form_data->value); - $var = ""; + $var = ''; foreach ($form_fields as $form_field) { - $var .= ''; + $var .= ''; } - echo '
    '; - } elseif ($form_data->type == "radio") { + echo '
    '; + } elseif ($form_data->type == 'radio') { $type2 = $form_data->value; $vals = explode(',', $type2); - echo '

    '; + echo '

    '; foreach ($vals as $val) { - echo ' ' . $form_data->value . '       '; + echo ' '.$form_data->value.'       '; } - echo "
    "; - } elseif ($form_data->type == "textarea") { + echo '
    '; + } elseif ($form_data->type == 'textarea') { $type3 = $form_data->value; - echo '

    '; - } elseif ($form_data->type == "checkbox") { + echo '

    '; + } elseif ($form_data->type == 'checkbox') { $type4 = $form_data->value; $checks = explode(',', $type4); - echo '

    '; + echo '

    '; foreach ($checks as $check) { - echo '  ' . $check; + echo '  '.$check; } } else { - echo '
    '; + echo '
    '; } } echo '

    '; @@ -142,15 +144,16 @@ class FormController extends Controller { * @param type Request $request * @param type User $user */ - public function postedForm(User $user, ClientRequest $request, Ticket $ticket_settings, Ticket_source $ticket_source, Ticket_attachments $ta, CountryCode $code) { - $form_extras = $request->except('Name', 'Phone', 'Email', 'Subject', 'Details', 'helptopic', '_wysihtml5_mode', '_token','mobile','Code', 'priority'); + public function postedForm(User $user, ClientRequest $request, Ticket $ticket_settings, Ticket_source $ticket_source, Ticket_attachments $ta, CountryCode $code) + { + $form_extras = $request->except('Name', 'Phone', 'Email', 'Subject', 'Details', 'helptopic', '_wysihtml5_mode', '_token', 'mobile', 'Code', 'priority'); $name = $request->input('Name'); $phone = $request->input('Phone'); if ($request->input('Email')) { - if($request->input('Email')) { + if ($request->input('Email')) { $email = $request->input('Email'); } else { - $email = null; + $email = null; } } else { $email = null; @@ -165,18 +168,18 @@ class FormController extends Controller { } $status = $ticket_settings->first()->status; $helptopic = $request->input('helptopic'); - $helpTopicObj = Help_topic::where('id','=', $helptopic); - if($helpTopicObj->exists() && ($helpTopicObj->value('status')==1)){ + $helpTopicObj = Help_topic::where('id', '=', $helptopic); + if ($helpTopicObj->exists() && ($helpTopicObj->value('status') == 1)) { $department = $helpTopicObj->value('department'); - }else{ - $defaultHelpTopicID = Ticket::where('id', '=', '1')->first()->help_topic; - $department = Help_topic::where('id','=', $defaultHelpTopicID)->value('department'); + } else { + $defaultHelpTopicID = Ticket::where('id', '=', '1')->first()->help_topic; + $department = Help_topic::where('id', '=', $defaultHelpTopicID)->value('department'); } $sla = $ticket_settings->first()->sla; - + // $priority = $ticket_settings->first()->priority; - $default_priority = Ticket_Priority::where('is_default','=',1)->first(); - $user_priority = CommonSettings::where('option_name','=','user_priority')->first(); + $default_priority = Ticket_Priority::where('is_default', '=', 1)->first(); + $user_priority = CommonSettings::where('option_name', '=', 'user_priority')->first(); if (!($request->input('priority'))) { $priority = $default_priority->priority_id; } else { @@ -193,8 +196,8 @@ class FormController extends Controller { $geoipcode = $code->where('iso', '=', $location->iso_code)->first(); if ($phonecode == null) { $data = [ - 'fails' => Lang::get('lang.country-code-required-error'), - 'phonecode' => $geoipcode->phonecode, + 'fails' => Lang::get('lang.country-code-required-error'), + 'phonecode' => $geoipcode->phonecode, 'country_code_error' => 1, ]; @@ -203,8 +206,8 @@ class FormController extends Controller { $code = CountryCode::select('phonecode')->where('phonecode', '=', $phonecode)->get(); if (!count($code)) { $data = [ - 'fails' => Lang::get('lang.incorrect-country-code-error'), - 'phonecode' => $geoipcode->phonecode, + 'fails' => Lang::get('lang.incorrect-country-code-error'), + 'phonecode' => $geoipcode->phonecode, 'country_code_error' => 1, ]; @@ -230,7 +233,7 @@ class FormController extends Controller { } } // dd($result); - return Redirect::back()->with('success', Lang::get('lang.Ticket-has-been-created-successfully-your-ticket-number-is') . ' ' . $result[0] . '. ' . Lang::get('lang.Please-save-this-for-future-reference')); + return Redirect::back()->with('success', Lang::get('lang.Ticket-has-been-created-successfully-your-ticket-number-is').' '.$result[0].'. '.Lang::get('lang.Please-save-this-for-future-reference')); } else { return Redirect::back()->withInput($request->except('password'))->with('fails', Lang::get('lang.failed-to-create-user-tcket-as-mobile-has-been-taken')); } @@ -244,14 +247,14 @@ class FormController extends Controller { * * @return type view */ - public function post_ticket_reply($id, Request $request) { - + public function post_ticket_reply($id, Request $request) + { try { if ($comment != null) { $tickets = Tickets::where('id', '=', $id)->first(); $thread = Ticket_Thread::where('ticket_id', '=', $tickets->id)->first(); - $subject = $thread->title . '[#' . $tickets->ticket_number . ']'; + $subject = $thread->title.'[#'.$tickets->ticket_number.']'; $body = $request->input('comment'); $user_cred = User::where('id', '=', $tickets->user_id)->first(); @@ -285,13 +288,14 @@ class FormController extends Controller { } } - public function getCustomForm(Request $request) { - $html = ""; + public function getCustomForm(Request $request) + { + $html = ''; $helptopic_id = $request->input('helptopic'); $helptopics = new Help_topic(); $helptopic = $helptopics->find($helptopic_id); if (!$helptopic) { - throw new Exception("We can not find your request"); + throw new Exception('We can not find your request'); } $custom_form = $helptopic->custom_form; if ($custom_form) { @@ -300,7 +304,7 @@ class FormController extends Controller { $form_controller = new \App\Http\Controllers\Admin\helpdesk\FormController($fields, $forms); $html = $form_controller->renderForm($custom_form); } + return $html; } - } diff --git a/app/Http/Controllers/Client/helpdesk/GuestController.php b/app/Http/Controllers/Client/helpdesk/GuestController.php index 37229d43c..0b1281d8d 100644 --- a/app/Http/Controllers/Client/helpdesk/GuestController.php +++ b/app/Http/Controllers/Client/helpdesk/GuestController.php @@ -6,30 +6,30 @@ namespace App\Http\Controllers\Client\helpdesk; use App\Http\Controllers\Common\PhpMailController; use App\Http\Controllers\Controller; // requests +use App\Http\Requests\helpdesk\OtpVerifyRequest; use App\Http\Requests\helpdesk\ProfilePassword; use App\Http\Requests\helpdesk\ProfileRequest; use App\Http\Requests\helpdesk\TicketRequest; -use App\Model\helpdesk\Manage\Help_topic; // models +use App\Model\helpdesk\Manage\Help_topic; +use App\Model\helpdesk\Settings\CommonSettings; use App\Model\helpdesk\Settings\Company; use App\Model\helpdesk\Settings\System; use App\Model\helpdesk\Ticket\Ticket_Thread; use App\Model\helpdesk\Ticket\Tickets; use App\Model\helpdesk\Utility\CountryCode; -use App\Model\helpdesk\Settings\CommonSettings; -use App\Http\Requests\helpdesk\OtpVerifyRequest; use App\Model\helpdesk\Utility\Otp; use App\User; use Auth; // classes +use DateTime; +use DB; use Exception; use GeoIP; use Hash; use Illuminate\Http\Request; use Input; use Lang; -use DateTime; -use DB; use Socialite; /** @@ -37,14 +37,15 @@ use Socialite; * * @author Ladybird */ -class GuestController extends Controller { - +class GuestController extends Controller +{ /** * Create a new controller instance. * * @return type void */ - public function __construct(PhpMailController $PhpMailController) { + public function __construct(PhpMailController $PhpMailController) + { $this->middleware('board'); $this->PhpMailController = $PhpMailController; // checking authentication @@ -56,15 +57,17 @@ class GuestController extends Controller { * * @return type Response */ - public function getProfile(CountryCode $code) { + public function getProfile(CountryCode $code) + { $user = Auth::user(); $location = GeoIP::getLocation(); $phonecode = $code->where('iso', '=', $location->iso_code)->first(); $settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); $status = $settings->status; + return view('themes.default1.client.helpdesk.profile', compact('user')) ->with(['phonecode' => $phonecode->phonecode, - 'verify' => $status]); + 'verify' => $status, ]); } /** @@ -75,7 +78,8 @@ class GuestController extends Controller { * * @return type Response */ - public function postProfile(ProfileRequest $request) { + public function postProfile(ProfileRequest $request) + { try { // geet authenticated user details $user = Auth::user(); @@ -85,14 +89,14 @@ class GuestController extends Controller { $code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get(); if (!count($code)) { return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput(); - } + } $user->country_code = $request->country_code; } $user->fill($request->except('profile_pic', 'mobile')); $user->gender = $request->input('gender'); $user->save(); if (Input::file('profile_pic')) { - // fetching picture name + // fetching picture name $name = Input::file('profile_pic')->getClientOriginalName(); // fetching upload destination path $destinationPath = 'uploads/profilepic'; @@ -109,11 +113,10 @@ class GuestController extends Controller { $user->mobile = null; } if ($user->save()) { - return redirect()->back()->with('success', Lang::get('lang.Profile-Updated-sucessfully')); + return redirect()->back()->with('success', Lang::get('lang.Profile-Updated-sucessfully')); } else { return redirect()->back()->route('profile')->with('fails', Lang::get('lang.Profile-Updated-sucessfully')); } - } catch (Exception $e) { return redirect()->back()->route('profile')->with('fails', $e->getMessage()); } @@ -121,8 +124,10 @@ class GuestController extends Controller { /** *@category fucntion to check if mobile number is unqique or not + * *@param string $mobile - *@return boolean true(if mobile exists in users table)/false (if mobile does not exist in user table) + * + *@return bool true(if mobile exists in users table)/false (if mobile does not exist in user table) */ public function checkMobile($mobile) { @@ -134,6 +139,7 @@ class GuestController extends Controller { return true; } } + return false; } @@ -144,7 +150,8 @@ class GuestController extends Controller { * * @return type Response */ - public function getTicket(Help_topic $topic) { + public function getTicket(Help_topic $topic) + { $topics = $topic->get(); return view('themes.default1.client.helpdesk.tickets.form', compact('topics')); @@ -157,7 +164,8 @@ class GuestController extends Controller { * * @return type */ - public function getForm(Help_topic $topic) { + public function getForm(Help_topic $topic) + { if (\Config::get('database.install') == '%0%') { return \Redirect::route('licence'); } @@ -179,7 +187,8 @@ class GuestController extends Controller { * * @return type Response */ - public function getMyticket() { + public function getMyticket() + { return view('themes.default1.client.helpdesk.mytickets'); } @@ -192,7 +201,8 @@ class GuestController extends Controller { * * @return type Response */ - public function thread(Ticket_Thread $thread, Tickets $tickets, User $user) { + public function thread(Ticket_Thread $thread, Tickets $tickets, User $user) + { $user_id = Auth::user()->id; //dd($user_id); /* get the ticket's id == ticket_id of thread */ @@ -209,8 +219,8 @@ class GuestController extends Controller { * * @return */ - public function ticketEdit() { - + public function ticketEdit() + { } /** @@ -221,7 +231,8 @@ class GuestController extends Controller { * * @return type Response */ - public function postProfilePassword(ProfilePassword $request) { + public function postProfilePassword(ProfilePassword $request) + { $user = Auth::user(); //echo $user->password; if (Hash::check($request->input('old_password'), $user->getAuthPassword())) { @@ -246,7 +257,8 @@ class GuestController extends Controller { * * @return type Response */ - public function reply(Ticket_Thread $thread, TicketRequest $request) { + public function reply(Ticket_Thread $thread, TicketRequest $request) + { $thread->ticket_id = $request->input('ticket_ID'); $thread->title = $request->input('To'); $thread->user_id = Auth::user()->id; @@ -257,7 +269,7 @@ class GuestController extends Controller { $tickets = Tickets::where('id', '=', $ticket_id)->first(); $thread = Ticket_Thread::where('ticket_id', '=', $ticket_id)->first(); - return Redirect('thread/' . $ticket_id); + return Redirect('thread/'.$ticket_id); } /** @@ -268,7 +280,8 @@ class GuestController extends Controller { * * @return type response */ - public function getCheckTicket(Tickets $ticket, User $user) { + public function getCheckTicket(Tickets $ticket, User $user) + { return view('themes.default1.client.helpdesk.guest-user.newticket', compact('ticket')); } @@ -282,9 +295,10 @@ class GuestController extends Controller { * * @return type Response */ - public function PostCheckTicket(Request $request) { + public function PostCheckTicket(Request $request) + { $validator = \Validator::make($request->all(), [ - 'email' => 'required|email', + 'email' => 'required|email', 'ticket_number' => 'required', ]); if ($validator->fails()) { @@ -304,7 +318,7 @@ class GuestController extends Controller { if ($user->role == 'user') { $username = $user->first_name; } else { - $username = $user->first_name . ' ' . $user->last_name; + $username = $user->first_name.' '.$user->last_name; } if ($user->email != $Email) { return \Redirect::route('form')->with('fails', Lang::get("lang.email_didn't_match_with_ticket_number")); @@ -315,7 +329,7 @@ class GuestController extends Controller { $company = $this->company(); $this->PhpMailController->sendmail( - $from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $username, 'email' => $user->email], $message = ['subject' => 'Ticket link Request [' . $Ticket_number . ']', 'scenario' => 'check-ticket'], $template_variables = ['user' => $username, 'ticket_link_with_number' => \URL::route('check_ticket', $code)] + $from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $username, 'email' => $user->email], $message = ['subject' => 'Ticket link Request ['.$Ticket_number.']', 'scenario' => 'check-ticket'], $template_variables = ['user' => $username, 'ticket_link_with_number' => \URL::route('check_ticket', $code)] ); return \Redirect::back() @@ -331,10 +345,12 @@ class GuestController extends Controller { * * @return type */ - public function get_ticket_email($id, CommonSettings $common_settings) { + public function get_ticket_email($id, CommonSettings $common_settings) + { $common_setting = $common_settings->select('status') ->where('option_name', '=', 'user_set_ticket_status') ->first(); + return view('themes.default1.client.helpdesk.ckeckticket', compact('id', 'common_setting')); } @@ -345,7 +361,8 @@ class GuestController extends Controller { * * @return type */ - public function getTicketStat(Tickets $ticket) { + public function getTicketStat(Tickets $ticket) + { return view('themes.default1.client.helpdesk.ckeckticket', compact('ticket')); } @@ -354,7 +371,8 @@ class GuestController extends Controller { * * @return type */ - public function company() { + public function company() + { $company = Company::Where('id', '=', '1')->first(); if ($company->company_name == null) { $company = 'Support Center'; @@ -371,10 +389,11 @@ class GuestController extends Controller { $sms = DB::table('sms')->get(); if (count($sms) > 0) { \Event::fire(new \App\Events\LoginEvent($request)); + return 1; } } else { - return "Plugin has not been setup successfully."; + return 'Plugin has not been setup successfully.'; } } @@ -386,18 +405,19 @@ class GuestController extends Controller { ->first(); if ($otp != null) { $otp_length = strlen(Input::get('otp')); - if(($otp_length == 6 && !preg_match("/[a-z]/i", Input::get('otp'))) ) { + if (($otp_length == 6 && !preg_match('/[a-z]/i', Input::get('otp')))) { $otp2 = Hash::make(Input::get('otp')); - $date1 = date_format($otp->updated_at, "Y-m-d h:i:sa"); - $date2 = date("Y-m-d h:i:sa"); + $date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa'); + $date2 = date('Y-m-d h:i:sa'); $time1 = new DateTime($date2); $time2 = new DateTime($date1); $interval = $time1->diff($time2); - if($interval->i >10 || $interval->h >0){ + if ($interval->i > 10 || $interval->h > 0) { $message = Lang::get('lang.otp-expired'); + return $message; } else { - if (Hash::check(Input::get('otp'), $otp->otp)){ + if (Hash::check(Input::get('otp'), $otp->otp)) { Otp::where('user_id', '=', Input::get('u_id')) ->update(['otp' => '']); // User::where('id', '=', $user->id) @@ -406,20 +426,24 @@ class GuestController extends Controller { return 1; } else { $message = Lang::get('lang.otp-not-matched'); + return $message; } } } else { $message = Lang::get('lang.otp-invalid'); + return $message; } } else { $message = Lang::get('lang.otp-not-matched'); + return $message; } } - public function sync() { + public function sync() + { try { $provider = $this->getProvider(); $this->changeRedirect(); @@ -431,56 +455,67 @@ class GuestController extends Controller { $user['email'] = $users->email; $user['username'] = $users->nickname; $user['avatar'] = $users->avatar; + return redirect('client-profile')->with('success', 'Additional informations fetched'); } catch (Exception $ex) { dd($ex); + return redirect('client-profile')->with('fails', $ex->getMessage()); } } - public function getProvider() { + public function getProvider() + { $provider = \Session::get('provider'); + return $provider; } - public function changeRedirect() { + public function changeRedirect() + { $provider = \Session::get('provider'); - $url = \Session::get($provider . 'redirect'); + $url = \Session::get($provider.'redirect'); \Config::set("services.$provider.redirect", $url); } - public function forgetSession() { + public function forgetSession() + { $provider = $this->getProvider(); \Session::forget('provider'); - \Session::forget($provider . 'redirect'); + \Session::forget($provider.'redirect'); } - public function checkArray($key, $array) { - $value = ""; + public function checkArray($key, $array) + { + $value = ''; if (array_key_exists($key, $array)) { $value = $array[$key]; } + return $value; } - public function updateUser($user = []) { + public function updateUser($user = []) + { $userid = \Auth::user()->id; $useremail = \Auth::user()->email; $email = $this->checkArray('email', $user); //$user['email']; - if ($email !== "" && $email !== $useremail) { - throw new Exception("Sorry! your current email and " . ucfirst($user['provider']) . " email is different so system can not sync"); + if ($email !== '' && $email !== $useremail) { + throw new Exception('Sorry! your current email and '.ucfirst($user['provider']).' email is different so system can not sync'); } $this->update($userid, $user); } - public function update($userid, $user, $provider) { + public function update($userid, $user, $provider) + { $email = $this->checkArray('email', $user); $this->deleteUser($userid, $user, $provider); $this->insertAdditional($userid, $provider, $user); $this->changeEmail($email); } - public function deleteUser($userid, $user, $provider) { + public function deleteUser($userid, $user, $provider) + { $info = new \App\UserAdditionalInfo(); $infos = $info->where('owner', $userid)->where('service', $provider)->get(); if ($infos->count() > 0 && count($user) > 0) { @@ -492,27 +527,27 @@ class GuestController extends Controller { } } - public function insertAdditional($id, $provider, $user = []) { + public function insertAdditional($id, $provider, $user = []) + { $info = new \App\UserAdditionalInfo(); if (count($user) > 0) { foreach ($user as $key => $value) { - $info->create([ - 'owner' => $id, + 'owner' => $id, 'service' => $provider, - 'key' => $key, - 'value' => $value, + 'key' => $key, + 'value' => $value, ]); } } } - public function changeEmail($email) { + public function changeEmail($email) + { $user = \Auth::user(); if ($user && $email && !$user->email) { $user->email = $email; $user->save(); } } - } diff --git a/app/Http/Controllers/Client/helpdesk/UnAuthController.php b/app/Http/Controllers/Client/helpdesk/UnAuthController.php index 95a9fb45c..5af44b5df 100644 --- a/app/Http/Controllers/Client/helpdesk/UnAuthController.php +++ b/app/Http/Controllers/Client/helpdesk/UnAuthController.php @@ -9,9 +9,9 @@ use App\Http\Controllers\Controller; use App\Model\helpdesk\Email\Emails; // models use App\Model\helpdesk\Settings\CommonSettings; +use App\Model\helpdesk\Settings\Followup; use App\Model\helpdesk\Ticket\Ticket_Status; use App\Model\helpdesk\Ticket\Ticket_Thread; -use App\Model\helpdesk\Settings\Followup; use App\Model\helpdesk\Ticket\Tickets; use App\Model\helpdesk\Ticket\TicketToken; use App\User; @@ -320,9 +320,10 @@ class UnAuthController extends Controller /** *@category function to change system's language - *@param string $lang //desired language's iso code - *@return response * + *@param string $lang //desired language's iso code + * + *@return response */ public static function changeLanguage($lang) { @@ -341,54 +342,55 @@ class UnAuthController extends Controller // dd() } else { return false; - } + } + return true; } // Follow up tickets public function followup() - { - $followup=Followup::whereId('1')->first(); - $condition=$followup->condition; + { + $followup = Followup::whereId('1')->first(); + $condition = $followup->condition; // dd($condition); switch ($condition) { - case "everyMinute": - $followup_set= ' + 1 minute'; + case 'everyMinute': + $followup_set = ' + 1 minute'; break; - case "everyFiveMinutes": - $followup_set= ' + 5 minute'; + case 'everyFiveMinutes': + $followup_set = ' + 5 minute'; break; - case "everyTenMinutes": - $followup_set= ' + 10 minute'; + case 'everyTenMinutes': + $followup_set = ' + 10 minute'; break; - case "everyThirtyMinutes": - $followup_set=' + 30 minute'; + case 'everyThirtyMinutes': + $followup_set = ' + 30 minute'; break; - case "hourly": - $followup_set=' + 1 hours'; + case 'hourly': + $followup_set = ' + 1 hours'; break; - case "daily": - $followup_set=' + 1 day'; + case 'daily': + $followup_set = ' + 1 day'; break; - case "weekly": - $followup_set=' + 7 day'; + case 'weekly': + $followup_set = ' + 7 day'; break; - case "monthly": - $followup_set=' + 30 day'; + case 'monthly': + $followup_set = ' + 30 day'; break; - case "yearly": - $followup_set=' + 365 day'; + case 'yearly': + $followup_set = ' + 365 day'; break; } - if($followup->status=1){ - $tickets=Tickets::where('id', '>=', 1)->where('status', '!=', 5)->get(); + 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) { + foreach ($tickets as $ticket) { // $id=1; // $id++; // $ticket=Tickets::where('status', '!=', 5)->get(); @@ -396,27 +398,20 @@ class UnAuthController extends Controller // dd($ticket); // if($ticket != null){ // dd('here'); - $ck=date('Y-m-d H:i:s', strtotime($ticket->updated_at . $followup_set)); + $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; + $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) - // {dd($ticket);} - - } + // {dd($ticket);} } - - } - - + } + } } - diff --git a/app/Http/Controllers/Client/kb/UserController.php b/app/Http/Controllers/Client/kb/UserController.php index 0cac42f8b..e514f486c 100644 --- a/app/Http/Controllers/Client/kb/UserController.php +++ b/app/Http/Controllers/Client/kb/UserController.php @@ -24,9 +24,10 @@ use Lang; use Mail; use Redirect; -class UserController extends Controller { - - public function __construct() { +class UserController extends Controller +{ + public function __construct() + { $this->middleware('board'); } @@ -35,18 +36,20 @@ class UserController extends Controller { * * @return response */ - public function getArticle(Article $article, Category $category, Settings $settings) { + public function getArticle(Article $article, Category $category, Settings $settings) + { $setting = $settings->first(); $pagination = $setting->pagination; if (!Auth::check() || \Auth::user()->role == 'user') { $article = $article->where('status', '1'); } $article = $article->where('type', '1'); - $article = $article->orderBy('publish_time','desc'); + $article = $article->orderBy('publish_time', 'desc'); $article = $article->paginate($pagination); - + $article->setPath('article-list'); $categorys = $category->get(); + return view('themes.default1.client.kb.article-list.articles', compact('time', 'categorys', 'article')); } @@ -59,7 +62,8 @@ class UserController extends Controller { * * @return string excerpt */ - public static function getExcerpt($str, $startPos = 0, $maxLength = 50) { + public static function getExcerpt($str, $startPos = 0, $maxLength = 50) + { if (strlen($str) > $maxLength) { $excerpt = substr($str, $startPos, $maxLength - 3); $lastSpace = strrpos($excerpt, ' '); @@ -82,13 +86,14 @@ class UserController extends Controller { * * @return type view */ - public function search(SearchRequest $request, Category $category, Article $article, Settings $settings) { + public function search(SearchRequest $request, Category $category, Article $article, Settings $settings) + { $settings = $settings->first(); $pagination = $settings->pagination; $search = $request->input('s'); - $result = $article->where('name', 'LIKE', '%' . $search . '%') - ->orWhere('slug', 'LIKE', '%' . $search . '%') - ->orWhere('description', 'LIKE', '%' . $search . '%') + $result = $article->where('name', 'LIKE', '%'.$search.'%') + ->orWhere('slug', 'LIKE', '%'.$search.'%') + ->orWhere('description', 'LIKE', '%'.$search.'%') ->paginate($pagination); $result->setPath('search?s='.$search); $categorys = $category->get(); @@ -101,15 +106,16 @@ class UserController extends Controller { * * @return response */ - public function show($slug, Article $article, Category $category) { + public function show($slug, Article $article, Category $category) + { //ArticleController::timezone(); $tz = \App\Model\helpdesk\Settings\System::where('id', '1')->first()->time_zone; $tz = \App\Model\helpdesk\Utility\Timezones::where('id', $tz)->first()->name; date_default_timezone_set($tz); $date = \Carbon\Carbon::now()->toDateTimeString(); $arti = $article->where('slug', $slug); - - if (!Auth::check()|| \Auth::user()->role == 'user') { + + if (!Auth::check() || \Auth::user()->role == 'user') { $arti = $arti->where('status', '1'); $arti = $arti->where('publish_time', '<', $date); } @@ -125,7 +131,8 @@ class UserController extends Controller { } } - public function getCategory($slug, Article $article, Category $category, Relationship $relation) { + public function getCategory($slug, Article $article, Category $category, Relationship $relation) + { /* get the article_id where category_id == current category */ $catid = $category->where('slug', $slug)->first(); if (!$catid) { @@ -141,7 +148,8 @@ class UserController extends Controller { return view('themes.default1.client.kb.article-list.category', compact('all', 'id', 'categorys', 'article_id')); } - public function home(Article $article, Category $category, Relationship $relation) { + public function home(Article $article, Category $category, Relationship $relation) + { if (Config::get('database.install') == '%0%') { return redirect('step1'); } else { @@ -153,7 +161,8 @@ class UserController extends Controller { } } - public function Faq(Faq $faq, Category $category) { + public function Faq(Faq $faq, Category $category) + { $faq = $faq->where('id', '1')->first(); $categorys = $category->get(); @@ -165,7 +174,8 @@ class UserController extends Controller { * * @return response */ - public function contact(Category $category, Settings $settings) { + public function contact(Category $category, Settings $settings) + { $settings = $settings->whereId('1')->first(); $categorys = $category->get(); @@ -177,7 +187,8 @@ class UserController extends Controller { * * @return response */ - public function postContact(ContactRequest $request, Contact $contact) { + public function postContact(ContactRequest $request, Contact $contact) + { $this->port(); $this->host(); $this->encryption(); @@ -195,8 +206,8 @@ class UserController extends Controller { //echo $message; //echo $contact->email; $mail = Mail::send('themes.default1.client.kb.article-list.contact-details', ['name' => $name, 'email' => $email, 'subject' => $subject, 'details' => $details], function ($message) use ($contact) { - $message->to($contact->email, $contact->name)->subject('Contact'); - }); + $message->to($contact->email, $contact->name)->subject('Contact'); + }); if ($mail) { return redirect('contact')->with('success', Lang::get('lang.your_details_send_to_system')); } else { @@ -204,7 +215,8 @@ class UserController extends Controller { } } - public function contactDetails() { + public function contactDetails() + { return view('themes.default1.client.kb.article-list.contact-details'); } @@ -218,10 +230,11 @@ class UserController extends Controller { * * @return type response */ - public function postComment($slug, Article $article, CommentRequest $request, Comment $comment) { + public function postComment($slug, Article $article, CommentRequest $request, Comment $comment) + { $article = $article->where('slug', $slug)->first(); - if(!$article){ - return Redirect::back()->with('fails', Lang::get('lang.sorry_not_processed')); + if (!$article) { + return Redirect::back()->with('fails', Lang::get('lang.sorry_not_processed')); } $id = $article->id; $comment->article_id = $id; @@ -232,42 +245,49 @@ class UserController extends Controller { } } - public function getPage($name, Page $page) { + public function getPage($name, Page $page) + { $page = $page->where('slug', $name)->first(); - if($page){ + if ($page) { return view('themes.default1.client.kb.article-list.pages', compact('page')); - }else{ + } else { return Redirect::back()->with('fails', Lang::get('lang.sorry_not_processed')); } } - public static function port() { + public static function port() + { $setting = Settings::whereId('1')->first(); Config::set('mail.port', $setting->port); } - public static function host() { + public static function host() + { $setting = Settings::whereId('1')->first(); Config::set('mail.host', $setting->host); } - public static function encryption() { + public static function encryption() + { $setting = Settings::whereId('1')->first(); Config::set(['mail.encryption' => $setting->encryption, 'mail.username' => $setting->email]); } - public static function email() { + public static function email() + { $setting = Settings::whereId('1')->first(); Config::set(['mail.from' => ['address' => $setting->email, 'name' => 'asd']]); //dd(Config::get('mail')); } - public static function password() { + public static function password() + { $setting = Settings::whereId('1')->first(); Config::set(['mail.password' => $setting->password, 'mail.sendmail' => $setting->email]); } - public function getCategoryList(Article $article, Category $category, Relationship $relation) { + public function getCategoryList(Article $article, Category $category, Relationship $relation) + { //$categorys = $category->get(); $categorys = $category->get(); // $categorys->setPath('home'); @@ -289,13 +309,15 @@ class UserController extends Controller { // //return substr($date, 0, -6); // } - public function clientProfile() { + public function clientProfile() + { $user = Auth::user(); return view('themes.default1.client.kb.article-list.profile', compact('user')); } - public function postClientProfile($id, ProfileRequest $request) { + public function postClientProfile($id, ProfileRequest $request) + { $user = Auth::user(); $user->gender = $request->input('gender'); $user->save(); @@ -314,7 +336,7 @@ class UserController extends Controller { //$extension = Input::file('profile_pic')->getClientOriginalExtension(); $name = Input::file('profile_pic')->getClientOriginalName(); $destinationPath = 'lb-faveo/dist/img'; - $fileName = rand(0000, 9999) . '.' . $name; + $fileName = rand(0000, 9999).'.'.$name; //echo $fileName; Input::file('profile_pic')->move($destinationPath, $fileName); $user->profile_pic = $fileName; @@ -328,7 +350,8 @@ class UserController extends Controller { } } - public function postClientProfilePassword($id, ProfilePassword $request) { + public function postClientProfilePassword($id, ProfilePassword $request) + { $user = Auth::user(); //echo $user->password; if (Hash::check($request->input('old_password'), $user->getAuthPassword())) { @@ -340,5 +363,4 @@ class UserController extends Controller { return redirect()->back()->with('fails', Lang::get('lang.password_was_not_updated')); } } - } diff --git a/app/Http/Controllers/Common/ExcelController.php b/app/Http/Controllers/Common/ExcelController.php index 0c92296ef..215c8e993 100644 --- a/app/Http/Controllers/Common/ExcelController.php +++ b/app/Http/Controllers/Common/ExcelController.php @@ -2,23 +2,21 @@ namespace App\Http\Controllers\Common; -use Illuminate\Http\Request; -use App\Http\Requests; use App\Http\Controllers\Controller; use Excel; use Exception; -class ExcelController extends Controller { - - public function export($filename, $data) { - if(count($data)==0){ +class ExcelController extends Controller +{ + public function export($filename, $data) + { + if (count($data) == 0) { throw new Exception('No data'); } - Excel::create($filename, function($excel) use($data){ - $excel->sheet('sheet', function($sheet) use($data) { + Excel::create($filename, function ($excel) use ($data) { + $excel->sheet('sheet', function ($sheet) use ($data) { $sheet->fromArray($data); }); })->export('xls'); } - } diff --git a/app/Http/Controllers/Common/FileuploadController.php b/app/Http/Controllers/Common/FileuploadController.php index 935dd4251..e1b57a815 100644 --- a/app/Http/Controllers/Common/FileuploadController.php +++ b/app/Http/Controllers/Common/FileuploadController.php @@ -4,9 +4,10 @@ namespace App\Http\Controllers\Common; use App\Http\Controllers\Controller; -class FileuploadController extends Controller { - - public function __construct() { +class FileuploadController extends Controller +{ + public function __construct() + { // checking authentication $this->middleware('auth'); // checking if role is agent @@ -15,7 +16,8 @@ class FileuploadController extends Controller { // Returns a file size limit in bytes based on the PHP upload_max_filesize // and post_max_size - function file_upload_max_size() { + public function file_upload_max_size() + { static $max_size = -1; if ($max_size < 0) { @@ -31,11 +33,13 @@ class FileuploadController extends Controller { $max_size_in_actual = ini_get('upload_max_filesize'); } } + return ['0' => $max_size_in_bytes, '1' => $max_size_in_actual]; // return $max_size_in_bytes; } - function parse_size($size) { + public function parse_size($size) + { $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size. $size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size. if ($unit) { @@ -45,5 +49,4 @@ class FileuploadController extends Controller { return round($size); } } - } diff --git a/app/Http/Controllers/Common/NotificationController.php b/app/Http/Controllers/Common/NotificationController.php index 41167da8d..1ab7058b1 100644 --- a/app/Http/Controllers/Common/NotificationController.php +++ b/app/Http/Controllers/Common/NotificationController.php @@ -4,33 +4,32 @@ namespace App\Http\Controllers\Common; use App\Http\Controllers\Controller; use App\Model\helpdesk\Notification\Notification; +use App\Model\helpdesk\Notification\NotificationType; use App\Model\helpdesk\Notification\UserNotification; use App\Model\helpdesk\Ticket\Tickets; -use App\Model\helpdesk\Ticket\Ticket_Thread; use App\User; -use App\Model\helpdesk\Notification\NotificationType; - -class NotificationController extends Controller { +class NotificationController extends Controller +{ /** - * ******************************************** + * ******************************************** * Class Notification Controller * ******************************************** * This controller is used to generate in app notification - * under the folling occurrence + * under the folling occurrence * 1. Ticket Creation * 2. Ticket Reply - * 3. User Creation - * + * 3. User Creation. + * * @author Ladybird */ public $user; /** - * Constructor + * Constructor. */ - public function __construct() { - + public function __construct() + { $user = new User(); $this->user = $user; // checking authentication @@ -41,6 +40,7 @@ class NotificationController extends Controller { /** * This function is used to create in app notifications. + * * @param type $model_id * @param type $userid_created * @param type $type_id @@ -68,49 +68,62 @@ class NotificationController extends Controller { } /** - * This function is to mark all ticket to read status + * This function is to mark all ticket to read status. + * * @param type $id + * * @return int */ - public function markAllRead($id) { + public function markAllRead($id) + { $markasread = UserNotification::where('user_id', '=', \Auth::user()->id)->where('is_read', '=', '0')->get(); foreach ($markasread as $mark) { $mark->is_read = '1'; $mark->save(); } + return 1; } /** - * This function to mark read + * This function to mark read. + * * @param type $id + * * @return int */ - public function markRead($id) { + public function markRead($id) + { $markasread = UserNotification::where('notification_id', '=', $id)->where('user_id', '=', \Auth::user()->id)->where('is_read', '=', '0')->get(); foreach ($markasread as $mark) { $mark->is_read = '1'; $mark->save(); } + return 1; } /** - * function to show all the notifications + * function to show all the notifications. + * * @return type */ - public function show() { + public function show() + { $notifications = $this->getNotifications(); //dd($notifications); return view('notifications-all', compact('notifications')); } /** - * function to delete notifications + * function to delete notifications. + * * @param type $id + * * @return int */ - public function delete($id) { + public function delete($id) + { $markasread = UserNotification::where('notification_id', '=', $id)->where('user_id', '=', \Auth::user()->id)->get(); foreach ($markasread as $mark) { $mark->delete(); @@ -119,36 +132,40 @@ class NotificationController extends Controller { return 1; } - public function deleteAll() { - try{ - $notifications = new Notification(); - if ($notifications->count()>0) { - foreach ($notifications->get() as $notification) { - $notification->delete(); + public function deleteAll() + { + try { + $notifications = new Notification(); + if ($notifications->count() > 0) { + foreach ($notifications->get() as $notification) { + $notification->delete(); + } } - } - $notifications->dummyDelete(); - return redirect()->back()->with('success', 'deleted'); - } catch (\Exception $ex){ - return redirect()->back()->with('fails',$ex->getMessage()); + $notifications->dummyDelete(); + + return redirect()->back()->with('success', 'deleted'); + } catch (\Exception $ex) { + return redirect()->back()->with('fails', $ex->getMessage()); } } /** * get the page to list the notifications. + * * @return response */ - public static function getNotifications() { + public static function getNotifications() + { $notifications = UserNotification::with([ - 'notification.type' => function($query) { + 'notification.type' => function ($query) { $query->select('id', 'message', 'type'); - }, 'users' => function($query) { + }, 'users' => function ($query) { $query->select('id', 'email', 'profile_pic'); - }, 'notification.model' => function($query) { + }, 'notification.model' => function ($query) { $query->select('id', 'ticket_number'); }, ]); + return $notifications; } - } diff --git a/app/Http/Controllers/Common/PhpMailController.php b/app/Http/Controllers/Common/PhpMailController.php index 84e4f730b..015aa62cc 100644 --- a/app/Http/Controllers/Common/PhpMailController.php +++ b/app/Http/Controllers/Common/PhpMailController.php @@ -10,14 +10,16 @@ use App\Model\helpdesk\Settings\Company; use App\Model\helpdesk\Settings\Email; use App\User; use Auth; -use Mail; use Exception; use Lang; +use Mail; -class PhpMailController extends Controller { - - public function fetch_smtp_details($id) { +class PhpMailController extends Controller +{ + public function fetch_smtp_details($id) + { $emails = Emails::where('id', '=', $id)->first(); + return $emails; } @@ -26,7 +28,8 @@ class PhpMailController extends Controller { * * @return type */ - public function company() { + public function company() + { $company = Company::Where('id', '=', '1')->first(); if ($company->company_name == null) { $company = 'Support Center'; @@ -45,8 +48,9 @@ class PhpMailController extends Controller { * * @return type integer */ - public function mailfrom($reg, $dept_id) { - $email_id = ""; + public function mailfrom($reg, $dept_id) + { + $email_id = ''; $emails = Emails::where('department', '=', $dept_id)->first(); $email = Email::find(1); @@ -55,17 +59,19 @@ class PhpMailController extends Controller { } else { $email_id = $email->sys_email; } + return $email_id; } - public function sendmail($from, $to, $message, $template_variables) { + public function sendmail($from, $to, $message, $template_variables) + { $this->setQueue(); $job = new \App\Jobs\SendEmail($from, $to, $message, $template_variables); $this->dispatch($job); } - public function sendEmail($from, $to, $message, $template_variables) { - + public function sendEmail($from, $to, $message, $template_variables) + { $from_address = $this->fetch_smtp_details($from); if ($from_address == null) { throw new Exception(Lang::get('lang.system-email-not-configured')); @@ -96,11 +102,11 @@ class PhpMailController extends Controller { $ticket_link_with_number = $this->checkElement('ticket_link_with_number', $template_variables); $system_from = $this->checkElement('system_from', $template_variables); - if ($system_from === "") { + if ($system_from === '') { $system_from = $this->company(); } $system_link = $this->checkElement('system_link', $template_variables); - if ($system_link === "") { + if ($system_link === '') { $system_link = \Config::get('app.url'); } $ticket_link = $this->checkElement('ticket_link', $template_variables); @@ -113,7 +119,6 @@ class PhpMailController extends Controller { $email_address = $this->checkElement('email_address', $template_variables); $user = $this->checkElement('user', $template_variables); - $status = \DB::table('settings_email')->first(); $template = TemplateType::where('name', '=', $template_type)->first(); @@ -127,7 +132,7 @@ class PhpMailController extends Controller { if ($template_data->subject) { $subject = $template_data->subject; if ($ticket_number != null) { - $subject = $subject . ' [#' . $ticket_number . ']'; + $subject = $subject.' [#'.$ticket_number.']'; } } else { $subject = $message['subject']; @@ -140,7 +145,6 @@ class PhpMailController extends Controller { $subject = null; } - $variables = ['{!!$user!!}', '{!!$agent!!}', '{!!$ticket_number!!}', '{!!$content!!}', '{!!$from!!}', '{!!$ticket_agent_name!!}', '{!!$ticket_client_name!!}', '{!!$ticket_client_email!!}', '{!!$ticket_body!!}', '{!!$ticket_assigner!!}', '{!!$ticket_link_with_number!!}', '{!!$system_error!!}', '{!!$agent_sign!!}', '{!!$department_sign!!}', '{!!$password_reset_link!!}', '{!!$email_address!!}', '{!!$user_password!!}', '{!!$system_from!!}', '{!!$system_link!!}', '{!!$ticket_link!!}']; $data = [$user, $agent, $ticket_number, $content, $from, $ticket_agent_name, $ticket_client_name, $ticket_client_email, $ticket_body, $ticket_assigner, $ticket_link_with_number, $system_error, $agent_sign, $department_sign, $password_reset_link, $email_address, $user_password, $system_from, $system_link, $ticket_link]; @@ -150,20 +154,20 @@ class PhpMailController extends Controller { $contents = $messagebody; } - if ($template_type == 'ticket-reply-agent') { $line = '---Reply above this line---

    '; - $content = $line . $messagebody; + $content = $line.$messagebody; } else { $content = $messagebody; } } $send = $this->laravelMail($recipants, $recipantname, $subject, $content, $cc, $attachment); + return $send; } - public function setMailConfig($from_address) { - + public function setMailConfig($from_address) + { $username = $from_address->email_address; $fromname = $from_address->email_name; $password = $from_address->password; @@ -180,88 +184,94 @@ class PhpMailController extends Controller { $port = ''; } $configs = [ - 'username' => $username, - 'from' => ['address' => $username, 'name' => $fromname,], - 'password' => $password, + 'username' => $username, + 'from' => ['address' => $username, 'name' => $fromname], + 'password' => $password, 'encryption' => $smtpsecure, - 'host' => $host, - 'port' => $port, - 'driver' => $protocol, + 'host' => $host, + 'port' => $port, + 'driver' => $protocol, ]; foreach ($configs as $key => $config) { if (is_array($config)) { foreach ($config as $from) { - \Config::set('mail.' . $key, $config); + \Config::set('mail.'.$key, $config); } } else { - \Config::set('mail.' . $key, $config); + \Config::set('mail.'.$key, $config); } } } - public function setServices($emailid, $protocol) { + public function setServices($emailid, $protocol) + { $service = new \App\Model\MailJob\FaveoMail(); $services = $service->where('email_id', $emailid)->lists('value', 'key')->toArray(); $controller = new \App\Http\Controllers\Admin\helpdesk\EmailsController(); $controller->setServiceConfig($protocol, $services); } - public function checkElement($element, $array) { - $value = ""; + public function checkElement($element, $array) + { + $value = ''; if (is_array($array)) { - if (key_exists($element, $array)) { + if (array_key_exists($element, $array)) { $value = $array[$element]; } } + return $value; } - public function laravelMail($to, $toname, $subject, $data, $cc, $attach) { + public function laravelMail($to, $toname, $subject, $data, $cc, $attach) + { //dd($to, $toname, $subject, $data, $cc, $attach); //dd(\Config::get('mail')); //dd($attach); $mail = Mail::send('emails.mail', ['data' => $data], function ($m) use ($to, $subject, $toname, $cc, $attach) { - $m->to($to, $toname)->subject($subject); + $m->to($to, $toname)->subject($subject); - if ($cc != null) { - foreach ($cc as $collaborator) { - //mail to collaborators + if ($cc != null) { + foreach ($cc 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; - $m->cc($collab_email); - } - } + $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); - if ($size > 0) { - for ($i = 0; $i < $size; $i++) { - if (is_array($attach) && array_key_exists($i, $attach)) { - $mode = 'normal'; - if (is_array($attach[$i]) && array_key_exists('mode', $attach[$i])) { - $mode = $attach[$i]['mode']; - } - $file = $attach[$i]['file_path']; - $name = $attach[$i]['file_name']; - $mime = $attach[$i]['mime']; - $this->attachmentMode($m, $file, $name, $mime, $mode); - } + if ($size > 0) { + for ($i = 0; $i < $size; $i++) { + if (is_array($attach) && array_key_exists($i, $attach)) { + $mode = 'normal'; + if (is_array($attach[$i]) && array_key_exists('mode', $attach[$i])) { + $mode = $attach[$i]['mode']; } + $file = $attach[$i]['file_path']; + $name = $attach[$i]['file_name']; + $mime = $attach[$i]['mime']; + $this->attachmentMode($m, $file, $name, $mime, $mode); } - }); + } + } + }); if (is_object($mail) || (is_object($mail) && $mail->getStatusCode() == 200)) { $mail = 1; } + return $mail; } - public function setQueue() { + public function setQueue() + { $short = 'database'; $field = [ 'driver' => 'database', - 'table' => 'jobs', - 'queue' => 'default', + 'table' => 'jobs', + 'queue' => 'default', 'expire' => 60, ]; $queue = new \App\Model\MailJob\QueueService(); @@ -274,18 +284,20 @@ class PhpMailController extends Controller { $this->setQueueConfig($short, $field); } - public function setQueueConfig($short, $field) { + public function setQueueConfig($short, $field) + { \Config::set('queue.default', $short); foreach ($field as $key => $value) { \Config::set("queue.connections.$short.$key", $value); } } - public function attachmentMode($message, $file, $name, $mime, $mode) { + public function attachmentMode($message, $file, $name, $mime, $mode) + { if ($mode == 'data') { return $message->attachData(base64_decode($file, true), $name, ['mime' => $mime]); } + return $message->attach($file, ['as' => $name, 'mime' => $mime]); } - } diff --git a/app/Http/Controllers/Common/SettingsController.php b/app/Http/Controllers/Common/SettingsController.php index efe29229a..c60896ba7 100644 --- a/app/Http/Controllers/Common/SettingsController.php +++ b/app/Http/Controllers/Common/SettingsController.php @@ -11,7 +11,6 @@ use App\Model\helpdesk\Email\Smtp; // models use App\Model\helpdesk\Settings\Plugin; use App\Model\helpdesk\Theme\Widgets; -use App\Model\helpdesk\Utility\Version_Check; use Config; // classes use Crypt; @@ -27,14 +26,15 @@ use Lang; * *************************** * Controller to keep smtp details and fetch where ever needed. */ -class SettingsController extends Controller { - +class SettingsController extends Controller +{ /** * Create a new controller instance. * * @return type void */ - public function __construct() { + public function __construct() + { $this->middleware('auth'); $this->middleware('roles'); } @@ -44,7 +44,8 @@ class SettingsController extends Controller { * * @return response */ - public function widgets() { + public function widgets() + { return view('themes.default1.admin.helpdesk.theme.widgets'); } @@ -53,7 +54,8 @@ class SettingsController extends Controller { * * @return response */ - public function list_widget() { + public function list_widget() + { return \Datatable::collection(Widgets::where('id', '<', '7')->get()) ->searchColumns('name') ->orderColumns('name', 'title', 'value') @@ -67,33 +69,33 @@ class SettingsController extends Controller { return $model->value; }) ->addColumn('Actions', function ($model) { - return '' . \Lang::get('lang.edit') . ' -