2014-12-20 21:20:17 +00:00
|
|
|
<?php
|
2014-12-20 18:53:52 +00:00
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers;
|
2015-01-01 15:45:04 +00:00
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
use CachetHQ\Cachet\Models\Setting;
|
2015-01-01 15:45:04 +00:00
|
|
|
use Exception;
|
2015-01-02 12:05:50 +00:00
|
|
|
use GrahamCampbell\Binput\Facades\Binput;
|
2015-01-01 16:18:24 +00:00
|
|
|
use Illuminate\Routing\Controller;
|
2015-01-01 17:23:49 +00:00
|
|
|
use Illuminate\Support\Facades\Redirect;
|
2015-01-01 15:45:04 +00:00
|
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
|
2014-12-20 21:20:17 +00:00
|
|
|
class DashSettingsController extends Controller
|
|
|
|
{
|
2014-12-31 10:38:59 +00:00
|
|
|
protected $subMenu = [];
|
|
|
|
protected $subTitle = 'Settings';
|
|
|
|
|
2014-12-31 11:39:28 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
2014-12-31 10:38:59 +00:00
|
|
|
$this->subMenu = [
|
|
|
|
'setup' => [
|
2015-01-05 11:12:34 +00:00
|
|
|
'title' => trans('dashboard.settings.app-setup.app-setup'),
|
2014-12-31 10:38:59 +00:00
|
|
|
'url' => '/dashboard/settings/setup',
|
|
|
|
'icon' => 'ion-gear-b',
|
|
|
|
'active' => false,
|
|
|
|
],
|
|
|
|
'security' => [
|
2015-01-05 11:12:34 +00:00
|
|
|
'title' => trans('dashboard.settings.security.security'),
|
2014-12-31 10:38:59 +00:00
|
|
|
'url' => '/dashboard/settings/security',
|
|
|
|
'icon' => 'ion-lock-combination',
|
|
|
|
'active' => false,
|
|
|
|
],
|
|
|
|
'theme' => [
|
2015-01-05 11:12:34 +00:00
|
|
|
'title' => trans('dashboard.settings.theme.theme'),
|
2014-12-31 10:38:59 +00:00
|
|
|
'url' => '/dashboard/settings/theme',
|
|
|
|
'icon' => 'ion-paintbrush',
|
|
|
|
'active' => false,
|
|
|
|
],
|
|
|
|
'stylesheet' => [
|
2015-01-05 11:12:34 +00:00
|
|
|
'title' => trans('dashboard.settings.stylesheet.stylesheet'),
|
2014-12-31 10:38:59 +00:00
|
|
|
'url' => '/dashboard/settings/stylesheet',
|
|
|
|
'icon' => 'ion-paintbucket',
|
|
|
|
'active' => false,
|
2014-12-31 11:39:28 +00:00
|
|
|
],
|
2014-12-31 10:38:59 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
View::share('subTitle', $this->subTitle);
|
2015-01-09 20:21:29 -06:00
|
|
|
|
2014-12-31 10:38:59 +00:00
|
|
|
View::share('subMenu', $this->subMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the settings setup view.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showSetupView()
|
|
|
|
{
|
|
|
|
$this->subMenu['setup']['active'] = true;
|
|
|
|
|
2015-01-01 10:39:22 +00:00
|
|
|
return View::make('dashboard.settings.app-setup')->with([
|
2014-12-31 10:38:59 +00:00
|
|
|
'pageTitle' => 'Application Setup - Dashboard',
|
2014-12-31 11:39:28 +00:00
|
|
|
'subMenu' => $this->subMenu,
|
2014-12-31 10:38:59 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the settings theme view.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showThemeView()
|
|
|
|
{
|
|
|
|
$this->subMenu['theme']['active'] = true;
|
|
|
|
|
2015-01-01 10:39:22 +00:00
|
|
|
return View::make('dashboard.settings.theme')->with([
|
2014-12-31 10:38:59 +00:00
|
|
|
'pageTitle' => 'Theme - Dashboard',
|
2014-12-31 11:39:28 +00:00
|
|
|
'subMenu' => $this->subMenu,
|
2014-12-31 10:38:59 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the settings security view.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showSecurityView()
|
|
|
|
{
|
|
|
|
$this->subMenu['security']['active'] = true;
|
|
|
|
|
2015-01-01 10:39:22 +00:00
|
|
|
return View::make('dashboard.settings.security')->with([
|
2014-12-31 10:38:59 +00:00
|
|
|
'pageTitle' => 'Security - Dashboard',
|
2014-12-31 11:39:28 +00:00
|
|
|
'subMenu' => $this->subMenu,
|
2014-12-31 10:38:59 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2014-12-20 21:20:17 +00:00
|
|
|
/**
|
2014-12-31 10:38:59 +00:00
|
|
|
* Shows the settings stylesheet view.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-20 21:20:17 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2014-12-31 10:38:59 +00:00
|
|
|
public function showStylesheetView()
|
2014-12-20 21:20:17 +00:00
|
|
|
{
|
2014-12-31 10:38:59 +00:00
|
|
|
$this->subMenu['stylesheet']['active'] = true;
|
|
|
|
|
2015-01-01 10:39:22 +00:00
|
|
|
return View::make('dashboard.settings.stylesheet')->with([
|
2014-12-31 10:38:59 +00:00
|
|
|
'pageTitle' => 'Stylesheet - Dashboard',
|
2014-12-31 11:39:28 +00:00
|
|
|
'subMenu' => $this->subMenu,
|
2014-12-20 21:20:17 +00:00
|
|
|
]);
|
|
|
|
}
|
2014-12-20 18:53:52 +00:00
|
|
|
|
2014-12-20 21:20:17 +00:00
|
|
|
/**
|
2014-12-31 11:45:54 +00:00
|
|
|
* Updates the status page settings.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-20 21:20:17 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function postSettings()
|
|
|
|
{
|
2015-01-04 12:25:21 +00:00
|
|
|
if (Binput::get('remove_banner') === '1') {
|
2015-01-01 11:23:34 +00:00
|
|
|
$setting = Setting::where('name', 'app_banner');
|
|
|
|
$setting->delete();
|
|
|
|
}
|
|
|
|
|
2015-01-02 12:05:50 +00:00
|
|
|
if (Binput::hasFile('app_banner')) {
|
|
|
|
$file = Binput::file('app_banner');
|
2014-12-31 11:45:54 +00:00
|
|
|
|
|
|
|
// Image Validation.
|
|
|
|
// Image size in bytes.
|
|
|
|
$maxSize = $file->getMaxFilesize();
|
2015-01-01 15:45:04 +00:00
|
|
|
|
2014-12-31 11:45:54 +00:00
|
|
|
if ($file->getSize() > $maxSize) {
|
2015-01-14 16:14:53 +00:00
|
|
|
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.too-big', [
|
|
|
|
'size' => $maxSize,
|
|
|
|
]));
|
2015-01-01 15:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$file->isValid() || $file->getError()) {
|
2015-01-09 20:21:29 -06:00
|
|
|
return Redirect::back()->withErrors($file->getErrorMessage());
|
2015-01-01 15:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strpos($file->getMimeType(), 'image/') !== 0) {
|
2015-01-13 11:55:26 +00:00
|
|
|
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.images-only'));
|
2014-12-31 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Store the banner.
|
|
|
|
Setting::firstOrCreate([
|
2014-12-31 11:51:06 +00:00
|
|
|
'name' => 'app_banner',
|
2014-12-31 11:45:54 +00:00
|
|
|
])->update([
|
2014-12-31 11:51:06 +00:00
|
|
|
'value' => base64_encode(file_get_contents($file->getRealPath())),
|
2014-12-31 11:45:54 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Store the banner type
|
|
|
|
Setting::firstOrCreate([
|
2014-12-31 11:51:06 +00:00
|
|
|
'name' => 'app_banner_type',
|
2014-12-31 11:45:54 +00:00
|
|
|
])->update([
|
2014-12-31 11:51:06 +00:00
|
|
|
'value' => $file->getMimeType(),
|
2014-12-31 11:45:54 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2014-12-31 10:38:59 +00:00
|
|
|
try {
|
2015-01-02 12:05:50 +00:00
|
|
|
foreach (Binput::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) {
|
2015-01-01 17:45:41 +00:00
|
|
|
Setting::firstOrCreate([
|
2014-12-31 10:38:59 +00:00
|
|
|
'name' => $settingName,
|
|
|
|
])->update([
|
|
|
|
'value' => $settingValue,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
2015-01-09 20:21:29 -06:00
|
|
|
return Redirect::back()->with('errors', trans('dashboard.settings.edit.failure'));
|
2014-12-20 21:20:17 +00:00
|
|
|
}
|
2014-12-20 18:53:52 +00:00
|
|
|
|
2015-01-09 20:21:29 -06:00
|
|
|
return Redirect::back()->with('success', trans('dashboard.settings.edit.success'));
|
2014-12-20 21:20:17 +00:00
|
|
|
}
|
2014-12-20 18:53:52 +00:00
|
|
|
}
|