<?php
class ControllerAccountSuccess extends Controller {
	public function index() {
		$this->language->load('account/success');

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

		$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_success'),
			'href'      => $this->url->link('account/success'),
			'separator' => $this->language->get('text_separator')
		);

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

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

		$this->load->model('account/customer_group');

		$customer_group = $this->model_account_customer_group->getCustomerGroup($this->customer->getCustomerGroupId());

		if($this->config->get('email_validation_status') > 0){
		    if(isset($_GET['token'])){
                $this->language->load('account/success');
                $this->load->model('account/emailvalidate');
                $this->model_account_emailvalidate->activateAccount($_GET['token']);
                $this->data['text_message'] = sprintf($this->language->get('text_validate_success'), $this->url->link('account/register'), $this->url->link('information/contact'));
            }else{
                $this->data['text_message'] = sprintf($this->language->get('text_validate'), $this->config->get('config_name'), $this->url->link('account/email_validate'), $this->url->link('information/contact'));
            }
        }else{
            if ($customer_group && !$customer_group['approval']) {
                $this->data['text_message'] = sprintf($this->language->get('text_message'), $this->url->link('information/contact'));
            } else {
                $this->data['text_message'] = sprintf($this->language->get('text_approval'), $this->config->get('config_name'), $this->url->link('information/contact'));
            }
        }


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

		if ($this->cart->hasProducts()) {
			$this->data['continue'] = $this->url->link('checkout/cart', '', 'SSL');
		} else {
			$this->data['continue'] = $this->customer->isLogged() ? $this->url->link('account/account', '', 'SSL') : $this->url->link('common/home', '', 'SSL');
		}

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

		$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('account/logout'));
	}
}
