Cachet/src/Http/Controllers/DashSettingsController.php

171 lines
4.8 KiB
PHP
Raw Normal View History

2014-12-20 21:20:17 +00:00
<?php
namespace CachetHQ\Cachet\Http\Controllers;
2015-01-01 15:45:04 +00:00
use CachetHQ\Cachet\Models\Setting;
2015-01-01 15:45:04 +00:00
use Exception;
2015-01-01 16:18:24 +00:00
use Illuminate\Routing\Controller;
2015-01-01 15:45:04 +00:00
use Illuminate\Support\Facades\Input;
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
{
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()
{
if (Input::get('remove_banner') == "1") {
$setting = Setting::where('name', 'app_banner');
$setting->delete();
}
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();
2015-01-01 15:45:04 +00:00
2014-12-31 11:45:54 +00:00
if ($file->getSize() > $maxSize) {
2015-01-01 17:45:41 +00:00
return Redirect::back()->withErrorMessage("You need to upload an image that is less than $maxSize.");
2015-01-01 15:45:04 +00:00
}
if (!$file->isValid() || $file->getError()) {
2014-12-31 11:45:54 +00:00
return Redirect::back()->withErrorMessage($file->getErrorMessage());
2015-01-01 15:45:04 +00:00
}
if (strpos($file->getMimeType(), 'image/') !== 0) {
2014-12-31 11:45:54 +00:00
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
]);
}
try {
2015-01-01 17:21:42 +00:00
foreach (Input::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) {
2015-01-01 17:45:41 +00:00
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
}
}