clearCache(); $ratesArray = $_POST['rates']; $update = 0; foreach ($ratesArray as $rates){ $record["tax_percent"] = $db->mySQLSafe($rates['tax_percent']); if ($rates['active']==1){ $record["active"] = $db->mySQLSafe($rates['active']); } else { $record["active"] = $db->mySQLSafe('0'); } $where = "id = ".$db->mySQLSafe($rates['id']); $res = $db->update($glob['dbprefix']."CubeCart_tax_rates", $record, $where); if ($res) { $update++; } } $msgTaxType = ""; if($update) { $msgTaxType = "
".$update." ".$lang['admin']['settings_tax_rates_upd_success']."
"; } } // Add/Update Tax Rates/Zones elseif(isset($_POST['new_rates'])) { $cache = new cache(); $cache->clearCache(); $rates = $_POST['new_rates']; $add = false; $edit = false; if (isset($rates['id'])) { $record["id"] = $db->mySQLSafe($rates['id']); $edit = TRUE; } else { $add = TRUE; } $record["type_id"] = $db->mySQLSafe($rates['type_id']); $record["details_id"] = $db->mySQLSafe($rates['details_id']); $record["country_id"] = $db->mySQLSafe($rates['country_id']); $record["county_id"] = $db->mySQLSafe($rates['county_id']); $record["tax_percent"] = $db->mySQLSafe($rates['tax_percent']); $record["goods"] = $db->mySQLSafe(substr($rates['goods_shipping'],0,1)); $record["shipping"] = $db->mySQLSafe(substr($rates['goods_shipping'],1,2)); if($rates['active']==1){ $record["active"] = $db->mySQLSafe($rates['active']); } else { $record["active"] = $db->mySQLSafe('0'); } if($add) { if($rates['county_id']==0) { $check_add = $db->select("SELECT * FROM ".$glob['dbprefix']."CubeCart_tax_rates WHERE type_id=".$record['type_id']." AND details_id=".$record['details_id']." AND country_id=".$record['country_id']); } else { $check_add = $db->select("SELECT * FROM ".$glob['dbprefix']."CubeCart_tax_rates WHERE type_id=".$record['type_id']." AND details_id=".$record['details_id']." AND country_id=".$record['country_id']." AND (county_id=".$record['county_id']." OR county_id=".$db->mySQLSafe('0').")"); } if($check_add) { $error = TRUE; } if(!$error){ $insert = $db->insert($glob['dbprefix']."CubeCart_tax_rates", $record); } } if ($edit) { if ($rates['county_id']==0) { $check_edit = $db->select("SELECT * FROM ".$glob['dbprefix']."CubeCart_tax_rates WHERE type_id=".$record['type_id']." AND details_id=".$record['details_id']." AND country_id=".$record['country_id']." AND id <> ".$record['id']); } else { $check_edit = $db->select("SELECT * FROM ".$glob['dbprefix']."CubeCart_tax_rates WHERE type_id=".$record['type_id']." AND details_id=".$record['details_id']." AND country_id=".$record['country_id']." AND (county_id=".$record['county_id']." OR county_id=".$db->mySQLSafe('0').") AND id <> ".$record['id']); } if($check_edit) { $error = true; } if(!$error) { $where = "id = ".$record['id']; $update = $db->update($glob['dbprefix']."CubeCart_tax_rates", $record, $where); } } if($add) { if ($insert) { $msgTaxType = "".$lang['admin']['settings_tax_rates_add_success']."
"; } else { $msgTaxType = "".$lang['admin']['settings_tax_rates_add_failure']."
"; } } elseif($edit) { if($error){ $msgTaxType = "".$lang['admin']['settings_tax_rates_upd_error']."
"; } elseif($update){ $msgTaxType = "".$lang['admin']['settings_tax_rates_upd_success']."
"; } else { $msgTaxType = "".$lang['admin']['settings_tax_rates_upd_failure']."
"; } } } // Delete Tax Rates/Zones elseif(isset($_GET['delete_rates'])) { $cache = new cache(); $cache->clearCache(); $where = "id = ".$db->mySQLSafe($_GET['delete_rates']); $delete = $db->delete($glob['dbprefix']."CubeCart_tax_rates", $where, ""); if($delete == TRUE) { $msgTaxType = "".$lang['admin']['settings_tax_rates_del_success']."
"; } else { $msgTaxType = "".$lang['admin']['settings_tax_rates_del_failure']."
"; } } // Save country filter if (isset($_POST['show_country'])) { $show_country = $_POST['show_country']; } elseif (isset($_GET['show_country'])) { $show_country = $_GET['show_country']; } else { $show_country = 0; } // Current/Next URL $currentURL = $glob['adminFile']."?_g=settings/tax_rates"; if ($show_country > 0) { $currentURL .= (strstr($currentURL,"?") ? "&" : "?") ."show_country=".$show_country; } // If error editing field, then leave it in edit state if ($edit && $error) { $_GET['edit'] = $rates['id']; } // If successfully added/edited field, make sure country filter // allows the changes to be seen if ((isset($insert) && $insert) || (isset($update) && $update)) { if ($rates['country_id'] != 0 && $show_country != 0 && $rates['country_id'] != $show_country) { $show_country = 0; } } // Lookup Existing Taxes/Config $taxDetails = $db->select("SELECT * FROM ".$glob['dbprefix']."CubeCart_tax_details ORDER BY id"); $taxRates = $db->select("SELECT r.id, type_id, t.taxName as class, details_id, d.name as tax, country_id, county_id, tax_percent, goods, shipping, active, status FROM ".$glob['dbprefix']."CubeCart_tax_rates AS r LEFT JOIN ".$glob['dbprefix']."CubeCart_tax_details AS d ON r.details_id = d.id LEFT JOIN ".$glob['dbprefix']."CubeCart_taxes AS t ON r.type_id = t.id ORDER BY type_id, country_id, county_id, d.id"); $all_countries = $db->select("SELECT id, iso, printable_name FROM ".$glob['dbprefix']."CubeCart_iso_countries"); $all_states = $db->select("SELECT id, countryId, abbrev, name FROM ".$glob['dbprefix']."CubeCart_iso_counties"); $country_names = array(); $state_names = array(); if(is_array($taxRates)) { foreach ($taxRates as $rate) { $id = $rate['country_id']; foreach ($all_countries as $country) { if ($id == $country['id']) { $country_names[$id] = $country['printable_name']; break; } } $id = $rate['county_id']; foreach ($all_states as $state) { if ($id == $state['id']) { $state_names[$id] = $state['name']; break; } } } } $taxTypes = $db->select("SELECT * FROM ".$glob['dbprefix']."CubeCart_taxes"); // Setup default country for inserts if ($show_country) { $defaultCountry = $show_country; } else { $defaultCountry = $db->select("SELECT id FROM ".$glob['dbprefix']."CubeCart_iso_countries WHERE iso='US'"); if(is_array($defaultCountry)) { $defaultCountry = $defaultCountry[0]['id']; } else { $defaultCountry = 1; } } $jsScript = jsGeoLocation("taxCountry", "taxCounty", "-- ".$lang['admin_common']['all']." --"); require($glob['adminFolder'].CC_DS."includes".CC_DS."header.inc.php"); ?> 0) { foreach ($taxRates as $r) { if ($r['id'] == $_GET['edit']) { $rate = $r; break; } } } ?>