Page 1 of 1

Premium days left?

Posted: Thu Nov 12, 2015 7:49 pm
by cbsarge
Is there any way to determine how many days of Premium membership a player has left?

Re: Premium days left?

Posted: Fri Nov 13, 2015 4:52 am
by KyleMassacre
Sure. You can use the TimeSpan or TimeLeft function (I forgot what it's called) or you can do something like:

Code: Select all

$premium = GetUserVariable(premium);//I think that's the user var. double check please
$now = time();
echo floor(($premium-$now)/86400); //Take the 2 time stamps and subtract them, then divide it by the number of seconds in a day. Floor just does a hardcore round down to the nearest whole number. i.e 1.9 = 1
 

Re: Premium days left?

Posted: Fri Nov 13, 2015 1:08 pm
by cbsarge
I tried something like that but, it shows the wrong value if you look at someone else's profile. Any way to only show it on your own profile?

This how I modified the player_info.php file that's part of the Premium module

Code: Select all

global $userId, $user;
    if ($user == null)
        $user = $userId;
$currentMembership = GetUserVariable(premiumMember, $user) + 0;
$nowtime = time();
$timeleftA = ($currentMembership - $nowtime) / 86400;
$timeleft = round($timeleftA, 2);
if (GetConfigValue("premiumMembershipPrice", "premium") + 0 == 0)
    return;
if (IsPremiumMember($_GET["id"] + 0))
    $profileStats["Premium Member"] = Translate("Yes ($timeleft days left)");
else
    $profileStats["Premium Member"] = Translate("No");

Re: Premium days left?

Posted: Fri Nov 13, 2015 2:28 pm
by cbsarge
ok, I think I got it. This code should (works on my server) display the Yes or No to being Premium Member and if its the players own profile it will display the days left.

Code: Select all

<?php
global $userId, $user;
    if ($user == null)
        $user = $userId;
$currentMembership = GetUserVariable(premiumMember, $user) + 0;
$nowtime = time();
$timeleftA = ($currentMembership - $nowtime) / 86400;
$timeleft = round($timeleftA, 2);
if (GetConfigValue("premiumMembershipPrice", "premium") + 0 == 0)
    return;
if (IsPremiumMember($_GET["id"] + 0))
    if ($_GET["id"] + 0 == $userId) // The user itself
    {
    $profileStats["Premium Member"] = Translate("Yes ($timeleft days left)");
    }
    else
    {
    $profileStats["Premium Member"] = Translate("Yes");    
    }
else
    $profileStats["Premium Member"] = Translate("No");
 

Re: Premium days left?

Posted: Fri Nov 13, 2015 5:42 pm
by gmoore
I wonder if something like your routine needs to go into the Premium Routine lib? With your permission of course.

Greg

Re: Premium days left?

Posted: Fri Nov 13, 2015 5:51 pm
by cbsarge
If you're asking me then absolutely ok with me. :D

Re: Premium days left?

Posted: Fri Nov 13, 2015 6:34 pm
by gmoore
Okay. Send me an email: admin@funmayhem.com.

Include the code, state that you are giving this code to us (either as a bug fix or as public domain) to incorporate into our codebase.

I will put it in, test it and push it to everyone.

(This will probably be our normal way to put changes into the core code we have)

Thanx!
Greg

Re: Premium days left?

Posted: Fri Nov 13, 2015 6:41 pm
by cbsarge
Sent. :)
gmoore wrote:Okay. Send me an email: admin@funmayhem.com.

Include the code, state that you are giving this code to us (either as a bug fix or as public domain) to incorporate into our codebase.

I will put it in, test it and push it to everyone.

(This will probably be our normal way to put changes into the core code we have)

Thanx!
Greg