Jump to content

Error: Call to a member function getTemplateVars() on null


Recommended Posts

I'm getting an error after upgrading (see screenshot)

Here's the code that's giving the error  (I removed the code between the else statement to keep it short here)

This is a custom tpl

<link href="modules/servers/cpanel/css/client.css" rel="stylesheet">
<script src="modules/servers/cpanel/js/client.js"></script>

{php}
$smartyvars = $template->getTemplateVars();  
$userid = $smartyvars['clientsdetails']['id'];
$query = mysql_query("SELECT tblhosting.id as serviceid FROM tblhosting,tblproducts WHERE userid = $userid AND tblhosting.packageid = tblproducts.id AND tblhosting.domainstatus = 'Active' AND tblproducts.servertype = 'cpanel'"); 
$result = mysql_fetch_array($query);  
$services = $result["serviceid"];
$template->assign('serviceid', $services);
{/php}  

{if $clientsstats.productsnumactivehosting eq "0"}
    <div class="alert alert-warning text-center" role="alert">
        {if $suspendreason}
            <strong>{$suspendreason}</strong><br />
        {/if}
        {$LANG.cPanel.packageNotActive} {$status}.<br />
        {if $systemStatus eq "Pending"}
            {$LANG.cPanel.statusPendingNotice}
        {elseif $systemStatus eq "Suspended"}
            {$LANG.cPanel.statusSuspendedNotice}
        {/if}
    </div>
{else if $clientsstats.productsnumactivehosting eq "1"}


   (output here)
    
{else}   
{/if}

How can I solve this?

Screen Shot 2021-03-16 at 8.34.18 AM.png

Edited by JackRabbit
Link to comment
Share on other sites

3 hours ago, JackRabbit said:

How can I solve this?

a quick fix should be to add the code below after the opening {php} tag...

global $smarty;

the better fix would be to use an action hook to do the db query and return the result to the template - even if you just used your existing SQL query direct in the code and not rewrite it in the usual format, that should still return the same value as your {php} code...

<?php

use WHMCS\Database\Capsule;

function jackrabbit_custom_hook($vars) {

	if ($vars['templatefile'] == "custom") {
		$client = Menu::context('client');
		$services = Capsule::select('SELECT tblhosting.id FROM tblhosting,tblproducts WHERE userid = "' . $client->id . '" AND tblhosting.packageid = tblproducts.id AND tblhosting.domainstatus = "Active" AND tblproducts.servertype = "cpanel"');
		return array("serviceid" => $services[0]->id);
	}
}
add_hook("ClientAreaPage", 1, "jackrabbit_custom_hook");
Link to comment
Share on other sites

Thank you Brian, It works! 

Your short fix didn't work but your hook solution worked great.

So in case anyone is curious, here's the solution:

<?php

use WHMCS\Database\Capsule;

function jackrabbit_quicklinks($vars) {

	if ($vars['templatefile'] == "quicklinks") {
		$client = Menu::context('client');
		$services = Capsule::select('SELECT tblhosting.id FROM tblhosting,tblproducts WHERE userid = "' . $client->id . '" AND tblhosting.packageid = tblproducts.id AND tblhosting.domainstatus = "Active" AND tblproducts.servertype = "cpanel"');
		return array("serviceid" => $services[0]->id);
	}
}
add_hook("ClientAreaHomepage", 1, "jackrabbit_quicklinks");

I've got a file called quicklinks.tpl which has the code I want to display (original code from the first post here, but I've removed the php) So here's what it looks like now:
 

<link href="modules/servers/cpanel/css/client.css" rel="stylesheet">
<script src="modules/servers/cpanel/js/client.js"></script>


{if $clientsstats.productsnumactivehosting eq "0"}
	<div class="alert alert-warning text-center" role="alert">
        {if $suspendreason}
            <strong>{$suspendreason}</strong><br />
        {/if}
        {$LANG.cPanel.packageNotActive} {$status}.<br />
        {if $systemStatus eq "Pending"}
            {$LANG.cPanel.statusPendingNotice}
        {elseif $systemStatus eq "Suspended"}
            {$LANG.cPanel.statusSuspendedNotice}
        {/if}
    </div>
{else if $clientsstats.productsnumactivehosting eq "1"}


    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">{$LANG.cPanel.quickShortcuts}</h3>
        </div>
        <div class="panel-body text-center">

            <div class="row cpanel-feature-row">
            	<div class="col-sm-3 col-xs-6" id="cPanelFileManager">
                    <a href="clientarea.php?action=productdetails&amp;id={$serviceid}&amp;dosinglesignon=1&amp;app=FileManager_Home" target="_blank">
                        <img src="modules/servers/cpanel/img/file_manager.png" />
                        {$LANG.cPanel.fileManager}
                    </a>
                </div>  
            </div>

        </div>
    </div>
    
{else}   
{/if}

And finally, I've inserting that quicklinks.tpl into the clientareahome.tpl using this:

 

{if $clientsstats.productsnumactivehosting eq "1"}
{include file="modules/servers/cpanel/templates/quicklinks.tpl"}
{else}
{/if}

I'm always so grateful to you Brian, you're the best. 

Edited by JackRabbit
Link to comment
Share on other sites

Ah, but now we have another problem. I'll put this here since it may be related to this hook. 

If the user has one cpanel account, the quicklinks for that cpanel account get replicated on the clientareahome.tpl for them. 

If you look at the code above for the quicklinks.tpl, you'll see the file manager link for direct access to their file manager. 

When I click on this filemanager link now, I'm not taken to cpanel, but to the clientareaproducts.tpl page - the original quicklinks work fine from the product details page, just not from my custom quicklinks on the clientareahome.tpl

It worked before, but not now. I'm not sure if it's the update or the new hook.  How can I get that to work again?

Link to comment
Share on other sites

46 minutes ago, JackRabbit said:

It worked before, but not now. I'm not sure if it's the update or the new hook.  How can I get that to work again?

I suspect you would need to pass the serviceid variable in the include - otherwise WHMCS wouldn't have a clue which service to link to, so it will be unable to use SSO and just show you the product details page instead.

I crippled the hook to match what your {php] code did, which was to return only one value - if we release it from the shackles and let it return all possible values....

return array("services" => $services);

so now in clientareahome (and i'm assuming the above hook is tweaked to work in clientareahome), I would change...

{if $clientsstats.productsnumactivehosting eq "1"}
{include file="modules/servers/cpanel/templates/quicklinks.tpl"}
{else}
{/if}

to...

{if count($services) > 0}
	{foreach $services as $service} 
		{include file="modules/servers/cpanel/templates/quicklinks.tpl" serviceid=$service->id}
	{/foreach}
{/if}

what I dislike about that original code is that your just counting active hosting accounts - it's possibly that there are active hosting accounts that aren't cpanel (maybe not on your server) and so you could end up adding quicklinks to products that aren't cpanel... whereas, if you count the services array, you know that all the services in there will be cpanel.

possibly it needs to be expanded in an else to handle non-cpanel services, or what to do for those with no services.

on my test account, there are 2 active cpanel, so because clientareahome is now looping through the array to show quicklinks to all active cpanel products, i'm seeing this....

1fOy8hN.png

yes, i've tweaked it a little more to pass the product and domain names to the quicklinks template - otherwise the client wouldn't know which services they're managing.

$services = Capsule::select('SELECT tblhosting.id, tblproducts.name, tblhosting.domain FROM tblhosting,tblproducts WHERE userid = "' . $client->id . '" AND tblhosting.packageid = tblproducts.id AND tblhosting.domainstatus = "Active" AND tblproducts.servertype = "cpanel"');
{include file="modules/servers/cpanel/templates/quicklinks.tpl" serviceid=$service->id servicename=$service->name servicedomain=$service->domain}
<link href="modules/servers/cpanel/css/client.css" rel="stylesheet">
<script src="modules/servers/cpanel/js/client.js"></script>

    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">{$LANG.cPanel.quickShortcuts} ({$servicename}{if $servicedomain} - {$servicedomain}{/if})</h3>
        </div>
        <div class="panel-body text-center">

            <div class="row cpanel-feature-row">
            	<div class="col-sm-3 col-xs-6" id="cPanelFileManager">
                    <a href="clientarea.php?action=productdetails&amp;id={$serviceid}&amp;dosinglesignon=1&amp;app=FileManager_Home" target="_blank">
                        <img src="modules/servers/cpanel/img/file_manager.png" />
                        {$LANG.cPanel.fileManager}
                    </a>
                </div>  
            </div>

        </div>
    </div>

the links should work and access the appropriate cpanel account. 🙂

Link to comment
Share on other sites

I first tried the full suggestion you gave, but the quicklinks disappeared on the clientareahome.tpl

so I put everything back the way it was, then just tried your first suggestion (in your last post here) and this is what I have, but the quicklink to the filemanager still sends me to the products page in the client area

 

<?php

use WHMCS\Database\Capsule;

function jackrabbit_quicklinks($vars) {

	if ($vars['templatefile'] == "quicklinks") {
		$client = Menu::context('client');
		$services = Capsule::select('SELECT tblhosting.id FROM tblhosting,tblproducts WHERE userid = "' . $client->id . '" AND tblhosting.packageid = tblproducts.id AND tblhosting.domainstatus = "Active" AND tblproducts.servertype = "cpanel"');
		return array("services" => $services);
	}
}
add_hook("ClientAreaHomepage", 1, "jackrabbit_quicklinks");

and in the clientareahome.tpl:

{if $clientsstats.productsnumactivehosting eq "1"}
{include file="modules/servers/cpanel/templates/quicklinks.tpl" serviceid=$service->id}
{else}
{/if}

 

Link to comment
Share on other sites

17 hours ago, JackRabbit said:

I first tried the full suggestion you gave, but the quicklinks disappeared on the clientareahome.tpl

which would imply the array was empty - that could occur if you were testing on an account that didn't have active cpanel services.

17 hours ago, JackRabbit said:

so I put everything back the way it was, then just tried your first suggestion (in your last post here) and this is what I have, but the quicklink to the filemanager still sends me to the products page in the client area

well first of all, I don't think the hook is even being triggered (hence why the array is empty - it probably won't even exist)... that first line where the hook checks for the templatefile, quicklinks.tpl (if you mean the included file from the cpanel folder) wouldn't trigger any hook points.... that value would need to be "clientareahome" if that's the file that needs to pass the value to the include.... though there's an argument as to why you're even bothering with the include in the first place.

second problem is that you're using completely the wrong hook point - ClientAreaHomepage returns HTML, not an array of values - so it's definitely not returning any array back to the template.

you would use ClientAreaPageHome and remove the if statement (as it would be redundant), or as I originally did, use ClientAreaPage and ensure the if statement was correct.

22 minutes ago, JackRabbit said:

The service id is missing. 

as I said, I don't' think the hook is even running.

ultimately, ClientAreaHomepage could be used to generate the entire output and remove the need to edit the template, but that's not what you're trying to do.... and so let's not try to run before we can walk on this. 🙂

Link to comment
Share on other sites

Sorry Brian, I'm not so good with this. 
 

3 hours ago, brian! said:

the array was empty - that could occur if you were testing on an account that didn't have active cpanel services.

there is an active cpanel

3 hours ago, brian! said:

that first line where the hook checks for the templatefile, quicklinks.tpl (if you mean the included file from the cpanel folder) wouldn't trigger any hook points.... that value would need to be "clientareahome"

so I've switched that to clientareahome

3 hours ago, brian! said:

though there's an argument as to why you're even bothering with the include in the first place.

I'm not sure what you mean by this, I shouldn't include the quicklinks file? 

3 hours ago, brian! said:

you're using completely the wrong hook point - ClientAreaHomepage returns HTML, not an array of values - so it's definitely not returning any array back to the template.

you would use ClientAreaPageHome and remove the if statement (as it would be redundant), or as I originally did, use ClientAreaPage and ensure the if statement was correct.

I've switched it to ClientAreaPage

Here's my hook:

<?php

use WHMCS\Database\Capsule;

function jackrabbit_quicklinks($vars) {

	if ($vars['templatefile'] == "clientareahome") {
		$client = Menu::context('client');
		$services = Capsule::select('SELECT tblhosting.id, tblproducts.name, tblhosting.domain FROM tblhosting,tblproducts WHERE userid = "' . $client->id . '" AND tblhosting.packageid = tblproducts.id AND tblhosting.domainstatus = "Active" AND tblproducts.servertype = "cpanel"');

		return array("services" => $services);
	}
}
add_hook("ClientAreaPage", 1, "jackrabbit_quicklinks");

here's my include code in the clientareahome.tpl

{if count($services) > 0}
	{foreach $services as $service} 
		{include file="modules/servers/cpanel/templates/quicklinks.tpl" serviceid=$service->id}
	{/foreach}
{/if}

Still, the hook isn't working , the quicklinks  don't appear in the client area home.

 

3 hours ago, brian! said:

first of all, I don't think the hook is even being triggered (hence why the array is empty - it probably won't even exist)

The array appears to be empty still,  my modifications didn't resolve it. So I removed the if statement and only included the file:

{include file="modules/servers/cpanel/templates/quicklinks.tpl" serviceid=$service->id}

And the quick links still don't work, the service id isn't being populated.

What is the correct code I should put on each page? I apologize if I'm making you roll your eyes 😕 I know you're not obligated to help here, I really appreciate your help. I may just find a developer who will do this for me. 

Edited by JackRabbit
Link to comment
Share on other sites

47 minutes ago, JackRabbit said:

Sorry Brian, I'm not so good with this. 

no worries - neither was I once upon a time.

quick question - ultimately, do you want it to look like the screenshot I posted previously ? with this output below the homepage panels ??

1fOy8hN.png

47 minutes ago, JackRabbit said:

I'm not sure what you mean by this, I shouldn't include the quicklinks file? 

personally, I wouldn't... but if you're telling me that you have, or intend to have, multiple pages including this output, then it's fair enough to include it from a separate file... otherwise, it's an unnecessary complication - it's not the cause of the issue though, just a preference on my part.

47 minutes ago, JackRabbit said:

The array appears to be empty still,  my modifications didn't resolve it. So I removed the if statement and only included the file:


{include file="modules/servers/cpanel/templates/quicklinks.tpl" serviceid=$service->id}

And the quick links still don't work, the service id isn't being populated.

that wouldn't have made any difference.

47 minutes ago, JackRabbit said:

What is the correct code I should put on each page?

well, the hook correctly written would be...

<?php

use WHMCS\Database\Capsule;

function jackrabbit_custom_hook($vars) {

	$client = Menu::context('client');
	$services = Capsule::table('tblhosting')
		->join('tblproducts','tblhosting.packageid','=','tblproducts.id')
		->where('userid',$client->id)
		->where('domainstatus','Active')
		->where('servertype','cpanel')
		->select('tblhosting.id')
		->get();
	$results = json_decode(json_encode($services), true);	
	return array("services" => $results);
}
add_hook("ClientAreaPageHome", 1, "jackrabbit_custom_hook");

for now, it's just returning IDs, we can worry about names and domains later.

the Smarty code in clientareahome would be...

{if count($services) > 0}
	{foreach $services as $service} 
		{include file="modules/servers/cpanel/templates/quicklinks.tpl" serviceid=$service['id']}
	{/foreach}
{/if}

and quicklinks would be...

<link href="modules/servers/cpanel/css/client.css" rel="stylesheet">
<script src="modules/servers/cpanel/js/client.js"></script>

    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">{$LANG.cPanel.quickShortcuts}</h3>
        </div>
        <div class="panel-body text-center">

            <div class="row cpanel-feature-row">
            	<div class="col-sm-3 col-xs-6" id="cPanelFileManager">
                    <a href="clientarea.php?action=productdetails&id={$serviceid}&dosinglesignon=1&app=FileManager_Home" target="_blank">
                        <img src="modules/servers/cpanel/img/file_manager.png" />
                        {$LANG.cPanel.fileManager}
                    </a>
                </div>  
            </div>

        </div>
    </div>

with that I still get the above screenshot, service ID is passed and the links work to cpanel.

if it doesn't work, then throw a {debug} in the clientareahome template, refresh the page and it should generate a popup window of available arrays... see if $services is in there.... and also ensure there are no other hooks, {php} code that could be generating the same array (or undoing what the hook is trying to do).

h42wWWO.png

and remember to remove the {debug} when you're finished (especially if you're doing this on a live production server that clients access). ⚠️

Edited by brian!
Link to comment
Share on other sites

4 minutes ago, JackRabbit said:

No $services  (I used ctrl+f)

then are you 120% sure that this client has an active cpanel account and that it's marked as using the cpanel module in the database... ?

5 minutes ago, JackRabbit said:

Man, this is so frustrating Brian.  Maybe it's a nice puzzle for you.

it's not what I had planned to be looking at at 8pm this evening. 🙂

6 minutes ago, JackRabbit said:

I'm going to attach the 3 files here. I don't know if there are any other hooks interfering. I don't think there are.

if I use your clientareahome, this is what i'm seeing...

F5ta2Vx.png

ignore that it's not passing names and that i've gone overboard with quicklinks.

however, when I use your quicklinks, then I see this...

Bu1ImjU.png

the problem is likely to be those if statements in quicklinks that are conditional on the number of active hosting, e.g if this client has more than 1 active service, including one cpanel, then $services would be created, but no output condition would be met and therefore nothing would be shown.

if you change quicklinks to just the bare bones code I posted above, e.g with none of your if statements, then what happens ?

Link to comment
Share on other sites

5 minutes ago, brian! said:

then are you 120% sure that this client has an active cpanel account

yes, it's my own account. the quicklinks were working before the 8.1.3 update

6 minutes ago, brian! said:

not what I had planned to be looking at at 8pm this evening. 🙂

me either, 9pm for me. 😕 And you don't have to do this, you're being very nice. 

9 minutes ago, brian! said:

if you change quicklinks to just the bare bones code I posted above, e.g with none of your if statements, then what happens ?

I tried that already too. I have it that way now and it's still not working. 

Link to comment
Share on other sites

5 minutes ago, JackRabbit said:

yes, it's my own account. the quicklinks were working before the 8.1.3 update

can you try it on Six/21 just so I know it's not something with Hostify causing this?

7 minutes ago, JackRabbit said:

me either, 9pm for me. 😕 And you don't have to do this, you're being very nice. 

it's stubbornly annoying - this should be simple, yet it's not working.

ok, this isn't going to be the hook for a working solution, but let's go nuclear...

<?php

use WHMCS\Database\Capsule;

function jackrabbit_custom_hook($vars) {

	$client = Menu::context('client');
	$services = $client->services->all();
	return array("services" => $services);
}
add_hook("ClientAreaPageHome", 1, "jackrabbit_custom_hook");

use that, keep the bare bones quicklinks and tell me that is now at least outputting something.

Link to comment
Share on other sites

10 minutes ago, brian! said:

can you try it on Six/21 just so I know it's not something with Hostify causing this?

same problem with 6

10 minutes ago, brian! said:

let's go nuclear...

it exploded. jk. same problem, adding the new hook. {debug} $services isn't there

If you've got a headache from this, you don't need to be here tonight. We can continue later if you want to. 

Link to comment
Share on other sites

Just now, JackRabbit said:

it exploded. jk. same problem, adding the new hook. {debug} $services isn't there

then something else is in play - that hook should have returned all services.

2 minutes ago, JackRabbit said:

If you've got a headache from this, you don't need to be here tonight. We can continue later if you want to. 

yep - let's start again in the morning.

Link to comment
Share on other sites

Got it! 
in the configuration file
 

$disable_hook_loading = true;

This little guy almost caused nuclear war. 

I only updated whmcs, I'm not sure why it was set to true. 

I'm going to use all your suggestions here. 

As always, you're the brain brian! Thank you for taking the extra time to help, I appreciate that so much! WHMCS would be a different world without you.

Link to comment
Share on other sites

  • 1 year later...
On 2/7/2023 at 8:08 AM, DennisHermannsen said:

@Agnel Perez Adding that to your configuration.php file will disable all hooks from loading. It's not something that should be used in production - it's to be used as a way to debug issues. If your website works just fine with all hooks disabled, your issue is located in one of the hooks you use.

i experimenting already what u talking about, the problem is: i'm not using any hooks

Link to comment
Share on other sites

Oops!

Something went wrong and we couldn't process your request.

Please go back to the previous page and try again.

 

hi guys! 

still dealing with this issue 

the full environment is

whmcs 8.6.1

PHP Version 8.1.14

inside of cPanel Version 108.0.11

lara theme v8.6.0

RS Theme(Lagom 2Theme Version:2.1.2

so far i get the error on clientarea.php & clientarea.php?action=productdetails&id=7

if i set on configuration.php:

$disable_hook_loading = true;

then lagom2 doesn't work and lara theme get a large of issues

Uncaught TypeError: $(...).bootstrapSwitch is not a function
    at HTMLDocument.init (scripts.min.js?v=ffd879:1:2683)
    at o (vendor.min.js?v=ffd879:1:27302)
    at Object.fireWith [as resolveWith] (vendor.min.js?v=ffd879:1:28085)
    at Function.ready (vendor.min.js?v=ffd879:1:29869)
    at HTMLDocument.e (vendor.min.js?v=ffd879:1:27069)

next i tried was:

set on configuration.php:

$disable_hook_loading = true;

disable lara and lagom 2, duplicate twenty-one theme to kk and active kk, save and try 

the client portal load just fine, but when a customer try to add or edit a payment method and try to process a payment doesn't work, another error show up

 

so basically 

$disable_hook_loading = true;

like @DennisHermannsen said it cannot be used on production, any help with this please

thanks

Link to comment
Share on other sites

@DennisHermannsen no lucky at all!

steps of what i did it today:

  • deactivate every module & addon (one by one and refreshing anytime)
  • backup database and files then do a fresh install and import database.

nothing help, looks like my problem is with structure on the database!

Already tried the WHMCS John solution:

SELECT * FROM tblhosting WHERE packageid NOT IN (SELECT id FROM tblproducts);

MySQL returned an empty result set (i.e. zero rows). (Query took 0.0006 seconds.)

Mean no orphaned service!

I'm getting frustrated with this issue 

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