htdocs/admin/invites/codetrace.bml
author fu
Fri Jan 27 13:51:52 2012 +0800
changeset 4239 555a213bdacc
parent 3871 4852ffcec614
permissions -rw-r--r--
http://bugs.dwscoalition.org/show_bug.cgi?id=4230

Fix all the bad my $var = ... if ... constructions.

Patch by sophie.
     1 <?page
     2 title=>Codetrace
     3 body<=
     4 <?_code
     5 {
     6     use strict;
     7     use vars qw( %POST );
     8 
     9     my $remote = LJ::get_remote;
    10     my @displayprivs = ( "finduser:codetrace", "finduser:*" );
    11     my $numprivs = @displayprivs;
    12 
    13     return "<?needlogin?>"
    14         unless $remote;
    15 
    16     return BML::ml( "admin.noprivserror", { numprivs => $numprivs, needprivs => "<b>" . join(", ", @displayprivs) . "</b>"} )
    17         unless $remote->has_priv( "finduser", "codetrace" );
    18 
    19     my $ret;
    20 
    21     $ret .= "<form method='GET'>";
    22     $ret .= "View invite details: ";
    23     $ret .= "<table summary=''>";
    24     $ret .= "<tr><td><label>By code: </label></td>";
    25     $ret .= "<td>" . LJ::html_text( { name => 'code', maxlength => DW::InviteCodes::CODE_LEN, size => DW::InviteCodes::CODE_LEN } ) . "</td></tr>";
    26     $ret .= "<tr><td><label>By account: </label></td>";
    27     $ret .= "<td>" . LJ::html_text( { name => 'account', maxlength => 25, size=> 20 } ) . "</td></tr>";
    28     $ret .= "<tr><td colspan='2' align='right'>";
    29     $ret .= LJ::html_submit( value => "View" );
    30     $ret .= "</td></tr></table>";
    31     $ret .= "</form>";
    32     $ret .= "<?hr?>";
    33 
    34     if ( $GET{code} ) {
    35 
    36         my $code = DW::InviteCodes->new( code => $GET{code} );
    37         return $ret . "Error: invalid code '$GET{code}'" unless $code;
    38 
    39         $ret .= display_codes ( $remote, $code );
    40 
    41     } elsif ( $GET{account} ) {
    42 
    43         my $account = LJ::load_user( $GET{account} );
    44         return $ret . "Error: invalid user '$GET{account}'" unless $account;
    45 
    46         my @used = DW::InviteCodes->by_recipient( userid => $account->id );
    47         my @owned = DW::InviteCodes->by_owner( userid => $account->id );
    48 
    49         $ret .= display_codes ( $account, @used, @owned );
    50     }
    51 
    52     return $ret;
    53 }
    54 
    55 sub display_codes {
    56     my ($account, @codes) = @_;
    57 
    58     my $ret = "<table border='1' cellpadding='5'><thead><tr><th>Code</th><th>Owner</th><th>Recipient</th><th>Reason</th><th>Date generated</th><th>Date sent</th><th>Date used</th><th>Email</th></tr></thead>";
    59 
    60     foreach my $code ( @codes ) {
    61         my $owner = $code->owner == $account->id ? $account : LJ::load_userid( $code->owner );
    62         my $recipient = $code->is_used ? LJ::load_userid( $code->recipient ) : undef;
    63         $ret .= "<tr>";
    64         $ret .= "<td><tt>" . $code->code . "</tt></td>";
    65         $ret .= "<td>" . ( $owner ? $owner->ljuser_display : "" ) . "</td>";
    66         $ret .= "<td>" . ( $code->is_used ? $recipient->ljuser_display : "" ) . "</td>";
    67         $ret .= "<td>" . $code->reason . "</td>";
    68         $ret .= "<td>" . LJ::time_to_http( $code->timegenerate). "</td>";
    69         $ret .= "<td>" . ( $code->timesent ? LJ::time_to_http( $code->timesent ) : "" ) . "</td>";
    70         $ret .= "<td>" . ( $code->is_used ? LJ::time_to_http( $recipient->timecreate ) : "" ) . "</td>";
    71         $ret .= "<td>" . $code->email . "</td>";
    72         $ret .= "</tr>";
    73     }
    74     $ret .= "</table>";
    75 
    76     return $ret;
    77 }
    78 
    79  _code?>
    80 <=body
    81 page?>