<?php
/**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License version 3.0
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/AFL-3.0
 * 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.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
 */
if (!defined('_PS_VERSION_')) {
    exit;
}

class SpmreviewsadvuseraccountModuleFrontController extends ModuleFrontController
{
    public $php_self;
	public function init()
	{

		parent::init();
	}
	
	public function setMedia()
	{
		parent::setMedia();
    }

	
	/**
	 * @see FrontController::initContent()
	 */
	public function initContent()
	{
        $name_module = 'spmreviewsadv';
        $this->php_self = 'module-'.$name_module.'-useraccount';


        parent::initContent();



        $is_uprof = Configuration::get($name_module.'is_uprof');

        if (!$is_uprof)
            Tools::redirect('index.php');

        $cookie = Context::getContext()->cookie;

        $id_customer = isset($cookie->id_customer)?$cookie->id_customer:0;
        if (!$id_customer)
            Tools::redirect('authentication.php');



        // loyality program //
        include_once(_PS_MODULE_DIR_ . $name_module . '/classes/loyality.class.php');
        $loyality = new loyality();
        $loyality->saveLoyalityAction(array('id_loyalty_status' => 1, 'id_customer' => $id_customer, 'type' => 'loyality_user_my_show'));
        // loyality program //


        include_once(_PS_MODULE_DIR_.$name_module.'/classes/userprofileg.class.php');
        $obj = new userprofileg();

        include_once(_PS_MODULE_DIR_.$name_module.'/spmreviewsadv.php');
        $obj_spmreviewsadv = new spmreviewsadv();
        $_data_translate = $obj_spmreviewsadv->translateCustom();

        $obj_spmreviewsadv->setSEOUrls();




        $obj_spmreviewsadv->setLoyalitySettings();





        include_once(_PS_MODULE_DIR_.$name_module.'/classes/spmreviewsadvhelp.class.php');
        $obj_spmreviewsadvhelp = new spmreviewsadvhelp();

        $data_urls = $obj_spmreviewsadvhelp->getSEOURLs();
        $my_account = $data_urls['my_account'];


        $info_customer = $obj->getCustomerInfo();
        $avatar_thumb = $info_customer['avatar_thumb'];
        $exist_avatar = $info_customer['exist_avatar'];
        $is_show = $info_customer['is_show'];


        if(version_compare(_PS_VERSION_, '1.7', '>')) {
            $this->context->smarty->tpl_vars['page']->value['meta']['title'] = $_data_translate['meta_title_myaccount'];
            $this->context->smarty->tpl_vars['page']->value['meta']['description'] = $_data_translate['meta_description_myaccount'];
            $this->context->smarty->tpl_vars['page']->value['meta']['keywords'] = $_data_translate['meta_keywords_myaccount'];
        }

        $this->context->smarty->assign('meta_title' , $_data_translate['meta_title_myaccount']);
        $this->context->smarty->assign('meta_description' , $_data_translate['meta_description_myaccount']);
        $this->context->smarty->assign('meta_keywords' , $_data_translate['meta_keywords_myaccount']);

        $this->context->smarty->assign(array(
            $name_module.'avatar_thumb' => $avatar_thumb,
            $name_module.'exist_avatar' => $exist_avatar,
            $name_module.'is_show' => $is_show,
            $name_module.'my_account'=>$my_account,

            $name_module.'ava_msg8'=>$_data_translate['ava_msg8'],
            $name_module.'ava_msg9'=>$_data_translate['ava_msg9'],

        ));






        if(version_compare(_PS_VERSION_, '1.7', '>')) {
            $this->setTemplate('module:' . $name_module . '/views/templates/front/useraccount17.tpl');
        }else {
            $this->setTemplate('useraccount.tpl');
        }


    }
}