wdele Posted December 20, 2016 Share Posted December 20, 2016 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! 0 Quote Link to comment Share on other sites More sharing options...
bear Posted December 20, 2016 Share Posted December 20, 2016 Isn't that counter to what you would want, the client accessing and paying his overdue bills? 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted December 20, 2016 Share Posted December 20, 2016 This is entirely possible to do, actually, and not necessarily counter to what you're after Give me a few hours, I'll have something whipped up here for you 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted December 21, 2016 Share Posted December 21, 2016 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"); 1 Quote Link to comment Share on other sites More sharing options...
bear Posted December 21, 2016 Share Posted December 21, 2016 Oh, so not block access completely, just push them to the unpaid invoice to force them to take care of it. That at least makes more sense. 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted December 21, 2016 Share Posted December 21, 2016 Well, that wasn't the original request, of course, but that code could be modified to do that. Just wanted to add that in. This way your client has the chance to pay 0 Quote Link to comment Share on other sites More sharing options...
bear Posted December 21, 2016 Share Posted December 21, 2016 Thought I'd missed something. 0 Quote Link to comment Share on other sites More sharing options...
wdele Posted December 21, 2016 Author Share Posted December 21, 2016 Thank you so much - this is exactly what I needed! 0 Quote Link to comment Share on other sites More sharing options...
SportsGalore Posted December 29, 2016 Share Posted December 29, 2016 Ok, here you go.. Sorry, had to run out for a couple hoursWhat 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! 0 Quote Link to comment Share on other sites More sharing options...
system53 Posted December 31, 2016 Share Posted December 31, 2016 I'm getting the following error The page is not redirected correctly Try to open the location that will never end, a routing loop is entered. This problem sometimes kaynaklabilir since your cookies are disabled or rejected. 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted December 31, 2016 Share Posted December 31, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
system53 Posted December 31, 2016 Share Posted December 31, 2016 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 0 Quote Link to comment Share on other sites More sharing options...
system53 Posted December 31, 2016 Share Posted December 31, 2016 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'); 0 Quote Link to comment Share on other sites More sharing options...
system53 Posted January 1, 2017 Share Posted January 1, 2017 Is there anybody that can help? 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted January 3, 2017 Share Posted January 3, 2017 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"); 0 Quote Link to comment Share on other sites More sharing options...
system53 Posted January 4, 2017 Share Posted January 4, 2017 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. 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted January 4, 2017 Share Posted January 4, 2017 The problem is not with the plugin, but with your setup. You need to investigate and fix that problem 0 Quote Link to comment Share on other sites More sharing options...
system53 Posted January 4, 2017 Share Posted January 4, 2017 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 0 Quote Link to comment Share on other sites More sharing options...
Tapeix Posted January 4, 2017 Share Posted January 4, 2017 Same problem. The hook results in an infinite loop of redirects. 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted January 4, 2017 Share Posted January 4, 2017 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. 0 Quote Link to comment Share on other sites More sharing options...
system53 Posted January 5, 2017 Share Posted January 5, 2017 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 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted January 7, 2017 Share Posted January 7, 2017 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. 0 Quote Link to comment Share on other sites More sharing options...
wsa Posted January 7, 2017 Share Posted January 7, 2017 Yes I tester also it work nice no error 0 Quote Link to comment Share on other sites More sharing options...
AffordableDomainsCanada Posted January 8, 2017 Share Posted January 8, 2017 If I have been using this and tested it and seems to be working fine for me! 0 Quote Link to comment Share on other sites More sharing options...
system53 Posted January 8, 2017 Share Posted January 8, 2017 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." 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.