<?php 
///////////////////////////////////////////////////////////////////////////////////////
// opencart1.4.0【日本語版】
// opencart.jp
// japan_post.php
// このファイルは、日本郵便のゆうパックの配送モジュールです。(admin/controller/shipping)
// ver 1.0.0 Coding By sae
// GPL ver 3
///////////////////////////////////////////////////////////////////////////////////////
class ControllerShippingJapanPost extends Controller {
	private $error = array(); 
	
	public function index() {   
		
		$this->load->language('shipping/japan_post');

		$this->document->title = $this->language->get('heading_title');
		
		$this->load->model( 'setting/setting' );
		
		$this->load->model('shipping/japan_post');
				
		$this->data['select_zone'] = $this->model_shipping_japan_post->getZone(107);
		
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) {
					
			$this->model_setting_setting->editSetting('japan_post', $this->request->post);	
			
			$this->session->data['success'] = $this->language->get('text_success');
						
			$this->redirect($this->url->https('extension/shipping'));
		}
				
		$this->data['heading_title'] = $this->language->get('heading_title');

		$this->data['text_enabled'] = $this->language->get('text_enabled');
		$this->data['text_disabled'] = $this->language->get('text_disabled');
		$this->data['text_all_zones'] = $this->language->get('text_all_zones');
		$this->data['text_none'] = $this->language->get('text_none');
		$this->data['text_shipping'] = $this->language->get('text_shipping');
		$this->data['text_exe'] = $this->language->get('text_exe');
		$this->data['text_stop'] = $this->language->get('text_stop');
		
		$this->data['entry_zone'] = $this->language->get('entry_zone');
		$this->data['entry_time'] = $this->language->get('entry_time');
		$this->data['entry_district'] = $this->language->get('entry_district');
		$this->data['hokkaido'] = $this->language->get('hokkaido');
		$this->data['touhoku'] = $this->language->get('touhoku');
		$this->data['kantou'] = $this->language->get('kantou');
		$this->data['shinetsu'] = $this->language->get('shinetsu');
		$this->data['hokuriku'] = $this->language->get('hokuriku');
		$this->data['toukai'] = $this->language->get('toukai');
		$this->data['kinki'] = $this->language->get('kinki');
		$this->data['chugoku'] = $this->language->get('chugoku');
		$this->data['shikoku'] = $this->language->get('shikoku');
		$this->data['kyusyu'] = $this->language->get('kyusyu');
		$this->data['okinawa'] = $this->language->get('okinawa');
		$this->data['zenkoku'] = $this->language->get('zenkoku');
		$this->data['entry_evenly'] = $this->language->get('entry_evenly');
		$this->data['entry_purchase'] = $this->language->get('entry_purchase');
		$this->data['entry_status'] = $this->language->get('entry_status');
		$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
		$this->data['selected_default'] = $this->language->get('selected_default');
		$this->data['entry_district_free'] = $this->language->get('entry_district_free');
		$this->data['entry_evenly_free'] = $this->language->get('entry_evenly_free');
		
		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');

		$this->data['tab_general'] = $this->language->get('tab_general');

		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}
		
  		$this->document->breadcrumbs = array();

   		$this->document->breadcrumbs[] = array(
       		'href'      => $this->url->https('common/home'),
       		'text'      => $this->language->get('text_home'),
      		'separator' => FALSE
   		);

   		$this->document->breadcrumbs[] = array(
       		'href'      => $this->url->https('extension/shipping'),
       		'text'      => $this->language->get('text_shipping'),
      		'separator' => ' :: '
   		);
		
   		$this->document->breadcrumbs[] = array(
       		'href'      => $this->url->https('shipping/japan_post'),
       		'text'      => $this->language->get('heading_title'),
      		'separator' => ' :: '
   		);
		
		$this->data['action'] = $this->url->https('shipping/japan_post');
		
		$this->data['cancel'] = $this->url->https('extension/shipping');
		
		if (isset($this->request->post['japan_post_zone'])) {
			$this->data['japan_post_zone'] = $this->request->post['japan_post_zone'];
		} else {
			$this->data['japan_post_zone'] = $this->config->get('japan_post_zone');
		}

		if (isset($this->request->post['japan_post_price'])) {
			$this->data['japan_post_price'] = $this->request->post['japan_post_price'];
		} else {
			$this->data['japan_post_price'] = $this->config->get('japan_post_price');
		}
		
		$this->data['checked_ev'] = '';
		
		$this->data['checked_di'] = '';
		
		$this->data['checked_pu'] = '';
		
		if ( $this->data['japan_post_price'] == 'ev' || $this->data['japan_post_price'] == '' ){
		
			$this->data['checked_ev'] = 'checked="checked"';
		
		}elseif( $this->data['japan_post_price'] == 'di' ){
		
			$this->data['checked_di'] = 'checked="checked"';
			
		}elseif( $this->data['japan_post_price'] == 'pu' ){
		
			$this->data['checked_pu'] = 'checked="checked"';
		
		}
		
		if( isset($this->request->post['japan_post_time']) ){
			$this->data['japan_post_time'] = $this->request->post['japan_post_time'];
		}else{
			$this->data['japan_post_time'] = $this->config->get('japan_post_time');
		}
		
		if( isset($this->request->post['japan_post_stop']) ){
		
			$this->data['japan_post_stop'] = 'checked="checked"';
		
		}else{
			
			if( $this->config->get('japan_post_stop') == 1 ){
			
				$this->data['japan_post_stop'] = 'checked="checked"';
			
			}else{
				
				$this->data['japan_post_stop'] = '';
			
			}
			
		}
		
		if( isset($this->request->post['japan_post_time_status']) ){
		
			$this->data['japan_post_time_status'] = 'checked="checked"';
		
		}else{
			
			if( $this->config->get('japan_post_time_status') == 1 ){
			
				$this->data['japan_post_time_status'] = 'checked="checked"';
			
			}else{
				
				$this->data['japan_post_time_status'] = '';
			
			}
			
		}
		
		if( isset($this->request->post['japan_post_district_free']) ){
		
			$this->data['japan_post_district_free'] = $this->request->post['japan_post_district_free'];
		
		}else{
		
			$this->data['japan_post_district_free'] = $this->config->get('japan_post_district_free');
		
		}
		
		if( isset($this->request->post['japan_post_evenly_free']) ){
		
			$this->data['japan_post_evenly_free'] = $this->request->post['japan_post_evenly_free'];
		
		}else{
		
			$this->data['japan_post_evenly_free'] = $this->config->get('japan_post_evenly_free');
		
		}
		
		if (isset($this->request->post['japan_post_evenly'])) {
			$this->data['japan_post_evenly'] = $this->request->post['japan_post_evenly'];
		} else {
			$this->data['japan_post_evenly'] = $this->config->get('japan_post_evenly');
		}

		if (isset($this->request->post['japan_post_purchase'])) {
			$this->data['japan_post_purchase'] = $this->request->post['japan_post_purchase'];

		} else {
			$this->data['japan_post_purchase'] = $this->config->get('japan_post_purchase');
		}
		
		if (isset($this->request->post['ho_p'])) {
			$this->data['ho_p'] = $this->request->post['ho_p'];
		} else {
			$this->data['ho_p'] = $this->config->get('ho_p');
		}
		
		if (isset($this->request->post['ho_p_free'])) {
			$this->data['ho_p_free'] = $this->request->post['ho_p_free'];
		} else {
			$this->data['ho_p_free'] = $this->config->get('ho_p_free');
		}

		if (isset($this->request->post['to_p'])) {
			$this->data['to_p'] = $this->request->post['to_p'];
		} else {
			$this->data['to_p'] = $this->config->get('to_p');
		}
		
		if (isset($this->request->post['to_p_free'])) {
			$this->data['to_p_free'] = $this->request->post['to_p_free'];
		} else {
			$this->data['to_p_free'] = $this->config->get('to_p_free');
		}
		
		if (isset($this->request->post['ka_p'])) {
			$this->data['ka_p'] = $this->request->post['ka_p'];
		} else {
			$this->data['ka_p'] = $this->config->get('ka_p');
		}
		
		if (isset($this->request->post['ka_p_free'])) {
			$this->data['ka_p_free'] = $this->request->post['ka_p_free'];
		} else {
			$this->data['ka_p_free'] = $this->config->get('ka_p_free');
		}
		
		if (isset($this->request->post['shi_p'])) {
			$this->data['shi_p'] = $this->request->post['shi_p'];
		} else {
			$this->data['shi_p'] = $this->config->get('shi_p');
		}
		
		if (isset($this->request->post['shi_p_free'])) {
			$this->data['shi_p_free'] = $this->request->post['shi_p_free'];
		} else {
			$this->data['shi_p_free'] = $this->config->get('shi_p_free');
		}
		
		if (isset($this->request->post['hoku_p'])) {
			$this->data['hoku_p'] = $this->request->post['hoku_p'];
		} else {
			$this->data['hoku_p'] = $this->config->get('hoku_p');
		}
		
		if (isset($this->request->post['hoku_p_free'])) {
			$this->data['hoku_p_free'] = $this->request->post['hoku_p_free'];
		} else {
			$this->data['hoku_p_free'] = $this->config->get('hoku_p_free');
		}
		
		if (isset($this->request->post['tou_p'])) {
			$this->data['tou_p'] = $this->request->post['tou_p'];
		} else {
			$this->data['tou_p'] = $this->config->get('tou_p');
		}
		
		if (isset($this->request->post['tou_p_free'])) {
			$this->data['tou_p_free'] = $this->request->post['tou_p_free'];
		} else {
			$this->data['tou_p_free'] = $this->config->get('tou_p_free');
		}
		
		if (isset($this->request->post['ki_p'])) {
			$this->data['ki_p'] = $this->request->post['ki_p'];
		} else {
			$this->data['ki_p'] = $this->config->get('ki_p');
		}
		
		if (isset($this->request->post['ki_p_free'])) {
			$this->data['ki_p_free'] = $this->request->post['ki_p_free'];
		} else {
			$this->data['ki_p_free'] = $this->config->get('ki_p_free');
		}
		
		if (isset($this->request->post['chu_p'])) {
			$this->data['chu_p'] = $this->request->post['chu_p'];
		} else {
			$this->data['chu_p'] = $this->config->get('chu_p');
		}
		
		if (isset($this->request->post['chu_p_free'])) {
			$this->data['chu_p_free'] = $this->request->post['chu_p_free'];
		} else {
			$this->data['chu_p_free'] = $this->config->get('chu_p_free');
		}
		
		if (isset($this->request->post['shiko_p'])) {
			$this->data['shiko_p'] = $this->request->post['shiko_p'];
		} else {
			$this->data['shiko_p'] = $this->config->get('shiko_p');
		}
		
		if (isset($this->request->post['shiko_p_free'])) {
			$this->data['shiko_p_free'] = $this->request->post['shiko_p_free'];
		} else {
			$this->data['shiko_p_free'] = $this->config->get('shiko_p_free');
		}
		
		if (isset($this->request->post['kyu_p'])) {
			$this->data['kyu_p'] = $this->request->post['kyu_p'];
		} else {
			$this->data['kyu_p'] = $this->config->get('kyu_p');
		}
		
		if (isset($this->request->post['kyu_p_free'])) {
			$this->data['kyu_p_free'] = $this->request->post['kyu_p_free'];
		} else {
			$this->data['kyu_p_free'] = $this->config->get('kyu_p_free');
		}
		
		if (isset($this->request->post['oki_p'])) {
			$this->data['oki_p'] = $this->request->post['oki_p'];
		} else {
			$this->data['oki_p'] = $this->config->get('oki_p');
		}
		
		if (isset($this->request->post['oki_p_free'])) {
			$this->data['oki_p_free'] = $this->request->post['oki_p_free'];
		} else {
			$this->data['oki_p_free'] = $this->config->get('oki_p_free');
		}
		
		if (isset($this->request->post['japan_post_status'])) {
			$this->data['japan_post_status'] = $this->request->post['japan_post_status'];
		} else {
			$this->data['japan_post_status'] = $this->config->get('japan_post_status');
		}
		
		if (isset($this->request->post['japan_post_sort_order'])) {
			$this->data['japan_post_sort_order'] = $this->request->post['japan_post_sort_order'];
		} else {
			$this->data['japan_post_sort_order'] = $this->config->get('japan_post_sort_order');
		}				
		
		$this->template = 'shipping/japan_post.tpl';
		$this->children = array(
			'common/header',	
			'common/footer'	
		);
		
		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
	}
	
	private function validate() {
		if (!$this->user->hasPermission('modify', 'shipping/japan_post')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		if (!$this->error) {
			return TRUE;
		} else {
			return FALSE;
		}	
	}
}
?>