diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index f191a0fb6..dcc0edcea 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -76,7 +76,7 @@ class Handler extends ExceptionHandler { return parent::render($request, $e); } - + protected function renderExceptionWithWhoops(Exception $e) diff --git a/app/Http/Controllers/API/helpdesk/InstallerApiController.php b/app/Http/Controllers/API/helpdesk/InstallerApiController.php new file mode 100644 index 000000000..35480184d --- /dev/null +++ b/app/Http/Controllers/API/helpdesk/InstallerApiController.php @@ -0,0 +1,177 @@ + + * + */ +class InstallerApiController extends Controller { + + /** + * config_database + * This function is to configure the database and install the application via API call. + * @return type Json + */ + public function config_database(Request $request) { + error_reporting(E_ALL & ~E_NOTICE); + + // Check for pre install + if (\Config::get('database.install') == '%0%') { + + $default = $request->database; + $host = $request->host; + $database = $request->databasename; + $dbusername = $request->dbusername; + $dbpassword = $request->dbpassword; + $port = $request->port; + + if(isset($default) && isset($host) && isset($database) && isset($dbusername)){ + + // Setting environment values + $_ENV['DB_TYPE'] = $default; + $_ENV['DB_HOST'] = $host; + $_ENV['DB_PORT'] = $port; + $_ENV['DB_DATABASE'] = $database; + $_ENV['DB_USERNAME'] = $dbusername; + $_ENV['DB_PASSWORD'] = $dbpassword; + + $config = ''; + foreach ($_ENV as $key => $val) { + $config .= "{$key}={$val}\n"; + } + + // Write environment file + $fp = fopen(base_path()."/.env", 'w'); + fwrite($fp, $config); + fclose($fp); + + return ['response'=>'success','status'=>'1']; + } else { + return ['response'=>'fail','reason'=>'insufficient parameters','status'=>'0']; + } + } else { + return ['response'=>'fail','reason'=>'this system is already installed','status'=>'0']; + } + } + + /** + * config_database + * This function is to configure the database and install the application via API call. + * @return type Json + */ + public function config_system(Request $request) { + error_reporting(E_ALL & ~E_NOTICE); + // Check for pre install + if (\Config::get('database.install') == '%0%') { + $firstname = $request->firstname; + $lastname = $request->lastname; + $email = $request->email; + $username = $request->username; + $password = $request->password; + $timezone = $request->timezone; + $datetime = $request->datetime; + + // Migrate database + Artisan::call('migrate', array('--force' => true)); + Artisan::call('db:seed', array('--force' => true)); + + // Creating minum settings + $system = System::where('id','=','1')->first(); + $system->time_zone = $timezone; + $system->date_time_format = $datetime; + $system->save(); + + // Creating default form field + $form1 = new Form_details; + $form1->label = 'Name'; + $form1->type = 'text'; + $form1->form_name_id = '1'; + $form1->save(); + + $form2 = new Form_details; + $form2->label = 'Phone'; + $form2->type = 'number'; + $form2->form_name_id = '1'; + $form2->save(); + + $form3 = new Form_details; + $form3->label = 'Email'; + $form3->type = 'text'; + $form3->form_name_id = '1'; + $form3->save(); + + $form4 = new Form_details; + $form4->label = 'Subject'; + $form4->type = 'text'; + $form4->form_name_id = '1'; + $form4->save(); + + $form5 = new Form_details; + $form5->label = 'Details'; + $form5->type = 'textarea'; + $form5->form_name_id = '1'; + $form5->save(); + + // Creating user + $user = User::create(array( + 'first_name' => $firstname, + 'last_name' => $lastname, + 'email' => $email, + 'user_name' => $username, + 'password' => Hash::make($password), + 'active' => 1, + 'role' => 'admin', + 'assign_group' => 'group A', + 'primary_dpt' => 'support', + )); + + // Setting database installed status + $value = '1'; + $install = app_path('../config/database.php'); + $datacontent = File::get($install); + $datacontent = str_replace('%0%', $value, $datacontent); + File::put($install, $datacontent); + + // Applying email configuration on route + $smtpfilepath = "\App\Http\Controllers\Common\SettingsController::smtp()"; + $path22 = app_path('Http/routes.php'); + $content23 = File::get($path22); + $content23 = str_replace('"%smtplink%"', $smtpfilepath, $content23); + File::put($path22, $content23); + + // If user created return success + if($user){ + return ['response'=>'success','status'=>'1']; + } + } else { + return ['response'=>'fail','reason'=>'this system is already installed','status'=>'0']; + } + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Agent/helpdesk/TicketController.php b/app/Http/Controllers/Agent/helpdesk/TicketController.php index 62a54382d..9d0c1edea 100644 --- a/app/Http/Controllers/Agent/helpdesk/TicketController.php +++ b/app/Http/Controllers/Agent/helpdesk/TicketController.php @@ -300,7 +300,6 @@ class TicketController extends Controller { * @param type TicketRequest $request * @return type bool */ - public function reply(Ticket_Thread $thread, TicketRequest $request, Ticket_attachments $ta ) { $attachments = $request->file('attachment'); $check_attachment = null; @@ -634,13 +633,16 @@ class TicketController extends Controller { if(Alert::first()->ticket_status == 1 || Alert::first()->ticket_department_member == 1) { // send email to agents $agents = User::where('role','=','agent')->get(); + // dd($agents); foreach($agents as $agent) { - if($ticketdata->dept_id == $agent->primary_dpt) + $department_data = Department::where('id','=',$ticketdata->dept_id)->first(); + + if($department_data->name == $agent->primary_dpt) { $agent_email = $agent->email; $agent_user = $agent->first_name; - Mail::send('emails.'.$mail, ['agent' => $agent_user, 'ticket_number' => $ticket_number2, 'from'=>$company, 'email' => $emailadd, 'name' => $ticket_creator, 'system' => $system], function ($message) use ($agent_email, $agent_user, $ticket_number2, $updated_subject) { + Mail::send('emails.'.$mail, ['agent' => $agent_user ,'content'=>$body , 'ticket_number' => $ticket_number2, 'from'=>$company, 'email' => $emailadd, 'name' => $ticket_creator, 'system' => $system], function ($message) use ($agent_email, $agent_user, $ticket_number2, $updated_subject) { $message->to($agent_email, $agent_user)->subject($updated_subject); }); } @@ -712,12 +714,9 @@ class TicketController extends Controller { $user_name = User::where('id','=', $user_id)->first(); - if($user_name->role == 'user' ) - { + if($user_name->role == 'user' ) { $username = $user_name->user_name; - } - elseif($user_name->role == 'agent' or $user_name->role == 'admin') - { + } elseif($user_name->role == 'agent' or $user_name->role == 'admin') { $username = $user_name->first_name . " " . $user_name->last_name; } @@ -756,12 +755,9 @@ class TicketController extends Controller { */ public function create_ticket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data) { $max_number = Tickets::whereRaw('id = (select max(`id`) from tickets)')->first(); - if($max_number == null) - { + if($max_number == null) { $ticket_number = "AAAA-9999-9999999"; - } - else - { + } else { foreach ($max_number as $number) { $ticket_number = $max_number->ticket_number; } @@ -798,11 +794,9 @@ class TicketController extends Controller { } } } - - // store collaborators + // dd($headers); $this->store_collaborators($headers, $id); - if ($this->ticket_thread($subject, $body, $id, $user_id) == true) { return $ticket_number; } diff --git a/app/Http/Controllers/Installer/helpdesk/InstallController.php b/app/Http/Controllers/Installer/helpdesk/InstallController.php index 6beb9c0b6..955356555 100644 --- a/app/Http/Controllers/Installer/helpdesk/InstallController.php +++ b/app/Http/Controllers/Installer/helpdesk/InstallController.php @@ -33,15 +33,14 @@ use View; */ class InstallController extends Controller { - /** - * Get Licence (step 1) - * @return type view - */ + /** + * Get Licence (step 1) + * @return type view + */ public function licence() { if (Session::get('step5') == 'step5') { return Redirect::route('account'); } - if (Config::get('database.install') == '%0%') { return view('themes/default1/installer/helpdesk/view1'); } else { @@ -50,10 +49,10 @@ class InstallController extends Controller { } } - /** - * Post Licencecheck - * @return type view - */ + /** + * Post Licencecheck + * @return type view + */ public function licencecheck() { $accept = (Input::has('accept1')) ? true : false; if ($accept == 'accept') { @@ -65,13 +64,13 @@ class InstallController extends Controller { // return 1; } - /** - * Get prerequisites (step 2) - * - * Checking the extensions enabled required for installing the faveo - * without which the project cannot be executed properly - * @return type view - */ + /** + * Get prerequisites (step 2) + * + * Checking the extensions enabled required for installing the faveo + * without which the project cannot be executed properly + * @return type view + */ public function prerequisites() { if (Session::get('step5') == 'step5') { return Redirect::route('account'); @@ -87,21 +86,21 @@ class InstallController extends Controller { } } - /** - * Post Prerequisitescheck - * checking prerequisites - * @return type view - */ + /** + * Post Prerequisitescheck + * checking prerequisites + * @return type view + */ public function prerequisitescheck() { Session::put('step2', 'step2'); return Redirect::route('configuration'); } - /** - * Get Localization (step 3) - * Requesting user recomended settings for installation - * @return type view - */ + /** + * Get Localization (step 3) + * Requesting user recomended settings for installation + * @return type view + */ public function localization() { if (Session::get('step5') == 'step5') { return Redirect::route('account'); @@ -117,11 +116,11 @@ class InstallController extends Controller { } } - /** - * Post localizationcheck - * checking prerequisites - * @return type view - */ + /** + * Post localizationcheck + * checking prerequisites + * @return type view + */ public function localizationcheck() { Session::put('step3', 'step3'); @@ -134,11 +133,11 @@ class InstallController extends Controller { return Redirect::route('configuration'); } - /** - * Get Configuration (step 4) - * checking prerequisites - * @return type view - */ + /** + * Get Configuration (step 4) + * checking prerequisites + * @return type view + */ public function configuration() { if (Session::get('step5') == 'step5') { return Redirect::route('account'); @@ -154,11 +153,11 @@ class InstallController extends Controller { } } - /** - * Post configurationcheck - * checking prerequisites - * @return type view - */ + /** + * Post configurationcheck + * checking prerequisites + * @return type view + */ public function configurationcheck() { Session::put('step4', 'step4'); @@ -186,145 +185,71 @@ class InstallController extends Controller { $dbpassword = Input::get('password'); $port = Input::get('port'); - // set default value - $path0 = app_path('../config/database.php'); - $content0 = File::get($path0); - $content0 = str_replace('%default%', $default, $content0); - File::put($path0, $content0); - // set host,databasename,username,password - if ($default == 'mysql') { - $path = app_path('../config/database.php'); - $content = File::get($path); - $content = str_replace('%host%', $host, $content); - File::put($path, $content); + // Setting environment values + $_ENV['DB_TYPE'] = $default; + $_ENV['DB_HOST'] = $host; + $_ENV['DB_PORT'] = $port; + $_ENV['DB_DATABASE'] = $database; + $_ENV['DB_USERNAME'] = $dbusername; + $_ENV['DB_PASSWORD'] = $dbpassword; - $path1 = app_path('../config/database.php'); - $content1 = File::get($path1); - $content1 = str_replace('%database%', $database, $content1); - File::put($path1, $content1); + $config = ''; + foreach ($_ENV as $key => $val) { + $config .= "{$key}={$val}\n"; + } + // Write environment file + $fp = fopen(base_path()."/.env", 'w'); + fwrite($fp, $config); + fclose($fp); - $path2 = app_path('../config/database.php'); - $content2 = File::get($path2); - $content2 = str_replace('%username%', $dbusername, $content2); - File::put($path2, $content2); - - $path3 = app_path('../config/database.php'); - $content3 = File::get($path3); - $content3 = str_replace('%password%', $dbpassword, $content3); - File::put($path3, $content3); - - $path4 = app_path('../config/database.php'); - $content4 = File::get($path4); - $content4 = str_replace('%port%', $port, $content4); - File::put($path4, $content4); - - } elseif ($default == 'pgsql') { - $path = app_path('../config/database.php'); - $content = File::get($path); - $content = str_replace('%host1%', $host, $content); - File::put($path, $content); - - $path1 = app_path('../config/database.php'); - $content1 = File::get($path1); - $content1 = str_replace('%database1%', $database, $content1); - File::put($path1, $content1); - - $path2 = app_path('../config/database.php'); - $content2 = File::get($path2); - $content2 = str_replace('%username1%', $username, $content2); - File::put($path2, $content2); - - $path3 = app_path('../config/database.php'); - $content3 = File::get($path3); - $content3 = str_replace('%password1%', $password, $content3); - File::put($path3, $content3); - - $path4 = app_path('../config/database.php'); - $content4 = File::get($path4); - $content4 = str_replace('%port1%', $port, $content4); - File::put($path4, $content4); - - } elseif ($default == 'sqlsrv') { - $path = app_path('../config/database.php'); - $content = File::get($path); - $content = str_replace('%host2%', $host, $content); - File::put($path, $content); - - $path1 = app_path('../config/database.php'); - $content1 = File::get($path1); - $content1 = str_replace('%database2%', $database, $content1); - File::put($path1, $content1); - - $path2 = app_path('../config/database.php'); - $content2 = File::get($path2); - $content2 = str_replace('%username2%', $username, $content2); - File::put($path2, $content2); - - $path3 = app_path('../config/database.php'); - $content3 = File::get($path3); - $content3 = str_replace('%password2%', $password, $content3); - File::put($path3, $content3); - - $path4 = app_path('../config/database.php'); - $content4 = File::get($path4); - $content4 = str_replace('%port2%', $port, $content4); - File::put($path4, $content4); - } return 1; } - /** - * Get database - * checking prerequisites - * @return type view - */ + /** + * Get database + * checking prerequisites + * @return type view + */ public function database() { - if (Config::get('database.install') == '%0%') { - if (Session::get('step4') == 'step4') { - return View::make('themes/default1/installer/helpdesk/view4'); - } else { - return Redirect::route('configuration'); - } + if (Config::get('database.install') == '%0%') { + if (Session::get('step4') == 'step4') { + return View::make('themes/default1/installer/helpdesk/view4'); } else { - return redirect('/auth/login'); + return Redirect::route('configuration'); } + } else { + return redirect('/auth/login'); + } } - /** - * Get account - * checking prerequisites - * @return type view - */ + /** + * Get account + * checking prerequisites + * @return type view + */ public function account() { - if (Config::get('database.install') == '%0%') { - if (Session::get('step4') == 'step4') { - Session::put('step5', 'step5'); - Session::forget('step1'); - Session::forget('step2'); - Session::forget('step3'); - return View::make('themes/default1/installer/helpdesk/view5'); - } else { - return Redirect::route('configuration'); - } + if (Config::get('database.install') == '%0%') { + if (Session::get('step4') == 'step4') { + Session::put('step5', 'step5'); + Session::forget('step1'); + Session::forget('step2'); + Session::forget('step3'); + return View::make('themes/default1/installer/helpdesk/view5'); } else { - return redirect('/auth/login'); + return Redirect::route('configuration'); } + } else { + return redirect('/auth/login'); + } } - /** - * Post accountcheck - * checking prerequisites - * @param type InstallerRequest $request - * @return type view - */ + /** + * Post accountcheck + * checking prerequisites + * @param type InstallerRequest $request + * @return type view + */ public function accountcheck(InstallerRequest $request) { - // dd($request); - // config/database.php management - $default = $request->input('default'); - $host = $request->input('host'); - $database = $request->input('databasename'); - $dbusername = $request->input('dbusername'); - $dbpassword = $request->input('dbpassword'); // migrate database Artisan::call('migrate', array('--force' => true)); @@ -347,7 +272,6 @@ class InstallController extends Controller { $system->date_time_format = $datetime; $system->save(); - $form1 = new Form_details; $form1->label = 'Name'; $form1->type = 'text'; @@ -396,17 +320,13 @@ class InstallController extends Controller { } } - /** - * Get finalize - * checking prerequisites - * @return type view - */ + /** + * Get finalize + * checking prerequisites + * @return type view + */ public function finalize() { if (Session::get('step6') == 'step6') { - // $var = "http://" . $_SERVER['HTTP_HOST'] . "/epeper-pdf"; - // $siteurl = Option::where('option_name', '=', 'siteurl')->first(); - // $siteurl->option_value = $var; - // $siteurl->save(); $value = '1'; $install = app_path('../config/database.php'); $datacontent = File::get($install); @@ -429,18 +349,16 @@ class InstallController extends Controller { } } - /** - * Post finalcheck - * checking prerequisites - * @return type view - */ + /** + * Post finalcheck + * checking prerequisites + * @return type view + */ public function finalcheck() { - try - { + try { return redirect('/auth/login'); } catch (Exception $e) { return redirect('/auth/login'); } } - -} +} \ No newline at end of file diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index abb4e4d9f..be9ae3c4f 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -21,6 +21,7 @@ class Kernel extends HttpKernel { 'Illuminate\Session\Middleware\StartSession', 'Illuminate\View\Middleware\ShareErrorsFromSession', //'App\Http\Middleware\VerifyCsrfToken', + 'App\Http\Middleware\LanguageMiddleware', ]; /** diff --git a/app/Http/routes.php b/app/Http/routes.php index c75f8b05f..f6b7b961e 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -1,6 +1,6 @@ get('getmail/{token}', 'Auth\AuthController@getMail'); /* |------------------------------------------------------------------------------- -|Admin Routes +| API Routes +|------------------------------------------------------------------------------- +| These routes are the API calls. +| + */ +Route::group(['prefix' => 'api'], function () { + + Route::get('/database-config',['as'=>'database-config','uses'=>'API\helpdesk\InstallerApiController@config_database']); + Route::get('/system-config',['as'=>'database-config','uses'=>'API\helpdesk\InstallerApiController@config_system']); + +}); + + + +/* +|------------------------------------------------------------------------------- +| Admin Routes |------------------------------------------------------------------------------- | Here is defining entire routes for the Admin Panel | @@ -401,7 +417,7 @@ Route::group(['middleware' => 'role.user', 'middleware' => 'auth'], function () Route::post('/step6post', ['as' => 'postaccount', 'uses' => 'Installer\helpdesk\InstallController@accountcheck']); Route::get('/final', ['as' => 'final','uses' => 'Installer\helpdesk\InstallController@finalize']); Route::post('/finalpost', ['as' => 'postfinal','uses' => 'Installer\helpdesk\InstallController@finalcheck']); - Route::patch('/postconnection', ['as' => 'postconnection','uses' => 'Installer\helpdesk\InstallController@postconnection']); + Route::post('/postconnection', ['as' => 'postconnection','uses' => 'Installer\helpdesk\InstallController@postconnection']); /* |============================================================= diff --git a/config/app.php b/config/app.php index 94455abee..53f37b040 100644 --- a/config/app.php +++ b/config/app.php @@ -38,7 +38,7 @@ return [ | */ - 'version' => 'COMMUNITY 1.0.4', + 'version' => 'COMMUNITY 1.0.4.1', /* |-------------------------------------------------------------------------- diff --git a/config/database.php b/config/database.php index 47460f80e..37b3424ac 100644 --- a/config/database.php +++ b/config/database.php @@ -25,7 +25,7 @@ return [ | */ - 'default' => '%default%', + 'default' => env('DB_TYPE', 'mysql'), /* |-------------------------------------------------------------------------- @@ -53,36 +53,37 @@ return [ 'mysql' => [ 'driver' => 'mysql', - 'host' => '%host%', - 'database' => '%database%', - 'username' => '%username%', - 'password' => '%password%', + 'host' => env('DB_HOST', 'localhost'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', - 'port' => '%port%', + 'port' => env('DB_PORT', ''), 'prefix' => '', 'strict' => false, ], 'pgsql' => [ 'driver' => 'pgsql', - 'host' => 'localhost', - 'database' => 'fav', - 'username' => '%username1%', - 'password' => '%password1%', - 'port' => '%port1%', + 'host' => env('DB_HOST', 'localhost'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'port' => env('DB_PORT', ''), 'charset' => 'utf8', 'prefix' => '', 'schema' => 'public', ], 'sqlsrv' => [ + 'driver' => 'sqlsrv', - 'host' => '%host2%', - 'database' => '%database2%', - 'username' => '%username2%', - 'password' => '%password2%', - 'port' => '%port2%', + 'host' => env('DB_HOST', 'localhost'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'port' => env('DB_PORT', ''), 'prefix' => '', ], diff --git a/resources/views/themes/default1/admin/helpdesk/setting.blade.php b/resources/views/themes/default1/admin/helpdesk/setting.blade.php index 7458a6068..dbe8b1a99 100644 --- a/resources/views/themes/default1/admin/helpdesk/setting.blade.php +++ b/resources/views/themes/default1/admin/helpdesk/setting.blade.php @@ -98,8 +98,7 @@