Cachet/app/controllers/DashSettingsController.php

157 lines
4.5 KiB
PHP
Raw Normal View History

2014-12-20 21:20:17 +00:00
<?php
2014-12-20 21:20:17 +00:00
class DashSettingsController extends Controller
{
protected $subMenu = [];
protected $subTitle = 'Settings';
2014-12-31 11:39:28 +00:00
public function __construct()
{
$this->subMenu = [
'setup' => [
'title' => 'Application Setup',
'url' => '/dashboard/settings/setup',
'icon' => 'ion-gear-b',
'active' => false,
],
'security' => [
'title' => 'Security',
'url' => '/dashboard/settings/security',
'icon' => 'ion-lock-combination',
'active' => false,
],
'theme' => [
'title' => 'Theme',
'url' => '/dashboard/settings/theme',
'icon' => 'ion-paintbrush',
'active' => false,
],
'stylesheet' => [
'title' => 'Stylesheet',
'url' => '/dashboard/settings/stylesheet',
'icon' => 'ion-paintbucket',
'active' => false,
2014-12-31 11:39:28 +00:00
],
];
View::share('subTitle', $this->subTitle);
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([
'pageTitle' => 'Application Setup - Dashboard',
2014-12-31 11:39:28 +00:00
'subMenu' => $this->subMenu,
]);
}
/**
* 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([
'pageTitle' => 'Theme - Dashboard',
2014-12-31 11:39:28 +00:00
'subMenu' => $this->subMenu,
]);
}
/**
* 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([
'pageTitle' => 'Security - Dashboard',
2014-12-31 11:39:28 +00:00
'subMenu' => $this->subMenu,
]);
}
2014-12-20 21:20:17 +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
*/
public function showStylesheetView()
2014-12-20 21:20:17 +00:00
{
$this->subMenu['stylesheet']['active'] = true;
2015-01-01 10:39:22 +00:00
return View::make('dashboard.settings.stylesheet')->with([
'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 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()
{
// Fetch all of the settings we've been POSTed.
2014-12-20 21:20:17 +00:00
$settings = Input::all();
2014-12-31 11:45:54 +00:00
if (Input::hasFile('app_banner')) {
$file = Input::file('app_banner');
// Image Validation.
// Image size in bytes.
$maxSize = $file->getMaxFilesize();
if ($file->getSize() > $maxSize) {
return Redirect::back()->withErrorMessage('You need to upload an image that is less than '.$maxSize.'.');
} elseif (!$file->isValid() || $file->getError()) {
return Redirect::back()->withErrorMessage($file->getErrorMessage());
} elseif (strpos($file->getMimeType(), 'image/') !== 0) {
return Redirect::back()->withErrorMessage('Only images may be uploaded.');
}
// 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
]);
}
unset($settings['app_banner']);
try {
foreach ($settings as $settingName => $settingValue) {
$setting = Setting::firstOrCreate([
'name' => $settingName,
])->update([
'value' => $settingValue,
]);
}
} catch (Exception $e) {
return Redirect::back()->withSaved(false);
2014-12-20 21:20:17 +00:00
}
return Redirect::back()->withSaved(true);
2014-12-20 21:20:17 +00:00
}
}