<?php
class ControllerCommonFooter extends Controller {
	public function index() {
		$this->load->language('common/footer');

		$data['text_information'] = $this->language->get('text_information');
		$data['text_service'] = $this->language->get('text_service');
		$data['text_extra'] = $this->language->get('text_extra');
		$data['text_contact'] = $this->language->get('text_contact');
		$data['text_return'] = $this->language->get('text_return');
		$data['text_sitemap'] = $this->language->get('text_sitemap');
		$data['text_manufacturer'] = $this->language->get('text_manufacturer');
		$data['text_voucher'] = $this->language->get('text_voucher');
		$data['text_affiliate'] = $this->language->get('text_affiliate');
		$data['text_special'] = $this->language->get('text_special');
		$data['text_account'] = $this->language->get('text_account');
		$data['text_order'] = $this->language->get('text_order');
		$data['text_wishlist'] = $this->language->get('text_wishlist');
		$data['text_newsletter'] = $this->language->get('text_newsletter');

		$this->load->model('catalog/information');

			$data['live_search'] = $this->load->controller('module/d_ajax_search');
			$data['footer_modules'] = $this->load->controller('common/footer_modules');
			$cosyone_footer_block_title = $this->config->get('cosyone_footer_custom_block_title');
			if(empty($cosyone_footer_block_title[$this->language->get('code')])) {
				$data['cosyone_footer_custom_block_title'] = false;
			} else if (isset($cosyone_footer_block_title[$this->language->get('code')])) {
				$data['cosyone_footer_custom_block_title'] = html_entity_decode($cosyone_footer_block_title[$this->language->get('code')], ENT_QUOTES, 'UTF-8');
			}
			$data['cosyone_footer_payment_icon'] = $this->config->get('cosyone_footer_payment_icon');
			$data['cosyone_use_retina'] = $this->config->get('cosyone_use_retina');
			$cosyone_footer_block = $this->config->get('cosyone_footer_custom_block');
			if(empty($cosyone_footer_block[$this->language->get('code')])) {
				$data['cosyone_footer_custom_block'] = false;
			} else if (isset($cosyone_footer_block[$this->language->get('code')])) {
				$data['cosyone_footer_custom_block'] = html_entity_decode($cosyone_footer_block[$this->language->get('code')], ENT_QUOTES, 'UTF-8');
			}
			

		$data['informations'] = array();

		foreach ($this->model_catalog_information->getInformations() as $result) {
			if ($result['bottom']) {
				$data['informations'][] = array(
					'title' => $result['title'],
					'href'  => $this->url->link('information/information', 'information_id=' . $result['information_id'])
				);
			}
		}

		$data['contact'] = $this->url->link('information/contact');
		$data['return'] = $this->url->link('account/return/add', '', 'SSL');
		$data['sitemap'] = $this->url->link('information/sitemap');
		$data['manufacturer'] = $this->url->link('product/manufacturer');
		$data['voucher'] = $this->url->link('account/voucher', '', 'SSL');
		$data['affiliate'] = $this->url->link('affiliate/account', '', 'SSL');
		$data['special'] = $this->url->link('product/special');
		$data['account'] = $this->url->link('account/account', '', 'SSL');
		$data['order'] = $this->url->link('account/order', '', 'SSL');
		$data['wishlist'] = $this->url->link('account/wishlist', '', 'SSL');
		 $data['newsletter'] = $this->url->link('account/newsletter', '', 'SSL');
			$data['yandex_metrika'] = $this->config->get('ya_metrika_code') ? html_entity_decode($this->config->get('ya_metrika_code'), ENT_QUOTES, 'UTF-8') : '';
			$data['ya_metrika_active'] = $this->config->get('ya_metrika_active') ? true : false;
			

		$data['powered'] = sprintf($this->language->get('text_powered'), $this->config->get('config_name'), date('Y', time()));

		// Whos Online
		if ($this->config->get('config_customer_online')) {
			$this->load->model('tool/online');

			if (isset($this->request->server['REMOTE_ADDR'])) {
				$ip = $this->request->server['REMOTE_ADDR'];
			} else {
				$ip = '';
			}

			if (isset($this->request->server['HTTP_HOST']) && isset($this->request->server['REQUEST_URI'])) {
				$url = 'http://' . $this->request->server['HTTP_HOST'] . $this->request->server['REQUEST_URI'];
			} else {
				$url = '';
			}

			if (isset($this->request->server['HTTP_REFERER'])) {
				$referer = $this->request->server['HTTP_REFERER'];
			} else {
				$referer = '';
			}

			$this->model_tool_online->whosonline($ip, $this->customer->getId(), $url, $referer);
		}


		///////////// volosnikov ///////////////////////
		$this->load->model('catalog/category');
		$this->load->model('catalog/product');

		$categories_1 = $this->model_catalog_category->getCategoriesWithUrl(0);

		foreach ($categories_1 as $category_1) {
			$categories_2 = $this->model_catalog_category->getCategoriesWithUrl($category_1['category_id']);

			foreach ($categories_2 as $category_2) {
				$data['categories'][] = array(
					'name'     => $category_2['name'],
					'id'	   => $category_2['category_id'],
					'url'	   => $category_2['keyword'],
					'parent'   => "/".$category_1['keyword'].'/'
				);
			}

			//var_dump($category_1);
			//echo "<hr>";
			if(sizeof($categories_2) == 0) {
				$data['categories'][] = array(
					'name'     => $category_1['name'],
					'id'	   => $category_1['category_id'],
					'url'	   => $category_1['keyword'],
					'parent'   => '/'
				);
			}
		}
		////////////////////////////////////////////////

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/footer.tpl')) {
			return $this->load->view($this->config->get('config_template') . '/template/common/footer.tpl', $data);
		} else {
			return $this->load->view('default/template/common/footer.tpl', $data);
		}
	}
}