Example #1
0
    public function display()
    {
        global $wpdb;
        ?>
		<h3><?php 
        echo _e('General Settings', 'wpmlm');
        ?>
</h3>
		<table class='wpmlm_options form-table'>
			<tr>
				<th scope="row"><?php 
        _e('Base Country/Region', 'wpmlm');
        ?>
: </th>
				<td>
					<select id="wpmlm-base-country-drop-down" name='wpmlm_options[base_country]'>
						<?php 
        echo country_list(esc_attr(get_option('base_country')));
        ?>
					</select>
					<span id='wpmlm-base-region-drop-down'>
						<?php 
        $this->display_region_drop_down();
        ?>
						<img src="<?php 
        echo esc_url(admin_url('images/wpspin_light.gif'));
        ?>
" class="ajax-feedback" title="" alt="" />
					</span>
					<br /><?php 
        _e('Select your primary business location.', 'wpmlm');
        ?>
				</td>
			</tr>
			<?php 
        /* START OF TARGET MARKET SELECTION */
        $countrylist = $wpdb->get_results("SELECT id,country,visible FROM `" . WPMLM_TABLE_CURRENCY_LIST . "` ORDER BY country ASC ", ARRAY_A);
        ?>
				<tr>
					<th scope="row">
					<?php 
        _e('Target Markets', 'wpmlm');
        ?>
:
					</th>
					<td>
					<?php 
        // check for the suhosin module
        if (@extension_loaded('suhosin') && @ini_get('suhosin.post.max_vars') > 0 && @ini_get('suhosin.post.max_vars') < 500) {
            echo "<em>" . __("The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature then disable the suhosin extension, if you can not do this, you will need to contact your hosting provider.", 'wpmlm') . "</em>";
        } else {
            ?>
							<span>
							<?php 
            printf(__('Select: <a href="%1$s"  class="wpmlm-select-all" title="All">All</a> <a href="%2$s" class="wpmlm-select-none" title="None">None</a>', 'wpmlm'), add_query_arg(array('selected_all' => 'all')), add_query_arg(array('selected_all' => 'none')));
            ?>
							</span><br />
							<div id='wpmlm-target-markets' class='ui-widget-content multiple-select'>
						<?php 
            foreach ((array) $countrylist as $country) {
                $country['country'] = htmlspecialchars($country['country']);
                if ($country['visible'] == 1) {
                    ?>
									<input type='checkbox' id="countrylist2-<?php 
                    echo $country['id'];
                    ?>
" name='countrylist2[]' value='<?php 
                    echo $country['id'];
                    ?>
' checked='checked' /> <label for="countrylist2-<?php 
                    echo $country['id'];
                    ?>
"><?php 
                    echo $country['country'];
                    ?>
</label><br />
						<?php 
                } else {
                    ?>
									<input type='checkbox' id="countrylist2-<?php 
                    echo $country['id'];
                    ?>
" name='countrylist2[]' value='<?php 
                    echo $country['id'];
                    ?>
'  /> <label for="countrylist2-<?php 
                    echo $country['id'];
                    ?>
"><?php 
                    esc_attr_e($country['country']);
                    ?>
</label><br />
<?php 
                }
            }
            ?>
							</div><br />
							<?php 
            _e('Select the markets you are selling products to.', 'wpmlm');
        }
        ?>
					</td>
				</tr>
				<?php 
        $stock_keeping_time = get_option('wpmlm_stock_keeping_time', 1);
        $stock_keeping_interval = get_option('wpmlm_stock_keeping_interval', 'day');
        ?>
				<tr>
					<th scope="row">
						<label for="wpmlm-stock-keeping-time"><?php 
        _e('Keep stock in cart for');
        ?>
:</label>
					</th>
					<td>
						<input type="text" name="wpmlm_options[wpmlm_stock_keeping_time]" id="wpmlm-stock-keeping-time" size="2" value="<?php 
        echo esc_attr($stock_keeping_time);
        ?>
" />
						<select name="wpmlm_options[wpmlm_stock_keeping_interval]">
							<option value="hour" <?php 
        selected('hour', $stock_keeping_interval);
        ?>
><?php 
        echo _n('hour', 'hours', $stock_keeping_time, 'wpmlm');
        ?>
</option>
							<option value="day" <?php 
        selected('day', $stock_keeping_interval);
        ?>
><?php 
        echo _n('day', 'days', $stock_keeping_time, 'wpmlm');
        ?>
</option>
							<option value="week" <?php 
        selected('week', $stock_keeping_interval);
        ?>
><?php 
        echo _n('week', 'weeks', $stock_keeping_time, 'wpmlm');
        ?>
</option>
						</select><br />
						<?php 
        _e("Set the amount of time items in a customer's cart are reserved. You can also specify decimal amounts such as '0.5 days' or '1.25 weeks'. Note that the minimum interval you can enter is 1 hour, i.e. you can't schedule it to run every 0.5 hour.");
        ?>
					</td>
				</tr>
				<?php 
        $hierarchical_category = get_option('product_category_hierarchical_url', 0);
        ?>
				<tr>
					<th scope="row">
						<?php 
        _e('Use Hierarchical Product Category URL:');
        ?>
					</th>
					<td>
						<label><input type="radio" <?php 
        checked($hierarchical_category, 1);
        ?>
 name="wpmlm_options[product_category_hierarchical_url]" value="1" /> <?php 
        _e('Yes', 'wpmlm');
        ?>
</label>&nbsp;&nbsp;
						<label><input type="radio" <?php 
        checked($hierarchical_category, 0);
        ?>
name="wpmlm_options[product_category_hierarchical_url]" value="0" /> <?php 
        _e('No', 'wpmlm');
        ?>
</label><br />
						<?php 
        _e('When Hierarchical Product Category URL is enabled, parent product categories are also included in the product URL.<br />For example: example.com/products-page/parent-cat/sub-cat/product-name', 'wpmlm');
        ?>
					</td>
				</tr>
			</table>

			<h3 class="form_group"><?php 
        _e('Currency Settings', 'wpmlm');
        ?>
:</h3>
			<table class='wpmlm_options form-table'>
				<tr>
					<th scope="row"><?php 
        _e('Currency Type', 'wpmlm');
        ?>
:</th>
				<td>
					<select name='wpmlm_options[currency_type]' onchange='getcurrency(this.options[this.selectedIndex].value);'>
						<?php 
        $currency_data = $wpdb->get_results("SELECT * FROM `" . WPMLM_TABLE_CURRENCY_LIST . "` ORDER BY `country` ASC", ARRAY_A);
        $currency_type = esc_attr(get_option('currency_type'));
        foreach ($currency_data as $currency) {
            ?>
							<option value='<?php 
            echo $currency['id'];
            ?>
' <?php 
            selected($currency['id'], $currency_type);
            ?>
><?php 
            echo htmlspecialchars($currency['country']);
            ?>
 (<?php 
            echo $currency['currency'];
            ?>
)</option>
						<?php 
        }
        $currency_data = $wpdb->get_row("SELECT `symbol`,`symbol_html`,`code` FROM `" . WPMLM_TABLE_CURRENCY_LIST . "` WHERE `id`='" . esc_attr(get_option('currency_type')) . "' LIMIT 1", ARRAY_A);
        if ($currency_data['symbol'] != '') {
            $currency_sign = esc_attr($currency_data['symbol_html']);
        } else {
            $currency_sign = esc_attr($currency_data['code']);
        }
        ?>
					</select>
				</td>
			</tr>
			<tr>
				<th scope="row"><?php 
        _e('Currency Sign Location', 'wpmlm');
        ?>
:</th>
					<td>
					<?php 
        $currency_sign_location = esc_attr(get_option('currency_sign_location'));
        $csl1 = "";
        $csl2 = "";
        $csl3 = "";
        $csl4 = "";
        switch ($currency_sign_location) {
            case 1:
                $csl1 = "checked ='checked'";
                break;
            case 2:
                $csl2 = "checked ='checked'";
                break;
            case 3:
                $csl3 = "checked ='checked'";
                break;
            case 4:
                $csl4 = "checked ='checked'";
                break;
        }
        ?>
						<input type='radio' value='1' name='wpmlm_options[currency_sign_location]' id='csl1' <?php 
        echo $csl1;
        ?>
 />
						<label for='csl1'>100<span id='cslchar1'><?php 
        echo $currency_sign;
        ?>
</span></label> &nbsp;
						<input type='radio' value='2' name='wpmlm_options[currency_sign_location]' id='csl2' <?php 
        echo $csl2;
        ?>
 />
						<label for='csl2'>100 <span id='cslchar2'><?php 
        echo $currency_sign;
        ?>
</span></label> &nbsp;
						<input type='radio' value='3' name='wpmlm_options[currency_sign_location]' id='csl3' <?php 
        echo $csl3;
        ?>
 />
						<label for='csl3'><span id='cslchar3'><?php 
        echo $currency_sign;
        ?>
</span>100</label> &nbsp;
						<input type='radio' value='4' name='wpmlm_options[currency_sign_location]' id='csl4' <?php 
        echo $csl4;
        ?>
 />
						<label for='csl4'><span id='cslchar4'><?php 
        echo $currency_sign;
        ?>
</span> 100</label>
					</td>
				</tr>
				<tr>
				<th scope="row"><?php 
        _e('Thousands and decimal separators', 'wpmlm');
        ?>
:</th>
					<td>
						<?php 
        _e('Thousands separator', 'wpmlm');
        ?>
: <input name="wpmlm_options[wpmlm_thousands_separator]" type="text" maxlength="1" size="1" value="<?php 
        echo esc_attr(stripslashes(get_option('wpmlm_thousands_separator')));
        ?>
" /> <br />
						<?php 
        _e('Decimal separator', 'wpmlm');
        ?>
: <input name="wpmlm_options[wpmlm_decimal_separator]" type="text" maxlength="1" size="1" value="<?php 
        echo esc_attr(stripslashes(get_option('wpmlm_decimal_separator')));
        ?>
" /> <br />
						<?php 
        _e('Preview:', 'wpmlm');
        ?>
 10<?php 
        echo esc_attr(stripslashes(get_option('wpmlm_thousands_separator')));
        ?>
000<?php 
        echo esc_attr(stripslashes(get_option('wpmlm_decimal_separator')));
        ?>
00
					</td>
				</tr>
			</table>
		<?php 
    }
        if (strtolower($sp['name']['value']) == strtolower($provider)) {
            if (array_key_exists('gsm', $sp)) {
                if (array_key_exists('attr', $sp['gsm']['apn'])) {
                    $name = $sp['gsm']['apn']['name'] ? $sp['gsm']['apn']['name'] : $sp['name']['value'];
                    echo $name . ":" . $sp['gsm']['apn']['attr']['value'];
                } else {
                    foreach ($sp['gsm']['apn'] as $apn_info) {
                        $name = $apn_info['name']['value'] ? $apn_info['name']['value'] : $apn_info['gsm']['apn']['name'];
                        echo $name . ":" . $apn_info['attr']['value'] . "\n";
                    }
                }
            }
            if (array_key_exists('cdma', $sp)) {
                $name = $sp['cdma']['name']['value'] ? $sp['cdma']['name']['value'] : $sp['name']['value'];
                echo $name . ":" . "CDMA";
            }
        }
    }
}
$_GET_OR_POST = $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : $_GET;
if (isset($_GET_OR_POST['country']) && !isset($_GET_OR_POST['provider'])) {
    providers_list($_GET_OR_POST['country']);
} elseif (isset($_GET_OR_POST['country']) && isset($_GET_OR_POST['provider'])) {
    if (isset($_GET_OR_POST['plan'])) {
        provider_plan_data($_GET_OR_POST['country'], $_GET_OR_POST['provider'], $_GET_OR_POST['plan']);
    } else {
        provider_plans_list($_GET_OR_POST['country'], $_GET_OR_POST['provider']);
    }
} else {
    country_list();
}
Example #3
0
function wpsc_options_general()
{
    global $wpdb;
    ?>
	<form name='cart_options' id='cart_options' method='post' action=''>
	<div id="options_general">
		<h2><?php 
    echo TXT_WPSC_OPTIONS_GENERAL_HEADER;
    ?>
</h2>
		<?php 
    /* wpsc_setting_page_update_notification displays the wordpress styled notifications */
    wpsc_settings_page_update_notification();
    ?>
		<table class='wpsc_options form-table'>
		<tr>
			<th scope="row"><?php 
    echo TXT_WPSC_BASE_COUNTRY;
    ?>
: </th>
			<td>
				<select name='wpsc_options[base_country]' onchange='submit_change_country();'>
				<?php 
    echo country_list(get_option('base_country'));
    ?>
				</select>
				<span id='options_country'>
				<?php 
    $region_list = $wpdb->get_results("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "`  WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN('" . get_option('base_country') . "') AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", ARRAY_A);
    if ($region_list != null) {
        ?>
					<select name='wpsc_options[base_region]'>
						<?php 
        foreach ($region_list as $region) {
            if (get_option('base_region') == $region['id']) {
                $selected = "selected='selected'";
            } else {
                $selected = "";
            }
            ?>
						<option value='<?php 
            echo $region['id'];
            ?>
' <?php 
            echo $selected;
            ?>
 ><?php 
            echo $region['name'];
            ?>
</option>	<?php 
        }
        ?>
					</select>
				   
		<?php 
    }
    ?>
				</span>
				<br /><?php 
    echo TXT_WPSC_SELECTYOURBUSINESSLOCATION;
    ?>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php 
    echo TXT_WPSC_TAX_SETTINGS;
    ?>
:</th>
			<td>
				<span id='options_region'>
				<?php 
    $country_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`='" . get_option('base_country') . "' LIMIT 1", ARRAY_A);
    echo $country_data['country'];
    $region_count = $wpdb->get_var("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "`  WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN('" . get_option('base_country') . "') AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`");
    if ($country_data['has_regions'] == 1) {
        ?>
&nbsp;&nbsp;&nbsp;&nbsp;<a href='<?php 
        echo add_query_arg(array('page' => 'wpsc-settings', 'isocode' => get_option('base_country')));
        ?>
'><?php 
        echo $region_count;
        ?>
 Regions</a>
		<?php 
    } else {
        ?>
					<input type='hidden' name='country_id' value='<?php 
        echo $country_data['id'];
        ?>
' />
					&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='country_tax' class='tax_forms' maxlength='5' size='5' value='<?php 
        echo $country_data['tax'];
        ?>
' />%
		<?php 
    }
    ?>
				</span>
			</td>
		</tr>
		<?php 
    /* START OF TARGET MARKET SELECTION */
    $countrylist = $wpdb->get_results("SELECT id,country,visible FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY country ASC ", ARRAY_A);
    ?>
		<tr>
			<th scope="row">
			<?php 
    echo TXT_WPSC_TM;
    ?>
:
			</th>
			<td>
				<?php 
    // check for the suhosin module
    if (@extension_loaded('suhosin') && @ini_get('suhosin.post.max_vars') > 0 && @ini_get('suhosin.post.max_vars') < 500) {
        echo "<em>" . __("The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature then disable the suhosin extension, if you can not do this, you will need to contact your hosting provider.\n\t\t\t", 'wpsc') . "</em>";
    } else {
        ?>
					<span>Select: <a href='<?php 
        echo add_query_arg(array('selected_all' => 'all'));
        ?>
' class='wpsc_select_all'>All</a>&nbsp; <a href='<?php 
        echo add_query_arg(array('selected_all' => 'none'));
        ?>
' class='wpsc_select_none'>None</a></span><br />

					<div id='resizeable' class='ui-widget-content multiple-select'>
						<?php 
        foreach ((array) $countrylist as $country) {
            $country['country'] = htmlspecialchars($country['country']);
            if ($country['visible'] == 1) {
                ?>
									<input type='checkbox' name='countrylist2[]' value='<?php 
                echo $country['id'];
                ?>
'  checked='checked' /><?php 
                echo $country['country'];
                ?>
<br />
						<?php 
            } else {
                ?>
									<input type='checkbox' name='countrylist2[]' value='<?php 
                echo $country['id'];
                ?>
'  /><?php 
                echo $country['country'];
                ?>
<br />
						<?php 
            }
        }
        ?>
		
					</div><br />
					Select the markets you are selling products to.
				<?php 
    }
    ?>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php 
    echo TXT_WPSC_LANGUAGE;
    ?>
:</th>
			<td>
				<select name='wpsc_options[language_setting]'>
			<?php 
    if (get_option('language_setting') != '') {
        $language_setting = get_option('language_setting');
    } else {
        $language_setting = "EN_en.php";
    }
    $languages_directory = WPSC_FILE_PATH . '/languages';
    $language_files = wpsc_list_dir($languages_directory);
    foreach ($language_files as $language_file) {
        switch ($language_file) {
            case "EN_en.php":
                $language = "English";
                break;
            case "DE_de.php":
                $language = "Deutsch";
                break;
            case "NL_nl.php":
                $language = "Dutch";
                break;
            case "FR_fr.php":
                $language = "Français";
                break;
            case "IT_it.php":
                $language = "Italian";
                break;
            case "BG_bg.php":
                $language = 'български';
                break;
            case "JP_jp.php":
                $language = "日本語";
                break;
            case "pt_BR.php":
                $language = "Brazilian Portuguese";
                break;
            case "RU_ru.php":
                $language = "Russian";
                break;
            case "SP_sp.php":
                $language = "Spanish";
                break;
            case "HU_hu.php":
                $language = "Hungarian";
                break;
            case "SV_sv.php":
                $language = "Swedish";
                break;
            case "TR_tr.php":
                $language = "Türkçe";
                break;
            case "EL_el.php":
                $language = "Ελληνικά";
                break;
            case "KO_ko.php":
                $language = "Korean";
                break;
            case "zh_CN.php":
                $language = "简体中文";
                break;
            case "DK_da.php":
                $language = "Danish";
                break;
            case "RO_ro.php":
                $language = "Romanian";
                break;
            case "nn_NO.php":
                $language = "Norwegian";
                break;
            case "CZ_cz.php":
                $language = "Czech";
                break;
            default:
                continue 2;
                break;
        }
        if ($language_setting == $language_file) {
            ?>
					<option selected='selected' value='<?php 
            echo $language_file;
            ?>
'><?php 
            echo $language;
            ?>
</option>
		<?php 
        } else {
            ?>
					<option value='<?php 
            echo $language_file;
            ?>
'><?php 
            echo $language;
            ?>
</option>            
		<?php 
        }
    }
    ?>
				</select>
			</td>
		</tr>
		</table> 
							
		<h3 class="form_group"><?php 
    echo TXT_WPSC_CURRENCYSETTINGS;
    ?>
:</h3>
		<table class='wpsc_options form-table'>
		<tr>
			<th scope="row"><?php 
    echo TXT_WPSC_CURRENCYTYPE;
    ?>
:</th>
			<td>
				<select name='wpsc_options[currency_type]' onchange='getcurrency(this.options[this.selectedIndex].value);'>
				<?php 
    $currency_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY `country` ASC", ARRAY_A);
    foreach ($currency_data as $currency) {
        if (get_option('currency_type') == $currency['id']) {
            $selected = "selected='selected'";
        } else {
            $selected = "";
        }
        ?>
					<option value='<?php 
        echo $currency['id'];
        ?>
' <?php 
        echo $selected;
        ?>
 ><?php 
        echo htmlspecialchars($currency['country']);
        ?>
 (<?php 
        echo $currency['currency'];
        ?>
)</option>
		<?php 
    }
    $currency_data = $wpdb->get_row("SELECT `symbol`,`symbol_html`,`code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1", ARRAY_A);
    if ($currency_data['symbol'] != '') {
        $currency_sign = $currency_data['symbol_html'];
    } else {
        $currency_sign = $currency_data['code'];
    }
    ?>
				</select>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php 
    echo TXT_WPSC_CURRENCYSIGNLOCATION;
    ?>
:</th>
			<td>
				<?php 
    $currency_sign_location = get_option('currency_sign_location');
    $csl1 = "";
    $csl2 = "";
    $csl3 = "";
    $csl4 = "";
    switch ($currency_sign_location) {
        case 1:
            $csl1 = "checked ='checked'";
            break;
        case 2:
            $csl2 = "checked ='checked'";
            break;
        case 3:
            $csl3 = "checked ='checked'";
            break;
        case 4:
            $csl4 = "checked ='checked'";
            break;
    }
    ?>
				<input type='radio' value='1' name='wpsc_options[currency_sign_location]' id='csl1' <?php 
    echo $csl1;
    ?>
 /> 
				<label for='csl1'>100<span id='cslchar1'><?php 
    echo $currency_sign;
    ?>
</span></label> &nbsp;
				<input type='radio' value='2' name='wpsc_options[currency_sign_location]' id='csl2' <?php 
    echo $csl2;
    ?>
 /> 
				<label for='csl2'>100 <span id='cslchar2'><?php 
    echo $currency_sign;
    ?>
</span></label> &nbsp;
				<input type='radio' value='3' name='wpsc_options[currency_sign_location]' id='csl3' <?php 
    echo $csl3;
    ?>
 /> 
				<label for='csl3'><span id='cslchar3'><?php 
    echo $currency_sign;
    ?>
</span>100</label> &nbsp;
				<input type='radio' value='4' name='wpsc_options[currency_sign_location]' id='csl4' <?php 
    echo $csl4;
    ?>
 /> 
				<label for='csl4'><span id='cslchar4'><?php 
    echo $currency_sign;
    ?>
</span> 100</label>
			</td>
		</tr>
		</table> 
		<div class="submit">
			<input type='hidden' name='wpsc_admin_action' value='submit_options' />
			<?php 
    wp_nonce_field('update-options', 'wpsc-update-options');
    ?>
			<input type="submit" value="<?php 
    echo TXT_WPSC_UPDATE_BUTTON;
    ?>
" name="updateoption"/>
		</div>
	</div>
	</form>
<?php 
}
Example #4
0
wp_head();
?>


<?php 
//wp_head();
?>

</head>
<body <?php 
body_class();
?>
>

        <?php 
country_list(0);
?>

<div class="header">


	<p class="logo">
          <a href="/"><img src="/wp-uploads/2014/11/LHG_Logo_circle-300x290.png" id="logoimg" alt="LHG Logo" /></a>
        <a href="<?php 
echo bloginfo('url');
$val = "";
if (function_exists(qtrans_getLanguage)) {
    $val = "/" . qtrans_getLanguage();
}
?>
/"><!-- img src="<?php 
function wpsc_options_general()
{
    global $wpdb;
    ?>
	<form name='cart_options' id='cart_options' method='post' action=''>
	<div id="options_general">
		<h2><?php 
    _e('General Settings', 'wpsc');
    ?>
</h2>
		<?php 
    /* wpsc_setting_page_update_notification displays the wordpress styled notifications */
    wpsc_settings_page_update_notification();
    ?>
		<table class='wpsc_options form-table'>
		<tr>
			<th scope="row"><?php 
    echo __('Base Country/Region', 'wpsc');
    ?>
: </th>
			<td>
				<select name='wpsc_options[base_country]' onchange='submit_change_country();'>
				<?php 
    echo country_list(get_option('base_country'));
    ?>
				</select>
				<span id='options_country'>
				<?php 
    $region_list = $wpdb->get_results("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "`  WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN('" . get_option('base_country') . "') AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", ARRAY_A);
    if ($region_list != null) {
        ?>
					<select name='wpsc_options[base_region]'>
						<?php 
        foreach ($region_list as $region) {
            if (get_option('base_region') == $region['id']) {
                $selected = "selected='selected'";
            } else {
                $selected = "";
            }
            ?>
						<option value='<?php 
            echo $region['id'];
            ?>
' <?php 
            echo $selected;
            ?>
 ><?php 
            echo $region['name'];
            ?>
</option>	<?php 
        }
        ?>
					</select>
				   
		<?php 
    }
    ?>
				</span>
				<br /><?php 
    echo __('Select your primary business location.', 'wpsc');
    ?>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php 
    echo __('Tax Settings', 'wpsc');
    ?>
:</th>
			<td>
				<span id='options_region'>
				<?php 
    $country_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`='" . get_option('base_country') . "' LIMIT 1", ARRAY_A);
    echo $country_data['country'];
    $region_count = $wpdb->get_var("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "`  WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN('" . get_option('base_country') . "') AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`");
    if ($country_data['has_regions'] == 1) {
        ?>
&nbsp;&nbsp;&nbsp;&nbsp;<a href='<?php 
        echo add_query_arg(array('page' => 'wpsc-settings', 'isocode' => get_option('base_country')));
        ?>
'><?php 
        echo $region_count;
        ?>
 Regions</a>
		<?php 
    } else {
        ?>
					<input type='hidden' name='country_id' value='<?php 
        echo $country_data['id'];
        ?>
' />
					&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='country_tax' class='tax_forms' maxlength='5' size='5' value='<?php 
        echo $country_data['tax'];
        ?>
' />%
		<?php 
    }
    ?>
				</span>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php 
    _e('Tax Included in prices', 'wpsc');
    ?>
:</th>		
			<td>
				<?php 
    $tax_inprice0 = '';
    $tax_inprice1 = '';
    if (wpsc_tax_isincluded()) {
        $tax_inprice1 = 'checked="checked"';
    } else {
        $tax_inprice0 = 'checked="checked"';
    }
    ?>
				<input <?php 
    echo $tax_inprice1;
    ?>
 type='radio' name='wpsc_options[tax_inprice]' value='1' id='tax_inprice1' />
				<label for='tax_inprice1'><?php 
    echo __('Yes', 'wpsc');
    ?>
</label>
				<input <?php 
    echo $tax_inprice0;
    ?>
 type='radio' name='wpsc_options[tax_inprice]' value='0' id='tax_inprice0' />
				<label for='tax_inprice1'><?php 
    echo __('No', 'wpsc');
    ?>
</label>
			</td>
		</tr>

		<?php 
    /* START OF TARGET MARKET SELECTION */
    $countrylist = $wpdb->get_results("SELECT id,country,visible FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY country ASC ", ARRAY_A);
    ?>
		<tr>
			<th scope="row">
			<?php 
    echo __('Target Markets', 'wpsc');
    ?>
:
			</th>
			<td>
				<?php 
    // check for the suhosin module
    if (@extension_loaded('suhosin') && @ini_get('suhosin.post.max_vars') > 0 && @ini_get('suhosin.post.max_vars') < 500) {
        echo "<em>" . __("The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature then disable the suhosin extension, if you can not do this, you will need to contact your hosting provider.\r\n\t\t\t", 'wpsc') . "</em>";
    } else {
        ?>
					<span>Select: <a href='<?php 
        echo add_query_arg(array('selected_all' => 'all'));
        ?>
' class='wpsc_select_all'>All</a>&nbsp; <a href='<?php 
        echo add_query_arg(array('selected_all' => 'none'));
        ?>
' class='wpsc_select_none'>None</a></span><br />

					<div id='resizeable' class='ui-widget-content multiple-select'>
						<?php 
        foreach ((array) $countrylist as $country) {
            $country['country'] = htmlspecialchars($country['country']);
            if ($country['visible'] == 1) {
                ?>
									<input type='checkbox' name='countrylist2[]' value='<?php 
                echo $country['id'];
                ?>
'  checked='checked' /><?php 
                echo $country['country'];
                ?>
<br />
						<?php 
            } else {
                ?>
									<input type='checkbox' name='countrylist2[]' value='<?php 
                echo $country['id'];
                ?>
'  /><?php 
                echo $country['country'];
                ?>
<br />
						<?php 
            }
        }
        ?>
		
					</div><br />
					Select the markets you are selling products to.
				<?php 
    }
    ?>
			</td>
		</tr>
		</table> 
							
		<h3 class="form_group"><?php 
    echo __('Currency Settings', 'wpsc');
    ?>
:</h3>
		<table class='wpsc_options form-table'>
		<tr>
			<th scope="row"><?php 
    echo __('Currency type', 'wpsc');
    ?>
:</th>
			<td>
				<select name='wpsc_options[currency_type]' onchange='getcurrency(this.options[this.selectedIndex].value);'>
				<?php 
    $currency_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY `country` ASC", ARRAY_A);
    foreach ($currency_data as $currency) {
        if (get_option('currency_type') == $currency['id']) {
            $selected = "selected='selected'";
        } else {
            $selected = "";
        }
        ?>
					<option value='<?php 
        echo $currency['id'];
        ?>
' <?php 
        echo $selected;
        ?>
 ><?php 
        echo htmlspecialchars($currency['country']);
        ?>
 (<?php 
        echo $currency['currency'];
        ?>
)</option>
		<?php 
    }
    $currency_data = $wpdb->get_row("SELECT `symbol`,`symbol_html`,`code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . get_option('currency_type') . "' LIMIT 1", ARRAY_A);
    if ($currency_data['symbol'] != '') {
        $currency_sign = $currency_data['symbol_html'];
    } else {
        $currency_sign = $currency_data['code'];
    }
    ?>
				</select>
			</td>
		</tr>
		<tr>
			<th scope="row"><?php 
    echo __('Currency sign location', 'wpsc');
    ?>
:</th>
			<td>
				<?php 
    $currency_sign_location = get_option('currency_sign_location');
    $csl1 = "";
    $csl2 = "";
    $csl3 = "";
    $csl4 = "";
    switch ($currency_sign_location) {
        case 1:
            $csl1 = "checked ='checked'";
            break;
        case 2:
            $csl2 = "checked ='checked'";
            break;
        case 3:
            $csl3 = "checked ='checked'";
            break;
        case 4:
            $csl4 = "checked ='checked'";
            break;
    }
    ?>
				<input type='radio' value='1' name='wpsc_options[currency_sign_location]' id='csl1' <?php 
    echo $csl1;
    ?>
 /> 
				<label for='csl1'>100<span id='cslchar1'><?php 
    echo $currency_sign;
    ?>
</span></label> &nbsp;
				<input type='radio' value='2' name='wpsc_options[currency_sign_location]' id='csl2' <?php 
    echo $csl2;
    ?>
 /> 
				<label for='csl2'>100 <span id='cslchar2'><?php 
    echo $currency_sign;
    ?>
</span></label> &nbsp;
				<input type='radio' value='3' name='wpsc_options[currency_sign_location]' id='csl3' <?php 
    echo $csl3;
    ?>
 /> 
				<label for='csl3'><span id='cslchar3'><?php 
    echo $currency_sign;
    ?>
</span>100</label> &nbsp;
				<input type='radio' value='4' name='wpsc_options[currency_sign_location]' id='csl4' <?php 
    echo $csl4;
    ?>
 /> 
				<label for='csl4'><span id='cslchar4'><?php 
    echo $currency_sign;
    ?>
</span> 100</label>
			</td>
		</tr>
		<tr>
			<?php 
    $decimals = get_option('wpsc_hide_decimals');
    switch ($decimals) {
        case '1':
            $decimal1 = 'checked="checked"';
            break;
        case '0':
        default:
            $decimal2 = 'checked="checked"';
            break;
    }
    ?>
			<th scope="row"><?php 
    _e('Hide Decimals on Products Pages');
    ?>
</th>
			<td>
			<input type='radio' value='1' name='wpsc_options[wpsc_hide_decimals]' id='hide_decimals1' <?php 
    echo $decimal1;
    ?>
 />
			<label for='hide_decimals1'><?php 
    _e('Yes');
    ?>
</label>

			<input type='radio' value='0' name='wpsc_options[wpsc_hide_decimals]' id='hide_decimals2' <?php 
    echo $decimal2;
    ?>
 />
			<label for='hide_decimals2'><?php 
    _e('No');
    ?>
</label>
			</td>
		</tr>
		</table> 
		<div class="submit">
			<input type='hidden' name='wpsc_admin_action' value='submit_options' />
			<?php 
    wp_nonce_field('update-options', 'wpsc-update-options');
    ?>
			<input type="submit" value="<?php 
    echo __('Update &raquo;', 'wpsc');
    ?>
" name="updateoption"/>
		</div>
	</div>
	</form>
<?php 
}
Example #6
0
function wpsc_options_general()
{
    global $wpdb;
    ?>
	<form method='post' action='' id='cart_options' name='cart_options' class='wpsc_form_track'>
		<div id="options_general">
			<h3><?php 
    _e('General Settings', 'wpsc');
    ?>
</h3>
		<?php 
    /* wpsc_setting_page_update_notification displays the wordpress styled notifications */
    wpsc_settings_page_update_notification();
    ?>
		<table class='wpsc_options form-table'>
			<tr>
				<th scope="row"><?php 
    _e('Base Country/Region', 'wpsc');
    ?>
: </th>
				<td>
					<select name='wpsc_options[base_country]' onchange='submit_change_country();'>

						<?php 
    echo country_list(esc_attr(get_option('base_country')));
    ?>

					</select>
					<span id='options_country'>
					<?php 
    $region_list = $wpdb->get_results("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "`  WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN('" . esc_attr(get_option('base_country')) . "') AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", ARRAY_A);
    if (!empty($region_list)) {
        ?>

						<select name='wpsc_options[base_region]'>
							<?php 
        foreach ($region_list as $region) {
            if (esc_attr(get_option('base_region')) == $region['id']) {
                $selected = "selected='selected'";
            } else {
                $selected = "";
            }
            ?>
								<option value='<?php 
            echo $region['id'];
            ?>
' <?php 
            echo $selected;
            ?>
 ><?php 
            echo esc_attr($region['name']);
            ?>
</option> <?php 
        }
        ?>
						</select>

<?php 
    }
    ?>
					</span>
					<br /><?php 
    _e('Select your primary business location.', 'wpsc');
    ?>
				</td>
			</tr>
			<?php 
    /* START OF TARGET MARKET SELECTION */
    $countrylist = $wpdb->get_results("SELECT id,country,visible FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY country ASC ", ARRAY_A);
    ?>
				<tr>
					<th scope="row">
					<?php 
    _e('Target Markets', 'wpsc');
    ?>
:
					</th>
					<td>
					<?php 
    // check for the suhosin module
    if (@extension_loaded('suhosin') && @ini_get('suhosin.post.max_vars') > 0 && @ini_get('suhosin.post.max_vars') < 500) {
        echo "<em>" . __("The Target Markets feature has been disabled because you have the Suhosin PHP extension installed on this server. If you need to use the Target Markets feature then disable the suhosin extension, if you can not do this, you will need to contact your hosting provider.", 'wpsc') . "</em>";
    } else {
        ?>
							<span><?php 
        printf(__('Select: <a href="%1$s"  class="wpsc_select_all" title="All">All</a> <a href="%1$s" class="wpsc_select_none" title="None">None</a>', 'wpsc'), add_query_arg(array('selected_all' => 'all')), add_query_arg(array('selected_all' => 'none')));
        ?>
</span><br />
							<div id='resizeable' class='ui-widget-content multiple-select'>
						<?php 
        foreach ((array) $countrylist as $country) {
            $country['country'] = htmlspecialchars($country['country']);
            if ($country['visible'] == 1) {
                ?>
									<input type='checkbox' id="countrylist2-<?php 
                echo $country['id'];
                ?>
" name='countrylist2[]' value='<?php 
                echo $country['id'];
                ?>
' checked='checked' /> <label for="countrylist2-<?php 
                echo $country['id'];
                ?>
"><?php 
                echo $country['country'];
                ?>
</label><br />
						<?php 
            } else {
                ?>
									<input type='checkbox' id="countrylist2-<?php 
                echo $country['id'];
                ?>
" name='countrylist2[]' value='<?php 
                echo $country['id'];
                ?>
'  /> <label for="countrylist2-<?php 
                echo $country['id'];
                ?>
"><?php 
                esc_attr_e($country['country']);
                ?>
</label><br />
<?php 
            }
        }
        ?>
							</div><br />
							<?php 
        _e('Select the markets you are selling products to.', 'wpsc');
    }
    ?>
					</td>
				</tr>
			</table>

			<h3 class="form_group"><?php 
    _e('Currency Settings', 'wpsc');
    ?>
:</h3>
			<table class='wpsc_options form-table'>
				<tr>
					<th scope="row"><?php 
    _e('Currency Type', 'wpsc');
    ?>
:</th>
				<td>
					<select name='wpsc_options[currency_type]' onchange='getcurrency(this.options[this.selectedIndex].value);'>
						<?php 
    $currency_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY `country` ASC", ARRAY_A);
    foreach ($currency_data as $currency) {
        if (esc_attr(get_option('currency_type')) == $currency['id']) {
            $selected = "selected='selected'";
        } else {
            $selected = "";
        }
        ?>
							<option value='<?php 
        echo $currency['id'];
        ?>
' <?php 
        echo $selected;
        ?>
 ><?php 
        echo htmlspecialchars($currency['country']);
        ?>
 (<?php 
        echo $currency['currency'];
        ?>
)</option>
						<?php 
    }
    $currency_data = $wpdb->get_row("SELECT `symbol`,`symbol_html`,`code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . esc_attr(get_option('currency_type')) . "' LIMIT 1", ARRAY_A);
    if ($currency_data['symbol'] != '') {
        $currency_sign = esc_attr($currency_data['symbol_html']);
    } else {
        $currency_sign = esc_attr($currency_data['code']);
    }
    ?>
					</select>
				</td>
			</tr>
			<tr>
				<th scope="row"><?php 
    _e('Currency Sign Location', 'wpsc');
    ?>
:</th>
					<td>
					<?php 
    $currency_sign_location = esc_attr(get_option('currency_sign_location'));
    $csl1 = "";
    $csl2 = "";
    $csl3 = "";
    $csl4 = "";
    switch ($currency_sign_location) {
        case 1:
            $csl1 = "checked ='checked'";
            break;
        case 2:
            $csl2 = "checked ='checked'";
            break;
        case 3:
            $csl3 = "checked ='checked'";
            break;
        case 4:
            $csl4 = "checked ='checked'";
            break;
    }
    ?>
						<input type='radio' value='1' name='wpsc_options[currency_sign_location]' id='csl1' <?php 
    echo $csl1;
    ?>
 />
						<label for='csl1'>100<span id='cslchar1'><?php 
    echo $currency_sign;
    ?>
</span></label> &nbsp;
						<input type='radio' value='2' name='wpsc_options[currency_sign_location]' id='csl2' <?php 
    echo $csl2;
    ?>
 />
						<label for='csl2'>100 <span id='cslchar2'><?php 
    echo $currency_sign;
    ?>
</span></label> &nbsp;
						<input type='radio' value='3' name='wpsc_options[currency_sign_location]' id='csl3' <?php 
    echo $csl3;
    ?>
 />
						<label for='csl3'><span id='cslchar3'><?php 
    echo $currency_sign;
    ?>
</span>100</label> &nbsp;
						<input type='radio' value='4' name='wpsc_options[currency_sign_location]' id='csl4' <?php 
    echo $csl4;
    ?>
 />
						<label for='csl4'><span id='cslchar4'><?php 
    echo $currency_sign;
    ?>
</span> 100</label>
					</td>
				</tr>
				<tr>
				<th scope="row"><?php 
    _e('Thousands and decimal separators', 'wpsc');
    ?>
:</th>
					<td>
						<?php 
    _e('Thousands separator', 'wpsc');
    ?>
: <input name="wpsc_options[wpsc_thousands_separator]" type="text" maxlength="1" size="1" value="<?php 
    echo esc_attr(stripslashes(get_option('wpsc_thousands_separator')));
    ?>
" /> <br />
						<?php 
    _e('Decimal separator', 'wpsc');
    ?>
: <input name="wpsc_options[wpsc_decimal_separator]" type="text" maxlength="1" size="1" value="<?php 
    echo esc_attr(stripslashes(get_option('wpsc_decimal_separator')));
    ?>
" /> <br />
						<?php 
    _e('Preview:', 'wpsc');
    ?>
 10<?php 
    echo esc_attr(stripslashes(get_option('wpsc_thousands_separator')));
    ?>
000<?php 
    echo esc_attr(stripslashes(get_option('wpsc_decimal_separator')));
    ?>
00
					</td>
				</tr>
			</table>
		<?php 
    do_action('wpsc_general_settings_page');
    ?>
			<div class="submit">
				<input type='hidden' name='wpsc_admin_action' value='submit_options' />
				<?php 
    wp_nonce_field('update-options', 'wpsc-update-options');
    ?>
				<input type="submit" value="<?php 
    _e('Update &raquo;', 'wpsc');
    ?>
" name="updateoption" />
			</div>
		</div>
	</form>
<?php 
}
Example #7
0
</h2>
						  <?php 
    /* here start the general options */
    ?>
							<table class='wpsc_options form-table'>
								<tr>
									<th scope="row">
									<?php 
    echo TXT_WPSC_BASE_COUNTRY;
    ?>
:
									</th>
									<td>
									<select name='base_country' onChange='submit_change_country();'>
									<?php 
    echo country_list(get_option('base_country'));
    ?>
									</select>
									<span id='options_region'>
									<?php 
    $region_list = $wpdb->get_results("SELECT `" . $wpdb->prefix . "region_tax`.* FROM `" . $wpdb->prefix . "region_tax`, `" . $wpdb->prefix . "currency_list`  WHERE `" . $wpdb->prefix . "currency_list`.`isocode` IN('" . get_option('base_country') . "') AND `" . $wpdb->prefix . "currency_list`.`id` = `" . $wpdb->prefix . "region_tax`.`country_id`", ARRAY_A);
    if ($region_list != null) {
        echo "<select name='base_region'>\n\r";
        foreach ($region_list as $region) {
            if (get_option('base_region') == $region['id']) {
                $selected = "selected='true'";
            } else {
                $selected = "";
            }
            echo "<option value='" . $region['id'] . "' {$selected}>" . $region['name'] . "</option>\n\r";
        }
                                    </table>
                                </div>


                            </div>


                            <div class="col-md-4">
                                <h3>Delivery Coverage</h3>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">Country</label>
                                    <div class="col-sm-9">
                                        <select class="selectpicker show-menu-arrow" data-style="btn-green" >
                                            <?php 
foreach (country_list() as $k) {
    ?>
                                            <option value="<?php 
    echo $k;
    ?>
"><?php 
    echo $k;
    ?>
</option>
                                            <?php 
}
?>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
function wpsc_display_coupons_page()
{
    global $wpdb;
    if (isset($_POST) && is_array($_POST) && !empty($_POST)) {
        if (isset($_POST['add_coupon']) && $_POST['add_coupon'] == 'true' && (!isset($_POST['is_edit_coupon']) || !($_POST['is_edit_coupon'] == 'true'))) {
            $coupon_code = $_POST['add_coupon_code'];
            $discount = (double) $_POST['add_discount'];
            $discount_type = (int) $_POST['add_discount_type'];
            $free_shipping_details = serialize((array) $_POST['free_shipping_options']);
            $use_once = (int) (bool) $_POST['add_use-once'];
            $every_product = (int) (bool) $_POST['add_every_product'];
            $is_active = (int) (bool) $_POST['add_active'];
            $use_x_times = (int) $_POST['add_use-x-times'];
            $start_date = date('Y-m-d', strtotime($_POST['add_start'])) . " 00:00:00";
            $end_date = date('Y-m-d', strtotime($_POST['add_end'])) . " 00:00:00";
            $rules = $_POST['rules'];
            foreach ($rules as $key => $rule) {
                foreach ($rule as $k => $r) {
                    $new_rule[$k][$key] = $r;
                }
            }
            foreach ($new_rule as $key => $rule) {
                if ('' == $rule['value']) {
                    unset($new_rule[$key]);
                }
            }
            $insert = $wpdb->insert(WPSC_TABLE_COUPON_CODES, array('coupon_code' => $coupon_code, 'value' => $discount, 'is-percentage' => $discount_type, 'use-once' => $use_once, 'use-x-times' => $use_x_times, 'free-shipping' => $free_shipping_details, 'is-used' => 0, 'active' => $is_active, 'every_product' => $every_product, 'start' => $start_date, 'expiry' => $end_date, 'condition' => serialize($new_rule)), array('%s', '%f', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s'));
            if ($insert) {
                echo "<div class='updated'><p align='center'>" . __('Thanks, the coupon has been added.', 'wpsc') . "</p></div>";
            }
        }
        if (isset($_POST['is_edit_coupon']) && $_POST['is_edit_coupon'] == 'true' && !isset($_POST['delete_condition']) && !isset($_POST['submit_condition'])) {
            foreach ((array) $_POST['edit_coupon'] as $coupon_id => $coupon_data) {
                $coupon_id = (int) $coupon_id;
                $coupon_data['start'] = $coupon_data['start'] . " 00:00:00";
                $coupon_data['expiry'] = $coupon_data['expiry'] . " 00:00:00";
                $check_values = $wpdb->get_row($wpdb->prepare("SELECT `id`, `coupon_code`, `value`, `is-percentage`, `use-once`, `active`, `start`, `expiry`,`every_product` FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE `id` = %d", $coupon_id), ARRAY_A);
                // Sort both arrays to make sure that if they contain the same stuff,
                // that they will compare to be the same, may not need to do this, but what the heck
                if ($check_values != null) {
                    ksort($check_values);
                }
                ksort($coupon_data);
                if ($check_values != $coupon_data) {
                    $insert_array = array();
                    foreach ($coupon_data as $coupon_key => $coupon_value) {
                        if ($coupon_key == "submit_coupon" || $coupon_key == "delete_coupon") {
                            continue;
                        }
                        if (isset($check_values[$coupon_key]) && $coupon_value != $check_values[$coupon_key]) {
                            $insert_array[] = "`{$coupon_key}` = '{$coupon_value}'";
                        }
                    }
                    if (isset($check_values['every_product']) && $coupon_data['add_every_product'] != $check_values['every_product']) {
                        $insert_array[] = "`every_product` = '{$coupon_data['add_every_product']}'";
                    }
                    if (count($insert_array) > 0) {
                        $wpdb->query($wpdb->prepare("UPDATE `" . WPSC_TABLE_COUPON_CODES . "` SET " . implode(", ", $insert_array) . " WHERE `id` = %d LIMIT 1;", $coupon_id));
                    }
                    unset($insert_array);
                    $rules = $_POST['rules'];
                    foreach ((array) $rules as $key => $rule) {
                        foreach ($rule as $k => $r) {
                            $new_rule[$k][$key] = $r;
                        }
                    }
                    foreach ((array) $new_rule as $key => $rule) {
                        if ($rule['value'] == '') {
                            unset($new_rule[$key]);
                        }
                    }
                    $conditions = $wpdb->get_var($wpdb->prepare("SELECT `condition` FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE `id` = %d LIMIT 1", $_POST['coupon_id']));
                    $conditions = unserialize($conditions);
                    $new_cond = array();
                    if ($_POST['rules']['value'][0] != '') {
                        $new_cond['property'] = $_POST['rules']['property'][0];
                        $new_cond['logic'] = $_POST['rules']['logic'][0];
                        $new_cond['value'] = $_POST['rules']['value'][0];
                        $conditions[] = $new_cond;
                    }
                    $wpdb->update(WPSC_TABLE_COUPON_CODES, array('condition' => serialize($conditions)), array('id' => $_POST['coupon_id']), '%s', '%d');
                }
            }
        }
        if (isset($_POST['delete_condition'])) {
            $conditions = $wpdb->get_var($wpdb->prepare("SELECT `condition` FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE `id` = %d LIMIT 1", $_POST['coupon_id']));
            $conditions = unserialize($conditions);
            unset($conditions[(int) $_POST['delete_condition']]);
            $wpdb->update(WPSC_TABLE_COUPON_CODES, array('condition' => serialize($conditions)), array('id' => $_POST['coupon_id']), '%s', '%d');
        }
        if (isset($_POST['submit_condition'])) {
            $conditions = $wpdb->get_var("SELECT `condition` FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE `id` = '" . (int) $_POST['coupon_id'] . "' LIMIT 1");
            $conditions = unserialize($conditions);
            $new_cond = array();
            $new_cond['property'] = $_POST['rules']['property'][0];
            $new_cond['logic'] = $_POST['rules']['logic'][0];
            $new_cond['value'] = $_POST['rules']['value'][0];
            $conditions[] = $new_cond;
            $wpdb->update(WPSC_TABLE_COUPON_CODES, array('condition' => serialize($conditions)), array('id' => $_POST['coupon_id']), '%s', '%d');
        }
    }
    ?>

	<script type='text/javascript'>
		jQuery(".pickdate").datepicker();
		/* jQuery datepicker selector */
		if (typeof jQuery('.pickdate').datepicker != "undefined") {
			jQuery('.pickdate').datepicker({ dateFormat: 'yy-mm-dd' });
		}
	</script>

	<div class="wrap">
		<h2>
			<?php 
    _e('Coupons', 'wpsc');
    ?>
			<a href="#" id="add_coupon_box_link" class="add_item_link button add-new-h2" onClick="return show_status_box( 'add_coupon_box', 'add_coupon_box_link' );">
				<?php 
    _e('Add New', 'wpsc');
    ?>
			</a>
		</h2>
		
		<table style="width: 100%;">
			<tr>
				<td id="coupon_data">
					<div id='add_coupon_box' class='modify_coupon' >
						<form name='add_coupon' method='post' action=''>
							<table class='add-coupon' >
								<tr>
									<th><?php 
    _e('Coupon Code', 'wpsc');
    ?>
</th>
									<th><?php 
    _e('Discount', 'wpsc');
    ?>
</th>
									<th id="free_shipping_options_tr" style="display:none;"><?php 
    _e('Select a Country/Region', 'wpsc');
    ?>
</th>
									<th><?php 
    _e('Start', 'wpsc');
    ?>
</th>
									<th><?php 
    _e('Expiry', 'wpsc');
    ?>
</th>
								</tr>
								<tr>
									<td>
										<input type='text' value='' name='add_coupon_code' />
									</td>
									<td>
										<input type='text' value='' size='3' name='add_discount' id='add_discount'  />
										<select name='add_discount_type' id='add_discount_type' onchange = 'show_shipping_options();'>
											<option value='0' >$</option>
											<option value='1' >%</option>
											<option value='2' ><?php 
    _e('Free shipping', 'wpsc');
    ?>
</option>
										</select>
									</td>
									<td id="free_shipping_options" style="display:none;">
								
										<select name='free_shipping_options[discount_country]' id='coupon_country_list' onchange='show_region_list();'>
											<option value='' >All Countries and Regions</option>
											<?php 
    echo country_list();
    ?>
										</select>
										
										<span id='discount_options_country'>
										<?php 
    //i dont think we need this cu we need to do an ajax request to generate this list
    //based on the country chosen probably need the span place holder tho
    $region_list = $wpdb->get_results($wpdb->prepare("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "`  WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN(%s) AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", get_option($free_shipping_country)), ARRAY_A);
    if (!empty($region_list)) {
        ?>

											<select name='free_shipping_options[discount_region]'>
											<?php 
        foreach ($region_list as $region) {
            if (esc_attr($free_shipping_region) == $region['id']) {
                $selected = "selected='selected'";
            } else {
                $selected = "";
            }
            ?>
												<option value='<?php 
            echo $region['id'];
            ?>
' <?php 
            echo $selected;
            ?>
 ><?php 
            echo esc_attr($region['name']);
            ?>
</option> <?php 
        }
        ?>
											</select>	
									<?php 
    }
    ?>
									</span>
									
									</td>
									<td>
										<input type='text' class='pickdate' size='11' value="<?php 
    echo date('Y-m-d');
    ?>
" name='add_start' />
									</td>
									<td>
										<input type='text' class='pickdate' size='11' name='add_end' value="<?php 
    echo date('Y') + 1 . date('-m-d');
    ?>
">
									</td>
									<td>
										<input type='hidden' value='true' name='add_coupon' />
										<input type='submit' value='Add Coupon' name='submit_coupon' class='button-primary' />
									</td>
								</tr>

								<tr>
									<td colspan='3' scope="row">
										<p>
											<span class='input_label'><?php 
    _e('Active', 'wpsc');
    ?>
</span><input type='hidden' value='0' name='add_active' />
											<input type='checkbox' value='1' checked='checked' name='add_active' />
											<span class='description'><?php 
    _e('Activate coupon on creation.', 'wpsc');
    ?>
</span>
										</p>
									</td>
								</tr>

								<tr>
									<td colspan='3' scope="row">
										<p>
											<span class='input_label'><?php 
    _e('Use Once', 'wpsc');
    ?>
</span><input type='hidden' value='0' name='add_use-once' />
											<input type='checkbox' value='1' name='add_use-once' />
											<span class='description'><?php 
    _e('Deactivate coupon after it has been used.', 'wpsc');
    ?>
</span>
										</p>
									</td>
								</tr>
								
								<tr>
									<td colspan='3' scope="row">
										<p>
											<span class='input_label'><?php 
    _e('Limited Number', 'wpsc');
    ?>
</span><input type='hidden' value='0' name='add_use-x-times' />
											<input type='text' size='4' value='' name='add_use-x-times' />
											<span class='description'><?php 
    _e('Set the amount of times the coupon can be used.', 'wpsc');
    ?>
</span>
										</p>
									</td>
								</tr>

								<tr>
									<td colspan='3' scope="row">
										<p>
											<span class='input_label'><?php 
    _e('Apply On All Products', 'wpsc');
    ?>
</span><input type='hidden' value='0' name='add_every_product' />
											<input type="checkbox" value="1" name='add_every_product'/>
											<span class='description'><?php 
    _e('This coupon affects each product at checkout.', 'wpsc');
    ?>
</span>
										</p>
									</td>
								</tr>

								<tr><td colspan='3'><span id='table_header'>Conditions</span></td></tr>
								<tr>
									<td colspan="8">
									<div class='coupon_condition' >
										<div class='first_condition'>
											<select class="ruleprops" name="rules[property][]">
												<option value="item_name" rel="order"><?php 
    _e('Item name', 'wpsc');
    ?>
</option>
												<option value="item_quantity" rel="order"><?php 
    _e('Item quantity', 'wpsc');
    ?>
</option>
												<option value="total_quantity" rel="order"><?php 
    _e('Total quantity', 'wpsc');
    ?>
</option>
												<option value="subtotal_amount" rel="order"><?php 
    _e('Subtotal amount', 'wpsc');
    ?>
</option>
												<?php 
    echo apply_filters('wpsc_coupon_rule_property_options', '');
    ?>
											</select>

											<select name="rules[logic][]">
												<option value="equal"><?php 
    _e('Is equal to', 'wpsc');
    ?>
</option>
												<option value="greater"><?php 
    _e('Is greater than', 'wpsc');
    ?>
</option>
												<option value="less"><?php 
    _e('Is less than', 'wpsc');
    ?>
</option>
												<option value="contains"><?php 
    _e('Contains', 'wpsc');
    ?>
</option>
												<option value="not_contain"><?php 
    _e('Does not contain', 'wpsc');
    ?>
</option>
												<option value="begins"><?php 
    _e('Begins with', 'wpsc');
    ?>
</option>
												<option value="ends"><?php 
    _e('Ends with', 'wpsc');
    ?>
</option>
												<option value="category"><?php 
    _e('In Category', 'wpsc');
    ?>
</option>
											</select>

											<span><input type="text" name="rules[value][]"/></span>

											<span>
												<script>
													var coupon_number=1;
													function add_another_property(this_button){
														var new_property='<div class="coupon_condition">\n'+
															'<div><img height="16" width="16" class="delete" alt="Delete" src="<?php 
    echo WPSC_CORE_IMAGES_URL;
    ?>
/cross.png" onclick="jQuery(this).parent().remove();"/> \n'+
															'<select class="ruleprops" name="rules[property][]"> \n'+
															'<option value="item_name" rel="order">Item name</option> \n'+
															'<option value="item_quantity" rel="order">Item quantity</option>\n'+
															'<option value="total_quantity" rel="order">Total quantity</option>\n'+
															'<option value="subtotal_amount" rel="order">Subtotal amount</option>\n'+
															'<?php 
    echo apply_filters('wpsc_coupon_rule_property_options', '');
    ?>
'+
															'</select> \n'+
															'<select name="rules[logic][]"> \n'+
															'<option value="equal">Is equal to</option> \n'+
															'<option value="greater">Is greater than</option> \n'+
															'<option value="less">Is less than</option> \n'+
															'<option value="contains">Contains</option> \n'+
															'<option value="not_contain">Does not contain</option> \n'+
															'<option value="begins">Begins with</option> \n'+
															'<option value="ends">Ends with</option> \n'+
															'</select> \n'+
															'<span> \n'+
															'<input type="text" name="rules[value][]"/> \n'+
															'</span>  \n'+
															'</div> \n'+
															'</div> ';
		
														jQuery('.coupon_condition :first').after(new_property);
														coupon_number++;
													}
													
													//displays the free shipping options
													function show_shipping_options() {
														var discount_type = document.getElementById("add_discount_type").value;
														if (discount_type == "2") {
															document.getElementById("free_shipping_options_tr").style.display='block';
															document.getElementById("free_shipping_options").style.display='block';
															document.getElementById("add_discount").style.display='none';
														}else{
															document.getElementById("free_shipping_options_tr").style.display='none';
															document.getElementById("free_shipping_options").style.display='none';
															document.getElementById("add_discount").style.display='inline';		
														}
													}
												
												//need to send the selected country off via ajax to return the region select box for that country
												function show_region_list(){
													var country_id = document.getElementById("coupon_country_list").value;
												}


												</script>
											</span>
										</div>
									</div>
								</tr>

								<tr>
									<td>
										<a class="wpsc_coupons_condition_add" onclick="add_another_property(jQuery(this));">
											<?php 
    _e('Add New Condition', 'wpsc');
    ?>
										</a>
									</td>
								</tr>
							</table>
						</form>
					</div>
				</td>
			</tr>
		</table>

		<?php 
    $columns = array('coupon_code' => __('Coupon Code', 'wpsc'), 'discount' => __('Discount', 'wpsc'), 'start' => __('Start', 'wpsc'), 'expiry' => __('Expiry', 'wpsc'), 'active' => __('Active', 'wpsc'), 'apply_on_prods' => __('Apply On All Products', 'wpsc'), 'edit' => __('Edit', 'wpsc'));
    register_column_headers('display-coupon-details', $columns);
    ?>

		<table class="coupon-list widefat" cellspacing="0">
			<thead>
				<tr>
					<?php 
    print_column_headers('display-coupon-details');
    ?>
				</tr>
			</thead>

			<tfoot>
				<tr>
					<?php 
    print_column_headers('display-coupon-details', false);
    ?>
				</tr>
			</tfoot>

			<tbody>
				<?php 
    $i = 0;
    $coupon_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` ", ARRAY_A);
    foreach ((array) $coupon_data as $coupon) {
        $alternate = "";
        $i++;
        if ($i % 2 != 0) {
            $alternate = "class='alt'";
        }
        echo "<tr {$alternate}>\n\r";
        echo "    <td>\n\r";
        esc_attr_e($coupon['coupon_code']);
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        if ($coupon['is-percentage'] == 1) {
            echo esc_attr($coupon['value']) . "%";
        } else {
            if ($coupon['is-percentage'] == 2) {
                if (!empty($coupon['free-shipping'])) {
                    echo __("Free Shipping - With Conditions ", 'wpsc');
                } else {
                    echo __("Free Shipping - Global", 'wpsc');
                }
            } else {
                echo wpsc_currency_display(esc_attr($coupon['value']));
            }
        }
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        echo date("d/m/Y", strtotime(esc_attr($coupon['start'])));
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        echo date("d/m/Y", strtotime(esc_attr($coupon['expiry'])));
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        switch ($coupon['active']) {
            case 1:
                echo "<img src='" . WPSC_CORE_IMAGES_URL . "/yes_stock.gif' alt='' title='' />";
                break;
            case 0:
            default:
                echo "<img src='" . WPSC_CORE_IMAGES_URL . "/no_stock.gif' alt='' title='' />";
                break;
        }
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        switch ($coupon['every_product']) {
            case 1:
                echo "<img src='" . WPSC_CORE_IMAGES_URL . "/yes_stock.gif' alt='' title='' />";
                break;
            case 0:
            default:
                echo "<img src='" . WPSC_CORE_IMAGES_URL . "/no_stock.gif' alt='' title='' />";
                break;
        }
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        echo "<a title='" . esc_attr($coupon['coupon_code']) . "' href='#' rel='" . $coupon['id'] . "' class='wpsc_edit_coupon'  >" . __('Edit', 'wpsc') . "</a>";
        echo "    </td>\n\r";
        echo "  </tr>\n\r";
        echo "  <tr class='coupon_edit'>\n\r";
        echo "    <td colspan='7' style='padding-left:0px;'>\n\r";
        echo "      <div id='coupon_box_" . $coupon['id'] . "' class='displaynone modify_coupon' >\n\r";
        coupon_edit_form($coupon);
        echo "      </div>\n\r";
        echo "    </td>\n\r";
        echo "  </tr>\n\r";
    }
    ?>
			</tbody>
		</table>

		<p style='margin: 10px 0px 5px 0px;'>
			<?php 
    _e('<strong>Note:</strong> Due to a current PayPal limitation, when a purchase is made using a coupon we cannot send a detailed list of items through for processing. Instead we send the total amount of the purchase so the customer will see your shop name and the total within PayPal.', 'wpsc');
    ?>
		</p>

	</div>

<?php 
}