<%args>
$user=>undef
$extra_info=>undef
</%args>
<%init>
return 50 if ($user !~ /^nug/); # para demos
return $m->comp("getusercredits2.m", %ARGS);
return undef unless $user;
my $credits = 50; # FIXME

my $dbh = $m->comp("/_shared/procs/utils/dbi_connect.m", database=>'guianet');
my $sth = $dbh->prepare("select credits from tdownloads_credits where username=?");
$sth->execute($user);

if ($sth->rows == 0){
	
	$dbh->do("insert into tdownloads_credits(username,credits) values('$user',$credits)");
	
}else{
	
	($credits) = $sth->fetchrow;
	
}

if ($extra_info){
	my ($use_count) = $dbh->selectrow_array("select count(*) from tdownloads_history where username='$user'");
	my $first_time = $use_count == 0;
	return ($credits, $first_time);
}else{
	return $credits;
}
</%init>
