/**
  * Determines if the current user is permitted to even think about using
  * simulation. If not allowed, then most of this class will not be used.
  *
  * @since  1.0.0
  * @return bool
  */
 public static function can_simulate()
 {
     if (defined('DOING_CRON') && DOING_CRON) {
         // No simulation during cron jobs...
         return false;
     }
     if (MS_Model_Member::is_admin_user()) {
         return true;
     }
     return false;
 }
 /**
  * Verify if current user can perform management actions.
  *
  * @since  1.0.0
  *
  * @return boolean True if can, false otherwise.
  */
 public function is_admin_user()
 {
     $is_admin_user = MS_Model_Member::is_admin_user();
     return apply_filters('ms_controller_is_admin_user', $is_admin_user);
 }
 /**
  * Returns true only then, when the current user can edit menu items.
  *
  * Reasons why it might be denied:
  * - There are no menus where items can be added to.
  * - The user is no admin.
  *
  * @since  1.0.0
  * @return bool
  */
 public static function can_edit_menus()
 {
     $Can_Edit_Menus = null;
     if (null === $Can_Edit_Menus) {
         $Can_Edit_Menus = false;
         if (!MS_Plugin::is_network_wide()) {
             $menus = wp_get_nav_menus();
             if (MS_Model_Member::is_admin_user() && !empty($menus)) {
                 $Can_Edit_Menus = true;
             }
         }
         $Can_Edit_Menus = apply_filters('ms_model_pages_can_edit_menus', $Can_Edit_Menus);
     }
     return $Can_Edit_Menus;
 }
 /**
  * Create membership column.
  *
  * @since  1.0.0
  *
  * @param MS_Model_Member $member The member object.
  */
 public function column_membership($member)
 {
     if (MS_Model_Member::is_admin_user($member->id)) {
         $html = '<b>' . __('Admin User', MS_TEXT_DOMAIN) . '</b>';
     } else {
         $subscriptions = $member->get_membership_ids();
         $visitor = array('id' => 'ms-empty-' . $member->id, 'type' => MS_Helper_Html::TYPE_HTML_TEXT, 'value' => __('(Visitor)'), 'after' => 'Edit', 'class' => 'ms-empty-note');
         $list = array('id' => 'ms-memberships-' . $member->id, 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $subscriptions, 'field_options' => self::$memberships, 'multiple' => true, 'class' => 'ms-memberships', 'ajax_data' => array('action' => MS_Controller_Member::AJAX_ACTION_CHANGE_MEMBERSHIPS, 'member' => $member->id));
         $html = sprintf('<div class="no-auto-init">%1$s%2$s</div>', MS_Helper_Html::html_element($visitor, true), MS_Helper_Html::html_element($list, true));
     }
     return apply_filters('ms_helper_listtable_member_column_membership', $html, $member, $this);
 }
 /**
  * Redirect user to account page.
  *
  * Only redirect when no previous redirect_to is set or when going to /wp-admin/.
  *
  * @since  1.0.0
  *
  * @param string $redirect_to URL to redirect to.
  * @param string $request URL the user is coming from.
  * @param object $user Logged user's data.
  * @return string The redirect url.
  */
 public function login_redirect($redirect_to, $request, $user)
 {
     if (!empty($user->ID) && !MS_Model_Member::is_admin_user($user->ID) && (empty($redirect_to) || admin_url() == $redirect_to)) {
         $redirect_to = MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_ACCOUNT);
     }
     return apply_filters('ms_controller_frontend_login_redirect', $redirect_to, $request, $user, $this);
 }
 /**
  * Customize the Admin Toolbar.
  *
  * Related Action Hooks:
  * - wp_before_admin_bar_render
  *
  * @since  1.0.0
  */
 public function customize_toolbar()
 {
     if (MS_Model_Member::is_admin_user() && MS_Plugin::is_enabled() && !is_network_admin() && MS_Model_Simulate::can_simulate()) {
         if ($this->simulate->is_simulating()) {
             $this->add_detail_nodes();
         } else {
             $this->add_test_membership_node();
         }
     } else {
         if (!MS_Plugin::is_enabled()) {
             $this->add_unprotected_node();
         }
     }
 }
 /**
  * Save model.
  *
  * Only saves if is not admin user and not a visitor.
  * Don't save automatically assigned visitor/system memberships.
  *
  * @since  1.0.0
  * @api
  */
 public function save()
 {
     do_action('ms_model_relationship_save_before', $this);
     if (!empty($this->user_id) && !MS_Model_Member::is_admin_user($this->user_id)) {
         if (!$this->is_system()) {
             parent::save();
             parent::store_singleton();
         }
     }
     do_action('ms_model_relationship_after', $this);
 }
 /**
  * Special Shortcode Callback: Replace shortcodes with empty value.
  *
  *     All Shortcodes use this callback function
  *     when Content Protection is DISABLED!
  *
  * @since  1.0.0
  * @param  mixed[] $atts Shortcode attributes.
  * @param  string $content
  * @return string
  */
 public function ms_no_value($atts, $content = '')
 {
     static $Done = false;
     if ($Done) {
         return '';
     }
     $Done = true;
     if (MS_Model_Member::is_admin_user()) {
         $content = sprintf('<p class="ms-alert-box ms-alert-error ms-unprotected">%s<br /><br /><em>(%s)</em></p>', __('Content Protection is disabled. Please enable the protection to see this shortcode.', 'membership2'), __('This message is only displayed to Site Administrators', 'membership2'));
     } else {
         $content = '';
     }
     return apply_filters('ms_controller_shortcode_ms_no_value', $content, $this);
 }
    public function to_html()
    {
        global $post;
        /**
         * Provide a customized account page.
         *
         * @since  1.0.0
         */
        $html = apply_filters('ms_shortcode_custom_account', '', $this->data);
        if (!empty($html)) {
            return $html;
        } else {
            $html = '';
        }
        $member = MS_Model_Member::get_current_member();
        $fields = $this->prepare_fields();
        // Extract shortcode options.
        extract($this->data);
        ob_start();
        ?>
		<div class="ms-account-wrapper">
			<?php 
        if (MS_Model_Member::is_logged_in()) {
            ?>

				<?php 
            // ================================================= MEMBERSHIPS
            if ($show_membership) {
                ?>
				<div id="account-membership">
				<h2>
					<?php 
                echo $membership_title;
                if ($show_membership_change) {
                    $signup_url = MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_REGISTER);
                    printf('<a href="%s" class="ms-edit-profile">%s</a>', $signup_url, $membership_change_label);
                }
                ?>
				</h2>
				<?php 
                /**
                 * Add custom content right before the memberships list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_memberships_top', $member, $this);
                if (MS_Model_Member::is_admin_user()) {
                    _e('You are an admin user and have access to all memberships', 'membership2');
                } else {
                    if (!empty($this->data['subscription'])) {
                        ?>
						<table>
							<tr>
								<th class="ms-col-membership"><?php 
                        _e('Membership name', 'membership2');
                        ?>
</th>
								<th class="ms-col-status"><?php 
                        _e('Status', 'membership2');
                        ?>
</th>
								<th class="ms-col-expire-date"><?php 
                        _e('Expire date', 'membership2');
                        ?>
</th>
							</tr>
							<?php 
                        $empty = true;
                        // These subscriptions have no expire date
                        $no_expire_list = array(MS_Model_Relationship::STATUS_PENDING, MS_Model_Relationship::STATUS_WAITING, MS_Model_Relationship::STATUS_DEACTIVATED);
                        // These subscriptions display the trial-expire date
                        $trial_expire_list = array(MS_Model_Relationship::STATUS_TRIAL, MS_Model_Relationship::STATUS_TRIAL_EXPIRED);
                        foreach ($this->data['subscription'] as $subscription) {
                            $empty = false;
                            $membership = $subscription->get_membership();
                            $subs_classes = array('ms-subscription-' . $subscription->id, 'ms-status-' . $subscription->status, 'ms-type-' . $membership->type, 'ms-payment-' . $membership->payment_type, 'ms-gateway-' . $subscription->gateway_id, 'ms-membership-' . $subscription->membership_id, $subscription->has_trial() ? 'ms-with-trial' : 'ms-no-trial');
                            ?>
								<tr class="<?php 
                            echo esc_attr(implode(' ', $subs_classes));
                            ?>
">
									<td class="ms-col-membership"><?php 
                            echo esc_html($membership->name);
                            ?>
</td>
									<td class="ms-col-status">
									<?php 
                            if (MS_Model_Relationship::STATUS_PENDING == $subscription->status) {
                                // Display a "Purchase" link when status is Pending
                                $code = sprintf('[%s id="%s" label="%s"]', MS_Helper_Shortcode::SCODE_MS_BUY, $membership->id, __('Pending', 'membership2'));
                                echo do_shortcode($code);
                            } else {
                                echo esc_html($subscription->status_text());
                            }
                            ?>
									</td>
									<td class="ms-col-expire-date"><?php 
                            if (in_array($subscription->status, $no_expire_list)) {
                                echo '&nbsp;';
                            } elseif (in_array($subscription->status, $trial_expire_list)) {
                                echo esc_html(MS_Helper_Period::format_date($subscription->trial_expire_date));
                            } elseif ($subscription->expire_date) {
                                echo esc_html(MS_Helper_Period::format_date($subscription->expire_date));
                            } else {
                                _e('Never', 'membership2');
                            }
                            ?>
</td>
								</tr>
							<?php 
                        }
                        if ($empty) {
                            $cols = 3;
                            if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_TRIAL)) {
                                $cols += 1;
                            }
                            printf('<tr><td colspan="%1$s">%2$s</td></tr>', $cols, __('(No Membership)', 'membership2'));
                        }
                        ?>
						</table>
					<?php 
                    } else {
                        _e('No memberships', 'membership2');
                    }
                }
                /**
                 * Add custom content right after the memberships list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_memberships_bottom', $member, $this);
                ?>
				</div>
				<?php 
            }
            // END: if ( $show_membership )
            // =============================================================
            ?>

				<?php 
            // ===================================================== PROFILE
            if ($show_profile) {
                ?>
				<div id="account-profile">
				<h2>
					<?php 
                echo $profile_title;
                if ($show_profile_change) {
                    $edit_url = esc_url_raw(add_query_arg(array('action' => MS_Controller_Frontend::ACTION_EDIT_PROFILE)));
                    printf('<a href="%s" class="ms-edit-profile">%s</a>', $edit_url, $profile_change_label);
                }
                ?>
				</h2>
				<?php 
                /**
                 * Add custom content right before the profile overview.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_profile_top', $member, $this);
                ?>
				<table>
					<?php 
                foreach ($fields['personal_info'] as $field => $title) {
                    ?>
						<tr>
							<th class="ms-label-title"><?php 
                    echo esc_html($title);
                    ?>
: </th>
							<td class="ms-label-field"><?php 
                    echo esc_html($this->data['member']->{$field});
                    ?>
</td>
						</tr>
					<?php 
                }
                ?>
				</table>
				<?php 
                do_action('ms_view_shortcode_account_card_info', $this->data);
                /**
                 * Add custom content right after the profile overview.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_profile_bottom', $member, $this);
                ?>
				</div>
				<?php 
            }
            // END: if ( $show_profile )
            // =============================================================
            ?>

				<?php 
            // ==================================================== INVOICES
            if ($show_invoices) {
                ?>
				<div id="account-invoices">
				<h2>
					<?php 
                echo $invoices_title;
                if ($show_all_invoices) {
                    $detail_url = esc_url_raw(add_query_arg(array('action' => MS_Controller_Frontend::ACTION_VIEW_INVOICES)));
                    printf('<a href="%s" class="ms-all-invoices">%s</a>', $detail_url, $invoices_details_label);
                }
                ?>
				</h2>
				<?php 
                /**
                 * Add custom content right before the invoice overview list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_invoices_top', $member, $this);
                ?>
				<table>
					<thead>
						<tr>
							<th class="ms-col-invoice-no"><?php 
                _e('Invoice #', 'membership2');
                ?>
</th>
							<th class="ms-col-invoice-status"><?php 
                _e('Status', 'membership2');
                ?>
</th>
							<th class="ms-col-invoice-total"><?php 
                printf('%s (%s)', __('Total', 'membership2'), MS_Plugin::instance()->settings->currency);
                ?>
</th>
							<th class="ms-col-invoice-title"><?php 
                _e('Membership', 'membership2');
                ?>
</th>
							<th class="ms-col-invoice-due"><?php 
                _e('Due date', 'membership2');
                ?>
</th>
						</tr>
					</thead>
					<tbody>
					<?php 
                foreach ($this->data['invoices'] as $invoice) {
                    $inv_membership = MS_Factory::load('MS_Model_Membership', $invoice->membership_id);
                    $inv_classes = array('ms-invoice-' . $invoice->id, 'ms-subscription-' . $invoice->ms_relationship_id, 'ms-invoice-' . $invoice->status, 'ms-gateway-' . $invoice->gateway_id, 'ms-membership-' . $invoice->membership_id, 'ms-type-' . $inv_membership->type, 'ms-payment-' . $inv_membership->payment_type);
                    ?>
						<tr class="<?php 
                    echo esc_attr(implode(' ', $inv_classes));
                    ?>
">
							<td class="ms-col-invoice-no"><?php 
                    printf('<a href="%s">%s</a>', get_permalink($invoice->id), $invoice->get_invoice_number());
                    ?>
</td>
							<td class="ms-col-invoice-status"><?php 
                    echo esc_html($invoice->status_text());
                    ?>
</td>
							<td class="ms-col-invoice-total"><?php 
                    echo esc_html(MS_Helper_Billing::format_price($invoice->total));
                    ?>
</td>
							<td class="ms-col-invoice-title"><?php 
                    echo esc_html($inv_membership->name);
                    ?>
</td>
							<td class="ms-col-invoice-due"><?php 
                    echo esc_html(MS_Helper_Period::format_date($invoice->due_date, __('F j', 'membership2')));
                    ?>
</td>
						</tr>
					<?php 
                }
                ?>
					</tbody>
				</table>
				<?php 
                /**
                 * Add custom content right after the invoices overview list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_invoices_bottom', $member, $this);
                ?>
				</div>
				<?php 
            }
            // END: if ( $show_invoices )
            // =============================================================
            ?>

				<?php 
            // ==================================================== ACTIVITY
            if ($show_activity) {
                ?>
				<div id="account-activity">
				<h2>
					<?php 
                echo $activity_title;
                if ($show_all_activities) {
                    $detail_url = esc_url_raw(add_query_arg(array('action' => MS_Controller_Frontend::ACTION_VIEW_ACTIVITIES)));
                    printf('<a href="%s" class="ms-all-activities">%s</a>', $detail_url, $activity_details_label);
                }
                ?>
				</h2>
				<?php 
                /**
                 * Add custom content right before the activities overview list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_activity_top', $member, $this);
                ?>
				<table>
					<thead>
						<tr>
							<th class="ms-col-activity-date"><?php 
                _e('Date', 'membership2');
                ?>
</th>
							<th class="ms-col-activity-title"><?php 
                _e('Activity', 'membership2');
                ?>
</th>
						</tr>
					</thead>
					<tbody>
					<?php 
                foreach ($this->data['events'] as $event) {
                    $ev_classes = array('ms-activity-topic-' . $event->topic, 'ms-activity-type-' . $event->type, 'ms-membership-' . $event->membership_id);
                    ?>
						<tr class="<?php 
                    echo esc_attr(implode(' ', $ev_classes));
                    ?>
">
							<td class="ms-col-activity-date"><?php 
                    echo esc_html(MS_Helper_Period::format_date($event->post_modified));
                    ?>
</td>
							<td class="ms-col-activity-title"><?php 
                    echo esc_html($event->description);
                    ?>
</td>
						</tr>
					<?php 
                }
                ?>
					</tbody>
				</table>
				<?php 
                /**
                 * Add custom content right after the activities overview list.
                 *
                 * @since  1.0.0
                 */
                do_action('ms_view_account_activity_bottom', $member, $this);
                ?>
				</div>
				<?php 
            }
            // END: if ( $show_activity )
            // =============================================================
            ?>

			<?php 
        } else {
            $has_login_form = MS_Helper_Shortcode::has_shortcode(MS_Helper_Shortcode::SCODE_LOGIN, $post->post_content);
            if (!$has_login_form) {
                $redirect = esc_url_raw(add_query_arg(array()));
                $title = __('Your account', 'membership2');
                $scode = sprintf('[%1$s redirect="%2$s" title="%3$s"]', MS_Helper_Shortcode::SCODE_LOGIN, esc_url($redirect), esc_attr($title));
                echo do_shortcode($scode);
            }
        }
        ?>
		</div>
		<?php 
        $html = ob_get_clean();
        $html = apply_filters('ms_compact_code', $html);
        return apply_filters('ms_shortcode_account', $html, $this->data);
    }
    /**
     * Returns the HTML code for the Purchase-Membership form.
     *
     * @since  1.0.0
     * @return string
     */
    public function to_html()
    {
        $membership = $this->data['membership'];
        $invoice = $this->data['invoice'];
        $subscription = $this->data['ms_relationship'];
        $class = 'ms-alert-success';
        $msg = __('Please check the details of the membership below and click ' . 'on the relevant button to complete the signup.', 'membership2');
        if (!empty($this->data['error'])) {
            $class = 'ms-alert-error';
            $msg = $this->data['error'];
        }
        /**
         * Log the users IP and current timestamp inside the invoice.
         *
         * @since 1.0.2.0
         */
        $invoice->checkout_ip = lib3()->net->current_ip()->ip;
        $invoice->checkout_date = date('Y-m-d H:i:s');
        $invoice->save();
        $cancel_warning = false;
        if (!MS_Model_Member::is_admin_user()) {
            if (!MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS)) {
                // Member can only sign up to one membership.
                $valid_status = array(MS_Model_Relationship::STATUS_TRIAL, MS_Model_Relationship::STATUS_ACTIVE, MS_Model_Relationship::STATUS_PENDING);
                foreach ($this->data['member']->subscriptions as $tmp_subscription) {
                    if ($tmp_subscription->is_system()) {
                        continue;
                    }
                    if (in_array($tmp_subscription->status, $valid_status)) {
                        $cancel_warning = __('Your other Memberships will be cancelled when you complete this payment.', 'membership2');
                        break;
                    }
                }
            } elseif ($subscription->move_from_id) {
                $move_from_ids = explode(',', $subscription->move_from_id);
                $names = array();
                foreach ($move_from_ids as $id) {
                    $ms = MS_Factory::load('MS_Model_Membership', $id);
                    if ($ms->is_system()) {
                        continue;
                    }
                    $names[] = $ms->name;
                }
                if (1 == count($names)) {
                    $cancel_warning = sprintf(__('When you complete this payment your Membership "%s" will be cancelled.', 'membership2'), $names[0]);
                } elseif (1 < count($names)) {
                    $cancel_warning = sprintf(__('When you complete this payment the following Memberships will be cancelled: %s.', 'membership2'), implode(', ', $names));
                }
            }
        }
        // Check if the user goes through a trial period before first payment.
        $is_trial = $invoice->uses_trial;
        $skip_form = !MS_Model_Member::is_admin_user() && !$cancel_warning && $membership->is_free();
        /**
         * Filter the flag to allow Add-ons like "Invitation codes" to override
         * the state and force the form to display.
         *
         * @var bool
         */
        $skip_form = apply_filters('ms_view_frontend_payment_skip_form', $skip_form, $invoice, $this);
        if ($skip_form) {
            // No confirmation required. Simply register for this membership!
            $args = array();
            $args['ms_relationship_id'] = $subscription->id;
            $args['gateway'] = MS_Gateway_Free::ID;
            $args['step'] = MS_Controller_Frontend::STEP_PROCESS_PURCHASE;
            $args['_wpnonce'] = wp_create_nonce($args['gateway'] . '_' . $args['ms_relationship_id']);
            $url = esc_url_raw(add_query_arg($args));
            /*
             * Very likely the html output has already began.
             * So we redirect by using javascript.
             */
            ?>
			<script>window.location.href = '<?php 
            echo $url;
            ?>
';</script>
			<?php 
            exit;
        }
        $show_tax = MS_Model_Addon::is_enabled(MS_Addon_Taxamo::ID);
        /**
         * Trigger an action before the payment form is displayed. This hook
         * can be used by Add-ons or plugins to initialize payment settings or
         * add custom code.
         */
        do_action('ms_view_frontend_payment_form_start', $invoice, $this);
        $classes = array('ms-membership-form-wrapper', 'ms-subscription-' . $subscription->id, 'ms-invoice-' . $invoice->id);
        ob_start();
        ?>
		<div class="<?php 
        echo esc_attr(implode(' ', $classes));
        ?>
">
			<legend><?php 
        _e('Join Membership', 'membership2');
        ?>
</legend>
			<p class="ms-alert-box <?php 
        echo esc_attr($class);
        ?>
">
				<?php 
        echo $msg;
        ?>
			</p>
			<table class="ms-purchase-table">
				<tr>
					<td class="ms-title-column">
						<?php 
        _e('Name', 'membership2');
        ?>
					</td>
					<td class="ms-details-column">
						<?php 
        echo esc_html($membership->name);
        ?>
					</td>
				</tr>

				<?php 
        if ($membership->description) {
            ?>
					<tr>
						<td class="ms-title-column">
							<?php 
            _e('Description', 'membership2');
            ?>
						</td>
						<td class="ms-desc-column">
							<span class="ms-membership-description"><?php 
            echo $membership->get_description();
            ?>
</span>
						</td>
					</tr>
				<?php 
        }
        ?>

				<?php 
        if (!$membership->is_free()) {
            ?>
					<?php 
            if ($invoice->discount || $invoice->pro_rate || $invoice->tax_rate) {
                ?>
					<tr>
						<td class="ms-title-column">
							<?php 
                _e('Price', 'membership2');
                ?>
						</td>
						<td class="ms-details-column">
							<?php 
                if ($membership->price > 0) {
                    printf('<span class="price">%s %s</span>', $invoice->currency, MS_Helper_Billing::format_price($membership->price));
                } else {
                    _e('Free', 'membership2');
                }
                ?>
						</td>
					</tr>
					<?php 
            }
            ?>

					<?php 
            if ($invoice->discount) {
                ?>
						<tr>
							<td class="ms-title-column">
								<?php 
                _e('Coupon Discount', 'membership2');
                ?>
							</td>
							<td class="ms-price-column">
								<?php 
                printf('%s -%s', $invoice->currency, MS_Helper_Billing::format_price($invoice->discount));
                ?>
							</td>
						</tr>
					<?php 
            }
            ?>

					<?php 
            if ($invoice->pro_rate) {
                ?>
						<tr>
							<td class="ms-title-column">
								<?php 
                _e('Pro-Rate Discount', 'membership2');
                ?>
							</td>
							<td class="ms-price-column">
								<?php 
                printf('%s -%s', $invoice->currency, MS_Helper_Billing::format_price($invoice->pro_rate));
                ?>
							</td>
						</tr>
					<?php 
            }
            ?>

					<?php 
            if ($show_tax) {
                ?>
						<tr>
							<td class="ms-title-column">
								<?php 
                printf(__('Taxes %s', 'membership2'), '<a href="#" class="ms-tax-editor"><small>(' . $invoice->tax_name . ')</small></a>');
                ?>
							</td>
							<td class="ms-price-column">
								<?php 
                printf('%s %s', $invoice->currency, MS_Helper_Billing::format_price($invoice->tax));
                ?>
							</td>
						</tr>
					<?php 
            }
            ?>

					<tr>
						<td class="ms-title-column">
							<?php 
            _e('Total', 'membership2');
            ?>
						</td>
						<td class="ms-price-column ms-total">
							<?php 
            if ($invoice->total > 0) {
                printf('<span class="price">%s %s</span>', $invoice->currency, MS_Helper_Billing::format_price($invoice->total));
            } else {
                _e('Free', 'membership2');
            }
            ?>
						</td>
					</tr>

					<?php 
            if ($is_trial) {
                ?>
						<tr>
							<td class="ms-title-column">
								<?php 
                _e('Payment due', 'membership2');
                ?>
							</td>
							<td class="ms-desc-column"><?php 
                echo MS_Helper_Period::format_date($invoice->due_date);
                ?>
</td>
						</tr>
						<tr>
							<td class="ms-title-column">
								<?php 
                _e('Trial price', 'membership2');
                ?>
							</td>
							<td class="ms-desc-column">
							<?php 
                if ($invoice->trial_price > 0) {
                    printf('<span class="price">%s %s</span>', $invoice->currency, MS_Helper_Billing::format_price($invoice->trial_price));
                } else {
                    _e('Free', 'membership2');
                }
                ?>
							</td>
						</tr>
					<?php 
            }
            ?>

					<?php 
            do_action('ms_view_frontend_payment_after_total_row', $subscription, $invoice, $this);
            ?>

					<tr>
						<td class="ms-desc-column" colspan="2">
							<span class="ms-membership-description"><?php 
            echo $subscription->get_payment_description($invoice);
            ?>
</span>
						</td>
					</tr>
				<?php 
        }
        ?>

				<?php 
        if ($cancel_warning) {
            ?>
					<tr>
						<td class="ms-desc-warning" colspan="2">
							<span class="ms-cancel-other-memberships"><?php 
            echo $cancel_warning;
            ?>
</span>
						</td>
					</tr>
				<?php 
        }
        if (MS_Model_Member::is_admin_user()) {
            ?>
					<tr>
						<td class="ms-desc-adminnote" colspan="2">
							<em><?php 
            _e('As admin user you already have access to this membership', 'membership2');
            ?>
</em>
						</td>
					</tr>
				<?php 
        } else {
            do_action('ms_view_frontend_payment_purchase_button', $subscription, $invoice, $this);
        }
        ?>
			</table>
		</div>
		<?php 
        do_action('ms_view_frontend_payment_after', $this->data, $this);
        do_action('ms_show_prices');
        if ($show_tax) {
            do_action('ms_tax_editor', $invoice);
        }
        ?>
		<div style="clear:both;"></div>
		<?php 
        $html = ob_get_clean();
        $html = apply_filters('ms_compact_code', $html);
        $html = apply_filters('ms_view_frontend_payment_form', $html, $this);
        return $html;
    }