<?php
class ControllerextensionModulegallery extends Controller {
	public function index($setting) {
		$data['titlename'] = $setting['titlename'];
		$data['bgcolor'] = $setting['bgcolor'];
		$data['bgcolorcss'] = $setting['bgcolorcss'];
		$data['titlecss'] = $setting['titlecss'];
		$data['titlesmcss'] = $setting['titlesmcss'];
		$data['describe'] = $setting['describe'];		
		$data['main'] = $setting['main'];
		$data['autoplay'] = $setting['autoplay'];
		$data['fade'] = $setting['fade'];
		$data['speed'] = $setting['speed'];
		$data['column'] = $setting['column'];
		$data['rows'] = $setting['rows'];
		$data['scroll'] = $setting['scroll'];
        $data['imagepicstyle'] = $setting['imagepicstyle'];		
		$data['picpa'] = $setting['picpa'];
		$data['topp'] = $setting['topp'];
		$data['buttonp'] = $setting['buttonp'];	
		$data['iplinew'] = $setting['iplinew'];	
		$data['iplineh'] = $setting['iplineh'];	
		$data['iplinec'] = $setting['iplinec'];	
        $data['sectionid'] = $setting['sectionid'];
        $data['sectiontab'] = $setting['sectiontab'];	
		$data['boxborder'] = $setting['boxborder'];
		$data['boxcolor'] = $setting['boxcolor'];	       
        $data['boxround'] = $setting['boxround'];
        $data['boxshadow'] = $setting['boxshadow'];
        $data['boxshadowhover'] = $setting['boxshadowhover'];			
		$data['images'] = array();

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

			$images = $setting['image'];

			$sort_order = array();

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

			array_multisort($sort_order, SORT_ASC, $images);

			foreach ($images as $image) {
				$image_info = array();

				if (isset($image['link'])) {
					$image_info['link'] = trim($image['link']);
				} else {
					$image_info['link'] = '';
				}

				if (isset($image['image']) && is_file(DIR_IMAGE . $image['image'])) {
					$image_info['image'] = $this->model_tool_image->resize($image['image'], $setting['width'], $setting['height']);
				} else {
					$image_info['image'] = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
				}

				$data['images'][] = $image_info;
			}
		}

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