Jump to content

Block access to client area if client has overdue invoice(s)


wdele

Recommended Posts

Hello,

 

I want to block client area access when a client has overdue invoices.

 

My idea is to do a database call (do a query if the client has any overdue invoices) in the page header and if it returns yes, block access.

I have absolutely no idea how to do this, though.

 

Help would be appreciated!

Link to comment
Share on other sites

Ok, here you go.. Sorry, had to run out for a couple hours

What this does is pretty straight forward, and this is somewhat well documented, so you should be able to tweak as necessary.

Because hooks don't play well with smarty, I couldn't really get this to do something with the template (woulda been nice).

Save the included as a php file, in your whmcs/includes/hooks directory. This should work on 6.x, though I don't have a 6.x box to test it on

The nuts and bolts:

#1: The script checks to see if you're logged in. If not, return. Nothing to see, no additional queries needed

#2: The script checks to see if you've got an unpaid invoice. If not, return. Nothing to see , no additional queries needed

#3: The script checks to see if your unpaid invoice has a due date past the current time();

if (n), then return

if (y), then the script redirects to clientarea.php?action=invoices, which won't redirect, nor will viewinvoice.php , which is where you need to pay. Anything else will

<?php

//redirect clients to invoice page if they are overdue. Nothing else.
//provided by https://www.whmcs.guru
use Illuminate\Database\Capsule\Manager as Capsule;

function check_client_access($vars)
{
//what time is it?
$time = time();
//are we logged in? If not, then return
$uid  = $_SESSION['uid'];
if (empty($uid))
{
	return;
}
$filename = $vars['filename'];
$displayTitle = $vars['displayTitle'];
//do we have any unpaid invoices?
$rows = Capsule::table('tblinvoices')->select('id') ->WHERE ('userid', '<=', $uid) ->where('status', '=', 'Unpaid') ->count();

if (empty($rows))
{

	//we have no unpaid invoices. Do not proceed any further
	return;
}

if (!empty($rows))
{
	//we have unpaid invoices. Are they overdue?

	foreach (Capsule::table('tblinvoices')->select('duedate') ->WHERE ('userid', '=', $uid) ->where('status', '=', 'Unpaid')->get() as $unpaidinvoice) {

		$invdue = $unpaidinvoice->duedate;

		if (strtotime($invdue) < $time) {

			//let's make sure they're not viewing, or attempting to pay their invoice, ok?
			if ($filename !="viewinvoice" && $displayTitle != "My Invoices")
			{
				//all those checks, we're finally where we need to be
				header('Location: clientarea.php?action=invoices');

			}

		}

	}

}





}
add_hook('ClientAreaPage', 1, "check_client_access");

Link to comment
Share on other sites

  • 2 weeks later...
Ok, here you go.. Sorry, had to run out for a couple hours

What this does is pretty straight forward, and this is somewhat well documented, so you should be able to tweak as necessary.

Because hooks don't play well with smarty, I couldn't really get this to do something with the template (woulda been nice).

Save the included as a php file, in your whmcs/includes/hooks directory. This should work on 6.x, though I don't have a 6.x box to test it on

The nuts and bolts:

#1: The script checks to see if you're logged in. If not, return. Nothing to see, no additional queries needed

#2: The script checks to see if you've got an unpaid invoice. If not, return. Nothing to see , no additional queries needed

#3: The script checks to see if your unpaid invoice has a due date past the current time();

if (n), then return

if (y), then the script redirects to clientarea.php?action=invoices, which won't redirect, nor will viewinvoice.php , which is where you need to pay. Anything else will

<?php

//redirect clients to invoice page if they are overdue. Nothing else.
//provided by https://www.whmcs.guru
use Illuminate\Database\Capsule\Manager as Capsule;

function check_client_access($vars)
{
//what time is it?
$time = time();
//are we logged in? If not, then return
$uid  = $_SESSION['uid'];
if (empty($uid))
{
	return;
}
$filename = $vars['filename'];
$displayTitle = $vars['displayTitle'];
//do we have any unpaid invoices?
$rows = Capsule::table('tblinvoices')->select('id') ->WHERE ('userid', '<=', $uid) ->where('status', '=', 'Unpaid') ->count();

if (empty($rows))
{

	//we have no unpaid invoices. Do not proceed any further
	return;
}

if (!empty($rows))
{
	//we have unpaid invoices. Are they overdue?

	foreach (Capsule::table('tblinvoices')->select('duedate') ->WHERE ('userid', '=', $uid) ->where('status', '=', 'Unpaid')->get() as $unpaidinvoice) {

		$invdue = $unpaidinvoice->duedate;

		if (strtotime($invdue) < $time) {

			//let's make sure they're not viewing, or attempting to pay their invoice, ok?
			if ($filename !="viewinvoice" && $displayTitle != "My Invoices")
			{
				//all those checks, we're finally where we need to be
				header('Location: clientarea.php?action=invoices');

			}

		}

	}

}





}
add_hook('ClientAreaPage', 1, "check_client_access");

 

I'll be defo adding this, thanks so much!

Link to comment
Share on other sites

The code works fine, there are no issues with updated versions of WHMCS.

Cookies are a part of today's internet society, they are required, so if you don't have those allowed, you can't do anything.

 

Thank you for the reply

 

I completely wiped and cleaned up the cookies I'm sure we can.

but the problem still continues

Link to comment
Share on other sites

Thank you for the reply

 

I completely wiped and cleaned up the cookies I'm sure we can.

but the problem still continues

 

Seamless redirect after 5 seconds in the following manner

but this time the automatic page refreshing every 5 seconds

 

header('Refresh: 5; url=clientarea.php?action=invoices');

Link to comment
Share on other sites

A quick fix for this, if your client uses credit card payments:

<?php

//redirect clients to invoice page if they are overdue. Nothing else.
//provided by https://www.whmcs.guru
use Illuminate\Database\Capsule\Manager as Capsule;

function check_client_access($vars)
{
   //what time is it?
   $time = time();
   //are we logged in? If not, then return
   $uid  = $_SESSION['uid'];
   if (empty($uid))
   {
       return;
   }
   $filename = $vars['filename'];
   $displayTitle = $vars['displayTitle'];
   //do we have any unpaid invoices?
   $rows = Capsule::table('tblinvoices')->select('id') ->WHERE ('userid', '<=', $uid) ->where('status', '=', 'Unpaid') ->count();

   if (empty($rows))
   {

       //we have no unpaid invoices. Do not proceed any further
       return;
   }

   if (!empty($rows))
   {
       //we have unpaid invoices. Are they overdue?

       foreach (Capsule::table('tblinvoices')->select('duedate') ->WHERE ('userid', '=', $uid) ->where('status', '=', 'Unpaid')->get() as $unpaidinvoice) {

           $invdue = $unpaidinvoice->duedate;

           if (strtotime($invdue) < $time) {

               //let's make sure they're not viewing, or attempting to pay their invoice, ok?
               if ($filename !="viewinvoice" && $displayTitle != "My Invoices" && $filename !="creditcard")
               {
                   //all those checks, we're finally where we need to be
                   header('Location: clientarea.php?action=invoices');

               }

           }

       }

   }





}
add_hook('ClientAreaPage', 1, "check_client_access");

Link to comment
Share on other sites

A quick fix for this, if your client uses credit card payments:

<?php

//redirect clients to invoice page if they are overdue. Nothing else.
//provided by https://www.whmcs.guru
use Illuminate\Database\Capsule\Manager as Capsule;

function check_client_access($vars)
{
   //what time is it?
   $time = time();
   //are we logged in? If not, then return
   $uid  = $_SESSION['uid'];
   if (empty($uid))
   {
       return;
   }
   $filename = $vars['filename'];
   $displayTitle = $vars['displayTitle'];
   //do we have any unpaid invoices?
   $rows = Capsule::table('tblinvoices')->select('id') ->WHERE ('userid', '<=', $uid) ->where('status', '=', 'Unpaid') ->count();

   if (empty($rows))
   {

       //we have no unpaid invoices. Do not proceed any further
       return;
   }

   if (!empty($rows))
   {
       //we have unpaid invoices. Are they overdue?

       foreach (Capsule::table('tblinvoices')->select('duedate') ->WHERE ('userid', '=', $uid) ->where('status', '=', 'Unpaid')->get() as $unpaidinvoice) {

           $invdue = $unpaidinvoice->duedate;

           if (strtotime($invdue) < $time) {

               //let's make sure they're not viewing, or attempting to pay their invoice, ok?
               if ($filename !="viewinvoice" && $displayTitle != "My Invoices" && $filename !="creditcard")
               {
                   //all those checks, we're finally where we need to be
                   header('Location: clientarea.php?action=invoices');

               }

           }

       }

   }





}
add_hook('ClientAreaPage', 1, "check_client_access");

 

thanks for the reply

but the problem still continues.

No change

 

- - - Updated - - -

 

I turned off the option and credit card payment

the problem did not improve.

Link to comment
Share on other sites

The problem is not with the plugin, but with your setup.

You need to investigate and fix that problem

 

Whmcs does not work alone routing connections

Redirect to an external URL is successful.

 

I don't know where to look for this problem

Cause this problem may be caused by :(

Link to comment
Share on other sites

If you've got an infinite loop of redirects, you're doing something wrong, or you don't have an up to date version of WHMCS installed. Can't help you there. You need to fix the problems with your own install.

 

This merely redirects once to clientarea.php, nothing more.

 

I've tested this on 5 installs myself, and others have had no problems. So, a properly setup, up to date WHMCS install won't have issues.

Link to comment
Share on other sites

If you've got an infinite loop of redirects, you're doing something wrong, or you don't have an up to date version of WHMCS installed. Can't help you there. You need to fix the problems with your own install.

 

This merely redirects once to clientarea.php, nothing more.

 

I've tested this on 5 installs myself, and others have had no problems. So, a properly setup, up to date WHMCS install won't have issues.

 

WHMCS Version: 7.1.1-date version.

Re-installation I did

but the problem still continues.

 

I am having a problem meaningless

Link to comment
Share on other sites

Then you have problems with your install.

Like I said, I've tested this multiple times and it works flawlessly.

If it redirects somewhere, that's a problem with your local install, and something you're going to have to figure out on your own.

 

We have tested 4 separate whmcs system.

The error is the same.

 

"The page are not correctly routed."

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