<?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 AskforaquotemodulmyquotecustomerModuleFrontController extends ModuleFrontController
{
    public function initContent()
    {
        parent::init();
        parent::initHeader();
        parent::initContent();
        $context = Context::getContext();
        if ($context->customer->logged == 1) {
            $customer = $this->context->customer->id;
            $option_price_total = Configuration::get('Option_price_total');
            $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
            $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'product_quote_dbboo where id_customer like';
            $sql .= '"' . (int) $customer . '"';
            $sql .= ' ORDER BY id_quote DESC';
            $tb_pro = $db->ExecuteS($sql, true, false);
            $link = new Link();
            $link_myaccount_seo = $link->getPageLink('my-account', true, null);
            if ($tb_pro != null) {
                $sl_mess = 'Select * from ' . _DB_PREFIX_ . 'cus_message_dbboo cm INNER JOIN ' . _DB_PREFIX_ . '';
                $sl_mess .= 'product_quote_dbboo pq ON cm.id_quote = pq.id_quote WHERE pq.id_customer like "';
                $sl_mess .= (int) $customer . '"';
                $sl_mess .= ' ORDER BY pq.id_quote DESC';
                $count_mess = $db->ExecuteS($sl_mess, true, false);
                foreach ($count_mess as $key => $value) {
                    $id_quote_cus = $count_mess[$key]['id_quote'];
                    $value;
                    $sql_quote_dbboo = 'SELECT * FROM ' . _DB_PREFIX_ . 'product_quote_dbboo where id_customer like "';
                    $sql_quote_dbboo .= (int) $customer . '" and id_quote like "' . (int) $id_quote_cus . '"';
                    $tb_quote_dbboo = $db->ExecuteS($sql_quote_dbboo, true, false);
                    $soucrce_checkk = $tb_quote_dbboo[0]['source_check'];
                    $link_myquotedetail_seo = $link->getModuleLink('askforaquotemodul', 'myquotedetail', array(
                        'id_quote' => $id_quote_cus,
                        'soucrce' => $soucrce_checkk,
                       ));
                    $count_mess[$key]['link_seo'] = $link_myquotedetail_seo;
                    $tt_price = (float) $count_mess[$key]['total_pri'];
                    $id_currency = (int) $count_mess[$key]['id_currency'];
                    $count_mess[$key]['total_price_full'] = Tools::displayPrice($tt_price, $id_currency);
                    $count_mess[$key]['date_quote'] = Tools::displayDate($count_mess[$key]['date_quote'], null, true);
                }
                $this->context->smarty->assign('tb_pro', $count_mess);
                $this->context->smarty->assign('link_myaccount_seo', $link_myaccount_seo);
                $this->context->smarty->assign('option_price_total', $option_price_total);
                $this->context->smarty->assign('path', _PS_MODULE_DIR_ . 'askforaquotemodul/');
                if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                    $this->context->controller->addCSS(_PS_MODULE_DIR_ . 'askforaquotemodul/views/css/style17.css');
                    $tpl_1 = _PS_MODULE_DIR_.'askforaquotemodul/views/templates/front/quotecustomer.tpl';
                    $html = $this->context->smarty->fetch($tpl_1);
                    $this->context->smarty->assign("html", $html);
                       $this->setTemplate('module:askforaquotemodul/views/templates/front/content.tpl');
                } else {
                    $this->context->controller->addCSS(_PS_MODULE_DIR_ . 'askforaquotemodul/views/css/style_new.css');
                    $this->setTemplate('quotecustomer.tpl');
                }
            } else {
                $tb_pro = 0;
                $this->context->smarty->assign('tb_pro', $tb_pro);
                $aaa = 'styledetailsquote.css';
                $this->context->controller->addCSS(_PS_MODULE_DIR_ . 'askforaquotemodul/views/css/'.$aaa);
                if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) { // for PrestaShop 1.7+
                    $css_1 = _PS_MODULE_DIR_ . 'askforaquotemodul/views/css/styledetailsquote17.css';
                    $this->context->controller->addCSS($css_1);
                    $tpl_1 = _PS_MODULE_DIR_.'askforaquotemodul/views/templates/front/quotecustomer.tpl';
                    $html = $this->context->smarty->fetch($tpl_1);
                    $this->context->smarty->assign("html", $html);
                       $this->setTemplate('module:askforaquotemodul/views/templates/front/content.tpl');
                } else {
                    $css_1 = _PS_MODULE_DIR_ . 'askforaquotemodul/views/css/styledetailsquote.css';
                    $this->context->controller->addCSS($css_1);
                    $this->setTemplate('quotecustomer.tpl');
                }
            }
        } else {
            $link = new Link();
            $link_to_account = $link->getPageLink('my-account');
            Tools::redirectAdmin($link_to_account);
        }
    }
}
