} } if ($mode == 'delete') { if (!empty($_REQUEST['state_id'])) { db_query("DELETE FROM ?:states WHERE state_id = ?i", $_REQUEST['state_id']); db_query("DELETE FROM ?:state_descriptions WHERE state_id = ?i", $_REQUEST['state_id']); } } return array(CONTROLLER_STATUS_OK, 'states.manage?country_code=' . $_REQUEST['country_code']); } if ($mode == 'manage') { $params = $_REQUEST; if (empty($params['country_code'])) { $params['country_code'] = Registry::get('settings.General.default_country'); } list($states, $search) = fn_get_states($params, Registry::get('settings.Appearance.admin_elements_per_page'), DESCR_SL); Tygh::$app['view']->assign('states', $states); Tygh::$app['view']->assign('search', $search); Tygh::$app['view']->assign('countries', fn_get_simple_countries(false, DESCR_SL)); } function fn_update_state($state_data, $state_id = 0, $lang_code = DESCR_SL) { if (empty($state_id)) { if (!empty($state_data['code']) && !empty($state_data['state'])) { $state_data['state_id'] = $state_id = db_query("REPLACE INTO ?:states ?e", $state_data); foreach (fn_get_translation_languages() as $state_data['lang_code'] => $_v) { db_query('REPLACE INTO ?:state_descriptions ?e', $state_data); } } } else { db_query("UPDATE ?:state_descriptions SET ?u WHERE state_id = ?i AND lang_code = ?s", $state_data, $state_id, $lang_code);
} } // // Adding new states // if ($mode == 'add') { foreach ($_REQUEST['state_data_add'] as $key => $value) { if (!empty($value['code']) && !empty($value['state'])) { $value['country_code'] = $_REQUEST['country_code']; $value['state_id'] = $state_id = db_query("REPLACE INTO ?:states ?e", $value); foreach ((array) Registry::get('languages') as $value['lang_code'] => $_v) { db_query('REPLACE INTO ?:state_descriptions ?e', $value); } } } } return array(CONTROLLER_STATUS_OK, "states.manage?country_code={$_REQUEST['country_code']}"); } if ($mode == 'manage') { $country_code = !empty($_REQUEST['country_code']) ? $_REQUEST['country_code'] : Registry::get('settings.General.default_country'); $view->assign('states', fn_get_states($country_code, DESCR_SL, true)); $view->assign('country_code', $country_code); $view->assign('countries', fn_get_countries()); } elseif ($mode == 'delete') { if (!empty($_REQUEST['state_id'])) { db_query("DELETE FROM ?:states WHERE state_id = ?i", $_REQUEST['state_id']); db_query("DELETE FROM ?:state_descriptions WHERE state_id = ?i", $_REQUEST['state_id']); } return array(CONTROLLER_STATUS_REDIRECT, "states.manage?country_code={$_REQUEST['country_code']}"); } /** /Body **/
function fn_destination_get_states($lang_code) { list($_states) = fn_get_states(array(), 0, $lang_code); $states = array(); foreach ($_states as $_state) { $states[$_state['state_id']] = $_state['country'] . ': ' . $_state['state']; } return $states; }
function fn_get_available_destination($location) { $country = !empty($location['country']) ? $location['country'] : ''; $state = !empty($location['state']) ? $location['state'] : ''; $zipcode = !empty($location['zipcode']) ? $location['zipcode'] : ''; $city = !empty($location['city']) ? $location['city'] : ''; $address = !empty($location['address']) ? $location['address'] : ''; if (!empty($country)) { $state_id = fn_get_state_id($state, $country); $condition = ''; if (AREA == 'C') { $condition .= fn_get_localizations_condition('localization'); } $__dests = db_get_array("SELECT a.* FROM ?:destination_elements as a LEFT JOIN ?:destinations as b ON b.destination_id = a.destination_id WHERE b.status = 'A' AND (b.destination_id = 1 OR (1 ?p))", $condition); $destinations = array(); foreach ($__dests as $k => $v) { $destinations[$v['destination_id']][$v['element_type']][] = $v['element']; } $concur_destinations = array(); foreach ($destinations as $dest_id => $elm_types) { // Significance level. The more significance level means the most amount of coincidences $significance = 0; $dest_countries = !empty($elm_types['C']) ? $elm_types['C'] : array(); foreach ($elm_types as $elm_type => $elms) { // Check country if ($elm_type == 'C') { $suitable = fn_check_element($elms, $country); if ($suitable == false) { break; } $significance += 1 * (1 / count($elms)); } // Check state if ($elm_type == 'S') { // if country is in destanation_countries and it haven't got states, // we suppose that destanation cover all country if (!in_array($country, $dest_countries) || fn_get_states($country)) { $suitable = fn_check_element($elms, $state_id); if ($suitable == false) { break; } } else { $suitable = true; } $significance += 2 * (1 / count($elms)); } // Check city if ($elm_type == 'T') { $suitable = fn_check_element($elms, $city, true); if ($suitable == false) { break; } $significance += 3 * (1 / count($elms)); } // Check zipcode if ($elm_type == 'Z') { $suitable = fn_check_element($elms, $zipcode, true); if ($suitable == false) { break; } $significance += 4 * (1 / count($elms)); } // Check address if ($elm_type == 'A') { $suitable = fn_check_element($elms, $address, true); if ($suitable == false) { break; } $significance += 5 * (1 / count($elms)); } } $significance = number_format($significance, 2, '.', ''); if ($suitable == true) { $concur_destinations[$significance][] = $dest_id; } } if (!empty($concur_destinations)) { ksort($concur_destinations, SORT_NUMERIC); $concur_destinations = array_pop($concur_destinations); return reset($concur_destinations); } else { return false; } } return false; }