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



class Checkout extends MY_Controller {



    Public function __construct(){

        parent::__construct();

        $this->load->model("checkout_model","checkout");

    }

    public function shoppingCartPage()
    {
        $this->loadHtml("shopping-cart","Shopping Cart");
    }

	public function userCheckoutPage()
	{
        if(isset($_GET['dt']) && $_GET['dt']==1){
            $this->session->set_userdata('delivery_type',1);
            $this->session->set_userdata('delivery_charge',10);
        }else if(isset($_GET['dt']) && $_GET['dt']==0){
            $this->session->set_userdata('delivery_type',0);
            $this->session->set_userdata('delivery_charge',0);
        }
		$is_user_logged_in = $this->session->userdata('is_user_logged_in');
        $user_login_type = $this->session->userdata('user_login_type');

        if(!$this->cart->contents()){
            $this->session->set_flashdata("emessage",$this->lang->line("email_empty"));
            redirect(base_url("shopping-cart"));
        }

        if(!isset($is_user_logged_in) || $is_user_logged_in != true)
        {
            $this->loadHtml("checkout-login","Checkout Login Page");
            // redirect(base_url('user-login?redirect=1'));
        }else{
            if(isset($_GET['edit']) && $_GET['edit']==1){
                $this->profileid = $this->session->userdata('profileid');
                $data['userdata'] = $this->common->getsData('user',array('profileid'=>$this->profileid));
                $this->loadHtml("checkout-login","Checkout Page",$data);
            }else{
                $this->loadHtml("checkout","Checkout Page");
            }
        }
	}

    public function checkoutCheckEmail()
    {
        $data['login_email'] = $_POST['email'];
        $this->session->set_userdata('login_email',$_POST['email']);
        $data['userdata'] = $this->common->getsData('user',array('email'=>$_POST['email']));
        if($data['userdata']){
            $data['status'] = 1;
            $this->loadHtml("checkout-login","Checkout Page",$data);
        }else{
            $data['status'] = 2;
            $this->loadHtml("checkout-login","Checkout Page",$data);
        }
    }

    public function checkoutRegisterEmail()
    {
        $data['login_email'] = ((isset($_POST['email']) && $_POST['email']!='')?$_POST['email']:$this->session->userdata('login_email'));
        $data['userdata'] = $this->common->getsData('user',array('email'=>$data['login_email']));
        if($data['userdata']){
            $data['status'] = 1;
            $this->loadHtml("checkout-login","Checkout Page",$data);
        }else{
            $data['status'] = 3;
            $this->loadHtml("checkout-login","Checkout Page",$data);
        }
    }


	public function thankYouPage()
    {
        $orderid = $this->session->userdata("orderid");
        $this->load->model(A."/".A."_model","admin");
        $data['invoice'] = $this->admin->getOrders($orderid,1);
        $data['order_status'] = $this->common->getData("order_status");
        $data['cart'] = $this->common->getData("cart_mapping",array("orderid"=>$data['invoice']['orderid']),array(),array(),array("field"=>"cmid","by"=>"asc"));
        $this->loadHtml("thank-you","Thank You",$data);
    }
    

}