File: /var/www/kpopbg.com_orig/speedy/ajax.php
<?php
session_start();
/* SSL Management */
$useSSL = true;
require_once(dirname(__FILE__).'../../../config/config.inc.php');
require_once(dirname(__FILE__).'../../../config/smarty.config.inc.php');
require_once(dirname(__FILE__).'../../../init.php');
include_once(dirname(__FILE__).'/speedy.php');
$speedy = new Speedy();
if (Tools::getValue('ajax_function') == 'speedy_calculate') {
speedy_calculate();
} elseif (Tools::getValue('ajax_function') == 'get_cities_by_name') {
$speedy->getCitiesByName();
} elseif (Tools::getValue('ajax_function') == 'get_streets_by_name') {
$speedy->getStreetsByName();
} elseif (Tools::getValue('ajax_function') == 'get_quarters_by_name') {
$speedy->getQuartersByName();
} elseif (Tools::getValue('ajax_function') == 'get_blocks_by_name') {
$speedy->getBlocksByName();
} elseif (Tools::getValue('ajax_function') == 'get_object_by_name') {
$speedy->getObjectByName();
} elseif (Tools::getValue('ajax_function') == 'get_offices_by_city_id') {
$speedy->getOfficesByCityId();
} elseif (Tools::getValue('ajax_function') == 'get_countries_by_name') {
$speedy->getCountriesByName();
} elseif (Tools::getValue('ajax_function') == 'get_states_by_name') {
$speedy->getStatesByName();
} elseif (Tools::getValue('ajax_function') == 'set_speedy_method') {
$speedy->setSpeedyMethod();
} elseif (Tools::getValue('ajax_function') == 'speedy_compare_address') {
$speedy->compareAddresses();
}
function speedy_calculate() {
global $speedy;
$results = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $speedy->validateSpeedyForm()) {
if (!isset($_POST['postcode'])) {
$_POST['postcode'] = 0;
}
if (!isset($_POST['city'])) {
$_POST['city'] = '';
}
if (!isset($_POST['city_id'])) {
$_POST['city_id'] = 0;
}
if (!isset($_POST['city_nomenclature'])) {
$_POST['city_nomenclature'] = '';
}
if (!isset($_POST['to_office'])) {
$_POST['to_office'] = 0;
}
if (!isset($_POST['office_id'])) {
$_POST['office_id'] = 0;
}
if (!isset($_POST['quarter'])) {
$_POST['quarter'] = '';
}
if (!isset($_POST['quarter_id'])) {
$_POST['quarter_id'] = 0;
}
if (!isset($_POST['street'])) {
$_POST['street'] = '';
}
if (!isset($_POST['street_id'])) {
$_POST['street_id'] = 0;
}
if (!isset($_POST['street_no'])) {
$_POST['street_no'] = '';
}
if (!isset($_POST['block_no'])) {
$_POST['block_no'] = '';
}
if (!isset($_POST['entrance_no'])) {
$_POST['entrance_no'] = '';
}
if (!isset($_POST['floor_no'])) {
$_POST['floor_no'] = '';
}
if (!isset($_POST['apartment_no'])) {
$_POST['apartment_no'] = '';
}
if (!isset($_POST['object'])) {
$_POST['object'] = '';
}
if (!isset($_POST['object_id'])) {
$_POST['object_id'] = 0;
}
if (!isset($_POST['note'])) {
$_POST['note'] = '';
}
if (!isset($_POST['country'])) {
$_POST['country'] = '';
}
if (!isset($_POST['country_id'])) {
$_POST['country_id'] = 0;
}
if (!isset($_POST['country_nomenclature'])) {
$_POST['country_nomenclature'] = '';
}
if (!isset($_POST['state'])) {
$_POST['state'] = '';
}
if (!isset($_POST['state_id'])) {
$_POST['state_id'] = '';
}
if (!isset($_POST['required_state'])) {
$_POST['required_state'] = 0;
}
if (!isset($_POST['required_postcode'])) {
$_POST['required_postcode'] = 0;
}
if (!isset($_POST['address_1'])) {
$_POST['address_1'] = '';
}
if (!isset($_POST['address_2'])) {
$_POST['address_2'] = '';
}
if (!isset($_POST['abroad'])) {
$_POST['abroad'] = 0;
}
if (Context::getContext()->customer->logged && !empty(Context::getContext()->cart->id_address_delivery)) {
$speedy->_addAddress(Context::getContext()->cart->id_address_delivery, $_POST);
}
$_POST['calculated_currency'] = Context::getContext()->currency->id;
$_SESSION['speedy'] = $_POST;
if (!empty($_POST['shipping_method_id'])) {
$results['shipping_method_id'] = trim($_POST['shipping_method_id']);
} else {
$results['shipping_method_id'] = '';
}
$results_speedy = $speedy->_getQuotePublic();
if (isset($results_speedy['speedy_error'])) {
$results['error']['warning'] = $results_speedy['speedy_error'];
}
if (isset($results_speedy['quote'])) {
$results['methods'] = $results_speedy['quote'];
}
echo json_encode($results);
exit;
}
}
?>