<?php
/**
* 2007-2019 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-2019 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 AdminSendProcessPaymentController extends ModuleAdminController
{
    public function run()
    {
        $quote_module_token = Tools::getValue('quote_token');
        if ($quote_module_token != md5(sha1(_COOKIE_KEY_.'askforaquotemodul'))) {
            die;
        } else {
            $td_firstname = Tools::getValue('td_firstname');
            $td_lastname = Tools::getValue('td_lastname');
            $td_email = Tools::getValue('td_email');
            $td_id_cart = (int) Tools::getValue('td_id_cart');
            $id_quote = (int) Tools::getValue('td_id_quote');
            //// cap nhat id cart lai cho Quote
            $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
            $sql = 'UPDATE '._DB_PREFIX_.'product_quote_dbboo SET id_cart_create='.$td_id_cart;
            $sql .= ' WHERE id_quote='.$id_quote;
            $db->query($sql);
            $cart = new Cart($td_id_cart);
            $ic = $cart->id;
            $t = md5(_COOKIE_KEY_.'recover_cart_'.(int)$ic);
            $l = $cart->id_lang;
            $g = 'step=3&recover_cart='.(int)$ic.'&token_cart='.$t;
            $link_order = Context::getContext()->link->getPageLink('order', false, (int)$l, $g);
            $a5 = array(
                '{order_link}' => $link_order,
                '{firstname}' => $td_firstname,
                '{lastname}' => $td_lastname
            );
            $a1 = Mail::l('Process the payment of your order');
            $a3 = 'backoffice_order';
            $a4 = (int)$cart->id_lang;
            $a6 = $td_firstname.' '.$td_lastname;
            $a7 = $cart->id_shop;
            $a8= _PS_MAIL_DIR_;
            $a9= $td_email;
            if (@Mail::Send($a4, $a3, $a1, $a5, $a9, $a6, null, null, null, null, $a8, true, $a7)) {
                $mail = 1;
            } else {
                $mail = 0;
            }
            echo $mail;
        }
    }
}
