init
This commit is contained in:
119
ljcom/htdocs/invite/claim.bml
Normal file
119
ljcom/htdocs/invite/claim.bml
Normal file
@@ -0,0 +1,119 @@
|
||||
<?_code
|
||||
{
|
||||
use strict;
|
||||
use vars qw(%GET $title $body);
|
||||
|
||||
$title = "Exchange Invitation codes";
|
||||
$body = "";
|
||||
|
||||
my $err = sub {
|
||||
$title = "Error";
|
||||
$body = LJ::bad_input(@_);
|
||||
return;
|
||||
};
|
||||
|
||||
my $remote = LJ::get_remote();
|
||||
return $err->($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;
|
||||
|
||||
if ($u->{'statusvis'} eq "S") {
|
||||
$title = "Suspended Account";
|
||||
$body = "<?h1 Suspended h1?><?p This journal has been either temporarily or permanently suspended by $LJ::SITENAME for policy violation. You are unable to exchange invite until this journal is unsuspended. p?>";
|
||||
return;
|
||||
}
|
||||
|
||||
# find out how much we owe them
|
||||
my $get_amt = sub {
|
||||
my $rowct = shift;
|
||||
|
||||
my $amt = 0;
|
||||
if ($rowct > 10) {
|
||||
$amt += 0.50*10;
|
||||
$amt += 0.25*($rowct-10);
|
||||
} else {
|
||||
$amt += 0.50*$rowct;
|
||||
}
|
||||
$amt = 25.00 if $amt > 25.00;
|
||||
|
||||
return $amt;
|
||||
};
|
||||
|
||||
# print dollars
|
||||
my $damt = sub { sprintf("\$%.02f", shift()) };
|
||||
|
||||
my $dbh = LJ::get_db_writer();
|
||||
|
||||
unless (LJ::did_post()) {
|
||||
# authas switcher form
|
||||
$body .= "<form method='get' action='claim.bml'>\n";
|
||||
$body .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'} }) . "\n";
|
||||
$body .= "</form>\n\n";
|
||||
|
||||
my $rowct = $dbh->selectrow_array("SELECT COUNT(*) FROM acctcode WHERE userid=? AND rcptid=0",
|
||||
undef, $u->{'userid'});
|
||||
unless ($rowct > 0) {
|
||||
$body .= "<?h1 No Codes h1?><?p You have no unused invite codes. p?>";
|
||||
return;
|
||||
}
|
||||
|
||||
my $amt = $get_amt->($rowct);
|
||||
|
||||
$body .= "<?h1 Exchange Invite Codes h1?>";
|
||||
$body .= "<?p You can use this tool to exchange your unused invite codes for a ";
|
||||
$body .= "coupon which you can then use at the <a href='$LJ::SITEROOT/pay/'>LiveJournal ";
|
||||
$body .= "Store</a>. p?>";
|
||||
|
||||
$body .= "<?p You will receive \$0.50 for each of your first 10 invite codes, then \$0.25 ";
|
||||
$body .= "for each additional code, with a maximum of \$25.00. Since you have a total of ";
|
||||
$body .= "$rowct unused invite codes, the final amount will be " . $damt->($amt) . ". p?>";
|
||||
|
||||
$body .= "<?p The coupon will be emailed to <b>$u->{'email'}</b>. Please be sure this email ";
|
||||
$body .= "address is correct. p?>";
|
||||
|
||||
my $getextra = $authas ne $remote->{'user'} ? "?authas=$authas" : '';
|
||||
$body .= "<form method='post' action='claim.bml$getextra'>";
|
||||
$body .= "<p align='center'>";
|
||||
$body .= LJ::html_submit(undef, "Generate Coupon",
|
||||
{ 'disabled' => $amt <= 0 });
|
||||
$body .= "</p></form>";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
my $system_id = LJ::get_userid("system") or die;
|
||||
my $rowct = $dbh->do("UPDATE acctcode SET rcptid=? WHERE userid=? AND rcptid=0",
|
||||
undef, $system_id, $u->{'userid'});
|
||||
unless ($rowct > 0) {
|
||||
$body = "<?h1 No Codes h1?><?p You have no unused invite codes. p?>";
|
||||
return;
|
||||
}
|
||||
|
||||
my $amt = $get_amt->($rowct);
|
||||
|
||||
my ($tokenid, $token) =
|
||||
LJ::Pay::new_coupon('dollaroffint', $amt, $u->{'userid'}, 0);
|
||||
return "<?h1 Error h1?><?p Error generating coupon. p?>"
|
||||
unless $tokenid && $token;
|
||||
|
||||
# send the coupon to the user in an email
|
||||
LJ::Pay::send_coupon_email($u, $token, $amt, "int");
|
||||
|
||||
# log to statushistory
|
||||
LJ::statushistory_add($u->{'userid'}, $remote->{'userid'}, "invitecp",
|
||||
"generated " . $damt->($amt) . " intangible coupon ($token) for " .
|
||||
"$rowct invite codes");
|
||||
|
||||
$body = "<?h1 Success! h1?><?p You have been emailed a coupon for " . $damt->($amt) .
|
||||
" in exchange for your $rowct invite codes. p?>";
|
||||
return;
|
||||
}
|
||||
_code?><?page
|
||||
title=><?_code return $title; _code?>
|
||||
body=><?_code return $body; _code?>
|
||||
page?>
|
||||
211
ljcom/htdocs/invite/gen.bml
Normal file
211
ljcom/htdocs/invite/gen.bml
Normal file
@@ -0,0 +1,211 @@
|
||||
<?_code
|
||||
{
|
||||
use strict;
|
||||
use vars qw(%GET $title $body);
|
||||
|
||||
$title = "Generate Invitation codes";
|
||||
$body = "";
|
||||
|
||||
my @time = localtime();
|
||||
my $now = sprintf("%04d%02d", $time[5]+1900, $time[4]+1);
|
||||
if ($now gt "2004") {
|
||||
$body = "Invite code generation is disabled, as invite codes are no longer necessary.";
|
||||
return;
|
||||
}
|
||||
|
||||
my $err = sub {
|
||||
$title = "Error";
|
||||
$body = LJ::bad_input(@_);
|
||||
return;
|
||||
};
|
||||
|
||||
my $remote = LJ::get_remote();
|
||||
return $err->($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 = "<?h1 Suspended h1?><?p This journal has been either temporarily or permanently suspended by $LJ::SITENAME for policy violation. You are unable to generate any more account codes until this journal is unsuspended p?>";
|
||||
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-<payid>-<piid>-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 <a href=\"/site/contributors.bml?mode=detail&coid=$r->[1]\">this contribution</a>";
|
||||
}
|
||||
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 .= "<?h1 Sorry h1?><?p You are not eligible to receive any more invitation codes at this time. p?><?p For more information on how invitation codes are given out, <a href=\"http://www.livejournal.com/support/faqbrowse.bml?faqid=103\">read this</a>. p?>";
|
||||
}
|
||||
|
||||
#### show which new ones they got
|
||||
else
|
||||
{
|
||||
my $s = $ct == 1 ? " was" : "s were";
|
||||
$body .= "<?h1 Codes Generated h1?><?p <b>$ct</b> more code$s generated for the following reasons: <ul>";
|
||||
foreach my $r (@added) {
|
||||
$body .= "<li>" . $reason_name->($r) . "</li>\n";
|
||||
}
|
||||
$body .= "</ul> p?>";
|
||||
}
|
||||
|
||||
#### show previous codes
|
||||
$body .= "<?h1 Previous Codes h1?><?p You've previously had codes generated for the following reasons: <ul>";
|
||||
foreach my $r (@prev) {
|
||||
$body .= "<li>" . $reason_name->($r) . "</li>\n";
|
||||
}
|
||||
$body .= "</ul> p?>";
|
||||
|
||||
$body .= "<?hr?>Back to your <a href=\"./$getextra\">list of codes</a>.";
|
||||
|
||||
return;
|
||||
}
|
||||
_code?><?page
|
||||
title=><?_code return $title; _code?>
|
||||
body=><?_code return $body; _code?>
|
||||
page?>
|
||||
80
ljcom/htdocs/invite/index.bml
Normal file
80
ljcom/htdocs/invite/index.bml
Normal file
@@ -0,0 +1,80 @@
|
||||
<?_code
|
||||
{
|
||||
use strict;
|
||||
use vars qw(%GET $title $body);
|
||||
|
||||
$title = $ML{'.title'};
|
||||
$body = "";
|
||||
|
||||
my $err = sub {
|
||||
$title = $ML{'.error'};
|
||||
$body = LJ::bad_input(@_);
|
||||
return;
|
||||
};
|
||||
|
||||
my $remote = LJ::get_remote();
|
||||
return $err->($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;
|
||||
|
||||
# extra arguments for get requests
|
||||
my $getextra = $authas ne $remote->{'user'} ? "?authas=$authas" : '';
|
||||
|
||||
# authas switcher form
|
||||
$body .= "<form method='get' action='./'>\n";
|
||||
$body .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'} }) . "\n";
|
||||
$body .= "</form>\n\n";
|
||||
|
||||
$body .= "<?h1 $ML{'.invite_header'} h1?><?p $ML{'.why_codes'} p?>";
|
||||
$body .= "<?h1 $ML{'.how_header'} h1?>";
|
||||
$body .= BML::ml('.how_detail', { 'factors_url' => "$LJ::SITEROOT/support/faqbrowse.bml?faqid=103" });
|
||||
|
||||
$body .= "<p><center>";
|
||||
$body .= "<table border=\"2\" cellpadding=\"5\">";
|
||||
|
||||
$body .= "<tr><td><b>$ML{'.code'}</b></td><td><b>$ML{'.redeemed'}</b></td></tr>\n";
|
||||
|
||||
my $dbh = LJ::get_db_writer();
|
||||
my $sth = $dbh->prepare("SELECT acid, rcptid, auth FROM acctcode WHERE userid=? ORDER BY rcptid");
|
||||
$sth->execute($u->{'userid'});
|
||||
my $ct = 0;
|
||||
|
||||
while (my ($acid, $rcptid, $auth) = $sth->fetchrow_array)
|
||||
{
|
||||
my $code = LJ::acct_code_encode($acid, $auth);
|
||||
my $rcpt;
|
||||
if ($rcptid) {
|
||||
$rcpt = LJ::get_username($rcptid);
|
||||
next unless $rcpt;
|
||||
}
|
||||
$ct++;
|
||||
|
||||
$body .= "<tr><td><font size=\"+1\"><tt>$code</tt></font></td><td>";
|
||||
if ($rcpt) {
|
||||
$body .= "<?ljuser $rcpt ljuser?>";
|
||||
} else {
|
||||
$body .= "<i>$ML{'.unused'}</i>";
|
||||
$body .= " " . BML::ml('Actionlink', { 'link' => "<a href=\"/create.bml?code=$code\">$ML{'.use'}</a>" });
|
||||
}
|
||||
$body .= "</td></tr>\n";
|
||||
}
|
||||
|
||||
unless ($ct) {
|
||||
$body .= "<tr><td colspan=\"2\"><i>$ML{'.none'}</i></td></tr>\n";
|
||||
}
|
||||
|
||||
$body .= "<tr><td colspan=\"2\" align=\"center\"><b><a href=\"gen.bml$getextra\">$ML{'.genmore '}</a></b></td></tr>\n";
|
||||
|
||||
$body .= "</table>";
|
||||
$body .= "</center>";
|
||||
|
||||
return;
|
||||
}
|
||||
_code?><?page
|
||||
title=><?_code return $title; _code?>
|
||||
body=><?_code return $body; _code?>
|
||||
page?>
|
||||
Reference in New Issue
Block a user