public function getRequestAsset($assetId = null)
 {
     $user = Sentry::getUser();
     // Check if the asset exists and is requestable
     if (is_null($asset = Asset::RequestableAssets()->find($assetId))) {
         // Redirect to the asset management page
         return Redirect::route('requestable-assets')->with('error', Lang::get('admin/hardware/message.does_not_exist_or_not_requestable'));
     } else {
         $logaction = new Actionlog();
         $logaction->asset_id = $asset->id;
         $logaction->asset_type = 'hardware';
         $logaction->created_at = date("Y-m-d h:i:s");
         if ($user->location_id) {
             $logaction->location_id = $user->location_id;
         }
         $logaction->user_id = Sentry::getUser()->id;
         $log = $logaction->logaction('requested');
         $settings = Setting::getSettings();
         if ($settings->slack_endpoint) {
             $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
             $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
             try {
                 $client->attach(['color' => 'good', 'fields' => [['title' => 'REQUESTED:', 'value' => strtoupper($logaction->asset_type) . ' asset <' . Config::get('app.url') . '/hardware/' . $asset->id . '/view' . '|' . $asset->showAssetName() . '> requested by <' . Config::get('app.url') . '/hardware/' . $asset->id . '/view' . '|' . Sentry::getUser()->fullName() . '>.']]])->send('Asset Requested');
             } catch (Exception $e) {
             }
         }
         return Redirect::route('requestable-assets')->with('success')->with('success', Lang::get('admin/hardware/message.requests.success'));
     }
 }
Exemple #2
0
 public function checkOutNotifySlack($settings, $admin, $note = null)
 {
     if ($settings->slack_endpoint) {
         $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
         $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
         try {
             $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked Out:', 'value' => 'HARDWARE asset <' . Config::get('app.url') . '/hardware/' . $this->id . '/view' . '|' . $this->showAssetName() . '> checked out to <' . Config::get('app.url') . '/admin/users/' . $this->assigned_to . '/view|' . $this->assigneduser->fullName() . '> by <' . Config::get('app.url') . '/hardware/' . $this->id . '/view' . '|' . $admin->fullName() . '>.'], ['title' => 'Note:', 'value' => e($note)]]])->send('Asset Checked Out');
         } catch (Exception $e) {
             print_r($e);
         }
     }
 }
Exemple #3
0
 /**
  * Send notification
  *
  * @param   array  $data
  * @return  bool
  */
 protected function send($channel, $data)
 {
     if (!$channel || empty($data)) {
         return false;
     }
     // @TODO  Move to Composer so other extensions can use it
     include_once __DIR__ . DS . 'lib' . DS . 'Client.php';
     include_once __DIR__ . DS . 'lib' . DS . 'Message.php';
     include_once __DIR__ . DS . 'lib' . DS . 'Attachment.php';
     include_once __DIR__ . DS . 'lib' . DS . 'AttachmentField.php';
     // Set up the client
     $client = new Maknz\Slack\Client($this->params->get('endpoint'), array('username' => $this->params->get('username'), 'channel' => '#' . trim($channel, '#'), 'link_names' => $this->params->get('link_names', 1) ? true : false, 'allow_markdown' => $this->params->get('allow_markdown', 1) ? true : false));
     try {
         $client->attach($data)->send();
     } catch (Exception $e) {
         // Fail silently
         return false;
     }
     return true;
 }
 public function getRequestAsset($assetId = null)
 {
     $user = Sentry::getUser();
     // Check if the asset exists and is requestable
     if (is_null($asset = Asset::RequestableAssets()->find($assetId))) {
         // Redirect to the asset management page
         return Redirect::route('requestable-assets')->with('error', Lang::get('admin/hardware/message.does_not_exist_or_not_requestable'));
     } else {
         if (!Company::isCurrentUserHasAccess($asset)) {
             return Redirect::route('requestable-assets')->with('error', Lang::get('general.insufficient_permissions'));
         } else {
             $logaction = new Actionlog();
             $logaction->asset_id = $data['asset_id'] = $asset->id;
             $logaction->asset_type = $data['asset_type'] = 'hardware';
             $logaction->created_at = $data['requested_date'] = date("Y-m-d h:i:s");
             if ($user->location_id) {
                 $logaction->location_id = $user->location_id;
             }
             $logaction->user_id = $data['user_id'] = Sentry::getUser()->id;
             $log = $logaction->logaction('requested');
             $data['requested_by'] = $user->fullName();
             $data['asset_name'] = $asset->showAssetName();
             $settings = Setting::getSettings();
             if ($settings->alert_email != '' && $settings->alerts_enabled == '1' && !Config::get('app.lock_passwords')) {
                 Mail::send('emails.asset-requested', $data, function ($m) use($user, $settings) {
                     $m->to($settings->alert_email, $settings->site_name);
                     $m->subject('Asset Requested');
                 });
             }
             if ($settings->slack_endpoint) {
                 $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
                 $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
                 try {
                     $client->attach(['color' => 'good', 'fields' => [['title' => 'REQUESTED:', 'value' => strtoupper($logaction->asset_type) . ' asset <' . Config::get('app.url') . '/hardware/' . $asset->id . '/view' . '|' . $asset->showAssetName() . '> requested by <' . Config::get('app.url') . '/hardware/' . $asset->id . '/view' . '|' . Sentry::getUser()->fullName() . '>.']]])->send('Asset Requested');
                 } catch (Exception $e) {
                 }
             }
             return Redirect::route('requestable-assets')->with('success')->with('success', Lang::get('admin/hardware/message.requests.success'));
         }
     }
 }
Exemple #5
0
 protected static function notify($status, $title, $message)
 {
     // We don't need the second notification about the suite failing
     if (strpos($title, 'suite ended') !== false) {
         return;
     }
     // If there's a prefix, prepend it to the title of the message
     if (self::$prefix !== null) {
         $title = '[' . self::$prefix . '] ' . $title;
     }
     // Fire up the Slack Client with the given webhook url and settings
     $client = new \Maknz\Slack\Client(self::$url, self::$settings);
     // Split the message on > as the behat step failures give the regex then the message
     // We just want the piece after the final '>'. @TODO: Better option here? As this will
     // fail horribly if there is a '>' character in the Exception
     $splitMessage = explode('>', $message);
     // Build the attachment
     self::$attachment['pretext'] = $title;
     self::$attachment['fields'] = array(array('title' => 'Step', 'value' => end($splitMessage), 'short' => false));
     // Send!
     $client->attach(self::$attachment)->enableMarkdown()->send();
 }
 /**
  * Check in the item so that it can be checked out again to someone else
  **/
 public function postCheckin($seatId = null, $backto = null)
 {
     // Check if the asset exists
     if (is_null($licenseseat = LicenseSeat::find($seatId))) {
         // Redirect to the asset management page with error
         return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.not_found'));
     }
     $license = License::find($licenseseat->license_id);
     if (!$license->reassignable) {
         // Not allowed to checkin
         Session::flash('error', 'License not reassignable.');
         return Redirect::back()->withInput();
     }
     // Declare the rules for the form validation
     $rules = array('note' => 'alpha_space', 'notes' => 'alpha_space');
     // 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);
     }
     $return_to = $licenseseat->assigned_to;
     $logaction = new Actionlog();
     $logaction->checkedout_to = $licenseseat->assigned_to;
     // Update the asset data
     $licenseseat->assigned_to = NULL;
     $licenseseat->asset_id = NULL;
     $user = Sentry::getUser();
     // Was the asset updated?
     if ($licenseseat->save()) {
         $logaction->asset_id = $licenseseat->license_id;
         $logaction->location_id = NULL;
         $logaction->asset_type = 'software';
         $logaction->note = e(Input::get('note'));
         $logaction->user_id = $user->id;
         $settings = Setting::getSettings();
         if ($settings->slack_endpoint) {
             $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
             $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
             try {
                 $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked In:', 'value' => strtoupper($logaction->asset_type) . ' <' . Config::get('app.url') . '/admin/licenses/' . $license->id . '/view' . '|' . $license->name . '> checked in by <' . Config::get('app.url') . '/admin/users/' . $user->id . '/view' . '|' . $user->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('License Checked In');
             } catch (Exception $e) {
             }
         }
         $log = $logaction->logaction('checkin from');
         if ($backto == 'user') {
             return Redirect::to("admin/users/" . $return_to . '/view')->with('success', Lang::get('admin/licenses/message.checkin.success'));
         } else {
             return Redirect::to("admin/licenses/" . $licenseseat->license_id . "/view")->with('success', Lang::get('admin/licenses/message.checkin.success'));
         }
     }
     // Redirect to the license page with error
     return Redirect::to("admin/licenses")->with('error', Lang::get('admin/licenses/message.checkin.error'));
 }
Exemple #7
0
 /**
  * Run the Slack plugin.
  * @return bool
  */
 public function execute()
 {
     $message = $this->phpci->interpolate($this->message);
     $successfulBuild = $this->build->isSuccessful();
     if ($successfulBuild) {
         $status = 'Success';
         $color = 'good';
     } else {
         $status = 'Failed';
         $color = 'danger';
     }
     // Build up the attachment data
     $attachment = new \Maknz\Slack\Attachment(array('fallback' => $message, 'pretext' => $message, 'color' => $color, 'fields' => array(new \Maknz\Slack\AttachmentField(array('title' => 'Status', 'value' => $status, 'short' => false)))));
     $client = new \Maknz\Slack\Client($this->webHook);
     if (!empty($this->room)) {
         $client->setChannel($this->room);
     }
     if (!empty($this->username)) {
         $client->setUsername($this->username);
     }
     if (!empty($this->icon)) {
         $client->setIcon($this->icon);
     }
     $client->attach($attachment);
     $success = true;
     $client->send('');
     // FIXME: Handle errors
     return $success;
 }
 /**
  * Check in the item so that it can be checked out again to someone else
  *
  * @param  int  $accessoryId
  * @return View
  **/
 public function postCheckin($accessoryUserId = null, $backto = null)
 {
     // Check if the accessory exists
     if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
         // Redirect to the accessory management page with error
         return Redirect::to('admin/accessories')->with('error', Lang::get('admin/accessories/message.not_found'));
     }
     $accessory = Accessory::find($accessory_user->accessory_id);
     if (!Company::isCurrentUserHasAccess($accessory)) {
         return Redirect::to('admin/accessories')->with('error', Lang::get('general.insufficient_permissions'));
     }
     $logaction = new Actionlog();
     $logaction->checkedout_to = $accessory_user->assigned_to;
     $return_to = $accessory_user->assigned_to;
     $admin_user = Sentry::getUser();
     // Was the accessory updated?
     if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {
         $logaction->accessory_id = $accessory->id;
         $logaction->location_id = NULL;
         $logaction->asset_type = 'accessory';
         $logaction->user_id = $admin_user->id;
         $logaction->note = e(Input::get('note'));
         $settings = Setting::getSettings();
         if ($settings->slack_endpoint) {
             $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
             $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
             try {
                 $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked In:', 'value' => strtoupper($logaction->asset_type) . ' <' . Config::get('app.url') . '/admin/accessories/' . $accessory->id . '/view' . '|' . $accessory->name . '> checked in by <' . Config::get('app.url') . '/admin/users/' . $admin_user->id . '/view' . '|' . $admin_user->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Accessory Checked In');
             } catch (Exception $e) {
             }
         }
         $log = $logaction->logaction('checkin from');
         if (!is_null($accessory_user->assigned_to)) {
             $user = User::find($accessory_user->assigned_to);
         }
         $data['log_id'] = $logaction->id;
         $data['first_name'] = $user->first_name;
         $data['item_name'] = $accessory->name;
         $data['checkin_date'] = $logaction->created_at;
         $data['item_tag'] = '';
         $data['note'] = $logaction->note;
         if ($accessory->checkin_email() == '1') {
             Mail::send('emails.checkin-asset', $data, function ($m) use($user) {
                 $m->to($user->email, $user->first_name . ' ' . $user->last_name);
                 $m->subject('Confirm Accessory Checkin');
             });
         }
         if ($backto == 'user') {
             return Redirect::to("admin/users/" . $return_to . '/view')->with('success', Lang::get('admin/accessories/message.checkin.success'));
         } else {
             return Redirect::to("admin/accessories/" . $accessory->id . "/view")->with('success', Lang::get('admin/accessories/message.checkin.success'));
         }
     }
     // Redirect to the accessory management page with error
     return Redirect::to("admin/accessories")->with('error', Lang::get('admin/accessories/message.checkin.error'));
 }
 /**
  * Check in the item so that it can be checked out again to someone else
  *
  * @param  int  $assetId
  * @return View
  **/
 public function postCheckin($assetId = null, $backto = null)
 {
     // Check if the asset exists
     if (is_null($asset = Asset::find($assetId))) {
         // Redirect to the asset management page with error
         return Redirect::to('hardware')->with('error', Lang::get('admin/hardware/message.not_found'));
     }
     if (!is_null($asset->assigned_to)) {
         $user = User::find($asset->assigned_to);
     }
     // This is just used for the redirect
     $return_to = $asset->assigned_to;
     $logaction = new Actionlog();
     $logaction->checkedout_to = $asset->assigned_to;
     // Update the asset data to null, since it's being checked in
     $asset->assigned_to = NULL;
     // Was the asset updated?
     if ($asset->save()) {
         if (Input::has('checkin_at')) {
             if (!strtotime(Input::get('checkin_at'))) {
                 $logaction->created_at = date("Y-m-d h:i:s");
             } elseif (Input::get('checkin_at') != date("Y-m-d")) {
                 $logaction->created_at = e(Input::get('checkin_at')) . ' 00:00:00';
             }
         }
         $logaction->asset_id = $asset->id;
         $logaction->location_id = NULL;
         $logaction->asset_type = 'hardware';
         $logaction->note = e(Input::get('note'));
         $logaction->user_id = Sentry::getUser()->id;
         $log = $logaction->logaction('checkin from');
         $settings = Setting::getSettings();
         if ($settings->slack_endpoint) {
             $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
             $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
             try {
                 $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked In:', 'value' => strtoupper($logaction->asset_type) . ' asset <' . Config::get('app.url') . '/hardware/' . $asset->id . '/view' . '|' . $asset->showAssetName() . '> checked in by <' . Config::get('app.url') . '/hardware/' . $asset->id . '/view' . '|' . Sentry::getUser()->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Asset Checked In');
             } catch (Exception $e) {
             }
         }
         if ($backto == 'user') {
             return Redirect::to("admin/users/" . $return_to . '/view')->with('success', Lang::get('admin/hardware/message.checkin.success'));
         } else {
             return Redirect::to("hardware")->with('success', Lang::get('admin/hardware/message.checkin.success'));
         }
     }
     // Redirect to the asset management page with error
     return Redirect::to("hardware")->with('error', Lang::get('admin/hardware/message.checkin.error'));
 }
Exemple #10
0
 /**
  * Validate and process the form data to check an asset back into inventory.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @param int $assetId
  * @since [v1.0]
  * @return Redirect
  */
 public function postCheckin(AssetCheckinRequest $request, $assetId = null, $backto = null)
 {
     // Check if the asset exists
     if (is_null($asset = Asset::find($assetId))) {
         // Redirect to the asset management page with error
         return redirect()->to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
     } elseif (!Company::isCurrentUserHasAccess($asset)) {
         return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions'));
     }
     $admin = Auth::user();
     if (!is_null($asset->assigned_to)) {
         $user = User::find($asset->assigned_to);
     } else {
         return redirect()->to('hardware')->with('error', trans('admin/hardware/message.checkin.already_checked_in'));
     }
     // This is just used for the redirect
     $return_to = $asset->assigned_to;
     $asset->expected_checkin = null;
     $asset->last_checkout = null;
     $asset->assigned_to = null;
     $asset->accepted = null;
     $asset->name = e(Input::get('name'));
     if (Input::has('status_id')) {
         $asset->status_id = e(Input::get('status_id'));
     }
     // Was the asset updated?
     if ($asset->save()) {
         if ($request->input('checkin_at') == Carbon::now()->format('Y-m-d')) {
             $checkin_at = Carbon::now();
         } else {
             $checkin_at = $request->input('checkin_at') . ' 00:00:00';
         }
         //$checkin_at = e(Input::get('checkin_at'));
         $logaction = $asset->createLogRecord('checkin', $asset, $admin, $user, null, e(Input::get('note')), $checkin_at);
         $settings = Setting::getSettings();
         if ($settings->slack_endpoint) {
             $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
             $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
             try {
                 $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked In:', 'value' => strtoupper($logaction->asset_type) . ' asset <' . config('app.url') . '/hardware/' . $asset->id . '/view' . '|' . e($asset->showAssetName()) . '> checked in by <' . config('app.url') . '/admin/users/' . Auth::user()->id . '/view' . '|' . e(Auth::user()->fullName()) . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Asset Checked In');
             } catch (Exception $e) {
             }
         }
         $data['log_id'] = $logaction->id;
         $data['first_name'] = $user->first_name;
         $data['item_name'] = $asset->showAssetName();
         $data['checkin_date'] = $logaction->created_at;
         $data['item_tag'] = $asset->asset_tag;
         $data['item_serial'] = $asset->serial;
         $data['note'] = $logaction->note;
         if ($asset->checkin_email() == '1' && $user && !config('app.lock_passwords')) {
             Mail::send('emails.checkin-asset', $data, function ($m) use($user) {
                 $m->to($user->email, $user->first_name . ' ' . $user->last_name);
                 $m->subject('Confirm Asset Checkin');
             });
         }
         if ($backto == 'user') {
             return redirect()->to("admin/users/" . $return_to . '/view')->with('success', trans('admin/hardware/message.checkin.success'));
         } else {
             return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkin.success'));
         }
     }
     // Redirect to the asset management page with error
     return redirect()->to("hardware")->with('error', trans('admin/hardware/message.checkin.error'));
 }
 /**
  * Saves the checkout information
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see ConsumablesController::getCheckout() method that returns the form.
  * @since [v1.0]
  * @param int $consumableId
  * @return Redirect
  */
 public function postCheckout($consumableId)
 {
     // Check if the consumable exists
     if (is_null($consumable = Consumable::find($consumableId))) {
         // Redirect to the consumable management page with error
         return redirect()->to('consumables')->with('error', trans('admin/consumables/message.not_found'));
     } elseif (!Company::isCurrentUserHasAccess($consumable)) {
         return redirect()->to('admin/consumables')->with('error', trans('general.insufficient_permissions'));
     }
     $admin_user = Auth::user();
     $assigned_to = e(Input::get('assigned_to'));
     // Check if the user exists
     if (is_null($user = User::find($assigned_to))) {
         // Redirect to the consumable management page with error
         return redirect()->to('admin/consumables')->with('error', trans('admin/consumables/message.user_does_not_exist'));
     }
     // Update the consumable data
     $consumable->assigned_to = e(Input::get('assigned_to'));
     $consumable->users()->attach($consumable->id, array('consumable_id' => $consumable->id, 'user_id' => $admin_user->id, 'assigned_to' => e(Input::get('assigned_to'))));
     $logaction = new Actionlog();
     $logaction->consumable_id = $consumable->id;
     $logaction->checkedout_to = $consumable->assigned_to;
     $logaction->asset_type = 'consumable';
     $logaction->asset_id = 0;
     $logaction->location_id = $user->location_id;
     $logaction->user_id = Auth::user()->id;
     $logaction->note = e(Input::get('note'));
     $settings = Setting::getSettings();
     if ($settings->slack_endpoint) {
         $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
         $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
         try {
             $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked Out:', 'value' => strtoupper($logaction->asset_type) . ' <' . config('app.url') . '/admin/consumables/' . $consumable->id . '/view' . '|' . $consumable->name . '> checked out to <' . config('app.url') . '/admin/users/' . $user->id . '/view|' . $user->fullName() . '> by <' . config('app.url') . '/admin/users/' . $admin_user->id . '/view' . '|' . $admin_user->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Consumable Checked Out');
         } catch (Exception $e) {
         }
     }
     $log = $logaction->logaction('checkout');
     $consumable_user = DB::table('consumables_users')->where('assigned_to', '=', $consumable->assigned_to)->where('consumable_id', '=', $consumable->id)->first();
     $data['log_id'] = $logaction->id;
     $data['eula'] = $consumable->getEula();
     $data['first_name'] = $user->first_name;
     $data['item_name'] = $consumable->name;
     $data['checkout_date'] = $logaction->created_at;
     $data['note'] = $logaction->note;
     $data['require_acceptance'] = $consumable->requireAcceptance();
     if ($consumable->requireAcceptance() == '1' || $consumable->getEula()) {
         Mail::send('emails.accept-asset', $data, function ($m) use($user) {
             $m->to($user->email, $user->first_name . ' ' . $user->last_name);
             $m->subject('Confirm consumable delivery');
         });
     }
     // Redirect to the new consumable page
     return redirect()->to("admin/consumables")->with('success', trans('admin/consumables/message.checkout.success'));
 }
Exemple #12
0
 /**
  * Check in the item so that it can be checked out again to someone else
  *
  * @param  int  $assetId
  * @return View
  **/
 public function postCheckin($assetId = null, $backto = null)
 {
     // Check if the asset exists
     if (is_null($asset = Asset::find($assetId))) {
         // Redirect to the asset management page with error
         return Redirect::to('hardware')->with('error', Lang::get('admin/hardware/message.does_not_exist'));
     } else {
         if (!Company::isCurrentUserHasAccess($asset)) {
             return Redirect::to('hardware')->with('error', Lang::get('general.insufficient_permissions'));
         }
     }
     // Check for a valid user to checkout fa-random
     // This will need to be tweaked for checkout to location
     if (!is_null($asset->assigned_to)) {
         $user = User::find($asset->assigned_to);
     } else {
         return Redirect::to('hardware')->with('error', Lang::get('admin/hardware/message.already_checked_in'));
     }
     // This is just used for the redirect
     $return_to = $asset->assigned_to;
     $logaction = new Actionlog();
     $logaction->checkedout_to = $asset->assigned_to;
     // Update the asset data to null, since it's being checked in
     $asset->assigned_to = NULL;
     $asset->accepted = NULL;
     // Was the asset updated?
     if ($asset->save()) {
         if (Input::has('checkin_at')) {
             if (!strtotime(Input::get('checkin_at'))) {
                 $logaction->created_at = date("Y-m-d H:i:s");
             } elseif (Input::get('checkin_at') != date("Y-m-d")) {
                 $logaction->created_at = e(Input::get('checkin_at')) . ' 00:00:00';
             }
         }
         $logaction->asset_id = $asset->id;
         $logaction->location_id = NULL;
         $logaction->asset_type = 'hardware';
         $logaction->note = e(Input::get('note'));
         $logaction->user_id = Sentry::getUser()->id;
         $log = $logaction->logaction('checkin from');
         $settings = Setting::getSettings();
         if ($settings->slack_endpoint) {
             $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
             $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
             try {
                 $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked In:', 'value' => strtoupper($logaction->asset_type) . ' asset <' . Config::get('app.url') . '/hardware/' . $asset->id . '/view' . '|' . $asset->showAssetName() . '> checked in by <' . Config::get('app.url') . '/hardware/' . $asset->id . '/view' . '|' . Sentry::getUser()->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Asset Checked In');
             } catch (Exception $e) {
             }
         }
         $data['log_id'] = $logaction->id;
         $data['first_name'] = $user->first_name;
         $data['item_name'] = $asset->showAssetName();
         $data['checkin_date'] = $logaction->created_at;
         $data['item_tag'] = $asset->asset_tag;
         $data['note'] = $logaction->note;
         if ($asset->checkin_email() == '1' && $user && !Config::get('app.lock_passwords')) {
             Mail::send('emails.checkin-asset', $data, function ($m) use($user) {
                 $m->to($user->email, $user->first_name . ' ' . $user->last_name);
                 $m->subject('Confirm Asset Checkin');
             });
         }
         if ($backto == 'user') {
             return Redirect::to("admin/users/" . $return_to . '/view')->with('success', Lang::get('admin/hardware/message.checkin.success'));
         } else {
             return Redirect::to("hardware")->with('success', Lang::get('admin/hardware/message.checkin.success'));
         }
     }
     // Redirect to the asset management page with error
     return Redirect::to("hardware")->with('error', Lang::get('admin/hardware/message.checkin.error'));
 }
 /**
  * Validate and store checkout data.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see ComponentsController::getCheckout() method that returns the form.
  * @since [v3.0]
  * @param int $componentId
  * @return Redirect
  */
 public function postCheckout(Request $request, $componentId)
 {
     // Check if the component exists
     if (is_null($component = Component::find($componentId))) {
         // Redirect to the component management page with error
         return redirect()->to('components')->with('error', trans('admin/components/message.not_found'));
     } elseif (!Company::isCurrentUserHasAccess($component)) {
         return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions'));
     }
     $max_to_checkout = $component->numRemaining();
     $validator = Validator::make($request->all(), ["asset_id" => "required", "assigned_qty" => "required|numeric|between:1,{$max_to_checkout}"]);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     $admin_user = Auth::user();
     $asset_id = e(Input::get('asset_id'));
     // Check if the user exists
     if (is_null($asset = Asset::find($asset_id))) {
         // Redirect to the component management page with error
         return redirect()->to('admin/components')->with('error', trans('admin/components/message.asset_does_not_exist'));
     }
     // Update the component data
     $component->asset_id = $asset_id;
     $component->assets()->attach($component->id, array('component_id' => $component->id, 'user_id' => $admin_user->id, 'created_at' => date('Y-m-d h:i:s'), 'assigned_qty' => e(Input::get('assigned_qty')), 'asset_id' => $asset_id));
     $logaction = new Actionlog();
     $logaction->component_id = $component->id;
     $logaction->asset_id = $asset_id;
     $logaction->asset_type = 'component';
     $logaction->location_id = $asset->location_id;
     $logaction->user_id = Auth::user()->id;
     $logaction->note = e(Input::get('note'));
     $settings = Setting::getSettings();
     if ($settings->slack_endpoint) {
         $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
         $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
         try {
             $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked Out:', 'value' => strtoupper($logaction->asset_type) . ' <' . config('app.url') . '/admin/components/' . $component->id . '/view' . '|' . $component->name . '> checked out to <' . config('app.url') . '/hardware/' . $asset->id . '/view|' . $asset->showAssetName() . '> by <' . config('app.url') . '/admin/users/' . $admin_user->id . '/view' . '|' . $admin_user->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Component Checked Out');
         } catch (Exception $e) {
         }
     }
     $log = $logaction->logaction('checkout');
     // Redirect to the new component page
     return redirect()->to("admin/components")->with('success', trans('admin/components/message.checkout.success'));
 }
 /**
  * Check out the consumable to a person
  **/
 public function postCheckout($consumableId)
 {
     // Check if the consumable exists
     if (is_null($consumable = Consumable::find($consumableId))) {
         // Redirect to the consumable management page with error
         return Redirect::to('consumables')->with('error', Lang::get('admin/consumables/message.not_found'));
     }
     $admin_user = Sentry::getUser();
     $assigned_to = e(Input::get('assigned_to'));
     // Declare the rules for the form validation
     $rules = array('assigned_to' => 'required|min:1');
     // 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);
     }
     // Check if the user exists
     if (is_null($user = User::find($assigned_to))) {
         // Redirect to the consumable management page with error
         return Redirect::to('admin/consumables')->with('error', Lang::get('admin/consumables/message.user_does_not_exist'));
     }
     // Update the consumable data
     $consumable->assigned_to = e(Input::get('assigned_to'));
     $consumable->users()->attach($consumable->id, array('consumable_id' => $consumable->id, 'assigned_to' => e(Input::get('assigned_to'))));
     $logaction = new Actionlog();
     $logaction->consumable_id = $consumable->id;
     $logaction->checkedout_to = $consumable->assigned_to;
     $logaction->asset_type = 'consumable';
     $logaction->location_id = $user->location_id;
     $logaction->user_id = Sentry::getUser()->id;
     $logaction->note = e(Input::get('note'));
     $settings = Setting::getSettings();
     if ($settings->slack_endpoint) {
         $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
         $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
         try {
             $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked Out:', 'value' => strtoupper($logaction->asset_type) . ' <' . Config::get('app.url') . '/admin/consumables/' . $consumable->id . '/view' . '|' . $consumable->name . '> checked out to <' . Config::get('app.url') . '/admin/users/' . $user->id . '/view|' . $user->fullName() . '> by <' . Config::get('app.url') . '/admin/users/' . $admin_user->id . '/view' . '|' . $admin_user->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Consumable Checked Out');
         } catch (Exception $e) {
         }
     }
     $log = $logaction->logaction('checkout');
     $consumable_user = DB::table('consumables_users')->where('assigned_to', '=', $consumable->assigned_to)->where('consumable_id', '=', $consumable->id)->first();
     $data['log_id'] = $logaction->id;
     $data['eula'] = $consumable->getEula();
     $data['first_name'] = $user->first_name;
     $data['item_name'] = $consumable->name;
     $data['checkout_date'] = $logaction->created_at;
     $data['item_tag'] = '';
     $data['expected_checkin'] = '';
     $data['note'] = $logaction->note;
     $data['require_acceptance'] = $consumable->requireAcceptance();
     if ($consumable->requireAcceptance() == '1' || $consumable->getEula()) {
         Mail::send('emails.accept-asset', $data, function ($m) use($user) {
             $m->to($user->email, $user->first_name . ' ' . $user->last_name);
             $m->subject('Confirm consumable delivery');
         });
     }
     // Redirect to the new consumable page
     return Redirect::to("admin/consumables")->with('success', Lang::get('admin/consumables/message.checkout.success'));
 }
 /**
  * Check in the item so that it can be checked out again to someone else
  *
  * @param  int  $accessoryId
  * @return View
  **/
 public function postCheckin($accessoryUserId = null, $backto = null)
 {
     // Check if the accessory exists
     if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
         // Redirect to the accessory management page with error
         return Redirect::to('admin/accessories')->with('error', Lang::get('admin/accessories/message.not_found'));
     }
     $accessory = Accessory::find($accessory_user->accessory_id);
     $logaction = new Actionlog();
     $logaction->checkedout_to = $accessory_user->assigned_to;
     $return_to = $accessory_user->assigned_to;
     $admin_user = Sentry::getUser();
     // Was the accessory updated?
     if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {
         $logaction->accessory_id = $accessory->id;
         $logaction->location_id = NULL;
         $logaction->asset_type = 'accessory';
         $logaction->user_id = $admin_user->id;
         $logaction->note = e(Input::get('note'));
         $settings = Setting::getSettings();
         if ($settings->slack_endpoint) {
             $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
             $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
             try {
                 $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked In:', 'value' => strtoupper($logaction->asset_type) . ' <' . Config::get('app.url') . '/admin/accessories/' . $accessory->id . '/view' . '|' . $accessory->name . '> checked in by <' . Config::get('app.url') . '/admin/users/' . $admin_user->id . '/view' . '|' . $admin_user->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Accessory Checked In');
             } catch (Exception $e) {
             }
         }
         $log = $logaction->logaction('checkin from');
         if ($backto == 'user') {
             return Redirect::to("admin/users/" . $return_to . '/view')->with('success', Lang::get('admin/accessories/message.checkin.success'));
         } else {
             return Redirect::to("admin/accessories/" . $accessory->id . "/view")->with('success', Lang::get('admin/accessories/message.checkin.success'));
         }
     }
     // Redirect to the accessory management page with error
     return Redirect::to("admin/accessories")->with('error', Lang::get('admin/accessories/message.checkin.error'));
 }