function pmpro_report_sales_widget()
{
    global $wpdb;
    ?>
<style>
	#pmpro_report_sales div {text-align: center;}
	#pmpro_report_sales em {display: block; font-style: normal; font-size: 2em; margin: 5px;}	
</style>
<span id="#pmpro_report_sales">
	<div style="width: 25%; float: left;">	
		<em><?php 
    echo pmpro_getSales("all time");
    ?>
</em>	
		<label>All Time</label>
		<em><?php 
    echo pmpro_formatPrice(pmpro_getRevenue("all time"));
    ?>
</em>		
	</div>
	<div style="width: 25%; float: left;">	
		<em><?php 
    echo pmpro_getSales("this year");
    ?>
</em>
		<label>This Year</label>
		<em><?php 
    echo pmpro_formatPrice(pmpro_getRevenue("this year"));
    ?>
</em>		
	</div>
	<div style="width: 25%; float: left;">	
		<em><?php 
    echo pmpro_getSales("this month");
    ?>
</em>
		<label>This Month</label>
		<em><?php 
    echo pmpro_formatPrice(pmpro_getRevenue("this month"));
    ?>
</em>		
	</div>
	<div style="width: 25%; float: left;">
		<em><?php 
    echo pmpro_getSales("today");
    ?>
</em>
		<label>Today</label>
		<em><?php 
    echo pmpro_formatPrice(pmpro_getRevenue("today"));
    ?>
</em>		
	</div>	
	<div class="clear"></div>
</span>
<?php 
}
        echo pmpro_formatPrice($auser->initial_payment);
        ?>
								<?php 
    }
    ?>
								<?php 
    if ((double) $auser->initial_payment > 0 && (double) $auser->billing_amount > 0) {
        ?>
+<br /><?php 
    }
    ?>
								<?php 
    if ((double) $auser->billing_amount > 0) {
        ?>
									<?php 
        echo pmpro_formatPrice($auser->billing_amount);
        ?>
/<?php 
        if ($auser->cycle_number > 1) {
            echo $auser->cycle_number . " " . $auser->cycle_period . "s";
        } else {
            echo $auser->cycle_period;
        }
        ?>
								<?php 
    }
    ?>
								<?php 
    if ((double) $auser->initial_payment <= 0 && (double) $auser->billing_amount <= 0) {
        ?>
									-
 function sendToTwocheckout(&$order)
 {
     global $pmpro_currency;
     $tco_args = array('sid' => pmpro_getOption("twocheckout_accountnumber"), 'mode' => '2CO', 'li_0_type' => 'product', 'li_0_name' => substr($order->membership_level->name . " at " . get_bloginfo("name"), 0, 127), 'li_0_quantity' => 1, 'li_0_tangible' => 'N', 'li_0_product_id' => $order->code, 'merchant_order_id' => $order->code, 'currency_code' => $pmpro_currency, 'pay_method' => 'CC', 'purchase_step' => 'billing-information', 'x_receipt_link_url' => admin_url("admin-ajax.php") . "?action=twocheckout-ins");
     //taxes on initial amount
     $initial_payment = $order->InitialPayment;
     $initial_payment_tax = $order->getTaxForPrice($initial_payment);
     $initial_payment = round((double) $initial_payment + (double) $initial_payment_tax, 2);
     //taxes on the amount (NOT CURRENTLY USED)
     $amount = $order->PaymentAmount;
     $amount_tax = $order->getTaxForPrice($amount);
     $amount = round((double) $amount + (double) $amount_tax, 2);
     // Recurring membership
     if (pmpro_isLevelRecurring($order->membership_level)) {
         $tco_args['li_0_startup_fee'] = number_format($initial_payment - $amount, 2, ".", "");
         //negative amount for lower initial payments
         $recurring_payment = number_format($order->membership_level->billing_amount, 2, ".", "");
         $recurring_payment_tax = number_format($order->getTaxForPrice($recurring_payment), 2, ".", "");
         $recurring_payment = number_format(round((double) $recurring_payment + (double) $recurring_payment_tax, 2), 2, ".", "");
         $tco_args['li_0_price'] = number_format($recurring_payment, 2, ".", "");
         $tco_args['li_0_recurrence'] = $order->BillingFrequency == 1 ? $order->BillingFrequency . ' ' . $order->BillingPeriod : $order->BillingFrequency . ' ' . $order->BillingPeriod . 's';
         if (property_exists($order, 'TotalBillingCycles')) {
             $tco_args['li_0_duration'] = $order->BillingFrequency * $order->TotalBillingCycles . ' ' . $order->BillingPeriod;
         } else {
             $tco_args['li_0_duration'] = 'Forever';
         }
     } else {
         $tco_args['li_0_price'] = number_format($initial_payment, 2, ".", "");
     }
     // Demo mode?
     if (empty($order->gateway_environment)) {
         $gateway_environment = pmpro_getOption("gateway_environment");
     } else {
         $gateway_environment = $order->gateway_environment;
     }
     if ("sandbox" === $gateway_environment || "beta-sandbox" === $gateway_environment) {
         Twocheckout::sandbox(true);
         $tco_args['demo'] = 'Y';
     } else {
         Twocheckout::sandbox(false);
     }
     // Trial?
     //li_#_startup_fee	Any start up fees for the product or service. Can be negative to provide discounted first installment pricing, but cannot equal or surpass the product price.
     if (!empty($order->TrialBillingPeriod)) {
         $trial_amount = $order->TrialAmount;
         $trial_tax = $order->getTaxForPrice($trial_amount);
         $trial_amount = pmpro_formatPrice(round((double) $trial_amount + (double) $trial_tax, 2), false, false);
         $tco_args['li_0_startup_fee'] = $trial_amount;
         // Negative trial amount
     }
     $ptpStr = '';
     foreach ($tco_args as $key => $value) {
         reset($tco_args);
         // Used to verify whether or not we're on the first argument
         $ptpStr .= $key == key($tco_args) ? '?' . $key . '=' . urlencode($value) : '&' . $key . '=' . urlencode($value);
     }
     //anything modders might add
     $additional_parameters = apply_filters('pmpro_twocheckout_return_url_parameters', array());
     if (!empty($additional_parameters)) {
         foreach ($additional_parameters as $key => $value) {
             $ptpStr .= "&" . urlencode($key) . "=" . urlencode($value);
         }
     }
     $ptpStr = apply_filters('pmpro_twocheckout_ptpstr', $ptpStr, $order);
     ///useful for debugging
     ///echo str_replace("&", "&<br />", $ptpStr);
     ///exit;
     //figure out gateway environment and URL to use
     if ($gateway_environment == "live") {
         $host = "www.2checkout.com";
     } else {
         $host = "sandbox.2checkout.com";
     }
     $tco_url = 'https://' . $host . '/checkout/purchase' . $ptpStr;
     //redirect to 2checkout
     wp_redirect($tco_url);
     exit;
 }
 function sendToMigs(&$order)
 {
     global $pmpro_currency;
     //$order_id = $order->code;
     //taxes on initial amount
     $initial_payment = $order->InitialPayment;
     $initial_payment_tax = $order->getTaxForPrice($initial_payment);
     $initial_payment = round((double) $initial_payment + (double) $initial_payment_tax, 2);
     $details = '';
     //taxes on the amount (NOT CURRENTLY USED)
     $amount = $order->PaymentAmount;
     $amount_tax = $order->getTaxForPrice($amount);
     $amount = round((double) $amount + (double) $amount_tax, 2);
     // Recurring membership
     if (pmpro_isLevelRecurring($order->membership_level)) {
         $amount = number_format($initial_payment - $amount, 2, ".", "");
         //negative amount for lower initial payments
         $recurring_payment = number_format($order->membership_level->billing_amount, 2, ".", "");
         $recurring_payment_tax = number_format($order->getTaxForPrice($recurring_payment), 2, ".", "");
         $recurring_payment = number_format(round((double) $recurring_payment + (double) $recurring_payment_tax, 2), 2, ".", "");
         $amount = number_format($recurring_payment, 2, ".", "");
         $details = $order->BillingFrequency == 1 ? $order->BillingFrequency . ' ' . $order->BillingPeriod : $order->BillingFrequency . ' ' . $order->BillingPeriod . 's';
         if (property_exists($order, 'TotalBillingCycles')) {
             $details = $order->BillingFrequency * $order->TotalBillingCycles . ' ' . $order->BillingPeriod;
         } else {
             $details = 'Forever';
         }
     } else {
         $amount = number_format($initial_payment, 2, ".", "");
     }
     if (!empty($order->TrialBillingPeriod)) {
         $trial_amount = $order->TrialAmount;
         $trial_tax = $order->getTaxForPrice($trial_amount);
         $trial_amount = pmpro_formatPrice(round((double) $trial_amount + (double) $trial_tax, 2), false, false);
         $amount = $trial_amount;
         // Negative trial amount
     }
     global $pmpro_level;
     //create a code for the order
     if (empty($order->code)) {
         $order->code = $order->getRandomCode();
     }
     //what amount to charge?
     $amount = $order->InitialPayment;
     //tax
     $order->subtotal = $amount;
     $tax = $order->getTax(true);
     $amount = round((double) $order->subtotal + (double) $tax, 2);
     //create a customer
     //$result = $this->getCustomer($order);
     /*if(empty($result))
     		{
     			//failed to create customer
     			return false;
     		}*/
     //charge
     try {
         $order_id = $order->code;
         $order_amount = 100 * $amount;
         $md5Hash = pmpro_getOption("securehashe");
         /* Make sure user entered MIGS url, otherwise use the default one */
         if (trim($this->service_host) == "" || $this->service_host == null) {
             $this->service_host = "https://migs.mastercard.com.au/vpcpay";
         }
         $service_host = $this->service_host . "?";
         $rurl = admin_url("admin-ajax.php") . "?action=migspaymenthandler";
         //$rurl='https://nibaya.com/ccc/wp-content/plugins/pmpro-example-gateway/classes/paymenthandler.php?';
         //$rurl = pmpro_url("confirmation", "?level=" . $order->membership_level);
         $user_ID = get_current_user_id();
         $DigitalOrder = array("vpc_Version" => "1", "vpc_Command" => "pay", "vpc_AccessCode" => pmpro_getOption("accescodee"), "vpc_MerchTxnRef" => $order_id . '_' . date("Y-m-d"), "vpc_Merchant" => pmpro_getOption("merchantide"), "vpc_OrderInfo" => $order_id . '_' . date("Y-m-d"), "vpc_Amount" => $order_amount, "vpc_Locale" => "en", "vpc_ReturnURL" => $rurl . '&level=1');
         ksort($DigitalOrder);
         foreach ($DigitalOrder as $key => $value) {
             if (strlen($value) > 0) {
                 if ($appendAmp == 0) {
                     $service_host .= urlencode($key) . '=' . urlencode($value);
                     $appendAmp = 1;
                 } else {
                     $service_host .= '&' . urlencode($key) . "=" . urlencode($value);
                 }
                 $md5Hash .= $value;
             }
         }
         $service_host .= "&vpc_SecureHash=" . strtoupper(md5($md5Hash));
         //$order->saveOrder();
         //echo $service_host;
         header("Location:" . $service_host);
         exit;
     } catch (Exception $e) {
         //$order->status = "error";
         $order->errorcode = true;
         $order->error = "Error: " . $e->getMessage();
         $order->shorterror = $order->error;
         return false;
     }
     //$order->saveOrder();
     //echo $service_host;
     //header("Location:".$service_host);
     //exit();
     // Demo mode?
     // if(empty($order->gateway_environment))
     // $gateway_environment = pmpro_getOption("gateway_environment");
     // else
     // $gateway_environment = $order->gateway_environment;
     // if("sandbox" === $gateway_environment || "beta-sandbox" === $gateway_environment)
     // {
     // Migs::sandbox(true);
     // $tco_args['demo'] = 'Y';
     // }
     // else
     // Migs::sandbox(false);
     // Trial?
     //li_#_startup_fee	Any start up fees for the product or service. Can be negative to provide discounted first installment pricing, but cannot equal or surpass the product price.
     //redirect to 2checkout
 }
function pmpro_membership_level_profile_fields($user)
{
    global $current_user;
    $membership_level_capability = apply_filters("pmpro_edit_member_capability", "manage_options");
    if (!current_user_can($membership_level_capability)) {
        return false;
    }
    global $wpdb;
    /*$user->membership_level = $wpdb->get_row("SELECT l.id AS ID, l.name AS name
    		FROM {$wpdb->pmpro_membership_levels} AS l
    		JOIN {$wpdb->pmpro_memberships_users} AS mu ON (l.id = mu.membership_id)
    		WHERE mu.user_id = " . $user->ID . "
    		LIMIT 1");*/
    $user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
    $levels = $wpdb->get_results("SELECT * FROM {$wpdb->pmpro_membership_levels}", OBJECT);
    if (!$levels) {
        return "";
    }
    ?>
<h3><?php 
    _e("Membership Level", "pmpro");
    ?>
</h3>
<table class="form-table">
    <?php 
    $show_membership_level = true;
    $show_membership_level = apply_filters("pmpro_profile_show_membership_level", $show_membership_level, $user);
    if ($show_membership_level) {
        ?>
		<tr>
			<th><label for="membership_level"><?php 
        _e("Current Level", "pmpro");
        ?>
</label></th>
			<td>
				<select name="membership_level" onchange="pmpro_mchange_warning();">
					<option value="" <?php 
        if (empty($user->membership_level->ID)) {
            ?>
selected="selected"<?php 
        }
        ?>
>-- <?php 
        _e("None", "pmpro");
        ?>
 --</option>
				<?php 
        foreach ($levels as $level) {
            $current_level = $user->membership_level->ID == $level->id;
            ?>
					<option value="<?php 
            echo $level->id;
            ?>
" <?php 
            if ($current_level) {
                ?>
selected="selected"<?php 
            }
            ?>
><?php 
            echo $level->name;
            ?>
</option>
				<?php 
        }
        ?>
				</select>
				<script>
					var pmpro_mchange_once = 0;
					function pmpro_mchange_warning()
					{
						if(pmpro_mchange_once == 0)
						{
							alert('Warning: The existing membership will be cancelled, and the new membership will be free.');
							pmpro_mchange_once = 1;
						}
					}
				</script>
				<?php 
        $membership_values = $wpdb->get_row("SELECT * FROM {$wpdb->pmpro_memberships_users} WHERE status = 'active' AND user_id = '" . $user->ID . "' LIMIT 1");
        if (!empty($membership_values->billing_amount) || !empty($membership_values->trial_amount)) {
            ?>
						<?php 
            if ($membership_values->billing_amount > 0) {
                ?>
							at <?php 
                echo pmpro_formatPrice($membership_values->billing_amount);
                ?>
							<?php 
                if ($membership_values->cycle_number > 1) {
                    ?>
								per <?php 
                    echo $membership_values->cycle_number;
                    ?>
 <?php 
                    echo sornot($membership_values->cycle_period, $membership_values->cycle_number);
                    ?>
							<?php 
                } elseif ($membership_values->cycle_number == 1) {
                    ?>
								per <?php 
                    echo $membership_values->cycle_period;
                    ?>
							<?php 
                }
                ?>
						<?php 
            }
            ?>

						<?php 
            if ($membership_values->billing_limit) {
                ?>
 for <?php 
                echo $membership_values->billing_limit . ' ' . sornot($membership_values->cycle_period, $membership_values->billing_limit);
            }
            ?>
.

						<?php 
            if ($membership_values->trial_limit) {
                ?>
							The first <?php 
                echo $membership_values->trial_limit;
                ?>
 <?php 
                echo sornot("payments", $membership_values->trial_limit);
                ?>
 will cost <?php 
                echo pmpro_formatPrice($membership_values->trial_amount);
                ?>
.
						<?php 
            }
            ?>
					<?php 
        } else {
            _e("User is not paying.", "pmpro");
        }
        ?>
			</td>
		</tr>
		<?php 
    }
    $show_expiration = true;
    $show_expiration = apply_filters("pmpro_profile_show_expiration", $show_expiration, $user);
    if ($show_expiration) {
        //is there an end date?
        $user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
        $end_date = !empty($user->membership_level->enddate);
        //some vars for the dates
        $current_day = date("j");
        if ($end_date) {
            $selected_expires_day = date("j", $user->membership_level->enddate);
        } else {
            $selected_expires_day = $current_day;
        }
        $current_month = date("M");
        if ($end_date) {
            $selected_expires_month = date("m", $user->membership_level->enddate);
        } else {
            $selected_expires_month = date("m");
        }
        $current_year = date("Y");
        if ($end_date) {
            $selected_expires_year = date("Y", $user->membership_level->enddate);
        } else {
            $selected_expires_year = (int) $current_year + 1;
        }
        ?>
		<tr>
			<th><label for="expiration"><?php 
        _e("Expires", "pmpro");
        ?>
</label></th>
			<td>
				<select id="expires" name="expires">
					<option value="0" <?php 
        if (!$end_date) {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e("No", "pmpro");
        ?>
</option>
					<option value="1" <?php 
        if ($end_date) {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e("Yes", "pmpro");
        ?>
</option>
				</select>
				<span id="expires_date" <?php 
        if (!$end_date) {
            ?>
style="display: none;"<?php 
        }
        ?>
>
					on
					<select name="expires_month">
						<?php 
        for ($i = 1; $i < 13; $i++) {
            ?>
							<option value="<?php 
            echo $i;
            ?>
" <?php 
            if ($i == $selected_expires_month) {
                ?>
selected="selected"<?php 
            }
            ?>
><?php 
            echo date("M", strtotime($i . "/1/" . $current_year, current_time("timestamp")));
            ?>
</option>
							<?php 
        }
        ?>
					</select>
					<input name="expires_day" type="text" size="2" value="<?php 
        echo $selected_expires_day;
        ?>
" />
					<input name="expires_year" type="text" size="4" value="<?php 
        echo $selected_expires_year;
        ?>
" />
				</span>
				<script>
					jQuery('#expires').change(function() {
						if(jQuery(this).val() == 1)
							jQuery('#expires_date').show();
						else
							jQuery('#expires_date').hide();
					});
				</script>
			</td>
		</tr>
		<?php 
    }
    ?>
</table>
<?php 
}
function pmpro_getLevelCost(&$level, $tags = true, $short = false)
{
    //initial payment
    if (!$short) {
        $r = sprintf(__('The price for membership is <strong>%s</strong> now', 'pmpro'), pmpro_formatPrice($level->initial_payment));
    } else {
        $r = sprintf(__('<strong>%s</strong> now', 'pmpro'), pmpro_formatPrice($level->initial_payment));
    }
    //recurring part
    if ($level->billing_amount != '0.00') {
        if ($level->billing_limit > 1) {
            if ($level->cycle_number == '1') {
                $r .= sprintf(__(' and then <strong>%s per %s for %d more %s</strong>.', 'pmpro'), pmpro_formatPrice($level->billing_amount), pmpro_translate_billing_period($level->cycle_period), $level->billing_limit, pmpro_translate_billing_period($level->cycle_period, $level->billing_limit));
            } else {
                $r .= sprintf(__(' and then <strong>%s every %d %s for %d more %s</strong>.', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number), $level->billing_limit, pmpro_translate_billing_period($level->cycle_period, $level->billing_limit));
            }
        } elseif ($level->billing_limit == 1) {
            $r .= sprintf(__(' and then <strong>%s after %d %s</strong>.', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
        } else {
            if ($level->billing_amount === $level->initial_payment) {
                if ($level->cycle_number == '1') {
                    if (!$short) {
                        $r = sprintf(__('The price for membership is <strong>%s per %s</strong>.', 'pmpro'), pmpro_formatPrice($level->initial_payment), pmpro_translate_billing_period($level->cycle_period));
                    } else {
                        $r = sprintf(__('<strong>%s per %s</strong>.', 'pmpro'), pmpro_formatPrice($level->initial_payment), pmpro_translate_billing_period($level->cycle_period));
                    }
                } else {
                    if (!$short) {
                        $r = sprintf(__('The price for membership is <strong>%s every %d %s</strong>.', 'pmpro'), pmpro_formatPrice($level->initial_payment), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
                    } else {
                        $r = sprintf(__('<strong>%s every %d %s</strong>.', 'pmpro'), pmpro_formatPrice($level->initial_payment), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
                    }
                }
            } else {
                if ($level->cycle_number == '1') {
                    $r .= sprintf(__(' and then <strong>%s per %s</strong>.', 'pmpro'), pmpro_formatPrice($level->billing_amount), pmpro_translate_billing_period($level->cycle_period));
                } else {
                    $r .= sprintf(__(' and then <strong>%s every %d %s</strong>.', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
                }
            }
        }
    } else {
        $r .= '.';
    }
    //add a space
    $r .= ' ';
    //trial part
    if ($level->trial_limit) {
        if ($level->trial_amount == '0.00') {
            if ($level->trial_limit == '1') {
                $r .= ' ' . __('After your initial payment, your first payment is Free.', 'pmpro');
            } else {
                $r .= ' ' . sprintf(__('After your initial payment, your first %d payments are Free.', 'pmpro'), $level->trial_limit);
            }
        } else {
            if ($level->trial_limit == '1') {
                $r .= ' ' . sprintf(__('After your initial payment, your first payment will cost %s.', 'pmpro'), pmpro_formatPrice($level->trial_amount));
            } else {
                $r .= ' ' . sprintf(__('After your initial payment, your first %d payments will cost %s.', 'pmpro'), $level->trial_limit, pmpro_formatPrice($level->trial_amount));
            }
        }
    }
    //taxes part
    $tax_state = pmpro_getOption("tax_state");
    $tax_rate = pmpro_getOption("tax_rate");
    if ($tax_state && $tax_rate && !pmpro_isLevelFree($level)) {
        $r .= sprintf(__('Customers in %s will be charged %s%% tax.', 'pmpro'), $tax_state, round($tax_rate * 100, 2));
    }
    if (!$tags) {
        $r = strip_tags($r);
    }
    $r = apply_filters("pmpro_level_cost_text", $r, $level, $tags, $short);
    //passing $tags and $short since v2.0
    return $r;
}
function pmpro_addon_packages_shortcode($atts, $content = null, $code = "")
{
    // $atts    ::= array of attributes
    // $content ::= text within enclosing form of shortcode element
    // $code    ::= the shortcode found, when == callback name
    // examples: [pmpro_addon_packages show="none" include="subpages"]
    // table of addone packages that are subpages of the page with shortcode and showing no description excerpt
    global $wpdb, $post, $current_user;
    extract(shortcode_atts(array('checkout_button' => __('Buy Now', 'pmproap'), 'levels_button' => __('Choose a Level', 'pmproap'), 'exclude' => NULL, 'layout' => 'table', 'link' => true, 'include' => NULL, 'orderby' => 'menu_order', 'order' => 'ASC', 'thumbnail' => 'thumbnail', 'view_button' => __('View Now', 'pmproap')), $atts));
    // prep exclude array
    $exclude = str_replace(" ", "", $exclude);
    $exclude = explode(",", $exclude);
    //turn 0's into falses
    if ($include == "subpages") {
        $post_type = "page";
        $post_parent = $post->ID;
    } else {
        $post_type = array('post', 'page');
        $post_parent = NULL;
    }
    if ($link === "0" || $link === "false" || $link === "no") {
        $link = false;
    } else {
        $link = true;
    }
    if ($thumbnail && strtolower($thumbnail) != "false") {
        if (strtolower($thumbnail) == "medium") {
            $thumbnail = "medium";
        } elseif (strtolower($thumbnail) == "large") {
            $thumbnail = "large";
        } else {
            $thumbnail = "thumbnail";
        }
    } else {
        $thumbnail = false;
    }
    // get posts
    $args = array('meta_key' => '_pmproap_price', 'meta_compare' => '>', 'meta_value' => '0', "order" => $order, "orderby" => $orderby, 'posts_per_page' => -1, 'post_status' => 'publish', "post_type" => $post_type, "post_parent" => $post_parent, "post__not_in" => $exclude);
    $pmproap_posts = get_posts($args);
    $layout_cols = preg_replace('/[^0-9]/', '', $layout);
    if (!empty($layout_cols)) {
        $pmproap_posts_chunks = array_chunk($pmproap_posts, $layout_cols);
    } else {
        $pmproap_posts_chunks = array_chunk($pmproap_posts, 1);
    }
    ob_start();
    if (!empty($pmproap_posts)) {
        ?>
			<style>
				.pmpro_addon_package td {vertical-align: middle; }
				tr.pmpro_addon_package td.pmpro_addon_package-title h3 {margin: 0; }
				#pmpro_addon_packages h3.pmpro_addon_package-title {margin: 0 0 2rem 0; }
				.pmpro_addon_package td.pmpro_addon_package-thumbnail img {max-width: 100%; height: auto; }
				.pmpro_addon_package td.pmpro_addon_package-buy .pmpro_btn, .pmpro_addon_package td.pmpro_addon_package-view .pmpro_btn {display: block; }
			</style>
		<?php 
        if ($layout == 'table') {
            ?>
				<table id="pmpro_addon_packages" cellpadding="0" cellspacing="0" border="0">					
					<tbody>
					<?php 
            foreach ($pmproap_posts as $post) {
                $pmproap_price = get_post_meta($post->ID, "_pmproap_price", true);
                ?>
							<tr id="pmpro_addon_package-<?php 
                echo $post->ID;
                ?>
" class="pmpro_addon_package">
							<?php 
                if (has_post_thumbnail() && !empty($thumbnail)) {
                    ?>
									<td width="15%" class="pmpro_addon_package-thumbnail">
									<?php 
                    if ($link) {
                        echo '<a href="' . get_permalink() . '">' . get_the_post_thumbnail($post->ID, $thumbnail) . '</a>';
                    } else {
                        echo get_the_post_thumbnail($post->ID, $thumbnail);
                    }
                    ?>
									</td>
									<?php 
                }
                ?>
								<td class="pmpro_addon_package-title">
									<h3>
									<?php 
                if (!empty($link)) {
                    echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
                } else {
                    echo get_the_title();
                }
                ?>
									</h3>									
								</td>
								<?php 
                if (!empty($current_user->ID) && pmproap_hasAccess($current_user->ID, $post->ID)) {
                    ?>
										<td width="25%" class="pmpro_addon_package-view"><a class="pmpro_btn" href="<?php 
                    echo the_permalink();
                    ?>
"><?php 
                    echo $view_button;
                    ?>
</a></td>
										<?php 
                } else {
                    //which level to use for checkout link?
                    $text_level_id = pmproap_getLevelIDForCheckoutLink($post->ID, $current_user->ID);
                    ?>
										<td width="25%" class="pmpro_addon_package-buy">
										<?php 
                    if (empty($text_level_id)) {
                        ?>
												<a class="pmpro_btn" href="<?php 
                        echo pmpro_url("levels");
                        ?>
">
													<?php 
                        echo $levels_button;
                        ?>
												</a>
											<?php 
                    } else {
                        //what's the price
                        $pmproap_price = get_post_meta($post->ID, "_pmproap_price", true);
                        ?>
												<a class="pmpro_btn" href="<?php 
                        echo pmpro_url("checkout", "?level=" . $text_level_id . "&ap=" . $post->ID);
                        ?>
">
													<?php 
                        echo $checkout_button;
                        ?>
 &mdash; <span class="pmpro_addon_package-price"><?php 
                        echo pmpro_formatPrice($pmproap_price);
                        ?>
</span>
												</a>
											<?php 
                    }
                    ?>
										</td>
										<?php 
                }
                ?>
							</tr> <!-- end pmpro_addon_package-->
							<?php 
            }
            ?>
					</tbody>
				</table> <!-- end #pmpro_addon_packages -->
				<?php 
        } else {
            ?>
				<div id="pmpro_addon_packages">
					<?php 
            foreach ($pmproap_posts_chunks as $row) {
                ?>
							<div class="row">
						<?php 
                foreach ($row as $post) {
                    $pmproap_price = get_post_meta($post->ID, "_pmproap_price", true);
                    ?>
								<div class="medium-<?php 
                    if ($layout == '2col') {
                        echo '6 ';
                    } elseif ($layout == '3col') {
                        echo '4 text-center ';
                    } elseif ($layout == '4col') {
                        echo '3 text-center ';
                    } else {
                        echo '12 ';
                    }
                    ?>
								columns">
									<article id="pmpro_addon_package-<?php 
                    echo $post->ID;
                    ?>
" class="<?php 
                    echo implode(" ", get_post_class());
                    ?>
 pmpro_addon_package">							
										<header class="entry-header"><h3 class="entry-title pmpro_addon_package-title">
										<?php 
                    if (has_post_thumbnail() && !empty($thumbnail)) {
                        if ($layout == '3col' || $layout == '4col') {
                            $thumbnail_class = "aligncenter";
                        } else {
                            $thumbnail_class = "alignright";
                        }
                        if ($link) {
                            echo '<a href="' . get_permalink() . '">' . get_the_post_thumbnail($post->ID, $thumbnail, array('class' => $thumbnail_class)) . '</a>';
                        } else {
                            echo get_the_post_thumbnail($post->ID, $thumbnail, array('class' => $thumbnail_class));
                        }
                    }
                    if (!empty($link)) {
                        echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
                    } else {
                        echo get_the_title();
                    }
                    ?>
									
										</h3></header>
										<div class="entry-content">																		
											<?php 
                    if (!empty($current_user->ID) && pmproap_hasAccess($current_user->ID, $post->ID)) {
                        ?>
													<p class="pmpro_addon_package-view"><a class="pmpro_btn" href="<?php 
                        echo the_permalink();
                        ?>
"><?php 
                        echo $view_button;
                        ?>
</a></p>
													<?php 
                    } else {
                        //which level to use for checkout link?
                        $text_level_id = pmproap_getLevelIDForCheckoutLink($post->ID, $current_user->ID);
                        if (empty($text_level_id)) {
                            ?>
															
														<p class="pmpro_addon_package-buy"><a class="pmpro_btn" href="<?php 
                            echo pmpro_url("levels");
                            ?>
"><?php 
                            echo $levels_button;
                            ?>
</a></p>
														<?php 
                        } else {
                            //what's the price
                            $pmproap_price = get_post_meta($post->ID, "_pmproap_price", true);
                            ?>
														<p class="pmpro_addon_package-buy"><a class="pmpro_btn" href="<?php 
                            echo pmpro_url("checkout", "?level=" . $text_level_id . "&ap=" . $post->ID);
                            ?>
"><?php 
                            echo $checkout_button;
                            ?>
 &mdash; <span class="pmpro_addon_package-price"><?php 
                            echo pmpro_formatPrice($pmproap_price);
                            ?>
</span></a></p>
														<?php 
                        }
                    }
                    ?>
										</div>
									</article> <!-- end pmpro_addon_package-->
								</div>
							<?php 
                }
                ?>
						</div> <!-- end row -->
						<?php 
                if ($layout == '3col' || $layout == '4col') {
                    echo "<hr />";
                }
                ?>
						
					<?php 
            }
            ?>
				</div> <!-- end #pmpro_addon_packages -->
				<?php 
        }
        //Reset Query
        wp_reset_query();
    } else {
        _e('No add on packages found.', 'pmproap');
    }
    $temp_content = ob_get_contents();
    ob_end_clean();
    return $temp_content;
}
function pmpro_membership_level_profile_fields($user)
{
    global $current_user;
    $membership_level_capability = apply_filters("pmpro_edit_member_capability", "manage_options");
    if (!current_user_can($membership_level_capability)) {
        return false;
    }
    global $wpdb;
    /*$user->membership_level = $wpdb->get_row("SELECT l.id AS ID, l.name AS name
    		FROM {$wpdb->pmpro_membership_levels} AS l
    		JOIN {$wpdb->pmpro_memberships_users} AS mu ON (l.id = mu.membership_id)
    		WHERE mu.user_id = " . $user->ID . "
    		LIMIT 1");*/
    $user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
    $levels = $wpdb->get_results("SELECT * FROM {$wpdb->pmpro_membership_levels}", OBJECT);
    if (!$levels) {
        return "";
    }
    ?>
<h3><?php 
    _e("Membership Level", "pmpro");
    ?>
</h3>
<table class="form-table">
    <?php 
    $show_membership_level = true;
    $show_membership_level = apply_filters("pmpro_profile_show_membership_level", $show_membership_level, $user);
    if ($show_membership_level) {
        ?>
		<tr>
			<th><label for="membership_level"><?php 
        _e("Current Level", "pmpro");
        ?>
</label></th>
			<td>
				<select name="membership_level">
					<option value="" <?php 
        if (empty($user->membership_level->ID)) {
            ?>
selected="selected"<?php 
        }
        ?>
>-- <?php 
        _e("None", "pmpro");
        ?>
 --</option>
				<?php 
        foreach ($levels as $level) {
            ?>
					<option value="<?php 
            echo $level->id;
            ?>
" <?php 
            selected($level->id, isset($user->membership_level->ID) ? $user->membership_level->ID : 0);
            ?>
><?php 
            echo $level->name;
            ?>
</option>
				<?php 
        }
        ?>
				</select>
                <span id="current_level_cost">
                <?php 
        $membership_values = pmpro_getMembershipLevelForUser($user->ID);
        //we tweak the initial payment here so the text here effectively shows the recurring amount
        if (!empty($membership_values)) {
            $membership_values->original_initial_payment = $membership_values->initial_payment;
            $membership_values->initial_payment = $membership_values->billing_amount;
        }
        if (empty($membership_values) || pmpro_isLevelFree($membership_values)) {
            if (!empty($membership_values->original_initial_payment) && $membership_values->original_initial_payment > 0) {
                echo "Paid " . pmpro_formatPrice($membership_values->original_initial_payment) . ".";
            } else {
                _e('Not paying.', 'pmpro');
            }
        } else {
            echo pmpro_getLevelCost($membership_values, true, true);
        }
        ?>
                </span>
                <p id="cancel_description" class="description hidden"><?php 
        _e("This will not change the subscription at the gateway unless the 'Cancel' checkbox is selected below.", "pmpro");
        ?>
</p>
            </td>
		</tr>
		<?php 
    }
    $show_expiration = true;
    $show_expiration = apply_filters("pmpro_profile_show_expiration", $show_expiration, $user);
    if ($show_expiration) {
        //is there an end date?
        $user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
        $end_date = !empty($user->membership_level->enddate);
        //some vars for the dates
        $current_day = date("j");
        if ($end_date) {
            $selected_expires_day = date("j", $user->membership_level->enddate);
        } else {
            $selected_expires_day = $current_day;
        }
        $current_month = date("M");
        if ($end_date) {
            $selected_expires_month = date("m", $user->membership_level->enddate);
        } else {
            $selected_expires_month = date("m");
        }
        $current_year = date("Y");
        if ($end_date) {
            $selected_expires_year = date("Y", $user->membership_level->enddate);
        } else {
            $selected_expires_year = (int) $current_year + 1;
        }
        ?>
		<tr>
			<th><label for="expiration"><?php 
        _e("Expires", "pmpro");
        ?>
</label></th>
			<td>
				<select id="expires" name="expires">
					<option value="0" <?php 
        if (!$end_date) {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e("No", "pmpro");
        ?>
</option>
					<option value="1" <?php 
        if ($end_date) {
            ?>
selected="selected"<?php 
        }
        ?>
><?php 
        _e("Yes", "pmpro");
        ?>
</option>
				</select>
				<span id="expires_date" <?php 
        if (!$end_date) {
            ?>
style="display: none;"<?php 
        }
        ?>
>
					on
					<select name="expires_month">
						<?php 
        for ($i = 1; $i < 13; $i++) {
            ?>
							<option value="<?php 
            echo $i;
            ?>
" <?php 
            if ($i == $selected_expires_month) {
                ?>
selected="selected"<?php 
            }
            ?>
><?php 
            echo date("M", strtotime($i . "/1/" . $current_year, current_time("timestamp")));
            ?>
</option>
							<?php 
        }
        ?>
					</select>
					<input name="expires_day" type="text" size="2" value="<?php 
        echo $selected_expires_day;
        ?>
" />
					<input name="expires_year" type="text" size="4" value="<?php 
        echo $selected_expires_year;
        ?>
" />
				</span>
				<script>
					jQuery('#expires').change(function() {
						if(jQuery(this).val() == 1)
							jQuery('#expires_date').show();
						else
							jQuery('#expires_date').hide();
					});
				</script>
			</td>
		</tr>
        <tr class="more_level_options">
            <th></th>
            <td>
                <label for="send_admin_change_email"><input value="1" id="send_admin_change_email" name="send_admin_change_email" type="checkbox"> Send the user an email about this change.</label>
            </td>
        </tr>
        <tr class="more_level_options">
            <th></th>
            <td>
                <label for="cancel_subscription"><input value="1" id="cancel_subscription" name="cancel_subscription" type="checkbox"> Cancel this user's subscription at the gateway.</label>
            </td>
        </tr>
		<?php 
    }
    ?>
</table>
    <script>
        jQuery(document).ready(function() {
            //vars for fields
			var $membership_level_select = jQuery("[name=membership_level]");
            var $expires_select = jQuery("[name=expires]");
			var $expires_month_select = jQuery("[name=expires_month]");
			var $expires_day_text = jQuery("[name=expires_day]");
			var $expires_year_text = jQuery("[name=expires_year]");
			
			//note old data to check for changes
			var old_level = $membership_level_select.val();
            var old_expires = $expires_select.val();
			var old_expires_month = $expires_month_select.val();
			var old_expires_day = $expires_day_text.val();
			var old_expires_year = $expires_year_text.val();
						
			var current_level_cost = jQuery("#current_level_cost").text();

            //hide by default
			jQuery(".more_level_options").hide();

			function pmpro_checkForLevelChangeInProfile()
			{
				//cancelling sub or not
				if($membership_level_select.val() == 0) {
                    jQuery("#cancel_subscription").attr('checked', true);
                    jQuery("#current_level_cost").text("Not paying.");
                }
                else {
                    jQuery("#cancel_subscription").attr('checked', false);
                    jQuery("#current_level_cost").text(current_level_cost);
                }
				
				//did level or expiration change?
                if(
					$membership_level_select.val() != old_level ||
					$expires_select.val() != old_expires ||
					$expires_month_select.val() != old_expires_month ||
					$expires_day_text.val() != old_expires_day ||
					$expires_year_text.val() != old_expires_year
				)
                {
                    jQuery(".more_level_options").show();
                    jQuery("#cancel_description").show();					
                }
                else
                {
                    jQuery(".more_level_options").hide();
                    jQuery("#cancel_description").hide();					
                }
			}
			
			//run check when fields change
            $membership_level_select.change(function() {
                pmpro_checkForLevelChangeInProfile();
            });
			$expires_select.change(function() {
                pmpro_checkForLevelChangeInProfile();
            });
			$expires_month_select.change(function() {
                pmpro_checkForLevelChangeInProfile();
            });
			$expires_day_text.change(function() {
                pmpro_checkForLevelChangeInProfile();
            });
			$expires_year_text.change(function() {
                pmpro_checkForLevelChangeInProfile();
            });			
			
            jQuery("#cancel_subscription").change(function() {
                if(jQuery(this).attr('checked') == 'checked')
                {
                    jQuery("#cancel_description").hide();
                    jQuery("#current_level_cost").text("Not paying.");
                }
                else
                {
                    jQuery("#current_level_cost").text(current_level_cost);
                    jQuery("#cancel_description").show();
                }
            });
        });
    </script>
<?php 
    do_action("pmpro_after_membership_level_profile_fields", $user);
}
function pmpro_report_sales_widget()
{
    global $wpdb;
    ?>
<style>
	#pmpro_report_sales tbody td:last-child {text-align: right; }
</style>
<span id="pmpro_report_sales">
	<table class="wp-list-table widefat fixed striped">
	<thead>
		<tr>
			<th scope="col">&nbsp;</th>
			<th scope="col"><?php 
    _e('Sales', 'pmpro');
    ?>
</th>
			<th scope="col"><?php 
    _e('Revenue', 'pmpro');
    ?>
</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<th scope="row"><?php 
    _e('Today', 'pmpro');
    ?>
</th>
			<td><?php 
    echo number_format_i18n(pmpro_getSales("today"));
    ?>
</td>
			<td><?php 
    echo pmpro_formatPrice(pmpro_getRevenue("today"));
    ?>
</td>
		</tr>
		<tr>
			<th scope="row"><?php 
    _e('This Month', 'pmpro');
    ?>
</th>
			<td><?php 
    echo number_format_i18n(pmpro_getSales("this month"));
    ?>
</td>
			<td><?php 
    echo pmpro_formatPrice(pmpro_getRevenue("this month"));
    ?>
</td>
		</tr>
		<tr>
			<th scope="row"><?php 
    _e('This Year', 'pmpro');
    ?>
</th>
			<td><?php 
    echo number_format_i18n(pmpro_getSales("this year"));
    ?>
</td>
			<td><?php 
    echo pmpro_formatPrice(pmpro_getRevenue("this year"));
    ?>
</td>
		</tr>
		<tr>
			<th scope="row"><?php 
    _e('All Time', 'pmpro');
    ?>
</th>
			<td><?php 
    echo number_format_i18n(pmpro_getSales("all time"));
    ?>
</td>
			<td><?php 
    echo pmpro_formatPrice(pmpro_getRevenue("all time"));
    ?>
</td>
		</tr>
	</tbody>
	</table>	
</span>
<?php 
}
					
				<?php 
        }
        ?>
			</td>				
			<td>
				<?php 
        if (!pmpro_isLevelTrial($level)) {
            ?>
					--
				<?php 
        } else {
            ?>
		
					<?php 
            echo pmpro_formatPrice($level->trial_amount);
            ?>
 <?php 
            _e('for', 'pmpro');
            ?>
 <?php 
            echo $level->trial_limit;
            ?>
 <?php 
            echo sornot("payment", $level->trial_limit);
            ?>
				<?php 
        }
        ?>
			</td>
			<td>
function billing_content_func($atts)
{
    global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
    //-> If a member is logged in, show them some info here (1. past invoices. 2. billing information with button to update.)
    if ($current_user->membership_level->ID) {
        if ($pmpro_msg) {
            ?>
            <div class="pmpro_message <?php 
            echo $pmpro_msgt;
            ?>
"><?php 
            echo $pmpro_msg;
            ?>
</div>
            <?php 
        }
        ?>
	
        <div class="row billing-content">
            <div class="col-md-8 col-sm-8 col-sm-offset-3 col-md-offset-3">
                <!-- BEGIN CONTENT-->
                <div id="pmpro_account">		
                    <div id="pmpro_account-membership" class="pmpro_box-first">

                        <?php 
        //wpex_logo();
        ?>
                        <!--
                        <div class="clear clearfix"></div>
                        <br/>
                        -->
                        <?php 
        $level = $current_user->membership_level->name;
        ?>
                        <p><?php 
        _e("Membership status: <strong>" . $level . "</strong>", "pmpro");
        ?>
</p>
                        <?php 
        //die(var_dump($current_user));
        ?>
                        <ul>
                            <li><strong><?php 
        _e("Level", "pmpro");
        ?>
:</strong> <?php 
        echo $current_user->membership_level->name;
        ?>
</li>
                            <?php 
        if ($current_user->membership_level->billing_amount > 0) {
            ?>
                                <li><strong><?php 
            _e("Membership Fee", "pmpro");
            ?>
:</strong>
                                    <?php 
            $level = $current_user->membership_level;
            if ($current_user->membership_level->cycle_number > 1) {
                printf(__('%s every %d %s.', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
            } elseif ($current_user->membership_level->cycle_number == 1) {
                printf(__('%s per %s.', 'pmpro'), pmpro_formatPrice($level->billing_amount), pmpro_translate_billing_period($level->cycle_period));
            } else {
                echo pmpro_formatPrice($current_user->membership_level->billing_amount);
            }
            ?>
                                </li>
                            <?php 
        }
        ?>
						

                            <?php 
        if ($current_user->membership_level->billing_limit) {
            ?>
                                <li><strong><?php 
            _e("Duration", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->membership_level->billing_limit . ' ' . sornot($current_user->membership_level->cycle_period, $current_user->membership_level->billing_limit);
            ?>
</li>
                            <?php 
        }
        ?>

                            <?php 
        if ($current_user->membership_level->enddate) {
            ?>
                                <li><strong><?php 
            _e("Next billing date", "pmpro");
            ?>
:</strong> <?php 
            echo date_i18n(get_option('date_format'), $current_user->membership_level->enddate);
            ?>
</li>
                            <?php 
        }
        ?>

                            <?php 
        if ($current_user->membership_level->trial_limit == 1) {
            printf(__("Your first payment will cost %s.", "pmpro"), pmpro_formatPrice($current_user->membership_level->trial_amount));
        } elseif (!empty($current_user->membership_level->trial_limit)) {
            printf(__("Your first %d payments will cost %s.", "pmpro"), $current_user->membership_level->trial_limit, pmpro_formatPrice($current_user->membership_level->trial_amount));
        }
        ?>
                        </ul>

                    </div> <!-- end pmpro_account-membership -->

                    <div id="pmpro_account-profile" class="pmpro_box hide">	
                        <?php 
        get_currentuserinfo();
        ?>
 
                        <h3><?php 
        _e("My Account", "pmpro");
        ?>
</h3>
                        <?php 
        if ($current_user->user_firstname) {
            ?>
                            <p><?php 
            echo $current_user->user_firstname;
            ?>
 <?php 
            echo $current_user->user_lastname;
            ?>
</p>
                        <?php 
        }
        ?>
                        <ul>
                            <li><strong><?php 
        _e("Username", "pmpro");
        ?>
:</strong> <?php 
        echo $current_user->user_login;
        ?>
</li>
                            <li><strong><?php 
        _e("Email", "pmpro");
        ?>
:</strong> <?php 
        echo $current_user->user_email;
        ?>
</li>
                        </ul>
                        <p>
                            <a href="<?php 
        echo admin_url('profile.php');
        ?>
"><?php 
        _e("Edit Profile", "pmpro");
        ?>
</a> |
                            <a href="<?php 
        echo admin_url('profile.php');
        ?>
"><?php 
        _ex("Change Password", "As in 'change password'.", "pmpro");
        ?>
</a>
                        </p>
                    </div> <!-- end pmpro_account-profile -->

                    <?php 
        //last invoice for current info
        //$ssorder = $wpdb->get_row("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM $wpdb->pmpro_membership_orders WHERE user_id = '$current_user->ID' AND membership_id = '" . $current_user->membership_level->ID . "' AND status = 'success' ORDER BY timestamp DESC LIMIT 1");
        $ssorder = new MemberOrder();
        $ssorder->getLastMemberOrder();
        $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' ORDER BY timestamp DESC LIMIT 6");
        if (!empty($ssorder->id) && $ssorder->gateway != "check" && $ssorder->gateway != "paypalexpress" && $ssorder->gateway != "paypalstandard" && $ssorder->gateway != "twocheckout") {
            //default values from DB (should be last order or last update)
            $bfirstname = get_user_meta($current_user->ID, "pmpro_bfirstname", true);
            $blastname = get_user_meta($current_user->ID, "pmpro_blastname", true);
            $baddress1 = get_user_meta($current_user->ID, "pmpro_baddress1", true);
            $baddress2 = get_user_meta($current_user->ID, "pmpro_baddress2", true);
            $bcity = get_user_meta($current_user->ID, "pmpro_bcity", true);
            $bstate = get_user_meta($current_user->ID, "pmpro_bstate", true);
            $bzipcode = get_user_meta($current_user->ID, "pmpro_bzipcode", true);
            $bcountry = get_user_meta($current_user->ID, "pmpro_bcountry", true);
            $bphone = get_user_meta($current_user->ID, "pmpro_bphone", true);
            $bemail = get_user_meta($current_user->ID, "pmpro_bemail", true);
            $bconfirmemail = get_user_meta($current_user->ID, "pmpro_bconfirmemail", true);
            $CardType = get_user_meta($current_user->ID, "pmpro_CardType", true);
            $AccountNumber = hideCardNumber(get_user_meta($current_user->ID, "pmpro_AccountNumber", true), false);
            $ExpirationMonth = get_user_meta($current_user->ID, "pmpro_ExpirationMonth", true);
            $ExpirationYear = get_user_meta($current_user->ID, "pmpro_ExpirationYear", true);
            ?>
	

                        <div id="pmpro_account-billing" class="pmpro_box">
                            <h3><?php 
            _e("Billing Information", "pmpro");
            ?>
</h3>
                            <?php 
            if (!empty($baddress1)) {
                ?>
                                <p>
                                    <strong><?php 
                _e("Billing Address", "pmpro");
                ?>
</strong><br />
                                    <?php 
                echo $bfirstname . " " . $blastname;
                ?>
                                    <br />		
                                    <?php 
                echo $current_user->user_email;
                ?>
<br />
                                    <?php 
                echo $baddress1;
                ?>
<br />
                                    <?php 
                if ($baddress2) {
                    echo $baddress2 . "<br />";
                }
                ?>
                                    <?php 
                if ($bcity && $bstate) {
                    ?>
                                        <?php 
                    echo $bcity;
                    ?>
, <?php 
                    echo $bstate;
                    ?>
 <?php 
                    echo $bzipcode;
                    ?>
 <?php 
                    echo $bcountry;
                    ?>
                                    <?php 
                }
                ?>
                         
                                    <br />
                                    <?php 
                echo formatPhone($bphone);
                ?>
                                </p>
                            <?php 
            }
            ?>

                            <?php 
            if (!empty($AccountNumber)) {
                ?>
                                <p>
                                    <strong><?php 
                _e("Payment Method", "pmpro");
                ?>
</strong><br />
                                    <?php 
                echo $CardType;
                ?>
: <?php 
                echo last4($AccountNumber);
                ?>
 (<?php 
                echo $ExpirationMonth;
                ?>
/<?php 
                echo $ExpirationYear;
                ?>
)
                                </p>
                            <?php 
            }
            ?>

                            <?php 
            if (isset($ssorder->status) && $ssorder->status == "success" && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource")))) {
                ?>
                                <p><a href="<?php 
                echo pmpro_url("billing", "");
                ?>
"><?php 
                _e("Edit Billing Information", "pmpro");
                ?>
</a></p>
                                <?php 
            }
            ?>
                        </div> <!-- end pmpro_account-billing -->				
                        <?php 
        }
        ?>

                    <?php 
        if (!empty($invoices)) {
            ?>
                        <div id="pmpro_account-invoices" class="pmpro_box">
                            <h3><?php 
            _e("Past Invoices", "pmpro");
            ?>
</h3>
                            <ul>
                                <?php 
            $count = 0;
            foreach ($invoices as $invoice) {
                if ($count++ > 5) {
                    break;
                }
                ?>
                                    <li><a href="<?php 
                echo pmpro_url("invoice", "?invoice=" . $invoice->code);
                ?>
"><?php 
                echo date_i18n(get_option("date_format"), $invoice->timestamp);
                ?>
 (<?php 
                echo pmpro_formatPrice($invoice->total);
                ?>
)</a></li>
                                    <?php 
            }
            ?>
                            </ul>
                            <?php 
            //if ($count == 6) {
            ?>
                            <p><a href="<?php 
            echo pmpro_url("invoice");
            ?>
"><?php 
            _e("View All Invoices", "pmpro");
            ?>
</a></p>
                            <?php 
            //}
            ?>
                        </div> <!-- end pmpro_account-billing -->
                    <?php 
        }
        ?>
                    <!--
                    <p class="help-block">We have the following subscriptions available for our site. To join, simply click on the <strong>Change Subscription</strong> button to Change Membership Level.</p>
                    -->                  
                    <?php 
        //getLevels();
        ?>
	
                </div> <!-- end pmpro_account -->	

                <!-- END CONTENT-->
            </div>
        </div>
        <?php 
    } else {
        $user_id = $current_user->ID;
        //make sure we only run once a day
        $today = date("Y-m-d", current_time("timestamp"));
        //look for memberships that expired
        $sqlQuery = "SELECT mu.user_id, mu.membership_id, mu.startdate, mu.enddate FROM {$wpdb->pmpro_memberships_users} mu WHERE mu.status = 'expired' AND mu.enddate IS NOT NULL AND mu.enddate <> '' AND mu.enddate <> '0000-00-00 00:00:00' AND DATE(mu.enddate) <= '" . $today . "' AND mu.user_id = '" . $user_id . "' ORDER BY mu.enddate  LIMIT 1";
        $expired = $wpdb->get_results($sqlQuery);
        if (count($expired) > 0) {
            ?>
            <div class="row billing-content">
                <div class="col-md-8 col-sm-8 col-sm-offset-3 col-md-offset-3">
                    <!-- BEGIN CONTENT-->
                    <div id="pmpro_account">		
                        <div id="pmpro_account-membership" class="pmpro_box-first">
                            <?php 
            foreach ($expired as $e) {
                $level_id = $e->membership_id;
                $level = pmpro_getLevel($level_id);
                ?>
                                <div class="pmpro_message">Your "<?php 
                echo $level->name;
                ?>
" Membership has expired, please renew now <a href="<?php 
                echo pmpro_url("levels");
                ?>
"><?php 
                _e("here", "pmpro");
                ?>
</a>.</div>
                                <div id="pmpro_account-membership" class="pmpro_box-first">
                                    <?php 
                $level = $current_user->membership_level->name;
                ?>
                                    <p><?php 
                _e("Membership status: <strong>" . $level->name . "(Expired)</strong>", "pmpro");
                ?>
</p>
                                    <ul>
                                        <?php 
                if ($e->enddate) {
                    //die(var_dump($e->enddate));
                    ?>

                                            <li><strong><?php 
                    _e("Expiration billing date", "pmpro");
                    ?>
:  </strong> <?php 
                    echo " " . date_i18n(get_option('date_format'), strtotime($e->enddate));
                    ?>
</li>
                                        <?php 
                }
                ?>
                                    </ul>

                                </div> <!-- end pmpro_account-membership -->                               
                                <?php 
            }
            ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php 
        }
    }
    ?>
    <?php 
}
function pmpropbc_reminder_emails()
{
    global $wpdb;
    //make sure we only run once a day
    $now = current_time('timestamp');
    $today = date("Y-m-d", $now);
    //have to run for each level, so get levels
    $levels = pmpro_getAllLevels(true, true);
    if (empty($levels)) {
        return;
    }
    foreach ($levels as $level) {
        //get options
        $options = pmpropbc_getOptions($level->id);
        if (!empty($options['reminder_days'])) {
            $date = date("Y-m-d", strtotime("+ " . $options['reminder_days'] . " days", $now));
        } else {
            $date = $today;
        }
        //need to get all combos of pay cycle and period
        $sqlQuery = "SELECT DISTINCT(CONCAT(cycle_number, ' ', cycle_period)) FROM {$wpdb->pmpro_memberships_users} WHERE membership_id = '" . $level->id . "' AND cycle_number > 0 AND status = 'active'";
        $combos = $wpdb->get_col($sqlQuery);
        if (empty($combos)) {
            continue;
        }
        foreach ($combos as $combo) {
            //get all check orders still pending after X days
            $sqlQuery = "\r\n\t\t\t\tSELECT id \r\n\t\t\t\tFROM {$wpdb->pmpro_membership_orders} \r\n\t\t\t\tWHERE membership_id = {$level->id} \r\n\t\t\t\t\tAND gateway = 'check' \r\n\t\t\t\t\tAND status = 'pending' \r\n\t\t\t\t\tAND DATE_ADD(timestamp, INTERVAL {$combo}) <= '" . $date . "'\r\n\t\t\t\t\tAND notes NOT LIKE '%Reminder Sent:%' AND notes NOT LIKE '%Reminder Skipped:%'\r\n\t\t\t\tORDER BY id\r\n\t\t\t";
            if (defined('PMPRO_CRON_LIMIT')) {
                $sqlQuery .= " LIMIT " . PMPRO_CRON_LIMIT;
            }
            $orders = $wpdb->get_col($sqlQuery);
            if (empty($orders)) {
                continue;
            }
            foreach ($orders as $order_id) {
                //get some data
                $order = new MemberOrder($order_id);
                $user = get_userdata($order->user_id);
                $user->membership_level = pmpro_getMembershipLevelForUser($order->user_id);
                //if they are no longer a member, let's not send them an email
                if (empty($user->membership_level) || empty($user->membership_level->ID) || $user->membership_level->id != $order->membership_id) {
                    //note when we send the reminder
                    $new_notes = $order->notes . "Reminder Skipped:" . $today . "\n";
                    $wpdb->query("UPDATE {$wpdb->pmpro_membership_orders} SET notes = '" . esc_sql($new_notes) . "' WHERE id = '" . $order_id . "' LIMIT 1");
                    continue;
                }
                //note when we send the reminder
                $new_notes = $order->notes . "Reminder Sent:" . $today . "\n";
                $wpdb->query("UPDATE {$wpdb->pmpro_membership_orders} SET notes = '" . esc_sql($new_notes) . "' WHERE id = '" . $order_id . "' LIMIT 1");
                //setup email to send
                $email = new PMProEmail();
                $email->template = "check_pending_reminder";
                $email->email = $user->user_email;
                $email->subject = sprintf(__("Reminder: New Invoice for %s at %s", "pmpropbc"), $user->membership_level->name, get_option("blogname"));
                //get body from template
                $email->body = file_get_contents(PMPRO_PAY_BY_CHECK_DIR . "/email/" . $email->template . ".html");
                //setup more data
                $email->data = array("name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "siteemail" => pmpro_getOption("from_email"), "membership_id" => $user->membership_level->id, "membership_level_name" => $user->membership_level->name, "membership_cost" => pmpro_getLevelCost($user->membership_level), "login_link" => wp_login_url(pmpro_url("account")), "display_name" => $user->display_name, "user_email" => $user->user_email);
                $email->data["instructions"] = pmpro_getOption('instructions');
                $email->data["invoice_id"] = $order->code;
                $email->data["invoice_total"] = pmpro_formatPrice($order->total);
                $email->data["invoice_date"] = date(get_option('date_format'), $order->timestamp);
                $email->data["billing_name"] = $order->billing->name;
                $email->data["billing_street"] = $order->billing->street;
                $email->data["billing_city"] = $order->billing->city;
                $email->data["billing_state"] = $order->billing->state;
                $email->data["billing_zip"] = $order->billing->zip;
                $email->data["billing_country"] = $order->billing->country;
                $email->data["billing_phone"] = $order->billing->phone;
                $email->data["cardtype"] = $order->cardtype;
                $email->data["accountnumber"] = hideCardNumber($order->accountnumber);
                $email->data["expirationmonth"] = $order->expirationmonth;
                $email->data["expirationyear"] = $order->expirationyear;
                $email->data["billing_address"] = pmpro_formatAddress($order->billing->name, $order->billing->street, "", $order->billing->city, $order->billing->state, $order->billing->zip, $order->billing->country, $order->billing->phone);
                if ($order->getDiscountCode()) {
                    $email->data["discount_code"] = "<p>" . __("Discount Code", "pmpro") . ": " . $order->discount_code->code . "</p>\n";
                } else {
                    $email->data["discount_code"] = "";
                }
                //send the email
                $email->sendEmail();
            }
        }
    }
}
function pmprodon_pmpro_email_filter($email)
{
    global $wpdb;
    //only update admin confirmation emails
    if (strpos($email->template, "checkout") !== false) {
        //get the user_id from the email
        $order_id = $email->data['invoice_id'];
        if (!empty($order_id)) {
            $order = new MemberOrder($order_id);
            $components = pmprodon_getPriceComponents($order);
            //add to bottom of email
            if (!empty($components['donation'])) {
                $email->body = preg_replace("/\\<p\\>\\s*Invoice/", "<p>Donation Amount: " . pmpro_formatPrice($components['donation']) . "</p><p>Invoice", $email->body);
            }
        }
    }
    return $email;
}
function pmpro_report_memberships_widget()
{
    global $wpdb, $pmpro_currency_symbol;
    ?>
	<style type="text/css">
		#pmpro_report_memberships .section-label {
			margin: 15px 0;
			font-size: 18px;
			text-align: left;
			display: block;
		}
		
		#pmpro_report_memberships .section-label:first-child {
			margin-top: 0;
		}

		#pmpro_report_memberships div {text-align: center;}
		#pmpro_report_memberships em {display: block; font-style: normal; font-size: 2em; margin: 5px; line-height: 26px;}	
	</style>
	<span id="pmpro_report_memberships">
		<label class="section-label"><?php 
    _e('Signups', 'pmpro');
    ?>
:</label>
		<div style="width: 25%; float: left;">	
			<label><?php 
    _e('All Time', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_getSignups('all time');
    ?>
</em>		
		</div>
		<div style="width: 25%; float: left;">	
			<label><?php 
    _e('This Year', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_getSignups('this year');
    ?>
</em>		
		</div>
		<div style="width: 25%; float: left;">	
			<label><?php 
    _e('This Month', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_getSignups('this month');
    ?>
</em>		
		</div>
		<div style="width: 25%; float: left;">
			<label><?php 
    _e('Today', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_getSignups('today');
    ?>
</em>		
		</div>	
		<div class="clear"></div>

		<label class="section-label"><?php 
    _e('Cancellations', 'pmpro');
    ?>
:</label>
		<div style="width: 25%; float: left;">	
			<label><?php 
    _e('All Time', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_getCancellations('all time');
    ?>
</em>		
		</div>
		<div style="width: 25%; float: left;">	
			<label><?php 
    _e('This Year', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_getCancellations('this year');
    ?>
</em>		
		</div>
		<div style="width: 25%; float: left;">	
			<label><?php 
    _e('This Month', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_getCancellations('this month');
    ?>
</em>		
		</div>
		<div style="width: 25%; float: left;">
			<label><?php 
    _e('Today', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_getCancellations('today');
    ?>
</em>		
		</div>	
		<div class="clear"></div>

		<label class="section-label"><?php 
    _e('Other Stats', 'pmpro');
    ?>
:</label>
		<div style="width: 33%; float: left;">	
			<label><?php 
    _e('Monthly Recurring Revenue (MRR)', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_formatPrice(pmpro_getMRR('all time'));
    ?>
</em>		
		</div>
		<div style="width: 33%; float: left;">	
			<label><?php 
    _e('Cancellation Rate', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_getCancellationRate('all time');
    ?>
%</em>		
		</div>
		<div style="width: 33%; float: left;">	
			<label><?php 
    _e('Lifetime Value (LTV)', 'pmpro');
    ?>
</label>
			<em><?php 
    echo pmpro_formatPrice(pmpro_getLTV('all time'));
    ?>
</em>		
		</div>
		<div class="clear"></div>
	</span>
<?php 
}
Beispiel #15
0
</li>
		<?php 
    if ($level->billing_amount > 0) {
        ?>
			<li><strong><?php 
        _e("Membership Fee", "pmpro");
        ?>
:</strong>
				<?php 
        $level = $current_user->membership_level;
        if ($current_user->membership_level->cycle_number > 1) {
            printf(__('%s every %d %s.', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
        } elseif ($current_user->membership_level->cycle_number == 1) {
            printf(__('%s per %s.', 'pmpro'), pmpro_formatPrice($level->billing_amount), pmpro_translate_billing_period($level->cycle_period));
        } else {
            echo pmpro_formatPrice($current_user->membership_level->billing_amount);
        }
        ?>
			</li>
		<?php 
    }
    ?>

		<?php 
    if ($level->billing_limit) {
        ?>
			<li><strong><?php 
        _e("Duration", "pmpro");
        ?>
:</strong> <?php 
        echo $level->billing_limit . ' ' . sornot($level->cycle_period, $level->billing_limit);
function pmpro_getLevelsCost(&$levels, $tags = true, $short = false)
{
    // let's build the array to work from to consolidate recurring info.
    // recurpmts[cycle_period][cycle_number][billing_limit] = total_amount
    $initpmt = 0;
    $recurpmts = array();
    $trialperiods = 0;
    foreach ($levels as $curlevel) {
        $initpmt += $curlevel->initial_payment;
        if ($curlevel->billing_amount != '0.00') {
            if (array_key_exists($curlevel->cycle_period, $recurpmts)) {
                if (array_key_exists($curlevel->cycle_number, $recurpmts[$curlevel->cycle_period])) {
                    if (array_key_exists($curlevel->billing_limit, $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number])) {
                        $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number][$curlevel->billing_limit] += $curlevel->billing_amount;
                    } else {
                        $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number][$curlevel->billing_limit] = $curlevel->billing_amount;
                    }
                } else {
                    $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number] = array();
                    $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number][$curlevel->billing_limit] = $curlevel->billing_amount;
                }
            } else {
                $recurpmts[$curlevel->cycle_period] = array();
                $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number] = array();
                $recurpmts[$curlevel->cycle_period][$curlevel->cycle_number][$curlevel->billing_limit] = $curlevel->billing_amount;
            }
        }
        if ($curlevel->trial_limit && intval($curlevel->trial_limit) > $trialperiods) {
            $trialperiods = intval($curlevel->trial_limit);
        }
    }
    // initial payment
    if (!$short) {
        $r = sprintf(__('The price for membership is <strong>%s</strong> now', 'pmpro'), pmpro_formatPrice($initpmt));
    } else {
        $r = sprintf(__('<strong>%s</strong> now', 'pmpro'), pmpro_formatPrice($initpmt));
    }
    //recurring part
    $billtextparts = array();
    if (count($recurpmts) > 0) {
        foreach ($recurpmts as $curperiod => $curpddata) {
            foreach ($curpddata as $curcyclenum => $curcycledata) {
                foreach ($curcycledata as $curbilllimit => $curtotal) {
                    if ($curbilllimit > 1) {
                        if ($curcyclenum == '1') {
                            $billtextparts[] = sprintf(__('<strong>%s per %s for %d more %s</strong>', 'pmpro'), pmpro_formatPrice($curtotal), pmpro_translate_billing_period($curperiod), $curbilllimit, pmpro_translate_billing_period($curperiod, $curbilllimit));
                        } else {
                            $billtextparts[] = sprintf(__('<strong>%s every %d %s for %d more payments</strong>', 'pmpro'), pmpro_formatPrice($curtotal), $curcyclenum, pmpro_translate_billing_period($curperiod, $curcyclenum), $curbilllimit);
                        }
                    } elseif ($curbilllimit == 1) {
                        $billtextparts[] = sprintf(__('<strong>%s after %d %s</strong>', 'pmpro'), pmpro_formatPrice($curtotal), $curcyclenum, pmpro_translate_billing_period($curperiod, $curcyclenum));
                    } else {
                        if ($curcyclenum == '1') {
                            $billtextparts[] = sprintf(__('<strong>%s every %s</strong>', 'pmpro'), pmpro_formatPrice($curtotal), pmpro_translate_billing_period($curperiod));
                        } else {
                            $billtextparts[] = sprintf(__('<strong>%s every %d %s</strong>', 'pmpro'), pmpro_formatPrice($curtotal), $curcyclenum, pmpro_translate_billing_period($curperiod, $curcyclenum));
                        }
                    }
                }
            }
        }
        $laststanza = array_pop($billtextparts);
        if (count($billtextparts) > 0) {
            $r .= ", ";
            $r .= implode(', ', $billtextparts);
        }
        $r .= ", and " . $laststanza . ".";
    } else {
        $r .= ".";
    }
    //add a space
    $r .= ' ';
    //trial part - not as detailed as the single-level counterpart. Could be improved in the future.
    if ($trialperiods > 0) {
        if ($trialperiods == 1) {
            $r .= __('Trial pricing has been applied to the first payment.', 'mmpu');
        } else {
            $r .= sprintf(__('Trial pricing has been applied to the first %d payments.', 'mmpu'), $trialperiods);
        }
    }
    //taxes part
    $tax_state = pmpro_getOption("tax_state");
    $tax_rate = pmpro_getOption("tax_rate");
    if ($tax_state && $tax_rate && !pmpro_areLevelsFree($levels)) {
        $r .= sprintf(__('Customers in %s will be charged %s%% tax.', 'pmpro'), $tax_state, round($tax_rate * 100, 2));
    }
    if (!$tags) {
        $r = strip_tags($r);
    }
    /**
     * Filter the levels cost text. Note the s in levels. Similar to pmpro_levels_cost_text
     */
    $r = apply_filters("pmpro_levels_cost_text", $r, $levels, $tags, $short);
    return $r;
}
function pmpro_shortcode_account($atts, $content = null, $code = "")
{
    global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
    // $atts    ::= array of attributes
    // $content ::= text within enclosing form of shortcode element
    // $code    ::= the shortcode found, when == callback name
    // examples: [pmpro_account] [pmpro_account sections="membership,profile"/]
    extract(shortcode_atts(array('section' => '', 'sections' => 'membership,profile,invoices,links'), $atts));
    //did they use 'section' instead of 'sections'?
    if (!empty($section)) {
        $sections = $section;
    }
    //turn into an array
    $sections = explode(',', $sections);
    ob_start();
    //if a member is logged in, show them some info here (1. past invoices. 2. billing information with button to update.)
    if (pmpro_hasMembershipLevel()) {
        $ssorder = new MemberOrder();
        $ssorder->getLastMemberOrder();
        $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' ORDER BY timestamp DESC LIMIT 6");
        ?>
	
	<div id="pmpro_account">		
		
		<?php 
        if (in_array('membership', $sections) || in_array('memberships', $sections)) {
            ?>
			<div id="pmpro_account-membership" class="pmpro_box">
				
				<h3><?php 
            _e("My Memberships", "pmpro");
            ?>
</h3>
				<table width="100%" cellpadding="0" cellspacing="0" border="0">
					<thead>
						<tr>
							<th><?php 
            _e("Level", "pmpro");
            ?>
</th>
							<th><?php 
            _e("Billing", "pmpro");
            ?>
</th>
							<th><?php 
            _e("Expiration", "pmpro");
            ?>
</th>
						</tr>
					</thead>
					<tbody>
						<?php 
            //TODO: v2.0 will loop through levels here
            $level = $current_user->membership_level;
            ?>
						<tr>
							<td class="pmpro_account-membership-levelname">
								<?php 
            echo $current_user->membership_level->name;
            ?>
								<div class="pmpro_actionlinks">
									<?php 
            do_action("pmpro_member_action_links_before");
            ?>
									
									<?php 
            if (pmpro_isLevelExpiringSoon($current_user->membership_level)) {
                ?>
										<a href="<?php 
                echo pmpro_url("checkout", "?level=" . $current_user->membership_level->id, "https");
                ?>
"><?php 
                _e("Renew", "pmpro");
                ?>
</a>
									<?php 
            }
            ?>

									<?php 
            if (isset($ssorder->status) && $ssorder->status == "success" && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource")))) {
                ?>
										<a href="<?php 
                echo pmpro_url("billing", "", "https");
                ?>
"><?php 
                _e("Update Billing Info", "pmpro");
                ?>
</a>
									<?php 
            }
            ?>
									
									<?php 
            //To do: Only show CHANGE link if this level is in a group that has upgrade/downgrade rules
            if (count($pmpro_levels) > 1 && !defined("PMPRO_DEFAULT_LEVEL")) {
                ?>
										<a href="<?php 
                echo pmpro_url("levels");
                ?>
"><?php 
                _e("Change", "pmpro");
                ?>
</a>
									<?php 
            }
            ?>
									<a href="<?php 
            echo pmpro_url("cancel", "?level=" . $current_user->membership_level->id);
            ?>
"><?php 
            _e("Cancel", "pmpro");
            ?>
</a>
									<?php 
            do_action("pmpro_member_action_links_after");
            ?>
								</div> <!-- end pmpro_actionlinks -->
							</td>
							<td class="pmpro_account-membership-levelfee">
								<p><?php 
            echo pmpro_getLevelCost($level, true, true);
            ?>
</p>
							</td>
							<td class="pmpro_account-membership-expiration">
							<?php 
            if ($current_user->membership_level->enddate) {
                echo date(get_option('date_format'), $current_user->membership_level->enddate);
            } else {
                echo "---";
            }
            ?>
							</td>
						</tr>
					</tbody>
				</table>
				<?php 
            //Todo: If there are multiple levels defined that aren't all in the same group defined as upgrades/downgrades
            ?>
				<div class="pmpro_actionlinks">
					<a href="<?php 
            echo pmpro_url("levels");
            ?>
"><?php 
            _e("View all Membership Options", "pmpro");
            ?>
</a>
				</div>

			</div> <!-- end pmpro_account-membership -->
		<?php 
        }
        ?>
		
		<?php 
        if (in_array('profile', $sections)) {
            ?>
			<div id="pmpro_account-profile" class="pmpro_box">	
				<?php 
            get_currentuserinfo();
            ?>
 
				<h3><?php 
            _e("My Account", "pmpro");
            ?>
</h3>
				<?php 
            if ($current_user->user_firstname) {
                ?>
					<p><?php 
                echo $current_user->user_firstname;
                ?>
 <?php 
                echo $current_user->user_lastname;
                ?>
</p>
				<?php 
            }
            ?>
				<ul>
					<?php 
            do_action('pmpro_account_bullets_top');
            ?>
					<li><strong><?php 
            _e("Username", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->user_login;
            ?>
</li>
					<li><strong><?php 
            _e("Email", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->user_email;
            ?>
</li>
					<?php 
            do_action('pmpro_account_bullets_bottom');
            ?>
				</ul>
				<div class="pmpro_actionlinks">
					<a href="<?php 
            echo admin_url('profile.php');
            ?>
"><?php 
            _e("Edit Profile", "pmpro");
            ?>
</a>
					<a href="<?php 
            echo admin_url('profile.php');
            ?>
"><?php 
            _e('Change Password', 'pmpro');
            ?>
</a>
				</div>
			</div> <!-- end pmpro_account-profile -->
		<?php 
        }
        ?>
	
		<?php 
        if (in_array('invoices', $sections) && !empty($invoices)) {
            ?>
		
		<div id="pmpro_account-invoices" class="pmpro_box">
			<h3><?php 
            _e("Past Invoices", "pmpro");
            ?>
</h3>
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<thead>
					<tr>
						<th><?php 
            _e("Date", "pmpro");
            ?>
</th>
						<th><?php 
            _e("Level", "pmpro");
            ?>
</th>
						<th><?php 
            _e("Amount", "pmpro");
            ?>
</th>
					</tr>
				</thead>
				<tbody>
				<?php 
            $count = 0;
            foreach ($invoices as $invoice) {
                if ($count++ > 4) {
                    break;
                }
                //get an member order object
                $invoice_id = $invoice->id;
                $invoice = new MemberOrder();
                $invoice->getMemberOrderByID($invoice_id);
                $invoice->getMembershipLevel();
                ?>
						<tr id="pmpro_account-invoice-<?php 
                echo $invoice->code;
                ?>
">
							<td><a href="<?php 
                echo pmpro_url("invoice", "?invoice=" . $invoice->code);
                ?>
"><?php 
                echo date(get_option("date_format"), $invoice->timestamp);
                ?>
</td>
							<td><?php 
                echo $invoice->membership_level->name;
                ?>
</td>
							<td><?php 
                echo pmpro_formatPrice($invoice->total);
                ?>
</td>
						</tr>
						<?php 
            }
            ?>
				</tbody>
			</table>						
			<?php 
            if ($count == 6) {
                ?>
				<div class="pmpro_actionlinks"><a href="<?php 
                echo pmpro_url("invoice");
                ?>
"><?php 
                _e("View All Invoices", "pmpro");
                ?>
</a></div>
			<?php 
            }
            ?>
		</div> <!-- end pmpro_account-invoices -->
		<?php 
        }
        ?>
		
		<?php 
        if (in_array('links', $sections) && (has_filter('pmpro_member_links_top') || has_filter('pmpro_member_links_bottom'))) {
            ?>
		<div id="pmpro_account-links" class="pmpro_box">
			<h3><?php 
            _e("Member Links", "pmpro");
            ?>
</h3>
			<ul>
				<?php 
            do_action("pmpro_member_links_top");
            ?>
				
				<?php 
            do_action("pmpro_member_links_bottom");
            ?>
			</ul>
		</div> <!-- end pmpro_account-links -->		
		<?php 
        }
        ?>
	</div> <!-- end pmpro_account -->		
	<?php 
    }
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}
function pmproap_pmpro_text_filter($text)
{
    global $wpdb, $current_user, $post, $pmpro_currency_symbol;
    if (!empty($post)) {
        if (pmproap_isPostLocked($post->ID) && !pmproap_hasAccess($current_user->ID, $post->ID)) {
            //which level to use for checkout link?
            $text_level_id = pmproap_getLevelIDForCheckoutLink($post->ID, $current_user->ID);
            if (empty($text_level_id)) {
                $text = "<p>" . __("You must first purchase a membership level before purchasing this content. ", "pmproap") . "</p>";
                $text .= "<p><a href=\"" . pmpro_url("levels") . "\">" . __("Click here to choose a membership level.", "pmproap") . "</a></p>";
            } else {
                //what's the price
                $pmproap_price = get_post_meta($post->ID, "_pmproap_price", true);
                //check for all access levels
                $all_access_levels = apply_filters("pmproap_all_access_levels", array(), $current_user->ID, $post->ID);
                //update text
                if (!empty($all_access_levels)) {
                    $level_names = array();
                    foreach ($all_access_levels as $level_id) {
                        $level = pmpro_getLevel($level_id);
                        $level_names[] = $level->name;
                    }
                    $text = "<p>" . __("This content requires that you purchase additional access. The price is %s or free for our %s members.", pmpro_formatPrice($pmproap_price), pmpro_implodeToEnglish($level_names)) . "</p>";
                    $text .= "<p><a href=\"" . pmpro_url("checkout", "?level=" . $text_level_id . "&ap=" . $post->ID) . "\">" . sprintf(__("Purchase this Content (%s)", 'pmproap'), pmpro_formatPrice($pmproap_price)) . "</a> <a href=\"" . pmpro_url("levels") . "\">" . __("Choose a Membership Level", "pmproap") . "</a></p>";
                } else {
                    $text = "<p>" . sprintf(__("This content requires that you purchase additional access. The price is %s.", "pmproap"), pmpro_formatPrice($pmproap_price)) . "</p>";
                    $text .= "<p><a href=\"" . pmpro_url("checkout", "?level=" . $text_level_id . "&ap=" . $post->ID) . "\">" . __("Click here to checkout", "pmproap") . "</a></p>";
                }
            }
        }
    }
    return $text;
}
    } elseif ($pmpro_invoice->payment_type) {
        ?>
						<?php 
        echo $pmpro_invoice->payment_type;
        ?>
					<?php 
    }
    ?>
				</td>
				<td><?php 
    echo $pmpro_invoice->membership_level->name;
    ?>
</td>					
				<td><?php 
    if ($pmpro_invoice->total) {
        echo pmpro_formatPrice($pmpro_invoice->total);
    } else {
        echo "---";
    }
    ?>
</td>
			</tr>
		</tbody>
	</table>		
<?php 
} else {
    $confirmation_message .= "<p>" . sprintf(__('Below are details about your membership account. A welcome email has been sent to %s.', 'pmpro'), $current_user->user_email) . "</p>";
    $confirmation_message = apply_filters("pmpro_confirmation_message", $confirmation_message, false);
    echo $confirmation_message;
    ?>
	
 function sendTrialEndingEmail($user = NULL)
 {
     global $current_user, $wpdb;
     if (!$user) {
         $user = $current_user;
     }
     if (!$user) {
         return false;
     }
     //make sure we have the current membership level data
     /*$user->membership_level = $wpdb->get_row("SELECT l.id AS ID, l.name AS name, UNIX_TIMESTAMP(mu.startdate) as startdate, mu.billing_amount, mu.cycle_number, mu.cycle_period, mu.trial_amount, mu.trial_limit
     		FROM {$wpdb->pmpro_membership_levels} AS l
     		JOIN {$wpdb->pmpro_memberships_users} AS mu ON (l.id = mu.membership_id)
     		WHERE mu.user_id = " . $user->ID . "
     		LIMIT 1");*/
     $user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
     $this->email = $user->user_email;
     $this->subject = sprintf(__("Your trial at %s is ending soon", "pmpro"), get_option("blogname"));
     $this->template = "trial_ending";
     $this->data = array("subject" => $this->subject, "name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "membership_id" => $user->membership_level->id, "membership_level_name" => $user->membership_level->name, "siteemail" => pmpro_getOption("from_email"), "login_link" => wp_login_url(), "display_name" => $user->display_name, "user_email" => $user->user_email, "billing_amount" => pmpro_formatPrice($user->membership_level->billing_amount), "cycle_number" => $user->membership_level->cycle_number, "cycle_period" => $user->membership_level->cycle_period, "trial_amount" => pmpro_formatPrice($user->membership_level->trial_amount), "trial_limit" => $user->membership_level->trial_limit, "trial_end" => date_i18n(get_option('date_format'), strtotime(date_i18n("m/d/Y", $user->membership_level->startdate) . " + " . $user->membership_level->trial_limit . " " . $user->membership_level->cycle_period), current_time("timestamp")));
     return $this->sendEmail();
 }
                $out .= "<span class='{$action}'>{$link}{$sep}</span>";
            }
            $out .= '</div>';
            echo $out;
        }
        ?>
					</td>
					<?php 
        do_action("pmpro_orders_extra_cols_body", $order);
        ?>
					<td><?php 
        echo $order->membership_id;
        ?>
</td>
					<td><?php 
        echo pmpro_formatPrice($order->total);
        ?>
</td>
					<td>
						<?php 
        if (!empty($order->payment_type)) {
            echo $order->payment_type . "<br />";
        }
        ?>
						<?php 
        if (!empty($order->accountnumber)) {
            ?>
							<?php 
            echo $order->cardtype;
            ?>
: x<?php 
function billing_content_func($atts)
{
    global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
    //-> If a member is logged in, show them some info here (1. past invoices. 2. billing information with button to update.)
    if ($current_user->membership_level->ID) {
        if ($pmpro_msg) {
            ?>
            <div class="pmpro_message <?php 
            echo $pmpro_msgt;
            ?>
"><?php 
            echo $pmpro_msg;
            ?>
</div>
            <?php 
        }
        ?>
	
        <div class="row">
            <div class="col-md-8 col-sm-8 col-sm-offset-2 col-md-offset-2">
                <!-- BEGIN CONTENT-->
                <div id="pmpro_account">		
                    <div id="pmpro_account-membership" class="pmpro_box">
                        <p><?php 
        _e("Your membership is <strong>active</strong>.", "pmpro");
        ?>
</p>
                        <ul>
                            <li><strong><?php 
        _e("Level", "pmpro");
        ?>
:</strong> <?php 
        echo $current_user->membership_level->name;
        ?>
</li>
                            <?php 
        if ($current_user->membership_level->billing_amount > 0) {
            ?>
                                <li><strong><?php 
            _e("Membership Fee", "pmpro");
            ?>
:</strong>
                                    <?php 
            $level = $current_user->membership_level;
            if ($current_user->membership_level->cycle_number > 1) {
                printf(__('%s every %d %s.', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
            } elseif ($current_user->membership_level->cycle_number == 1) {
                printf(__('%s per %s.', 'pmpro'), pmpro_formatPrice($level->billing_amount), pmpro_translate_billing_period($level->cycle_period));
            } else {
                echo pmpro_formatPrice($current_user->membership_level->billing_amount);
            }
            ?>
                                </li>
                            <?php 
        }
        ?>
						

                            <?php 
        if ($current_user->membership_level->billing_limit) {
            ?>
                                <li><strong><?php 
            _e("Duration", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->membership_level->billing_limit . ' ' . sornot($current_user->membership_level->cycle_period, $current_user->membership_level->billing_limit);
            ?>
</li>
                            <?php 
        }
        ?>

                            <?php 
        if ($current_user->membership_level->enddate) {
            ?>
                                <li><strong><?php 
            _e("Membership Expires", "pmpro");
            ?>
:</strong> <?php 
            echo date_i18n(get_option('date_format'), $current_user->membership_level->enddate);
            ?>
</li>
                            <?php 
        }
        ?>

                            <?php 
        if ($current_user->membership_level->trial_limit == 1) {
            printf(__("Your first payment will cost %s.", "pmpro"), pmpro_formatPrice($current_user->membership_level->trial_amount));
        } elseif (!empty($current_user->membership_level->trial_limit)) {
            printf(__("Your first %d payments will cost %s.", "pmpro"), $current_user->membership_level->trial_limit, pmpro_formatPrice($current_user->membership_level->trial_amount));
        }
        ?>
                        </ul>

                    </div> <!-- end pmpro_account-membership -->

                    <div id="pmpro_account-profile" class="pmpro_box hide">	
                        <?php 
        get_currentuserinfo();
        ?>
 
                        <h3><?php 
        _e("My Account", "pmpro");
        ?>
</h3>
                        <?php 
        if ($current_user->user_firstname) {
            ?>
                            <p><?php 
            echo $current_user->user_firstname;
            ?>
 <?php 
            echo $current_user->user_lastname;
            ?>
</p>
                        <?php 
        }
        ?>
                        <ul>
                            <li><strong><?php 
        _e("Username", "pmpro");
        ?>
:</strong> <?php 
        echo $current_user->user_login;
        ?>
</li>
                            <li><strong><?php 
        _e("Email", "pmpro");
        ?>
:</strong> <?php 
        echo $current_user->user_email;
        ?>
</li>
                        </ul>
                        <p>
                            <a href="<?php 
        echo admin_url('profile.php');
        ?>
"><?php 
        _e("Edit Profile", "pmpro");
        ?>
</a> |
                            <a href="<?php 
        echo admin_url('profile.php');
        ?>
"><?php 
        _ex("Change Password", "As in 'change password'.", "pmpro");
        ?>
</a>
                        </p>
                    </div> <!-- end pmpro_account-profile -->

                    <?php 
        //last invoice for current info
        //$ssorder = $wpdb->get_row("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM $wpdb->pmpro_membership_orders WHERE user_id = '$current_user->ID' AND membership_id = '" . $current_user->membership_level->ID . "' AND status = 'success' ORDER BY timestamp DESC LIMIT 1");
        $ssorder = new MemberOrder();
        $ssorder->getLastMemberOrder();
        $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' ORDER BY timestamp DESC LIMIT 6");
        if (!empty($ssorder->id) && $ssorder->gateway != "check" && $ssorder->gateway != "paypalexpress" && $ssorder->gateway != "paypalstandard" && $ssorder->gateway != "twocheckout") {
            //default values from DB (should be last order or last update)
            $bfirstname = get_user_meta($current_user->ID, "pmpro_bfirstname", true);
            $blastname = get_user_meta($current_user->ID, "pmpro_blastname", true);
            $baddress1 = get_user_meta($current_user->ID, "pmpro_baddress1", true);
            $baddress2 = get_user_meta($current_user->ID, "pmpro_baddress2", true);
            $bcity = get_user_meta($current_user->ID, "pmpro_bcity", true);
            $bstate = get_user_meta($current_user->ID, "pmpro_bstate", true);
            $bzipcode = get_user_meta($current_user->ID, "pmpro_bzipcode", true);
            $bcountry = get_user_meta($current_user->ID, "pmpro_bcountry", true);
            $bphone = get_user_meta($current_user->ID, "pmpro_bphone", true);
            $bemail = get_user_meta($current_user->ID, "pmpro_bemail", true);
            $bconfirmemail = get_user_meta($current_user->ID, "pmpro_bconfirmemail", true);
            $CardType = get_user_meta($current_user->ID, "pmpro_CardType", true);
            $AccountNumber = hideCardNumber(get_user_meta($current_user->ID, "pmpro_AccountNumber", true), false);
            $ExpirationMonth = get_user_meta($current_user->ID, "pmpro_ExpirationMonth", true);
            $ExpirationYear = get_user_meta($current_user->ID, "pmpro_ExpirationYear", true);
            ?>
	

                        <div id="pmpro_account-billing" class="pmpro_box">
                            <h3><?php 
            _e("Billing Information", "pmpro");
            ?>
</h3>
                            <?php 
            if (!empty($baddress1)) {
                ?>
                                <p>
                                    <strong><?php 
                _e("Billing Address", "pmpro");
                ?>
</strong><br />
                                    <?php 
                echo $bfirstname . " " . $blastname;
                ?>
                                    <br />		
                                    <?php 
                echo $baddress1;
                ?>
<br />
                                    <?php 
                if ($baddress2) {
                    echo $baddress2 . "<br />";
                }
                ?>
                                    <?php 
                if ($bcity && $bstate) {
                    ?>
                                        <?php 
                    echo $bcity;
                    ?>
, <?php 
                    echo $bstate;
                    ?>
 <?php 
                    echo $bzipcode;
                    ?>
 <?php 
                    echo $bcountry;
                    ?>
                                    <?php 
                }
                ?>
                         
                                    <br />
                                    <?php 
                echo formatPhone($bphone);
                ?>
                                </p>
                            <?php 
            }
            ?>

                            <?php 
            if (!empty($AccountNumber)) {
                ?>
                                <p>
                                    <strong><?php 
                _e("Payment Method", "pmpro");
                ?>
</strong><br />
                                    <?php 
                echo $CardType;
                ?>
: <?php 
                echo last4($AccountNumber);
                ?>
 (<?php 
                echo $ExpirationMonth;
                ?>
/<?php 
                echo $ExpirationYear;
                ?>
)
                                </p>
                            <?php 
            }
            ?>

                            <?php 
            if (isset($ssorder->status) && $ssorder->status == "success" && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource")))) {
                ?>
                                <p><a href="<?php 
                echo pmpro_url("billing", "");
                ?>
"><?php 
                _e("Edit Billing Information", "pmpro");
                ?>
</a></p>
                                <?php 
            }
            ?>
                        </div> <!-- end pmpro_account-billing -->				
                        <?php 
        }
        ?>

                    <?php 
        if (!empty($invoices)) {
            ?>
                        <div id="pmpro_account-invoices" class="pmpro_box">
                            <h3><?php 
            _e("Past Invoices", "pmpro");
            ?>
</h3>
                            <ul>
                                <?php 
            $count = 0;
            foreach ($invoices as $invoice) {
                if ($count++ > 5) {
                    break;
                }
                ?>
                                    <li><a href="<?php 
                echo pmpro_url("invoice", "?invoice=" . $invoice->code);
                ?>
"><?php 
                echo date_i18n(get_option("date_format"), $invoice->timestamp);
                ?>
 (<?php 
                echo pmpro_formatPrice($invoice->total);
                ?>
)</a></li>
                                    <?php 
            }
            ?>
                            </ul>
                            <?php 
            if ($count == 6) {
                ?>
                                <p><a href="<?php 
                echo pmpro_url("invoice");
                ?>
"><?php 
                _e("View All Invoices", "pmpro");
                ?>
</a></p>
                            <?php 
            }
            ?>
                        </div> <!-- end pmpro_account-billing -->
                    <?php 
        }
        ?>
                    <p class="help-block">We have the following subscriptions available for our site. To join, simply click on the <strong>Renew</strong> or <strong>Change Subscription</strong> button and then complete the registration details.</p>
                    <?php 
        getLevels();
        ?>
                    <div id="pmpro_account-links" class="pmpro_box">
                        <h3><?php 
        _e("Manage Membership", "pmpro");
        ?>
</h3>
                        <ul>
                            <?php 
        do_action("pmpro_member_links_top");
        ?>
                            <?php 
        if (isset($ssorder->status) && $ssorder->status == "success" && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource")))) {
            ?>
                                <li><a href="<?php 
            echo pmpro_url("billing", "", "https");
            ?>
"><?php 
            _e("Update Billing Information", "pmpro");
            ?>
</a></li>
                            <?php 
        }
        ?>
                            <?php 
        if (count($pmpro_levels) > 1 && !defined("PMPRO_DEFAULT_LEVEL")) {
            ?>
                                <li><a href="<?php 
            echo pmpro_url("levels");
            ?>
"> <?php 
            _e("Change Membership Level", "pmpro");
            ?>
</a></li>
                            <?php 
        }
        ?>
                            <li><a href="<?php 
        echo pmpro_url("cancel");
        ?>
" class="red"><?php 
        _e("Cancel Membership", "pmpro");
        ?>
</a></li>
                            <?php 
        do_action("pmpro_member_links_bottom");
        ?>
                        </ul>
                    </div> <!-- end pmpro_account-links -->		
                </div> <!-- end pmpro_account -->	

                <!-- END CONTENT-->
            </div>
        </div>
        <?php 
    }
    ?>
    <?php 
}