get_option( 'referrals_status', AFFILIATES_REFERRAL_STATUS_ACCEPTED ); if ( isset( $_POST['status'] ) ) { switch ( $_POST['status'] ) { case AFFILIATES_REFERRAL_STATUS_ACCEPTED : case AFFILIATES_REFERRAL_STATUS_CLOSED : case AFFILIATES_REFERRAL_STATUS_PENDING : case AFFILIATES_REFERRAL_STATUS_REJECTED : $status = $_POST['status']; break; } } $reference = isset( $_POST['reference'] ) ? wp_strip_all_tags( $_POST['reference'] ) : ''; $saved = false; if ( isset( $_POST['save'] ) ) { if ( !wp_verify_nonce( $_POST['referral-nonce'], 'save' ) ) { wp_die( __( 'Access denied.', 'affiliates' ) ); } else { if ( !empty( $affiliate_id ) ) { if ( empty( $referral_id ) ) { $action = apply_filters( 'affiliates_admin_referral_edit_add_referral', array( 'add_referral' => true, 'output' => '' ), compact( 'referral_id', 'affiliate_id', 'datetime', 'description', 'amount', 'currency_id', 'status', 'reference', 'reference_amount' ) ); $output .= !empty( $action['output'] ) ? $action['output'] : ''; if ( !empty( $action['referral_id'] ) ) { $referral_id = $action['referral_id']; } if ( isset( $action['add_referral'] ) && $action['add_referral'] ) { global $captured_referral_id; add_action( 'affiliates_referral', 'affiliates_admin_referral_capture_id' ); affiliates_add_referral( $affiliate_id, null, $description, null, $amount, $currency_id, $status, 'manual', $reference, null, $reference_amount ); remove_action( 'affiliates_referral', 'affiliates_admin_referral_capture_id' ); if ( !empty( $captured_referral_id ) ) { $referral_id = $captured_referral_id; } } if ( !empty( $referral_id ) ) { $output .= '
'; $output .= '
' . __( 'The referral has been created.', 'affiliates' ) . '
'; $saved = true; } else { $output .= '
'; $output .= '
' . __( 'The referral has not been created. Duplicate?', 'affiliates' ) . '
'; } } else { $action = apply_filters( 'affiliates_admin_referral_edit_update_referral', array( 'update_referral' => true, 'output' => '' ), compact( 'referral_id', 'affiliate_id', 'datetime', 'description', 'amount', 'currency_id', 'status', 'reference', 'reference_amount' ) ); $output .= !empty( $action['output'] ) ? $action['output'] : ''; if ( isset( $action['update_referral'] ) && $action['update_referral'] ) { if ( affiliates_update_referral( $referral_id, array( 'affiliate_id' => intval( $affiliate_id ), 'datetime' => $datetime, 'description' => $description, 'reference_amount' => $reference_amount, 'amount' => $amount, 'currency_id' => $currency_id, 'status' => $status, 'reference' => $reference ) ) ) { $output .= '
'; $output .= '
' . __( 'The referral has been saved.', 'affiliates' ) . '
'; $saved = true; } } } } } } if ( $referral_id !== null ) { $referrals_table = _affiliates_get_tablename( 'referrals' ); if ( $referrals = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $referrals_table WHERE referral_id = %d", $referral_id ) ) ) { if ( count( $referrals ) > 0 ) { $referral = $referrals[0]; $affiliate_id = $referral->affiliate_id; $datetime = $referral->datetime; $description = $referral->description; $reference_amount = $referral->reference_amount; $amount = $referral->amount; $currency_id = $referral->currency_id; $status = $referral->status; $reference = $referral->reference; } } } $output .= sprintf( '
', empty( $referral_id ) ? 'new-referral' : 'edit-referral' ); $output .= '

'; if ( empty( $referral_id ) ) { $output .= __( 'New Referral', 'affiliates' ); } else { $output .= __( 'Edit Referral', 'affiliates' ); } $output .= '

'; $output .= '
'; $output .= '
'; if ( $referral_id ) { $output .= sprintf( '', intval( $referral_id ) ); } $output .= ''; $output .= '

'; $output .= ''; $output .= '

'; $output .= Affiliates_UI_Elements::render_select( 'select.affiliates-uie' ); $output .= '

'; $output .= ''; $output .= '

'; $output .= '

'; $output .= ''; $output .= '

'; $output .= '

'; $output .= ''; $output .= '

'; $output .= '

'; $output .= ''; $output .= '

'; $status_descriptions = array( AFFILIATES_REFERRAL_STATUS_ACCEPTED => __( 'Accepted', 'affiliates' ), AFFILIATES_REFERRAL_STATUS_CLOSED => __( 'Closed', 'affiliates' ), AFFILIATES_REFERRAL_STATUS_PENDING => __( 'Pending', 'affiliates' ), AFFILIATES_REFERRAL_STATUS_REJECTED => __( 'Rejected', 'affiliates' ), ); $output .= '

'; $output .= ''; $output .= '

'; $output .= '

'; $output .= ''; $output .= '

'; $output .= '

'; $output .= ''; $output .= '

'; $output .= apply_filters( 'affiliates_admin_referral_edit_form_suffix', '', compact( 'referral_id', 'affiliate_id', 'datetime', 'description', 'reference_amount', 'amount', 'currency_id', 'status', 'reference' ) ); $output .= wp_nonce_field( 'save', 'referral-nonce', true, false ); $output .= sprintf( '', __( 'Save', 'affiliates' ) ); $output .= ' '; $output .= sprintf( '%s', $cancel_url, $saved ? __( 'Back', 'affiliates' ) : __( 'Cancel', 'affiliates' ) ); $output .= '
'; $output .= '
'; $output .= '
'; echo $output; affiliates_footer(); } /** * Captures the referral ID for a new referral. * @param int $referral_id */ function affiliates_admin_referral_capture_id( $referral_id ) { global $captured_referral_id; $captured_referral_id = $referral_id; }