/**
     * Returns the contens of the dialog
     *
     * @since  1.0.0
     *
     * @return object
     */
    public function get_contents($data)
    {
        $subscription = $data['model'];
        $gateways = MS_Model_Gateway::get_gateway_names(false, true);
        if (isset($gateways[$subscription->gateway_id])) {
            $gateway = $gateways[$subscription->gateway_id];
        } elseif (empty($subscription->gateway_id)) {
            $gateway = __('- No Gateway -', 'membership2');
        } else {
            $gateway = '(' . $subscription->gateway_id . ')';
        }
        $events = MS_Model_Event::get_events(array('topic' => 'membership', 'nopaging' => true, 'relationship_id' => $subscription->id));
        $sub_details = array('title' => __('Subscription Details', 'membership2'), 'type' => MS_Helper_Html::TYPE_HTML_TABLE, 'value' => array(array('Subscription ID', $subscription->id), array('Membership', $subscription->get_membership()->name), array('Payment Gateway', $gateway), array('Payment Type', $subscription->get_payment_description(null, true)), array('Subscription Start', $subscription->start_date), array('Subscription End', $subscription->expire_date), array('Status', $subscription->status)), 'field_options' => array('head_col' => true));
        $evt_details = array();
        foreach ($events as $event) {
            $evt_details[] = array('title' => __('Event Details', 'membership2'), 'type' => MS_Helper_Html::TYPE_HTML_TABLE, 'value' => array(array('Event ID', $event->id), array('Date', $event->date), array('Description', $event->description)), 'field_options' => array('head_col' => true));
        }
        ob_start();
        ?>
		<div>
			<?php 
        MS_Helper_Html::html_element($sub_details);
        MS_Helper_Html::html_separator();
        foreach ($evt_details as $detail) {
            MS_Helper_Html::html_element($detail);
        }
        ?>
		</div>
		<?php 
        $html = ob_get_clean();
        return apply_filters('ms_view_member_subscription_to_html', $html);
    }
    /**
     * Returns the contens of the dialog
     *
     * @since  1.0.0
     *
     * @return object
     */
    public function get_contents($data)
    {
        $subscription = $data['model'];
        $gateways = MS_Model_Gateway::get_gateway_names();
        $invoices = $subscription->get_invoices();
        $pay_details = array();
        $inv_details = array();
        foreach ($subscription->get_payments() as $payment) {
            if (isset($gateways[$payment['gateway']])) {
                $gateway = $gateways[$payment['gateway']];
            } else {
                $gateway = '(' . $payment['gateway'] . ')';
            }
            $pay_details[] = array('title' => __('Recorded Payment', 'membership2'), 'type' => MS_Helper_Html::TYPE_HTML_TABLE, 'value' => array(0 => array('Payment Date', $payment['date']), 1 => array('Payment Gateway', $gateway), 2 => array('Amount', $payment['amount']), 3 => array('External ID', $payment['external_id'])), 'field_options' => array('head_col' => true));
        }
        $invoice_list = array();
        foreach ($invoices as $invoice) {
            if (isset($gateways[$invoice->gateway_id])) {
                $gateway = $gateways[$invoice->gateway_id];
            } else {
                $gateway = '(' . $invoice->gateway_id . ')';
            }
            $transaction_log = sprintf(' <small>- <a href="%s" target="_blank">%s</a></small>', MS_Controller_Plugin::get_admin_url('billing', array('show' => 'logs', 'invoice' => $invoice->id)), __('Show Transaction', 'membership2'));
            $invoice_list[] = $invoice->id;
            $inv_details[$invoice->id] = array('title' => sprintf(__('Invoice %s', 'membership2'), $invoice->id), 'type' => MS_Helper_Html::TYPE_HTML_TABLE, 'value' => array(0 => array('Invoice ID', $invoice->id . $transaction_log), 2 => array('Create Date', $invoice->invoice_date), 1 => array('Payment Gateway', $gateway), 2 => array('Due Date', $invoice->due_date), 3 => array('Regular amount', $invoice->amount), 4 => array('Total billed', $invoice->total), 5 => array('Status', $invoice->status), 6 => array('Notes', $invoice->description), 7 => array('Checkout IP', $invoice->checkout_ip), 8 => array('Checkout Date', $invoice->checkout_date)), 'field_options' => array('head_col' => true));
            if ($invoice->amount == $invoice->total) {
                unset($inv_details[$invoice->id]['value'][3]);
                $inv_details[$invoice->id]['value'] = array_values($inv_details[$invoice->id]['value']);
            }
        }
        $transaction_url = MS_Controller_Plugin::get_admin_url('billing', array('show' => 'logs', 'invoice' => implode(',', $invoice_list)));
        $transaction_log = array('type' => MS_Helper_Html::TYPE_HTML_LINK, 'value' => __('Show all Transactions for this subscription', 'membership2'), 'url' => $transaction_url, 'target' => '_blank');
        ob_start();
        ?>
		<div class="wpmui-grid-8 ms-payment-infos">
			<div class="col-5">
				<?php 
        foreach ($inv_details as $detail) {
            MS_Helper_Html::html_element($detail);
        }
        ?>
			</div>
			<div class="col-3">
				<?php 
        MS_Helper_Html::html_element($transaction_log);
        MS_Helper_Html::html_separator();
        foreach ($pay_details as $detail) {
            MS_Helper_Html::html_element($detail);
        }
        ?>
			</div>
		</div>
		<?php 
        $html = ob_get_clean();
        return apply_filters('ms_view_member_payment_to_html', $html);
    }
    /**
     * Returns the contens of the dialog
     *
     * @since  1.0.0
     *
     * @return object
     */
    public function get_contents($data)
    {
        $subscription = $data['model'];
        $gateways = MS_Model_Gateway::get_gateway_names();
        $invoices = $subscription->get_invoices();
        $pay_details = array();
        $inv_details = array();
        foreach ($subscription->payments as $payment) {
            if (isset($gateways[$payment['gateway']])) {
                $gateway = $gateways[$payment['gateway']];
            } else {
                $gateway = '(' . $payment['gateway'] . ')';
            }
            $pay_details[] = array('title' => __('Recorded Payment', MS_TEXT_DOMAIN), 'type' => MS_Helper_Html::TYPE_HTML_TABLE, 'value' => array(0 => array('Payment Date', $payment['date']), 1 => array('Payment Gateway', $gateway), 2 => array('Amount', $payment['amount'])), 'field_options' => array('head_col' => true));
        }
        if (!empty($pay_details)) {
            $pay_details[] = array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR);
        }
        foreach ($invoices as $invoice) {
            if (isset($gateways[$invoice->gateway_id])) {
                $gateway = $gateways[$invoice->gateway_id];
            } else {
                $gateway = '(' . $invoice->gateway_id . ')';
            }
            $inv_details[$invoice->id] = array('title' => sprintf(__('Invoice %s', MS_TEXT_DOMAIN), $invoice->id), 'type' => MS_Helper_Html::TYPE_HTML_TABLE, 'value' => array(0 => array('Invoice ID', $invoice->id), 1 => array('Payment Gateway', $gateway), 2 => array('Due Date', $invoice->due_date), 3 => array('Regular amount', $invoice->amount), 4 => array('Total billed', $invoice->total), 5 => array('Status', $invoice->status), 6 => array('Notes', $invoice->description)), 'field_options' => array('head_col' => true));
            if ($invoice->amount == $invoice->total) {
                unset($inv_details[$invoice->id]['value'][3]);
                $inv_details[$invoice->id]['value'] = array_values($inv_details[$invoice->id]['value']);
            }
        }
        ob_start();
        ?>
		<div>
			<?php 
        foreach ($pay_details as $detail) {
            MS_Helper_Html::html_element($detail);
        }
        foreach ($inv_details as $detail) {
            MS_Helper_Html::html_element($detail);
        }
        ?>
		</div>
		<?php 
        $html = ob_get_clean();
        return apply_filters('ms_view_member_payment_to_html', $html);
    }
 /**
  * Input fields displayed in the "Edit Member" screen.
  *
  * @since  1.0.1.0
  * @return array
  */
 public function prepare_fields_edit()
 {
     $action_update = MS_Controller_Member::ACTION_UPDATE_MEMBER;
     $action_modify = MS_Controller_Member::ACTION_MODIFY_SUBSCRIPTIONS;
     $user_id = $this->data['user_id'];
     $user = MS_Factory::load('MS_Model_Member', $user_id);
     $unused_memberships = array();
     $temp_memberships = MS_Model_Membership::get_memberships(array('include_guest' => 0));
     foreach ($temp_memberships as $membership) {
         $unused_memberships[$membership->id] = $membership;
     }
     $fields = array();
     $fields['editor'] = array('title' => array('type' => MS_Helper_Html::TYPE_HTML_TEXT, 'class' => 'group-title', 'value' => __('Basic Profile details', MS_TEXT_DOMAIN)), 'username' => array('id' => 'username', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => __('Username', MS_TEXT_DOMAIN), 'value' => $user->username, 'class' => 'ms-text-medium', 'config' => array('disabled' => 'disabled')), 'email' => array('id' => 'email', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => __('Email', MS_TEXT_DOMAIN), 'value' => $user->email, 'class' => 'ms-text-medium'), 'first_name' => array('id' => 'first_name', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => __('First Name', MS_TEXT_DOMAIN), 'value' => $user->first_name, 'class' => 'ms-text-medium'), 'last_name' => array('id' => 'last_name', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => __('Last Name', MS_TEXT_DOMAIN), 'value' => $user->last_name, 'class' => 'ms-text-medium'), 'displayname' => array('id' => 'displayname', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => __('Display Name', MS_TEXT_DOMAIN), 'value' => $user->get_user()->display_name, 'class' => 'ms-text-medium'), 'sep' => array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR), 'user_id' => array('id' => 'user_id', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $user->id), 'button' => array('id' => 'btn_save', 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT, 'value' => __('Save', MS_TEXT_DOMAIN)), 'profile' => array('id' => 'user_profile', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'value' => __('Full User Profile', MS_TEXT_DOMAIN) . ' &raquo;', 'url' => admin_url('user-edit.php?user_id=' . $user->id), 'class' => 'button wpmui-field-input'), 'action' => array('id' => 'action', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $action_update), '_wpnonce' => array('id' => '_wpnonce', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => wp_create_nonce($action_update)));
     $fields['subscriptions'] = array();
     // Section: Edit existing subscriptions.
     $fields['subscriptions'][] = array('type' => MS_Helper_Html::TYPE_HTML_TEXT, 'class' => 'group-title', 'value' => __('Manage Subscriptions', MS_TEXT_DOMAIN));
     if ($user->subscriptions) {
         $gateways = MS_Model_Gateway::get_gateway_names(false, true);
         foreach ($user->subscriptions as $subscription) {
             if (MS_Model_Relationship::STATUS_DEACTIVATED == $subscription->status) {
                 continue;
             }
             $the_membership = $subscription->get_membership();
             unset($unused_memberships[$the_membership->id]);
             $status_options = array(MS_Model_Relationship::STATUS_PENDING => __('Pending (activate on next payment)', MS_TEXT_DOMAIN), MS_Model_Relationship::STATUS_WAITING => __('Waiting (activate on start date)', MS_TEXT_DOMAIN), MS_Model_Relationship::STATUS_TRIAL => __('Trial Active', MS_TEXT_DOMAIN), MS_Model_Relationship::STATUS_ACTIVE => __('Active', MS_TEXT_DOMAIN), MS_Model_Relationship::STATUS_CANCELED => __('Cancelled (deactivate on expire date)', MS_TEXT_DOMAIN), MS_Model_Relationship::STATUS_TRIAL_EXPIRED => __('Trial Expired (activate on next payment)', MS_TEXT_DOMAIN), MS_Model_Relationship::STATUS_EXPIRED => __('Expired (no access) ', MS_TEXT_DOMAIN), MS_Model_Relationship::STATUS_DEACTIVATED => __('Deactivated (no access)', MS_TEXT_DOMAIN));
             if (!$the_membership->has_trial()) {
                 unset($status_options[MS_Model_Relationship::STATUS_TRIAL]);
                 unset($status_options[MS_Model_Relationship::STATUS_TRIAL_EXPIRED]);
             }
             if (isset($gateways[$subscription->gateway_id])) {
                 $gateway_name = $gateways[$subscription->gateway_id];
             } elseif (empty($subscription->gateway_id)) {
                 $gateway_name = __('- No Gateway -', MS_TEXT_DOMAIN);
             } else {
                 $gateway_name = '(' . $subscription->gateway_id . ')';
             }
             $field_start = array('name' => 'mem_' . $the_membership->id . '[start]', 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER, 'value' => $subscription->start_date);
             $field_expire = array('name' => 'mem_' . $the_membership->id . '[expire]', 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER, 'value' => $subscription->expire_date);
             $field_status = array('name' => 'mem_' . $the_membership->id . '[status]', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $subscription->status, 'field_options' => $status_options);
             $fields['subscriptions'][] = array('name' => 'memberships[]', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $the_membership->id);
             $fields['subscriptions'][] = array('title' => $the_membership->get_name_tag(), 'type' => MS_Helper_Html::TYPE_HTML_TABLE, 'value' => array(array(__('Subscription ID', MS_TEXT_DOMAIN), $subscription->id), array(__('Payment Gateway', MS_TEXT_DOMAIN), $gateway_name), array(__('Payment Type', MS_TEXT_DOMAIN), $subscription->get_payment_description(null, true)), array(__('Start Date', MS_TEXT_DOMAIN) . ' <sup>*)</sup>', MS_Helper_Html::html_element($field_start, true)), array(__('Expire Date', MS_TEXT_DOMAIN) . ' <sup>*)</sup>', MS_Helper_Html::html_element($field_expire, true)), array(__('Status', MS_TEXT_DOMAIN) . ' <sup>*)</sup>', MS_Helper_Html::html_element($field_status, true))), 'field_options' => array('head_col' => true));
         }
     } else {
         $fields['subscriptions'][] = array('type' => MS_Helper_Html::TYPE_HTML_TEXT, 'value' => __('This user does not have any subscriptions yet.', MS_TEXT_DOMAIN));
     }
     // Section: Add new subscription.
     if (count($unused_memberships)) {
         $options = array();
         if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS)) {
             $field_type = MS_Helper_Html::INPUT_TYPE_CHECKBOX;
             $group_title = __('Add Subscriptions', MS_TEXT_DOMAIN);
         } else {
             $field_type = MS_Helper_Html::INPUT_TYPE_RADIO;
             $group_title = __('Set Subscription', MS_TEXT_DOMAIN);
         }
         $fields['subscriptions'][] = array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR);
         $fields['subscriptions'][] = array('type' => MS_Helper_Html::TYPE_HTML_TEXT, 'class' => 'group-title', 'value' => $group_title);
         foreach ($unused_memberships as $the_membership) {
             $options[$the_membership->id] = $the_membership->get_name_tag();
         }
         $fields['subscriptions'][] = array('id' => 'subscribe', 'type' => $field_type, 'field_options' => $options);
         $fields['subscriptions'][] = array('id' => 'user_id', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $user->id);
     }
     if ($user->subscriptions) {
         $fields['subscriptions'][] = array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR);
         $fields['subscriptions'][] = array('type' => MS_Helper_Html::TYPE_HTML_TEXT, 'value' => '<sup>*)</sup> ' . __('Subscription Dates and Status are validated when saved and might result in a different value then the one specified above.', MS_TEXT_DOMAIN), 'class' => 'info-field');
     }
     $fields['subscriptions'][] = array('id' => 'btn_modify', 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT, 'value' => __('Save Changes', MS_TEXT_DOMAIN));
     $fields['subscriptions'][] = array('id' => 'history', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'value' => '<i class="dashicons dashicons-id"></i>' . __('History and logs', MS_TEXT_DOMAIN), 'url' => '#history', 'class' => 'button wpmui-field-input', 'config' => array('data-ms-dialog' => 'View_Member_Dialog', 'data-ms-data' => array('member_id' => $user->id)));
     $fields['subscriptions'][] = array('id' => 'action', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $action_modify);
     $fields['subscriptions'][] = array('id' => '_wpnonce', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => wp_create_nonce($action_modify));
     return apply_filters('ms_view_member_editor_fields_edit', $fields);
 }