function foxyshop_subscription_template($id)
{
    global $product, $foxyshop_settings;
    $original_product = $product;
    $template_id = get_posts(array('post_type' => 'foxyshop_product', 'p' => $id));
    foreach ($template_id as $the_template_id) {
        $product = foxyshop_setup_product($the_template_id);
        if ($product['quantity_min'] == 0) {
            $product['quantity_min'] = 1;
        }
        if (!$product['category']) {
            $product['category'] = "DEFAULT";
        }
        if (!$product['weight']) {
            $product['weight'] = "0";
        }
        $product = apply_filters("foxyshop_template_transaction_product_array", $product);
        $xml = "<transaction_template>\n";
        $xml .= "\t<custom_fields />\n";
        $xml .= "\t<discounts />\n";
        $xml .= "\t<transaction_details>\n";
        $xml .= "\t<transaction_detail>\n";
        $xml .= "\t\t<product_name><![CDATA[" . $product['name'] . "]]></product_name>\n";
        $xml .= "\t\t<product_price><![CDATA[" . $product['price'] . "]]></product_price>\n";
        $xml .= "\t\t<product_quantity><![CDATA[" . $product['quantity_min'] . "]]></product_quantity>\n";
        $xml .= "\t\t<product_weight><![CDATA[" . $product['weight'] . "]]></product_weight>\n";
        $xml .= "\t\t<product_code><![CDATA[" . $product['code'] . "]]></product_code>\n";
        $xml .= "\t\t<image><![CDATA[" . foxyshop_get_main_image() . "]]></image>\n";
        $xml .= "\t\t<url><![CDATA[" . $product['url'] . "]]></url>\n";
        $xml .= "\t\t<category_code><![CDATA[" . $product['category'] . "]]></category_code>\n";
        $xml .= "\t\t<transaction_detail_options />\n";
        $xml .= "\t</transaction_detail>\n";
        $xml .= "\t</transaction_details>\n";
        $xml .= "</transaction_template>";
        $xml = apply_filters("foxyshop_template_transaction_xml", $xml, $product);
    }
    $product = $original_product;
    return $xml;
}
function foxyshop_google_products_page()
{
    global $foxyshop_settings, $product;
    $local_products = array();
    $google_icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABh0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzT7MfTgAAABZ0RVh0Q3JlYXRpb24gVGltZQAwNy8xNS8xMMjfMS0AAAQRdEVYdFhNTDpjb20uYWRvYmUueG1wADw/eHBhY2tldCBiZWdpbj0iICAgIiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+Cjx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDQuMS1jMDM0IDQ2LjI3Mjk3NiwgU2F0IEphbiAyNyAyMDA3IDIyOjM3OjM3ICAgICAgICAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp4YXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iPgogICAgICAgICA8eGFwOkNyZWF0b3JUb29sPkFkb2JlIEZpcmV3b3JrcyBDUzM8L3hhcDpDcmVhdG9yVG9vbD4KICAgICAgICAgPHhhcDpDcmVhdGVEYXRlPjIwMTAtMDctMTVUMTk6MDU6MDFaPC94YXA6Q3JlYXRlRGF0ZT4KICAgICAgICAgPHhhcDpNb2RpZnlEYXRlPjIwMTAtMDctMTVUMTk6MTg6MDBaPC94YXA6TW9kaWZ5RGF0ZT4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgICAgIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiCiAgICAgICAgICAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyI+CiAgICAgICAgIDxkYzpmb3JtYXQ+aW1hZ2UvcG5nPC9kYzpmb3JtYXQ+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDBS8igAAAJlSURBVDiNfY9PSFRhFMV/33uvcRzfzKijmQr5jyzFciGFldlGiRCCoAIhqFy0CdpE0Sao3Ei1CtdBuAjDhdBSQiw3SaM5IBpkJTlRaprydJznvO+2sNRJ68CBy733nHuuisfjLVNf4k+fReciI1+TWCa0HLA5VhIAwHOcBR48sMyVlSC/IUohhhHLTCTOWfPz80+GZndFuqdCaAxYg/GYoqd2L1UFGQA50tCwRGfnHz3aMHBs+9DP7OxuKxAI7P64Ksx5gqDWNzx49CZJ75Wi9Yv19SF97x5bEwQcB0+pWsu2bUIBF9GarXg37WwKEgm0UmlzXzJJ1vKyYZimSWNFELSXRncttRl5eJj56hKGT1cxfLqKlXAmIoLyPCyA5v1hmitt+t4vbogayrI36ktHRni+bxpPvPXGBQiuMna7z3LNoqard+srcjlTk8v3pSSLiRSNFUEenysn5DfpmuyifeIhIpL2gmuxe7TMX6jybg7KxeOlXD+RT1mub3NBu7S/a6cj1rF5+S9E1iKovBsD8kNnbTT7r1VysiJIa38r3Z+6dxRuGKQiGOgUWzk05eBql5qcGsJWGDT/pSq79VLOHy3nVHUO4UyT4rCPPaH1V+LLcdoG2uib7vtnAhWb/CoHywsBEOcDOB/AXUAVnwXTj6tdml40MfhtcGeDufiE5Cz1IrOv06f+AozqO6isUqKzUQ73HN5u4EUw9HgHMvMKRNKZ+IYeuw+Soi6/DtuyQdhGQ7tLo6Jlu8FvE3E+A+BpL02oRKFEvTWUyOVkyoztaGL4Uf4CojNREmuJNHGGlzHk077WXxkiNLGzmnadAAAAAElFTkSuQmCC";
    $debug_querystring = isset($_GET['debug']) ? "&amp;debug=1" : "";
    ?>
	<?php 
    if (!$foxyshop_settings['google_product_auth']) {
        ?>
		<div class="wrap">
		<div class="icon32" id="icon-tools"><br></div>
		<h2>Google Products Management - Authentication Required</h2>

		<table class="widefat" style="margin-top: 14px;">
			<thead>
				<tr>
					<th><img src="<?php 
        echo $google_icon;
        ?>
" alt="" /><?php 
        _e("Google Authentication Required", 'foxyshop');
        ?>
</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>
						<p>To view and manage your Google Products you need to log in to your Google Account. Your username and password are not saved withing FoxyShop, but are passed directly to Google for authentication. If authenticated, Google will issue an auth key that will be stored with your store settings. This auth key will expire after two weeks at which point you will need to authenticate again.</p>

						<form onsubmit="return false;" autocomplete="off" style="display: block; margin-bottom: 10px;">

						<div class="foxyshop_field_control">
							<label for="Email"><?php 
        echo __('Email');
        ?>
</label>
							<input type="text" id="Email" name="Email" value="" />
						</div>

						<div class="foxyshop_field_control">
							<label for="Passwd"><?php 
        echo __('Password');
        ?>
</label>
							<input type="password" id="Passwd" name="Passwd" value="" />
						</div>

						<div style="clear: both; height: 4px;"></div>

						<button class="button-primary" id="authnow">Authenticate Now</button>
						</form>

						<div id="error" style="color: red; margin-top: 10px; font-weight: bold; display: none;"></div>


						<script type="text/javascript">
						jQuery(document).ready(function($){

							$("#authnow").click(function() {
								var data = {
									action: 'foxyshop_set_google_auth',
									security: '<?php 
        echo wp_create_nonce("foxyshop-ajax-set-google-auth");
        ?>
',
									Email: $("#Email").val(),
									Passwd: $("#Passwd").val()
								};
								$("#error").hide();
								$.post(ajaxurl, data, function(response) {
									if (!response) {
										$("#error").text("Error: No Response").show();
									} else if (response == "Error") {
										$("#error").text("Error: Login Failed. Please try again.").show();
									} else if (response == "Success") {
										$("#error").hide();
										location.reload();
									} else {
										$("#error").text("Error: " + response).show();
									}
								});
							});
						});
						</script>


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


	<?php 
    } else {
        ?>
		<div class="wrap">
		<div class="icon32" id="icon-tools"><br></div>
		<h2>Google Products Management <a class="<?php 
        if (version_compare(get_bloginfo('version'), '3.2', "<")) {
            echo "button ";
        }
        ?>
add-new-h2" href="edit.php?post_type=foxyshop_product&amp;page=foxyshop_google_products_page&amp;foxyshop_google_products_update=1&amp;googleprodlogout=1&amp;_wpnonce=<?php 
        echo wp_create_nonce('gp1');
        ?>
">De-Authenticate</a></h2>
		<?php 
        //Display Confirmations and Errors
        if (isset($_GET['error'])) {
            echo '<div class="error"><p><strong>Error!</strong><br /><ul style="margin: 0 10px;">';
            $error_list = explode("||", $_GET['error']);
            foreach ($error_list as $the_error) {
                if ($the_error) {
                    echo "<li style=\"list-style: disc inside none;\">{$the_error}</li>\n";
                }
            }
            echo '</ul></p></div>';
        } elseif (isset($_GET['success'])) {
            echo '<div class="updated"><p>' . __('Operation completed successfully.') . '</p></div>';
        }
        //Get All Local Product ID's
        $args = array('post_type' => 'foxyshop_product', 'post_status' => 'publish', 'numberposts' => "-1", "orderby" => "id", "order" => "ASC", "meta_key" => "_google_product_category", "meta_compare" => "!=", "meta_value" => "");
        $product_list = get_posts($args);
        foreach ($product_list as $single_product) {
            $local_products[] = $single_product->ID;
        }
        //Get Feed
        $header_array = array("Authorization: GoogleLogin auth=" . $foxyshop_settings['google_product_auth']);
        $url = "https://content.googleapis.com/content/v1/" . $foxyshop_settings['google_product_merchant_id'] . "/items/products/schema?performance.start=" . date("Y-m-d", strtotime("-30 days")) . "&max-results=250&performance.end=" . date("Y-m-d", strtotime("now"));
        if (isset($_GET['nextlink'])) {
            $url = $_GET['nextlink'];
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        $response = trim(curl_exec($ch));
        $xml = preg_replace("/(<\\/?)(\\w+):([^>]*>)/", "\$1\$2\$3", $response);
        $xml = simplexml_load_string($xml, NULL, LIBXML_NOCDATA);
        //Check For Next Link
        $nextlink = "";
        foreach ($xml->link as $link) {
            $thisone = 0;
            foreach ($link->attributes() as $a => $b) {
                if ($a == "rel" && $b == "next") {
                    $thisone = 1;
                }
                if ($thisone && $a == "href") {
                    $nextlink = $b;
                }
            }
        }
        //Token Has Expired, Remove and Restart Authentication
        if ((string) $xml->BODY->H1 == "Token invalid" || (string) $xml->BODY->H1 == "Token expired") {
            $foxyshop_settings['google_product_auth'] = "";
            update_option("foxyshop_settings", $foxyshop_settings);
            $local_products = array();
            echo '<div class="updated"><p>' . __('Authentication Failed. It appears that your authentication has expired. This happens every two weeks. Please login again.') . '</p></div>';
            echo '<p><a href="edit.php?post_type=foxyshop_product&amp;page=foxyshop_google_products_page" class="button">Login Now</a></p>';
        } else {
            ?>

		<form action="edit.php?post_type=foxyshop_product&page=foxyshop_google_products_page&foxyshop_manage_google_feed=1" method="post">

		<table cellpadding="0" cellspacing="0" border="0" class="wp-list-table widefat foxyshop-list-table" id="product_feed_view" style="margin-top: 14px;">
			<thead>
				<tr>
					<th id="cb" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th>
					<th class="column-id"><span><?php 
            _e('ID', 'foxyshop');
            ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
            _e('Name', 'foxyshop');
            ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
            _e('Image', 'foxyshop');
            ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
            _e('Expiration', 'foxyshop');
            ?>
</span><span class="sorting-indicator"></span></th>
					<th><span><?php 
            _e('Performance', 'foxyshop');
            ?>
</span><span class="sorting-indicator"></span></th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<th class="manage-column column-cb check-column" style="" scope="col"><input type="checkbox"></th>
					<th><?php 
            _e('ID', 'foxyshop');
            ?>
</th>
					<th><?php 
            _e('Name', 'foxyshop');
            ?>
</th>
					<th><?php 
            _e('Image', 'foxyshop');
            ?>
</th>
					<th><?php 
            _e('Expiration', 'foxyshop');
            ?>
</th>
					<th><?php 
            _e('Performance', 'foxyshop');
            ?>
</th>
				</tr>
			</tfoot>
			<tbody>
		<?php 
            if (count($xml->entry) == 0) {
                echo '<tr class="no-items"><td colspan="6" class="colspanchange">No entries found.</td></tr>';
            }
            foreach ($xml->entry as $entry) {
                $expiration_date = (string) $entry->scexpiration_date;
                $expiration_date = substr($expiration_date, 0, strpos($expiration_date, "T"));
                $clicks = 0;
                foreach ($entry->scperformance->scdatapoint as $scdatapoint) {
                    $clicks += $scdatapoint->attributes()->clicks;
                }
                $google_product_id = (string) $entry->scid;
                if (in_array($google_product_id, $local_products)) {
                    $local_products = array_diff($local_products, array($google_product_id));
                    $unmatched_text = "";
                } else {
                    $unmatched_text = "<br /><em>" . __('Unmatched!', 'foxyshop') . "</em>\n";
                }
                echo '<tr>' . "\n";
                echo '<th class="check-column" scope="row"><input type="checkbox" value="' . $google_product_id . '" name="post[]"></th>' . "\n";
                echo '<td><strong>' . $google_product_id . '</strong>' . $unmatched_text . '</td>' . "\n";
                if ($unmatched_text == "") {
                    echo '<td><strong><a href="post.php?post=' . $google_product_id . '&action=edit">' . (string) $entry->title . '</a></strong>';
                    echo '<div class="row-actions">';
                    echo '<span><a href="edit.php?foxyshop_manage_google_feed=1&amp;editid=' . $google_product_id . $debug_querystring . '&amp;_wpnonce=' . wp_create_nonce("manage-the-google-feed-settings") . '" class="update_google_product" rel="' . $google_product_id . '">' . __('Renew/Update', 'foxyshop') . '</a> | </span>';
                    echo '<span class="delete"><a href="edit.php?foxyshop_manage_google_feed=1&amp;deleteid=' . $google_product_id . $debug_querystring . '&amp;_wpnonce=' . wp_create_nonce("manage-the-google-feed-settings") . '" class="delete_google_product" rel="' . $google_product_id . '">' . __('Delete', 'foxyshop') . '</a></span>';
                    echo '</div>';
                    echo '</td>' . "\n";
                } else {
                    echo '<td><strong><a href="#" onclick="return false;">' . (string) $entry->title . '</a></strong>';
                    echo '<div class="row-actions">';
                    echo '<span class="delete"><a href="edit.php?foxyshop_manage_google_feed=1&amp;deleteid=' . $google_product_id . $debug_querystring . '&amp;_wpnonce=' . wp_create_nonce("manage-the-google-feed-settings") . '" class="delete_google_product" rel="' . $google_product_id . '">' . __('Delete', 'foxyshop') . '</a></span>';
                    echo '</div>';
                    echo '</td>' . "\n";
                }
                if ((string) $entry->scimage_link) {
                    echo '<td><img src="' . (string) $entry->scimage_link . '" class="productfeedimage" /></td>' . "\n";
                } else {
                    echo '<td>&nbsp;</td>' . "\n";
                }
                echo '<td>' . $expiration_date . '</td>' . "\n";
                echo '<td>' . $clicks . ' Click' . ($clicks != 1 ? 's' : '') . '</td>' . "\n";
                echo '</tr>' . "\n";
            }
            ?>
			</tbody>
		</table>
		<div style="padding-top: 10px;">
			<button type="submit" class="button" name="update_checked_google_products" value="1" id="update_checked_google_products">Update/Renew Checked <?php 
            echo FOXYSHOP_PRODUCT_NAME_PLURAL;
            ?>
</button>
			&nbsp;&nbsp;&nbsp;
			<button type="submit" class="button" name="delete_checked_google_products" value="1" id="delete_checked_google_products">Delete Checked <?php 
            echo FOXYSHOP_PRODUCT_NAME_PLURAL;
            ?>
</button>

			<?php 
            if ($nextlink) {
                echo '<a href="edit.php?post_type=foxyshop_product&page=foxyshop_google_products_page&nextlink=' . urlencode($nextlink) . '" class="button" style="float: right;">Next Page</a>';
            }
            ?>

		</div>
		<input type="hidden" name="foxyshop_run_the_xml" value="1" />
		<?php 
            wp_nonce_field('manage-the-google-feed-settings');
            ?>
		<?php 
            if (isset($_GET['debug'])) {
                echo '<input type="hidden" name="debug" value="1" />';
            }
            ?>
		</form>
		<?php 
        }
        //Display All Unmatched Products
        $meta_query = array('relation' => 'OR', array('key' => '_google_product_category', 'value' => "", 'compare' => '!='));
        $args = array('post_type' => 'foxyshop_product', 'post_status' => 'publish', 'numberposts' => "100", "orderby" => "id", "order" => "ASC", "meta_query" => $meta_query);
        $product_list = get_posts($args);
        if ($product_list) {
            ?>
			<h2 style="padding: 100px 0 0 0;">Available, Unmatched <?php 
            echo FOXYSHOP_PRODUCT_NAME_PLURAL;
            ?>
 to Add</h2>
			<p style="margin: 0;">In order to appear in this list, <?php 
            echo strtolower(FOXYSHOP_PRODUCT_NAME_PLURAL);
            ?>
 must have a "Google Product Category" attribute.</p>

			<form action="edit.php?post_type=foxyshop_product&page=foxyshop_google_products_page&foxyshop_manage_google_feed=1" method="post">

			<table cellpadding="0" cellspacing="0" border="0" class="wp-list-table widefat foxyshop-list-table" id="available_product_view" style="margin-top: 14px;">
				<thead>
					<tr>
						<th id="cb" class="manage-column column-cb check-column" scope="col"><input type="checkbox"></th>
						<th class="column-id"><span><?php 
            _e('ID');
            ?>
</span><span class="sorting-indicator"></span></th>
						<th><span><?php 
            _e('Name', 'foxyshop');
            ?>
</span><span class="sorting-indicator"></span></th>
						<th><span><?php 
            _e('Code', 'foxyshop');
            ?>
</span><span class="sorting-indicator"></span></th>
						<th><span><?php 
            _e('Image', 'foxyshop');
            ?>
</span><span class="sorting-indicator"></span></th>
						<th><span><?php 
            _e('Price', 'foxyshop');
            ?>
</span><span class="sorting-indicator"></span></th>
						<th><span><?php 
            _e('Date', 'foxyshop');
            ?>
</span><span class="sorting-indicator"></span></th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<th class="manage-column column-cb check-column" style="" scope="col"><input type="checkbox"></th>
						<th><?php 
            _e('ID', 'foxyshop');
            ?>
</th>
						<th><?php 
            _e('Name', 'foxyshop');
            ?>
</th>
						<th><?php 
            _e('Code', 'foxyshop');
            ?>
</th>
						<th><?php 
            _e('Image', 'foxyshop');
            ?>
</th>
						<th><?php 
            _e('Price', 'foxyshop');
            ?>
</th>
						<th><?php 
            _e('Data', 'foxyshop');
            ?>
</th>
					</tr>
				</tfoot>
				<tbody>
			<?php 
            $none_available = 1;
            foreach ($product_list as $single_product) {
                $product = foxyshop_setup_product($single_product);
                $google_product_listed = (int) get_post_meta($product['id'], '_google_product_listed', TRUE);
                if ($google_product_listed > strtotime("now") && !isset($_GET['debug'])) {
                    continue;
                }
                $none_available = 0;
                if (!isset($google_product_id)) {
                    $google_product_id = "";
                }
                $salestartdate = get_post_meta($product['id'], '_salestartdate', TRUE);
                $saleenddate = get_post_meta($product['id'], '_saleenddate', TRUE);
                if ($salestartdate == '999999999999999999') {
                    $salestartdate = 0;
                }
                if ($saleenddate == '999999999999999999') {
                    $saleenddate = 0;
                }
                $originalprice = $product['originalprice'];
                $saleprice = get_post_meta($product['id'], '_saleprice', true);
                if ($saleprice > 0) {
                    $beginningOK = strtotime("now") > $salestartdate;
                    $endingOK = strtotime("now") < $saleenddate + 86400 || $saleenddate == 0;
                    if ($beginningOK && $endingOK || $salestartdate == 0 && $saleenddate == 0) {
                        $pricewrite = '<span style="text-decoration: line-through; margin-right: 10px;">' . foxyshop_currency($originalprice) . '</span><span style="color: red;">' . foxyshop_currency($saleprice) . '</span>';
                    } else {
                        $pricewrite = foxyshop_currency($originalprice);
                    }
                } else {
                    $pricewrite = foxyshop_currency($originalprice);
                }
                echo '<tr>' . "\n";
                echo '<th class="check-column" scope="row"><input type="checkbox" value="' . $product['id'] . '" name="post[]"></th>' . "\n";
                echo '<td><strong>' . $product['id'] . '</strong></td>' . "\n";
                echo '<td><strong><a href="post.php?post=' . $product['id'] . '&action=edit">' . $product['name'] . '</a></strong>';
                echo '<div class="row-actions">';
                echo '<span><a href="edit.php?foxyshop_manage_google_feed=1&amp;addid=' . $product['id'] . $debug_querystring . '&amp;_wpnonce=' . wp_create_nonce("manage-the-google-feed-settings") . '" class="insert_google_product" rel="' . $google_product_id . '">' . __('Add To Google Products Feed', 'foxyshop') . '</a></span>';
                echo '</div>';
                echo '</td>' . "\n";
                echo '<td>' . $product['code'] . '</td>' . "\n";
                echo '<td><img src="' . foxyshop_get_main_image() . '" class="productfeedimage" /></td>' . "\n";
                echo '<td>' . $pricewrite . '</td>' . "\n";
                echo '<td>' . Date("Y-m-d", strtotime($single_product->post_date)) . '</td>' . "\n";
                echo '</tr>' . "\n";
            }
            if ($none_available) {
                echo '<tr><td colspan="7"><em>No ' . FOXYSHOP_PRODUCT_NAME_PLURAL . ' Available.</em></td></tr>' . "\n";
            }
            ?>
				</tbody>
			</table>
			<input type="hidden" name="foxyshop_run_the_xml" value="1" />
			<?php 
            wp_nonce_field('manage-the-google-feed-settings');
            ?>
			<?php 
            if (isset($_GET['debug'])) {
                echo '<input type="hidden" name="debug" value="1" />';
            }
            ?>
			<div style="padding-top: 10px;">
				<button type="submit" class="button" name="add_checked_google_products" value="1" id="add_checked_google_products">Add Checked <?php 
            echo FOXYSHOP_PRODUCT_NAME_PLURAL;
            ?>
 to Google</button>
			</div>
			</form>



		<?php 
        }
        ?>


	<?php 
    }
    ?>

		<br /><br /><br /><br /><br /><br />
	<table class="widefat">
		<thead>
			<tr>
				<th><img src="<?php 
    echo $google_icon;
    ?>
" alt="" /><?php 
    _e("Create Manual Export File");
    ?>
</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>
					<p>If you would like to <a href="http://www.google.com/merchants" target="_blank">submit your products to Google</a>, you may do so by creating a product feed using this tool. Make sure that you check the option that <a href="http://www.google.com/support/merchants/bin/answer.py?answer=160037" target="_blank">enables double quotes.</a> You also need to make sure that the '_google_product_category' custom field is filled out for each product.</p>
					<form action="edit.php" method="get">
						<input type="hidden" name="post_type" value="foxyshop_product">
						<input type="hidden" name="create_google_product_feed" value="1">
						<p>
							<a href="#" onclick="jQuery('#db_export_settings').show(); jQuery(this).hide(); return false;">Export just part of your product database</a>
							<div id="db_export_settings" style="display: none;">
								<label for="records_per_page">How May Records Per Page?</label><input type="text" id="records_per_page" name="records_per_page" value="-1"> (-1 for all)<br>
								<label for="records_page">Which Page To Export?</label><input type="text" id="records_page" name="records_page" value="1">
							</div>
							<button type="submit" name="submitnow" id="submitnow" value="1" class="button-primary">Create Google Product Feed</button>
							<button type="submit" name="amazon_version" id="amazon_version" value="1" class="button-primary">Create Amazon Product Ads Feed</button>
						</p>
					</form>
				</td>
			</tr>
		</tbody>
	</table>



	</div>


<script type="text/javascript" src="<?php 
    echo FOXYSHOP_DIR;
    ?>
/js/jquery.tablesorter.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
	$("#product_feed_view").tablesorter({
		'cssDesc': 'asc sorted',
		'cssAsc': 'desc sorted',
		'headers': { 0: { sorter: false} }
	});
});
</script>

	<?php 
}
Пример #3
0
function foxyshop_custom_sort()
{
    global $wpdb, $product;
    $parentID = 0;
    $success = "";
    //Reset Order
    if (isset($_GET['upgrade_menu_order'])) {
        foxyshop_upgrade_menu_order();
    }
    if (isset($_POST['submit_new_product_order'])) {
        if (check_admin_referer('update-foxyshop-sorting-options')) {
            $success = foxyshop_update_order();
        }
    } elseif (isset($_POST['revert_product_order'])) {
        if (check_admin_referer('update-foxyshop-sorting-options')) {
            $success = foxyshop_revert_order();
        }
    }
    ?>

	<div class="wrap">
	<div class="icon32" id="icon-tools"><br></div>
	<h2><?php 
    echo sprintf(__('Custom %s Order'), FOXYSHOP_PRODUCT_NAME_SINGULAR);
    ?>
</h2>
	<?php 
    if ($success) {
        echo $success;
    }
    ?>

	<?php 
    $product_categories = get_terms('foxyshop_categories', 'hide_empty=0&hierarchical=0&orderby=name&order=ASC');
    $categoryID = 0;
    if (isset($_REQUEST['categoryID'])) {
        $categoryID = $_REQUEST['categoryID'];
    }
    if ($product_categories) {
        echo '<p>' . sprintf(__("Select a category from the drop down to order the %s in that category.", 'foxyshop'), strtolower(FOXYSHOP_PRODUCT_NAME_PLURAL)) . "</p>\n";
        echo '<form name="form_product_category_order" method="post" action="edit.php?post_type=foxyshop_product&page=foxyshop_custom_sort">';
        echo '<select name="categoryID" id="categoryID">' . "\n";
        echo '<option value="0"' . ($categoryID == 0 ? ' selected="selected"' : '') . '>' . __('All', 'foxyshop') . ' ' . FOXYSHOP_PRODUCT_NAME_PLURAL . '</option>' . "\n";
        foreach ($product_categories as $cat) {
            echo '<option value="' . esc_attr($cat->term_id) . '"' . ($categoryID == $cat->term_id ? ' selected="selected"' : '') . '>' . esc_html($cat->name) . ' (' . $cat->count . ')' . '</option>' . "\n";
        }
        echo '</select>' . "\n";
        echo '<input type="submit" name="btnSubPages" class="button" id="btnSubPages" value="' . __('Select Category', 'foxyshop') . '" /></form>';
    } else {
        $categoryID = 0;
    }
    if ($categoryID >= 0) {
        if ($categoryID > 0) {
            $term = get_term_by('id', $categoryID, "foxyshop_categories");
            $current_category_name = $term->name;
            $args = array('post_type' => 'foxyshop_product', 'foxyshop_categories' => $term->slug, 'posts_per_page' => -1, 'orderby' => "meta_value_num", "meta_key" => "_foxyshop_menu_order_" . $categoryID, 'order' => "ASC", 'post__not_in' => foxyshop_hide_children_array($categoryID));
        } else {
            $current_category_name = __("All", 'foxyshop') . ' ' . FOXYSHOP_PRODUCT_NAME_PLURAL;
            $args = array('post_type' => 'foxyshop_product', 'numberposts' => -1, 'orderby' => "menu_order", 'order' => "ASC");
        }
        $product_list = get_posts($args);
        if ($product_list) {
            echo '<h3>' . $current_category_name . '</h3>' . "\n";
            echo '<p>' . sprintf(__('Drag %s to the preferred order and then click the Save button at the bottom of the page.', 'foxyshop'), strtolower(FOXYSHOP_PRODUCT_NAME_PLURAL)) . '</p>';
            echo '<form name="form_product_order" method="post" action="">' . "\n";
            echo '<ul id="foxyshop_product_order_list" class="foxyshop_sort_list">' . "\n";
            foreach ($product_list as $prod) {
                $product = foxyshop_setup_product($prod);
                if ($categoryID == 0) {
                    $current_count = $prod->menu_order;
                } else {
                    $current_count = (int) get_post_meta($prod->ID, "_foxyshop_menu_order_" . $categoryID, true);
                }
                echo '<li id="id_' . $prod->ID . '" class="lineitem">';
                echo '<img src="' . foxyshop_get_main_image() . '" />';
                echo '<h4>' . $prod->post_title . '</h4>' . "\n";
                echo foxyshop_price();
                echo '<div class="counter">' . ($current_count + 1) . '</div>';
                echo '<div style="clear: both; height: 1px;"></div>' . "\n";
                echo '</li>' . "\n";
            }
            echo '</ul>' . "\n";
            ?>
			<div style="width: 90%; height: 100px;">
				<input type="submit" name="submit_new_product_order" id="submit_new_product_order" class="button-primary" value="<?php 
            _e('Save Custom Order', 'foxyshop');
            ?>
" onclick="javascript:orderPages(); return true;" />&nbsp;&nbsp;<strong id="updateText"></strong>
				<input type="submit" name="revert_product_order" id="revert_product_order" class="button" style="float: right;" value="<?php 
            _e('Revert To Original', 'foxyshop');
            ?>
" onclick="javascript:orderPages(); return true;" />
			</div>
			<input type="hidden" id="foxyshop_product_order_value" name="foxyshop_product_order_value" />
			<input type="hidden" id="hdnParentID" name="hdnParentID" value="<?php 
            echo $parentID;
            ?>
" />
			<input type="hidden" id="categoryID" name="categoryID" value="<?php 
            echo $categoryID;
            ?>
" />
			<?php 
            wp_nonce_field('update-foxyshop-sorting-options');
            ?>
			</form>
			<?php 
        } else {
            echo '<p><em>' . sprintf(__('No %s Found For This Category.', 'foxyshop'), FOXYSHOP_PRODUCT_NAME_PLURAL) . '</em></p>';
            echo '<p><a href="edit.php?post_type=foxyshop_product&amp;page=foxyshop_custom_sort&amp;upgrade_menu_order=1&amp;categoryID=' . $categoryID . '">Missing products? Click here.</a></p>';
        }
    }
    ?>

</div>

<script type="text/javascript">
function foxyshop_custom_order_load_event(){
	jQuery("#foxyshop_product_order_list").sortable({
		placeholder: "sortable-placeholder",
		revert: false,
		tolerance: "pointer",
		update: function() {
			var counter = 1;
			jQuery("#foxyshop_product_order_list li").each(function() {
				jQuery(this).find('.counter').html(counter);
				counter++;
			});
		}
	});
};
addLoadEvent(foxyshop_custom_order_load_event);
function orderPages() {
	jQuery("#updateText").html("<?php 
    echo sprintf(__('Updating %s Order...', 'foxyshop'), FOXYSHOP_PRODUCT_NAME_SINGULAR);
    ?>
");
	jQuery("#foxyshop_product_order_value").val(jQuery("#foxyshop_product_order_list").sortable("toArray"));
}
</script>
<?php 
}