<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@buy-addons.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author    Buy-Addons <contact@buy-addons.com>
*  @copyright 2007-2020 PrestaShop SA
*  @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
* @since 1.6
*/

class AskforaquotemodulGeninforaddressModuleFrontController extends ModuleFrontController
{
    public function run()
    {
        parent::init();
        parent::initHeader();
        parent::initContent();
        $quote_module_token = Tools::getValue('quote_token');
        if ($quote_module_token != md5(sha1(_COOKIE_KEY_.'askforaquotemodul'))) {
            die;
        }
        $result = array();
        $name_address = array();
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $id_address = (int) Tools::getValue('id_address');
        $select_address = 'SELECT * FROM '._DB_PREFIX_.'address';
        $select_address .= ' WHERE id_address = "'.$id_address.'"';
        $name_address = $db->ExecuteS($select_address, true, false);
        $id_lang = $this->context->language->id;
        if (!empty($name_address)) {
            $name_address[0]['name_country'] = '';
            $name_address[0]['name_state'] = '';
            if (Country::getNameById($id_lang, $name_address[0]['id_country'])) {
                $name_address[0]['name_country'] = Country::getNameById($id_lang, $name_address[0]['id_country']);
            }
            if (State::getNameById($name_address[0]['id_state'])) {
                $name_address[0]['name_state'] = State::getNameById($name_address[0]['id_state']);
            }
        }
        $id_shop = Tools::getValue('jsshopid');
        $this->context->shop->id = $id_shop;
        $result['name_address'] = $name_address;
        $result['oldprice'] = array();
        echo Tools::jsonEncode($result);
    }
}
