Gossamer Forum
Quote Reply
global question
I have the following global to determine the age of a user:
Code:
sub {
my ($rec) = @_;
my $age;
my $day;
my $month;
my $year;
my $birthyear = $rec->{'BirthYear'};
my $birthmonth = $rec->{'BirthMonth'};
my $birthday = $rec->{'BirthDay'};
my $date = GT::Date::date_get();
($year, $month, $day) = split(/-/, $date);
$age = $year - $birthyear;
if ($month < $birthmonth) {
$age = $age - 1;
}
if ($month = $birthmonth) {
if ($day < $birthday) {
$age = $age - 1;
}
}

return $age;
}

It works great...if you are logged in. My question is two-fold:
1. If you are not logged in, the age shows the current year (e.g., 2008). I am using other globals that work properly without logging in so is there something here that could be fixed to work for guests?

2. If you are logged in, the age global displays the correct date in all places except when called in the link.html loop by modify.cgi. Then you get some odd string like 20080206008755. Back to the first part...is there something inherent in the above global that needs to be fixed to be more stable?

TIA,
Kevin

My Green Promise: To learn (and practice) as much as I can about living a sustainable life and then spreading the word.
What's your Green Promise?
Quote Reply
Re: [kthull] global question In reply to
Ok...looking at my post, I see why you need to be logged in for it to show the age. Wink Is there a way to get around that? <%age (LinkOwner)%> or something like that?

I still can't figure out the modify.cgi busted age though.
Kevin

My Green Promise: To learn (and practice) as much as I can about living a sustainable life and then spreading the word.
What's your Green Promise?
Quote Reply
Re: [kthull] global question In reply to
Hi,

The problem is whose age do you calcualate the logged user or Linkowner? And what is the usage of your global? In any cases, I guess you should pass in the username and the below should work:


Cheers,



sub {
my ($username,$rec) = @_;
$rec = $DB->table('Users')->get($username);
my $age;
my $day;
my $month;
my $year;
my $birthyear = $rec->{'BirthYear'};
my $birthmonth = $rec->{'BirthMonth'};
my $birthday = $rec->{'BirthDay'};

Links::init_date();
my $date = GT::Date::date_get();
($year, $month, $day) = split(/-/, $date);
$age = $year - $birthyear;
if ($month < $birthmonth) {
$age = $age - 1;
}
if ($month = $birthmonth) {
if ($day < $birthday) {
$age = $age - 1;
}
}

return $age;
}

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] global question In reply to
Great...that fixed the first issue. Any thoughts why the age global goes funky when called via the modify.cgi? (still does it after global mod)
Kevin

My Green Promise: To learn (and practice) as much as I can about living a sustainable life and then spreading the word.
What's your Green Promise?
Quote Reply
Re: [kthull] global question In reply to
Hi
,
What do you mean "goes funky" ? :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] global question In reply to
I mentioned it upthread...meaning instead of showing the age, it shows something like 20080206008755. I've already figured a workaround, but I'd be curious to know what's up.

Thanks,
Kevin

My Green Promise: To learn (and practice) as much as I can about living a sustainable life and then spreading the word.
What's your Green Promise?
Quote Reply
Re: [kthull] global question In reply to
Hi,

I think its :

GT::Date::date_get();

You could try this:

Code:
date_set_format('%yyyy%-%mm%-%dd%');
my $date = GT::Date::date_get();

I had a similar problem in one of my plugins - where it wasn't returning the right format Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] global question In reply to
Links wasn't too happy with the date_set_format statement.
Kevin

My Green Promise: To learn (and practice) as much as I can about living a sustainable life and then spreading the word.
What's your Green Promise?
Quote Reply
Re: [kthull] global question In reply to
What, you got an error?

Could be you need:

GT::Date::date_set_format('%yyyy%-%mm%-%dd%');

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] global question In reply to
That did it! Thanks all.
Kevin

My Green Promise: To learn (and practice) as much as I can about living a sustainable life and then spreading the word.
What's your Green Promise?