Jump to content

Home page Panels


TGK

Recommended Posts

Hi there is possible add a client area homepage panel that show a custom client field?  i dont know  how call it exactly maybe some can help me 

thanks

 

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
   $client = Menu::context( "client" );
   $clientid = intval( $client->id );
    {
       $bodyhtml = ;
       $examplePanel = $homePagePanels->addChild( 'Example', array(
           'label' => Lang::trans('example'),
           'icon' => 'fa-example',
           'extras' => array(
               'color' => 'red',
               'btn-link' => '#',
               'btn-text' => Lang::trans('example'),
               'btn-icon' => 'fa-plus',
           ),
           'bodyHtml' => $bodyhtml
       ));
   }
});

 

Link to comment
Share on other sites

14 hours ago, TGK said:

Hi there is possible add a client area homepage panel that show a custom client field?  i don't know  how call it exactly maybe some can help me.

there would be the usual three ways...

  1. take it from Smarty variables - you know that they'll be logged in, therefore you can access the $clientsdetails array and get the value from there.
  2. query the database... again, you know they'll be logged in so you can get their ID, and if you know the CCF you are looking for, with that info you can query the db to get the value.
  3. use the Class Docs to get the array...

of the 3, i'd use 2 as the most accurate - especially if you're only getting one CCF value.

ultimately, getting a customfield value is a navbar/sidebar or homepagepanel are all the same methods - only the hook names, and the output method varies slightly...

so to take your example hook, and add a DB query for a specific client customfield (e.g Account Manager), you could do this...

<?php

use WHMCS\View\Menu\Item;
use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
	$client = Menu::context( "client" );
	$fieldid = Capsule::table('tblcustomfields')->where('fieldname', 'Account Manager')->where('type', 'client')->value('id');
	$fieldvalue = Capsule::table('tblcustomfieldsvalues')->where('fieldid', $fieldid)->where('relid', $client->id)->value('value'); 
	
	$bodyhtml = '<p>Your Account Manager is '.$fieldvalue.'.</p>';
	$examplePanel = $homePagePanels->addChild( 'Example', array(
           'label' => Lang::trans('example'),
           'icon' => 'fa-example',
           'extras' => array(
               'color' => 'red',
               'btn-link' => '#',
               'btn-text' => Lang::trans('example'),
               'btn-icon' => 'fa-plus',
           ),
           'bodyHtml' => $bodyhtml
       ));
});

eeysT1t.png

Link to comment
Share on other sites

 

7 hours ago, brian! said:

there would be the usual three ways...

  1. take it from Smarty variables - you know that they'll be logged in, therefore you can access the $clientsdetails array and get the value from there.
  2. query the database... again, you know they'll be logged in so you can get their ID, and if you know the CCF you are looking for, with that info you can query the db to get the value.
  3. use the Class Docs to get the array...

of the 3, i'd use 2 as the most accurate - especially if you're only getting one CCF value.

ultimately, getting a customfield value is a navbar/sidebar or homepagepanel are all the same methods - only the hook names, and the output method varies slightly...

so to take your example hook, and add a DB query for a specific client customfield (e.g Account Manager), you could do this...


<?php

use WHMCS\View\Menu\Item;
use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
	$client = Menu::context( "client" );
	$fieldid = Capsule::table('tblcustomfields')->where('fieldname', 'Account Manager')->where('type', 'client')->value('id');
	$fieldvalue = Capsule::table('tblcustomfieldsvalues')->where('fieldid', $fieldid)->where('relid', $client->id)->value('value'); 
	
	$bodyhtml = '<p>Your Account Manager is '.$fieldvalue.'.</p>';
	$examplePanel = $homePagePanels->addChild( 'Example', array(
           'label' => Lang::trans('example'),
           'icon' => 'fa-example',
           'extras' => array(
               'color' => 'red',
               'btn-link' => '#',
               'btn-text' => Lang::trans('example'),
               'btn-icon' => 'fa-plus',
           ),
           'bodyHtml' => $bodyhtml
       ));
});

eeysT1t.png

code works fine Brian maybe you can help me a bit i want show panel only if custom field info exists,

 

please ill apreciate it

Link to comment
Share on other sites

11 hours ago, TGK said:

code works fine Brian maybe you can help me a bit i want show panel only if custom field info exists,

just wrap the output in an if statement that checks whether that final db query got a result.

<?php

use WHMCS\View\Menu\Item;
use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
	$client = Menu::context( "client" );
	$fieldid = Capsule::table('tblcustomfields')->where('fieldname', 'Account Manager')->where('type', 'client')->value('id');
	$fieldvalue = Capsule::table('tblcustomfieldsvalues')->where('fieldid', $fieldid)->where('relid', $client->id)->value('value'); 
	if ($fieldvalue) {	
		$bodyhtml = '<p>Your Account Manager is '.$fieldvalue.'.</p>';
		$examplePanel = $homePagePanels->addChild( 'Example', array(
			'label' => Lang::trans('example'),
			'icon' => 'fa-money-bill',
			'extras' => array(
				'color' => 'red',
				'btn-link' => '#',
				'btn-text' => Lang::trans('example'),
				'btn-icon' => 'fa-plus',
			),
			'bodyHtml' => $bodyhtml
		));
	}
});
16 hours ago, TGK said:

'icon' => 'fa-example', to 'icon' => 'fa-money', but the icon doesn't show i dont know why

fa-example and fa-money aren't existing FontAwesome Icons - you would need to choose one from FA5 is using WHMCS v7.6.. there are bugs with FA5 in v7.6, but it's unlikely you'll come across them (though I just found another answering this thread!). 😀

Link to comment
Share on other sites

maybe im doing something wrong if  i put  a "if " all panels didnt show  the code stop work

My fieldname is Banesco

<?php

use WHMCS\View\Menu\Item;
use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
	$client = Menu::context( "client" );
	$fieldid = Capsule::table('tblcustomfields')->where('fieldname', 'Banesco')->where('type', 'client')->value('id');
	$fieldvalue = Capsule::table('tblcustomfieldsvalues')->where('fieldid', $fieldid)->where('relid', $client->id)->value('value'); 
	if ($fieldvalue) {
	$bodyhtml = '<p>Numero de Cuenta: '.$fieldvalue.'</p>';
	$cuentabancariaPanel = $homePagePanels->addChild( 'Cuenta BancariaV', array(
		   'label' => 'Cuenta Bancaria&nbsp;<img src="https://www.com/notoch99/wp-content/uploads/2018/08/ven.png" width="20" height="20 ">',
		   'icon' => 'fa-bank',
           'extras' => array(
               'color' => 'green',
               'btn-link' => 'https://com/clientarea.php?action=details',
               'btn-text' => 'Agregar',
               'btn-icon' => 'fa-plus',
           ),
           'bodyHtml' => $bodyhtml,
	));
	}
});

 

Link to comment
Share on other sites

23 minutes ago, TGK said:

maybe im doing something wrong if  i put  a "if " all panels didnt show  the code stop work

there is something wrong with you code, as it's causing an error message..

Quote

exception 'Whoops\Exception\ErrorException' with message 'syntax error, unexpected '$bodyhtml'

try the following, it's working fine for me on v7.6 - though don't forget to change the image path in the labe; you don't need to add your domain to the btn-link URL.. and I don't think 'fa-bank' is a valid fontawesome icon.

<?php

use WHMCS\View\Menu\Item;
use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
	$client = Menu::context( "client" );
	$fieldid = Capsule::table('tblcustomfields')->where('fieldname', 'Banesco')->where('type', 'client')->value('id');
	$fieldvalue = Capsule::table('tblcustomfieldsvalues')->where('fieldid', $fieldid)->where('relid', $client->id)->value('value'); 
	if ($fieldvalue) {	
		$bodyhtml = '<p>Numero de Cuenta: '.$fieldvalue.'.</p>';
		$homePagePanels->addChild( 'Example', array(
			'label' => 'Cuenta Bancaria&nbsp;<img src="https://www.com/notoch99/wp-content/uploads/2018/08/ven.png" width="20" height="20 ">',
			'icon' => 'fa-bank',
			'extras' => array(
				'color' => 'green',
				'btn-link' => 'clientarea.php?action=details',
				'btn-text' => 'Agregar',
				'btn-icon' => 'fa-plus',
			),
			'bodyHtml' => $bodyhtml
		));
	}
});

 

Link to comment
Share on other sites

i leave image panel is show fine problem is when i put the " IF " panel dissapear

fa-bank works fine 

thanks for your help i apreciate it 

im using 7.5.2 atm cant update because somes modules not compatible yet

Captura.PNG

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