diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php
index d6f18837a1..25d0e0eded 100644
--- a/app/controllers/admin/AssetsController.php
+++ b/app/controllers/admin/AssetsController.php
@@ -6,6 +6,7 @@ use Lang;
use Asset;
use Statuslabel;
use User;
+use Setting;
use Redirect;
use DB;
use Actionlog;
@@ -51,7 +52,7 @@ class AssetsController extends AdminController {
}
// Paginate the users
- $assets = $assets->paginate(10)
+ $assets = $assets->paginate(Setting::getSettings()->per_page)
->appends(array(
'Pending' => Input::get('Pending'),
'RTD' => Input::get('RTD'),
diff --git a/app/controllers/admin/CategoriesController.php b/app/controllers/admin/CategoriesController.php
index 54e7e46b1b..2750eb24f9 100644
--- a/app/controllers/admin/CategoriesController.php
+++ b/app/controllers/admin/CategoriesController.php
@@ -5,6 +5,7 @@ use Input;
use Lang;
use Category;
use Redirect;
+use Setting;
use DB;
use Sentry;
use Str;
@@ -22,7 +23,7 @@ class CategoriesController extends AdminController {
public function getIndex()
{
// Grab all the categories
- $categories = Category::orderBy('created_at', 'DESC')->paginate(10);
+ $categories = Category::orderBy('created_at', 'DESC')->paginate(Setting::getSettings()->per_page);
// Show the page
return View::make('backend/categories/index', compact('categories'));
diff --git a/app/controllers/admin/DepreciationsController.php b/app/controllers/admin/DepreciationsController.php
index 72aee62e87..5d49df3be4 100644
--- a/app/controllers/admin/DepreciationsController.php
+++ b/app/controllers/admin/DepreciationsController.php
@@ -5,6 +5,7 @@ use Input;
use Lang;
use Depreciation;
use Redirect;
+use Setting;
use DB;
use Sentry;
use Str;
@@ -22,7 +23,7 @@ class DepreciationsController extends AdminController {
public function getIndex()
{
// Grab all the depreciations
- $depreciations = Depreciation::orderBy('created_at', 'DESC')->paginate(10);
+ $depreciations = Depreciation::orderBy('created_at', 'DESC')->paginate(Setting::getSettings()->per_page);
// Show the page
return View::make('backend/depreciations/index', compact('depreciations'));
diff --git a/app/controllers/admin/GroupsController.php b/app/controllers/admin/GroupsController.php
index e872beb60b..56dc76bb03 100755
--- a/app/controllers/admin/GroupsController.php
+++ b/app/controllers/admin/GroupsController.php
@@ -8,6 +8,7 @@ use Config;
use Input;
use Lang;
use Redirect;
+use Setting;
use Sentry;
use Validator;
use View;
diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php
index 99a7c099d6..bdc987fbec 100644
--- a/app/controllers/admin/LicensesController.php
+++ b/app/controllers/admin/LicensesController.php
@@ -9,6 +9,7 @@ use User;
use Actionlog;
use DB;
use Redirect;
+use Setting;
use Sentry;
use Str;
use Validator;
@@ -25,7 +26,7 @@ class LicensesController extends AdminController {
public function getIndex()
{
// Grab all the licenses
- $licenses = License::orderBy('created_at', 'DESC')->where('physical', '=', 0)->paginate(10);
+ $licenses = License::orderBy('created_at', 'DESC')->where('physical', '=', 0)->paginate(Setting::getSettings()->per_page);
// Show the page
return View::make('backend/licenses/index', compact('licenses'));
diff --git a/app/controllers/admin/LocationsController.php b/app/controllers/admin/LocationsController.php
index 9a3760318b..a64fe9ac83 100644
--- a/app/controllers/admin/LocationsController.php
+++ b/app/controllers/admin/LocationsController.php
@@ -5,6 +5,7 @@ use Input;
use Lang;
use Location;
use Redirect;
+use Setting;
use DB;
use Sentry;
use Str;
@@ -22,7 +23,7 @@ class LocationsController extends AdminController {
public function getIndex()
{
// Grab all the locations
- $locations = Location::orderBy('created_at', 'DESC')->paginate(10);
+ $locations = Location::orderBy('created_at', 'DESC')->paginate(Setting::getSettings()->per_page);
// Show the page
return View::make('backend/locations/index', compact('locations'));
diff --git a/app/controllers/admin/ManufacturersController.php b/app/controllers/admin/ManufacturersController.php
index d7f0056f39..32f12793e6 100644
--- a/app/controllers/admin/ManufacturersController.php
+++ b/app/controllers/admin/ManufacturersController.php
@@ -5,6 +5,7 @@ use Input;
use Lang;
use Manufacturer;
use Redirect;
+use Setting;
use Sentry;
use Str;
use Validator;
@@ -20,7 +21,7 @@ class ManufacturersController extends AdminController {
public function getIndex()
{
// Grab all the manufacturers
- $manufacturers = Manufacturer::orderBy('created_at', 'DESC')->paginate(10);
+ $manufacturers = Manufacturer::orderBy('created_at', 'DESC')->paginate(Setting::getSettings()->per_page);
// Show the page
return View::make('backend/manufacturers/index', compact('manufacturers'));
diff --git a/app/controllers/admin/ModelsController.php b/app/controllers/admin/ModelsController.php
index dcaa7f31ad..d186f2f9d2 100644
--- a/app/controllers/admin/ModelsController.php
+++ b/app/controllers/admin/ModelsController.php
@@ -5,6 +5,7 @@ use Input;
use Lang;
use Model;
use Redirect;
+use Setting;
use Sentry;
use DB;
use Depreciation;
@@ -22,7 +23,7 @@ class ModelsController extends AdminController {
public function getIndex()
{
// Grab all the models
- $models = Model::orderBy('created_at', 'DESC')->paginate(10);
+ $models = Model::orderBy('created_at', 'DESC')->paginate(Setting::getSettings()->per_page);
// Show the page
return View::make('backend/models/index', compact('models'));
diff --git a/app/controllers/admin/SettingsController.php b/app/controllers/admin/SettingsController.php
index fe355729ae..2f67ecd6fc 100644
--- a/app/controllers/admin/SettingsController.php
+++ b/app/controllers/admin/SettingsController.php
@@ -22,7 +22,7 @@ class SettingsController extends AdminController {
public function getIndex()
{
// Grab all the settings
- $settings = Setting::orderBy('created_at', 'DESC')->paginate(10);
+ $settings = Setting::all();
// Show the page
return View::make('backend/settings/index', compact('settings'));
@@ -51,35 +51,47 @@ class SettingsController extends AdminController {
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();
- // create a new model instance
- $setting = new Location();
- // attempt validation
- if ($setting->validate($new))
+ // 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 setting data
- $setting->option_value = e(Input::get('name'));
+ // Update the asset data
+ $setting->id = '1';
+ $setting->site_name = e(Input::get('site_name'));
+ $setting->per_page = e(Input::get('per_page'));
-
- // Was the asset created?
+ // Was the asset updated?
if($setting->save())
{
- // Redirect to the saved setting page
- return Redirect::to("admin/settings/app/$settingId/edit")->with('success', Lang::get('admin/settings/message.update.success'));
+ // Redirect to the settings page
+ return Redirect::to("admin/settings/app")->with('success', Lang::get('admin/settings/message.update.success'));
}
- }
- else
- {
- // failure
- $errors = $setting->errors();
- return Redirect::back()->withInput()->withErrors($errors);
- }
- // Redirect to the setting management page
- return Redirect::to("admin/settings/app/$settingId/edit")->with('error', Lang::get('admin/settings/message.update.error'));
+ // Redirect to the setting management page
+ return Redirect::to("admin/settings/app/edit")->with('error', Lang::get('admin/settings/message.update.error'));
}
diff --git a/app/controllers/admin/StatuslabelsController.php b/app/controllers/admin/StatuslabelsController.php
index 8479bc52d1..e45cb61e78 100644
--- a/app/controllers/admin/StatuslabelsController.php
+++ b/app/controllers/admin/StatuslabelsController.php
@@ -7,6 +7,7 @@ use Statuslabel;
use Redirect;
use DB;
use Sentry;
+use Setting;
use Str;
use Validator;
use View;
diff --git a/app/controllers/admin/UsersController.php b/app/controllers/admin/UsersController.php
index 0849f72a97..1ebf7daaef 100755
--- a/app/controllers/admin/UsersController.php
+++ b/app/controllers/admin/UsersController.php
@@ -13,6 +13,7 @@ use Asset;
use Lang;
use Actionlog;
use Location;
+use Setting;
use Redirect;
use Sentry;
use Validator;
diff --git a/app/database/seeds/SettingsSeeder.php b/app/database/seeds/SettingsSeeder.php
index cc16064825..43838a1b70 100644
--- a/app/database/seeds/SettingsSeeder.php
+++ b/app/database/seeds/SettingsSeeder.php
@@ -11,18 +11,8 @@ class SettingsSeeder extends Seeder {
$date = new DateTime;
$setting[] = array(
- 'option_name' => 'per_page',
- 'option_label' => 'Results Per Page',
- 'option_value' => '50',
- 'created_at' => $date->modify('-10 day'),
- 'updated_at' => $date->modify('-3 day'),
- 'user_id' => 1,
- );
-
- $setting[] = array(
- 'option_name' => 'site_name',
- 'option_label' => 'Site Name',
- 'option_value' => 'Snipe IT Asset Management System',
+ 'per_page' => '50',
+ 'site_name' => 'Snipe IT Asset Management',
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
diff --git a/app/lang/en/admin/settings/message.php b/app/lang/en/admin/settings/message.php
new file mode 100755
index 0000000000..107da1f8d1
--- /dev/null
+++ b/app/lang/en/admin/settings/message.php
@@ -0,0 +1,11 @@
+ array(
+ 'error' => 'An error has occurred while updating. ',
+ 'success' => 'Settings updated successfully.'
+ ),
+
+);
diff --git a/app/models/Setting.php b/app/models/Setting.php
index eb443e6eee..9894c22cdf 100644
--- a/app/models/Setting.php
+++ b/app/models/Setting.php
@@ -2,16 +2,10 @@
class Setting extends Elegant {
- protected $table = 'settings';
- protected $rules = array(
- "option_value['site_name']" => 'required|min:3',
- "option_value['per_page']" => 'required|min:1|numeric',
- );
- public function getsettings()
+ public static function getSettings()
{
- //$foo = Setting::all();
- //print_r($foo);
+ return Setting::find(1);
}
}
diff --git a/app/views/backend/assets/index.blade.php b/app/views/backend/assets/index.blade.php
index 0548720224..52fd7396cc 100755
--- a/app/views/backend/assets/index.blade.php
+++ b/app/views/backend/assets/index.blade.php
@@ -56,7 +56,7 @@ Assets ::
-@if ($assets && $assets->getTotal() && $assets->getTotal() > 10)
+@if ($assets && $assets->getTotal() && $assets->getTotal() > Setting::getSettings()->per_page)
{{ $assets->links() }}
@endif
@@ -147,7 +147,7 @@ Assets ::
-@if ($assets && $assets->getTotal() && $assets->getTotal() > 10)
+@if ($assets && $assets->getTotal() && $assets->getTotal() > Setting::getSettings()->per_page)
{{ $assets->links() }}
@endif
@stop
diff --git a/app/views/backend/categories/index.blade.php b/app/views/backend/categories/index.blade.php
index a93ab5a5f4..24b62781da 100755
--- a/app/views/backend/categories/index.blade.php
+++ b/app/views/backend/categories/index.blade.php
@@ -17,7 +17,7 @@ Asset Categories ::
-@if ($categories->getTotal() > 10)
+@if ($categories->getTotal() > Setting::getSettings()->per_page)
{{ $categories->links() }}
@endif