<?php
// wpStoreCart, (c) 2011 wpStoreCart.com. All rights reserved.
global $wpsc_error_reporting;
if($wpsc_error_reporting==false) {
error_reporting(0);
}
global $wpdb, $wpStoreCart, $cart, $wpsc_cart_type;
if (!function_exists('add_action'))
{
require_once("../../../../../wp-config.php");
}
$devOptions = $wpStoreCart->getAdminOptions();
require_once('shareyourcart-sdk.php');
require_once(WP_CONTENT_DIR . '/plugins/wpstorecart/php/wpsc-1.1/wpsc/wpsc-config.php');
require_once(WP_CONTENT_DIR . '/plugins/wpstorecart/php/wpsc-1.1/wpsc/wpsc-defaults.php');
require_once(WP_CONTENT_DIR . '/plugins/wpstorecart/php/wpsc-1.1/wpsc/wpsc.php');
if($wpsc_cart_type == 'session') {
if(!isset($_SESSION)) {
@session_start();
}
if(@!is_object($cart)) {
$cart =& $_SESSION['wpsc'];
if(@!is_object($cart)) {
$cart = new wpsc();
}
}
}
if($wpsc_cart_type == 'cookie') {
if(!isset($_SESSION)) { @session_start(); }
if(@!is_object($cart)) {
if(isset($_COOKIE['wpsccart'])) { @$cart =& unserialize(base64_decode($_COOKIE['wpsccart'])); }
if(@!is_object($cart) && !isset($_COOKIE['wpsccart'])) {
$cart = new wpsc();
$xdomain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;setcookie('wpsccart', base64_encode(serialize($cart)), time()+7222, '/', $xdomain, false);
}
}
}
shareyourcart_ensureCouponIsValidAPI(); // Script will die here if it is not valid
$syc_token = $POST['token'];
$wpStoreCartcode = $_POST['coupon_code'];
$syc_coupon_type = $_POST['coupon_type'];
$syc_coupon_value = $_POST['coupon_value'];
if($syc_coupon_type=='amount') {
$wpStoreCartamount = intval($syc_coupon_value);
$wpStoreCartpercent = 0;
}
if($syc_coupon_type=='percent') {
$wpStoreCartamount = 0;
$wpStoreCartpercent = intval($syc_coupon_value);
}
$wpStoreCartdescription = 'Generated by ShareYourCart.com';
$wpStoreCartproduct = 0;
$yesterday = mktime(0, 0, 0, date("m"), date("d")-1, date("y"));
$twodays = mktime(0, 0, 0, date("m"), date("d")+2, date("y"));
$wpStoreCartstartdate = date("Ymd", $yesterday);
$wpStoreCartenddate = date("Ymd", $twodays);
$syc_save_only = false;
if(isset($_POST['save_only'])) {
@$syc_save_only = $_POST['save_only'];
}
$table_name = $wpdb->prefix . "wpstorecart_coupons";
$insert = "
INSERT INTO `{$table_name}` (`primkey`, `code`, `amount`, `percent`, `description`, `product`, `startdate`, `enddate`) VALUES (
NULL,
'{$wpStoreCartcode}',
'{$wpStoreCartamount}',
'{$wpStoreCartpercent}',
'{$wpStoreCartdescription}',
'{$wpStoreCartproduct}',
'{$wpStoreCartstartdate}',
'{$wpStoreCartenddate}');
";
$results = $wpdb->query($insert);
if(!$syc_save_only) {
$_POST['ccoupon'] = $wpStoreCartcode;
$cart->update_coupon(0);
}
?>