<?php
class ControllerextensionModulereason extends Controller {
	public function index($setting) {
		$data['autoplay'] = $setting['autoplay'];
		$data['main'] = $setting['main'];
		$data['fade'] = $setting['fade'];
		$data['speed'] = $setting['speed'];
		$data['column'] = $setting['column'];
		$data['rows'] = $setting['rows'];
		$data['scroll'] = $setting['scroll'];	
		$data['mtitle'] = $setting['mtitle'];
		$data['mdescribe'] = $setting['mdescribe'];
		$data['mbgcolor'] = $setting['mbgcolor'];
		$data['mpa'] = $setting['mpa'];
		$data['mborder'] = $setting['mborder'];
        $data['miconbj'] = $setting['miconbj'];		
        $data['miconcolorc'] = $setting['miconcolorc'];
		$data['miconcolor'] = $setting['miconcolor'];
        $data['hoverbj'] = $setting['hoverbj'];
        $data['hovertit'] = $setting['hovertit'];	
		$data['miconround'] = $setting['miconround'];
		$data['miconsize'] = $setting['miconsize'];
		$data['miconborder'] = $setting['miconborder'];
		$data['miconbc'] = $setting['miconbc'];
		$data['miconwidth'] = $setting['miconwidth'];
		$data['miconheight'] = $setting['miconheight'];	
		$data['buttonbj'] = $setting['buttonbj'];
		$data['buttoncolor'] = $setting['buttoncolor'];
		$data['buttonhover'] = $setting['buttonhover'];
		$data['buttonround'] = $setting['buttonround'];	
        $data['sectionid'] = $setting['sectionid'];
        $data['sectiontab'] = $setting['sectiontab'];
        $data['boxrnum'] = $setting['boxrnum'];			
		$data['services'] = array();

		if (isset($setting['service']) && $setting['service']) {
			$this->load->model('tool/image');

			$services = $setting['service'];

			$sort_order = array();

			foreach ($services as $key => $value) {
				$sort_order[$key] = $value['sort_order'];
			}

			array_multisort($sort_order, SORT_ASC, $services);

			foreach ($services as $service) {
				$service_info = array();
				if (isset($service['title'][$this->config->get('config_language_id')])) {
					$service_info['title'] = trim($service['title'][$this->config->get('config_language_id')]);
				} else {
					$service_info['title'] = '';
				}

				if (isset($service['text'][$this->config->get('config_language_id')])) {
					$service_info['text'] = trim($service['text'][$this->config->get('config_language_id')]);
				} else {
					$service_info['text'] = '';
				}
				if (isset($service['icon'][$this->config->get('config_language_id')])) {
					$service_info['icon'] = trim($service['icon']);
				} else {
					$service_info['icon'] = '';
				}
				if (isset($service['position'][$this->config->get('config_language_id')])) {
					$service_info['position'] = trim($service['position']);
				} else {
					$service_info['position'] = '';
				}
				if (isset($service['boxcolor'][$this->config->get('config_language_id')])) {
					$service_info['boxcolor'] = trim($service['boxcolor']);
				} else {
					$service_info['boxcolor'] = '';
				}
				if (isset($service['buttonname'][$this->config->get('config_language_id')])) {
					$service_info['buttonname'] = trim($service['buttonname'][$this->config->get('config_language_id')]);
				} else {
					$service_info['buttonname'] = '';
				}
				if (isset($service['link'])) {
					$service_info['link'] = trim($service['link']);
				} else {
					$service_info['link'] = '';
				}

				if (isset($service['image']) && is_file(DIR_IMAGE . $service['image'])) {
					$service_info['image'] = $this->model_tool_image->resize($service['image'], $setting['imagewidth'], $setting['imageheight']);
				} else {
					$service_info['image'] = $this->model_tool_image->resize('placeholder.png', $setting['imagewidth'], $setting['imageheight']);
				}

				$data['services'][] = $service_info;
			}
		}

		if ($data['services']) {
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . 'extension/module/reason.tpl')) {
				return $this->load->view($this->config->get('config_template') . 'extension/module/reason.tpl', $data);
			} else {
				return $this->load->view('extension/module/reason.tpl', $data);
			}
		}

	}
}