Small phpcbf cleanup

This commit is contained in:
snipe 2016-12-29 14:02:18 -08:00
parent fd805bde50
commit 51ceaedfaf
68 changed files with 383 additions and 395 deletions

View file

@ -70,11 +70,11 @@ class LdapSync extends Command
$results = Ldap::findLdapUsers(); $results = Ldap::findLdapUsers();
if ($this->option('location')!='') { if ($this->option('location')!='') {
$location = Location::where('name','=',$this->option('location'))->first(); $location = Location::where('name', '=', $this->option('location'))->first();
LOG::debug('Location name '.$this->option('location').' passed'); LOG::debug('Location name '.$this->option('location').' passed');
LOG::debug('Importing to '.$location->name.' ('.$location->id.')'); LOG::debug('Importing to '.$location->name.' ('.$location->id.')');
} elseif ($this->option('location_id')!='') { } elseif ($this->option('location_id')!='') {
$location = Location::where('id','=',$this->option('location_id'))->first(); $location = Location::where('id', '=', $this->option('location_id'))->first();
LOG::debug('Location ID '.$this->option('location_id').' passed'); LOG::debug('Location ID '.$this->option('location_id').' passed');
LOG::debug('Importing to '.$location->name.' ('.$location->id.')'); LOG::debug('Importing to '.$location->name.' ('.$location->id.')');
} else { } else {
@ -146,7 +146,7 @@ class LdapSync extends Command
if ($this->option('summary')) { if ($this->option('summary')) {
for ($x = 0; $x < count($summary); $x++) { for ($x = 0; $x < count($summary); $x++) {
if ($summary[$x]['status']=='error') { if ($summary[$x]['status']=='error') {
$this->error('ERROR: '.$summary[$x]['firstname'].' '.$summary[$x]['lastname'].' (username: '.$summary[$x]['username'].' was not imported: '.$summary[$x]['note'] ); $this->error('ERROR: '.$summary[$x]['firstname'].' '.$summary[$x]['lastname'].' (username: '.$summary[$x]['username'].' was not imported: '.$summary[$x]['note']);
} else { } else {
$this->info('User '.$summary[$x]['firstname'].' '.$summary[$x]['lastname'].' (username: '.$summary[$x]['username'].' was '.strtoupper($summary[$x]['createorupdate']).'.'); $this->info('User '.$summary[$x]['firstname'].' '.$summary[$x]['lastname'].' (username: '.$summary[$x]['username'].' was '.strtoupper($summary[$x]['createorupdate']).'.');
} }
@ -159,6 +159,4 @@ class LdapSync extends Command
} }
} }

View file

@ -125,12 +125,12 @@ class ObjectImportCommand extends Command
} }
public function progress($count) public function progress($count)
{ {
if(!$this->bar) { if (!$this->bar) {
$this->bar = $this->output->createProgressBar($count); $this->bar = $this->output->createProgressBar($count);
} }
static $index =0; static $index =0;
$index++; $index++;
if($index < $count) { if ($index < $count) {
$this->bar->advance(); $this->bar->advance();
} else { } else {
$this->bar->finish(); $this->bar->finish();

View file

@ -42,7 +42,7 @@ class Versioning extends Command
{ {
$versionFile = 'config/version.php'; $versionFile = 'config/version.php';
$hash_version = str_replace("\n",'',shell_exec('git describe --tags')); $hash_version = str_replace("\n", '', shell_exec('git describe --tags'));
$version = explode('-', $hash_version); $version = explode('-', $hash_version);
@ -52,18 +52,19 @@ class Versioning extends Command
'build_version' => $version[1], 'build_version' => $version[1],
'hash_version' => $version[2], 'hash_version' => $version[2],
'full_hash' => $hash_version), 'full_hash' => $hash_version),
true); true
);
// Construct our file content // Construct our file content
$content = <<<CON $content = <<<CON
<?php <?php
return $array; return $array;
CON; CON;
// And finally write the file and output the current version // And finally write the file and output the current version
\File::put($versionFile, $content); \File::put($versionFile, $content);
$this->line('Setting version: '. config('version.app_version').' build '.config('version.build_version').' ('.config('version.hash_version').')'); $this->line('Setting version: '. config('version.app_version').' build '.config('version.build_version').' ('.config('version.hash_version').')');
} }
/** /**

View file

@ -46,20 +46,20 @@ class Handler extends ExceptionHandler
public function render($request, Exception $e) public function render($request, Exception $e)
{ {
if ($e instanceof \Illuminate\Session\TokenMismatchException) { if ($e instanceof \Illuminate\Session\TokenMismatchException) {
return redirect()->back()->with('error', trans('general.token_expired')); return redirect()->back()->with('error', trans('general.token_expired'));
} }
if ($this->isHttpException($e)) { if ($this->isHttpException($e)) {
$statusCode = $e->getStatusCode(); $statusCode = $e->getStatusCode();
switch ($statusCode) { switch ($statusCode) {
case '404': case '404':
return response()->view('layouts/basic', [ return response()->view('layouts/basic', [
'content' => view('errors/404') 'content' => view('errors/404')
]); ]);
} }
} }
return parent::render($request, $e); return parent::render($request, $e);

View file

@ -31,7 +31,8 @@ class Helper
* @since [v2.0] * @since [v2.0]
* @return String * @return String
*/ */
public static function parseEscapedMarkedown($str) { public static function parseEscapedMarkedown($str)
{
$Parsedown = new \Parsedown(); $Parsedown = new \Parsedown();
if ($str) { if ($str) {
@ -173,8 +174,9 @@ class Helper
$categories = Category::orderBy('name', 'asc') $categories = Category::orderBy('name', 'asc')
->whereNull('deleted_at') ->whereNull('deleted_at')
->orderBy('name', 'asc'); ->orderBy('name', 'asc');
if(!empty($category_type)) if (!empty($category_type)) {
$categories = $categories->where('category_type', '=', $category_type); $categories = $categories->where('category_type', '=', $category_type);
}
$category_list = array('' => trans('general.select_category')) + $categories->pluck('name', 'id')->toArray(); $category_list = array('' => trans('general.select_category')) + $categories->pluck('name', 'id')->toArray();
return $category_list; return $category_list;
} }
@ -309,7 +311,7 @@ class Helper
{ {
$users_list = array( '' => trans('general.select_user')) + $users_list = array( '' => trans('general.select_user')) +
Company::scopeCompanyables(User::where('deleted_at', '=', null)) Company::scopeCompanyables(User::where('deleted_at', '=', null))
->where('show_in_list','=',1) ->where('show_in_list', '=', 1)
->orderBy('last_name', 'asc') ->orderBy('last_name', 'asc')
->orderBy('first_name', 'asc')->get() ->orderBy('first_name', 'asc')->get()
->pluck('complete_name', 'id')->toArray(); ->pluck('complete_name', 'id')->toArray();
@ -554,7 +556,7 @@ class Helper
if ($permission[$x]['display'] === true) { if ($permission[$x]['display'] === true) {
if ($selected_arr) { if ($selected_arr) {
if (array_key_exists($permission_name,$selected_arr)) { if (array_key_exists($permission_name, $selected_arr)) {
$permissions_arr[$permission_name] = $selected_arr[$permission_name]; $permissions_arr[$permission_name] = $selected_arr[$permission_name];
} else { } else {
$permissions_arr[$permission_name] = '0'; $permissions_arr[$permission_name] = '0';
@ -585,7 +587,8 @@ class Helper
* @since [v3.0] * @since [v3.0]
* @return boolean * @return boolean
*/ */
public static function checkIfRequired($class, $field) { public static function checkIfRequired($class, $field)
{
$rules = $class::rules(); $rules = $class::rules();
foreach ($rules as $rule_name => $rule) { foreach ($rules as $rule_name => $rule) {
if ($rule_name == $field) { if ($rule_name == $field) {
@ -612,7 +615,7 @@ class Helper
*/ */
public static function array_smart_fetch(array $array, $key, $default = '') public static function array_smart_fetch(array $array, $key, $default = '')
{ {
array_change_key_case($array, CASE_LOWER); array_change_key_case($array, CASE_LOWER);
return array_key_exists(strtolower($key), array_change_key_case($array)) ? e(trim($array[ $key ])) : $default; return array_key_exists(strtolower($key), array_change_key_case($array)) ? e(trim($array[ $key ])) : $default;
} }
@ -647,7 +650,8 @@ class Helper
* @param String $string * @param String $string
* @return string * @return string
*/ */
public static function gracefulDecrypt(CustomField $field, $string) { public static function gracefulDecrypt(CustomField $field, $string)
{
if ($field->isFieldDecryptable($string)) { if ($field->isFieldDecryptable($string)) {
@ -675,7 +679,8 @@ class Helper
* @param $array array * @param $array array
* @return Array * @return Array
*/ */
public static function stripTagsFromJSON(Array $array) { public static function stripTagsFromJSON(array $array)
{
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
$clean_value = strip_tags($value); $clean_value = strip_tags($value);
@ -699,7 +704,7 @@ class Helper
public static function generateDatatableButton($type, $route, $enabled = true, $message = null, $itemName = null) public static function generateDatatableButton($type, $route, $enabled = true, $message = null, $itemName = null)
{ {
$disabledString = $enabled ? '' : 'disabled'; $disabledString = $enabled ? '' : 'disabled';
switch($type) { switch ($type) {
case 'checkout': case 'checkout':
return '<a href="' . $route . '" style="margin-right:5px;" class="btn btn-info btn-sm ' . $disabledString . '">' . trans('general.checkout') . '</a>'; return '<a href="' . $route . '" style="margin-right:5px;" class="btn btn-info btn-sm ' . $disabledString . '">' . trans('general.checkout') . '</a>';
case 'checkin': case 'checkin':
@ -714,5 +719,4 @@ class Helper
return '<a href="'.$route.'" class="btn btn-warning btn-sm ' . $disabledString . '"><i class="fa fa-recycle icon-white"></i></a>'; return '<a href="'.$route.'" class="btn btn-warning btn-sm ' . $disabledString . '"><i class="fa fa-recycle icon-white"></i></a>';
} }
} }
} }

View file

@ -74,7 +74,7 @@ class AssetMaintenancesController extends Controller
*/ */
public function getDatatable(Request $request) public function getDatatable(Request $request)
{ {
$maintenances = AssetMaintenance::with('asset', 'supplier', 'asset.company','admin'); $maintenances = AssetMaintenance::with('asset', 'supplier', 'asset.company', 'admin');
if (Input::has('search')) { if (Input::has('search')) {
$maintenances = $maintenances->TextSearch(e($request->input('search'))); $maintenances = $maintenances->TextSearch(e($request->input('search')));
@ -107,12 +107,12 @@ class AssetMaintenancesController extends Controller
if (Gate::allows('update', Asset::class)) { if (Gate::allows('update', Asset::class)) {
$actions .= Helper::generateDatatableButton('edit', route('maintenances.edit', $maintenance->id)); $actions .= Helper::generateDatatableButton('edit', route('maintenances.edit', $maintenance->id));
$actions .= Helper::generateDatatableButton( $actions .= Helper::generateDatatableButton(
'delete', 'delete',
route('maintenances.destroy', $maintenance->id), route('maintenances.destroy', $maintenance->id),
$enabled = true, $enabled = true,
trans('admin/asset_maintenances/message.delete.confirm'), trans('admin/asset_maintenances/message.delete.confirm'),
$maintenance->title $maintenance->title
); );
} }
if (($maintenance->cost) && (isset($maintenance->asset)) && ($maintenance->asset->assetloc) && ($maintenance->asset->assetloc->currency!='')) { if (($maintenance->cost) && (isset($maintenance->asset)) && ($maintenance->asset->assetloc) && ($maintenance->asset->assetloc->currency!='')) {

View file

@ -418,7 +418,7 @@ class AssetModelsController extends Controller
if (Input::has('search')) { if (Input::has('search')) {
$assets = $assets->TextSearch(e($request->input('search'))); $assets = $assets->TextSearch(e($request->input('search')));
} }
$offset = request('offset',0); $offset = request('offset', 0);
$limit = request('limit', 50); $limit = request('limit', 50);

View file

@ -156,7 +156,7 @@ class AssetsController extends Controller
$asset->archived = '0'; $asset->archived = '0';
$asset->physical = '1'; $asset->physical = '1';
$asset->depreciate = '0'; $asset->depreciate = '0';
$asset->status_id = request('status_id',0); $asset->status_id = request('status_id', 0);
$asset->warranty_months = request('warranty_months', null); $asset->warranty_months = request('warranty_months', null);
$asset->purchase_cost = Helper::ParseFloat(Input::get('purchase_cost')); $asset->purchase_cost = Helper::ParseFloat(Input::get('purchase_cost'));
$asset->purchase_date = request('purchase_date', null); $asset->purchase_date = request('purchase_date', null);
@ -784,7 +784,7 @@ class AssetsController extends Controller
// We use hardware instead of asset in the url // We use hardware instead of asset in the url
$redirectTo = "hardware"; $redirectTo = "hardware";
switch(request('import-type')) { switch (request('import-type')) {
case "asset": case "asset":
$redirectTo = "hardware.index"; $redirectTo = "hardware.index";
break; break;
@ -819,7 +819,7 @@ class AssetsController extends Controller
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
} }
$this->authorize('create',$asset_to_clone); $this->authorize('create', $asset_to_clone);
$asset = clone $asset_to_clone; $asset = clone $asset_to_clone;
$asset->id = null; $asset->id = null;
@ -882,7 +882,7 @@ class AssetsController extends Controller
$status['success'] = array(); $status['success'] = array();
foreach($results as $row) { foreach ($results as $row) {
if (is_array($row)) { if (is_array($row)) {
@ -899,37 +899,37 @@ class AssetsController extends Controller
$item[$asset_tag][$batch_counter]['name'] = Helper::array_smart_fetch($row, "name"); $item[$asset_tag][$batch_counter]['name'] = Helper::array_smart_fetch($row, "name");
$item[$asset_tag][$batch_counter]['email'] = Helper::array_smart_fetch($row, "email"); $item[$asset_tag][$batch_counter]['email'] = Helper::array_smart_fetch($row, "email");
if ($asset = Asset::where('asset_tag','=',$asset_tag)->first()) { if ($asset = Asset::where('asset_tag', '=', $asset_tag)->first()) {
$item[$asset_tag][$batch_counter]['asset_id'] = $asset->id; $item[$asset_tag][$batch_counter]['asset_id'] = $asset->id;
$base_username = User::generateFormattedNameFromFullName(Setting::getSettings()->username_format,$item[$asset_tag][$batch_counter]['name']); $base_username = User::generateFormattedNameFromFullName(Setting::getSettings()->username_format, $item[$asset_tag][$batch_counter]['name']);
$user = User::where('username','=',$base_username['username']); $user = User::where('username', '=', $base_username['username']);
$user_query = ' on username '.$base_username['username']; $user_query = ' on username '.$base_username['username'];
if ($request->input('match_firstnamelastname')=='1') { if ($request->input('match_firstnamelastname')=='1') {
$firstnamedotlastname = User::generateFormattedNameFromFullName('firstname.lastname',$item[$asset_tag][$batch_counter]['name']); $firstnamedotlastname = User::generateFormattedNameFromFullName('firstname.lastname', $item[$asset_tag][$batch_counter]['name']);
$item[$asset_tag][$batch_counter]['username'][] = $firstnamedotlastname['username']; $item[$asset_tag][$batch_counter]['username'][] = $firstnamedotlastname['username'];
$user->orWhere('username','=',$firstnamedotlastname['username']); $user->orWhere('username', '=', $firstnamedotlastname['username']);
$user_query .= ', or on username '.$firstnamedotlastname['username']; $user_query .= ', or on username '.$firstnamedotlastname['username'];
} }
if ($request->input('match_flastname')=='1') { if ($request->input('match_flastname')=='1') {
$flastname = User::generateFormattedNameFromFullName('filastname',$item[$asset_tag][$batch_counter]['name']); $flastname = User::generateFormattedNameFromFullName('filastname', $item[$asset_tag][$batch_counter]['name']);
$item[$asset_tag][$batch_counter]['username'][] = $flastname['username']; $item[$asset_tag][$batch_counter]['username'][] = $flastname['username'];
$user->orWhere('username','=',$flastname['username']); $user->orWhere('username', '=', $flastname['username']);
$user_query .= ', or on username '.$flastname['username']; $user_query .= ', or on username '.$flastname['username'];
} }
if ($request->input('match_firstname')=='1') { if ($request->input('match_firstname')=='1') {
$firstname = User::generateFormattedNameFromFullName('firstname',$item[$asset_tag][$batch_counter]['name']); $firstname = User::generateFormattedNameFromFullName('firstname', $item[$asset_tag][$batch_counter]['name']);
$item[$asset_tag][$batch_counter]['username'][] = $firstname['username']; $item[$asset_tag][$batch_counter]['username'][] = $firstname['username'];
$user->orWhere('username','=',$firstname['username']); $user->orWhere('username', '=', $firstname['username']);
$user_query .= ', or on username '.$firstname['username']; $user_query .= ', or on username '.$firstname['username'];
} }
if ($request->input('match_email')=='1') { if ($request->input('match_email')=='1') {
if ($item[$asset_tag][$batch_counter]['email']=='') { if ($item[$asset_tag][$batch_counter]['email']=='') {
$item[$asset_tag][$batch_counter]['username'][] = $user_email = User::generateEmailFromFullName($item[$asset_tag][$batch_counter]['name']); $item[$asset_tag][$batch_counter]['username'][] = $user_email = User::generateEmailFromFullName($item[$asset_tag][$batch_counter]['name']);
$user->orWhere('username','=',$user_email); $user->orWhere('username', '=', $user_email);
$user_query .= ', or on username '.$user_email; $user_query .= ', or on username '.$user_email;
} }
} }
@ -948,8 +948,7 @@ class AssetsController extends Controller
'target_type' => User::class, 'target_type' => User::class,
'created_at' => $item[$asset_tag][$batch_counter]['checkout_date'], 'created_at' => $item[$asset_tag][$batch_counter]['checkout_date'],
'action_type' => 'checkout', 'action_type' => 'checkout',
) ));
);
$asset->assigned_to = $user->id; $asset->assigned_to = $user->id;
@ -974,13 +973,13 @@ class AssetsController extends Controller
// Loop through and backfill the checkins // Loop through and backfill the checkins
foreach ($item as $key => $asset_batch) { foreach ($item as $key => $asset_batch) {
$total_in_batch = count($asset_batch); $total_in_batch = count($asset_batch);
for($x = 0; $x < $total_in_batch; $x++) { for ($x = 0; $x < $total_in_batch; $x++) {
$next = $x + 1; $next = $x + 1;
// Only do this if a matching user was found // Only do this if a matching user was found
if ((array_key_exists('checkedout_to',$asset_batch[$x])) && ($asset_batch[$x]['checkedout_to']!='')) { if ((array_key_exists('checkedout_to', $asset_batch[$x])) && ($asset_batch[$x]['checkedout_to']!='')) {
if (($total_in_batch > 1) && ($x < $total_in_batch) && (array_key_exists($next,$asset_batch))) { if (($total_in_batch > 1) && ($x < $total_in_batch) && (array_key_exists($next, $asset_batch))) {
$checkin_date = Carbon::parse($asset_batch[$next]['checkout_date'])->subDay(1)->format('Y-m-d H:i:s'); $checkin_date = Carbon::parse($asset_batch[$next]['checkout_date'])->subDay(1)->format('Y-m-d H:i:s');
$asset_batch[$x]['real_checkin'] = $checkin_date; $asset_batch[$x]['real_checkin'] = $checkin_date;
@ -992,13 +991,12 @@ class AssetsController extends Controller
'target_id' => null, 'target_id' => null,
'created_at' => $checkin_date, 'created_at' => $checkin_date,
'action_type' => 'checkin' 'action_type' => 'checkin'
) ));
);
} }
} }
} }
} }
return View::make('hardware/history')->with('status',$status); return View::make('hardware/history')->with('status', $status);
} }
/** /**
@ -1152,12 +1150,14 @@ class AssetsController extends Controller
// Create labels // Create labels
if (Input::get('bulk_actions')=='labels') { if (Input::get('bulk_actions')=='labels') {
$count = 0; $count = 0;
return View::make('hardware/labels')->with('assets', Asset::find($asset_ids))->with('settings', Setting::getSettings())->with('count', $count)->with('settings', return View::make('hardware/labels')->with('assets', Asset::find($asset_ids))->with('settings', Setting::getSettings())->with('count', $count)->with(
Setting::getSettings()); 'settings',
Setting::getSettings()
);
} elseif (Input::get('bulk_actions')=='delete') { } elseif (Input::get('bulk_actions')=='delete') {
$assets = Asset::with('assigneduser', 'assetloc')->find($asset_ids); $assets = Asset::with('assigneduser', 'assetloc')->find($asset_ids);
$assets->each(function($asset) { $assets->each(function ($asset) {
$this->authorize('delete',$asset); $this->authorize('delete', $asset);
}); });
return View::make('hardware/bulk-delete')->with('assets', $assets); return View::make('hardware/bulk-delete')->with('assets', $assets);
// Bulk edit // Bulk edit
@ -1168,8 +1168,10 @@ class AssetsController extends Controller
->with('statuslabel_list', Helper::statusLabelList()) ->with('statuslabel_list', Helper::statusLabelList())
->with('location_list', Helper::locationsList()) ->with('location_list', Helper::locationsList())
->with('models_list', Helper::modelList()) ->with('models_list', Helper::modelList())
->with('companies_list', ->with(
array('' => '') + array('clear' => trans('general.remove_company')) + Helper::companyList()); 'companies_list',
array('' => '') + array('clear' => trans('general.remove_company')) + Helper::companyList()
);
} }
} }
return redirect()->back()->with('error', 'No action selected'); return redirect()->back()->with('error', 'No action selected');
@ -1347,7 +1349,7 @@ class AssetsController extends Controller
} }
if ($request->has('status_id')) { if ($request->has('status_id')) {
$assets->where('status_id','=', e($request->get('status_id'))); $assets->where('status_id', '=', e($request->get('status_id')));
} }
$allowed_columns = [ $allowed_columns = [
@ -1429,60 +1431,58 @@ class AssetsController extends Controller
return $data; return $data;
} }
public function getBulkCheckout() public function getBulkCheckout()
{ {
$this->authorize('checkout', Asset::class); $this->authorize('checkout', Asset::class);
// Filter out assets that are not deployable. // Filter out assets that are not deployable.
$assets_list = Company::scopeCompanyables(Asset::RTD()->get(), 'assets.company_id')->pluck('detailed_name', 'id')->toArray(); $assets_list = Company::scopeCompanyables(Asset::RTD()->get(), 'assets.company_id')->pluck('detailed_name', 'id')->toArray();
return View::make('hardware/bulk-checkout') return View::make('hardware/bulk-checkout')
->with('users_list', Helper::usersList()) ->with('users_list', Helper::usersList())
->with('assets_list', $assets_list); ->with('assets_list', $assets_list);
} }
public function postBulkCheckout(Request $request) public function postBulkCheckout(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
"assigned_to" => 'required' "assigned_to" => 'required'
]); ]);
$user = User::find(e(Input::get('assigned_to'))); $user = User::find(e(Input::get('assigned_to')));
$admin = Auth::user(); $admin = Auth::user();
$asset_ids = array_filter(Input::get('selected_assets')); $asset_ids = array_filter(Input::get('selected_assets'));
if ((Input::has('checkout_at')) && (Input::get('checkout_at')!= date("Y-m-d"))) { if ((Input::has('checkout_at')) && (Input::get('checkout_at')!= date("Y-m-d"))) {
$checkout_at = e(Input::get('checkout_at')); $checkout_at = e(Input::get('checkout_at'));
} else { } else {
$checkout_at = date("Y-m-d H:i:s"); $checkout_at = date("Y-m-d H:i:s");
} }
if (Input::has('expected_checkin')) { if (Input::has('expected_checkin')) {
$expected_checkin = e(Input::get('expected_checkin')); $expected_checkin = e(Input::get('expected_checkin'));
} else { } else {
$expected_checkin = ''; $expected_checkin = '';
} }
$errors = []; $errors = [];
DB::transaction(function() use ($user, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids) DB::transaction(function () use ($user, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids) {
{
foreach($asset_ids as $asset_id) foreach ($asset_ids as $asset_id) {
{ $asset = Asset::find($asset_id);
$asset = Asset::find($asset_id); $this->authorize('checkout', $asset);
$this->authorize('checkout', $asset); $error = $asset->checkOutToUser($user, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), null);
$error = $asset->checkOutToUser($user, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), null);
if($error) { if ($error) {
array_merge_recursive($errors, $asset->getErrors()->toArray()); array_merge_recursive($errors, $asset->getErrors()->toArray());
} }
} }
}); });
if (!$errors) { if (!$errors) {
// Redirect to the new asset page // Redirect to the new asset page
return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkout.success')); return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkout.success'));
} }
// Redirect to the asset management page with error // Redirect to the asset management page with error
return redirect()->to("hardware/bulk-checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($errors); return redirect()->to("hardware/bulk-checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($errors);
} }
} }

View file

@ -36,7 +36,8 @@ class ForgotPasswordController extends Controller
* Overriding method "getEmailSubject()" from trait "use ResetsPasswords" * Overriding method "getEmailSubject()" from trait "use ResetsPasswords"
* @return string * @return string
*/ */
public function getEmailSubject(){ public function getEmailSubject()
{
return property_exists($this, 'subject') ? $this->subject : \Lang::get('mail.reset_link'); return property_exists($this, 'subject') ? $this->subject : \Lang::get('mail.reset_link');
} }

View file

@ -17,8 +17,6 @@ use Log;
use View; use View;
use PragmaRX\Google2FA\Google2FA; use PragmaRX\Google2FA\Google2FA;
/** /**
* This controller handles authentication for the user, including local * This controller handles authentication for the user, including local
* database users and LDAP users. * database users and LDAP users.
@ -65,7 +63,7 @@ class LoginController extends Controller
{ {
LOG::debug("Binding user to LDAP."); LOG::debug("Binding user to LDAP.");
$ldap_user = Ldap::findAndBindUserLdap($request->input('username'), $request->input('password')); $ldap_user = Ldap::findAndBindUserLdap($request->input('username'), $request->input('password'));
if(!$ldap_user) { if (!$ldap_user) {
LOG::debug("LDAP user ".$request->input('username')." not found in LDAP or could not bind"); LOG::debug("LDAP user ".$request->input('username')." not found in LDAP or could not bind");
throw new \Exception("Could not find user in LDAP directory"); throw new \Exception("Could not find user in LDAP directory");
} else { } else {
@ -73,7 +71,7 @@ class LoginController extends Controller
} }
// Check if the user already exists in the database and was imported via LDAP // Check if the user already exists in the database and was imported via LDAP
$user = User::where('username', '=', Input::get('username'))->whereNull('deleted_at')->where('ldap_import','=',1)->first(); $user = User::where('username', '=', Input::get('username'))->whereNull('deleted_at')->where('ldap_import', '=', 1)->first();
LOG::debug("Local auth lookup complete"); LOG::debug("Local auth lookup complete");
// The user does not exist in the database. Try to get them from LDAP. // The user does not exist in the database. Try to get them from LDAP.
@ -135,8 +133,8 @@ class LoginController extends Controller
if (Setting::getSettings()->ldap_enabled=='1') { if (Setting::getSettings()->ldap_enabled=='1') {
LOG::debug("LDAP is enabled."); LOG::debug("LDAP is enabled.");
try { try {
$user = $this->login_via_ldap($request); $user = $this->login_via_ldap($request);
Auth::login($user, true); Auth::login($user, true);
// If the user was unable to login via LDAP, log the error and let them fall through to // If the user was unable to login via LDAP, log the error and let them fall through to
// local authentication. // local authentication.
@ -146,20 +144,20 @@ class LoginController extends Controller
} }
// If the user wasn't authenticated via LDAP, skip to local auth // If the user wasn't authenticated via LDAP, skip to local auth
if(!$user) { if (!$user) {
LOG::debug("Authenticating user against database."); LOG::debug("Authenticating user against database.");
// Try to log the user in // Try to log the user in
if (!Auth::attempt(Input::only('username', 'password'), Input::get('remember-me', 0))) { if (!Auth::attempt(Input::only('username', 'password'), Input::get('remember-me', 0))) {
if (!$lockedOut) { if (!$lockedOut) {
$this->incrementLoginAttempts($request); $this->incrementLoginAttempts($request);
} }
LOG::debug("Local authentication failed."); LOG::debug("Local authentication failed.");
return redirect()->back()->withInput()->with('error', trans('auth/message.account_not_found')); return redirect()->back()->withInput()->with('error', trans('auth/message.account_not_found'));
} else { } else {
$this->clearLoginAttempts($request); $this->clearLoginAttempts($request);
} }
} }
// Get the page we were before // Get the page we were before
@ -200,7 +198,7 @@ class LoginController extends Controller
$user->two_factor_secret $user->two_factor_secret
); );
return View::make('auth.two_factor_enroll')->with('google2fa_url',$google2fa_url); return View::make('auth.two_factor_enroll')->with('google2fa_url', $google2fa_url);
} }
@ -210,7 +208,8 @@ class LoginController extends Controller
* *
* @return Redirect * @return Redirect
*/ */
public function getTwoFactorAuth() { public function getTwoFactorAuth()
{
return View::make('auth.two_factor'); return View::make('auth.two_factor');
} }
@ -219,7 +218,8 @@ class LoginController extends Controller
* *
* @return Redirect * @return Redirect
*/ */
public function postTwoFactorAuth(Request $request) { public function postTwoFactorAuth(Request $request)
{
if (!Auth::check()) { if (!Auth::check()) {
return redirect()->route('login')->with('error', 'You must be logged in.'); return redirect()->route('login')->with('error', 'You must be logged in.');
@ -290,7 +290,7 @@ class LoginController extends Controller
$minutes = round($seconds / 60); $minutes = round($seconds / 60);
$message = \Lang::get('auth/message.throttle',['minutes' => $minutes]); $message = \Lang::get('auth/message.throttle', ['minutes' => $minutes]);
return redirect()->back() return redirect()->back()
->withInput($request->only($this->username(), 'remember')) ->withInput($request->only($this->username(), 'remember'))
@ -310,8 +310,9 @@ class LoginController extends Controller
$maxLoginAttempts = config('auth.throttle.max_attempts'); $maxLoginAttempts = config('auth.throttle.max_attempts');
return $this->limiter()->tooManyAttempts( return $this->limiter()->tooManyAttempts(
$this->throttleKey($request), $maxLoginAttempts, $lockoutTime $this->throttleKey($request),
$maxLoginAttempts,
$lockoutTime
); );
} }
} }

View file

@ -264,7 +264,7 @@ class ComponentsController extends Controller
$this->authorize('checkout', $component); $this->authorize('checkout', $component);
$max_to_checkout = $component->numRemaining(); $max_to_checkout = $component->numRemaining();
$validator = Validator::make($request->all(),[ $validator = Validator::make($request->all(), [
"asset_id" => "required", "asset_id" => "required",
"assigned_qty" => "required|numeric|between:1,$max_to_checkout" "assigned_qty" => "required|numeric|between:1,$max_to_checkout"
]); ]);

View file

@ -114,7 +114,7 @@ class CustomFieldsController extends Controller
$field = CustomField::find($field_id); $field = CustomField::find($field_id);
if ($field->fieldset()->detach($fieldset_id)) { if ($field->fieldset()->detach($fieldset_id)) {
return redirect()->route('fieldsets.show',['fieldset' => $fieldset_id])->with("success", trans('admin/custom_fields/message.field.delete.success')); return redirect()->route('fieldsets.show', ['fieldset' => $fieldset_id])->with("success", trans('admin/custom_fields/message.field.delete.success'));
} }
return redirect()->back()->withErrors(['message' => "Field is in-use"]); return redirect()->back()->withErrors(['message' => "Field is in-use"]);

View file

@ -34,24 +34,24 @@ class CustomFieldsetsController extends Controller
* @since [v1.8] * @since [v1.8]
* @return View * @return View
*/ */
public function show($id) public function show($id)
{ {
$cfset = CustomFieldset::with('fields')->where('id','=',$id)->orderBy('id','ASC')->first(); $cfset = CustomFieldset::with('fields')->where('id', '=', $id)->orderBy('id', 'ASC')->first();
$custom_fields_list = ["" => "Add New Field to Fieldset"] + CustomField::pluck("name", "id")->toArray(); $custom_fields_list = ["" => "Add New Field to Fieldset"] + CustomField::pluck("name", "id")->toArray();
$maxid = 0; $maxid = 0;
foreach ($cfset->fields() as $field) { foreach ($cfset->fields() as $field) {
if ($field->pivot->order > $maxid) { if ($field->pivot->order > $maxid) {
$maxid=$field->pivot->order; $maxid=$field->pivot->order;
} }
if (isset($custom_fields_list[$field->id])) { if (isset($custom_fields_list[$field->id])) {
unset($custom_fields_list[$field->id]); unset($custom_fields_list[$field->id]);
}
} }
return View::make("custom_fields.fieldset")->with("custom_fieldset", $cfset)->with("maxid", $maxid+1)->with("custom_fields_list", $custom_fields_list);
} }
return View::make("custom_fields.fieldset")->with("custom_fieldset", $cfset)->with("maxid", $maxid+1)->with("custom_fields_list", $custom_fields_list);
}
/** /**
* Returns a view with a form for creating a new custom fieldset. * Returns a view with a form for creating a new custom fieldset.
@ -80,7 +80,7 @@ class CustomFieldsetsController extends Controller
[ [
"name" => e($request->get("name")), "name" => e($request->get("name")),
"user_id" => Auth::user()->id] "user_id" => Auth::user()->id]
); );
$validator = Validator::make(Input::all(), $cfset->rules); $validator = Validator::make(Input::all(), $cfset->rules);
if ($validator->passes()) { if ($validator->passes()) {
@ -169,5 +169,4 @@ class CustomFieldsetsController extends Controller
return redirect()->route("fieldsets.show", [$id])->with("success", trans('admin/custom_fields/message.field.create.assoc_success')); return redirect()->route("fieldsets.show", [$id])->with("success", trans('admin/custom_fields/message.field.create.assoc_success'));
} }
} }

View file

@ -587,7 +587,7 @@ class LicensesController extends Controller
$upload_success = $file->move($destinationPath, $filename); $upload_success = $file->move($destinationPath, $filename);
//Log the upload to the log //Log the upload to the log
$license->logUpload($filename, e($request->input('notes'))); $license->logUpload($filename, e($request->input('notes')));
} }
if ($upload_success) { if ($upload_success) {

View file

@ -302,7 +302,7 @@ class ManufacturersController extends Controller
'accessories.category', 'accessories.category',
'accessories.manufacturer', 'accessories.manufacturer',
'accessories.users' 'accessories.users'
); );
$accessories = $manufacturer->accessories(); $accessories = $manufacturer->accessories();
if ($request->has('search')) { if ($request->has('search')) {

View file

@ -117,11 +117,11 @@ class ReportsController extends Controller
$customfields = CustomField::get(); $customfields = CustomField::get();
$response = new StreamedResponse(function() use ($customfields) { $response = new StreamedResponse(function () use ($customfields) {
// Open output stream // Open output stream
$handle = fopen('php://output', 'w'); $handle = fopen('php://output', 'w');
Asset::with('assigneduser', 'assetloc','defaultLoc','assigneduser.userloc','model','supplier','assetstatus','model.manufacturer')->orderBy('created_at', 'DESC')->chunk(500, function($assets) use($handle, $customfields) { Asset::with('assigneduser', 'assetloc', 'defaultLoc', 'assigneduser.userloc', 'model', 'supplier', 'assetstatus', 'model.manufacturer')->orderBy('created_at', 'DESC')->chunk(500, function ($assets) use ($handle, $customfields) {
$headers=[ $headers=[
trans('general.company'), trans('general.company'),
trans('admin/hardware/table.asset_tag'), trans('admin/hardware/table.asset_tag'),
@ -140,7 +140,7 @@ class ReportsController extends Controller
trans('admin/hardware/table.location'), trans('admin/hardware/table.location'),
trans('general.notes'), trans('general.notes'),
]; ];
foreach($customfields as $field) { foreach ($customfields as $field) {
$headers[]=$field->name; $headers[]=$field->name;
} }
fputcsv($handle, $headers); fputcsv($handle, $headers);
@ -166,7 +166,7 @@ class ReportsController extends Controller
e($asset->assigneduser->userloc->name) : ( ($asset->defaultLoc!='') ? e($asset->defaultLoc->name) : ''), e($asset->assigneduser->userloc->name) : ( ($asset->defaultLoc!='') ? e($asset->defaultLoc->name) : ''),
($asset->notes) ? e($asset->notes) : '', ($asset->notes) ? e($asset->notes) : '',
]; ];
foreach($customfields as $field) { foreach ($customfields as $field) {
$values[]=$asset->{$field->db_column_name()}; $values[]=$asset->{$field->db_column_name()};
} }
fputcsv($handle, $values); fputcsv($handle, $values);
@ -339,7 +339,7 @@ class ReportsController extends Controller
foreach ($activitylogs as $activity) { foreach ($activitylogs as $activity) {
if (($activity->item) && ($activity->itemType()=="asset")) { if (($activity->item) && ($activity->itemType()=="asset")) {
$activity_item = '<a href="'.route('hardware.show', $activity->item_id).'">'.e($activity->item->asset_tag).' - '. e($activity->item->present()->name()).'</a>'; $activity_item = '<a href="'.route('hardware.show', $activity->item_id).'">'.e($activity->item->asset_tag).' - '. e($activity->item->present()->name()).'</a>';
$item_type = 'asset'; $item_type = 'asset';
} elseif ($activity->item) { } elseif ($activity->item) {
$activity_item = '<a href="' . route($activity->parseItemRoute().'.show', $activity->item_id) . '">' . e($activity->item->name) . '</a>'; $activity_item = '<a href="' . route($activity->parseItemRoute().'.show', $activity->item_id) . '">' . e($activity->item->name) . '</a>';
@ -353,14 +353,14 @@ class ReportsController extends Controller
if (($activity->user) && ($activity->action_type=="uploaded") && ($activity->itemType()=="user")) { if (($activity->user) && ($activity->action_type=="uploaded") && ($activity->itemType()=="user")) {
$activity_target = '<a href="'.route('users.show', $activity->target_id).'">'.$activity->user->present()->fullName().'</a>'; $activity_target = '<a href="'.route('users.show', $activity->target_id).'">'.$activity->user->present()->fullName().'</a>';
} elseif ($activity->target_type === "App\Models\Asset") { } elseif ($activity->target_type === "App\Models\Asset") {
if($activity->target) { if ($activity->target) {
$activity_target = '<a href="'.route('hardware.show', $activity->target_id).'">'.$activity->target->present()->name().'</a>'; $activity_target = '<a href="'.route('hardware.show', $activity->target_id).'">'.$activity->target->present()->name().'</a>';
} else { } else {
$activity_target = ""; $activity_target = "";
} }
} elseif ( $activity->target_type === "App\Models\User") { } elseif ($activity->target_type === "App\Models\User") {
if($activity->target) { if ($activity->target) {
$activity_target = '<a href="'.route('users.show', $activity->target_id).'">'.$activity->target->present()->fullName().'</a>'; $activity_target = '<a href="'.route('users.show', $activity->target_id).'">'.$activity->target->present()->fullName().'</a>';
} else { } else {
$activity_target = ''; $activity_target = '';
} }
@ -374,7 +374,7 @@ class ReportsController extends Controller
$activity_target = ''; $activity_target = '';
} }
} else { } else {
if($activity->target) { if ($activity->target) {
$activity_target = $activity->target->id; $activity_target = $activity->target->id;
} else { } else {
$activity_target = ""; $activity_target = "";
@ -385,7 +385,7 @@ class ReportsController extends Controller
$rows[] = array( $rows[] = array(
'icon' => '<i class="'.$activity->parseItemIcon().'"></i>', 'icon' => '<i class="'.$activity->parseItemIcon().'"></i>',
'created_at' => date("M d, Y g:iA", strtotime($activity->created_at)), 'created_at' => date("M d, Y g:iA", strtotime($activity->created_at)),
'action_type' => strtolower(trans('general.'.str_replace(' ','_',$activity->action_type))), 'action_type' => strtolower(trans('general.'.str_replace(' ', '_', $activity->action_type))),
'admin' => $activity->user ? (string) link_to_route('users.show', $activity->user->present()->fullName(), [$activity->user_id]) : '', 'admin' => $activity->user ? (string) link_to_route('users.show', $activity->user->present()->fullName(), [$activity->user_id]) : '',
'target' => $activity_target, 'target' => $activity_target,
'item' => $activity_item, 'item' => $activity_item,
@ -492,7 +492,7 @@ class ReportsController extends Controller
*/ */
public function postCustom() public function postCustom()
{ {
$assets = Asset::orderBy('created_at', 'DESC')->with('company','assigneduser', 'assetloc','defaultLoc','assigneduser.userloc','model','supplier','assetstatus','model.manufacturer')->get(); $assets = Asset::orderBy('created_at', 'DESC')->with('company', 'assigneduser', 'assetloc', 'defaultLoc', 'assigneduser.userloc', 'model', 'supplier', 'assetstatus', 'model.manufacturer')->get();
$customfields = CustomField::get(); $customfields = CustomField::get();
$rows = [ ]; $rows = [ ];

View file

@ -21,7 +21,6 @@ use App\Models\User;
use App\Http\Requests\SetupUserRequest; use App\Http\Requests\SetupUserRequest;
use App\Http\Requests\ImageUploadRequest; use App\Http\Requests\ImageUploadRequest;
/** /**
* This controller handles all actions related to Settings for * This controller handles all actions related to Settings for
* the Snipe-IT Asset Management application. * the Snipe-IT Asset Management application.
@ -58,7 +57,7 @@ class SettingsController extends Controller
$host = $_SERVER['SERVER_NAME']; $host = $_SERVER['SERVER_NAME'];
if (($protocol === 'http://' && $_SERVER['SERVER_PORT'] != '80') || ($protocol === 'https://' && $_SERVER['SERVER_PORT'] != '443')) { if (($protocol === 'http://' && $_SERVER['SERVER_PORT'] != '80') || ($protocol === 'https://' && $_SERVER['SERVER_PORT'] != '443')) {
$host .= ':' . $_SERVER['SERVER_PORT']; $host .= ':' . $_SERVER['SERVER_PORT'];
} }
$pageURL = $protocol . $host . $_SERVER['REQUEST_URI']; $pageURL = $protocol . $host . $_SERVER['REQUEST_URI'];
@ -443,7 +442,8 @@ class SettingsController extends Controller
} }
public function getLdapTest() { public function getLdapTest()
{
try { try {
$connection = Ldap::connectToLdap(); $connection = Ldap::connectToLdap();

View file

@ -207,7 +207,7 @@ class StatuslabelsController extends Controller
$statuslabel->pending = $statustype['pending']; $statuslabel->pending = $statustype['pending'];
$statuslabel->archived = $statustype['archived']; $statuslabel->archived = $statustype['archived'];
$statuslabel->color = Input::get('color'); $statuslabel->color = Input::get('color');
$statuslabel->show_in_nav = Input::get('show_in_nav',0); $statuslabel->show_in_nav = Input::get('show_in_nav', 0);
// Was the asset created? // Was the asset created?

View file

@ -200,8 +200,10 @@ class SuppliersController extends Controller
// Delete the supplier // Delete the supplier
$supplier->delete(); $supplier->delete();
// Redirect to the suppliers management page // Redirect to the suppliers management page
return redirect()->route('suppliers.index')->with('success', return redirect()->route('suppliers.index')->with(
trans('admin/suppliers/message.delete.success')); 'success',
trans('admin/suppliers/message.delete.success')
);
} }
// Redirect to the asset management page // Redirect to the asset management page
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.assoc_users')); return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.assoc_users'));

View file

@ -217,13 +217,14 @@ class UsersController extends Controller
* @internal param int $id * @internal param int $id
*/ */
private function filterDisplayable($permissions) { private function filterDisplayable($permissions)
{
$output = null; $output = null;
foreach($permissions as $key=>$permission) { foreach ($permissions as $key => $permission) {
$output[$key] = array_filter($permission, function($p) { $output[$key] = array_filter($permission, function ($p) {
return $p['display'] === true; return $p['display'] === true;
}); });
} }
return $output; return $output;
} }
@ -308,7 +309,7 @@ class UsersController extends Controller
if ($request->has('password')) { if ($request->has('password')) {
$user->password = bcrypt($request->input('password')); $user->password = bcrypt($request->input('password'));
} }
if ( $request->has('username')) { if ($request->has('username')) {
$user->username = e($request->input('username')); $user->username = e($request->input('username'));
} }
$user->email = e($request->input('email')); $user->email = e($request->input('email'));
@ -334,7 +335,7 @@ class UsersController extends Controller
if (!Auth::user()->isSuperUser()) { if (!Auth::user()->isSuperUser()) {
unset($permissions_array['superuser']); unset($permissions_array['superuser']);
$permissions_array['superuser'] = $orig_superuser; $permissions_array['superuser'] = $orig_superuser;
} }
$user->permissions = json_encode($permissions_array); $user->permissions = json_encode($permissions_array);
@ -550,7 +551,7 @@ class UsersController extends Controller
*/ */
public function show($userId = null) public function show($userId = null)
{ {
if(!$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId)) { if (!$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId)) {
$error = trans('admin/users/message.user_not_found', compact('id')); $error = trans('admin/users/message.user_not_found', compact('id'));
// Redirect to the user management page // Redirect to the user management page
return redirect()->route('users.index')->with('error', $error); return redirect()->route('users.index')->with('error', $error);
@ -815,7 +816,7 @@ class UsersController extends Controller
'users.company_id', 'users.company_id',
'users.deleted_at', 'users.deleted_at',
'users.activated' 'users.activated'
])->with('manager', 'groups', 'userloc', 'company','throttle'); ])->with('manager', 'groups', 'userloc', 'company', 'throttle');
$users = Company::scopeCompanyables($users); $users = Company::scopeCompanyables($users);
switch ($status) { switch ($status) {
@ -1036,13 +1037,13 @@ class UsersController extends Controller
try { try {
$ldapconn = Ldap::connectToLdap(); $ldapconn = Ldap::connectToLdap();
} catch (\Exception $e) { } catch (\Exception $e) {
return redirect()->back()->withInput()->with('error',$e->getMessage()); return redirect()->back()->withInput()->with('error', $e->getMessage());
} }
try { try {
Ldap::bindAdminToLdap($ldapconn); Ldap::bindAdminToLdap($ldapconn);
} catch (\Exception $e) { } catch (\Exception $e) {
return redirect()->back()->withInput()->with('error',$e->getMessage()); return redirect()->back()->withInput()->with('error', $e->getMessage());
} }
$summary = array(); $summary = array();
@ -1128,11 +1129,11 @@ class UsersController extends Controller
$this->authorize('view', User::class); $this->authorize('view', User::class);
\Debugbar::disable(); \Debugbar::disable();
$response = new StreamedResponse(function() { $response = new StreamedResponse(function () {
// Open output stream // Open output stream
$handle = fopen('php://output', 'w'); $handle = fopen('php://output', 'w');
User::with('assets', 'accessories', 'consumables', 'licenses', 'manager', 'groups', 'userloc', 'company','throttle')->orderBy('created_at', 'DESC')->chunk(500, function($users) use($handle) { User::with('assets', 'accessories', 'consumables', 'licenses', 'manager', 'groups', 'userloc', 'company', 'throttle')->orderBy('created_at', 'DESC')->chunk(500, function ($users) use ($handle) {
$headers=[ $headers=[
// strtolower to prevent Excel from trying to open it as a SYLK file // strtolower to prevent Excel from trying to open it as a SYLK file
strtolower(trans('general.id')), strtolower(trans('general.id')),

View file

@ -315,7 +315,7 @@ class ViewAssetsController extends Controller
} elseif (!Company::isCurrentUserHasAccess($item)) { } elseif (!Company::isCurrentUserHasAccess($item)) {
return redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions')); return redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions'));
} else { } else {
return View::make('account/accept-asset', compact('item'))->with('findlog', $findlog)->with('item',$item); return View::make('account/accept-asset', compact('item'))->with('findlog', $findlog)->with('item', $item);
} }
} }

View file

@ -19,7 +19,7 @@ class CheckForDebug
view()->share('debug_in_production', false); view()->share('debug_in_production', false);
if (((Auth::check() && (Auth::user()->isSuperUser()))) && (app()->environment()=='production') && (config('app.warn_debug')===true) && (config('app.debug')===true)) { if (((Auth::check() && (Auth::user()->isSuperUser()))) && (app()->environment()=='production') && (config('app.warn_debug')===true) && (config('app.debug')===true)) {
view()->share('debug_in_production', true); view()->share('debug_in_production', true);
} }
return $next($request); return $next($request);

View file

@ -8,7 +8,6 @@
namespace App\Importer; namespace App\Importer;
use App\Helpers\Helper; use App\Helpers\Helper;
use App\Models\Accessory; use App\Models\Accessory;
@ -41,7 +40,7 @@ class AccessoryImporter extends ItemImporter
$accessory = $this->accessories->search(function ($key) { $accessory = $this->accessories->search(function ($key) {
return strcasecmp($key->name, $this->item['item_name']) == 0; return strcasecmp($key->name, $this->item['item_name']) == 0;
}); });
if($accessory) { if ($accessory) {
$editingAccessory = true; $editingAccessory = true;
if (!$this->updating) { if (!$this->updating) {
$this->log('A matching Accessory ' . $this->item["item_name"] . ' already exists. '); $this->log('A matching Accessory ' . $this->item["item_name"] . ' already exists. ');
@ -101,10 +100,10 @@ class AccessoryImporter extends ItemImporter
// $this->comment('Accessory ' . $this->item["item_name"] . ' was created'); // $this->comment('Accessory ' . $this->item["item_name"] . ' was created');
} else { } else {
$this->jsonError($accessory,'Accessory', $accessory->getErrors()) ; $this->jsonError($accessory, 'Accessory', $accessory->getErrors()) ;
} }
} else { } else {
$this->log('TEST RUN - Accessory ' . $this->item["item_name"] . ' not created'); $this->log('TEST RUN - Accessory ' . $this->item["item_name"] . ' not created');
} }
} }
} }

View file

@ -8,7 +8,6 @@
namespace App\Importer; namespace App\Importer;
use App\Helpers\Helper; use App\Helpers\Helper;
use App\Models\Asset; use App\Models\Asset;
use App\Models\Category; use App\Models\Category;
@ -52,7 +51,7 @@ class AssetImporter extends ItemImporter
$asset = $this->assets->search(function ($key) { $asset = $this->assets->search(function ($key) {
return strcasecmp($key->asset_tag, $this->item['asset_tag']) == 0; return strcasecmp($key->asset_tag, $this->item['asset_tag']) == 0;
}); });
if($asset) { if ($asset) {
$editingAsset = true; $editingAsset = true;
if (!$this->updating) { if (!$this->updating) {
$this->log('A matching Asset ' . $this->item['asset_tag'] . ' already exists'); $this->log('A matching Asset ' . $this->item['asset_tag'] . ' already exists');
@ -91,7 +90,7 @@ class AssetImporter extends ItemImporter
if (isset($this->item["status_label"])) { if (isset($this->item["status_label"])) {
$status_id = $this->item["status_label"]->id; $status_id = $this->item["status_label"]->id;
} else if (!$editingAsset) { } elseif (!$editingAsset) {
// Assume if we are editing, we already have a status and can ignore. // Assume if we are editing, we already have a status and can ignore.
$this->log("No status field found, defaulting to first status."); $this->log("No status field found, defaulting to first status.");
$status_id = $this->status_labels->first()->id; $status_id = $this->status_labels->first()->id;
@ -173,4 +172,4 @@ class AssetImporter extends ItemImporter
} }
} }
} }
} }

View file

@ -8,7 +8,6 @@
namespace App\Importer; namespace App\Importer;
use App\Helpers\Helper; use App\Helpers\Helper;
use App\Models\Consumable; use App\Models\Consumable;
@ -41,7 +40,7 @@ class ConsumableImporter extends ItemImporter
$consumable = $this->consumables->search(function ($key) { $consumable = $this->consumables->search(function ($key) {
return strcasecmp($key->name, $this->item['item_name']) == 0; return strcasecmp($key->name, $this->item['item_name']) == 0;
}); });
if($consumable) { if ($consumable) {
$editingConsumable = true; $editingConsumable = true;
if (!$this->updating) { if (!$this->updating) {
$this->log('A matching Consumable ' . $this->item["item_name"] . ' already exists. '); $this->log('A matching Consumable ' . $this->item["item_name"] . ' already exists. ');
@ -102,4 +101,4 @@ class ConsumableImporter extends ItemImporter
$this->log('TEST RUN - Consumable ' . $this->item['item_name'] . ' not created'); $this->log('TEST RUN - Consumable ' . $this->item['item_name'] . ' not created');
} }
} }
} }

View file

@ -1,7 +1,6 @@
<?php <?php
namespace App\Importer; namespace App\Importer;
use App\Models\AssetModel; use App\Models\AssetModel;
use App\Models\Category; use App\Models\Category;
use App\Models\Company; use App\Models\Company;
@ -69,15 +68,17 @@ abstract class Importer
* @param bool $updating * @param bool $updating
* @param null $usernameFormat * @param null $usernameFormat
*/ */
function __construct(string $filename, function __construct(
$logCallback, string $filename,
$progressCallback, $logCallback,
$errorCallback, $progressCallback,
$testRun = false, $errorCallback,
$user_id = -1, $testRun = false,
$updating = false, $user_id = -1,
$usernameFormat = null) $updating = false,
{ $usernameFormat = null
) {
$this->filename = $filename; $this->filename = $filename;
$this->csv = Reader::createFromPath($filename); $this->csv = Reader::createFromPath($filename);
$this->csv->setNewLine('\r\n'); $this->csv->setNewLine('\r\n');
@ -85,7 +86,7 @@ abstract class Importer
ini_set("auto_detect_line_endings", '1'); ini_set("auto_detect_line_endings", '1');
} }
$this->testRun = $testRun; $this->testRun = $testRun;
if($user_id == -1) { if ($user_id == -1) {
$user_id = Auth::id(); $user_id = Auth::id();
} }
$this->user_id = $user_id; $this->user_id = $user_id;
@ -193,11 +194,13 @@ abstract class Importer
return array_key_exists($index_name, $array) ? e(trim($array[$index_name])) : ''; return array_key_exists($index_name, $array) ? e(trim($array[$index_name])) : '';
} }
protected function log($string) { protected function log($string)
{
call_user_func($this->logCallback, $string); call_user_func($this->logCallback, $string);
} }
protected function jsonError($item, $field, $errorString) { protected function jsonError($item, $field, $errorString)
{
call_user_func($this->errorCallback, $item, $field, $errorString); call_user_func($this->errorCallback, $item, $field, $errorString);
} }
@ -276,10 +279,10 @@ abstract class Importer
if ($user->save()) { if ($user->save()) {
$this->log('User '.$first_name.' created'); $this->log('User '.$first_name.' created');
} else { } else {
$this->jsonError($user,'User "' . $first_name . '"', $user->getErrors()); $this->jsonError($user, 'User "' . $first_name . '"', $user->getErrors());
} }
} }
} }
return $user; return $user;
} }
} }

View file

@ -2,7 +2,6 @@
namespace App\Importer; namespace App\Importer;
use App\Models\AssetModel; use App\Models\AssetModel;
use App\Models\Category; use App\Models\Category;
use App\Models\Company; use App\Models\Company;
@ -91,7 +90,7 @@ class ItemImporter extends Importer
}); });
// We need strict compare here because the index returned above can be 0. // We need strict compare here because the index returned above can be 0.
// This casts to false and causes false positives // This casts to false and causes false positives
if(($asset_model !== false) && !$editingModel) { if (($asset_model !== false) && !$editingModel) {
return $this->asset_models[$asset_model]; return $this->asset_models[$asset_model];
} else { } else {
$this->log("No Matching Model, Creating a new one"); $this->log("No Matching Model, Creating a new one");
@ -116,7 +115,7 @@ class ItemImporter extends Importer
$this->log('Asset Model ' . $asset_model_name . ' with model number ' . $asset_modelNumber . ' was created'); $this->log('Asset Model ' . $asset_model_name . ' with model number ' . $asset_modelNumber . ' was created');
return $asset_model; return $asset_model;
} else { } else {
$this->jsonError($asset_model,'Asset Model "' . $asset_model_name . '"', $asset_model->getErrors()); $this->jsonError($asset_model, 'Asset Model "' . $asset_model_name . '"', $asset_model->getErrors());
$this->log('Asset Model "' . $asset_model_name . '"' . $asset_model->getErrors()); $this->log('Asset Model "' . $asset_model_name . '"' . $asset_model->getErrors());
return $asset_model; return $asset_model;
} }
@ -186,12 +185,12 @@ class ItemImporter extends Importer
*/ */
public function createOrFetchCompany($asset_company_name) public function createOrFetchCompany($asset_company_name)
{ {
$company = $this->companies->search(function ($key) use($asset_company_name) { $company = $this->companies->search(function ($key) use ($asset_company_name) {
return strcasecmp($key->name, $asset_company_name) == 0; return strcasecmp($key->name, $asset_company_name) == 0;
}); });
// We need strict compare here because the index returned above can be 0. // We need strict compare here because the index returned above can be 0.
// This casts to false and causes false positives // This casts to false and causes false positives
if($company !== false) { if ($company !== false) {
$this->log('A matching Company ' . $asset_company_name . ' already exists'); $this->log('A matching Company ' . $asset_company_name . ' already exists');
return $this->companies[$company]; return $this->companies[$company];
} }
@ -225,7 +224,7 @@ class ItemImporter extends Importer
if (empty($asset_statuslabel_name)) { if (empty($asset_statuslabel_name)) {
return null; return null;
} }
$status = $this->status_labels->search(function ($key) use($asset_statuslabel_name) { $status = $this->status_labels->search(function ($key) use ($asset_statuslabel_name) {
return strcasecmp($key->name, $asset_statuslabel_name) == 0; return strcasecmp($key->name, $asset_statuslabel_name) == 0;
}); });
// We need strict compare here because the index returned above can be 0. // We need strict compare here because the index returned above can be 0.
@ -248,7 +247,7 @@ class ItemImporter extends Importer
$this->log('Status ' . $asset_statuslabel_name . ' was created'); $this->log('Status ' . $asset_statuslabel_name . ' was created');
return $status; return $status;
} else { } else {
$this->jsonError($status,'Status "'. $asset_statuslabel_name . '"', $status->getErrors()); $this->jsonError($status, 'Status "'. $asset_statuslabel_name . '"', $status->getErrors());
return $status; return $status;
} }
} else { } else {
@ -272,7 +271,7 @@ class ItemImporter extends Importer
if (empty($item_manufacturer)) { if (empty($item_manufacturer)) {
$item_manufacturer='Unknown'; $item_manufacturer='Unknown';
} }
$manufacturer = $this->manufacturers->search(function ($key) use($item_manufacturer) { $manufacturer = $this->manufacturers->search(function ($key) use ($item_manufacturer) {
return strcasecmp($key->name, $item_manufacturer) == 0; return strcasecmp($key->name, $item_manufacturer) == 0;
}); });
// We need strict compare here because the index returned above can be 0. // We need strict compare here because the index returned above can be 0.
@ -317,7 +316,7 @@ class ItemImporter extends Importer
$this->log('No location given, so none created.'); $this->log('No location given, so none created.');
return null; return null;
} }
$location = $this->locations->search(function ($key) use($asset_location) { $location = $this->locations->search(function ($key) use ($asset_location) {
return strcasecmp($key->name, $asset_location) == 0; return strcasecmp($key->name, $asset_location) == 0;
}); });
// We need strict compare here because the index returned above can be 0. // We need strict compare here because the index returned above can be 0.
@ -366,7 +365,7 @@ class ItemImporter extends Importer
$item_supplier='Unknown'; $item_supplier='Unknown';
} }
$supplier = $this->suppliers->search(function ($key) use($item_supplier) { $supplier = $this->suppliers->search(function ($key) use ($item_supplier) {
return strcasecmp($key->name, $item_supplier) == 0; return strcasecmp($key->name, $item_supplier) == 0;
}); });
// We need strict compare here because the index returned above can be 0. // We need strict compare here because the index returned above can be 0.
@ -394,6 +393,4 @@ class ItemImporter extends Importer
return $supplier; return $supplier;
} }
} }
}
}

View file

@ -26,15 +26,15 @@ class Actionlog extends Model
public static function boot() public static function boot()
{ {
parent::boot(); parent::boot();
static::creating( function (Actionlog $actionlog) { static::creating(function (Actionlog $actionlog) {
// If the admin is a superadmin, let's see if the target instead has a company. // If the admin is a superadmin, let's see if the target instead has a company.
if (Auth::user() && Auth::user()->isSuperUser()) { if (Auth::user() && Auth::user()->isSuperUser()) {
if ($actionlog->target) { if ($actionlog->target) {
$actionlog->company_id = $actionlog->target->company_id; $actionlog->company_id = $actionlog->target->company_id;
} else if ($actionlog->item) { } elseif ($actionlog->item) {
$actionlog->company_id = $actionlog->item->company_id; $actionlog->company_id = $actionlog->item->company_id;
} }
} else if (Auth::user() && Auth::user()->company) { } elseif (Auth::user() && Auth::user()->company) {
$actionlog->company_id = Auth::user()->company_id; $actionlog->company_id = Auth::user()->company_id;
} }
}); });
@ -45,27 +45,29 @@ class Actionlog extends Model
return $this->morphTo('item')->withTrashed(); return $this->morphTo('item')->withTrashed();
} }
public function company() { public function company()
return $this->hasMany('\App\Models\Company', 'id','company_id'); {
return $this->hasMany('\App\Models\Company', 'id', 'company_id');
} }
public function itemType() public function itemType()
{ {
if($this->item_type == AssetModel::class) { if ($this->item_type == AssetModel::class) {
return "model"; return "model";
} }
return camel_case(class_basename($this->item_type)); return camel_case(class_basename($this->item_type));
} }
public function parseItemRoute() { public function parseItemRoute()
{
if ($this->itemType() == "asset") { if ($this->itemType() == "asset") {
$itemroute = 'assets'; $itemroute = 'assets';
} elseif ($this->itemType() == "accessory") { } elseif ($this->itemType() == "accessory") {
$itemroute = 'accessories'; $itemroute = 'accessories';
} elseif ($this->itemType()=="consumable") { } elseif ($this->itemType()=="consumable") {
$itemroute = 'consumables'; $itemroute = 'consumables';
} elseif ($this->itemType()=="license"){ } elseif ($this->itemType()=="license") {
$itemroute = 'licenses'; $itemroute = 'licenses';
} elseif ($this->itemType()=="component") { } elseif ($this->itemType()=="component") {
$itemroute = 'components'; $itemroute = 'components';
@ -77,14 +79,15 @@ class Actionlog extends Model
} }
public function parseItemIcon() { public function parseItemIcon()
{
if ($this->itemType() == "asset") { if ($this->itemType() == "asset") {
$itemicon = 'fa fa-barcode'; $itemicon = 'fa fa-barcode';
} elseif ($this->itemType() == "accessory") { } elseif ($this->itemType() == "accessory") {
$itemicon = 'fa fa-keyboard-o'; $itemicon = 'fa fa-keyboard-o';
} elseif ($this->itemType()=="consumable") { } elseif ($this->itemType()=="consumable") {
$itemicon = 'fa fa-tint'; $itemicon = 'fa fa-tint';
} elseif ($this->itemType()=="license"){ } elseif ($this->itemType()=="license") {
$itemicon = 'fa fa-floppy-o'; $itemicon = 'fa fa-floppy-o';
} elseif ($this->itemType()=="component") { } elseif ($this->itemType()=="component") {
$itemicon = 'fa fa-hdd-o'; $itemicon = 'fa fa-hdd-o';

View file

@ -74,7 +74,7 @@ class Asset extends Depreciable
public function availableForCheckout() public function availableForCheckout()
{ {
return ( return (
empty($this->assigned_to) && empty($this->assigned_to) &&
$this->assetstatus->deployable == 1 && $this->assetstatus->deployable == 1 &&
empty($this->deleted_at) empty($this->deleted_at)
@ -105,7 +105,7 @@ class Asset extends Depreciable
$this->assigneduser()->associate($user); $this->assigneduser()->associate($user);
if($name != null) { if ($name != null) {
$this->name = $name; $this->name = $name;
} }
@ -359,7 +359,7 @@ class Asset extends Depreciable
->max('id'); ->max('id');
if ($settings->zerofill_count > 0) { if ($settings->zerofill_count > 0) {
return $settings->auto_increment_prefix.Asset::zerofill(($asset_tag + 1),$settings->zerofill_count); return $settings->auto_increment_prefix.Asset::zerofill(($asset_tag + 1), $settings->zerofill_count);
} }
return $settings->auto_increment_prefix.($asset_tag + 1); return $settings->auto_increment_prefix.($asset_tag + 1);
} else { } else {
@ -368,7 +368,7 @@ class Asset extends Depreciable
} }
public static function zerofill ($num, $zerofill = 3) public static function zerofill($num, $zerofill = 3)
{ {
return str_pad($num, $zerofill, '0', STR_PAD_LEFT); return str_pad($num, $zerofill, '0', STR_PAD_LEFT);
} }

View file

@ -58,7 +58,7 @@ class AssetMaintenance extends Model implements ICompanyableChild
public function setIsWarrantyAttribute($value) public function setIsWarrantyAttribute($value)
{ {
if($value == '') { if ($value == '') {
$value = 0; $value = 0;
} }
$this->attributes['is_warranty'] = $value; $this->attributes['is_warranty'] = $value;
@ -70,7 +70,7 @@ class AssetMaintenance extends Model implements ICompanyableChild
public function setCostAttribute($value) public function setCostAttribute($value)
{ {
$value = Helper::ParseFloat($value); $value = Helper::ParseFloat($value);
if($value == '0.0') { if ($value == '0.0') {
$value = null; $value = null;
} }
$this->attributes['cost'] = $value; $this->attributes['cost'] = $value;
@ -81,7 +81,7 @@ class AssetMaintenance extends Model implements ICompanyableChild
*/ */
public function setNotesAttribute($value) public function setNotesAttribute($value)
{ {
if($value == '') { if ($value == '') {
$value = null; $value = null;
} }
$this->attributes['notes'] = $value; $this->attributes['notes'] = $value;
@ -92,7 +92,7 @@ class AssetMaintenance extends Model implements ICompanyableChild
*/ */
public function setCompletionDateAttribute($value) public function setCompletionDateAttribute($value)
{ {
if($value == '' || $value == "0000-00-00") { if ($value == '' || $value == "0000-00-00") {
$value = null; $value = null;
} }
$this->attributes['completion_date'] = $value; $this->attributes['completion_date'] = $value;

View file

@ -41,7 +41,8 @@ class AssetModel extends SnipeModel
protected $injectUniqueIdentifier = true; protected $injectUniqueIdentifier = true;
use ValidatingTrait; use ValidatingTrait;
public function setEolAttribute($value) { public function setEolAttribute($value)
{
if ($value == '') { if ($value == '') {
$value = 0; $value = 0;
} }

View file

@ -164,26 +164,32 @@ final class Company extends SnipeModel
} }
} }
public function users() { public function users()
{
return $this->hasMany(User::class); return $this->hasMany(User::class);
} }
public function assets() { public function assets()
{
return $this->hasMany(Asset::class); return $this->hasMany(Asset::class);
} }
public function licenses() { public function licenses()
{
return $this->hasMany(License::class); return $this->hasMany(License::class);
} }
public function accessories() { public function accessories()
{
return $this->hasMany(Accessory::class); return $this->hasMany(Accessory::class);
} }
public function consumables() { public function consumables()
{
return $this->hasMany(Consumable::class); return $this->hasMany(Consumable::class);
} }
public function components() { public function components()
{
return $this->hasMany(Component::class); return $this->hasMany(Component::class);
} }
} }

View file

@ -37,7 +37,7 @@ class CustomField extends Model
{ {
self::creating(function ($custom_field) { self::creating(function ($custom_field) {
if (Schema::hasColumn(CustomField::$table_name,$custom_field->db_column_name())) { if (Schema::hasColumn(CustomField::$table_name, $custom_field->db_column_name())) {
//field already exists when making a new custom field; fail. //field already exists when making a new custom field; fail.
return false; return false;
} }
@ -50,20 +50,20 @@ class CustomField extends Model
self::updating(function ($custom_field) { self::updating(function ($custom_field) {
if ($custom_field->isDirty("name")) { if ($custom_field->isDirty("name")) {
if (Schema::hasColumn(CustomField::$table_name,$custom_field->db_column_name())) { if (Schema::hasColumn(CustomField::$table_name, $custom_field->db_column_name())) {
//field already exists when renaming a custom field //field already exists when renaming a custom field
return false; return false;
} }
return Schema::table(CustomField::$table_name, function ($table) use ($custom_field) { return Schema::table(CustomField::$table_name, function ($table) use ($custom_field) {
$table->renameColumn(self::name_to_db_name($custom_field->getOriginal("name")),$custom_field->db_column_name()); $table->renameColumn(self::name_to_db_name($custom_field->getOriginal("name")), $custom_field->db_column_name());
}); });
} }
return true; return true;
}); });
self::deleting(function ($custom_field) { self::deleting(function ($custom_field) {
return Schema::table(CustomField::$table_name,function ($table) use ($custom_field) { return Schema::table(CustomField::$table_name, function ($table) use ($custom_field) {
$table->dropColumn(self::name_to_db_name($custom_field->getOriginal("name"))); $table->dropColumn(self::name_to_db_name($custom_field->getOriginal("name")));
}); });
}); });
} }
@ -122,7 +122,8 @@ class CustomField extends Model
* @since [v3.4] * @since [v3.4]
* @return Array * @return Array
*/ */
public function formatFieldValuesAsArray() { public function formatFieldValuesAsArray()
{
$arr = preg_split("/\\r\\n|\\r|\\n/", $this->field_values); $arr = preg_split("/\\r\\n|\\r|\\n/", $this->field_values);
$result[''] = 'Select '.strtolower($this->format); $result[''] = 'Select '.strtolower($this->format);
@ -130,7 +131,7 @@ class CustomField extends Model
for ($x = 0; $x < count($arr); $x++) { for ($x = 0; $x < count($arr); $x++) {
$arr_parts = explode('|', $arr[$x]); $arr_parts = explode('|', $arr[$x]);
if ($arr_parts[0]!='') { if ($arr_parts[0]!='') {
if (key_exists('1',$arr_parts)) { if (key_exists('1', $arr_parts)) {
$result[$arr_parts[0]] = $arr_parts[1]; $result[$arr_parts[0]] = $arr_parts[1];
} else { } else {
$result[$arr_parts[0]] = $arr_parts[0]; $result[$arr_parts[0]] = $arr_parts[0];
@ -143,14 +144,11 @@ class CustomField extends Model
return $result; return $result;
} }
public function isFieldDecryptable($string) { public function isFieldDecryptable($string)
{
if (($this->field_encrypted=='1') && ($string!='')) { if (($this->field_encrypted=='1') && ($string!='')) {
return true; return true;
} }
return false; return false;
} }
} }

View file

@ -34,9 +34,7 @@ class CustomFieldset extends Model
$rule = []; $rule = [];
if (($field->field_encrypted!='1') || if (($field->field_encrypted!='1') ||
(($field->field_encrypted =='1') && (Gate::allows('admin')) )) (($field->field_encrypted =='1') && (Gate::allows('admin')) )) {
{
if ($field->pivot->required) { if ($field->pivot->required) {
$rule[]="required"; $rule[]="required";
} }
@ -47,5 +45,4 @@ class CustomFieldset extends Model
} }
return $rules; return $rules;
} }
} }

View file

@ -8,7 +8,6 @@ use Exception;
use Input; use Input;
use Log; use Log;
class Ldap extends Model class Ldap extends Model
{ {
@ -36,8 +35,8 @@ class Ldap extends Model
} }
// If the user specifies where CA Certs are, make sure to use them // If the user specifies where CA Certs are, make sure to use them
if(env("LDAPTLS_CACERT")) { if (env("LDAPTLS_CACERT")) {
putenv("LDAPTLS_CACERT=".env("LDAPTLS_CACERT")); putenv("LDAPTLS_CACERT=".env("LDAPTLS_CACERT"));
} }
$connection = @ldap_connect($ldap_host); $connection = @ldap_connect($ldap_host);
@ -78,13 +77,10 @@ class Ldap extends Model
$ldap_username_field = $settings->ldap_username_field; $ldap_username_field = $settings->ldap_username_field;
$baseDn = $settings->ldap_basedn; $baseDn = $settings->ldap_basedn;
if ($settings->is_ad =='1') if ($settings->is_ad =='1') {
{ // Check if they are using the userprincipalname for the username field.
// Check if they are using the userprincipalname for the username field.
// If they are, we can skip building the UPN to authenticate against AD // If they are, we can skip building the UPN to authenticate against AD
if ($ldap_username_field=='userprincipalname') if ($ldap_username_field=='userprincipalname') {
{
$userDn = $username; $userDn = $username;
} else { } else {
// In case they haven't added an AD domain // In case they haven't added an AD domain
@ -238,7 +234,8 @@ class Ldap extends Model
* @param $ldapatttibutes * @param $ldapatttibutes
* @return array|bool * @return array|bool
*/ */
static function findLdapUsers() { static function findLdapUsers()
{
$ldapconn = Ldap::connectToLdap(); $ldapconn = Ldap::connectToLdap();
$ldap_bind = Ldap::bindAdminToLdap($ldapconn); $ldap_bind = Ldap::bindAdminToLdap($ldapconn);
@ -291,8 +288,4 @@ class Ldap extends Model
} }
} }

View file

@ -35,7 +35,7 @@ class License extends Depreciable
public function setExpirationDateAttribute($value) public function setExpirationDateAttribute($value)
{ {
if($value == '' || $value == '0000-00-00') { if ($value == '' || $value == '0000-00-00') {
$value = null; $value = null;
} }
$this->attributes['expiration_date'] = $value; $this->attributes['expiration_date'] = $value;
@ -43,7 +43,7 @@ class License extends Depreciable
public function setTerminationDateAttribute($value) public function setTerminationDateAttribute($value)
{ {
if($value == '' || $value == '0000-00-00') { if ($value == '' || $value == '0000-00-00') {
$value = null; $value = null;
} }
$this->attributes['termination_date'] = $value; $this->attributes['termination_date'] = $value;
@ -261,8 +261,8 @@ class License extends Depreciable
->orWhereHas('manufacturer', function ($query) use ($search) { ->orWhereHas('manufacturer', function ($query) use ($search) {
$query->where(function ($query) use ($search) { $query->where(function ($query) use ($search) {
$query->where('manufacturers.name', 'LIKE', '%'.$search.'%'); $query->where('manufacturers.name', 'LIKE', '%'.$search.'%');
}); });
}) })
->orWhereHas('company', function ($query) use ($search) { ->orWhereHas('company', function ($query) use ($search) {
$query->where(function ($query) use ($search) { $query->where(function ($query) use ($search) {
$query->where('companies.name', 'LIKE', '%'.$search.'%'); $query->where('companies.name', 'LIKE', '%'.$search.'%');

View file

@ -47,7 +47,7 @@ trait Loggable
if (!is_null($this->asset_id) || isset($target)) { if (!is_null($this->asset_id) || isset($target)) {
$log->target_type = Asset::class; $log->target_type = Asset::class;
$log->target_id = $this->asset_id; $log->target_id = $this->asset_id;
} else if (!is_null($this->assigned_to)) { } elseif (!is_null($this->assigned_to)) {
$log->target_type = User::class; $log->target_type = User::class;
$log->target_id = $this->assigned_to; $log->target_id = $this->assigned_to;
} }

View file

@ -51,11 +51,11 @@ class Setting extends Model
{ {
static $static_cache = null; static $static_cache = null;
if (!$static_cache) { if (!$static_cache) {
if (Schema::hasTable('settings')) { if (Schema::hasTable('settings')) {
$static_cache = Setting::first(); $static_cache = Setting::first();
}
} }
}
return $static_cache; return $static_cache;

View file

@ -10,7 +10,7 @@ class SnipeModel extends Model
// Setters that are appropriate across multiple models. // Setters that are appropriate across multiple models.
public function setPurchaseDateAttribute($value) public function setPurchaseDateAttribute($value)
{ {
if($value == '') { if ($value == '') {
$value = null; $value = null;
} }
$this->attributes['purchase_date'] = $value; $this->attributes['purchase_date'] = $value;
@ -22,7 +22,7 @@ class SnipeModel extends Model
public function setPurchaseCostAttribute($value) public function setPurchaseCostAttribute($value)
{ {
$value = Helper::ParseFloat($value); $value = Helper::ParseFloat($value);
if($value == '0.0') { if ($value == '0.0') {
$value = null; $value = null;
} }
$this->attributes['purchase_cost'] = $value; $this->attributes['purchase_cost'] = $value;
@ -30,7 +30,7 @@ class SnipeModel extends Model
public function setLocationIdAttribute($value) public function setLocationIdAttribute($value)
{ {
if($value == '') { if ($value == '') {
$value = null; $value = null;
} }
$this->attributes['location_id'] = $value; $this->attributes['location_id'] = $value;
@ -38,7 +38,7 @@ class SnipeModel extends Model
public function setCategoryIdAttribute($value) public function setCategoryIdAttribute($value)
{ {
if($value == '') { if ($value == '') {
$value = null; $value = null;
} }
$this->attributes['category_id'] = $value; $this->attributes['category_id'] = $value;
@ -46,7 +46,7 @@ class SnipeModel extends Model
public function setSupplierIdAttribute($value) public function setSupplierIdAttribute($value)
{ {
if($value == '') { if ($value == '') {
$value = null; $value = null;
} }
$this->attributes['supplier_id'] = $value; $this->attributes['supplier_id'] = $value;
@ -54,7 +54,7 @@ class SnipeModel extends Model
public function setDepreciationIdAttribute($value) public function setDepreciationIdAttribute($value)
{ {
if($value == '') { if ($value == '') {
$value = null; $value = null;
} }
$this->attributes['depreciation_id'] = $value; $this->attributes['depreciation_id'] = $value;
@ -62,7 +62,7 @@ class SnipeModel extends Model
public function setManufacturerIdAttribute($value) public function setManufacturerIdAttribute($value)
{ {
if($value == '') { if ($value == '') {
$value = null; $value = null;
} }
$this->attributes['manufacturer_id'] = $value; $this->attributes['manufacturer_id'] = $value;

View file

@ -277,7 +277,8 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
->orWhere('username', '=', $user_email); ->orWhere('username', '=', $user_email);
} }
public static function generateEmailFromFullName($name) { public static function generateEmailFromFullName($name)
{
$username = User::generateFormattedNameFromFullName(Setting::getSettings()->email_format, $name); $username = User::generateFormattedNameFromFullName(Setting::getSettings()->email_format, $name);
return $username['username'].'@'.Setting::getSettings()->email_domain; return $username['username'].'@'.Setting::getSettings()->email_domain;
} }

View file

@ -37,12 +37,11 @@ class CheckinNotification extends Notification
public function via($notifiable) public function via($notifiable)
{ {
$notifyBy = []; $notifyBy = [];
if(Setting::getSettings()->slack_endpoint) { if (Setting::getSettings()->slack_endpoint) {
$notifyBy[] = 'slack'; $notifyBy[] = 'slack';
} }
$item = $this->params['item']; $item = $this->params['item'];
if ( if ((method_exists($item, 'requireAcceptance') && ($item->requireAcceptance()=='1'))
(method_exists($item, 'requireAcceptance') && ($item->requireAcceptance()=='1'))
|| (method_exists($item, 'getEula') && ($item->getEula())) || (method_exists($item, 'getEula') && ($item->getEula()))
) { ) {
$notifyBy[] = 'mail'; $notifyBy[] = 'mail';
@ -63,7 +62,7 @@ class CheckinNotification extends Notification
]; ];
array_key_exists('note', $this->params) && $fields['Notes'] = $this->params['note']; array_key_exists('note', $this->params) && $fields['Notes'] = $this->params['note'];
$attachment->title($item->name, $item->present()->viewUrl() ) $attachment->title($item->name, $item->present()->viewUrl())
->fields($fields); ->fields($fields);
}); });
} }

View file

@ -38,13 +38,12 @@ class CheckoutNotification extends Notification
public function via($notifiable) public function via($notifiable)
{ {
$notifyBy = []; $notifyBy = [];
if(Setting::getSettings()->slack_endpoint) { if (Setting::getSettings()->slack_endpoint) {
$notifyBy[] = 'slack'; $notifyBy[] = 'slack';
} }
$item = $this->params['item']; $item = $this->params['item'];
if ( if ((method_exists($item, 'requireAcceptance') && ($item->requireAcceptance()=='1'))
(method_exists($item, 'requireAcceptance') && ($item->requireAcceptance()=='1'))
|| (method_exists($item, 'getEula') && ($item->getEula())) || (method_exists($item, 'getEula') && ($item->getEula()))
) { ) {
$notifyBy[] = 'mail'; $notifyBy[] = 'mail';
@ -68,7 +67,7 @@ class CheckoutNotification extends Notification
]; ];
array_key_exists('note', $this->params) && $fields['Notes'] = $this->params['note']; array_key_exists('note', $this->params) && $fields['Notes'] = $this->params['note'];
$attachment->title($item->name, $item->present()->viewUrl() ) $attachment->title($item->name, $item->present()->viewUrl())
->fields($fields); ->fields($fields);
}); });
} }

View file

@ -41,7 +41,7 @@ class AssetPolicy
return $user->hasAccess('assets.view'); return $user->hasAccess('assets.view');
} }
public function viewRequestable(User $user, Asset $asset=null) public function viewRequestable(User $user, Asset $asset = null)
{ {
return $user->hasAccess('assets.view.requestable'); return $user->hasAccess('assets.view.requestable');
} }
@ -77,5 +77,4 @@ class AssetPolicy
{ {
return $user->hasAccess('assets.edit'); return $user->hasAccess('assets.edit');
} }
} }

View file

@ -70,7 +70,7 @@ class UserPolicy
*/ */
public function delete(User $user, User $targetUser = null) public function delete(User $user, User $targetUser = null)
{ {
if($targetUser) { if ($targetUser) {
//We can't delete ourselves. //We can't delete ourselves.
if ($user->id == $targetUser->id) { if ($user->id == $targetUser->id) {
return false; return false;

View file

@ -8,7 +8,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
@ -133,7 +132,7 @@ class AccessoryPresenter extends Presenter
$results = []; $results = [];
$results['name'] = $this->nameUrl(); $results['name'] = $this->nameUrl();
$results['category'] = ''; $results['category'] = '';
if($this->model->category) { if ($this->model->category) {
$results['category'] = $this->model->category->present()->nameUrl(); $results['category'] = $this->model->category->present()->nameUrl();
} }
$results['model_number'] = $this->model_number; $results['model_number'] = $this->model_number;

View file

@ -8,7 +8,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
/** /**
@ -48,7 +47,7 @@ class AssetModelPresenter extends Presenter
$results['model_number'] = $this->model_number; $results['model_number'] = $this->model_number;
$results['numassets'] = $this->assets()->count(); $results['numassets'] = $this->assets()->count();
$results['depreciation'] = trans('general.no_depreciation'); $results['depreciation'] = trans('general.no_depreciation');
if(($depreciation = $this->model->depreciation) and $depreciation->id > 0) { if (($depreciation = $this->model->depreciation) and $depreciation->id > 0) {
$results['depreciation'] = $depreciation->name.' ('.$depreciation->months.')'; $results['depreciation'] = $depreciation->name.' ('.$depreciation->months.')';
} }
$results['category'] = $this->categoryUrl(); $results['category'] = $this->categoryUrl();
@ -76,7 +75,7 @@ class AssetModelPresenter extends Presenter
public function eolText() public function eolText()
{ {
if($this->eol) { if ($this->eol) {
return $this->eol.' '.trans('general.months'); return $this->eol.' '.trans('general.months');
} }
return ''; return '';
@ -101,7 +100,7 @@ class AssetModelPresenter extends Presenter
*/ */
public function nameUrl() public function nameUrl()
{ {
return (string) link_to_route('models.show',$this->name, $this->id); return (string) link_to_route('models.show', $this->name, $this->id);
} }
/** /**
@ -110,7 +109,7 @@ class AssetModelPresenter extends Presenter
*/ */
public function imageUrl() public function imageUrl()
{ {
if(!empty($this->image)) { if (!empty($this->image)) {
return '<img src="' . url('/') . '/uploads/models/' . $this->image . '" height=50 width=50>'; return '<img src="' . url('/') . '/uploads/models/' . $this->image . '" height=50 width=50>';
} }
return ''; return '';

View file

@ -1,5 +1,6 @@
<?php <?php
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
use App\Models\SnipeModel; use App\Models\SnipeModel;
use DateTime; use DateTime;
@ -10,7 +11,6 @@ use Illuminate\Support\Facades\Gate;
* @package App\Presenters * @package App\Presenters
*/ */
class AssetPresenter extends Presenter class AssetPresenter extends Presenter
{ {
/** /**
@ -48,18 +48,21 @@ class AssetPresenter extends Presenter
$actions .= '</div>'; $actions .= '</div>';
if (($this->model->availableForCheckout())) if (($this->model->availableForCheckout())) {
{
if (Gate::allows('checkout', $this->model)) { if (Gate::allows('checkout', $this->model)) {
$inout = '<a href="' . route('checkout/hardware', $inout = '<a href="' . route(
$this->model->id) . '" class="btn btn-info btn-sm" title="Checkout this asset to a user" data-toggle="tooltip">' . trans('general.checkout') . '</a>'; 'checkout/hardware',
$this->model->id
) . '" class="btn btn-info btn-sm" title="Checkout this asset to a user" data-toggle="tooltip">' . trans('general.checkout') . '</a>';
} }
} else { } else {
if (!empty($this->model->assigned_to)) { if (!empty($this->model->assigned_to)) {
if (Gate::allows('checkin', $this->model)) { if (Gate::allows('checkin', $this->model)) {
$inout = '<a href="' . route('checkin/hardware', $inout = '<a href="' . route(
$this->model->id) . '" class="btn btn-primary btn-sm" title="Checkin this asset" data-toggle="tooltip">' . trans('general.checkin') . '</a>'; 'checkin/hardware',
$this->model->id
) . '" class="btn btn-primary btn-sm" title="Checkin this asset" data-toggle="tooltip">' . trans('general.checkin') . '</a>';
} }
} }
} }
@ -80,16 +83,16 @@ class AssetPresenter extends Presenter
$results['status_label'] = ''; $results['status_label'] = '';
$results['assigned_to'] = ''; $results['assigned_to'] = '';
if($assigned = $this->model->assigneduser) { if ($assigned = $this->model->assigneduser) {
$results['status_label'] = 'Deployed'; $results['status_label'] = 'Deployed';
$results['assigned_to'] = (string) link_to_route('users.show', $assigned->present()->fullName(), $this->assigned_to ); $results['assigned_to'] = (string) link_to_route('users.show', $assigned->present()->fullName(), $this->assigned_to);
} else if($this->model->assetstatus) { } elseif ($this->model->assetstatus) {
$results['status_label'] = $this->model->assetstatus->name; $results['status_label'] = $this->model->assetstatus->name;
} }
$results['location'] = ''; $results['location'] = '';
if (isset($assigned) and !empty($assignedLoc = $assigned->userloc)) { if (isset($assigned) and !empty($assignedLoc = $assigned->userloc)) {
$results['location'] = $assignedLoc->present()->nameUrl(); $results['location'] = $assignedLoc->present()->nameUrl();
} else if (!empty($this->model->defaultLoc)) { } elseif (!empty($this->model->defaultLoc)) {
$results['location'] = $this->model->defaultLoc->present()->nameUrl(); $results['location'] = $this->model->defaultLoc->present()->nameUrl();
} }
@ -98,14 +101,14 @@ class AssetPresenter extends Presenter
$results['purchase_date'] = $this->purchase_date ?: ''; $results['purchase_date'] = $this->purchase_date ?: '';
$results['notes'] = $this->notes; $results['notes'] = $this->notes;
$results['order_number'] = ''; $results['order_number'] = '';
if(!empty($this->order_number)) { if (!empty($this->order_number)) {
$results['order_number'] = link_to_route('hardware.index', $this->order_number, ['order_number' => $this->order_number]); $results['order_number'] = link_to_route('hardware.index', $this->order_number, ['order_number' => $this->order_number]);
} }
$results['last_checkout'] = $this->last_checkout ?: ''; $results['last_checkout'] = $this->last_checkout ?: '';
$results['expected_checkin'] = $this->expected_checkin ?: ''; $results['expected_checkin'] = $this->expected_checkin ?: '';
$results['created_at'] = ''; $results['created_at'] = '';
if(!empty($this->created_at)) { if (!empty($this->created_at)) {
$results['created_at'] = $this->created_at->format('F j, Y h:iA'); $results['created_at'] = $this->created_at->format('F j, Y h:iA');
} }
$results['companyName'] = $this->companyUrl(); $results['companyName'] = $this->companyUrl();
@ -162,7 +165,7 @@ class AssetPresenter extends Presenter
public function modelUrl() public function modelUrl()
{ {
if($this->model->model) { if ($this->model->model) {
return $this->model->model->present()->nameUrl(); return $this->model->model->present()->nameUrl();
} }
return ''; return '';
@ -175,13 +178,13 @@ class AssetPresenter extends Presenter
public function imageUrl() public function imageUrl()
{ {
$imagePath = ''; $imagePath = '';
if($this->image && !empty($this->image)) { if ($this->image && !empty($this->image)) {
$imagePath = $this->image; $imagePath = $this->image;
} else if ($this->model && !empty($this->model->image)) { } elseif ($this->model && !empty($this->model->image)) {
$imagePath = $this->model->image; $imagePath = $this->model->image;
} }
$url = config('app.url'); $url = config('app.url');
if(!empty($imagePath)) { if (!empty($imagePath)) {
$imagePath = "<img src='{$url}/uploads/assets/{$imagePath}' height=50 width=50>"; $imagePath = "<img src='{$url}/uploads/assets/{$imagePath}' height=50 width=50>";
} }
return $imagePath; return $imagePath;

View file

@ -2,7 +2,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
/** /**

View file

@ -2,7 +2,6 @@
namespace App\Presenters; namespace App\Presenters;
/** /**
* Class CompanyPresenter * Class CompanyPresenter
* @package App\Presenters * @package App\Presenters

View file

@ -2,7 +2,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;

View file

@ -2,7 +2,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;

View file

@ -2,7 +2,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
/** /**

View file

@ -2,7 +2,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;

View file

@ -2,7 +2,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
/** /**

View file

@ -2,7 +2,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
/** /**
@ -48,7 +47,7 @@ class ManufacturerPresenter extends Presenter
*/ */
public function nameUrl() public function nameUrl()
{ {
return (string) link_to_route('manufacturers.show', $this->name, $this->id); return (string) link_to_route('manufacturers.show', $this->name, $this->id);
} }
/** /**

View file

@ -2,7 +2,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Models\SnipeModel; use App\Models\SnipeModel;
abstract class Presenter abstract class Presenter
@ -27,11 +26,11 @@ abstract class Presenter
{ {
$model = $this->model; $model = $this->model;
// Category of Asset belongs to model. // Category of Asset belongs to model.
if($model->model) { if ($model->model) {
$model = $this->model->model; $model = $this->model->model;
} }
if($model->category) { if ($model->category) {
return $model->category->present()->nameUrl(); return $model->category->present()->nameUrl();
} }
return ''; return '';
@ -51,12 +50,12 @@ abstract class Presenter
return $this->model->company->present()->nameUrl(); return $this->model->company->present()->nameUrl();
} }
return ''; return '';
} }
public function manufacturerUrl() public function manufacturerUrl()
{ {
$model = $this->model; $model = $this->model;
// Category of Asset belongs to model. // Category of Asset belongs to model.
if($model->model) { if ($model->model) {
$model = $this->model->model; $model = $this->model->model;
} }
@ -68,7 +67,7 @@ abstract class Presenter
public function __get($property) public function __get($property)
{ {
if( method_exists($this, $property)) { if (method_exists($this, $property)) {
return $this->{$property}(); return $this->{$property}();
} }
@ -79,5 +78,4 @@ abstract class Presenter
{ {
return $this->model->$method($args); return $this->model->$method($args);
} }
} }

View file

@ -2,7 +2,6 @@
namespace App\Presenters; namespace App\Presenters;
use App\Helpers\Helper; use App\Helpers\Helper;
use App\Models\Setting; use App\Models\Setting;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -38,8 +37,8 @@ class UserPresenter extends Presenter
$actions .= link_to_route( $actions .= link_to_route(
'unsuspend/user', 'unsuspend/user',
'<span class="fa fa-clock-o"></span>"', '<span class="fa fa-clock-o"></span>"',
$this->id, $this->id,
['class' => 'btn btn-default btn-sm'] ['class' => 'btn btn-default btn-sm']
); );
} }
} }

View file

@ -6,7 +6,6 @@ use Illuminate\Support\ServiceProvider;
use DB; use DB;
use Log; use Log;
/** /**
* This service provider handles a few custom validation rules. * This service provider handles a few custom validation rules.
* *
@ -27,12 +26,11 @@ class AppServiceProvider extends ServiceProvider
{ {
// Email array validator // Email array validator
Validator::extend('email_array', function($attribute, $value, $parameters, $validator) { Validator::extend('email_array', function ($attribute, $value, $parameters, $validator) {
$value = str_replace(' ','',$value); $value = str_replace(' ', '', $value);
$array = explode(',', $value); $array = explode(',', $value);
foreach($array as $email) //loop over values foreach ($array as $email) { //loop over values
{
$email_to_validate['alert_email'][]=$email; $email_to_validate['alert_email'][]=$email;
} }
@ -41,7 +39,7 @@ class AppServiceProvider extends ServiceProvider
'alert_email.*'=>trans('validation.email_array') 'alert_email.*'=>trans('validation.email_array')
); );
$validator = Validator::make($email_to_validate,$rules,$messages); $validator = Validator::make($email_to_validate, $rules, $messages);
if ($validator->passes()) { if ($validator->passes()) {
return true; return true;
@ -54,9 +52,9 @@ class AppServiceProvider extends ServiceProvider
// Unique only if undeleted // Unique only if undeleted
// This works around the use case where multiple deleted items have the same unique attribute. // This works around the use case where multiple deleted items have the same unique attribute.
// (I think this is a bug in Laravel's validator?) // (I think this is a bug in Laravel's validator?)
Validator::extend('unique_undeleted', function($attribute, $value, $parameters, $validator) { Validator::extend('unique_undeleted', function ($attribute, $value, $parameters, $validator) {
$count = DB::table($parameters[0])->select('id')->where($attribute,'=',$value)->whereNull('deleted_at')->where('id','!=',$parameters[1])->count(); $count = DB::table($parameters[0])->select('id')->where($attribute, '=', $value)->whereNull('deleted_at')->where('id', '!=', $parameters[1])->count();
if ($count < 1) { if ($count < 1) {
return true; return true;
@ -91,7 +89,7 @@ class AppServiceProvider extends ServiceProvider
} }
} }
foreach($monolog->getHandlers() as $handler) { foreach ($monolog->getHandlers() as $handler) {
$handler->setLevel($log_level); $handler->setLevel($log_level);
} }
} }

View file

@ -2,7 +2,8 @@
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
class MacroServiceProvider extends ServiceProvider { class MacroServiceProvider extends ServiceProvider
{
/** /**
* Bootstrap the application services. * Bootstrap the application services.
@ -12,9 +13,9 @@ class MacroServiceProvider extends ServiceProvider {
public function boot() public function boot()
{ {
// require base_path() . '/resources/macros/community_types.php'; // require base_path() . '/resources/macros/community_types.php';
foreach(glob(base_path('resources/macros/*.php')) as $filename) { foreach (glob(base_path('resources/macros/*.php')) as $filename) {
require_once($filename); require_once($filename);
} }
} }
@ -27,5 +28,4 @@ class MacroServiceProvider extends ServiceProvider {
{ {
// //
} }
} }

View file

@ -63,7 +63,7 @@ use Carbon\Carbon;
<div class="row"> <div class="row">
<div class="col-md-3 col-sm-3" style="padding-bottom: 10px; margin-left: 15px; word-wrap: break-word;"> <div class="col-md-3 col-sm-3" style="padding-bottom: 10px; margin-left: 15px; word-wrap: break-word;">
<strong>{{ trans('admin/asset_maintenances/form.start_date') }}: </strong> <strong>{{ trans('admin/asset_maintenances/form.start_date') }}: </strong>
<?php $startDate = Carbon::parse($assetMaintenance->start_date); ?> <?php $startDate = Carbon::parse($assetMaintenance->start_date); ?>
{{ $startDate->toDateString() }} {{ $startDate->toDateString() }}
</div> </div>
<div class="col-md-3 col-sm-3" style="padding-bottom: 10px; margin-left: 15px; word-wrap: break-word;"> <div class="col-md-3 col-sm-3" style="padding-bottom: 10px; margin-left: 15px; word-wrap: break-word;">

View file

@ -51,9 +51,9 @@
<?php $model=$item->model; ?> <?php $model=$item->model; ?>
@endif @endif
@if (Input::old('model_id')) @if (Input::old('model_id'))
<?php $model=\App\Models\AssetModel::find(Input::old('model_id')); ?> <?php $model=\App\Models\AssetModel::find(Input::old('model_id')); ?>
@elseif (isset($selected_model)) @elseif (isset($selected_model))
<?php $model=$selected_model; ?> <?php $model=$selected_model; ?>
@endif @endif
@if (isset($model) && $model) @if (isset($model) && $model)
@include("models/custom_fields_form",["model" => $model]) @include("models/custom_fields_form",["model" => $model])
@ -84,12 +84,12 @@
@include ('partials.forms.edit.purchase_date') @include ('partials.forms.edit.purchase_date')
@include ('partials.forms.edit.supplier') @include ('partials.forms.edit.supplier')
@include ('partials.forms.edit.order_number') @include ('partials.forms.edit.order_number')
<?php <?php
$currency_type=null; $currency_type=null;
if ($item->id && $item->assetloc) { if ($item->id && $item->assetloc) {
$currency_type = $item->assetloc->currency; $currency_type = $item->assetloc->currency;
} }
?> ?>
@include ('partials.forms.edit.purchase_cost', ['currency_type' => $currency_type]) @include ('partials.forms.edit.purchase_cost', ['currency_type' => $currency_type])
@include ('partials.forms.edit.warranty') @include ('partials.forms.edit.warranty')
@include ('partials.forms.edit.notes') @include ('partials.forms.edit.notes')

View file

@ -521,7 +521,7 @@
<a href="{{ route('users.show', $assetMaintenance->admin->id) }}">{{ $assetMaintenance->admin->present()->fullName() }}</a> <a href="{{ route('users.show', $assetMaintenance->admin->id) }}">{{ $assetMaintenance->admin->present()->fullName() }}</a>
@endif @endif
</td> </td>
<?php $totalCost += $assetMaintenance->cost; ?> <?php $totalCost += $assetMaintenance->cost; ?>
@can('update', \App\Models\Asset::class) @can('update', \App\Models\Asset::class)
<td> <td>
<a href="{{ route('maintenances.edit', $assetMaintenance->id) }}" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a href="{{ route('maintenances.edit', $assetMaintenance->id) }}" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a>

View file

@ -414,7 +414,7 @@
<a href="{{ url('hardware') }}">@lang('general.list_all')</a> <a href="{{ url('hardware') }}">@lang('general.list_all')</a>
</li> </li>
<?php $status_navs = \App\Models\Statuslabel::where('show_in_nav','=',1)->get(); ?> <?php $status_navs = \App\Models\Statuslabel::where('show_in_nav', '=', 1)->get(); ?>
@if (count($status_navs) > 0) @if (count($status_navs) > 0)
<li class="divider">&nbsp;</li> <li class="divider">&nbsp;</li>
@foreach ($status_navs as $status_nav) @foreach ($status_navs as $status_nav)

View file

@ -106,7 +106,7 @@
@endcan @endcan
</td> </td>
</tr> </tr>
<?php $count++; ?> <?php $count++; ?>
@endforeach @endforeach
@endif @endif
</tbody> </tbody>

View file

@ -48,7 +48,7 @@
if ($errormessage) { if ($errormessage) {
$errormessage=preg_replace('/ snipeit /', '', $errormessage); $errormessage=preg_replace('/ snipeit /', '', $errormessage);
print('<span class="alert-msg"><i class="fa fa-times"></i> '.$errormessage.'</span>'); print('<span class="alert-msg"><i class="fa fa-times"></i> '.$errormessage.'</span>');
} }
?> ?>
</div> </div>

View file

@ -39,7 +39,7 @@
<?php <?php
$totalDays = 0; $totalDays = 0;
$totalCost = 0; $totalCost = 0;
?> ?>
@foreach ($assetMaintenances as $assetMaintenance) @foreach ($assetMaintenances as $assetMaintenance)
<tr> <tr>
<td>{{ is_null($assetMaintenance->asset->company) ? '' : $assetMaintenance->asset->company->name }}</td> <td>{{ is_null($assetMaintenance->asset->company) ? '' : $assetMaintenance->asset->company->name }}</td>
@ -65,10 +65,10 @@
{{ number_format($assetMaintenance->cost,2) }} {{ number_format($assetMaintenance->cost,2) }}
</td> </td>
</tr> </tr>
<?php <?php
$totalDays += $assetMaintenanceTime; $totalDays += $assetMaintenanceTime;
$totalCost += floatval($assetMaintenance->cost); $totalCost += floatval($assetMaintenance->cost);
?> ?>
@endforeach @endforeach
</tbody> </tbody>
<tfoot> <tfoot>

View file

@ -198,7 +198,7 @@
<td>{{ $improvement->completion_date }}</td> <td>{{ $improvement->completion_date }}</td>
<td>{{ $improvement->is_warranty ? trans('admin/asset_maintenances/message.warranty') : trans('admin/asset_maintenances/message.not_warranty') }}</td> <td>{{ $improvement->is_warranty ? trans('admin/asset_maintenances/message.warranty') : trans('admin/asset_maintenances/message.not_warranty') }}</td>
<td>{{ sprintf( trans( 'general.currency' ) . '%01.2f', $improvement->cost) }}</td> <td>{{ sprintf( trans( 'general.currency' ) . '%01.2f', $improvement->cost) }}</td>
<?php $totalCost += $improvement->cost; ?> <?php $totalCost += $improvement->cost; ?>
<td><a href="{{ route('maintenances.edit', $improvement->id) }}" class="btn btn-warning"><i class="fa fa-pencil icon-white"></i></a> <td><a href="{{ route('maintenances.edit', $improvement->id) }}" class="btn btn-warning"><i class="fa fa-pencil icon-white"></i></a>
</td> </td>
</tr> </tr>

View file

@ -108,16 +108,16 @@ $style = [
<tr> <tr>
<td align="center"> <td align="center">
<?php <?php
switch ($level) { switch ($level) {
case 'success': case 'success':
$actionColor = 'button--green'; $actionColor = 'button--green';
break; break;
case 'error': case 'error':
$actionColor = 'button--red'; $actionColor = 'button--red';
break; break;
default: default:
$actionColor = 'button--blue'; $actionColor = 'button--blue';
} }
?> ?>
<a href="{{ $actionUrl }}" <a href="{{ $actionUrl }}"