| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Http\Controllers\Installer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use App\User; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use App\Settings; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Carbon\Carbon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use App\Mail\TestEmail; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Illuminate\Support\Facades\Log; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Illuminate\Support\Facades\Auth; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Illuminate\Support\Facades\Mail; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use App\Http\Controllers\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Illuminate\Support\Facades\Route; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Illuminate\Support\Facades\Config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Illuminate\Support\Facades\Storage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Illuminate\Support\Facades\Artisan; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class SettingsController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 24 |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 24 |  |         $this->middleware(['auth', 'can:is_installer']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 24 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     //  Bring up the change logo form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 2 |  |     public function logoSettings() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 2 |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 2 |  |         return view('installer.logoSettings'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     //  Submit the new company logo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 2 |  |     public function submitLogo(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 2 |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name.'. Submitted Data - ', $request->toArray()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 2 |  |         $request->validate([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 2 |  |             'file' => 'mimes:jpeg,bmp,png,jpg,gif' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 2 |  |         $file     = $request->file; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 2 |  |         $fileName = $file->getClientOriginalName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 2 |  |         $file->storeAs('img', $fileName, 'public'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 2 |  |         Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 2 |  |             ['key'   => 'app.logo'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 2 |  |             ['key'   => 'app.logo', 'value' => '/storage/img/'.$fileName] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 2 |  |         )->update(['value' => '/storage/img/'.$fileName]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 2 |  |         Log::notice('A new company logo has been uploaded by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2 |  |         return response()->json(['url' => '/storage/img/'.$fileName]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 2 |  |     public function configuration() | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 | 2 |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 | 2 |  |         $settings = collect([ | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |             // 'url'      => config('app.url'), | 
            
                                                                        
                            
            
                                    
            
            
                | 62 | 2 |  |             'timezone' => config('app.timezone'), | 
            
                                                                        
                            
            
                                    
            
            
                | 63 | 2 |  |             'filesize' => config('filesystems.paths.max_size'), | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 | 2 |  |         return view('installer.configuration', [ | 
            
                                                                        
                            
            
                                    
            
            
                | 67 | 2 |  |             'timzone_list' => \Timezonelist::toArray(), | 
            
                                                                        
                            
            
                                    
            
            
                | 68 | 2 |  |             'settings'     => $settings, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 2 |  |     public function submitConfiguration(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 2 |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name.'. Submitted Data - ', $request->toArray()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 2 |  |         $request->validate([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 2 |  |             'timezone' => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             'filesize' => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             //  TODO - add additinal validation to make sure proper information is passed in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         //  Update the site timezone | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 2 |  |         if (config('app.timezone') !== $request->timezone) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 2 |  |             Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 2 |  |                 ['key'   => 'app.timezone'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 2 |  |                 ['key'   => 'app.timezone', 'value' => $request->timezone] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 2 |  |             )->update(['value' => $request->timezone]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         //  Update the maximum file upload size | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 2 |  |         if (config('filesystems.paths.max_size') !== $request->filesize) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 2 |  |             Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 2 |  |                 ['key'   => 'filesystems.paths.max_size'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 2 |  |                 ['key'   => 'filesystems.paths.max_size', 'value' => $request->filesize] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 2 |  |             )->update(['value' => $request->filesize]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 2 |  |         $request->session()->flash('success', 'Configuration Updated'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 2 |  |         return response()->json(['success' => true]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     //  System backups index page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     public function backupsIndex() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         return view('installer.backupsIndex'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     //  Retrieve the list of backups | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     public function getBackups() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $backups = Storage::disk('backup')->files(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $buArray = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         //  Filter list to include timestamp | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         foreach($backups as $backup) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             $parts = pathinfo($backup); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             if($parts['extension'] === 'zip') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                 $buArray[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                     'name' => $backup, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                     'date' => Carbon::createFromTimestamp(Storage::disk('backup')->lastModified($backup))->format('M d, Y h:m a'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         return $buArray; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     //  Delete a backup | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     public function delBackup($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         Storage::disk('backup')->delete($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         Log::notice('Backup '.$name.' deleted by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         return response()->json(['success' => true]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     //  Download a backup | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     public function downloadBackup($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         if(Storage::disk('backup')->exists($name)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             Log::info('Backup '.$name.' downloaded by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             return Storage::disk('backup')->download($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         Log::error('User '.Auth::user()->full_name.' tried to download a backup named '.$name.' that does not exist'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         return view('err.badFile'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     //  Create a new backup | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     public function runBackup() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         Artisan::call('tb-backup:run'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         Log::notice('Backup created by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         return response()->json(['success' => true]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     //  Email Settings form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     public function emailSettings() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         $settings = collect([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |             'host'       => config('mail.host'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |             'port'       => config('mail.port'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |             'encryption' => config('mail.encryption'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |             'username'   => config('mail.username'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |             'fromEmail'  =>config('mail.from.address'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |             'fromName'   => config('mail.from.name'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         return view('installer.emailSettings', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             'settings' => $settings, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |     //  Send a test email | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |     public function sendTestEmail(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name.'. Submitted Data - ', $request->toArray()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         //  TODO - fix this and make it work | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |         return response()->json(['success' => false]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         // $request->validate([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         //     'host'       => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         //     'port'       => 'required|numeric', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |         //     'encryption' => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |         //     'username'   => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         //     'fromEmail'  => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         //     'fromName'   => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         // ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         // //  Update each setting | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |         // Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         //     ['key'   => 'mail.host'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         //     ['key'   => 'mail.host', 'value' => $request->host] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |         // )->update(['value' => $request->host]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         // Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |         //     ['key'   => 'mail.port'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         //     ['key'   => 'mail.port', 'value' => $request->port] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         // )->update(['value' => $request->port]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |         // Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         //     ['key'   => 'mail.encryption'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         //     ['key'   => 'mail.encryption', 'value' => $request->encryption] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |         // )->update(['value' => $request->encryption]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |         // Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |         //     ['key'   => 'mail.username'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         //     ['key'   => 'mail.username', 'value' => $request->username] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         // )->update(['value' => $request->username]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |         // Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |         //     ['key'   => 'mail.from.address'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         //     ['key'   => 'mail.from.address', 'value' => $request->fromEmail] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         // )->update(['value' => $request->fromEmail]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         // Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         //     ['key'   => 'mail.from.name'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |         //     ['key'   => 'mail.from.name', 'value' => $request->fromName] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         // )->update(['value' => $request->fromName]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |         // //  Only update the password if it has changed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |         // if (!empty($request->password) && $request->password !== 'NULL') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |         //     // Settings::where('key', 'mail.password')->update(['value' => $request->password]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |         //     Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |         //         ['key'   => 'mail.password'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |         //         ['key'   => 'mail.password', 'value' => $request->password] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         //     )->update(['value' => $request->password]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |         // } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |         // try | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         // { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         //     Mail::to(Auth::user())->send(new TestEmail($request)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         // } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         // catch (\Exception $e) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         // { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |         //     // return $e->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         //     return response()->json(['success' => false, 'message' => $e->getMessage()]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |         // } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |         // return response()->json(['success' => true, 'message' => 'Email successfully sent to '.Auth::user()->email]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |     //  Submit the test email form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |     public function submitEmailSettings(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |         Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name.'. Submitted Data - ', $request->toArray()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |         $request->validate([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |             'host'       => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |             'port'       => 'required|numeric', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |             'encryption' => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |             'fromEmail'  => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |             'fromName'   => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |         //  Update each setting | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |             ['key'   => 'mail.host'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |             ['key'   => 'mail.host', 'value' => $request->host] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |         )->update(['value' => $request->host]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |         Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |             ['key'   => 'mail.port'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |             ['key'   => 'mail.port', 'value' => $request->port] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |         )->update(['value' => $request->port]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |         Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |             ['key'   => 'mail.encryption'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |             ['key'   => 'mail.encryption', 'value' => $request->encryption] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |         )->update(['value' => $request->encryption]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |         Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |             ['key'   => 'mail.username'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |             ['key'   => 'mail.username', 'value' => $request->username] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |         )->update(['value' => $request->username]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |         Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |             ['key'   => 'mail.from.address'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |             ['key'   => 'mail.from.address', 'value' => $request->fromEmail] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |         )->update(['value' => $request->fromEmail]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |         Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |             ['key'   => 'mail.from.name'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |             ['key'   => 'mail.from.name', 'value' => $request->fromName] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |         )->update(['value' => $request->fromName]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |         //  Only update the password if it has changed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |         if(!empty($request->password) && $request->password !== 'NULL') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |             // Settings::where('key', 'mail.password')->update(['value' => $request->password]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |             Settings::firstOrCreate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |                 ['key'   => 'mail.password'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |                 ['key'   => 'mail.password', 'value' => $request->password] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |             )->update(['value' => $request->password]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |         Log::notice('Email Settings have been changed by '.Auth::user()->full_name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |         return response()->json(['success' => true]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 310 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 311 |  |  |  |