diff --git a/app/controllers/admin/AccessoriesController.php b/app/controllers/admin/AccessoriesController.php index 6240a1ba9e..395c9c41dd 100755 --- a/app/controllers/admin/AccessoriesController.php +++ b/app/controllers/admin/AccessoriesController.php @@ -166,13 +166,18 @@ class AccessoriesController extends AdminController } - - - $accessory->delete(); + if ($accessory->hasUsers() > 0) { + return Redirect::to('admin/accessories')->with('error', Lang::get('admin/accessories/message.assoc_users', array('count'=> $accessory->hasUsers()))); + } else { + $accessory->delete(); // Redirect to the locations management page return Redirect::to('admin/accessories')->with('success', Lang::get('admin/accessories/message.delete.success')); - + + } + + + } @@ -273,15 +278,16 @@ class AccessoriesController extends AdminController $accessory_user = DB::table('accessories_users')->where('assigned_to','=',$accessory->assigned_to)->where('accessory_id','=',$accessory->id)->first(); - print_r($accessory_user); - //$data['accessory_user_id'] = $accessory_user->id; + $data['log_id'] = $logaction->id; $data['eula'] = $accessory->getEula(); $data['first_name'] = $user->first_name; + $data['item_name'] = $accessory->name; + $data['require_acceptance'] = $accessory->requireAcceptance(); - if ($accessory->requireAcceptance()=='1') { + if (($accessory->requireAcceptance()=='1') || ($accessory->getEula())) { - Mail::send('emails.accept-accessory', $data, function ($m) use ($user) { + Mail::send('emails.accept-asset', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); $m->subject('Confirm accessory delivery'); }); diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index 1b797a4538..7e02cac87a 100755 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -451,12 +451,14 @@ class AssetsController extends AdminController $logaction->note = e(Input::get('note')); $log = $logaction->logaction('checkout'); - $data['asset_id'] = $asset->id; + $data['log_id'] = $logaction->id; $data['eula'] = $asset->getEula(); $data['first_name'] = $user->first_name; + $data['item_name'] = $asset->name; + $data['require_acceptance'] = $asset->requireAcceptance(); - if ($asset->requireAcceptance()=='1') { + if (($asset->requireAcceptance()=='1') || ($asset->getEula())) { Mail::send('emails.accept-asset', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); diff --git a/app/controllers/admin/CategoriesController.php b/app/controllers/admin/CategoriesController.php index 84ddb914db..d46c18365c 100755 --- a/app/controllers/admin/CategoriesController.php +++ b/app/controllers/admin/CategoriesController.php @@ -68,7 +68,7 @@ class CategoriesController extends AdminController $category->name = e(Input::get('name')); $category->category_type = e(Input::get('category_type')); $category->eula_text = e(Input::get('eula_text')); - $category->use_default_eula = e(Input::get('use_default_eula', '1')); + $category->use_default_eula = e(Input::get('use_default_eula', '0')); $category->require_acceptance = e(Input::get('require_acceptance', '0')); $category->user_id = Sentry::getId(); @@ -145,7 +145,7 @@ class CategoriesController extends AdminController $category->name = e(Input::get('name')); $category->category_type = e(Input::get('category_type')); $category->eula_text = e(Input::get('eula_text')); - $category->use_default_eula = e(Input::get('use_default_eula', '1')); + $category->use_default_eula = e(Input::get('use_default_eula', '0')); $category->require_acceptance = e(Input::get('require_acceptance', '0')); // Was the asset created? diff --git a/app/lang/en/admin/accessories/message.php b/app/lang/en/admin/accessories/message.php index 18b75f88b8..62f179c5a1 100755 --- a/app/lang/en/admin/accessories/message.php +++ b/app/lang/en/admin/accessories/message.php @@ -3,7 +3,7 @@ return array( 'does_not_exist' => 'Category does not exist.', - 'assoc_users' => 'This category is currently associated with at least one model and cannot be deleted. Please update your models to no longer reference this category and try again. ', + 'assoc_users' => 'This accessory currently has :count items checked out to users. Please check in the accessories and and try again. ', 'create' => array( 'error' => 'Category was not created, please try again.', diff --git a/app/lang/en/admin/categories/general.php b/app/lang/en/admin/categories/general.php index a267a4728c..241dd24326 100755 --- a/app/lang/en/admin/categories/general.php +++ b/app/lang/en/admin/categories/general.php @@ -11,6 +11,8 @@ return array( 'eula_text' => 'Category EULA', 'eula_text_help' => 'This field allows you to customize your EULAs for specific types of assets. If you only have one EULA for all of your assets, you can check the box below to use the primary default.', 'require_acceptance' => 'Require users to confirm acceptance of assets in this category.', + 'required_acceptance' => 'This user will be emailed with a link to confirm acceptance of this item.', + 'required_eula' => 'This user will be emailed a copy of the EULA', 'no_default_eula' => 'No primary default EULA found. Add one in Settings.', 'update' => 'Update Category', 'use_default_eula' => 'Use the primary default EULA instead.', diff --git a/app/models/Accessory.php b/app/models/Accessory.php index b5c0f5af45..c909672a90 100755 --- a/app/models/Accessory.php +++ b/app/models/Accessory.php @@ -34,6 +34,11 @@ class Accessory extends Elegant return $this->belongsToMany('User', 'accessories_users', 'accessory_id','assigned_to')->withPivot('id')->withTrashed(); } + public function hasUsers() + { + return $this->belongsToMany('User', 'accessories_users', 'accessory_id','assigned_to')->count(); + } + public function requireAcceptance() { return $this->category->require_acceptance; @@ -45,7 +50,7 @@ class Accessory extends Elegant if ($this->category->eula_text) { return $Parsedown->text(e($this->category->eula_text)); - } elseif (Setting::getSettings()->default_eula_text) { + } elseif ((Setting::getSettings()->default_eula_text) && ($this->category->use_default_eula=='1')) { return $Parsedown->text(e(Setting::getSettings()->default_eula_text)); } else { return null; diff --git a/app/models/Category.php b/app/models/Category.php index 4119cff8ee..d99559a4da 100755 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -46,5 +46,20 @@ class Category extends Elegant return $this->hasMany('Model', 'category_id'); } + public function getEula() { + + $Parsedown = new Parsedown(); + + if ($this->eula_text) { + return $Parsedown->text(e($this->eula_text)); + } elseif ((Setting::getSettings()->default_eula_text) && ($this->use_default_eula=='1')) { + return $Parsedown->text(e(Setting::getSettings()->default_eula_text)); + } else { + return null; + } + + } + + } diff --git a/app/views/backend/accessories/checkout.blade.php b/app/views/backend/accessories/checkout.blade.php index 50918fc1a3..51fa2244fa 100755 --- a/app/views/backend/accessories/checkout.blade.php +++ b/app/views/backend/accessories/checkout.blade.php @@ -45,8 +45,9 @@ @endif - - + + +
@lang('admin/categories/general.required_acceptance')
+@lang('admin/categories/general.required_eula')
+@lang('admin/categories/general.required_acceptance')
+@lang('admin/categories/general.required_eula')
+Hello {{{ $first_name }}},
- -A new asset has been checked out to you. Please read the terms of use below, and click on the link at the bottom to confirm that you read and agree to the terms of use, and have received the asset.
- -{{ $eula }}
- -I have read and agree to the terms of use, and have received this item.
- -{{{ Setting::getSettings()->site_name }}}
-@stop diff --git a/app/views/emails/accept-asset.blade.php b/app/views/emails/accept-asset.blade.php index 2515a2370e..f32eec975f 100755 --- a/app/views/emails/accept-asset.blade.php +++ b/app/views/emails/accept-asset.blade.php @@ -3,11 +3,31 @@ @section('content')Hello {{{ $first_name }}},
-A new asset has been checked out to you. Please read the terms of use below, and click on the link at the bottom to confirm that you read and agree to the terms of use, and have received the asset.
+ +A new item ({{{ strtoupper($item_name) }}}) has been checked out to you. + +@if (($require_acceptance==1) && ($eula!='')) + + Please read the terms of use below, and click on the link at the bottom to confirm that you read and agree to the terms of use, and have received the asset. + +@elseif (($require_acceptance==1) && ($eula=='')) + + Please click on the link at the bottom to confirm that you have received the asset. + +@elseif (($require_acceptance==0) && ($eula!='')) + + Please read the terms of use below. + +@endif + +
+{{ $eula }}
-I have read and agree to the terms of use, and have received this item.
+@if ($require_acceptance==1) +I have read and agree to the terms of use, and have received this item.
+@endif{{{ Setting::getSettings()->site_name }}}
@stop