Cleanup controller escaping (#3084)

* Make delete routes work.  We put a little form in the modal that spoofs the delete field.

* Fix route on creating a user.

* Fix redundant id parameter.

* Port acceptance tests to new urls.

* Initial work on migrating to model based policies instead of global gates.  Will allow for much more detailed permissions bits in the future.

* This needs to stay for the dashboard checks.

* Add user states for permissions to build tests.

* Build up unit tests for gates/permissions.  Move accessories/consumables/assets to policies instead of in authserviceprovider

* Migrate various locations to new syntax.  Update test to be more specific

* Fix functional tests.

Add an artisan command for installing a settings setup on travis-ci

* Try a different id... Need to come up with a better way of passing the id for tests that need an existing one.

* Try to fix travis

* Update urls to use routes and not hardcode old paths.  Also fix some migration errors found along the way.:

* Add a environment for travis functional tests.

* Adjust config file to make travis use it.

* Use redirect()->route instead of redirect()-to

* Dump all failures in the output directory if travis fails.

* Cleanups and minor fixes.

* Adjust the supplier modelfactory to comply with new validation restrictions.

* Some test fixes.

* Locales can be longer than 5 characters according to faker... fex gez_ET.  Increase lenght in mysql and add a validation

* Update test database dump to latest migrations.

* Extend Supplier phone/fax length.

This catches issues found in testing with a phone number with a five digit extension.  fex (356) 654-3024 x36632

Also move away from escaping all values put into eloquent.  Eloquent
already uses PDO parameter binding, and this was leading to names like
Mr Ryan O'Malley turning into an html escaped version of that name when
stored.  All values should be escaped when using {{}}, we'll just have
to be more cautious when we use {!!, but I think we already are?

* Remove additional escaping here, like we did in suppliers controller.

* No need to eager load all of these relationships when we can call the count on the querybuilder directly

* Work on controller cleanup

* Always start from scrach, catches more issues this way.

* Update sql dump.  Remove old code from permissions test.

* Generate a deletable item on demand in the test, rather than relying on one existing.  I think we should probably move to mock all the database stuff at some point..

* More travis related fixes

* Break script into multiple functional lines

* Update all controllers to use the new helper, also cleanup syntax and docblocks along the way.
This commit is contained in:
Daniel Meltzer 2016-12-20 00:00:50 -06:00 committed by snipe
parent cd8c585377
commit 323c3807fa
32 changed files with 1717 additions and 2284 deletions

View file

@ -21,7 +21,7 @@ DB_PASSWORD=null
# -------------------------------------------- # --------------------------------------------
# REQUIRED: OUTGOING MAIL SERVER SETTINGS # REQUIRED: OUTGOING MAIL SERVER SETTINGS
# -------------------------------------------- # --------------------------------------------
MAIL_DRIVER=smtp MAIL_DRIVER=log
MAIL_HOST=email-smtp.us-west-2.amazonaws.com MAIL_HOST=email-smtp.us-west-2.amazonaws.com
MAIL_PORT=587 MAIL_PORT=587
MAIL_USERNAME=YOURUSERNAME MAIL_USERNAME=YOURUSERNAME

View file

@ -15,3 +15,7 @@ APP_KEY=base64:tu9NRh/a6+dCXBDGvg0Gv/0TcABnFsbT4AKxrr8mwQo=
# -------------------------------------------- # --------------------------------------------
LOGIN_MAX_ATTEMPTS=1000000 LOGIN_MAX_ATTEMPTS=1000000
LOGIN_LOCKOUT_DURATION=100000000 LOGIN_LOCKOUT_DURATION=100000000
MAIL_DRIVER=log
MAIL_FROM_ADDR=you@example.com
MAIL_FROM_NAME=Snipe-IT

View file

@ -35,7 +35,10 @@ before_script:
# omitting "script:" will default to phpunit # omitting "script:" will default to phpunit
# use the $DB env variable to determine the phpunit.xml to use # use the $DB env variable to determine the phpunit.xml to use
# script: ./vendor/bin/codecept run --env testing-ci # script: ./vendor/bin/codecept run --env testing-ci
script: ./vendor/bin/codecept run unit --env testing-ci && ./vendor/bin/codecept run functional --env=functional-travis script:
- ./vendor/bin/codecept run unit --env testing-ci
- ./vendor/bin/codecept run acceptance --env=testing-ci
- ./vendor/bin/codecept run functional --env=functional-travis
#script: ./vendor/bin/codecept run #script: ./vendor/bin/codecept run
after_success: after_success:

View file

@ -685,5 +685,34 @@ class Helper
} }
/**
* Generate html button for datatable actions.
* @author Daniel Meltzer
* @since 3.7
* @param string $type
* @param string $route
* @param boolean $enabled Used for checkin/checkout
* @param string $message Used for Delete Modal
* @param string $itemName Used for Delete Modal
* @return string
*/
public static function generateDatatableButton($type, $route, $enabled = true, $message = null, $itemName = null)
{
$disabledString = $enabled ? '' : 'disabled';
switch($type) {
case 'checkout':
return '<a href="' . $route . '" style="margin-right:5px;" class="btn btn-info btn-sm ' . $disabledString . '">' . trans('general.checkout') . '</a>';
case 'checkin':
return '<a href="' . $route . '" class="btn btn-info btn-sm ' . $disabledString . '">'.trans('general.checkin').'</a>';
case 'edit':
return '<a href="' . $route . '" class="btn btn-warning btn-sm ' . $disabledString . '" title="Edit" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
case 'clone':
return '<a href="'.$route.'" class="btn btn-info btn-sm ' . $disabledString . '" title="Clone" data-toggle="tooltip"><i class="fa fa-clone"></i></a>';
case 'delete':
return '<a data-html="false" class="btn delete-asset btn-danger btn-sm ' . $disabledString . '" data-toggle="modal" href="' . $route . '" data-content="' . $message . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($itemName) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
case 'restore':
return '<a href="'.$route.'" class="btn btn-warning btn-sm ' . $disabledString . '"><i class="fa fa-recycle icon-white"></i></a>';
}
}
} }

View file

@ -77,28 +77,28 @@ class AccessoriesController extends Controller
$accessory = new Accessory(); $accessory = new Accessory();
// Update the accessory data // Update the accessory data
$accessory->name = e(Input::get('name')); $accessory->name = request('name');
$accessory->category_id = e(Input::get('category_id')); $accessory->category_id = request('category_id');
$accessory->location_id = e(Input::get('location_id')); $accessory->location_id = request('location_id');
$accessory->min_amt = e(Input::get('min_amt')); $accessory->min_amt = request('min_amt');
$accessory->company_id = Company::getIdForCurrentUser(Input::get('company_id')); $accessory->company_id = Company::getIdForCurrentUser(request('company_id'));
$accessory->order_number = e(Input::get('order_number')); $accessory->order_number = request('order_number');
$accessory->manufacturer_id = e(Input::get('manufacturer_id')); $accessory->manufacturer_id = request('manufacturer_id');
$accessory->model_number = e(Input::get('model_number')); $accessory->model_number = request('model_number');
if (e(Input::get('purchase_date')) == '') { if (request('purchase_date') == ''){
$accessory->purchase_date = null; $accessory->purchase_date = null;
} else { } else {
$accessory->purchase_date = e(Input::get('purchase_date')); $accessory->purchase_date = request('purchase_date');
} }
if (e(Input::get('purchase_cost')) == '0.00') { if (request('purchase_cost') == '0.00'){
$accessory->purchase_cost = null; $accessory->purchase_cost = null;
} else { } else {
$accessory->purchase_cost = Helper::ParseFloat(e(Input::get('purchase_cost'))); $accessory->purchase_cost = Helper::ParseFloat(request('purchase_cost'));
} }
$accessory->qty = e(Input::get('qty')); $accessory->qty = request('qty');
$accessory->user_id = Auth::user()->id; $accessory->user_id = Auth::user()->id;
// Was the accessory created? // Was the accessory created?
@ -107,8 +107,6 @@ class AccessoriesController extends Controller
// Redirect to the new accessory page // Redirect to the new accessory page
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.create.success')); return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.create.success'));
} }
return redirect()->back()->withInput()->withErrors($accessory->getErrors()); return redirect()->back()->withInput()->withErrors($accessory->getErrors());
} }
@ -155,43 +153,40 @@ class AccessoriesController extends Controller
$this->authorize($accessory); $this->authorize($accessory);
// Update the accessory data // Update the accessory data
$accessory->name = e(Input::get('name')); $accessory->name = e(request('name'));
if (e(Input::get('location_id')) == '') { if (e(request('location_id')) == '') {
$accessory->location_id = null; $accessory->location_id = null;
} else { } else {
$accessory->location_id = e(Input::get('location_id')); $accessory->location_id = request('location_id');
} }
$accessory->min_amt = e(Input::get('min_amt')); $accessory->min_amt = request('min_amt');
$accessory->category_id = e(Input::get('category_id')); $accessory->category_id = request('category_id');
$accessory->company_id = Company::getIdForCurrentUser(Input::get('company_id')); $accessory->company_id = Company::getIdForCurrentUser(request('company_id'));
$accessory->manufacturer_id = e(Input::get('manufacturer_id')); $accessory->manufacturer_id = request('manufacturer_id');
$accessory->order_number = e(Input::get('order_number')); $accessory->order_number = request('order_number');
$accessory->model_number = e(Input::get('model_number')); $accessory->model_number = request('model_number');
if (e(Input::get('purchase_date')) == '') { if (request('purchase_date') == '') {
$accessory->purchase_date = null; $accessory->purchase_date = null;
} else { } else {
$accessory->purchase_date = e(Input::get('purchase_date')); $accessory->purchase_date = request('purchase_date');
} }
if (e(Input::get('purchase_cost')) == '0.00') { if (request('purchase_cost') == '0.00') {
$accessory->purchase_cost = null; $accessory->purchase_cost = null;
} else { } else {
$accessory->purchase_cost = e(Input::get('purchase_cost')); $accessory->purchase_cost = request('purchase_cost');
} }
$accessory->qty = e(Input::get('qty')); $accessory->qty = request('qty');
// Was the accessory updated? // Was the accessory updated?
if ($accessory->save()) { if ($accessory->save()) {
// Redirect to the updated accessory page // Redirect to the updated accessory page
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.update.success')); return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.update.success'));
} }
return redirect()->back()->withInput()->withErrors($accessory->getErrors()); return redirect()->back()->withInput()->withErrors($accessory->getErrors());
} }
/** /**
@ -214,13 +209,10 @@ class AccessoriesController extends Controller
if ($accessory->hasUsers() > 0) { if ($accessory->hasUsers() > 0) {
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.assoc_users', array('count'=> $accessory->hasUsers()))); return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.assoc_users', array('count'=> $accessory->hasUsers())));
} else { }
$accessory->delete(); $accessory->delete();
// Redirect to the locations management page // Redirect to the locations management page
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.delete.success')); return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.delete.success'));
}
} }
@ -230,7 +222,7 @@ class AccessoriesController extends Controller
* the content for the accessory detail view, which is generated in getDataView. * the content for the accessory detail view, which is generated in getDataView.
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $accessoryId * @param int $accessoryID
* @see AccessoriesController::getDataView() method that generates the JSON response * @see AccessoriesController::getDataView() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @return View * @return View
@ -241,7 +233,7 @@ class AccessoriesController extends Controller
$this->authorize('view', $accessory); $this->authorize('view', $accessory);
if (isset($accessory->id)) { if (isset($accessory->id)) {
return View::make('accessories/view', compact('accessory')); return View::make('accessories/view', compact('accessory'));
} else { }
// Prepare the error message // Prepare the error message
$error = trans('admin/accessories/message.does_not_exist', compact('id')); $error = trans('admin/accessories/message.does_not_exist', compact('id'));
@ -249,9 +241,6 @@ class AccessoriesController extends Controller
return redirect()->route('accessories')->with('error', $error); return redirect()->route('accessories')->with('error', $error);
} }
}
/** /**
* Return the form to checkout an Accessory to a user. * Return the form to checkout an Accessory to a user.
* *
@ -270,9 +259,7 @@ class AccessoriesController extends Controller
$this->authorize('checkout', $accessory); $this->authorize('checkout', $accessory);
// Get the dropdown of users and then pass it to the checkout view // Get the dropdown of users and then pass it to the checkout view
$users_list = Helper::usersList(); return View::make('accessories/checkout', compact('accessory'))->with('users_list', Helper::usersList());
return View::make('accessories/checkout', compact('accessory'))->with('users_list', $users_list);
} }
@ -311,14 +298,11 @@ class AccessoriesController extends Controller
$logaction = $accessory->logCheckout(e(Input::get('note'))); $logaction = $accessory->logCheckout(e(Input::get('note')));
$admin_user = Auth::user(); $admin_user = Auth::user();
$settings = Setting::getSettings(); $settings = Setting::getSettings();
if ($settings->slack_endpoint) { if ($settings->slack_endpoint) {
$slack_settings = [ $slack_settings = [
'username' => $settings->botname, 'username' => $settings->botname,
'channel' => $settings->slack_channel, 'channel' => $settings->slack_channel,
@ -347,8 +331,7 @@ class AccessoriesController extends Controller
} }
DB::table('accessories_users')->where('assigned_to', '=', $accessory->assigned_to)->where('accessory_id', '=', $accessory->id)->first();
$accessory_user = DB::table('accessories_users')->where('assigned_to', '=', $accessory->assigned_to)->where('accessory_id', '=', $accessory->id)->first();
$data['log_id'] = $logaction->id; $data['log_id'] = $logaction->id;
$data['eula'] = $accessory->getEula(); $data['eula'] = $accessory->getEula();
@ -372,9 +355,6 @@ class AccessoriesController extends Controller
// Redirect to the new accessory page // Redirect to the new accessory page
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.checkout.success')); return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.checkout.success'));
} }
@ -382,9 +362,12 @@ class AccessoriesController extends Controller
* Check the accessory back into inventory * Check the accessory back into inventory
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $accessoryId * @param Request $request
* @param integer $accessoryUserId
* @param string $backto
* @return View * @return View
**/ * @internal param int $accessoryId
*/
public function getCheckin(Request $request, $accessoryUserId = null, $backto = null) public function getCheckin(Request $request, $accessoryUserId = null, $backto = null)
{ {
// Check if the accessory exists // Check if the accessory exists
@ -404,9 +387,12 @@ class AccessoriesController extends Controller
* *
* @uses Accessory::checkin_email() to determine if an email can and should be sent * @uses Accessory::checkin_email() to determine if an email can and should be sent
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $accessoryId * @param Request $request
* @param integer $accessoryUserId
* @param string $backto
* @return Redirect * @return Redirect
**/ * @internal param int $accessoryId
*/
public function postCheckin(Request $request, $accessoryUserId = null, $backto = null) public function postCheckin(Request $request, $accessoryUserId = null, $backto = null)
{ {
// Check if the accessory exists // Check if the accessory exists
@ -415,7 +401,6 @@ class AccessoriesController extends Controller
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found')); return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found'));
} }
$accessory = Accessory::find($accessory_user->accessory_id); $accessory = Accessory::find($accessory_user->accessory_id);
$this->authorize('checkin', $accessory); $this->authorize('checkin', $accessory);
@ -424,7 +409,6 @@ class AccessoriesController extends Controller
$logaction = $accessory->logCheckin(User::find($return_to), e(Input::get('note'))); $logaction = $accessory->logCheckin(User::find($return_to), e(Input::get('note')));
$admin_user = Auth::user(); $admin_user = Auth::user();
// Was the accessory updated? // Was the accessory updated?
if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) { if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {
@ -485,11 +469,9 @@ class AccessoriesController extends Controller
if ($backto=='user') { if ($backto=='user') {
return redirect()->route("users.show", $return_to)->with('success', trans('admin/accessories/message.checkin.success')); return redirect()->route("users.show", $return_to)->with('success', trans('admin/accessories/message.checkin.success'));
} else { }
return redirect()->route("accessories.show", $accessory->id)->with('success', trans('admin/accessories/message.checkin.success')); return redirect()->route("accessories.show", $accessory->id)->with('success', trans('admin/accessories/message.checkin.success'));
} }
}
// Redirect to the accessory management page with error // Redirect to the accessory management page with error
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkin.error')); return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkin.error'));
} }
@ -518,9 +500,10 @@ class AccessoriesController extends Controller
* For debugging, see at /api/accessories/list * For debugging, see at /api/accessories/list
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $accessoryId * @param Request $request
* @return string JSON containing accessories and their associated atrributes. * @return string JSON containing accessories and their associated atrributes.
**/ * @internal param int $accessoryId
*/
public function getDatatable(Request $request) public function getDatatable(Request $request)
{ {
$this->authorize('index', Accessory::class); $this->authorize('index', Accessory::class);
@ -532,19 +515,8 @@ class AccessoriesController extends Controller
if (Input::has('search')) { if (Input::has('search')) {
$accessories = $accessories->TextSearch(e(Input::get('search'))); $accessories = $accessories->TextSearch(e(Input::get('search')));
} }
$offset = request('offset', 0);
if (Input::has('offset')) { $limit = request('limit', 50);
$offset = e(Input::get('offset'));
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e(Input::get('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['name','min_amt','order_number','purchase_date','purchase_cost','companyName','category','model_number']; $allowed_columns = ['name','min_amt','order_number','purchase_date','purchase_cost','companyName','category','model_number'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
@ -571,16 +543,23 @@ class AccessoriesController extends Controller
$actions = '<nobr>'; $actions = '<nobr>';
if (Gate::allows('checkout', $accessory)) { if (Gate::allows('checkout', $accessory)) {
$actions .= '<a href="' . route('checkout/accessory', $actions .= Helper::generateDatatableButton(
$accessory->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm" ' . (($accessory->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>'; 'checkout',
route('checkout/accessory', $accessory->id),
$accessory->numRemaining() > 0
);
} }
if (Gate::allows('update', $accessory)) { if (Gate::allows('update', $accessory)) {
$actions .= '<a href="' . route('accessories.update', $actions .= Helper::generateDatatableButton('edit', route('accessories.update', $accessory->id));
$accessory->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
} }
if (Gate::allows('delete', $accessory)) { if (Gate::allows('delete', $accessory)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('accessories.destroy', $actions .= Helper::generateDatatableButton(
$accessory->id) . '" data-content="' . trans('admin/accessories/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($accessory->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; 'delete',
route('accessories.destroy', $accessory->id),
$enabled = true,
trans('admin/accessories/message.delete.confirm'),
$accessory->name
);
} }
$actions .= '</nobr>'; $actions .= '</nobr>';
$company = $accessory->company; $company = $accessory->company;
@ -650,8 +629,7 @@ class AccessoriesController extends Controller
foreach ($accessory_users as $user) { foreach ($accessory_users as $user) {
$actions = ''; $actions = '';
if (Gate::allows('checkin', $accessory)) { if (Gate::allows('checkin', $accessory)) {
$actions .= '<a href="' . route('checkin/accessory', $actions .= Helper::generateDatatableButton('checkin', route('checkin/accessory', $user->pivot->id));
$user->pivot->id) . '" class="btn btn-info btn-sm">Checkin</a>';
} }
if (Gate::allows('view', $user)) { if (Gate::allows('view', $user)) {

View file

@ -61,7 +61,6 @@ class AssetMaintenancesController extends Controller
*/ */
public function index() public function index()
{ {
return View::make('asset_maintenances/index'); return View::make('asset_maintenances/index');
} }
@ -83,18 +82,8 @@ class AssetMaintenancesController extends Controller
$maintenances = $maintenances->TextSearch(e($request->input('search'))); $maintenances = $maintenances->TextSearch(e($request->input('search')));
} }
$offset = request('offset', 0);
if ($request->has('offset')) { $limit = request('limit', 50);
$offset = e($request->input('offset'));
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e($request->input('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['id','title','asset_maintenance_time','asset_maintenance_type','cost','start_date','completion_date','notes','user_id']; $allowed_columns = ['id','title','asset_maintenance_time','asset_maintenance_type','cost','start_date','completion_date','notes','user_id'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
@ -118,9 +107,14 @@ class AssetMaintenancesController extends Controller
foreach ($maintenances as $maintenance) { foreach ($maintenances as $maintenance) {
$actions = ''; $actions = '';
if (Gate::allows('update', Asset::class)) { if (Gate::allows('update', Asset::class)) {
$actions .= '<nobr><a href="' . route('maintenances.edit', $actions .= Helper::generateDatatableButton('edit', route('maintenances.edit', $maintenance->id));
$maintenance->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('maintenances.destroy', $actions .= Helper::generateDatatableButton(
$maintenance->id) . '" data-content="' . trans('admin/asset_maintenances/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($maintenance->title) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>'; 'delete',
route('maintenances.destroy', $maintenance->id),
$enabled = true,
trans('admin/asset_maintenances/message.delete.confirm'),
$maintenance->title
);
} }
if (($maintenance->cost) && (isset($maintenance->asset)) && ($maintenance->asset->assetloc) && ($maintenance->asset->assetloc->currency!='')) { if (($maintenance->cost) && (isset($maintenance->asset)) && ($maintenance->asset->assetloc) && ($maintenance->asset->assetloc->currency!='')) {
@ -167,17 +161,11 @@ class AssetMaintenancesController extends Controller
'' => 'Select an asset maintenance type', '' => 'Select an asset maintenance type',
] + AssetMaintenance::getImprovementOptions(); ] + AssetMaintenance::getImprovementOptions();
// Mark the selected asset, if it came in // Mark the selected asset, if it came in
$selectedAsset = request('asset_id');
$assets = Helper::detailedAssetList();
$supplier_list = Helper::suppliersList();
// Render the view // Render the view
return View::make('asset_maintenances/edit') return View::make('asset_maintenances/edit')
->with('asset_list', $assets) ->with('asset_list', Helper::detailedAssetList())
->with('selectedAsset', $selectedAsset) ->with('selectedAsset', request('asset_id'))
->with('supplier_list', $supplier_list) ->with('supplier_list', Helper::suppliersList())
->with('assetMaintenanceType', $assetMaintenanceType) ->with('assetMaintenanceType', $assetMaintenanceType)
->with('item', new AssetMaintenance); ->with('item', new AssetMaintenance);
} }
@ -193,14 +181,9 @@ class AssetMaintenancesController extends Controller
*/ */
public function store(Request $request) public function store(Request $request)
{ {
// get the POST data
$new = $request->all();
// dd($new);
// create a new model instance // create a new model instance
$assetMaintenance = new AssetMaintenance(); $assetMaintenance = new AssetMaintenance();
if (e(Input::get('supplier_id')) == '') { if (e(Input::get('supplier_id')) == '') {
$assetMaintenance->supplier_id = null; $assetMaintenance->supplier_id = null;
} else { } else {
@ -232,12 +215,12 @@ class AssetMaintenancesController extends Controller
} }
// Save the asset maintenance data // Save the asset maintenance data
$assetMaintenance->asset_id = e($request->input('asset_id')); $assetMaintenance->asset_id = $request->input('asset_id');
$assetMaintenance->asset_maintenance_type = e($request->input('asset_maintenance_type')); $assetMaintenance->asset_maintenance_type = $request->input('asset_maintenance_type');
$assetMaintenance->title = e($request->input('title')); $assetMaintenance->title = $request->input('title');
$assetMaintenance->start_date = e($request->input('start_date')); $assetMaintenance->start_date = $request->input('start_date');
$assetMaintenance->completion_date = e($request->input('completion_date')); $assetMaintenance->completion_date = $request->input('completion_date');
$assetMaintenance->user_id = Auth::user()->id; $assetMaintenance->user_id = Auth::id();
if (( $assetMaintenance->completion_date == "" ) if (( $assetMaintenance->completion_date == "" )
|| ( $assetMaintenance->completion_date == "0000-00-00" ) || ( $assetMaintenance->completion_date == "0000-00-00" )
@ -308,15 +291,12 @@ class AssetMaintenancesController extends Controller
'' => 'Select an improvement type', '' => 'Select an improvement type',
] + AssetMaintenance::getImprovementOptions(); ] + AssetMaintenance::getImprovementOptions();
$assets = Helper::detailedAssetList();
// Get Supplier List // Get Supplier List
$supplier_list = Helper::suppliersList();
// Render the view // Render the view
return View::make('asset_maintenances/edit') return View::make('asset_maintenances/edit')
->with('asset_list', $assets) ->with('asset_list', Helper::detailedAssetList())
->with('selectedAsset', null) ->with('selectedAsset', null)
->with('supplier_list', $supplier_list) ->with('supplier_list', Helper::suppliersList())
->with('assetMaintenanceType', $assetMaintenanceType) ->with('assetMaintenanceType', $assetMaintenanceType)
->with('item', $assetMaintenance); ->with('item', $assetMaintenance);
@ -327,17 +307,14 @@ class AssetMaintenancesController extends Controller
* *
* @see AssetMaintenancesController::postEdit() method that stores the data * @see AssetMaintenancesController::postEdit() method that stores the data
* @author Vincent Sposato <vincent.sposato@gmail.com> * @author Vincent Sposato <vincent.sposato@gmail.com>
* @param Request $request
* @param int $assetMaintenanceId * @param int $assetMaintenanceId
* @return mixed
* @version v1.0 * @version v1.0
* @since [v1.8] * @since [v1.8]
* @return mixed
*/ */
public function update(Request $request, $assetMaintenanceId = null) public function update(Request $request, $assetMaintenanceId = null)
{ {
// get the POST data
$new = $request->all();
// Check if the asset maintenance exists // Check if the asset maintenance exists
if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) { if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) {
// Redirect to the asset maintenance management page // Redirect to the asset maintenance management page
@ -347,44 +324,42 @@ class AssetMaintenancesController extends Controller
return static::getInsufficientPermissionsRedirect(); return static::getInsufficientPermissionsRedirect();
} }
if (request('supplier_id') == '') {
if (e(Input::get('supplier_id')) == '') {
$assetMaintenance->supplier_id = null; $assetMaintenance->supplier_id = null;
} else { } else {
$assetMaintenance->supplier_id = e($request->input('supplier_id')); $assetMaintenance->supplier_id = e($request->input('supplier_id'));
} }
if (e(Input::get('is_warranty')) == '') { if (request('is_warranty') == '') {
$assetMaintenance->is_warranty = 0; $assetMaintenance->is_warranty = 0;
} else { } else {
$assetMaintenance->is_warranty = e($request->input('is_warranty')); $assetMaintenance->is_warranty = e($request->input('is_warranty'));
} }
if (e(Input::get('cost')) == '') { if (request('cost') == '') {
$assetMaintenance->cost = ''; $assetMaintenance->cost = '';
} else { } else {
$assetMaintenance->cost = Helper::ParseFloat(e($request->input('cost'))); $assetMaintenance->cost = Helper::ParseFloat(e($request->input('cost')));
} }
if (e(Input::get('notes')) == '') { if (request('notes') == '') {
$assetMaintenance->notes = null; $assetMaintenance->notes = null;
} else { } else {
$assetMaintenance->notes = e($request->input('notes')); $assetMaintenance->notes = e($request->input('notes'));
} }
$asset = Asset::find(e(Input::get('asset_id'))); $asset = Asset::find(request('asset_id'));
if (!Company::isCurrentUserHasAccess($asset)) { if (!Company::isCurrentUserHasAccess($asset)) {
return static::getInsufficientPermissionsRedirect(); return static::getInsufficientPermissionsRedirect();
} }
// Save the asset maintenance data // Save the asset maintenance data
$assetMaintenance->asset_id = e($request->input('asset_id')); $assetMaintenance->asset_id = $request->input('asset_id');
$assetMaintenance->asset_maintenance_type = e($request->input('asset_maintenance_type')); $assetMaintenance->asset_maintenance_type = $request->input('asset_maintenance_type');
$assetMaintenance->title = e($request->input('title')); $assetMaintenance->title = $request->input('title');
$assetMaintenance->start_date = e($request->input('start_date')); $assetMaintenance->start_date = $request->input('start_date');
$assetMaintenance->completion_date = e($request->input('completion_date')); $assetMaintenance->completion_date = $request->input('completion_date');
if (( $assetMaintenance->completion_date == "" ) if (( $assetMaintenance->completion_date == "" )
|| ( $assetMaintenance->completion_date == "0000-00-00" ) || ( $assetMaintenance->completion_date == "0000-00-00" )
@ -415,8 +390,6 @@ class AssetMaintenancesController extends Controller
->with('success', trans('admin/asset_maintenances/message.create.success')); ->with('success', trans('admin/asset_maintenances/message.create.success'));
} }
return redirect()->back()->withInput()->withErrors($assetMaintenance->getErrors()); return redirect()->back()->withInput()->withErrors($assetMaintenance->getErrors());
} }
/** /**

View file

@ -53,13 +53,10 @@ class AssetModelsController extends Controller
public function create() public function create()
{ {
// Show the page // Show the page
$depreciation_list = Helper::depreciationList();
$manufacturer_list = Helper::manufacturerList();
$category_list = Helper::categoryList('asset');
return View::make('models/edit') return View::make('models/edit')
->with('category_list', $category_list) ->with('category_list', Helper::categoryList('asset'))
->with('depreciation_list', $depreciation_list) ->with('depreciation_list', Helper::depreciationList())
->with('manufacturer_list', $manufacturer_list) ->with('manufacturer_list', Helper::manufacturerList())
->with('item', new AssetModel); ->with('item', new AssetModel);
} }
@ -77,33 +74,31 @@ class AssetModelsController extends Controller
// Create a new asset model // Create a new asset model
$model = new AssetModel; $model = new AssetModel;
if ($request->input('depreciation_id') == '') {
if (e($request->input('depreciation_id')) == '') {
$model->depreciation_id = 0; $model->depreciation_id = 0;
} else { } else {
$model->depreciation_id = e($request->input('depreciation_id')); $model->depreciation_id = $request->input('depreciation_id');
} }
if (e($request->input('eol')) == '') { if ($request->input('eol') == '') {
$model->eol = 0; $model->eol = 0;
} else { } else {
$model->eol = e($request->input('eol')); $model->eol = $request->input('eol');
} }
// Save the model data // Save the model data
$model->name = e($request->input('name')); $model->name = $request->input('name');
$model->model_number = e($request->input('model_number')); $model->model_number = $request->input('model_number');
$model->manufacturer_id = e($request->input('manufacturer_id')); $model->manufacturer_id = $request->input('manufacturer_id');
$model->category_id = e($request->input('category_id')); $model->category_id = $request->input('category_id');
$model->notes = e($request->input('notes')); $model->notes = $request->input('notes');
$model->user_id = Auth::user()->id; $model->user_id = Auth::id();
$model->requestable = Input::has('requestable'); $model->requestable = Input::has('requestable');
if ($request->input('custom_fieldset')!='') { if ($request->input('custom_fieldset')!='') {
$model->fieldset_id = e($request->input('custom_fieldset')); $model->fieldset_id = e($request->input('custom_fieldset'));
} }
if (Input::file('image')) { if (Input::file('image')) {
$image = Input::file('image'); $image = Input::file('image');
$file_name = str_random(25).".".$image->getClientOriginalExtension(); $file_name = str_random(25).".".$image->getClientOriginalExtension();
@ -120,9 +115,7 @@ class AssetModelsController extends Controller
// Redirect to the new model page // Redirect to the new model page
return redirect()->route("models.index")->with('success', trans('admin/models/message.create.success')); return redirect()->route("models.index")->with('success', trans('admin/models/message.create.success'));
} }
return redirect()->back()->withInput()->withErrors($model->getErrors()); return redirect()->back()->withInput()->withErrors($model->getErrors());
} }
/** /**
@ -131,6 +124,7 @@ class AssetModelsController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v2.0] * @since [v2.0]
* @param Request $request
* @return String JSON * @return String JSON
*/ */
public function apiStore(Request $request) public function apiStore(Request $request)
@ -141,12 +135,12 @@ class AssetModelsController extends Controller
$settings=Input::all(); $settings=Input::all();
$settings['eol']= null; $settings['eol']= null;
$model->name=e($request->input('name')); $model->name=$request->input('name');
$model->manufacturer_id = e($request->input('manufacturer_id')); $model->manufacturer_id = $request->input('manufacturer_id');
$model->category_id = e($request->input('category_id')); $model->category_id = $request->input('category_id');
$model->model_number = e($request->input('model_number')); $model->model_number = $request->input('model_number');
$model->user_id = Auth::user()->id; $model->user_id = Auth::id();
$model->notes = e($request->input('notes')); $model->notes = $request->input('notes');
$model->eol= null; $model->eol= null;
if ($request->input('fieldset_id')=='') { if ($request->input('fieldset_id')=='') {
@ -179,14 +173,10 @@ class AssetModelsController extends Controller
return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist')); return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist'));
} }
$depreciation_list = Helper::depreciationList();
$manufacturer_list = Helper::manufacturerList();
$category_list = Helper::categoryList('asset');
$view = View::make('models/edit', compact('item')); $view = View::make('models/edit', compact('item'));
$view->with('category_list', $category_list); $view->with('category_list', Helper::categoryList('asset'));
$view->with('depreciation_list', $depreciation_list); $view->with('depreciation_list', Helper::depreciationList());
$view->with('manufacturer_list', $manufacturer_list); $view->with('manufacturer_list', Helper::manufacturerList());
return $view; return $view;
} }
@ -208,31 +198,30 @@ class AssetModelsController extends Controller
return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist')); return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist'));
} }
if ($request->input('depreciation_id') == '') {
if (e($request->input('depreciation_id')) == '') {
$model->depreciation_id = 0; $model->depreciation_id = 0;
} else { } else {
$model->depreciation_id = e($request->input('depreciation_id')); $model->depreciation_id = $request->input('depreciation_id');
} }
if (e($request->input('eol')) == '') { if ($request->input('eol') == '') {
$model->eol = null; $model->eol = null;
} else { } else {
$model->eol = e($request->input('eol')); $model->eol = $request->input('eol');
} }
$model->name = e($request->input('name')); $model->name = $request->input('name');
$model->model_number = e($request->input('model_number')); $model->model_number = $request->input('model_number');
$model->manufacturer_id = e($request->input('manufacturer_id')); $model->manufacturer_id = $request->input('manufacturer_id');
$model->category_id = e($request->input('category_id')); $model->category_id = $request->input('category_id');
$model->notes = e($request->input('notes')); $model->notes = $request->input('notes');
$model->requestable = Input::has('requestable'); $model->requestable = Input::has('requestable');
if ($request->input('custom_fieldset')=='') { if ($request->input('custom_fieldset')=='') {
$model->fieldset_id = null; $model->fieldset_id = null;
} else { } else {
$model->fieldset_id = e($request->input('custom_fieldset')); $model->fieldset_id = $request->input('custom_fieldset');
} }
if (Input::file('image')) { if (Input::file('image')) {
@ -250,17 +239,10 @@ class AssetModelsController extends Controller
$model->image = null; $model->image = null;
} }
if ($model->save()) { if ($model->save()) {
return redirect()->route("models.index")->with('success', trans('admin/models/message.update.success')); return redirect()->route("models.index")->with('success', trans('admin/models/message.update.success'));
} else {
return redirect()->back()->withInput()->withErrors($model->getErrors());
} }
return redirect()->back()->withInput()->withErrors($model->getErrors());
// Redirect to the model create page
return redirect()->route('models.create')->with('error', trans('admin/models/message.update.error'));
} }
/** /**
@ -279,18 +261,16 @@ class AssetModelsController extends Controller
return redirect()->route('models.index')->with('error', trans('admin/models/message.not_found')); return redirect()->route('models.index')->with('error', trans('admin/models/message.not_found'));
} }
if ($model->assets->count() > 0) { if ($model->assets()->count() > 0) {
// Throw an error that this model is associated with assets // Throw an error that this model is associated with assets
return redirect()->route('models.index')->with('error', trans('admin/models/message.assoc_users')); return redirect()->route('models.index')->with('error', trans('admin/models/message.assoc_users'));
}
} else {
// Delete the model // Delete the model
$model->delete(); $model->delete();
// Redirect to the models management page // Redirect to the models management page
return redirect()->route('models.index')->with('success', trans('admin/models/message.delete.success')); return redirect()->route('models.index')->with('success', trans('admin/models/message.delete.success'));
} }
}
/** /**
@ -318,9 +298,8 @@ class AssetModelsController extends Controller
// Redirect back // Redirect back
return redirect()->route('models.index')->with('success', $success); return redirect()->route('models.index')->with('success', $success);
} else {
return redirect()->back()->with('error', trans('admin/models/message.not_found'));
} }
return redirect()->back()->with('error', trans('admin/models/message.not_found'));
} }
@ -339,7 +318,7 @@ class AssetModelsController extends Controller
if (isset($model->id)) { if (isset($model->id)) {
return View::make('models/view', compact('model')); return View::make('models/view', compact('model'));
} else { }
// Prepare the error message // Prepare the error message
$error = trans('admin/models/message.does_not_exist', compact('id')); $error = trans('admin/models/message.does_not_exist', compact('id'));
@ -347,9 +326,6 @@ class AssetModelsController extends Controller
return redirect()->route('models.index')->with('error', $error); return redirect()->route('models.index')->with('error', $error);
} }
}
/** /**
* Get the clone page to clone a model * Get the clone page to clone a model
* *
@ -369,13 +345,10 @@ class AssetModelsController extends Controller
$model->id = null; $model->id = null;
// Show the page // Show the page
$depreciation_list = Helper::depreciationList();
$manufacturer_list = Helper::manufacturerList();
$category_list = Helper::categoryList('asset');
$view = View::make('models/edit'); $view = View::make('models/edit');
$view->with('category_list', $category_list); $view->with('category_list', Helper::categoryList('asset'));
$view->with('depreciation_list', $depreciation_list); $view->with('depreciation_list', Helper::depreciationList());
$view->with('manufacturer_list', $manufacturer_list); $view->with('manufacturer_list', Helper::manufacturerList());
$view->with('item', $model); $view->with('item', $model);
$view->with('clone_model', $model_to_clone); $view->with('clone_model', $model_to_clone);
return $view; return $view;
@ -424,18 +397,8 @@ class AssetModelsController extends Controller
$models = $models->TextSearch($request->input('search')); $models = $models->TextSearch($request->input('search'));
} }
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e($request->input('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e($request->input('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['id','name','model_number']; $allowed_columns = ['id','name','model_number'];
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
@ -449,10 +412,18 @@ class AssetModelsController extends Controller
$rows = array(); $rows = array();
foreach ($models as $model) { foreach ($models as $model) {
$actions = '<div style="white-space: nowrap;">';
if ($model->deleted_at == '') { if ($model->deleted_at == '') {
$actions = '<div style=" white-space: nowrap;"><a href="'.route('clone/model', $model->id).'" class="btn btn-info btn-sm" title="Clone Model" data-toggle="tooltip"><i class="fa fa-clone"></i></a> <a href="'.route('models.edit', ['model' => $model->id]).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('models.destroy', ['model' => $model->id]).'" data-content="'.trans('admin/models/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($model->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>'; $actions .= Helper::generateDatatableButton('clone', route('clone/model', $model->id));
$actions .= Helper::generateDatatableButton('edit', route('models.edit', $model->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('models.destroy', $model->id),
trans('admin/models/message.delete.confirm'),
$model->name
);
} else { } else {
$actions = '<a href="'.route('restore/model', $model->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>'; $actions .= Helper::generateDatatableButton('restore', route('restore/model', $model->id));
} }
$rows[] = array( $rows[] = array(
@ -516,9 +487,9 @@ class AssetModelsController extends Controller
if ($asset->assetstatus) { if ($asset->assetstatus) {
if ($asset->assetstatus->deployable != 0) { if ($asset->assetstatus->deployable != 0) {
if (($asset->assigned_to !='') && ($asset->assigned_to > 0)) { if (($asset->assigned_to !='') && ($asset->assigned_to > 0)) {
$actions = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>'; $actions = Helper::generateDatatableButton('checkin', route('checkin/hardware', $asset->id));
} else { } else {
$actions = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>'; $actions = Helper::generateDatatableButton('checkout', route('checkout/hardware', $asset->id));
} }
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -32,7 +32,7 @@ class CategoriesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see CategoriesController::getDatatable() method that generates the JSON response * @see CategoriesController::getDatatable() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
{ {
@ -47,7 +47,7 @@ class CategoriesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see CategoriesController::store() method that stores the data * @see CategoriesController::store() method that stores the data
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
@ -64,33 +64,26 @@ class CategoriesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see CategoriesController::create() method that makes the form. * @see CategoriesController::create() method that makes the form.
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function store(Request $request) public function store(Request $request)
{ {
// create a new model instance // create a new model instance
$category = new Category(); $category = new Category();
// Update the category data // Update the category data
$category->name = e($request->input('name')); $category->name = $request->input('name');
$category->category_type = e($request->input('category_type')); $category->category_type = $request->input('category_type');
$category->eula_text = e($request->input('eula_text')); $category->eula_text = $request->input('eula_text');
$category->use_default_eula = e($request->input('use_default_eula', '0')); $category->use_default_eula = $request->input('use_default_eula', '0');
$category->require_acceptance = e($request->input('require_acceptance', '0')); $category->require_acceptance = $request->input('require_acceptance', '0');
$category->checkin_email = e($request->input('checkin_email', '0')); $category->checkin_email = $request->input('checkin_email', '0');
$category->user_id = Auth::user()->id; $category->user_id = Auth::id();
if ($category->save()) { if ($category->save()) {
return redirect()->route('categories.index')->with('success', trans('admin/categories/message.create.success')); return redirect()->route('categories.index')->with('success', trans('admin/categories/message.create.success'));
} else {
return redirect()->back()->withInput()->withErrors($category->getErrors());
} }
return redirect()->route('categories.create')->with('error', trans('admin/categories/message.create.error')); return redirect()->back()->withInput()->withErrors($category->getErrors());
} }
/** /**
@ -100,7 +93,7 @@ class CategoriesController extends Controller
* @see CategoriesController::postEdit() method saves the data * @see CategoriesController::postEdit() method saves the data
* @param int $categoryId * @param int $categoryId
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function edit($categoryId = null) public function edit($categoryId = null)
{ {
@ -110,7 +103,6 @@ class CategoriesController extends Controller
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.does_not_exist')); return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.does_not_exist'));
} }
$category_options = array('' => 'Top Level') + DB::table('categories')->where('id', '!=', $categoryId)->lists('name', 'id'); $category_options = array('' => 'Top Level') + DB::table('categories')->where('id', '!=', $categoryId)->lists('name', 'id');
$category_types= Helper::categoryTypeList(); $category_types= Helper::categoryTypeList();
@ -125,83 +117,68 @@ class CategoriesController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see CategoriesController::getEdit() method that makes the form. * @see CategoriesController::getEdit() method that makes the form.
* @param Request $request
* @param int $categoryId * @param int $categoryId
* @return \Illuminate\Http\RedirectResponse
* @since [v1.0] * @since [v1.0]
* @return Redirect
*/ */
public function update(Request $request, $categoryId = null) public function update(Request $request, $categoryId = null)
{ {
// Check if the blog post exists // Check if the blog post exists
if (is_null($category = Category::find($categoryId))) { if (is_null($category = Category::find($categoryId))) {
// Redirect to the blogs management page // Redirect to the categories management page
return redirect()->to('admin/categories')->with('error', trans('admin/categories/message.does_not_exist')); return redirect()->to('admin/categories')->with('error', trans('admin/categories/message.does_not_exist'));
} }
// Update the category data // Update the category data
$category->name = e($request->input('name')); $category->name = $request->input('name');
// If the item count is > 0, we disable the category type in the edit. Disabled items // If the item count is > 0, we disable the category type in the edit. Disabled items
// don't POST, so if the category_type is blank we just set it to the default. // don't POST, so if the category_type is blank we just set it to the default.
$category->category_type = e($request->input('category_type', $category->category_type)); $category->category_type = $request->input('category_type', $category->category_type);
$category->eula_text = e($request->input('eula_text')); $category->eula_text = $request->input('eula_text');
$category->use_default_eula = e($request->input('use_default_eula', '0')); $category->use_default_eula = $request->input('use_default_eula', '0');
$category->require_acceptance = e($request->input('require_acceptance', '0')); $category->require_acceptance = $request->input('require_acceptance', '0');
$category->checkin_email = e($request->input('checkin_email', '0')); $category->checkin_email = $request->input('checkin_email', '0');
if ($category->save()) { if ($category->save()) {
// Redirect to the new category page // Redirect to the new category page
return redirect()->route('categories.index')->with('success', trans('admin/categories/message.update.success')); return redirect()->route('categories.index')->with('success', trans('admin/categories/message.update.success'));
} // attempt validation }
else {
// The given data did not pass validation // The given data did not pass validation
return redirect()->back()->withInput()->withErrors($category->getErrors()); return redirect()->back()->withInput()->withErrors($category->getErrors());
} }
// Redirect to the category management page
return redirect()->back()->with('error', trans('admin/categories/message.update.error'));
}
/** /**
* Validates and marks a category as deleted. * Validates and marks a category as deleted.
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $categoryId * @param int $categoryId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($categoryId) public function destroy($categoryId)
{ {
// Check if the category exists // Check if the category exists
if (is_null($category = Category::find($categoryId))) { if (is_null($category = Category::find($categoryId))) {
// Redirect to the blogs management page
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.not_found')); return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.not_found'));
} }
if ($category->has_models() > 0) { if ($category->has_models() > 0) {
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'model'])); return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'model']));
} elseif ($category->accessories()->count() > 0) { } elseif ($category->accessories()->count() > 0) {
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'accessory'])); return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'accessory']));
} elseif ($category->consumables()->count() > 0) { } elseif ($category->consumables()->count() > 0) {
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'consumable'])); return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'consumable']));
} elseif ($category->components()->count() > 0) { } elseif ($category->components()->count() > 0) {
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'component'])); return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'component']));
} else { }
$category->delete(); $category->delete();
// Redirect to the locations management page // Redirect to the locations management page
return redirect()->to('admin/settings/categories')->with('success', trans('admin/categories/message.delete.success')); return redirect()->to('admin/settings/categories')->with('success', trans('admin/categories/message.delete.success'));
} }
}
/** /**
* Returns a view that invokes the ajax tables which actually contains * Returns a view that invokes the ajax tables which actually contains
* the content for the categories detail view, which is generated in getDataView. * the content for the categories detail view, which is generated in getDataView.
@ -210,7 +187,7 @@ class CategoriesController extends Controller
* @see CategoriesController::getDataView() method that generates the JSON response * @see CategoriesController::getDataView() method that generates the JSON response
* @param int $categoryId * @param int $categoryId
* @since [v1.8] * @since [v1.8]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function show($categoryId = null) public function show($categoryId = null)
{ {
@ -218,25 +195,23 @@ class CategoriesController extends Controller
if (isset($category->id)) { if (isset($category->id)) {
return View::make('categories/view', compact('category')); return View::make('categories/view', compact('category'));
} else { }
// Prepare the error message // Prepare the error message
$error = trans('admin/categories/message.does_not_exist', compact('id')); $error = trans('admin/categories/message.does_not_exist', compact('id'));
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('categories.index')->with('error', $error); return redirect()->route('categories.index')->with('error', $error);
} }
}
/** /**
* Returns a JSON response with the data to populate the bootstrap table on the * Returns a JSON response with the data to populate the bootstrap table on the
* cateory listing page. * category listing page.
* *
* @todo Refactor this nastiness. Assets do not behave the same as accessories, etc. * @todo Refactor this nastiness. Assets do not behave the same as accessories, etc.
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see CategoriesController::getIndex() method that generates the view * @see CategoriesController::getIndex() method that generates the view
* @since [v1.8] * @since [v1.8]
* @param Request $request
* @return String JSON * @return String JSON
*/ */
public function getDatatable(Request $request) public function getDatatable(Request $request)
@ -248,18 +223,8 @@ class CategoriesController extends Controller
$categories = $categories->TextSearch(e($request->input('search'))); $categories = $categories->TextSearch(e($request->input('search')));
} }
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e($request->input('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e($request->input('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['id','name','category_type']; $allowed_columns = ['id','name','category_type'];
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
@ -273,14 +238,15 @@ class CategoriesController extends Controller
$rows = array(); $rows = array();
foreach ($categories as $category) { foreach ($categories as $category) {
$actions = Helper::generateDatatableButton('edit', route('categories.edit', $category->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('categories.destroy', $category->id),
$category->itemCount() == 0, /* enabled */
trans('admin/categories/message.delete.confirm'),
$category->name
);
$actions = '<a href="'.route('categories.edit', ['category' => $category->id]).'" class="btn btn-warning btn-sm" style="margin-right:5px;">';
$actions .='<i class="fa fa-pencil icon-white"></i></a>';
$actions .='<a data-html="false" class="btn delete-asset btn-danger btn-sm';
if ($category->itemCount() > 0) {
$actions .=' disabled';
}
$actions .=' data-toggle="modal" href="'.route('categories.destroy', ['category' => $category->id]).'" data-content="'.trans('admin/categories/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($category->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
$rows[] = array( $rows[] = array(
'id' => $category->id, 'id' => $category->id,
'name' => (string)link_to_route('categories.show', $category->name, ['category' => $category->id]) , 'name' => (string)link_to_route('categories.show', $category->name, ['category' => $category->id]) ,
@ -299,7 +265,6 @@ class CategoriesController extends Controller
public function getDataViewAssets(Request $request, $categoryID) public function getDataViewAssets(Request $request, $categoryID)
{ {
$category = Category::find($categoryID); $category = Category::find($categoryID);
$category = $category->load('assets.company', 'assets.model', 'assets.assetstatus', 'assets.assigneduser'); $category = $category->load('assets.company', 'assets.model', 'assets.assetstatus', 'assets.assigneduser');
$category_assets = $category->assets(); $category_assets = $category->assets();
@ -307,17 +272,8 @@ class CategoriesController extends Controller
$category_assets = $category_assets->TextSearch(e($request->input('search'))); $category_assets = $category_assets->TextSearch(e($request->input('search')));
} }
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e($request->input('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e($request->input('limit'));
} else {
$limit = 50;
}
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
@ -332,18 +288,28 @@ class CategoriesController extends Controller
$inout=''; $inout='';
if ($asset->deleted_at=='') { if ($asset->deleted_at=='') {
$actions = '<div style=" white-space: nowrap;"><a href="'.route('clone/hardware', $asset->id).'" class="btn btn-info btn-sm" title="Clone asset"><i class="fa fa-files-o"></i></a> <a href="'.route('hardware.edit', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('hardware.destroy', ['aseset' => $asset->id]).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->asset_tag).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>'; $actions = '<div style=" white-space: nowrap;">';
$actions .= Helper::generateDatatableButton('clone', route('clone/hardware', $asset->id));
$actions .= Helper::generateDatatableButton('edit', route('hardware.edit', $asset->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('hardware.destroy', $asset->id),
true, /* enabled */
trans('admin/hardware/message.delete.confirm'),
$asset->asset_tag
);
$actions .= '</div>';
} elseif ($asset->deleted_at!='') { } elseif ($asset->deleted_at!='') {
$actions = '<a href="'.route('restore/hardware', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>'; $actions = Helper::generateDatatableButton('restore', route('restore/hardware', $asset->id));
} }
if ($asset->availableForCheckout()) { if ($asset->availableForCheckout()) {
if (Gate::allows('checkout', $asset)) { if (Gate::allows('checkout', $asset)) {
$inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>'; $inout = Helper::generateDatatableButton('checkout', route('checkout/hardware', $asset->id));
} }
} else { } else {
if (Gate::allows('checkin', $asset)) { if (Gate::allows('checkin', $asset)) {
$inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>'; $inout = Helper::generateDatatableButton('checkin', route('checkin/hardware', $asset->id));
} }
} }
@ -365,48 +331,48 @@ class CategoriesController extends Controller
} }
/**
* @param $categoryID
* @return array
*/
public function getDataViewAccessories($categoryID) public function getDataViewAccessories($categoryID)
{ {
$category = Category::with('accessories.company')->find($categoryID); $category = Category::with('accessories.company')->find($categoryID);
$category_assets = $category->accessories; $category_accessories = $category->accessories();
if (Input::has('search')) { if (Input::has('search')) {
$category_assets = $category_assets->TextSearch(e($request->input('search'))); $category_accessories = $category_accessories->TextSearch(e($request->input('search')));
} }
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e($request->input('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e($request->input('limit'));
} else {
$limit = 50;
}
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$allowed_columns = ['id','name','serial','asset_tag']; $allowed_columns = ['id','name','serial','asset_tag'];
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
$count = $category_assets->count(); $count = $category_accessories->count();
$category_accessories = $category_accessories->skip($offset)->take($limit)->get();
$rows = array(); $rows = array();
foreach ($category_assets as $asset) { foreach ($category_accessories as $accessory) {
$actions = ''; $actions = '';
$inout='';
if ($asset->deleted_at=='') { if ($accessory->deleted_at=='') {
$actions = '<div style=" white-space: nowrap;"><a href="'.route('accessories.update', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('accessories.destroy', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>'; $actions = '<div style="white-space: nowrap;">';
$actions .= Helper::generateDatatableButton('edit', route('accessories.update', $accessory->id));
$actions .= Helper::generateDatatableButton('delete',
route('accessories.destroy', $accessory->id),
true, /* enabled */
trans('admin/accessories/message.delete.confirm'),
$accessory->name
);
$actions .= '</div>';
} }
$rows[] = array( $rows[] = array(
'id' => $asset->id, 'id' => $asset->id,
'name' => (string)link_to_route('view/accessory', $asset->name, [$asset->id]), 'name' => (string)link_to_route('view/accessory', $asset->name, [$asset->id]),
@ -429,10 +395,10 @@ class CategoriesController extends Controller
{ {
$category = Category::with('accessories.company')->find($categoryID); $category = Category::with('accessories.company')->find($categoryID);
$category_assets = $category->consumables; $category_consumables = $category->consumables();
if (Input::has('search')) { if (Input::has('search')) {
$category_assets = $category_assets->TextSearch(e($request->input('search'))); $category_consumables = $category_consumables->TextSearch(e($request->input('search')));
} }
$offset = request('offset', 0); $offset = request('offset', 0);
$limit = request('limit', 50); $limit = request('limit', 50);
@ -441,26 +407,32 @@ class CategoriesController extends Controller
$allowed_columns = ['id','name','serial','asset_tag']; $allowed_columns = ['id','name','serial','asset_tag'];
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
$count = $category_assets->count(); $count = $category_consumables->count();
$category_consumables = $category_consumables->skip($offset)->take($limit)->get();
$rows = array(); $rows = array();
foreach ($category_assets as $asset) { foreach ($category_consumables as $consumable) {
$actions = ''; $actions = '';
$inout='';
if ($asset->deleted_at=='') { if ($consumable->deleted_at=='') {
$actions = '<div style=" white-space: nowrap;"><a href="'.route('consumables.edit', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('consumables.destroy', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>'; $actions = '<div style="white-space: nowrap;">';
$actions .= Helper::generateDatatableButton('edit', route('consumables.update', $consumable->id));
$actions .= Helper::generateDatatableButton('delete',
route('consumables.destroy', $consumable->id),
true, /* enabled */
trans('admin/consumables/message.delete.confirm'),
$consumable->name
);
$actions .= '</div>';
} }
$rows[] = array( $rows[] = array(
'id' => $asset->id, 'id' => $consumable->id,
'name' => (string) link_to_route('consumables.show', $asset->name, [$asset->id]), 'name' => (string) link_to_route('consumables.show', $consumable->name, [$consumable->id]),
'actions' => $actions, 'actions' => $actions,
'companyName' => Company::getName($asset), 'companyName' => Company::getName($consumable),
); );
} }
@ -472,48 +444,44 @@ class CategoriesController extends Controller
{ {
$category = Category::with('accessories.company')->find($categoryID); $category = Category::with('accessories.company')->find($categoryID);
$category_assets = $category->components; $category_components = $category->components();
if (Input::has('search')) { if (Input::has('search')) {
$category_assets = $category_assets->TextSearch(e($request->input('search'))); $category_components = $category_components->TextSearch(e($request->input('search')));
} }
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e($request->input('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e($request->input('limit'));
} else {
$limit = 50;
}
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$allowed_columns = ['id','name','serial','asset_tag']; $allowed_columns = ['id','name','serial','asset_tag'];
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
$count = $category_assets->count(); $count = $category_components->count();
$category_components = $category_components->skip($offset)->take($limit)->get();
$rows = array(); $rows = array();
foreach ($category_components as $component) {
foreach ($category_assets as $asset) {
$actions = ''; $actions = '';
$inout='';
if ($asset->deleted_at=='') { if ($component->deleted_at=='') {
$actions = '<div style=" white-space: nowrap;"><a href="'.route('components.edit', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('components.destroy', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>'; $actions = '<div style="white-space: nowrap;">';
$actions .= Helper::generateDatatableButton('edit', route('components.edit', $component->id));
$actions .= Helper::generateDatatableButton('delete',
route('components.destroy', $component->id),
true, /* enabled */
trans('admin/components/message.delete.confirm'),
$component->name
);
$actions .= '</div>';
} }
$rows[] = array( $rows[] = array(
'id' => $asset->id, 'id' => $component->id,
'name' => (string)link_to_route('view/accessory', $asset->name, [$asset->id]), 'name' => (string)link_to_route('view/accessory', $component->name, [$component->id]),
'actions' => $actions, 'actions' => $actions,
'companyName' => Company::getName($asset), 'companyName' => Company::getName($component),
); );
} }

View file

@ -23,7 +23,7 @@ final class CompaniesController extends Controller
* *
* @author [Abdullah Alansari] [<ahimta@gmail.com>] * @author [Abdullah Alansari] [<ahimta@gmail.com>]
* @since [v1.8] * @since [v1.8]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
{ {
@ -35,7 +35,7 @@ final class CompaniesController extends Controller
* *
* @author [Abdullah Alansari] [<ahimta@gmail.com>] * @author [Abdullah Alansari] [<ahimta@gmail.com>]
* @since [v1.8] * @since [v1.8]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
@ -47,20 +47,19 @@ final class CompaniesController extends Controller
* *
* @author [Abdullah Alansari] [<ahimta@gmail.com>] * @author [Abdullah Alansari] [<ahimta@gmail.com>]
* @since [v1.8] * @since [v1.8]
* @return Redirect * @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/ */
public function store(Request $request) public function store(Request $request)
{ {
$company = new Company; $company = new Company;
$company->name = e($request->input('name')); $company->name = $request->input('name');
if ($company->save()) { if ($company->save()) {
return redirect()->route('companies.index') return redirect()->route('companies.index')
->with('success', trans('admin/companies/message.create.success')); ->with('success', trans('admin/companies/message.create.success'));
} else {
return redirect()->back()->withInput()->withErrors($company->getErrors());
} }
return redirect()->back()->withInput()->withErrors($company->getErrors());
} }
@ -70,16 +69,15 @@ final class CompaniesController extends Controller
* @author [Abdullah Alansari] [<ahimta@gmail.com>] * @author [Abdullah Alansari] [<ahimta@gmail.com>]
* @since [v1.8] * @since [v1.8]
* @param int $companyId * @param int $companyId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function edit($companyId) public function edit($companyId)
{ {
if (is_null($item = Company::find($companyId))) { if (is_null($item = Company::find($companyId))) {
return redirect()->route('companies.index') return redirect()->route('companies.index')
->with('error', trans('admin/companies/message.does_not_exist')); ->with('error', trans('admin/companies/message.does_not_exist'));
} else {
return View::make('companies/edit')->with('item', $item);
} }
return View::make('companies/edit')->with('item', $item);
} }
/** /**
@ -87,36 +85,33 @@ final class CompaniesController extends Controller
* *
* @author [Abdullah Alansari] [<ahimta@gmail.com>] * @author [Abdullah Alansari] [<ahimta@gmail.com>]
* @since [v1.8] * @since [v1.8]
* @param Request $request
* @param int $companyId * @param int $companyId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function update(Request $request, $companyId) public function update(Request $request, $companyId)
{ {
if (is_null($company = Company::find($companyId))) { if (is_null($company = Company::find($companyId))) {
return redirect()->route('companies.index')->with('error', trans('admin/companies/message.does_not_exist')); return redirect()->route('companies.index')->with('error', trans('admin/companies/message.does_not_exist'));
} else { }
$company->name = $request->input('name');
$company->name = e($request->input('name'));
if ($company->save()) { if ($company->save()) {
return redirect()->route('companies.index') return redirect()->route('companies.index')
->with('success', trans('admin/companies/message.update.success')); ->with('success', trans('admin/companies/message.update.success'));
} else { }
return redirect()->route('companies.edit', ['company' => $companyId]) return redirect()->route('companies.edit', ['company' => $companyId])
->with('error', trans('admin/companies/message.update.error')); ->with('error', trans('admin/companies/message.update.error'));
} }
}
}
/** /**
* Delete company * Delete company
* *
* @author [Abdullah Alansari] [<ahimta@gmail.com>] * @author [Abdullah Alansari] [<ahimta@gmail.com>]
* @since [v1.8] * @since [v1.8]
* @param int $companyId * @param int $companyId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($companyId) public function destroy($companyId)
{ {

View file

@ -11,6 +11,7 @@ use App\Models\Asset;
use Auth; use Auth;
use Config; use Config;
use DB; use DB;
use DeepCopyTest\H;
use Input; use Input;
use Lang; use Lang;
use Mail; use Mail;
@ -37,7 +38,7 @@ class ComponentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ComponentsController::getDatatable() method that generates the JSON response * @see ComponentsController::getDatatable() method that generates the JSON response
* @since [v3.0] * @since [v3.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
{ {
@ -52,21 +53,17 @@ class ComponentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ComponentsController::postCreate() method that stores the data * @see ComponentsController::postCreate() method that stores the data
* @since [v3.0] * @since [v3.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
$this->authorize('create', Component::class); $this->authorize('create', Component::class);
// Show the page // Show the page
$category_list = Helper::categoryList('component');
$company_list = Helper::companyList();
$location_list = Helper::locationsList();
return View::make('components/edit') return View::make('components/edit')
->with('item', new Component) ->with('item', new Component)
->with('category_list', $category_list) ->with('category_list', Helper::categoryList('component'))
->with('company_list', $company_list) ->with('company_list', Helper::companyList())
->with('location_list', $location_list); ->with('location_list', Helper::locationsList());
} }
@ -76,7 +73,7 @@ class ComponentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ComponentsController::getCreate() method that generates the view * @see ComponentsController::getCreate() method that generates the view
* @since [v3.0] * @since [v3.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function store() public function store()
{ {
@ -85,28 +82,28 @@ class ComponentsController extends Controller
$component = new Component(); $component = new Component();
// Update the component data // Update the component data
$component->name = e(Input::get('name')); $component->name = Input::get('name');
$component->category_id = e(Input::get('category_id')); $component->category_id = Input::get('category_id');
$component->location_id = e(Input::get('location_id')); $component->location_id = Input::get('location_id');
$component->company_id = Company::getIdForCurrentUser(Input::get('company_id')); $component->company_id = Company::getIdForCurrentUser(Input::get('company_id'));
$component->order_number = e(Input::get('order_number')); $component->order_number = Input::get('order_number');
$component->min_amt = e(Input::get('min_amt')); $component->min_amt = Input::get('min_amt');
$component->serial = e(Input::get('serial')); $component->serial = Input::get('serial');
if (e(Input::get('purchase_date')) == '') { if (Input::get('purchase_date') == '') {
$component->purchase_date = null; $component->purchase_date = null;
} else { } else {
$component->purchase_date = e(Input::get('purchase_date')); $component->purchase_date = Input::get('purchase_date');
} }
if (e(Input::get('purchase_cost')) == '0.00') { if (Input::get('purchase_cost') == '0.00') {
$component->purchase_cost = null; $component->purchase_cost = null;
} else { } else {
$component->purchase_cost = Helper::ParseFloat(e(Input::get('purchase_cost'))); $component->purchase_cost = Helper::ParseFloat(Input::get('purchase_cost'));
} }
$component->qty = e(Input::get('qty')); $component->qty = Input::get('qty');
$component->user_id = Auth::user()->id; $component->user_id = Auth::id();
// Was the component created? // Was the component created?
if ($component->save()) { if ($component->save()) {
@ -114,10 +111,7 @@ class ComponentsController extends Controller
// Redirect to the new component page // Redirect to the new component page
return redirect()->route('components.index')->with('success', trans('admin/components/message.create.success')); return redirect()->route('components.index')->with('success', trans('admin/components/message.create.success'));
} }
return redirect()->back()->withInput()->withErrors($component->getErrors()); return redirect()->back()->withInput()->withErrors($component->getErrors());
} }
/** /**
@ -127,7 +121,7 @@ class ComponentsController extends Controller
* @see ComponentsController::postEdit() method that stores the data. * @see ComponentsController::postEdit() method that stores the data.
* @since [v3.0] * @since [v3.0]
* @param int $componentId * @param int $componentId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function edit($componentId = null) public function edit($componentId = null)
{ {
@ -139,14 +133,10 @@ class ComponentsController extends Controller
$this->authorize('update', $item); $this->authorize('update', $item);
$category_list = Helper::categoryList('component');
$company_list = Helper::companyList();
$location_list = Helper::locationsList();
return View::make('components/edit', compact('item')) return View::make('components/edit', compact('item'))
->with('category_list', $category_list) ->with('category_list', Helper::categoryList('component'))
->with('company_list', $company_list) ->with('company_list', Helper::companyList())
->with('location_list', $location_list); ->with('location_list', Helper::locationsList());
} }
@ -157,7 +147,7 @@ class ComponentsController extends Controller
* @see ComponentsController::getEdit() method presents the form. * @see ComponentsController::getEdit() method presents the form.
* @param int $componentId * @param int $componentId
* @since [v3.0] * @since [v3.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function update($componentId = null) public function update($componentId = null)
{ {
@ -171,34 +161,32 @@ class ComponentsController extends Controller
// Update the component data // Update the component data
$component->name = e(Input::get('name')); $component->name = Input::get('name');
$component->category_id = e(Input::get('category_id')); $component->category_id = Input::get('category_id');
$component->location_id = e(Input::get('location_id')); $component->location_id = Input::get('location_id');
$component->company_id = Company::getIdForCurrentUser(Input::get('company_id')); $component->company_id = Company::getIdForCurrentUser(Input::get('company_id'));
$component->order_number = e(Input::get('order_number')); $component->order_number = Input::get('order_number');
$component->min_amt = e(Input::get('min_amt')); $component->min_amt = Input::get('min_amt');
$component->serial = e(Input::get('serial')); $component->serial = Input::get('serial');
if (e(Input::get('purchase_date')) == '') { if (Input::get('purchase_date') == '') {
$component->purchase_date = null; $component->purchase_date = null;
} else { } else {
$component->purchase_date = e(Input::get('purchase_date')); $component->purchase_date = Input::get('purchase_date');
} }
if (e(Input::get('purchase_cost')) == '0.00') { if (Input::get('purchase_cost') == '0.00') {
$component->purchase_cost = null; $component->purchase_cost = null;
} else { } else {
$component->purchase_cost = Helper::ParseFloat(e(Input::get('purchase_cost'))); $component->purchase_cost = Helper::ParseFloat(Input::get('purchase_cost'));
} }
$component->qty = e(Input::get('qty')); $component->qty = Input::get('qty');
if ($component->save()) { if ($component->save()) {
return redirect()->route('components.index')->with('success', trans('admin/components/message.update.success')); return redirect()->route('components.index')->with('success', trans('admin/components/message.update.success'));
} }
return redirect()->back()->withInput()->withErrors($component->getErrors()); return redirect()->back()->withInput()->withErrors($component->getErrors());
} }
/** /**
@ -207,7 +195,7 @@ class ComponentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0] * @since [v3.0]
* @param int $componentId * @param int $componentId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($componentId) public function destroy($componentId)
{ {
@ -216,10 +204,8 @@ class ComponentsController extends Controller
} }
$this->authorize('delete', $component); $this->authorize('delete', $component);
$component->delete(); $component->delete();
return redirect()->route('components.index')->with('success', trans('admin/components/message.delete.success')); return redirect()->route('components.index')->with('success', trans('admin/components/message.delete.success'));
} }
public function postBulk($componentId = null) public function postBulk($componentId = null)
@ -242,25 +228,20 @@ class ComponentsController extends Controller
* @see ComponentsController::getDataView() method that generates the JSON response * @see ComponentsController::getDataView() method that generates the JSON response
* @since [v3.0] * @since [v3.0]
* @param int $componentId * @param int $componentId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function show($componentId = null) public function show($componentId = null)
{ {
$component = Component::find($componentId); $component = Component::find($componentId);
if (isset($component->id)) { if (isset($component->id)) {
$this->authorize('view', $component); $this->authorize('view', $component);
return View::make('components/view', compact('component')); return View::make('components/view', compact('component'));
} }
// Prepare the error message // Prepare the error message
$error = trans('admin/components/message.does_not_exist', compact('id')); $error = trans('admin/components/message.does_not_exist', compact('id'));
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('components')->with('error', $error); return redirect()->route('components')->with('error', $error);
} }
/** /**
@ -270,7 +251,7 @@ class ComponentsController extends Controller
* @see ComponentsController::postCheckout() method that stores the data. * @see ComponentsController::postCheckout() method that stores the data.
* @since [v3.0] * @since [v3.0]
* @param int $componentId * @param int $componentId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function getCheckout($componentId) public function getCheckout($componentId)
{ {
@ -279,14 +260,8 @@ class ComponentsController extends Controller
// Redirect to the component management page with error // Redirect to the component management page with error
return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found')); return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found'));
} }
$this->authorize('checkout', $component); $this->authorize('checkout', $component);
return View::make('components/checkout', compact('component'))->with('assets_list', Helper::detailedAssetList());
// Get the dropdown of assets and then pass it to the checkout view
$assets_list = Helper::detailedAssetList();
return View::make('components/checkout', compact('component'))->with('assets_list', $assets_list);
} }
/** /**
@ -295,8 +270,9 @@ class ComponentsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ComponentsController::getCheckout() method that returns the form. * @see ComponentsController::getCheckout() method that returns the form.
* @since [v3.0] * @since [v3.0]
* @param Request $request
* @param int $componentId * @param int $componentId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postCheckout(Request $request, $componentId) public function postCheckout(Request $request, $componentId)
{ {
@ -332,12 +308,13 @@ class ComponentsController extends Controller
// Update the component data // Update the component data
$component->asset_id = $asset_id; $component->asset_id = $asset_id;
$component->assets()->attach($component->id, array( $component->assets()->attach($component->id, [
'component_id' => $component->id, 'component_id' => $component->id,
'user_id' => $admin_user->id, 'user_id' => $admin_user->id,
'created_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s'),
'assigned_qty' => e(Input::get('assigned_qty')), 'assigned_qty' => Input::get('assigned_qty'),
'asset_id' => $asset_id)); 'asset_id' => $asset_id
]);
$logaction = $component->logCheckout(e(Input::get('note')), $asset_id); $logaction = $component->logCheckout(e(Input::get('note')), $asset_id);
@ -377,9 +354,6 @@ class ComponentsController extends Controller
} }
return redirect()->route('components.index')->with('success', trans('admin/components/message.checkout.success')); return redirect()->route('components.index')->with('success', trans('admin/components/message.checkout.success'));
} }
@ -402,17 +376,8 @@ class ComponentsController extends Controller
$components = $components->TextSearch(Input::get('search')); $components = $components->TextSearch(Input::get('search'));
} }
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e(Input::get('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e(Input::get('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['id','name','min_amt','order_number','serial','purchase_date','purchase_cost','companyName','category','total_qty']; $allowed_columns = ['id','name','min_amt','order_number','serial','purchase_date','purchase_cost','companyName','category','total_qty'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
@ -433,7 +398,7 @@ class ComponentsController extends Controller
break; break;
} }
$consumCount = $components->count(); $componentsCount = $components->count();
$components = $components->skip($offset)->take($limit)->get(); $components = $components->skip($offset)->take($limit)->get();
$rows = array(); $rows = array();
@ -441,18 +406,21 @@ class ComponentsController extends Controller
foreach ($components as $component) { foreach ($components as $component) {
$actions = '<nobr>'; $actions = '<nobr>';
if (Gate::allows('checkout', $component)) { if (Gate::allows('checkout', $component)) {
$actions .= '<a href="' . route('checkout/component', $actions .= Helper::generateDatatableButton('checkout', route('checkout/component', $component->id), $component->numRemaining() > 0);
$component->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm ' . (($component->numRemaining() > 0) ? '' : ' disabled') . '" ' . (($component->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>';
} }
if (Gate::allows('edit', $component)) { if (Gate::allows('update', $component)) {
$actions .= '<a href="' . route('components.edit', $actions .= Helper::generateDatatableButton('edit', route('components.edit', $component->id));
$component->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
} }
if (Gate::allows('delete', $component)) { if (Gate::allows('delete', $component)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('components.destroy', $actions .= Helper::generateDatatableButton(
$component->id) . '" data-content="' . trans('admin/components/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($component->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; 'delete',
route('components.destroy', $component->id),
true, /* enabled */
trans('admin/components/message.delete.confirm'),
$component->name
);
} }
$actions .='</nobr>'; $actions .='</nobr>';
@ -476,7 +444,7 @@ class ComponentsController extends Controller
); );
} }
$data = array('total' => $consumCount, 'rows' => $rows); $data = array('total' => $componentsCount, 'rows' => $rows);
return $data; return $data;

View file

@ -34,7 +34,7 @@ class ConsumablesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ConsumablesController::getDatatable() method that generates the JSON response * @see ConsumablesController::getDatatable() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
{ {
@ -49,23 +49,18 @@ class ConsumablesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ConsumablesController::postCreate() method that stores the form data * @see ConsumablesController::postCreate() method that stores the form data
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
$this->authorize('create', Consumable::class); $this->authorize('create', Consumable::class);
// Show the page // Show the page
$category_list = Helper::categoryList('consumable');
$company_list = Helper::companyList();
$location_list = Helper::locationsList();
$manufacturer_list = Helper::manufacturerList();
return View::make('consumables/edit') return View::make('consumables/edit')
->with('item', new Consumable) ->with('item', new Consumable)
->with('category_list', $category_list) ->with('category_list', Helper::categoryList('consumable'))
->with('company_list', $company_list) ->with('company_list', Helper::companyList())
->with('location_list', $location_list) ->with('location_list', Helper::locationsList())
->with('manufacturer_list', $manufacturer_list); ->with('manufacturer_list', Helper::manufacturerList());
} }
@ -75,36 +70,36 @@ class ConsumablesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ConsumablesController::getCreate() method that returns the form view * @see ConsumablesController::getCreate() method that returns the form view
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function store() public function store()
{ {
$this->authorize('create', Consumable::class); $this->authorize('create', Consumable::class);
$consumable = new Consumable(); $consumable = new Consumable();
$consumable->name = e(Input::get('name')); $consumable->name = Input::get('name');
$consumable->category_id = e(Input::get('category_id')); $consumable->category_id = Input::get('category_id');
$consumable->location_id = e(Input::get('location_id')); $consumable->location_id = Input::get('location_id');
$consumable->company_id = Company::getIdForCurrentUser(Input::get('company_id')); $consumable->company_id = Company::getIdForCurrentUser(Input::get('company_id'));
$consumable->order_number = e(Input::get('order_number')); $consumable->order_number = Input::get('order_number');
$consumable->min_amt = e(Input::get('min_amt')); $consumable->min_amt = Input::get('min_amt');
$consumable->manufacturer_id = e(Input::get('manufacturer_id')); $consumable->manufacturer_id = Input::get('manufacturer_id');
$consumable->model_number = e(Input::get('model_number')); $consumable->model_number = Input::get('model_number');
$consumable->item_no = e(Input::get('item_no')); $consumable->item_no = Input::get('item_no');
if (e(Input::get('purchase_date')) == '') { if (Input::get('purchase_date') == '') {
$consumable->purchase_date = null; $consumable->purchase_date = null;
} else { } else {
$consumable->purchase_date = e(Input::get('purchase_date')); $consumable->purchase_date = Input::get('purchase_date');
} }
if (e(Input::get('purchase_cost')) == '0.00') { if (Input::get('purchase_cost') == '0.00') {
$consumable->purchase_cost = null; $consumable->purchase_cost = null;
} else { } else {
$consumable->purchase_cost = Helper::ParseFloat(e(Input::get('purchase_cost'))); $consumable->purchase_cost = Helper::ParseFloat(Input::get('purchase_cost'));
} }
$consumable->qty = e(Input::get('qty')); $consumable->qty = Input::get('qty');
$consumable->user_id = Auth::user()->id; $consumable->user_id = Auth::id();
// Was the consumable created? // Was the consumable created?
if ($consumable->save()) { if ($consumable->save()) {
@ -125,7 +120,7 @@ class ConsumablesController extends Controller
* @param int $consumableId * @param int $consumableId
* @see ConsumablesController::postEdit() method that stores the form data. * @see ConsumablesController::postEdit() method that stores the form data.
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function edit($consumableId = null) public function edit($consumableId = null)
{ {
@ -137,16 +132,11 @@ class ConsumablesController extends Controller
$this->authorize($item); $this->authorize($item);
$category_list = Helper::categoryList('consumable');
$company_list = Helper::companyList();
$location_list = Helper::locationsList();
$manufacturer_list = Helper::manufacturerList();
return View::make('consumables/edit', compact('item')) return View::make('consumables/edit', compact('item'))
->with('category_list', $category_list) ->with('category_list', Helper::categoryList('consumable'))
->with('company_list', $company_list) ->with('company_list', Helper::companyList())
->with('location_list', $location_list) ->with('location_list', Helper::locationsList())
->with('manufacturer_list', $manufacturer_list); ->with('manufacturer_list', Helper::manufacturerList());
} }
@ -157,7 +147,7 @@ class ConsumablesController extends Controller
* @param int $consumableId * @param int $consumableId
* @see ConsumablesController::getEdit() method that stores the form data. * @see ConsumablesController::getEdit() method that stores the form data.
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function update($consumableId = null) public function update($consumableId = null)
{ {
@ -167,36 +157,34 @@ class ConsumablesController extends Controller
$this->authorize($consumable); $this->authorize($consumable);
$consumable->name = e(Input::get('name')); $consumable->name = Input::get('name');
$consumable->category_id = e(Input::get('category_id')); $consumable->category_id = Input::get('category_id');
$consumable->location_id = e(Input::get('location_id')); $consumable->location_id = Input::get('location_id');
$consumable->company_id = Company::getIdForCurrentUser(Input::get('company_id')); $consumable->company_id = Company::getIdForCurrentUser(Input::get('company_id'));
$consumable->order_number = e(Input::get('order_number')); $consumable->order_number = Input::get('order_number');
$consumable->min_amt = e(Input::get('min_amt')); $consumable->min_amt = Input::get('min_amt');
$consumable->manufacturer_id = e(Input::get('manufacturer_id')); $consumable->manufacturer_id = Input::get('manufacturer_id');
$consumable->model_number = e(Input::get('model_number')); $consumable->model_number = Input::get('model_number');
$consumable->item_no = e(Input::get('item_no')); $consumable->item_no = Input::get('item_no');
if (e(Input::get('purchase_date')) == '') { if (Input::get('purchase_date') == '') {
$consumable->purchase_date = null; $consumable->purchase_date = null;
} else { } else {
$consumable->purchase_date = e(Input::get('purchase_date')); $consumable->purchase_date = Input::get('purchase_date');
} }
if (e(Input::get('purchase_cost')) == '0.00') { if (Input::get('purchase_cost') == '0.00') {
$consumable->purchase_cost = null; $consumable->purchase_cost = null;
} else { } else {
$consumable->purchase_cost = Helper::ParseFloat(e(Input::get('purchase_cost'))); $consumable->purchase_cost = Helper::ParseFloat(Input::get('purchase_cost'));
} }
$consumable->qty = Helper::ParseFloat(e(Input::get('qty'))); $consumable->qty = Helper::ParseFloat(Input::get('qty'));
if ($consumable->save()) { if ($consumable->save()) {
return redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.update.success')); return redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.update.success'));
} }
return redirect()->back()->withInput()->withErrors($consumable->getErrors()); return redirect()->back()->withInput()->withErrors($consumable->getErrors());
} }
/** /**
@ -205,7 +193,7 @@ class ConsumablesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $consumableId * @param int $consumableId
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($consumableId) public function destroy($consumableId)
{ {
@ -214,18 +202,12 @@ class ConsumablesController extends Controller
// Redirect to the blogs management page // Redirect to the blogs management page
return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.not_found')); return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.not_found'));
} }
$this->authorize($consumable); $this->authorize($consumable);
$consumable->delete(); $consumable->delete();
// Redirect to the locations management page // Redirect to the locations management page
return redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.delete.success')); return redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.delete.success'));
} }
/** /**
* Return a view to display component information. * Return a view to display component information.
* *
@ -233,7 +215,7 @@ class ConsumablesController extends Controller
* @see ConsumablesController::getDataView() method that generates the JSON response * @see ConsumablesController::getDataView() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @param int $consumableId * @param int $consumableId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function show($consumableId = null) public function show($consumableId = null)
{ {
@ -256,7 +238,7 @@ class ConsumablesController extends Controller
* @see ConsumablesController::postCheckout() method that stores the data. * @see ConsumablesController::postCheckout() method that stores the data.
* @since [v1.0] * @since [v1.0]
* @param int $consumableId * @param int $consumableId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function getCheckout($consumableId) public function getCheckout($consumableId)
{ {
@ -266,12 +248,8 @@ class ConsumablesController extends Controller
return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.not_found')); return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.not_found'));
} }
$this->authorize('checkout', $consumable); $this->authorize('checkout', $consumable);
// Get the dropdown of users and then pass it to the checkout view // Get the dropdown of users and then pass it to the checkout view
$users_list = Helper::usersList(); return View::make('consumables/checkout', compact('consumable'))->with('users_list', Helper::usersList());
return View::make('consumables/checkout', compact('consumable'))->with('users_list', $users_list);
} }
/** /**
@ -281,7 +259,7 @@ class ConsumablesController extends Controller
* @see ConsumablesController::getCheckout() method that returns the form. * @see ConsumablesController::getCheckout() method that returns the form.
* @since [v1.0] * @since [v1.0]
* @param int $consumableId * @param int $consumableId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postCheckout($consumableId) public function postCheckout($consumableId)
{ {
@ -305,10 +283,11 @@ class ConsumablesController extends Controller
// Update the consumable data // Update the consumable data
$consumable->assigned_to = e(Input::get('assigned_to')); $consumable->assigned_to = e(Input::get('assigned_to'));
$consumable->users()->attach($consumable->id, array( $consumable->users()->attach($consumable->id, [
'consumable_id' => $consumable->id, 'consumable_id' => $consumable->id,
'user_id' => $admin_user->id, 'user_id' => $admin_user->id,
'assigned_to' => e(Input::get('assigned_to')))); 'assigned_to' => e(Input::get('assigned_to'))
]);
$logaction = $consumable->logCheckout(e(Input::get('note'))); $logaction = $consumable->logCheckout(e(Input::get('note')));
@ -356,7 +335,6 @@ class ConsumablesController extends Controller
$data['note'] = $logaction->note; $data['note'] = $logaction->note;
$data['require_acceptance'] = $consumable->requireAcceptance(); $data['require_acceptance'] = $consumable->requireAcceptance();
if (($consumable->requireAcceptance()=='1') || ($consumable->getEula())) { if (($consumable->requireAcceptance()=='1') || ($consumable->getEula())) {
Mail::send('emails.accept-asset', $data, function ($m) use ($user) { Mail::send('emails.accept-asset', $data, function ($m) use ($user) {
@ -369,8 +347,6 @@ class ConsumablesController extends Controller
// Redirect to the new consumable page // Redirect to the new consumable page
return redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.checkout.success')); return redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.checkout.success'));
} }
@ -380,8 +356,7 @@ class ConsumablesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ConsumablesController::getIndex() method that returns the view that consumes the JSON. * @see ConsumablesController::getIndex() method that returns the view that consumes the JSON.
* @since [v1.0] * @since [v1.0]
* @param int $consumableId * @return array
* @return View
*/ */
public function getDatatable() public function getDatatable()
{ {
@ -396,18 +371,8 @@ class ConsumablesController extends Controller
$consumables = $consumables->TextSearch(e(Input::get('search'))); $consumables = $consumables->TextSearch(e(Input::get('search')));
} }
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e(Input::get('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e(Input::get('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['id','name','order_number','min_amt','purchase_date','purchase_cost','companyName','category','model_number', 'item_no', 'manufacturer']; $allowed_columns = ['id','name','order_number','min_amt','purchase_date','purchase_cost','companyName','category','model_number', 'item_no', 'manufacturer'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at'; $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
@ -438,19 +403,21 @@ class ConsumablesController extends Controller
foreach ($consumables as $consumable) { foreach ($consumables as $consumable) {
$actions = '<nobr>'; $actions = '<nobr>';
if (Gate::allows('checkout', $consumable)) { if (Gate::allows('checkout', $consumable)) {
$actions .= '<a href="' . route('checkout/consumable', $actions .= Helper::generateDatatableButton('checkout', route('checkout/consumable', $consumable->id), $consumable->numRemaining() > 0);
$consumable->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm" ' . (($consumable->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>';
} }
if (Gate::allows('update', $consumable)) { if (Gate::allows('update', $consumable)) {
$actions .= '<a href="' . route('consumables.edit', $actions .= Helper::generateDatatableButton('edit', route('consumables.edit', $consumable->id));
$consumable->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
} }
if (Gate::allows('delete', $consumable)) { if (Gate::allows('delete', $consumable)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('consumables.destroy', $actions .= Helper::generateDatatableButton(
$consumable->id) . '" data-content="' . trans('admin/consumables/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($consumable->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; 'delete',
route('consumables.destroy', $consumable->id),
true, /* enabled */
trans('admin/consumables/message.delete.confirm'),
$consumable->name
);
} }
$actions .='</nobr>'; $actions .='</nobr>';
$company = $consumable->company; $company = $consumable->company;
@ -487,7 +454,7 @@ class ConsumablesController extends Controller
* @see ConsumablesController::getView() method that returns the form. * @see ConsumablesController::getView() method that returns the form.
* @since [v1.0] * @since [v1.0]
* @param int $consumableId * @param int $consumableId
* @return View * @return array
*/ */
public function getDataView($consumableId) public function getDataView($consumableId)
{ {
@ -507,7 +474,7 @@ class ConsumablesController extends Controller
if (!Company::isCurrentUserHasAccess($consumable)) { if (!Company::isCurrentUserHasAccess($consumable)) {
return ['total' => 0, 'rows' => []]; return ['total' => 0, 'rows' => []];
} }
$this->authorize('view', Component::class);
$rows = array(); $rows = array();
foreach ($consumable->consumableAssigments as $consumable_assignment) { foreach ($consumable->consumableAssigments as $consumable_assignment) {

View file

@ -1,6 +1,7 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\Helper;
use Lang; use Lang;
use App\Models\Depreciation; use App\Models\Depreciation;
use Redirect; use Redirect;
@ -26,7 +27,7 @@ class DepreciationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net] * @author [A. Gianotto] [<snipe@snipe.net]
* @see DepreciationsController::getDatatable() method that generates the JSON response * @see DepreciationsController::getDatatable() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
{ {
@ -41,7 +42,7 @@ class DepreciationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net] * @author [A. Gianotto] [<snipe@snipe.net]
* @see DepreciationsController::postCreate() * @see DepreciationsController::postCreate()
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
@ -56,30 +57,24 @@ class DepreciationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net] * @author [A. Gianotto] [<snipe@snipe.net]
* @see DepreciationsController::postCreate() * @see DepreciationsController::postCreate()
* @since [v1.0] * @since [v1.0]
* @return Redirect * @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/ */
public function store(Request $request) public function store(Request $request)
{ {
// get the POST data
$new = $request->all();
// create a new instance // create a new instance
$depreciation = new Depreciation(); $depreciation = new Depreciation();
// Depreciation data // Depreciation data
$depreciation->name = e($request->input('name')); $depreciation->name = $request->input('name');
$depreciation->months = e($request->input('months')); $depreciation->months = $request->input('months');
$depreciation->user_id = Auth::user()->id; $depreciation->user_id = Auth::id();
// Was the asset created? // Was the asset created?
if ($depreciation->save()) { if ($depreciation->save()) {
// Redirect to the new depreciation page // Redirect to the new depreciation page
return redirect()->route('depreciations.index')->with('success', trans('admin/depreciations/message.create.success')); return redirect()->route('depreciations.index')->with('success', trans('admin/depreciations/message.create.success'));
} }
return redirect()->back()->withInput()->withErrors($depreciation->getErrors()); return redirect()->back()->withInput()->withErrors($depreciation->getErrors());
} }
/** /**
@ -89,7 +84,7 @@ class DepreciationsController extends Controller
* @see DepreciationsController::postEdit() * @see DepreciationsController::postEdit()
* @param int $depreciationId * @param int $depreciationId
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function edit($depreciationId = null) public function edit($depreciationId = null)
{ {
@ -110,7 +105,7 @@ class DepreciationsController extends Controller
* @see DepreciationsController::getEdit() * @see DepreciationsController::getEdit()
* @param Request $request * @param Request $request
* @param int $depreciationId * @param int $depreciationId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
* @since [v1.0] * @since [v1.0]
*/ */
public function update(Request $request, $depreciationId = null) public function update(Request $request, $depreciationId = null)
@ -122,18 +117,15 @@ class DepreciationsController extends Controller
} }
// Depreciation data // Depreciation data
$depreciation->name = e($request->input('name')); $depreciation->name = $request->input('name');
$depreciation->months = e($request->input('months')); $depreciation->months = $request->input('months');
// Was the asset created? // Was the asset created?
if ($depreciation->save()) { if ($depreciation->save()) {
// Redirect to the depreciation page // Redirect to the depreciation page
return redirect()->route("depreciations.index")->with('success', trans('admin/depreciations/message.update.success')); return redirect()->route("depreciations.index")->with('success', trans('admin/depreciations/message.update.success'));
} }
return redirect()->back()->withInput()->withErrors($depreciation->getErrors()); return redirect()->back()->withInput()->withErrors($depreciation->getErrors());
} }
/** /**
@ -143,28 +135,24 @@ class DepreciationsController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net] * @author [A. Gianotto] [<snipe@snipe.net]
* @since [v1.0] * @since [v1.0]
* @return Redirect * @param integer $depreciationId
* @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($depreciationId) public function destroy($depreciationId)
{ {
// Check if the depreciation exists // Check if the depreciation exists
if (is_null($depreciation = Depreciation::find($depreciationId))) { if (is_null($depreciation = Depreciation::find($depreciationId))) {
// Redirect to the blogs management page
return redirect()->route('depreciations.index')->with('error', trans('admin/depreciations/message.not_found')); return redirect()->route('depreciations.index')->with('error', trans('admin/depreciations/message.not_found'));
} }
if ($depreciation->has_models() > 0) { if ($depreciation->has_models() > 0) {
// Redirect to the asset management page // Redirect to the asset management page
return redirect()->route('depreciations.index')->with('error', trans('admin/depreciations/message.assoc_users')); return redirect()->route('depreciations.index')->with('error', trans('admin/depreciations/message.assoc_users'));
} else {
$depreciation->delete();
// Redirect to the depreciations management page
return redirect()->route('depreciations.index')->with('success', trans('admin/depreciations/message.delete.success'));
} }
$depreciation->delete();
// Redirect to the depreciations management page
return redirect()->route('depreciations.index')->with('success', trans('admin/depreciations/message.delete.success'));
} }
@ -173,9 +161,10 @@ class DepreciationsController extends Controller
* *
* @see DepreciationsController::getIndex() * @see DepreciationsController::getIndex()
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @param string $status * @param Request $request
* @since [v1.2]
* @return String JSON * @return String JSON
* @internal param string $status
* @since [v1.2]
*/ */
public function getDatatable(Request $request) public function getDatatable(Request $request)
{ {
@ -185,17 +174,8 @@ class DepreciationsController extends Controller
$depreciations = $depreciations->TextSearch(e($request->input('search'))); $depreciations = $depreciations->TextSearch(e($request->input('search')));
} }
if ($request->has('offset')) { $offset = request('offset', 0);
$offset = e($request->input('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if ($request->has('limit')) {
$limit = e($request->input('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['id','name','months']; $allowed_columns = ['id','name','months'];
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
@ -209,7 +189,14 @@ class DepreciationsController extends Controller
$rows = array(); $rows = array();
foreach ($depreciations as $depreciation) { foreach ($depreciations as $depreciation) {
$actions = '<a href="'.route('depreciations.edit', $depreciation->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('depreciations.destroy', $depreciation->id).'" data-content="'.trans('admin/depreciations/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($depreciation->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; $actions = Helper::generateDatatableButton('edit', route('depreciations.edit', $depreciation->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('depreciations.destroy', $depreciation->id),
true, /*enabled*/
trans('admin/depreciations/message.delete.confirm'),
$depreciation->name
);
$rows[] = array( $rows[] = array(
'id' => $depreciation->id, 'id' => $depreciation->id,

View file

@ -26,7 +26,7 @@ class GroupsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net] * @author [A. Gianotto] [<snipe@snipe.net]
* @see GroupsController::getDatatable() method that generates the JSON response * @see GroupsController::getDatatable() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function getIndex() public function getIndex()
{ {
@ -40,7 +40,7 @@ class GroupsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net] * @author [A. Gianotto] [<snipe@snipe.net]
* @see GroupsController::postCreate() * @see GroupsController::postCreate()
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function getCreate() public function getCreate()
{ {
@ -60,7 +60,7 @@ class GroupsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net] * @author [A. Gianotto] [<snipe@snipe.net]
* @see GroupsController::getCreate() * @see GroupsController::getCreate()
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postCreate() public function postCreate()
{ {
@ -72,10 +72,7 @@ class GroupsController extends Controller
if ($group->save()) { if ($group->save()) {
return redirect()->to("admin/groups")->with('success', trans('admin/groups/message.success.create')); return redirect()->to("admin/groups")->with('success', trans('admin/groups/message.success.create'));
} }
return redirect()->back()->withInput()->withErrors($group->getErrors()); return redirect()->back()->withInput()->withErrors($group->getErrors());
} }
/** /**
@ -85,7 +82,7 @@ class GroupsController extends Controller
* @see GroupsController::postEdit() * @see GroupsController::postEdit()
* @param int $id * @param int $id
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function getEdit($id = null) public function getEdit($id = null)
{ {
@ -103,30 +100,24 @@ class GroupsController extends Controller
* @see GroupsController::getEdit() * @see GroupsController::getEdit()
* @param int $id * @param int $id
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postEdit($id = null) public function postEdit($id = null)
{ {
$permissions = config('permissions'); $permissions = config('permissions');
if (!$group = Group::find($id)) { if (!$group = Group::find($id)) {
return redirect()->route('groups')->with('error', trans('admin/groups/message.group_not_found', compact('id'))); return redirect()->route('groups')->with('error', trans('admin/groups/message.group_not_found', compact('id')));
} }
$group->name = e(Input::get('name')); $group->name = e(Input::get('name'));
$group->permissions = json_encode(Input::get('permission')); $group->permissions = json_encode(Input::get('permission'));
if (!config('app.lock_passwords')) { if (!config('app.lock_passwords')) {
if ($group->save()) { if ($group->save()) {
return redirect()->to("admin/groups")->with('success', trans('admin/groups/message.success.update')); return redirect()->to("admin/groups")->with('success', trans('admin/groups/message.success.update'));
} }
return redirect()->back()->withInput()->withErrors($group->getErrors()); return redirect()->back()->withInput()->withErrors($group->getErrors());
} else {
return redirect()->route('update/group', $id)->withInput()->with('error', 'Denied! Editing groups is not allowed in the demo.');
} }
return redirect()->route('groups')->with('error', trans('general.feature_disabled'));
} }
/** /**
@ -136,25 +127,19 @@ class GroupsController extends Controller
* @see GroupsController::getEdit() * @see GroupsController::getEdit()
* @param int $id * @param int $id
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function getDelete($id = null) public function getDelete($id = null)
{ {
if (!config('app.lock_passwords')) { if (!config('app.lock_passwords')) {
try { if (!$group = Group::find($id)) {
// Get group information
$group = Group::find($id);
$group->delete();
// Redirect to the group management page
return redirect()->route('groups')->with('success', trans('admin/groups/message.success.delete'));
} catch (GroupNotFoundException $e) {
// Redirect to the group management page
return redirect()->route('groups')->with('error', trans('admin/groups/message.group_not_found', compact('id'))); return redirect()->route('groups')->with('error', trans('admin/groups/message.group_not_found', compact('id')));
} }
} else { $group->delete();
return redirect()->route('groups')->with('error', trans('general.feature_disabled')); // Redirect to the group management page
return redirect()->route('groups')->with('success', trans('admin/groups/message.success.delete'));
} }
return redirect()->route('groups')->with('error', trans('general.feature_disabled'));
} }
@ -168,17 +153,8 @@ class GroupsController extends Controller
public function getDatatable() public function getDatatable()
{ {
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e(Input::get('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e(Input::get('limit'));
} else {
$limit = 50;
}
if (Input::get('sort')=='name') { if (Input::get('sort')=='name') {
$sort = 'first_name'; $sort = 'first_name';
@ -188,7 +164,6 @@ class GroupsController extends Controller
// Grab all the groups // Grab all the groups
$groups = Group::with('users')->orderBy('name', 'ASC'); $groups = Group::with('users')->orderBy('name', 'ASC');
//$users = Company::scopeCompanyables($users);
if (Input::has('search')) { if (Input::has('search')) {
$groups = $users->TextSearch(e(Input::get('search'))); $groups = $users->TextSearch(e(Input::get('search')));
@ -196,8 +171,7 @@ class GroupsController extends Controller
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
$allowed_columns = $allowed_columns = [
[
'name','created_at' 'name','created_at'
]; ];
@ -209,14 +183,17 @@ class GroupsController extends Controller
$rows = array(); $rows = array();
foreach ($groups as $group) { foreach ($groups as $group) {
$group_names = '';
$inout = '';
$actions = '<nobr>'; $actions = '<nobr>';
$actions .= Helper::generateDatatableButton('edit', route('update/group', $group->id));
$actions .= '<a href="' . route('update/group', $group->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> ';
if (!config('app.lock_passwords')) { if (!config('app.lock_passwords')) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/group', $group->id) . '" data-content="'.trans('admin/groups/message.delete.confirm').'" data-title="Delete ' . htmlspecialchars($group->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a> '; $actions .= Helper::generateDatatableButton(
'delete',
route('delete/group', $group->id),
true, /*enabled*/
trans('admin/groups/message.delete.confirm'),
$group->name
);
} else { } else {
$actions .= ' <span class="btn delete-asset btn-danger btn-sm disabled"><i class="fa fa-trash icon-white"></i></span>'; $actions .= ' <span class="btn delete-asset btn-danger btn-sm disabled"><i class="fa fa-trash icon-white"></i></span>';
} }
@ -231,7 +208,6 @@ class GroupsController extends Controller
'actions' => ($actions) ? $actions : '', 'actions' => ($actions) ? $actions : '',
); );
} }
$data = array('total'=>$groupsCount, 'rows'=>$rows); $data = array('total'=>$groupsCount, 'rows'=>$rows);
return $data; return $data;
} }

View file

@ -42,7 +42,7 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see LicensesController::getDatatable() method that generates the JSON response * @see LicensesController::getDatatable() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
{ {
@ -57,12 +57,16 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see AccessoriesController::getDatatable() method that generates the JSON response * @see AccessoriesController::getDatatable() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
$this->authorize('create', License::class); $this->authorize('create', License::class);
$maintained_list = array('' => 'Maintained', '1' => 'Yes', '0' => 'No'); $maintained_list = [
'' => 'Maintained',
'1' => 'Yes',
'0' => 'No'
];
return View::make('licenses/edit') return View::make('licenses/edit')
//->with('license_options',$license_options) //->with('license_options',$license_options)
@ -83,7 +87,8 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see LicensesController::getCreate() method that provides the form view * @see LicensesController::getCreate() method that provides the form view
* @since [v1.0] * @since [v1.0]
* @return Redirect * @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/ */
public function store(Request $request) public function store(Request $request)
{ {
@ -91,57 +96,57 @@ class LicensesController extends Controller
// create a new model instance // create a new model instance
$license = new License(); $license = new License();
if (e($request->input('purchase_cost')) == '') { if ($request->input('purchase_cost') == '') {
$license->purchase_cost = null; $license->purchase_cost = null;
} else { } else {
$license->purchase_cost = Helper::ParseFloat(e($request->input('purchase_cost'))); $license->purchase_cost = Helper::ParseFloat($request->input('purchase_cost'));
} }
if (e($request->input('supplier_id')) == '') { if ($request->input('supplier_id') == '') {
$license->supplier_id = null; $license->supplier_id = null;
} else { } else {
$license->supplier_id = e($request->input('supplier_id')); $license->supplier_id = $request->input('supplier_id');
} }
if (e($request->input('maintained')) == '') { if ($request->input('maintained') == '') {
$license->maintained = 0; $license->maintained = 0;
} else { } else {
$license->maintained = e($request->input('maintained')); $license->maintained = $request->input('maintained');
} }
if (e($request->input('reassignable')) == '') { if ($request->input('reassignable') == '') {
$license->reassignable = 0; $license->reassignable = 0;
} else { } else {
$license->reassignable = e($request->input('reassignable')); $license->reassignable = $request->input('reassignable');
} }
if (e($request->input('purchase_order')) == '') { if ($request->input('purchase_order') == '') {
$license->purchase_order = ''; $license->purchase_order = '';
} else { } else {
$license->purchase_order = e($request->input('purchase_order')); $license->purchase_order = $request->input('purchase_order');
} }
if (empty(e($request->input('manufacturer_id')))) { if (empty($request->input('manufacturer_id'))) {
$license->manufacturer_id = null; $license->manufacturer_id = null;
} else { } else {
$license->manufacturer_id = e($request->input('manufacturer_id')); $license->manufacturer_id = $request->input('manufacturer_id');
} }
// Save the license data // Save the license data
$license->name = e($request->input('name')); $license->name = $request->input('name');
$license->serial = e($request->input('serial')); $license->serial = $request->input('serial');
$license->license_email = e($request->input('license_email')); $license->license_email = $request->input('license_email');
$license->license_name = e($request->input('license_name')); $license->license_name = $request->input('license_name');
$license->notes = e($request->input('notes')); $license->notes = $request->input('notes');
$license->order_number = e($request->input('order_number')); $license->order_number = $request->input('order_number');
$license->seats = e($request->input('seats')); $license->seats = $request->input('seats');
$license->purchase_date = e($request->input('purchase_date')); $license->purchase_date = $request->input('purchase_date');
$license->purchase_order = e($request->input('purchase_order')); $license->purchase_order = $request->input('purchase_order');
$license->depreciation_id = e($request->input('depreciation_id')); $license->depreciation_id = $request->input('depreciation_id');
$license->company_id = Company::getIdForCurrentUser($request->input('company_id')); $license->company_id = Company::getIdForCurrentUser($request->input('company_id'));
$license->expiration_date = e($request->input('expiration_date')); $license->expiration_date = $request->input('expiration_date');
$license->termination_date = e($request->input('termination_date')); $license->termination_date = $request->input('termination_date');
$license->user_id = Auth::user()->id; $license->user_id = Auth::id();
if (($license->purchase_date == "") || ($license->purchase_date == "0000-00-00")) { if (($license->purchase_date == "") || ($license->purchase_date == "0000-00-00")) {
$license->purchase_date = null; $license->purchase_date = null;
@ -164,20 +169,16 @@ class LicensesController extends Controller
for ($x=0; $x<$license->seats; $x++) { for ($x=0; $x<$license->seats; $x++) {
$license_seat = new LicenseSeat(); $license_seat = new LicenseSeat();
$license_seat->license_id = $insertedId; $license_seat->license_id = $insertedId;
$license_seat->user_id = Auth::user()->id; $license_seat->user_id = Auth::id();
$license_seat->assigned_to = null; $license_seat->assigned_to = null;
$license_seat->notes = null; $license_seat->notes = null;
$license_seat->save(); $license_seat->save();
} }
}); });
// Redirect to the new license page // Redirect to the new license page
return redirect()->route("licenses.index")->with('success', trans('admin/licenses/message.create.success')); return redirect()->route("licenses.index")->with('success', trans('admin/licenses/message.create.success'));
} }
return redirect()->back()->withInput()->withErrors($license->getErrors()); return redirect()->back()->withInput()->withErrors($license->getErrors());
} }
/** /**
@ -187,7 +188,7 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $licenseId * @param int $licenseId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function edit($licenseId = null) public function edit($licenseId = null)
{ {
@ -205,7 +206,11 @@ class LicensesController extends Controller
$item->purchase_cost = null; $item->purchase_cost = null;
} }
$maintained_list = array('' => 'Maintained', '1' => 'Yes', '0' => 'No'); $maintained_list = [
'' => 'Maintained',
'1' => 'Yes',
'0' => 'No'
];
return View::make('licenses/edit', compact('item')) return View::make('licenses/edit', compact('item'))
->with('depreciation_list', Helper::depreciationList()) ->with('depreciation_list', Helper::depreciationList())
@ -223,8 +228,9 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see LicensesController::getEdit() method that provides the form view * @see LicensesController::getEdit() method that provides the form view
* @since [v1.0] * @since [v1.0]
* @param Request $request
* @param int $licenseId * @param int $licenseId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function update(Request $request, $licenseId = null) public function update(Request $request, $licenseId = null)
{ {
@ -237,78 +243,78 @@ class LicensesController extends Controller
$this->authorize('update', $license); $this->authorize('update', $license);
// Update the license data // Update the license data
$license->name = e($request->input('name')); $license->name = $request->input('name');
$license->serial = e($request->input('serial')); $license->serial = $request->input('serial');
$license->license_email = e($request->input('license_email')); $license->license_email = $request->input('license_email');
$license->license_name = e($request->input('license_name')); $license->license_name = $request->input('license_name');
$license->notes = e($request->input('notes')); $license->notes = $request->input('notes');
$license->order_number = e($request->input('order_number')); $license->order_number = $request->input('order_number');
$license->depreciation_id = e($request->input('depreciation_id')); $license->depreciation_id = $request->input('depreciation_id');
$license->company_id = Company::getIdForCurrentUser($request->input('company_id')); $license->company_id = Company::getIdForCurrentUser($request->input('company_id'));
$license->purchase_order = e($request->input('purchase_order')); $license->purchase_order = $request->input('purchase_order');
$license->maintained = e($request->input('maintained')); $license->maintained = $request->input('maintained');
$license->reassignable = e($request->input('reassignable')); $license->reassignable = $request->input('reassignable');
if (empty(e($request->input('manufacturer_id')))) { if (empty($request->input('manufacturer_id'))) {
$license->manufacturer_id = null; $license->manufacturer_id = null;
} else { } else {
$license->manufacturer_id = e($request->input('manufacturer_id')); $license->manufacturer_id = $request->input('manufacturer_id');
} }
if (e($request->input('supplier_id')) == '') { if ($request->input('supplier_id') == '') {
$license->supplier_id = null; $license->supplier_id = null;
} else { } else {
$license->supplier_id = e($request->input('supplier_id')); $license->supplier_id = $request->input('supplier_id');
} }
// Update the asset data // Update the asset data
if (e($request->input('purchase_date')) == '') { if ($request->input('purchase_date') == '') {
$license->purchase_date = null; $license->purchase_date = null;
} else { } else {
$license->purchase_date = e($request->input('purchase_date')); $license->purchase_date = $request->input('purchase_date');
} }
if (e($request->input('expiration_date')) == '') { if ($request->input('expiration_date') == '') {
$license->expiration_date = null; $license->expiration_date = null;
} else { } else {
$license->expiration_date = e($request->input('expiration_date')); $license->expiration_date = $request->input('expiration_date');
} }
if (e($request->input('termination_date')) == '') { if ($request->input('termination_date') == '') {
$license->termination_date = null; $license->termination_date = null;
} else { } else {
$license->termination_date = e($request->input('termination_date')); $license->termination_date = $request->input('termination_date');
} }
if (e($request->input('purchase_cost')) == '') { if ($request->input('purchase_cost') == '') {
$license->purchase_cost = null; $license->purchase_cost = null;
} else { } else {
$license->purchase_cost = Helper::ParseFloat(e($request->input('purchase_cost'))); $license->purchase_cost = Helper::ParseFloat($request->input('purchase_cost'));
} }
if (e($request->input('maintained')) == '') { if ($request->input('maintained') == '') {
$license->maintained = 0; $license->maintained = 0;
} else { } else {
$license->maintained = e($request->input('maintained')); $license->maintained = $request->input('maintained');
} }
if (e($request->input('reassignable')) == '') { if ($request->input('reassignable') == '') {
$license->reassignable = 0; $license->reassignable = 0;
} else { } else {
$license->reassignable = e($request->input('reassignable')); $license->reassignable = $request->input('reassignable');
} }
if (e($request->input('purchase_order')) == '') { if ($request->input('purchase_order') == '') {
$license->purchase_order = ''; $license->purchase_order = '';
} else { } else {
$license->purchase_order = e($request->input('purchase_order')); $license->purchase_order = $request->input('purchase_order');
} }
//Are we changing the total number of seats? //Are we changing the total number of seats?
if ($license->seats != e($request->input('seats'))) { if ($license->seats != $request->input('seats')) {
//Determine how many seats we are dealing with //Determine how many seats we are dealing with
$difference = e($request->input('seats')) - $license->licenseseats()->count(); $difference = $request->input('seats') - $license->licenseseats()->count();
if ($difference < 0) { if ($difference < 0) {
//Filter out any license which have a user attached; //Filter out any license which have a user attached;
@ -316,7 +322,6 @@ class LicensesController extends Controller
return is_null($seat->user); return is_null($seat->user);
}); });
//If the remaining collection is as large or larger than the number of seats we want to delete //If the remaining collection is as large or larger than the number of seats we want to delete
if ($seats->count() >= abs($difference)) { if ($seats->count() >= abs($difference)) {
for ($i=1; $i <= abs($difference); $i++) { for ($i=1; $i <= abs($difference); $i++) {
@ -325,14 +330,13 @@ class LicensesController extends Controller
} }
//Log the deletion of seats to the log //Log the deletion of seats to the log
$logaction = new Actionlog(); $logAction = new Actionlog();
$logaction->item_type = License::class; $logAction->item_type = License::class;
$logaction->item_id = $license->id; $logAction->item_id = $license->id;
$logaction->user_id = Auth::user()->id; $logAction->user_id = Auth::user()->id;
$logaction->note = '-'.abs($difference)." seats"; $logAction->note = '-'.abs($difference)." seats";
$logaction->target_id = null; $logAction->target_id = null;
$log = $logaction->logaction('delete seats'); $logAction->logaction('delete seats');
} else { } else {
// Redirect to the license edit page // Redirect to the license edit page
return redirect()->to("admin/licenses/$licenseId/edit")->with('error', trans('admin/licenses/message.assoc_users')); return redirect()->to("admin/licenses/$licenseId/edit")->with('error', trans('admin/licenses/message.assoc_users'));
@ -350,26 +354,21 @@ class LicensesController extends Controller
} }
//Log the addition of license to the log. //Log the addition of license to the log.
$logaction = new Actionlog(); $logAction = new Actionlog();
$logaction->item_type = License::class; $logAction->item_type = License::class;
$logaction->item_id = $license->id; $logAction->item_id = $license->id;
$logaction->user_id = Auth::user()->id; $logAction->user_id = Auth::user()->id;
$logaction->note = '+'.abs($difference)." seats"; $logAction->note = '+'.abs($difference)." seats";
$logaction->target_id = null; $logAction->target_id = null;
$log = $logaction->logaction('add seats'); $logAction->logaction('add seats');
} }
$license->seats = e($request->input('seats')); $license->seats = e($request->input('seats'));
} }
if ($license->save()) { if ($license->save()) {
// Redirect to the new license page
return redirect()->route('licenses.show', ['license' => $licenseId])->with('success', trans('admin/licenses/message.update.success')); return redirect()->route('licenses.show', ['license' => $licenseId])->with('success', trans('admin/licenses/message.update.success'));
} }
return redirect()->to("admin/licenses/$licenseId/edit")->with('error', trans('admin/licenses/message.update.error')); return redirect()->to("admin/licenses/$licenseId/edit")->with('error', trans('admin/licenses/message.update.error'));
} }
/** /**
@ -379,7 +378,7 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $licenseId * @param int $licenseId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($licenseId) public function destroy($licenseId)
{ {
@ -391,26 +390,22 @@ class LicensesController extends Controller
$this->authorize('delete', $license); $this->authorize('delete', $license);
if ($license->assigned_seats_count > 0) { if ($license->assigned_seats_count == 0) {
// Redirect to the license management page
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.assoc_users'));
} else {
// Delete the license and the associated license seats // Delete the license and the associated license seats
DB::table('license_seats') DB::table('license_seats')
->where('id', $license->id) ->where('id', $license->id)
->update(array('assigned_to' => null,'asset_id' => null)); ->update(array('assigned_to' => null,'asset_id' => null));
$licenseseats = $license->licenseseats(); $licenseSeats = $license->licenseseats();
$licenseseats->delete(); $licenseSeats->delete();
$license->delete(); $license->delete();
// Redirect to the licenses management page // Redirect to the licenses management page
return redirect()->route('licenses.index')->with('success', trans('admin/licenses/message.delete.success')); return redirect()->route('licenses.index')->with('success', trans('admin/licenses/message.delete.success'));
// Redirect to the license management page
} }
// There are still licenses in use.
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.assoc_users'));
} }
@ -423,55 +418,47 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $seatId * @param int $seatId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function getCheckout($seatId) public function getCheckout($seatId)
{ {
// Check if the license seat exists // Check if the license seat exists
if (is_null($licenseseat = LicenseSeat::find($seatId))) { if (is_null($licenseSeat = LicenseSeat::find($seatId))) {
// Redirect to the asset management page with error // Redirect to the asset management page with error
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found')); return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
} }
$this->authorize('checkout', $licenseseat); $this->authorize('checkout', $licenseSeat);
return View::make('licenses/checkout', compact('licenseSeat'))
// Get the dropdown of users and then pass it to the checkout view ->with('users_list', Helper::usersList())
$users_list = Helper::usersList(); ->with('asset_list', Helper::detailedAssetList());
$assets = Helper::detailedAssetList();
return View::make('licenses/checkout', compact('licenseseat'))
->with('users_list', $users_list)
->with('asset_list', $assets);
} }
/** /**
* Validates and stores the license checkout action. * Validates and stores the license checkout action.
* *
* @todo Switch to using a FormRequest for validation here. * @todo Switch to using a FormRequest for validation here.
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param Request $request
* @param int $seatId * @param int $seatId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postCheckout(Request $request, $seatId) public function postCheckout(Request $request, $seatId)
{ {
$licenseSeat = LicenseSeat::find($seatId);
$licenseseat = LicenseSeat::find($seatId);
$assigned_to = e($request->input('assigned_to')); $assigned_to = e($request->input('assigned_to'));
$asset_id = e($request->input('asset_id')); $asset_id = e($request->input('asset_id'));
$user = Auth::user(); $user = Auth::user();
$this->authorize('checkout', $licenseseat); $this->authorize('checkout', $licenseSeat);
// Declare the rules for the form validation // Declare the rules for the form validation
$rules = array( $rules = [
'note' => 'string', 'note' => 'string',
'asset_id' => 'required_without:assigned_to', 'asset_id' => 'required_without:assigned_to',
); ];
// Create a new validator instance from our validation rules // Create a new validator instance from our validation rules
$validator = Validator::make(Input::all(), $rules); $validator = Validator::make(Input::all(), $rules);
@ -491,65 +478,57 @@ class LicensesController extends Controller
} }
if ($asset_id!='') { if ($asset_id!='') {
if (is_null($asset = Asset::find($asset_id))) { if (is_null($asset = Asset::find($asset_id))) {
// Redirect to the asset management page with error // Redirect to the asset management page with error
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.asset_does_not_exist')); return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.asset_does_not_exist'));
} }
if (($asset->assigned_to!='') && (($asset->assigned_to!=$assigned_to)) && ($assigned_to!='')) { if (($asset->assigned_to!='') && (($asset->assigned_to!=$assigned_to)) && ($assigned_to!='')) {
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.owner_doesnt_match_asset')); return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.owner_doesnt_match_asset'));
} }
} }
// Check if the asset exists // Check if the asset exists
if (is_null($licenseseat)) { if (is_null($licenseSeat)) {
// Redirect to the asset management page with error // Redirect to the asset management page with error
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found')); return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
} }
if ($request->input('asset_id') == '') { if ($request->input('asset_id') == '') {
$licenseseat->asset_id = null; $licenseSeat->asset_id = null;
} else { } else {
$licenseseat->asset_id = e($request->input('asset_id')); $licenseSeat->asset_id = $request->input('asset_id');
} }
// Update the asset data // Update the asset data
if (e($request->input('assigned_to')) == '') { if ($request->input('assigned_to') == '') {
$licenseseat->assigned_to = null; $licenseSeat->assigned_to = null;
} else { } else {
$licenseseat->assigned_to = e($request->input('assigned_to')); $licenseSeat->assigned_to = $request->input('assigned_to');
} }
// Was the asset updated? // Was the asset updated?
if ($licenseseat->save()) { if ($licenseSeat->save()) {
$licenseSeat->logCheckout($request->input('note'));
$licenseseat->logCheckout(e($request->input('note'))); $data['license_id'] =$licenseSeat->license_id;
$data['note'] = $request->input('note');
$data['license_id'] =$licenseseat->license_id; $license = License::find($licenseSeat->license_id);
$data['note'] = e($request->input('note'));
$license = License::find($licenseseat->license_id);
$settings = Setting::getSettings(); $settings = Setting::getSettings();
// Update the asset data // Update the asset data
if (e($request->input('assigned_to')) == '') { if ($request->input('assigned_to') == '') {
$slack_msg = 'License <'.url('/').'/licenses/'.$license->id.'|'.$license->name.'> checked out to <'.url('/').'/hardware/'.$asset->id.'/view|'.$asset->showAssetName().'> by <'.url('/').'/users/'.$user->id.'/view'.'|'.$user->fullName().'>.'; $slack_msg = 'License <'.route('licenses.show', $license->id).'|'.$license->name
.'> checked out to <'.route('hardware.show',$asset->id) .'|'.$asset->showAssetName()
.'> by <'.route('users.show', $user->id).'|'.$user->fullName().'>.';
} else { } else {
$slack_msg = 'License <'.url('/').'/licenses/'.$license->id.'|'.$license->name.'> checked out to <'.url('/').'/users/'.$user->id.'/view|'.$is_assigned_to->fullName().'> by <'.url('/').'/users/'.$user->id.'/view'.'|'.$user->fullName().'>.'; $slack_msg = 'License <'.route('licenses.show', $license->id).'|'.$license->name
.'> checked out to <'.route('users.show', $user->id).'|'.$is_assigned_to->fullName()
.'> by <'.route('users.show', $user->id) .'|'.$user->fullName().'>.';
} }
if ($settings->slack_endpoint) { if ($settings->slack_endpoint) {
$slack_settings = [ $slack_settings = [
'username' => $settings->botname, 'username' => $settings->botname,
'channel' => $settings->slack_channel, 'channel' => $settings->slack_channel,
@ -587,7 +566,7 @@ class LicensesController extends Controller
} }
// Redirect to the asset management page with error // Redirect to the asset management page with error
return redirect()->to('admin/licenses/$assetId/checkout')->with('error', trans('admin/licenses/message.create.error'))->with('license', new License); return redirect()->to("admin/licenses/{$asset_id}/checkout")->with('error', trans('admin/licenses/message.create.error'))->with('license', new License);
} }
@ -597,10 +576,10 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $seatId * @param int $seatId
* @param string $backto * @param string $backTo
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function getCheckin($seatId = null, $backto = null) public function getCheckin($seatId = null, $backTo = null)
{ {
// Check if the asset exists // Check if the asset exists
if (is_null($licenseseat = LicenseSeat::find($seatId))) { if (is_null($licenseseat = LicenseSeat::find($seatId))) {
@ -608,12 +587,10 @@ class LicensesController extends Controller
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found')); return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
} }
$this->authorize('checkin', $licenseseat); $this->authorize('checkin', $licenseseat);
return View::make('licenses/checkin', compact('licenseseat'))->with('backto', $backto); return View::make('licenses/checkin', compact('licenseseat'))->with('backto', $backTo);
} }
/** /**
* Validates and stores the license checkin action. * Validates and stores the license checkin action.
* *
@ -621,20 +598,20 @@ class LicensesController extends Controller
* @see LicensesController::getCheckin() method that provides the form view * @see LicensesController::getCheckin() method that provides the form view
* @since [v1.0] * @since [v1.0]
* @param int $seatId * @param int $seatId
* @param string $backto * @param string $backTo
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postCheckin($seatId = null, $backto = null) public function postCheckin($seatId = null, $backTo = null)
{ {
// Check if the asset exists // Check if the asset exists
if (is_null($licenseseat = LicenseSeat::find($seatId))) { if (is_null($licenseSeat = LicenseSeat::find($seatId))) {
// Redirect to the asset management page with error // Redirect to the asset management page with error
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found')); return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
} }
$license = License::find($licenseseat->license_id); $license = License::find($licenseSeat->license_id);
$this->authorize('checkin', $licenseseat); $this->authorize('checkin', $licenseSeat);
if (!$license->reassignable) { if (!$license->reassignable) {
// Not allowed to checkin // Not allowed to checkin
@ -656,25 +633,23 @@ class LicensesController extends Controller
// Ooops.. something went wrong // Ooops.. something went wrong
return redirect()->back()->withInput()->withErrors($validator); return redirect()->back()->withInput()->withErrors($validator);
} }
$return_to = User::find($licenseseat->assigned_to); $return_to = User::find($licenseSeat->assigned_to);
if (!$return_to) { if (!$return_to) {
$return_to = Asset::find($licenseseat->asset_id); $return_to = Asset::find($licenseSeat->asset_id);
} }
// Update the asset data // Update the asset data
$licenseseat->assigned_to = null; $licenseSeat->assigned_to = null;
$licenseseat->asset_id = null; $licenseSeat->asset_id = null;
$user = Auth::user(); $user = Auth::user();
// Was the asset updated? // Was the asset updated?
if ($licenseseat->save()) { if ($licenseSeat->save()) {
$licenseseat->logCheckin($return_to, e($request->input('note'))); $licenseSeat->logCheckin($return_to, e($request->input('note')));
$settings = Setting::getSettings(); $settings = Setting::getSettings();
if ($settings->slack_endpoint) { if ($settings->slack_endpoint) {
$slack_settings = [ $slack_settings = [
'username' => $settings->botname, 'username' => $settings->botname,
'channel' => $settings->slack_channel, 'channel' => $settings->slack_channel,
@ -706,16 +681,11 @@ class LicensesController extends Controller
} }
if ($backTo=='user') {
return redirect()->route("users.show", $return_to->id)->with('success', trans('admin/licenses/message.checkin.success'));
if ($backto=='user') {
return redirect()->to("admin/users/".$return_to->id.'/view')->with('success', trans('admin/licenses/message.checkin.success'));
} else {
return redirect()->to("admin/licenses/".$licenseseat->license_id."/view")->with('success', trans('admin/licenses/message.checkin.success'));
} }
redirect()->route("licenses.show", $licenseSeat->license_id)->with('success', trans('admin/licenses/message.checkin.success'));
} }
// Redirect to the license page with error // Redirect to the license page with error
return redirect()->route("licenses.index")->with('error', trans('admin/licenses/message.checkin.error')); return redirect()->route("licenses.index")->with('error', trans('admin/licenses/message.checkin.error'));
} }
@ -726,11 +696,10 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $licenseId * @param int $licenseId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function show($licenseId = null) public function show($licenseId = null)
{ {
$license = License::find($licenseId); $license = License::find($licenseId);
if (isset($license->id)) { if (isset($license->id)) {
$license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset'); $license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset');
@ -749,24 +718,24 @@ class LicensesController extends Controller
$this->authorize('create', License::class); $this->authorize('create', License::class);
$maintained_list = array('' => 'Maintained', '1' => 'Yes', '0' => 'No'); $maintained_list = [
$company_list = Helper::companyList(); '' => 'Maintained',
'1' => 'Yes',
'0' => 'No'
];
//clone the orig //clone the orig
$license = clone $license_to_clone; $license = clone $license_to_clone;
$license->id = null; $license->id = null;
$license->serial = null; $license->serial = null;
// Show the page // Show the page
$depreciation_list = Helper::depreciationList();
$supplier_list = Helper::suppliersList();
return View::make('licenses/edit') return View::make('licenses/edit')
->with('depreciation_list', $depreciation_list) ->with('depreciation_list', Helper::depreciationList())
->with('supplier_list', $supplier_list) ->with('supplier_list', Helper::suppliersList())
->with('item', $license) ->with('item', $license)
->with('maintained_list', $maintained_list) ->with('maintained_list', $maintained_list)
->with('company_list', $company_list) ->with('company_list', Helper::companyList())
->with('manufacturer_list', Helper::manufacturerList()); ->with('manufacturer_list', Helper::manufacturerList());
} }
@ -777,7 +746,7 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $licenseId * @param int $licenseId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postUpload($licenseId = null) public function postUpload($licenseId = null)
{ {
@ -813,14 +782,11 @@ class LicensesController extends Controller
return redirect()->back()->with('success', trans('admin/licenses/message.upload.success')); return redirect()->back()->with('success', trans('admin/licenses/message.upload.success'));
} }
return redirect()->back()->with('error', trans('admin/licenses/message.upload.error')); return redirect()->back()->with('error', trans('admin/licenses/message.upload.error'));
} }
return redirect()->back()->with('error', trans('admin/licenses/message.upload.nofiles')); return redirect()->back()->with('error', trans('admin/licenses/message.upload.nofiles'));
} }
// Prepare the error message // Prepare the error message
$error = trans('admin/licenses/message.does_not_exist', compact('id')); $error = trans('admin/licenses/message.does_not_exist', compact('id'));
// Redirect to the licence management page
return redirect()->route('licenses.index')->with('error', $error); return redirect()->route('licenses.index')->with('error', $error);
} }
@ -832,7 +798,7 @@ class LicensesController extends Controller
* @since [v1.0] * @since [v1.0]
* @param int $licenseId * @param int $licenseId
* @param int $fileId * @param int $fileId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function getDeleteFile($licenseId = null, $fileId = null) public function getDeleteFile($licenseId = null, $fileId = null)
{ {
@ -841,9 +807,7 @@ class LicensesController extends Controller
// the license is valid // the license is valid
if (isset($license->id)) { if (isset($license->id)) {
$this->authorize('edit', $license); $this->authorize('edit', $license);
$log = Actionlog::find($fileId); $log = Actionlog::find($fileId);
$full_filename = $destinationPath.'/'.$log->filename; $full_filename = $destinationPath.'/'.$log->filename;
if (file_exists($full_filename)) { if (file_exists($full_filename)) {
@ -851,7 +815,6 @@ class LicensesController extends Controller
} }
$log->delete(); $log->delete();
return redirect()->back()->with('success', trans('admin/licenses/message.deletefile.success')); return redirect()->back()->with('success', trans('admin/licenses/message.deletefile.success'));
} }
// Prepare the error message // Prepare the error message
$error = trans('admin/licenses/message.does_not_exist', compact('id')); $error = trans('admin/licenses/message.does_not_exist', compact('id'));
@ -869,7 +832,7 @@ class LicensesController extends Controller
* @since [v1.4] * @since [v1.4]
* @param int $licenseId * @param int $licenseId
* @param int $fileId * @param int $fileId
* @return Redirect * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/ */
public function displayFile($licenseId = null, $fileId = null) public function displayFile($licenseId = null, $fileId = null)
{ {
@ -878,9 +841,7 @@ class LicensesController extends Controller
// the license is valid // the license is valid
if (isset($license->id)) { if (isset($license->id)) {
$this->authorize('view', $license); $this->authorize('view', $license);
$log = Actionlog::find($fileId); $log = Actionlog::find($fileId);
$file = $log->get_src('licenses'); $file = $log->get_src('licenses');
return Response::download($file); return Response::download($file);
@ -908,11 +869,8 @@ class LicensesController extends Controller
if (Input::has('search')) { if (Input::has('search')) {
$licenses = $licenses->TextSearch($request->input('search')); $licenses = $licenses->TextSearch($request->input('search'));
} }
$offset = request('offset', 0);
($request->input('offset')) ? $offset = e($request->input('offset')) : $offset = 0; $limit = request('limit', 50);
($request->input('limit')) ? $limit = e($request->input('limit')) : $limit = 50;
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company']; $allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company'];
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
@ -930,7 +888,6 @@ class LicensesController extends Controller
break; break;
} }
$licenseCount = $licenses->count(); $licenseCount = $licenses->count();
$licenses = $licenses->skip($offset)->take($limit)->get(); $licenses = $licenses->skip($offset)->take($limit)->get();
@ -940,22 +897,27 @@ class LicensesController extends Controller
$actions = '<span style="white-space: nowrap;">'; $actions = '<span style="white-space: nowrap;">';
if (Gate::allows('checkout', License::class)) { if (Gate::allows('checkout', License::class)) {
$actions .= '<a href="' . route('licenses.freecheckout', $license->id) $actions .= Helper::generateDatatableButton(
. '" class="btn btn-primary btn-sm' . (($license->remaincount() > 0) ? '' : ' disabled') . '" style="margin-right:5px;">' . trans('general.checkout') . '</a> '; 'checkout',
route('licenses.freecheckout', $license->id),
$license->remaincount() > 0
);
} }
if (Gate::allows('create', $license)) { if (Gate::allows('create', $license)) {
$actions .= '<a href="' . route('clone/license', $license->id) $actions .= Helper::generateDatatableButton('clone', route('clone/license', $license->id));
. '" class="btn btn-info btn-sm" style="margin-right:5px;" title="Clone license"><i class="fa fa-files-o"></i></a>';
} }
if (Gate::allows('update', $license)) { if (Gate::allows('update', $license)) {
$actions .= '<a href="' . route('licenses.edit', $license->id) $actions .= Helper::generateDatatableButton('edit', route('licenses.edit', $license->id));
. '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
} }
if (Gate::allows('delete', $license)) { if (Gate::allows('delete', $license)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' $actions .= Helper::generateDatatableButton(
. route('licenses.destroy', $license->id) 'delete',
. '" data-content="' . trans('admin/licenses/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($license->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; route('licenses.destroy', $license->id),
true, /*enabled*/
trans('admin/licenses/message.delete.confirm'),
$license->name
);
} }
$actions .='</span>'; $actions .='</span>';
@ -995,7 +957,7 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $licenseId * @param int $licenseId
* @return View * @return \Illuminate\Http\RedirectResponse
*/ */
public function getFreeLicense($licenseId) public function getFreeLicense($licenseId)
{ {

View file

@ -1,6 +1,7 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\Helper;
use Input; use Input;
use Lang; use Lang;
use App\Models\Location; use App\Models\Location;
@ -32,7 +33,7 @@ class LocationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see LocationsController::getDatatable() method that generates the JSON response * @see LocationsController::getDatatable() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
{ {
@ -50,7 +51,7 @@ class LocationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see LocationsController::postCreate() method that validates and stores the data * @see LocationsController::postCreate() method that validates and stores the data
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
@ -73,33 +74,30 @@ class LocationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see LocationsController::getCreate() method that makes the form * @see LocationsController::getCreate() method that makes the form
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function store() public function store()
{ {
$location = new Location(); $location = new Location();
$location->name = Input::get('name');
$location->name = e(Input::get('name'));
if (Input::get('parent_id')=='') { if (Input::get('parent_id')=='') {
$location->parent_id = null; $location->parent_id = null;
} else { } else {
$location->parent_id = e(Input::get('parent_id')); $location->parent_id = Input::get('parent_id');
} }
$location->currency = e(Input::get('currency', '$')); $location->currency = Input::get('currency', '$');
$location->address = e(Input::get('address')); $location->address = Input::get('address');
$location->address2 = e(Input::get('address2')); $location->address2 = Input::get('address2');
$location->city = e(Input::get('city')); $location->city = Input::get('city');
$location->state = e(Input::get('state')); $location->state = Input::get('state');
$location->country = e(Input::get('country')); $location->country = Input::get('country');
$location->zip = e(Input::get('zip')); $location->zip = Input::get('zip');
$location->user_id = Auth::user()->id; $location->user_id = Auth::id();
if ($location->save()) { if ($location->save()) {
return redirect()->route("locations.index")->with('success', trans('admin/locations/message.create.success')); return redirect()->route("locations.index")->with('success', trans('admin/locations/message.create.success'));
} }
return redirect()->back()->withInput()->withErrors($location->getErrors()); return redirect()->back()->withInput()->withErrors($location->getErrors());
} }
/** /**
@ -113,33 +111,28 @@ class LocationsController extends Controller
*/ */
public function apiStore() public function apiStore()
{ {
$new['currency']=Setting::first()->default_currency; $new['currency']=Setting::first()->default_currency;
// create a new location instance // create a new location instance
$location = new Location(); $location = new Location();
// Save the location data // Save the location data
$location->name = e(Input::get('name')); $location->name = Input::get('name');
$location->currency = Setting::first()->default_currency; //e(Input::get('currency')); $location->currency = Setting::first()->default_currency; //e(Input::get('currency'));
$location->address = ''; //e(Input::get('address')); $location->address = ''; //e(Input::get('address'));
// $location->address2 = e(Input::get('address2')); // $location->address2 = e(Input::get('address2'));
$location->city = e(Input::get('city')); $location->city = Input::get('city');
$location->state = '';//e(Input::get('state')); $location->state = '';//e(Input::get('state'));
$location->country = e(Input::get('country')); $location->country = Input::get('country');
// $location->zip = e(Input::get('zip')); // $location->zip = e(Input::get('zip'));
$location->user_id = Auth::user()->id; $location->user_id = Auth::id();
// Was the location created? // Was the location created?
if ($location->save()) { if ($location->save()) {
return JsonResponse::create($location); return JsonResponse::create($location);
} }
// failure // failure
$errors = $location->errors();
return JsonResponse::create(["error" => "Failed validation: ".print_r($location->getErrors(), true)], 500); return JsonResponse::create(["error" => "Failed validation: ".print_r($location->getErrors(), true)], 500);
} }
@ -150,7 +143,7 @@ class LocationsController extends Controller
* @see LocationsController::postCreate() method that validates and stores * @see LocationsController::postCreate() method that validates and stores
* @param int $locationId * @param int $locationId
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function edit($locationId = null) public function edit($locationId = null)
{ {
@ -176,40 +169,37 @@ class LocationsController extends Controller
* @see LocationsController::getEdit() method that makes the form view * @see LocationsController::getEdit() method that makes the form view
* @param int $locationId * @param int $locationId
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function update($locationId = null) public function update($locationId = null)
{ {
// Check if the location exists // Check if the location exists
if (is_null($location = Location::find($locationId))) { if (is_null($location = Location::find($locationId))) {
// Redirect to the blogs management page
return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.does_not_exist')); return redirect()->to('admin/settings/locations')->with('error', trans('admin/locations/message.does_not_exist'));
} }
// Update the location data // Update the location data
$location->name = e(Input::get('name')); $location->name = Input::get('name');
if (Input::get('parent_id')=='') { if (Input::get('parent_id')=='') {
$location->parent_id = null; $location->parent_id = null;
} else { } else {
$location->parent_id = e(Input::get('parent_id', '')); $location->parent_id = Input::get('parent_id', '');
} }
$location->currency = e(Input::get('currency', '$')); $location->currency = Input::get('currency', '$');
$location->address = e(Input::get('address')); $location->address = Input::get('address');
$location->address2 = e(Input::get('address2')); $location->address2 = Input::get('address2');
$location->city = e(Input::get('city')); $location->city = Input::get('city');
$location->state = e(Input::get('state')); $location->state = Input::get('state');
$location->country = e(Input::get('country')); $location->country = Input::get('country');
$location->zip = e(Input::get('zip')); $location->zip = Input::get('zip');
// Was the asset created? // Was the asset created?
if ($location->save()) { if ($location->save()) {
// Redirect to the saved location page // Redirect to the saved location page
return redirect()->to("admin/settings/locations/")->with('success', trans('admin/locations/message.update.success')); return redirect()->route("locations.index")->with('success', trans('admin/locations/message.update.success'));
} }
// Redirect to the location management page // Redirect to the location management page
return redirect()->back()->withInput()->withInput()->withErrors($location->getErrors()); return redirect()->back()->withInput()->withInput()->withErrors($location->getErrors());
} }
/** /**
@ -218,7 +208,7 @@ class LocationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $locationId * @param int $locationId
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($locationId) public function destroy($locationId)
{ {
@ -241,9 +231,6 @@ class LocationsController extends Controller
$location->delete(); $location->delete();
return redirect()->to('admin/settings/locations')->with('success', trans('admin/locations/message.delete.success')); return redirect()->to('admin/settings/locations')->with('success', trans('admin/locations/message.delete.success'));
} }
} }
@ -256,7 +243,7 @@ class LocationsController extends Controller
* @see LocationsController::getDataViewAssets() method that returns JSON for location assets * @see LocationsController::getDataViewAssets() method that returns JSON for location assets
* @param int $locationId * @param int $locationId
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function show($locationId = null) public function show($locationId = null)
{ {
@ -264,15 +251,12 @@ class LocationsController extends Controller
if (isset($location->id)) { if (isset($location->id)) {
return View::make('locations/view', compact('location')); return View::make('locations/view', compact('location'));
} else { }
// Prepare the error message // Prepare the error message
$error = trans('admin/locations/message.does_not_exist', compact('id')); $error = trans('admin/locations/message.does_not_exist', compact('id'));
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('locations')->with('error', $error); return redirect()->route('locations.index')->with('error', $error);
}
} }
@ -282,33 +266,32 @@ class LocationsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see LocationsController::getIndex() method that returns JSON for location index * @see LocationsController::getIndex() method that returns JSON for location index
* @since [v1.0] * @since [v1.0]
* @return View * @return array
*/ */
public function getDatatable() public function getDatatable()
{ {
$locations = Location::select(array('locations.id','locations.name','locations.address','locations.address2','locations.city','locations.state','locations.zip','locations.country','locations.parent_id','locations.currency'))->with('assets'); $locations = Location::select([
'locations.id',
'locations.name',
'locations.address',
'locations.address2',
'locations.city',
'locations.state',
'locations.zip',
'locations.country',
'locations.parent_id',
'locations.currency'
])->with('assets');
if (Input::has('search')) { if (Input::has('search')) {
$locations = $locations->TextSearch(e(Input::get('search'))); $locations = $locations->TextSearch(e(Input::get('search')));
} }
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e(Input::get('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e(Input::get('limit'));
} else {
$limit = 50;
}
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
switch (Input::get('sort')) { switch (Input::get('sort')) {
case 'parent': case 'parent':
$locations = $locations->OrderParent($order); $locations = $locations->OrderParent($order);
@ -321,14 +304,22 @@ class LocationsController extends Controller
break; break;
} }
$locationsCount = $locations->count(); $locationsCount = $locations->count();
$locations = $locations->skip($offset)->take($limit)->get(); $locations = $locations->skip($offset)->take($limit)->get();
$rows = array(); $rows = array();
foreach ($locations as $location) { foreach ($locations as $location) {
$actions = '<nobr><a href="'.route('locations.edit', ['location' => $location->id]).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('locations.destroy', ['location' => $location->id]).'" data-content="'.trans('admin/locations/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($location->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>'; $actions = '<nobr>';
$actions .= Helper::generateDatatableButton('edit', route('locations.edit', $location->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('locations.destroy', $location->id),
true, /*enabled*/
trans('admin/locations/message.delete.confirm'),
$location->name
);
$actions .= '</nobr>';
$rows[] = array( $rows[] = array(
'id' => $location->id, 'id' => $location->id,
@ -346,7 +337,6 @@ class LocationsController extends Controller
'actions' => $actions 'actions' => $actions
); );
} }
$data = array('total' => $locationsCount, 'rows' => $rows); $data = array('total' => $locationsCount, 'rows' => $rows);
return $data; return $data;
@ -399,7 +389,7 @@ class LocationsController extends Controller
* @see LocationsController::getView() method that creates the display view * @see LocationsController::getView() method that creates the display view
* @param int $locationID * @param int $locationID
* @since [v1.8] * @since [v1.8]
* @return View * @return array
*/ */
public function getDataViewAssets($locationID) public function getDataViewAssets($locationID)
{ {
@ -415,12 +405,12 @@ class LocationsController extends Controller
$rows = array(); $rows = array();
foreach ($assets as $asset) { foreach ($assets as $asset) {
$rows[] = array( $rows[] = [
'name' => (string)link_to_route('hardware.show', e($asset->showAssetName()), ['hardware' => $asset->id]), 'name' => (string)link_to_route('hardware.show', e($asset->showAssetName()), ['hardware' => $asset->id]),
'asset_tag' => e($asset->asset_tag), 'asset_tag' => e($asset->asset_tag),
'serial' => e($asset->serial), 'serial' => e($asset->serial),
'model' => e($asset->model->name), 'model' => e($asset->model->name),
); ];
} }
$data = array('total' => $assets->count(), 'rows' => $rows); $data = array('total' => $assets->count(), 'rows' => $rows);

View file

@ -1,8 +1,10 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\Helper;
use App\Models\Manufacturer; use App\Models\Manufacturer;
use Auth; use Auth;
use Exception;
use Gate; use Gate;
use Input; use Input;
use Lang; use Lang;
@ -26,7 +28,7 @@ class ManufacturersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ManufacturersController::getDatatable() method that generates the JSON response * @see ManufacturersController::getDatatable() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
{ {
@ -41,7 +43,7 @@ class ManufacturersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ManufacturersController::postCreate() * @see ManufacturersController::postCreate()
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
@ -55,20 +57,19 @@ class ManufacturersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ManufacturersController::postCreate() * @see ManufacturersController::postCreate()
* @since [v1.0] * @since [v1.0]
* @return Redirect * @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/ */
public function store(Request $request) public function store(Request $request)
{ {
$manufacturer = new Manufacturer; $manufacturer = new Manufacturer;
$manufacturer->name = e($request->input('name')); $manufacturer->name = $request->input('name');
$manufacturer->user_id = Auth::user()->id; $manufacturer->user_id = Auth::id();
if ($manufacturer->save()) { if ($manufacturer->save()) {
return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.create.success')); return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.create.success'));
} }
return redirect()->back()->withInput()->withErrors($manufacturer->getErrors()); return redirect()->back()->withInput()->withErrors($manufacturer->getErrors());
} }
/** /**
@ -78,7 +79,7 @@ class ManufacturersController extends Controller
* @see ManufacturersController::postEdit() * @see ManufacturersController::postEdit()
* @param int $manufacturerId * @param int $manufacturerId
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function edit($manufacturerId = null) public function edit($manufacturerId = null)
{ {
@ -87,7 +88,6 @@ class ManufacturersController extends Controller
// Redirect to the manufacturer page // Redirect to the manufacturer page
return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.does_not_exist')); return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.does_not_exist'));
} }
// Show the page // Show the page
return View::make('manufacturers/edit', compact('item')); return View::make('manufacturers/edit', compact('item'));
} }
@ -98,9 +98,10 @@ class ManufacturersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ManufacturersController::getEdit() * @see ManufacturersController::getEdit()
* @param Request $request
* @param int $manufacturerId * @param int $manufacturerId
* @return \Illuminate\Http\RedirectResponse
* @since [v1.0] * @since [v1.0]
* @return View
*/ */
public function update(Request $request, $manufacturerId = null) public function update(Request $request, $manufacturerId = null)
{ {
@ -111,17 +112,13 @@ class ManufacturersController extends Controller
} }
// Save the data // Save the data
$manufacturer->name = e($request->input('name')); $manufacturer->name = $request->input('name');
// Was it created? // Was it created?
if ($manufacturer->save()) { if ($manufacturer->save()) {
// Redirect to the new manufacturer page // Redirect to the new manufacturer page
return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.update.success')); return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.update.success'));
} }
return redirect()->back()->withInput()->withErrors($manufacturer->getErrors()); return redirect()->back()->withInput()->withErrors($manufacturer->getErrors());
} }
/** /**
@ -130,7 +127,7 @@ class ManufacturersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $manufacturerId * @param int $manufacturerId
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($manufacturerId) public function destroy($manufacturerId)
{ {
@ -141,22 +138,15 @@ class ManufacturersController extends Controller
} }
if ($manufacturer->has_models() > 0) { if ($manufacturer->has_models() > 0) {
// Redirect to the asset management page // Redirect to the asset management page
return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.assoc_users')); return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.assoc_users'));
} else { }
// Delete the manufacturer // Delete the manufacturer
$manufacturer->delete(); $manufacturer->delete();
// Redirect to the manufacturers management page // Redirect to the manufacturers management page
return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.delete.success')); return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.delete.success'));
} }
}
/** /**
* Returns a view that invokes the ajax tables which actually contains * Returns a view that invokes the ajax tables which actually contains
* the content for the manufacturers detail listing, which is generated in getDatatable. * the content for the manufacturers detail listing, which is generated in getDatatable.
@ -166,7 +156,7 @@ class ManufacturersController extends Controller
* @see ManufacturersController::getDataView() * @see ManufacturersController::getDataView()
* @param int $manufacturerId * @param int $manufacturerId
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function show($manufacturerId = null) public function show($manufacturerId = null)
{ {
@ -174,45 +164,31 @@ class ManufacturersController extends Controller
if (isset($manufacturer->id)) { if (isset($manufacturer->id)) {
return View::make('manufacturers/view', compact('manufacturer')); return View::make('manufacturers/view', compact('manufacturer'));
} else { }
// Prepare the error message // Prepare the error message
$error = trans('admin/manufacturers/message.does_not_exist', compact('id')); $error = trans('admin/manufacturers/message.does_not_exist', compact('id'));
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('manufacturers')->with('error', $error); return redirect()->route('manufacturers')->with('error', $error);
} }
}
/** /**
* Generates the JSON used to display the manufacturer listings. * Generates the JSON used to display the manufacturer listings.
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ManufacturersController::getIndex() * @see ManufacturersController::getIndex()
* @since [v1.0] * @since [v1.0]
* @param Request $request
* @return String JSON * @return String JSON
*/ */
public function getDatatable(Request $request) public function getDatatable(Request $request)
{ {
$manufacturers = Manufacturer::select(array('id','name'))->with('assets', 'licenses', 'accessories', 'consumables') $manufacturers = Manufacturer::select(array('id','name'))->whereNull('deleted_at');
->whereNull('deleted_at');
if ($request->has('search')) { if ($request->has('search')) {
$manufacturers = $manufacturers->TextSearch(e($request->input('search'))); $manufacturers = $manufacturers->TextSearch(e($request->input('search')));
} }
$offset = request('offset', 0);
if ($request->has('offset')) { $limit = request('limit', 50);
$offset = e($request->input('offset'));
} else {
$offset = 0;
}
if ($request->has('limit')) {
$limit = e($request->input('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['id','name']; $allowed_columns = ['id','name'];
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
@ -226,15 +202,24 @@ class ManufacturersController extends Controller
$rows = array(); $rows = array();
foreach ($manufacturers as $manufacturer) { foreach ($manufacturers as $manufacturer) {
$actions = '<a href="'.route('manufacturers.edit', $manufacturer->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('manufacturers.destroy', $manufacturer->id).'" data-content="'.trans('admin/manufacturers/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($manufacturer->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; $actions = '<nobr>';
$actions .= Helper::generateDatatableButton('edit', route('manufacturers.edit', $manufacturer->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('manufacturers.destroy'),
true, /*enabled*/
trans('admin/manufacturers/message.delete.confirm'),
$manufacturer->name
);
$actions .= '</nobr>';
$rows[] = array( $rows[] = array(
'id' => $manufacturer->id, 'id' => $manufacturer->id,
'name' => (string)link_to_route('manufacturers.show', e($manufacturer->name),['manufacturer' => $manufacturer->id]), 'name' => (string)link_to_route('manufacturers.show', e($manufacturer->name),['manufacturer' => $manufacturer->id]),
'assets' => $manufacturer->assets->count(), 'assets' => $manufacturer->assets()->count(),
'licenses' => $manufacturer->licenses->count(), 'licenses' => $manufacturer->licenses()->count(),
'accessories' => $manufacturer->accessories->count(), 'accessories' => $manufacturer->accessories()->count(),
'consumables' => $manufacturer->consumables->count(), 'consumables' => $manufacturer->consumables()->count(),
'actions' => $actions 'actions' => $actions
); );
} }
@ -254,15 +239,15 @@ class ManufacturersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see ManufacturersController::getView() * @see ManufacturersController::getView()
* @param int $manufacturerId * @param int $manufacturerId
* @param string $itemtype * @param string $itemType
* @param Request $request * @param Request $request
* @return String JSON* @since [v1.0] * @return String JSON* @since [v1.0]
*/ */
public function getDataView($manufacturerId, $itemtype = null, Request $request) public function getDataView($manufacturerId, $itemType = null, Request $request)
{ {
$manufacturer = Manufacturer::find($manufacturerId); $manufacturer = Manufacturer::find($manufacturerId);
switch ($itemtype) { switch ($itemType) {
case "assets": case "assets":
return $this->getDataAssetsView($manufacturer, $request); return $this->getDataAssetsView($manufacturer, $request);
case "licenses": case "licenses":
@ -273,55 +258,53 @@ class ManufacturersController extends Controller
return $this->getDataConsumablesView($manufacturer, $request); return $this->getDataConsumablesView($manufacturer, $request);
} }
throw new Exception("We shouldn't be here"); return "We shouldn't be here";
} }
protected function getDataAssetsView(Manufacturer $manufacturer, Request $request) protected function getDataAssetsView(Manufacturer $manufacturer, Request $request)
{ {
$manufacturer = $manufacturer->load('assets.model', 'assets.assigneduser', 'assets.assetstatus', 'assets.company'); $manufacturer = $manufacturer->load('assets.model', 'assets.assigneduser', 'assets.assetstatus', 'assets.company');
$manufacturer_assets = $manufacturer->assets; $manufacturer_assets = $manufacturer->assets();
if ($request->has('search')) { if ($request->has('search')) {
$manufacturer_assets = $manufacturer_assets->TextSearch(e($request->input('search'))); $manufacturer_assets = $manufacturer_assets->TextSearch(e($request->input('search')));
} }
if ($request->has('offset')) { $offset = request('offset', 0);
$offset = e($request->input('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if ($request->has('limit')) {
$limit = e($request->input('limit'));
} else {
$limit = 50;
}
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$allowed_columns = ['id','name','serial','asset_tag']; $allowed_columns = ['id','name','serial','asset_tag'];
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
$count = $manufacturer_assets->count(); $count = $manufacturer_assets->count();
$manufacturer_assets = $manufacturer_assets->skip($offset)->take($limit)->get();
$rows = array(); $rows = array();
foreach ($manufacturer_assets as $asset) { foreach ($manufacturer_assets as $asset) {
$actions = '<div style="white-space: nowrap;">';
$actions = '';
if ($asset->deleted_at=='') { if ($asset->deleted_at=='') {
$actions = '<div style=" white-space: nowrap;"><a href="'.route('clone/hardware', $asset->id).'" class="btn btn-info btn-sm" title="Clone asset"><i class="fa fa-files-o"></i></a> <a href="'.route('hardware.edit', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('hardware.destroy', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->asset_tag).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>'; $actions .= Helper::generateDatatableButton('clone', route('clone/hardware', $asset->id));
$actions .= Helper::generateDatatableButton('edit', route('hardware.edit', $asset->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('hardware.destroy', $asset->id),
true, /*enabled*/
trans('admin/hardware/message.delete.confirm'),
$asset->asset_tag
);
} elseif ($asset->deleted_at!='') { } elseif ($asset->deleted_at!='') {
$actions = '<a href="'.route('restore/hardware', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>'; $actions .= Helper::generateDatatableButton('restore', route('restore/hardware', $asset->id));
} }
$actions .= '</div>';
if ($asset->availableForCheckout()) { if ($asset->availableForCheckout()) {
if (Gate::allows('checkout', $asset)) { if (Gate::allows('checkout', $asset)) {
$inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>'; $inout = Helper::generateDatatableButton('checkout', route('checkout/hardware', $asset->id));
} }
} else { } else {
if (Gate::allows('checkin', $asset)) { if (Gate::allows('checkin', $asset)) {
$inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>'; $inout = Helper::generateDatatableButton('checkin', route('checkin/hardware', $asset->id));
} }
} }
@ -362,22 +345,27 @@ class ManufacturersController extends Controller
$actions = '<span style="white-space: nowrap;">'; $actions = '<span style="white-space: nowrap;">';
if (Gate::allows('checkout', \App\Models\License::class)) { if (Gate::allows('checkout', \App\Models\License::class)) {
$actions .= '<a href="' . route('licenses.freecheckout', $license->id) $actions .= Helper::generateDatatableButton(
. '" class="btn btn-primary btn-sm' . (($license->remaincount() > 0) ? '' : ' disabled') . '" style="margin-right:5px;">' . trans('general.checkout') . '</a> '; 'checkout',
route('licenses.freecheckout', $license->id),
$license->remaincount() > 0
);
} }
if (Gate::allows('create', $license)) { if (Gate::allows('create', $license)) {
$actions .= '<a href="' . route('clone/license', $license->id) $actions .= Helper::generateDatatableButton('clone', route('clone/license', $license->id));
. '" class="btn btn-info btn-sm" style="margin-right:5px;" title="Clone asset"><i class="fa fa-files-o"></i></a>';
} }
if (Gate::allows('edit', $license)) { if (Gate::allows('update', $license)) {
$actions .= '<a href="' . route('licenses.edit', ['license' => $license->id]) $actions .= Helper::generateDatatableButton('edit', route('licenses.edit', $license->id));
. '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
} }
if (Gate::allows('delete', $license)) { if (Gate::allows('delete', $license)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' $actions .= Helper::generateDatatableButton(
. route('licenses.destroy', $license->id) 'delete',
. '" data-content="' . trans('admin/licenses/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($license->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; route('licenses.destroy', $license->id),
true, /*enabled*/
trans('admin/licenses/message.delete.confirm'),
$license->name
);
} }
$actions .='</span>'; $actions .='</span>';
@ -415,36 +403,40 @@ class ManufacturersController extends Controller
'accessories.manufacturer', 'accessories.manufacturer',
'accessories.users' 'accessories.users'
); );
$accessories = $manufacturer->accessories; $accessories = $manufacturer->accessories();
if ($request->has('search')) { if ($request->has('search')) {
$accessories = $accessories->TextSearch(e($request->input('search'))); $accessories = $accessories->TextSearch(e($request->input('search')));
} }
if ($request->has('limit')) { $offset = request('offset', 0);
$limit = e($request->input('limit')); $limit = request('limit', 50);
} else {
$limit = 50;
}
$accessCount = $accessories->count(); $accessCount = $accessories->count();
$accessories = $accessories->skip($offset)->take($limit)->get();
$rows = array(); $rows = array();
foreach ($accessories as $accessory) { foreach ($accessories as $accessory) {
$actions = '<nobr>'; $actions = '<nobr>';
if (Gate::allows('checkout', $accessory)) { if (Gate::allows('checkout', $accessory)) {
$actions .= '<a href="' . route('checkout/accessory', $actions .= Helper::generateDatatableButton(
$accessory->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm" ' . (($accessory->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>'; 'checkout',
route('checkout/accessory', $accessory->id),
$accessory->numRemaining() > 0
);
} }
if (Gate::allows('update', $accessory)) { if (Gate::allows('update', $accessory)) {
$actions .= '<a href="' . route('accessories.update', $actions .= Helper::generateDatatableButton('edit', route('accessories.update', $accessory->id));
$accessory->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
} }
if (Gate::allows('delete', $accessory)) { if (Gate::allows('delete', $accessory)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('accessories.destroy', $actions .= Helper::generateDatatableButton(
$accessory->id) . '" data-content="' . trans('admin/accessories/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($accessory->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; 'delete',
route('accessories.destroy', $accessory->id),
$enabled = true,
trans('admin/accessories/message.delete.confirm'),
$accessory->name
);
} }
$actions .= '</nobr>'; $actions .= '</nobr>';
$company = $accessory->company; $company = $accessory->company;
@ -480,36 +472,37 @@ class ManufacturersController extends Controller
'consumables.manufacturer', 'consumables.manufacturer',
'consumables.users' 'consumables.users'
); );
$consumables = $manufacturer->consumables; $consumables = $manufacturer->consumables();
if ($request->has('search')) { if ($request->has('search')) {
$consumables = $consumables->TextSearch(e($request->input('search'))); $consumables = $consumables->TextSearch(e($request->input('search')));
} }
if ($request->has('limit')) { $offset = request('offset', 0);
$limit = e($request->input('limit')); $limit = request('limit', 50);
} else {
$limit = 50;
}
$consumCount = $consumables->count(); $consumCount = $consumables->count();
$consumables = $consumables->skip($offset)->take($limit)->get();
$rows = array(); $rows = array();
foreach ($consumables as $consumable) { foreach ($consumables as $consumable) {
$actions = '<nobr>'; $actions = '<nobr>';
if (Gate::allows('checkout', $consumable)) { if (Gate::allows('checkout', $consumable)) {
$actions .= '<a href="' . route('checkout/consumable', $actions .= Helper::generateDatatableButton('checkout', route('checkout/consumable', $consumable->id), $consumable->numRemaining() > 0);
$consumable->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm" ' . (($consumable->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>';
} }
if (Gate::allows('update', $consumable)) { if (Gate::allows('update', $consumable)) {
$actions .= '<a href="' . route('consumables.edit', $actions .= Helper::generateDatatableButton('edit', route('consumables.edit', $consumable->id));
$consumable->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
} }
if (Gate::allows('delete', $consumable)) { if (Gate::allows('delete', $consumable)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('consumables.destroy', $actions .= Helper::generateDatatableButton(
$consumable->id) . '" data-content="' . trans('admin/consumables/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($consumable->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; 'delete',
route('consumables.destroy', $consumable->id),
true, /* enabled */
trans('admin/consumables/message.delete.confirm'),
$consumable->name
);
} }
$actions .='</nobr>'; $actions .='</nobr>';

View file

@ -24,7 +24,7 @@ class ProfileController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function getIndex() public function getIndex()
{ {
@ -39,7 +39,7 @@ class ProfileController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postIndex() public function postIndex()
{ {
@ -48,16 +48,16 @@ class ProfileController extends Controller
$user = Auth::user(); $user = Auth::user();
// Update the user information // Update the user information
$user->first_name = e(Input::get('first_name')); $user->first_name = Input::get('first_name');
$user->last_name = e(Input::get('last_name')); $user->last_name = Input::get('last_name');
$user->website = e(Input::get('website')); $user->website = Input::get('website');
$user->location_id = e(Input::get('location_id')); $user->location_id = Input::get('location_id');
$user->gravatar = e(Input::get('gravatar')); $user->gravatar = Input::get('gravatar');
$user->locale = e(Input::get('locale')); $user->locale = Input::get('locale');
if ((Gate::allows('self.two_factor')) && ((Setting::getSettings()->two_factor_enabled=='1') && (!config('app.lock_passwords')))) { if ((Gate::allows('self.two_factor')) && ((Setting::getSettings()->two_factor_enabled=='1') && (!config('app.lock_passwords')))) {
$user->two_factor_optin = e(Input::get('two_factor_optin', '0')); $user->two_factor_optin = Input::get('two_factor_optin', '0');
} }
if (Input::file('avatar')) { if (Input::file('avatar')) {

View file

@ -27,7 +27,7 @@ class StatuslabelsController extends Controller
/** /**
* Show a list of all the statuslabels. * Show a list of all the statuslabels.
* *
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
@ -40,27 +40,24 @@ class StatuslabelsController extends Controller
/** /**
* Show a count of assets by status label * Show a count of assets by status label
* *
* @return View * @return array
*/ */
public function getAssetCountByStatuslabel() public function getAssetCountByStatuslabel()
{ {
$colors = [];
$statuslabels = Statuslabel::with('assets')->get(); $statusLabels = Statuslabel::with()->get();
$labels=[]; $labels=[];
$points=[]; $points=[];
$colors=[]; $colors=[];
foreach ($statuslabels as $statuslabel) { foreach ($statusLabels as $statusLabel) {
if ($statuslabel->assets->count() > 0) { if ($statusLabel->assets()->count() > 0) {
$labels[]=$statuslabel->name; $labels[]=$statusLabel->name;
$points[]=$statuslabel->assets()->whereNull('assigned_to')->count(); $points[]=$statusLabel->assets()->whereNull('assigned_to')->count();
if ($statuslabel->color!='') { if ($statusLabel->color!='') {
$colors[]=$statuslabel->color; $colors[]=$statusLabel->color;
} }
} }
} }
$labels[]='Deployed'; $labels[]='Deployed';
$points[]=Asset::whereNotNull('assigned_to')->count(); $points[]=Asset::whereNotNull('assigned_to')->count();
@ -82,7 +79,7 @@ class StatuslabelsController extends Controller
/** /**
* Statuslabel create. * Statuslabel create.
* *
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
@ -98,52 +95,53 @@ class StatuslabelsController extends Controller
/** /**
* Statuslabel create form processing. * Statuslabel create form processing.
* *
* @return Redirect * @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/ */
public function store(Request $request) public function store(Request $request)
{ {
// create a new model instance // create a new model instance
$statuslabel = new Statuslabel(); $statusLabel = new Statuslabel();
if (!$request->has('statuslabel_types')) { if (!$request->has('statuslabel_types')) {
return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]); return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]);
} }
$statustype = Statuslabel::getStatuslabelTypesForDB($request->input('statuslabel_types')); $statusType = Statuslabel::getStatuslabelTypesForDB($request->input('statuslabel_types'));
// Save the Statuslabel data // Save the Statuslabel data
$statuslabel->name = e(Input::get('name')); $statusLabel->name = Input::get('name');
$statuslabel->user_id = Auth::user()->id; $statusLabel->user_id = Auth::id();
$statuslabel->notes = e(Input::get('notes')); $statusLabel->notes = Input::get('notes');
$statuslabel->deployable = $statustype['deployable']; $statusLabel->deployable = $statusType['deployable'];
$statuslabel->pending = $statustype['pending']; $statusLabel->pending = $statusType['pending'];
$statuslabel->archived = $statustype['archived']; $statusLabel->archived = $statusType['archived'];
$statuslabel->color = e(Input::get('color')); $statusLabel->color = Input::get('color');
$statuslabel->show_in_nav = e(Input::get('show_in_nav'),0); $statusLabel->show_in_nav = Input::get('show_in_nav', 0);
// Was the asset created? // Was the asset created?
if ($statuslabel->save()) { if ($statusLabel->save()) {
// Redirect to the new Statuslabel page // Redirect to the new Statuslabel page
return redirect()->route('statuslabels.index')->with('success', trans('admin/statuslabels/message.create.success')); return redirect()->route('statuslabels.index')->with('success', trans('admin/statuslabels/message.create.success'));
} }
return redirect()->back()->withInput()->withErrors($statusLabel->getErrors());
return redirect()->back()->withInput()->withErrors($statuslabel->getErrors());
} }
/**
* @param Request $request
* @return JsonResponse
*/
public function apiStore(Request $request) public function apiStore(Request $request)
{ {
$statuslabel = new Statuslabel(); $statuslabel = new Statuslabel();
if (!$request->has('statuslabel_types')) { if (!$request->has('statuslabel_types')) {
return JsonResponse::create(["error" => trans('validation.statuslabel_type')], 500); return JsonResponse::create(["error" => trans('validation.statuslabel_type')], 500);
} }
$statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types')); $statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
$statuslabel->name = e(Input::get('name')); $statuslabel->name = Input::get('name');
$statuslabel->user_id = Auth::user()->id; $statuslabel->user_id = Auth::id();
$statuslabel->notes = ''; $statuslabel->notes = '';
$statuslabel->deployable = $statustype['deployable']; $statuslabel->deployable = $statustype['deployable'];
$statuslabel->pending = $statustype['pending']; $statuslabel->pending = $statustype['pending'];
@ -164,7 +162,7 @@ class StatuslabelsController extends Controller
* Statuslabel update. * Statuslabel update.
* *
* @param int $statuslabelId * @param int $statuslabelId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function edit($statuslabelId = null) public function edit($statuslabelId = null)
{ {
@ -186,7 +184,7 @@ class StatuslabelsController extends Controller
* Statuslabel update form processing page. * Statuslabel update form processing page.
* *
* @param int $statuslabelId * @param int $statuslabelId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function update(Request $request, $statuslabelId = null) public function update(Request $request, $statuslabelId = null)
{ {
@ -203,34 +201,28 @@ class StatuslabelsController extends Controller
// Update the Statuslabel data // Update the Statuslabel data
$statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types')); $statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
$statuslabel->name = e(Input::get('name')); $statuslabel->name = Input::get('name');
$statuslabel->notes = e(Input::get('notes')); $statuslabel->notes = Input::get('notes');
$statuslabel->deployable = $statustype['deployable']; $statuslabel->deployable = $statustype['deployable'];
$statuslabel->pending = $statustype['pending']; $statuslabel->pending = $statustype['pending'];
$statuslabel->archived = $statustype['archived']; $statuslabel->archived = $statustype['archived'];
$statuslabel->color = e(Input::get('color')); $statuslabel->color = Input::get('color');
$statuslabel->show_in_nav = e(Input::get('show_in_nav'),0); $statuslabel->show_in_nav = Input::get('show_in_nav',0);
// Was the asset created? // Was the asset created?
if ($statuslabel->save()) { if ($statuslabel->save()) {
// Redirect to the saved Statuslabel page // Redirect to the saved Statuslabel page
return redirect()->to("admin/settings/statuslabels/")->with('success', trans('admin/statuslabels/message.update.success')); return redirect()->to("admin/settings/statuslabels/")->with('success', trans('admin/statuslabels/message.update.success'));
} else {
return redirect()->back()->withInput()->withErrors($statuslabel->getErrors());
} }
return redirect()->back()->withInput()->withErrors($statuslabel->getErrors());
// Redirect to the Statuslabel management page
return redirect()->to("admin/settings/statuslabels/$statuslabelId/edit")->with('error', trans('admin/statuslabels/message.update.error'));
} }
/** /**
* Delete the given Statuslabel. * Delete the given Statuslabel.
* *
* @param int $statuslabelId * @param int $statuslabelId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($statuslabelId) public function destroy($statuslabelId)
{ {
@ -241,20 +233,13 @@ class StatuslabelsController extends Controller
} }
if ($statuslabel->has_assets() > 0) { if ($statuslabel->has_assets() == 0) {
// Redirect to the asset management page
return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.assoc_assets'));
} else {
$statuslabel->delete(); $statuslabel->delete();
// Redirect to the statuslabels management page // Redirect to the statuslabels management page
return redirect()->route('statuslabels.index')->with('success', trans('admin/statuslabels/message.delete.success')); return redirect()->route('statuslabels.index')->with('success', trans('admin/statuslabels/message.delete.success'));
} }
// Redirect to the asset management page
return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.assoc_assets'));
} }
@ -267,17 +252,8 @@ class StatuslabelsController extends Controller
$statuslabels = $statuslabels->TextSearch(e(Input::get('search'))); $statuslabels = $statuslabels->TextSearch(e(Input::get('search')));
} }
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e(Input::get('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e(Input::get('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['id','name']; $allowed_columns = ['id','name'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
@ -301,8 +277,16 @@ class StatuslabelsController extends Controller
} else { } else {
$label_type = trans('admin/statuslabels/table.undeployable'); $label_type = trans('admin/statuslabels/table.undeployable');
} }
$actions = '<nobr>';
$actions = '<a href="'.route('statuslabels.edit', $statuslabel->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('statuslabels.destroy', $statuslabel->id).'" data-content="'.trans('admin/statuslabels/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($statuslabel->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; $actions .= Helper::generateDatatableButton('edit', route('statuslabels.edit', $statuslabel->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('statuslabels.destroy'),
true, /*enabled*/
trans('admin/statuslabels/message.delete.confirm'),
$statuslabel->name
);
$actions .= '</nobr>';
if ($statuslabel->color!='') { if ($statuslabel->color!='') {
$color = '<div class="pull-left" style="margin-right: 5px; height: 20px; width: 20px; background-color: '.e($statuslabel->color).'"></div>'.e($statuslabel->color); $color = '<div class="pull-left" style="margin-right: 5px; height: 20px; width: 20px; background-color: '.e($statuslabel->color).'"></div>'.e($statuslabel->color);

View file

@ -1,6 +1,7 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\Helper;
use Image; use Image;
use App\Models\AssetMaintenance; use App\Models\AssetMaintenance;
use Input; use Input;
@ -26,7 +27,7 @@ class SuppliersController extends Controller
/** /**
* Show a list of all suppliers * Show a list of all suppliers
* *
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
{ {
@ -41,7 +42,7 @@ class SuppliersController extends Controller
/** /**
* Supplier create. * Supplier create.
* *
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
@ -52,37 +53,31 @@ class SuppliersController extends Controller
/** /**
* Supplier create form processing. * Supplier create form processing.
* *
* @return Redirect * @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/ */
public function store() public function store(Request $request)
{ {
// get the POST data
$new = Input::all();
// Create a new supplier // Create a new supplier
$supplier = new Supplier; $supplier = new Supplier;
// Save the location data // Save the location data
$supplier->name = e(Input::get('name')); $supplier->name = request('name');
$supplier->address = e(Input::get('address')); $supplier->address = request('address');
$supplier->address2 = e(Input::get('address2')); $supplier->address2 = request('address2');
$supplier->city = e(Input::get('city')); $supplier->city = request('city');
$supplier->state = e(Input::get('state')); $supplier->state = request('state');
$supplier->country = e(Input::get('country')); $supplier->country = request('country');
$supplier->zip = e(Input::get('zip')); $supplier->zip = request('zip');
$supplier->contact = e(Input::get('contact')); $supplier->contact = request('contact');
$supplier->phone = e(Input::get('phone')); $supplier->phone = request('phone');
$supplier->fax = e(Input::get('fax')); $supplier->fax = request('fax');
$supplier->email = e(Input::get('email')); $supplier->email = request('email');
$supplier->notes = e(Input::get('notes')); $supplier->notes = request('notes');
$supplier->url = $supplier->addhttp(e(Input::get('url'))); $supplier->url = $supplier->addhttp(request('url'));
$supplier->user_id = Auth::user()->id; $supplier->user_id = Auth::id();
if (Input::file('image')) { if (Input::file('image')) {
$image = Input::file('image'); $image = $request->file('image');
$file_name = str_random(25).".".$image->getClientOriginalExtension(); $file_name = str_random(25).".".$image->getClientOriginalExtension();
$path = public_path('uploads/suppliers/'.$file_name); $path = public_path('uploads/suppliers/'.$file_name);
Image::make($image->getRealPath())->resize(300, null, function ($constraint) { Image::make($image->getRealPath())->resize(300, null, function ($constraint) {
@ -97,30 +92,30 @@ class SuppliersController extends Controller
// Redirect to the new supplier page // Redirect to the new supplier page
return redirect()->route('suppliers.index')->with('success', trans('admin/suppliers/message.create.success')); return redirect()->route('suppliers.index')->with('success', trans('admin/suppliers/message.create.success'));
} }
return redirect()->back()->withInput()->withErrors($supplier->getErrors()); return redirect()->back()->withInput()->withErrors($supplier->getErrors());
} }
/**
* @param Request $request
* @return JsonResponse
*/
public function apiStore(Request $request) public function apiStore(Request $request)
{ {
$supplier = new Supplier; $supplier = new Supplier;
$supplier->name = e($request->input('name')); $supplier->name = $request->input('name');
$supplier->user_id = Auth::user()->id; $supplier->user_id = Auth::id();
if ($supplier->save()) { if ($supplier->save()) {
return JsonResponse::create($supplier); return JsonResponse::create($supplier);
} }
return JsonResponse::create(["error" => "Failed validation: ".print_r($supplier->getErrors(), true)], 500); return JsonResponse::create(["error" => "Failed validation: ".print_r($supplier->getErrors(), true)], 500);
return JsonResponse::create(["error" => "Couldn't save Supplier"]);
} }
/** /**
* Supplier update. * Supplier update.
* *
* @param int $supplierId * @param int $supplierId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function edit($supplierId = null) public function edit($supplierId = null)
{ {
@ -139,9 +134,9 @@ class SuppliersController extends Controller
* Supplier update form processing page. * Supplier update form processing page.
* *
* @param int $supplierId * @param int $supplierId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function update($supplierId = null) public function update($supplierId = null, Request $request)
{ {
// Check if the supplier exists // Check if the supplier exists
if (is_null($supplier = Supplier::find($supplierId))) { if (is_null($supplier = Supplier::find($supplierId))) {
@ -150,22 +145,22 @@ class SuppliersController extends Controller
} }
// Save the data // Save the data
$supplier->name = e(Input::get('name')); $supplier->name = request('name');
$supplier->address = e(Input::get('address')); $supplier->address = request('address');
$supplier->address2 = e(Input::get('address2')); $supplier->address2 = request('address2');
$supplier->city = e(Input::get('city')); $supplier->city = request('city');
$supplier->state = e(Input::get('state')); $supplier->state = request('state');
$supplier->country = e(Input::get('country')); $supplier->country = request('country');
$supplier->zip = e(Input::get('zip')); $supplier->zip = request('zip');
$supplier->contact = e(Input::get('contact')); $supplier->contact = request('contact');
$supplier->phone = e(Input::get('phone')); $supplier->phone = request('phone');
$supplier->fax = e(Input::get('fax')); $supplier->fax = request('fax');
$supplier->email = e(Input::get('email')); $supplier->email = request('email');
$supplier->url = $supplier->addhttp(e(Input::get('url'))); $supplier->url = $supplier->addhttp(request('url'));
$supplier->notes = e(Input::get('notes')); $supplier->notes = request('notes');
if (Input::file('image')) { if (Input::file('image')) {
$image = Input::file('image'); $image = $request->file('image');
$file_name = str_random(25).".".$image->getClientOriginalExtension(); $file_name = str_random(25).".".$image->getClientOriginalExtension();
$path = public_path('uploads/suppliers/'.$file_name); $path = public_path('uploads/suppliers/'.$file_name);
Image::make($image->getRealPath())->resize(300, null, function ($constraint) { Image::make($image->getRealPath())->resize(300, null, function ($constraint) {
@ -175,7 +170,7 @@ class SuppliersController extends Controller
$supplier->image = $file_name; $supplier->image = $file_name;
} }
if (Input::get('image_delete') == 1 && Input::file('image') == "") { if (request('image_delete') == 1 && $request->file('image') == "") {
$supplier->image = null; $supplier->image = null;
} }
@ -191,7 +186,7 @@ class SuppliersController extends Controller
* Delete the given supplier. * Delete the given supplier.
* *
* @param int $supplierId * @param int $supplierId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($supplierId) public function destroy($supplierId)
{ {
@ -201,35 +196,32 @@ class SuppliersController extends Controller
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.not_found')); return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.not_found'));
} }
if ($supplier->num_assets() > 0) { if ($supplier->num_assets() == 0) {
// Redirect to the asset management page
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.assoc_users'));
} else {
// Delete the supplier // Delete the supplier
$supplier->delete(); $supplier->delete();
// Redirect to the suppliers management page // Redirect to the suppliers management page
return redirect()->route('suppliers.index')->with('success', trans('admin/suppliers/message.delete.success')); return redirect()->route('suppliers.index')->with('success',
trans('admin/suppliers/message.delete.success'));
} }
// Redirect to the asset management page
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.assoc_users'));
} }
/** /**
* Get the asset information to present to the supplier view page * Get the asset information to present to the supplier view page
* *
* @param int $assetId * @param null $supplierId
* @return View * @return \Illuminate\Contracts\View\View
**/ * @internal param int $assetId
*/
public function show($supplierId = null) public function show($supplierId = null)
{ {
$supplier = Supplier::find($supplierId); $supplier = Supplier::find($supplierId);
if (isset($supplier->id)) { if (isset($supplier->id)) {
return View::make('suppliers/view', compact('supplier')); return View::make('suppliers/view', compact('supplier'));
} else { }
// Prepare the error message // Prepare the error message
$error = trans('admin/suppliers/message.does_not_exist', compact('id')); $error = trans('admin/suppliers/message.does_not_exist', compact('id'));
@ -237,9 +229,6 @@ class SuppliersController extends Controller
return redirect()->route('suppliers')->with('error', $error); return redirect()->route('suppliers')->with('error', $error);
} }
}
public function getDatatable() public function getDatatable()
{ {
$suppliers = Supplier::with('assets', 'licenses')->select(array('id','name','address','address2','city','state','country','fax', 'phone','email','contact')) $suppliers = Supplier::with('assets', 'licenses')->select(array('id','name','address','address2','city','state','country','fax', 'phone','email','contact'))
@ -249,17 +238,9 @@ class SuppliersController extends Controller
$suppliers = $suppliers->TextSearch(e(Input::get('search'))); $suppliers = $suppliers->TextSearch(e(Input::get('search')));
} }
if (Input::has('offset')) { $offset = request('offset', 0);
$offset = e(Input::get('offset')); $limit = request('limit', 50);
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e(Input::get('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['id','name','address','phone','contact','fax','email']; $allowed_columns = ['id','name','address','phone','contact','fax','email'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $order = Input::get('order') === 'asc' ? 'asc' : 'desc';
@ -273,7 +254,16 @@ class SuppliersController extends Controller
$rows = array(); $rows = array();
foreach ($suppliers as $supplier) { foreach ($suppliers as $supplier) {
$actions = '<a href="'.route('suppliers.edit', $supplier->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('suppliers.destroy', $supplier->id).'" data-content="'.trans('admin/suppliers/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($supplier->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>'; $actions = '<nobr>';
$actions .= Helper::generateDatatableButton('edit', route('suppliers.edit', $supplier->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('suppliers.destroy', $supplier->id),
true, /*enabled*/
trans('admin/suppliers/message.delete.confirm'),
$supplier->name
);
$actions .= '</nobr>';
$rows[] = array( $rows[] = array(
'id' => $supplier->id, 'id' => $supplier->id,
@ -288,10 +278,7 @@ class SuppliersController extends Controller
'actions' => $actions 'actions' => $actions
); );
} }
$data = array('total' => $suppliersCount, 'rows' => $rows); $data = array('total' => $suppliersCount, 'rows' => $rows);
return $data; return $data;
} }
} }

View file

@ -55,7 +55,7 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @see UsersController::getDatatable() method that generates the JSON response * @see UsersController::getDatatable() method that generates the JSON response
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function index() public function index()
{ {
@ -68,7 +68,7 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function create() public function create()
{ {
@ -85,14 +85,10 @@ class UsersController extends Controller
$userPermissions = Helper::selectedPermissionsArray($permissions, Input::old('permissions', array())); $userPermissions = Helper::selectedPermissionsArray($permissions, Input::old('permissions', array()));
$permissions = $this->filterDisplayable($permissions); $permissions = $this->filterDisplayable($permissions);
$location_list = Helper::locationsList();
$manager_list = Helper::managerList();
$company_list = Helper::companyList();
return View::make('users/edit', compact('groups', 'userGroups', 'permissions', 'userPermissions')) return View::make('users/edit', compact('groups', 'userGroups', 'permissions', 'userPermissions'))
->with('location_list', $location_list) ->with('location_list', Helper::locationsList())
->with('manager_list', $manager_list) ->with('manager_list', Helper::managerList())
->with('company_list', $company_list) ->with('company_list', Helper::companyList())
->with('user', new User); ->with('user', new User);
} }
@ -101,7 +97,7 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function store(SaveUserRequest $request) public function store(SaveUserRequest $request)
{ {
@ -115,17 +111,17 @@ class UsersController extends Controller
$data['password'] = $request->input('password'); $data['password'] = $request->input('password');
} }
// Update the user // Update the user
$user->first_name = e($request->input('first_name')); $user->first_name = $request->input('first_name');
$user->last_name = e($request->input('last_name')); $user->last_name = $request->input('last_name');
$user->locale = e($request->input('locale')); $user->locale = $request->input('locale');
$user->employee_num = e($request->input('employee_num')); $user->employee_num = $request->input('employee_num');
$user->activated = e($request->input('activated', $user->activated)); $user->activated = $request->input('activated', $user->activated);
$user->jobtitle = e($request->input('jobtitle')); $user->jobtitle = $request->input('jobtitle');
$user->phone = e($request->input('phone')); $user->phone = $request->input('phone');
$user->location_id = e($request->input('location_id')); $user->location_id = $request->input('location_id');
$user->company_id = e(Company::getIdForUser($request->input('company_id'))); $user->company_id = Company::getIdForUser($request->input('company_id'));
$user->manager_id = e($request->input('manager_id')); $user->manager_id = $request->input('manager_id');
$user->notes = e($request->input('notes')); $user->notes = $request->input('notes');
// Strip out the superuser permission if the user isn't a superadmin // Strip out the superuser permission if the user isn't a superadmin
$permissions_array = $request->input('permission'); $permissions_array = $request->input('permission');
@ -175,11 +171,7 @@ class UsersController extends Controller
} }
return redirect::route('users.index')->with('success', trans('admin/users/message.success.create')); return redirect::route('users.index')->with('success', trans('admin/users/message.success.create'));
} }
return redirect()->back()->withInput()->withErrors($user->getErrors()); return redirect()->back()->withInput()->withErrors($user->getErrors());
} }
/** /**
@ -198,18 +190,15 @@ class UsersController extends Controller
$inputs = Input::except('csrf_token', 'password_confirm', 'groups', 'email_user'); $inputs = Input::except('csrf_token', 'password_confirm', 'groups', 'email_user');
$inputs['activated'] = true; $inputs['activated'] = true;
$user->first_name = e(Input::get('first_name')); $user->first_name = Input::get('first_name');
$user->last_name = e(Input::get('last_name')); $user->last_name = Input::get('last_name');
$user->username = e(Input::get('username')); $user->username = Input::get('username');
$user->email = e(Input::get('email')); $user->email = Input::get('email');
if (Input::has('password')) { if (Input::has('password')) {
$user->password = bcrypt(Input::get('password')); $user->password = bcrypt(Input::get('password'));
} }
$user->activated = true; $user->activated = true;
// Was the user created? // Was the user created?
if ($user->save()) { if ($user->save()) {
@ -230,12 +219,8 @@ class UsersController extends Controller
return JsonResponse::create($user); return JsonResponse::create($user);
} else {
return JsonResponse::create(["error" => "Failed validation: " . print_r($user->getErrors(), true)], 500);
} }
return JsonResponse::create(["error" => "Failed validation: " . print_r($user->getErrors(), true)], 500);
} }
/** /**
@ -243,8 +228,9 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $id * @param $permissions
* @return View * @return View
* @internal param int $id
*/ */
private function filterDisplayable($permissions) { private function filterDisplayable($permissions) {
@ -271,9 +257,6 @@ class UsersController extends Controller
$user->permissions = $user->decodePermissions(); $user->permissions = $user->decodePermissions();
$userPermissions = Helper::selectedPermissionsArray($permissions, $user->permissions); $userPermissions = Helper::selectedPermissionsArray($permissions, $user->permissions);
$permissions = $this->filterDisplayable($permissions); $permissions = $this->filterDisplayable($permissions);
$location_list = Helper::locationsList();
$company_list = Helper::companyList();
$manager_list = Helper::managerList();
} catch (UserNotFoundException $e) { } catch (UserNotFoundException $e) {
// Prepare the error message // Prepare the error message
$error = trans('admin/users/message.user_not_found', compact('id')); $error = trans('admin/users/message.user_not_found', compact('id'));
@ -284,9 +267,9 @@ class UsersController extends Controller
// Show the page // Show the page
return View::make('users/edit', compact('user', 'groups', 'userGroups', 'permissions', 'userPermissions')) return View::make('users/edit', compact('user', 'groups', 'userGroups', 'permissions', 'userPermissions'))
->with('location_list', $location_list) ->with('location_list', Helper::locationsList())
->with('company_list', $company_list) ->with('company_list', Helper::companyList())
->with('manager_list', $manager_list); ->with('manager_list', Helper::managerList());
} }
/** /**
@ -294,8 +277,9 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param UpdateUserRequest $request
* @param int $id * @param int $id
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function update(UpdateUserRequest $request, $id = null) public function update(UpdateUserRequest $request, $id = null)
{ {
@ -314,15 +298,11 @@ class UsersController extends Controller
$this->authorize('update', $user); $this->authorize('update', $user);
// Figure out of this user was an admin before this edit // Figure out of this user was an admin before this edit
$orig_permissions_array = $user->decodePermissions(); $orig_permissions_array = $user->decodePermissions();
$orig_superuser = '0';
if (is_array($orig_permissions_array)) { if (is_array($orig_permissions_array)) {
if (array_key_exists('superuser', $orig_permissions_array)) { if (array_key_exists('superuser', $orig_permissions_array)) {
$orig_superuser = $orig_permissions_array['superuser']; $orig_superuser = $orig_permissions_array['superuser'];
} else {
$orig_superuser = '0';
} }
} else {
$orig_superuser = '0';
} }
} catch (UserNotFoundException $e) { } catch (UserNotFoundException $e) {
@ -351,18 +331,18 @@ class UsersController extends Controller
// Update the user // Update the user
$user->first_name = e($request->input('first_name')); $user->first_name = $request->input('first_name');
$user->last_name = e($request->input('last_name')); $user->last_name = $request->input('last_name');
$user->two_factor_optin = e($request->input('two_factor_optin')); $user->two_factor_optin = $request->input('two_factor_optin');
$user->locale = e($request->input('locale')); $user->locale = $request->input('locale');
$user->employee_num = e($request->input('employee_num')); $user->employee_num = $request->input('employee_num');
$user->activated = e($request->input('activated', $user->activated)); $user->activated = $request->input('activated', $user->activated);
$user->jobtitle = e($request->input('jobtitle')); $user->jobtitle = $request->input('jobtitle');
$user->phone = e($request->input('phone')); $user->phone = $request->input('phone');
$user->location_id = e($request->input('location_id')); $user->location_id = $request->input('location_id');
$user->company_id = e(Company::getIdForUser($request->input('company_id'))); $user->company_id = Company::getIdForUser($request->input('company_id'));
$user->manager_id = e($request->input('manager_id')); $user->manager_id = $request->input('manager_id');
$user->notes = e($request->input('notes')); $user->notes = $request->input('notes');
// Strip out the superuser permission if the user isn't a superadmin // Strip out the superuser permission if the user isn't a superadmin
$permissions_array = $request->input('permission'); $permissions_array = $request->input('permission');
@ -372,7 +352,6 @@ class UsersController extends Controller
$permissions_array['superuser'] = $orig_superuser; $permissions_array['superuser'] = $orig_superuser;
} }
$user->permissions = json_encode($permissions_array); $user->permissions = json_encode($permissions_array);
if ($user->manager_id == "") { if ($user->manager_id == "") {
@ -387,20 +366,14 @@ class UsersController extends Controller
$user->company_id = null; $user->company_id = null;
} }
// Was the user updated? // Was the user updated?
if ($user->save()) { if ($user->save()) {
// Prepare the success message // Prepare the success message
$success = trans('admin/users/message.success.update'); $success = trans('admin/users/message.success.update');
// Redirect to the user page // Redirect to the user page
return redirect()->route('users.index')->with('success', $success); return redirect()->route('users.index')->with('success', $success);
} }
return redirect()->back()->withInput()->withErrors($user->getErrors()); return redirect()->back()->withInput()->withErrors($user->getErrors());
} }
/** /**
@ -409,7 +382,7 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $id * @param int $id
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy($id = null) public function destroy($id = null)
{ {
@ -419,22 +392,21 @@ class UsersController extends Controller
// Authorize takes care of many of our logic checks now. // Authorize takes care of many of our logic checks now.
$this->authorize('delete', User::class); $this->authorize('delete', User::class);
if (count($user->assets) > 0) { if ($user->assets()->count() > 0) {
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('users.index')->with('error', 'This user still has ' . count($user->assets) . ' assets associated with them.'); return redirect()->route('users.index')->with('error', 'This user still has ' . $user->assets()->count() . ' assets associated with them.');
} }
if (count($user->licenses) > 0) { if ($user->licenses()->count() > 0) {
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('users.index')->with('error', 'This user still has ' . count($user->licenses) . ' licenses associated with them.'); return redirect()->route('users.index')->with('error', 'This user still has ' . $user->licenses()->count() . ' licenses associated with them.');
} }
if (count($user->accessories) > 0) { if ($user->accessories()->count() > 0) {
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('users.index')->with('error', 'This user still has ' . count($user->accessories) . ' accessories associated with them.'); return redirect()->route('users.index')->with('error', 'This user still has ' . $user->accessories()->count() . ' accessories associated with them.');
} }
// Delete the user // Delete the user
@ -448,7 +420,6 @@ class UsersController extends Controller
} catch (UserNotFoundException $e) { } catch (UserNotFoundException $e) {
// Prepare the error message // Prepare the error message
$error = trans('admin/users/message.user_not_found', compact('id')); $error = trans('admin/users/message.user_not_found', compact('id'));
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('users.index')->with('error', $error); return redirect()->route('users.index')->with('error', $error);
} }
@ -459,7 +430,7 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.7] * @since [v1.7]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function postBulkEdit() public function postBulkEdit()
{ {
@ -471,8 +442,6 @@ class UsersController extends Controller
$user_raw_array = array_keys(Input::get('edit_user')); $user_raw_array = array_keys(Input::get('edit_user'));
$licenses = DB::table('license_seats')->whereIn('assigned_to', $user_raw_array)->get(); $licenses = DB::table('license_seats')->whereIn('assigned_to', $user_raw_array)->get();
//print_r($licenses);
$users = User::whereIn('id', $user_raw_array)->with('groups', 'assets', 'licenses', 'accessories')->get(); $users = User::whereIn('id', $user_raw_array)->with('groups', 'assets', 'licenses', 'accessories')->get();
// $users = Company::scopeCompanyables($users)->get(); // $users = Company::scopeCompanyables($users)->get();
@ -485,7 +454,7 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postBulkSave() public function postBulkSave()
{ {
@ -517,56 +486,50 @@ class UsersController extends Controller
$license_array = array(); $license_array = array();
$accessory_array = array(); $accessory_array = array();
foreach ($assets as $asset) { foreach ($assets as $asset) {
$asset_array[] = $asset->id; $asset_array[] = $asset->id;
// Update the asset log // Update the asset log
$logaction = new Actionlog(); $logAction = new Actionlog();
$logaction->item_id = $asset->id; $logAction->item_id = $asset->id;
$logaction->item_type = Asset::class; $logAction->item_type = Asset::class;
$logaction->target_id = $asset->assigned_to; $logAction->target_id = $asset->assigned_to;
$logaction->target_type = User::class; $logAction->target_type = User::class;
$logaction->user_id = Auth::user()->id; $logAction->user_id = Auth::user()->id;
$logaction->note = 'Bulk checkin asset and delete user'; $logAction->note = 'Bulk checkin asset and delete user';
$logaction->logaction('checkin from'); $logAction->logaction('checkin from');
Asset::whereIn('id', $asset_array)->update( Asset::whereIn('id', $asset_array)->update([
array(
'status_id' => e(Input::get('status_id')), 'status_id' => e(Input::get('status_id')),
'assigned_to' => null, 'assigned_to' => null,
) ]);
);
} }
foreach ($accessories as $accessory) { foreach ($accessories as $accessory) {
$accessory_array[] = $accessory->accessory_id; $accessory_array[] = $accessory->accessory_id;
// Update the asset log // Update the asset log
$logaction = new Actionlog(); $logAction = new Actionlog();
$logaction->item_id = $accessory->id; $logAction->item_id = $accessory->id;
$logaction->item_type = Accessory::class; $logAction->item_type = Accessory::class;
$logaction->target_id = $accessory->assigned_to; $logAction->target_id = $accessory->assigned_to;
$logaction->target_type = User::class; $logAction->target_type = User::class;
$logaction->user_id = Auth::user()->id; $logAction->user_id = Auth::user()->id;
$logaction->note = 'Bulk checkin accessory and delete user'; $logAction->note = 'Bulk checkin accessory and delete user';
$logaction->logaction('checkin from'); $logAction->logaction('checkin from');
} }
foreach ($licenses as $license) { foreach ($licenses as $license) {
$license_array[] = $license->id; $license_array[] = $license->id;
// Update the asset log // Update the asset log
$logaction = new Actionlog(); $logAction = new Actionlog();
$logaction->item_id = $license->id; $logAction->item_id = $license->id;
$logaction->item_type = License::class; $logAction->item_type = License::class;
$logaction->target_id = $license->assigned_to; $logAction->target_id = $license->assigned_to;
$logaction->target_type = User::class; $logAction->target_type = User::class;
$logaction->user_id = Auth::user()->id; $logAction->user_id = Auth::user()->id;
$logaction->note = 'Bulk checkin license and delete user'; $logAction->note = 'Bulk checkin license and delete user';
$logaction->logaction('checkin from'); $logAction->logaction('checkin from');
} }
LicenseSeat::whereIn('id', $license_array)->update(['assigned_to' => null]); LicenseSeat::whereIn('id', $license_array)->update(['assigned_to' => null]);
@ -577,10 +540,8 @@ class UsersController extends Controller
} }
return redirect()->route('users.index')->with('success', 'Your selected users have been deleted and their assets have been updated.'); return redirect()->route('users.index')->with('success', 'Your selected users have been deleted and their assets have been updated.');
} else {
return redirect()->route('users.index')->with('error', 'Bulk delete is not enabled in this installation');
} }
return redirect()->route('users.index')->with('error', 'Bulk delete is not enabled in this installation');
} }
} }
@ -590,7 +551,7 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $id * @param int $id
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function getRestore($id = null) public function getRestore($id = null)
{ {
@ -605,7 +566,6 @@ class UsersController extends Controller
return redirect()->route('users.index')->with('success', trans('admin/users/message.success.restored')); return redirect()->route('users.index')->with('success', trans('admin/users/message.success.restored'));
} }
return redirect()->route('users.index')->with('error', 'User could not be restored.'); return redirect()->route('users.index')->with('error', 'User could not be restored.');
} }
@ -615,13 +575,12 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $userId * @param int $userId
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function show($userId = null) public function show($userId = null)
{ {
if(!$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId)) { if(!$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId)) {
$error = trans('admin/users/message.user_not_found', compact('id')); $error = trans('admin/users/message.user_not_found', compact('id'));
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('users.index')->with('error', $error); return redirect()->route('users.index')->with('error', $error);
} }
@ -632,7 +591,6 @@ class UsersController extends Controller
$this->authorize('view', $user); $this->authorize('view', $user);
return View::make('users/view', compact('user', 'userlog')); return View::make('users/view', compact('user', 'userlog'));
} }
} }
/** /**
@ -654,7 +612,6 @@ class UsersController extends Controller
if ($user->id === Auth::user()->id) { if ($user->id === Auth::user()->id) {
// Prepare the error message // Prepare the error message
$error = trans('admin/users/message.error.unsuspend'); $error = trans('admin/users/message.error.unsuspend');
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('users.index')->with('error', $error); return redirect()->route('users.index')->with('error', $error);
} }
@ -667,13 +624,11 @@ class UsersController extends Controller
// Prepare the success message // Prepare the success message
$success = trans('admin/users/message.success.unsuspend'); $success = trans('admin/users/message.success.unsuspend');
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('users.index')->with('success', $success); return redirect()->route('users.index')->with('success', $success);
} catch (UserNotFoundException $e) { } catch (UserNotFoundException $e) {
// Prepare the error message // Prepare the error message
$error = trans('admin/users/message.user_not_found', compact('id')); $error = trans('admin/users/message.user_not_found', compact('id'));
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('users.index')->with('error', $error); return redirect()->route('users.index')->with('error', $error);
} }
@ -687,7 +642,7 @@ class UsersController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param int $id * @param int $id
* @return Redirect * @return \Illuminate\Contracts\View\View
*/ */
public function getClone($id = null) public function getClone($id = null)
{ {
@ -711,34 +666,24 @@ class UsersController extends Controller
// Get this user groups // Get this user groups
$userGroups = $user_to_clone->groups()->lists('name', 'id'); $userGroups = $user_to_clone->groups()->lists('name', 'id');
// Get a list of all the available groups
$groups = Group::pluck('name', 'id');
// Get all the available permissions // Get all the available permissions
$permissions = config('permissions'); $permissions = config('permissions');
$clonedPermissions = $user_to_clone->decodePermissions(); $clonedPermissions = $user_to_clone->decodePermissions();
$userPermissions =Helper::selectedPermissionsArray($permissions, $clonedPermissions); $userPermissions =Helper::selectedPermissionsArray($permissions, $clonedPermissions);
//$this->encodeAllPermissions($permissions);
$location_list = Helper::locationsList();
$company_list = Helper::companyList();
$manager_list = Helper::managerList();
// Show the page // Show the page
return View::make('users/edit', compact('groups', 'userGroups', 'permissions', 'userPermissions')) return View::make('users/edit', compact('permissions', 'userPermissions'))
->with('location_list', $location_list) ->with('location_list', Helper::locationsList())
->with('company_list', $company_list) ->with('company_list', Helper::companyList())
->with('manager_list', $manager_list) ->with('manager_list', Helper::managerList())
->with('user', $user) ->with('user', $user)
->with('groups', $groups) ->with('groups', Group::pluck('name', 'id'))
->with('userGroups', $userGroups) ->with('userGroups', $userGroups)
->with('clone_user', $user_to_clone); ->with('clone_user', $user_to_clone);
} catch (UserNotFoundException $e) { } catch (UserNotFoundException $e) {
// Prepare the error message // Prepare the error message
$error = trans('admin/users/message.user_not_found', compact('id')); $error = trans('admin/users/message.user_not_found', compact('id'));
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('users.index')->with('error', $error); return redirect()->route('users.index')->with('error', $error);
} }
@ -749,23 +694,18 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function getImport() public function getImport()
{ {
$this->authorize('update', User::class); $this->authorize('update', User::class);
// Get all the available groups
//$groups = Sentry::getGroupProvider()->findAll();
// Selected groups // Selected groups
$selectedGroups = Input::old('groups', array()); $selectedGroups = Input::old('groups', array());
// Get all the available permissions // Get all the available permissions
$permissions = config('permissions'); $permissions = config('permissions');
//$this->encodeAllPermissions($permissions);
// Selected permissions
$selectedPermissions = Input::old('permissions', array('superuser' => -1)); $selectedPermissions = Input::old('permissions', array('superuser' => -1));
//$this->encodePermissions($selectedPermissions);
// Show the page // Show the page
return View::make('users/import', compact('groups', 'selectedGroups', 'permissions', 'selectedPermissions')); return View::make('users/import', compact('selectedGroups', 'permissions', 'selectedPermissions'));
} }
/** /**
@ -773,7 +713,7 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postImport() public function postImport()
{ {
@ -864,8 +804,6 @@ class UsersController extends Controller
return true; return true;
} }
}); });
return redirect()->route('users.index')->with('duplicates', $duplicates)->with('success', 'Success'); return redirect()->route('users.index')->with('duplicates', $duplicates)->with('success', 'Success');
} }
@ -880,17 +818,9 @@ class UsersController extends Controller
public function getDatatable(Request $request, $status = null) public function getDatatable(Request $request, $status = null)
{ {
$this->authorize('view', User::class); $this->authorize('view', User::class);
if (Input::has('offset')) {
$offset = e(Input::get('offset'));
} else {
$offset = 0;
}
if (Input::has('limit')) { $offset = request('offset', 0);
$limit = e(Input::get('limit')); $limit = request('limit', 50);
} else {
$limit = 50;
}
if (Input::get('sort')=='name') { if (Input::get('sort')=='name') {
$sort = 'first_name'; $sort = 'first_name';
@ -940,21 +870,16 @@ class UsersController extends Controller
foreach ($users as $user) { foreach ($users as $user) {
$group_names = ''; $group_names = '';
$inout = '';
$actions = '<nobr>'; $actions = '<nobr>';
foreach ($user->groups as $group) { foreach ($user->groups as $group) {
$group_names .= '<a href="' . route('update/group', $group->id) . '" class="label label-default">' . $group->name . '</a> '; $group_names .= '<a href="' . route('update/group', $group->id) . '" class="label label-default">' . $group->name . '</a> ';
} }
if (!is_null($user->deleted_at)) { if (!is_null($user->deleted_at)) {
if (Gate::allows('delete', $user)) { if (Gate::allows('delete', $user)) {
$actions .= '<a href="' . route('restore/user', $actions .= Helper::generateDatatableButton('restore', route('restore/user', $user->id));
$user->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-share icon-white"></i></a> ';
} }
} else { } else {
if (Gate::allows('delete', $user)) { if (Gate::allows('delete', $user)) {
if ($user->accountStatus() == 'suspended') { if ($user->accountStatus() == 'suspended') {
$actions .= '<a href="' . route('unsuspend/user', $actions .= '<a href="' . route('unsuspend/user',
@ -962,21 +887,21 @@ class UsersController extends Controller
} }
} }
if (Gate::allows('update', $user)) { if (Gate::allows('update', $user)) {
$actions .= '<a href="' . route('users.edit', $actions .= Helper::generateDatatableButton('edit', route('users.edit', $user->id));
$user->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> '; $actions .= Helper::generateDatatableButton('clone', route('clone/user', $user->id));
$actions .= '<a href="' . route('clone/user',
$user->id) . '" class="btn btn-info btn-sm"><i class="fa fa-clone"></i></a>';
} }
if (Gate::allows('delete', $user)) { if (Gate::allows('delete', $user)) {
if ((Auth::user()->id !== $user->id) && (!config('app.lock_passwords'))) { if ((Auth::user()->id !== $user->id) && (!config('app.lock_passwords'))) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('users.destroy', $actions .= Helper::generateDatatableButton(
$user->id) . '" data-content="Are you sure you wish to delete this user?" data-title="Delete ' . htmlspecialchars($user->first_name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a> '; 'delete',
route('users.destroy', $user->id),
true, /*enabled*/
"Are you sure you wish to delete this user?",
$user->first_name
);
} else { } else {
$actions .= ' <span class="btn delete-asset btn-danger btn-sm disabled"><i class="fa fa-trash icon-white"></i></span>'; $actions .= ' <span class="btn delete-asset btn-danger btn-sm disabled"><i class="fa fa-trash icon-white"></i></span>';
} }
} else {
$actions.='';
} }
} }
@ -1019,6 +944,7 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.6] * @since [v1.6]
* @param AssetFileRequest $request
* @param int $userId * @param int $userId
* @return string JSON * @return string JSON
*/ */
@ -1039,22 +965,22 @@ class UsersController extends Controller
$upload_success = $file->move($destinationPath, $filename); $upload_success = $file->move($destinationPath, $filename);
//Log the uploaded file to the log //Log the uploaded file to the log
$logaction = new Actionlog(); $logAction = new Actionlog();
$logaction->item_id = $user->id; $logAction->item_id = $user->id;
$logaction->item_type = User::class; $logAction->item_type = User::class;
$logaction->user_id = Auth::user()->id; $logAction->user_id = Auth::user()->id;
$logaction->note = e(Input::get('notes')); $logAction->note = e(Input::get('notes'));
$logaction->target_id = null; $logAction->target_id = null;
$logaction->created_at = date("Y-m-d H:i:s"); $logAction->created_at = date("Y-m-d H:i:s");
$logaction->filename = $filename; $logAction->filename = $filename;
$logaction->action_type = 'uploaded'; $logAction->action_type = 'uploaded';
$logaction->save(); $logAction->save();
} }
return JsonResponse::create($logaction); return JsonResponse::create($logAction);
} }
return JsonResponse::create(["error" => "Failed validation: ".print_r($logaction->getErrors(), true)], 500); return JsonResponse::create(["error" => "Failed validation: ".print_r($logAction->getErrors(), true)], 500);
} }
@ -1065,7 +991,7 @@ class UsersController extends Controller
* @since [v1.6] * @since [v1.6]
* @param int $userId * @param int $userId
* @param int $fileId * @param int $fileId
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function getDeleteFile($userId = null, $fileId = null) public function getDeleteFile($userId = null, $fileId = null)
{ {
@ -1085,7 +1011,6 @@ class UsersController extends Controller
} }
// Prepare the error message // Prepare the error message
$error = trans('admin/users/message.does_not_exist', compact('id')); $error = trans('admin/users/message.does_not_exist', compact('id'));
// Redirect to the licence management page // Redirect to the licence management page
return redirect()->route('users.index')->with('error', $error); return redirect()->route('users.index')->with('error', $error);
@ -1124,20 +1049,17 @@ class UsersController extends Controller
* *
* @author Aladin Alaily * @author Aladin Alaily
* @since [v1.8] * @since [v1.8]
* @return View * @return \Illuminate\Contracts\View\View
*/ */
public function getLDAP() public function getLDAP()
{ {
$this->authorize('update', User::class); $this->authorize('update', User::class);
$location_list = Helper::locationsList();
try { try {
$ldapconn = Ldap::connectToLdap(); $ldapconn = Ldap::connectToLdap();
} catch (\Exception $e) { } catch (\Exception $e) {
return redirect()->route('users.index')->with('error', $e->getMessage()); return redirect()->route('users.index')->with('error', $e->getMessage());
} }
try { try {
Ldap::bindAdminToLdap($ldapconn); Ldap::bindAdminToLdap($ldapconn);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -1145,8 +1067,7 @@ class UsersController extends Controller
} }
return View::make('users/ldap') return View::make('users/ldap')
->with('location_list', $location_list); ->with('location_list', Helper::locationsList());
} }
@ -1173,7 +1094,7 @@ class UsersController extends Controller
* *
* @author Aladin Alaily * @author Aladin Alaily
* @since [v1.8] * @since [v1.8]
* @return Redirect * @return \Illuminate\Http\RedirectResponse
*/ */
public function postLDAP(Request $request) public function postLDAP(Request $request)
{ {
@ -1208,7 +1129,6 @@ class UsersController extends Controller
$tmp_pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20); $tmp_pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);
$pass = bcrypt($tmp_pass); $pass = bcrypt($tmp_pass);
for ($i = 0; $i < $results["count"]; $i++) { for ($i = 0; $i < $results["count"]; $i++) {
if (empty($ldap_result_active_flag) || $results[$i][$ldap_result_active_flag][0] == "TRUE") { if (empty($ldap_result_active_flag) || $results[$i][$ldap_result_active_flag][0] == "TRUE") {
@ -1228,8 +1148,6 @@ class UsersController extends Controller
} }
// Create the user if they don't exist. // Create the user if they don't exist.
$user->first_name = e($item["firstname"]); $user->first_name = e($item["firstname"]);
$user->last_name = e($item["lastname"]); $user->last_name = e($item["lastname"]);
$user->username = e($item["username"]); $user->username = e($item["username"]);
@ -1254,14 +1172,9 @@ class UsersController extends Controller
$item["note"] = $errors; $item["note"] = $errors;
$item["status"]='error'; $item["status"]='error';
} }
array_push($summary, $item); array_push($summary, $item);
} }
} }
return redirect()->route('ldap/user')->with('success', "LDAP Import successful.")->with('summary', $summary); return redirect()->route('ldap/user')->with('success', "LDAP Import successful.")->with('summary', $summary);
} }
@ -1270,6 +1183,7 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0] * @since [v3.0]
* @param $userId
* @return string JSON * @return string JSON
*/ */
public function getAssetList($userId) public function getAssetList($userId)
@ -1284,14 +1198,13 @@ class UsersController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.5] * @since [v3.5]
* @return \Illuminate\Http\Response * @return StreamedResponse
*/ */
public function getExportUserCsv() public function getExportUserCsv()
{ {
$this->authorize('view', User::class); $this->authorize('view', User::class);
\Debugbar::disable(); \Debugbar::disable();
$response = new StreamedResponse(function() { $response = new StreamedResponse(function() {
// Open output stream // Open output stream
$handle = fopen('php://output', 'w'); $handle = fopen('php://output', 'w');
@ -1364,7 +1277,6 @@ class UsersController extends Controller
} }
public function postTwoFactorReset(Request $request) public function postTwoFactorReset(Request $request)
{ {
if (Gate::denies('users.edit')) { if (Gate::denies('users.edit')) {
@ -1380,8 +1292,5 @@ class UsersController extends Controller
} catch (\Exception $e) { } catch (\Exception $e) {
return response()->json(['message' => trans('admin/settings/general.two_factor_reset_error')], 500); return response()->json(['message' => trans('admin/settings/general.two_factor_reset_error')], 500);
} }
} }
} }

View file

@ -20,8 +20,8 @@ class Supplier extends SnipeModel
'city' => 'min:3|max:255', 'city' => 'min:3|max:255',
'state' => 'min:0|max:32', 'state' => 'min:0|max:32',
'country' => 'min:0|max:2', 'country' => 'min:0|max:2',
'fax' => 'min:7|max:20', 'fax' => 'min:7|max:35',
'phone' => 'min:7|max:20', 'phone' => 'min:7|max:35',
'contact' => 'min:0|max:100', 'contact' => 'min:0|max:100',
'notes' => 'min:0|max:255', 'notes' => 'min:0|max:255',
'email' => 'email|min:5|max:150', 'email' => 'email|min:5|max:150',

View file

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ExtendPhoneLengthsInSupplierAndElsewhere extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('suppliers', function (Blueprint $table) {
//
$table->string('phone',35)->nullable()->default(NULL)->change();
$table->string('fax',35)->nullable()->default(NULL)->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('suppliers', function (Blueprint $table) {
//
$table->string('phone',20)->nullable()->default(NULL)->change();
$table->string('fax',20)->nullable()->default(NULL)->change();
});
}
}

File diff suppressed because one or more lines are too long

View file

@ -9,11 +9,10 @@
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: AcceptanceTester class_name: AcceptanceTester
modules: modules:
enabled: config:
- WebDriver: WebDriver:
url: http://localhost:8000 url: http://localhost:8000
browser: phantomjs browser: phantomjs
- \Helper\Acceptance Laravel5:
- Laravel5:
part: ORM part: ORM
environment_file: .env environment_file: .env

View file

@ -11,13 +11,13 @@ modules:
- \Helper\Functional - \Helper\Functional
- Laravel5: - Laravel5:
environment_file: .env.tests environment_file: .env.tests
cleanup: false cleanup: true
- Db: - Db:
dsn: 'mysql:host=localhost;dbname=snipeittests' dsn: 'mysql:host=localhost;dbname=snipeittests'
user: 'snipeit_laravel' user: 'snipeit_laravel'
password: '' password: ''
dump: tests/_data/dump.sql dump: tests/_data/dump.sql
populate: true populate: true
cleanup: false cleanup: true
- REST: - REST:
depends: Laravel5 depends: Laravel5

View file

@ -56,7 +56,8 @@ class AssetModelsCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo('Ensure I can delete an asset model'); $I->wantTo('Ensure I can delete an asset model');
$I->sendDelete(route('models.destroy', $I->getEmptyModelId()), ['_token' => csrf_token()]); $model = factory(App\Models\AssetModel::class, 'assetmodel')->create();
$I->sendDelete(route('models.destroy', $model->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }

View file

@ -55,7 +55,8 @@ class CategoryCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo('Ensure I can delete a category'); $I->wantTo('Ensure I can delete a category');
$I->sendDelete(route('categories.destroy', $I->getEmptyCategoryId()), ['_token' => csrf_token()]); $category = factory(App\Models\Category::class, 'asset-category')->create();
$I->sendDelete(route('categories.destroy', $category->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }
} }

View file

@ -54,11 +54,10 @@ class GroupsCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo("Fix this test to generate a group for deletes");
$I->wantTo('Ensure I can delete a group'); $I->wantTo('Ensure I can delete a group');
$I->amOnPage(route('delete/group', Group::doesntHave('users')->first()->id)); // $I->amOnPage(route('delete/group', Group::doesntHave('users')->first()->id));
$I->seeElement('.alert-success'); // $I->seeElement('.alert-success');
// $I->sendDelete(route('delete/group', Group::doesntHave('users')->first()->id), ['_token' => csrf_token()]);
// $I->seeResponseCodeIs(200);
} }
} }

View file

@ -57,10 +57,7 @@ class ManufacturersCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo('Ensure I can delete a manufacturer'); $I->wantTo('Ensure I can delete a manufacturer');
$manufacturerId = Manufacturer::doesntHave('models') $manufacturerId = factory(App\Models\Manufacturer::class, 'manufacturer')->create()->id;
->doesntHave('accessories')
->doesntHave('consumables')
->doesntHave('licenses')->first()->id;
$I->sendDelete(route('manufacturers.destroy', $manufacturerId), ['_token' => csrf_token()]); $I->sendDelete(route('manufacturers.destroy', $manufacturerId), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }

View file

@ -1,8 +1,5 @@
<?php <?php
use App\Models\Supplier;
class SuppliersCest class SuppliersCest
{ {
public function _before(FunctionalTester $I) public function _before(FunctionalTester $I)
@ -69,7 +66,8 @@ class SuppliersCest
public function allowsDelete(FunctionalTester $I) public function allowsDelete(FunctionalTester $I)
{ {
$I->wantTo('Ensure I can delete a supplier'); $I->wantTo('Ensure I can delete a supplier');
$I->sendDelete(route('suppliers.destroy', Supplier::doesntHave('assets')->doesntHave('licenses')->first()->id), ['_token' => csrf_token()]); $supplier = factory(App\Models\Supplier::class, 'supplier')->create();
$I->sendDelete(route('suppliers.destroy', $supplier->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }
} }

View file

@ -418,20 +418,12 @@ class PermissionsTest extends TestCase
private function hitRoutes(array $routes, User $user) private function hitRoutes(array $routes, User $user)
{ {
$this->actingAs($user); $this->actingAs($user);
// dd($user);
foreach ($routes as $route => $response) { foreach ($routes as $route => $response) {
// $this->log($route);
// if (strpos($route, 'edit') || strpos($route, 'show') || strpos($route, 'destroy')) {
// // ($this->get(route($route,2))->dump());
// $this->get(route($route, 1))
// ->assertResponseStatus($response);
// } else {
// dd($this->get(route($route))); // dd($this->get(route($route)));
// echo($this->get(route($route))->dump()); // echo($this->get(route($route))->dump());
$this->get($route) $this->get($route)
->assertResponseStatus($response); ->assertResponseStatus($response);
// }
} }
} }
} }