Paid Time Transfer body<= {'user'}; my $u = LJ::get_authas_user($authas); return LJ::bad_input($ML{'error.invalidauth'}) unless $u; # extra arguments for get requests my $getextra = $authas ne $remote->{'user'} ? "?authas=$authas" : ''; my $ret = ""; my $dbh = LJ::get_db_writer(); my $is_perm = sub { return $_[0]->{caps} & (1 << $LJ::Pay::capinf{perm}->{bit}) }; my $paid_bit = (1 << $LJ::Pay::capinf{paid}->{bit}); my $get_days = sub { return sprintf("%0.02f", $_[0] / 86400) }; my $get_secs = sub { return $dbh->selectrow_array ("SELECT UNIX_TIMESTAMP(paiduntil)-UNIX_TIMESTAMP() " . "FROM paiduser WHERE userid=?", undef, $_[0]->{userid}); }; if (LJ::did_post() && $POST{'submit'}) { my $u_from = ($has_priv ? LJ::load_user($POST{user}) : $remote) or return LJ::bad_input("User $POST{user} doesn't exist."); my $u_to = LJ::load_user($POST{userto}) or return LJ::bad_input("User $POST{userto} doesn't exist."); return LJ::bad_input("Source and destination users must be different") if LJ::u_equals($u_from, $u_to); return LJ::bad_input("Source user must be currently logged in user") unless $has_priv || LJ::u_equals($u_from, $u); return LJ::bad_input("Destination user already has a permanent account!") if $is_perm->($u_to); return LJ::bad_input("You must have purchased a permanent account to transfer paid time to another user.") unless $has_priv || $is_perm->($u_from); my $secs = $get_secs->($u_from); my $days = $get_days->($secs); return "" unless $secs > 0; $ret .= "Transferred $days days from " . LJ::ljuser($u_from) . " to " . LJ::ljuser($u_to) . "\n"; # first try inserting in the case of a new paid account LJ::update_user($u_to, { raw => "caps=caps|$paid_bit" }); $dbh->do("INSERT INTO paiduser (userid, paiduntil) " . "VALUES (?, FROM_UNIXTIME(UNIX_TIMESTAMP()+?))", undef, $u_to->{userid}, $secs); # already a paid user, just extend their existing row if ($dbh->err) { $dbh->do("UPDATE paiduser " . "SET paiduntil=FROM_UNIXTIME(UNIX_TIMESTAMP(paiduntil)+?) " . "WHERE userid=?", undef, $secs, $u_to->{userid}); } # log to statushistory so there's a record of this action my $logmesg = "Transferred $days days: $u_from->{user} => $u_to->{user}"; LJ::statushistory_add($u_from, $remote->{'userid'}, "acct_xfer_src", $logmesg); LJ::statushistory_add($u_to, $remote->{'userid'}, "acct_xfer_dest", $logmesg); ### take away time from source if ($is_perm->($u_from)) { # take away their paid until time so they can't give it away again. # don't remove them from paiduser though, since they're permanent and need # to be here to get the email alias generated. $dbh->do("UPDATE paiduser SET paiduntil='0000-00-00' WHERE userid=?", undef, $u_from->{userid}); } else { $dbh->do("DELETE FROM paiduser WHERE userid=?", undef, $u_from->{userid}); LJ::update_user($u_from->{userid}, { raw => "caps=caps&~$paid_bit" }); } my $source = $has_priv && $POST{'anon'} ? "(ANONYMOUS)" : $u_from->{user}; LJ::send_mail({ 'to' => $u_to->{email}, 'from' => $LJ::ACCOUNTS_EMAIL, 'fromname' => 'LiveJournal', 'subject' => "Gift! Paid account left-overs...", 'body' => "Hey,\n\nUser $source has decided to transfer his/her remaining paid time to you. So, you now have a paid account (if you didn't have one already) and $days more days of paid account status.\n\nYou can find out more about paid accounts and their benefits at http://www.livejournal.com/paidaccounts/\n\nEnjoy!\n", }); return $ret; } # authas switcher form -- makes no sense if user is priv'd unless ($has_priv) { $ret .= "
\n"; $ret .= LJ::make_authas_select($remote, { authas => $GET{'authas'} }) . "\n"; $ret .= "
\n\n"; } $ret .= ""; # standard intro paragraph for users if ($has_priv) { $ret .= ""; # only available to admins and perm account holders } elsif (! $is_perm->($u)) { $ret .= ""; return $ret; # standard form for normal permanent accounts } else { my $secs = $get_secs->($u); my $days = $get_days->($secs); $ret .= " 0; $ret .= "to any other non-permanent account. p?>"; unless ($secs > 0) { $ret .= ""; return $ret; } } # begin submission form $ret .= "
"; # from user $ret .= ""; # to user $ret .= ""; $ret .= ""; # anonymous option for admins if ($has_priv) { $ret .= ""; $ret .= ""; } $ret .= "
From:"; if ($has_priv) { $ret .= LJ::html_text({ size => 15, maxlength => 15, name => 'user' }); } else { $ret .= LJ::ljuser($u); } $ret .= "
To:" . LJ::html_text({ size => 15, maxlength => 15, name => 'userto' }); $ret .= "
Anonymous?" . LJ::html_check({ value => 1, name => 'anon' }); $ret .= "
 "; $ret .= LJ::html_submit('submit' => "Transfer"); $ret .= "
"; return $ret; } _code?> <=body page?>