<?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
 */

$_GET['controller'] = 'all';
$_GET['fc'] = 'module';
$_GET['module'] = 'reviewsadv';
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');

		$name_module = 'reviewsadv';
		
		if (version_compare(_PS_VERSION_, '1.5', '<')){
			require_once(_PS_MODULE_DIR_.$name_module.'/backward_compatibility/backward.php');
		} else{
			$smarty = Context::getContext()->smarty;
		}


$is_uprof = Configuration::get($name_module.'is_uprof');
if (!$is_uprof)
    Tools::redirect('index.php');

$user_id = (int)Tools::getValue('uid');

include_once(dirname(__FILE__).'/reviewsadv.php');
$obj_reviewsadv = new reviewsadv();

$_data_translate = $obj_reviewsadv->translateCustom();





include_once(dirname(__FILE__).'/classes/userprofileg.class.php');
$obj = new userprofileg();

$info = $obj->getShopperInfo(array('shopper_id' => $user_id));

$title = @$info['customer'][0]['firstname']." " .@$info['customer'][0]['lastname']. " ".$_data_translate['profile'];

$smarty->assign('meta_title' , $title);
$smarty->assign('meta_description' , $title);
$smarty->assign('meta_keywords' , $title);


        if (version_compare(_PS_VERSION_, '1.5', '>') && version_compare(_PS_VERSION_, '1.6', '<')) {
            if (isset(Context::getContext()->controller)) {
                $oController = Context::getContext()->controller;
            }
            else {
                $oController = new FrontController();
                $oController->init();
            }
            // header
            $oController->setMedia();
            @$oController->displayHeader();
        } else {
            if(version_compare(_PS_VERSION_, '1.5', '<'))
                include(dirname(__FILE__).'/../../header.php');
        }




        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);



        if(sizeof($info['customer'])==0)
            Tools::redirect($users_url);



        $smarty->assign(array(
            $name_module.'customer' => $info['customer']
        ));





        $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;

        }



        $smarty->assign($name_module.'is_search', $is_search);
        $smarty->assign($name_module.'search', $search);
        $smarty->assign($name_module.'frat', $frat);
        $smarty->assign($name_module.'gp', $gp);
        $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,
            )
        );

        $smarty->assign(array(
            $name_module.'user_id' => $user_id,
            $name_module.'user_reviews' => $data_my_reviews['reviews'],

            $name_module.'paging' => $paging,

            $name_module.'my_a_link'=> $my_account,

            $name_module.'rev_url' => $rev_url,

            $name_module.'page_text' => $data_translate['page'],



        ));

        ## product reviews for customer ##












if(version_compare(_PS_VERSION_, '1.5', '>')){

        if(version_compare(_PS_VERSION_, '1.6', '>')){

            $obj_front_c = new ModuleFrontController();
            $obj_front_c->module->name = "reviewsadv";
            $obj_front_c->setTemplate('user.tpl');

            $obj_front_c->setMedia();

            $obj_front_c->initHeader();

            $obj_front_c->initContent();

            $obj_front_c->initFooter();


            $obj_front_c->display();

        } else {
            echo $obj_reviewsadv->renderUser();
        }
    } else {
        echo Module::display(dirname(__FILE__).'/reviewsadv.php', 'views/templates/front/user.tpl');
    }



if (version_compare(_PS_VERSION_, '1.5', '>') && version_compare(_PS_VERSION_, '1.6', '<')) {
    if (isset(Context::getContext()->controller)) {
        $oController = Context::getContext()->controller;
    }
    else {
        $oController = new FrontController();
        $oController->init();
    }
    // header
    @$oController->displayFooter();
} else {
    if(version_compare(_PS_VERSION_, '1.5', '<'))
        include(dirname(__FILE__).'/../../footer.php');
}
