2020-08-30 22:06:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-08-31 18:53:10 +00:00
|
|
|
use App\Facades\Options;
|
2020-08-31 16:55:36 +00:00
|
|
|
use App\Options as Option;
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-08-30 22:06:01 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2020-09-07 21:54:20 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2020-08-30 22:06:01 +00:00
|
|
|
|
|
|
|
class OptionsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Http\Response|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2020-08-31 16:55:36 +00:00
|
|
|
// TODO: Obtain this from the facade
|
|
|
|
$options = Option::all();
|
2020-08-30 22:06:01 +00:00
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-08-31 16:58:07 +00:00
|
|
|
return view('dashboard.administration.settings')
|
2020-08-31 16:55:36 +00:00
|
|
|
->with('options', $options);
|
2020-08-30 22:06:01 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
public function saveSettings(Request $request)
|
|
|
|
{
|
|
|
|
if (Auth::user()->can('admin.settings.edit'))
|
|
|
|
{
|
|
|
|
Log::debug('Updating application options', [
|
|
|
|
'ip' => $request->ip(),
|
|
|
|
'ua' => $request->userAgent(),
|
|
|
|
'username' => Auth::user()->username
|
|
|
|
]);
|
|
|
|
foreach($request->all() as $optionName => $option)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Log::debug('Going through option ' . $optionName);
|
|
|
|
if (Options::optionExists($optionName))
|
|
|
|
{
|
|
|
|
Log::debug('Option exists, updating to new values', [
|
|
|
|
'opt' => $optionName,
|
|
|
|
'new_value' => $option
|
|
|
|
]);
|
|
|
|
Options::changeOption($optionName, $option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(\Exception $ex)
|
|
|
|
{
|
|
|
|
Log::error('Unable to update options!', [
|
|
|
|
'msg' => $ex->getMessage(),
|
|
|
|
'trace' => $ex->getTraceAsString()
|
|
|
|
]);
|
|
|
|
report($ex);
|
2020-09-07 21:54:20 +00:00
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
$errorCond = true;
|
|
|
|
$request->session()->flash('error', 'An error occurred while trying to save settings: ' . $ex->getMessage());
|
|
|
|
}
|
|
|
|
}
|
2020-08-30 22:06:01 +00:00
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
if (!isset($errorCond))
|
|
|
|
{
|
|
|
|
$request->session()->flash('success', 'Settings saved successfully!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$request->session()->flash('error', 'You do not have permission to update this resource.');
|
|
|
|
}
|
2020-08-30 22:06:01 +00:00
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
2020-08-30 22:06:01 +00:00
|
|
|
}
|