<?php

use system\entity\filter\baseFilter;

class ControllerMicrosoftOutlook extends Controller
{

    public function index()
    {

        $this->language->load('module/outlook');
        $this->data['breadcrumbs'] = array();

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

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

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

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

        $this->data['heading_title'] = $this->language->get('text_title');
        $this->data['text_intro'] = $this->language->get('text_intro');
        $this->data['text_auth'] = $this->language->get('text_auth');
        $this->data['text_auth_done'] = $this->language->get('text_auth_done');
        $this->data['button_continue'] = $this->language->get('button_continue');
        $this->data['continue'] = $this->url->link('common/home');

        $this->data['error'] = '';
        if (isset($this->request->get['error'])) {
            $this->data['error'] = 'Error: ' . $this->request->get['error'] . (($this->request->get['error_description']) ? ' - ' . $this->request->get['error_description'] : '');
        }

        if (isset($this->request->get['code'])) {
            $this->data['error'] = $this->outlookapi->getAccessToken($this->request->get['code']);
        }

        $this->data['auth_done'] = '';
        if ($this->outlookapi->getAccess()) {
            $this->data['auth_done'] = '1';
            $this->data['text_auth'] = $this->language->get('text_reauth');
        }

        $this->data['login_url'] = $this->outlookapi->getLoginUrl();


        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/microsoft/auth.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/microsoft/auth.tpl';
        } else {
            $this->template = 'default/template/microsoft/auth.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());

    }
}
