function foxyshop_display_ajax()
{
    global $wpdb, $foxyshop_settings;
    check_ajax_referer('foxyshop-display-list-function', 'security');
    if (!isset($_POST['foxyshop_action'])) {
        die;
    }
    $id = isset($_POST['id']) ? $_POST['id'] : 0;
    $transaction_template_id = isset($_POST['transaction_template_id']) ? (int) $_POST['transaction_template_id'] : 0;
    //Change Subscription
    if ($_POST['foxyshop_action'] == 'subscription_modify') {
        $foxy_data = array("api_action" => "subscription_modify", "sub_token" => $_POST['sub_token'], "start_date" => $_POST['start_date'], "frequency" => $_POST['frequency'], "past_due_amount" => $_POST['past_due_amount'], "is_active" => $_POST['is_active']);
        if ($_POST['end_date'] == "0000-00-00" || strtotime($_POST['end_date']) > strtotime("now")) {
            $foxy_data['end_date'] = $_POST['end_date'];
        }
        if (strtotime($_POST['next_transaction_date']) > strtotime("now")) {
            $foxy_data['next_transaction_date'] = $_POST['next_transaction_date'];
        }
        if ($transaction_template_id) {
            $foxy_data['transaction_template'] = foxyshop_subscription_template($transaction_template_id);
        }
        $foxy_response = foxyshop_get_foxycart_data($foxy_data);
        $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
        do_action("foxyshop_after_subscription_modify", $xml);
        echo (string) $xml->result . ": " . (string) $xml->messages->message;
        die;
        //Hide/Unhide Transaction
    } elseif ($_POST['foxyshop_action'] == 'hide_transaction') {
        $foxy_data = array("api_action" => "transaction_modify", "transaction_id" => $id, "hide_transaction" => (int) $_POST['hide_transaction']);
        $foxy_response = foxyshop_get_foxycart_data($foxy_data);
        $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
        do_action("foxyshop_after_transaction_archive", $xml);
        echo (string) $xml->result . ": " . (string) $xml->messages->message;
        die;
    }
    die;
}
function foxyshop_delete_attribute($att_type, $id, $att_name)
{
    $foxy_data = array("api_action" => "attribute_delete", "name" => $att_name, "type" => $att_type, "identifier" => $id);
    $foxy_response = foxyshop_get_foxycart_data($foxy_data);
    $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
    return (string) $xml->result . ": " . (string) $xml->messages->message;
}
function foxyshop_subscription_management()
{
    global $foxyshop_settings, $wp_version, $product;
    //Setup Fields and Defaults
    $foxy_data_defaults = array("is_active_filter" => "", "frequency_filter" => "", "past_due_amount_filter" => "", "start_date_filter_begin" => date("Y-m-d", strtotime("-10 days")), "start_date_filter_end" => date("Y-m-d"), "next_transaction_date_filter_begin" => "", "next_transaction_date_filter_end" => "", "end_date_filter_begin" => "", "end_date_filter_end" => "", "third_party_id_filter" => "", "last_transaction_id_filter" => "", "customer_id_filter" => "", "customer_email_filter" => "", "customer_first_name_filter" => "", "customer_last_name_filter" => "", "product_code_filter" => "", "product_name_filter" => "", "product_option_name_filter" => "", "product_option_value_filter" => "");
    if (version_compare($foxyshop_settings['version'], '0.7.2', ">=")) {
        $foxy_data_defaults["custom_field_name_filter"] = "";
        $foxy_data_defaults["custom_field_value_filter"] = "";
    }
    $foxy_data = wp_parse_args(array("api_action" => "subscription_list"), apply_filters('foxyshop_subscription_filter_defaults', $foxy_data_defaults));
    $foxyshop_querystring = "?post_type=foxyshop_product&page=foxyshop_subscription_management&foxyshop_search=1";
    $foxyshop_hidden_input = "";
    if (isset($_GET['foxyshop_search']) || !defined('FOXYSHOP_AUTO_API_DISABLED')) {
        $fields = array("is_active_filter", "frequency_filter", "past_due_amount_filter", "start_date_filter_begin", "start_date_filter_end", "next_transaction_date_filter_begin", "next_transaction_date_filter_end", "end_date_filter_begin", "end_date_filter_end", "third_party_id_filter", "last_transaction_id_filter", "customer_id_filter", "customer_email_filter", "customer_first_name_filter", "customer_last_name_filter", "product_code_filter", "product_name_filter", "product_option_name_filter", "product_option_value_filter", "custom_field_name_filter", "custom_field_value_filter");
        foreach ($fields as $field) {
            if (isset($_GET[$field])) {
                $foxy_data[$field] = $_GET[$field];
                $foxyshop_querystring .= "&{$field}=" . urlencode($_GET[$field]);
                $foxyshop_hidden_input .= '<input type="hidden" name="' . $field . '" value="' . htmlspecialchars($_GET[$field]) . '" />' . "\n";
            }
        }
        $foxy_data['pagination_start'] = isset($_GET['pagination_start']) ? $_GET['pagination_start'] : 0;
        $p = (int) (version_compare($foxyshop_settings['version'], '0.7.1', "<") ? 50 : FOXYSHOP_API_ENTRIES_PER_PAGE);
        if (version_compare($foxyshop_settings['version'], '0.7.0', ">")) {
            $foxy_data['entries_per_page'] = $p;
        }
        $start_offset = (int) (version_compare($foxyshop_settings['version'], '0.7.1', "<=") ? -1 : 0);
        if (isset($_GET['paged-top']) || isset($_GET['paged-bottom'])) {
            if ($_GET['paged-top'] != $_GET['paged-top-original']) {
                $foxy_data['pagination_start'] = $p * ((int) $_GET['paged-top'] - 1) + 1 + $start_offset;
            }
            if ($_GET['paged-bottom'] != $_GET['paged-bottom-original']) {
                $foxy_data['pagination_start'] = $p * ((int) $_GET['paged-bottom'] - 1) + 1 + $start_offset;
            }
        }
    }
    $subscription_products = get_posts(array('post_type' => 'foxyshop_product', "meta_key" => "_sub_frequency", "meta_value" => "", 'meta_compare' => '!=', "_sub_frequency", 'numberposts' => -1));
    $subscription_product_array = array();
    foreach ($subscription_products as $subscription_product) {
        $product = foxyshop_setup_product($subscription_product);
        $subscription_product_array[] = array("id" => $product['id'], "name" => $product['name'], "price" => $product['price']);
    }
    ?>

	<div class="wrap">
		<div class="icon32 icon32-posts-page" id="icon-edit-pages"><br></div>
		<h2><?php 
    _e('Manage Subscriptions', 'foxyshop');
    ?>
</h2>

		<form action="edit.php" method="get" id="foxyshop_searchform" name="foxyshop_searchform" style="display: block; margin: 14px 0 20px 0;">
		<input type="hidden" name="foxyshop_search" value="1" />
		<input type="hidden" name="post_type" value="foxyshop_product" />
		<input type="hidden" name="page" value="foxyshop_subscription_management" />

		<table class="widefat">
		<thead><tr><th colspan="2"><img src="<?php 
    echo FOXYSHOP_DIR;
    ?>
/images/search-icon.png" alt="" /><?php 
    _e('Search Options', 'foxyshop');
    ?>
</th></tr></thead>
		<tbody><tr><td>
			<div class="foxyshop_field_control">
				<label for="is_active_filter"><?php 
    _e('Subscription Type', 'foxyshop');
    ?>
</label>
				<select name="is_active_filter" id="is_active_filter">
				<?php 
    $selectArray = array("0" => __("Disabled", 'foxyshop'), "1" => __("Active", 'foxyshop'), "" => __("Both", 'foxyshop'));
    foreach ($selectArray as $selectKey => $selectOption) {
        echo '<option value="' . $selectKey . '"' . ($foxy_data['is_active_filter'] == $selectKey ? ' selected="selected"' : '') . '>' . $selectOption . '</option>' . "\n";
    }
    ?>
				</select>
			</div>
			<div class="foxyshop_field_control">
				<label for="past_due_amount_filter"><?php 
    _e('Past Due Status', 'foxyshop');
    ?>
</label>
				<select name="past_due_amount_filter" id="past_due_amount_filter">
				<?php 
    $selectArray = array("" => __('Show All', 'foxyshop'), "1" => __('Show Past Due Only', 'foxyshop'));
    foreach ($selectArray as $selectKey => $selectOption) {
        echo '<option value="' . $selectKey . '"' . ($foxy_data['past_due_amount_filter'] == $selectKey ? ' selected="selected"' : '') . '>' . $selectOption . '</option>' . "\n";
    }
    ?>
				</select>
			</div>
			<div class="foxyshop_field_control">
				<label for="frequency_filter"><?php 
    _e('Frequency', 'foxyshop');
    ?>
</label><input type="text" name="frequency_filter" id="frequency_filter" value="<?php 
    echo $foxy_data['frequency_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="third_party_id_filter"><?php 
    _e('Third Party ID', 'foxyshop');
    ?>
</label><input type="text" name="third_party_id_filter" id="third_party_id_filter" value="<?php 
    echo $foxy_data['third_party_id_filter'];
    ?>
" />
				<span>PayPal</span>
			</div>
			<div class="foxyshop_field_control">
				<label for="last_transaction_id_filter"><?php 
    _e('Last Transaction ID', 'foxyshop');
    ?>
</label><input type="text" name="last_transaction_id_filter" id="last_transaction_id_filter" value="<?php 
    echo $foxy_data['last_transaction_id_filter'];
    ?>
" />
			</div>

			<div class="foxyshop_field_control">
				<label for="product_code_filter"><?php 
    echo FOXYSHOP_PRODUCT_NAME_SINGULAR . ' ' . __('Code', 'foxyshop');
    ?>
</label><input type="text" name="product_code_filter" id="product_code_filter" value="<?php 
    echo $foxy_data['product_code_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="product_name_filter"><?php 
    echo FOXYSHOP_PRODUCT_NAME_SINGULAR . ' ' . __('Name', 'foxyshop');
    ?>
</label><input type="text" name="product_name_filter" id="product_name_filter" value="<?php 
    echo $foxy_data['product_name_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="product_option_name_filter"><?php 
    echo FOXYSHOP_PRODUCT_NAME_SINGULAR . ' ' . __('Option Name', 'foxyshop');
    ?>
</label><input type="text" name="product_option_name_filter" id="product_option_name_filter" value="<?php 
    echo $foxy_data['product_option_name_filter'];
    ?>
" />
				<label for="product_option_value_filter" style="margin-left: 15px; margin-top: 4px; width: 38px;"><?php 
    _e('Value', 'foxyshop');
    ?>
</label><input type="text" name="product_option_value_filter" id="product_option_value_filter" value="<?php 
    echo $foxy_data['product_option_value_filter'];
    ?>
" />
			</div>
			<?php 
    if (version_compare($foxyshop_settings['version'], '0.7.2', ">=")) {
        ?>
			<div class="foxyshop_field_control">
				<label for="custom_field_name_filter"><?php 
        _e('Custom Field Name', 'foxyshop');
        ?>
</label><input type="text" name="custom_field_name_filter" id="custom_field_name_filter" value="<?php 
        echo $foxy_data['custom_field_name_filter'];
        ?>
" />
				<label for="custom_field_value_filter" style="margin-left: 15px; margin-top: 4px; width: 38px;"><?php 
        _e('Value', 'foxyshop');
        ?>
</label><input type="text" name="custom_field_value_filter" id="custom_field_value_filter" value="<?php 
        echo $foxy_data['custom_field_value_filter'];
        ?>
" />
			</div>
			<?php 
    }
    ?>

		</td><td>

			<div class="foxyshop_field_control">
				<label for="start_date_filter_begin"><?php 
    _e('Start Date', 'foxyshop');
    ?>
</label>
				<input type="text" name="start_date_filter_begin" id="start_date_filter_begin" value="<?php 
    echo $foxy_data['start_date_filter_begin'];
    ?>
" class="foxyshop_date_field" />
				<span><?php 
    _e('to', 'foxyshop');
    ?>
</span>
				<input type="text" name="start_date_filter_end" id="start_date_filter_end" value="<?php 
    echo $foxy_data['start_date_filter_end'];
    ?>
" class="foxyshop_date_field" />
			</div>
			<div class="foxyshop_field_control">
				<label for="next_transaction_date_filter_begin"><?php 
    _e('Next Transaction Date', 'foxyshop');
    ?>
</label>
				<input type="text" name="next_transaction_date_filter_begin" id="next_transaction_date_filter_begin" value="<?php 
    echo $foxy_data['next_transaction_date_filter_begin'];
    ?>
" class="foxyshop_date_field" />
				<span><?php 
    _e('to', 'foxyshop');
    ?>
</span>
				<input type="text" name="next_transaction_date_filter_end" id="next_transaction_date_filter_end" value="<?php 
    echo $foxy_data['next_transaction_date_filter_end'];
    ?>
" class="foxyshop_date_field" />
			</div>
			<div class="foxyshop_field_control">
				<label for="end_date_filter_begin"><?php 
    _e('End Date', 'foxyshop');
    ?>
</label>
				<input type="text" name="end_date_filter_begin" id="end_date_filter_begin" value="<?php 
    echo $foxy_data['end_date_filter_begin'];
    ?>
" class="foxyshop_date_field" />
				<span><?php 
    _e('to', 'foxyshop');
    ?>
</span>
				<input type="text" name="end_date_filter_end" id="end_date_filter_end" value="<?php 
    echo $foxy_data['end_date_filter_end'];
    ?>
" class="foxyshop_date_field" />
			</div>

			<div class="foxyshop_field_control">
				<label for="customer_id_filter"><?php 
    _e('Customer ID', 'foxyshop');
    ?>
</label><input type="text" name="customer_id_filter" id="customer_id_filter" value="<?php 
    echo $foxy_data['customer_id_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_email_filter"><?php 
    _e('Customer Email', 'foxyshop');
    ?>
</label><input type="text" name="customer_email_filter" id="customer_email_filter" value="<?php 
    echo $foxy_data['customer_email_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_first_name_filter"><?php 
    _e('Customer First Name', 'foxyshop');
    ?>
</label><input type="text" name="customer_first_name_filter" id="customer_first_name_filter" value="<?php 
    echo $foxy_data['customer_first_name_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_last_name_filter"><?php 
    _e('Customer Last Name', 'foxyshop');
    ?>
</label><input type="text" name="customer_last_name_filter" id="customer_last_name_filter" value="<?php 
    echo $foxy_data['customer_last_name_filter'];
    ?>
" />
			</div>

			<div style="clear: both;"></div>
			<button type="submit" id="foxyshop_search_submit" name="foxyshop_search_submit" class="button-primary" style="clear: both; margin-top: 10px;"><?php 
    _e('Search Records Now', 'foxyshop');
    ?>
</button>
			<button type="button" class="button" style="margin-left: 15px; margin-top: 10px;" onclick="document.location.href = 'edit.php?post_type=foxyshop_product&page=foxyshop_subscription_management';"><?php 
    _e('Reset Form', 'foxyshop');
    ?>
</button>

		</td></tr></tbody></table>


		</form>
		<script type="text/javascript" charset="utf-8">
		jQuery(document).ready(function($) {
			$(".foxyshop_date_field").datepicker({ dateFormat: 'yy-mm-dd' });
		});
		</script>

	<?php 
    if (!isset($_GET['foxyshop_search']) && defined('FOXYSHOP_AUTO_API_DISABLED')) {
        return;
    }
    $foxy_response = foxyshop_get_foxycart_data($foxy_data);
    $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
    if ((string) $xml->result == __('ERROR', 'foxyshop')) {
        echo '<h3>' . (string) $xml->messages->message . '</h3>';
        return;
    } else {
        ?>



		<form action="edit.php" method="get">
		<input type="hidden" name="foxyshop_search" value="1" />
		<input type="hidden" name="post_type" value="foxyshop_product" />
		<input type="hidden" name="page" value="foxyshop_subscription_management" />

		<?php 
        echo $foxyshop_hidden_input;
        foxyshop_api_paging_nav('subscriptions', 'top', $xml, $foxyshop_querystring);
        ?>

		<table cellpadding="0" cellspacing="0" border="0" class="wp-list-table widefat foxyshop-list-table" id="subscription_table">
			<thead>
				<tr>
					<th><span><?php 
        _e('Customer', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Start Date', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Next Date', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('End Date', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Past Due', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Details', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Frequency', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<th><?php 
        _e('Customer', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('Start Date', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('Next Date', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('End Date', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('Past Due', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('Details', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('Frequency', 'foxyshop');
        ?>
</th>
				</tr>
			</tfoot>
			<tbody id="the-list">

		<?php 
        $holder = "";
        foreach ($xml->subscriptions->subscription as $subscription) {
            $sub_token = (string) $subscription->sub_token;
            $customer_id = (string) $subscription->customer_id;
            $customer_first_name = (string) $subscription->customer_first_name;
            $customer_last_name = (string) $subscription->customer_last_name;
            $start_date = (string) $subscription->start_date;
            $next_transaction_date = (string) $subscription->next_transaction_date;
            $end_date = (string) $subscription->end_date;
            $frequency = (string) $subscription->frequency;
            $past_due_amount = (string) $subscription->past_due_amount;
            $is_active = (string) $subscription->is_active;
            $product_name = "";
            if (version_compare($foxyshop_settings['version'], '0.7.0', ">")) {
                foreach ($subscription->transaction_template->transaction_details->transaction_detail as $transaction_detail) {
                    if ($product_name) {
                        $product_name .= "<br />";
                    }
                    $product_price = (double) $transaction_detail->product_price;
                    foreach ($transaction_detail->transaction_detail_options->transaction_detail_option as $transaction_detail_option) {
                        $product_price += (double) $transaction_detail_option->price_mod;
                    }
                    $product_name .= (string) $transaction_detail->product_name . ' ' . foxyshop_currency($product_price);
                }
            } else {
                // The 0.7.0 code had an extra transaction_template node which was removed in subsequent versions
                foreach ($subscription->transaction_template->transaction_template->transaction_details->transaction_detail as $transaction_detail) {
                    if ($product_name) {
                        $product_name .= "<br />";
                    }
                    $product_price = (double) $transaction_detail->product_price;
                    foreach ($transaction_detail->transaction_detail_options->transaction_detail_option as $transaction_detail_option) {
                        $product_price += (double) $transaction_detail_option->price_mod;
                    }
                    $product_name .= (string) $transaction_detail->product_name . ' ' . foxyshop_currency($product_price);
                }
            }
            if ($customer_first_name != "") {
                $customer_name = $customer_last_name . ', ' . $customer_first_name;
            } else {
                $customer_name = $customer_id;
            }
            echo '<tr rel="' . $sub_token . '">';
            echo '<td class="customer_name">';
            echo '<strong' . ($is_active == "0" ? ' class="strikethrough"' : '') . '><a href="#" class="view_detail">' . $customer_name . '</a></strong>';
            echo '<div class="row-actions">';
            echo '<span class="edit"><a title="' . __('Edit') . '" href="#" class="view_detail">' . __('Edit') . '</a> | </span>';
            echo '<span class="view_customer"><a href="edit.php?post_type=foxyshop_product&page=foxyshop_customer_management&customer_id_filter=' . $customer_id . '&foxyshop_search=1" title="' . __('Customer') . '">' . __('Customer') . '</a></span>';
            do_action('foxyshop_subscription_action_line', $subscription);
            echo '</div>';
            echo '</td>';
            echo '<td class="start_date">' . $start_date . '</td>';
            echo '<td class="next_transaction_date">' . $next_transaction_date . '</td>';
            echo '<td class="end_date">' . $end_date . '</td>';
            echo '<td class="past_due_amount">' . $past_due_amount . '</td>';
            echo '<td class="product_description">' . $product_name . '</td>';
            echo '<td class="frequency">' . $frequency . '</td>';
            echo "</tr>\n";
            $holder .= '<div class="detail_holder" id="holder_' . $sub_token . '">' . "\n";
            $holder .= '<form class="subscription_update_form" name="subscription_update_form_' . $sub_token . '" id="subscription_update_form_' . $sub_token . '" onsubmit="return false;">' . "\n";
            $holder .= '<div class="foxyshop_field_control">' . "\n";
            $holder .= '<label>' . __('Subscription Status', 'foxyshop') . '</label>' . "\n";
            $holder .= '<input type="radio" name="is_active" id="is_active_1_' . $sub_token . '" value="1"' . ($is_active == "1" ? ' checked="checked"' : '') . ' style="float: left; margin-top: 7px;" />' . "\n";
            $holder .= '<label for="is_active_1_' . $sub_token . '" style="width: 55px;">' . __('Active', 'foxyshop') . '</label>' . "\n";
            $holder .= '<input type="radio" name="is_active" id="is_active_0_' . $sub_token . '" value="0"' . ($is_active == "0" ? ' checked="checked"' : '') . ' style="float: left; margin-top: 7px;" />' . "\n";
            $holder .= '<label for="is_active_0_' . $sub_token . '">' . __('In-active', 'foxyshop') . '</label>' . "\n";
            $holder .= '</div>' . "\n";
            $holder .= '<div class="foxyshop_field_control">' . "\n";
            $holder .= '<label for="start_date_' . $sub_token . '">' . __('Start Date', 'foxyshop') . '</label>' . "\n";
            $holder .= '<input type="text" name="start_date" id="start_date_' . $sub_token . '" class="foxyshop_date_field" value="' . (string) $subscription->start_date . '" /><span>(YYYY-MM-DD)</span>' . "\n";
            $holder .= '</div>' . "\n";
            $holder .= '<div class="foxyshop_field_control">' . "\n";
            $holder .= '<label for="next_transaction_date_' . $sub_token . '">' . __('Next Transaction Date', 'foxyshop') . '</label>' . "\n";
            $holder .= '<input type="text" name="next_transaction_date" id="next_transaction_date_' . $sub_token . '" value="' . (string) $subscription->next_transaction_date . '" class="foxyshop_date_field" /><span>(YYYY-MM-DD)</span>' . "\n";
            $holder .= '</div>' . "\n";
            $holder .= '<div class="foxyshop_field_control">' . "\n";
            $holder .= '<label for="end_date_' . $sub_token . '">' . __('End Date', 'foxyshop') . '</label>' . "\n";
            $holder .= '<input type="text" name="end_date" id="end_date_' . $sub_token . '" value="' . $end_date . '" class="foxyshop_date_field" /><span>(YYYY-MM-DD)</span> <a href="#" onclick="jQuery(\'#end_date_' . $sub_token . '\').val(\'0000-00-00\'); this.blur(); return false;" class="button" style="margin: 5px 0 0 5px; float: left;">Never</a> <a href="#" onclick="jQuery(\'#end_date_' . $sub_token . '\').val(\'' . date("Y-m-d", strtotime("+1 day")) . '\'); this.blur(); return false;" class="button" style="margin: 5px 0 0 5px; float: left;">Tomorrow</a>' . "\n";
            $holder .= '</div>' . "\n";
            $holder .= '<div class="foxyshop_field_control">' . "\n";
            $holder .= '<label for="frequency_' . $sub_token . '">' . __('Frequency', 'foxyshop') . '</label>' . "\n";
            $holder .= '<input type="text" name="frequency" id="frequency_' . $sub_token . '" value="' . $frequency . '" /><span>(60d, 2w, 1m, 1y, .5m)</span>' . "\n";
            $holder .= '</div>' . "\n";
            $holder .= '<div class="foxyshop_field_control">' . "\n";
            $holder .= '<label for="past_due_amount_' . $sub_token . '">' . __('Past Due Amount', 'foxyshop') . '</label>' . "\n";
            $holder .= '<input type="text" name="past_due_amount" id="past_due_amount_' . $sub_token . '" value="' . $past_due_amount . '" onblur="foxyshop_check_number(this);" /><span>(0.00)</span>' . "\n";
            $holder .= '</div>' . "\n";
            $holder .= '<div class="foxyshop_field_control">' . "\n";
            $holder .= '<label for="update_url_' . $sub_token . '">' . __('Update URL', 'foxyshop') . '</label>' . "\n";
            $holder .= '<input type="text" name="update_url" id="update_url_' . $sub_token . '" value="https://' . $foxyshop_settings['domain'] . '/cart?sub_token=' . $sub_token . '&amp;empty=true&amp;cart=checkout" style="width: 390px;" onclick="this.select();" />' . "\n";
            $holder .= '</div>' . "\n";
            $holder .= '<div class="foxyshop_field_control">' . "\n";
            $holder .= '<label for="cancel_url_' . $sub_token . '">' . __('Cancellation URL', 'foxyshop') . '</label>' . "\n";
            $holder .= '<input type="text" name="cancel_url" id="cancel_url_' . $sub_token . '" value="https://' . $foxyshop_settings['domain'] . '/cart?sub_token=' . $sub_token . '&amp;empty=true&amp;cart=checkout&amp;sub_cancel=true" style="width: 390px;" onclick="this.select();" />' . "\n";
            $holder .= '</div>' . "\n";
            $holder .= '<div class="foxyshop_field_control">' . "\n";
            $holder .= '<label for="transaction_template_id_' . $sub_token . '">' . __('Transaction Template') . '</label>' . "\n";
            $holder .= '<select name="transaction_template_id" id="transaction_template_id_' . $sub_token . '">' . "\n";
            $holder .= '<option value="0">- - ' . __('Select Option Below', 'foxyshop') . ' - -</option>' . "\n";
            foreach ($subscription_product_array as $key => $val) {
                $holder .= '<option value="' . $val['id'] . '">' . $val['name'] . ' ' . foxyshop_currency($val['price']) . '</option>' . "\n";
            }
            $holder .= '</select>' . "\n";
            $holder .= '</div>' . "\n";
            $holder .= '<p style="padding-top: 5px; clear: both"><a href="#" class="subscription_save button-primary">' . __('Save Changes', 'foxyshop') . '</a> <a href="#" class="detail_close button">' . __('Cancel', 'foxyshop') . '</a></p>' . "\n";
            $holder .= '<input type="hidden" name="sub_token" value="' . $sub_token . '" />' . "\n";
            $holder .= '<input type="hidden" name="action" value="foxyshop_display_list_ajax_action" />' . "\n";
            $holder .= '<input type="hidden" name="foxyshop_action" value="subscription_modify" />' . "\n";
            $holder .= '<input type="hidden" name="security" value="' . wp_create_nonce("foxyshop-display-list-function") . '" />' . "\n";
            //Custom Attributes
            $holder .= foxyshop_manage_attributes($subscription->attributes, $sub_token, "subscription");
            $holder .= '</form>' . "\n";
            $holder .= '</div>' . "\n";
        }
        ?>
		</tbody>
		</table>

		<?php 
        foxyshop_api_paging_nav('subscriptions', 'bottom', $xml, $foxyshop_querystring);
        ?>
		</form>
	<?php 
    }
    ?>

	<div id="details_holder"><?php 
    echo $holder;
    ?>
</div>

	<script type="text/javascript" src="<?php 
    echo FOXYSHOP_DIR;
    ?>
/js/jquery.tablesorter.js"></script>
	<script type="text/javascript">
	jQuery(document).ready(function($){
		$(".foxyshop-list-table thead th").click(function() {
			$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
			$("#foxyshop-list-inline").remove();
		});
		$(".foxyshop-list-table").tablesorter({
			'cssDesc': 'asc sorted',
			'cssAsc': 'desc sorted'
		});
		$(".view_detail").click(function() {
			var id = $(this).parents("tr").attr("rel");

			if ($("#foxyshop-list-inline #holder_" + id).length > 0) {
				$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
				$("#foxyshop-list-inline").remove();
			} else {
				$("#details_holder select").prop('selectedIndex', 0);
				$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
				$("#foxyshop-list-inline").remove();

				$(this).parents("tr").after('<tr id="foxyshop-list-inline"><td colspan="7"></td></tr>');
				$("#holder_"+id).appendTo("#foxyshop-list-inline td");
			}

			return false;
		});
		$(".detail_close").click(function() {
			$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
			$("#foxyshop-list-inline").remove();
			return false;
		});
		$(".subscription_save").click(function() {
			var id = $(this).parents("form").children("input[name='sub_token']").val();
			$.post(ajaxurl, $(this).parents("form").serialize(), function(response) {

				$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
				$("#foxyshop-list-inline").remove();

				if (response.indexOf("ERROR") < 0) {
					$("tr[rel='" + id + "']").css("background-color", "#FFFFE0").delay(500).animate({ backgroundColor: 'transparent' }, 500);
					if ($("#is_active_0_" + id).is(":checked")) {
						$("tr[rel='" + id + "'] td.customer_name strong").addClass("strikethrough");
					} else {
						$("tr[rel='" + id + "'] td.customer_name strong").removeClass("strikethrough");
					}
					$("tr[rel='" + id + "'] td.start_date").text($("#start_date" + id).val());
					$("tr[rel='" + id + "'] td.next_transaction_date").text($("#next_transaction_date_" + id).val());
					$("tr[rel='" + id + "'] td.end_date").text($("#end_date_" + id).val());
					$("tr[rel='" + id + "'] td.past_due_amount").text($("#past_due_amount_" + id).val());
					$("tr[rel='" + id + "'] td.frequency").text($("#frequency_" + id).val());
					if ($("#transaction_template_id_" + id).prop("selectedIndex") > 0) {
						$("tr[rel='" + id + "'] td.product_description").text($("#transaction_template_id_" + id + " option:selected").text());
					}
				} else {
					alert(response);
				}
			});
			return false;
		});

		<?php 
    foxyshop_manage_attributes_jquery('subscription');
    ?>

	});

	function foxyshop_format_number(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + num + '.' + cents); }
	function foxyshop_check_number(el) { el.value = foxyshop_format_number(el.value); }

	</script>
	<?php 
    echo '</div>';
}
function foxyshop_customer_order_history($customer_id = 0, $date_filter = 'n/j/Y', $no_results_message = "No Records Found.")
{
    global $foxyshop_settings;
    //Setup Fields and Defaults
    $foxy_data_defaults = array("customer_id_filter" => $customer_id);
    $foxy_data = wp_parse_args(array("api_action" => "transaction_list"), $foxy_data_defaults);
    $foxy_data['pagination_start'] = isset($_GET['pagination_start']) ? $_GET['pagination_start'] : 0;
    if (version_compare($foxyshop_settings['version'], '0.7.0', ">")) {
        $foxy_data['entries_per_page'] = 50;
    }
    $foxy_response = foxyshop_get_foxycart_data($foxy_data);
    $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
    //No Results
    if ($xml->result == "ERROR") {
        $msg = $xml->messages->message;
        if ($msg == "No transactions found. Please double check your filter fields.") {
            $msg = $no_results_message;
        }
        echo '<div class="foxyshop_customer_order_history_no_results">' . $msg . '</div>';
        return;
    }
    //Table Header
    echo '<table cellpadding="0" cellspacing="0" border="0" class="foxyshop_table_list" id="foxyshop_customer_order_history">' . "\n";
    echo '<thead>' . "\n";
    echo '<tr>' . "\n";
    echo '<th>Order ID</th>' . "\n";
    echo '<th>Date</th>' . "\n";
    echo '<th>Total</th>' . "\n";
    echo '<th>&nbsp;</th>' . "\n";
    echo '</tr>' . "\n";
    echo '</thead>' . "\n";
    echo '<tbody>' . "\n";
    foreach ($xml->transactions->transaction as $transaction) {
        $transaction_id = $transaction->id;
        echo '<tr rel="' . $transaction_id . '">';
        echo '<td class="order_id">' . $transaction_id . '</td>';
        echo '<td class="order_date">' . date($date_filter, strtotime($transaction->transaction_date)) . '</td>';
        echo '<td class="order_total">' . foxyshop_currency((double) $transaction->order_total) . '</td>';
        echo '<td class="order_receipt"><a href="' . $transaction->receipt_url . '" target="_blank">Show Receipt</a></td>';
        echo '</tr>' . "\n";
    }
    echo '</tbody></table>';
    //Pagination
    $p = (int) (version_compare($foxyshop_settings['version'], '0.7.0', "==") ? 50 : 50);
    $total_records = (int) $xml->statistics->total_orders;
    $filtered_total = (int) $xml->statistics->filtered_total;
    $pagination_start = (int) $xml->statistics->pagination_start;
    $pagination_end = (int) $xml->statistics->pagination_end;
    if ($pagination_start > 1 || $filtered_total > $pagination_end) {
        echo '<div id="foxyshop_list_pagination">';
        echo $xml->messages->message[1] . '<br />';
        if ($pagination_start > 1) {
            echo '<a href="edit.php' . $querystring . '&amp;pagination_start=' . ($pagination_start - $p - 1) . '">&laquo; Previous</a>';
        }
        if ($pagination_end < $filtered_total) {
            if ($pagination_start > 1) {
                echo ' | ';
            }
            echo '<a href="edit.php' . $querystring . '&amp;pagination_start=' . $pagination_end . '">Next &raquo;</a>';
        }
        echo '</div>';
    }
}
function foxyshop_order_history_dashboard_ajax()
{
    global $foxyshop_settings;
    check_ajax_referer('foxyshop-order-info-dashboard', 'security');
    $pagination_start = 1;
    $filtered_total = 2;
    $orderstats = array(1 => array(0, 0), 7 => array(0, 0), 30 => array(0, 0));
    while ($pagination_start < $filtered_total) {
        //Get Order Info
        $foxy_data = array("api_action" => "transaction_list", "entries_per_page" => 50, "pagination_start" => $pagination_start, "transaction_date_filter_begin" => date("Y-m-d", strtotime("-30 days")), "transaction_date_filter_end" => date("Y-m-d"), "is_test_filter" => 0, "hide_transaction_filter" => "");
        $foxy_response = foxyshop_get_foxycart_data($foxy_data);
        $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
        if ($xml->result != "ERROR") {
            $filtered_total = (int) $xml->statistics->filtered_total;
            $pagination_start = (int) $xml->statistics->pagination_end + 1;
            foreach ($xml->transactions->transaction as $transaction) {
                $transaction_date = (string) $transaction->transaction_date;
                $transaction_total = (double) $transaction->order_total;
                if (strtotime($transaction_date) >= strtotime("-24 hours")) {
                    $orderstats[1][0]++;
                    $orderstats[1][1] += $transaction_total;
                }
                if (strtotime($transaction_date) >= strtotime("-7 days")) {
                    $orderstats[7][0]++;
                    $orderstats[7][1] += $transaction_total;
                }
                $orderstats[30][0]++;
                $orderstats[30][1] += $transaction_total;
            }
        } else {
            $filtered_total = 0;
        }
    }
    echo '<li>' . __('One Day', 'foxyshop') . ': <a href="edit.php?foxyshop_search=1&amp;is_test_filter=&amp;post_type=foxyshop_product&amp;page=foxyshop_order_management&amp;transaction_date_filter_begin=' . date("Y-m-d", strtotime("-1 day")) . '&amp;transaction_date_filter_end=' . date("Y-m-d") . '">' . $orderstats[1][0] . ' ' . _n('order', 'orders', $orderstats[1][0], 'foxyshop') . ', ' . foxyshop_currency($orderstats[1][1]) . '</a></li>' . "\n";
    echo '<li>' . __('Seven Days', 'foxyshop') . ': <a href="edit.php?foxyshop_search=1&amp;is_test_filter=&amp;post_type=foxyshop_product&amp;page=foxyshop_order_management&amp;transaction_date_filter_begin=' . date("Y-m-d", strtotime("-7 days")) . '&amp;transaction_date_filter_end=' . date("Y-m-d") . '">' . $orderstats[7][0] . ' ' . _n('order', 'orders', $orderstats[7][0], 'foxyshop') . ', ' . foxyshop_currency($orderstats[7][1]) . '</a></li>' . "\n";
    echo '<li>' . __('30 Days', 'foxyshop') . ': <a href="edit.php?foxyshop_search=1&amp;is_test_filter=&amp;post_type=foxyshop_product&amp;page=foxyshop_order_management&amp;transaction_date_filter_begin=' . date("Y-m-d", strtotime("-30 days")) . '&amp;transaction_date_filter_end=' . date("Y-m-d") . '">' . $orderstats[30][0] . ' ' . _n('order', 'orders', $orderstats[30][0], 'foxyshop') . ', ' . foxyshop_currency($orderstats[30][1]) . '</a></li>' . "\n";
    die;
}
function foxyshop_save_settings()
{
    if (!isset($_POST['foxyshop_settings_update'])) {
        return;
    }
    if (!check_admin_referer('update-foxyshop-options')) {
        return;
    }
    global $foxyshop_settings;
    //Check for downloadables sync first and perform if setting is new
    if (!$foxyshop_settings['downloadables_sync'] && isset($_POST['foxyshop_downloadables_sync'])) {
        foxyshop_get_downloadable_list();
    }
    //Loop Through Most Fields
    $fields = array("version", "ship_categories", "weight_type", "enable_ship_to", "enable_dashboard_stats", "enable_subscriptions", "expiring_cards_reminder", "enable_bundled_products", "enable_addon_products", "related_products_custom", "related_products_tags", "sort_key", "use_jquery", "ga", "ga_advanced", "ga_type", "ga_demographics", "hide_subcat_children", "generate_product_sitemap", "manage_inventory_levels", "inventory_alert_level", "inventory_alert_email", "enable_sso", "sso_account_required", "checkout_customer_create", "downloadables_sync", "google_product_support", "google_product_merchant_id", "include_exception_list", "show_add_to_cart_link", "use_cart_validation", "locale_code");
    foreach ($fields as $field1) {
        $foxyshop_settings[$field1] = isset($_POST['foxyshop_' . $field1]) ? trim(stripslashes($_POST['foxyshop_' . $field1])) : '';
    }
    //Loop Through No Trim Fields
    $fields = array("browser_title_1", "browser_title_2", "browser_title_3", "browser_title_4", "browser_title_5", "browser_title_6", "browser_title_7");
    foreach ($fields as $field1) {
        $foxyshop_settings[$field1] = isset($_POST['foxyshop_' . $field1]) ? stripslashes($_POST['foxyshop_' . $field1]) : '';
    }
    //Default Image
    if ($_POST['foxyshop_default_image'] == 2) {
        $foxyshop_settings["default_image"] = "none";
    } elseif ($_POST['foxyshop_default_image'] == 1 && $_POST['foxyshop_default_image_custom'] != "") {
        $foxyshop_settings["default_image"] = trim(stripslashes($_POST['foxyshop_default_image_custom']));
    } else {
        $foxyshop_settings["default_image"] = "";
    }
    //Order Desk URL
    if (isset($_POST['foxyshop_set_orderdesk_url']) && !empty($_POST['foxyshop_orderdesk_url'])) {
        $foxyshop_settings["orderdesk_url"] = $_POST['foxyshop_orderdesk_url'];
    } else {
        $foxyshop_settings["orderdesk_url"] = "";
    }
    //Set FoxyCart Domain Name
    $domain = $_POST['foxyshop_domain'];
    if ($domain && get_option("foxyshop_setup_required")) {
        delete_option("foxyshop_setup_required");
    }
    //Delete the setup prompt if domain entered
    if ($domain && strpos($domain, ".") === false) {
        $domain .= ".foxycart.com";
    }
    $foxyshop_settings["domain"] = trim(stripslashes(str_replace("http://", "", $domain)));
    //Set Setup Prompt If FoxyCart API Version Available
    //if ($domain && version_compare($foxyshop_settings['version'], '1.1', ">=") && !$foxyshop_settings['api']['store_access_token']) add_option("foxyshop_setup_required", 1);
    //Other Settings Treated Specially
    $foxyshop_settings["default_weight"] = (int) $_POST['foxyshop_default_weight1'] . ' ' . (double) $_POST['foxyshop_default_weight2'];
    $foxyshop_settings["products_per_page"] = (int) $_POST['foxyshop_products_per_page'] == 0 ? -1 : (int) $_POST['foxyshop_products_per_page'];
    //Cache the FoxyCart Includes
    if (version_compare($foxyshop_settings['version'], '0.7.2', ">=") && version_compare($foxyshop_settings['version'], '2.0', "<") && $foxyshop_settings['domain']) {
        if (version_compare($foxyshop_settings['version'], '0.7.2', "<=")) {
            $cart_type = "colorbox";
        } else {
            $cart_type = "sidecart";
        }
        $foxy_data = array("api_action" => "store_includes_get", "javascript_library" => "none", "cart_type" => $cart_type);
        $foxy_data = apply_filters('foxyshop_store_includes_get', $foxy_data);
        $foxy_response = foxyshop_get_foxycart_data($foxy_data);
        $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
        if ($xml->result != "ERROR") {
            if ($xml->code_block) {
                $foxyshop_settings['foxycart_include_cache'] = (string) $xml->code_block;
            }
        } else {
            $foxyshop_settings['foxycart_include_cache'] = "";
        }
    } else {
        $foxyshop_settings['foxycart_include_cache'] = "";
    }
    //Save
    update_option("foxyshop_settings", $foxyshop_settings);
    wp_redirect("edit.php?post_type=foxyshop_product&page=foxyshop_settings_page&saved=1");
    exit;
}
function foxyshop_transaction_export()
{
    global $foxyshop_settings;
    if ($_GET['transaction_search_type'] == "export_csv") {
        $field_delimiter = ",";
    } elseif ($_GET['transaction_search_type'] == "export_tab") {
        $field_delimiter = "\t";
    }
    //Setup Fields and Defaults
    $foxy_data_defaults = array("is_test_filter" => "0", "hide_transaction_filter" => "0", "data_is_fed_filter" => "", "id_filter" => "", "order_total_filter" => "", "coupon_code_filter" => "", "transaction_date_filter_begin" => date("Y-m-d", strtotime("-10 days")), "transaction_date_filter_end" => date("Y-m-d"), "customer_id_filter" => "", "customer_email_filter" => "", "customer_first_name_filter" => "", "customer_last_name_filter" => "", "customer_state_filter" => "", "shipping_state_filter" => "", "customer_ip_filter" => "", "product_code_filter" => "", "product_name_filter" => "", "product_option_name_filter" => "", "product_option_value_filter" => "");
    if (version_compare($foxyshop_settings['version'], '0.7.2', ">=")) {
        $foxy_data_defaults["custom_field_name_filter"] = "";
        $foxy_data_defaults["custom_field_value_filter"] = "";
    }
    $foxy_data = wp_parse_args(array("api_action" => "transaction_list"), $foxy_data_defaults);
    if (isset($_GET['foxyshop_search'])) {
        $fields = array("is_test_filter", "hide_transaction_filter", "data_is_fed_filter", "id_filter", "order_total_filter", "coupon_code_filter", "transaction_date_filter_begin", "transaction_date_filter_end", "customer_id_filter", "customer_email_filter", "customer_first_name_filter", "customer_last_name_filter", "customer_state_filter", "shipping_state_filter", "customer_ip_filter", "product_code_filter", "product_name_filter", "product_option_name_filter", "product_option_value_filter", "custom_field_name_filter", "custom_field_value_filter");
        foreach ($fields as $field) {
            if (isset($_GET[$field])) {
                $foxy_data[$field] = $_GET[$field];
            }
        }
        $foxy_data['pagination_start'] = isset($_GET['pagination_start']) ? $_GET['pagination_start'] : 0;
        if ($foxyshop_settings['version'] != "0.7.0") {
            $foxy_data['entries_per_page'] = 10000;
        }
    }
    $foxy_response = foxyshop_get_foxycart_data($foxy_data);
    $xml_return = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
    if ((string) $xml_return->result == "ERROR") {
        echo '<h3>' . $xml_return->messages->message . '</h3>';
        die;
    }
    // Define the path to file
    $filename = 'foxycart-export-' . Date('d-m-Y') . '.' . ($field_delimiter == "," ? "csv" : "txt");
    // Set headers
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\"");
    header("Content-Type: text/csv");
    $fields = array('transaction_id', 'store_id', 'transaction_date', 'product_total', 'tax_total', 'shipping_total', 'discount_total', 'order_total', 'purchase_order', 'cc_type', 'cc_number_masked', 'cc_exp_month', 'cc_exp_year', 'processor_response', 'customer_id', 'is_anonymous', 'minfraud_score', 'customer_first_name', 'customer_last_name', 'customer_company', 'customer_address1', 'customer_address2', 'customer_city', 'customer_state', 'customer_postal_code', 'customer_country', 'customer_phone', 'customer_email', 'customer_ip', 'custom_fields', 'attributes', 'coupons_used', 'shipping_service_description', 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address1', 'shipping_address2', 'shipping_city', 'shipping_state', 'shipping_postal_code', 'shipping_country', 'shipping_phone', 'sub_token_url', 'category_code', 'product_name', 'product_code', 'product_price', 'product_quantity', 'product_weight', 'product_options');
    echo implode($field_delimiter, $fields) . "\n";
    foreach ($xml_return->transactions->transaction as $transaction) {
        $custom_fields = "";
        if (!empty($transaction->custom_fields)) {
            foreach ($transaction->custom_fields->custom_field as $custom_field) {
                if ($custom_fields) {
                    $custom_fields .= " - ";
                }
                $custom_fields .= (string) $custom_field->custom_field_name . ":" . (string) $custom_field->custom_field_value;
            }
        }
        $attributes1 = "";
        if (!empty($transaction->attributes)) {
            foreach ($transaction->attributes->attribute as $attribute) {
                if ($attributes1) {
                    $attributes1 .= " - ";
                }
                $attributes1 .= (string) $attribute->name . ":" . (string) $attribute->value;
            }
        }
        $discounts = "";
        $discount_total = 0;
        if (!empty($transaction->discounts)) {
            foreach ($transaction->discounts->discount as $discount) {
                if ($discounts) {
                    $discounts .= " - ";
                }
                $discounts .= (string) $discount->code . ":" . (string) $discount->amount;
                $discount_total += (double) $discount->amount;
            }
        }
        $tax_total = 0;
        if (!empty($transaction->taxes)) {
            foreach ($transaction->taxes->tax as $tax) {
                $tax_total += (double) $tax->tax_amount;
            }
        }
        $product_total = 0;
        $future_product_total = 0;
        foreach ($transaction->transaction_details->transaction_detail as $transaction_detail) {
            $product_price = (double) $transaction_detail->product_price;
            foreach ($transaction_detail->transaction_detail_options->transaction_detail_option as $transaction_detail_option) {
                $product_price += (double) $transaction_detail_option->price_mod;
            }
            $product_total += $product_price * (int) $transaction_detail->product_quantity;
            if ($transaction_detail->is_future_line_item) {
                $future_product_total += $product_price * (int) $transaction_detail->product_quantity;
            }
        }
        $shipping_total = (double) $transaction->shipping_total;
        $order_total = $product_total + $shipping_total + $discount_total + $tax_total - $future_product_total;
        //Start Writing
        echo (string) $transaction->id;
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->store_id) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->transaction_date) . '"';
        echo $field_delimiter . $product_total;
        echo $field_delimiter . $tax_total;
        echo $field_delimiter . $shipping_total;
        echo $field_delimiter . $discount_total;
        echo $field_delimiter . $order_total;
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->purchase_order) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->cc_type) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->cc_number_masked) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->cc_exp_month) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->cc_exp_year) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->processor_response) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_id) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->is_anonymous) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->minfraud_score) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_first_name) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_last_name) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_company) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_address1) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_address2) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_city) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_state) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_postal_code) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_country) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_phone) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_email) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->customer_ip) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes($custom_fields) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes($attributes1) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes($discounts) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipto_shipping_service_description) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipping_first_name) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipping_last_name) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipping_company) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipping_address1) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipping_address2) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipping_city) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipping_state) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipping_postal_code) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipping_country) . '"';
        echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction->shipping_phone) . '"';
        //Products
        $product_count = 1;
        foreach ($transaction->transaction_details->transaction_detail as $transaction_detail) {
            //New Line for Second Product
            if ($product_count > 1) {
                echo (string) $transaction->id;
                for ($i = 1; $i <= 42; $i++) {
                    echo $field_delimiter . '""';
                }
            }
            //Options
            $product_options = "";
            foreach ($transaction_detail->transaction_detail_options->transaction_detail_option as $transaction_detail_option) {
                if ($product_options) {
                    $product_options .= " - ";
                }
                $product_options .= (string) $transaction_detail_option->product_option_name . ":" . (string) $transaction_detail_option->product_option_value;
            }
            echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction_detail->sub_token_url) . '"';
            echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction_detail->category_code) . '"';
            echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction_detail->product_name) . '"';
            echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction_detail->product_code) . '"';
            echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction_detail->product_price) . '"';
            echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction_detail->product_quantity) . '"';
            echo $field_delimiter . '"' . foxyshop_dblquotes((string) $transaction_detail->product_weight) . '"';
            echo $field_delimiter . '"' . foxyshop_dblquotes($product_options) . '"';
            echo "\n";
            $product_count++;
        }
    }
    die;
}
function foxyshop_add_new_customer_id($email, $pass, $first_name, $last_name)
{
    global $current_user;
    get_currentuserinfo();
    $foxy_data = array("api_action" => "customer_save", "customer_email" => $email, "customer_password_hash" => $pass);
    if ($first_name != '') {
        $foxy_data['customer_first_name'] = $first_name;
    }
    if ($last_name != '') {
        $foxy_data['customer_last_name'] = $last_name;
    }
    $foxy_response = foxyshop_get_foxycart_data($foxy_data);
    $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
    $foxycart_customer_id = (string) $xml->customer_id;
    if ($foxycart_customer_id) {
        add_user_meta($current_user->ID, 'foxycart_customer_id', $foxycart_customer_id, true);
    }
    return $foxycart_customer_id;
}
function foxyshop_save_tools()
{
    global $foxyshop_settings;
    //Import Settings
    if (isset($_POST['foxyshop_import_settings'])) {
        if (!check_admin_referer('import-foxyshop-settings')) {
            return;
        }
        $encrypt_key = "foxyshop_encryption_key_16";
        $foxyshop_import_settings = str_replace("\n", "", $_POST['foxyshop_import_settings']);
        $decrypted = explode("|-|", rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($encrypt_key), base64_decode($foxyshop_import_settings), MCRYPT_MODE_CBC, md5(md5($encrypt_key))), ""));
        if (count($decrypted) != 3) {
            wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&importerror=1');
            exit;
        } else {
            update_option("foxyshop_settings", unserialize($decrypted[0]));
            update_option("foxyshop_category_sort", unserialize($decrypted[1]));
            update_option("foxyshop_saved_variations", unserialize($decrypted[2]));
            delete_option("foxyshop_setup_required");
            wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&import=1');
            exit;
        }
        //Scan For Old Variations
    } elseif (isset($_GET['foxyshop_old_variations_scan'])) {
        if (!check_admin_referer('foxyshop_old_variations_scan')) {
            return;
        }
        $foxyshop_settings['foxyshop_version'] = "2.9";
        update_option("foxyshop_settings", $foxyshop_settings);
        wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&oldvars=1');
        exit;
        //Update FoxyCart Template
    } elseif (isset($_POST['foxycart_cart_update_save']) || isset($_POST['foxycart_checkout_update_save']) || isset($_POST['foxycart_receipt_update_save'])) {
        if (!check_admin_referer('update-foxycart-template')) {
            return;
        }
        $foxyshop_settings['template_url_cart'] = $_POST['foxycart_cart_update'];
        $foxyshop_settings['template_url_checkout'] = $_POST['foxycart_checkout_update'];
        $foxyshop_settings['template_url_receipt'] = $_POST['foxycart_receipt_update'];
        update_option("foxyshop_settings", $foxyshop_settings);
        //If just clearing the urls, return now
        if (empty($_POST['foxycart_cart_update']) && empty($_POST['foxycart_checkout_update'])) {
            wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&updatetemplate=clear');
            exit;
        }
        //Cart
        if (isset($_POST['foxycart_cart_update_save'])) {
            $foxy_data = array("api_action" => "store_template_cache", "template_type" => "cart", "template_url" => $_POST['foxycart_cart_update']);
            $foxy_response = foxyshop_get_foxycart_data($foxy_data);
            $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
            if ($xml->result != "ERROR") {
                wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&updatetemplate=cart');
            } else {
                wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&updatetemplate=error&error=' . urlencode((string) $xml->messages->message));
            }
            exit;
            //Checkout
        } elseif (isset($_POST['foxycart_checkout_update_save'])) {
            $foxy_data = array("api_action" => "store_template_cache", "template_type" => "checkout", "template_url" => $_POST['foxycart_checkout_update']);
            $foxy_response = foxyshop_get_foxycart_data($foxy_data);
            $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
            if ($xml->result != "ERROR") {
                wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&updatetemplate=checkout');
            } else {
                wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&updatetemplate=error&error=' . urlencode((string) $xml->messages->message));
            }
            exit;
            //Receipt
        } elseif (isset($_POST['foxycart_receipt_update_save'])) {
            $foxy_data = array("api_action" => "store_template_cache", "template_type" => "receipt", "template_url" => $_POST['foxycart_receipt_update']);
            $foxy_response = foxyshop_get_foxycart_data($foxy_data);
            $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
            if ($xml->result != "ERROR") {
                wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&updatetemplate=receipt');
            } else {
                wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&updatetemplate=error&error=' . urlencode((string) $xml->messages->message));
            }
            exit;
        }
        //Process Saved Variations
    } elseif (isset($_POST['foxyshop_process_saved_variations'])) {
        if (!check_admin_referer('wp-foxyshop-process-saved-variations')) {
            return;
        }
        $currentID = 1;
        $variations = array();
        for ($i = 1; $i <= (int) $_POST['max_variations']; $i++) {
            //Get Target From Sort Numbers
            $target_id = 0;
            for ($k = 1; $k <= (int) $_POST['max_variations']; $k++) {
                $tempid = isset($_POST['sort' . $k]) ? $_POST['sort' . $k] : 0;
                if ($tempid == $i) {
                    $target_id = $k;
                }
            }
            //Set Values, Skip if Not There or Empty Name
            if ($target_id == 0) {
                continue;
            }
            $_variationRefName = trim(str_replace(".", "", str_replace('"', '', $_POST['_variation_ref_name_' . $target_id])));
            $_variationName = trim(str_replace(".", "", str_replace('"', '', $_POST['_variation_name_' . $target_id])));
            $_variationType = $_POST['_variation_type_' . $target_id];
            $_variationDisplayKey = $_POST['_variation_dkey_' . $target_id];
            $_variationRequired = isset($_POST['_variation_required_' . $target_id]) ? $_POST['_variation_required_' . $target_id] : '';
            if ($_POST['_variation_name_' . $target_id] == "") {
                continue;
            }
            //Get Values
            if ($_variationType == 'text') {
                $_variationValue = $_POST['_variation_textsize1_' . $target_id] . "|" . $_POST['_variation_textsize2_' . $target_id];
            } elseif ($_variationType == 'textarea') {
                $_variationValue = (int) $_POST['_variation_textareasize_' . $target_id];
                if ($_variationValue == 0) {
                    $_variationValue = 3;
                }
            } elseif ($_variationType == 'upload') {
                $_variationValue = $_POST['_variation_uploadinstructions_' . $target_id];
            } elseif ($_variationType == 'descriptionfield') {
                $_variationValue = $_POST['_variation_description_' . $target_id];
            } elseif ($_variationType == 'dropdown') {
                $_variationValue = $_POST['_variation_value_' . $target_id];
            } elseif ($_variationType == 'checkbox') {
                $_variationValue = $_POST['_variation_checkbox_' . $target_id];
            } elseif ($_variationType == 'hiddenfield') {
                $_variationValue = $_POST['_variation_hiddenfield_' . $target_id];
            } elseif ($_variationType == 'radio') {
                $_variationValue = $_POST['_variation_radio_' . $target_id];
            }
            $variations[$currentID] = array("refname" => stripslashes($_variationRefName), "name" => stripslashes($_variationName), "type" => stripslashes($_variationType), "value" => stripslashes($_variationValue), "displayKey" => stripslashes($_variationDisplayKey), "required" => stripslashes($_variationRequired));
            $currentID++;
        }
        if (count($variations) > 0) {
            update_option('foxyshop_saved_variations', $variations);
        } else {
            delete_option('foxyshop_saved_variations');
        }
        wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&processedvars=1');
        exit;
        //Reset API Key
    } elseif (isset($_GET['foxyshop_api_key_reset'])) {
        if (!check_admin_referer('reset-foxyshop-api-key')) {
            return;
        }
        $foxyshop_settings['api_key'] = "sp92fx" . hash_hmac('sha256', rand(21654, 6489798), "dkjw82j1" . time());
        update_option("foxyshop_settings", $foxyshop_settings);
        wp_redirect('edit.php?post_type=foxyshop_product&page=foxyshop_tools&key=1');
        exit;
    }
}
Exemple #10
0
function foxyshop_profile_add($user_id)
{
    //Get User Data
    $wp_user = get_userdata($user_id);
    //Set Foxy Data
    $foxy_data = array("api_action" => "customer_save");
    $foxy_data["customer_email"] = $wp_user->user_email;
    $foxy_data["customer_password_hash"] = $wp_user->user_pass;
    if ($wp_user->user_firstname) {
        $foxy_data["customer_first_name"] = $wp_user->user_firstname;
    }
    if ($wp_user->user_lastname) {
        $foxy_data["customer_last_name"] = $wp_user->user_lastname;
    }
    //Hook To Add Your Own Function to Update the $foxy_data array with your own data
    if (has_filter('foxyshop_save_sso_to_foxycart')) {
        $foxy_data = apply_filters('foxyshop_save_sso_to_foxycart', $foxy_data, $user_id, "add");
    }
    //Send To FoxyCart
    $foxy_response = foxyshop_get_foxycart_data($foxy_data);
    $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
    $foxycart_customer_id = (string) $xml->result != "ERROR" ? (string) $xml->customer_id : "";
    //If FoxyCart Customer ID Returned, Add FoxyCart Customer ID To User Meta
    if ($foxycart_customer_id) {
        add_user_meta($user_id, 'foxycart_customer_id', $foxycart_customer_id, true);
    }
    //Auto-login if user wasn't logged in before
    //Note that if you don't have the querystring "redirect_to" set on the registration page the page will not redirect anywhere and won't appear logged in at first
    $auto_login = apply_filters("foxyshop_new_user_auto_login", true);
    if (!is_user_logged_in() && $auto_login) {
        wp_set_auth_cookie($user_id, false, is_ssl());
    }
}
function foxyshop_customer_management()
{
    global $foxyshop_settings, $wp_version;
    //Setup Fields and Defaults
    $foxy_data_defaults = array("customer_id_filter" => "", "customer_email_filter" => "", "customer_first_name_filter" => "", "customer_last_name_filter" => "", "customer_state_filter" => "");
    if (version_compare($foxyshop_settings['version'], '0.7.2', ">=")) {
        $foxy_data_defaults["custom_field_name_filter"] = "";
        $foxy_data_defaults["custom_field_value_filter"] = "";
    }
    $foxy_data = wp_parse_args(array("api_action" => "customer_list"), apply_filters('foxyshop_customer_filter_defaults', $foxy_data_defaults));
    $foxyshop_querystring = "?post_type=foxyshop_product&amp;page=foxyshop_customer_management&amp;foxyshop_search=1";
    $foxyshop_hidden_input = "";
    if (isset($_GET['foxyshop_search'])) {
        $fields = array("customer_id_filter", "customer_email_filter", "customer_first_name_filter", "customer_last_name_filter", "customer_state_filter", "custom_field_name_filter", "custom_field_value_filter");
        foreach ($fields as $field) {
            if (isset($_GET[$field])) {
                $foxy_data[$field] = $_GET[$field];
                $foxyshop_querystring .= "&amp;{$field}=" . urlencode($_GET[$field]);
                $foxyshop_hidden_input .= '<input type="hidden" name="' . $field . '" value="' . htmlspecialchars($_GET[$field]) . '" />' . "\n";
            }
        }
        $foxy_data['pagination_start'] = isset($_GET['pagination_start']) ? $_GET['pagination_start'] : 0;
        $p = (int) (version_compare($foxyshop_settings['version'], '0.7.1', "<") ? 50 : FOXYSHOP_API_ENTRIES_PER_PAGE);
        if (version_compare($foxyshop_settings['version'], '0.7.0', ">")) {
            $foxy_data['entries_per_page'] = $p;
        }
        $start_offset = (int) (version_compare($foxyshop_settings['version'], '0.7.1', "<=") ? -1 : 0);
        if (isset($_GET['paged-top']) || isset($_GET['paged-bottom'])) {
            if ($_GET['paged-top'] != $_GET['paged-top-original']) {
                $foxy_data['pagination_start'] = $p * ((int) $_GET['paged-top'] - 1) + 1 + $start_offset;
            }
            if ($_GET['paged-bottom'] != $_GET['paged-bottom-original']) {
                $foxy_data['pagination_start'] = $p * ((int) $_GET['paged-bottom'] - 1) + 1 + $start_offset;
            }
        }
    }
    ?>
	<div class="wrap">
		<div class="icon32" id="icon-users"><br></div>
		<h2><?php 
    _e('Manage Customers', 'foxyshop');
    ?>
</h2>

		<form action="edit.php" method="get" id="foxyshop_searchform" name="foxyshop_searchform" style="display: block; margin: 14px 0 20px 0;">
		<input type="hidden" name="foxyshop_search" value="1" />
		<input type="hidden" name="post_type" value="foxyshop_product" />
		<input type="hidden" name="page" value="foxyshop_customer_management" />

		<table class="widefat">
		<thead><tr><th colspan="2"><img src="<?php 
    echo FOXYSHOP_DIR;
    ?>
/images/search-icon.png" alt="" /><?php 
    _e('Search Options', 'foxyshop');
    ?>
</th></tr></thead>
		<tbody><tr><td>

			<div class="foxyshop_field_control">
				<label for="customer_id_filter"><?php 
    _e('Customer ID', 'foxyshop');
    ?>
</label><input type="text" name="customer_id_filter" id="customer_id_filter" value="<?php 
    echo $foxy_data['customer_id_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_first_name_filter"><?php 
    _e('Customer First Name', 'foxyshop');
    ?>
</label><input type="text" name="customer_first_name_filter" id="customer_first_name_filter" value="<?php 
    echo $foxy_data['customer_first_name_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_last_name_filter"><?php 
    _e('Customer Last Name', 'foxyshop');
    ?>
</label><input type="text" name="customer_last_name_filter" id="customer_last_name_filter" value="<?php 
    echo $foxy_data['customer_last_name_filter'];
    ?>
" />
			</div>
			<?php 
    if (version_compare($foxyshop_settings['version'], '0.7.2', ">=")) {
        ?>
			<div class="foxyshop_field_control">
				<label for="custom_field_name_filter"><?php 
        _e('Custom Field Name', 'foxyshop');
        ?>
</label><input type="text" name="custom_field_name_filter" id="custom_field_name_filter" value="<?php 
        echo $foxy_data['custom_field_name_filter'];
        ?>
" />
				<label for="custom_field_value_filter" style="margin-left: 15px; margin-top: 4px; width: 34px;"><?php 
        _e('Value', 'foxyshop');
        ?>
</label><input type="text" name="custom_field_value_filter" id="custom_field_value_filter" value="<?php 
        echo $foxy_data['custom_field_value_filter'];
        ?>
" />
			</div>
			<?php 
    }
    ?>
		</td><td>
			<div class="foxyshop_field_control">
				<label for="customer_email_filter"><?php 
    _e('Customer Email', 'foxyshop');
    ?>
</label><input type="text" name="customer_email_filter" id="customer_email_filter" value="<?php 
    echo $foxy_data['customer_email_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_state_filter"><?php 
    _e('Customer State', 'foxyshop');
    ?>
</label><input type="text" name="customer_state_filter" id="customer_state_filter" value="<?php 
    echo $foxy_data['customer_state_filter'];
    ?>
" />
			</div>

			<div style="clear: both;"></div>
			<button type="submit" id="foxyshop_search_submit" name="foxyshop_search_submit" class="button-primary" style="clear: left; margin: 10px 0 6px 0;"><?php 
    _e('Search Records Now', 'foxyshop');
    ?>
</button>
			<button type="button" class="button" style="margin-left: 15px; margin-top: 10px;" onclick="document.location.href = 'edit.php?post_type=foxyshop_product&page=foxyshop_customer_management';"><?php 
    _e('Reset Form', 'foxyshop');
    ?>
</button>

		</td></tr></tbody></table>
		</form>

	<?php 
    if (!isset($_GET['foxyshop_search'])) {
        return;
    }
    $foxy_response = foxyshop_get_foxycart_data($foxy_data);
    $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
    //print_r($foxy_data);
    //echo "<pre>" . substr($foxy_response,1,2000) . "</pre>";
    if ((string) $xml->result == "ERROR") {
        echo '<h3>' . (string) $xml->messages->message . '</h3>';
        return;
    } else {
        ?>

		<form action="edit.php" method="get">
		<input type="hidden" name="foxyshop_search" value="1" />
		<input type="hidden" name="post_type" value="foxyshop_product" />
		<input type="hidden" name="page" value="foxyshop_customer_management" />

		<?php 
        echo $foxyshop_hidden_input;
        foxyshop_api_paging_nav('customers', 'top', $xml, $foxyshop_querystring);
        ?>


		<table cellpadding="0" cellspacing="0" border="0" class="wp-list-table widefat foxyshop-list-table" id="customer_table">
			<thead>
				<tr>
					<th><span><?php 
        _e('Customer ID', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Last Name', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('First Name', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Email', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Orders', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<?php 
        if ($foxyshop_settings['enable_subscriptions']) {
            echo "<th><span>" . __('Subscriptions', 'foxyshop') . "</span><span class=\"sorting-indicator\"></span></th>\n";
        }
        ?>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<th><?php 
        _e('Customer ID', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('Last Name', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('First Name', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('Email', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('Orders', 'foxyshop');
        ?>
</th>
					<?php 
        if ($foxyshop_settings['enable_subscriptions']) {
            echo "<th>" . __('Subscriptions', 'foxyshop') . "</th>\n";
        }
        ?>
				</tr>
			</tfoot>
			<tbody id="the-list">

		<?php 
        $holder = "";
        foreach ($xml->customers->customer as $customer) {
            $customer_id = (string) $customer->customer_id;
            $customer_first_name = (string) $customer->customer_first_name;
            $customer_last_name = (string) $customer->customer_last_name;
            $customer_email = (string) $customer->customer_email;
            $last_modified_date = (string) $customer->last_modified_date;
            $last_modified_date = date(apply_filters("foxyshop_date_time_format", "Y-m-d H:i"), strtotime($last_modified_date));
            echo '<tr rel="' . $customer_id . '">';
            echo '<td><strong><a href="#" class="view_detail">' . (string) $customer_id . '</a></strong></td>';
            echo '<td>' . (string) $customer_last_name . '</td>';
            echo '<td>' . (string) $customer_first_name . '</td>';
            echo '<td>' . (string) $customer_email . '</td>';
            echo '<td><a href="edit.php?post_type=foxyshop_product&page=foxyshop_order_management&customer_id_filter=' . (string) $customer->customer_id . '&transaction_date_filter_begin=&transaction_date_filter_end=&hide_transaction_filter=&foxyshop_search=1">' . __('Orders', 'foxyshop') . '</a></td>';
            if ($foxyshop_settings['enable_subscriptions']) {
                echo '<td><a href="edit.php?post_type=foxyshop_product&page=foxyshop_subscription_management&customer_id_filter=' . (string) $customer->customer_id . '&start_date_filter_begin=&start_date_filter_end=&&foxyshop_search=1">' . __('Subscriptions', 'foxyshop') . '</a></td>';
            }
            echo '</tr>' . "\n";
            $holder .= '<div class="detail_holder" id="holder_' . $customer_id . '">' . "\n";
            //Customer Details
            $holder .= '<div class="foxyshop_list_col">';
            $holder .= '<h4>' . __('Customer Details', 'foxyshop') . '</h4>';
            $holder .= '<ul>';
            if ((string) $customer->customer_phone != "") {
                $holder .= '<li>' . (string) $customer->customer_phone . '</li>';
            }
            $holder .= '<li><a href="mailto:' . $customer->customer_email . '">' . (string) $customer->customer_email . '</a></li>';
            if ((string) $customer->cc_number != "") {
                $holder .= '<li>' . __('Card', 'foxyshop') . ': ' . (string) $customer->cc_number . '</li>';
            }
            // 0.7.1 and lower
            if ((string) $customer->cc_number_masked != "") {
                $holder .= '<li>' . __('Card', 'foxyshop') . ': ' . (string) $customer->cc_number_masked . '</li>';
            }
            //0.7.2+
            if ((string) $customer->cc_exp_month != "") {
                $holder .= '<li>' . __('Exp', 'foxyshop') . ': ' . (string) $customer->cc_exp_month . '-' . (string) $customer->cc_exp_year . '</li>';
            }
            $holder .= '<li>' . __('Last Modified', 'foxyshop') . ': ' . $last_modified_date . '</li>';
            $holder .= '<li>&nbsp;</li>';
            $holder .= '</ul>';
            $holder .= '</div>';
            //Customer Address
            $holder .= '<div class="foxyshop_list_col">';
            $holder .= '<h4>' . __('Customer Address', 'foxyshop') . '</h4>';
            $holder .= '<ul>';
            $holder .= '<li>' . (string) $customer->customer_first_name . ' ' . (string) $customer->customer_last_name . '</li>';
            if ((string) $customer->customer_company != "") {
                $holder .= '<li>' . (string) $customer->customer_company . '</li>';
            }
            if ((string) $customer->customer_address1 != "") {
                $holder .= '<li>' . (string) $customer->customer_address1 . '</li>';
            }
            if ((string) $customer->customer_address2 != "") {
                $holder .= '<li>' . (string) $customer->customer_address2 . '</li>';
            }
            if ((string) $customer->customer_city != "") {
                $holder .= '<li>' . (string) $customer->customer_city . ', ' . (string) $customer->customer_state . ' ' . (string) $customer->customer_postal_code . '</li>';
            }
            if ((string) $customer->customer_country != "") {
                $holder .= '<li>' . (string) $customer->customer_country . '</li>';
            }
            $holder .= '</ul>';
            $holder .= '</div>';
            //Shipping Addresses (if entered)
            if ((string) $customer->shipping_first_name != "") {
                $holder .= '<div class="foxyshop_list_col">';
                $holder .= '<h4>' . __('Shipping Details', 'foxyshop') . '</h4>';
                $holder .= '<ul>';
                $holder .= '<li>' . (string) $customer->shipping_first_name . ' ' . (string) $customer->shipping_last_name . '</li>';
                if ((string) $customer->shipping_company != "") {
                    $holder .= '<li>' . (string) $customer->shipping_company . '</li>';
                }
                if ((string) $customer->shipping_address1 != "") {
                    $holder .= '<li>' . $customer->shipping_address1 . '</li>';
                }
                if ((string) $customer->shipping_address2 != "") {
                    $holder .= '<li>' . (string) $customer->shipping_address2 . '</li>';
                }
                if ((string) $customer->shipping_city != "") {
                    $holder .= '<li>' . (string) $customer->shipping_city . ', ' . (string) $customer->shipping_state . ' ' . (string) $customer->shipping_postal_code . '</li>';
                }
                if ((string) $customer->shipping_country != "") {
                    $holder .= '<li>' . (string) $customer->shipping_country . '</li>';
                }
                if ((string) $customer->shipping_phone != "") {
                    $holder .= '<li>' . (string) $customer->shipping_phone . '</li>';
                }
                $holder .= '</ul>';
                $holder .= '</div>';
            }
            //Multi-ship Addresses
            foreach ($customer->shipto_addresses->shipto_address as $shipto_address) {
                $holder .= '<div class="foxyshop_list_col">';
                $holder .= '<h4>' . __('Shipping Details', 'foxyshop') . ': ' . $shipto_address->address_name . '</h4>';
                $holder .= '<ul>';
                $holder .= '<li>' . (string) $shipto_address->shipto_first_name . ' ' . (string) $shipto_address->shipto_last_name . '</li>';
                if ((string) $shipto_address->shipto_company != "") {
                    $holder .= '<li>' . (string) $shipto_address->shipto_company . '</li>';
                }
                $holder .= '<li>' . (string) $shipto_address->shipto_address1 . '</li>';
                if ((string) $shipto_address->shipto_address2 != "") {
                    $holder .= '<li>' . (string) $shipto_address->shipto_address2 . '</li>';
                }
                $holder .= '<li>' . (string) $shipto_address->shipto_city . ', ' . (string) $shipto_address->shipto_state . ' ' . (string) $shipto_address->shipto_postal_code . '</li>';
                $holder .= '<li>' . (string) $shipto_address->shipto_country . '</li>';
                if ((string) $shipto_address->shipto_phone != "") {
                    $holder .= '<li>' . (string) $shipto_address->shipto_phone . '</li>';
                }
                $holder .= '</ul>';
                $holder .= '</div>';
            }
            //Custom Attributes
            $holder .= foxyshop_manage_attributes($customer->attributes, $customer_id, "customer");
            $holder .= '<div style="clear: both; height: 20px;"></div>';
            $holder .= "</div>\n";
        }
        echo '</tbody></table>';
        foxyshop_api_paging_nav('customers', 'bottom', $xml, $foxyshop_querystring);
        ?>
		</form>
	<?php 
    }
    ?>

	<div id="details_holder"><?php 
    echo $holder;
    ?>
</div>

	<script type="text/javascript" src="<?php 
    echo FOXYSHOP_DIR;
    ?>
/js/jquery.tablesorter.js"></script>
	<script type="text/javascript">
	jQuery(document).ready(function($){
		$(".foxyshop-list-table thead th").click(function() {
			$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
			$("#foxyshop-list-inline").remove();
		});
		$(".foxyshop-list-table").tablesorter({
			'cssDesc': 'asc sorted',
			'cssAsc': 'desc sorted'
		});
		$(".view_detail").click(function() {
			var id = $(this).parents("tr").attr("rel");

			if ($("#foxyshop-list-inline #holder_" + id).length > 0) {
				$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
				$("#foxyshop-list-inline").remove();
			} else {
				$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
				$("#foxyshop-list-inline").remove();

				$(this).parents("tr").after('<tr id="foxyshop-list-inline"><td colspan="7"></td></tr>');
				$("#holder_"+id).appendTo("#foxyshop-list-inline td");
			}

			return false;
		});


		<?php 
    foxyshop_manage_attributes_jquery('customer');
    ?>

	});
	</script>


	<?php 
    echo '</div>';
}
Exemple #12
0
function foxyshop_order_management()
{
    global $foxyshop_settings, $wp_version;
    //Setup Fields and Defaults
    $foxy_data_defaults = array("is_test_filter" => "0", "hide_transaction_filter" => "0", "data_is_fed_filter" => "", "id_filter" => "", "order_total_filter" => "", "coupon_code_filter" => "", "transaction_date_filter_begin" => date("Y-m-d", strtotime("-10 days")), "transaction_date_filter_end" => date("Y-m-d"), "customer_id_filter" => "", "customer_email_filter" => "", "customer_first_name_filter" => "", "customer_last_name_filter" => "", "customer_state_filter" => "", "shipping_state_filter" => "", "customer_ip_filter" => "", "product_code_filter" => "", "product_name_filter" => "", "product_option_name_filter" => "", "product_option_value_filter" => "");
    if (version_compare($foxyshop_settings['version'], '0.7.2', ">=")) {
        $foxy_data_defaults["custom_field_name_filter"] = "";
        $foxy_data_defaults["custom_field_value_filter"] = "";
    }
    $foxy_data = wp_parse_args(array("api_action" => "transaction_list"), apply_filters('foxyshop_transaction_filter_defaults', $foxy_data_defaults));
    $foxyshop_querystring = "?post_type=foxyshop_product&amp;page=foxyshop_order_management&amp;foxyshop_search=1";
    $foxyshop_hidden_input = "";
    if (isset($_GET['foxyshop_search']) || !defined('FOXYSHOP_AUTO_API_DISABLED')) {
        $fields = array("is_test_filter", "hide_transaction_filter", "data_is_fed_filter", "id_filter", "order_total_filter", "coupon_code_filter", "transaction_date_filter_begin", "transaction_date_filter_end", "customer_id_filter", "customer_email_filter", "customer_first_name_filter", "customer_last_name_filter", "customer_state_filter", "shipping_state_filter", "customer_ip_filter", "product_code_filter", "product_name_filter", "product_option_name_filter", "product_option_value_filter", "custom_field_name_filter", "custom_field_value_filter");
        foreach ($fields as $field) {
            if (isset($_GET[$field])) {
                $foxy_data[$field] = $_GET[$field];
                $foxyshop_querystring .= "&amp;{$field}=" . urlencode($_GET[$field]);
                $foxyshop_hidden_input .= '<input type="hidden" name="' . $field . '" value="' . htmlspecialchars($_GET[$field]) . '" />' . "\n";
            }
        }
        $foxy_data['pagination_start'] = isset($_GET['pagination_start']) ? $_GET['pagination_start'] : 0;
        $p = (int) (version_compare($foxyshop_settings['version'], '0.7.1', "<") ? 50 : FOXYSHOP_API_ENTRIES_PER_PAGE);
        if (version_compare($foxyshop_settings['version'], '0.7.0', ">")) {
            $foxy_data['entries_per_page'] = $p;
        }
        $start_offset = (int) (version_compare($foxyshop_settings['version'], '0.7.1', "<=") ? -1 : 0);
        if (isset($_GET['paged-top']) || isset($_GET['paged-bottom'])) {
            if ($_GET['paged-top'] != $_GET['paged-top-original']) {
                $foxy_data['pagination_start'] = $p * ((int) $_GET['paged-top'] - 1) + 1 + $start_offset;
            }
            if ($_GET['paged-bottom'] != $_GET['paged-bottom-original']) {
                $foxy_data['pagination_start'] = $p * ((int) $_GET['paged-bottom'] - 1) + 1 + $start_offset;
            }
        }
    }
    $transaction_search_type = isset($_GET['transaction_search_type']) ? $_GET['transaction_search_type'] : '';
    if ($foxyshop_settings["orderdesk_url"]) {
        $orderdesk_link = ' <a class="' . (version_compare(get_bloginfo('version'), '3.2', "<") ? "button " : '') . 'add-new-h2" href="https://app.orderdesk.me/" target="_blank">' . __('Launch Order Desk', 'foxyshop') . '</a>';
    } else {
        $orderdesk_link = "";
    }
    ?>

	<div class="wrap">
		<div class="icon32 icon32-posts-page" id="icon-edit-pages"><br></div>
		<h2><?php 
    _e('Manage Orders', 'foxyshop');
    echo $orderdesk_link;
    ?>
</h2>


		<form action="edit.php" method="get" id="foxyshop_searchform" name="foxyshop_searchform" style="display: block; margin: 14px 0 20px 0;">
		<input type="hidden" name="foxyshop_search" value="1" />
		<input type="hidden" name="post_type" value="foxyshop_product" />
		<input type="hidden" name="page" value="foxyshop_order_management" />

		<table class="widefat">
		<thead><tr><th colspan="2"><img src="<?php 
    echo FOXYSHOP_DIR;
    ?>
/images/search-icon.png" alt="" /><?php 
    _e('Search Options', 'foxyshop');
    ?>
</th></tr></thead>
		<tbody><tr><td>

			<div class="foxyshop_field_control foxyshop_radio_label_container">
				<label><?php 
    _e('Transaction Status', 'foxyshop');
    ?>
</label>

				<input type="radio" id="hide_transaction_filter0" name="hide_transaction_filter" value="0"<?php 
    echo $foxy_data['hide_transaction_filter'] == 0 ? ' checked="checked"' : '';
    ?>
 />
				<label for="hide_transaction_filter0"><?php 
    _e('Unfilled', 'foxyshop');
    ?>
</label>

				<input type="radio" id="hide_transaction_filter1" name="hide_transaction_filter" value="1"<?php 
    echo $foxy_data['hide_transaction_filter'] == 1 ? ' checked="checked"' : '';
    ?>
 />
				<label for="hide_transaction_filter1"><?php 
    _e('Filled', 'foxyshop');
    ?>
</label>

				<input type="radio" id="hide_transaction_filter" name="hide_transaction_filter" value=""<?php 
    echo $foxy_data['hide_transaction_filter'] == '' ? ' checked="checked"' : '';
    ?>
 />
				<label for="hide_transaction_filter"><?php 
    _e('Both', 'foxyshop');
    ?>
</label>
			</div>

			<div class="foxyshop_field_control foxyshop_radio_label_container">
				<label><?php 
    _e('Datafeed Status', 'foxyshop');
    ?>
</label>

				<input type="radio" id="data_is_fed_filter0" name="data_is_fed_filter" value="0"<?php 
    echo $foxy_data['data_is_fed_filter'] == 0 ? ' checked="checked"' : '';
    ?>
 />
				<label for="data_is_fed_filter0"><?php 
    _e('Fed', 'foxyshop');
    ?>
</label>

				<input type="radio" id="data_is_fed_filter1" name="data_is_fed_filter" value="1"<?php 
    echo $foxy_data['data_is_fed_filter'] == 1 ? ' checked="checked"' : '';
    ?>
 />
				<label for="data_is_fed_filter1"><?php 
    _e('Unfed', 'foxyshop');
    ?>
</label>

				<input type="radio" id="data_is_fed_filter" name="data_is_fed_filter" value=""<?php 
    echo $foxy_data['data_is_fed_filter'] == '' ? ' checked="checked"' : '';
    ?>
 />
				<label for="data_is_fed_filter"><?php 
    _e('Both', 'foxyshop');
    ?>
</label>
			</div>

			<div class="foxyshop_field_control foxyshop_radio_label_container">
				<label><?php 
    _e('Test Transactions', 'foxyshop');
    ?>
</label>

				<input type="radio" id="is_test_filter0" name="is_test_filter" value="0"<?php 
    echo $foxy_data['is_test_filter'] == 0 ? ' checked="checked"' : '';
    ?>
 />
				<label for="is_test_filter0"><?php 
    _e('Live', 'foxyshop');
    ?>
</label>

				<input type="radio" id="is_test_filter1" name="is_test_filter" value="1"<?php 
    echo $foxy_data['is_test_filter'] == 1 ? ' checked="checked"' : '';
    ?>
 />
				<label for="is_test_filter1"><?php 
    _e('Test', 'foxyshop');
    ?>
</label>

				<input type="radio" id="is_test_filter" name="is_test_filter" value=""<?php 
    echo $foxy_data['is_test_filter'] == '' ? ' checked="checked"' : '';
    ?>
 />
				<label for="is_test_filter"><?php 
    _e('Both', 'foxyshop');
    ?>
</label>
			</div>

			<div class="foxyshop_field_control">
				<label for="order_id_filter"><?php 
    _e('Order ID', 'foxyshop');
    ?>
</label><input type="text" name="id_filter" id="id_filter" value="<?php 
    echo $foxy_data['id_filter'];
    ?>
" />
			</div>

			<div class="foxyshop_field_control">
				<label for="order_total_filter"><?php 
    _e('Order Total', 'foxyshop');
    ?>
</label><input type="text" name="order_total_filter" id="order_total_filter" value="<?php 
    echo $foxy_data['order_total_filter'];
    ?>
" />
			</div>

			<div class="foxyshop_field_control">
				<label for="coupon_code_filter"><?php 
    _e('Coupon Code', 'foxyshop');
    ?>
</label><input type="text" name="coupon_code_filter" id="coupon_code_filter" value="<?php 
    echo $foxy_data['coupon_code_filter'];
    ?>
" />
			</div>

			<div class="foxyshop_field_control">
				<label for="product_code_filter"><?php 
    echo FOXYSHOP_PRODUCT_NAME_SINGULAR . ' ' . __('Code', 'foxyshop');
    ?>
</label><input type="text" name="product_code_filter" id="product_code_filter" value="<?php 
    echo $foxy_data['product_code_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="product_name_filter"><?php 
    echo FOXYSHOP_PRODUCT_NAME_SINGULAR . ' ' . __('Name', 'foxyshop');
    ?>
</label><input type="text" name="product_name_filter" id="product_name_filter" value="<?php 
    echo $foxy_data['product_name_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="product_option_name_filter"><?php 
    echo FOXYSHOP_PRODUCT_NAME_SINGULAR . ' ' . __('Option Name', 'foxyshop');
    ?>
</label><input type="text" name="product_option_name_filter" id="product_option_name_filter" value="<?php 
    echo $foxy_data['product_option_name_filter'];
    ?>
" />
				<label for="product_option_value_filter" style="margin-left: 15px; margin-top: 4px; width: 34px;"><?php 
    _e('Value', 'foxyshop');
    ?>
</label><input type="text" name="product_option_value_filter" id="product_option_value_filter" value="<?php 
    echo $foxy_data['product_option_value_filter'];
    ?>
" />
			</div>

			<?php 
    if (version_compare($foxyshop_settings['version'], '0.7.2', ">=")) {
        ?>
			<div class="foxyshop_field_control">
				<label for="custom_field_name_filter"><?php 
        _e('Custom Field Name', 'foxyshop');
        ?>
</label><input type="text" name="custom_field_name_filter" id="custom_field_name_filter" value="<?php 
        echo $foxy_data['custom_field_name_filter'];
        ?>
" />
				<label for="custom_field_value_filter" style="margin-left: 15px; margin-top: 4px; width: 34px;"><?php 
        _e('Value', 'foxyshop');
        ?>
</label><input type="text" name="custom_field_value_filter" id="custom_field_value_filter" value="<?php 
        echo $foxy_data['custom_field_value_filter'];
        ?>
" />
			</div>
			<?php 
    }
    ?>

		</td><td>

			<div class="foxyshop_field_control">
				<label for="transaction_date_filter_begin"><?php 
    _e('Date Range', 'foxyshop');
    ?>
</label><input type="text" name="transaction_date_filter_begin" id="transaction_date_filter_begin" value="<?php 
    echo $foxy_data['transaction_date_filter_begin'];
    ?>
" class="foxyshop_date_field" />
				<span><?php 
    _e('to', 'foxyshop');
    ?>
</span><input type="text" name="transaction_date_filter_end" id="transaction_date_filter_end" value="<?php 
    echo $foxy_data['transaction_date_filter_end'];
    ?>
" class="foxyshop_date_field" />
			</div>



			<div class="foxyshop_field_control">
				<label for="customer_id_filter"><?php 
    _e('Customer ID', 'foxyshop');
    ?>
</label><input type="text" name="customer_id_filter" id="customer_id_filter" value="<?php 
    echo $foxy_data['customer_id_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_email_filter"><?php 
    _e('Customer Email', 'foxyshop');
    ?>
</label><input type="text" name="customer_email_filter" id="customer_email_filter" value="<?php 
    echo $foxy_data['customer_email_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_first_name_filter"><?php 
    _e('Customer First Name', 'foxyshop');
    ?>
</label><input type="text" name="customer_first_name_filter" id="customer_first_name_filter" value="<?php 
    echo $foxy_data['customer_first_name_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_last_name_filter"><?php 
    _e('Customer Last Name', 'foxyshop');
    ?>
</label><input type="text" name="customer_last_name_filter" id="customer_last_name_filter" value="<?php 
    echo $foxy_data['customer_last_name_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_state_filter"><?php 
    _e('Customer State', 'foxyshop');
    ?>
</label><input type="text" name="customer_state_filter" id="customer_state_filter" value="<?php 
    echo $foxy_data['customer_state_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="shipping_state_filter"><?php 
    _e('Shipping State', 'foxyshop');
    ?>
</label><input type="text" name="shipping_state_filter" id="shipping_state_filter" value="<?php 
    echo $foxy_data['shipping_state_filter'];
    ?>
" />
			</div>
			<div class="foxyshop_field_control">
				<label for="customer_ip_filter"><?php 
    _e('Customer IP', 'foxyshop');
    ?>
</label><input type="text" name="customer_ip_filter" id="customer_ip_filter" value="<?php 
    echo $foxy_data['customer_ip_filter'];
    ?>
" />
			</div>

			<div style="clear: both;"></div>
			<select name="transaction_search_type" id="transaction_search_type">
				<option value="show_orders"<?php 
    echo $transaction_search_type == "show_orders" ? ' selected="selected"' : '';
    ?>
><?php 
    _e('Show Orders', 'foxyshop');
    ?>
</option>
				<option value="print_recipts" target="_blank"><?php 
    _e('Print Receipts', 'foxyshop');
    ?>
</option>
				<?php 
    if (!$foxyshop_settings['enable_ship_to']) {
        ?>
				<option value="export_csv"><?php 
        _e('Export CSV', 'foxyshop');
        ?>
</option>
				<option value="export_tab"><?php 
        _e('Export Tab Delimeted', 'foxyshop');
        ?>
</option>
				<option value="export_ups"><?php 
        _e('Export to UPS', 'foxyshop');
        ?>
</option>
				<?php 
    }
    ?>
				<?php 
    do_action("foxyshop_order_search_list");
    ?>
			</select>
			<button type="submit" id="foxyshop_search_submit" name="foxyshop_search_submit" class="button-primary" style="clear: left; margin-top: 10px;"><?php 
    _e('Submit', 'foxyshop');
    ?>
</button>
			<button type="button" class="button submitcancel" style="margin-top: 10px;" onclick="document.location.href = 'edit.php?post_type=foxyshop_product&page=foxyshop_order_management';"><?php 
    _e('Reset', 'foxyshop');
    ?>
</button>

			<div style="clear: both;"></div>
			<?php 
    if (has_action('foxyshop_order_search_buttons')) {
        echo '<div id="foxyshop_order_search_buttons">';
        do_action("foxyshop_order_search_buttons", $foxy_data);
        echo '</div>';
    }
    ?>
		</td></tr></tbody></table>

		</form>

		<script type="text/javascript">
		jQuery(document).ready(function($) {
			$("#foxyshop_searchform button").live("click", function() {
				if ($("#transaction_search_type option:selected").attr("target") == "_blank") {
					$("#foxyshop_searchform").attr("target","_blank");
				} else {
					$("#foxyshop_searchform").attr("target","_self");
				}
			});
			$(".tablenav a.disabled").click(function() {
				return false;
			});

			$(".foxyshop_date_field").datepicker({ dateFormat: 'yy-mm-dd' });
		});
		</script>

	<?php 
    if (!isset($_GET['foxyshop_search']) && defined('FOXYSHOP_AUTO_API_DISABLED')) {
        return;
    }
    $foxy_response = foxyshop_get_foxycart_data($foxy_data);
    $xml = simplexml_load_string($foxy_response, NULL, LIBXML_NOCDATA);
    //var_dump($xml);
    if ((string) $xml->result == __('ERROR', 'foxyshop')) {
        echo '<h3>' . (string) $xml->messages->message . '</h3>';
        return;
    } else {
        ?>

		<form action="edit.php" method="get">
		<input type="hidden" name="foxyshop_search" value="1" />
		<input type="hidden" name="post_type" value="foxyshop_product" />
		<input type="hidden" name="page" value="foxyshop_order_management" />

		<?php 
        echo $foxyshop_hidden_input;
        foxyshop_api_paging_nav('transactions', 'top', $xml, $foxyshop_querystring);
        ?>

		<table cellpadding="0" cellspacing="0" border="0" class="wp-list-table widefat foxyshop-list-table" id="transaction_table">
			<thead>
				<tr>
					<th id="cb" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th>
					<th><span><?php 
        _e('Transaction ID', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Order Date', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Customer', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
        _e('Total', 'foxyshop');
        ?>
</span><span class="sorting-indicator"></span></th>
					<?php 
        do_action("foxyshop_order_table_head");
        ?>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<th class="manage-column column-cb check-column" style="" scope="col"><input type="checkbox"></th>
					<th><?php 
        _e('Transaction ID', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('OrderDate', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('Customer', 'foxyshop');
        ?>
</th>
					<th><?php 
        _e('Total', 'foxyshop');
        ?>
</th>
					<?php 
        do_action("foxyshop_order_table_foot");
        ?>
				</tr>
			</tfoot>
			<tbody id="the-list">

		<?php 
        $holder = "";
        $hide_transaction_filter = isset($_REQUEST['hide_transaction_filter']) ? $_REQUEST['hide_transaction_filter'] : 0;
        foreach ($xml->transactions->transaction as $transaction) {
            $transaction_id = (string) $transaction->id;
            $customer_first_name = (string) $transaction->customer_first_name;
            $customer_last_name = (string) $transaction->customer_last_name;
            $is_anonymous = (int) $transaction->is_anonymous;
            $customer_id = (string) $transaction->customer_id;
            $minfraud_score = (int) $transaction->minfraud_score;
            $transaction_date = (string) $transaction->transaction_date;
            $transaction_date = date(apply_filters("foxyshop_date_time_format", "Y-m-d H:i"), strtotime($transaction_date));
            $customer_name = $customer_last_name . ', ' . $customer_first_name;
            if ($is_anonymous != 1 && $customer_id) {
                $customer_name = '<a href="edit.php?post_type=foxyshop_product&page=foxyshop_customer_management&customer_id_filter=' . $customer_id . '&foxyshop_search=1" title="Customer ' . $customer_id . '">' . $customer_name . '</a>';
            }
            $print_receipt_link = "edit.php?foxyshop_search=1&amp;post_type=foxyshop_product&amp;page=foxyshop_order_management&amp;id_filter=" . $transaction_id . "&amp;foxyshop_print_invoice=1&amp;is_test_filter=&amp;skip_print=1&amp;transaction_date_filter_begin=" . $foxy_data['transaction_date_filter_begin'] . "&amp;transaction_date_filter_end=" . $foxy_data['transaction_date_filter_end'];
            foreach ($transaction->transaction_details->transaction_detail as $transaction_detail) {
                $pickup_day = "";
                $pickup_location = "";
                foreach ($transaction_detail->transaction_detail_options->transaction_detail_option as $transaction_detail_option) {
                    if ((string) $transaction_detail_option->product_option_name == "Pickup_Day") {
                        $pickup_day = (string) $transaction_detail_option->product_option_value;
                    } elseif ((string) $transaction_detail_option->product_option_name == "Pickup_Location") {
                        $pickup_location = (string) $transaction_detail_option->product_option_value;
                    }
                    $holder .= '<li>';
                    $holder .= str_replace("_", " ", (string) $transaction_detail_option->product_option_name) . ': ';
                    if (substr((string) $transaction_detail_option->product_option_value, 0, 5) == "file-") {
                        $upload_dir = wp_upload_dir();
                        $holder .= '<a href="' . $upload_dir['baseurl'] . '/customuploads/' . (string) $transaction_detail_option->product_option_value . '" target="_blank">' . (string) $transaction_detail_option->product_option_value . '</a>';
                    } else {
                        $holder .= $transaction_detail_option->product_option_value;
                    }
                    if ((string) $transaction_detail_option->price_mod != '0.000') {
                        $holder .= ' (' . (strpos("-", $transaction_detail_option->price_mod) !== false ? '-' : '+') . foxyshop_currency((double) $transaction_detail_option->price_mod) . ')';
                    }
                    $holder .= '</li>';
                }
            }
            echo '<tr rel="' . $transaction_id . '">';
            echo '<th class="check-column" scope="row"><input type="checkbox" value="' . $transaction_id . '" name="post[]"></th>' . "\n";
            echo '<td>';
            echo '<a href="' . (string) $transaction->receipt_url . '" title="' . __('FoxyCart Receipt', 'foxyshop') . '" target="_blank" style="float: left;"><img src="' . FOXYSHOP_DIR . '/images/foxycart-icon.png" alt="" align="top" /></a>';
            echo '<strong><a href="#" class="view_detail" style="float: left; line-height: 18px; margin: 0 0 0 5px;">' . $transaction_id . '</a></strong>';
            echo '<div class="row-actions">';
            echo '<span><a href="#" class="view_detail">' . __('View Order', 'foxyshop') . '</a> | </span>';
            echo '<span><a href="' . $print_receipt_link . '" title="' . __('Printable Receipt', 'foxyshop') . '" target="_blank">' . __('Receipt', 'foxyshop') . '</a></span>';
            if (!isset($transaction->is_hidden)) {
                $is_hidden = $hide_transaction_filter;
            } else {
                $is_hidden = (string) $transaction->is_hidden;
            }
            if ($is_hidden == 1) {
                echo '<span> | <a href="#" class="set_order_hidden_status" rel="0">' . __('Un-Archive', 'foxyshop') . '</a></span>';
            } else {
                echo '<span> | <a href="#" class="set_order_hidden_status" rel="1">' . __('Archive', 'foxyshop') . '</a></span>';
            }
            do_action("foxyshop_order_line_item", $transaction);
            echo '</div>';
            echo '</td>';
            echo '<td>' . $transaction_date . '</td>';
            echo '<td>' . $customer_name . '</td>';
            echo '<td>' . foxyshop_currency((double) $transaction->order_total) . '</td>';
            do_action("foxyshop_order_line_end", $transaction);
            echo '</tr>' . "\n";
            //Write Out Order Details Holder
            $holder .= '<div class="detail_holder" id="holder_' . $transaction_id . '">' . "\n";
            $holder .= '<div class="foxyshop_list_col">';
            $holder .= '<h4>' . __('Transaction Details', 'foxyshop') . '</h4>';
            $holder .= '<ul>';
            $holder .= '<li>' . __('Order ID', 'foxyshop') . ': ' . (string) $transaction->id . '</li>';
            $holder .= '<li>' . __('Date', 'foxyshop') . ': ' . $transaction_date . '</li>';
            $holder .= '<li>' . (string) $transaction->processor_response . '</li>';
            if ((string) $transaction->cc_number_masked != "") {
                $holder .= '<li>' . __('Card', 'foxyshop') . ': ' . (string) $transaction->cc_number_masked . ' (' . (string) $transaction->cc_type . ')</li>';
            }
            if ((string) $transaction->cc_exp_month != "") {
                $holder .= '<li>' . __('Exp', 'foxyshop') . ': ' . (string) $transaction->cc_exp_month . '-' . (string) $transaction->cc_exp_year . '</li>';
            }
            if ($minfraud_score > 0) {
                $holder .= '<li>' . __('MinFraud Score', 'foxyshop') . ': ' . $minfraud_score . '</li>';
            }
            if ((string) $transaction->shipto_shipping_service_description != "") {
                $holder .= '<li>' . __('Shipping Type', 'foxyshop') . ': ' . (string) $transaction->shipto_shipping_service_description . '</li>';
            }
            if ((string) $transaction->processor_response == "Purchase Order") {
                $holder .= '<li>PO #: ' . (string) $transaction->purchase_order . '</li>';
            }
            $holder .= '</ul>';
            $holder .= '</div>';
            $holder .= '<div class="foxyshop_list_col">';
            $holder .= '<h4>' . __('Order Details', 'foxyshop') . '</h4>';
            $holder .= '<ul>';
            $holder .= '<li>' . __('Subtotal', 'foxyshop') . ': ' . foxyshop_currency((double) $transaction->product_total) . '</li>';
            //Discounts
            foreach ($transaction->discounts->discount as $discount) {
                $holder .= '<li>' . (string) $discount->name . ': ' . foxyshop_currency((double) $discount->amount) . '</li>';
            }
            //Taxes
            foreach ($transaction->taxes->tax as $tax) {
                $holder .= '<li>' . (string) $tax->tax_name . ': ' . foxyshop_currency((double) $tax->tax_amount) . '</li>';
            }
            $holder .= '<li>' . __('Shipping', 'foxyshop') . ': ' . foxyshop_currency((double) $transaction->shipping_total) . '</li>';
            $holder .= '<li><strong>' . __('Order Total', 'foxyshop') . ': ' . foxyshop_currency((double) $transaction->order_total) . '</strong></li>';
            $holder .= '</ul>';
            $holder .= '</div>';
            $holder .= '<div class="foxyshop_list_col">';
            $holder .= '<h4>' . __('Customer Address', 'foxyshop') . '</h4>';
            $holder .= '<ul>';
            $holder .= '<li>' . (string) $transaction->customer_first_name . ' ' . (string) $transaction->customer_last_name . '</li>';
            if ((string) $transaction->customer_company != "") {
                $holder .= '<li>' . (string) $transaction->customer_company . '</li>';
            }
            $holder .= '<li>' . (string) $transaction->customer_address1 . '</li>';
            if ((string) $transaction->customer_address2 != "") {
                $holder .= '<li>' . (string) $transaction->customer_address2 . '</li>';
            }
            $holder .= '<li>' . (string) $transaction->customer_city . ', ' . (string) $transaction->customer_state . ' ' . (string) $transaction->customer_postal_code . '</li>';
            $holder .= '<li>' . (string) $transaction->customer_country . '</li>';
            $holder .= '</ul>';
            $holder .= '</div>';
            //Shipping Addresses (if entered)
            if ((string) $transaction->shipping_first_name != "" && !isset($transaction->shipto_addresses->shipto_address)) {
                $holder .= '<div class="foxyshop_list_col">';
                $holder .= '<h4>' . __('Shipping Details', 'foxyshop') . '</h4>';
                $holder .= '<ul>';
                $holder .= '<li>' . (string) $transaction->shipping_first_name . ' ' . (string) $transaction->shipping_last_name . '</li>';
                if ((string) $transaction->shipping_company != "") {
                    $holder .= '<li>' . (string) $transaction->shipping_company . '</li>';
                }
                $holder .= '<li>' . (string) $transaction->shipping_address1 . '</li>';
                if ((string) $transaction->shipping_address2 != "") {
                    $holder .= '<li>' . (string) $transaction->shipping_address2 . '</li>';
                }
                $holder .= '<li>' . (string) $transaction->shipping_city . ', ' . (string) $transaction->shipping_state . ' ' . (string) $transaction->shipping_postal_code . '</li>';
                $holder .= '<li>' . (string) $transaction->shipping_country . '</li>';
                if ((string) $transaction->shipping_phone != "") {
                    $holder .= '<li>' . (string) $transaction->shipping_phone . '</li>';
                }
                $holder .= '</ul>';
                $holder .= '</div>';
            }
            //Multi-ship Addresses
            foreach ($transaction->shipto_addresses->shipto_address as $shipto_address) {
                $holder .= '<div class="foxyshop_list_col">';
                $holder .= '<h4>' . __('Shipping Details', 'foxyshop') . ': ' . $shipto_address->address_name . '</h4>';
                $holder .= '<ul>';
                $holder .= '<li>' . $shipto_address->shipto_first_name . ' ' . $shipto_address->shipto_last_name . '</li>';
                if ((string) $shipto_address->shipto_company != "") {
                    $holder .= '<li>' . $shipto_address->shipto_company . '</li>';
                }
                $holder .= '<li>' . $shipto_address->shipto_address1 . '</li>';
                if ((string) $shipto_address->shipto_address2 != "") {
                    $holder .= '<li>' . $shipto_address->shipto_address2 . '</li>';
                }
                $holder .= '<li>' . $shipto_address->shipto_city . ', ' . $shipto_address->shipto_state . ' ' . $shipto_address->shipto_postal_code . '</li>';
                $holder .= '<li>' . $shipto_address->shipto_country . '</li>';
                if ((string) $shipto_address->shipto_phone != "") {
                    $holder .= '<li>' . $shipto_address->shipto_phone . '</li>';
                }
                $holder .= '<li><br />' . __('Method', 'foxyshop') . ': ' . $shipto_address->shipto_shipping_service_description . '</li>';
                $holder .= '<li>' . __('Shipping', 'foxyshop') . ': ' . foxyshop_currency((double) $shipto_address->shipto_shipping_total) . '</li>';
                $holder .= '</ul>';
                $holder .= '</div>';
            }
            //Customer Details
            $holder .= '<div class="foxyshop_list_col">';
            $holder .= '<h4>' . __('Customer Details', 'foxyshop') . '</h4>';
            $holder .= '<ul>';
            if ((string) $transaction->customer_phone != "") {
                $holder .= '<li>' . (string) $transaction->customer_phone . '</li>';
            }
            $holder .= '<li><a href="mailto:' . (string) $transaction->customer_email . '">' . (string) $transaction->customer_email . '</a></li>';
            $holder .= '<li>' . apply_filters('foxyshop_order_ip', '<a href="http://whatismyipaddress.com/ip/' . (string) $transaction->customer_ip . '" target="_blank">' . (string) $transaction->customer_ip . '</a>', (string) $transaction->customer_ip) . '</li>';
            $holder .= '<li>&nbsp;</li>';
            //Custom Fields
            foreach ($transaction->custom_fields->custom_field as $custom_field) {
                if ($custom_field->custom_field_name != 'ga') {
                    $holder .= '<li><strong>' . str_replace("_", " ", (string) $custom_field->custom_field_name) . ':</strong> ' . nl2br((string) $custom_field->custom_field_value) . '</li>';
                }
            }
            $holder .= '</ul>';
            $holder .= '</div>';
            //Custom Attributes
            $holder .= foxyshop_manage_attributes($transaction->attributes, $transaction_id, "transaction");
            $holder .= '<div style="clear: both; height: 20px;"></div>';
            foreach ($transaction->transaction_details->transaction_detail as $transaction_detail) {
                $holder .= '<div class="product_listing">';
                if ($transaction_detail->image != "") {
                    $holder .= '<div class="image_div">';
                    if ($transaction_detail->url != "") {
                        $holder .= '<a href="' . $transaction_detail->url . '" target="_blank">';
                    }
                    $holder .= '<img src="' . $transaction_detail->image . '" />';
                    if ($transaction_detail->url != "") {
                        $holder .= '</a>';
                    }
                    $holder .= '</div>';
                }
                $product_discount = 0;
                $weight_discount = 0;
                foreach ($transaction_detail->transaction_detail_options->transaction_detail_option as $transaction_detail_option) {
                    $product_discount += (double) $transaction_detail_option->price_mod;
                    $weight_discount += (double) $transaction_detail_option->weight_mod;
                }
                $holder .= '<div class="details_div">';
                $holder .= '<h4>' . $transaction_detail->product_name . '</h4>';
                $holder .= '<ul>';
                if ((string) $transaction_detail->shipto != "") {
                    $holder .= '<li>Ship To: ' . (string) $transaction_detail->shipto . '</li>';
                }
                $holder .= '<li>' . __('Code', 'foxyshop') . ': ' . (string) $transaction_detail->product_code . '</li>';
                $holder .= '<li>' . __('Price', 'foxyshop') . ': ' . foxyshop_currency((double) $transaction_detail->product_price) . '</li>';
                if ($product_discount != 0) {
                    $holder .= '<li>Adjusted Price: ' . foxyshop_currency((double) $transaction_detail->product_price + $product_discount) . '</li>';
                }
                $holder .= '<li>' . __('Qty', 'foxyshop') . ': ' . $transaction_detail->product_quantity . '</li>';
                if ((string) $transaction_detail->product_weight != "0.000") {
                    $holder .= '<li>Weight: ' . (string) $transaction_detail->product_weight . '</li>';
                }
                if ($weight_discount != 0) {
                    $holder .= '<li>Adjusted Weight: ' . ((double) $transaction_detail->product_weight + $weight_discount) . '</li>';
                }
                if ((string) $transaction_detail->category_code != "DEFAULT") {
                    $holder .= '<li>Category: ' . (string) $transaction_detail->category_description . '</li>';
                }
                if ((string) $transaction_detail->product_delivery_type != "shipped") {
                    $holder .= '<li>Delivery Type: ' . (string) $transaction_detail->product_delivery_type . '</li>';
                }
                if ((string) $transaction_detail->downloadable_url != "") {
                    $holder .= '<li>Downloadable URL: <a href="' . (string) $transaction_detail->downloadable_url . '" target="_blank">Click Here</a></li>';
                }
                if ($transaction_detail->subscription_frequency != "") {
                    $holder .= '<li>' . __('Subscription Frequency', 'foxyshop') . ': ' . (string) $transaction_detail->subscription_frequency . '</li>';
                    $holder .= '<li>' . __('Subscription Start Date', 'foxyshop') . ': ' . (string) $transaction_detail->subscription_startdate . '</li>';
                    $holder .= '<li>' . __('Subscription Next Date', 'foxyshop') . ': ' . (string) $transaction_detail->subscription_nextdate . '</li>';
                    if ((string) $transaction_detail->subscription_enddate != "0000-00-00") {
                        $holder .= '<li>Subscription End Date: ' . (string) $transaction_detail->subscription_enddate . '</li>';
                    }
                }
                foreach ($transaction_detail->transaction_detail_options->transaction_detail_option as $transaction_detail_option) {
                    $holder .= '<li>';
                    $holder .= str_replace("_", " ", (string) $transaction_detail_option->product_option_name) . ': ';
                    if (substr((string) $transaction_detail_option->product_option_value, 0, 5) == "file-") {
                        $upload_dir = wp_upload_dir();
                        $holder .= '<a href="' . $upload_dir['baseurl'] . '/customuploads/' . (string) $transaction_detail_option->product_option_value . '" target="_blank">' . (string) $transaction_detail_option->product_option_value . '</a>';
                    } else {
                        $holder .= $transaction_detail_option->product_option_value;
                    }
                    if ((string) $transaction_detail_option->price_mod != '0.000') {
                        $holder .= ' (' . (strpos("-", $transaction_detail_option->price_mod) !== false ? '-' : '+') . foxyshop_currency((double) $transaction_detail_option->price_mod) . ')';
                    }
                    $holder .= '</li>';
                }
                $holder .= '</ul>';
                $holder .= '</div>';
                $holder .= '<div style="clear: both;"></div>';
                $holder .= '</div>';
            }
            $holder .= '<div style="clear: both; height: 10px;"></div>';
            $holder .= '</div>';
        }
        echo '</tbody></table>';
        foxyshop_api_paging_nav('transactions', 'bottom', $xml, $foxyshop_querystring);
        ?>
		</form>
	<?php 
    }
    ?>


	<div id="details_holder"><?php 
    echo $holder;
    ?>
</div>

	<script type="text/javascript" src="<?php 
    echo FOXYSHOP_DIR;
    ?>
/js/jquery.tablesorter.js"></script>
	<script type="text/javascript">
	jQuery(document).ready(function($){
		$(".foxyshop-list-table thead th").click(function() {
			$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
			$("#foxyshop-list-inline").remove();
		});
		$(".foxyshop-list-table").tablesorter({
			'cssDesc': 'asc sorted',
			'cssAsc': 'desc sorted',
			'headers': { 0: { sorter: false} }
		});
		$(".view_detail").click(function() {
			var id = $(this).parents("tr").attr("rel");

			if ($("#foxyshop-list-inline #holder_" + id).length > 0) {
				$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
				$("#foxyshop-list-inline").remove();
			} else {
				$("#foxyshop-list-inline .detail_holder").appendTo("#details_holder");
				$("#foxyshop-list-inline").remove();

				$(this).parents("tr").after('<tr id="foxyshop-list-inline"><td colspan="7"></td></tr>');
				$("#holder_"+id).appendTo("#foxyshop-list-inline td");
			}

			return false;
		});



		$(".set_order_hidden_status").click( function() {
			var hide_transaction = $(this).attr("rel");
			var transaction_id = $(this).parents("tr").attr("rel");
			var data = {
				action: 'foxyshop_display_list_ajax_action',
				security: '<?php 
    echo wp_create_nonce("foxyshop-display-list-function");
    ?>
',
				hide_transaction: hide_transaction,
				foxyshop_action: 'hide_transaction',
				id: transaction_id
			};
			$.post(ajaxurl, data, function(response) {
			<?php 
    if ($hide_transaction_filter == "0") {
        ?>
				$("tr[rel="+transaction_id+"]").remove();
				$("#foxyshop-list-inline #holder_" + transaction_id).remove();
			<?php 
    } else {
        ?>
				alert(response);
			<?php 
    }
    ?>
			});

			return false;
		});

		<?php 
    foxyshop_manage_attributes_jquery('transaction');
    ?>

	});
	</script>


	<?php 
}