<?php
/**
 * mitrocops
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the EULA
 * that is bundled with this package in the file LICENSE.txt.
 *
/*
 *
 * @author    mitrocops
 * @category content_management
 * @package reviewsadv
 * @copyright Copyright mitrocops
 * @license   mitrocops
 */

class reviewsadvuserModuleFrontController extends ModuleFrontController
{
	
	public function init()
	{
    	parent::init();
	}
	
	public function setMedia()
	{
		parent::setMedia();
        $this->addJqueryPlugin(array('fancybox'));
    }


	/**
	 * @see FrontController::initContent()
	 */
	public function initContent()
	{
		parent::initContent();



        $name_module = 'reviewsadv';

        $is_uprof = Configuration::get($name_module.'is_uprof');
        if (!$is_uprof)
            Tools::redirect('index.php');

        include_once(dirname(__FILE__).'../../../reviewsadv.php');
        $obj_reviewsadv = new reviewsadv();

        include_once(dirname(__FILE__).'../../../classes/userprofile.class.php');
        $obj = new userprofile();

        $user_id = (int)Tools::getValue('uid');


        include_once(dirname(__FILE__).'../../../classes/reviewsadvhelp.class.php');
        $obj_reviewsadvhelp = new reviewsadvhelp();


        $data_urls = $obj_reviewsadvhelp->getSEOURLs();
        $users_url = $data_urls['users_url'];

        $rev_url = $data_urls['rev_url'];
        $user_url = $data_urls['user_url'].$user_id;
        $my_account = $data_urls['my_account'];


        if(!$user_id)
            Tools::redirect($users_url);

        $info = $obj->getShopperInfo(array('shopper_id' => $user_id));


        if(sizeof($info['customer'])==0)
            Tools::redirect($users_url);



        $this->context->smarty->assign(array(
            $name_module.'customer' => $info['customer']
        ));

        $_data_translate = $obj_reviewsadv->translateCustom();


        $title = @$info['customer'][0]['firstname']." " .@$info['customer'][0]['lastname']. " ".$_data_translate['profile'];



        $obj_reviewsadv->setSEOUrls();
        $obj_reviewsadv->settingsHooks();

        ## product reviews for customer ##

        $gp = (int)Tools::getValue('gp');
        $step = (int)Configuration::get($name_module.'revperpage');

        $start = (int)(($gp - 1)*$step);
        if($start<0)
            $start = 0;


        $frat = Tools::getValue('frat');

        $search = Tools::getValue("search");
        $is_search = 0;

        ### search ###
        if(Tools::strlen($search)>0){
            $is_search = 1;

        }



        $this->context->smarty->assign($name_module.'is_search', $is_search);
        $this->context->smarty->assign($name_module.'search', $search);
        $this->context->smarty->assign($name_module.'frat', $frat);
        $this->context->smarty->assign($name_module.'gp', $gp);
        $this->context->smarty->assign($name_module.'isgp', Tools::isSubmit('gp'));




        $data_translate = $obj_reviewsadv->translateCustom();

        include_once(dirname(__FILE__).'../../../classes/reviewsadvhelp.class.php');
        $obj_reviewsadvhelp = new reviewsadvhelp();
        $data_my_reviews = $obj_reviewsadvhelp->getMyReviews(array('id_customer'=>$user_id,'start'=>$start,'step'=>$step,'frat'=>$frat,'is_search'=>$is_search,'search'=>$search));

        $count_reviews = $data_my_reviews['count_all'];



        $paging = $obj_reviewsadvhelp->paging17(array('start'=>$start,
                'step'=> $step,
                'count' => $count_reviews,
                'all_my' => 1,
                'product_url' => $user_url,
                'page' => $data_translate['page'],
                'frat'=>$frat,
                'is_search'=>$is_search,
                'search'=>$search,
                'user_url' => $user_url,
            )
        );

        $this->context->smarty->assign(array(
            $name_module.'user_id' => $user_id,
            $name_module.'user_reviews' => $data_my_reviews['reviews'],

            $name_module.'paging' => $paging,
            $name_module.'page_text' => $data_translate['page'],

            $name_module.'my_a_link'=> $my_account,

            $name_module.'rev_url' => $rev_url,



        ));

        ## product reviews for customer ##


        if(version_compare(_PS_VERSION_, '1.7', '>')) {
            $this->context->smarty->tpl_vars['page']->value['meta']['title'] = $title;
            $this->context->smarty->tpl_vars['page']->value['meta']['description'] = $title;
            $this->context->smarty->tpl_vars['page']->value['meta']['keywords'] = $title;
        }

        $this->context->smarty->assign('meta_title' , $title);
        $this->context->smarty->assign('meta_description' , $title);
        $this->context->smarty->assign('meta_keywords' , $title);





        if(version_compare(_PS_VERSION_, '1.7', '>')) {
            $this->setTemplate('module:' . $name_module . '/views/templates/front/user17.tpl');
        }else {
            $this->setTemplate('user.tpl');
        }


    }
}