<?php


class ControllerPaymentCaptcha extends Controller
{
    public function index() {
        $this->load->dmodel('checkout/order');
        $this->language->load('payment/captcha');
        $this->data['text_captcha'] = $this->language->get('text_captcha'); 
        $this->data['text_captcha_placeholder'] = $this->language->get('text_captcha_placeholder'); 

		/*carregamento do captcha*/
		$data_atual = new DateTime($this->db->dataAtual(), new DateTimeZone('America/Sao_Paulo'));
		$data_atual = $data_atual->format("Y-m-d");
		$count_customer_orders_day = $this->dmodel_checkout_order->getOrdersByCustommer($this->customer->getId(),$data_atual,$data_atual);	
        $count_ip_orders_day = $this->dmodel_checkout_order->getOrdersByIP($this->request->server['REMOTE_ADDR'],$data_atual,$data_atual);	
        $this->data['captcha_validate'] = false;
		
		if ( (count($count_customer_orders_day)>1) || (count($count_ip_orders_day)>1) ){
			$this->data['site_key'] = $this->config->get('google_recaptcha_site_key');
            $this->data['google_captcha'] = ($this->data['site_key'] && $this->config->get('google_recaptcha_secret_key') && $this->config->get('wg24_google_recaptcha_status')) ? 1 : 0;	
            $this->data['captcha_validate'] = true;

            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/captcha.twig')) {
                $this->template = $this->config->get('config_template') . '/template/payment/captcha.twig';
            } 
      
            $this->response->setOutput($this->render());  
        } 
        
    }

	public function loadCaptcha(){
		$this->ftrgeralregistry->loadCaptcha();
	}

}
