diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index 7e11b4b65e..70236b1291 100644 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -4,6 +4,8 @@ use AdminController; use Input; use Lang; use License; +use Asset; +use User; use DB; use Redirect; use Sentry; @@ -192,5 +194,105 @@ class LicensesController extends AdminController { } + /** + * Check out the asset to a person + **/ + public function getCheckout($assetId) + { + // Check if the asset exists + if (is_null($license = License::find($assetId))) + { + // Redirect to the asset management page with error + return Redirect::to('admin/licenses')->with('error', Lang::get('admin/assets/message.not_found')); + } + + // Get the dropdown of users and then pass it to the checkout view + $users_list = array('' => 'Select a User') + DB::table('users')->select(DB::raw('concat (first_name," ",last_name) as full_name, id'))->lists('full_name', 'id'); + + //print_r($users); + return View::make('backend/licenses/checkout', compact('license'))->with('users_list',$users_list); + + } + + + + /** + * Check out the asset to a person + **/ + public function postCheckout($assetId) + { + // Check if the asset exists + if (is_null($license = License::find($assetId))) + { + // Redirect to the asset management page with error + return Redirect::to('admin/licenses')->with('error', Lang::get('admin/assets/message.not_found')); + } + + $user_id = e(Input::get('user_id')); + + // Check if the asset exists + if (is_null($user = User::find($user_id))) + { + // Redirect to the asset management page with error + return Redirect::to('admin/licenses')->with('error', Lang::get('admin/assets/message.user_does_not_exist')); + } + + // Declare the rules for the form validation + $rules = array( + 'user_id' => 'required' + ); + + // Create a new validator instance from our validation rules + $validator = Validator::make(Input::all(), $rules); + + // If validation fails, we'll exit the operation now. + if ($validator->fails()) + { + // Ooops.. something went wrong + return Redirect::back()->withInput()->withErrors($validator); + } + + // Update the asset data + $license->assigned_to = e(Input::get('user_id')); + + + // Was the asset updated? + if($license->save()) + { + // Redirect to the new asset page + return Redirect::to("admin/licenses")->with('success', Lang::get('admin/assets/message.checkout.success')); + } + + // Redirect to the asset management page with error + return Redirect::to("admin/licenses")->with('error', Lang::get('admin/assets/message.checkout.error')); + } + + /** + * Check in the item so that it can be checked out again to someone else + **/ + public function postCheckin($assetId) + { + // Check if the asset exists + if (is_null($license = License::find($assetId))) + { + // Redirect to the asset management page with error + return Redirect::to('admin/licenses')->with('error', Lang::get('admin/assets/message.not_found')); + } + + // Update the asset data + $license->assigned_to = ''; + + // Was the asset updated? + if($license->save()) + { + // Redirect to the new asset page + return Redirect::to("admin/licenses")->with('success', Lang::get('admin/assets/message.checkout.success')); + } + + // Redirect to the asset management page with error + return Redirect::to("admin/licenses")->with('error', Lang::get('admin/assets/message.checkout.error')); + } + + }