($ML{'error.noremote'}) unless $remote; my $authas = $GET{'authas'} || $remote->{'user'}; my $u = LJ::get_authas_user($authas); return $err->($ML{'error.invalidauth'}) unless $u && $u->{'user'} ne "test"; # extra arguments for get requests my $getextra = $authas ne $remote->{'user'} ? "?authas=$authas" : ''; my $dbr = LJ::get_db_reader(); my $sth; if ($u->{'statusvis'} eq "S") { $title = "Suspended Account"; $body = ""; return; } $sth = $dbr->prepare("SELECT reason FROM acctinvite WHERE userid=? ORDER BY dateadd"); $sth->execute($u->{'userid'}); my @prev; my %reason; while ($_ = $sth->fetchrow_array) { $reason{$_} = 1; push @prev, [ split(/-/, $_) ]; } my @added; # REASONS TO GET INVITATION CODES REASON FORMAT # -------------------------------------------------------- # 1 in a week "week" # 1 per acked contribution "con-0123456789" # 1 per month of paid account time "pay-2342343243-nn # "" "" (payitem rcpt) "pay2---nn" # 1 per 20 support points "sup-20/40/60" # 5 per month for perm accounts "perm-200108-n" # 15 base for early adopters "early-nn" my $dbh; my $gen_code = sub { my $reasonlist = shift; my $reason = join("-", @$reasonlist); return 0 if $reason{$reason}; # duplicate $dbh ||= LJ::get_db_writer(); my $qr = $dbh->quote($reason); $dbh->do("INSERT INTO acctinvite (userid, reason, dateadd, acid) ". "VALUES ($u->{'userid'}, $qr, NOW(), 0)"); return 0 if $dbh->err; # already exists (race / slave behind) my $code = LJ::acct_code_generate($u->{'userid'}); my ($acid, $auth) = LJ::acct_code_decode($code); $dbh->do("UPDATE acctinvite SET acid=$acid WHERE ". "userid=$u->{'userid'} AND reason=$qr"); push @added, $reasonlist; return 1; }; my $reason_name = sub { my $r = shift; if ($r->[0] eq "week") { return "For having an account for at least a week."; } if ($r->[0] eq "con") { return "For [1]\">this contribution"; } if ($r->[0] eq "early") { return "For being an early adopter (#$r->[1])"; } if ($r->[0] eq "pay") { return "For payment #$r->[1] (#$r->[2])"; } if ($r->[0] eq "pay2") { return "For payment #$r->[1], item $r->[2] (#$r->[3])"; } if ($r->[0] eq "perm") { return "For having a permanent account ($r->[1], #$r->[2])"; } if ($r->[0] eq "sup") { return "For reaching $r->[1] support points."; } }; #### try to make some new ones ## for being a member for a week if (0 && ! $reason{'week'}) { # off $sth = $dbr->prepare("SELECT (UNIX_TIMESTAMP()-UNIX_TIMESTAMP(timecreate)) > (86400*7) FROM userusage WHERE userid=$u->{'userid'}"); $sth->execute; my ($been_week) = $sth->fetchrow_array; if ($been_week) { $gen_code->(['week']); } } ## one for every acked contribution $sth = $dbr->prepare("SELECT coid FROM contributed WHERE userid=$u->{'userid'} AND acks > 0"); $sth->execute; while (my ($coid) = $sth->fetchrow_array) { next if $reason{"con-$coid"}; $gen_code->(['con', $coid]); } ## one for each month of paid account time $sth = $dbr->prepare("SELECT payid, months FROM payments WHERE mailed<>'C' AND userid=$u->{'userid'}"); $sth->execute; while (my ($payid, $months) = $sth->fetchrow_array) { next if ($months > 24); for (1..$months) { $gen_code->(['pay', $payid, $_]); } } # and the new payment system: $sth = $dbr->prepare("SELECT payid, piid, qty FROM payitems ". "WHERE rcptid=? AND status='done' ". "AND item='paidacct'"); $sth->execute($u->{'userid'}); while (my ($payid, $piid, $months) = $sth->fetchrow_array) { next if $payid > 422525; # approx. last payid before invite codes were removed for (1..$months) { $gen_code->(['pay2', $payid, $piid, $_]); } } $sth = $dbr->prepare("SELECT pi.payid, pi.piid, pi.qty ". "FROM acctcode a, acctpayitem api, payitems pi ". "WHERE a.rcptid=? AND api.acid=a.acid ". "AND pi.piid=api.piid AND pi.status='done' ". "AND pi.item='paidacct'"); $sth->execute($u->{'userid'}); while (my ($payid, $piid, $months) = $sth->fetchrow_array) { next if $payid > 422525; # approx. last payid before invite codes were removed for (1..$months) { $gen_code->(['pay2', $payid, $piid, $_]); } } ## 15 for early adopters if (LJ::get_cap($u, "earlyadopter")) { for (1..15) { $gen_code->(['early', $_]); } } ## 1 per 20 support points $sth = $dbr->prepare("SELECT SUM(points) FROM supportpoints WHERE userid=$u->{'userid'}"); $sth->execute; { my ($points) = $sth->fetchrow_array; my $p = 20; while ($p <= $points) { $gen_code->(['sup', $p]); $p += 20; } } ## 5 per month for permanent accounters if ($u->{'caps'} & 0x10) { for (1..5) { $gen_code->(['perm', $now, $_]); } } #### apologize if they couldn't get more my $ct = scalar @added; unless ($ct) { $body .= "read this. p?>"; } #### show which new ones they got else { my $s = $ct == 1 ? " was" : "s were"; $body .= "$ct more code$s generated for the following reasons: p?>"; } #### show previous codes $body .= ""; foreach my $r (@prev) { $body .= "
  • " . $reason_name->($r) . "
  • \n"; } $body .= " p?>"; $body .= "Back to your list of codes."; return; } _code?> body=> page?>