Making WordPress.org


Ignore:
Timestamp:
02/26/2016 12:56:15 AM (10 years ago)
Author:
kovshenin
Message:

WordCamp.org: Reintegrate branch into trunk (wordcamp-payments-network)

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network

  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-dashboard.php

    r2597 r2632  
    33class Payment_Requests_Dashboard {
    44    public static $list_table;
    5     public static $db_version = 6;
     5    public static $db_version = 7;
    66    public static $import_results = null;
    77
     
    2020        add_action( 'network_admin_menu', array( __CLASS__, 'network_admin_menu' ) );
    2121        add_action( 'init', array( __CLASS__, 'upgrade' ) );
     22        add_action( 'init', array( __CLASS__, 'process_approval' ) );
    2223        add_action( 'init', array( __CLASS__, 'process_export_request' ) );
    2324        add_action( 'init', array( __CLASS__, 'process_import_request' ) );
     
    6162            post_id int(11) unsigned NOT NULL default '0',
    6263            created int(11) unsigned NOT NULL default '0',
     64            updated int(11) unsigned NOT NULL default '0',
    6365            paid int(11) unsigned NOT NULL default '0',
    6466            category varchar(255) NOT NULL default '',
     
    99101            while ( $requests = get_posts( array(
    100102                'paged' => $paged++,
    101                 'post_status' => array( 'paid', 'unpaid', 'incomplete' ),
     103                'post_status' => 'any',
    102104                'post_type' => 'wcp_payment_request',
    103105                'posts_per_page' => 20,
     
    142144        }
    143145
     146        $back_compat_statuses = array(
     147            'unpaid' => 'draft',
     148            'incomplete' => 'wcb-incomplete',
     149            'paid' => 'wcb-paid',
     150        );
     151
     152        // Map old statuses to new statuses.
     153        if ( array_key_exists( $request->post_status, $back_compat_statuses ) ) {
     154            $request->post_status = $back_compat_statuses[ $request->post_status ];
     155        }
     156
     157        // One of these timestamps.
     158        while ( true ) {
     159            $updated_timestamp = absint( get_post_meta( $request->ID, '_wcb_updated_timestamp', time() ) );
     160            if ( $updated_timestamp ) break;
     161
     162            $updated_timestamp = strtotime( $request->post_modified_gmt );
     163            if ( $updated_timestamp ) break;
     164
     165            $updated_timestamp = strtotime( $request->post_date_gmt );
     166            if ( $updated_timestamp ) break;
     167
     168            $updated_timestamp = strtotime( $request->post_date );
     169            break;
     170        }
     171
    144172        return array(
    145173            'blog_id' => get_current_blog_id(),
    146174            'post_id' => $request->ID,
    147175            'created' => get_post_time( 'U', true, $request->ID ),
     176            'updated' => $updated_timestamp,
    148177            'paid'    => absint( get_post_meta( $request->ID, '_camppayments_date_vendor_paid', true ) ),
    149178            'due' => absint( get_post_meta( $request->ID, '_camppayments_due_by', true ) ),
     
    228257            <h1>Vendor Payments</h1>
    229258
     259            <?php do_action( 'admin_notices' ); ?>
    230260            <?php settings_errors(); ?>
    231261
     
    268298
    269299        <?php
     300    }
     301
     302    /**
     303     * Process Approve button in network admin
     304     */
     305    public static function process_approval() {
     306        if ( ! current_user_can( 'network_admin' ) )
     307            return;
     308
     309        if ( empty( $_GET['wcb-approve'] ) || empty( $_GET['_wpnonce'] ) )
     310            return;
     311
     312        list( $blog_id, $post_id ) = explode( '-', $_GET['wcb-approve'] );
     313
     314        if ( ! wp_verify_nonce( $_GET['_wpnonce'], sprintf( 'wcb-approve-%d-%d', $blog_id, $post_id ) ) ) {
     315            add_action( 'admin_notices', function() {
     316                ?><div class="notice notice-error is-dismissible">
     317                    <p><?php _e( 'Error! Could not verify nonce.', 'wordcamporg' ); ?></p>
     318                </div><?php
     319            });
     320            return;
     321        }
     322
     323        switch_to_blog( $blog_id );
     324        $post = get_post( $post_id );
     325        if ( $post->post_type == 'wcp_payment_request' ) {
     326            $post->post_status = 'wcb-approved';
     327            wp_insert_post( $post );
     328
     329            WordCamp_Budgets::log( $post->ID, get_current_user_id(), 'Request approved via Network Admin', array(
     330                'action' => 'approved',
     331            ) );
     332
     333            add_action( 'admin_notices', function() {
     334                ?><div class="notice notice-success is-dismissible">
     335                    <p><?php _e( 'Success! Request has been marked as approved.', 'wordcamporg' ); ?></p>
     336                </div><?php
     337            });
     338        }
     339        restore_current_blog();
    270340    }
    271341
     
    324394        }
    325395
     396        $status = $_POST['wcpn_export_status'];
     397        if ( ! in_array( $status, array( 'wcb-approved', 'wcb-paid' ) ) )
     398            $status = 'wcb-approved';
     399
    326400        $start_date = strtotime( $_POST['wcpn_export_start_date'] . ' 00:00:00' );
    327401        $end_date   = strtotime( $_POST['wcpn_export_end_date']   . ' 23:59:59' );
     
    329403        $filename = sanitize_file_name( $filename );
    330404
    331         $report = self::generate_payment_report( $_POST['wcpn_date_type'], $start_date, $end_date, $export_type );
     405        $report = self::generate_payment_report( $status, $start_date, $end_date, $export_type );
    332406
    333407        if ( is_wp_error( $report ) ) {
     
    355429     * @return string | WP_Error
    356430     */
    357     protected static function generate_payment_report( $date_type, $start_date, $end_date, $export_type ) {
     431    protected static function generate_payment_report( $status, $start_date, $end_date, $export_type ) {
    358432        global $wpdb;
    359 
    360         if ( ! in_array( $date_type, array( 'paid', 'created' ), true ) ) {
    361             return new WP_Error( 'wcpn_bad_date_type', 'Invalid date type.' );
    362         }
    363433
    364434        if ( ! is_int( $start_date ) || ! is_int( $end_date ) ) {
     
    367437
    368438        $table_name = self::get_table_name();
     439        $date_type = 'updated';
     440
     441        if ( $status == 'wcb-paid' )
     442            $date_type = 'paid';
    369443
    370444        $request_indexes = $wpdb->get_results( $wpdb->prepare( "
     
    381455        $args = array(
    382456            'request_indexes' => $request_indexes,
    383             'date_type' => $date_type,
    384457            'start_date' => $start_date,
    385458            'end_date' => $end_date,
    386459            'export_type' => $export_type,
     460            'status' => $status,
    387461        );
    388462
     
    400474        $args = wp_parse_args( $args, array(
    401475            'request_indexes' => array(),
     476            'status' => '',
    402477        ) );
    403478
     
    414489
    415490        foreach( $args['request_indexes'] as $index ) {
    416             fputcsv( $report, self::get_report_row( $index ) );
     491            $row = self::get_report_row( $index, $args );
     492            if ( ! empty( $row ) ) {
     493                fputcsv( $report, $row );
     494            }
    417495        }
    418496
     
    431509        $args = wp_parse_args( $args, array(
    432510            'request_indexes' => array(),
     511            'status' => '',
    433512        ) );
    434513
     
    452531            switch_to_blog( $index->blog_id );
    453532            $post = get_post( $index->post_id );
     533
     534            if ( $args['status'] && $post->post_status != $args['status'] )
     535                continue;
    454536
    455537            if ( get_post_meta( $post->ID, '_camppayments_payment_method', true ) != 'Check' )
     
    539621        $args = wp_parse_args( $args, array(
    540622            'request_indexes' => array(),
     623            'status' => '',
    541624        ) );
    542625
     
    605688            $post = get_post( $index->post_id );
    606689
     690            if ( $args['status'] && $post->post_status != $args['status'] )
     691                continue;
     692
    607693            if ( get_post_meta( $post->ID, '_camppayments_payment_method', true ) != 'Direct Deposit' )
    608694                continue;
     
    738824        $args = wp_parse_args( $args, array(
    739825            'request_indexes' => array(),
     826            'status' => '',
    740827        ) );
    741828
     
    752839            switch_to_blog( $index->blog_id );
    753840            $post = get_post( $index->post_id );
     841
     842            if ( $args['status'] && $post->post_status != $args['status'] )
     843                continue;
    754844
    755845            // Only wires here.
     
    9551045     *
    9561046     * @param stdClass $index
     1047     * @param array $args
    9571048     *
    9581049     * @return array
    9591050     */
    960     protected static function get_report_row( $index ) {
     1051    protected static function get_report_row( $index, $args ) {
    9611052        switch_to_blog( $index->blog_id );
    9621053
    963         $request          = get_post( $index->post_id );
     1054        $request = get_post( $index->post_id );
     1055
     1056        $back_compat_statuses = array(
     1057            'unpaid' => 'draft',
     1058            'incomplete' => 'wcb-incomplete',
     1059            'paid' => 'wcb-paid',
     1060        );
     1061
     1062        // Map old statuses to new statuses.
     1063        if ( array_key_exists( $request->post_status, $back_compat_statuses ) ) {
     1064            $request->post_status = $back_compat_statuses[ $request->post_status ];
     1065        }
     1066
     1067        if ( $args['status'] && $request->post_status != $args['status'] ) {
     1068            return null;
     1069        }
     1070
    9641071        $currency         = get_post_meta( $index->post_id, '_camppayments_currency',         true );
    9651072        $category         = get_post_meta( $index->post_id, '_camppayments_payment_category', true );
     
    10321139            <?php wp_nonce_field( 'export', 'wcpn_request_export' ); ?>
    10331140
    1034             <p>
    1035                 This form will supply a CSV file with payment requests matching the parameters you select below.
    1036                 For example, all requests that were <code>paid</code> between <code><?php echo esc_html( $last_month ); ?></code> and <code><?php echo esc_html( $today ); ?></code>.
    1037             </p>
    1038 
    1039             <p>
    1040                 <label>
    1041                     Date type:
    1042                     <select name="wcpn_date_type">
    1043                         <option value="created">created</option>
    1044                         <option value="paid" selected>paid</option>
    1045                     </select>
    1046                 </label>
    1047             </p>
    1048 
    1049             <p>
    1050                 <label>
    1051                     Start date:
    1052                     <input type="date" name="wcpn_export_start_date" class="medium-text" value="<?php echo esc_attr( $last_month ); ?>" />
    1053                 </label>
    1054             </p>
    1055 
    1056             <p>
    1057                 <label>
    1058                     End date:
    1059                     <input type="date" name="wcpn_export_end_date" class="medium-text" value="<?php echo esc_attr( $today ); ?>" />
    1060                 </label>
    1061             </p>
    1062 
    1063             <p>
    1064                 <label>Export Type:
    1065                     <select name="wcpn_export_type">
    1066                         <?php foreach ( self::get_export_types() as $key => $export_type ) : ?>
    1067                         <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $export_type['label'] ); ?></option>
    1068                         <?php endforeach; ?>
    1069                     </select>
    1070                 </label>
    1071 
    1072             <?php submit_button( 'Export' ); ?>
     1141            <h2>Export Settings</h2>
     1142
     1143            <table class="form-table">
     1144                <tr>
     1145                    <th><label>Status</label></th>
     1146                    <td>
     1147                        <select name="wcpn_export_status">
     1148                            <option value="wcb-approved"><?php _e( 'Approved', 'wordcamporg' ); ?></option>
     1149                            <option value="wcb-paid"><?php _e( 'Paid', 'wordcamporg' ); ?></option>
     1150                        </select>
     1151                    </td>
     1152                </tr>
     1153                <tr>
     1154                    <th><label>Date Range</label></th>
     1155                    <td>
     1156                        <input type="date" name="wcpn_export_start_date" class="medium-text" value="<?php echo esc_attr( $last_month ); ?>" /> to
     1157                        <input type="date" name="wcpn_export_end_date" class="medium-text" value="<?php echo esc_attr( $today ); ?>" />
     1158                    </td>
     1159                </tr>
     1160                <tr>
     1161                    <th><label>Format</label></th>
     1162                    <td>
     1163                        <select name="wcpn_export_type">
     1164                            <?php foreach ( self::get_export_types() as $key => $export_type ) : ?>
     1165                            <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $export_type['label'] ); ?></option>
     1166                            <?php endforeach; ?>
     1167                        </select>
     1168                    </td>
     1169                </tr>
     1170            </table>
     1171
     1172            <?php submit_button( 'Download Export' ); ?>
    10731173        </form>
    10741174
     
    12301330        $tab = 'overdue';
    12311331        $tabs = array(
    1232             'pending',
    12331332            'overdue',
     1333
     1334            'pending-approval',
     1335            'approved',
     1336            'pending-payment',
    12341337            'paid',
     1338            'cancelled-failed',
    12351339            'incomplete',
     1340
    12361341            'export',
    12371342            'import',
     
    12511356        $current_section = self::get_current_tab();
    12521357        $sections = array(
    1253             'overdue' => 'Overdue',
    1254             'pending' => 'Pending',
    1255             'paid'    => 'Paid',
    1256             'incomplete' => __( 'Incomplete', 'wordcamporg' ),
    1257             'export'     => __( 'Export', 'wordcamporg' ),
    1258             'import'     => __( 'Import', 'wordcamporg' ),
     1358            'overdue'          => __( 'Overdue', 'wordcamporg' ), // pending-approval + after due date
     1359            'pending-approval' => __( 'Pending Approval', 'wordcamporg' ),
     1360            'approved'         => __( 'Approved', 'wordcamporg' ),
     1361            'pending-payment'  => __( 'Pending Payment', 'wordcamporg' ),
     1362            'paid'             => __( 'Paid', 'wordcamporg' ),
     1363            'cancelled-failed' => __( 'Cancelled/Failed', 'wordcamporg' ),
     1364            'incomplete'       => __( 'Incomplete', 'wordcamporg' ),
     1365            'export'           => __( 'Export', 'wordcamporg' ),
     1366            'import'           => __( 'Import', 'wordcamporg' ),
    12591367        );
    12601368
Note: See TracChangeset for help on using the changeset viewer.