<?php
/**
 * 2012 - 2017 Mitrocops
 *
 * MODULE reviewsadv
 *
 * @author    Mitrocops <developersaddons@gmail.com>
 * @copyright Copyright (c) permanent, Mitrocops
 * @license   Addons PrestaShop license limitation
 * @version   1.4.6
 * @link      https://addons.prestashop.com/en/2_community-developer?contributor=189784
 *
 * NOTICE OF LICENSE
 *
 * Don't use this module on several shops. The license provided by PrestaShop Addons
 * for all its modules is valid only once for a single shop.
 */

class reviewsadv extends Module
{

    private $_data_translate_custom = array();

	private $_is15;
	private $_id_shop;

	private $_is16;
    private $_translate;
    private $_is_cloud;
    private $path_img_cloud;
    private $_is_rtl;
    public $is_demo = 0;

    private $_prefix_review = "r";


    private $_min_star_param = 0.2;
    private $_max_star_param = 0.8;


    private $_is_bug_product_page = 1;

    private $_is_mobile = 0;

	
	public function __construct()	
 	{
 	 	$this->name = 'reviewsadv';
 	 	$this->version = '1.4.7';
 	 	$this->tab = 'content_management';
 	 	$this->author = 'mitrocops';
		$this->module_key = 'be56b0b4f453dcfd3d9f1983ad6c135c';
		$this->confirmUninstall = $this->l('Are you sure you want to remove it ? Your will no longer work. Be careful, all your configuration and your data will be lost');



        $this->_is_rtl = 0;

        if(version_compare(_PS_VERSION_, '1.6', '>')){
            $this->bootstrap = true;
            $this->need_instance = 0;
            if(Context::getContext()->language->is_rtl){
                $this->_is_rtl = 1;
            }
        }

		$this->_id_shop = Context::getContext()->shop->id;
		$this->_is15 = 1;


		
 		$this->_is16 = 1;

        ### store reviews ##
        if(version_compare(_PS_VERSION_, '1.5', '>') && version_compare(_PS_VERSION_, '1.7', '<')){

            require_once(_PS_TOOL_DIR_.'mobile_Detect/Mobile_Detect.php');
            $mobile_detect = new Mobile_Detect();

            if ($mobile_detect->isMobile()){
                $this->_is_mobile = 1;
            }

        }

        if(version_compare(_PS_VERSION_, '1.7', '>')) {
            $mobile_detect = new \Mobile_Detect();
            if ($mobile_detect->isMobile()) {
                $this->_is_mobile = 1;
            }
        }

        //$this->_is_mobile = 1;

        ### store reviews ##


        if (defined('_PS_HOST_MODE_'))
            $this->_is_cloud = 1;
        else
            $this->_is_cloud = 0;


        // for test
        //$this->_is_cloud = 1;
        // for test



        if($this->_is_cloud){
            $this->path_img_cloud = "modules/".$this->name."/upload/";
        } else {
            $this->path_img_cloud = "upload/".$this->name."/";

        }


        $this->_translate = array(
            'name'=>$this->name,
            'title'=>$this->l('Social networks Integration'),
            'title_pstwitterpost'=>$this->l('Facebook Wall Posts + Twitter Cards (2 in 1)'),
            'title_psvkpost'=>$this->l('Vkontakte Wall Post'),

            'buy_module_pstwitterpost'=>$this->l('This feature requires you to have purchased, installed and correctly configured our Facebook Wall Posts + Twitter Cards (2 in 1) module.')
                .' '
                .$this->l('You may purchase it on:')
                .' <a href="http://addons.prestashop.com/product.php?id_product=17676" target="_blank" style="font-weight:bold;text-decoration:underline">'
                .$this->l('PrestaShop Addons').'</a>. '
                .$this->l('Once this is all set, you will see the configuration options instead of this red text.'),

            'buy_module_psvkpost'=>$this->l('This feature requires you to have purchased, installed and correctly configured our Vkontakte Wall Post module.')
                .' '
                .$this->l('You may purchase it on:')
                .' <a href="http://addons.prestashop.com/product.php?id_product=17731" target="_blank" style="font-weight:bold;text-decoration:underline">'
                .$this->l('PrestaShop Addons').'</a>. '
                .$this->l('Once this is all set, you will see the configuration options instead of this red text.'),

            'hint1'=>$this->l('This section lets you integrate with our')
                .' <b><a href="http://addons.prestashop.com/product.php?id_product=17676" target="_blank" style="font-weight:bold;text-decoration:underline">'
                .$this->l('Facebook Wall Posts + Twitter Cards (2 in 1) module')
                .'</a></b> '
                /*.$this->l('and')
                .' <b><a href="http://addons.prestashop.com/product.php?id_product=17731" target="_blank" style="font-weight:bold;text-decoration:underline">'
                .$this->l('Vkontakte Wall Post module')
                .'</a></b> '*/
                .$this->l(', and allows you to have any ratings and comments posted on a product on your PrestaShop website to be also automatically posted to your')
                .' '
                //.$this->l(' Facebook, Twitter, Vkontakte fan pages').'.'.' ',
                .$this->l(' Facebook, Twitter fan pages').'.'.' ',

            'hint2'=>$this->l('If you have enabled Require Admin Approval for the "Reviews", it will only be posted once you approve the rating and comment in the moderation interface.'),

            'update_button'=>$this->l('Update settings'),
            'form_action'=>Tools::safeOutput($_SERVER['REQUEST_URI']),

            'enable_psvkpost'=> $this->l('Enable Vkontakte Wall Post'),

            'enable_pstwitterpost'=> $this->l('Enable Facebook Wall Posts + Twitter Cards (2 in 1)'),

            'template_text'=>$this->l('Post template text'),

        );
		
		parent::__construct();
		$this->page = basename(__FILE__, '.php');
		$this->displayName = $this->l('Product Reviews Advanced PRO + Reminder + User Profile');
		$this->description = $this->l('Product Reviews Advanced PRO + Reminder + User Profile');
		
		$this->initContext();

        ## prestashop 1.7 ##
        if(version_compare(_PS_VERSION_, '1.7', '>')) {
            require_once(_PS_MODULE_DIR_.$this->name.'/classes/ps17helpreviewsadv.class.php');
            $ps17help = new ps17helpreviewsadv();
            $ps17help->setMissedVariables();
        } else {
            $smarty = $this->context->smarty;
            $smarty->assign($this->name.'is17' , 0);
        }
        ## prestashop 1.7 ##

	}

    public function getokencron(){
        $_token_cron_shop = sha1(_COOKIE_KEY_ . $this->name);
        return $_token_cron_shop;
    }

    public function getPrefixProductReviews(){
        return $this->_prefix_review;
    }



    public function getURLMultiShop(){
        if(version_compare(_PS_VERSION_, '1.6', '>')){
            $_http_host = Tools::getShopDomainSsl(true, true).__PS_BASE_URI__;
        } else {
            $_http_host = _PS_BASE_URL_SSL_.__PS_BASE_URI__;
        }
        if(version_compare(_PS_VERSION_, '1.5', '>')) {
            $current_shop_id = Shop::getContextShopID();


            if($current_shop_id) {

                $is_ssl = false;
                if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (bool)Configuration::get('PS_SSL_ENABLED'))
                    $is_ssl = true;

                $shop_obj = new Shop($current_shop_id);

                $_http_host = $shop_obj->getBaseURL($is_ssl);

            }

        }
        return $_http_host;
    }
 	
	private function initContext()
	{
	  $this->context = Context::getContext();
	  $this->context->currentindex = isset(AdminController::$currentIndex)?AdminController::$currentIndex:'index.php?controller=AdminModules';
	  $this->context->done = isset($this->done)?$this->done:null;

        $contextLanguageCode = $this->context->language->language_code;
        if(!empty($contextLanguageCode)) {
            $explodeLanguageCode = explode('-', $contextLanguageCode);
            $first_locate = isset($explodeLanguageCode[0])?$explodeLanguageCode[0]:'';
            $second_locate = isset($explodeLanguageCode[1])?$explodeLanguageCode[1]:'';
            if(Tools::strlen($first_locate)>0 && Tools::strlen($second_locate)>0) {
                $localeOfContextLanguage = $first_locate . '_' . Tools::strtoupper($second_locate);
                setlocale(LC_ALL, $localeOfContextLanguage . '.UTF-8', $localeOfContextLanguage);
                //setlocale(LC_ALL, $localeOfContextLanguage);
            }
        }
	}
	
 	public function install()
	{

        // users sliders
        Configuration::updateValue($this->name.'sr_slideru', 1);
        Configuration::updateValue($this->name.'sr_slu', 3);

        Configuration::updateValue($this->name.'sr_sliderhu', 1);
        Configuration::updateValue($this->name.'sr_slhu', 3);

        Configuration::updateValue($this->name.'d_eff_shopu', 'flipInX');

        Configuration::updateValue($this->name.'perpageu'.$this->_prefix_review, 5);

        // users sliders

        // product reviews sliders
        Configuration::updateValue($this->name.'sr_sliderr', 1);
        Configuration::updateValue($this->name.'sr_slr', 2);

        Configuration::updateValue($this->name.'sr_sliderhr', 1);
        Configuration::updateValue($this->name.'sr_slhr', 2);



        Configuration::updateValue($this->name.'d_eff_rev', 'flipInX');
        Configuration::updateValue($this->name.'d_eff_rev_my', 'flipInX');
        Configuration::updateValue($this->name.'d_eff_rev_u', 'flipInX');
        Configuration::updateValue($this->name.'d_eff_rev_all', 'flipInX');


        // store reviews sliders
        Configuration::updateValue($this->name.'sr_slider', 1);
        Configuration::updateValue($this->name.'sr_sl', 2);

        Configuration::updateValue($this->name.'sr_sliderh', 1);
        Configuration::updateValue($this->name.'sr_slh', 2);



        ## ids_groups ##

        $cookie = $this->context->cookie;
        $id_lang =  $cookie->id_lang;


        $ids_groups_array = array();
        foreach(Group::getGroups($id_lang) as $group_item){
            $id_group = $group_item['id_group'];
            $ids_groups_array[] = $id_group;
        }
        $ids_groups = implode(",",$ids_groups_array);


        Configuration::updateValue($this->name.'ids_groups', $ids_groups);
        Configuration::updateValue($this->name.'ids_groupsfb', $ids_groups);

        ## ids_groups ##





        Configuration::updateValue($this->name.'crondelay'.$this->_prefix_review, 10);
        Configuration::updateValue($this->name.'cronnpost'.$this->_prefix_review, 20);

        ## subjects ##
        $languages = Language::getLanguages(false);
        foreach ($languages as $language){
            $i = $language['id_lang'];
            Configuration::updateValue($this->name.'reminderok'.$this->_prefix_review.'_'.$i, $this->l('The emails requests on the reviews was successfully sent'));
            Configuration::updateValue($this->name.'thankyou'.$this->_prefix_review.'_'.$i, $this->l('Thank you for your review'));

            Configuration::updateValue($this->name.'emailreminder_'.$i, $this->l('Are you satisfied with our products'));
            Configuration::updateValue($this->name.'subpubem_'.$i, $this->l('Your review has been published'));
            Configuration::updateValue($this->name.'subresem_'.$i, $this->l('The shop admin has replied to your product review'));
            Configuration::updateValue($this->name.'textresem_'.$i, $this->l('Thank you for your product review on our website. We always welcome reviews, whether it is positive or negative. However, we would like to have a chance to invite you to change your review. Here is why:'));

            Configuration::updateValue($this->name.'newrev'.$this->_prefix_review.'_'.$i, $this->l('New review'));
            Configuration::updateValue($this->name.'modrev'.$this->_prefix_review.'_'.$i, $this->l('One of your customers has modified own product review'));
            Configuration::updateValue($this->name.'abuserev'.$this->_prefix_review.'_'.$i, $this->l('Someone send abuse for review'));

            Configuration::updateValue($this->name.'facvouc'.$this->_prefix_review.'_'.$i, $this->l('You share review on Facebook and get voucher for discount'));
            Configuration::updateValue($this->name.'revvouc'.$this->_prefix_review.'_'.$i, $this->l('You submit a review and get voucher for discount'));


            Configuration::updateValue($this->name.'sugvouc'.$this->_prefix_review.'_'.$i, $this->l('Share your review on Facebook and get voucher for discount'));


        }
        ## subjects ##


        Configuration::updateValue($this->name.'is_emailreminder', 1);
        Configuration::updateValue($this->name.'is_reminderok'.$this->_prefix_review, 1);
        Configuration::updateValue($this->name.'is_thankyou'.$this->_prefix_review, 1);
        Configuration::updateValue($this->name.'is_newrev'.$this->_prefix_review, 1);
        Configuration::updateValue($this->name.'is_subresem', 1);
        Configuration::updateValue($this->name.'is_modrev'.$this->_prefix_review, 1);
        Configuration::updateValue($this->name.'is_subpubem', 1);
        Configuration::updateValue($this->name.'is_abuserev'.$this->_prefix_review, 1);
        Configuration::updateValue($this->name.'is_revvouc'.$this->_prefix_review, 1);
        Configuration::updateValue($this->name.'is_facvouc'.$this->_prefix_review, 1);
        Configuration::updateValue($this->name.'is_sugvouc'.$this->_prefix_review, 1);


        ## user profile ###
        Configuration::updateValue($this->name.'is_uprof', 1);

        Configuration::updateValue($this->name.'is_proftab', 1);

        if($this->_is16 == 1){
            Configuration::updateValue($this->name.'radv_home', 1);
            Configuration::updateValue($this->name.'radv_footer', 1);

        }
        Configuration::updateValue($this->name.'radv_left', 1);


        Configuration::updateValue($this->name.'rshoppers_blc', 5);
        Configuration::updateValue($this->name.'rpage_shoppers', 16);
        ## user profile ###

        Configuration::updateValue($this->name.'is_avatar'.$this->_prefix_review, 1);
        Configuration::updateValue($this->name.'is_files'.$this->_prefix_review, 1);
        Configuration::updateValue($this->name.'ruploadfiles', 7);
        Configuration::updateValue($this->name.'rminc', 20);


        Configuration::updateValue($this->name.'is_onerev', 1);
        Configuration::updateValue($this->name.'is_sortallf', 1);
        Configuration::updateValue($this->name.'is_sortfu', 1);


		
		#### posts api ###
		$languages = Language::getLanguages(false);
    	foreach ($languages as $language){
    		$i = $language['id_lang'];
    		$iso = Tools::strtoupper(Language::getIsoById($i));
    		Configuration::updateValue($this->name.'twdesc_'.$i, $this->l('rated product in our shop').' '.$iso);
            Configuration::updateValue($this->name.'vkdesc_'.$i, $this->l('rated product in our shop').' '.$iso);
		}
		
		#### posts api ###
		
		



        Configuration::updateValue($this->name.'reminder', 1);
        Configuration::updateValue($this->name.'delaysec'.$this->_prefix_review, 7);
        Configuration::updateValue($this->name.'remindersec'.$this->_prefix_review, 0);

		
		Configuration::updateValue($this->name.'delay', 7);
        // orderstatuses
        Configuration::updateValue($this->name.'orderstatuses', implode(",",array(2,5,12)));
        // orderstatuses

        Configuration::updateValue($this->name.'breadvis_on', 1);
		

		
		// product reviews advanced 
		Configuration::updateValue($this->name.'rvis_on', 1);
        Configuration::updateValue($this->name.'ratings_on', 1);
		Configuration::updateValue($this->name.'text_on', 1);
		Configuration::updateValue($this->name.'title_on', 1);
		Configuration::updateValue($this->name.'ip_on', 1);
		Configuration::updateValue($this->name.'is_captcha', 1);

        Configuration::updateValue($this->name.'is_filterp', 1);
        Configuration::updateValue($this->name.'is_filterall', 1);



        Configuration::updateValue($this->name.'ptabs_type', 1);


        Configuration::updateValue($this->name.'is_abusef', 1);
        Configuration::updateValue($this->name.'is_helpfulf', 1);
        Configuration::updateValue($this->name.'is_sortf', 1);

        Configuration::updateValue($this->name.'rsoc_on', 1);
        Configuration::updateValue($this->name.'rsoccount_on', 1);

        Configuration::updateValue($this->name.'revperpagecus', 5);

        Configuration::updateValue($this->name.'is_blocklr', 1);

        Configuration::updateValue($this->name.'blocklr_home_pos', 'home');
        Configuration::updateValue($this->name.'blocklr_cat_pos', 'leftcol');
        Configuration::updateValue($this->name.'blocklr_man_pos', 'leftcol');
        Configuration::updateValue($this->name.'blocklr_prod_pos', 'leftcol');
        Configuration::updateValue($this->name.'blocklr_oth_pos', 'leftcol');
        Configuration::updateValue($this->name.'blocklr_chook_pos', 'chook');

        Configuration::updateValue($this->name.'blocklr_home_w', 100);
        Configuration::updateValue($this->name.'blocklr_cat_w', 100);
        Configuration::updateValue($this->name.'blocklr_man_w', 100);
        Configuration::updateValue($this->name.'blocklr_prod_w', 100);
        Configuration::updateValue($this->name.'blocklr_oth_w', 100);
        Configuration::updateValue($this->name.'blocklr_chook_w', 100);


        Configuration::updateValue($this->name.'blocklr_home', 'blocklr_home');
        Configuration::updateValue($this->name.'blocklr_cat', 'blocklr_cat');
        Configuration::updateValue($this->name.'blocklr_man', 'blocklr_man');
        Configuration::updateValue($this->name.'blocklr_prod', 'blocklr_prod');
        Configuration::updateValue($this->name.'blocklr_oth', 'blocklr_oth');
        Configuration::updateValue($this->name.'blocklr_chook', 'blocklr_chook');

        Configuration::updateValue($this->name.'blocklr_home_ndr', 3);
        Configuration::updateValue($this->name.'blocklr_cat_ndr', 3);
        Configuration::updateValue($this->name.'blocklr_man_ndr', 3);
        Configuration::updateValue($this->name.'blocklr_prod_ndr', 3);
        Configuration::updateValue($this->name.'blocklr_oth_ndr', 3);
        Configuration::updateValue($this->name.'blocklr_chook_ndr', 3);

        Configuration::updateValue($this->name.'blocklr_home_tr', 250);
        Configuration::updateValue($this->name.'blocklr_cat_tr', 75);
        Configuration::updateValue($this->name.'blocklr_man_tr', 75);
        Configuration::updateValue($this->name.'blocklr_prod_tr', 75);
        Configuration::updateValue($this->name.'blocklr_oth_tr', 75);
        Configuration::updateValue($this->name.'blocklr_chook_tr', 75);

        $img_default = "small"."_"."default";
        Configuration::updateValue($this->name . 'blocklr_home_im', $img_default);
        Configuration::updateValue($this->name . 'blocklr_cat_im', $img_default);
        Configuration::updateValue($this->name . 'blocklr_man_im', $img_default);
        Configuration::updateValue($this->name . 'blocklr_prod_im', $img_default);
        Configuration::updateValue($this->name . 'blocklr_oth_im', $img_default);
        Configuration::updateValue($this->name . 'blocklr_chook_im', $img_default);


        Configuration::updateValue($this->name.'img_size_em', $img_default);


        Configuration::updateValue($this->name.'rswitch_lng', 0);


		Configuration::updateValue($this->name.'revperpage', 5);
		Configuration::updateValue($this->name.'revperpageall', 10);

		Configuration::updateValue($this->name.'whocanadd', 'all');
		Configuration::updateValue($this->name.'is_approval', 0);
		Configuration::updateValue($this->name.'position', 'left');
		//Configuration::updateValue($this->name.'homeon', 1);
        if(version_compare(_PS_VERSION_, '1.7', '>')) {
            Configuration::updateValue($this->name . 'hooktodisplay', 'product_actions');
        } else {
            Configuration::updateValue($this->name . 'hooktodisplay', 'extra_right');
        }
		Configuration::updateValue($this->name.'stylestars', 'style1'); // yellow

        Configuration::updateValue($this->name.'starratingon', 1);
		Configuration::updateValue($this->name.'noti', 1);	
		Configuration::updateValue($this->name.'mail', @Configuration::get('PS_SHOP_EMAIL'));
		Configuration::updateValue($this->name.'lastrevitems', 5);

		
		Configuration::updateValue($this->name.'starscat', 1);
        Configuration::updateValue($this->name.'is_starscat', 0);
		// product reviews advanced
		
		// voucher settings

        Configuration::updateValue($this->name.'vis_on', 1);

        Configuration::updateValue($this->name.'is_show_min', 1);


        $languages = Language::getLanguages(false);
        foreach ($languages as $language){
            $i = $language['id_lang'];
            $iso = Tools::strtoupper(Language::getIsoById($i));

            $coupondesc = $this->displayName;
            Configuration::updateValue($this->name.'coupondesc_'.$i, $coupondesc.' '.$iso);
        }

        Configuration::updateValue($this->name.'vouchercode', "PRG");
        Configuration::updateValue($this->name.'discount_type', 2);
        Configuration::updateValue($this->name.'percentage_val', 1);

        Configuration::updateValue($this->name.'tax', 1);


        $cur = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);
        foreach ($cur AS $_cur){
            if(Configuration::get('PS_CURRENCY_DEFAULT') == $_cur['id_currency']){
                Configuration::updateValue('sdamount_'.(int)$_cur['id_currency'], 1);
            }
        }
        Configuration::updateValue($this->name.'sdvvalid', 365);

        // cumulable
        Configuration::updateValue($this->name.'cumulativeother', 0);
        Configuration::updateValue($this->name.'cumulativereduc', 0);
        // cumulable

        Configuration::updateValue($this->name.'highlight', 1);
        // categories
        Configuration::updateValue($this->name.'catbox', $this->getIdsCategories());
        // categories
        // voucher settings


        // voucher facebook settings

        $this->installVoucherShareReviewSettings();

        // voucher facebook settings
		
		
		Configuration::updateValue($this->name.'rsson', 1);
		Configuration::updateValue($this->name.'number_rssitems', 10);
		
		
		
		$languages = Language::getLanguages(false);
    	foreach ($languages as $language){
    		$i = $language['id_lang'];

    		$rssname = Configuration::get('PS_SHOP_NAME');
    		Configuration::updateValue($this->name.'rssname_'.$i, $rssname);
			$rssdesc = Configuration::get('PS_SHOP_NAME');
			Configuration::updateValue($this->name.'rssdesc_'.$i, $rssdesc);
		}
		
		$this->createAdminTabs15();

		if (!parent::install())
	 		return false;
	 	
	 	if (!$this->installTable() OR
            !$this->installCriteriaTable() OR
            !$this->installReviewCriteria() OR
            !$this->installReviewAbuse() OR
            !$this->installReviewHelpfull() OR
            !$this->installSocialShare() OR
            !$this->installReminder2CustomerTable() OR

            !$this->installUserTable() OR
            !$this->installFiles2ReviewTable() OR



            !$this->registerHook('leftColumn') OR
			!$this->registerHook('rightColumn') OR
			!$this->registerHook('header') OR 
			!$this->registerHook('ProductTab') OR
			!$this->registerHook('productTabContent') OR
			!$this->registerHook('footer') OR
			!$this->registerHook('extraLeft') OR
		 	!$this->registerHook('extraRight') OR
		 	!$this->registerHook('productfooter') OR


		 	//!$this->registerHook('productActions') OR
            !((version_compare(_PS_VERSION_, '1.7', '>'))? $this->registerHook('displayProductButtons') : $this->registerHook('productActions')) OR

		 	!$this->registerHook('home') OR
            !$this->registerHook('top') OR
		 	!$this->registerHook('customerAccount') OR
	 		!$this->registerHook('myAccountBlock') OR
	 		!$this->registerHook('OrderConfirmation') OR
            !((version_compare(_PS_VERSION_, '1.6', '>'))? $this->registerHook('displayProductListReviews') : true) OR
            !((version_compare(_PS_VERSION_, '1.5', '>'))? $this->registerHook('lastReviewsMitrocops') : true) OR
	 		!((version_compare(_PS_VERSION_, '1.5.0', '>'))? $this->registerHook('actionValidateOrder') : $this->registerHook('newOrder')) OR
	 		!($this->_is_cloud? true : $this->createFolderAndSetPermissions()) OR

            !($this->_is_cloud? true : $this->createFolderAndSetPermissionsAvatar()) OR
            !($this->_is_cloud? true : $this->createFolderAndSetPermissionsFiles()) OR


	 		!((version_compare(_PS_VERSION_, '1.6', '>'))? $this->registerHook('DisplayBackOfficeHeader') : true)


        	)
			return false;
	 	
	 	return true;
	}

    public function getPrefixReviews(){
        return $this->_prefix_review;
    }




	public function hookDisplayBackOfficeHeader()
	{


        ob_start();
        include(_PS_MODULE_DIR_.$this->name .'/views/templates/hooks/hookdisplayBackOfficeHeader.phtml');
        $css = ob_get_clean();

        return $css;



	}
	
	public function installVoucherShareReviewSettings(){
        // voucher facebook settings

        Configuration::updateValue($this->name.'vis_onfb', 1);

        Configuration::updateValue($this->name.'is_show_minfb', 1);


        $languages = Language::getLanguages(false);
        foreach ($languages as $language){
            $i = $language['id_lang'];
            $iso = Tools::strtoupper(Language::getIsoById($i));

            $coupondesc = $this->displayName;
            Configuration::updateValue($this->name.'coupondescfb_'.$i, $coupondesc.' '.$iso);
        }

        Configuration::updateValue($this->name.'vouchercodefb', "PRF");
        Configuration::updateValue($this->name.'discount_typefb', 2);
        Configuration::updateValue($this->name.'percentage_valfb', 1);

        Configuration::updateValue($this->name.'taxfb', 1);


        $cur = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);
        foreach ($cur AS $_cur){
            if(Configuration::get('PS_CURRENCY_DEFAULT') == $_cur['id_currency']){
                Configuration::updateValue('sdamountfb_'.(int)$_cur['id_currency'], 1);
            }
        }
        Configuration::updateValue($this->name.'sdvvalidfb', 365);

        // cumulable
        Configuration::updateValue($this->name.'cumulativeotherfb', 0);
        Configuration::updateValue($this->name.'cumulativereducfb', 0);
        // cumulable

        Configuration::updateValue($this->name.'highlightfb', 1);
        // categories
        Configuration::updateValue($this->name.'catboxfb', $this->getIdsCategories());
        // categories
        // voucher facebook settings
    }
	
	
	public function uninstall()
	{





        #### posts api ###
        $languages = Language::getLanguages(false);
        foreach ($languages as $language){
            $i = $language['id_lang'];
            Configuration::deleteByName($this->name.'twdesc_'.$i);
            Configuration::deleteByName($this->name.'vkdesc_'.$i);
        }
        #### posts api ###




        $languages = Language::getLanguages(false);
        foreach ($languages as $language){
            $i = $language['id_lang'];
            Configuration::deleteByName($this->name.'emailreminder_'.$i);
        }

        Configuration::deleteByName($this->name.'delay');



        // product reviews advanced
        Configuration::deleteByName($this->name.'rvis_on');
        Configuration::deleteByName($this->name.'ratings_on');
        Configuration::deleteByName($this->name.'text_on');
        Configuration::deleteByName($this->name.'title_on');
        Configuration::deleteByName($this->name.'ip_on');
        Configuration::deleteByName($this->name.'is_captcha');

        Configuration::deleteByName($this->name.'is_filterp');
        Configuration::deleteByName($this->name.'is_filterall');


        Configuration::deleteByName($this->name.'ptabs_type');

        Configuration::deleteByName($this->name.'is_abusef');
        Configuration::deleteByName($this->name.'is_helpfulf');
        Configuration::deleteByName($this->name.'is_sortf');

        Configuration::deleteByName($this->name.'rsoc_on');
        Configuration::deleteByName($this->name.'rsoccount_on');

        Configuration::deleteByName($this->name.'revperpagecus');
        Configuration::deleteByName($this->name.'is_blocklr');

        Configuration::deleteByName($this->name.'blocklr_home_pos');
        Configuration::deleteByName($this->name.'blocklr_cat_pos');
        Configuration::deleteByName($this->name.'blocklr_man_pos');
        Configuration::deleteByName($this->name.'blocklr_prod_pos');
        Configuration::deleteByName($this->name.'blocklr_oth_pos');
        Configuration::deleteByName($this->name.'blocklr_chook_pos');

        Configuration::deleteByName($this->name.'blocklr_home_w');
        Configuration::deleteByName($this->name.'blocklr_cat_w');
        Configuration::deleteByName($this->name.'blocklr_man_w');
        Configuration::deleteByName($this->name.'blocklr_prod_w');
        Configuration::deleteByName($this->name.'blocklr_oth_w');
        Configuration::deleteByName($this->name.'blocklr_chook_w');

        Configuration::deleteByName($this->name.'blocklr_home');
        Configuration::deleteByName($this->name.'blocklr_cat');
        Configuration::deleteByName($this->name.'blocklr_man');
        Configuration::deleteByName($this->name.'blocklr_prod');
        Configuration::deleteByName($this->name.'blocklr_oth');
        Configuration::deleteByName($this->name.'blocklr_chook');

        Configuration::deleteByName($this->name.'blocklr_home_ndr');
        Configuration::deleteByName($this->name.'blocklr_cat_ndr');
        Configuration::deleteByName($this->name.'blocklr_man_ndr');
        Configuration::deleteByName($this->name.'blocklr_prod_ndr');
        Configuration::deleteByName($this->name.'blocklr_oth_ndr');
        Configuration::deleteByName($this->name.'blocklr_chook_ndr');

        Configuration::deleteByName($this->name.'blocklr_home_tr');
        Configuration::deleteByName($this->name.'blocklr_cat_tr');
        Configuration::deleteByName($this->name.'blocklr_man_tr');
        Configuration::deleteByName($this->name.'blocklr_prod_tr');
        Configuration::deleteByName($this->name.'blocklr_oth_tr');
        Configuration::deleteByName($this->name.'blocklr_chook_tr');

        Configuration::deleteByName($this->name.'blocklr_home_im');
        Configuration::deleteByName($this->name.'blocklr_cat_im');
        Configuration::deleteByName($this->name.'blocklr_man_im');
        Configuration::deleteByName($this->name.'blocklr_prod_im');
        Configuration::deleteByName($this->name.'blocklr_oth_im');
        Configuration::deleteByName($this->name.'blocklr_chook_im');


        Configuration::deleteByName($this->name.'img_size_em');
        $languages = Language::getLanguages(false);
        foreach ($languages as $language){
            $i = $language['id_lang'];
            Configuration::deleteByName($this->name.'subpubem_'.$i);
            Configuration::deleteByName($this->name.'subresem_'.$i);
            Configuration::deleteByName($this->name.'textresem_'.$i);

        }

        Configuration::deleteByName($this->name.'rswitch_lng');


        Configuration::deleteByName($this->name.'revperpage');
        Configuration::deleteByName($this->name.'revperpageall');

        Configuration::deleteByName($this->name.'whocanadd');
        Configuration::deleteByName($this->name.'is_approval');

        Configuration::deleteByName($this->name.'position');

        Configuration::deleteByName($this->name.'hooktodisplay');
        Configuration::deleteByName($this->name.'stylestars');
        Configuration::deleteByName($this->name.'noti');

        Configuration::deleteByName($this->name.'mail');
        Configuration::deleteByName($this->name.'lastrevitems');


        Configuration::deleteByName($this->name.'starscat');
        // product reviews advanced


        // voucher settings

        Configuration::deleteByName($this->name.'vis_on');
        Configuration::deleteByName($this->name.'is_show_min');


        $languages = Language::getLanguages(false);
        foreach ($languages as $language){
            $i = $language['id_lang'];
            Configuration::deleteByName($this->name.'coupondesc_'.$i);
        }

        Configuration::deleteByName($this->name.'vouchercode');
        Configuration::deleteByName($this->name.'discount_type');
        Configuration::deleteByName($this->name.'percentage_val');

        Configuration::deleteByName($this->name.'tax');




        $cur = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);
        foreach ($cur AS $_cur){
            if(Configuration::get('PS_CURRENCY_DEFAULT') == $_cur['id_currency']){
                Configuration::deleteByName('sdamount_'.(int)$_cur['id_currency']);
            }
        }
        Configuration::deleteByName($this->name.'sdvvalid');
        // cumulable
        Configuration::deleteByName($this->name.'cumulativeother');
        Configuration::deleteByName($this->name.'cumulativereduc');
        // cumulable

        Configuration::deleteByName($this->name.'highlight');
        // categories
        Configuration::deleteByName($this->name.'catbox');
        // categories
        // voucher settings


        // voucher facebook settings

        Configuration::deleteByName($this->name.'vis_onfb');
        Configuration::deleteByName($this->name.'is_show_minfb');


        $languages = Language::getLanguages(false);
        foreach ($languages as $language){
            $i = $language['id_lang'];
            Configuration::deleteByName($this->name.'coupondescfb_'.$i);
        }

        Configuration::deleteByName($this->name.'vouchercodefb');
        Configuration::deleteByName($this->name.'discount_typefb');
        Configuration::deleteByName($this->name.'percentage_vafbl');

        Configuration::deleteByName($this->name.'taxfb');




        $cur = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);
        foreach ($cur AS $_cur){
            if(Configuration::get('PS_CURRENCY_DEFAULT') == $_cur['id_currency']){
                Configuration::deleteByName('sdamountfb_'.(int)$_cur['id_currency']);
            }
        }
        Configuration::deleteByName($this->name.'sdvvalidfb');
        // cumulable
        Configuration::deleteByName($this->name.'cumulativeotherfb');
        Configuration::deleteByName($this->name.'cumulativereducfb');
        // cumulable

        Configuration::deleteByName($this->name.'highlightfb');
        // categories
        Configuration::deleteByName($this->name.'catboxfb');
        // categories

        // voucher facebook settings


        Configuration::deleteByName($this->name.'rsson');
        Configuration::deleteByName($this->name.'number_rssitems');



        $languages = Language::getLanguages(false);
        foreach ($languages as $language){
            $i = $language['id_lang'];

            Configuration::deleteByName($this->name.'rssname_'.$i);
            Configuration::deleteByName($this->name.'rssdesc_'.$i);
        }

       	$this->uninstallTab15();



		if (!parent::uninstall() 
			|| !$this->uninstallTable()
			)
			return false;
		return true;
	}


    public function uninstallTab15(){

            $prefix = '';


		$tab_id = Tab::getIdFromClassName("AdminReview".$prefix);
        if($tab_id){
			$tab = new Tab($tab_id);

			$tab->delete();
		}


		$tab_id = Tab::getIdFromClassName("AdminReviews".$prefix);
		if($tab_id){
			$tab = new Tab($tab_id);
			$tab->delete();
		}
		
		@unlink(_PS_ROOT_DIR_."/img/t/AdminReview".$prefix.".gif");
		
		
	}
	
	



    public function createAdminTabs15(){

        $prefix = '';
    		@copy(dirname(__FILE__)."/views/img/AdminReview".$prefix.".gif",_PS_ROOT_DIR_."/img/t/AdminReview".$prefix.".gif");
		
		 	$langs = Language::getLanguages();
            
          
            $tab0 = new Tab();
            $tab0->class_name = "AdminReview".$prefix;
            $tab0->module = $this->name;
            $tab0->id_parent = 0; 
            foreach($langs as $l){
                    $tab0->name[$l['id_lang']] = (version_compare(_PS_VERSION_, '1.6', '>')?$this->l('Product Reviews'):$this->l('Reviews'));
            }
            $tab0->save();
            $main_tab_id = $tab0->id;

            unset($tab0);
            
            $tab1 = new Tab();
            $tab1->class_name = "AdminReviews".$prefix;
            $tab1->module = $this->name;
            $tab1->id_parent = $main_tab_id; 
            foreach($langs as $l){
                    $tab1->name[$l['id_lang']] = (version_compare(_PS_VERSION_, '1.6', '>')?$this->l('Moderate Product Reviews'):$this->l('Moderate Reviews'));
            }
            $tab1->save();

            unset($tab1);


          

	}




	private function uninstallTable() {
		Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv');
		Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_data_order');
		Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_customer');

        Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_review_criterion');
        Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_review_criterion_lang');
        Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_review2criterion');

        Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_review_abuse');

        Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_review_helpfull');

        Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_socialshare');

        Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_reminder2customer');



        Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_avatar2customer');
        Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'reviewsadv_files2review');

        return true;
	}

    public function installReviewCriteria(){


        $languages = Language::getLanguages(false);
        $data_content_lang = array();



        $shops = array();
        foreach(Shop::getShops() as $shop){
            $shops[] = $shop['id_shop'];
        }
        $cat_shop_association = $shops;


        foreach ($languages as $language){
            $id_lang = $language['id_lang'];
            $description = '';
            $name = $this->l('Total Rating');

                $data_content_lang[$id_lang] = array( 'description' => $description,
                                                        'name' => $name
                );
        }


        $data = array(
            'active' => 1,
            'data_content_lang'=>$data_content_lang,
            'cat_shop_association' => $cat_shop_association
        );



        include_once(_PS_MODULE_DIR_.$this->name . '/classes/reviewsadvhelp.class.php');
        $obj = new reviewsadvhelp();
        $obj->saveReviewCriteriaItem($data);

       return true;
    }
	
	public function installTable()
	{
		$db = Db::getInstance();
	
		$query = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv` (
							  `id` int(11) NOT NULL auto_increment,
							  `id_product` int(11) NOT NULL,
							  `id_customer` int(11) NOT NULL default \'0\',
							  `customer_name` varchar(500) default NULL,
							  `title_review` varchar(5000) default NULL,
							  `text_review` text,
							  `rating` int(11) NOT NULL default \'0\',

							  `title_review_old` varchar(5000) default NULL,
							  `text_review_old` text,
							  `rating_old` text,
							  `admin_response` text,
							  `is_changed` int(11) NOT NULL default \'0\',
							  `is_display_old` int(11) NOT NULL default \'0\',
							  `is_count_sending_suggestion` int(11) NOT NULL default \'0\',
							  `review_date_update` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

							  `avatar` text,


							  `email` VARCHAR(255) NOT NULL,
							  `ip` varchar(255) default NULL,
							  `id_shop` int(11) NOT NULL default \'0\',
							  `id_lang` int(11) NOT NULL default \'0\',
							  `is_abuse` int(11) NOT NULL default \'0\',
							  `is_active` int(11) NOT NULL default \'1\',
							  `time_add` timestamp NULL,
							  `is_import` int(11) NOT NULL default \'0\',
							  PRIMARY KEY  (`id`),
							  KEY `id_product` (`id_product`),
							  KEY `id_customer` (`id_customer`)
							) ENGINE='.(defined(_MYSQL_ENGINE_)?_MYSQL_ENGINE:"MyISAM").' DEFAULT CHARSET=utf8;';
		$db->Execute($query);
		
		$sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_data_order` (
					  `id` int(10) NOT NULL AUTO_INCREMENT,
					  `id_shop` int(11) NOT NULL default \'0\',
					  `order_id` int(10) NOT NULL,
					  `date_add` timestamp NOT NULL DEFAULT \'0000-00-00 00:00:00\',
					  `status` int(10) NOT NULL default \'0\',
					  `customer_id` int(11) NOT NULL default \'0\',
					  `data` text,
					  `date_send` timestamp NULL,
					  `date_send_second` timestamp NULL,
                      `count_sent` int(10) NOT NULL default \'0\',
					  PRIMARY KEY (`id`)
					) ENGINE='.(defined(_MYSQL_ENGINE_)?_MYSQL_ENGINE:"MyISAM").' DEFAULT CHARSET=utf8;';
		$db->Execute($sql);
		
		$sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_customer` (
						  `id_shop` int(11) NOT NULL default \'0\',
						  `customer_id` int(11) NOT NULL default \'0\',
						  `status` int(10) NOT NULL default \'0\',
						   KEY (`id_shop`,`customer_id`),
						  KEY `shop_status` (`id_shop`,`status`)
						) ENGINE='.(defined(_MYSQL_ENGINE_)?_MYSQL_ENGINE:"MyISAM").' DEFAULT CHARSET=utf8;';
		$db->Execute($sql);
		return true;
	}

    public function installSocialShare(){
        $db = Db::getInstance();

        $sql_coupon = '
				CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_socialshare` (
					`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
					`id_discount` INT( 11 ) NOT NULL ,
					`ip_adress` VARCHAR(255) NOT NULL,
					`id_guest` INT( 11 ) NOT NULL ,
					`id_customer` INT( 11 ) NOT NULL ,
					`id_review` INT( 11 ) NOT NULL ,
					`type` int(11) NOT NULL default \'0\'
					  COMMENT \'1 - Facebook, 2 - Google  \',
				    INDEX (`id_discount`)
				) ENGINE=InnoDB DEFAULT CHARSET=utf8;
				';
        $db->Execute($sql_coupon);

        return true;
    }

    public function installReviewHelpfull(){
        $db = Db::getInstance();
        $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_review_helpfull` (
						  `id_customer` int(11)  NOT NULL,
                          `review_id` int(11) NOT NULL,
                          `is_guest` int(11) NOT NULL default \'0\',
                          `ip` varchar(255) default NULL,
                          `helpfull` tinyint(1) NOT NULL,
                          KEY (`id_customer`,`review_id`)
						) ENGINE='.(defined(_MYSQL_ENGINE_)?_MYSQL_ENGINE:"MyISAM").' DEFAULT CHARSET=utf8;';

        $db->Execute($sql);
        return true;
    }

    public function installReviewAbuse(){
        $db = Db::getInstance();
        $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_review_abuse` (
						  `review_id` int UNSIGNED NOT NULL DEFAULT \'0\',
                          `id_customer` INT UNSIGNED NOT NULL,
                          `name` VARCHAR(500)  default NULL ,
                          `email` VARCHAR(255) default NULL ,
                          `text_abuse` text,
                          `is_customer` int(11) NOT NULL default \'0\',
                          KEY (`review_id`,`id_customer`)
						) ENGINE='.(defined(_MYSQL_ENGINE_)?_MYSQL_ENGINE:"MyISAM").' DEFAULT CHARSET=utf8;';

        $db->Execute($sql);
        return true;
    }

    public function installCriteriaTable(){
        $db = Db::getInstance();
        $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_review_criterion` (
						  `id_reviewsadv_review_criterion` int(10) unsigned NOT NULL auto_increment,
						  `id_shop` varchar(1024) NOT NULL default \'0\',
						  id_product text,
						  `id_category` text,
						  `is_category` int(11) NOT NULL default \'0\',
                          `active` tinyint(1) NOT NULL,
                          PRIMARY KEY (`id_reviewsadv_review_criterion`)
						) ENGINE='.(defined(_MYSQL_ENGINE_)?_MYSQL_ENGINE:"MyISAM").' DEFAULT CHARSET=utf8;';

        $db->Execute($sql);

        $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_review_criterion_lang` (
						  `id_reviewsadv_review_criterion` INT(11) UNSIGNED NOT NULL ,
                          `id_lang` INT(11) UNSIGNED NOT NULL ,
                          `name` VARCHAR(255) NOT NULL ,
                          `description` text,
                          KEY ( `id_reviewsadv_review_criterion` , `id_lang` )
						) ENGINE='.(defined(_MYSQL_ENGINE_)?_MYSQL_ENGINE:"MyISAM").' DEFAULT CHARSET=utf8;';

        $db->Execute($sql);


        $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_review2criterion` (
						  `id_review` int(10) unsigned NOT NULL,
                          `id_criterion` int(10) unsigned NOT NULL,
                          `rating` INT(11) NOT NULL DEFAULT \'0\',
                           KEY(`id_review`, `id_criterion`),
                          KEY `id_criterion` (`id_criterion`)
						) ENGINE='.(defined(_MYSQL_ENGINE_)?_MYSQL_ENGINE:"MyISAM").' DEFAULT CHARSET=utf8;';

        $db->Execute($sql);

        return true;
    }

    public function installReminder2CustomerTable(){
        $db = Db::getInstance();


        $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_reminder2customer` (
						  `id_customer` int(10) unsigned NOT NULL,
                          `id_shop` int(10) NOT NULL DEFAULT \'0\',
                          `status` INT(11) NOT NULL DEFAULT \'0\',
                           KEY `id_c2id_shop` (`id_customer`, `id_shop`),
                          KEY `id_customer` (`id_shop`)
						) ENGINE='.(defined(_MYSQL_ENGINE_)?_MYSQL_ENGINE:"MyISAM").' DEFAULT CHARSET=utf8;';

        $db->Execute($sql);

        return true;
    }


    public function installUserTable(){

        $db = Db::getInstance();
        $query = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_avatar2customer` (
							  `id_customer` int(11) NOT NULL,
							  `avatar_thumb` text,
							  `is_show` int(11) NOT NULL default \'1\',
							  KEY `id_customer` (`id_customer`)
							) ENGINE='.(defined('_MYSQL_ENGINE_')?_MYSQL_ENGINE_:"MyISAM").' DEFAULT CHARSET=utf8';
        $db->Execute($query);
        return true;

    }

    public function installFiles2ReviewTable(){

        $db = Db::getInstance();
        $query = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reviewsadv_files2review` (
                              `id_reviewsadv_files2review` int(10) unsigned NOT NULL auto_increment,
							  `id_review` int(11) NOT NULL,
							  `full_path` text,
							 PRIMARY KEY (`id_reviewsadv_files2review`)
							) ENGINE='.(defined('_MYSQL_ENGINE_')?_MYSQL_ENGINE_:"MyISAM").' DEFAULT CHARSET=utf8';
        $db->Execute($query);
        return true;

    }


    public function createFolderAndSetPermissions(){

        $prev_cwd = getcwd();

        $module_dir = dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR;
        @chdir($module_dir);
        //folder avatars
        $module_dir_img = $module_dir.$this->name.DIRECTORY_SEPARATOR;
        @mkdir($module_dir_img, 0777);

        @chdir($prev_cwd);

        return true;
    }

    public function createFolderAndSetPermissionsAvatar(){

        $prev_cwd = getcwd();

        $module_dir = dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR;
        @chdir($module_dir);
        //folder avatars
        $module_dir_img = $module_dir.$this->name.DIRECTORY_SEPARATOR;
        @mkdir($module_dir_img, 0777);

        @chdir($module_dir_img);

        $module_dir_img_avatar = $module_dir.$this->name.DIRECTORY_SEPARATOR."avatar".DIRECTORY_SEPARATOR;
        @mkdir($module_dir_img_avatar, 0777);

        @chdir($prev_cwd);

        return true;
    }


    public function createFolderAndSetPermissionsFiles(){

        $prev_cwd = getcwd();

        $module_dir = dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR;
        @chdir($module_dir);
        //folder avatars
        $module_dir_img = $module_dir.$this->name.DIRECTORY_SEPARATOR;
        @mkdir($module_dir_img, 0777);

        @chdir($module_dir_img);

        $module_dir_img_files_tmp = $module_dir.$this->name.DIRECTORY_SEPARATOR."tmp".DIRECTORY_SEPARATOR;
        @mkdir($module_dir_img_files_tmp, 0777);

        $module_dir_img_files = $module_dir.$this->name.DIRECTORY_SEPARATOR."files".DIRECTORY_SEPARATOR;
        @mkdir($module_dir_img_files, 0777);

        @chdir($prev_cwd);

        return true;
    }




    public function getContent()
    {
    	$cookie = $this->context->cookie;
		
    	$currentIndex = $this->context->currentindex;
    	 
    	$_html = '';
        $errors = array();


        $this->addBackOfficeMedia();

        ## product reviews owl sliders and WOW effects ###

        $woweffectssettingsset = Tools::getValue("woweffectssettingsset");
        if (Tools::strlen($woweffectssettingsset)>0) {

            ob_start();
            $number_tab = 58;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();




        }

        if (Tools::isSubmit('woweffectssettings'))
        {

            Configuration::updateValue($this->name.'d_eff_rev', Tools::getValue('d_eff_rev'));
            Configuration::updateValue($this->name.'d_eff_rev_my', Tools::getValue('d_eff_rev_my'));
            Configuration::updateValue($this->name.'d_eff_rev_u', Tools::getValue('d_eff_rev_u'));
            Configuration::updateValue($this->name.'d_eff_rev_all', Tools::getValue('d_eff_rev_all'));

            // clear cache //
            $this->clearSmartyCacheItems();
            // clear cache //
            $url = $currentIndex . '&conf=6&tab=AdminModules&woweffectssettingsset=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
            Tools::redirectAdmin($url);


        }



        $owlcarouselssettingsset = Tools::getValue("owlcarouselssettingsset");
        if (Tools::strlen($owlcarouselssettingsset)>0) {

            ob_start();
            $number_tab = 57;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }

        if (Tools::isSubmit('owlcarouselssettings'))
        {

            Configuration::updateValue($this->name.'sr_sliderr', Tools::getValue('sr_sliderr'));
            if(!ctype_digit(Tools::getValue('sr_slr')) || Tools::getValue('sr_slr') == NULL) {
                $errors[] = $this->l('Displayed number of items in the slider in the block Last Reviews block in the Left, Right, Footer positions').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name.'sr_slr', Tools::getValue('sr_slr'));
            }

            Configuration::updateValue($this->name.'sr_sliderhr', Tools::getValue('sr_sliderhr'));
            if(!ctype_digit(Tools::getValue('sr_slhr')) || Tools::getValue('sr_slhr') == NULL) {
                $errors[] = $this->l('Displayed number of items in the slider in the block Last Reviews block on the Home Page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name.'sr_slhr', Tools::getValue('sr_slhr'));
            }


            if(count($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&owlcarouselssettingsset=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {

                ob_start();
                $number_tab = 57;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();

            }

        }

        ## product reviews owl sliders and WOW effects ###




        $start_end_orders_reviews = Tools::getValue("start_end_orders_reviews");
        if (Tools::strlen($start_end_orders_reviews)>0) {

            ob_start();
            $number_tab = 44;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        $start_date_orders = Tools::getValue('start_date_orders');
        $end_date_orders = Tools::getValue('end_date_orders');

        if (($start_date_orders || $end_date_orders) && !$start_end_orders_reviews) {

            $url = $currentIndex.'&conf=6&tab=AdminModules&start_date_orders='.$start_date_orders.'&end_date_orders='.$end_date_orders.'&start_end_orders_reviews=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
            Tools::redirectAdmin($url);



        }

        ### csv import ###
        $csvset = Tools::getValue("csvset");
        if (Tools::strlen($csvset)>0) {

            ob_start();
            $number_tab = 45;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }

        if (Tools::isSubmit('product_csv')) {

            $name_class =  'csvhelp'.$this->_prefix_review;
            include_once(_PS_MODULE_DIR_.$this->name.'/classes/'.$name_class.'.class.php');
            $obj_csv = new $name_class;
            $error_data = $obj_csv->import();

            $error_number = $error_data['error_number'];

            switch($error_number){
                case 1:
                    $errors[] = Tools::displayError('Please select the CSV file');
                    break;
                case 2:
                    $errors[] = Tools::displayError('Your CSV file is empty');
                    break;

            }


            if(sizeof($errors)==0) {

                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //

                $url = $currentIndex . '&conf=18&tab=AdminModules&csvset=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {

                ob_start();
                $number_tab = 45;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();


            }
        }
        ### csv import ###


        #### user profile ###
        $userprofilegset = Tools::getValue("userprofilegset");
        if (Tools::strlen($userprofilegset)>0) {

            ob_start();
            $number_tab = 56;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();


        }
        if (Tools::isSubmit('userprofilegsettings'))
        {
            Configuration::updateValue($this->name.'is_uprof', Tools::getValue('is_uprof'));

            Configuration::updateValue($this->name.'is_proftab', Tools::getValue('is_proftab'));




            if(!ctype_digit(Tools::getValue('perpageu' . $this->_prefix_review)) || Tools::getValue('perpageu' . $this->_prefix_review) == NULL) {
                $errors[] = $this->l('Product reviews per Page on the User Page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'perpageu' . $this->_prefix_review, Tools::getValue('perpageu' . $this->_prefix_review));
            }

            if(!ctype_digit(Tools::getValue('rpage_shoppers')) || Tools::getValue('rpage_shoppers') == NULL) {
                $errors[] = $this->l('Users per page in the list view must be digit!');
            } else {
                Configuration::updateValue($this->name . 'rpage_shoppers', Tools::getValue('rpage_shoppers'));
            }

            Configuration::updateValue($this->name.'radv_home', Tools::getValue('radv_home'));
            Configuration::updateValue($this->name.'radv_left', Tools::getValue('radv_left'));
            Configuration::updateValue($this->name.'radv_right', Tools::getValue('radv_right'));
            Configuration::updateValue($this->name.'radv_footer', Tools::getValue('radv_footer'));

            if(!ctype_digit(Tools::getValue('rshoppers_blc')) || Tools::getValue('rshoppers_blc') == NULL) {
                $errors[] = $this->l('The number of shoppers in the "Block Users"').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'rshoppers_blc', Tools::getValue('rshoppers_blc'));
            }


            Configuration::updateValue($this->name.'sr_slideru', Tools::getValue('sr_slideru'));
            if(!ctype_digit(Tools::getValue('sr_slu')) || Tools::getValue('sr_slu') == NULL) {
                $errors[] = $this->l('Displayed number of items in the slider in the block Block Users block in the Left, Right, Footer positions').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name.'sr_slu', Tools::getValue('sr_slu'));
            }

            Configuration::updateValue($this->name.'sr_sliderhu', Tools::getValue('sr_sliderhu'));
            if(!ctype_digit(Tools::getValue('sr_slhu')) || Tools::getValue('sr_slhu') == NULL) {
                $errors[] = $this->l('Displayed number of items in the slider in the block Users block on the Home Page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name.'sr_slhu', Tools::getValue('sr_slhu'));
            }

            Configuration::updateValue($this->name.'d_eff_shopu', Tools::getValue('d_eff_shopu'));

            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&userprofilegset=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 56;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();

            }
        }


    	#### posts api ###
    	$vkset = Tools::getValue("vkset");
        if (Tools::strlen($vkset)>0) {

            ob_start();
            $number_tab = 8;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();
        }
    	if (Tools::isSubmit('psvkpostsettings'))
        {
        	Configuration::updateValue($this->name.'vkpost_on', Tools::getValue('vkpost_on'));
        	
        	$languages = Language::getLanguages(false);
        	foreach ($languages as $language){
    			$i = $language['id_lang'];
        		Configuration::updateValue($this->name.'vkdesc_'.$i, Tools::getValue('vkdesc_'.$i));
        	}
        	
        	$url = $currentIndex.'&conf=6&tab=AdminModules&vkset=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
        	Tools::redirectAdmin($url);
        }
        
        
        
    	$twset = Tools::getValue("twset");
        if (Tools::strlen($twset)>0) {
            ob_start();
            $number_tab = 8;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();
        }
    	if (Tools::isSubmit('pstwitterpostsettings'))
        {
        	Configuration::updateValue($this->name.'twpost_on', Tools::getValue('twpost_on'));
        	
        	
        	$languages = Language::getLanguages(false);
        	foreach ($languages as $language){
    			$i = $language['id_lang'];
        		Configuration::updateValue($this->name.'twdesc_'.$i, Tools::getValue('twdesc_'.$i));
        	}
        	
        	$url = $currentIndex.'&conf=6&tab=AdminModules&twset=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
        	Tools::redirectAdmin($url);
        }
    	#### posts api ###
    	
    	


        ### global settings ###
        $revglobalsettings = Tools::getValue("revglobalsettings");
        if (Tools::strlen($revglobalsettings)>0) {

            ob_start();
            $number_tab = 31;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('globalsettings'))
        {
            Configuration::updateValue($this->name.'rvis_on', Tools::getValue('rvis_on'));
            Configuration::updateValue($this->name.'ratings_on', Tools::getValue('ratings_on'));
            Configuration::updateValue($this->name.'text_on', Tools::getValue('text_on'));
            Configuration::updateValue($this->name.'title_on', Tools::getValue('title_on'));
            Configuration::updateValue($this->name.'ip_on', Tools::getValue('ip_on'));
            Configuration::updateValue($this->name.'is_captcha', Tools::getValue('is_captcha'));

            Configuration::updateValue($this->name.'is_filterp', Tools::getValue('is_filterp'));
            Configuration::updateValue($this->name.'is_filterall', Tools::getValue('is_filterall'));

            Configuration::updateValue($this->name.'is_avatar'.$this->_prefix_review, Tools::getValue('is_avatar'.$this->_prefix_review));
            Configuration::updateValue($this->name.'is_files'.$this->_prefix_review, Tools::getValue('is_files'.$this->_prefix_review));


            if(!ctype_digit(Tools::getValue('ruploadfiles')) || Tools::getValue('ruploadfiles') == NULL) {
                $errors[] = $this->l('Number of files user can add for review').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'ruploadfiles', Tools::getValue('ruploadfiles'));
            }


            if(!ctype_digit(Tools::getValue('rminc')) || Tools::getValue('rminc') == NULL) {
                $errors[] = $this->l('Minimum chars the user must write in the Text field for add review').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'rminc', Tools::getValue('rminc'));
            }


            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&revglobalsettings=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 31;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();
            }

        }
        ### global settings ###


        ### product page settings ###
        $revproductpagesettings = Tools::getValue("revproductpagesettings");
        if (Tools::strlen($revproductpagesettings)>0) {

            ob_start();
            $number_tab = 32;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('productpagesettings'))
        {
            Configuration::updateValue($this->name.'ptabs_type', Tools::getValue('ptabs_type'));
            Configuration::updateValue($this->name.'is_abusef', Tools::getValue('is_abusef'));
            Configuration::updateValue($this->name.'is_helpfulf', Tools::getValue('is_helpfulf'));
            Configuration::updateValue($this->name.'is_sortf', Tools::getValue('is_sortf'));

            Configuration::updateValue($this->name.'hooktodisplay', Tools::getValue('hooktodisplay'));
            Configuration::updateValue($this->name.'starratingon', Tools::getValue('starratingon'));
            Configuration::updateValue($this->name.'stylestars', Tools::getValue('stylestars'));

            if(!ctype_digit(Tools::getValue('revperpage')) || Tools::getValue('revperpage') == NULL) {
                $errors[] = $this->l('Number of reviews per page on Product page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'revperpage', Tools::getValue('revperpage'));
            }


            Configuration::updateValue($this->name.'rsoc_on', Tools::getValue('rsoc_on'));
            Configuration::updateValue($this->name.'rsoccount_on', Tools::getValue('rsoccount_on'));

            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&revproductpagesettings=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 32;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();
            }

        }
        ### product page settings ###

        ### reviewsmanagementsettings settings ###
        $revreviewsmanagementsettings = Tools::getValue("revreviewsmanagementsettings");
        if (Tools::strlen($revreviewsmanagementsettings)>0) {
            ob_start();
            $number_tab = 33;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('reviewsmanagementsettings'))
        {
            Configuration::updateValue($this->name.'is_approval', Tools::getValue('is_approval'));
            Configuration::updateValue($this->name.'whocanadd', Tools::getValue('whocanadd'));
            Configuration::updateValue($this->name.'rswitch_lng', Tools::getValue('rswitch_lng'));

            if(!ctype_digit(Tools::getValue('revperpageall')) || Tools::getValue('revperpageall') == NULL) {
                $errors[] = $this->l('Number of reviews per page on All Reviews page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'revperpageall', Tools::getValue('revperpageall'));
            }



            Configuration::updateValue($this->name.'is_onerev', Tools::getValue('is_onerev'));

            Configuration::updateValue($this->name.'is_sortallf', Tools::getValue('is_sortallf'));

            Configuration::updateValue($this->name.'is_sortfu', Tools::getValue('is_sortfu'));


            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&revreviewsmanagementsettings=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 33;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();
            }

        }
        ### addcriteriasettings settings ###


        ### customeraccountreviewspage settings ###
        if (Tools::isSubmit("reviewsadvcriteriaset") && !$this->_is15)
        {

            $url = $currentIndex.'&tab=AdminModules&revcriteriasettings=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
            Tools::redirectAdmin($url);
        }

        $revcriteriasettings = Tools::getValue("revcriteriasettings");

        $addCriteria = Tools::isSubmit("addCriteria");
        $editreviewsadv = Tools::isSubmit('editreviewsadv');
        $delete_itemreviewsadv = Tools::isSubmit("delete_itemreviewsadv");

        if (Tools::strlen($revcriteriasettings)>0
            || $addCriteria || $editreviewsadv || $delete_itemreviewsadv) {
            ob_start();
            $number_tab = 34;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit("reviewsadvcriteriaset")) {
            ob_start();
            $number_tab = 34;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }

        if (Tools::isSubmit("delete_itemreviewsadv")) {
            if (Validate::isInt(Tools::getValue("id"))) {
                $data = array('id' => Tools::getValue("id"));
                include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
                $obj_reviewsadvhelp = new reviewsadvhelp();
                $obj_reviewsadvhelp->deleteReviewCriteriaItem($data);

                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //

                $url = $currentIndex.'&conf=1&tab=AdminModules&revcriteriasettings=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
                Tools::redirectAdmin($url);
            }

        }

        if (Tools::isSubmit('editcriteriasettings'))
        {
            $id = Tools::getValue("id");

            //var_dump($_REQUEST);exit;

            $cat_shop_association = Tools::getValue("cat_shop_association");

            $languages = Language::getLanguages(false);
            $data_content_lang = array();

            $data_content_lang_name = array();

            foreach ($languages as $language){
                $id_lang = $language['id_lang'];
                $description = Tools::getValue("description_".$id_lang);
                $name = Tools::getValue("name_".$id_lang);
                if(Tools::strlen($name)>0)
                {
                    $data_content_lang[$id_lang] = array('description' => $description,
                                                         'name' => $name);
                    $data_content_lang_name[$id_lang] = array('name' => $name);
                }
            }

            $active = Tools::getValue("active");


            $choose_type = Tools::getValue('criterion_type');
            $categoryBox = Tools::getValue('categoryBoxc');
            $ids_products = Tools::getValue("inputAccessories");

            $data = array('active' => $active,
                          'data_content_lang'=>$data_content_lang,
                          'cat_shop_association' => $cat_shop_association,
                          'id' => $id,

                          'id_product' => $ids_products,
                          'choose_type' => $choose_type,
                          'categoryBox' => $categoryBox,

            );
            if(sizeof($data_content_lang_name)>0 && $cat_shop_association){
                include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
                $obj_reviewsadvhelp = new reviewsadvhelp();
                $obj_reviewsadvhelp->updateReviewCriteriaItem($data);

            } else {
                $error = 2;
                $errors[] = $this->l('Criterion name or Shop association is empty!');
                //$_html .= $this->_error(array('text' => 'Criterion name or Description is empty!'));
                $this->_criterion_error = 1;

            }



            if($error == 0){

                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //

                $url = $currentIndex.'&conf=4&tab=AdminModules&revcriteriasettings=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
                Tools::redirectAdmin($url);
            }


        }

        //echo "<pre>"; var_dump($_POST);var_dumP(Tools::isSubmit('addcriteriasettings'));exit;
        if (Tools::isSubmit('addcriteriasettings'))
        {
            $languages = Language::getLanguages(false);
            $data_content_lang = array();
            $data_content_lang_name = array();


            $cat_shop_association = Tools::getValue("cat_shop_association");


            foreach ($languages as $language){
                $id_lang = $language['id_lang'];
                $description = Tools::getValue("description_".$id_lang);
                $name = Tools::getValue("name_".$id_lang);
                if(Tools::strlen($name)>0)
                {
                    $data_content_lang[$id_lang] = array( 'description' => $description,
                                                           'name' => $name
                                                        );
                    $data_content_lang_name[$id_lang] = array('name' => $name);
                }
            }

            $active = Tools::getValue("active");

            $choose_type = Tools::getValue('criterion_type');
            $categoryBox = Tools::getValue('categoryBoxc');
            $ids_products = Tools::getValue("inputAccessories");


            $data = array(
                'active' => $active,
                'data_content_lang'=>$data_content_lang,
                'cat_shop_association' => $cat_shop_association,
                'id_product' => $ids_products,
                'choose_type' => $choose_type,
                'categoryBox' => $categoryBox,
            );


            //echo "<pre>"; var_dump($data);exit;

            if(sizeof($data_content_lang_name)>0 && $cat_shop_association){
                include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
                $obj_reviewsadvhelp = new reviewsadvhelp();
                $obj_reviewsadvhelp->saveReviewCriteriaItem($data);

            } else {
                $error = 2;
                $errors[] = $this->l('Criterion name or Shop association is empty!');
                //$_html .= $this->_error(array('text' => 'Criterion name or Description or Shop association is empty!'));
                $this->_criterion_error = 1;

            }


            if($error == 0){

                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //

                $url = $currentIndex.'&conf=3&tab=AdminModules&revcriteriasettings=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
                Tools::redirectAdmin($url);
            }




        }
        ### addcriteriasettings settings ###


        ### customeraccountreviewspage settings ###
        $revcustomeraccountreviewspagesettings = Tools::getValue("revcustomeraccountreviewspagesettings");
        if (Tools::strlen($revcustomeraccountreviewspagesettings)>0) {
            ob_start();
            $number_tab = 35;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('customeraccountreviewspagesettings'))
        {
            if(!ctype_digit(Tools::getValue('revperpagecus')) || Tools::getValue('revperpagecus') == NULL) {
                $errors[] = $this->l('Number of reviews per page on Customer account page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'revperpagecus', Tools::getValue('revperpagecus'));
            }

            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&revcustomeraccountreviewspagesettings=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 35;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();
            }

        }
        ### customeraccountreviewspage settings ###


        ### lastreviewsblock settings ###
        $revlastreviewsblocksettings = Tools::getValue("revlastreviewsblocksettings");
        if (Tools::strlen($revlastreviewsblocksettings)>0) {
            ob_start();
            $number_tab = 36;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('lastreviewsblocksettings'))
        {
            Configuration::updateValue($this->name.'is_blocklr', Tools::getValue('is_blocklr'));

            Configuration::updateValue($this->name.'blocklr_home_pos', Tools::getValue('pblocklr_home'));
            Configuration::updateValue($this->name.'blocklr_cat_pos', Tools::getValue('pblocklr_cat'));
            Configuration::updateValue($this->name.'blocklr_man_pos', Tools::getValue('pblocklr_man'));
            Configuration::updateValue($this->name.'blocklr_prod_pos', Tools::getValue('pblocklr_prod'));
            Configuration::updateValue($this->name.'blocklr_oth_pos', Tools::getValue('pblocklr_oth'));
            Configuration::updateValue($this->name.'blocklr_chook_pos', Tools::getValue('pblocklr_chook'));

            if(!ctype_digit(Tools::getValue('blocklr_home_w')) || Tools::getValue('blocklr_home_w') == NULL) {
                $errors[] = $this->l('Width').' '.$this->l('Last Reviews Block').' '.$this->l('for home page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_home_w', Tools::getValue('blocklr_home_w'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_cat_w')) || Tools::getValue('blocklr_cat_w') == NULL) {
                $errors[] = $this->l('Width').' '.$this->l('Last Reviews Block').' '.$this->l('for each category page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_cat_w', Tools::getValue('blocklr_cat_w'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_man_w')) || Tools::getValue('blocklr_man_w') == NULL) {
                $errors[] = $this->l('Width').' '.$this->l('Last Reviews Block').' '.$this->l('for each manufacturer/brand').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_man_w', Tools::getValue('blocklr_man_w'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_prod_w')) || Tools::getValue('blocklr_prod_w') == NULL) {
                $errors[] = $this->l('Width').' '.$this->l('Last Reviews Block').' '.$this->l('for each product page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_prod_w', Tools::getValue('blocklr_prod_w'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_oth_w')) || Tools::getValue('blocklr_oth_w') == NULL) {
                $errors[] = $this->l('Width').' '.$this->l('Last Reviews Block').' '.$this->l('for other pages').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_oth_w', Tools::getValue('blocklr_oth_w'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_chook_w')) || Tools::getValue('blocklr_chook_w') == NULL) {
                $errors[] = $this->l('Width').' '.$this->l('Last Reviews Block').' '.$this->l('for CUSTOM HOOK pages').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_chook_w', Tools::getValue('blocklr_chook_w'));
            }


            Configuration::updateValue($this->name.'blocklr_home', Tools::getValue('blocklr_home'));
            Configuration::updateValue($this->name.'blocklr_cat', Tools::getValue('blocklr_cat'));
            Configuration::updateValue($this->name.'blocklr_man', Tools::getValue('blocklr_man'));
            Configuration::updateValue($this->name.'blocklr_prod', Tools::getValue('blocklr_prod'));
            Configuration::updateValue($this->name.'blocklr_oth', Tools::getValue('blocklr_oth'));
            Configuration::updateValue($this->name.'blocklr_chook', Tools::getValue('blocklr_chook'));


            if(!ctype_digit(Tools::getValue('blocklr_home_ndr')) || Tools::getValue('blocklr_home_ndr') == NULL) {
                $errors[] = $this->l('Number').' '.$this->l('of displayed reviews').' '.$this->l('for home page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_home_ndr', Tools::getValue('blocklr_home_ndr'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_cat_ndr')) || Tools::getValue('blocklr_cat_ndr') == NULL) {
                $errors[] = $this->l('Number').' '.$this->l('of displayed reviews').' '.$this->l('for each category page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_cat_ndr', Tools::getValue('blocklr_cat_ndr'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_man_ndr')) || Tools::getValue('blocklr_man_ndr') == NULL) {
                $errors[] = $this->l('Number').' '.$this->l('of displayed reviews').' '.$this->l('for each manufacturer/brand page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_man_ndr', Tools::getValue('blocklr_man_ndr'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_prod_ndr')) || Tools::getValue('blocklr_prod_ndr') == NULL) {
                $errors[] = $this->l('Number').' '.$this->l('of displayed reviews').' '.$this->l('for each product page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_prod_ndr', Tools::getValue('blocklr_prod_ndr'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_oth_ndr')) || Tools::getValue('blocklr_oth_ndr') == NULL) {
                $errors[] = $this->l('Number').' '.$this->l('of displayed reviews').' '.$this->l('for other pages').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_oth_ndr', Tools::getValue('blocklr_oth_ndr'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_chook_ndr')) || Tools::getValue('blocklr_chook_ndr') == NULL) {
                $errors[] = $this->l('Number').' '.$this->l('of displayed reviews').' '.$this->l('for CUSTOM HOOK pages').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_chook_ndr', Tools::getValue('blocklr_chook_ndr'));
            }







            if(!ctype_digit(Tools::getValue('blocklr_home_tr')) || Tools::getValue('blocklr_home_tr') == NULL) {
                $errors[] = $this->l('Truncate').' '.$this->l('reviews').' '.$this->l('for home page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_home_tr', Tools::getValue('blocklr_home_tr'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_cat_tr')) || Tools::getValue('blocklr_cat_tr') == NULL) {
                $errors[] = $this->l('Truncate').' '.$this->l('reviews').' '.$this->l('for each category page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_cat_tr', Tools::getValue('blocklr_cat_tr'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_man_tr')) || Tools::getValue('blocklr_man_tr') == NULL) {
                $errors[] = $this->l('Truncate').' '.$this->l('reviews').' '.$this->l('for each manufacturer/brand page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_man_tr', Tools::getValue('blocklr_man_tr'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_prod_tr')) || Tools::getValue('blocklr_prod_tr') == NULL) {
                $errors[] = $this->l('Truncate').' '.$this->l('reviews').' '.$this->l('for each product page').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_prod_tr', Tools::getValue('blocklr_prod_tr'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_oth_tr')) || Tools::getValue('blocklr_oth_tr') == NULL) {
                $errors[] = $this->l('Truncate').' '.$this->l('reviews').' '.$this->l('for other pages').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_oth_tr', Tools::getValue('blocklr_oth_tr'));
            }

            if(!ctype_digit(Tools::getValue('blocklr_chook_tr')) || Tools::getValue('blocklr_chook_tr') == NULL) {
                $errors[] = $this->l('Truncate').' '.$this->l('reviews').' '.$this->l('for CUSTOM HOOK pages').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'blocklr_chook_tr', Tools::getValue('blocklr_chook_tr'));
            }

            Configuration::updateValue($this->name.'blocklr_home_im', Tools::getValue('iblocklr_home'));
            Configuration::updateValue($this->name.'blocklr_cat_im', Tools::getValue('iblocklr_cat'));
            Configuration::updateValue($this->name.'blocklr_man_im', Tools::getValue('iblocklr_man'));
            Configuration::updateValue($this->name.'blocklr_prod_im', Tools::getValue('iblocklr_prod'));
            Configuration::updateValue($this->name.'blocklr_oth_im', Tools::getValue('iblocklr_oth'));
            Configuration::updateValue($this->name.'blocklr_chook_im', Tools::getValue('iblocklr_chook'));


            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&revlastreviewsblocksettings=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 36;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();
            }

        }
        ### lastreviewsblock settings ###


        ### starslistandsearchsettings settings ###
        $revstarslistandsearchsettings = Tools::getValue("revstarslistandsearchsettings");
        if (Tools::strlen($revstarslistandsearchsettings)>0) {
            ob_start();
            $number_tab = 37;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('starslistandsearchsettings'))
        {

            Configuration::updateValue($this->name.'starscat', Tools::getValue('starscat'));
            Configuration::updateValue($this->name.'is_starscat', Tools::getValue('is_starscat'));

            // clear cache //
            $this->clearSmartyCacheItems();
            // clear cache //

            $url = $currentIndex.'&conf=6&tab=AdminModules&revstarslistandsearchsettings=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
            Tools::redirectAdmin($url);

        }
        ### starslistandsearchsettings settings ###


        ### rssfeed settings ###
        $revrssfeedsettings = Tools::getValue("revrssfeedsettings");
        if (Tools::strlen($revrssfeedsettings)>0) {

            ob_start();
            $number_tab = 38;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('rssfeedsettings'))
        {
            Configuration::updateValue($this->name.'rsson', Tools::getValue('rsson'));

            if(!ctype_digit(Tools::getValue('number_rssitems')) || Tools::getValue('number_rssitems') == NULL) {
                $errors[] = $this->l('Number of items in RSS Feed').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'number_rssitems', Tools::getValue('number_rssitems'));
            }


            $languages = Language::getLanguages(false);
            foreach ($languages as $language){
                $i = $language['id_lang'];
                Configuration::updateValue($this->name.'rssname_'.$i, Tools::getValue('rssname_'.$i));
                Configuration::updateValue($this->name.'rssdesc_'.$i, Tools::getValue('rssdesc_'.$i));
            }

            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //

                $url = $currentIndex . '&conf=6&tab=AdminModules&revrssfeedsettings=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 38;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();
            }

        }
        ### rssfeed settings ###


        ### importcommentssettings settings ###
        $revimportcommentssettings = Tools::getValue("revimportcommentssettings");
        if (Tools::strlen($revimportcommentssettings)>0) {

            ob_start();
            $number_tab = 39;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('submitcomments'))
        {
            include_once(_PS_MODULE_DIR_.$this->name.'/classes/importhelp.class.php');
            $obj = new importhelp();

            $obj->importComments();

            // clear cache //
            $this->clearSmartyCacheItems();
            // clear cache //

            $url = $currentIndex.'&conf=6&tab=AdminModules&revimportcommentssettings=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
            Tools::redirectAdmin($url);

        }
        ### importcommentssettings settings ###


        // Google Product Review Feeds for Google Shopping
        $revsubmitgooglereviews = Tools::getValue("revsubmitgooglereviews");
        if (Tools::strlen($revsubmitgooglereviews)>0) {
            ob_start();
            $number_tab = 43;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('submitgooglereviews'))
        {
            include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
            $obj = new reviewsadvhelp();


            $obj->generateGoogleReviews();

            $url = $currentIndex.'&conf=6&tab=AdminModules&revsubmitgooglereviews=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
            Tools::redirectAdmin($url);

        }
        // Google Product Review Feeds for Google Shopping




        ### reviewsemailssettings settings ###
        $revreviewsemailssettings = Tools::getValue("revreviewsemailssettings");
        if (Tools::strlen($revreviewsemailssettings)>0) {

            ob_start();
            $number_tab = 40;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('reviewsemailssettings'))
        {
            if(!Validate::isEmail(Tools::getValue('mail'))){
                $errors[] = $this->l('Admin email is incorrect!');
            } else {
                Configuration::updateValue($this->name . 'mail', Tools::getValue('mail'));
            }

            Configuration::updateValue($this->name.'noti', Tools::getValue('noti'));
            Configuration::updateValue($this->name.'img_size_em', Tools::getValue('img_size_em'));


            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&revreviewsemailssettings=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 40;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();
            }

        }
        ### reviewsemailssettings settings ###


        ### revresponseadminemailssettings settings ###
        $revresponseadminemailssettings = Tools::getValue("revresponseadminemailssettings");
        if (Tools::strlen($revresponseadminemailssettings)>0) {
            ob_start();
            $number_tab = 41;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('responseadminemailssettings'))
        {
            $languages = Language::getLanguages(false);
            foreach ($languages as $language){
                $i = $language['id_lang'];
                Configuration::updateValue($this->name.'subresem_'.$i, Tools::getValue('subresem_'.$i));
                Configuration::updateValue($this->name.'textresem_'.$i, Tools::getValue('textresem_'.$i));
                Configuration::updateValue($this->name.'emailreminder_'.$i, Tools::getValue('emailreminder_'.$i));

                Configuration::updateValue($this->name.'reminderok'.$this->_prefix_review.'_'.$i, Tools::getValue('reminderok'.$this->_prefix_review.'_'.$i));
                Configuration::updateValue($this->name.'thankyou'.$this->_prefix_review.'_'.$i, Tools::getValue('thankyou'.$this->_prefix_review.'_'.$i));

                Configuration::updateValue($this->name.'newrev'.$this->_prefix_review.'_'.$i, Tools::getValue('newrev'.$this->_prefix_review.'_'.$i));
                Configuration::updateValue($this->name.'subpubem_'.$i, Tools::getValue('subpubem_'.$i));
                Configuration::updateValue($this->name.'modrev'.$this->_prefix_review.'_'.$i, Tools::getValue('modrev'.$this->_prefix_review.'_'.$i));

                Configuration::updateValue($this->name.'abuserev'.$this->_prefix_review.'_'.$i, Tools::getValue('abuserev'.$this->_prefix_review.'_'.$i));

                Configuration::updateValue($this->name.'facvouc'.$this->_prefix_review.'_'.$i, Tools::getValue('facvouc'.$this->_prefix_review.'_'.$i));
                Configuration::updateValue($this->name.'revvouc'.$this->_prefix_review.'_'.$i, Tools::getValue('revvouc'.$this->_prefix_review.'_'.$i));

                Configuration::updateValue($this->name.'sugvouc'.$this->_prefix_review.'_'.$i, Tools::getValue('sugvouc'.$this->_prefix_review.'_'.$i));

            }

            Configuration::updateValue($this->name.'is_emailreminder', Tools::getValue('is_emailreminder'));
            Configuration::updateValue($this->name.'is_reminderok'.$this->_prefix_review, Tools::getValue('is_reminderok'.$this->_prefix_review));
            Configuration::updateValue($this->name.'is_thankyou'.$this->_prefix_review, Tools::getValue('is_thankyou'.$this->_prefix_review));
            Configuration::updateValue($this->name.'is_newrev'.$this->_prefix_review, Tools::getValue('is_newrev'.$this->_prefix_review));
            Configuration::updateValue($this->name.'is_subresem', Tools::getValue('is_subresem'));
            Configuration::updateValue($this->name.'is_modrev'.$this->_prefix_review, Tools::getValue('is_modrev'.$this->_prefix_review));
            Configuration::updateValue($this->name.'is_subpubem', Tools::getValue('is_subpubem'));
            Configuration::updateValue($this->name.'is_abuserev'.$this->_prefix_review, Tools::getValue('is_abuserev'.$this->_prefix_review));
            Configuration::updateValue($this->name.'is_revvouc'.$this->_prefix_review, Tools::getValue('is_revvouc'.$this->_prefix_review));
            Configuration::updateValue($this->name.'is_facvouc'.$this->_prefix_review, Tools::getValue('is_facvouc'.$this->_prefix_review));
            Configuration::updateValue($this->name.'is_sugvouc'.$this->_prefix_review, Tools::getValue('is_sugvouc'.$this->_prefix_review));






            $url = $currentIndex.'&conf=6&tab=AdminModules&revresponseadminemailssettings=1&configure='.$this->name.'&token='.Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)($cookie->id_employee)).'';
            Tools::redirectAdmin($url);

        }
        ### revresponseadminemailssettings settings ###


        ### customerremindersettings settings ###
        $revcustomerremindersettings = Tools::getValue("revcustomerremindersettings");
        if (Tools::strlen($revcustomerremindersettings)>0) {
            ob_start();
            $number_tab = 42;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }


        if (Tools::isSubmit('customerremindersettings'))
        {

            if(!ctype_digit(Tools::getValue('crondelay' . $this->_prefix_review)) || Tools::getValue('crondelay' . $this->_prefix_review) == NULL) {
                $errors[] = $this->l('Delay between each email in seconds').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'crondelay' . $this->_prefix_review, Tools::getValue('crondelay' . $this->_prefix_review));
            }

            if(!ctype_digit(Tools::getValue('cronnpost' . $this->_prefix_review)) || Tools::getValue('cronnpost' . $this->_prefix_review) == NULL) {
                $errors[] = $this->l('Number of emails for each cron call').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'cronnpost' . $this->_prefix_review, Tools::getValue('cronnpost' . $this->_prefix_review));
            }

            if(!ctype_digit(Tools::getValue('delay')) || Tools::getValue('delay') == NULL) {
                $errors[] = $this->l('Delay for sending reminder by email').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'delay', Tools::getValue('delay'));
            }

            Configuration::updateValue($this->name.'reminder', Tools::getValue('reminder'));

            // orderstatuses
            $orderstatuses = Tools::getValue('orderstatuses');
            $orderstatuses = implode(",",$orderstatuses);
            Configuration::updateValue($this->name.'orderstatuses', $orderstatuses);

            if(!ctype_digit(Tools::getValue('delaysec' . $this->_prefix_review)) || Tools::getValue('delaysec' . $this->_prefix_review) == NULL) {
                $errors[] = $this->l('Days after the first emails were sent').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'delaysec' . $this->_prefix_review, Tools::getValue('delaysec' . $this->_prefix_review));
            }

            Configuration::updateValue($this->name.'remindersec'.$this->_prefix_review, Tools::getValue('remindersec'.$this->_prefix_review));


            Configuration::updateValue($this->name.'remrevsec'.$this->_prefix_review, Tools::getValue('remrevsec'.$this->_prefix_review));



            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&revcustomerremindersettings=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 42;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();
            }

        }
        ### customerremindersettings settings ###





        
        // voucher settings
        
    	$voucherset = Tools::getValue("voucherset");
        if (Tools::strlen($voucherset)>0) {
            ob_start();
            $number_tab = 5;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }
        
        if (Tools::isSubmit('vouchersettings'))
        {

            ## ids groups ##
            $ids_groups = Tools::getValue("ids_groups");

            if(!($ids_groups)) {
                $errors[] = $this->l('Please select the Customers Groups');
            } else {
                $ids_groups = implode(",",$ids_groups);
                Configuration::updateValue($this->name.'ids_groups', $ids_groups);

            }
            ## ids groups ##



        	Configuration::updateValue($this->name.'vis_on', Tools::getValue('vis_on'));

            Configuration::updateValue($this->name.'is_show_min', Tools::getValue('is_show_min'));
	    	
        
   			$languages = Language::getLanguages(false);
        	foreach ($languages as $language){
    			$i = $language['id_lang'];
        		Configuration::updateValue($this->name.'coupondesc_'.$i, Tools::getValue('coupondesc_'.$i));
        	}


            if(Tools::getValue('vouchercode') == NULL || Tools::strlen(Tools::getValue('vouchercode'))<3) {
                $errors[] = $this->l('Voucher code cannot be empty or must be at least 3 letters long!');
            } else {
                Configuration::updateValue($this->name . 'vouchercode', Tools::getValue('vouchercode'));
            }
        	
        	Configuration::updateValue($this->name.'discount_type', Tools::getValue('discount_type'));
			Configuration::updateValue($this->name.'percentage_val', Tools::getValue('percentage_val'));
			
        	
        	foreach (Tools::getValue('sdamount') AS $id => $value){
				Configuration::updateValue('sdamount_'.(int)($id), (float)($value));
        	}
            
        	if(Tools::getValue('discount_type') == 2){
        		Configuration::updateValue($this->name.'tax', Tools::getValue('tax'));
        	}


            if(!ctype_digit(Tools::getValue('sdvvalid')) || Tools::getValue('sdvvalid') == NULL) {
                $errors[] = $this->l('Voucher validity').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'sdvvalid', Tools::getValue('sdvvalid'));
            }
            
            
            if(Tools::getValue($this->name.'isminamount') == true){
	        	foreach (Tools::getValue('sdminamount') AS $id => $value){
					Configuration::updateValue('sdminamount_'.(int)($id), (float)($value));
	        	}
        	}
        	
            Configuration::updateValue($this->name.'isminamount', Tools::getValue($this->name.'isminamount'));
        	
            
            // category
            $categoryBox = Tools::getValue('categoryBox');
            $categoryBox = implode(",",$categoryBox);
            Configuration::updateValue($this->name.'catbox', $categoryBox);
            
        	
            // cumulable
            Configuration::updateValue($this->name.'cumulativeother', Tools::getValue('cumulativeother'));
			Configuration::updateValue($this->name.'cumulativereduc', Tools::getValue('cumulativereduc'));

            Configuration::updateValue($this->name.'highlight', Tools::getValue('highlight'));

            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&voucherset=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 5;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();
            }
        }
        
        // voucher settings


        // voucher facebook settings

        $vouchersetfb = Tools::getValue("vouchersetfb");
        if (Tools::strlen($vouchersetfb)>0) {
            ob_start();
            $number_tab = 55;
            include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
            $_html .= ob_get_clean();

        }

        if (Tools::isSubmit('vouchersettingsfb'))
        {

            ## ids groups ##
            $ids_groups = Tools::getValue("ids_groupsfb");

            if(!($ids_groups)) {
                $errors[] = $this->l('Please select the Customers Groups');
            } else {
                $ids_groups = implode(",",$ids_groups);
                Configuration::updateValue($this->name.'ids_groupsfb', $ids_groups);

            }
            ## ids groups ##

            Configuration::updateValue($this->name.'vis_onfb', Tools::getValue('vis_onfb'));

            Configuration::updateValue($this->name.'is_show_minfb', Tools::getValue('is_show_minfb'));


            $languages = Language::getLanguages(false);
            foreach ($languages as $language){
                $i = $language['id_lang'];
                Configuration::updateValue($this->name.'coupondescfb_'.$i, Tools::getValue('coupondescfb_'.$i));
            }


            if(Tools::getValue('vouchercodefb') == NULL || Tools::strlen(Tools::getValue('vouchercodefb'))<3) {
                $errors[] = $this->l('Voucher code cannot be empty or must be at least 3 letters long!');
            } else {
                Configuration::updateValue($this->name . 'vouchercodefb', Tools::getValue('vouchercodefb'));
            }

            Configuration::updateValue($this->name.'discount_typefb', Tools::getValue('discount_typefb'));
            Configuration::updateValue($this->name.'percentage_valfb', Tools::getValue('percentage_valfb'));


            foreach (Tools::getValue('sdamountfb') AS $id => $value){
                Configuration::updateValue('sdamountfb_'.(int)($id), (float)($value));
            }

            if(Tools::getValue('discount_typefb') == 2){
                Configuration::updateValue($this->name.'taxfb', Tools::getValue('taxfb'));
            }

            if(!ctype_digit(Tools::getValue('sdvvalidfb')) || Tools::getValue('sdvvalidfb') == NULL) {
                $errors[] = $this->l('Voucher validity').' '.$this->l('must be digit!');
            } else {
                Configuration::updateValue($this->name . 'sdvvalidfb', Tools::getValue('sdvvalidfb'));
            }


            if(Tools::getValue($this->name.'isminamountfb') == true){
                foreach (Tools::getValue('sdminamountfb') AS $id => $value){
                    Configuration::updateValue('sdminamountfb_'.(int)($id), (float)($value));
                }
            }

            Configuration::updateValue($this->name.'isminamountfb', Tools::getValue($this->name.'isminamountfb'));


            // category
            $categoryBox = Tools::getValue('categoryBoxfb');
            $categoryBox = implode(",",$categoryBox);
            Configuration::updateValue($this->name.'catboxfb', $categoryBox);


            // cumulable
            Configuration::updateValue($this->name.'cumulativeotherfb', Tools::getValue('cumulativeotherfb'));
            Configuration::updateValue($this->name.'cumulativereducfb', Tools::getValue('cumulativereducfb'));

            Configuration::updateValue($this->name.'highlightfb', Tools::getValue('highlightfb'));

            if(sizeof($errors)==0) {
                // clear cache //
                $this->clearSmartyCacheItems();
                // clear cache //
                $url = $currentIndex . '&conf=6&tab=AdminModules&vouchersetfb=1&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int)(Tab::getIdFromClassName('AdminModules')) . (int)($cookie->id_employee)) . '';
                Tools::redirectAdmin($url);
            } else {
                ob_start();
                $number_tab = 55;
                include(dirname(__FILE__).'/views/templates/hooks/js.phtml');
                $_html .= ob_get_clean();
            }
        }

        // voucher facebook settings
   		
        
        




        $_html .= $this->_displayForm16(array('errors'=>$errors));


        return $_html;
    	
    }

    private function _error($data){
        $text = $data['text'];
        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();
        return $_html;

    }

    protected function addBackOfficeMedia()
    {
        $this->context->controller->addCSS($this->_path.'views/css/font-custom.min.css');
        //CSS files
        $this->context->controller->addCSS($this->_path.'views/css/menu16.css');

        $this->context->controller->addCSS($this->_path.'views/css/admin.css');

        // JS files
        $this->context->controller->addJs($this->_path.'views/js/menu16.js');

        $this->context->controller->addJs($this->_path.'views/js/reminder.js');


        $this->context->controller->addJs($this->_path.'views/js/criterions-admin.js');


    }

    private function _displayForm16($data = null){
        $_html = '';


        $errors = $data['errors'];
        if(count($errors)>0) {
            foreach ($errors as $error_text) {
                $_html .= $this->_error(array('text' => $error_text));
            }
        }


        $this->_data_translate_custom['_displayForm16_welcome'] = $this->l('Welcome');
        $this->_data_translate_custom['_displayForm16_reviews'] = $this->l('Reviews');
        $this->_data_translate_custom['_displayForm16_user_profile'] = $this->l('User profile');
        $this->_data_translate_custom['_displayForm16_soc_netw_integr'] = $this->l('Social networks Integration');
        $this->_data_translate_custom['_displayForm16_help_doc'] = $this->l('Help / Documentation');
        $this->_data_translate_custom['_displayForm16_mitr_mod'] = $this->l('Mitrocops Modules');


        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();
        return $_html;


    }






    private function _userprofileg16(){
        $fields_form = array(
            'form'=> array(
                'legend' => array(
                    'title' => $this->l('User profile'),
                    'icon' => 'fa fa-users fa-lg'
                ),
                'input' => array(

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable User profile'),
                        'name' => 'is_uprof',
                        'desc' => $this->l('Enable or Disable User profile functional on your site'),

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Profile tab on the user page'),
                        'name' => 'is_proftab',
                        'desc' => $this->l('Enable or Disable Profile tab on the user page'),

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('The number of shoppers in the "Block Users":'),
                        'name' => 'rshoppers_blc',
                        'class' => ' fixed-width-sm',

                    ),

                    array(
                        'type' => 'checkbox_custom_blocks',
                        'label' => $this->l('Position "Block Users":'),
                        'name' => 'rproft_left',
                        'values' => array(
                            'query' => array(

                                array(
                                    'id' => 'radv_left',
                                    'name' => $this->l('Left column'),
                                    'val' => 1
                                ),


                                array(
                                    'id' => 'radv_right',
                                    'name' => $this->l('Right column'),
                                    'val' => 1
                                ),


                                array(
                                    'id' => 'radv_footer',
                                    'name' => $this->l('Footer'),
                                    'val' => 1
                                ),

                                array(
                                    'id' => 'radv_home',
                                    'name' => $this->l('Home'),
                                    'val' => 1
                                ),

                            ),
                            'id' => 'id',
                            'name' => 'name'
                        ),

                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Users per page in the list view:'),
                        'name' => 'rpage_shoppers',
                        'class' => ' fixed-width-sm',

                    ),



                    array(
                        'type' => 'text',
                        'label' => $this->l('Product reviews per Page on the User Page:'),
                        'name' => 'perpageu'.$this->_prefix_review,
                        'class' => ' fixed-width-sm',

                    ),

                ),
            ),
        );



        $fields_form1 = array(
            'form'=> array(

                'legend' => array(
                    'title' => $this->l('OWL carousels for Block Users block in the Left, Right, Footer positions settings'),
                    'icon' => 'fa fa-sliders fa-lg'
                ),
                'input' => array(



                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Slider for Block Users block in the Left, Right, Footer positions'),
                        'name' => 'sr_slideru',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Displayed number of items in the slider in the block Block Users block in the Left, Right, Footer positions'),
                        'name' => 'sr_slu',
                        'id' => 'sr_slu',
                        'lang' => FALSE,
                    ),

                ),



            ),


        );



        $fields_form2 = array(
            'form'=> array(

                'legend' => array(
                    'title' => $this->l('OWL carousel for block Block Users block on the Home Page settings'),
                    'icon' => 'fa fa-sliders fa-lg'
                ),
                'input' => array(



                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Slider for Block Users block on the Home Page'),
                        'name' => 'sr_sliderhu',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Displayed number of items in the slider in the block Block Users block on the Home Page'),
                        'name' => 'sr_slhu',
                        'id' => 'sr_slhu',
                        'lang' => FALSE,
                    ),

                ),



            ),


        );



        $fields_form3 = array(
            'form'=> array(

                'legend' => array(
                    'title' => $this->l('WOW effects for items in the list view settings'),
                    'icon' => 'fa fa-sliders fa-lg'
                ),
                'input' => array(


                    array(
                        'type' => 'wow_display_effect',
                        'label' => $this->l('Display effect in the list view on the All Users page'),
                        'name' => 'd_eff_shopu',
                        'id' => 'd_eff_shopu',
                        'lang' => FALSE,
                        'value' => $this->_effects(array('value' => 'd_eff_shopu'))
                    ),




                ),



            ),


        );

        $fields_form10 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );

        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'userprofilegsettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesUserSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );


        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'_js.phtml');
        $_html = ob_get_clean();





        return  $_html.$helper->generateForm(array($fields_form,$fields_form1,$fields_form2,$fields_form3,$fields_form10));
    }

    public function getConfigFieldsValuesUserSettings(){

        $data_config = array(
            'is_uprof' =>Configuration::get($this->name.'is_uprof'),

            'rshoppers_blc' => Configuration::get($this->name.'rshoppers_blc'),
            'rpage_shoppers'=> Configuration::get($this->name.'rpage_shoppers'),

            'radv_left'=>Configuration::get($this->name.'radv_left'),
            'radv_right'=>Configuration::get($this->name.'radv_right'),
            'radv_footer'=>Configuration::get($this->name.'radv_footer'),
            'radv_home'=>Configuration::get($this->name.'radv_home'),

            'is_proftab'=>Configuration::get($this->name.'is_proftab'),

            'perpageu'.$this->_prefix_review => (int)Configuration::get($this->name.'perpageu'.$this->_prefix_review),


            'sr_slideru'=> (int)Configuration::get($this->name.'sr_slideru'),
            'sr_slu'=> (int)Configuration::get($this->name.'sr_slu'),

            'sr_sliderhu'=> (int)Configuration::get($this->name.'sr_sliderhu'),
            'sr_slhu'=> (int)Configuration::get($this->name.'sr_slhu'),

        );

        return $data_config;

    }






    private function _autoposts16(){
        #### posts api ###
        include_once(_PS_MODULE_DIR_.$this->name.'/classes/postshelp.class.php');
        $postshelp = new postshelp();

        return $postshelp->postsSettings(array('translate'=>$this->_translate));
        #### posts api ###
    }

    public function psvkform16($data){
        $update_button = $data['translate']['update_button'];
        $enable_pstwitterpost = $data['translate']['enable_psvkpost'];

        $template_text = $data['translate']['template_text'];
        $name = $data['translate']['name'];


        $fields_form = array(
            'form'=> array(
                //'tinymce' => FALSE,
                'legend' => array(
                    'title' => $enable_pstwitterpost,
                    'icon' => 'fa fa-vk fa-lg'
                ),
                'input' => array(

                    array(
                        'type' => 'switch',
                        'label' => $enable_pstwitterpost,
                        'name' => 'vkpost_on',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'text_autopost',
                        'label' => $template_text,
                        'name' => 'vkdesc',
                        'id' => 'vkdesc',
                        'lang' => TRUE,
                        'text_before' => '{John. D.}',
                        'text_after' => ' : ★★★★☆ - {Product name} - {Product URL}',

                    ),


                ),



            ),


        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $update_button,
                )
            ),
        );


        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'psvkpostsettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$name.'&tab_module='.$this->tab.'&module_name='.$name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesPsvkpostsettingsSettings($name),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        return  $helper->generateForm(array($fields_form,$fields_form1));
    }

    public function getConfigFieldsValuesPsvkpostsettingsSettings($name){
        $languages = Language::getLanguages(false);
        $fields_vkdesc = array();

        foreach ($languages as $lang)
        {
            $fields_vkdesc[$lang['id_lang']] =  Configuration::get($name.'vkdesc_'.$lang['id_lang']);

        }


        $data_config = array(
            'vkdesc' => $fields_vkdesc,
            'vkpost_on' => Configuration::get($name.'vkpost_on'),
        );

        return $data_config;


    }


    public function pstwitterform16($data){
        $update_button = $data['translate']['update_button'];
        $enable_pstwitterpost = $data['translate']['enable_pstwitterpost'];

        $template_text = $data['translate']['template_text'];
        $name = $data['translate']['name'];


        $fields_form = array(
            'form'=> array(
                //'tinymce' => FALSE,
                'legend' => array(
                    'title' => $enable_pstwitterpost,
                    'icon' => 'fa fa-facebook fa-twitter fa-lg'
                ),
                'input' => array(

                    array(
                        'type' => 'switch',
                        'label' => $enable_pstwitterpost,
                        'name' => 'twpost_on',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'text_autopost',
                        'label' => $template_text,
                        'name' => 'twdesc',
                        'id' => 'twdesc',
                        'lang' => TRUE,
                        'text_before' => '{John. D.}',
                        'text_after' => ' : ★★★★☆ - {Product name} - {Product URL}',
                        'desc'=>'Example: John D. rated product in our shop: ★★★★☆ - Test product - https://www.test.com/testproduct',

                    ),


                ),



            ),


        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $update_button,
                )
            ),
        );


        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'pstwitterpostsettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$name.'&tab_module='.$this->tab.'&module_name='.$name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesPstwitterpostsettingsSettings($name),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        return  $helper->generateForm(array($fields_form,$fields_form1));
    }

    public function getConfigFieldsValuesPstwitterpostsettingsSettings($name){
        $languages = Language::getLanguages(false);
        $fields_twdesc = array();

        foreach ($languages as $lang)
        {
            $fields_twdesc[$lang['id_lang']] =  Configuration::get($name.'twdesc_'.$lang['id_lang']);

        }


        $data_config = array(
            'twdesc' => $fields_twdesc,
            'twpost_on' => Configuration::get($name.'twpost_on'),
        );

        return $data_config;


    }



    private function _voucherwhensharereviewsettings16(){
        $cookie = $this->context->cookie;

        $curs = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);


        $discount_type_currency_value = array();
        $min_checkout_value = array();

        foreach ($curs AS $_cur){

            $discount_type_currency_value[$_cur['id_currency']] = array('amount' => Tools::getValue('sdamountfb['.(int)($_cur['id_currency']).']', Configuration::get('sdamountfb_'.(int)($_cur['id_currency']))),
                'currency'=>$_cur['sign'],
                'name'=>htmlentities($_cur['name'], ENT_NOQUOTES, 'utf-8'),
                'name_item' => 'sdamountfb'
            );

            $min_checkout_value[$_cur['id_currency']]  = array('amount' => Tools::getValue('sdminamountfb['.(int)($_cur['id_currency']).']', Configuration::get('sdminamountfb_'.(int)($_cur['id_currency']))),
                'currency'=>$_cur['sign'],
                'name'=>htmlentities($_cur['name'], ENT_NOQUOTES, 'utf-8'),
                'name_item' => 'sdminamountfb'
            );
        }

        // select categories


        $_selected_cat = Configuration::get($this->name.'catboxfb');
        $select_categories = explode(",",$_selected_cat);


        $id_lang =  $cookie->id_lang;
        $ids_groups = Configuration::get($this->name.'ids_groupsfb');
        $ids_groups = $ids_groups?explode(",",$ids_groups):array();




        $categories = array();
        foreach ($select_categories as $key => $category) {
            $categories[] = $category;
        }

        //ob_start();
        $root = Category::getRootCategory();
        $tree = new HelperTreeCategories('associated-categories-tree-fb', 'Associated categories when a user share review on the Facebook');
        $tree->setTemplate('tree_associated_categories.tpl')
            ->setHeaderTemplate('tree_associated_header.tpl')
            ->setTemplateDirectory(dirname(__FILE__).'/views/templates/admin/_configure/helpers/tree/')
            ->setRootCategory((int)$root->id)
            ->setInputName('categoryBoxfb')
            ->setUseCheckBox(true)
            ->setUseSearch(true)
            ->setSelectedCategories($categories);
        $selected_categories = $tree->render();

        //echo $selected_categories;

        //$selected_categories = ob_get_clean();

        //var_dump($selected_categories);exit;
        // select categories


        $fields_form = array(
            'form' => array(
                'legend' => array(
                    'title' => $this->l('Voucher settings, when a user share review on the Facebook'),
                    'icon' => 'fa fa-facebook fa-lg'
                ),
                'input' => array(

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Voucher'),
                        'name' => 'vis_onfb',
                        'desc' => '<b style="color:red">'.$this->l('Enable or Disable Voucher, when a user share review on the Facebook').'</b>',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                    array(
                        'type' => 'group_association',
                        'label' => $this->l('Voucher will be displayed only for selected Customers Groups'),
                        'name' => 'ids_groupsfb',
                        'values'=>Group::getGroups($id_lang),
                        'selected_data'=>$ids_groups,
                        'required' => TRUE,
                        'desc' => $this->l('Voucher will be displayed only for selected Customers Groups'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Coupon Description'),
                        'name' => 'coupondescfb',
                        'lang' => true,
                        'hint' => $this->l('The description is displayed in cart once your customers use their voucher.'),
                        'desc' => $this->l('The description is displayed in cart once your customers use their voucher.')
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Voucher code'),
                        'name' => 'vouchercodefb',
                        'desc' => $this->l('Voucher code prefix. It must be at least 3 letters long. Prefix voucher code will be used in the first part of the coupon code, which the user will use to get a discount'),
                    ),

                    array(
                        'type' => 'select',
                        'label' => $this->l('Discount Type'),
                        'name' => 'discount_typefb',
                        //'desc' => $this->l('Discount Type'),
                        'options' => array(
                            'query' => array(
                                array(
                                    'id' => '1',
                                    'name' => $this->l('Percentages')
                                ),

                                array(
                                    'id' => '2',
                                    'name' => $this->l('Currency'),
                                ),


                            ),
                            'id' => 'id',
                            'name' => 'name'
                        )
                    ),


                    array(
                        'type' => 'cms_pages',
                        'label' => '',
                        'name' => 'currency_valfb',
                        'values'=> $discount_type_currency_value,

                    ),

                    array(
                        'type' => 'select',
                        'label' => $this->l('Tax'),
                        'name' => 'taxfb',
                        'options' => array(
                            'query' => array(
                                array(
                                    'id' => '0',
                                    'name' => $this->l('Tax Excluded')
                                ),

                                array(
                                    'id' => '1',
                                    'name' => $this->l('Tax Included'),
                                ),


                            ),
                            'id' => 'id',
                            'name' => 'name'
                        )
                    ),

                    array(
                        'type' => 'text_custom',
                        'label' => $this->l('Voucher percentage'),
                        'name' => 'percentage_valfb',
                        'value'=> Configuration::get($this->name.'percentage_valfb'),
                    ),




                    array(
                        'type' => 'checkbox_custom',
                        'label' => $this->l('Minimum checkout'),
                        'name' => $this->name.'isminamountfb',
                        'hint' => $this->l('Minimum checkout'),
                        'values' => array(
                            'query' => array(
                                array(
                                    'id' => $this->name.'isminamountfb',
                                    'name' => '',
                                    'val' => 1
                                ),

                            ),
                            'id' => 'id',
                            'name' => 'name'
                        ),


                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Display the minimum amount in the Front Office in the add review form ?'),
                        'name' => 'is_show_minfb',
                        'desc' => $this->l('Use to show or not the minimum amount on the Front office in the add review form'),
                        'hint' => $this->l('Use to show or not the minimum amount on the Front office in the add review form'),

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'cms_pages',
                        'label' => '',
                        'name' => 'mincheckout_valfb',
                        'values'=> $min_checkout_value,

                    ),

                    array(
                        'type' => 'cms_categories',
                        'label' => $this->l('Select categories'),
                        'hint' => $this->l('Check all box(es) of categories to which the discount is to be applied. No categories checked will apply the voucher on all of them.'),
                        'desc' => $this->l('Check all box(es) of categories to which the discount is to be applied. No categories checked will apply the voucher on all of them.'),

                        'name' => 'select_catfb',
                        'values'=> $selected_categories,

                    ),

                    array(
                        'type' => 'text_validity',
                        'label' => $this->l('Voucher validity'),
                        'name' => 'sdvvalidfb',
                        'value'=> Configuration::get($this->name.'sdvvalidfb'),
                        'desc' =>$this->l('Voucher term of validity in days'),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Highlight'),
                        'name' => 'highlightfb',
                        'desc'=>$this->l('If the voucher is not yet in the cart, it will be displayed in the cart summary.'),

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Cumulative with others vouchers'),
                        'name' => 'cumulativeotherfb',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Cumulative with price reductions'),
                        'name' => 'cumulativereducfb',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                ),

                'submit' => array(
                    'title' => $this->l('Save'),
                )
            ),
        );



        $helper = new HelperForm();
        $helper->show_toolbar = false;
        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'vouchersettingsfb';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesCouponWhenShareReviewSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        $currency_discount_amount = (int)Configuration::get($this->name.'discount_typefb');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'_js.phtml');
        $_html = ob_get_clean();



        return $_html . $helper->generateForm(array($fields_form));
    }

    public function getConfigFieldsValuesCouponWhenShareReviewSettings(){




        $languages = Language::getLanguages(false);
        $fields_fcoupondesc = array();

        foreach ($languages as $lang)
        {
            $fields_fcoupondesc[$lang['id_lang']] = Configuration::get($this->name.'coupondescfb_'.$lang['id_lang']);

        }

        $data_config = array(
            'vis_onfb' => Configuration::get($this->name.'vis_onfb'),
            'vouchercodefb' => Configuration::get($this->name.'vouchercodefb'),
            'discount_typefb' => Configuration::get($this->name.'discount_typefb'),

            'coupondescfb' => $fields_fcoupondesc,


            'taxfb' =>  Configuration::get($this->name.'taxfb'),

            //'taxpercfb' => Configuration::get($this->name.'taxpercfb'),

            $this->name.'isminamountfb' =>  Configuration::get($this->name.'isminamountfb'),

            'is_show_minfb' => Configuration::get($this->name.'is_show_minfb'),

            'cumulativeotherfb' => Configuration::get($this->name.'cumulativeotherfb'),

            'cumulativereducfb' =>  Configuration::get($this->name.'cumulativereducfb'),

            'highlightfb' => Configuration::get($this->name.'highlightfb'),
        );



        return $data_config;
    }

    private function _voucherwhenaddreviewsettings16(){
        $cookie = $this->context->cookie;




        $curs = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);


        $discount_type_currency_value = array();
        $min_checkout_value = array();

        foreach ($curs AS $_cur){

            $discount_type_currency_value[$_cur['id_currency']] = array('amount' => Tools::getValue('sdamount['.(int)($_cur['id_currency']).']', Configuration::get('sdamount_'.(int)($_cur['id_currency']))),
                'currency'=>$_cur['sign'],
                'name'=>htmlentities($_cur['name'], ENT_NOQUOTES, 'utf-8'),
                'name_item' => 'sdamount'
            );

            $min_checkout_value[$_cur['id_currency']]  = array('amount' => Tools::getValue('sdminamount['.(int)($_cur['id_currency']).']', Configuration::get('sdminamount_'.(int)($_cur['id_currency']))),
                'currency'=>$_cur['sign'],
                'name'=>htmlentities($_cur['name'], ENT_NOQUOTES, 'utf-8'),
                'name_item' => 'sdminamount'
            );
        }

        // select categories


        $_selected_cat = Configuration::get($this->name.'catbox');
        $select_categories = explode(",",$_selected_cat);


        $id_lang =  $cookie->id_lang;
        $ids_groups = Configuration::get($this->name.'ids_groups');
        $ids_groups = $ids_groups?explode(",",$ids_groups):array();





        $categories = array();
        foreach ($select_categories as $key => $category) {
            $categories[] = $category;
        }

        $root = Category::getRootCategory();
        $tree = new HelperTreeCategories('associated-categories-tree', 'Associated categories');
        $tree->setTemplate('tree_associated_categories.tpl')
            ->setHeaderTemplate('tree_associated_header.tpl')
            ->setTemplateDirectory(dirname(__FILE__).'/views/templates/admin/_configure/helpers/tree/')
            ->setRootCategory((int)$root->id)
            ->setUseCheckBox(true)
            ->setUseSearch(true)
            ->setSelectedCategories($categories);
        $selected_categories = $tree->render();

        //var_dump($select_categories);exit;
        // select categories


        $fields_form = array(
            'form' => array(
                'legend' => array(
                    'title' => $this->l('Voucher settings, when a user add review'),
                    'icon' => 'fa fa-reviews fa-lg'
                ),
                'input' => array(

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Voucher'),
                        'name' => 'vis_on',
                        'desc' => '<b style="color:red">'.$this->l('Enable or Disable Voucher, when a user add review').'</b>',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'group_association',
                        'label' => $this->l('Voucher will be displayed only for selected Customers Groups'),
                        'name' => 'ids_groups',
                        'values'=>Group::getGroups($id_lang),
                        'selected_data'=>$ids_groups,
                        'required' => TRUE,
                        'desc' => $this->l('Voucher will be displayed only for selected Customers Groups'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Coupon Description'),
                        'name' => 'coupondesc',
                        'lang' => true,
                        'hint' => $this->l('The description is displayed in cart once your customers use their voucher.'),
                        'desc' => $this->l('The description is displayed in cart once your customers use their voucher.')
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Voucher code'),
                        'name' => 'vouchercode',
                        'desc' => $this->l('Voucher code prefix. It must be at least 3 letters long. Prefix voucher code will be used in the first part of the coupon code, which the user will use to get a discount'),
                    ),

                    array(
                        'type' => 'select',
                        'label' => $this->l('Discount Type'),
                        'name' => 'discount_type',
                        //'desc' => $this->l('Discount Type'),
                        'options' => array(
                            'query' => array(
                                array(
                                    'id' => '1',
                                    'name' => $this->l('Percentages')
                                ),

                                array(
                                    'id' => '2',
                                    'name' => $this->l('Currency'),
                                ),


                            ),
                            'id' => 'id',
                            'name' => 'name'
                        )
                    ),


                    array(
                        'type' => 'cms_pages',
                        'label' => '',
                        'name' => 'currency_val',
                        'values'=> $discount_type_currency_value,

                    ),

                    array(
                        'type' => 'select',
                        'label' => $this->l('Tax'),
                        'name' => 'tax',
                        'options' => array(
                            'query' => array(
                                array(
                                    'id' => '0',
                                    'name' => $this->l('Tax Excluded')
                                ),

                                array(
                                    'id' => '1',
                                    'name' => $this->l('Tax Included'),
                                ),


                            ),
                            'id' => 'id',
                            'name' => 'name'
                        )
                    ),

                    array(
                        'type' => 'text_custom',
                        'label' => $this->l('Voucher percentage'),
                        'name' => 'percentage_val',
                        'value'=> Configuration::get($this->name.'percentage_val'),
                    ),




                    array(
                        'type' => 'checkbox_custom',
                        'label' => $this->l('Minimum checkout'),
                        'name' => $this->name.'isminamount',
                        'hint' => $this->l('Minimum checkout'),
                        'values' => array(
                            'query' => array(
                                array(
                                    'id' => $this->name.'isminamount',
                                    'name' => '',
                                    'val' => 1
                                ),

                            ),
                            'id' => 'id',
                            'name' => 'name'
                        ),


                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Display the minimum amount in the Front Office in the add review form ?'),
                        'name' => 'is_show_min',
                        'desc' => $this->l('Use to show or not the minimum amount on the Front office in the add review form'),
                        'hint' => $this->l('Use to show or not the minimum amount on the Front office in the add review form'),

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'cms_pages',
                        'label' => '',
                        'name' => 'mincheckout_val',
                        'values'=> $min_checkout_value,

                    ),

                    array(
                        'type' => 'cms_categories',
                        'label' => $this->l('Select categories'),
                        'hint' => $this->l('Check all box(es) of categories to which the discount is to be applied. No categories checked will apply the voucher on all of them.'),
                        'desc' => $this->l('Check all box(es) of categories to which the discount is to be applied. No categories checked will apply the voucher on all of them.'),

                        'name' => 'select_cat',
                        'values'=> $selected_categories,

                    ),

                    array(
                        'type' => 'text_validity',
                        'label' => $this->l('Voucher validity'),
                        'name' => 'sdvvalid',
                        'value'=> Configuration::get($this->name.'sdvvalid'),
                        'desc' =>$this->l('Voucher term of validity in days'),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Highlight'),
                        'name' => 'highlight',
                        'desc'=>$this->l('If the voucher is not yet in the cart, it will be displayed in the cart summary.'),

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Cumulative with others vouchers'),
                        'name' => 'cumulativeother',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Cumulative with price reductions'),
                        'name' => 'cumulativereduc',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                ),

                'submit' => array(
                    'title' => $this->l('Save'),
                )
            ),
        );



        $helper = new HelperForm();
        $helper->show_toolbar = false;
        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'vouchersettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesCouponSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        $currency_discount_amount = (int)Configuration::get($this->name.'discount_type');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'_js.phtml');
        $_html = ob_get_clean();



        return $_html . $helper->generateForm(array($fields_form));
    }

    public function getConfigFieldsValuesCouponSettings(){




        $languages = Language::getLanguages(false);
        $fields_fcoupondesc = array();

        foreach ($languages as $lang)
        {
            $fields_fcoupondesc[$lang['id_lang']] = Configuration::get($this->name.'coupondesc_'.$lang['id_lang']);

        }

        $data_config = array(
            'vis_on' => Configuration::get($this->name.'vis_on'),
            'vouchercode' => Configuration::get($this->name.'vouchercode'),
            'discount_type' => Configuration::get($this->name.'discount_type'),

            'coupondesc' => $fields_fcoupondesc,


            'tax' =>  Configuration::get($this->name.'tax'),

            //'taxperc' => Configuration::get($this->name.'taxperc'),

            $this->name.'isminamount' =>  Configuration::get($this->name.'isminamount'),

            'is_show_min' => Configuration::get($this->name.'is_show_min'),

            'cumulativeother' => Configuration::get($this->name.'cumulativeother'),

            'cumulativereduc' =>  Configuration::get($this->name.'cumulativereduc'),
            'highlight' =>  Configuration::get($this->name.'highlight'),
        );



        return $data_config;
    }



    private function _customerreminder(){

        include_once(_PS_MODULE_DIR_ . $this->name.'/classes/featureshelp.class.php');
        $obj_featureshelp = new featureshelp();
        $cookie = $this->context->cookie;
		$id_lang = (int)($cookie->id_lang);


        require_once(_PS_MODULE_DIR_ . $this->name . '/classes/reviewsadvhelp.class.php');
        $obj_reviewsadvhelp = new reviewsadvhelp();

        $data_seo_url = $obj_reviewsadvhelp->getSEOURLs();
        $reviews_admin_url = $data_seo_url['reviews_admin_url'];

        $delimeter_rewrite = "&";
        if(Configuration::get('PS_REWRITING_SETTINGS')){
            $delimeter_rewrite = "?";
        }
        $url_cron = $data_seo_url['cron_url'];




        $fields_form = array(
            'form'=> array(
                //'tinymce' => FALSE,
                'legend' => array(
                    'title' => $this->l('Customer Reminder settings'),
                    'icon' => 'fa fa-bell-o fa-lg'
                ),
                'input' => array(

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Send a review reminder by email to customers'),
                        'name' => 'reminder',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('If activated, when a customer purchases a product on your shop, an e-mail will be sent to him after X days (specify below after selecting "yes" here) to invite him to rate the product.').'
                                    <br/><br/>
                                    <b>'.$this->l('IMPORTANT NOTE').'</b>: '.$this->l('This requires to set a CRON task on your server. ').'
                                    <a style="text-decoration:underline;font-weight:bold;color:red" onclick="tabs_custom(104)" href="javascript:void(0)">'.$this->l('CRON HELP PRODUCT REVIEWS').'</a>
                                    <br/><br/>
                                    <b>'.$this->l('Your CRON URL to call').'</b>:&nbsp;<a href="'.$url_cron.$delimeter_rewrite.'token='.$this->getokencron().'" style="text-decoration:underline;font-weight:bold">'.$url_cron.$delimeter_rewrite.'token='.$this->getokencron().'</a>',
                    ),


                    array(
                        'type' => 'text_custom_delay',
                        'label' => $this->l('Delay between each email in seconds'),
                        'name' => 'crondelay'.$this->_prefix_review,
                        'value'=>(int)Configuration::get($this->name.'crondelay'.$this->_prefix_review),
                        'desc' => $this->l('The delay is intended in order to your server is not blocked the email function'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Number of emails for each cron call'),
                        'name' => 'cronnpost'.$this->_prefix_review,
                        'desc' => $this->l('This will reduce the load on your server. The more powerful your server - the more emails you can do for each CRON call!'),
                    ),



                    array(
                        'type' => 'text_custom_delay_reminder',
                        'label' => $this->l('Delay for sending reminder by email'),
                        'name' => 'delay',
                        'value'=> Configuration::get($this->name.'delay'),
                        'desc'=>$this->l('We recommend you enter at least 7 days here to have enough time to process the order and for the customer to receive it.')
                    ),



                    array(
                        'type' => 'text_custom_orders_import',
                        'label' => $this->l('Import your old orders'),
                        'name' => 'orders_import',
                        'end_date' =>date('Y-m-d H:i:s'),
                        'host_url'=>$this->getURLMultiShop(),
                        'reviews_admin_url'=>$reviews_admin_url,
                        'desc'=>$this->l('Please select a date. All orders placed between that start date and end date (today) will be imported.')
                    ),

                    array(
                        'type' => 'text_custom_order_statuses',
                        'label' => $this->l('Send emails only for the orders with the current selected status'),
                        'name' => 'sel_statuses',
                        'value'=> $obj_featureshelp->getOrderStatuses(array('id_lang'=>$id_lang)),
                        'orderstatuses'=> explode(",",Configuration::get($this->name.'orderstatuses')),
                        'desc'=>$this->l('This feature prevents customers to leave a review for orders that they haven\'t received yet. You must choose at least one status.')
                    ),


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Send a review reminder by email to customer when customer already write review in shop?'),
                        'name' => 'remrevsec'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Send a review reminder by email to customers a second time?'),
                        'name' => 'remindersec'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('This feature allows you to send a second time the opinion request emails that have already been sent.'),
                    ),

                    array(
                        'type' => 'text_custom_delay_reminder',
                        'label' => $this->l('Days after the first emails were sent'),
                        'name' => 'delaysec'.$this->_prefix_review,
                        'value'=> Configuration::get($this->name.'delaysec'.$this->_prefix_review),
                    ),



                ),



            ),


        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );




        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'customerremindersettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesCustomerreminderSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );


        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'_js.phtml');
        $_html = ob_get_clean();



        return  $_html.$helper->generateForm(array($fields_form,$fields_form1));
    }

    public function getConfigFieldsValuesCustomerreminderSettings(){

        $data_config = array(

            'reminder' => Configuration::get($this->name.'reminder'),

            'remindersec'.$this->_prefix_review => Configuration::get($this->name.'remindersec'.$this->_prefix_review),

            'remrevsec'.$this->_prefix_review => Configuration::get($this->name.'remrevsec'.$this->_prefix_review),

            'cronnpost'.$this->_prefix_review=>(int)Configuration::get($this->name.'cronnpost'.$this->_prefix_review),
        );
        //echo "<pre>"; var_dumP($data_config); exit;

        return $data_config;

    }

    private function _responseadminemailsDesc($data){
        $name_template = $data['name'];
        return $this->l('You can customize the subject of the e-mail here.').' '
        . $this->l('If you wish to customize the e-mail message itself, you will need to manually edit the files in the')
        .'  "mails" '
        . $this->l(' folder inside the')
        .' "'.$this->name.'" '
        .$this->l('module folder, for each language, both the text and the HTML version each time. ')
        .'<br/><br/><b>'.$this->l('FTP Location').': /modules/'.$this->name.'/mails/{YOUR_ISO_CODE_LANGUAGE}/'.$name_template.'.html</b>';
    }

    private function _responseadminemails(){
        $fields_form = array(
            'form'=> array(
                //'tinymce' => FALSE,
                'legend' => array(
                    'title' => $this->l('Emails subjects settings'),
                    'icon' => 'fa fa-envelope-o fa-lg'
                ),
                'input' => array(

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable reminder email'),
                        'name' => 'is_emailreminder',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable reminder email'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Email reminder subject'),
                        'name' => 'emailreminder',
                        'id' => 'emailreminder',
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'customer-reminderserg'))
                    ),


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable admin confirmation email, when emails requests on the reviews was successfully sent email'),
                        'name' => 'is_reminderok'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable admin confirmation email, when emails requests on the reviews was successfully sent email'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Admin confirmation subject, when emails requests on the reviews was successfully sent'),
                        'name' => 'reminderok'.$this->_prefix_review,
                        'id' => 'reminderok'.$this->_prefix_review,
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'customer-reminder-admin-r'))
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable thank you for your review email'),
                        'name' => 'is_thankyou'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable thank you for your review email'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Thank you for your review subject'),
                        'name' => 'thankyou'.$this->_prefix_review,
                        'id' => 'thankyou'.$this->_prefix_review,
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'review-thank-you-r'))
                    ),


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable new Review email'),
                        'name' => 'is_newrev'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable new Review email'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('New Review subject'),
                        'name' => 'newrev'.$this->_prefix_review,
                        'id' => 'newrev'.$this->_prefix_review,
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'reviewserg'))
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable suggest to change review email'),
                        'name' => 'is_subresem',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable suggest to change review email'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Suggest to change review subject'),
                        'name' => 'subresem',
                        'id' => 'subresem',
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'reviewserg-suggest-to-change'))
                    ),


                    array(
                        'type' => 'textarea',
                        'label' => $this->l('Default content of the suggest to change review email'),
                        'name' => 'textresem',
                        'autoload_rte' => FALSE,
                        'lang' => TRUE,
                        'class'=>'mitrocops-textarea-email',
                        'desc' => $this->l('Templates for sending emails when people leave bad reviews and you wish to contact the user and try to convince a user to change his review / rating'),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable email, when one of your customers has modified own product review'),
                        'name' => 'is_modrev'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable email, when one of your customers has modified own product review'),
                    ),


                    array(
                        'type' => 'text',
                        'label' => $this->l('One of your customers has modified own product review subject'),
                        'name' => 'modrev'.$this->_prefix_review,
                        'id' => 'modrev'.$this->_prefix_review,
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'reviewserg-customer-change-review'))
                    ),


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable notification email when a review is published'),
                        'name' => 'is_subpubem',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable notification email when a review is published'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Notification email when a review is published subject'),
                        'name' => 'subpubem',
                        'id' => 'subpubem',
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'reviewserg-publish'))
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable, when someone send abuse for review email'),
                        'name' => 'is_abuserev'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable, when someone send abuse for review email'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Someone send abuse for review subject'),
                        'name' => 'abuserev'.$this->_prefix_review,
                        'id' => 'abuserev'.$this->_prefix_review,
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'abuseserg'))
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable submit a review and get voucher for discount email'),
                        'name' => 'is_revvouc'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable submit a review and get voucher for discount email'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('You submit a review and get voucher for discount subject'),
                        'name' => 'revvouc'.$this->_prefix_review,
                        'id' => 'revvouc'.$this->_prefix_review,
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'voucherserg'))
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable You share review on Facebook and get voucher for discount email'),
                        'name' => 'is_facvouc'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable You share review on Facebook and get voucher for discount email'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('You share review on Facebook and get voucher for discount subject'),
                        'name' => 'facvouc'.$this->_prefix_review,
                        'id' => 'facvouc'.$this->_prefix_review,
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'voucherserg'))
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Share your review on Facebook and get voucher for discount email'),
                        'name' => 'is_sugvouc'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),

                        'desc' => $this->l('Enable or Disable Share your review on Facebook and get voucher for discount email'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Share your review on Facebook and get voucher for discount subject'),
                        'name' => 'sugvouc'.$this->_prefix_review,
                        'id' => 'sugvouc'.$this->_prefix_review,
                        'lang' => TRUE,
                        'desc' => $this->_responseadminemailsDesc(array('name'=>'voucherserg-suggest'))
                    ),




                ),
            ),
        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );




        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'responseadminemailssettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesResponseadminemailsSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        return  $helper->generateForm(array($fields_form,$fields_form1));
    }

    public function getConfigFieldsValuesResponseadminemailsSettings(){

        $languages = Language::getLanguages(false);
        $fields_subresem = array();
        $fields_textresem = array();
        $fields_emailreminder = array();
        $fields_reminderok = array();
        $fields_thankyou = array();
        $fields_newrev = array();
        $fields_subpubem = array();
        $fields_modrev = array();
        $fields_abuserev = array();
        $fields_facvouc = array();
        $fields_revvouc = array();
        $fields_sugvouc = array();

        foreach ($languages as $lang)
        {
            $fields_subresem[$lang['id_lang']] =  Configuration::get($this->name.'subresem_'.$lang['id_lang']);
            $fields_textresem[$lang['id_lang']] =  Configuration::get($this->name.'textresem_'.$lang['id_lang']);
            $fields_emailreminder[$lang['id_lang']] =  Configuration::get($this->name.'emailreminder_'.$lang['id_lang']);
            $fields_reminderok[$lang['id_lang']] =  Configuration::get($this->name.'reminderok'.$this->_prefix_review.'_'.$lang['id_lang']);
            $fields_thankyou[$lang['id_lang']] =  Configuration::get($this->name.'thankyou'.$this->_prefix_review.'_'.$lang['id_lang']);
            $fields_newrev[$lang['id_lang']] =  Configuration::get($this->name.'newrev'.$this->_prefix_review.'_'.$lang['id_lang']);
            $fields_subpubem[$lang['id_lang']] =  Configuration::get($this->name.'subpubem_'.$lang['id_lang']);
            $fields_modrev[$lang['id_lang']] =  Configuration::get($this->name.'modrev'.$this->_prefix_review.'_'.$lang['id_lang']);
            $fields_abuserev[$lang['id_lang']] =  Configuration::get($this->name.'abuserev'.$this->_prefix_review.'_'.$lang['id_lang']);
            $fields_facvouc[$lang['id_lang']] =  Configuration::get($this->name.'facvouc'.$this->_prefix_review.'_'.$lang['id_lang']);
            $fields_revvouc[$lang['id_lang']] =  Configuration::get($this->name.'revvouc'.$this->_prefix_review.'_'.$lang['id_lang']);
            $fields_sugvouc[$lang['id_lang']] =  Configuration::get($this->name.'sugvouc'.$this->_prefix_review.'_'.$lang['id_lang']);
        }


        $data_config = array(
            'subresem' => $fields_subresem,
            'textresem' => $fields_textresem,
            'emailreminder' => $fields_emailreminder,
            'reminderok'.$this->_prefix_review => $fields_reminderok,
            'thankyou'.$this->_prefix_review => $fields_thankyou,
            'newrev'.$this->_prefix_review => $fields_newrev,
            'subpubem' =>$fields_subpubem,
            'modrev'.$this->_prefix_review => $fields_modrev,
            'abuserev'.$this->_prefix_review => $fields_abuserev,

            'facvouc'.$this->_prefix_review => $fields_facvouc,
            'revvouc'.$this->_prefix_review => $fields_revvouc,
            'sugvouc'.$this->_prefix_review => $fields_sugvouc,

            'is_emailreminder' => Configuration::get($this->name.'is_emailreminder'),
            'is_reminderok'.$this->_prefix_review => Configuration::get($this->name.'is_reminderok'.$this->_prefix_review),
            'is_thankyou'.$this->_prefix_review => Configuration::get($this->name.'is_thankyou'.$this->_prefix_review),
            'is_newrev'.$this->_prefix_review => Configuration::get($this->name.'is_newrev'.$this->_prefix_review),
            'is_subresem' => Configuration::get($this->name.'is_subresem'),
            'is_modrev'.$this->_prefix_review => Configuration::get($this->name.'is_modrev'.$this->_prefix_review),
            'is_subpubem' => Configuration::get($this->name.'is_subpubem'),
            'is_abuserev'.$this->_prefix_review => Configuration::get($this->name.'is_abuserev'.$this->_prefix_review),
            'is_revvouc'.$this->_prefix_review => Configuration::get($this->name.'is_revvouc'.$this->_prefix_review),
            'is_facvouc'.$this->_prefix_review => Configuration::get($this->name.'is_facvouc'.$this->_prefix_review),
            'is_sugvouc'.$this->_prefix_review => Configuration::get($this->name.'is_sugvouc'.$this->_prefix_review),

        );

        return $data_config;

    }

    private function _reviewsemails(){

        $data_img_sizes = array();

        $available_types = ImageType::getImagesTypes('products');

        foreach ($available_types as $type){

            $id = $type['name'];
            $name = $type['name'].' ('.$type['width'].' x '.$type['height'].')';

            $data_item_size = array(
                'id' => $id,
                'name' => $name,
            );

            array_push($data_img_sizes,$data_item_size);


        }

        $fields_form = array(
            'form'=> array(

                'legend' => array(
                    'title' => $this->l('Reviews emails settings'),
                    'icon' => 'fa fa-envelope-o fa-lg'
                ),
                'input' => array(

                    array(
                        'type' => 'text_custom_email',
                        'label' => $this->l('Email administrator for notifications'),
                        'name' => 'mail',
                        'value'=> Configuration::get($this->name.'mail'),

                    ),


                    array(
                        'type' => 'checkbox_custom_email',
                        'label' => $this->l('Email notifications'),
                        'name' => 'noti',
                        'desc' => $this->l('Email notifications when customer add review / rating or review is reported as an abuse'),
                        'values' => array(
                            'value' => (int)Configuration::get($this->name.'noti')
                        ),


                    ),

                    array(
                        'type' => 'select',
                        'label' => $this->l('Image size for products'),
                        'name' => 'img_size_em',
                        'desc' => $this->l('The emails will contain a photo of each product.'),
                        'options' => array(
                            'query' => $data_img_sizes,
                            'id' => 'id',
                            'name' => 'name'
                        )
                    ),



                ),



            ),


        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );




        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'reviewsemailssettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesReviewsemailsSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        return  $helper->generateForm(array($fields_form,$fields_form1));
    }

    public function getConfigFieldsValuesReviewsemailsSettings(){

        $data_config = array(

            'img_size_em' => Configuration::get($this->name.'img_size_em'),

        );

        return $data_config;

    }

    private function _reviews16(){

        $this->_data_translate_custom['_reviews16_gl_set'] = $this->l('Global settings');
        $this->_data_translate_custom['_reviews16_pr_page'] = $this->l('Product page');
        $this->_data_translate_custom['_reviews16_rev_man'] = $this->l('Reviews management');
        $this->_data_translate_custom['_reviews16_rev_crit'] = $this->l('Review Criteria');
        $this->_data_translate_custom['_reviews16_cust_acc_rev_p'] = $this->l('Customer account reviews page');
        $this->_data_translate_custom['_reviews16_wow_eff'] = $this->l('WOW effects for items in the list view settings');
        $this->_data_translate_custom['_reviews16_owl_car'] = $this->l('OWL carousels for Last Reviews Block settings');
        $this->_data_translate_custom['_reviews16_last_rev_block'] = $this->l('Last Reviews Block');
        $this->_data_translate_custom['_reviews16_stars_in_cat_and_search_p'] = $this->l('Stars in Category and Search pages');
        $this->_data_translate_custom['_reviews16_rev_rss_feed'] = $this->l('Reviews RSS Feed');
        $this->_data_translate_custom['_reviews16_import_prod_com'] = $this->l('Import Product Comments');
        $this->_data_translate_custom['_reviews16_g_pr_rev_feed'] = $this->l('Google Product Review Feeds for Google Shopping');
        $this->_data_translate_custom['_reviews16_voucher_set_add_rev'] = $this->l('Voucher settings, when a user add review');
        $this->_data_translate_custom['_reviews16_voucher_set_share_rev_on_f'] = $this->l('Voucher settings, when a user share review on the Facebook');
        $this->_data_translate_custom['_reviews16_rev_em_set'] = $this->l('Reviews emails settings');
        $this->_data_translate_custom['_reviews16_em_subj_set'] = $this->l('Emails subjects settings');
        $this->_data_translate_custom['_reviews16_cust_rem_set'] = $this->l('Customer Reminder settings');
        $this->_data_translate_custom['_reviews16_cust_rem_stat'] = $this->l('Customer Reminder Statistics');
        $this->_data_translate_custom['_reviews16_cron_help_p_rev'] = $this->l('CRON HELP PRODUCT REVIEWS');
        $this->_data_translate_custom['_reviews16_csv_imp_exp_pr'] = $this->l('CSV import/export product reviews settings');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();
        return $_html;


    }


    private function _owlcarousels(){



        $fields_form1 = array(
            'form'=> array(

                'legend' => array(
                    'title' => $this->l('OWL carousels for Last Reviews block in the Left, Right, Footer positions settings'),
                    'icon' => 'fa fa-sliders fa-lg'
                ),
                'input' => array(



                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Slider for Last Reviews block in the Left, Right, Footer positions'),
                        'name' => 'sr_sliderr',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Displayed number of items in the slider in the block Last Reviews block in the Left, Right, Footer positions'),
                        'name' => 'sr_slr',
                        'id' => 'sr_slr',
                        'lang' => FALSE,
                    ),

                ),



            ),


        );



        $fields_form2 = array(
            'form'=> array(

                'legend' => array(
                    'title' => $this->l('OWL carousel for block Last Reviews block on the Home Page settings'),
                    'icon' => 'fa fa-sliders fa-lg'
                ),
                'input' => array(



                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Slider for Last Reviews block on the Home Page'),
                        'name' => 'sr_sliderhr',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Displayed number of items in the slider in the block Last Reviews block on the Home Page'),
                        'name' => 'sr_slhr',
                        'id' => 'sr_slhr',
                        'lang' => FALSE,
                    ),

                ),



            ),


        );



        $fields_form10 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );




        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'owlcarouselssettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesOwlcarouselsSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );






        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'_js.phtml');
        $_html = ob_get_clean();



        return  $_html.$helper->generateForm(array($fields_form1,$fields_form2, $fields_form10));
    }

    public function getConfigFieldsValuesOwlcarouselsSettings(){

        $data_config = array(

            'sr_sliderr'=> (int)Configuration::get($this->name.'sr_sliderr'),
            'sr_slr'=> (int)Configuration::get($this->name.'sr_slr'),

            'sr_sliderhr'=> (int)Configuration::get($this->name.'sr_sliderhr'),
            'sr_slhr'=> (int)Configuration::get($this->name.'sr_slhr'),
        );

        return $data_config;

    }


    private function _woweffects(){



        $fields_form = array(
            'form'=> array(

                'legend' => array(
                    'title' => $this->l('WOW effects for items in the list view settings'),
                    'icon' => 'fa fa-sliders fa-lg'
                ),
                'input' => array(


                    array(
                        'type' => 'wow_display_effect',
                        'label' => $this->l('Display effect in the list view for Reviews on the Product page'),
                        'name' => 'd_eff_rev',
                        'id' => 'd_eff_rev',
                        'lang' => FALSE,
                        'value' => $this->_effects(array('value' => 'd_eff_rev'))
                    ),


                    array(
                        'type' => 'wow_display_effect',
                        'label' => $this->l('Display effect for Reviews in the My account'),
                        'name' => 'd_eff_rev_my',
                        'id' => 'd_eff_rev_my',
                        'lang' => FALSE,
                        'value' => $this->_effects(array('value' => 'd_eff_rev_my'))
                    ),

                    array(
                        'type' => 'wow_display_effect',
                        'label' => $this->l('Display effect in the tab Product Reviews on the User Page'),
                        'name' => 'd_eff_rev_u',
                        'id' => 'd_eff_rev_u',
                        'lang' => FALSE,
                        'value' => $this->_effects(array('value' => 'd_eff_rev_u'))
                    ),

                    array(
                        'type' => 'wow_display_effect',
                        'label' => $this->l('Display effect in the list view for All Reviews page'),
                        'name' => 'd_eff_rev_all',
                        'id' => 'd_eff_rev_all',
                        'lang' => FALSE,
                        'value' => $this->_effects(array('value' => 'd_eff_rev_all'))
                    ),

                ),



            ),


        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );




        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'woweffectssettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesWoweffectsSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        return  $helper->generateForm(array($fields_form,$fields_form1));
    }

    public function getConfigFieldsValuesWoweffectsSettings(){

        $data_config = array(

        );

        return $data_config;

    }


    public function _csvImportExportProductReviews(){
        include_once(_PS_MODULE_DIR_ . $this->name .'/classes/csvhelpr.class.php');
        $obj = new csvhelpr();
        $data_fields = $obj->getAvailableFields();
        $_html = '';


        require_once(_PS_MODULE_DIR_ . $this->name . '/classes/reviewsadvhelp.class.php');
        $obj_reviewsadvhelp = new reviewsadvhelp();

        $data_seo_url = $obj_reviewsadvhelp->getSEOURLs();
        $export_product_url = $data_seo_url['export_product_url'];

        $delimeter_rewrite = "&";
        if(Configuration::get('PS_REWRITING_SETTINGS')){
            $delimeter_rewrite = "?";

        }

        $this->_data_translate_custom['_csvImportExportProductReviews_you_must_resp'] = $this->l('You must respect the following rules to upload the CSV Product Reviews correctly');
        $this->_data_translate_custom['_csvImportExportProductReviews_csv_imp_exp'] = $this->l('CSV import/export product reviews settings');
        $this->_data_translate_custom['_csvImportExportProductReviews_click_downl'] = $this->l('Click here to download an example of CSV file (you can write your reviews directly in it)');
        $this->_data_translate_custom['_csvImportExportProductReviews_save_in_csv'] = $this->l('Save your file in CSV format. If you use Open Office, choose the option "Field separator: semi-colon"');
        $this->_data_translate_custom['_csvImportExportProductReviews_csv_imp'] = $this->l('CSV Import');
        $this->_data_translate_custom['_csvImportExportProductReviews_imp_rev'] = $this->l('Import reviews');
        $this->_data_translate_custom['_csvImportExportProductReviews_csv_exp'] = $this->l('CSV Export');
        $this->_data_translate_custom['_csvImportExportProductReviews_exp_all_rev'] = $this->l('Export all reviews');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();
        return $_html;


    }


    public function _customerreminderstat(){


        include_once(_PS_MODULE_DIR_.$this->name.'/classes/featureshelp.class.php');
        $obj = new featureshelp();

        $start_date_orders = Tools::getValue('start_date_orders');
        $end_date_orders = Tools::getValue('end_date_orders');



        $end_date = empty($end_date_orders)?date('Y-m-d H:i:s',strtotime("+1 day")):$end_date_orders;
        $start_date = empty($start_date_orders)?date('Y-m-d H:i:s',strtotime("-1 week")):$start_date_orders;



        $delayed_posts_data = $obj->getOrdersForReminder(array('start_date'=>$start_date,'end_date'=>$end_date));
        $delayed_posts = $delayed_posts_data['result'];
        $count_all = $delayed_posts_data['count_all'];




        return $this->drawDelayedPosts(array('posts'=>$delayed_posts,'count_all'=>$count_all,
            'start_date'=>$start_date,'end_date'=>$end_date));
    }

    public function drawDelayedPosts($data){


        $cookie = $this->context->cookie;
        $id_lang = (int)($cookie->id_lang);

        include_once(_PS_MODULE_DIR_ . $this->name.'/classes/featureshelp.class.php');
        $obj = new featureshelp();

        include_once(_PS_MODULE_DIR_ . $this->name.'/classes/reviewsadvhelp.class.php');
        $obj_shopreviews = new reviewsadvhelp();



        $data_seo_url = $obj_shopreviews->getSEOURLs();
        $reviews_admin_url = $data_seo_url['reviews_url'];


        $this->_data_translate_custom['drawDelayedPosts_cust_rem_stat'] = $this->l('Customer Reminder Statistics');
        $this->_data_translate_custom['drawDelayedPosts_send_em_with_sel_stat'] = $this->l('Send emails only for the orders with the current selected status');
        $this->_data_translate_custom['drawDelayedPosts_send_a_rev_rem_by_em'] = $this->l('Enable or Disable Send a review reminder by email to customers');
        $this->_data_translate_custom['drawDelayedPosts_yes'] = $this->l('Yes');
        $this->_data_translate_custom['drawDelayedPosts_no'] = $this->l('No');
        $this->_data_translate_custom['drawDelayedPosts_del_for_send_rem_by_em'] = $this->l('Delay for sending reminder by email');
        $this->_data_translate_custom['drawDelayedPosts_days'] = $this->l('days');
        $this->_data_translate_custom['drawDelayedPosts_send_rem_second_time'] = $this->l('Enable or Disable Send a review reminder by email to customers a second time?');
        $this->_data_translate_custom['drawDelayedPosts_days_after_first_em'] = $this->l('Days after the first emails were sent');
        $this->_data_translate_custom['drawDelayedPosts_already_write_rev'] = $this->l('Enable or Disable Send a review reminder by email to customer when customer already write review in shop?');
        $this->_data_translate_custom['drawDelayedPosts_start_date'] = $this->l('start date');
        $this->_data_translate_custom['drawDelayedPosts_end_date'] = $this->l('end date');
        $this->_data_translate_custom['drawDelayedPosts_fil_orders'] = $this->l('Filter orders');
        $this->_data_translate_custom['drawDelayedPosts_id'] = $this->l('ID');
        $this->_data_translate_custom['drawDelayedPosts_ref'] = $this->l('Reference');
        $this->_data_translate_custom['drawDelayedPosts_add_date'] = $this->l('Adding date');
        $this->_data_translate_custom['drawDelayedPosts_ord_stat'] = $this->l('Order status');
        $this->_data_translate_custom['drawDelayedPosts_shop'] = $this->l('Shop');
        $this->_data_translate_custom['drawDelayedPosts_em_sent_once'] = $this->l('Email sent once?');
        $this->_data_translate_custom['drawDelayedPosts_em_sent_twice'] = $this->l('Email sent twice?');
        $this->_data_translate_custom['drawDelayedPosts_rev_alredy_wr'] = $this->l('Review already written?');
        $this->_data_translate_custom['drawDelayedPosts_send_ord_man'] = $this->l('Send order manually');
        $this->_data_translate_custom['drawDelayedPosts_are_sure_send_ord'] = $this->l('Are you sure to want Send order manually ');
        $this->_data_translate_custom['drawDelayedPosts_no_ord'] =$this->l('There is no orders for customer reminder');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();
        return $_html;



    }


    private $_criterion_error =  0;
    private function _reviewcriteria(){

        if (Tools::isSubmit('addCriteria') || Tools::isSubmit('editreviewsadv') || $this->_criterion_error) {
            return $this->_displayAddReviewcriteriaForm16();
        } else {
            return $this->_displayReviewcriteriaGrid16();
        }
    }

    private function _displayAddReviewcriteriaForm16(){
        $token = Tools::getAdminTokenLite('AdminModules');
        $back = Tools::safeOutput(Tools::getValue('back', ''));
        $current_index = AdminController::$currentIndex;
        if (!isset($back) || empty($back))
            $back = $current_index.'&amp;configure='.$this->name.'&token='.$token;





        $id_block = Tools::getValue('id');

        if (Tools::isSubmit('id') && Tools::isSubmit('editreviewsadv'))
        {
            $this->_display = 'edit';

            include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
            $obj_reviewsadvhelp = new reviewsadvhelp();
            $_data = $obj_reviewsadvhelp->getReviewCriteriaItem(array('id'=>(int)$id_block));


            $id_shop = isset($_data['item'][0]['id_shop']) ? explode(",",$_data['item'][0]['id_shop']) : array();

            $id_category = isset($_data['item'][0]['id_category'])?$_data['item'][0]['id_category']:'';
            $selected_cat = $id_category;
            $is_category = isset($_data['item'][0]['is_category'])?$_data['item'][0]['is_category']:0;

            $id_pr = isset($_data['item'][0]['id_product'])?$_data['item'][0]['id_product']:'';
            $selected_products = (($id_pr!=0) ? $obj_reviewsadvhelp->getProducts($id_pr) : array());


        } else {
            $this->_display = 'add';
            $id_shop = Tools::getValue('cat_shop_association')?Tools::getValue('cat_shop_association'):array();

            $ids_products = Tools::getValue("inputAccessories");
            if($ids_products){

                include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
                $obj_reviewsadvhelp = new reviewsadvhelp();


                $ids_products = explode("-",$ids_products,-1);
                $ids_products = implode(",",$ids_products);
                $selected_products = (($ids_products!=0) ? $obj_reviewsadvhelp->getProducts($ids_products) : array());

            } else {
                $selected_products = array();
            }
            $is_category = 0;
            $id_category = Tools::getValue('categoryBoxc');
            $selected_cat = $id_category;
        }




        /* design of the categories with checkbox buttons */
        $select_categories = explode(",",$selected_cat);

        $categories = array();
        foreach ($select_categories as $key => $category) {
            $categories[] = $category;
        }

        $root = Category::getRootCategory();
        $tree = new HelperTreeCategories('associated-categories-tree-c', 'Associated categories');
        $tree->setTemplate('tree_associated_categories.tpl')
            ->setHeaderTemplate('tree_associated_header.tpl')
            ->setTemplateDirectory(dirname(__FILE__).'/views/templates/admin/_configure/helpers/tree/')
            ->setRootCategory((int)$root->id)
            ->setInputName('categoryBoxc')
            ->setUseCheckBox(true)
            ->setUseSearch(true)
            ->setSelectedCategories($categories);
        $selected_categories = $tree->render();



        /* design of the categories with checkbox buttons */




        $fields_form = array(
            'form' => array(
                'tinymce' => TRUE,
                'legend' => array(
                    'title' => !empty($id_block) ? $this->l('Edit criterion') : $this->l('Add new criterion'),
                    'icon' => !empty($id_block) ? 'icon-edit' : 'icon-plus-square'
                ),
                'input' => array(
                    array(
                        'type' => 'text',
                        'label' => $this->l('Criterion name'),
                        'name' => 'name',
                        'id' => 'name',
                        'lang' => TRUE,
                        'required' => TRUE,
                        'size' => 50,
                        'maxlength' => 50,
                    ),

                    array(
                        'type' => 'textarea',
                        'label' => $this->l('Description'),
                        'name' => 'description',
                        //'required' => TRUE,
                        'autoload_rte' => FALSE,
                        'lang' => TRUE,
                        'rows' => 5,
                        'cols' => 40,
                        'desc' => $this->l('If you do not want see description - just leave this field empty'),
                        'hint' => $this->l('If you do not want see description - just leave this field empty'),
                    ),


                    array(
                        'type' => 'select',
                        'label' => $this->l('Application scope of the criterion'),
                        'name' => 'criterion_type',
                        'class' => 'fixed-width-xxl',
                        'options' => array(
                            'query' => array(
                                array(
                                    'id' => '1',
                                    'name' => $this->l('Restricted to some products')
                                ),

                                array(
                                    'id' => '2',
                                    'name' => $this->l('Restricted to some categories'),
                                ),

                                array(
                                    'id' => '3',
                                    'name' => $this->l('Valid for the entire catalog'),
                                ),
                            ),
                            'id' => 'id',
                            'name' => 'name'
                        )
                    ),

                    array(
                        'type' => 'cms_categories',
                        'label' => $this->l('Select categories:'),
                        'hint' => $this->l('Check all box(es) of categories to which the products in categories is to be applied.'),
                        'desc' => $this->l('Check all box(es) of categories to which the products in categories is to be applied.'),

                        'name' => 'select_cat',
                        'values'=> $selected_categories,

                    ),

                    array(
                        'type' => 'text_custom_criteria',
                        'label' => $this->l('Select products:'),
                        'name' => 'selected_products',
                        'id' => 'selected_products',
                        'required' => FALSE,
                        'size' => 50,
                        'maxlength' => 50,
                        'selected_products' => $selected_products,
                    ),

                    array(
                        'type' => 'cms_shop_association',
                        'label' => $this->l('Shop association'),
                        'name' => 'cat_shop_association',
                        'values'=>Shop::getShops(),
                        'selected_data'=>$id_shop,
                        'required' => TRUE,
                        'is17'=>(version_compare(_PS_VERSION_, '1.7', '>')?1:0),

                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Status'),
                        'name' => 'active',
                        'required' => FALSE,
                        'class' => 't',
                        'is_bool' => TRUE,
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Enabled')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('Disabled')
                            )
                        ),
                    ),


                ),
                'buttons' => array(
                    'cancelBlock' => array(
                        'title' => $this->l('Cancel'),
                        'href' => $back.'&'.$this->name.'criteriaset=1',
                        'icon' => 'process-icon-cancel'
                    )
                ),
                'submit' => array(
                    'name' => ((!$id_block)?'submit':'update_item'),
                    'title' => ((!$id_block)?$this->l('Save'):$this->l('Update')),
                )
            )
        );




        $helper = new HelperForm();

        $helper->toolbar_scroll = true;
        $helper->toolbar_btn = $this->initToolbar();

        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;


        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesReviewCriteriaSettings(array('id_block'=>$id_block,'is_category'=>$is_category,'selected_products'=>$selected_products)),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        if (Tools::isSubmit('id')
            //&& Tools::isSubmit('editreviewsadv')
            ) {
            $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name . '&id=' . $id_block .'&'.$this->name.'criteriaset=1';
            $helper->submit_action = 'editcriteriasettings';
        }else {
            $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'&'.$this->name.'criteriaset=1';
            $helper->submit_action = 'addcriteriasettings';
        }


        $criterion_type = 3;
        if(count($selected_products)>0){
            $criterion_type = 1;
        }
        if($is_category){
            $criterion_type = 2;
        }


        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'_js.phtml');
        $_html = ob_get_clean();



        return $_html.$helper->generateForm(array($fields_form));

    }

    public function getConfigFieldsValuesReviewCriteriaSettings($data_in){
        $id = $data_in['id_block'];

        include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
        $obj_reviewsadvhelp = new reviewsadvhelp();
        $_data = $obj_reviewsadvhelp->getReviewCriteriaItem(array('id'=>(int)$id));

        $item_data_lng = isset($_data['item']['data'])?$_data['item']['data']:array();
        $active = isset($_data['item'][0]['active'])?$_data['item'][0]['active']:0;


        $languages = Language::getLanguages(false);
        $fields_name = array();
        $fields_description = array();

        foreach ($languages as $lang)
        {
            $fields_name[$lang['id_lang']] = isset($item_data_lng[$lang['id_lang']]['name'])?$item_data_lng[$lang['id_lang']]['name']:Tools::getValue('name_'.$lang['id_lang']);

            $fields_description[$lang['id_lang']] = isset($item_data_lng[$lang['id_lang']]['description'])?$item_data_lng[$lang['id_lang']]['description']:Tools::getValue('description_'.$lang['id_lang']);
        }

        $is_category = $data_in['is_category'];
        $selected_products = $data_in['selected_products'];

        $criterion_type = 3;
        if(count($selected_products)>0){
            $criterion_type = 1;
        }
        if($is_category){
            $criterion_type = 2;
        }


        $config_array = array(
            'name' => $fields_name,
            'description' => $fields_description,
            'active' => $active,
            'criterion_type'=>$criterion_type,
        );

        return $config_array;
    }

    private function _displayReviewcriteriaGrid16(){
        $current_index = AdminController::$currentIndex;
        $token = Tools::getAdminTokenLite('AdminModules');

        ## add information ##
        include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
        $obj_reviewsadvhelp = new reviewsadvhelp();


        $_data = $obj_reviewsadvhelp->getReviewCriteriaItems(array('start' => 0,'step'=>1000));
        $_items = $_data['items'];


        if(sizeof($_items)>0) {

            foreach ($_items as $_k=>$_item) {

                ## languages ##
                $ids_lng = isset($_item['ids_lng']) ? $_item['ids_lng'] : array();
                $lang_for_item = array();
                foreach ($ids_lng as $lng_id) {
                    $data_lng = Language::getLanguage($lng_id);
                    $lang_for_item[] = $data_lng['iso_code'];
                }
                $lang_for_item = implode(",", $lang_for_item);

                $_items[$_k]['ids_lng'] = $lang_for_item;
                ## languages ##

                ## shops ##
                $ids_shops = explode(",", $_item['id_shop']);

                $shops = Shop::getShops();
                $name_shop = array();
                foreach ($shops as $_shop) {
                    $id_shop_lists = $_shop['id_shop'];
                    if (in_array($id_shop_lists, $ids_shops))
                        $name_shop[] = $_shop['name'];
                }

                $name_shop = implode(", ", $name_shop);

                $_items[$_k]['id_shop'] = $name_shop;
                ## shops ##


                $id_product_tmp = explode(",", $_item['id_product']);
                $id_product_tmp = implode(", ", $id_product_tmp);

                $_items[$_k]['id_product'] = $id_product_tmp;



                $id_cat_tmp = explode(",", $_item['id_category']);
                $id_cat_tmp = implode(", ", $id_cat_tmp);

                $_items[$_k]['id_category'] = $id_cat_tmp;

            }
        }
        ## add information ##



        $fields_form = array(
            'form' => array(
                'legend' => array(
                    'title' => $this->l('Review Criteria'),
                    'icon' => 'fa fa-reviews fa-lg'
                ),
                'input' => array(
                    array(
                        'type' => 'cms_blocks_custom_product_reviews',
                        'label' => $this->l('Review Criteria'),
                        'name' => 'cms_blocks_custom',
                        'values' => $_items,
                        'prefix' => '',
                    )
                ),
                'buttons' => array(
                    'newBlock' => array(
                        'title' => $this->l('Add New Criterion'),
                        'href' => $current_index.'&amp;configure='.$this->name.'&amp;token='.$token.'&amp;addCriteria',
                        'class' => 'pull-right',
                        'icon' => 'process-icon-new'
                    )
                )
            )
        );


        $this->_display = 'index';

        $helper = new HelperForm();

        $helper->toolbar_scroll = true;
        $helper->toolbar_btn = $this->initToolbar();

        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = '';

        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');

        return $helper->generateForm(array($fields_form));
    }

    public function initToolbar()
    {
        $current_index = AdminController::$currentIndex;
        $token = Tools::getAdminTokenLite('AdminModules');
        $back = Tools::safeOutput(Tools::getValue('back', ''));
        if (!isset($back) || empty($back)) {
            $back = $current_index . '&amp;configure=' . $this->name . '&token=' . $token . '&'.$this->name.'criteriaset=1';
        } else {
            $back = $back.'&'.$this->name.'criteriaset=1';
        }
        switch ($this->_display)
        {
            case 'add':
                $this->toolbar_btn['cancel'] = array(
                    'href' => $back,
                    'desc' => $this->l('Cancel')
                );
                break;
            case 'edit':
                $this->toolbar_btn['cancel'] = array(
                    'href' => $back,
                    'desc' => $this->l('Cancel')
                );
                break;
            case 'index':
                $this->toolbar_btn['new'] = array(
                    'href' => $current_index.'&amp;configure='.$this->name.'&amp;token='.$token.'&amp;addCriteria&'.$this->name.'criteriaset=1',
                    'desc' => $this->l('Add New Criterion')
                );
                break;
            default:
                break;
        }
        return $this->toolbar_btn;
    }

    private function _groductFeed(){

        require_once(_PS_MODULE_DIR_ . $this->name . '/classes/reviewsadvhelp.class.php');
        $obj_reviewsadvhelp = new reviewsadvhelp();

        $data_seo_url = $obj_reviewsadvhelp->getSEOURLs();
        $reviews_admin_url = $data_seo_url['reviews_admin_url'];

        $delimeter_rewrite = "&";
        if(Configuration::get('PS_REWRITING_SETTINGS')){
            $delimeter_rewrite = "?";
        }
        $url_cron = $data_seo_url['cron_reviews_url'];


        $this->_data_translate_custom['_groductFeed_g_pr_feed'] = $this->l('Google Product Review Feeds for Google Shopping');
        $this->_data_translate_custom['_groductFeed_g_pr_feed_let_cont'] = $this->l('Google Product Review Feeds let content providers send product reviews to');
        $this->_data_translate_custom['_groductFeed_g_shop'] = $this->l('Google Shopping');
        $this->_data_translate_custom['_groductFeed_g_pr_rat_feed'] = $this->l('Google Product Ratings Feeds');
        $this->_data_translate_custom['_groductFeed_more_inf'] = $this->l('More info');
        $this->_data_translate_custom['_groductFeed_cron_to_call'] = $this->l('Your CRON URL to call');
        $this->_data_translate_custom['_groductFeed_regenerate'] = $this->l('Regenerate Google Product Ratings Feed');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();


        $_html .= $this->_cronhelp(array('url'=>'cronreviews'));

        return $_html;
    }

    private function _importcomments(){
        $_html = '';
        include_once(_PS_MODULE_DIR_.$this->name.'/classes/importhelp.class.php');
        $obj = new importhelp();


        $this->_data_translate_custom['_importcomments_imp_pr_com'] = $this->l('Import Product Comments');
        $this->_data_translate_custom['_importcomments_your_database'] = $this->l('Your database no contains Product comments for imports');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();



        return $_html;
    }

    private function _rssfeed(){
        $fields_form = array(
            'form'=> array(

                'legend' => array(
                    'title' => $this->l('Reviews RSS Feed'),
                    'icon' => 'fa fa-rss fa-lg'
                ),
                'input' => array(

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable RSS Feed'),
                        'name' => 'rsson',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Title of your RSS Feed'),
                        'name' => 'rssname',
                        'id' => 'rssname',
                        'lang' => TRUE,
                        //'required' => TRUE,
                        'size' => 50,
                        //'maxlength' => 50,
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Description of your RSS Feed'),
                        'name' => 'rssdesc',
                        'id' => 'rssdesc',
                        'lang' => TRUE,
                        //'required' => TRUE,
                        'size' => 50,
                        //'maxlength' => 50,
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Number of items in RSS Feed'),
                        'name' => 'number_rssitems',
                        'class' => ' fixed-width-sm',

                    ),


                ),



            ),


        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );




        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'rssfeedsettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesRssfeedSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        return  $helper->generateForm(array($fields_form,$fields_form1));
    }

    public function getConfigFieldsValuesRssfeedSettings(){
        $languages = Language::getLanguages(false);
        $fields_rssname = array();
        $fields_rssdesc = array();

        foreach ($languages as $lang)
        {
            $fields_rssname[$lang['id_lang']] =  Configuration::get($this->name.'rssname_'.$lang['id_lang']);

            $fields_rssdesc[$lang['id_lang']] =  Configuration::get($this->name.'rssdesc_'.$lang['id_lang']);
        }


        $data_config = array(
            'rsson' => Configuration::get($this->name.'rsson'),
            'rssname' => $fields_rssname,
            'rssdesc' => $fields_rssdesc,
            'number_rssitems' => (int)Configuration::get($this->name.'number_rssitems'),

        );

        return $data_config;

    }

    private function _starslistandsearch(){
        $fields_form = array(
            'form'=> array(
                'legend' => array(
                    'title' => $this->l('Stars in Category and Search pages'),
                    'icon' => 'fa fa-bars fa-lg'
                ),
                'input' => array(

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable stars on the category and search pages'),
                        'name' => 'starscat',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),



                    array(
                        'type' => 'switch',
                        'label' => $this->l('Hide stars when product no has reviews on the category and search pages'),
                        'name' => 'is_starscat',


                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),



                ),
            ),


        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );




        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'starslistandsearchsettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesStarslistandsearchSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        $_html = '';
        if (version_compare(_PS_VERSION_, '1.7', '>')) {

            $this->_data_translate_custom['_starslistandsearch_faq'] = $this->l('Frequently Asked Questions');

            ob_start();
            include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
            $_html = ob_get_clean();
        }

        return  $helper->generateForm(array($fields_form,$fields_form1)).$_html;
    }

    public function getConfigFieldsValuesStarslistandsearchSettings(){

        $data_config = array(
            'starscat' => (int)Configuration::get($this->name.'starscat'),
            'is_starscat'=> (int)Configuration::get($this->name.'is_starscat'),


        );

        return $data_config;

    }


    private function block_last_reviews(){

        $data_img_sizes = array();

        $available_types = ImageType::getImagesTypes('products');

        foreach ($available_types as $type){

            $id = $type['name'];
            $name = $type['name'].' ('.$type['width'].' x '.$type['height'].')';

            $data_item_size = array(
                'id' => $id,
                'name' => $name,
            );

            array_push($data_img_sizes,$data_item_size);


        }


        $block_last_reviews = array(
            'type' => 'block_last_reviews',
            'label' => $this->l('Display block on the following pages'),

            'name' => 'block_last_reviews',
            'values'=> array(
                'blocklr_home' => array('name'=>$this->l('for home page'),
                    'status' => Configuration::get($this->name.'blocklr_home'),
                    'position'=>Configuration::get($this->name.'blocklr_home_pos'),
                    'number_display_reviews' => array('number_display_reviews' => (int)Configuration::get($this->name.'blocklr_home_ndr'), 'name'=>'blocklr_home_ndr'),
                    'truncate' => array('truncate' => (int)Configuration::get($this->name.'blocklr_home_tr'), 'name'=>'blocklr_home_tr'),
                    'imsize' => array('imsize' => Configuration::get($this->name.'blocklr_home_im'), 'name'=>'blocklr_home_im'),
                    'width' => array('width' => (int)Configuration::get($this->name.'blocklr_home_w'), 'name'=>'blocklr_home_w')),
                'blocklr_cat' => array('name'=>$this->l('for each category page'),
                    'status' => Configuration::get($this->name.'blocklr_cat'),
                    'position'=>Configuration::get($this->name.'blocklr_cat_pos'),
                    'number_display_reviews' => array('number_display_reviews' => (int)Configuration::get($this->name.'blocklr_cat_ndr'), 'name'=>'blocklr_cat_ndr'),
                    'truncate' => array('truncate' => (int)Configuration::get($this->name.'blocklr_cat_tr'), 'name'=>'blocklr_cat_tr'),
                    'imsize' => array('imsize' => Configuration::get($this->name.'blocklr_cat_im'), 'name'=>'blocklr_cat_im'),
                    'width' => array('width' => (int)Configuration::get($this->name.'blocklr_cat_w'), 'name'=>'blocklr_cat_w')),
                'blocklr_man' => array('name'=>$this->l('for each manufacturer/brand page'),
                    'status' => Configuration::get($this->name.'blocklr_man'),
                    'position'=>Configuration::get($this->name.'blocklr_man_pos'),
                    'number_display_reviews' => array('number_display_reviews' => (int)Configuration::get($this->name.'blocklr_man_ndr'), 'name'=>'blocklr_man_ndr'),
                    'truncate' => array('truncate' => (int)Configuration::get($this->name.'blocklr_man_tr'), 'name'=>'blocklr_man_tr'),
                    'imsize' => array('imsize' => Configuration::get($this->name.'blocklr_man_im'), 'name'=>'blocklr_man_im'),
                    'width' => array('width' => (int)Configuration::get($this->name.'blocklr_man_w'), 'name'=>'blocklr_man_w')),
                'blocklr_prod' => array('name'=>$this->l('for each product page'),
                    'status' => Configuration::get($this->name.'blocklr_prod'),
                    'position'=>Configuration::get($this->name.'blocklr_prod_pos'),
                    'number_display_reviews' => array('number_display_reviews' => (int)Configuration::get($this->name.'blocklr_prod_ndr'), 'name'=>'blocklr_prod_ndr'),
                    'truncate' => array('truncate' => (int)Configuration::get($this->name.'blocklr_prod_tr'), 'name'=>'blocklr_prod_tr'),
                    'imsize' => array('imsize' => Configuration::get($this->name.'blocklr_prod_im'), 'name'=>'blocklr_prod_im'),
                    'width' => array('width' => (int)Configuration::get($this->name.'blocklr_prod_w'), 'name'=>'blocklr_prod_w')),
                'blocklr_oth' => array('name'=>$this->l('for other pages'),
                    'status' => Configuration::get($this->name.'blocklr_oth'),
                    'position'=>Configuration::get($this->name.'blocklr_oth_pos'),
                    'number_display_reviews' => array('number_display_reviews' => (int)Configuration::get($this->name.'blocklr_oth_ndr'), 'name'=>'blocklr_oth_ndr'),
                    'truncate' => array('truncate' => (int)Configuration::get($this->name.'blocklr_oth_tr'), 'name'=>'blocklr_oth_tr'),
                    'imsize' => array('imsize' => Configuration::get($this->name.'blocklr_oth_im'), 'name'=>'blocklr_oth_im'),
                    'width' => array('width' => (int)Configuration::get($this->name.'blocklr_oth_w'), 'name'=>'blocklr_oth_w')),
                'blocklr_chook' => array('name'=>$this->l('for CUSTOM HOOK pages'),
                    'status' => Configuration::get($this->name.'blocklr_chook'),
                    'position'=>Configuration::get($this->name.'blocklr_chook_pos'),
                    'number_display_reviews' => array('number_display_reviews' => (int)Configuration::get($this->name.'blocklr_chook_ndr'), 'name'=>'blocklr_chook_ndr'),
                    'truncate' => array('truncate' => (int)Configuration::get($this->name.'blocklr_chook_tr'), 'name'=>'blocklr_chook_tr'),
                    'imsize' => array('imsize' => Configuration::get($this->name.'blocklr_chook_im'), 'name'=>'blocklr_chook_im'),
                    'width' => array('width' => (int)Configuration::get($this->name.'blocklr_chook_w'), 'name'=>'blocklr_chook_w')),
            ),
            'available_pos' => array(
                'top'=>$this->l('Top'),
                'bottom'=>$this->l('Bottom'),
                'leftcol'=>$this->l('Left Column'),
                'rightcol'=>$this->l('Right Column'),

            ),
            'available_pos_home' => array(
                'top'=>$this->l('Top'),
                'home'=>$this->l('Home'),
                'bottom'=>$this->l('Bottom'),
                'leftcol'=>$this->l('Left Column'),
                'rightcol'=>$this->l('Right Column'),

            ),
            'available_pos_chook' => array(
                'chook'=>$this->l('Custom Hook'),


            ),
            'image_sizes' => $data_img_sizes,
        );

        return $block_last_reviews;
    }

    private function _lastreviewsblock(){




        $fields_form = array(
            'form'=> array(
                'legend' => array(
                    'title' => $this->l('Last Reviews Block'),
                    'icon' => 'fa fa-list-alt fa-lg'
                ),
                'input' => array(


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Block "Last Reviews"'),
                        'name' => 'is_blocklr',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),



                    $this->block_last_reviews(),




                ),



            ),


        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );




        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'lastreviewsblocksettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesLastreviewsblockpageSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );


        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'_js.phtml');
        $_html = ob_get_clean();



        return  $_html . $helper->generateForm(array($fields_form,$fields_form1)).$this->_customhookhelp();
    }

    public function getConfigFieldsValuesLastreviewsblockpageSettings(){

        $data_config = array(
            'is_blocklr' => (int)Configuration::get($this->name.'is_blocklr'),


        );

        return $data_config;

    }

    private function _customhookhelp(){


        $this->_data_translate_custom['_customhookhelp_faq'] = $this->l('Frequently Asked Questions');
        $this->_data_translate_custom['_customhookhelp_c_h_help'] = $this->l('CUSTOM HOOK HELP:');
        $this->_data_translate_custom['_customhookhelp_cms'] = $this->l('How I can show block last reviews on a single page (CMS or blog for example) ?');
        $this->_data_translate_custom['_customhookhelp_just_place'] = $this->l('You just need to add a line of code to the tpl file of the page where you want to add the block last reviews.');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();

        return $_html;
    }

    private function _customeraccountreviewspage(){
        $fields_form = array(
            'form'=> array(
                'legend' => array(
                    'title' => $this->l('Customer account reviews page'),
                    'icon' => 'fa icon-AdminParentCustomer fa-lg'
                ),
                'input' => array(


                    array(
                        'type' => 'text',
                        'label' => $this->l('Number of reviews per page on Customer account page'),
                        'name' => 'revperpagecus',
                        'class' => ' fixed-width-sm',

                    ),



                ),



            ),


        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );




        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'customeraccountreviewspagesettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesCustomeraccountreviewspageSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );




        return  $helper->generateForm(array($fields_form,$fields_form1));
    }

    public function getConfigFieldsValuesCustomeraccountreviewspageSettings(){

        $data_config = array(
            'revperpagecus' => (int)Configuration::get($this->name.'revperpagecus'),


        );

        return $data_config;

    }

    private function _reviewsmanagement(){


        $fields_form = array(
            'form'=> array(
                'legend' => array(
                    'title' => $this->l('Reviews management'),
                    'icon' => 'fa fa-reviews fa-lg'
                ),
                'input' => array(


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Require Admin Approval'),
                        'name' => 'is_approval',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),




                    array(
                        'type' => 'block_radio_buttons_reviews_custom',
                        'label' => $this->l('Who can add review?'),

                        'name' => 'block_radio_buttons_reviews_custom',
                        'values'=> array(
                            'value' => Configuration::get($this->name.'whocanadd')
                        ),

                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('The user can add more one review'),
                        'name' => 'is_onerev',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('MULTILANGUAGE. Separates different languages comments depended on the language selected by the customer (e.g. only English comments on the English site)'),
                        'name' => 'rswitch_lng',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Sort by on the All Reviews page functional'),
                        'name' => 'is_sortallf',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Sort by for Product Reviews on the User page functional'),
                        'name' => 'is_sortfu',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                    array(
                        'type' => 'text',
                        'label' => $this->l('Number of reviews per page on All Reviews page'),
                        'name' => 'revperpageall',
                        'class' => ' fixed-width-sm',

                    ),






                ),



            ),


        );

        $fields_form1 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );




        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'reviewsmanagementsettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesReviewsmanagementSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );


        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'_js.phtml');
        $_html = ob_get_clean();




        return  $_html.$helper->generateForm(array($fields_form,$fields_form1));
    }

    public function getConfigFieldsValuesReviewsmanagementSettings(){

        $data_config = array(
            'is_approval' => Configuration::get($this->name.'is_approval'),
            'rswitch_lng' => Configuration::get($this->name.'rswitch_lng'),
            'revperpageall' => Configuration::get($this->name.'revperpageall'),


            'is_onerev' => Configuration::get($this->name.'is_onerev'),

            'is_sortallf'=> Configuration::get($this->name.'is_sortallf'),

            'is_sortfu'=> Configuration::get($this->name.'is_sortfu'),

        );

        return $data_config;
    }

    private function _productpage(){
        $fields_form = array(
            'form'=> array(
                'legend' => array(
                    'title' => $this->l('Product page Settings'),
                    'icon' => 'fa icon-AdminCatalog fa-lg'
                ),
                'input' => array(



                    array(
                        'type' => 'select',
                        'label' => $this->l('Product tabs'),
                        'name' => 'ptabs_type',
                        'options' => array(
                            'query' => array(
                                array(
                                    'id' => 1,
                                    'name' => $this->l('Standard theme without Tabs')),

                                array(
                                    'id' => 2,
                                    'name' => $this->l('Custom theme with tabs on product page for Prestashop 1.6'),
                                ),
                                array(
                                    'id' => 3,
                                    'name' => $this->l('Custom theme with tabs on product page for Prestashop 1.7'),
                                ),
                            ),
                            'id' => 'id',
                            'name' => 'name'
                        ),
                        'desc' => $this->l('On a standard PrestaShop 1.6 and PrestaShop 1.7 theme, the product page no longer has tabs for the various sections.').
                                  '&nbsp;'.$this->l('But some custom themes have added back tabs on the product page. ')
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Sort by on the product page functional'),
                        'name' => 'is_sortf',
                        'desc' => $this->l('Enable or Disable Sort by on the product page functional'),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Helpful review functional'),
                        'name' => 'is_helpfulf',
                        'desc' => $this->l('Enable or Disable Helpful review functional'),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Report abuse functional'),
                        'name' => 'is_abusef',
                        'desc' => $this->l('Enable or Disable Report abuse functional'),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),


                    array(
                        'type' => 'select_stars',
                        'label' => $this->l('Style stars'),
                        'name' => 'select_stars',
                        'values' => array(
                           'stylestars'=>Configuration::get($this->name.'stylestars'),
                        ),

                        'desc' => $this->l('Choose your style for the stars icons')
                    ),

                    array(
                        'type' => 'select_stars_custom',
                        'label' => $this->l('Enable or Disable stars for each reviews'),
                        'name' => 'starratingon',
                        'values' => array(
                            'value'=>Configuration::get($this->name.'starratingon'),
                            'stylestars'=>Configuration::get($this->name.'stylestars'),

                        ),

                    ),

                    array(
                        'type' => 'select',
                        'label' => $this->l('Hook to display block with ratings, number of reviews etc'),
                        'name' => 'hooktodisplay',
                        'class' => ' fixed-width-xxl',
                        'options' => array(
                            'query' => array(
                                array(
                                    'id' => 'extra_right',
                                    'name' => $this->l('displayLeftColumnProduct (Extra right)'),

                                ),

                                array(
                                    'id' => 'extra_left',
                                    'name' => $this->l('displayRightColumnProduct (Extra Left)'),
                                ),
                                array(
                                    'id' => 'product_actions',
                                    'name' => $this->l('displayProductButtons (Product actions)'),
                                ),
                                array(
                                    'id' => 'product_footer',
                                    'name' => $this->l('displayFooterProduct (Product footer)'),
                                ),
                                array(
                                    'id' => 'none',
                                    'name' => $this->l('None'),
                                ),
                            ),
                            'id' => 'id',
                            'name' => 'name'
                        ),
                        'desc' => $this->l('Block with ratings, number of reviews, link to post a new review'),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Number of reviews per page on Product page'),
                        'name' => 'revperpage',
                        'class' => ' fixed-width-sm',

                    ),


                ),



            ),


        );

        $fields_form1 = array(
            'form'=> array(
                'legend' => array(
                    'title' => $this->l('Social Buttons'),
                    'icon' => 'fa fa-facebook fa-lg'
                ),
                'input' => array(


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Social buttons'),
                        'name' => 'rsoc_on',
                        'desc' => $this->l('Enable or Disable Social buttons for each Product Review'),

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Display count box'),
                        'name' => 'rsoccount_on',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),





                ),
                'desc' => $this->l('You can configure "Voucher, when a user share review on the Facebook" in the').
                        ' <a href="javascript:void(0)" onclick="tabs_custom(103)" style="text-decoration:underline;font-weight:bold;color:red">'.$this->l('Voucher Settings').'</a> '.
                        $this->l('Tab'),


            ),


        );

        $fields_form2 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );



        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'productpagesettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesProductpageSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );


        $this->_data_translate_custom['_productpage_read'] = $this->l('Read Step 8 "How to configure product tabs for Prestashop 1.7.x.x ?" in the');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/_productpage_js.phtml');
        $_html = ob_get_clean();

        return  $_html . $helper->generateForm(array($fields_form,$fields_form1,$fields_form2));
    }

    public function getConfigFieldsValuesProductpageSettings(){

        $data_config = array(
            'ptabs_type' => Configuration::get($this->name.'ptabs_type'),
            'hooktodisplay' => Configuration::get($this->name.'hooktodisplay'),
            'revperpage' => Configuration::get($this->name.'revperpage'),
            'rsoc_on' => Configuration::get($this->name.'rsoc_on'),
            'rsoccount_on' => Configuration::get($this->name.'rsoccount_on'),
            'is_abusef' => Configuration::get($this->name.'is_abusef'),
            'is_helpfulf' => Configuration::get($this->name.'is_helpfulf'),
            'is_sortf' => Configuration::get($this->name.'is_sortf'),


        );

        return $data_config;
    }

    private function _global(){
        $fields_form = array(
            'form'=> array(
                'legend' => array(
                    'title' => $this->l('Global Settings'),
                    'icon' => 'fa fa-cogs fa-lg'
                ),
                'input' => array(



                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Product Reviews and Ratings'),
                        'name' => 'rvis_on',
                        'desc' => $this->l('Enable or Disable Product Reviews and Ratings'),
                        'hint' => $this->l('Enable or Disable Product Reviews and Ratings'),

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable "Rating/Review Criteria" field(s)'),
                        'name' => 'ratings_on',
                        'desc' => $this->l('You also can add').' <a href="javascript:void(0)" onclick="tabs_custom(102)">'.$this->l('Review Criteria').'</a><br/>'.
                        $this->l('If you delete/disable all Review criteria will be displayed only Rating field in Write Your Review form'),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable "Avatar" field'),
                        'name' => 'is_avatar'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable "Files" field'),
                        'name' => 'is_files'.$this->_prefix_review,

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Number of files user can add for review'),
                        'name' => 'ruploadfiles',
                        'class' => ' fixed-width-sm',


                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable "Title" field'),
                        'name' => 'title_on',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable "Text" field'),
                        'name' => 'text_on',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'text',
                        'label' => $this->l('Minimum chars the user must write in the Text field for add review'),
                        'name' => 'rminc',
                        'class' => ' fixed-width-sm',


                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable "IP" or "City and Country Name" field'),
                        'name' => 'ip_on',
                        'desc' => ((version_compare(_PS_VERSION_, '1.7', '>'))?$this->l('City and Country Name will be displayed, if your enable Geolocation in admin panel -> IMPROVE -> International -> Localization -> Geolocation'):$this->l('City and Country Name will be displayed, if your enable Geolocation in admin  panel -> Preferences -> Geolocation')),
                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Captcha'),
                        'name' => 'is_captcha',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),




                ),



            ),


        );


        $fields_form1 = array(
            'form'=> array(

                'legend' => array(
                    'title' => $this->l('Filter by Ratings settings'),
                    'icon' => 'fa fa-filter fa-lg'
                ),
                'input' => array(


                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Filter by Ratings on the Product page'),
                        'name' => 'is_filterp',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),

                    array(
                        'type' => 'switch',
                        'label' => $this->l('Enable or Disable Filter by Ratings on the All reviews page'),
                        'name' => 'is_filterall',

                        'values' => array(
                            array(
                                'id' => 'active_on',
                                'value' => 1,
                                'label' => $this->l('Yes')
                            ),
                            array(
                                'id' => 'active_off',
                                'value' => 0,
                                'label' => $this->l('No')
                            )
                        ),
                    ),



                ),



            ),


        );

        $fields_form2 = array(
            'form' => array(


                'submit' => array(
                    'title' => $this->l('Update Settings'),
                )
            ),
        );



        $helper = new HelperForm();



        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'globalsettings';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValuesGlobalSettings(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );


        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'_js.phtml');
        $_html = ob_get_clean();


        return $_html . $helper->generateForm(array($fields_form,$fields_form1,$fields_form2));
    }

    public function getConfigFieldsValuesGlobalSettings(){

        $data_config = array(
            'rvis_on' => Configuration::get($this->name.'rvis_on'),
            'is_avatar'.$this->_prefix_review => Configuration::get($this->name.'is_avatar'.$this->_prefix_review),
            'is_files'.$this->_prefix_review => Configuration::get($this->name.'is_files'.$this->_prefix_review),
            'title_on' => Configuration::get($this->name.'title_on'),
            'text_on' => Configuration::get($this->name.'text_on'),
            'ip_on' => Configuration::get($this->name.'ip_on'),
            'is_captcha' => Configuration::get($this->name.'is_captcha'),
            'ratings_on' => Configuration::get($this->name.'ratings_on'),

            'ruploadfiles'=> (int)Configuration::get($this->name.'ruploadfiles'),
            'rminc'=> (int)Configuration::get($this->name.'rminc'),

            'is_filterp'=> (int)Configuration::get($this->name.'is_filterp'),
            'is_filterall'=> (int)Configuration::get($this->name.'is_filterall'),

        );

        return $data_config;
    }








    private function _cronhelp($data = null){
        $url_cron = isset($data['url'])?$data['url']:'';


        include_once(_PS_MODULE_DIR_ . $this->name.'/classes/reviewsadvhelp.class.php');
        $obj_shopreviews = new reviewsadvhelp();
        $data_seo_url = $obj_shopreviews->getSEOURLs();

        $delimeter_rewrite = "&";
        if(Configuration::get('PS_REWRITING_SETTINGS')){
            $delimeter_rewrite = "?";
        }



            $text_type_review = $this->l('PRODUCT');

            if($url_cron == "cronreviews") {
                $url_cron = $data_seo_url['cron_reviews_url'];
            } else {
                $url_cron = $data_seo_url['cron_url'];
            }



        $this->_data_translate_custom['_cronhelp_cron_help'] = $this->l('CRON HELP');
        $this->_data_translate_custom['_cronhelp_reviews'] = $this->l('REVIEWS');
        $this->_data_translate_custom['_cronhelp_you_can_conf'] = $this->l('You can configure sending email messages through cron. You have 2 possibilities:');
        $this->_data_translate_custom['_cronhelp_you_can_enter'] = $this->l('You can enter the following url in your browser: ');
        $this->_data_translate_custom['_cronhelp_you_can_set'] = $this->l('You can set a cron\'s task (a recursive task that fulfills the sending of reminders)');
        $this->_data_translate_custom['_cronhelp_the_task_run'] = $this->l('The task run every hour');
        $this->_data_translate_custom['_cronhelp_how_to_conf'] = $this->l('How to configure a cron task ?');
        $this->_data_translate_custom['_cronhelp_on_your_serv'] = $this->l('On your server, the interface allows you to configure cron\'s tasks');
        $this->_data_translate_custom['_cronhelp_about_cron'] = $this->l('About CRON');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();

        return $_html;


    }
    
    private function _productComments(){
    	include_once(_PS_MODULE_DIR_.$this->name.'/classes/importhelp.class.php');
		$obj = new importhelp();

		$data_comments = $obj->getCountComments();
		
		$is_count_comments = $data_comments['is_count_comments'];
		$count_comments = $data_comments['comments'];


        $this->_data_translate_custom['_productComments_imp_pr_com'] = $this->l('Import Product Comments');
        $this->_data_translate_custom['_productComments_if_you_already'] = $this->l('If you are already using PrestaShop "Product comments" module, you can import all your existing ratings and comments so as not to lose any of your history. ');
        $this->_data_translate_custom['_productComments_you_have'] = $this->l('You have');
        $this->_data_translate_custom['_productComments_com'] = $this->l('comments');
        $this->_data_translate_custom['_productComments_imp_pr_com1'] = $this->l('Import Product comments');
        $this->_data_translate_custom['_productComments_no_com'] = $this->l('Your database no contains Product comments for imports');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();

        return $_html;
		

	    	
    }



  private function _help_documentation(){

      $this->_data_translate_custom['_help_documentation_h_d'] = $this->l('Help / Documentation');
      $this->_data_translate_custom['_help_documentation_mod_doc'] = $this->l('MODULE DOCUMENTATION ');
      $this->_data_translate_custom['_help_documentation_h_to_conf'] = $this->l('Hot to configure CRON FOR PRODUCT REVIEWS ');
      $this->_data_translate_custom['_help_documentation_cron_help_pr'] = $this->l('CRON HELP PRODUCT REVIEWS');

      ob_start();
      include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
      $_html = ob_get_clean();


      $_html .= $this->_faq16();

        return $_html;
    }

    private function _faq16(){

        $this->_data_translate_custom['_faq16_faq'] = $this->l('Frequently Asked Questions');
        $this->_data_translate_custom['_faq16_500'] = $this->l('I get 500 Internal Error, when try get Images (Avatar does not load and File upload does not work)');
        $this->_data_translate_custom['_faq16_int_500'] = $this->l('Internal 500 error - this error related with setting of your server.');
        $this->_data_translate_custom['_faq16_pr'] = $this->l('- The problem may be in the access rights to the folder /modules/'.$this->name.'/ Must be 0777 or 0755');
        $this->_data_translate_custom['_faq16_1'] = $this->l('- The problem may be in the .htaccess file in the folder /modules/ . Try delete/rename file .htaccess');
        $this->_data_translate_custom['_faq16_2'] = $this->l('- The problem may be in the index.php file in the folder /modules/ . Try delete/rename file index.php');

        ob_start();
        include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
        $_html = ob_get_clean();

        return $_html;



    }

    private function _faqStars17_reviewsadv(){
        $_html = '';
        if(version_compare(_PS_VERSION_, '1.7', '>')) {

            $this->_data_translate_custom['_faqStars17_reviewsadv_how'] = $this->l('How can I add Stars in Category and Search pages?');
            $this->_data_translate_custom['_faqStars17_reviewsadv_you_just'] = $this->l('You just need to add a line of code in the tpl file /themes/{YOUR_CURRENT_THEME}/templates/catalog/_partials/miniatures/product.tpl.');

            ob_start();
            include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
            $_html = ob_get_clean();




        }
        return $_html;
    }
    
 private function _welcome(){

     $this->_data_translate_custom['_welcome_w'] = $this->l('Welcome');
     $this->_data_translate_custom['_welcome_w_and_thank_y'] = $this->l('Welcome and thank you for purchasing the module.');
     $this->_data_translate_custom['_welcome_to_conf'] = $this->l('To configure module please read');
     $this->_data_translate_custom['_welcome_h_doc'] = $this->l('Help / Documentation');


     ob_start();
     include(dirname(__FILE__).'/views/templates/hooks/'.__FUNCTION__.'.phtml');
     $data = ob_get_clean();



     	return  $data;
 	
    }

    public function renderUserAccount(){
        return $this->display(__FILE__.'/reviewsadv.php', 'views/templates/front/useraccount.tpl');
    }

    public function renderUser(){
        return $this->display(__FILE__.'/reviewsadv.php', 'views/templates/front/user.tpl');
    }


    public function renderUsers(){
        return $this->display(__FILE__.'/reviewsadv.php', 'views/templates/front/users.tpl');
    }

    public function renderListUsers(){
        return $this->display(__FILE__.'/reviewsadv.php', 'views/templates/front/list_users.tpl');
    }



    public function renderListMyReviews(){
        return $this->display(__FILE__.'/reviewsadv.php', 'views/templates/front/list_myreviews.tpl');
    }

    public function renderListAllReviews(){
        return $this->display(__FILE__.'/reviewsadv.php', 'views/templates/front/list_allreviews.tpl');
    }

    public function renderListReviews(){
        return $this->display(__FILE__.'/reviewsadv.php', 'views/templates/front/list_reviews.tpl');
    }

	public function renderMyReviews(){
		return $this->display(__FILE__.'/reviewsadv.php', 'views/templates/front/my-reviews.tpl');
	}
	

    public function renderReviewAbuseForm(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/hooks/review-abuse-form.tpl');
    }

    public function renderReviewAbuseAdmin(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/hooks/review-abuse-admin.tpl');
    }

    public function renderReviewChangedAdmin(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/hooks/review-changed-admin.tpl');
    }

    public function renderReviewChangedMy(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/hooks/review-changed-my.tpl');
    }

    public function renderReviewError(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/hooks/error.tpl');
    }

    public function renderReviewFacebookSuccess(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/hooks/success.tpl');
    }

    public function renderReviewCoupon(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/hooks/coupon.tpl');
    }

    public function renderReviewFacebookSuggestion(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/hooks/coupon-suggestion.tpl');
    }

    public function renderError(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/hooks/error.tpl');
    }

    public function renderSuccess(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/hooks/success.tpl');
    }

    public function renderTplItems(){
        return Module::display(_PS_MODULE_DIR_.$this->name.'/reviewsadv.php', 'views/templates/front/storereviews.tpl');
    }





	public function translateCustom(){
		$cookie = $this->context->cookie;


		
			// set discount
    		switch (Configuration::get($this->name.'discount_type'))
			{
				case 1:
					// percent
					$id_discount_type = 1;
					$value = Configuration::get($this->name.'percentage_val');
					break;
				case 2:
					// currency
					$id_discount_type = 2;
					$id_currency = (int)$cookie->id_currency;
					$value = Configuration::get('sdamount_'.(int)$id_currency);
				break;
				default:
					$id_discount_type = 2;
					$id_currency = (int)$cookie->id_currency;
					$value = Configuration::get('sdamount_'.(int)$id_currency);
			}
			$valuta = "%";
            $tax = '';



            if($id_discount_type == 2){
				$cur = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);
			    foreach ($cur AS $_cur){
		    	if($id_currency == $_cur['id_currency']){
		    			$valuta = $_cur['sign'];
		    		}
		    	}
                $tax = (int)Configuration::get($this->name.'tax');
			}

            /* social share coupon */
            // set discount
            switch (Configuration::get($this->name.'discount_typefb'))
            {
                case 1:
                    // percent
                    $id_discount_type = 1;
                    $valuefb = Configuration::get($this->name.'percentage_valfb');
                    break;
                case 2:
                    // currency
                    $id_discount_type = 2;
                    $id_currency = (int)$cookie->id_currency;
                    $valuefb = Configuration::get('sdamountfb_'.(int)$id_currency);
                    break;
                default:
                    $id_discount_type = 2;
                    $id_currency = (int)$cookie->id_currency;
                    $valuefb = Configuration::get('sdamountfb_'.(int)$id_currency);
            }
            $valutafb = "%";
            $taxfb = '';

            if($id_discount_type == 2){
                $cur = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);
                foreach ($cur AS $_cur){
                    if($id_currency == $_cur['id_currency']){
                        $valutafb = $_cur['sign'];
                    }
                }
                $taxfb = (int)Configuration::get($this->name.'taxfb');
            }
            /* social share coupon */
			
		return array('page'=>$this->l('Page'),'reviews'=>$this->l('reviews'),'review'=>$this->l('review'),
					 'firsttext' => $this->l('You get voucher for discount'),
					 'secondtext' => $this->l('Here is you voucher code'),
					 'threetext' => $this->l('It is valid until'),

					 'discountvalue' => $value.$valuta,
                     'discountvaluefb' => $valuefb.$valutafb,

                     'valutafb'=>$valutafb,
                     'valuta' => $valuta,

                     'tax'=>$tax,
                     'taxfb'=>$taxfb,

					 'category' => $this->l('Category'),
					 'product'=> $this->l('Product'),
			         'rate_post'=>$this->l('Rate / post a review for this product on'),
					 'sent_cron_items'=>$this->l('Number of cron items sent'),
					 'delete_cron_items'=>$this->l('Number of cron items deleted'),
					 'no_sent_items'=>$this->l('No tasks sent'),
					 'review_reminder'=>$this->l('Please Enable Review reminder email to customers in admin panel'),


		  		     'review_text_voucher' => $this->l('submit a review'),

                     'facebook_text_voucher' => $this->l('share review on Facebook'),

                     'tax_included' => $this->l('Tax Included'),
                     'tax_excluded' => $this->l('Tax Excluded'),
                     'valid_day' => $this->l('day'),
                     'valid_days' => $this->l('days'),



					 'title'=>$this->l('Title'),
                     'review'=>$this->l('Review'),
                     'reg_customer'=>$this->l('Registered customer'),
                     'no_reg_customer'=>$this->l('Not registered customer'),


                     'helpfull_exists'=>$this->l('You have already voted.'),
                     'helpfull_success' => $this->l('Thank you for your feedback.'),

                     'coupon_success' => $this->l('Thank you for sharing this review on Facebook'),

                     'coupon_suggestion_title' => $this->l('Share your review on Facebook'),
                     'coupon_suggestion_msg' => $this->l('To share your review, simply use the Like button below your review on the product page'),
                     'already_get_coupon' => $this->l('You have already received a coupon with discount'),
                     'expiried_voucher' => $this->l('The validity of your coupon for discount has expired'),
                     'used_voucher' => $this->l('This voucher has already been used'),

                     'all_reviews_meta_title' => $this->l('All Reviews'),
                     'all_reviews_meta_description' => $this->l('All Reviews'),
                     'all_reviews_meta_keywords' => $this->l('All Reviews'),

                     'my_reviews_meta_title' => $this->l('My account - Product Reviews'),
                     'my_reviews_meta_description' => $this->l('My account - Product Reviews'),
                     'my_reviews_meta_keywords' => $this->l('My account - Product Reviews'),

                     'pending_review' => $this->l('The customer has rated the product but has not posted a review, or the review is pending moderation'),

                    'error_login' => $this->l('You must be a registered customer!'),

                    'orders_date_empty' => $this->l('The date is still empty, you should select a date first'),
                    'orders_date_start_more_end' => $this->l('Start date more than end date'),
                    'orders_date_not_exists' => $this->l('There are no orders to import'),
                    'orders_date_ok1' => $this->l('You have successfully imported your'),
                    'orders_date_ok2' => $this->l('old orders'),

                    'google_reviews_title'=>$this->l('Reviews Aggregator'),

                    'myr_msg1'=>$this->l('now active'),
                    'myr_msg2'=>$this->l('now inactive'),
                    'myr_msg3'=>$this->l('Settings updated'),
                    'myr_msg4'=>$this->l("e-mail reminders are"),

                    'ptc_msg1'=>$this->l('Please, enter the security code'),
                    'ptc_msg2'=>$this->l('Please, enter the text'),
                    'ptc_msg3'=>$this->l('Please, enter the name'),
                    'ptc_msg4'=>$this->l('Please, enter the email'),
                    'ptc_msg5'=>$this->l('Please, enter the title'),
                    'ptc_msg6'=>$this->l('Please, choose the rating for'),
                    'ptc_msg7'=>$this->l('Please, choose the rating'),
                    'ptc_msg8'=>$this->l('You entered the wrong security code'),
                    'ptc_msg9'=>$this->l('Please enter a valid email address. For example johndoe@domain.com.'),
                    'ptc_msg10'=>$this->l('You have already add review for this product'),
                    'ptc_msg11'=>$this->l('chars'),
                    'ptc_msg12'=>$this->l('Min'),

                    'ptc_msg13_1'=>$this->l('You can upload a maximum of'),
                    'ptc_msg13_2'=>$this->l('files'),

                    'ava_msg8'=>$this->l('Invalid file type, please try again!'),
                    'ava_msg9'=>$this->l('Wrong file format, please try again!'),

                    'raad_msg1'=>$this->l('Review is NOT Abusive.'),

                    'raf_msg5'=>$this->l('Your report has been taken into account and the merchant has been warned by e-mail.'),
                    'raf_msg8'=>$this->l('You cannot send report for this review because somebody has already posted a report.'),

                    'rca_msg1'=>$this->l('Please, enter your suggestion text'),
                    'rca_msg2'=>$this->l('The changed customer review is pending modification.'),

                    'rcmy_msg5'=>$this->l('Review already changed.'),


                    //for reminder

                    'review_reminder'=>$this->l('Please Enable Customer Reminder in admin panel'),
                    'review_reminder_second'=>$this->l('Please Enable review reminder email to customers a second time in admin panel'),
                    'review_reminder_customer_txt'=>$this->l('Customer already write review in shop'),
                    'review_reminder_customer'=>$this->l('Please Enable Send a review reminder by email to customer when customer already write review in shop in admin panel'),
                    'category' => $this->l('Category'),
                    'product'=> $this->l('Product'),
                    'rate_post'=>$this->l('Rate / post a review for this product on'),
                    'sent_cron_items'=>$this->l('Number of items sent'),
                    'delete_cron_items'=>$this->l('Number of items deleted'),
                    'no_sent_items'=>$this->l('No tasks sent'),
                    'sent_request'=>$this->l('The reviews requests emails have been sent for following orders'),
                    'subject_success_sent_email'=>$this->l('The emails requests on the reviews was successfully sent'),
                    'accepted_order_statuses' => $this->l('Accepted order statuses'),
                    'configure_order_statuses'=>$this->l('Configure order statuses here'),
                    'customer_reminder_settings'=>$this->l('Customer Reminder settings'),
                    'customer_reminder_error1_1'=>$this->l('Have passed less'),
                    'customer_reminder_error1_2'=>$this->l('days from Adding date'),
                    'customer_reminder_error2_2'=>$this->l('days after the first sending'),
                    'configure_reminder_delay_first'=>$this->l('Configure Delay for sending reminder by email here'),
                    'configure_reminder_delay_second'=>$this->l('Configure Days after the first emails were sent here'),

                    //for reminder


                    // for CSV

                    'A_name'=>$this->l('Language ID'),
                    'A_example'=>'<b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('1'),
                    'B_name'=>$this->l('Rating'),
                    'B_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(1/5).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('5'),
                    'C_name'=>$this->l('Product ID'),
                    'C_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(1,2,3, .. etc).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('1'),
                    'D_name'=>$this->l('Customer ID'),
                    'D_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(0 - Guest; 1,2,3, .. etc - Customer).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('1'),
                    'E_name'=>$this->l('Customer full name'),
                    'E_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(need fill, required, if Customer ID = 0).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('John Doe'),
                    'F_name'=>$this->l('Customer email'),
                    'F_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(need fill, required, if Customer ID = 0).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('john@doe.com'),
                    'G_name'=>$this->l('Title'),
                    'G_example'=>'<b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('Title review'),
                    'H_name'=>$this->l('Message'),
                    'H_example'=>'<b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('Test message'),
                    'I_name'=>$this->l('Admin Response'),
                    'I_example'=>'<b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('Test response by admin'),
                    'J_name'=>$this->l('Display "Admin response" on the site'),
                    'J_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(0 or 1).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('1'),
                    'K_name'=>$this->l('Date Add'),
                    'K_example'=> '<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(dd/mm/yyyy).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.date("d/m/Y"),
                    'L_name'=>$this->l('Status'),
                    'L_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(0 or 1).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('1'),

                    // for CSV

                    // user
                    'meta_title_shoppers'=>$this->l('All Users'),
                    'meta_description_shoppers'=>$this->l('All Users'),
                    'meta_keywords_shoppers'=>$this->l('All Users'),
                    'profile'=>$this->l('profile'),
                    'meta_title_myaccount'=>$this->l('My account - User Profile'),
                    'meta_description_myaccount'=>$this->l('My account - User Profile'),
                    'meta_keywords_myaccount'=>$this->l('My account - User Profile'),

                    'male'=>$this->l('Male'),
                    'female'=>$this->l('Female'),
                    // user

        );
	}


    public function translateItems(){



        return array(

            'page'=>$this->l('Page'),
            'subject'=>$this->l('New Store review from Your Customer'),
            'subject_response'=>$this->l('Response on the Store review'),
            'company'=>$this->l('Company'),
            'address'=>$this->l('Address'),
            'country'=>$this->l('Country'),
            'city'=>$this->l('City'),
            'web'=>$this->l('Web address'),
            'message'=>$this->l('Message'),

            'subject_thank_you'=>$this->l('Thank you for your review'),

            //for reminder

            'review_reminder'=>$this->l('Please Enable Review reminder email to customers in admin panel'),
            'review_reminder_second'=>$this->l('Please Enable review reminder email to customers a second time in admin panel'),
            'review_reminder_customer_txt'=>$this->l('Customer already write review in shop'),
            'review_reminder_customer'=>$this->l('Please Enable Send a review reminder by email to customer when customer already write review in shop in admin panel'),
            'category' => $this->l('Category'),
            'product'=> $this->l('Product'),
            'rate_post'=>$this->l('Rate / post a review for this product on'),
            'sent_cron_items'=>$this->l('Number of items sent'),
            'delete_cron_items'=>$this->l('Number of items deleted'),
            'no_sent_items'=>$this->l('No tasks sent'),
            'sent_request'=>$this->l('The reviews requests emails have been sent for following orders'),
            'subject_success_sent_email'=>$this->l('The emails requests on the reviews was successfully sent'),
            'accepted_order_statuses' => $this->l('Accepted order statuses'),
            'configure_order_statuses'=>$this->l('Configure order statuses here'),
            'customer_reminder_settings'=>$this->l('Customer Reminder settings'),
            'customer_reminder_error1_1'=>$this->l('Have passed less'),
            'customer_reminder_error1_2'=>$this->l('days from Adding date'),
            'customer_reminder_error2_2'=>$this->l('days after the first sending'),
            'configure_reminder_delay_first'=>$this->l('Configure Delay for sending reminder by email here'),
            'configure_reminder_delay_second'=>$this->l('Configure Days after the first emails were sent here'),

            //for reminder

            'orders_date_empty' => $this->l('The date is still empty, you should select a date first'),
            'orders_date_start_more_end' => $this->l('Start date more than end date'),
            'orders_date_not_exists' => $this->l('There are no orders to import'),
            'orders_date_ok1' => $this->l('You have successfully imported your'),
            'orders_date_ok2' => $this->l('old orders'),



            'msg1'=>$this->l('Please, choose the rating.'),
            'msg1_2'=>$this->l('Please, choose the rating for'),
            'msg2'=>$this->l('Please, enter the Name.'),
            'msg3'=>$this->l('Please, enter the Email.'),
            'msg4'=>$this->l('Please, enter the Message.'),
            'msg5'=>$this->l('Please, enter the security code.'),
            'msg6'=>$this->l('Please enter a valid email address. For example johndoe@domain.com.'),
            'msg7'=>$this->l('You entered the wrong security code.'),
            'msg8'=>$this->l('Invalid file type, please try again!'),
            'msg9'=>$this->l('Wrong file format, please try again!'),

            // for CSV

            'A_name'=>$this->l('Language ID'),
            'A_example'=>'<b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('1'),
            'B_name'=>$this->l('Rating'),
            'B_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(1/5).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('5'),
            'C_name'=>$this->l('Customer ID'),
            'C_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(0 - Guest; 1,2,3, .. etc - Customer).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('1'),
            'D_name'=>$this->l('Customer full name'),
            'D_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(need fill, required, if Customer ID = 0).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('John Doe'),
            'E_name'=>$this->l('Customer email'),
            'E_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(need fill, required, if Customer ID = 0).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('john@doe.com'),
            'F_name'=>$this->l('Message'),
            'F_example'=>'<b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('Test message'),
            'G_name'=>$this->l('Admin Response'),
            'G_example'=>'<b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('Test response by admin'),
            'H_name'=>$this->l('Display "Admin response" on the site'),
            'H_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(0 or 1).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('1'),
            'I_name'=>$this->l('Date Add'),
            'I_example'=> '<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(dd/mm/yyyy).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.date("d/m/Y"),
            'J_name'=>$this->l('Status'),
            'J_example'=>'<b>'.$this->l('Format').'</b>:&nbsp;'.$this->l('(0 or 1).').'<br/><br/><b>'.$this->l('Example').'</b>:&nbsp;'.$this->l('1'),

            // for CSV


        );

    }
	
	
	public function hookNewOrder($params)
	{
		return (
			$this->hookOrderConfirmation($params)
		);
	}
	
	public function hookActionValidateOrder($params)
	{
		return (
			$this->hookOrderConfirmation($params)
		);
	}


    public function hookOrderConfirmation($params){

        $this->collectOrdersForProductReviews($params);




        return $this->display(dirname(__FILE__).'/reviewsadv.php', 'views/templates/hooks/orderconfirmation.tpl');
    }


    private function collectOrdersForProductReviews($params){
        $cookie = $this->context->cookie;


        if(version_compare(_PS_VERSION_, '1.7', '>')){
            $params_obj_order = isset($params['order'])?$params['order']:null;
        } else {
            $params_obj_order = isset($params['objOrder'])?$params['objOrder']:null;
        }


        if (!empty($params_obj_order) && is_object($params_obj_order))
        {
            include_once(_PS_MODULE_DIR_.$this->name.'/classes/featureshelp.class.php');
            $obj = new featureshelp();

            $guest = false;

            // check if customer is guest
            if (version_compare(_PS_VERSION_, '1.4', '>')) {
                $customer = new Customer($params_obj_order->id_customer);

                if (Validate::isLoadedObject($customer)) {
                    $guest = $customer->isGuest();
                }
                unset($customer);
            }



            if (false === $obj->isDataExist(
                    array('id_shop'=>$this->_id_shop,
                        'order_id'=>$params_obj_order->id
                    )
                )
                &&
                empty($guest)
            ) {


                if (Configuration::get($this->name.'reminder') && isset($params_obj_order->id_customer) &&
                    is_numeric($params_obj_order->id_customer)
                ) {

                    $status  = $obj->getStatus(
                        array('id_shop'=>$this->_id_shop,
                            'customer_id'=> $params_obj_order->id_customer
                        )
                    );

                    if (false === $status) {
                        $obj->addStatus(
                            array('id_shop'=>$this->_id_shop,
                                'customer_id'=> $params_obj_order->id_customer,
                                'status'=>1
                            )
                        );

                        $add_status = 1;
                    } else {
                        $add_status  = $status;
                    }

                    if (!empty($add_status)) {
                        $id_lang = $cookie->id_lang;
                        $products = $obj->getProductsInOrder(
                            array('order_id'=>$params_obj_order->id,
                                'id_lang' => $id_lang
                            )
                        );
                        //echo "<pre>"; var_dump($products);exit;

                        if (!empty($products)) {
                            $data = array();
                            foreach ($products as $product) {

                                $product['rate'] = 0;
                                $attributes = Product::getProductProperties($id_lang, $product);
                                $data[] = array('title' => $attributes['name'],
                                    'category' => $attributes['category'],
                                    'link' => $attributes['link'],
                                    'id_lang' => $id_lang,
                                    'id_product' =>$attributes['id_product'],
                                );

                                unset($attributes);
                            }

                            //echo "<pre>"; var_dump($data);exit;
                            $obj->saveOrder(
                                array('id_shop'=>$this->_id_shop,
                                    'order_id' => $params_obj_order->id,
                                    'customer_id' => $params_obj_order->id_customer,
                                    'data' => $data
                                )
                            );

                            unset($data);
                        }
                    }
                }
            }
        }
    }
	
	
	public function hookLeftColumn($params)
	{

        $name_template = "left.tpl";
        $cache_id = $this->name.$name_template;

        if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {

            $smarty = $this->context->smarty;
            $this->setLastReviewsBlockSettings(array('custom_page_name'=>'leftcol'));


			## user profile ##
            if(Configuration::get($this->name . $this->_prefix_review . 'adv_left') == 1) {
                $this->setuserprofilegSettings();
            }
            $smarty->assign($this->name . $this->_prefix_review . 'adv_left', Configuration::get($this->name . $this->_prefix_review . 'adv_left'));
            ## user profile ##


        }
        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));
				
	}
	
	public function hookRightColumn($params)
	{
        $name_template = "right.tpl";
        $cache_id = $this->name.$name_template;

        if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {

            $smarty = $this->context->smarty;
            $this->setLastReviewsBlockSettings(array('custom_page_name'=>'rightcol'));



            ## user profile ##
            if(Configuration::get($this->name . $this->_prefix_review . 'adv_right') == 1) {
                $this->setuserprofilegSettings();
            }
            $smarty->assign($this->name . $this->_prefix_review . 'adv_right', Configuration::get($this->name . $this->_prefix_review . 'adv_right'));
            ## user profile ##



        }
        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));
				
	}



    public function hookTop($params)
    {

        $name_template = "top.tpl";


        //$id_product = (int)Tools::getValue('id_product');
        //$cache_id = $this->name.$name_template.$id_product;


        //if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {


            $this->basicSettingsHook();

            $this->setLastReviewsBlockSettings(array('custom_page_name' => 'top'));



        /*}
        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));
        */
        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template);




    }

	
	public function hookhome($params)
	{

        $name_template = "home.tpl";
        $cache_id = $this->name.$name_template;

        if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {
            $smarty = $this->context->smarty;



            include_once(_PS_MODULE_DIR_.$this->name . '/classes/reviewsadvhelp.class.php');
            $obj = new reviewsadvhelp();
            $data = $obj->getHomeLastReviews(array('start' => 0,
                    'step' => Configuration::get($this->name . 'blocklr_home_ndr')
                )
            );

            $smarty->assign(array($this->name . 'reviews_home' => $data['reviews']));

            $smarty->assign($this->name . 'sr_sliderhr', (int)Configuration::get($this->name . 'sr_sliderhr'));
            $smarty->assign($this->name . 'sr_slhr', (int)Configuration::get($this->name . 'sr_slhr'));

            ### block last reviews ###

            $smarty->assign(
                array(
                    $this->name . 'is_blocklr' => Configuration::get($this->name . 'is_blocklr'),
                    $this->name . 'blocklr_home_pos' => Configuration::get($this->name . 'blocklr_home_pos'),
                    $this->name . 'blocklr_home_w' => Configuration::get($this->name . 'blocklr_home_w'),
                    $this->name . 'blocklr_home' => Configuration::get($this->name . 'blocklr_home'),
                    $this->name . 'blocklr_home_tr' => Configuration::get($this->name . 'blocklr_home_tr'),
                )
            );

            ### block last reviews ###

            $this->basicSettingsHook();

            $smarty->assign($this->name . 'rsson', Configuration::get($this->name . 'rsson'));

            $smarty->assign($this->name . 'is_ps15', $this->_is15);

            $cookie = $this->context->cookie;
            $id_lang = (int)$cookie->id_lang;


            $data_seo_url = $obj->getSEOURLs(array('id_lang' => $id_lang));
            $all = $data_seo_url['rev_all'];

            $smarty->assign($this->name . 'allr_url', $all);


            ## user profile ##
            if(Configuration::get($this->name . $this->_prefix_review . 'adv_home') == 1) {
                $this->setuserprofilegSettings();
            }
            $smarty->assign($this->name . $this->_prefix_review . 'adv_home', Configuration::get($this->name . $this->_prefix_review . 'adv_home'));
            ## user profile ##



        }
        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));

	}
	

    public function setLastReviewsBlockSettings($data){

        $custom_page_name = $data['custom_page_name'];

        ## home page ##
        $smarty = $this->context->smarty;

        ## prestashop 1.7 ##
        if(version_compare(_PS_VERSION_, '1.7', '>')){
            $page_name = $smarty->tpl_vars['page']->value['page_name'];
         ## prestashop 1.7 ##
        } else {
            if (defined('_MYSQL_ENGINE_')) {
                $page_name = $smarty->tpl_vars['page_name']->value;
            } else {
                $page_name = $smarty->_tpl_vars['page_name'];
            }
        }
        $is_home = 0;
        if($page_name == 'index'){
            $is_home = 1;
        }
        ## home page ##

        $id_manufacturer = (int)Tools::getValue('id_manufacturer');
        $id_supplier = (int)Tools::getValue('id_supplier');
        $id_category = (int)Tools::getValue('id_category');
        $id_product = (int)Tools::getValue('id_product');


        include_once(_PS_MODULE_DIR_.$this->name . '/classes/reviewsadvhelp.class.php');
        $obj = new reviewsadvhelp();

        $this->basicSettingsHook();

        $smarty->assign($this->name . 'rsson', Configuration::get($this->name . 'rsson'));


        /* home page */
        $is_home_custom_page_name =0;

        if($is_home) {
            $prefix_home = 'home';
            if(Configuration::get($this->name . 'blocklr_'.$prefix_home) == "blocklr_".$prefix_home && Configuration::get($this->name . 'blocklr_'.$prefix_home.'_pos') == $custom_page_name){
                $is_home_custom_page_name =1;
                $data = $obj->getHomeLastReviews(array('start' => 0,
                                                      'step' => Configuration::get($this->name . 'blocklr_'.$prefix_home.'_ndr')
                    )
                );

                $smarty->assign(array($this->name . 'reviews_block' => $data['reviews']));


                ### block last reviews ###
                $smarty->assign(
                    array(
                        $this->name . 'blocklr_w' => Configuration::get($this->name . 'blocklr_'.$prefix_home.'_w'),
                        $this->name . 'blocklr_tr' => Configuration::get($this->name . 'blocklr_'.$prefix_home.'_tr'),
                    )
                );

                ### block last reviews ###
            }


        }
        /* home page */

        /* category page */
        $is_cat_custom_page_name =0;
        if($id_category){
            $prefix_cat = 'cat';
            if(Configuration::get($this->name . 'blocklr_'.$prefix_cat) == "blocklr_".$prefix_cat && Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_pos') == $custom_page_name){
                $is_cat_custom_page_name =1;

                $data = $obj->getBlockLastReviews(array('start' => 0,
                        'step' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_ndr'),
                        'prefix' => $prefix_cat,
                    )
                );

                $smarty->assign(array($this->name . 'reviews_block' => $data['reviews']));


                ### block last reviews ###
                $smarty->assign(
                    array(
                        $this->name . 'blocklr_w' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_w'),
                        $this->name . 'blocklr_tr' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_tr'),
                    )
                );

                ### block last reviews ###
            }
        }
        /* category page */

        /* manufacturer/brand page */
        $is_man_custom_page_name =0;

        if($id_manufacturer || $id_supplier){

            $prefix_cat = 'man';
            if(Configuration::get($this->name . 'blocklr_'.$prefix_cat) == "blocklr_".$prefix_cat
                && Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_pos') == $custom_page_name){
                $is_man_custom_page_name =1;

                $data = $obj->getBlockLastReviews(array('start' => 0,
                        'step' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_ndr'),
                        'prefix' => $prefix_cat,
                    )
                );

                $smarty->assign(array($this->name . 'reviews_block' => $data['reviews']));


                ### block last reviews ###
                $smarty->assign(
                    array(
                        $this->name . 'blocklr_w' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_w'),
                        $this->name . 'blocklr_tr' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_tr'),
                    )
                );

                ### block last reviews ###
            }
        }
        /* manufacturer/brand page */


        /* product page */
        $is_prod_custom_page_name =0;
        if($id_product){
            $prefix_cat = 'prod';
            if(Configuration::get($this->name . 'blocklr_'.$prefix_cat) == "blocklr_".$prefix_cat && Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_pos') == $custom_page_name){
                $is_prod_custom_page_name =1;

                $data = $obj->getBlockLastReviews(array('start' => 0,
                        'step' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_ndr'),
                        'prefix' => $prefix_cat,
                    )
                );

                $smarty->assign(array($this->name . 'reviews_block' => $data['reviews']));


                ### block last reviews ###
                $smarty->assign(
                    array(
                        $this->name . 'blocklr_w' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_w'),
                        $this->name . 'blocklr_tr' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_tr'),
                    )
                );

                ### block last reviews ###
            }
        }
        /* product page */


        /* other page */
        $is_oth_custom_page_name =0;
        if(!$id_product && !$id_manufacturer && !$id_category && !$is_home){
            $prefix_cat = 'oth';
            if(Configuration::get($this->name . 'blocklr_'.$prefix_cat) == "blocklr_".$prefix_cat && Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_pos') == $custom_page_name){
                $is_oth_custom_page_name =1;

                $data = $obj->getBlockLastReviews(array('start' => 0,
                        'step' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_ndr'),
                        'prefix' => $prefix_cat,
                    )
                );

                $smarty->assign(array($this->name . 'reviews_block' => $data['reviews']));


                ### block last reviews ###
                $smarty->assign(
                    array(
                        $this->name . 'blocklr_w' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_w'),
                        $this->name . 'blocklr_tr' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_tr'),
                    )
                );

                ### block last reviews ###
            }
        }
        /* other page */



        $smarty->assign($this->name . 'is_blocklr', Configuration::get($this->name . 'is_blocklr'));
        $smarty->assign($this->name . 'is_home_'.$custom_page_name, $is_home_custom_page_name);
        $smarty->assign($this->name . 'is_cat_'.$custom_page_name, $is_cat_custom_page_name);
        $smarty->assign($this->name . 'is_man_'.$custom_page_name, $is_man_custom_page_name);
        $smarty->assign($this->name . 'is_prod_'.$custom_page_name, $is_prod_custom_page_name);
        $smarty->assign($this->name . 'is_oth_'.$custom_page_name, $is_oth_custom_page_name);


        $cookie = $this->context->cookie;
        $id_lang = (int)$cookie->id_lang;


        $data_seo_url = $obj->getSEOURLs(array('id_lang'=>$id_lang));

        $all = $data_seo_url['rev_all'];
        $rss_url = $data_seo_url['rss_url'];

        $smarty->assign($this->name . 'allr_url', $all);
        $smarty->assign($this->name . 'rss_url', $rss_url);


        $smarty->assign($this->name . 'sr_sliderr', (int)Configuration::get($this->name . 'sr_sliderr'));
        $smarty->assign($this->name . 'sr_slr', (int)Configuration::get($this->name . 'sr_slr'));


    }




    public function hooklastReviewsMitrocops($params)
    {

        $name_template = "lastreviewsmitrocops.tpl";
        $cache_id = $this->name.$name_template;

        if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {

            $smarty = $this->context->smarty;
            include_once(_PS_MODULE_DIR_.$this->name . '/classes/reviewsadvhelp.class.php');
            $obj = new reviewsadvhelp();

            $this->basicSettingsHook();

            $smarty->assign($this->name . 'rsson', Configuration::get($this->name . 'rsson'));

            $prefix_cat = 'chook';
            $data = $obj->getBlockLastReviews(array('start' => 0,
                    'step' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_ndr'),
                    'prefix' => $prefix_cat,
                )
            );

            $smarty->assign(array($this->name . 'reviews_block_chook' => $data['reviews']));


            ### block last reviews ###
            $smarty->assign(
                array(
                    $this->name . 'blocklr_w' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_w'),
                    $this->name . 'blocklr_tr' => Configuration::get($this->name . 'blocklr_'.$prefix_cat.'_tr'),
                    $this->name.'blocklr_'.$prefix_cat.'_pos' => Configuration::get($this->name.'blocklr_'.$prefix_cat.'_pos'),
                    $this->name.'blocklr_'.$prefix_cat.'' => Configuration::get($this->name.'blocklr_'.$prefix_cat.''),
                )
            );

            ### block last reviews ###

            $cookie = $this->context->cookie;
            $id_lang = (int)$cookie->id_lang;



            $data_seo_url = $obj->getSEOURLs(array('id_lang'=>$id_lang));

            $all = $data_seo_url['rev_all'];
            $rss_url = $data_seo_url['rss_url'];

            $smarty->assign($this->name . 'allr_url', $all);
            $smarty->assign($this->name . 'rss_url', $rss_url);





        }
        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));
    }
    

	

	
	private function _getDefaultCategory($id_category)
	{
		$cookie = $this->context->cookie;
		
		$_category = new Category($id_category);
		return $_category->getName((int)($cookie->id_lang));
	}


    public function setStarsImagesSetting(){
        $smarty = $this->context->smarty;

        switch(Configuration::get($this->name.'stylestars')){
            case 'style1':
                $smarty->assign($this->name.'activestar', 'star-active-yellow.png');
                $smarty->assign($this->name.'activestarh', 'star-half-active-yellow.png');
                $smarty->assign($this->name.'noactivestar', 'star-noactive-yellow.png');
                break;
            case 'style2':
                $smarty->assign($this->name.'activestar', 'star-active-green.png');
                $smarty->assign($this->name.'activestarh', 'star-half-active-green.png');
                $smarty->assign($this->name.'noactivestar', 'star-noactive-green.png');
                break;
            case 'style3':
                $smarty->assign($this->name.'activestar', 'star-active-blue.png');
                $smarty->assign($this->name.'activestarh', 'star-half-active-blue.png');
                $smarty->assign($this->name.'noactivestar', 'star-noactive-blue.png');
                break;
            default:
                $smarty->assign($this->name.'activestar', 'star-active-yellow.png');
                $smarty->assign($this->name.'activestarh', 'star-half-active-yellow.png');
                $smarty->assign($this->name.'noactivestar', 'star-noactive-yellow.png');
                break;
        }

    }

    public function basicSettingsHook(){
        $smarty = $this->context->smarty;
        $cookie = $this->context->cookie;
        $id_lang = (int)$cookie->id_lang;

        include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
        $obj = new reviewsadvhelp();

        $hooktodisplay = Configuration::get($this->name.'hooktodisplay');
        $smarty->assign($this->name.'hooktodisplay', $hooktodisplay);

        $this->setStarsImagesSetting();

        $smarty->assign($this->name.'rvis_on', Configuration::get($this->name.'rvis_on'));
        $smarty->assign($this->name.'ratings_on', Configuration::get($this->name.'ratings_on'));

        $smarty->assign($this->name.'svis_on', Configuration::get($this->name.'svis_on'));
        $smarty->assign($this->name.'ip_on', Configuration::get($this->name.'ip_on'));
        $smarty->assign($this->name.'is_captcha', Configuration::get($this->name.'is_captcha'));

        $smarty->assign($this->name.'is_filterp', Configuration::get($this->name.'is_filterp'));
        $smarty->assign($this->name.'is_filterall', Configuration::get($this->name.'is_filterall'));

        $smarty->assign($this->name.'title_on', Configuration::get($this->name.'title_on'));
        $smarty->assign($this->name.'text_on', Configuration::get($this->name.'text_on'));

        $smarty->assign($this->name.'is_abusef',Configuration::get($this->name.'is_abusef'));
        $smarty->assign($this->name.'is_helpfulf',Configuration::get($this->name.'is_helpfulf'));

        $smarty->assign($this->name.'is_sortf',Configuration::get($this->name.'is_sortf'));

        $smarty->assign($this->name.'rsoc_on',Configuration::get($this->name.'rsoc_on'));
        $smarty->assign($this->name.'rsoccount_on',Configuration::get($this->name.'rsoccount_on'));

        $smarty->assign($this->name.'ptabs_type',Configuration::get($this->name.'ptabs_type'));
        $smarty->assign($this->name.'is_rtl',$this->_is_rtl);


        $smarty->assign($this->name.'is_avatar'.$this->_prefix_review, Configuration::get($this->name.'is_avatar'.$this->_prefix_review));
        $smarty->assign($this->name.'is_files'.$this->_prefix_review, Configuration::get($this->name.'is_files'.$this->_prefix_review));

        $smarty->assign($this->name.'ruploadfiles', Configuration::get($this->name.'ruploadfiles'));
        $smarty->assign($this->name.'rminc', Configuration::get($this->name.'rminc'));
        $smarty->assign($this->name.'fpath', $this->path_img_cloud);


        $smarty->assign($this->name.'is_uprof', Configuration::get($this->name.'is_uprof'));


        $data_seo_url = $obj->getSEOURLs(array('id_lang'=>$id_lang));
        $user_url = $data_seo_url['user_url'];
        $useraccount_url = $data_seo_url['useraccount_url'];

        $smarty->assign($this->name.'user_url', $user_url);
        $smarty->assign($this->name.'uacc_url', $useraccount_url);






        ## prestashop 1.7 ##
        if(version_compare(_PS_VERSION_, '1.7', '>')){
            $meta_description = isset($smarty->tpl_vars['page']->value['meta']['description'])?$smarty->tpl_vars['page']->value['meta']['description']:'';
            $smarty->assign('meta_description', $meta_description);
        }

        ## prestashop 1.7 ##

        $smarty->assign($this->name.'is_bug', $this->_is_bug_product_page);



        $smarty->assign($this->name.'min_star_par', $this->_min_star_param);
        $smarty->assign($this->name.'max_star_par', $this->_max_star_param);

        $smarty->assign($this->name.'is_mobile', $this->_is_mobile);




        $is_ajax = 0;
        $ajax = Tools::getValue('ajax');
        $action = Tools::getValue('action');
        $content_only = Tools::getValue('content_only');


        if($action == "quickview" || $ajax || $action == "add-to-cart" || $action == "refresh" || $content_only == 1) {
            //$this->context->controller->addJS($this->_path.'views/js/r_stars.js');
            $is_ajax = 1;
        }

        $smarty->assign($this->name.'ajax_action', $action);
        $smarty->assign($this->name.'ajax', $is_ajax);




        if($is_ajax && version_compare(_PS_VERSION_, '1.7', '>')) {
            $_product_id = Tools::getValue("id_product");
            if($_product_id) {
                $id_lang = (int)($cookie->id_lang);

                $product = new Product($_product_id,false,$id_lang);
                //$product = $this->context->controller->getProduct();
                $sharing_url = addcslashes($this->context->link->getProductLink($product), "'");
            } else {
                $sharing_url = "";
            }


        } else {


            $_product_id = (int)Tools::getValue('id_product');
            $product = new Product($_product_id,false,(int)($id_lang));
            $data_product = $this->_productData(array('product'=>$product));
            $sharing_url = $data_product['product_url'];

            $sharing_url = str_replace("?content_only=1","",$sharing_url);
        }

        $smarty->assign($this->name.'sharing_url', $sharing_url);

    }

    public function settingsHooks()
    {

        //echo "1<br/>";

        $smarty = $this->context->smarty;
        $cookie = $this->context->cookie;

        $this->basicSettingsHook();

        $smarty->assign($this->name.'is16', $this->_is16);


        $smarty->assign($this->name.'starratingon', Configuration::get($this->name.'starratingon'));


        $id_customer = (int)$cookie->id_customer;
        $id_product = (int)Tools::getValue('id_product');

        include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
        $obj = new reviewsadvhelp();

        $avg_rating = $obj->getAvgReview(array('id_product'=>$id_product));

        $smarty->assign($this->name.'avg_rating', $avg_rating['avg_rating']);
        $smarty->assign($this->name.'avg_decimal', $avg_rating['avg_rating_decimal']);



        $count_reviews = $obj->getCountReviews(array('id_product'=>$id_product));
        $smarty->assign($this->name.'count_reviews', $count_reviews);
        $smarty->assign($this->name.'text_reviews', $obj->number_ending($count_reviews, $this->l('reviews'), $this->l('review'), $this->l('reviews')));

        $data_rating = $obj->getCountRatingForItem();
        $smarty->assign($this->name.'one', $data_rating['one']);
        $smarty->assign($this->name.'two', $data_rating['two']);
        $smarty->assign($this->name.'three', $data_rating['three']);
        $smarty->assign($this->name.'four', $data_rating['four']);
        $smarty->assign($this->name.'five', $data_rating['five']);


        $smarty->assign($this->name.'is_onerev', Configuration::get($this->name.'is_onerev'));

        $smarty->assign($this->name.'is_sortallf', Configuration::get($this->name.'is_sortallf'));
        $smarty->assign($this->name.'is_sortfu', Configuration::get($this->name.'is_sortfu'));

        if(Configuration::get($this->name.'is_onerev') != 1) {
            $is_alreadyaddreview = $obj->checkIsUserAlreadyAddReview(array('id_product' => $id_product, 'id_customer' => $id_customer));

        } else {
            $is_alreadyaddreview = 0;
        }
        $smarty->assign(array($this->name.'is_add' => $is_alreadyaddreview));


        if(Configuration::get('PS_REWRITING_SETTINGS')){
            $smarty->assign($this->name.'is_rewrite', 1);
        } else {
            $smarty->assign($this->name.'is_rewrite',0);
        }


        $smarty->assign(
                array(
                    $this->name.'sh_name' => @Configuration::get('PS_SHOP_NAME'),
                     )
                );

        $smarty->assign($this->name.'is_ps15', $this->_is15);


    }



    public function hookExtraRight($params){

        $id_product = (int)Tools::getValue('id_product');
        $name_template = "reviewsblockextraright.tpl";
        $cache_id = $this->name.$name_template.$id_product;

        if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {


            $this->basicSettingsHook();

            $hooktodisplay = Configuration::get($this->name.'hooktodisplay');

            if($hooktodisplay == "extra_right") {
                $this->settingsHooks();
            }




        }
        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));

    }

	public function hookExtraLeft($params){

        $id_product = (int)Tools::getValue('id_product');
        $name_template = "reviewsblockextraleft.tpl";
        $cache_id = $this->name.$name_template.$id_product;

        if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {


            $this->basicSettingsHook();


            $hooktodisplay = Configuration::get($this->name.'hooktodisplay');

            if($hooktodisplay == "extra_left") {
                $this->settingsHooks();
            }



			

        }
        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));
	}
	
	public function hookproductFooter($params){


        $ptabs_type = Configuration::get($this->name . 'ptabs_type');


        if(version_compare(_PS_VERSION_, '1.7', '>') && $ptabs_type != 3) {



            $id_product = (int)Tools::getValue('id_product');
            $name_template = "producttabcontent17.tpl";
            $cache_id = $this->name.$name_template.$id_product;

            if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {

                ## prestashop 1.7 ##
                $this->setHookProductTabContentSettings($params);
                ## prestashop 1.7 ##



            }

            return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));


        } else {


            $id_product = (int)Tools::getValue('id_product');
            $name_template = "reviewsblockproductfooter.tpl";
            $cache_id = $this->name.$name_template.$id_product;

            if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {


                $this->basicSettingsHook();

                //$hooktodisplay = Configuration::get($this->name.'hooktodisplay');

                //if($hooktodisplay == "product_footer") {
                $this->settingsHooks();
                //}




                ## user profile ##
                if(Configuration::get($this->name . $this->_prefix_review . 'adv_footer') == 1) {
                    $this->setuserprofilegSettings();
                }
                ## user profile ##

            }
            return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));


        }
	}

    public function hookdisplayProductButtons($params)
    {
        if(version_compare(_PS_VERSION_, '1.7', '>')) {
            return $this->hookproductActions($params);
        }


    }
	
	public function hookproductActions($params){


        $id_product = (int)Tools::getValue('id_product');
        $name_template = "reviewsblockproductactions.tpl";
        $cache_id = $this->name.$name_template.$id_product;

        if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {



            $this->basicSettingsHook();

            $hooktodisplay = Configuration::get($this->name.'hooktodisplay');

            if($hooktodisplay == "product_actions") {
                $this->settingsHooks();
            }





        }

        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));
	}
    
    public function hookProductTab($params)
    {



        $id_product = (int)Tools::getValue('id_product');
        $name_template = "tab.tpl";
        $cache_id = $this->name.$name_template.$id_product;

        if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {

            $smarty = $this->context->smarty;
            $cookie = $this->context->cookie;
            $smarty->assign($this->name.'is16', $this->_is16);

            $id_customer = (int)$cookie->id_customer;

            $smarty->assign(array($this->name.'id_customer' => $id_customer));

            $id_product = (int)Tools::getValue('id_product');

            include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
            $obj = new reviewsadvhelp();
            $count_reviews = $obj->getCountReviews(array('id_product'=>$id_product));
            $smarty->assign(array($this->name.'count_reviews' => $count_reviews));

            $is_alreadyaddreview = $obj->checkIsUserAlreadyAddReview(array('id_product'=>$id_product,'id_customer'=>$id_customer));
            $smarty->assign(array($this->name.'is_add' => $is_alreadyaddreview));

            $this->basicSettingsHook();




        }
        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));
			
	}

    public function setHookProductTabContentSettings($params){
        $smarty = $this->context->smarty;
        $cookie = $this->context->cookie;



        $id_product = isset($params['id_product'])?(int)$params['id_product']:(int)Tools::getValue('id_product');


        $smarty->assign($this->name.'is16', $this->_is16);
        $smarty->assign($this->name.'is15', $this->_is15);


        $smarty->assign($this->name.'d_eff_rev', Configuration::get($this->name.'d_eff_rev'));
        $smarty->assign($this->name.'ptabs_type',Configuration::get($this->name.'ptabs_type'));


        $this->settingsHooks();

        $this->setSEOUrls();

        if(Configuration::get('PS_REWRITING_SETTINGS')){
            $smarty->assign($this->name.'is_rewrite', 1);
        } else {
            $smarty->assign($this->name.'is_rewrite',0);
        }

        $id_lang = (int)$cookie->id_lang;
        $iso_lang = Language::getIsoById((int)($id_lang));
        $smarty->assign($this->name.'iso_lang', $iso_lang);

        include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
        $obj = new reviewsadvhelp();


        $data_permissions_vouchers = $obj->getGroupPermissionsForVouchers();
        $is_show_voucher = $data_permissions_vouchers['is_show_voucher'];
        $is_show_fb_voucher = $data_permissions_vouchers['is_show_fb_voucher'];


        $params_obj_product = isset($params['product'])?$params['product']:null;
        $id_category_default = 0;

        if ((!empty($params_obj_product) && is_array($params_obj_product) && version_compare(_PS_VERSION_, '1.7', '>')) ||
            (!empty($params_obj_product) && is_object($params_obj_product) && version_compare(_PS_VERSION_, '1.7', '<'))
        )
        {
            $id_category_default = isset($params_obj_product->id_category_default)?$params_obj_product->id_category_default:(isset($params_obj_product['id_category_default'])?$params_obj_product['id_category_default']:0);

        }

        $smarty->assign(array(
            $this->name.'criterions' => $obj->getReviewCriteria(array('id_lang'=>$id_lang,'id_shop'=>$this->_id_shop,
                                                                      'id_category'=>$id_category_default,'id_product'=>$id_product)),
        ));

        $smarty->assign($this->name.'id_category', $id_category_default);

        $data_seo_url = $obj->getSEOURLs(array('id_lang'=>$id_lang));

        $my_account = $data_seo_url['my_account'];
        $rev_url = $data_seo_url['rev_url'];



        $smarty->assign($this->name.'m_acc', $my_account);
        $smarty->assign($this->name.'rev_url', $rev_url);


        $id_customer = (int)$cookie->id_customer;
        $is_logged = isset($cookie->id_customer)?$cookie->id_customer:0;


        $smarty->assign($this->name.'islogged', $is_logged);

        $customer_name = '';
        $customer_email = '';
        $avatar = '';
        if($is_logged) {
            $customer_data = $obj->getInfoAboutCustomer(array('id_customer' => $id_customer));
            $customer_name = $customer_data['customer_name'];
            $customer_email = $customer_data['email'];

            $data_avatar = $obj->getAvatarForCustomer(array('id_customer' => $id_customer));
            $avatar = $data_avatar['avatar'];
        }

        $smarty->assign(array($this->name.'c_avatar' => $avatar));
        $smarty->assign(array($this->name.'c_name' => $customer_name));
        $smarty->assign(array($this->name.'c_email' => $customer_email));





        $is_buy = $obj->checkProductBought(array('id_product'=>$id_product,'id_customer'=>$id_customer));
        $smarty->assign(array($this->name.'is_buy' => $is_buy));

        $smarty->assign($this->name.'is_onerev', Configuration::get($this->name.'is_onerev'));

        if(Configuration::get($this->name.'is_onerev') != 1) {
            $is_alreadyaddreview = $obj->checkIsUserAlreadyAddReview(array('id_product' => $id_product, 'id_customer' => $id_customer));

        } else {
            $is_alreadyaddreview = 0;
        }
        $smarty->assign(array($this->name . 'is_add' => $is_alreadyaddreview));

        $smarty->assign(array($this->name.'id_customer' => $id_customer));
        $smarty->assign(array($this->name.'id_product' => $id_product));

        $smarty->assign($this->name.'whocanadd', Configuration::get($this->name.'whocanadd'));


        $this->basicSettingsHook();

        // voucher //
        $smarty->assign($this->name.'vis_on', Configuration::get($this->name.'vis_on'));

        // set discount
        switch (Configuration::get($this->name.'discount_type'))
        {
            case 1:
                // percent
                $id_discount_type = 1;
                $value = Configuration::get($this->name.'percentage_val');
                $id_currency = (int)$cookie->id_currency;
                break;
            case 2:
                // currency
                $id_discount_type = 2;
                $id_currency = (int)$cookie->id_currency;
                $value = Configuration::get('sdamount_'.(int)$id_currency);
                break;
            default:
                $id_discount_type = 2;
                $id_currency = (int)$cookie->id_currency;
                $value = Configuration::get('sdamount_'.(int)$id_currency);
        }
        $valuta = "%";
        $tax = '';

        if($id_discount_type == 2){

            $cur = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);


            $id_currency = (int)$cookie->id_currency;
            foreach ($cur AS $_cur){
                if(
                    //Configuration::get('PS_CURRENCY_DEFAULT') == $_cur['id_currency']
                    $id_currency == $_cur['id_currency']
                ){
                    $valuta = $_cur['sign'];
                }
            }

            $tax = (int)Configuration::get($this->name.'tax');
        }

        $smarty->assign($this->name.'tax', $tax);
        $smarty->assign($this->name.'discount', $value.' '.$valuta);
        $smarty->assign($this->name.'valuta', $valuta);
        $smarty->assign($this->name.'sdvvalid', Configuration::get($this->name.'sdvvalid'));
        $smarty->assign($this->name.'days', $obj->number_ending(Configuration::get($this->name.'sdvvalid'), $this->l('days'), $this->l('day'), $this->l('days')));


        // minimum checkout //
        $smarty->assign($this->name.'is_show_min', Configuration::get($this->name.'is_show_min'));
        $smarty->assign($this->name.'isminamount', Configuration::get($this->name.'isminamount'));
        $smarty->assign($this->name.'minamount', Configuration::get('sdminamount_'.(int)$id_currency));
        $fvaluta_min = '';

        $cur = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);


        $id_currency = (int)$cookie->id_currency;
        foreach ($cur AS $_cur){
            if(
                //Configuration::get('PS_CURRENCY_DEFAULT') == $_cur['id_currency']
                $id_currency == $_cur['id_currency']
            ){
                $fvaluta_min = $_cur['sign'];
            }
        }

        $smarty->assign($this->name.'curtxt', $fvaluta_min);
        // minimum checkout //




        $smarty->assign($this->name.'is_show_voucher', $is_show_voucher);




        // voucher //

        // voucher facebook //
        $smarty->assign($this->name.'vis_onfb', Configuration::get($this->name.'vis_onfb'));

        // set discount
        switch (Configuration::get($this->name.'discount_typefb'))
        {
            case 1:
                // percent
                $id_discount_type = 1;
                $value = Configuration::get($this->name.'percentage_valfb');
                $id_currency = (int)$cookie->id_currency;
                break;
            case 2:
                // currency
                $id_discount_type = 2;
                $id_currency = (int)$cookie->id_currency;
                $value = Configuration::get('sdamountfb_'.(int)$id_currency);
                break;
            default:
                $id_discount_type = 2;
                $id_currency = (int)$cookie->id_currency;
                $value = Configuration::get('sdamountfb_'.(int)$id_currency);
        }
        $valuta = "%";
        $tax = '';

        if($id_discount_type == 2){

            $cur = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);

            $id_currency = (int)$cookie->id_currency;
            foreach ($cur AS $_cur){
                if(
                    //Configuration::get('PS_CURRENCY_DEFAULT') == $_cur['id_currency']
                    $id_currency == $_cur['id_currency']
                ){
                    $valuta = $_cur['sign'];
                }
            }

            $tax = (int)Configuration::get($this->name.'taxfb');
        }

        $smarty->assign($this->name.'taxfb', $tax);
        $smarty->assign($this->name.'discountfb', $value.' '.$valuta);
        $smarty->assign($this->name.'valutafb', $valuta);
        $smarty->assign($this->name.'sdvvalidfb', Configuration::get($this->name.'sdvvalidfb'));
        $smarty->assign($this->name.'daysfb', $obj->number_ending(Configuration::get($this->name.'sdvvalidfb'), $this->l('days'), $this->l('day'), $this->l('days')));


        // minimum checkout //
        $smarty->assign($this->name.'is_show_minfb', Configuration::get($this->name.'is_show_minfb'));
        $smarty->assign($this->name.'isminamountfb', Configuration::get($this->name.'isminamountfb'));
        $smarty->assign($this->name.'minamountfb', Configuration::get('sdminamountfb_'.(int)$id_currency));
        $fvaluta_min = '';

        $cur = Currency::getCurrenciesByIdShop(Context::getContext()->shop->id);



        $id_currency = (int)$cookie->id_currency;
        foreach ($cur AS $_cur){
            if(
                //Configuration::get('PS_CURRENCY_DEFAULT') == $_cur['id_currency']
                $id_currency == $_cur['id_currency']
            ){
                $fvaluta_min = $_cur['sign'];
            }
        }

        $smarty->assign($this->name.'curtxtfb', $fvaluta_min);
        // minimum checkout //




        $smarty->assign($this->name.'is_show_fb_voucher', $is_show_fb_voucher);




        // voucher facebook //


        ### reviews ###
        $gp = (int)Tools::getValue('gp');
        $step = (int)Configuration::get($this->name.'revperpage');

        $page = isset($params['page'])?$params['page']:null;

        if($page){
            // for ajax request
            $start = $page;
            // for ajax request
        } else {
            $start = (int)(($gp - 1) * $step);
        }
        if($start<0)
            $start = 0;

        $frat = isset($params['frat'])?$params['frat']:Tools::getValue('frat');

        $search = isset($params['search'])?$params['search']:Tools::getValue("search");
        $is_search = 0;

        ### search ###
        if(Tools::strlen($search)>0){
            $is_search = 1;

        }
        $this->context->smarty->assign($this->name.'is_search', $is_search);
        $this->context->smarty->assign($this->name.'search', $search);
        ## search ###

        $is_sort = isset($params['is_sort'])?$params['is_sort']:0;
        $sort_condition = isset($params['sort_condition'])?$params['sort_condition']:'';

        $reviews_data = $obj->getReviews(
                                        array(
                                               'id_product'=>$id_product,'start'=>$start,'frat'=>$frat,'is_search'=>$is_search,'search'=>$search,
                                               'is_sort'=>$is_sort,'sort_condition'=>$sort_condition
                                              )
                                        );
        $data = $reviews_data['reviews'];
        $count_reviews = $reviews_data['count_all_reviews'];


        $_obj_product = new Product($id_product,null,$id_lang);
        $data_product = $this->_productData(array('product'=>$_obj_product));


        $paging = $obj->paging17(
            array('start'=>$start,
                'step'=> $step,
                'count' => $count_reviews,
                'id_product'=>$id_product,
                'frat'=>$frat,'is_search'=>$is_search,'search'=>$search,'is_sort'=>$is_sort,
                'action'=>'productpagereviews'
            )
        );

        $data_translate = $this->translateCustom();


        $smarty->assign(
            array('reviews' => $data,
                'paging' => $paging,
                $this->name.'page_text' => $this->l('Page'),
                $this->name.'gp' => $gp,
                $this->name.'frat' => $frat,
                $this->name.'product_url' => $data_product['product_url'],

                $this->name.'ptc_msg1'=>$data_translate['ptc_msg1'],
                $this->name.'ptc_msg2'=>$data_translate['ptc_msg2'],
                $this->name.'ptc_msg3'=>$data_translate['ptc_msg3'],
                $this->name.'ptc_msg4'=>$data_translate['ptc_msg4'],
                $this->name.'ptc_msg5'=>$data_translate['ptc_msg5'],
                $this->name.'ptc_msg6'=>$data_translate['ptc_msg6'],
                $this->name.'ptc_msg7'=>$data_translate['ptc_msg7'],
                $this->name.'ptc_msg8'=>$data_translate['ptc_msg8'],
                $this->name.'ptc_msg9'=>$data_translate['ptc_msg9'],
                $this->name.'ptc_msg10'=>$data_translate['ptc_msg10'],
                $this->name.'ptc_msg11'=>$data_translate['ptc_msg11'],
                $this->name.'ptc_msg12'=>$data_translate['ptc_msg12'],
                $this->name.'ptc_msg13_1'=>$data_translate['ptc_msg13_1'],
                $this->name.'ptc_msg13_2'=>$data_translate['ptc_msg13_2'],

                $this->name.'ava_msg8'=>$data_translate['ava_msg8'],
                $this->name.'ava_msg9'=>$data_translate['ava_msg9'],

            ));
        ### reviews ###



        $smarty->assign($this->name.'vis_on', Configuration::get($this->name.'vis_on'));

        $smarty->assign($this->name.'is_ps15',$this->_is15);








        return array('paging'=>$paging); // for ajax
    }

    public function hookProductTabContent($params)
    {

        $id_product = (int)Tools::getValue('id_product');

        if(version_compare(_PS_VERSION_, '1.7', '>')) {
            $name_template = "producttabcontent17.tpl";
        } else {
            $name_template = "producttabcontent.tpl";
        }
        $cache_id = $this->name.$name_template.$id_product;

        if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {

            ## prestashop 1.7 ##
            $this->setHookProductTabContentSettings($params);
            ## prestashop 1.7 ##


        }

        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));
    }


    public function hookdisplayProductListReviews($params){


        if(Configuration::get($this->name.'starscat') == 1 && Configuration::get($this->name.'rvis_on') == 1) {


            $id_product = isset($params['product']['id_product'])?(int)$params['product']['id_product']:(int)$params['product']->id;
            $name_template = "liststars.tpl";
            $cache_id = $this->name.$name_template.$id_product;



            if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {
                $smarty = $this->context->smarty;



                include_once(_PS_MODULE_DIR_.$this->name . '/classes/reviewsadvhelp.class.php');
                $obj_reviewshelp = new reviewsadvhelp();
                $count_review = $obj_reviewshelp->getCountReviews(array('id_product' => $id_product));
                $avg_rating = $obj_reviewshelp->getAvgReview(array('id_product' => $id_product));

                $smarty->assign(
                    array(
                        'id_product' => $id_product,
                        'avg_rating' => $avg_rating['avg_rating'],
                        'count_review' => $count_review,
                        $this->name.'min_star_par' => $this->_min_star_param,
                        $this->name.'max_star_par' => $this->_max_star_param,
                        $this->name.'is_starscat' => Configuration::get($this->name.'is_starscat')
                    )
                );

                $this->basicSettingsHook();
            }

            return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));


        }
    }

    
    public function hookHeader($params){





             // for 16
            $this->context->controller->addCSS(($this->_path) . 'views/css/reviewsadv.css', 'all');

            if(version_compare(_PS_VERSION_, '1.7', '>')) {
                $this->context->controller->addCSS(($this->_path) . 'views/css/reviewsadv17.css', 'all');
            }


             if($this->_is_rtl)
                $this->context->controller->addCSS(($this->_path) . 'views/css/reviewsadv-rtl.css', 'all');

    		$this->context->controller->addJS($this->_path.'views/js/r_stars.js');
            $this->context->controller->addJS($this->_path.'views/js/reviewsadv.js');

            $id_product = Tools::getValue('id_product');

            if(Configuration::get($this->name.'is_files'.$this->_prefix_review) && $id_product){
                $this->context->controller->addJqueryUI(array('ui.widget'));
                $this->context->controller->addJS($this->_path.'views/js/jquery.fileupload.js');
                $this->context->controller->addJS($this->_path.'views/js/jquery.fileupload-process.js');
                $this->context->controller->addJS($this->_path.'views/js/jquery.fileupload-validate.js');

                $this->context->controller->addJS($this->_path.'views/js/main-fileupload.js');


                $this->context->controller->addCSS(($this->_path) . 'views/css/font-custom.min.css', 'all');


                if(version_compare(_PS_VERSION_, '1.7', '>')) {
                    $this->context->controller->addJqueryPlugin(array('fancybox'));
                }

            }


            if(Configuration::get($this->name.'is_uprof')){
                $this->context->controller->addCSS(($this->_path) . 'views/css/users.css', 'all');
                $this->context->controller->addJS($this->_path . 'views/js/users.js');
            }





            ### owl carousel ###
            $sr_sliderr = Configuration::get($this->name . 'sr_sliderr');
            $sr_sliderhr = Configuration::get($this->name . 'sr_sliderhr');
            $rvis_on = Configuration::get($this->name . 'rvis_on');


            $sr_slideru = Configuration::get($this->name . 'sr_slideru');
            $sr_sliderhu = Configuration::get($this->name . 'sr_sliderhu');
            $is_uprof = Configuration::get($this->name.'is_uprof');

            if (
                ($sr_sliderr == 1 && $rvis_on) || ($sr_sliderhr == 1 && $rvis_on) ||

                ($sr_slideru == 1 && $is_uprof) || ($sr_sliderhu == 1 && $is_uprof)
                ) {

                $this->context->controller->addJs(__PS_BASE_URI__ . 'modules/' . $this->name . '/views/js/owl.carousel.js');
                $this->context->controller->addCSS(__PS_BASE_URI__ . 'modules/' . $this->name . '/views/css/owl.carousel.css');
                $this->context->controller->addCSS(__PS_BASE_URI__ . 'modules/' . $this->name . '/views/css/owl.theme.default.css');
            }
            ### owl carousel ###


            // wow effects only for product page
            if($id_product && Configuration::get($this->name .'d_eff_rev') != "disable_all_effects" && $id_product){
                $this->context->controller->addJs(__PS_BASE_URI__ . 'modules/' . $this->name . '/views/js/wow.js');
                $this->context->controller->addCSS(__PS_BASE_URI__ . 'modules/' . $this->name . '/views/css/animate.css');

            }
            // wow effects only for product page


        if(version_compare(_PS_VERSION_, '1.7', '>')) {
            $this->context->controller->addJs(__PS_BASE_URI__ . 'modules/' . $this->name . '/views/js/jquery.scrollTo.min.js');
        }

        $name_template = "head.tpl";
        $cache_id = $this->name.$name_template;

        if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {

            $smarty = $this->context->smarty;
            $cookie = $this->context->cookie;




            $smarty->assign($this->name.'is15', $this->_is15);
            $smarty->assign('shop_name', @Configuration::get('PS_SHOP_NAME'));

            include_once(_PS_MODULE_DIR_.$this->name.'/classes/reviewsadvhelp.class.php');
            $obj_reviewshelp = new reviewsadvhelp();



            $smarty->assign($this->name . 'is_files'.$this->_prefix_review, Configuration::get($this->name.'is_files'.$this->_prefix_review));

            if(Configuration::get($this->name.'is_uprof')) {
                include_once(_PS_MODULE_DIR_.$this->name . "/classes/userprofileg.class.php");
                $obj_userprofileg = new userprofileg();

                $info_customer = $obj_userprofileg->getCustomerInfo();
                $avatar_thumb = $info_customer['avatar_thumb'];
                $exist_avatar = $info_customer['exist_avatar'];
                $is_show = $info_customer['is_show'];

                $smarty->assign($this->name . 'avatar_thumb', $avatar_thumb);
                $smarty->assign($this->name . 'exist_avatar', $exist_avatar);
                $smarty->assign($this->name . 'is_show', $is_show);

                $is_logged = isset($cookie->id_customer)?$cookie->id_customer:0;
                $smarty->assign($this->name.'islogged', $is_logged);
            }

            $smarty->assign($this->name . 'is_uprof', Configuration::get($this->name.'is_uprof'));




            $rid = (int)Tools::getValue('rid');
            $is_review_page = 0;
            if($rid){
                $data = $obj_reviewshelp->getOneReview(array('rid'=>$rid,));
                $smarty->assign($this->name.'name', $data['reviews'][0]['title_review']);
                $smarty->assign($this->name.'descr', strip_tags($data['reviews'][0]['text_review']));
                $smarty->assign($this->name.'img', $data['reviews'][0]['product_img']);
                $smarty->assign($this->name.'review_url', $data['reviews'][0]['review_url']);
                $is_review_page = 1;
            }
            $smarty->assign($this->name.'is_r_p', $is_review_page);


            $smarty->assign($this->name.'rsoc_on', Configuration::get($this->name.'rsoc_on'));

            $data_fb = $obj_reviewshelp->getfacebooklib((int)$params['cookie']->id_lang);
            $smarty->assign($this->name.'fbliburl', $data_fb['url']);

            $smarty->assign($this->name.'is16', $this->_is16);

            $this->basicSettingsHook();

            $smarty->assign($this->name.'rsson', Configuration::get($this->name.'rsson'));


            switch(Configuration::get($this->name.'stylestars')){
                case 'style1':
                    $smarty->assign($this->name.'stylecolor', '#F7B900');
                    break;
                case 'style2':
                    $smarty->assign($this->name.'stylecolor', '#7BE408');
                    break;
                case 'style3':
                    $smarty->assign($this->name.'stylecolor', '#00ABEC');
                    break;
                default:
                    $smarty->assign($this->name.'stylecolor', '#F7B900');
                    break;
            }


            ### snippets and pins ####
            $_product_id = Tools::getValue("id_product");

            $this->_infoAboutProductData($params);
            // pinterest




            $smarty->assign($this->name.'is_product_page', $_product_id);
            $smarty->assign($this->name.'pinvis_on', Configuration::get($this->name.'pinvis_on'));

            $is_ssl = 0;
            if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (bool)Configuration::get('PS_SSL_ENABLED'))
                $is_ssl = 1;
            $smarty->assign($this->name.'is_ssl', $is_ssl);
            // pinterest
            ### snippets and pins ####

            $smarty->assign($this->name.'starscat', Configuration::get($this->name.'starscat'));


            $this->setSEOUrls();




        }
        return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));
		

	}


    private function _infoAboutProductData($params){
        $_product_id = Tools::getValue("id_product");

        $smarty = $this->context->smarty;
        $cookie = $this->context->cookie;

        if($_product_id){



            $id_lang = (int)($cookie->id_lang);

            $_obj_product = new Product($_product_id);

            $data_product = $this->_productData(array('product'=>$_obj_product));
            $picture = $data_product['image_link'];


            $productname = addslashes($_obj_product->name[$id_lang]);

            $description = $_obj_product->description_short[$id_lang] .' '. $_obj_product->description[$id_lang];
            $description = strip_tags($description);
            $smarty->assign($this->name.'pindesc', $description);


            $smarty->assign($this->name.'picture', isset($picture)?$picture:'');
            $smarty->assign($this->name.'productname', $productname);


            //// new ///

            $product = new Product(Tools::getValue("id_product"),false,(int)($cookie->id_lang));

            $cart = $this->context->cart;
            $id_currency = $cart->id_currency;
            //$id_currency = isset($params['cart']->id_currency)?(int)($params['cart']->id_currency):0;

            $currency = new Currency($id_currency);
            if (!$currency) {
                try {
                    $currency = Currency::getCurrencyInstance($cookie->id_currency);
                } catch (Exception $e) {
                }
            }
            $qty = $product->getQuantity(Tools::getValue("id_product"));
            $desc = ($product->description_short != "") ? $product->description_short : $product->description;

            $smarty->assign(array(
                'product_brand' => Manufacturer::getNameById($product->id_manufacturer),
                'product_name' => $product->name,
                'product_image' => $picture,
                'product_price_custom' => number_format($product->getPrice(),2,".",","),
                'product_description' => Tools::htmlentitiesUTF8(strip_tags($desc)),
                'product_category' => $this->_getDefaultCategory($product->id_category_default),
                'currency_custom' => $currency->iso_code,
                'quantity' => $qty,
                'stock_string' => ($qty > 0) ? 'in_stock' : 'out_of_stock'
            ));



            /// end new ///
        }
    }
	
public function hookFooter($params){


    $name_template = "footer.tpl";
    $cache_id = $this->name.$name_template;

    if (!$this->isCached('views/templates/hooks/'.$name_template, $this->getCacheId($cache_id))) {

            $smarty = $this->context->smarty;
            $smarty->assign($this->name.'is16', $this->_is16);



            $this->_infoAboutProductData($params);



            $this->setLastReviewsBlockSettings(array('custom_page_name'=>'bottom'));



            ## user profile ##
            if(Configuration::get($this->name . $this->_prefix_review . 'adv_footer') == 1) {
                $this->setuserprofilegSettings();
            }
            $smarty->assign($this->name . $this->_prefix_review . 'adv_footer', Configuration::get($this->name . $this->_prefix_review . 'adv_footer'));
            ## user profile ##





    }
    return $this->display(__FILE__, 'views/templates/hooks/'.$name_template, $this->getCacheId($cache_id));


	}
	
	public function hookCustomerAccount($params)
	{

        $cookie = $this->context->cookie;
        $is_logged = isset($cookie->id_customer)?$cookie->id_customer:0;

        if($is_logged) {

            $name_template = "my-account.tpl";
            $cache_id = $this->name . $name_template;

            if (!$this->isCached('views/templates/hooks/' . $name_template, $this->getCacheId($cache_id))) {

                $smarty = $this->context->smarty;

                $smarty->assign($this->name . 'is16', $this->_is16);

                $smarty->assign($this->name . 'is_ps15', $this->_is15);

                $this->basicSettingsHook();


                $smarty->assign($this->name . 'islogged', $is_logged);

                include_once(_PS_MODULE_DIR_.$this->name . '/classes/reviewsadvhelp.class.php');
                $obj_reviewshelp = new reviewsadvhelp();

                $id_lang = (int)($cookie->id_lang);
                $data_seo_url = $obj_reviewshelp->getSEOURLs(array('id_lang' => $id_lang));

                $account_url = $data_seo_url['account_url'];
                $smarty->assign($this->name . 'account_url', $account_url);


            }
            return $this->display(__FILE__, 'views/templates/hooks/' . $name_template, $this->getCacheId($cache_id));
        }
	}
	
	public function hookMyAccountBlock($params)
	{
        $cookie = $this->context->cookie;
        $is_logged = isset($cookie->id_customer) ? $cookie->id_customer : 0;

        if($is_logged) {

            $name_template = "my-account-block.tpl";
            $cache_id = $this->name . $name_template;

            if (!$this->isCached('views/templates/hooks/' . $name_template, $this->getCacheId($cache_id))) {

                $smarty = $this->context->smarty;

                $smarty->assign($this->name . 'is16', $this->_is16);

                $smarty->assign($this->name . 'is_ps15', $this->_is15);

                $this->basicSettingsHook();


                $smarty->assign($this->name . 'islogged', $is_logged);


                include_once(_PS_MODULE_DIR_.$this->name . '/classes/reviewsadvhelp.class.php');
                $obj_reviewshelp = new reviewsadvhelp();

                $id_lang = (int)($cookie->id_lang);
                $data_seo_url = $obj_reviewshelp->getSEOURLs(array('id_lang' => $id_lang));

                $account_url = $data_seo_url['account_url'];

                $smarty->assign($this->name . 'account_url', $account_url);




            }
            return $this->display(__FILE__, 'views/templates/hooks/' . $name_template, $this->getCacheId($cache_id));
        }
	}
	

	
	public function recurseCategoryIds($indexedCategories, $categories, $current, $id_category = 1, $id_category_default = NULL)
	{
		$done = $this->context->done;
		
		// set variables
		static $_idsCat;
		
		if ($id_category == 1) {
			$_idsCat = null;
		}
		
		if (!isset($done[$current['infos']['id_parent']]))
			$done[$current['infos']['id_parent']] = 0;
		$done[$current['infos']['id_parent']] += 1;

		
		$_idsCat[] = (string)$id_category;
		
		if (isset($categories[$id_category]))
			foreach ($categories[$id_category] AS $key => $row)
				if ($key != 'infos')
					$this->recurseCategoryIds($indexedCategories, $categories, $categories[$id_category][$key], $key, $id_category_default, $row);
		return $_idsCat;
	}
	
	public function getIdsCategories(){
		/// get all category ids ///
		$cookie = $this->context->cookie;
		$cat = new Category();
		$list_cat = $cat->getCategories($cookie->id_lang);
		$current_cat = Category::getRootCategory()->id;
		$cat_ids = $this->recurseCategoryIds($list_cat, $list_cat, $current_cat);
		$cat_ids = implode(",",$cat_ids);
		return $cat_ids;
		/// get all category ids ///
	}
    
	public function hideCategoryPosition($name)
	{
		return preg_replace('/^[0-9]+\./', '', $name);
	}


	
	
	
	public function _productData($data){
		$product = $data['product'];
		if(is_object($product) && !empty($product->id)){
		$cookie = $this->context->cookie;
		$id_lang = isset($data['id_lang'])?$data['id_lang']:(int)($cookie->id_lang);	
		
			/* Product URL */
			$link = Context::getContext()->link;

            $id_shop = Context::getContext()->shop->id;



            if (version_compare(_PS_VERSION_, '1.5.5', '>=') && version_compare(_PS_VERSION_, '1.7', '<')) {
                $product_url = $link->getProductLink((int)$product->id, null, null, null,
                    (int)$id_lang, (int)$id_shop, 0, false);

            } else {


                $id_product_attribute = $product->getDefaultAttribute((int)$product->id);
                $product_url = $link->getProductLink((int)$product->id, $product->link_rewrite[$id_lang], null, null, $id_lang, null, $id_product_attribute, false, false, true);

                $product_url = preg_replace('/#.*/im', '', $product_url);

            }


			/* Image */
			$image = Image::getCover((int)($product->id));

			if ($image)
			{
                $block = isset($data['block'])?$data['block']:'';

				$available_types = ImageType::getImagesTypes('products');

                switch($block){

                    case 'reminder':
                        $type_img = Configuration::get($this->name.'img_size_em');
                        break;
                    default;

                        foreach ($available_types as $type){
                            $width = $type['width'];
                            if($width>400){
                                $type_img = $type['name'];
                                break;
                            }
                        }
                    break;
                }


				
				$image_link = $link->getImageLink(@$product->link_rewrite[$id_lang], (int)($product->id).'-'.(int)($image['id_image']),$type_img);
					
			    /* version 1.4 */
				if (strpos($image_link, 'http://') === FALSE && strpos($image_link, 'https://') === FALSE && version_compare(_PS_VERSION_, '1.4', '<'))
				{
					$image_link = 'http://'.$_SERVER['HTTP_HOST'].$image_link;
				}
			}
			else
			{
				$image_link = false;
				
			}
        }else {
			$image_link= false;
			$product_url = false;
		}     
            return array('product_url'=>$product_url,'image_link'=>$image_link);
	}

    public function getIdLang(){
        $cookie = $this->context->cookie;
        $id_lang = (int)($cookie->id_lang);
        return $id_lang;
    }

    public function getHttpost(){
        if(version_compare(_PS_VERSION_, '1.5', '>')){
            $custom_ssl_var = 0;
            if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (bool)Configuration::get('PS_SSL_ENABLED'))
                $custom_ssl_var = 1;


            //if ((bool)Configuration::get('PS_SSL_ENABLED') || $custom_ssl_var == 1 || (bool)Configuration::get('PS_SSL_ENABLED_EVERYWHERE'))
            if ($custom_ssl_var == 1)
                $_http_host = _PS_BASE_URL_SSL_.__PS_BASE_URI__;
            else
                $_http_host = _PS_BASE_URL_SSL_.__PS_BASE_URI__;

        } else {
            $_http_host = _PS_BASE_URL_SSL_.__PS_BASE_URI__;
        }
        return $_http_host;
    }



    public function setSEOUrls(){
        $smarty = $this->context->smarty;
        $cookie = $this->context->cookie;

        include_once(_PS_MODULE_DIR_.$this->name . '/classes/reviewsadvhelp.class.php');
        $obj_reviewshelp = new reviewsadvhelp();

        $id_lang = (int)($cookie->id_lang);
        $data_url = $obj_reviewshelp->getSEOURLs(array('id_lang'=>$id_lang));


        $my_account = $data_url['my_account'];

        $shoppers_url = $data_url['users_url'];
        $shopper_url = $data_url['user_url'];
        $shopperaccount_url = $data_url['useraccount_url'];
        $ajax_users_url = $data_url['ajax_users_url'];

        $account_url = $data_url['account_url'];

        $captcha_url = $data_url['captcha_url'];
        $captchaabuse = $data_url['captcha_abuse'];


        $reviews_url = $data_url['reviews_url'];
        $reviews_admin_url = $data_url['reviews_admin_url'];

        $rss_url = $data_url['rss_url'];


        $upload = $data_url['upload_url'];



        $smarty->assign(
            array(
                $this->name.'my_account' => $my_account,

                $this->name.'shoppers_url' => $shoppers_url,
                $this->name.'shopper_url' => $shopper_url,
                $this->name.'user_url' => $shopper_url,
                $this->name.'shopperaccount_url' => $shopperaccount_url,
                $this->name.'ajax_users_url'=>$ajax_users_url,

                $this->name.'account_url'=>$account_url,




                $this->name.'captcha_url' => $captcha_url,
                $this->name.'captchaabuse' => $captchaabuse,


                $this->name.'reviews_url' => $reviews_url,
                $this->name.'reviews_admin_url'=>$reviews_admin_url,

                $this->name.'rss_url' => $rss_url,


                $this->name.'upload' => $upload,

            )
        );

        $smarty->assign($this->name.'is16', $this->_is16);
        $smarty->assign($this->name.'is_ps15', $this->_is15);
        $smarty->assign($this->name.'pic', $this->path_img_cloud);


    }


    public function setuserprofilegSettings(){

        $smarty = $this->context->smarty;

        $smarty->assign($this->name.'is_uprof', Configuration::get($this->name.'is_uprof'));





        if(Configuration::get($this->name.'is_uprof') == 1) {

            $this->setSEOUrls();




            include_once(_PS_MODULE_DIR_.$this->name . '/classes/userprofileg.class.php');
            $obj_userprofileg = new userprofileg();

            $info_customers = $obj_userprofileg->getShoppersBlock(
                array(
                    'start' => 0,
                    'step' => (int)Configuration::get($this->name . $this->_prefix_review . 'shoppers_blc')
                )
            );


            $smarty->assign(array(
                $this->name . 'customers_block' => $info_customers['customers']
            ));

            $smarty->assign($this->name . 'sr_sliderhu', (int)Configuration::get($this->name . 'sr_sliderhu'));
            $smarty->assign($this->name . 'sr_slhu', (int)Configuration::get($this->name . 'sr_slhu'));

            $smarty->assign($this->name . 'sr_slideru', (int)Configuration::get($this->name . 'sr_slideru'));
            $smarty->assign($this->name . 'sr_slu', (int)Configuration::get($this->name . 'sr_slu'));


        }
    }




    private function _effects($data){

        $value = $data['value'];

        $current_value = Configuration::get($this->name.$value);

        $all_effects = array();



        $all_effects[$this->l('Disable All Effects')] = array('disable_all_effects');

        $all_effects[$this->l('Attention Seekers')] = array('bounce','flash','pulse','rubberBand','shake','swing','tada','wobble','jello');
        $all_effects[$this->l('Bouncing Entrances')] = array('bounceIn','bounceInDown','bounceInLeft','bounceInRight','bounceInUp');
        $all_effects[$this->l('Bouncing Exits')] = array('bounceOut','bounceOutDown','bounceOutLeft','bounceOutRight','bounceOutUp');
        $all_effects[$this->l('Fading Entrances')] = array('fadeIn','fadeInDown','fadeInDownBig','fadeInLeft','fadeInLeftBig','fadeInRight','fadeInRightBig','fadeInUp','fadeInUpBig');
        $all_effects[$this->l('Flippers')] = array('flip','flipInX','flipInY','flipOutX','flipOutY');
        $all_effects[$this->l('Lightspeed')] = array('lightSpeedIn','lightSpeedOut');
        $all_effects[$this->l('Rotating Entrances')] = array('rotateIn','rotateInDownLeft','rotateInDownRight','rotateInUpLeft','rotateInUpRight');
        $all_effects[$this->l('Rotating Exits')] = array('rotateOut','rotateOutDownLeft','rotateOutDownRight','rotateOutUpLeft','rotateOutUpRight');
        $all_effects[$this->l('Sliding Entrances')] = array('slideInUp','slideInDown','slideInLeft','slideInRight');
        $all_effects[$this->l('Sliding Exits')] = array('slideOutUp','slideOutDown','slideOutLeft','slideOutRight');
        $all_effects[$this->l('Zoom Entrances')] = array('zoomIn','zoomInDown','zoomInLeft','zoomInRight','zoomInUp');
        $all_effects[$this->l('Zoom Exits')] = array('zoomOut','zoomOutDown','zoomOutLeft','zoomOutRight','zoomOutUp');
        $all_effects[$this->l('Specials')] = array('hinge','rollIn','rollOut');

        $_html = '';
        $_html .= '<select name="'.$value.'" id="'.$value.'">';

        foreach($all_effects as $k => $val){
            $_html .= '<optgroup label="'.$k.'">';
            foreach($val as $_val_item){
                $_html .= '<option value="'.$_val_item.'" '.(($current_value == $_val_item)?'selected = "selected"':'').'>'.$_val_item.'</option>';
            }
            $_html .= '</optgroup>';
        }

        $_html .= '</select>';

        return $_html;
    }



    public function clearSmartyCacheItems(){

        include_once(_PS_MODULE_DIR_.$this->name.'/classes/cachereviewsadv.class.php');
        $cache = new cachereviewsadv();


        $cache->clearSmartyCacheModule();
    }

	
	
	
}
