<?php
class ControllerExtensionModuleytabs extends Controller {
	public function index($setting) {
		$data['name'] = $setting['name'];
		$data['bgcolor'] = $setting['bgcolor'];
		$data['bgcolorcss'] = $setting['bgcolorcss'];
		$data['titlecss'] = $setting['titlecss'];
		$data['tab1'] = $setting['tab1'];
		$data['tab2'] = $setting['tab2'];
		$data['tab3'] = $setting['tab3'];
		$data['tab4'] = $setting['tab4'];
		$data['tab5'] = $setting['tab5'];
		$data['tab6'] = $setting['tab6'];
		$data['describe'] = $setting['describe'];
		$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['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['tabs'])) {
					$service_info['tabs'] = trim($service['tabs']);
				} else {
					$service_info['tabs'] = '';
				}
				if (isset($service['image']) && is_file(DIR_IMAGE . $service['image'])) {
					$service_info['image'] = $this->model_tool_image->resize($service['image'], 750, 464);
				} else {
					$service_info['image'] = $this->model_tool_image->resize('placeholder.png', 750, 464);
				}

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

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

	}
}