glardone Posted August 11, 2016 Share Posted August 11, 2016 Dear all, I'm trying to create a simple hook to list the company name of the clients, but I do not understand how to retrieve the userid of logged client Thank you! Best regards, Giorgio 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 11, 2016 Share Posted August 11, 2016 Hi Giorgio, do you need to use a hook to get the company name of the logged in client? if they're logged in, then you should be able to use the Smarty variable {$clientsdetails.companyname} in a client area template. 0 Quote Link to comment Share on other sites More sharing options...
glardone Posted August 11, 2016 Author Share Posted August 11, 2016 Hi Brian, the Smarty variable {$clientsdetails.companyname} return the company name of logged client, but I need to retrive the company names of all contacts of logged client. Thank you! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 11, 2016 Share Posted August 11, 2016 the Smarty variable {$clientsdetails.companyname} return the company name of logged client, but I need to retrieve the company names of all contacts of logged client. there's a $contacts array in Smarty, but it only gives you names and email addresses - not company names. here's an action hook that will create a new array, called $clientscontacts and contains all the information in the database table. <?php use WHMCS\View\Menu\Item as MenuItem; use Illuminate\Database\Capsule\Manager as Capsule; function client_contacts_hook($vars) { $client = Menu::context("client"); $clientid = (int) $client->id; $contacts = Capsule::table('tblcontacts') ->where('userid',$clientid) ->get(); $encodedata = json_encode($contacts); $decodedata = json_decode($encodedata, true); return array("clientscontacts" => $decodedata); } add_hook("ClientAreaPage", 1, "client_contacts_hook"); ?> and then in your template, you can list it's content using... {foreach $clientscontacts as $contact} Name: {$contact.firstname} {$contact.lastname}<br> Company Name: {$contact.companyname}<br> {/foreach} and then adjust the above output to suit your own needs. 0 Quote Link to comment Share on other sites More sharing options...
glardone Posted August 11, 2016 Author Share Posted August 11, 2016 there's a $contacts array in Smarty, but it only gives you names and email addresses - not company names. here's an action hook that will create a new array, called $clientscontacts and contains all the information in the database table. <?php use WHMCS\View\Menu\Item as MenuItem; use Illuminate\Database\Capsule\Manager as Capsule; function client_contacts_hook($vars) { $client = Menu::context("client"); $clientid = (int) $client->id; $contacts = Capsule::table('tblcontacts') ->where('userid',$clientid) ->get(); $encodedata = json_encode($contacts); $decodedata = json_decode($encodedata, true); return array("clientscontacts" => $decodedata); } add_hook("ClientAreaPage", 1, "client_contacts_hook"); ?> and then in your template, you can list it's content using... {foreach $clientscontacts as $contact} Name: {$contact.firstname} {$contact.lastname}<br> Company Name: {$contact.companyname}<br> {/foreach} and then adjust the above output to suit your own needs. Fantastic! Thank you very much Brian! 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.