<?php
class ControllerCommonOfage extends Controller {

  public function index() {

    if($this->ftrgeralregistry->isApp()){
      return false;
    }

    $this->language->load('common/maintenance');
    $this->load->model('localisation/language');
    $this->load->type('tipocomum');
    $this->load->helper('ftr_geral');

    if( $this->config->get('wg24_futura_of_age_status') && ($this->config->get('wg24_futura_of_age_type_message') == Type_MessageOfAge::Tp_TelaInteira) && (!isset($_COOKIE['ofage'])) ){
      $route = '';

      if (isset($this->request->get['route']) || isset($this->request->get['_route_'])) {

        $part = (isset($this->request->get['route'])) ? explode('/', $this->request->get['route']) : explode('/', $this->request->get['_route_']);

        if (isset($part[0])) {
          $route .= $part[0];
        }

        if($route == Type_DefaultValues::Tp_UrlLiberada){
          return false;
        }        

        $route2 = (isset($this->request->get['route'])) ? $this->request->get['route'] : $this->request->get['_route_'];

        if($this->ftrgeralregistry->getUrlRelease($route2)){
          return false;
        }

      }

      // Show site if logged in as admin
      $this->load->library('user');

      $this->user = new User($this->registry);

      if (($route != 'payment') && !$this->user->isLogged()) {
        return $this->forward('common/ofage/info');
      }
    }

  }

  public function info() {

    $this->language->load('common/ofage');
    $this->load->model('localisation/language');
    $this->load->type('tipocomum');
    $this->load->helper('ftr_geral');
    $this->load->dmodel('tool/image');
	
	  $server = $this->url->link('', '', 'SSL', false);
	
    $this->document->setTitle($this->language->get('heading_title'));
    $this->data['heading_title']      = $this->language->get('heading_title');
    $this->data['text_yes']           = $this->language->get('text_yes');
    $this->data['text_no']            = $this->language->get('text_no');
    $this->data['text_message_ofage'] = $this->language->get('text_message_ofage');
    $this->data['link_no']		        = $this->config->get('wg24_futura_of_age_link');
    $this->data['link_yes']		        = $this->url->link('common/home','','NONSSL','false');
    $this->data['imagebackground']    = $server . 'image/' .$this->config->get('wg24_futura_of_age_background');
    $background                       = $this->config->get('wg24_futura_of_age_background_repeat');
    $this->data['repeatbackground']   = ($background == Type_BackgroundRepeat::Tp_NoRepeat) ? $background.' center center fixed' : $background;
    $this->data['norepeat']           = $background;
    $this->data['name']               = $this->config->get('config_name');

    if ($this->config->get('wg24_futura_of_age_logo') && file_exists(DIR_IMAGE . $this->config->get('wg24_futura_of_age_logo'))) {
      $this->data['logoofage'] =  $server . 'image/' . $this->config->get('wg24_futura_of_age_logo');
    } else {
      $this->data['logoofage'] = $server . 'image/' . $this->config->get('config_logo');
    }

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/ofage.tpl')) {
      $this->template = $this->config->get('config_template') . '/template/common/ofage.tpl';
    } else {
      $this->template = 'default/template/common/ofage.tpl';
    }

    $this->response->setOutput($this->render());
  }
}
