gcphost Posted March 3, 2011 Share Posted March 3, 2011 Hi all I offer a 31 day free trial of my product. This is managed with the free trial add-on and works very well. The big problem is people can order more then 1 trial per account. I could never get an action hook to stop the person from fully ordering SO I have restored to using a `clean up` script to help. This will terminate all related products if the user has more then 1 So if usera buys 2 trials - both will be terminated. I use mysql to calculate if its duplicated - I know this can be optimized more - I really didnt care. I hope someone else will find it useful. <?php // include WHMCS and base functions require("../../dbconnect.php"); require("../../includes/functions.php"); require("functions.php"); $url = "http://..../includes/api.php"; # URL to WHMCS API file $username = ""; # Admin username goes here $password = ""; # Admin password goes here $packageid=""; $allq = "SELECT O.userid FROM tblorders O, tblhosting TH WHERE TH.packageid='$packageid' AND TH.orderid=O.id"; $sq_allq = mysql_query($allq) or die(mysql_error()); $okarray=array(); while($row = mysql_fetch_array($sq_allq)){ if($row['userid']){ $allqq = "SELECT TH.id, O.userid FROM tblorders O, tblhosting TH WHERE TH.packageid='$packageid' AND TH.orderid=O.id AND O.userid='".$row['userid']."'"; $sq_allq2 = mysql_query($allqq)or die(mysql_error()); $cnt=mysql_num_rows($sq_allq2); if($cnt > 1){ while($row2 = mysql_fetch_array($sq_allq2)){ echo "duplicate found ".$cnt." user #". $row2['userid'].", hosting id#".$row2['id']."\n"; $postfields=array() $postfields["username"] = $username; $postfields["password"] = md5($password); $postfields["action"] = "moduleterminate"; $postfields["accountid"] = $row2['id']; $postdata = http_build_query($postfields); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); $data = file_get_contents($url, false, $context); $data = explode(";",$data); foreach ($data AS $temp) { $temp = explode("=",$temp); $results[$temp[0]] = $temp[1]; } if ($results["result"]=="success") { echo "ok\n"; } else { # An error occured echo "The following error occured: ".$results["message"]."\n"; } } } } } ?> I run this as: modules/freetrial/duplicates.php 0 Quote Link to comment Share on other sites More sharing options...
jeremyhaber Posted March 10, 2011 Share Posted March 10, 2011 Awesome job. Just so you know on most hosts "file_get_contents" will not allow you to get the contents of a URL for security reasons. I suggest you use cURL to make your API requests to the terminate function As well take a look at this quick tip I posted: http://forum.whmcs.com/showthread.php?t=36321 If you run the code on your local server you can save yourself the trouble of connecting to the server (why make a connection when you don't need to?). As well as removing the need for a username/password in the script. 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.