jarod Posted February 17, 2017 Share Posted February 17, 2017 I'm creating an admin hook and I have two questions. How can I pull the current admin user role id? I need to know how I can grab the $roleId of the current admin user. How do I create a smarty tag that can be used throughout the admin area? I want to use a smarty tag to control where this is output. If I echo something right now it dumps it into the top of the page before <html>... I've started my hook with this snippet: add_hook('AdminAreaPage', 1, function($vars) { if ($vars['adminid'] == '3') { // Do Awesome Stuff } }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 17, 2017 Share Posted February 17, 2017 How can I pull the current admin user role id?I need to know how I can grab the $roleId of the current admin user. the usual two ways - either query the database or use the class documentation. I want to use a smarty tag to control where this is output. If I echo something right now it dumps it into the top of the page before <html>... i'm sure if you search the forums for 'adminareapage', you'll find lots of example hooks that will help you... e.g the hook below creates a new variable in the admin area... https://forum.whmcs.com/showthread.php?115031-Show-active-tickets-count-at-top-of-page&p=465459#post465459 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted June 12, 2017 Author Share Posted June 12, 2017 Thank you, Brian. Can you provide a working db query example for grabbing the roleid? Also, how can I use this in a smarty variable? I'm familiar with $smarty.session.adminid, but what about roleid? I can't dig anything up on the web that covers it. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 12, 2017 Share Posted June 12, 2017 Can you provide a working db query example for grabbing the roleid? in v7.2, you could query the database like this... <?php # Get Admin Roleid (using Capsule). # Written by brian! use Illuminate\Database\Capsule\Manager as Capsule; function admin_roleid_capsule_hook($vars) { $adminid = $vars['adminid']; $roleid = Capsule::table('tbladmins') ->where('id', $adminid) ->value('roleid'); return array("roleid1" => $roleid); } add_hook("AdminAreaPage", 1, "admin_roleid_capsule_hook"); ?> that will give you a Smarty variable {$roleid1} that you can use anywhere in the template. and if you want to do magical things with the value, then you can... and then output the result of that back to the template by returning the variable. or if you want to use the Class method... <?php # Get Admin Roleid (using Class). # Written by brian! use WHMCS\User\Admin; function admin_roleid_class_hook($vars) { $admin = Admin::find($vars['adminid']); $roleid = $admin->roleId; return array("roleid2" => $roleid); } add_hook("AdminAreaPage", 1, "admin_roleid_class_hook"); ?> similarly, that will give you a {$roleid2} Smarty variable - hopefully if you run both hooks together, the values should be exactly the same! Also, how can I use this in a smarty variable? I'm familiar with $smarty.session.adminid, but what about roleid? I can't dig anything up on the web that covers it. either of the above methods should give you a Smarty variable that you can use - obviously, you won't need to use both hooks, just whichever one suits your needs. 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted June 13, 2017 Author Share Posted June 13, 2017 Oh that is beautiful! Thank you 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.