garancia/controllers/front/OffrefideliteController.php
2017-05-29 12:58:33 +02:00

265 lines
9.5 KiB
PHP
Executable File

<?php
/*
* 2007-2013 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@prestashop.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 PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class OffrefideliteControllerCore extends FrontController
{
public $php_self = 'offrefidelite';
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function init()
{
parent::init();
$this->customer = $this->context->customer;
}
public function setMedia()
{
parent::setMedia();
$this->addCSS(_THEME_CSS_DIR_.'offrefidelite.css');
}
public function getItemVideo()
{
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT hs.`id_item` as id_item,
hss.`position`,
hss.`active`,
hssl.`description`
FROM '._DB_PREFIX_.'devspeoffrefidelitevideo hs
LEFT JOIN '._DB_PREFIX_.'devspeoffrefidelitevideo_items hss ON (hs.id_item = hss.id_item)
LEFT JOIN '._DB_PREFIX_.'devspeoffrefidelitevideo_items_lang hssl ON (hss.id_item = hssl.id_item)
WHERE (id_shop = '.(int)$id_shop.')
AND hssl.id_lang = '.(int)$id_lang.
($active ? ' AND hss.`active` = 1' : ' ').'
ORDER BY hss.position
limit 0,1');
}
public function getLivredorEnAvant()
{
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT hs.`id_livredor_item` as id_livredor,
hss.`position`,
hss.`id_theme`,
hss.`active`,
hss.`en_avant`,
hss.`note`,
hss.`age`,
hssl.`prenom`,
hssl.`nom`,
hssl.`nom`,
hssl.`departement`,
hssl.`ville`,
hssl.`titre`,
hssl.`phrase`
FROM '._DB_PREFIX_.'devspelivredor hs
LEFT JOIN '._DB_PREFIX_.'devspelivredor_item hss ON (hs.id_livredor_item = hss.id_livredor_item)
LEFT JOIN '._DB_PREFIX_.'devspelivredor_item_lang hssl ON (hss.id_livredor_item = hssl.id_livredor_item)
WHERE (id_shop = '.(int)$id_shop.')
AND hssl.id_lang = '.(int)$id_lang.
($active ? ' AND hss.`active` = 1' : ' ').
' AND hss.`en_avant` = 1
ORDER BY hss.position');
}
public function getItemsProducts()
{
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
$id_category = Configuration::get('PS_CATEGORY_FIDELITY');
$sql = '
SELECT distinct(p.`id_product`), pl.name, pl.link_rewrite,cl.name as categoryName,c.id_category,p.id_category_default
FROM '._DB_PREFIX_.'category_product cp
LEFT JOIN '._DB_PREFIX_.'category c ON (cp.id_category = c.id_category)
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_lang = '.(int)$id_lang.' and c.id_category = cl.id_category)
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = cp.id_product)
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_lang = '.(int)$id_lang.' and p.id_product = pl.id_product)
WHERE c.id_category = '.(int)$id_category.'
AND p.active = 1
ORDER BY cl.name desc,cp.position asc,pl.name asc';
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
return $products;
}
public function getItemsProductsChoice($choice)
{
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
if ($choice == 2) {
$id_category = Configuration::get('PS_CATEGORY_FIDELITYCHOICE2');
} else {
$id_category = Configuration::get('PS_CATEGORY_FIDELITYCHOICE1');
}
$sql = '
SELECT distinct(p.`id_product`), pl.name, pl.link_rewrite,cl.name as categoryName,c.id_category,p.id_category_default
FROM '._DB_PREFIX_.'category_product cp
LEFT JOIN '._DB_PREFIX_.'category c ON (cp.id_category = c.id_category)
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_lang = '.(int)$id_lang.' and c.id_category = cl.id_category)
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = cp.id_product)
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_lang = '.(int)$id_lang.' and p.id_product = pl.id_product)
WHERE c.id_category = '.(int)$id_category.'
AND p.active = 1
ORDER BY cl.name desc,cp.position asc,pl.name asc';
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
return $products;
}
public function getItemsProductsChoice2()
{
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
$id_category = Configuration::get('PS_CATEGORY_FIDELITYCHOICE2');
$sql = '
SELECT distinct(p.`id_product`), pl.name, pl.link_rewrite,cl.name as categoryName,c.id_category,p.id_category_default
FROM '._DB_PREFIX_.'category_product cp
LEFT JOIN '._DB_PREFIX_.'category c ON (cp.id_category = c.id_category)
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_lang = '.(int)$id_lang.' and c.id_category = cl.id_category)
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = cp.id_product)
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_lang = '.(int)$id_lang.' and p.id_product = pl.id_product)
WHERE c.id_category = '.(int)$id_category.'
AND p.active = 1
ORDER BY cl.name desc,cp.position asc,pl.name asc';
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
return $products;
}
public function initContent()
{
// $this->context = Context::getContext();
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
if($id_address_delivery = $this->context->cart->id_address_delivery){
$this->context->smarty->assign('address', new Address($id_address_delivery));
}
// birthday
$naissance=explode('-',$this->customer->birthday);
$this->customer->naissanceAnnee=$naissance[0];
$this->customer->naissanceMois=$naissance[1];
$this->customer->naissanceJour=$naissance[2];
$this->context->smarty->assign('customer', $this->customer);
if (Tools::isSubmit('submitOffreFidelite'))
{
$this->emailOffreFidelite();
}
$this->context->smarty->assign('productFidelity',$this->getItemsProducts());
$this->context->smarty->assign('productChoice1', $this->getItemsProductsChoice(1));
$this->context->smarty->assign('productChoice2', $this->getItemsProductsChoice(2));
$this->context->smarty->assign('livredorEnAvant',$this->getLivredorEnAvant());
$years = Tools::dateYears();
$months = Tools::dateMonths();
$days = Tools::dateDays();
if(Tools::getValue('error')=="badmail"){
$this->context->smarty->assign(array(
'msgOffrefidelite_error' => 1,
'msgOffrefidelite' => 'adresse e-mail invalide'
));
}
$this->context->smarty->assign(array(
'succes'=> Tools::getValue('succes'),
'years' => $years,
'months' => $months,
'days' => $days,
'getItemVideo' => $this->getItemVideo()
));
$this->context->smarty->assign(array(
'contacts' => Contact::getContacts($this->context->language->id)
));
$this->setTemplate(_PS_THEME_DIR_.'offrefidelite.tpl');
parent::initContent();
}
public function emailOffreFidelite(){
$fileAttachment = array();
// if (isset($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['tmp_name']))
// {
// $extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
// $filename = uniqid().substr($_FILES['fileUpload']['name'], -5);
$fileAttachment['content'] = file_get_contents(_PS_BASE_URL_.__PS_BASE_URI__.'offre_fidelite.pdf');
$fileAttachment['name'] = "offre_fidelite.pdf";
$fileAttachment['mime'] = "application/pdf";
// }
if (!($from = trim(Tools::getValue('recevoir_from'))) || !Validate::isEmail($from))
$this->errors[] = Tools::displayError('Invalid email address.');
$id_contact=1;
$contact = new Contact($id_contact, $this->context->language->id);
if (!count($this->errors))
{
$var_list = array(
'{attached_file}' => '-',
'{email}' => $from,
);
// if (isset($filename))
$var_list['{attached_file}'] = 'offre_fidelite.pdf';
$var_list['{attached_file_href}'] = _PS_BASE_URL_.__PS_BASE_URI__.'offre_fidelite.pdf';
// $contact->email;
// offrefidelite
// if (!Mail::Send($this->context->language->id, 'offrefidelite', Mail::l('Offre de fidélité'), $var_list, $from, null, $contact->email, $contact->name, $fileAttachment))
if (!Mail::Send($this->context->language->id, 'offrefidelite', Mail::l('Offre de fidélité'), $var_list, $from, null, '', '', $fileAttachment))
$this->errors[] = Tools::displayError('An error occurred while sending the message.');
$this->context->smarty->assign(array(
'from' => $from,
'msgOffrefidelite' => 1
));
}else{
$this->context->smarty->assign(array(
'msgOffrefidelite_error' => 1,
'msgOffrefidelite' => $this->errors
));
}
// print_r($this->errors);
}
}