예제 #1
0
 function submit_submission_form($id = 0, $values = array(), $args = array())
 {
     if (is_admin() && (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'fes-form-submission-form'))) {
         return;
     }
     global $edd_options;
     check_ajax_referer('fes-form-submission-form');
     @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
     $form_id = isset($_POST['form_id']) ? intval($_POST['form_id']) : 0;
     $db_form_id = EDD_FES()->helper->get_option('fes-submission-form', false);
     if ($form_id != $db_form_id) {
         $response = array('success' => false, 'redirect_to' => get_permalink($_POST['page_id']), 'message' => __('Access Denied: ' . $form_id . ' != ' . $db_form_id, 'edd_fes'), 'is_post' => true);
         echo json_encode($response);
         exit;
     }
     if (!$id && isset($_REQUEST['post_id']) && absint($_REQUEST['post_id'])) {
         $id = absint($_REQUEST['post_id']);
     }
     $user_id = get_current_user_id();
     $is_vendor = EDD_FES()->vendors->vendor_is_vendor($user_id);
     $is_admin = EDD_FES()->vendors->vendor_is_admin($user_id);
     // if they are not a vendor, admin, or in the backend
     if (!$is_admin && !is_admin() && !$is_vendor) {
         $response = array('success' => false, 'redirect_to' => get_permalink($_POST['page_id']), 'message' => __('Access Denied', 'edd_fes'), 'is_post' => true);
         echo json_encode($response);
         exit;
     }
     if ($id) {
         $post = get_post($id);
         $post_author = $post->post_author;
         // if they are not admin, in the admin, or the author of the post
         if (!$is_admin && !is_admin() && $id !== 0 && $post_author !== $user_id) {
             $response = array('success' => false, 'redirect_to' => get_permalink($_POST['page_id']), 'message' => __('Access Denied', 'edd_fes'), 'is_post' => true);
             echo json_encode($response);
             exit;
         }
     }
     $form_vars = $this->get_input_fields($form_id);
     $form_settings = get_post_meta($form_id, 'fes-form_settings', true);
     list($post_vars, $taxonomy_vars, $meta_vars) = $form_vars;
     // don't check captcha on post edit
     if (!$id) {
         // check recaptcha
         if ($this->search_array($post_vars, 'input_type', 'recaptcha')) {
             $this->validate_re_captcha();
         }
     }
     $error = apply_filters('fes_submit_post_validate', '', $form_id);
     if (!empty($error)) {
         $this->signal_error($error);
     }
     $pending = false;
     $new = true;
     $post_id = $id;
     if (!empty($post->post_status) && 'publish' != $post->post_status) {
         $status = $post->post_status;
     } else {
         $status = 'publish';
     }
     // already existing product
     if ($id && is_object(get_post($id))) {
         $new = false;
         $post_id = $id;
         if (!EDD_FES()->helper->get_option('fes-auto-approve-edits', false)) {
             $pending = true;
             $status = 'pending';
         }
     } else {
         if (!EDD_FES()->helper->get_option('fes-auto-approve-submissions', false)) {
             $pending = true;
             $status = 'pending';
         }
     }
     $post_author = get_current_user_id();
     $postarr = array('post_type' => 'download', 'post_status' => $status, 'post_author' => $post_author, 'post_title' => isset($_POST['post_title']) ? sanitize_text_field(trim($_POST['post_title'])) : '', 'post_content' => isset($_POST['post_content']) ? wp_kses($_POST['post_content'], fes_allowed_html_tags()) : '', 'post_excerpt' => isset($_POST['post_excerpt']) ? wp_kses($_POST['post_excerpt'], fes_allowed_html_tags()) : '');
     if (isset($_POST['category'])) {
         $category = $_POST['category'];
         $postarr['post_category'] = is_array($category) ? $category : array($category);
     }
     if (isset($_POST['tags'])) {
         $postarr['tags_input'] = explode(',', $_POST['tags']);
     }
     $postarr = apply_filters('fes_add_post_args', $postarr, $form_id, $form_settings, $form_vars);
     if ($new) {
         $post_id = wp_insert_post($postarr);
     } else {
         $postarr['ID'] = $post_id;
         wp_update_post($postarr);
     }
     if ($post_id) {
         self::update_post_meta($meta_vars, $post_id);
         // set the post form_id for later usage
         update_post_meta($post_id, '_fes-form_id', $form_id);
         // find our if any images in post content and associate them
         if (!empty($postarr['post_content'])) {
             $dom = new DOMDocument();
             $dom->loadHTML($postarr['post_content']);
             $images = $dom->getElementsByTagName('img');
             if ($images->length) {
                 foreach ($images as $img) {
                     $url = $img->getAttribute('src');
                     $url = str_replace(array('"', "'", "\\"), '', $url);
                     $attachment_id = fes_get_attachment_id_from_url($url, $post_author);
                     if ($attachment_id) {
                         fes_associate_attachment($attachment_id, $post_id);
                     }
                 }
             }
         }
         foreach ($taxonomy_vars as $taxonomy) {
             if (isset($_POST[$taxonomy['name']])) {
                 if (is_object_in_taxonomy('download', $taxonomy['name'])) {
                     $tax = $_POST[$taxonomy['name']];
                     // if it's not an array, make it one
                     if (!is_array($tax)) {
                         $tax = array($tax);
                     }
                     if ($taxonomy['type'] == 'text') {
                         $hierarchical = array_map('trim', array_map('strip_tags', explode(',', $_POST[$taxonomy['name']])));
                         wp_set_object_terms($post_id, $hierarchical, $taxonomy['name']);
                     } else {
                         if (is_taxonomy_hierarchical($taxonomy['name'])) {
                             wp_set_post_terms($post_id, $_POST[$taxonomy['name']], $taxonomy['name']);
                         } else {
                             if ($tax) {
                                 $non_hierarchical = array();
                                 foreach ($tax as $value) {
                                     $term = get_term_by('id', $value, $taxonomy['name']);
                                     if ($term && !is_wp_error($term)) {
                                         $non_hierarchical[] = $term->name;
                                     }
                                 }
                                 wp_set_post_terms($post_id, $non_hierarchical, $taxonomy['name']);
                             }
                         }
                         // hierarchical
                     }
                     // is text
                 }
                 // is object tax
             }
             // isset tax
         }
         $options = isset($_POST['option']) ? $_POST['option'] : '';
         $files = isset($_POST['files']) ? $_POST['files'] : '';
         $prices = array();
         $edd_files = array();
         if (isset($options) && $options != '') {
             foreach ($options as $key => $option) {
                 $prices[] = array('name' => isset($option['description']) ? sanitize_text_field($option['description']) : '', 'amount' => isset($option['price']) ? $option['price'] : '');
             }
             if (!empty($files)) {
                 foreach ($files as $key => $url) {
                     $edd_files[$key] = array('name' => basename($url), 'file' => $url, 'condition' => $key);
                 }
             }
         } elseif (!empty($files)) {
             // For when there are no prices or option names allowed, https://github.com/chriscct7/edd-fes/issues/417
             foreach ($files as $key => $url) {
                 $edd_files[$key] = array('name' => basename($url), 'file' => $url, 'condition' => $key);
             }
         }
         do_action('fes_submission_form_save_custom_fields', $post_id);
         if (count($prices) === 1 || count($prices) === 0) {
             if (!isset($prices[0]['amount'])) {
                 $prices[0]['amount'] = "";
             }
             update_post_meta($post_id, '_variable_pricing', 0);
             update_post_meta($post_id, 'edd_price', $prices[0]['amount']);
             update_post_meta($post_id, 'edd_variable_prices', $prices);
             // Save variable prices anyway so that price options are saved
         } else {
             update_post_meta($post_id, '_variable_pricing', 1);
             update_post_meta($post_id, 'edd_variable_prices', $prices);
             if (EDD_FES()->helper->get_option('fes-allow-multiple-purchase-mode', false)) {
                 update_post_meta($post_id, '_edd_price_options_mode', '1');
             }
         }
         if (!empty($files)) {
             $edd_files = apply_filters('fes_pre_files_save', $edd_files, $post_id);
             update_post_meta($post_id, 'edd_download_files', $edd_files);
         }
         if (EDD_FES()->integrations->is_commissions_active() && $new === true) {
             $commission = array('amount' => eddc_get_recipient_rate(0, $post_author), 'user_id' => $post_author, 'type' => 'percentage');
             update_post_meta($post_id, '_edd_commission_settings', $commission);
             update_post_meta($post_id, '_edd_commisions_enabled', '1');
         }
         do_action('fes_submit_submission_form_bottom', $post_id);
         $redirect_to = get_permalink(EDD_FES()->helper->get_option('fes-vendor-dashboard-page', false));
         if (EDD_FES()->vendors->vendor_can_edit_product($post_id)) {
             $redirect_to = add_query_arg(array('task' => 'edit-product'), $redirect_to);
             $redirect_to = add_query_arg(array('post_id' => $post_id), $redirect_to);
         } else {
             $redirect_to = add_query_arg(array('task' => 'dashboard'), $redirect_to);
         }
         // Unset edd session
         EDD()->session->set('edd_fes_post_id', '');
         if ($new) {
             if ($pending) {
                 // email admin
                 $to = apply_filters('fes_submission_form_pending_to_admin', edd_get_admin_notice_emails(), $post_id);
                 $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
                 $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
                 $subject = apply_filters('fes_submission_form_to_admin_subject', __('New Submission Received', 'edd_fes'));
                 $message = EDD_FES()->helper->get_option('fes-admin-new-submission-email', '');
                 $type = "post";
                 $id = $post_id;
                 $args = array('permissions' => 'fes-admin-new-submission-email-toggle');
                 EDD_FES()->emails->send_email($to, $from_name, $from_email, $subject, $message, $type, $id, $args);
                 // email user
                 $user = new WP_User($user_id);
                 $to = $user->user_email;
                 $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
                 $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
                 $subject = apply_filters('fes_submission_new_form_to_vendor_subject', __('Submission Received', 'edd_fes'));
                 $message = EDD_FES()->helper->get_option('fes-vendor-new-submission-email', '');
                 $type = "post";
                 $id = $post_id;
                 $args = array('permissions' => 'fes-vendor-new-submission-email-toggle');
                 EDD_FES()->emails->send_email($to, $from_name, $from_email, $subject, $message, $type, $id, $args);
                 do_action('fes_submission_form_new_pending', $post_id);
             } else {
                 do_action('fes_submission_form_new_published', $post_id);
             }
         } else {
             // submission heading to pending
             if ($pending) {
                 // email admin
                 $to = apply_filters('fes_submission_form_published_to_admin', edd_get_admin_notice_emails(), $post_id);
                 $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
                 $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
                 $subject = apply_filters('fes_submission_form_edit_to_admin_subject', __('New Submission Edit Received', 'edd_fes'));
                 $message = EDD_FES()->helper->get_option('fes-admin-new-submission-edit-email', '');
                 $type = "post";
                 $id = $post_id;
                 $args = array('permissions' => 'fes-admin-new-submission-edit-email-toggle');
                 EDD_FES()->emails->send_email($to, $from_name, $from_email, $subject, $message, $type, $id, $args);
                 do_action('fes_submission_form_edit_pending', $post_id);
             } else {
                 do_action('fes_submission_form_edit_published', $post_id);
             }
         }
         $response = array('success' => true, 'redirect_to' => $redirect_to, 'message' => __('Success!', 'edd_fes'), 'is_post' => true);
         $response = apply_filters('fes_add_post_redirect', $response, $post_id, $form_id);
         echo json_encode($response);
         exit;
     } else {
         $this->signal_error(__('Something went wrong! Error 1049: Post ID not set. Possibly Database lock in place.', 'edd_fes'));
     }
 }
예제 #2
0
/**
 * Setup PayPal receivers when a purchase is made
 *
 * @since 2.7
 * @param $receivers string The default receivers and their percentages as defined in the Payment Gateway settings
 * @param $payment_id int The payment ID of the purchase
 * @return receivers $string The modified receivers string
 */
function eddc_paypal_adaptive_autopay($receivers, $payment_id)
{
    if (!edd_get_option('edd_commissions_autopay_pa')) {
        return $receivers;
    }
    $cart = edd_get_payment_meta_cart_details($payment_id);
    if ('subtotal' == edd_get_option('edd_commissions_calc_base', 'subtotal')) {
        $total = edd_get_payment_subtotal($payment_id);
    } else {
        $total = edd_get_payment_amount($payment_id);
    }
    $final = array();
    foreach ($cart as $item) {
        $recipients = eddc_get_recipients($item['id']);
        if ('subtotal' == edd_get_option('edd_commissions_calc_base', 'subtotal')) {
            $price = $item['subtotal'];
        } else {
            $price = $item['price'];
        }
        foreach ($recipients as $recipient) {
            $type = eddc_get_commission_type($item['id']);
            $rate = eddc_get_recipient_rate($item['id'], $recipient);
            $args = array('price' => $price, 'rate' => $rate, 'type' => $type, 'download_id' => $item['id'], 'recipient' => $recipient, 'payment_id' => $payment_id);
            $amount = eddc_calc_commission_amount($args);
            $percentage = round(100 / $total * $amount, 2);
            $user = get_userdata($recipient);
            $custom_paypal = get_user_meta($recipient, 'eddc_user_paypal', true);
            $email = is_email($custom_paypal) ? $custom_paypal : $user->user_email;
            if ($percentage !== 0) {
                if (isset($final[$email])) {
                    $final[$email] = $percentage + $final[$email];
                } else {
                    $final[$email] = $percentage;
                }
            }
        }
    }
    $return = '';
    $counter = 0;
    $taken = 0;
    // Add up the total commissions
    foreach ($final as $person => $val) {
        $taken = $taken + $val;
    }
    // Calculate the final percentage the store owners should receive
    $remaining = 100 - $taken;
    $owners = $receivers;
    $owners = explode("\n", $owners);
    foreach ($owners as $key => $val) {
        $val = explode('|', $val);
        $email = $val[0];
        $percentage = $val[1];
        $remainder = $percentage / 100 * $remaining;
        if (isset($final[$email])) {
            $final[$email] = $final[$email] + $remainder;
        } else {
            $final[$email] = $remainder;
        }
    }
    // Rebuild the final PayPal receivers string
    foreach ($final as $person => $val) {
        if ($counter === 0) {
            $return = $person . "|" . $val;
        } else {
            $return = $return . "\n" . $person . "|" . $val;
        }
        $counter++;
    }
    //echo '<pre>'; print_r( $return ); echo '</pre>'; exit;
    return $return;
}
/**
 * Record Commissions
 *
 * @access      private
 * @since       1.0
 * @return      void
 */
function eddc_record_commission($payment_id, $new_status, $old_status)
{
    // Check if the payment was already set to complete
    if ($old_status == 'publish' || $old_status == 'complete') {
        return;
    }
    // Make sure that payments are only completed once
    // Make sure the commission is only recorded when new status is complete
    if ($new_status != 'publish' && $new_status != 'complete') {
        return;
    }
    if (edd_get_payment_gateway($payment_id) == 'manual_purchases' && !isset($_POST['commission'])) {
        return;
    }
    // do not record commission on manual payments unless specified
    if (edd_get_payment_meta($payment_id, '_edd_completed_date')) {
        return;
    }
    $payment_data = edd_get_payment_meta($payment_id);
    $user_info = maybe_unserialize($payment_data['user_info']);
    $cart_details = edd_get_payment_meta_cart_details($payment_id);
    $calc_base = edd_get_option('edd_commissions_calc_base', 'subtotal');
    $shipping = edd_get_option('edd_commissions_shipping', 'ignored');
    // loop through each purchased download and award commissions, if needed
    foreach ($cart_details as $download) {
        $download_id = absint($download['id']);
        $commissions_enabled = get_post_meta($download_id, '_edd_commisions_enabled', true);
        if ('subtotal' == $calc_base) {
            $price = $download['subtotal'];
        } else {
            if ('total_pre_tax' == $calc_base) {
                $price = $download['price'] - $download['tax'];
            } else {
                $price = $download['price'];
            }
        }
        if (!empty($download['fees'])) {
            foreach ($download['fees'] as $fee_id => $fee) {
                if (false !== strpos($fee_id, 'shipping')) {
                    // If we're adjusting the commission for shipping, we need to remove it from the calculation and then add it after the commission amount has been determined
                    if ('ignored' !== $shipping) {
                        continue;
                    }
                }
                $price += $fee['amount'];
            }
        }
        // if we need to award a commission, and the price is greater than zero
        if ($commissions_enabled && floatval($price) > '0') {
            // set a flag so downloads with commissions awarded are easy to query
            update_post_meta($download_id, '_edd_has_commission', true);
            $commission_settings = get_post_meta($download_id, '_edd_commission_settings', true);
            if ($commission_settings) {
                $type = eddc_get_commission_type($download_id);
                // but if we have price variations, then we need to get the name of the variation
                $has_variable_prices = edd_has_variable_prices($download_id);
                if ($has_variable_prices) {
                    $price_id = edd_get_cart_item_price_id($download);
                    $variation = edd_get_price_option_name($download_id, $price_id);
                }
                $recipients = eddc_get_recipients($download_id);
                // Record a commission for each user
                foreach ($recipients as $recipient) {
                    $rate = eddc_get_recipient_rate($download_id, $recipient);
                    // percentage amount of download price
                    $args = array('price' => $price, 'rate' => $rate, 'type' => $type, 'download_id' => $download_id, 'recipient' => $recipient, 'payment_id' => $payment_id);
                    $commission_amount = eddc_calc_commission_amount($args);
                    // calculate the commission amount to award
                    $currency = $payment_data['currency'];
                    // If shipping is included or not included, we need to adjust the amount
                    if (!empty($download['fees']) && 'ignored' !== $shipping) {
                        foreach ($download['fees'] as $fee_id => $fee) {
                            if (false !== strpos($fee_id, 'shipping')) {
                                // If we're adjusting the commission for shipping, we need to remove it from the calculation and then add it after the commission amount has been determined
                                if ('include_shipping' == $shipping) {
                                    $commission_amount += $fee['amount'];
                                }
                            }
                        }
                    }
                    $commission = array('post_type' => 'edd_commission', 'post_title' => $user_info['email'] . ' - ' . get_the_title($download_id), 'post_status' => 'publish');
                    $commission_id = wp_insert_post(apply_filters('edd_commission_post_data', $commission));
                    $commission_info = apply_filters('edd_commission_info', array('user_id' => $recipient, 'rate' => $rate, 'amount' => $commission_amount, 'currency' => $currency), $commission_id, $payment_id, $download_id);
                    eddc_set_commission_status($commission_id, 'unpaid');
                    update_post_meta($commission_id, '_edd_commission_info', $commission_info);
                    update_post_meta($commission_id, '_download_id', $download_id);
                    update_post_meta($commission_id, '_user_id', $recipient);
                    update_post_meta($commission_id, '_edd_commission_payment_id', $payment_id);
                    // If we are dealing with a variation, then save variation info
                    if ($has_variable_prices && isset($variation)) {
                        update_post_meta($commission_id, '_edd_commission_download_variation', $variation);
                    }
                    // If it's a renewal, save that detail
                    if (!empty($download['item_number']['options']['is_renewal'])) {
                        update_post_meta($commission_id, '_edd_commission_is_renewal', true);
                    }
                    do_action('eddc_insert_commission', $recipient, $commission_amount, $rate, $download_id, $commission_id, $payment_id);
                }
            }
        }
    }
}
function set_collaborators_regular_unfinished_commission($args)
{
    $post_id = (int) $args['post_id'];
    $new_post_id = (int) $args['new_post_id'];
    $commission = array();
    $old_commission = get_post_meta($post_id, '_edd_commission_settings', true);
    if (isset($old_commission['user_id'])) {
        $Main_Item_Id = get_parent_item($new_post_id);
        $users = explode(',', $old_commission['user_id']);
        $users[] = get_current_user_id();
        $Get_Commission_Rate = (int) eddc_get_recipient_rate(0, get_post_field('post_author', $Main_Item_Id));
        $Commission_Amounts = array();
        foreach ($users as $Item) {
            $Get_Commission_Amount = $Get_Commission_Rate / sizeof($users);
            $Commission_Amounts[] = (int) $Get_Commission_Amount;
            $Commission_Collaborators[] = $Item;
        }
        $commission = array('amount' => implode(',', $Commission_Amounts), 'user_id' => implode(',', $Commission_Collaborators), 'type' => 'percentage', 'from' => 'unfinished');
    }
    update_post_meta($new_post_id, '_edd_product_status', $args['_edd_product_status']);
    update_post_meta($new_post_id, '_edd_commission_settings', $commission);
}
/**
 * Record Commissions
 *
 * @access      private
 * @since       1.0
 * @return      void
 */
function eddc_record_commission($payment_id, $new_status, $old_status)
{
    // Check if the payment was already set to complete
    if ($old_status == 'publish' || $old_status == 'complete') {
        return;
    }
    // Make sure that payments are only completed once
    // Make sure the commission is only recorded when new status is complete
    if ($new_status != 'publish' && $new_status != 'complete') {
        return;
    }
    if (edd_get_payment_gateway($payment_id) == 'manual_purchases' && !isset($_POST['commission'])) {
        return;
    }
    // do not record commission on manual payments unless specified
    $payment_data = edd_get_payment_meta($payment_id);
    $user_info = maybe_unserialize($payment_data['user_info']);
    $cart_details = maybe_unserialize($payment_data['cart_details']);
    // loop through each purchased download and award commissions, if needed
    foreach ($cart_details as $download) {
        $download_id = absint($download['id']);
        $commissions_enabled = get_post_meta($download_id, '_edd_commisions_enabled', true);
        if ('subtotal' == edd_get_option('edd_commissions_calc_base', 'subtotal')) {
            $price = $download['subtotal'];
        } else {
            $price = $download['price'];
        }
        // if we need to award a commission, and the price is greater than zero
        if ($commissions_enabled && floatval($price) > '0') {
            // set a flag so downloads with commissions awarded are easy to query
            update_post_meta($download_id, '_edd_has_commission', true);
            $commission_settings = get_post_meta($download_id, '_edd_commission_settings', true);
            if ($commission_settings) {
                $type = eddc_get_commission_type($download_id);
                // but if we have price variations, then we need to get the name of the variation
                if (edd_has_variable_prices($download_id)) {
                    $price_id = edd_get_cart_item_price_id($download);
                    $variation = edd_get_price_option_name($download_id, $price_id);
                }
                $recipients = eddc_get_recipients($download_id);
                // Record a commission for each user
                foreach ($recipients as $recipient) {
                    $rate = eddc_get_recipient_rate($download_id, $recipient);
                    // percentage amount of download price
                    $commission_amount = eddc_calc_commission_amount($price, $rate, $type);
                    // calculate the commission amount to award
                    $currency = $payment_data['currency'];
                    $commission = array('post_type' => 'edd_commission', 'post_title' => $user_info['email'] . ' - ' . get_the_title($download_id), 'post_status' => 'publish');
                    $commission_id = wp_insert_post(apply_filters('edd_commission_post_data', $commission));
                    $commission_info = apply_filters('edd_commission_info', array('user_id' => $recipient, 'rate' => $rate, 'amount' => $commission_amount, 'currency' => $currency), $commission_id);
                    update_post_meta($commission_id, '_edd_commission_info', $commission_info);
                    update_post_meta($commission_id, '_commission_status', 'unpaid');
                    update_post_meta($commission_id, '_download_id', $download_id);
                    update_post_meta($commission_id, '_user_id', $recipient);
                    update_post_meta($commission_id, '_edd_commission_payment_id', $payment_id);
                    //if we are dealing with a variation, then save variation info
                    if (isset($variation)) {
                        update_post_meta($commission_id, '_edd_commission_download_variation', $variation);
                    }
                    do_action('eddc_insert_commission', $recipient, $commission_amount, $rate, $download_id, $commission_id, $payment_id);
                }
            }
        }
    }
}
예제 #6
0
/**
 * Display the commissions area for the customer view
 *
 * @since  3.2
 * @param  object $customer The Customer being displayed
 * @return void
 */
function eddc_customer_commissions_view($customer)
{
    ?>
	<div class="edd-item-notes-header">
		<?php 
    echo get_avatar($customer->email, 30);
    ?>
 <span><?php 
    echo $customer->name;
    ?>
</span>
	</div>

	<div id="edd-item-stats-wrapper" class="customer-section">
		<ul>
			<li>
				<span class="dashicons dashicons-chart-area"></span>
				<?php 
    echo edd_currency_filter(edd_format_amount(eddc_get_paid_totals($customer->user_id)));
    ?>
 <?php 
    _e('Paid Commissions', 'eddc');
    ?>
				<?php 
    $paid_sales = eddc_count_user_commissions($customer->user_id, 'paid');
    ?>
				<?php 
    if (!empty($paid_sales)) {
        ?>
				<br />
				<a title="<?php 
        _e('View All Paid Commissions', 'edd');
        ?>
" href="<?php 
        echo admin_url('edit.php?post_type=download&page=edd-commissions&view=paid&user='******'via %d sale', 'via %d sales', $paid_sales, 'eddc'), $paid_sales);
        ?>
				</a>
				<?php 
    }
    ?>
			</li>
			<li>
				<span class="dashicons dashicons-chart-area"></span>
				<?php 
    echo edd_currency_filter(edd_format_amount(eddc_get_unpaid_totals($customer->user_id)));
    ?>
 <?php 
    _e('Unpaid Commissions', 'eddc');
    ?>
				<?php 
    $unpaid_sales = eddc_count_user_commissions($customer->user_id, 'unpaid');
    ?>
				<?php 
    if (!empty($unpaid_sales)) {
        ?>
				<br />
				<a title="<?php 
        _e('View All Unpaid Commissions', 'edd');
        ?>
" href="<?php 
        echo admin_url('edit.php?post_type=download&page=edd-commissions&view=unpaid&user='******'via %d sale', 'via %d sales', $unpaid_sales, 'eddc'), $unpaid_sales);
        ?>
				</a>
				<?php 
    }
    ?>
			</li>
		</ul>
	</div>

	<?php 
    $downloads = eddc_get_download_ids_of_user($customer->user_id);
    ?>
	<?php 
    if (false !== $downloads) {
        ?>
	<div id="edd-item-tables-wrapper" class="customer-section">
		<h3><?php 
        printf(__('Commissioned %s', 'eddc'), edd_get_label_plural());
        ?>
</h3>

		<table class="wp-list-table widefat striped downloads">
			<thead>
				<tr>
					<th><?php 
        echo edd_get_label_singular();
        ?>
</th>
					<th><?php 
        _e('Rate', 'eddc');
        ?>
</th>
					<th width="120px"><?php 
        _e('Actions', 'eddc');
        ?>
</th>
				</tr>
			</thead>
			<tbody>
				<?php 
        if (!empty($downloads)) {
            ?>
					<?php 
            foreach ($downloads as $download) {
                ?>
						<?php 
                $download = new EDD_Download($download);
                ?>
						<?php 
                $commission_type = eddc_get_commission_type($download->ID);
                ?>
						<?php 
                $commission_rate = eddc_get_recipient_rate($download->ID, $customer->user_id);
                ?>
						<tr>
							<td><?php 
                echo $download->post_title;
                ?>
</td>
							<td>
								<?php 
                if ($commission_type === 'percentage') {
                    ?>
									<?php 
                    echo $commission_rate;
                    ?>
%
								<?php 
                } else {
                    ?>
									<?php 
                    echo edd_currency_filter(edd_format_amount($commission_rate));
                    ?>
								<?php 
                }
                ?>

							</td>
							<td>
								<a title="<?php 
                echo esc_attr(sprintf(__('View %s', 'edd'), $download->post_title));
                ?>
" href="<?php 
                echo esc_url(admin_url('post.php?action=edit&post=' . $download->ID));
                ?>
">
									<?php 
                printf(__('View %s', 'eddc'), edd_get_label_singular());
                ?>
								</a>
							</td>
						</tr>
					<?php 
            }
            ?>
				<?php 
        } else {
            ?>
					<tr><td colspan="2"><?php 
            printf(__('No %s Found', 'eddc'), edd_get_label_plural());
            ?>
</td></tr>
				<?php 
        }
        ?>
			</tbody>
		</table>

	</div>
	<?php 
    }
    ?>

	<div id="edd-item-tables-wrapper" class="customer-section">

		<h3><?php 
    _e('Recent Unpaid Commissions', 'edd');
    ?>
</h3>
		<?php 
    $args = array('user_id' => $customer->user_id, 'number' => 10);
    $commissions = eddc_get_unpaid_commissions($args);
    ?>
		<table class="wp-list-table widefat striped payments">
			<thead>
				<tr>
					<th><?php 
    _e('ID', 'edd');
    ?>
</th>
					<th><?php 
    _e('Item', 'edd');
    ?>
</th>
					<th><?php 
    _e('Amount', 'edd');
    ?>
</th>
				</tr>
			</thead>
			<tbody>
				<?php 
    if (!empty($commissions)) {
        ?>
					<?php 
        foreach ($commissions as $commission) {
            ?>
						<?php 
            $commission_meta = get_post_meta($commission->ID, '_edd_commission_info', true);
            ?>
						<tr>
							<td><?php 
            echo $commission->ID;
            ?>
</td>
							<td><?php 
            echo get_the_title(get_post_meta($commission->ID, '_download_id', true));
            ?>
</td>
							<td><?php 
            echo edd_currency_filter(edd_sanitize_amount($commission_meta['amount']));
            ?>
</td>
						</tr>
					<?php 
        }
        ?>
				<?php 
    } else {
        ?>
					<tr><td colspan="5"><?php 
        _e('No unpaid commissions', 'edd');
        ?>
</td></tr>
				<?php 
    }
    ?>
			</tbody>
		</table>

	</div>

	<?php 
}