<?php
class ControllerAccountRegister extends Controller
{
  private $error = array();

  public function index()
  {
    if ((!isset($this->request->get['old']) && !$this->config->get('register_old')) && !$this->ftrgeralregistry->isApp()) {
      $this->load->controller('account/register_new');
      $registerNew = new ControllerAccountRegisterNew($this->registry);
      return $registerNew->index();
    }


    $this->load->controller('common/footer');

    if ($this->customer->isLogged()) {
      $this->redirect($this->url->link('account/account', '', 'SSL'));
    }

    $this->language->load('account/register');

    $this->document->setTitle($this->language->get('heading_title'));

    $this->load->model('account/customer');
    $this->load->helper('ftr_geral');
    $this->load->controller('account/register_content');

    if (isset($this->request->get['tbp'])) {
      $this->session->data['tbp'] = base64_decode($this->request->get['tbp']);
    }

    if (isset($this->request->get['indication_customer_id'])) {
      $this->session->data['indication_customer_id'] = $this->request->get['indication_customer_id'];
    }


    $this->data['breadcrumbs'] = array();

    $this->data['breadcrumbs'][] = array(
      'text' => $this->language->get('text_home'),
      'href' => $this->url->link('common/home', '', 'NONSSL', 'false'),
      'separator' => false
    );

    $this->data['breadcrumbs'][] = array(
      'text' => $this->language->get('text_account'),
      'href' => $this->url->link('account/account', '', 'SSL'),
      'separator' => $this->language->get('text_separator')
    );

    $this->data['breadcrumbs'][] = array(
      'text' => $this->language->get('text_register'),
      'href' => $this->url->link('account/register', '', 'SSL'),
      'separator' => $this->language->get('text_separator')
    );

    $this->breadcrumbs->setbreadcumbs($this->data['breadcrumbs']);

    $this->data['heading_title'] = $this->language->get('heading_title');

    $language = $this->language->load('account/register');
    $this->data = array_merge($this->data, $language);

    $this->data['customer_interests_remember'] = ($this->config->get('fields_register_brazil_status_interests')) ? true : false;
    $this->data['interests_categories'] = $this->getChild('account/interests_categories', isset($this->request->post['categories']) ? $this->request->post['categories'] : '');
    $this->data['register_content'] = $this->getChild('account/register_content');

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/register.twig')) {
      $this->template = $this->config->get('config_template') . '/template/account/register.twig';
    } else {
      $this->template = 'default/template/account/register.twig';
    }

    $this->children = array(
      'common/breadcrumbs',
      'common/column_left',
      'common/column_right',
      'common/content_top',
      'common/content_bottom',
      'common/footer',
      'common/header'
    );

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

}