Jump to content

How to get the Contact List of a User in ClientAreaPage?


glardone

Recommended Posts

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. :roll:

 

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.

Link to comment
Share on other sites

there's a $contacts array in Smarty, but it only gives you names and email addresses - not company names. :roll:

 

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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated