Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2.  
  3. function close_fraud_accounts_hook($args) {
  4.     $logfile=fopen("/tmp/WHMCS_action_hooks_log.txt","w");
  5.     fwrite($logfile,"Entering function");
  6.  
  7.     //Grab a list of unique client IDs with fraudulent orders against their account
  8.     $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");
  9.     fwrite($logfile,"Got client list\n");
  10.  
  11.     //Loop through each client ID the list
  12.     while($client = mysql_fetch_array($fraud_clients))
  13.     {
  14.         //Get a count of the none fraudulent orders on the client account
  15.         $orders = full_query("SELECT count(tblorders.status) AS total FROM tblorders WHERE tblorders.userid={$client['id']} AND tblorders.status!='Fraud'");
  16.         $legitimate_order=mysql_fetch_array($orders);
  17.         fwrite($logfile,"Got legitimate order details for client {$client['id']}\n");
  18.  
  19.         //Debugging
  20.         fwrite($logfile,"DEBUG: {$legitimate_order['total']} legitimate orders for client {$client['id']}\n");
  21.  
  22.         //If there are no legitimate orders then close the account
  23.         if($legitimate_order['total']==0)
  24.         {
  25.             update_query("tblclients",array("status"=>"Closed"),array("id"=>$client['id']));
  26.             fwrite($logfile,"Updated client status for client {$client['id']}\n");
  27.         }
  28.     }
  29.     fclose($logfile);
  30. }
  31.  
  32. add_hook("DailyCronJob",1,"close_fraud_accounts_hook","");
  33.  
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement