Date expire for Subscribers


For those using the subscription module and would like to know how to calculate the time remaing for a user. The following codes will accomplish that.

Steps :
The first thing is to get the user id from cookies.
<?php
        
global $user$db$prefix;
        
cookiedecode($user);
        
$wsuserid$cookie[0]; 
        
?>

Now we have the userid inside the variable $wsuserid. We now need to query the subscription table to see if that user id exist and calculate the time. The following codes will accomplish that.

<?php
      $resultws_sub 
$db->sql_query("SELECT subscription_expire FROM ".$prefix."_subscriptions WHERE userid='$wsuserid'");
    while (
$row $db->sql_fetchrow($resultws_sub)) {
    
$wstime $row['subscription_expire'];//Places the expiration time within a variable
    
if($wstime ==""){//Checks if its blank
    
echo "you are not subscribed";//User will see this if they are not a subscriber.
    
}else{
    echo 
"Subscription expires<br>";//Text to let people know they are subscribed
    //Caculate expire date
$mydiff $wstime-time(); //we use the variable $wstime that contains the subscription period.
        
$myyearDiff floor($mydiff/60/60/24/365);
        
$mydiff -= $myyearDiff*60*60*24*365;
        if (
$myyearDiff 1) {
            
$mydiff $wstime-time();
        }
        
$mydaysDiff floor($mydiff/60/60/24);
        
$mydiff -= $mydaysDiff*60*60*24;
        
$myhrsDiff floor($mydiff/60/60);
        
$mydiff -= $myhrsDiff*60*60;
        
$myminsDiff floor($mydiff/60);
        
$mydiff -= $myminsDiff*60;
        
$mysecsDiff $mydiff;
        if (
$myyearDiff 1) {
            
$myrest "$mydaysDiff "._SBDAYS.", $myhrsDiff "._SBHOURS."";
        } elseif (
$myyearDiff == 1) {
            
$myrest "$myyearDiff "._SBYEAR.", $mydaysDiff "._SBDAYS."";
        } elseif (
$myyearDiff 1) {
            
$myrest "$myyearDiff "._SBYEARS.", $mydaysDiff "._SBDAYS."";
        }
        echo 
$myrest// after running all those codes we echo the result which is contained in $myrest
    
}
    }
      
?>
      

As you can see, it's pretty easy. The entire script should look like the following.

<?php
      
global $user$db$prefix;
      
cookiedecode($user);
      
$wsuserid$cookie[0];
      
$resultws_sub $db->sql_query("SELECT subscription_expire FROM ".$prefix."_subscriptions WHERE userid='$wsuserid'");
      while (
$row $db->sql_fetchrow($resultws_sub)) {
      
$wstime $row['subscription_expire'];//Places the expiration time within a variable
      
if($wstime ==""){//Checks if its blank
      
echo "you are not subscribed";//User will see this if they are not a subscriber.
      
}else{
      echo 
"Subscription expires<br>";//Text to let people know they are subscribed
      //Caculate expire date
      
$mydiff $wstime-time(); //we use the variable $wstime that contains the subscription period.
      
$myyearDiff floor($mydiff/60/60/24/365);
      
$mydiff -= $myyearDiff*60*60*24*365;
      if (
$myyearDiff 1) {
            
$mydiff $wstime-time();
        }
        
$mydaysDiff floor($mydiff/60/60/24);
        
$mydiff -= $mydaysDiff*60*60*24;
        
$myhrsDiff floor($mydiff/60/60);
        
$mydiff -= $myhrsDiff*60*60;
        
$myminsDiff floor($mydiff/60);
        
$mydiff -= $myminsDiff*60;
        
$mysecsDiff $mydiff;
        if (
$myyearDiff 1) {
            
$myrest "$mydaysDiff "._SBDAYS.", $myhrsDiff "._SBHOURS."";
        } elseif (
$myyearDiff == 1) {
            
$myrest "$myyearDiff "._SBYEAR.", $mydaysDiff "._SBDAYS."";
        } elseif (
$myyearDiff 1) {
            
$myrest "$myyearDiff "._SBYEARS.", $mydaysDiff "._SBDAYS."";
        }
    echo 
$myrest// after running all those codes we echo the result which is contained in $myrest
    //final results should say -->> Subscription expires 2 years, 35 days
    
}
    }
?>

That's all! You can now place those in any blocks or module that you want to display the expiration time for a nuke user.