public function show_custom_css() { $custom_css = Setting::getSettings()->custom_css; $custom_css = e($custom_css); // Needed for modifying the bootstrap nav :( $custom_css = str_ireplace('script', 'SCRIPTS-NOT-ALLOWED-HERE', $custom_css); $custom_css = str_replace('>', '>', $custom_css); return $custom_css; }
private static function isFullMultipleCompanySupportEnabled() { $settings = Setting::getSettings(); // NOTE: this can happen when seeding the database if (is_null($settings)) { return false; } else { return $settings->full_multiple_companies_support == 1; } }
public function getEula() { $Parsedown = new \Parsedown(); if ($this->category->eula_text) { return $Parsedown->text(e($this->category->eula_text)); } elseif (Setting::getSettings()->default_eula_text && $this->category->use_default_eula == '1') { return $Parsedown->text(e(Setting::getSettings()->default_eula_text)); } else { return null; } }
/** * Returns the raw configuration array * * @return array */ public function getRawConfig() { if ($this->data === null) { if ($this->cache instanceof Cache) { $data = $this->cache->get($this->cacheKey); if ($data === false) { $data = $this->model->getSettings(); $this->cache->set($this->cacheKey, $data); } } else { $data = $this->model->getSettings(); } $this->data = $data; } return $this->data; }
/** * Handle the locale for the user, default to settings otherwise * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string|null $guard * @return mixed */ public function handle($request, Closure $next, $guard = null) { if (Schema::hasTable('settings')) { // User's preference if ($request->user() && $request->user()->locale) { \App::setLocale($request->user()->locale); // App setting preference } elseif (Setting::getSettings() && Setting::getSettings()->locale != '') { \App::setLocale(Setting::getSettings()->locale); // Default app setting } else { \App::setLocale(config('app.locale')); } } \App::setLocale(config('app.locale')); return $next($request); }
/** * Execute the console command. * * @return mixed */ public function handle() { if (Setting::getSettings()->alert_email != '' && Setting::getSettings()->alerts_enabled == 1) { $data['data'] = Helper::checkLowInventory(); $data['count'] = count($data['data']); if (count($data['data']) > 0) { \Mail::send('emails.low-inventory', $data, function ($m) { $m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name); $m->subject('Low Inventory Report'); }); } } else { if (Setting::getSettings()->alert_email == '') { echo "Could not send email. No alert email configured in settings. \n"; } elseif (Setting::getSettings()->alerts_enabled != 1) { echo "Alerts are disabled in the settings. No mail will be sent. \n"; } } }
public function getRequestAsset($assetId = null) { $user = Auth::user(); // 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', trans('admin/hardware/message.does_not_exist_or_not_requestable')); } elseif (!Company::isCurrentUserHasAccess($asset)) { return redirect()->route('requestable-assets')->with('error', trans('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'] = Auth::user()->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('app.lock_passwords')) { Mail::send('emails.asset-requested', $data, function ($m) use($user, $settings) { $m->to(explode(',', $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('app.url') . '/hardware/' . $asset->id . '/view' . '|' . $asset->showAssetName() . '> requested by <' . config('app.url') . '/hardware/' . $asset->id . '/view' . '|' . Auth::user()->fullName() . '>.']]])->send('Asset Requested'); } catch (Exception $e) { } } return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')); } }
/** * Validates and stores the license checkin action. * * @author [A. Gianotto] [<*****@*****.**>] * @see LicensesController::getCheckin() method that provides the form view * @since [v1.0] * @param int $seatId * @param string $backto * @return Redirect */ 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', trans('admin/licenses/message.not_found')); } $license = License::find($licenseseat->license_id); if (!Company::isCurrentUserHasAccess($license)) { return redirect()->to('admin/licenses')->with('error', trans('general.insufficient_permissions')); } 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' => 'string', 'notes' => 'string'); // 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 = Auth::user(); // 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('app.url') . '/admin/licenses/' . $license->id . '/view' . '|' . $license->name . '> checked in by <' . config('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', 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 to the license page with error return redirect()->to("admin/licenses")->with('error', trans('admin/licenses/message.checkin.error')); }
/** * Display the bulk edit page. * * @author [A. Gianotto] [<*****@*****.**>] * @param int $assetId * @since [v2.0] * @return View */ public function postBulkEdit($assets = null) { if (!Company::isCurrentUserAuthorized()) { return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions')); } elseif (!Input::has('edit_asset')) { return redirect()->back()->with('error', 'No assets selected'); } else { $asset_raw_array = Input::get('edit_asset'); foreach ($asset_raw_array as $asset_id => $value) { $asset_ids[] = $asset_id; } } if (Input::has('bulk_actions')) { // Create labels if (Input::get('bulk_actions') == 'labels') { $settings = Setting::getSettings(); $assets = Asset::find($asset_ids); $count = 0; return View::make('hardware/labels')->with('assets', $assets)->with('settings', $settings)->with('count', $count)->with('settings', $settings); } elseif (Input::get('bulk_actions') == 'delete') { $assets = Asset::with('assigneduser', 'assetloc')->find($asset_ids); return View::make('hardware/bulk-delete')->with('assets', $assets); // Bulk edit } elseif (Input::get('bulk_actions') == 'edit') { $assets = Input::get('edit_asset'); $supplier_list = Helper::suppliersList(); $statuslabel_list = Helper::statusLabelList(); $location_list = Helper::locationsList(); $models_list = Helper::modelList(); $companies_list = array('' => '') + array('clear' => trans('general.remove_company')) + Helper::companyList(); return View::make('hardware/bulk')->with('assets', $assets)->with('supplier_list', $supplier_list)->with('statuslabel_list', $statuslabel_list)->with('location_list', $location_list)->with('models_list', $models_list)->with('companies_list', $companies_list); } } else { return redirect()->back()->with('error', 'No action selected'); } }
/** * 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')); }
/** * Finds the user matching given data, or creates a new one if there is no match * * @author Daniel Melzter * @since 3.0 * @param $row array * @return User Model w/ matching name * @internal param string $user_username Username extracted from CSV * @internal param string $user_email Email extracted from CSV * @internal param string $first_name * @internal param string $last_name */ public function createOrFetchUser($row) { $user_name = $this->array_smart_fetch($row, "name"); $user_email = $this->array_smart_fetch($row, "email"); $user_username = $this->array_smart_fetch($row, "username"); // A number was given instead of a name if (is_numeric($user_name)) { $this->log('User ' . $user_name . ' is not a name - assume this user already exists'); $user_username = ''; $first_name = ''; $last_name = ''; // No name was given } elseif (empty($user_name)) { $this->log('No user data provided - skipping user creation, just adding asset'); $first_name = ''; $last_name = ''; //$user_username = ''; } else { $user_email_array = User::generateFormattedNameFromFullName(Setting::getSettings()->email_format, $user_name); $first_name = $user_email_array['first_name']; $last_name = $user_email_array['last_name']; if ($user_email == '') { $user_email = $user_email_array['username'] . '@' . Setting::getSettings()->email_domain; } if ($user_username == '') { if ($this->option('username_format') == 'email') { $user_username = $user_email; } else { $user_name_array = User::generateFormattedNameFromFullName(Setting::getSettings()->username_format, $user_name); $user_username = $user_name_array['username']; } } } $this->log("--- User Data ---"); $this->log('Full Name: ' . $user_name); $this->log('First Name: ' . $first_name); $this->log('Last Name: ' . $last_name); $this->log('Username: '******'Email: ' . $user_email); $this->log('--- End User Data ---'); if ($this->option('testrun')) { return new User(); } if (!empty($user_username)) { if ($user = User::MatchEmailOrUsername($user_username, $user_email)->whereNotNull('username')->first()) { $this->log('User ' . $user_username . ' already exists'); } elseif ($first_name != '' && $last_name != '' && $user_username != '') { $user = new \App\Models\User(); $password = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20); $user->first_name = $first_name; $user->last_name = $last_name; $user->username = $user_username; $user->email = $user_email; $user->password = bcrypt($password); $user->activated = 1; if ($user->save()) { $this->log('User ' . $first_name . ' created'); } else { $this->jsonError('User "' . $first_name . '"', $user->getErrors()); } } else { $user = new User(); } } else { $user = new User(); } return $user; }
/** * Searches LDAP * * @author [A. Gianotto] [<*****@*****.**>] * @since [v3.0] * @param $ldapatttibutes * @return array|bool */ static function findLdapUsers() { $ldapconn = Ldap::connectToLdap(); $ldap_bind = Ldap::bindAdminToLdap($ldapconn); $base_dn = Setting::getSettings()->ldap_basedn; $filter = Setting::getSettings()->ldap_filter; // Set up LDAP pagination for very large databases // @author Richard Hofman $page_size = 500; $cookie = ''; $result_set = array(); $global_count = 0; // Perform the search do { // Paginate (non-critical, if not supported by server) ldap_control_paged_result($ldapconn, $page_size, false, $cookie); $search_results = ldap_search($ldapconn, $base_dn, '(' . $filter . ')'); if (!$search_results) { return redirect()->route('users')->with('error', trans('admin/users/message.error.ldap_could_not_search') . ldap_error($ldapconn)); } // Get results from page $results = ldap_get_entries($ldapconn, $search_results); if (!$results) { return redirect()->route('users')->with('error', trans('admin/users/message.error.ldap_could_not_get_entries') . ldap_error($ldapconn)); } // Add results to result set $global_count += $results['count']; $result_set = array_merge($result_set, $results); ldap_control_paged_result_response($ldapconn, $search_results, $cookie); } while ($cookie !== null && $cookie != ''); // Clean up after search $result_set['count'] = $global_count; $results = $result_set; ldap_control_paged_result($ldapconn, 0); return $results; }
/** * This nasty little method gets the low inventory info for the * alert dropdown **/ public static function checkLowInventory() { $consumables = Consumable::with('users')->whereNotNull('min_amt')->get(); $accessories = Accessory::with('users')->whereNotNull('min_amt')->get(); $components = Component::with('assets')->whereNotNull('min_amt')->get(); $avail_consumables = 0; $items_array = array(); $all_count = 0; foreach ($consumables as $consumable) { $avail = $consumable->numRemaining(); if ($avail < $consumable->min_amt + \App\Models\Setting::getSettings()->alert_threshold) { if ($consumable->total_qty > 0) { $percent = number_format($consumable->numRemaining() / $consumable->total_qty * 100, 0); } else { $percent = 100; } $items_array[$all_count]['id'] = $consumable->id; $items_array[$all_count]['name'] = $consumable->name; $items_array[$all_count]['type'] = 'consumables'; $items_array[$all_count]['percent'] = $percent; $items_array[$all_count]['remaining'] = $consumable->numRemaining(); $items_array[$all_count]['min_amt'] = $consumable->min_amt; $all_count++; } } foreach ($accessories as $accessory) { $avail = $accessory->numRemaining(); if ($avail < $accessory->min_amt + \App\Models\Setting::getSettings()->alert_threshold) { if ($accessory->total_qty > 0) { $percent = number_format($accessory->numRemaining() / $accessory->total_qty * 100, 0); } else { $percent = 100; } $items_array[$all_count]['id'] = $accessory->id; $items_array[$all_count]['name'] = $accessory->name; $items_array[$all_count]['type'] = 'accessories'; $items_array[$all_count]['percent'] = $percent; $items_array[$all_count]['remaining'] = $accessory->numRemaining(); $items_array[$all_count]['min_amt'] = $accessory->min_amt; $all_count++; } } foreach ($components as $component) { $avail = $component->numRemaining(); if ($avail < $component->min_amt + \App\Models\Setting::getSettings()->alert_threshold) { if ($component->total_qty > 0) { $percent = number_format($component->numRemaining() / $component->total_qty * 100, 0); } else { $percent = 100; } $items_array[$all_count]['id'] = $component->id; $items_array[$all_count]['name'] = $component->name; $items_array[$all_count]['type'] = 'components'; $items_array[$all_count]['percent'] = $percent; $items_array[$all_count]['remaining'] = $component->numRemaining(); $items_array[$all_count]['min_amt'] = $component->min_amt; $all_count++; } } return $items_array; }
/** * 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')); }
public static function generateEmailFromFullName($name) { $username = User::generateFormattedNameFromFullName(Setting::getSettings()->email_format, $name); return $username['username'] . '@' . Setting::getSettings()->email_domain; }
/** * Account sign in form processing. * * @return Redirect */ public function login(Request $request) { $validator = $this->validator(Input::all()); if ($validator->fails()) { return redirect()->back()->withInput()->withErrors($validator); } // Should we even check for LDAP users? if (Setting::getSettings()->ldap_enabled == '1') { LOG::debug("LDAP is enabled."); // Check if the user exists in the database $user = User::where('username', '=', Input::get('username'))->whereNull('deleted_at')->first(); LOG::debug("Local auth lookup complete"); try { Ldap::findAndBindUserLdap($request->input('username'), $request->input('password')); LOG::debug("Binding user to LDAP."); } catch (\Exception $e) { LOG::debug("User " . Input::get('username') . ' did not authenticate successfully against LDAP.'); //$ldap_error = $e->getMessage(); // return redirect()->back()->withInput()->with('error',$e->getMessage()); } // The user does not exist in the database. Try to get them from LDAP. // If user does not exist and authenticates sucessfully with LDAP we // will create it on the fly and sign in with default permissions if (!$user) { LOG::debug("Local user " . Input::get('username') . " does not exist"); try { if ($userattr = Ldap::findAndBindUserLdap($request->input('username'), $request->input('password'))) { LOG::debug("Creating local user " . Input::get('username')); if ($newuser = Ldap::createUserFromLdap($userattr)) { LOG::debug("Local user created.."); } else { LOG::debug("Could not create local user."); } } else { LOG::debug("User did not authenticate correctly against LDAP. No local user was created."); } } catch (\Exception $e) { return redirect()->back()->withInput()->with('error', $e->getMessage()); } // If the user exists and they were imported from LDAP already } else { LOG::debug("Local user " . Input::get('username') . " exists in database. Authenticating existing user against LDAP."); if ($ldap_user = Ldap::findAndBindUserLdap($request->input('username'), $request->input('password'))) { $ldap_attr = Ldap::parseAndMapLdapAttributes($ldap_user); LOG::debug("Valid LDAP login. Updating the local data."); $user->password = bcrypt($request->input('password')); $user->email = $ldap_attr['email']; $user->first_name = $ldap_attr['firstname']; $user->last_name = $ldap_attr['lastname']; $user->save(); } else { LOG::debug("User " . Input::get('username') . " did not authenticate correctly against LDAP. Local user was not updated."); } // End LDAP auth } // End if(!user) // NO LDAP enabled - just try to login the user normally } LOG::debug("Authenticating user against database."); // Try to log the user in if (!Auth::attempt(Input::only('username', 'password'), Input::get('remember-me', 0))) { LOG::debug("Local authentication failed."); // throw new Cartalyst\Sentry\Users\UserNotFoundException(); return redirect()->back()->withInput()->with('error', trans('auth/message.account_not_found')); } // Get the page we were before $redirect = \Session::get('loginRedirect', 'home'); // Unset the page we were before from the session \Session::forget('loginRedirect'); // Redirect to the users page return redirect()->to($redirect)->with('success', trans('auth/message.signin.success')); // Ooops.. something went wrong return redirect()->back()->withInput()->withErrors($this->messageBag); }
/** * Check in the item so that it can be checked out again to someone else * * @uses Accessory::checkin_email() to determine if an email can and should be sent * @author [A. Gianotto] [<*****@*****.**>] * @param int $accessoryId * @return Redirect **/ public function postCheckin(Request $request, $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', trans('admin/accessories/message.not_found')); } $accessory = Accessory::find($accessory_user->accessory_id); if (!Company::isCurrentUserHasAccess($accessory)) { return redirect()->to('admin/accessories')->with('error', trans('general.insufficient_permissions')); } $logaction = new Actionlog(); $logaction->checkedout_to = e($accessory_user->assigned_to); $return_to = e($accessory_user->assigned_to); $admin_user = Auth::user(); // Was the accessory updated? if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) { $logaction->accessory_id = e($accessory->id); $logaction->location_id = null; $logaction->asset_type = 'accessory'; $logaction->user_id = e($admin_user->id); $logaction->note = e(Input::get('note')); $settings = Setting::getSettings(); if ($settings->slack_endpoint) { $slack_settings = ['username' => e($settings->botname), 'channel' => e($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('app.url') . '/admin/accessories/' . e($accessory->id) . '/view' . '|' . e($accessory->name) . '> checked in by <' . config('app.url') . '/admin/users/' . e($admin_user->id) . '/view' . '|' . e($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'] = e($user->first_name); $data['item_name'] = e($accessory->name); $data['checkin_date'] = e($logaction->created_at); $data['item_tag'] = ''; $data['note'] = e($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', trans('admin/accessories/message.checkin.success')); } else { return redirect()->to("admin/accessories/" . $accessory->id . "/view")->with('success', trans('admin/accessories/message.checkin.success')); } } // Redirect to the accessory management page with error return redirect()->to("admin/accessories")->with('error', trans('admin/accessories/message.checkin.error')); }
/** * LDAP form processing. * * @author Aladin Alaily * @since [v1.8] * @return Redirect */ public function postLDAP(Request $request) { ini_set('max_execution_time', 600); //600 seconds = 10 minutes ini_set('memory_limit', '500M'); $ldap_result_username = Setting::getSettings()->ldap_username_field; $ldap_result_last_name = Setting::getSettings()->ldap_lname_field; $ldap_result_first_name = Setting::getSettings()->ldap_fname_field; $ldap_result_active_flag = Setting::getSettings()->ldap_active_flag_field; $ldap_result_emp_num = Setting::getSettings()->ldap_emp_num; $ldap_result_email = Setting::getSettings()->ldap_email; try { $ldapconn = Ldap::connectToLdap(); } catch (\Exception $e) { return redirect()->back()->withInput()->with('error', $e->getMessage()); } try { Ldap::bindAdminToLdap($ldapconn); } catch (\Exception $e) { return redirect()->back()->withInput()->with('error', $e->getMessage()); } $summary = array(); $results = Ldap::findLdapUsers(); $tmp_pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20); $pass = bcrypt($tmp_pass); for ($i = 0; $i < $results["count"]; $i++) { if (empty($ldap_result_active_flag) || $results[$i][$ldap_result_active_flag][0] == "TRUE") { $item = array(); $item["username"] = isset($results[$i][$ldap_result_username][0]) ? $results[$i][$ldap_result_username][0] : ""; $item["employee_number"] = isset($results[$i][$ldap_result_emp_num][0]) ? $results[$i][$ldap_result_emp_num][0] : ""; $item["lastname"] = isset($results[$i][$ldap_result_last_name][0]) ? $results[$i][$ldap_result_last_name][0] : ""; $item["firstname"] = isset($results[$i][$ldap_result_first_name][0]) ? $results[$i][$ldap_result_first_name][0] : ""; $item["email"] = isset($results[$i][$ldap_result_email][0]) ? $results[$i][$ldap_result_email][0] : ""; // User exists $item["createorupdate"] = 'updated'; if (!($user = User::where('username', $item["username"])->first())) { $user = new User(); $user->password = $pass; $item["createorupdate"] = 'created'; } // Create the user if they don't exist. $user->first_name = e($item["firstname"]); $user->last_name = e($item["lastname"]); $user->username = e($item["username"]); $user->email = e($item["email"]); $user->employee_num = e($item["employee_number"]); $user->activated = 1; if ($request->input('location_id') != '') { $user->location_id = e($request->input('location_id')); } $user->notes = 'Imported from LDAP'; $user->ldap_import = 1; $errors = ''; if ($user->save()) { $item["note"] = $item["createorupdate"]; $item["status"] = 'success'; } else { foreach ($user->getErrors()->getMessages() as $key => $err) { $errors .= '<li>' . $err[0]; } $item["note"] = $errors; $item["status"] = 'error'; } array_push($summary, $item); } } return redirect()->route('ldap/user')->with('success', "LDAP Import successful.")->with('summary', $summary); }
/** * Generates the JSON response for asset maintenances listing view. * * @see AssetMaintenancesController::getIndex() method that generates view * @author Vincent Sposato <*****@*****.**> * @version v1.0 * @since [v1.8] * @return String JSON */ public function getDatatable() { $maintenances = AssetMaintenance::with('asset', 'supplier', 'asset.company', 'admin')->withTrashed(); if (Input::has('search')) { $maintenances = $maintenances->TextSearch(e(Input::get('search'))); } if (Input::has('offset')) { $offset = e(Input::get('offset')); } else { $offset = 0; } if (Input::has('limit')) { $limit = e(Input::get('limit')); } else { $limit = 50; } $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'; $sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at'; switch ($sort) { case 'user_id': $maintenances = $maintenances->OrderAdmin($order); break; default: $maintenances = $maintenances->orderBy($sort, $order); break; } $maintenancesCount = $maintenances->count(); $maintenances = $maintenances->skip($offset)->take($limit)->get(); $rows = array(); $settings = Setting::getSettings(); foreach ($maintenances as $maintenance) { $actions = '<nobr><a href="' . route('update/asset_maintenance', $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('delete/asset_maintenance', $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>'; if ($maintenance->cost && $maintenance->asset->assetloc && $maintenance->asset->assetloc->currency != '') { $maintenance_cost = $maintenance->asset->assetloc->currency . $maintenance->cost; } else { $maintenance_cost = $settings->default_currency . $maintenance->cost; } $company = $maintenance->asset->company; $rows[] = array('id' => $maintenance->id, 'asset_name' => (string) link_to('/hardware/' . $maintenance->asset->id . '/view', $maintenance->asset->showAssetName()), 'title' => $maintenance->title, 'notes' => $maintenance->notes, 'supplier' => $maintenance->supplier->name, 'cost' => $maintenance_cost, 'asset_maintenance_type' => e($maintenance->asset_maintenance_type), 'start_date' => $maintenance->start_date, 'asset_maintenance_time' => $maintenance->asset_maintenance_time, 'completion_date' => $maintenance->completion_date, 'user_id' => $maintenance->admin ? (string) link_to('/admin/users/' . $maintenance->admin->id . '/view', $maintenance->admin->fullName()) : '', 'actions' => $actions, 'companyName' => is_null($company) ? '' : $company->name); } $data = array('total' => $maintenancesCount, 'rows' => $rows); return $data; }
/** * Execute the console command. * * @return mixed */ public function fire() { // Expiring Assets $expiring_assets = Asset::getExpiringWarrantee(Setting::getSettings()->alert_interval); $this->info(count($expiring_assets) . ' expiring assets'); $asset_data['count'] = count($expiring_assets); $asset_data['email_content'] = ''; $now = date("Y-m-d"); foreach ($expiring_assets as $asset) { $expires = $asset->warrantee_expires(); $difference = round(abs(strtotime($expires) - strtotime($now)) / 86400); if ($difference > 30) { $asset_data['email_content'] .= '<tr style="background-color: #fcffa3;">'; } else { $asset_data['email_content'] .= '<tr style="background-color:#d9534f;">'; } $asset_data['email_content'] .= '<td><a href="' . config('app.url') . '/hardware/' . e($asset->id) . '/view">'; $asset_data['email_content'] .= $asset->showAssetName() . '</a></td><td>' . e($asset->asset_tag) . '</td>'; $asset_data['email_content'] .= '<td>' . e($asset->warrantee_expires()) . '</td>'; $asset_data['email_content'] .= '<td>' . $difference . ' days</td>'; $asset_data['email_content'] .= '<td>' . ($asset->supplier ? e($asset->supplier->name) : '') . '</td>'; $asset_data['email_content'] .= '<td>' . ($asset->assigneduser ? e($asset->assigneduser->fullName()) : '') . '</td>'; $asset_data['email_content'] .= '</tr>'; } // Expiring licenses $expiring_licenses = License::getExpiringLicenses(Setting::getSettings()->alert_interval); $this->info(count($expiring_licenses) . ' expiring licenses'); $license_data['count'] = count($expiring_licenses); $license_data['email_content'] = ''; foreach ($expiring_licenses as $license) { $expires = $license->expiration_date; $difference = round(abs(strtotime($expires) - strtotime($now)) / 86400); if ($difference > 30) { $license_data['email_content'] .= '<tr style="background-color: #fcffa3;">'; } else { $license_data['email_content'] .= '<tr style="background-color:#d9534f;">'; } $license_data['email_content'] .= '<td><a href="' . config('app.url') . '/admin/licenses/' . $license->id . '/view">'; $license_data['email_content'] .= $license->name . '</a></td>'; $license_data['email_content'] .= '<td>' . $license->expiration_date . '</td>'; $license_data['email_content'] .= '<td>' . $difference . ' days</td>'; $license_data['email_content'] .= '</tr>'; } if (Setting::getSettings()->alert_email != '' && Setting::getSettings()->alerts_enabled == 1) { if (count($expiring_assets) > 0) { \Mail::send('emails.expiring-assets-report', $asset_data, function ($m) { $m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name); $m->subject('Expiring Assets Report'); }); } if (count($expiring_licenses) > 0) { \Mail::send('emails.expiring-licenses-report', $license_data, function ($m) { $m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name); $m->subject('Expiring Licenses Report'); }); } } else { if (Setting::getSettings()->alert_email == '') { echo "Could not send email. No alert email configured in settings. \n"; } elseif (Setting::getSettings()->alerts_enabled != 1) { echo "Alerts are disabled in the settings. No mail will be sent. \n"; } } }