/** * Save submitted options to the database. * @since 3.8.8 * @uses check_admin_referer() Prevents CSRF. * @uses update_option() Saves options to the database. * @uses wpdb::query() Queries the database. * @uses wpdb::get_col() Queries the database. * @access public */ private function save_options($selected = '') { global $wpdb, $wpsc_gateways; $updated = 0; //This is to change the Overall target market selection check_admin_referer('update-options', 'wpsc-update-options'); //Should be refactored along with the Marketing tab if (isset($_POST['change-settings'])) { if (isset($_POST['wpsc_also_bought']) && $_POST['wpsc_also_bought'] == 'on') { update_option('wpsc_also_bought', 1); } else { update_option('wpsc_also_bought', 0); } if (isset($_POST['display_find_us']) && $_POST['display_find_us'] == 'on') { update_option('display_find_us', 1); } else { update_option('display_find_us', 0); } if (isset($_POST['wpsc_share_this']) && $_POST['wpsc_share_this'] == 'on') { update_option('wpsc_share_this', 1); } else { update_option('wpsc_share_this', 0); } if (isset($_POST['wpsc_ga_disable_tracking']) && $_POST['wpsc_ga_disable_tracking'] == '1') { update_option('wpsc_ga_disable_tracking', 1); } else { update_option('wpsc_ga_disable_tracking', 0); } if (isset($_POST['wpsc_ga_currently_tracking']) && $_POST['wpsc_ga_currently_tracking'] == '1') { update_option('wpsc_ga_currently_tracking', 1); } else { update_option('wpsc_ga_currently_tracking', 0); } if (isset($_POST['wpsc_ga_advanced']) && $_POST['wpsc_ga_advanced'] == '1') { update_option('wpsc_ga_advanced', 1); update_option('wpsc_ga_currently_tracking', 1); } else { update_option('wpsc_ga_advanced', 0); } if (isset($_POST['wpsc_ga_tracking_id']) && !empty($_POST['wpsc_ga_tracking_id'])) { update_option('wpsc_ga_tracking_id', esc_attr($_POST['wpsc_ga_tracking_id'])); } else { update_option('wpsc_ga_tracking_id', ''); } } if (empty($_POST['countrylist2']) && !empty($_POST['wpsc_options']['currency_sign_location'])) { $selected = 'none'; } if (!isset($_POST['countrylist2'])) { $_POST['countrylist2'] = ''; } if (!isset($_POST['country_id'])) { $_POST['country_id'] = ''; } if (!isset($_POST['country_tax'])) { $_POST['country_tax'] = ''; } if ($_POST['countrylist2'] != null || !empty($selected)) { $AllSelected = false; if ($selected == 'all') { $wpdb->query("UPDATE `" . WPSC_TABLE_CURRENCY_LIST . "` SET visible = '1'"); $AllSelected = true; } if ($selected == 'none') { $wpdb->query("UPDATE `" . WPSC_TABLE_CURRENCY_LIST . "` SET visible = '0'"); $AllSelected = true; } if ($AllSelected != true) { $countrylist = $wpdb->get_col("SELECT id FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY country ASC "); //find the countries not selected $unselectedCountries = array_diff($countrylist, $_POST['countrylist2']); foreach ($unselectedCountries as $unselected) { $wpdb->update(WPSC_TABLE_CURRENCY_LIST, array('visible' => 0), array('id' => $unselected), '%d', '%d'); } //find the countries that are selected $selectedCountries = array_intersect($countrylist, $_POST['countrylist2']); foreach ($selectedCountries as $selected) { $wpdb->update(WPSC_TABLE_CURRENCY_LIST, array('visible' => 1), array('id' => $selected), '%d', '%d'); } } WPSC_Countries::clear_cache(); wpsc_core_flush_temporary_data(); } $previous_currency = get_option('currency_type'); //To update options if (isset($_POST['wpsc_options'])) { $_POST['wpsc_options'] = stripslashes_deep($_POST['wpsc_options']); // make sure stock keeping time is a number if (isset($_POST['wpsc_options']['wpsc_stock_keeping_time'])) { $skt = $_POST['wpsc_options']['wpsc_stock_keeping_time']; // I hate repeating myself $skt = (double) $skt; if ($skt <= 0 || $skt < 1 && $_POST['wpsc_options']['wpsc_stock_keeping_interval'] == 'hour') { unset($_POST['wpsc_options']['wpsc_stock_keeping_time']); unset($_POST['wpsc_options']['wpsc_stock_keeping_interval']); } } foreach ($_POST['wpsc_options'] as $key => $value) { if ($value != get_option($key)) { update_option($key, $value); $updated++; } } } if ($previous_currency != get_option('currency_type')) { $currency_code = $wpdb->get_var("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id` IN ('" . absint(get_option('currency_type')) . "')"); $selected_gateways = get_option('custom_gateway_options'); $already_changed = array(); foreach ($selected_gateways as $selected_gateway) { if (isset($wpsc_gateways[$selected_gateway]['supported_currencies'])) { if (in_array($currency_code, $wpsc_gateways[$selected_gateway]['supported_currencies']['currency_list'])) { $option_name = $wpsc_gateways[$selected_gateway]['supported_currencies']['option_name']; if (!in_array($option_name, $already_changed)) { update_option($option_name, $currency_code); $already_changed[] = $option_name; } } } } } foreach ($GLOBALS['wpsc_shipping_modules'] as $shipping) { if (is_object($shipping)) { $shipping->submit_form(); } } //This is for submitting shipping details to the shipping module if (!isset($_POST['update_gateways'])) { $_POST['update_gateways'] = ''; } if (!isset($_POST['custom_shipping_options'])) { $_POST['custom_shipping_options'] = null; } if ($_POST['update_gateways'] == 'true') { update_option('custom_shipping_options', $_POST['custom_shipping_options']); $shipadd = 0; foreach ($GLOBALS['wpsc_shipping_modules'] as $shipping) { foreach ((array) $_POST['custom_shipping_options'] as $shippingoption) { if ($shipping->internal_name == $shippingoption) { $shipadd++; } } } } }
/** * saves region data to the database * * @access private * * @since 3.8.14 * * @param array key/value pairs that are put into the database columns * * @return int|boolean country_id on success, false on failure */ private function _save_region_data($region_data) { global $wpdb; /* * We need to figure out if we are updating an existing country. There are three * possible unique identifiers for a country. Look for a row that has any of the * identifiers. */ $region_id = isset($region_data['id']) ? intval($region_data['id']) : 0; $country_id = isset($region_data['country_id']) ? intval($region_data['country_id']) : 0; $region_code = isset($region_data['code']) ? $region_data['code'] : ''; $region_name = isset($region_data['code']) ? $region_data['code'] : ''; $region_id_from_db = false; /* * If at least one of the key feilds ins't present we aren'y going to continue, we can't reliably update * a row in the table, nor could we insrt a row that could reliably be updated. */ if (empty($country_id) || empty($region_code) || empty($region_name)) { _wpsc_doing_it_wrong(__FUNCTION__, __('Creating a new region requires country id, region code and region name.', 'wpsc'), '3.8.11'); return $region_id_from_db; } if ($region_id) { $sql = $wpdb->prepare('SELECT id FROM ' . WPSC_TABLE_REGION_TAX . ' WHERE (`id` = %d )', $region_id); $region_id_from_db = $wpdb->get_var($sql); } if (empty($region_id_from_db)) { // we are doing an insert of a new country $result = $wpdb->insert(WPSC_TABLE_REGION_TAX, $region_data); if ($result) { $region_id_from_db = $wpdb->insert_id; } } else { // we are doing an update of an existing country if (isset($region_data['id'])) { // no need to update the id to itself, don't want to allow changing of region id's either unset($region_data['id']); } $wpdb->update(WPSC_TABLE_REGION_TAX, $region_data, array('id' => $region_id_from_db), '%s', array('%d')); } // clear the cached data, force a rebuild WPSC_Countries::clear_cache(); return $region_id_from_db; }