Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function close_fraud_accounts_hook($args) {
- $logfile=fopen("/tmp/WHMCS_action_hooks_log.txt","w");
- fwrite($logfile,"Entering function");
- //Grab a list of unique client IDs with fraudulent orders against their account
- $fraud_clients = full_query("SELECT tblclients.id FROM tblclients JOIN tblorders ON tblclients.id=tblorders.userid WHERE tblclients.status='Active' AND tblorders.status='Fraud' GROUP BY tblorders.userid");
- fwrite($logfile,"Got client list\n");
- //Loop through each client ID the list
- while($client = mysql_fetch_array($fraud_clients))
- {
- //Get a count of the none fraudulent orders on the client account
- $orders = full_query("SELECT count(tblorders.status) AS total FROM tblorders WHERE tblorders.userid={$client['id']} AND tblorders.status!='Fraud'");
- $legitimate_order=mysql_fetch_array($orders);
- fwrite($logfile,"Got legitimate order details for client {$client['id']}\n");
- //Debugging
- fwrite($logfile,"DEBUG: {$legitimate_order['total']} legitimate orders for client {$client['id']}\n");
- //If there are no legitimate orders then close the account
- if($legitimate_order['total']==0)
- {
- update_query("tblclients",array("status"=>"Closed"),array("id"=>$client['id']));
- fwrite($logfile,"Updated client status for client {$client['id']}\n");
- }
- }
- fclose($logfile);
- }
- add_hook("DailyCronJob",1,"close_fraud_accounts_hook","");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement