'.print_r($_POST, true).''); if(isset($_POST['add_coupon']) && ($_POST['add_coupon'] == 'true')&& (!($_POST['is_edit_coupon'] == 'true'))) { $coupon_code = $_POST['add_coupon_code']; $discount = (double)$_POST['add_discount']; // cast to boolean, then integer, prevents the value from being anything but 1 or 0 $discount_type = (int)(bool)$_POST['add_discount_type']; $use_once = (int)(bool)$_POST['add_use-once']; $every_product = (int)(bool)$_POST['add_every_product']; // $start_date = date("Y-m-d H:i:s", mktime(0, 0, 0, (int)$_POST['add_start']['month'], (int)$_POST['add_start']['day'], (int)$_POST['add_start']['year'])); // $end_date = date("Y-m-d H:i:s", mktime(0, 0, 0, (int)$_POST['add_end']['month'], (int)$_POST['add_end']['day'], (int)$_POST['add_end']['year'])); $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]); } } if($wpdb->query("INSERT INTO `".WPSC_TABLE_COUPON_CODES."` ( `coupon_code` , `value` , `is-percentage` , `use-once` , `is-used` , `active` , `every_product` , `start` , `expiry`, `condition` ) VALUES ( '$coupon_code', '$discount', '$discount_type', '$use_once', '0', '1', '$every_product', '$start_date' , '$end_date' , '".serialize($new_rule)."' );")) { echo "
".TXT_WPSC_COUPONHASBEENADDED."
'.print_r($coupon_data,true).""); $coupon_id = (int)$coupon_id; // convert dates to a form that compares well and can be inserted into the database // $coupon_data['start'] = date("Y-m-d H:i:s", mktime(0, 0, 0, (int)$coupon_data['start']['month'], (int)$coupon_data['start']['day'], (int)$coupon_data['start']['year'])); // $coupon_data['expiry'] = date("Y-m-d H:i:s", mktime(0, 0, 0, (int)$coupon_data['expiry']['month'], (int)$coupon_data['expiry']['day'], (int)$coupon_data['expiry']['year'])); $coupon_data['start'] = $coupon_data['start']." 00:00:00"; $coupon_data['expiry'] = $coupon_data['expiry']." 00:00:00"; $check_values = $wpdb->get_row("SELECT `id`, `coupon_code`, `value`, `is-percentage`, `use-once`, `active`, `start`, `expiry` FROM `".WPSC_TABLE_COUPON_CODES."` WHERE `id` = '$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 // exit('
'.print_r($coupon_data, true).''); 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($coupon_value != $check_values[$coupon_key]) { $insert_array[] = "`$coupon_key` = '$coupon_value'"; } } //echo("
".print_r($insert_array,true).""); if(count($insert_array) > 0) { $wpdb->query("UPDATE `".WPSC_TABLE_COUPON_CODES."` SET ".implode(", ", $insert_array)." WHERE `id` = '$coupon_id' LIMIT 1;"); } 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]); } } $sql ="UPDATE `".WPSC_TABLE_COUPON_CODES."` SET `condition`='".serialize($new_rule)."' WHERE `id` = '$coupon_id' LIMIT 1"; $wpdb->query($sql); } if($coupon_data['delete_coupon'] != '') { $wpdb->query("DELETE FROM `".WPSC_TABLE_COUPON_CODES."` WHERE `id` = '$coupon_id' LIMIT 1;"); } } } if($_POST['delete_condition'] == 'Delete'){ $sql ="UPDATE `".WPSC_TABLE_COUPON_CODES."` SET `condition`='' WHERE `id` = '".(int)$_POST['coupon_id']."' LIMIT 1"; $wpdb->query($sql); } if($_POST['change-settings'] == 'true') { if($_POST['wpsc_also_bought'] == 1) { update_option('wpsc_also_bought', 1); } else { update_option('wpsc_also_bought', 0); } if($_POST['display_find_us'] == 'on') { update_option('display_find_us', 1); } else { update_option('display_find_us', 0); } if($_POST['wpsc_share_this'] == 1) { update_option('wpsc_share_this', 1); } else { update_option('wpsc_share_this', 0); } } } // taken the token to the token option for google base if(isset($_GET['token'])) { update_option('wpsc_google_base_token', $_GET['token']); } else if(isset($_GET['destroy_token']) && ($_GET['destroy_token'] == 1)) { update_option('wpsc_google_base_token', ''); } /**/ ?>
| ||||||
\n\r"; echo TXT_WPSC_COUPON_CODE; echo " | \n\r"; echo "\n\r"; echo TXT_WPSC_DISCOUNT; echo " | \n\r"; echo "\n\r"; echo TXT_WPSC_START; echo " | \n\r"; echo "\n\r"; echo TXT_WPSC_EXPIRY; echo " | \n\r"; echo "\n\r"; echo TXT_WPSC_ACTIVE; echo " | \n\r"; echo "\n\r"; echo TXT_WPSC_PERTICKED; echo " | \n\r"; echo "\n\r"; echo TXT_WPSC_EDIT; echo " | \n\r"; $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 "
\n\r"; echo $coupon['coupon_code']; echo " | \n\r"; echo "\n\r"; if($coupon['is-percentage'] == 1){ echo $coupon['value']."%"; } else { echo nzshpcrt_currency_display($coupon['value'], 1); } echo " | \n\r"; echo "\n\r"; echo date("d/m/Y",strtotime($coupon['start'])); echo " | \n\r"; echo "\n\r"; echo date("d/m/Y",strtotime($coupon['expiry'])); echo " | \n\r"; echo "\n\r"; switch($coupon['active']) { case 1: echo ""; break; case 0: default: echo ""; break; } echo " | \n\r"; echo "\n\r"; switch($coupon['every_product']) { case 1: echo ""; break; case 0: default: echo ""; break; } echo " | \n\r"; echo "\n\r"; echo "".TXT_WPSC_EDIT.""; echo " | \n\r"; echo "
\n\r";
//$status_style = "style='display: block;'";
echo " \n\r";
coupon_edit_form($coupon);
echo " \n\r";
echo " | \n\r";
echo "
RSS Feed Address: |