/** * Sends a notification via Slack * @param string $message */ public function sendNotification($message) { // Only send a notification if we are running in production mode if (Director::isLive()) { $config = SiteConfig::current_site_config(); $message = $config->Title . ' (' . Director::absoluteBaseURL() . ') - ' . $message; $this->client->send($message); } }
public function sendAcknowledge(Incident $incident) { $client = new \Maknz\Slack\Client($this->webhookURL, $this->settings); $gotoUrl = "<" . $this->router->generate("bauer_incident_dashboard_core_homepage", array('project' => $incident->getEventIdentifier()->getProject()->getIdentifier()), true) . "|Go to Koalamon>"; $label = "The current incident for System " . $incident->getEventIdentifier()->getSystem()->getName() . ' (Tool: ' . $incident->getEventIdentifier()->getTool()->getName() . ")" . ' was acknowledged by ' . $incident->getAcknowledgedBy()->getUsername() . '.'; $client->enableMarkdown()->attach(['text' => $gotoUrl, 'color' => self::COLOR_ACK])->send($label); }
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')); } }
/** * Run the Slack plugin. * @return bool */ public function execute() { $body = $this->phpci->interpolate($this->message); $client = new \Maknz\Slack\Client($this->webHook); $message = $client->createMessage(); if (!empty($this->room)) { $message->setChannel($this->room); } if (!empty($this->username)) { $message->setUsername($this->username); } if (!empty($this->icon)) { $message->setIcon($this->icon); } // Include an attachment which shows the status and hide the message if ($this->show_status) { $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' => $body, 'pretext' => $body, 'color' => $color, 'fields' => array(new \Maknz\Slack\AttachmentField(array('title' => 'Status', 'value' => $status, 'short' => false))))); $message->attach($attachment); $body = ''; } $message->send($body); return true; }
/** * 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; }
/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->call(function () { $users = User::all(); foreach ($users as $user) { $user->update(['available_points' => 40]); } $settings = ['username' => 'BenisBot', 'channel' => '#tempel_der_weisheit', 'link_names' => true, 'icon_emoji' => ':squirrel:']; $client = new \Maknz\Slack\Client('https://hooks.slack.com/services/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', $settings); $client->send('Mitternacht! Alle haben nun wieder 40 Benispunkte zu verteilen!'); })->daily(); }
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); } } }
public function slack() { // Instantiate with defaults, so all messages created // will be sent from 'Cyril' and to the #accounting channel // by default. Any names like @regan or #channel will also be linked. $settings = ['username' => env('SLACK_USERNAME'), 'channel' => env('SLACK_CHANNEL'), 'link_names' => true]; $client = new \Maknz\Slack\Client(env('SLACK_WEBHOOKS'), $settings); $client->send('Test Message!'); $client->to(array_get($settings, 'channel'))->send('Are we rich yet?'); $client->from('lubri')->to(array_get($settings, 'channel'))->send('Adventure time!'); return ''; }
public function fire() { // get last update $latestLog = DB::table('steam_log')->orderBy('updated', 'DESC')->first(); if (count($latestLog) == 0) { // create new record for player DB::table('steam_log')->insert(['steam_id' => env('STEAM_ID'), 'in_game' => 0, 'updated' => time()]); $currentStatus = 0; } else { $currentStatus = $latestLog->in_game; } $client = new \GuzzleHttp\Client(); $request = $client->createRequest('GET', 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . env('STEAM_KEY') . '&steamids=' . env('STEAM_ID')); $response = $client->send($request); $responseData = json_decode($response->getBody()->getContents()); $player = $responseData->response->players[0]; //dd(isset($player->gameid)); if (isset($player->gameid)) { // in game $status = 1; $game_id = $player->gameid; $game_name = $player->gameextrainfo; } else { // out of game $status = 0; $game_id = null; $game_name = null; } // save latest status DB::table('steam_log')->where('steam_id', env('STEAM_ID'))->update(['in_game' => $status, 'game_id' => $game_id, 'game_name' => $game_name, 'updated' => time()]); // check to see if notification needs to be sent if ($currentStatus != $status) { if ($status == 1) { $pushMessage = 'In Game: ' . $game_name; } else { $pushMessage = 'No longer playing game'; } if (env('STEAM_NOTIFY_METHOD') == 'pushover') { // send to Pushover curl_setopt_array($ch = curl_init(), array(CURLOPT_URL => "https://api.pushover.net/1/messages.json", CURLOPT_POSTFIELDS => array("token" => env('PUSHOVER_API_KEY'), "user" => env('PUSHOVER_USER_KEY'), "message" => $pushMessage), CURLOPT_SAFE_UPLOAD => true)); curl_exec($ch); curl_close($ch); } else { // send to Slack $settings = ['username' => env('STEAM_SLACK_USERNAME'), 'channel' => '#' . env('STEAM_SLACK_CHANNEL'), 'link_names' => true, 'icon' => ':ghost:']; // send to slack $client = new \Maknz\Slack\Client(env('STEAM_SLACK_WEBHOOK'), $settings); $client->send($pushMessage); } } $this->info('Complete'); }
private function send($post, $context, $userName) { $slackUrl = Configure::read('Slack.Url'); if ($slackUrl) { $postLink = '<' . Configure::read('Email.UrlRoot') . '/posts/view/' . $post['Post']['id'] . '|' . $post['Post']['title'] . '>'; $roomLink = '<' . Configure::read('Email.UrlRoot') . '/rooms/view/' . $post['Room']['id'] . '|' . $post['Room']['name'] . '>'; $slackMessage = "{$userName} {$context} {$postLink} in the room {$roomLink}"; $channel = strpos($post['Room']['slack_channel'], '#') === false ? Configure::read('Slack.DefaultChannel') : trim($post['Room']['slack_channel']); $settings = ['username' => 'Truckr', 'channel' => $channel, 'link_names' => true]; $client = new Maknz\Slack\Client(Configure::read('Slack.Url'), $settings); $message = $client->createMessage(); $message->send($slackMessage); } }
public function handle(Request $request) { $command = new BenisBotCommand($request->channel_id, $request->user_name, $request->text); $channel = "#{$request->channel_name}"; if (!($channel == "#privategroup")) { $handler = new BenisBotCommandHandler(); $response = "@{$request->user_name}: /BenisBot {$request->text}\n"; $response .= $handler->handle($command); $settings = ['username' => 'BenisBot', 'channel' => $channel, 'link_names' => true, 'icon_emoji' => ':squirrel:']; $client = new \Maknz\Slack\Client('https://hooks.slack.com/services/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', $settings); try { Log::info('OK'); $client->send($response); } catch (ServerException $e) { Log::info($e->getResponse()->getBody()); } } }
/** * Sends a message to slack created by information given in the event. * * @param Event $event */ public function send(Event $event) { $client = new \Maknz\Slack\Client($this->webhookURL, $this->settings); $gotoUrl = "<" . $this->router->generate("bauer_incident_dashboard_core_homepage", array('project' => $event->getEventIdentifier()->getProject()->getIdentifier()), true) . "|Go to www.koalamon.com>"; if ($event->hasUrl()) { $gotoUrl .= "\n<" . $event->getUrl() . "|Go to " . $event->getEventIdentifier()->getTool()->getName() . ">"; } if ($event->getStatus() == Event::STATUS_SUCCESS) { $color = self::COLOR_SUCCESS; $label = "Your test succeeded (" . $event->getSystem() . ")\nIdentifier: " . $event->getEventIdentifier()->getIdentifier() . ")"; $message = ""; } else { $color = self::COLOR_FAILURE; $label = "Your test failed (" . $event->getSystem() . ") \nIdentifier: " . $event->getEventIdentifier()->getIdentifier() . ""; $message = $this->slackifyText($event->getMessage()) . "\n"; } $client->enableMarkdown()->attach(['text' => $message . $gotoUrl, 'color' => $color])->send($label); }
/** * 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')); } } }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->info('Generating reports ...'); $generators = Generator::where('is_active', 1)->get(); foreach ($generators as $generator) { $activation_hours = explode(',', $generator['activation_hours']); $activation_days = explode(',', $generator['activation_days']); $this->info('Testing ' . $generator['name'] . ' ...'); $is_day = false; $is_hour = false; $actual_time = time() + 3600; // UTC+1 = 3600 secondes $actual_day = date("w", $actual_time); foreach ($activation_days as $day) { if ($day == $actual_day) { $is_day = true; } } if ($is_day) { $this->info('It is today !'); } $actual_hour = date("H", $actual_time); foreach ($activation_hours as $hour) { if ($hour == $actual_hour) { $is_hour = true; } } if ($is_hour) { $this->info('It is hour !'); } if ($is_day == true && $is_hour == true) { $this->info('Publishing to slack ...'); $data = Generator::createReport($generator); $settings = ['username' => 'Slackreport', 'link_names' => true]; $client = new \Maknz\Slack\Client($data['generator']['slack_service']['var2'], $settings); $client->send($data['message']); } } }
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(); }
/** * {@inheritdoc} */ public function send(array $metrics, array $params = array()) { $message = $this->formatter->format($metrics); $this->client->to($params['room'])->from($params['from'])->send($message); }
/** * 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')); }
public function sendMessage($message) { $client = new \Maknz\Slack\Client($this->webhook_url); $client->to($this->channel)->send($message); }
public function actions($action, $param = null, $param2 = null, $param3 = null) { if ($action == "getservices") { return Service::transformMany(Service::where('slug', 'slack')->orWhere('slug', 'ga')->where('user_id', Auth::user()->id)->get()); } if ($action == "getaccounts") { $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first(); $client = new \Google_Client(); $client->setAuthConfigFile(public_path() . '/private/google_oauth.json'); $client->refreshToken($service['var2']); $analytics = new \Google_Service_Analytics($client); $accounts = $analytics->management_accounts->listManagementAccounts(); return $accounts->getItems(); } if ($action == "getproperties") { $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first(); $client = new \Google_Client(); $client->setAuthConfigFile(public_path() . '/private/google_oauth.json'); $client->refreshToken($service['var2']); $analytics = new \Google_Service_Analytics($client); $properties = $analytics->management_webproperties->listManagementWebproperties($param2); return $properties->getItems(); } if ($action == "getprofiles") { $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first(); $client = new \Google_Client(); $client->setAuthConfigFile(public_path() . '/private/google_oauth.json'); $client->refreshToken($service['var2']); $analytics = new \Google_Service_Analytics($client); $profiles = $analytics->management_profiles->listManagementProfiles($param2, $param3); return $profiles->getItems(); } if ($action == "testslack") { $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first(); $client = new \Maknz\Slack\Client($service['var2'], ['username' => 'Cyril', 'channel' => '#' . $param2, 'link_names' => true]); $client->send('Hey, this is a test message from SlackReport !'); return 'success'; } }
/** * 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')); }
/** * 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')); }
/** * 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 $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')); }
/** * 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')); }