<?php
class ControllerextensionModuleystep extends Controller {
	public function index($setting) {
		$data['titlename'] = $setting['titlename'];
		$data['linew'] = $setting['linew'];
		$data['lineh'] = $setting['lineh'];
		$data['linec'] = $setting['linec'];
		$data['bgcolor'] = $setting['bgcolor'];
		$data['bgcolorcss'] = $setting['bgcolorcss'];
		$data['titlecss'] = $setting['titlecss'];
		$data['titlesmcss'] = $setting['titlesmcss'];
		$data['sectionptop'] = $setting['sectionptop'];
		$data['sectionpbuttom'] = $setting['sectionpbuttom'];
		$data['describe'] = $setting['describe'];
		$data['stepcolumn'] = $setting['stepcolumn'];
		$data['stepborder'] = $setting['stepborder'];
		$data['stepcolor'] = $setting['stepcolor'];
		$data['stepbj'] = $setting['stepbj'];
		$data['stepwide'] = $setting['stepwide'];
		$data['stephigh'] = $setting['stephigh'];
		$data['slborder'] = $setting['slborder'];
		$data['slcolor'] = $setting['slcolor'];
		
		$this->load->model('tool/image');

		if (is_file(DIR_IMAGE . $setting['image'])) {
			$image = $setting['image'];
		} else {
			$image = 'placeholder.png';
		}

		$data['image'] = $this->model_tool_image->resize($image, $setting['width'], $setting['height']);
		$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'] = '';
				}

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

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

	}
}