<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Payment extends CI_Controller {
	

	private $cart_qty   = '' ;
	private $logged 	= 0  ;	
	private $user 		= '' ;
	

	public function __construct()
	{
		parent::__construct();
		
		$this->load->model(array('admin_model','Db_model'));
		
		$this->load->library(array('cart','user_loginfunctions'));
		
		$this->load->helper('basic_helper');
		
		$ic=0;
		foreach ($this->cart->contents() as $items):
		$ic++;
		
		endforeach;
		$this->cart_qty = ''.$ic.'';
		
		//if logged out, redirect to login page
		if($this->user_loginfunctions->checkloggedin()===FALSE)
		{
			redirect('User/login') ;
		}
		
		if($this->session->userdata('shop_user2'))
		{
			$this->load->library('encrypt') ;
			$this->user = $this->encrypt->decode($this->session->userdata('shop_user2')); 
			$this->logged = 1;
		}
		
	}
	
	public function index($order_id='')
	{
		$this->home();
	}
	
	public function home()
	{
		$data['cart_qty'] = $this->cart_qty;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		$data['c_page'] = 'home';
				
		$this->_home_inc($data);
	}
	
	
	private function _home_inc($data=array())
	{
		

		$data['cart_qty'] = $this->cart_qty;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		$data['error'] = '';
		$data['suc_msg'] = '';
		$data['c_page'] = 'shipaddress';
		
				$data['category']=$data['result'] = $this->Db_model->get_where_by_order('shop_category',array('gift'=>1),'order','asc') ;	
		$data['gift'] = $this->Db_model->get_where_by_order('shop_category',array('gift'=>2),'order','asc') ;
		
		//$data['category']=$data['result'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;	
		$data['subcate'] = $this->Db_model->get_all_by_order('shop_subcategory','id','desc') ;
		
 		$data['contactus'] = $this->Db_model->get_where_by_order('shop_contact',array('status'=>'1'),'id','desc') ;
		
	
		//$data['offer'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
		if($this->Db_model->get_all_by_order('shop_shipping','area','asc')!==FALSE)
		{
			$area_det = $this->Db_model->get_all_by_order('shop_shipping','area','asc');
		}
		else
		{
			$area_det = array() ;
		}
		
		$data['area_det'] = $area_det;
		
		
		$this->load->library('form_validation');
		
		/*$data = array(
					  
				
				'location_id' => $this->input->post('location_id'),
				'location_result' => $location_result,
				'area' => $this->input->post('area'),
				'area_det' => $area_det,
				'logged' => $this->logged,
				'suc_msg' => '',
				'c_page' => 'profile',
				);*/
		

		
		$ship_det = $this->Db_model->get_one('shop_shipdetails',array('user_id'=>$this->_userid(),'order_id'=>$order_id)) ;
		
		
		
		
	//print_r($ship_det);
		//$ship_det = $this->Db_model->get_all_by_order('shop_shipdetails','name','asc');
		
		
		//get details from databse for updation
		if($ship_det!==FALSE)
		{
			
		$data['first_name']=$ship_det->first_name;
		$data['address']=$ship_det->shaddress;
		$data['pin']=$ship_det->shpin;
		$data['area']=$ship_det->area;
		$data['landmark']=$ship_det->landmark;
		$data['city']=$ship_det->city;
		$data['state']=$ship_det->state;
		$data['tel']=$ship_det->tel;
		$data['mobile']=$ship_det->mobile;
		$data['name']=$ship_det->name;
		$data['shaddress']=$ship_det->shaddress;
		$data['shpin']=$ship_det->shpin;
		$data['shtel']=$ship_det->shtel;
		$data['shmobile']=$ship_det->shmobile;
		$data['area']=$ship_det->area;
		$data['landmark']=$ship_det->landmark;
		$data['gifts']=$ship_det->gifts;
		$data['giftmsg']=$ship_det->giftmsg;
		$data['ddate']=$ship_det->ddate;
		$data['dtime']=$ship_det->dtime;
		$data['order_id']=$ship_det->order_id;
		
		}
		
		if($this->input->post('submit'))
		{
$this->cart->destroy();

}
		
		
		
		$this->load->view('website/header',$data);
		$this->load->view('website/menu',$data);  
		$this->load->view('website/user_menu',$data);
		$this->load->view('website/payment',$data);
        $this->load->view('website/footer');
		
		
		
	}
	
	

	



	
	private function _userid()
	{
		$user_det = $this->Db_model->get_one('shop_checkoutusers',array('email'=>$this->user));//print_r($user_det);
		if($user_det!==FALSE)
			return $user_det->id ;
		else
			return '';
	}
	
	
		private function _maxorderid_plus_one()
	{
		if($this->Db_model->max_orderid()!==FALSE)
		{
			$det = $this->Db_model->max_orderid();
			$order_id = $det->order_id + 1 ;
		}
		else
		{
			$order_id = 1 ;
		}
		
		return $order_id ;
	}
	
	
	
	public function success()
	{
		

		$data['cart_qty'] = $this->cart_qty;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		$data['error'] = '';
		$data['suc_msg'] = '';
		$data['c_page'] = 'shipaddress';
		
				$data['category']=$data['result'] = $this->Db_model->get_where_by_order('shop_category',array('gift'=>1),'order','asc') ;	
		$data['gift'] = $this->Db_model->get_where_by_order('shop_category',array('gift'=>2),'order','asc') ;
		
		//$data['category']=$data['result'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;	
		$data['subcate'] = $this->Db_model->get_all_by_order('shop_subcategory','id','desc') ;
		
 		$data['contactus'] = $this->Db_model->get_where_by_order('shop_contact',array('status'=>'1'),'id','desc') ;
		
	
	
		//$this->load->view('website/base_header');
		//$this->load->view('website/menu',$data);
		//$this->load->view('website/about',$data);
		//$this->load->view('website/right');
		//$this->load->view('website/footer');
		$this->load->view('website/header',$data);
		$this->load->view('website/menu',$data);
		$this->load->view('website/success',$data);
		$this->load->view('website/footer');
	}
	
	
	
	public function failure()
	{
		
		

		$data['cart_qty'] = $this->cart_qty;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		$data['error'] = '';
		$data['suc_msg'] = '';
		$data['c_page'] = 'shipaddress';
		
				$data['category']=$data['result'] = $this->Db_model->get_where_by_order('shop_category',array('gift'=>1),'order','asc') ;	
		$data['gift'] = $this->Db_model->get_where_by_order('shop_category',array('gift'=>2),'order','asc') ;
		
		//$data['category']=$data['result'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;	
		$data['subcate'] = $this->Db_model->get_all_by_order('shop_subcategory','id','desc') ;
		
 		$data['contactus'] = $this->Db_model->get_where_by_order('shop_contact',array('status'=>'1'),'id','desc') ;
		
	
	
		//$this->load->view('website/base_header');
		//$this->load->view('website/menu',$data);
		//$this->load->view('website/about',$data);
		//$this->load->view('website/right');
		//$this->load->view('website/footer');
		$this->load->view('website/header',$data);
		$this->load->view('website/menu',$data);
		$this->load->view('website/failure',$data);
		$this->load->view('website/footer');
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	
	
	
	
	


	
	
}
