Files
snipe-it/app/controllers/admin/SettingsController.php
T
Jake McGraw 55b54e0a42 added sql migration for qr_code in settings table
added baconqr to composer package list
added admin settings page for qr code
2014-01-28 04:25:58 +00:00

104 lines
2.2 KiB
PHP

<?php namespace Controllers\Admin;
use AdminController;
use Input;
use Lang;
use Setting;
use Redirect;
use DB;
use Sentry;
use Str;
use Validator;
use View;
class SettingsController extends AdminController {
/**
* Show a list of all the settings.
*
* @return View
*/
public function getIndex()
{
// Grab all the settings
$settings = Setting::all();
// Show the page
return View::make('backend/settings/index', compact('settings'));
}
/**
* Setting update.
*
* @param int $settingId
* @return View
*/
public function getEdit()
{
$settings = Setting::orderBy('created_at', 'DESC')->paginate(10);
$is_gd_installed = !!extension_loaded('gd');
return View::make('backend/settings/edit', compact('settings', 'is_gd_installed'));
}
/**
* Setting update form processing page.
*
* @param int $settingId
* @return Redirect
*/
public function postEdit()
{
// Check if the asset exists
if (is_null($setting = Setting::find(1)))
{
// Redirect to the asset management page with error
return Redirect::to('admin')->with('error', Lang::get('admin/settings/message.update.error'));
}
$new = Input::all();
// Declare the rules for the form validation
$rules = array(
"site_name" => 'required|min:3',
"per_page" => 'required|min:1|numeric',
);
// Create a new validator instance from our validation rules
$validator = Validator::make(Input::all(), $rules);
// If validation fails, we'll exit the operation now.
if ($validator->fails())
{
// Ooops.. something went wrong
return Redirect::back()->withInput()->withErrors($validator);
}
// Update the asset data
$setting->id = '1';
$setting->site_name = e(Input::get('site_name'));
$setting->per_page = e(Input::get('per_page'));
$setting->qr_code = e(Input::get('qr_code', '0'));
// Was the asset updated?
if($setting->save())
{
// Redirect to the settings page
return Redirect::to("admin/settings/app")->with('success', Lang::get('admin/settings/message.update.success'));
}
// Redirect to the setting management page
return Redirect::to("admin/settings/app/edit")->with('error', Lang::get('admin/settings/message.update.error'));
}
}