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