Buy for friends! body<= login."; } my $ret; $ret .= ""; $ret .= "paid account for one of the people on your friends list! p?>"; # get status of all friends # TAG:FR:bml_paidaccts_friends:get_friend_statuses my $sth = $dbr->prepare("SELECT u.userid, u.user, u.name, u.caps, u.journaltype ". "FROM friends f, user u, userusage uu ". "WHERE f.userid=? AND u.userid=f.friendid AND uu.userid=f.friendid ". "AND u.statusvis='V' LIMIT 500"); $sth->execute($remote->{'userid'}); my %f; while (my $f = $sth->fetchrow_hashref) { next unless $f->{'journaltype'} eq "P" || $f->{'journaltype'} eq "C"; $f{$f->{'userid'}} = $f; } # when are people's paid accounts expiring? # TAG:FR:bml_paidaccts_friends:get_friend_expiring $sth = $dbr->prepare("SELECT p.userid, UNIX_TIMESTAMP(p.paiduntil) AS 'paiduntil' ". "FROM friends f, paiduser p ". "WHERE f.userid=? AND f.friendid=p.userid"); $sth->execute($remote->{'userid'}); while (my $f = $sth->fetchrow_hashref) { next unless $f{$f->{'userid'}}; $f{$f->{'userid'}}->{'paiduntil'} = $f->{'paiduntil'}; } # who has pending gifts? # TAG:FR:bml_paidaccts_friends:get_pending_gifts $sth = $dbr->prepare("SELECT p.userid, p.months ". "FROM friends f, payments p ". "WHERE f.userid=? AND f.friendid=p.userid AND ". " p.used='N' AND p.giveafter > 0"); $sth->execute($remote->{'userid'}); while (my $f = $sth->fetchrow_hashref) { next unless $f{$f->{'userid'}}; $f{$f->{'userid'}}->{'pending'} += $f->{'months'}; } unless (%f) { $ret .= ""; return $ret; } my $now = time; my $one_month = 60*60*24*30; # separate users into two groups: those needy and those who aren't my (@needy_paid, @needy_free, @not); foreach my $f (sort { $a->{'user'} cmp $b->{'user'} } values %f) { my $paid_months; if ($f->{'caps'} & 8) { $paid_months += ($f->{'paiduntil'} - $now) / $one_month; $paid_months = 0 if $paid_months < 0; } $paid_months += $f->{'pending'}; # permanent account holders or those with 6 months of real or pending gift payments # aren't needy if ($f->{'caps'} & 16 || $paid_months > 6) { push @not, $f; next; } # now, they're needy, but do they already have a paid account? if ($f->{'caps'} & 8) { push @needy_paid, $f; } else { push @needy_free, $f; } } my $dump_table = sub { my $list = shift; $ret .= "
"; $ret .= LJ::ljuser($f->{'user'}, { 'type' => $f->{'journaltype'} }); $ret .= " - " . LJ::ehtml($f->{'name'}); unless ($f->{'caps'} & 16) { # unless a permanent account $ret .= " [buy gift]"; } $ret .= " |