[dw-free] More admin page functionality. I know, this REALLY needs to be abstracted out to use DW::
[commit: http://hg.dwscoalition.org/dw-free/rev/847dc1707b04]
More admin page functionality. I know, this REALLY needs to be abstracted
out to use DW::Shop::Item::Account and DW::InviteCodes, but I don't have the
time this second. These need major cleanup.
Patch by
mark.
Files modified:
More admin page functionality. I know, this REALLY needs to be abstracted
out to use DW::Shop::Item::Account and DW::InviteCodes, but I don't have the
time this second. These need major cleanup.
Patch by
![[staff profile]](https://www.dreamwidth.org/img/silk/identity/user_staff.png)
Files modified:
- cgi-bin/LJ/Widget/ShopCart.pm
- htdocs/admin/pay/view.bml
-------------------------------------------------------------------------------- diff -r 9371c5583be4 -r 847dc1707b04 cgi-bin/LJ/Widget/ShopCart.pm --- a/cgi-bin/LJ/Widget/ShopCart.pm Sat May 02 04:32:44 2009 +0000 +++ b/cgi-bin/LJ/Widget/ShopCart.pm Sat May 02 06:00:48 2009 +0000 @@ -39,6 +39,8 @@ sub render_body { # no matter where we are $opts{receipt} = 1 unless $cart->state == $DW::Shop::STATE_OPEN; + $opts{receipt} = 1 + if $opts{admin}; $ret .= $class->start_form unless $opts{receipt}; @@ -50,7 +52,9 @@ sub render_body { $ret .= "<th>" . $class->ml( 'widget.shopcart.header.deliverydate' ) . "</th>"; $ret .= "<th>" . $class->ml( 'widget.shopcart.header.to' ) . "</th>"; $ret .= "<th>" . $class->ml( 'widget.shopcart.header.from' ) . "</th>"; - $ret .= "<th>" . $class->ml( 'widget.shopcart.header.price' ) . "</th></tr>"; + $ret .= "<th>" . $class->ml( 'widget.shopcart.header.price' ) . "</th>"; + $ret .= "<th>ADMIN</th>" if $opts{admin}; + $ret .= "</tr>"; foreach my $item ( @{$cart->items} ) { my $from_u = LJ::load_userid( $item->from_userid ); @@ -62,6 +66,28 @@ sub render_body { $ret .= "<td>" . $item->t_html . "</td>"; $ret .= "<td>" . ( $item->anonymous || !LJ::isu( $from_u ) ? $class->ml( 'widget.shopcart.anonymous' ) : $from_u->ljuser_display ) . "</td>"; $ret .= "<td>\$" . $item->cost . " USD</td>"; + if ( $opts{admin} ) { + $ret .= "<td>"; + if ( $item->t_email ) { + my $dbh = LJ::get_db_writer(); + my $acid = $dbh->selectrow_array( 'SELECT acid FROM shop_codes WHERE cartid = ? AND itemid = ?', + undef, $cart->id, $item->id ); + if ( $acid ) { + my ( $auth, $rcptid ) = $dbh->selectrow_array( 'SELECT auth, rcptid FROM acctcode WHERE acid = ?', undef, $acid ); + $ret .= DW::InviteCodes->encode( $acid, $auth ); + if ( my $ru = LJ::load_userid( $rcptid ) ) { + $ret .= ' (' . $ru->ljuser_display . ", <a href='$LJ::SITEROOT/admin/pay/index?view=" . $ru->user . "'>edit</a>)"; + } else { + $ret .= " (unused, <a href='$LJ::SITEROOT/admin/pay/view?striptimefrom=$acid'>strip</a>)"; + } + } else { + $ret .= 'no code yet or code was stripped'; + } + } else { + $ret .= '--'; + } + $ret .= "</td>"; + } $ret .= "</tr>"; } $ret .= "<tr><td colspan='6' class='total'>" . $class->ml( 'widget.shopcart.total' ) . " \$" . $cart->display_total . " USD</td></tr>"; diff -r 9371c5583be4 -r 847dc1707b04 htdocs/admin/pay/view.bml --- a/htdocs/admin/pay/view.bml Sat May 02 04:32:44 2009 +0000 +++ b/htdocs/admin/pay/view.bml Sat May 02 06:00:48 2009 +0000 @@ -14,6 +14,31 @@ return "<?needlogin?>" unless $remote; return BML::ml( "admin.noprivserror", { numprivs => $numprivs, needprivs => "<b>" . join(", ", @displayprivs) . "</b>"} ) unless LJ::check_priv($remote, 'payments'); + + # FIXME: there should be a better page for this or something + if ( my $acid = $GET{striptimefrom} ) { + if ( LJ::did_post() && LJ::check_form_auth() ) { + my $dbh = LJ::get_db_writer(); + my $ct = $dbh->do( 'DELETE FROM shop_codes WHERE acid = ?', + undef, $acid ); + return $dbh->errstr if $dbh->err; + return "Failed to strip the code, already stripped?" + unless $ct > 0; + return "Okay, code stripped."; + } + + my $auth = LJ::form_auth(); + return <<EOF; +<h1>Payment Manager - Strip Code</h1> +<p><strong>This action strips the paid time from an invite code. The code will still be +usable, but it will no longer grant the user with any paid time. Please confirm you wish +to do this by clicking the button below.</strong></p> +<form method='post' action='$LJ::SITEROOT/admin/pay/view?striptimefrom=$acid'> +$auth +<input type='submit' value='Strip that code!' /> +</form> +EOF + } my $body = '<h1>Payment Manager - View Cart</h1>'; $body .= '<p>[ <a href="/admin/pay/index.bml"><< Back to Index</a> ]</p>'; @@ -46,7 +71,7 @@ $body .= "<h3>Items</h3>"; if ( $cart->has_items ) { - $body .= LJ::Widget::ShopCart->render( receipt => 1, cart => $cart ); + $body .= LJ::Widget::ShopCart->render( admin => 1, cart => $cart ); } else { $body .= "<p>This cart has no items in it.</p>"; --------------------------------------------------------------------------------