shell bypass 403

GrazzMean Shell

Uname: Linux server.thebazaar99.com 5.14.0-687.17.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Jun 22 07:21:26 EDT 2026 x86_64
Software: Apache
PHP version: 8.3.32 [ PHP INFO ] PHP os: Linux
Server Ip: 163.227.92.254
Your Ip: 216.73.217.24
User: gutlooks (1003) | Group: gutlooks (1005)
Safe Mode: OFF
Disable Function:
exec,passthru,shell_exec,system

name : Home.php
<?php 
class Home extends CI_Controller{
    
    public $CI = NULL;
    
    public function __construct()
    {
        parent::__construct();
        $this->load->model("Curd");
        $this->load->library('cart');
        $this->load->database();
        $this->load->helper('array');
        $this->CI = & get_instance();
    }
    function search_ajax(){
        $data = array('prod_id'=>'','id'=>'','label'=>'','value'=>'');
        $da = $this->input->get('term');
        $callback = $this->input->get('callback');
      $query2 = $this->db->query("SELECT * FROM `tb_product` WHERE title like '%$da%' or description like '%$da%' or pro_short like '%$da%'");
		if($query2->num_rows()>0){
		    echo "<ul class='sera'>";
            $data = array();
            foreach($query2->result() as $row){
                $url = base_url('home/product_detail/'.base64_encode($row->id));
                echo "<li><a href='$url'>$row->title</a></li>"; 
            }
            echo "</ul>";
		}   
    }
    function insert_product_review(){
        $ref_rul =$_SERVER['HTTP_REFERER'];
        if(isset($_SESSION['user_id'])){ 
            $user_id=$_SESSION['user_id'];
            $ddata = array('user_id'=>$user_id,
                'product'=>$this->input->post('product'),
                'product_id'=>$this->input->post('product_id'),
                'rating'=>$this->input->post('rating'),
                'review'=>$this->input->post('review'),
                'is_active'=>'N',
                'email_id'=>$this->input->post('email_id'),
                'name'=>$this->input->post('name')
                );
            $this->db->insert('rating_review',$ddata);
             echo "<script>  alert('Product Review');   window.location = '".$ref_rul."';</script>"; 
        }else{
             echo "<script>  alert('Some Error');   window.location = '".$ref_rul."';</script>"; 
        }
    }
    public function login(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
    	$this->load->view('home/frontend/login',$data);
    }
    public function register(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
    	$this->load->view('home/frontend/register',$data);
    }
    public function forgot_password(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
    	$this->load->view('home/frontend/forgot_password',$data);
    }
    public function index(){
    
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
//        $data['slider_res'] = $this->Curd->fetch_where_slider("tb_slider",array("name"),array("status"=>1),"DESC");
//        echo $this->db->last_query();
        $data['deals_category'] = $this->Curd->fetch_where_order_limit('tb_deals_of_month',array("*"),array("status"=>1),"asc",6);
        $data['featured_product'] = $this->Curd->inner_featured_Product("t1.featured_product=1"); 
//        echo $this->db->last_query();
        $data['exclusive_product'] = $this->Curd->inner_featured_Product("t1.exclusive_product=1"); 
        
        $data['testi'] = $this->Curd->fetch_where_order_limit('tb_testimonial', array("*"),array("status"=>1),"DESC",10);
        
    	$this->load->view('home/index',$data);
    }

    public function get_username(){
        $res=$this->Curd->fetch_where("tb_user",array("mobile","first_name","last_name"),array("id"=>$_SESSION["user_id"]));
        foreach($res as $row){
            $mobile = $row->mobile;
            $name = $row->first_name;  
        }
        if(empty($name)){
            return $mobile;   
        }else{
            return $name;  
        }
    }

    public function product_list($m_c_id,$c_id=null){
        $this->load->helper('cookie');
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $main_cat_id = base64_decode($m_c_id);
        $cat_id = base64_decode($c_id);
        set_cookie('main_cat_id',$main_cat_id,'3600');
        set_cookie('cat_id',$cat_id,'3600'); 
//        echo "<pre> main_cat ".$main_cat_id;
//        print_r( $data['main_cat']);
//          echo "</pre>";  echo "<pre>Cat=".$cat_id;
//        print_r( $data['cat']);
//           echo "</pre>"; 
       
        $data['main_cat_banner'] = $this->Curd->fetch_where("tb_main_category",array("image,name"),array("id"=>$main_cat_id));
        $data['subcat_filter'] = $this->Curd->fetch_where("tb_category",array("*"),array("main_cat_id"=>$main_cat_id));
        $data['weight_filter'] = $this->Curd->fetch_where_order("tb_weight",array("*"),array("status"=>1),'DESC');
        $this->load->view('home/product-list',$data);

    }

    public function product_detail($pro_id){
         $product_id = base64_decode($pro_id);
        if($this->Curd->inner_featured_Product("t1.id=$product_id")){
            $data['product_detail'] = $this->Curd->inner_featured_Product("t1.id=$product_id"); 
        }else{
            redirect(base_url()); 
        }
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));       
    	$this->load->view('home/product-detail',$data);
    }
public function repeat_to_cart(){
   $user_id = $_SESSION['user_id'];
        $product_price = $product_sale_price=''; 
        $product_id = $this->input->post('product_id');
        $product_weight = $this->input->post('product_weight');
        $product_qty = $this->input->post('product_qty'); 
        $delivery_charges = $this->input->post('delivery_charges'); 
        $this->db->where('id',$product_id); 
        $query =  $this->db->get('tb_product');
		if($query->num_rows()>0){
			foreach($query->result() as $ro){
			  $product_title = $ro->title;  
			  $product_sku= $ro->sku;  
			}
			$this->db->where('product_id',$product_id); 
			$this->db->where('weight',$product_weight); 
            $query1 =  $this->db->get('tb_product_price');
//            echo $this->db->last_query();
    		if($query1->num_rows()>0){
    			foreach($query1->result() as $ro1){
           $product_price = $ro1->price;
            $product_sale_price = $ro1->reg_sale_price;
           
    			}
    		}
    			$this->db->where('product_id',$product_id);  
            $query2 =  $this->db->get('tb_gallery');
    		if($query2->num_rows()>0){
    			foreach($query2->result() as $ro2){
            	$product_img = base_url('uploads/gallery/'.$ro2->name);
    			}
    		}
    	
		} 

        if(isset($_SESSION['user_token'])){
            $data = array("user_id"=>$_SESSION['user_id'],"product_id"=>$product_id,"title"=>$product_title,"image"=>$product_img,"sku"=>$product_sku,"weight"=>$product_weight,"price"=>$product_price,"sale_price"=>$product_sale_price,"qty"=>$product_qty);    
//            print_r($data);
//            die();
            $res = $this->Curd->fetch_where("tb_cart",array("id"),array("product_id"=>$product_id,"user_id"=>$_SESSION['user_id']));
            if($res==false){
                $this->Curd->insert("tb_cart",$data);
                $total_cart = $this->Curd->fetch_where_row_count("tb_cart",array("user_id"=>$user_id));
                echo json_encode(array("status"=>1,"total_cart"=>$total_cart,"msg"=>"Successfully added to cart"));
            }else{
                $this->Curd->array_update("tb_cart",$data,array("product_id"=>$product_id,"user_id"=>$_SESSION['user_id']));
                echo json_encode(array("status"=>2,"msg"=>"Successfully added to cart"));
            }
        }else{
      echo json_encode(array("status"=>0,"msg"=>"Successfully added to cart"));
        }
    }
function repeat_order_to_cart(){
      $user_id = $_SESSION['user_id'];
    $order_id = $this->input->post('order_id');
    $id = $this->input->post('id');
  $res = $this->Curd->fetch_where("tb_sub_order",array("*"),array("order_no"=>$order_id));
    if($res==true){
      foreach($res as $o_row){
  $res1 = $this->Curd->fetch_where("tb_product_price",array("*"),array("product_id"=>$o_row->product_id,'weight'=>$o_row->weight));
           if($res1==true){
              foreach($res1 as $row){
                 
              }
           }
$data = array('user_id'=>$user_id,'product_id'=>$o_row->product_id,'title'=>$o_row->title,'image'=>$o_row->image,'sku'=>$o_row->sku,'hsn_no'=>$o_row->hsn_no,'tax_per'=>$o_row->tax_per,'weight'=>$o_row->weight,'price'=>$row->price,'sale_price'=>$row->reg_sale_price,'qty'=>$o_row->qty);
   $this->Curd->insert("tb_cart",$data);
        }
   
  $total_cart = $this->Curd->fetch_where_row_count("tb_cart",array("user_id"=>$user_id));
echo json_encode(array("status"=>1,"total_cart"=>$total_cart,"msg"=>"Successfully added to cart"));
    }else{ 
      echo json_encode(array("status"=>0,"msg"=>"Successfully added to cart"));
    
    } 
}
public function repeat_order_to_cart_old(){
        $user_id = $_SESSION['user_id'];
        $product_price = $product_sale_price=''; 
        $product_id = $this->input->post('product_id');
        $product_weight = $this->input->post('product_weight');
        $product_qty = $this->input->post('product_qty'); 
        $delivery_charges = $this->input->post('delivery_charges'); 
        $this->db->where('id',$product_id); 
        $query =  $this->db->get('tb_product');
		if($query->num_rows()>0){
			foreach($query->result() as $ro){
			  $product_title = $ro->title;  
			  $product_sku= $ro->sku;  
			}
			$this->db->where('product_id',$product_id); 
			$this->db->where('weight',$product_weight); 
            $query1 =  $this->db->get('tb_product_price');
//            echo $this->db->last_query();
    		if($query1->num_rows()>0){
    			foreach($query1->result() as $ro1){
           $product_price = $ro1->price;
            $product_sale_price = $ro1->reg_sale_price;
           
    			}
    		}
    			$this->db->where('product_id',$product_id);  
            $query2 =  $this->db->get('tb_gallery');
    		if($query2->num_rows()>0){
    			foreach($query2->result() as $ro2){
            	$product_img = base_url('uploads/gallery/'.$ro2->name);
    			}
    		}
    	
		} 

        if(isset($_SESSION['user_token'])){
            $data = array("user_id"=>$_SESSION['user_id'],"product_id"=>$product_id,"title"=>$product_title,"image"=>$product_img,"sku"=>$product_sku,"weight"=>$product_weight,"price"=>$product_price,"sale_price"=>$product_sale_price,"qty"=>$product_qty);    
//            print_r($data);
//            die();
            $res = $this->Curd->fetch_where("tb_cart",array("id"),array("product_id"=>$product_id,"user_id"=>$_SESSION['user_id']));
            if($res==false){
                $this->Curd->insert("tb_cart",$data);
                $total_cart = $this->Curd->fetch_where_row_count("tb_cart",array("user_id"=>$user_id));
                echo json_encode(array("status"=>1,"total_cart"=>$total_cart,"msg"=>"Successfully added to cart"));
            }else{
                $this->Curd->array_update("tb_cart",$data,array("product_id"=>$product_id,"user_id"=>$_SESSION['user_id']));
                echo json_encode(array("status"=>2,"msg"=>"Successfully added to cart"));
            }
        }else{
      echo json_encode(array("status"=>0,"msg"=>"Successfully added to cart"));
        }
    }
    function cleans($string) {
   //$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
//  return preg_replace("/[a-zA-Z0-9]/", "", $string);
 return preg_replace("/[^a-zA-Z0-9\s!?.,\'\"]/", "", $string);
//   return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
    public function add_to_cart(){
        $product_id = $this->input->post('product_id');
        $product_weight_id = $this->input->post('product_weight_id');
        $product_title = $this->input->post('product_title');
        $product_title =$this->cleans($product_title); 
        $product_img = $this->input->post('product_img');
        $product_price = $this->input->post('product_price');
        $product_sale_price = $this->input->post('product_sale_price');
        $product_qty = $this->input->post('product_qty');
        $product_weight = $this->input->post('product_weight');
        $product_sku = $this->input->post('product_sku');
        $tax_per = $this->input->post('tax_per');
        $hsn_no = $this->input->post('hsn_no');
        $product_color = $this->input->post('product_color');
        $delivery_charges = $this->input->post('delivery_charges');

        if(isset($_SESSION['user_token'])){
             $user_id = $_SESSION['user_id'];
            $data = array("user_id"=>$_SESSION['user_id'],"hsn_no"=>$hsn_no,"tax_per"=>$tax_per,"product_id"=>$product_id,"title"=>$product_title,"image"=>$product_img,"sku"=>$product_sku,"product_color"=>$product_color,"weight"=>$product_weight,"price"=>$product_price,"sale_price"=>$product_sale_price,"qty"=>$product_qty);    
            $res = $this->Curd->fetch_where("tb_cart",array("id"),array("product_id"=>$product_id,"product_color"=>$product_color,"weight"=>$product_weight,"user_id"=>$_SESSION['user_id']));
            if($res==false){
                $this->Curd->insert("tb_cart",$data);
                $total_cart = $this->Curd->fetch_where_row_count("tb_cart",array("user_id"=>$user_id));
                echo json_encode(array("status"=>1,"total_cart"=>$total_cart,"msg"=>"Successfully added to cart"));
            }else{
                $this->Curd->array_update("tb_cart",$data,array("product_id"=>$product_id,"product_color"=>$product_color,"weight"=>$product_weight,"user_id"=>$_SESSION['user_id']));
                echo json_encode(array("status"=>2,"msg"=>"Successfully added to cart"));
            }
        }else{
            $p_w_id = $product_id."_".$product_weight_id."_".$product_color;
            $p_w_id = preg_replace('/\s+/', '', $p_w_id);
            $data = array("hsn_no"=>$hsn_no,"product_color"=>$product_color,"tax_per"=>$tax_per,"id"=>$p_w_id,"product_id"=>$product_id,"name"=>"$product_title","image"=>$product_img,"sku"=>$product_sku,"weight"=>$product_weight,"price"=>$product_price,"sale_price"=>$product_sale_price,"qty"=>$product_qty);
//             print_r($data);
            if($this->cart->insert($data)){
//                echo "Done";
                echo json_encode(array("status"=>1,"total_cart"=>count($this->cart->contents()),"msg"=>"Successfully added to cart"));
            }else{
//                 echo "Error";
               echo json_encode(array("status"=>0,"total_cart"=>count($this->cart->contents()),"msg"=>"Some Error"));  
            }
        }
    }
    public function colors_list(){
        $product_id = $this->input->post('product_id');
        $color_code = $this->input->post('color_code'); 
         $price_weight = $this->Curd->product_color_price_list($product_id,$color_code,'','asc'); 
//        $price_weight = $this->Curd->fetch_where_order_dynamic("tb_product_price",array("*"),array("product_id"=>$product_id,"color_id"=>$color_code),"ASC");
        foreach($price_weight as $p_row) {
           echo '<option '.$sle.' value="'.$p_row->weight.'&&'.$p_row->price.'&&'.$p_row->reg_discount.'&&'.$p_row->reg_sale_price.'&&'.$p_row->id.'&&'.$p_row->color_name.'">'.$p_row->weight.'</option>';
        }
}

    public function cart_update(){
        $qty=$this->input->post("qty");
        $rowid=$this->input->post("rowid");
        if(isset($_SESSION['user_token'])){
            if($this->Curd->array_update("tb_cart",array("qty"=>$qty),array("id"=>$rowid))){
                echo 1;    
            }
        }else{
            if($this->cart->update(array('rowid'=>$rowid,'qty'=>$qty))){
                echo 1;
            }
        }
    }

    function delete_cart(){ 
        $rowid = $this->input->post('row_id');
        if(isset($_SESSION['user_token'])){
            if($this->Curd->delete("tb_cart",array("id"=>$rowid))){
                echo 1;
            }else{
                echo 0;
            }
        }else{
            if($this->cart->remove($rowid)){
                echo 1;
            }else{
                echo 0;
            }
        }
        
    }
    function send_mail(){
     if($this->Curd->send_query()){
             echo "<script>  alert('Thank you for your Enquiry regarding our service.');   window.location = '".base_url('home/contact')."';</script>"; 
        }else{
 echo "<script>  alert('Some Error');   window.location = '".base_url('home/contact')."';</script>"; 
           
        }
   

    }
    function send_newsletter(){
     if($this->Curd->send_newsletter()){
             echo "<script>  alert('Thank you!');   window.location = '".base_url('home/contact')."';</script>"; 
        }else{
 echo "<script>  alert('Some Error');   window.location = '".base_url()."';</script>"; 
           
        }
   

    }

    public function cart(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        if(isset($_SESSION['user_token'])){
            $data['cart_res'] = $this->Curd->fetch_where("tb_cart",array("*"),array("user_id"=>$_SESSION['user_id']));
        }else{
            $data['cart_res'] = $this->cart->contents();
        }   
        
    	$this->load->view('home/cart',$data);
    }
    
    public function blog(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['blog'] = $this->Curd->fetch_where_order("tb_blog", array("*"), array("status"=>1), "DESC");
        $this->load->view('home/blog', $data);
    }

    public function blogdetail($id){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['blog'] = $this->Curd->fetch_where("tb_blog",array("*"),array("id"=>base64_decode($id)));

        $this->load->view('home/blogdetail', $data);
    }
    
    public function special_offer(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['offer'] = $this->Curd->fetch_where_order("tb_offer",array("*"),array("status"=>1),"ASC");
        $this->load->view('home/special-offer', $data);
    }
    
    
    public function about(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));

        $this->load->view('home/about', $data);
    }

    public function contact(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));

        $this->load->view('home/contact', $data);
    }

    public function terms(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));

        $this->load->view('home/terms', $data);
    }
    public function page_cnt(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $this->load->view('home/terms', $data);
    }
     

    public function privacy(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));

        $this->load->view('home/privacy', $data);
    }

    public function cancel(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));

        $this->load->view('home/cancel', $data);
    }
    function order_cancel_process(){
      
    		$id = $this->input->post('order_id');
		$status = $this->input->post('status');
		$order_no = $this->input->post('order_no');
		$mobile = $this->input->post('phone');
// 		$status ='0';
		if($this->Curd->array_update("tb_order",array("status"=>$status,"order_staus"=>'Cancelled by customer',"order_update"=>$this->Curd->getdate()),array("id"=>$id))){
	if($mobile) {
		$msdf ="Sorry! Your order No. $order_no couldn't be confirmed and has been cancelled. For more details contact us on 8209722282 See you again! -Gutlooks";
        $this->otpsms($mobile,$msdf,'1207162075295906989');  
	}
			echo 1;
		}else{
			echo 0;
		}
    }

    public function refund(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));

        $this->load->view('home/refund', $data);
    }

    public function checkout(){
        $this->security_guard_user();
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['cart_res'] = $this->Curd->fetch_where("tb_cart",array("*"),array("user_id"=>$_SESSION['user_id']));
        $data['login_info'] = $this->Curd->fetch_where('tb_user',array('*'),array('id'=>$_SESSION['user_id']));
        $data['del_address'] = $this->Curd->fetch_where("tb_delivery_address",array("*"),array("user_id"=>$_SESSION['user_id']));
    	$this->load->view('home/checkout',$data);
    }
    function guest_checkout(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['cart_res'] =  $this->cart->contents();
        // $data['login_info'] = $this->Curd->fetch_where('tb_user',array('*'),array('id'=>$_SESSION['user_id']));
        // $data['del_address'] = $this->Curd->fetch_where("tb_delivery_address",array("*"),array("user_id"=>$_SESSION['user_id']));
    	$this->load->view('home/guest_checkout',$data); 
    } 
    public function update_delivery_address(){
        $full_name = $this->input->post("full_name");
        $mobile = $this->input->post("mobile");
        $pincode = $this->input->post("pincode");
        $state = $this->input->post("state");
        $city = $this->input->post("city");
        $address = $this->input->post("address");
        $landmark = $this->input->post("landmark");
      
        $res = $this->Curd->fetch_where("tb_delivery_address",array("id"),array("user_id"=>$_SESSION['user_id']));
        if($res==true){
            if($this->Curd->array_update("tb_delivery_address",array("full_name"=>$full_name,"mobile"=>$mobile,"pincode"=>$pincode,"state"=>$state,"city"=>$city,"address"=>$address,"landmark"=>$landmark),array("user_id"=>$_SESSION['user_id']))){
                $this->session->set_flashdata('success_msg','<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Success ! </strong>Update Successfully</div>'); redirect('home/checkout');  
            }
        }else{
            if($this->Curd->insert("tb_delivery_address",array("user_id"=>$_SESSION['user_id'],"full_name"=>$full_name,"mobile"=>$mobile,"pincode"=>$pincode,"state"=>$state,"city"=>$city,"address"=>$address,"landmark"=>$landmark))){
                $this->session->set_flashdata('success_msg','<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Success ! </strong>Insert Successfully</div>');redirect('home/checkout');   
            }
        }   
    }

    public function generate_order(){
        $today = date("Y");
        $rand = strtoupper(substr(uniqid((sha1(time()))),0,6));
        $unique = "GL-".$today . $rand;
        return $unique;
    }

    public function thankyou1(){
        $this->security_guard_user();
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $this->load->view('home/thank-you',$data); 
    }
    public function thankyou(){
        $this->security_guard_user();
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $this->load->view('home/thank-you',$data); 
    }
     function insert_order($payment_method,$mobile,$order_price,$order_no){
        $guest_check = $this->input->post("guest_check");
        if($guest_check){
            $b_name = $this->input->post("b_name");
            $b_phone = $this->input->post("b_phone");
            $b_email = $this->input->post("b_email");
            $email = $this->input->post("email");
            $gstno = $this->input->post("gstno");
            $b_add = $this->input->post("b_add");
            $b_landmark = $this->input->post("b_landmark");
            $b_city = $this->input->post("b_city");
            $b_state = $this->input->post("b_state");
            $b_pincode = $this->input->post("b_pincode");
            $type = $this->input->post("type"); 
            $full_name = $this->input->post("full_name");
            $address = $this->input->post("address");
            $landmark = $this->input->post("landmark"); 
            $city = $this->input->post("city");
            $state = $this->input->post("state");
            $pincode = $this->input->post("pincode");
            $coupon_discount = $this->input->post("coupon_discount");
            $coupon_type = $this->input->post("coupon_type");
            $promo_code1 = $this->input->post("promo_code1");
            $shipping_charge = $this->input->post("shipping_charge");
            $cod_charge = $this->input->post("cod_charge"); 
        }else{
            $full_name=$b_name = $this->input->post("b_name");
            $b_phone = $this->input->post("b_phone");
            $email=$b_email = $this->input->post("b_email");           
            $gstno = $this->input->post("gstno");
            $address=$b_add = $this->input->post("b_add");
            $landmark=$b_landmark = $this->input->post("b_landmark");
            $city=$b_city = $this->input->post("b_city");
            $state=$b_state = $this->input->post("b_state");
            $pincode=$b_pincode = $this->input->post("b_pincode");
            $type = $this->input->post("type"); 
            
//            $full_name = $this->input->post("full_name");
//            $email = $this->input->post("email");
//            $address = $this->input->post("address");
//            $landmark = $this->input->post("landmark"); 
//            $city = $this->input->post("city");
//            $state = $this->input->post("state");
//            $pincode = $this->input->post("pincode");
            
            $coupon_discount = $this->input->post("coupon_discount");
            $coupon_type = $this->input->post("coupon_type");
            $promo_code1 = $this->input->post("promo_code1");
            $shipping_charge = $this->input->post("shipping_charge");
            $cod_charge = $this->input->post("cod_charge"); 
        }
       
        if(isset($_SESSION['user_id'])) {
            $user_id = $_SESSION['user_id'];}
        else { $user_id ="0";}
        if($this->Curd->insert("tb_order",array("user_id"=>$user_id,            
            "b_name"=>$b_name,"b_phone"=>$b_phone,"b_email"=>$b_email,"gstno"=>$gstno,"order_staus"=>'Processing',
            "b_add"=>$b_add,"b_landmark"=>$b_landmark,"b_city"=>$b_city,"b_state"=>$b_state,"b_pincode"=>$b_pincode,            
            "order_no"=>$order_no,"full_name"=>$full_name,"email"=>$email,"mobile"=>$mobile,"pincode"=>$pincode,"address"=>$address,
            "landmark"=>$landmark,"state"=>$state,"city"=>$city,"type"=>$type,"delivery_charges"=>$shipping_charge,
            "cod_charge"=>$cod_charge,"order_price"=>$order_price,"coupon_discount"=>$coupon_discount,
            "coupon_type"=>$coupon_type,
            "status"=>1,"pay_status"=>'Unpaid',"payment_method"=>$payment_method,"order_date"=>$this->Curd->getdate(),
            "order_update"=>$this->Curd->getdate()))){
            if($user_id){
                $res = $this->Curd->fetch_where("tb_cart",array("*"),array("user_id"=>$_SESSION['user_id']));  
                 if($res==true){
                     $i =0;
                     foreach($res as $row){
                         $i++;    
                         $this->Curd->insert("tb_sub_order",array("order_no"=>$order_no,"product_color"=>$row->product_color,"hsn_no"=>$row->hsn_no,"tax_per"=>$row->tax_per,"product_id"=>$row->product_id,"title"=>$row->title,"image"=>$row->image,"sku"=>$row->sku,"weight"=>$row->weight,"sale_price"=>$row->sale_price,"qty"=>$row->qty,"total_price"=>($row->sale_price*$row->qty),"status"=>1,"status_date"=>$this->Curd->getdate()));
                         $this->remove_inventory($row->qty,$row->weight,$row->product_id); 
                    }
                     $this->Curd->delete("tb_cart",array('user_id'=>$_SESSION['user_id']));
                 }
            }else{
//                ===================check Cart=
                if(count($this->cart->contents())>0){
                    foreach($this->cart->contents() as $row){
//                        $data = array("user_id"=>$_SESSION["user_id"],"hsn_no"=>$row['hsn_no'],"tax_per"=>$row['tax_per'],"product_id"=>$row['product_id'],"title"=>$row['name'],"image"=>$row['image'],"sku"=>$row['sku'],"weight"=>$row['weight'],"price"=>$row['price'],"sale_price"=>$row['sale_price'],"qty"=>$row['qty']);  
                        $this->Curd->insert("tb_sub_order",array("order_no"=>$order_no,"product_color"=>$row->product_color,"hsn_no"=>$row['hsn_no'],"tax_per"=>$row['tax_per'],"product_id"=>$row['product_id'],"title"=>$row['name'],"image"=>$row['image'],"sku"=>$row['sku'],"weight"=>$row['weight'],"sale_price"=>$row['sale_price'],"qty"=>$row['qty'],"total_price"=>($row['sale_price']*$row['qty']),"status"=>1,"status_date"=>$this->Curd->getdate()));
                    $this->remove_inventory($row['qty'],$row['weight'],$row['product_id']); 
                        
                    }
                    $this->cart->destroy();
                }  
            }
            if($coupon_type ==4) {
            $da = array('status'=>'2');
            $this->db->where('discount_type',$coupon_type);
            $this->db->where('promo_code',$promo_code1);
            $this->db->update('tb_coupon',$da);
            }
            if($payment_method =='COD'){
                $this->send_ordermail($order_no,$b_email,'Processing',$order_price);
            }
//            if($mobile){
//                $dt = date("Y-m-d");
//                $date_n =  date( "Y-m-d", strtotime( "$dt +7 day" ) );
//                
//                $msdf ="Received! Order No. $order_no of Rs. $order_price confirmed. We expect to deliver your order by $date_n. Thank You for shopping at Gutlooks!";
//               $this->otpsms($mobile,$msdf,'1207162022275237245');   
//            }
        }  
    }
    function insert_order_old($payment_method,$mobile,$order_price,$order_no){
        $guest_check = $this->input->post("guest_check");
        if($guest_check){
        $b_name = $this->input->post("b_name");
            $b_phone = $this->input->post("b_phone");
            $b_email = $this->input->post("b_email");
            $email = $this->input->post("email");
            $gstno = $this->input->post("gstno");
            $b_add = $this->input->post("b_add");
            $b_landmark = $this->input->post("b_landmark");
            $b_city = $this->input->post("b_city");
            $b_state = $this->input->post("b_state");
            $b_pincode = $this->input->post("b_pincode");
            $type = $this->input->post("type"); 
            $full_name = $this->input->post("full_name");
            $address = $this->input->post("address");
            $landmark = $this->input->post("landmark"); 
            $city = $this->input->post("city");
            $state = $this->input->post("state");
            $pincode = $this->input->post("pincode");
            $coupon_discount = $this->input->post("coupon_discount");
            $coupon_type = $this->input->post("coupon_type");
            $promo_code1 = $this->input->post("promo_code1");
            $shipping_charge = $this->input->post("shipping_charge");
            $cod_charge = $this->input->post("cod_charge"); 
        }else{
            $b_name = $this->input->post("b_name");
            $b_phone = $this->input->post("b_phone");
            $b_email = $this->input->post("b_email");
            $email = $this->input->post("email");
            $gstno = $this->input->post("gstno");
            $b_add = $this->input->post("b_add");
            $b_landmark = $this->input->post("b_landmark");
            $b_city = $this->input->post("b_city");
            $b_state = $this->input->post("b_state");
            $b_pincode = $this->input->post("b_pincode");
            $type = $this->input->post("type"); 
            $full_name = $this->input->post("full_name");
            $address = $this->input->post("address");
            $landmark = $this->input->post("landmark"); 
            $city = $this->input->post("city");
            $state = $this->input->post("state");
            $pincode = $this->input->post("pincode");
            $coupon_discount = $this->input->post("coupon_discount");
            $coupon_type = $this->input->post("coupon_type");
            $promo_code1 = $this->input->post("promo_code1");
            $shipping_charge = $this->input->post("shipping_charge");
            $cod_charge = $this->input->post("cod_charge"); 
        }
       
        if(isset($_SESSION['user_id'])) {
            $user_id = $_SESSION['user_id'];}
        else { $user_id ="0";}
        if($this->Curd->insert("tb_order",array("user_id"=>$user_id,            
            "b_name"=>$b_name,"b_phone"=>$b_phone,"b_email"=>$b_email,"gstno"=>$gstno,"order_staus"=>'Processing',
            "b_add"=>$b_add,"b_landmark"=>$b_landmark,"b_city"=>$b_city,"b_state"=>$b_state,"b_pincode"=>$b_pincode,            
            "order_no"=>$order_no,"full_name"=>$full_name,"email"=>$email,"mobile"=>$mobile,"pincode"=>$pincode,"address"=>$address,
            "landmark"=>$landmark,"state"=>$state,"city"=>$city,"type"=>$type,"delivery_charges"=>$shipping_charge,
            "cod_charge"=>$cod_charge,"order_price"=>$order_price,"coupon_discount"=>$coupon_discount,
            "coupon_type"=>$coupon_type,
            "status"=>1,"pay_status"=>'Unpaid',"payment_method"=>$payment_method,"order_date"=>$this->Curd->getdate(),
            "order_update"=>$this->Curd->getdate()))){
            if($user_id){
                $res = $this->Curd->fetch_where("tb_cart",array("*"),array("user_id"=>$_SESSION['user_id']));  
                 if($res==true){
                     $i =0;
                     foreach($res as $row){
                         $i++;    
                         $this->Curd->insert("tb_sub_order",array("order_no"=>$order_no,"hsn_no"=>$row->hsn_no,"tax_per"=>$row->tax_per,"product_id"=>$row->product_id,"title"=>$row->title,"image"=>$row->image,"sku"=>$row->sku,"weight"=>$row->weight,"sale_price"=>$row->sale_price,"qty"=>$row->qty,"total_price"=>($row->sale_price*$row->qty),"status"=>1,"status_date"=>$this->Curd->getdate()));
                         $this->remove_inventory($row->qty,$row->weight,$row->product_id); 
                    }
                     $this->Curd->delete("tb_cart",array('user_id'=>$_SESSION['user_id']));
                 }
            }else{
//                ===================check Cart=
                if(count($this->cart->contents())>0){
                    foreach($this->cart->contents() as $row){
//                        $data = array("user_id"=>$_SESSION["user_id"],"hsn_no"=>$row['hsn_no'],"tax_per"=>$row['tax_per'],"product_id"=>$row['product_id'],"title"=>$row['name'],"image"=>$row['image'],"sku"=>$row['sku'],"weight"=>$row['weight'],"price"=>$row['price'],"sale_price"=>$row['sale_price'],"qty"=>$row['qty']);  
                        $this->Curd->insert("tb_sub_order",array("order_no"=>$order_no,"hsn_no"=>$row['hsn_no'],"tax_per"=>$row['tax_per'],"product_id"=>$row['product_id'],"title"=>$row['name'],"image"=>$row['image'],"sku"=>$row['sku'],"weight"=>$row['weight'],"sale_price"=>$row['sale_price'],"qty"=>$row['qty'],"total_price"=>($row['sale_price']*$row['qty']),"status"=>1,"status_date"=>$this->Curd->getdate()));
                    $this->remove_inventory($row['qty'],$row['weight'],$row['product_id']); 
                        
                    }
                    $this->cart->destroy();
                }  
            }
            if($coupon_type ==4) {
            $da = array('status'=>'2');
            $this->db->where('discount_type',$coupon_type);
            $this->db->where('promo_code',$promo_code1);
            $this->db->update('tb_coupon',$da);
            }
         $this->send_ordermail($order_no,$b_email,'Processing',$order_price);
            if($mobile){
                $dt = date("Y-m-d");
                $date_n =  date( "Y-m-d", strtotime( "$dt +7 day" ) );
                
                $msdf ="Received! Order No. $order_no of Rs. $order_price confirmed. We expect to deliver your order by $date_n. Thank You for shopping at Gutlooks!";
               $this->otpsms($mobile,$msdf,'1207162022275237245');   
            }
        }  
    }
   
    function remove_inventory($qty,$weight,$product_id){
        $this->db->where('product_id',$product_id); 
        $this->db->where('weight',$weight); 
        $query1 =  $this->db->get('tb_product_price');
        if($query1->num_rows()>0){
            foreach($query1->result() as $ro1){
                $total_qty = $ro1->qty; 
                $live_st = $total_qty-$qty;
                $da4 = array('qty'=>$live_st);
                $this->db->where('product_id',$product_id); 
                $this->db->where('weight',$weight); 
                $this->db->update('tb_product_price',$da4);
             } 
         }
    }
   
    function send_ordermail($order_no,$b_email,$order_st,$order_price){
      
        $tol_pay=$cod_charge=$delivery_charges=$gr_total=0; 
         $this->db->or_where('order_no', $order_no);
        $query = $this->db->get('tb_order'); 
        if($query ->num_rows()> 0) { 
            foreach($query -> result() as $row)
            {   } 
        }
        $total_pay_amt = $row->order_price;
        $c_name = $row->b_name;
        $c_status=$row->order_staus; 
        
	  $or_temp = '<table class="table table-bordered" border="1" style="width:100%">
    <tr>
    <td>S.No.</td>
  <td colspan="3">Products</td>
  <!--td>HSN No.</td><td>SKU</td-->
  <td>Qty.</td>
  <td>Price</td>
  <td>Amount</td>
  <td>Tax %</td>
  <td>Tax Amount</td>
  <td>Net Amount</td>

    </tr>
    <tbody style="text-align:center;">';
        $p=0; $ta_amt1=$g_amt1=$n_total=0;
        $order_list = array();
         $order_list1 = array();
        $this->db->or_where('order_no', $order_no);
        $query = $this->db->get('tb_sub_order'); 
        if($query ->num_rows()> 0) { 
            foreach($query -> result() as $r2)
            {
                $order_list[] = array( "sku" => $r2->weight."-".$r2->sku,
                        "itemName" => $r2->title,
                        "quantity" => $r2->qty,
                        "price" => $r2->sale_price,
                        "itemLength" => '', 
                        "itemWidth" => '', 
                        "itemHeight"=> '', 
                        "itemWeight" => '' );
                        
             $order_list1[] = array( 
                        "name" => $r2->title,
                        "sku" => $r2->weight."-".$r2->sku,
                        "units" => $r2->qty,
                        "selling_price" => $r2->sale_price,
                        "discount" => '', 
                        "tax" => '',  
                        "hsn" => $r2->hsn_no );
                        
                 $pay_amt = round(($r2->sale_price*100)/( 100+$r2->tax_per ),2);
                $tx =round($pay_amt*$r2->tax_per/100,2); 
                
                $ta_amt = $tx*$r2->qty; 
                $g_amt = $pay_amt*$r2->qty;
                 $p++;
                $tol =$r2->sale_price * $r2->qty;
                $tol_pay +=$tol;
                $pro_co="";
                if($r2->product_color!="None"){
                       $pro_co="($r2->product_color)";
                }
                $or_temp.="<tr><td>$p</td>
                <td  colspan='3'>$r2->title ($r2->weight) $pro_co</td>
                <!--td>$r2->hsn_no</td><td>$r2->sku</td-->
                <td>$r2->qty</td> <td>Rs.$pay_amt</td>
                <td>Rs.$g_amt</td><td>$r2->tax_per</td>
                <td>Rs.$ta_amt</td>
                <td>Rs.$r2->total_price</td>
                </tr>";
                $ta_amt1= $ta_amt1+$ta_amt;
                    $g_amt1= $g_amt1+$g_amt;
                    $n_total = $n_total+$r2->total_price;
                     
            }
        }
        if($row->payment_method=='COD'){
              $gr_total = $tol_pay+$row->cod_charge+$row->delivery_charges;  
          
        }else{
         $gr_total = $tol_pay+$row->delivery_charges; 
        }
        $g_amt1 = $n_total-$row->coupon_discount;
          $pay_amt_3 = round(($g_amt1*100)/( 105 ),2);
        $ta_amt1 =round($pay_amt_3*5/100,2); 
$or_temp.='<tr> 
               	<td colspan="5">&nbsp;</td>
               	<td colspan="4">Total Product Value</td>
               	<td>Rs.  '.$n_total.'</td>
       </tr>					
            <tr>
                  <td colspan="5">&nbsp;</td>
                  <td colspan="4">Discount Amount</td>
                  <td >Rs. '.$row->coupon_discount.'</td>
              </tr> 
               <tr>
                  <td colspan="5">&nbsp;</td>
                  <td colspan="4">Net Total Amount</td>
                  <td >Rs. '.$g_amt1.'</td>
              </tr>  
               <tr>
                  <td colspan="5">&nbsp;</td>
                  <td colspan="4">Total Taxable Value</td>
                  <td >Rs. '.$pay_amt_3.'</td>
              </tr>   ';
        if(strtolower($row->b_state)=='delhi') {
          	$or_temp.='   <tr> 
               <td colspan="5">&nbsp;</td>
               	<td colspan="4">CGST Amount</td>
               	<td>Rs.   '.round($ta_amt1/2,2).'</td>
       </tr>';  
       	$or_temp.='   <tr> 
               <td colspan="5">&nbsp;</td>
               	<td colspan="4">SGST Amount</td>
               	<td>Rs.   '.round($ta_amt1/2,2).'</td>
       </tr>';  
        }else{
     	$or_temp.='   <tr> 
               <td colspan="5">&nbsp;</td>
               	<td colspan="4">IGST Amount</td>
               	<td>Rs.   '.$ta_amt1.'</td>
       </tr>';  
        }
        $or_temp.='   <tr> 
               <td colspan="5">&nbsp;</td>
               	<td colspan="4">Shipping Charge</td>
               	<td>Rs.   '.$row->delivery_charges.'</td>
       </tr>';  
       if($row->payment_method=='COD') {	$or_temp.='   <tr> 
               <td colspan="5">&nbsp;</td>
               	<td colspan="4">COD Charge</td>
               	<td>Rs.   '.$row->cod_charge.'</td>
       </tr>';
       }
				   				   				  
		  $or_temp.= '<tr> 
               	<td colspan="5">&nbsp;</td>
               	<td colspan="4">Total Invoice Value</td>
               	<td>Rs.   '.$total_pay_amt.'	</td>
       </tr>
    </tbody>
    </table>';
    $message ='<table border="0" cellspacing="0" cellpadding="0" style="max-width:750px;margin:auto;padding:20px;font-family:Future Standard;color:#424243;background-color:#ffffff">
            <tbody>
                <tr>
                    <td colspan="2" align="center">
<a href="https://gutlooks.com/" ><img style="height:100px;" src="https://gutlooks.com/images/gutlooks.jpeg"  ></a>
                    </td>               
                </tr>
                <tr>
                    <td colspan="2" style="padding-top:30px">
                        <p style="padding-top:20px;font-weight:400;font-size:16px;color:#424243;margin-bottom:0;line-height:20px;letter-spacing:0.4px">Hi, '.$row->b_name.'</p><p style="padding-top:20px;font-weight:400;font-size:16px;color:#424243;margin-bottom:0;line-height:20px;letter-spacing:0.4px"><span style="letter-spacing:0.4px">Thank you for placing an order with Gutlooks.</span></p>
                        <p style="font-weight:400;font-size:16px;color:#424243;margin-bottom:0;line-height:20px;letter-spacing:0.4px">Once confirmed, we will process your order and prepare it for dispatch. We would also like to assure you of the stringent safety checks and measures that we are observing, at our warehouse and for our employees. Some of these include:</p>
                        <ul style="font-weight:400;font-size:16px;color:#424243;margin-bottom:0;line-height:20px;letter-spacing:0.4px">
                            <li>Daily Temperature Checks of All Employees</li>
                            <li>Daily Sanitisation/ Fumigation of the warehouse premises</li>
                            <li>In-house Doctor stationed at the warehouse</li>
                            <li>Mandatory use of masks and gloves</li>
                            <li>Social Distancing- Employees working in shifts, with only one employee per worktable</li>
                            <li>Regular Announcements of Safety Measures</li>
                            <li>Contact-Less Delivery of Products</li>
                        </ul>
                        <br>
                        <p style="font-weight:400;font-size:16px;color:#424243;margin-bottom:0;line-height:20px;letter-spacing:0.4px">You will receive an E-mail and SMS notification with tracking details once the items are dispatched.</p>
                        <p style="font-weight:400;font-size:16px;color:#424243;margin-bottom:0;line-height:20px;letter-spacing:0.4px">In case of any queries, please go through our  <a href="https://gutlooks.com/home/contact" rel="noreferrer" target="_blank" >Contact Us</a> if you need any further help.</p>
                    </td>                   
                </tr>
                <tr>
                    <td>
                        <p style="padding-top:20px;font-weight:400;font-size:16px;color:#424243;margin-bottom:0;line-height:20px;letter-spacing:0.4px"><span style="letter-spacing:0.4px">Shipping Address:</span><br></p>
                        <p style="padding-top:20px;font-weight:400;font-size:16px;color:#424243;margin-bottom:0;line-height:20px;letter-spacing:0.4px">Mr/Ms, '.$row->b_name.'<br> '.$row->address.' <br>'.$row->landmark.' <br> City:'.$row->city.' State:'.$row->state.' Pincode:'.$row->pincode.' </p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <table style="border-collapse:collapse;width:750px">
    <tbody>
        <tr>
            <td colspan="5" align="center">
                                    <h2 style="background:#edeeef;color:#3e4142;padding:10px;margin-top:50px;font-size:20px;font-weight:400;letter-spacing:0.4px">ORDER SUMMARY</h2>
                            </td>
        </tr>
        <tr style="color:#404748;overflow:hidden;border-bottom:1px dotted #b2d4e3;height:40px">
            <td colspan="5" align="center">
                '.$or_temp.'
            </td>
         </tr>
                
            </tbody>
</table>
 
</td>
                </tr>
                
                <tr>
                    <td align="center">
                        <p>THANK YOU FOR SHOPPING WITH US</p>
                    </td>
                </tr>
            </tbody>
        </table>';
        // echo $b_email;
        // echo $message;
        // die();
        if($row->payment_method =='COD'){
     $payment_method="COD";
    $cod_charge =$row->cod_charge;
}else{
    $payment_method="Prepaid";
    $cod_charge =0;
}
         if($b_email){
             $o_date = date('Y-m-d');
             $data_11 = array(
                "orders" => array(
                    "0" => array(
                        "orderId" => $order_no,
                        "customerName" => $row->b_name,
                        "customerAddress" => $row->address,
                        "customerCity" => $row->city,
                        "customerPinCode" => $row->pincode,
                        "customerContact" => $row->mobile,
                        "orderType" => $payment_method,
                        "modeType" => "Lite-1kg",
                        "orderDate" => $o_date,
                        "package" => array( 
                            "itemLength" =>'' ,
                            "itemWidth" => '',
                            "itemHeight"=> '',
                            "itemWeight" => ''
                        ),
                        "skuList" => $order_list,
                        "totalValue" => $total_pay_amt,
                        "sellerAddressId" => 10144
                    )
                )
            );

$orderdtls = array(
"order_id"=>$order_no,
  "order_date"=>date('Y-m-d G:i'),
  "pickup_location"=>"Primary",
  "channel_id"=>"1786801",
  "comment"=>"Reseller: Book",
  "billing_customer_name"=>$row->b_name,
  "billing_last_name"=>"",
  "billing_address"=>$row->b_add,
  "billing_address_2"=>$row->b_landmark,
  "billing_city"=>$row->b_city,
  "billing_pincode"=>$row->b_pincode,
  "billing_state"=>$row->b_state,
  "billing_country"=>"India",
  "billing_email"=>$row->b_email,
  "billing_phone"=>$row->b_phone,
  "shipping_is_billing"=> true,
  "shipping_customer_name"=>$row->full_name,
  "shipping_last_name"=>"",
  "shipping_address"=>$row->address,
  "shipping_address_2"=>$row->landmark,
  "shipping_city"=>$row->city,
  "shipping_pincode"=>$row->pincode,
  "shipping_country"=>"India",
  "shipping_state"=>$row->state,
  "shipping_email"=>$row->email,
  "shipping_phone"=>$row->mobile,
  "order_items"=>$order_list1,
  "payment_method"=>$payment_method,
  "shipping_charges"=> $row->delivery_charges,
  "giftwrap_charges"=> 0,
  "transaction_charges"=> $cod_charge,
  "total_discount"=> 0,
  "sub_total"=> $g_amt1,
  "length"=> 10,
  "breadth"=> 15,
  "height"=> 20,
  "weight"=> '2.5');
              $this->sendEmail_3($b_email,$message,"Gutlooks - Your Order ID: $order_no ");
              $this->sendEmail_3("info@gutlooks.com",$message,"Gutlooks - Your Order ID: $order_no ");
            //   die(); 
         }
            }
 
 


   
    public function order_process1(){ 
       //print_r($_POST);die;
        $payment_method = $this->input->post("payment_method");
        $mobile = $this->input->post("b_phone");
        $order_price = $this->input->post("order_price");
        $order_no = $this->input->post("order_no");
        if($payment_method =='COD'){
            $this->insert_order($payment_method,$mobile,$order_price,$order_no);
             redirect('home/thankyou1');
        }else{
             $this->insert_order($payment_method,$mobile,$order_price,$order_no);
            if($payment_method =='PayUMoney'){
                //   die();
            //   $this->pay($order_no,$this->db->insert_id());
               ?>
            <form method="post" name='f1' id="payment-form" action="<?php echo base_url('payumoney/pay'); ?>">
                 <input type="hidden" name="txnid"  value="<?php echo $order_no; ?>">
                <input type="hidden" name="last_id"  value="<?php echo $this->db->insert_id(); ?>"> 
             <input type="hidden"  name="phone" value="<?php echo $mobile; ?>">
          <input type="hidden" name="amount" value="<?php echo $order_price; ?>">
         </form>        
        <script type="text/javascript">
                    document.f1.submit();
            </script>    
            <?php
            } else if($payment_method =='phonepe'){
                 ?>
            <form method="post" name='f1' id="payment-form" action="<?php echo base_url('phonepe/pay'); ?>">
              <input type="hidden" name="txnid"  value="<?php echo $order_no; ?>">
              <input type="hidden" name="last_id"  value="<?php echo $this->db->insert_id(); ?>"> 
             <input type="hidden"  name="phone" value="<?php echo $mobile; ?>">
             <input type="hidden" name="amount" value="<?php echo $order_price; ?>">
            
                
            </form>        
            <script type="text/javascript">
                    document.f1.submit();
            </script>     
            <?php
               
            }
            else if($payment_method == "cashfree"){
                $ch = curl_init();
                $jsone = array(
  "order_amount"=> $order_price,
  "order_currency"=> "INR",
  "customer_details"=> array(
    "customer_id"=> "USER123",
    "customer_name"=> "joe",
    "customer_email"=> "joe.s@cashfree.com",
    "customer_phone"=> "+919876543210"
  ),
  "order_meta"=> array( 
    "return_url"=> "https://b8af79f41056.eu.ngrok.io?order_id=order_123",
  )

);
      
                    
                    
$json = json_encode($jsone);
curl_setopt($ch, CURLOPT_URL, 'https://api.cashfree.com/pg/orders');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);

$headers = array();
$headers[] = 'X-Client-Secret: cfsk_ma_prod_9c6b360cd80259b118097cf3bd796e94_1747c468';
$headers[] = 'X-Client-Id: 72011254354ed7d1ea0209f811211027';
$headers[] = 'X-Api-Version: 2023-08-01';
$headers[] = 'Content-Type: application/json';
$headers[] = 'Accept: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
$data = json_decode($result, true);
$my = $data['payment_session_id'];

?>
    <style>
        body {
            margin: 0;
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background: linear-gradient(135deg, #6a11cb, #2575fc);
        }

        .payment-container {
            text-align: center;
            background: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2);
        }

        .payment-container h1 {
            font-size: 24px;
            color: #333;
        }

        .payment-container p {
            color: #666;
            font-size: 16px;
            margin: 10px 0 20px;
        }

        #payNowButton {
            padding: 15px 30px;
            font-size: 18px;
            font-weight: bold;
            color: white;
            background-color: #28a745;
            border: none;
            border-radius: 30px;
            cursor: pointer;
            box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.2);
            transition: all 0.3s ease;
        }

        #payNowButton:hover {
            background-color: #218838;
            box-shadow: 0px 15px 20px rgba(0, 0, 0, 0.3);
            transform: translateY(-3px);
        }

        #payNowButton:active {
            transform: translateY(2px);
            box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2);
        }
    </style>
     <div class="payment-container">
        <h1>Make a Payment</h1>
        <p>Pay securely to Gutlooks with Cashfree</p>
        <button id="payNowButton">Pay Now</button>
    </div>
<input type = "hidden" id = "ses_id" value = "<?=$my?>">
<!--<button type = "button" class = "btn btn-primary" id = "payNowButton">Pay Now</button>-->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://sdk.cashfree.com/js/v3/cashfree.js"></script>
<script>
 //document.f1.submit();
$("#payNowButton").click(function(){
   // alert("Sdgsd");
  var sess = $("#ses_id").val(); 
    //alert(sess);
    
    

    const cashfree = Cashfree({
    mode:"production" //or production
});
let checkoutOptions = {
    paymentSessionId: sess,
    redirectTarget: "_self" //optional ( _self, _blank, or _top)
}
console.log(checkoutOptions);
cashfree.checkout(checkoutOptions)
});
</script>
<?php                 }
            else{
            ?>
            <form method="post" name='f1' id="payment-form" action="<?php echo base_url('paytm/redirect'); ?>">
                <input type="hidden" id="ORDER_ID" tabindex="1" maxlength="20" size="20" name="ORDER_ID" autocomplete="off" value="<?php echo $order_no; ?>">
                 <input type="hidden" id="CUST_ID" tabindex="2" maxlength="12" size="12" name="CUST_ID" autocomplete="off" value="<?=mt_rand(1000,9999)?>"> 
                <input type="hidden" id="INDUSTRY_TYPE_ID" tabindex="4" maxlength="12" size="12" name="INDUSTRY_TYPE_ID" autocomplete="off" value="Retail">
                 <input type="hidden" id="CHANNEL_ID" tabindex="4" maxlength="12"size="12" name="CHANNEL_ID" autocomplete="off" value="WEB">
                <input type="hidden"  name="MSISDN" value="<?php echo $mobile; ?>"> 
       
                <input type="hidden" title="TXN_AMOUNT" tabindex="10" type="text" name="TXN_AMOUNT" value="<?php echo $order_price; ?>">
                <input value="Confirm Now" type="submit"  class="btn btn-success">
                <a href="<?php echo base_url('checkout'); ?>" class="btn btn-danger">Cancel Payment</a>
            </form>        
        <script type="text/javascript">
                    document.f1.submit();
            </script>    
            <?php
            }  
        }
           
    }
    
    
    
  
    public function order_process(){
        $this->security_guard_user();
        $payment_method = $this->input->post("payment_method");
        $mobile = $this->input->post("b_phone");
        $order_price = $this->input->post("order_price");
        $order_no = $this->input->post("order_no");
         //die();
        // $transaction_id = rand();
        if($payment_method =='COD'){
            $this->insert_order($payment_method,$mobile,$order_price,$order_no);
             redirect('home/thankyou');
        }else{
             $this->insert_order($payment_method,$mobile,$order_price,$order_no);
            
            if($payment_method =='PayUMoney'){
               
                 ?>
         <form method="post" name='f1' id="payment-form" action="<?php echo base_url('payumoney/pay'); ?>">
            <input type="hidden" name="txnid"  value="<?php echo $order_no; ?>">
            <input type="hidden" name="last_id"  value="<?php echo $this->db->insert_id(); ?>"> 
            <input type="hidden"  name="phone" value="<?php echo $mobile; ?>">
            <input type="hidden" name="amount" value="<?php echo $order_price; ?>">
                        
           </form>        
         <script type="text/javascript">
                    document.f1.submit();
            </script>     
            <?php
                
                // $this->pay($order_no,$this->db->insert_id()); 
            }else  if($payment_method =='razorpay'){
               
                 ?>
            <form method="post" name='f1' id="payment-form" action="<?php echo base_url('razorpay/pay'); ?>">
            <input type="hidden" name="txnid"  value="<?php echo $order_no; ?>">
            <input type="hidden" name="last_id"  value="<?php echo $this->db->insert_id(); ?>"> 
            <input type="hidden"  name="phone" value="<?php echo $mobile; ?>">
            <input type="hidden" name="amount" value="<?php echo $order_price; ?>">
            
                
            </form>        
            <script type="text/javascript">
                    document.f1.submit();
            </script>     
            <?php
            
             }else if($payment_method =='phonepe'){
                 ?>
            <form method="post" name='f1' id="payment-form" action="<?php echo base_url('phonepe/pay'); ?>">
              <input type="hidden" name="txnid"  value="<?php echo $order_no; ?>">
              <input type="hidden" name="last_id"  value="<?php echo $this->db->insert_id(); ?>"> 
             <input type="hidden"  name="phone" value="<?php echo $mobile; ?>">
             <input type="hidden" name="amount" value="<?php echo $order_price; ?>">
            
            </form>        
            <script type="text/javascript">
                    document.f1.submit();
            </script>     
            <?php
                // $this->pay($order_no,$this->db->insert_id()); 
            }
            else if($payment_method == "cashfree"){
                $ch = curl_init();
                $jsone = array(
  "order_amount"=> $order_price,
  "order_currency"=> "INR",
  "customer_details"=> array(
    "customer_id"=> "USER123",
    "customer_name"=> "joe",
    "customer_email"=> "joe.s@cashfree.com",
    "customer_phone"=> "+919876543210"
  ),
  "order_meta"=> array( 
    "return_url"=> "https://b8af79f41056.eu.ngrok.io?order_id=order_123",
  )

);
      
                    
                    
$json = json_encode($jsone);
curl_setopt($ch, CURLOPT_URL, 'https://api.cashfree.com/pg/orders');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);

$headers = array();
$headers[] = 'X-Client-Secret: cfsk_ma_prod_9c6b360cd80259b118097cf3bd796e94_1747c468';
$headers[] = 'X-Client-Id: 72011254354ed7d1ea0209f811211027';
$headers[] = 'X-Api-Version: 2023-08-01';
$headers[] = 'Content-Type: application/json';
$headers[] = 'Accept: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
$data = json_decode($result, true);
$my = $data['payment_session_id'];

?>
   <style>
        body {
            margin: 0;
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background: linear-gradient(135deg, #6a11cb, #2575fc);
        }

        .payment-container {
            text-align: center;
            background: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2);
        }

        .payment-container h1 {
            font-size: 24px;
            color: #333;
        }

        .payment-container p {
            color: #666;
            font-size: 16px;
            margin: 10px 0 20px;
        }

        #payNowButton {
            padding: 15px 30px;
            font-size: 18px;
            font-weight: bold;
            color: white;
            background-color: #28a745;
            border: none;
            border-radius: 30px;
            cursor: pointer;
            box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.2);
            transition: all 0.3s ease;
        }

        #payNowButton:hover {
            background-color: #218838;
            box-shadow: 0px 15px 20px rgba(0, 0, 0, 0.3);
            transform: translateY(-3px);
        }

        #payNowButton:active {
            transform: translateY(2px);
            box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2);
        }
    </style>
     <div class="payment-container">
        <h1>Make a Payment</h1>
        <p>Pay securely to Gutlooks with Cashfree</p>
        <button id="payNowButton">Pay Now</button>
    </div>
<input type = "hidden" id = "ses_id" value = "<?=$my?>">

<!--<button type = "button" class = "btn btn-primary" id = "but">-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://sdk.cashfree.com/js/v3/cashfree.js"></script>
<script>
$("#payNowButton").click(function(){
   // alert("Sdgsd");
  var sess = $("#ses_id").val(); 
    //alert(sess);
    
    

    const cashfree = Cashfree({
    mode:"production" //or production
});
let checkoutOptions = {
    paymentSessionId: sess,
    redirectTarget: "_self" //optional ( _self, _blank, or _top)
}
console.log(checkoutOptions);
cashfree.checkout(checkoutOptions)
});
</script>
<?php                 }
          else if($payment_method == "ccavenue")
          {?>
          <form method="post" name='f1' id="payment-form" action="<?php echo base_url('ccavenue/ccavRequestHandler'); ?>">
                  <input type="hidden" name="txnid"  value="<?php echo $order_no; ?>">
              <input type="hidden" name="last_id"  value="<?php echo $this->db->insert_id(); ?>"> 
             <input type="hidden"  name="phone" value="<?php echo $mobile; ?>">
             <input type="hidden" name="amount" value="<?php echo $order_price; ?>">
                
                
                <input type="hidden" name="tid"  value="<?php echo rand(); ?>">
                <input type="hidden" name="merchant_id" value="3687035">
                <input type = "hidden" name="order_id" value="<?php echo $order_no; ?>" /> 
                <input type="hidden" name="amount" value="<?php echo $order_price; ?>">
                <input type="hidden" name="currency" value="INR">
                  <input type="hidden"  name="redirect_url" value="<?php echo base_url('home/ccavResponseHandler');?>">
                  <input type="hidden"  name="cancel_url" value="<?php echo base_url('home/ccavResponseHandler');?>">
                  <input type="hidden" name = "language" value="EN">
               
            </form>        
           <script type="text/javascript">
                    document.f1.submit();
            </script> 
              
          <?php }
          
          else if($payment_method == "instamojo")
          {
            $this->load->view('main');
              
          }
          else
            {
            ?>
            <form method="post" name='f1' id="payment-form" action="<?php echo base_url('paytm/redirect'); ?>">
                <input type="hidden" id="ORDER_ID" tabindex="1" maxlength="20" size="20" name="ORDER_ID" autocomplete="off" value="<?php echo $order_no; ?>">
                <input type="hidden" id="CUST_ID" tabindex="2" maxlength="12" size="12" name="CUST_ID" autocomplete="off" value="<?php echo $_SESSION['user_id']; ?>">
                   <input type="hidden" name="udf2" value="<?php echo  $_SESSION['user_token'];?>" /> 
                  <input type="hidden" id="INDUSTRY_TYPE_ID" tabindex="4" maxlength="12" size="12" name="INDUSTRY_TYPE_ID" autocomplete="off" value="Retail">
                <input type="hidden" id="CHANNEL_ID" tabindex="4" maxlength="12"size="12" name="CHANNEL_ID" autocomplete="off" value="WEB">
                  <input type="hidden"  name="MSISDN" value="<?php echo $mobile; ?>">
                  <input type="hidden" title="TXN_AMOUNT" tabindex="10" type="text" name="TXN_AMOUNT" value="<?php echo $order_price; ?>">
                <input type="hidden" name="udf1" value="<?php echo  $_SESSION['user_id'];?>" />
                  <input type="hidden" name="udf2" value="<?php echo  $_SESSION['user_token'];?>" /> 
                <input value="Confirm Now" type="submit"  class="btn btn-success">
                <a href="<?php echo base_url('checkout'); ?>" class="btn btn-danger">Cancel Payment</a>
            </form>        
           <script type="text/javascript">
                    document.f1.submit();
            </script>    
            <?php
            }  
        }
           
    }

    public function profile(){
        $this->security_guard_user();
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['user_data'] = $this->Curd->fetch_where("tb_user",array("*"),array("id"=>$_SESSION['user_id']));
        $this->load->view('home/profile',$data);
    }
    
    
    public function ccavResponseHandler(){
        
         $this->load->view('ccavResponseHandler');
    }

    public function order(){
        $this->security_guard_user();
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['order_res'] = $this->Curd->fetch_where_order("tb_order",array("*"),array("user_id"=>$_SESSION['user_id']),"DESC");
    	$this->load->view('home/order',$data);
    }
    public function veiw_order(){
        $this->security_guard_user();
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['order_res'] = $this->Curd->fetch_where_order("tb_order",array("*"),array("user_id"=>$_SESSION['user_id'],"id"=>$this->uri->segment('3')),"DESC");
    	$this->load->view('home/veiw_order',$data);
    }

function specialoffer(){
     $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
//         $data['offer'] = $this->Curd->fetch_where_order("tb_coupon",array("*"),array("status"=>1),"ASC"); 
    	$this->load->view('home/specialoffer',$data);
}


function response(){
        $this->load->view('casefree_response');
    }
    
    
    public function wishlist(){
        $this->security_guard_user();
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['wishlist_res'] = $this->Curd->fetch_where('tb_wishlist',array("*"),array("user_id"=>$_SESSION['user_id']));
    	$this->load->view('home/wishlist',$data);
    }

    public function wishlist_process(){
        if(isset($_SESSION['user_id'])){
            $product_id = $this->input->post("product_id");
            $res = $this->Curd->fetch_where("tb_wishlist",array("product_id"),array("user_id"=>$_SESSION['user_id'],"product_id"=>$product_id));
            if($res==false){
                if($this->Curd->insert("tb_wishlist",array("user_id"=>$_SESSION['user_id'],"product_id"=>$product_id))){
                 echo 1;
                }
            }else{
                echo 2;
            }
            
        }else{
            echo 0;
        }
    }

    public function delete_wishlist(){
        $p_id = $this->input->post("product_id");
        if($this->Curd->delete("tb_wishlist",array("id"=>$p_id,"user_id"=>$_SESSION['user_id']))){
//            echo $this->db->last_query();
            echo json_encode(array("status"=>1,"total_cart"=>'0',"msg"=>"Successfully"));
//             $this->session->set_flashdata('success_msg','<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Success ! </strong>Delete Successfully</div>'); redirect('home/wishlist');     
        }else{
            echo 0;
        }
    }

    public function manage_address(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['del_address'] = $this->Curd->fetch_where("tb_delivery_address",array("*"),array("user_id"=>$_SESSION['user_id']));
    	$this->load->view('home/manage-address',$data);
    }

    public function add_address(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['del_address'] = $this->Curd->fetch_where("tb_delivery_address",array("*"),array("user_id"=>$_SESSION['user_id']));
        $this->load->view('home/add-address',$data);
    }

    public function update_user_address(){
        $full_name = $this->input->post("full_name");
        $mobile = $this->input->post("mobile");
        $pincode = $this->input->post("pincode");
        $state = $this->input->post("state");
        $city = $this->input->post("city");
        $address = $this->input->post("address");
        $landmark = $this->input->post("landmark");
        $GSTNo = $this->input->post("GSTNo");
        $type = $this->input->post("type");

        $res = $this->Curd->fetch_where("tb_delivery_address",array("id"),array("user_id"=>$_SESSION['user_id']));
        if($res==true){
            if($this->Curd->array_update("tb_delivery_address",array("full_name"=>$full_name,"mobile"=>$mobile,"GSTNo"=>$GSTNo,"pincode"=>$pincode,"state"=>$state,"city"=>$city,"address"=>$address,"landmark"=>$landmark,"type"=>$type),array("user_id"=>$_SESSION['user_id']))){
                $this->session->set_flashdata('success_msg','<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Success ! </strong>Update Successfully</div>'); redirect('home/manage_address');  
            }
        }else{
            if($this->Curd->insert("tb_delivery_address",array("user_id"=>$_SESSION['user_id'],"full_name"=>$full_name,"mobile"=>$mobile,"GSTNo"=>$GSTNo,"pincode"=>$pincode,"state"=>$state,"city"=>$city,"address"=>$address,"landmark"=>$landmark,"type"=>$type))){
                $this->session->set_flashdata('success_msg','<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Success ! </strong>Insert Successfully</div>');redirect('home/manage_address');   
            }
        }  
    }

    public function update_delivery_address_checkout(){
        $full_name = $this->input->post("full_name");
        $mobile = $this->input->post("mobile");
        $pincode = $this->input->post("pincode");
        $state = $this->input->post("state");
        $city = $this->input->post("city");
        $address = $this->input->post("address");
        $landmark = $this->input->post("landmark");
        $type = $this->input->post("type");
        $GSTNo = $this->input->post("GSTNo");
      
        $res = $this->Curd->fetch_where("tb_delivery_address",array("id"),array("user_id"=>$_SESSION['user_id']));
        if($res==true){
            if($this->Curd->array_update("tb_delivery_address",array("full_name"=>$full_name,"mobile"=>$mobile,"pincode"=>$pincode,"state"=>$state,"city"=>$city,"GSTNo"=>$GSTNo,"address"=>$address,"landmark"=>$landmark,"type"=>$type),array("user_id"=>$_SESSION['user_id']))){
                $this->session->set_flashdata('success_msg','<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Success ! </strong>Update Successfully</div>'); redirect('home/checkout');  
            }
        }else{
            if($this->Curd->insert("tb_delivery_address",array("user_id"=>$_SESSION['user_id'],"full_name"=>$full_name,"mobile"=>$mobile,"pincode"=>$pincode,"GSTNo"=>$GSTNo,"state"=>$state,"city"=>$city,"address"=>$address,"landmark"=>$landmark,"type"=>$type))){
                $this->session->set_flashdata('success_msg','<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Success ! </strong>Insert Successfully</div>');redirect('home/checkout');   
            }
        }  
    }

    public function delete_address($id){
        $address_id = base64_decode($id);
        if($this->Curd->delete("tb_delivery_address",array("id"=>$address_id))){
             $this->session->set_flashdata('success_msg','<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Success ! </strong>Delete Successfully</div>'); redirect('home/manage_address');     
        }else{
            echo 0;
        }
    }

     public function change_pwd(){
        $this->security_guard_user();
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $this->load->library(array("form_validation"=>"fv"));
        $this->load->view("home/change-password",$data);
    }

     public function change_pwd_process(){
        $this->load->library(array("form_validation"=>"fv"));
        $this->fv->set_error_delimiters("<span class='text-danger'>","</span>");
        $this->fv->set_rules("c_pwd","Current Password","trim|required");
        $this->fv->set_rules("new_pwd","New Password","trim|required|min_length[6]");
        $this->fv->set_rules("rpwd","Confirm Password","trim|required|matches[new_pwd]");
        if($this->fv->run()==false){
            $this->change_pwd();    
        }else{
            // echo "KKR==";
             $c_pwd=sha1($this->input->post('c_pwd'));   
        //   echo "===<br>";
            $new_pwd=sha1($this->input->post('new_pwd'));
            $rpwd=$this->input->post('rpwd');
            $res=$this->Curd->fetch_where('tb_user',array('pwd'),array('id'=>$_SESSION['user_id']));
            foreach ($res as $row){
                 $pwd=$row->pwd; 
            }
            if($pwd===$c_pwd){
                if($this->Curd->update('tb_user',array('pwd'=>$new_pwd),'id',$_SESSION['user_id'])){
                    $this->session->set_flashdata('success_msg','<div class="alert alert-success">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <strong>Success ! </strong> Password Update Succesfully</div>');
                redirect('home/change_pwd');
                }
        
            }else{
                    $this->session->set_flashdata('error_msg','<div class="alert alert-danger">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <strong>Failure ! </strong> Current Password Does Not Matchs</div>');
                redirect('home/change_pwd');
            }   
        }   
    }

    public function account($url=null){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        if($_SESSION['user_id']){
        $data['user_data'] = $this->Curd->fetch_where("tb_user",array("*"),array("id"=>$_SESSION['user_id']));
        }
        if(isset($_SESSION['user_token'])){
            $this->load->view('home/account',$data);    
        }else{
            redirect(base_url('home'));
        }
    }

   
 

 
 
        public function otpsms($mobiles,$message,$template_id)
        {
      
        }

    public function verify_otp(){
        $otp = $this->input->post('otp');
        if(isset($_SESSION['user_id'])){
            $res = $this->Curd->fetch_where("tb_user",array("otp"),array("id"=>$_SESSION['user_id']));
            if($res[0]->otp==$otp){
                if($this->Curd->array_update("tb_user",array("verify"=>1),array("id"=>$_SESSION['user_id']))){
                    $uid =$_SESSION['user_id'];
                $query2 = $this->db->query("SELECT * FROM `tb_user` WHERE id=$uid");
		if($query2->num_rows()>0){
                    foreach($query2->result() as $row){
                        $dda ='<div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin:auto;padding:20px;font-family:arial;background:#f5f5f5">
            <tbody>
                <tr>
                    <td align="center" valign="top">
                        <table border="0" cellpadding="0" cellspacing="0" width="600" style="border:1px solid #f5f5f5;background:white;padding:20px;margin-bottom:30px">
                            <tbody><tr align="center">
                                <td>
                                    <a href="https://gutlooks.com/"  target="_blank" ><img src="'.base_url('images/gutlooks.jpeg').'" title="Gutlooks" alt="Gutlooks" style="height:100px" class="CToWUd"></a>
                                </td>
                            </tr>
                        </tbody></table>
                    </td>
                </tr>
                <tr>
                    <td align="center" valign="top">
                        <table border="0" cellpadding="0" cellspacing="0" width="600" style="border-radius:6px;background-color:#ffffff">
                            <tbody><tr>
                                <td align="left" valign="top" style="line-height:150%;font-family:Helvetica;font-size:14px;color:#333333;padding:30px 20px">
                                    <p><span style="font-family:arial,helvetica neue,helvetica,sans-serif">Welcome and thank you for registering at Gutlooks! </span></p>
                                    <p><span style="font-family:arial,helvetica neue,helvetica,sans-serif">Your account has now been created and you can log in by using your email address and password by visiting our website or at the following URL: <a href="https://gutlooks.com/" rel="noreferrer" target="_blank"><b>Gutlooks</b></a></span></p>
                                    <p><span style="font-family:arial,helvetica neue,helvetica,sans-serif">Upon logging in, you will be able to access other services including reviewing past orders, editing your accout information and a lot more. </span></p>
                                    <p><span style="font-family:arial,helvetica neue,helvetica,sans-serif">Thanks, </span><br>
                                        Team Gutlooks                                        <br><br>
                                        <span style="font-size:12px">
                                            <span style="font-family:arial,helvetica neue,helvetica,sans-serif">
                                                <a href="https://gutlooks.com/" rel="noreferrer" target="_blank" ><img src="'.base_url('images/gutlooks.jpeg').'" title="Gutlooks" alt="Gutlooks" style="height:100px" class="CToWUd"></a>
                                            </span>
                                        </span>
                                    </p><p style="padding:0 0 10px 0">For your records, here is a copy of the information you submitted to us.</p>
                                    <ul style="display:block;margin:15px 20px;padding:0;list-style:none;border-top:1px solid #eee">
                                        <li style="display:block;margin:0;padding:5px 0;border-bottom:1px solid #eee"><strong>Phone:</strong> '.$row->mobile.'</li>
                                        <li style="display:block;margin:0;padding:5px 0;border-bottom:1px solid #eee"><strong>Email:</strong> <a href="mailto:'.$row->email.'" rel="noreferrer" target="_blank">'.$row->email.'</a></li>
                                                                                                                        
                                    </ul>
                                    <p style="padding:0 0 10px 0">You may also contact us at:<br>
                                        <a href="mailto:info@gutlooks.com" style="color:#fcc4ab" rel="noreferrer" target="_blank" >info@gutlooks.com</a></p>
                                <p></p></td>
                            </tr>
                        </tbody></table>
                    </td>
                </tr>
               
            </tbody>
        </table>
 </div>';
//$temp_msg = str_ireplace('#cust_d',$dda,  $d_temp);
                       if($this->sendEmail_3($row->email,$dda,"Gutlooks - Thank You for registering.")){ }  
                    }
		}
                     
                    $_SESSION["user_token"]=md5($_SESSION["user_id"]);
                    if(count($this->cart->contents())>0){
                        foreach($this->cart->contents() as $row){
                            $data = array("user_id"=>$_SESSION["user_id"],"hsn_no"=>$row['hsn_no'],"tax_per"=>$row['tax_per'],"product_id"=>$row['product_id'],"title"=>$row['name'],"image"=>$row['image'],"sku"=>$row['sku'],"weight"=>$row['weight'],"price"=>$row['price'],"sale_price"=>$row['sale_price'],"qty"=>$row['qty']);  
                            $cartExist = $this->Curd->fetch_where_row_count('tb_cart',array("user_id"=>$_SESSION['user_id'],"product_id"=>$row['id'])); 
                            if($cartExist==true){
                                $this->Curd->array_update('tb_cart',$data,array("user_id"=>$_SESSION["user_id"],"product_id"=>$row['product_id'],"weight"=>$row['weight']));
                            }else{
                                $this->Curd->insert('tb_cart',$data);
                            }    
                        }
                        $this->Curd->array_update('tb_cart',array('user_id'=>$_SESSION['user_id']),array('user_id'=>session_id()));
                    }
                    echo 1;
                }
            }else{
                echo 0;
            }  
        }else{
            echo 2;
        }
    }

    private function last_id(){
         $insert_id = $this->db->insert_id();
         return  $insert_id;
    }

    public function user_register(){
        $first_name = $this->input->post("first_name");
        $last_name = $this->input->post("last_name");
        $email = $this->input->post("email");
        $mobile = $this->input->post("mobile");
        $pwd = $this->input->post("pwd");
        $birthdate = $this->input->post("birthdate");
//        $birthdate = date('d-m-Y',strtotime($birt));
        $this->db->where('email',$this->input->post('email'));  
        $this->db->or_where('mobile', $this->input->post('mobile'));
        $query = $this->db->get('tb_user');
        if($query ->num_rows() > 0)
        {
            $return_url= base_url('home/register');
            echo "<script>alert('This Phone Number or Email is already Registered');"
            . "window.location.href='".$return_url."';</script>";  
//            echo json_encode(array("result"=>0,"msg"=>"This Phone Number or Email is already Registered")); 
        }else{
            $otp= mt_rand(1000, 9999);
            $data = array("first_name"=>$first_name,"last_name"=>$last_name,"email"=>$email,"mobile"=>$mobile,"pwd"=>sha1($pwd),"otp"=>$otp,"verify"=>1,"status"=>1,"created"=>$this->Curd->getdate(),"ip_address"=>$this->input->ip_address());
            if($this->Curd->insert("tb_user",$data)){
                $last_id = $this->last_id();
                $_SESSION["user_id"]=$last_id;
                $dda="Hi $first_name $last_name, Thank You for registering with Gutlooks. Your Password for registration is $pwd. Use this password to validate your login at website.";
//          
                if($this->sendEmail($email,$dda,"Gutlooks - Thank You for registering.")){
//                    echo json_encode(array("result"=>1,"msg"=>"User Verify OTP"));
                }
                  $return_url= base_url('home/login');
            echo "<script>alert('Thank You for registering.');"
            . "window.location.href='".$return_url."';</script>";  
                
            }else{
                echo json_encode(array("result"=>0,"msg"=>"Internal Problem"));
            }
        } 
    }
    public function user_register_old(){
        $first_name = $this->input->post("first_name");
        $last_name = $this->input->post("last_name");
        $email = $this->input->post("email");
        $mobile = $this->input->post("mobile");
        $pwd = $this->input->post("pwd");
        $birt = $this->input->post("birthdate");
        $birthdate = date('d-m-Y',strtotime($birt));
        $res=$this->Curd->fetch_where("tb_user",array("id"),array("mobile"=>$mobile));
        $otp= mt_rand(1000, 9999);
        if($res==false){
            $data = array("first_name"=>$first_name,"last_name"=>$last_name,"birthdate"=>$birthdate,"email"=>$email,"mobile"=>$mobile,"pwd"=>sha1($pwd),"otp"=>$otp,"verify"=>0,"status"=>1,"created"=>$this->Curd->getdate(),"ip_address"=>$this->input->ip_address());
            if($this->Curd->insert("tb_user",$data)){
                $last_id = $this->last_id();
                $_SESSION["user_id"]=$last_id;
                $message="Dear Customer, your OTP for registration is ".$otp." ";
//                $this->otpsms($mobile,$message);   
                if($mobile){
                  $msdf ="Hi $first_name $last_name, Thank You for registering with Gutlooks. Your OTP for registration is $otp. Use this password to validate your login at website.";
                $this->otpsms($mobile,$msdf,'1207162022235873780'); 
                }
                if($this->sendEmail($email,$message,"Gutlooks - Thank You for registering.")){
                    echo json_encode(array("result"=>1,"msg"=>"User Verify OTP"));
                }
            }else{
                echo json_encode(array("result"=>0,"msg"=>"Internal Problem"));
            }
        }else{
            $res = $this->Curd->fetch_where("tb_user",array("id","otp","status","verify"),array("mobile"=>$mobile));
            if($res[0]->status==1){
                if($res[0]->verify==0){
                    $_SESSION['user_id'] = $res[0]->id;
                    $message="Dear Customer, your OTP for registration is ".$res[0]->otp." ";
                     if($mobile){
                         $name =$res[0]->first_name." ".$res[0]->last_name;
                         $otp = $res[0]->otp;
                        $msdf ="Hi $name, Thank You for registering with Gutlooks. Your OTP for registration is $otp. Use this password to validate your login at website.";
                      $this->otpsms($mobile,$msdf,'1207162022235873780'); 
                      }
//                    $this->otpsms($mobile,$message); 
                     if($this->sendEmail($email,$message,"Gutlooks - Thank You for registering.")){
                        echo json_encode(array("result"=>1,"msg"=>"User Verify OTP"));
                     }
                }else{
                    echo json_encode(array("result"=>0,"msg"=>"User Already Exist"));
                }
            }else{
                echo json_encode(array("result"=>0,"msg"=>"Account has been blocked"));
            }
        }
        
    }

    public function logout(){
        session_destroy();
        redirect(base_url("home"));
    }
    
    

    

    public function user_login_process(){
        $userName = $this->input->post('userName');
        $pwd = $this->input->post('userPwd'); 
        $enPwd = sha1($pwd);
        $res = $this->Curd->fetch_where_custom('tb_user',array('id','first_name','last_name','status','otp','verify','mobile','email'),"(mobile='".$userName."' OR email='".$userName."') AND pwd='".$enPwd."'");
$name ="Customer";
        if($res==true){
            foreach($res as $row){
                $id=$row->id;
                $status=$row->status;
                $verify = $row->verify;
                $mobile = $row->mobile;
                $otp = $row->otp;
                $email = $row->email;
                $name = $row->first_name." ".$row->last_name;
            }
            $_SESSION["user_id"]=$id;
            if($status==1){
                if($verify==0){
                    if($mobile){
                        //  $name =; 
                        $msdf ="Hi $name, Thank You for registering with Gutlooks. Your OTP for registration is $otp. Use this password to validate your login at website.";
                      $this->otpsms($mobile,$msdf,'1207162022235873780'); 
                      }
                    $message="Dear $name, your OTP for registration is ".$otp." ";
//                    $this->otpsms($mobile,$message); 
                     if($this->sendEmail($email,$message,"Verification Code")){
                       
                     }
                      echo json_encode(array("result"=>2,"msg"=>"User Verify OTP"));   
                }else{
                    $_SESSION["user_token"]=md5($_SESSION["user_id"]);
                    if(count($this->cart->contents())>0){
                        foreach($this->cart->contents() as $row){
                            $data = array("user_id"=>$_SESSION["user_id"],"hsn_no"=>$row['hsn_no'],"tax_per"=>$row['tax_per'],"product_id"=>$row['product_id'],"title"=>$row['name'],"image"=>$row['image'],"sku"=>$row['sku'],"weight"=>$row['weight'],"price"=>$row['price'],"sale_price"=>$row['sale_price'],"qty"=>$row['qty']);  
                            $cartExist = $this->Curd->fetch_where_row_count('tb_cart',array("user_id"=>$_SESSION['user_id'],"product_id"=>$row['product_id'],"weight"=>$row['weight'])); 
                            if($cartExist==true){
                                $this->Curd->array_update('tb_cart',$data,array("user_id"=>$_SESSION["user_id"],"product_id"=>$row['product_id'],"weight"=>$row['weight']));
                            }else{
                                $this->Curd->insert('tb_cart',$data);
                            }    
                        }
                        $this->Curd->array_update('tb_cart',array('user_id'=>$_SESSION['user_id']),array('user_id'=>session_id()));
                    }
                    // echo json_encode(array("result"=>1,"msg"=>"Login Succesfully"));
                      $return_url= base_url('home/');
            echo "<script>alert('Logged Successfully');"
            . "window.location.href='".$return_url."';</script>";  
//                    echo json_encode(array("result"=>1,"msg"=>"Logged Successfully"));
                }
            }else{
                 $return_url= base_url('home/login');
            echo "<script>alert('Account has been blocked');"
            . "window.location.href='".$return_url."';</script>";  
//                echo json_encode(array("result"=>0,"msg"=>"Account has been blocked"));
            } 
        }else{
             $return_url= base_url('home/login');
            echo "<script>alert('Username Or Password Incorrect');"
            . "window.location.href='".$return_url."';</script>";  
//            echo json_encode(array("result"=>0,"msg"=>"Username Or Password Incorrect"));
        }
    }

    public function security_guard_user(){
        if(isset($_SESSION["user_token"])){
            if($_SESSION["user_token"]!=md5($_SESSION["user_id"])){
                redirect("home/");
            }
        }else{
            redirect("home/account");
        }
    }

     public function update_account(){
        $first_name = $this->input->post('first_name');
        $last_name = $this->input->post('last_name');
        $email = $this->input->post('email');
        $birthdate = date('d-m-Y',strtotime( $this->input->post('birthdate')));
        $mobile = $this->input->post('mobile');
        if($this->Curd->update("tb_user",array("first_name"=>$first_name,"last_name"=>$last_name,"birthdate"=>$birthdate,"email"=>$email),"id",$_SESSION['user_id'])){
            $this->session->set_flashdata('success_msg','<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Success ! </strong>Update Successfully</div>');
                redirect('home/account');
        }else{
            $this->session->set_flashdata('success_msg','<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Error ! </strong>Internal Problem</div>');
        }
    }

 
 

    public function generate_password($len, $set="")
        {
        $gen="";
        for($i=0;$i<$len;$i++)
        {
            $set = str_shuffle($set);
            $gen .= $set[0];
        }
        return $gen;
    }  

     public function forget_pwd_ajax(){
        $userName = $this->input->post("mobile");
        $res=$this->Curd->fetch_where_custom('tb_user',array('id','first_name','last_name','status','otp','verify','email','mobile'),"(mobile='".$userName."' OR email='".$userName."')");
        if($res==true){
            foreach($res as $row){
                $id = $row->id;
                $name = $row->first_name.' '.$row->last_name;
                $mobile = $row->mobile;
                $email = $row->email;
                $verify = $row->verify;
                $status = $row->status;
                $otp = $row->otp;
            }
            if($verify==1 && $status==1){
                $passcode=$this->generate_password(6,'0123456789');
                $en_pwd= sha1($passcode);
                if($this->Curd->update("tb_user",array("pwd"=>$en_pwd),"mobile",$mobile)){
                    $dda ='<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#f7f7f7" style="max-width:500px;margin:auto;padding:12px;font-family:arial;color:#565a5c;background-color:#f5f5f5;border:1px solid #e8e8e8">
            <tbody>
                <tr>
                    <td align="center">
                        <img src="'.base_url('images/gutlooks.jpeg').'" style="height:100px;" title="Gutlooks" alt="Gutlooks" class="CToWUd">
                        <hr style="border:none;border-bottom:1px solid #bbbbbb;margin-top:15px">
                    </td>
                </tr>
                <tr>
                    <td>
                        <h4 style="color:#222222">Hello <span>'.$name.'</span>,</h4>                    
                        <p style="font-size:18px;color:#222222">your new password for login is '.$passcode.'. We recommend you to change it after login with new password. </p>                        
                        
                        <p style="font-size:14px">Best Regards,<br>Team Gutlooks</p>
                    </td>
                </tr>
            </tbody>
        </table>';
                    // $dda = "Dear ".$name.", your new password for login is ".$passcode.". We recommend you to change it after login with new password. ";
//                    $this->otpsms($mobile,$message);
//                        $d_temp = $this->mailtemp();
//                         $message = str_ireplace('#cust_d',$dda,  $d_temp);
$send_data =0; 
                if($mobile){
                    $send_data+=1;
                  $msdf ="Dear $name, Your new password for login at our website is $passcode. We recommend you to change it after login with new password. Thank You!";
                    $this->otpsms($mobile,$msdf,'1207162175746506098'); 
                }
                    if($email) {
                        if($this->sendEmail_3($email,$dda,"Gutlooks - Password Reset")){
                           $send_data+=1;
                        }
                    }
                    if($send_data>0){
                 echo json_encode(array('result'=>1,'msg'=>'Password Successfully Sent on your Email & Mobile No.'));
                       
                    }
                }    
            }else if($verify==1 && $status==0){
                echo json_encode(array('result'=>2,'msg'=>'Account has been blocked'));
            }else if($verify==0 && $status==1){
                $_SESSION['user_id'] = $id;
                $dda = "Dear ".$name.", your otp for verify account is ".$otp.". We recommend you to change it after login with new password. ";
//                $this->otpsms($mobile,$message);
//                   $d_temp = $this->mailtemp();
//                       $message = str_ireplace('#cust_d',$dda,  $d_temp);
                if($mobile){
                  $msdf ="Hi $name, Thank You for registering with Gutlooks. Your OTP for registration is $otp. Use this password to validate your login at website.";
                $this->otpsms($mobile,$msdf,'1207162022235873780'); 
                }
                 if($email) {
                if($this->sendEmail($email,$dda,"Verification")){
                    echo json_encode(array('result'=>3,'msg'=>'Account is not verified'));
                } }
            }
            
        }else{
            echo json_encode(array('result'=>0,'msg'=>'User account not Exist'));
        }
    }
    public function check_promocode1(){
        $promo_code = $this->input->post("promo_code");
        $cat_val = $this->input->post("order_price");
        $date = $this->Curd->getdate(); 
        $res = $this->Curd->fetch_where("tb_coupon",array("*"),array("promo_code"=>$promo_code));
        // print_r($res);
        if($res==true){
            $res2 = $this->Curd->get_promo($promo_code);
            $min_value=0;
            if($res2==true){
                // print_r($res);
                foreach($res as $row){
                    $discount_type = $row->discount_type;
                    $discount = $row->discount;
                    $min_value =$row->min_value; 
                    $status =$row->status; 
                }
                
                if($status ==1){
                    // echo $cat_val."===KKR====".$min_value;
                    if($min_value <= $cat_val){
                        echo json_encode(array("status"=>1,"msg"=>"Promocode applied successfully","discount_type"=>$discount_type,"discount"=>$discount,"min_price"=>'0',"total_cart"=>$cat_val)); 
                     }else{
                         echo json_encode(array("status"=>2,"msg"=>"Promocode applicable on minimum cart value of Rs. ".$min_value));
                     }
                }else{
                  echo json_encode(array("status"=>2,"msg"=>"promo code already used"));   
                }
            }else{
                echo json_encode(array("status"=>2,"msg"=>"Promocode Expired"));
            }
        }else{
            echo json_encode(array("status"=>0,"msg"=>"Please enter a valid Promocode"));
        }
    }
    public function check_promocode(){
        $promo_code = $this->input->post("promo_code");
        $date = $this->Curd->getdate();
        $res = $this->Curd->fetch_where("tb_coupon",array("*"),array("promo_code"=>$promo_code));
        $min_price = $this->Curd->min_price($_SESSION['user_id']);
        $total_cart_value = $this->Curd->total_cart_price($_SESSION['user_id']);
        $cat_val = intval($total_cart_value[0]->total_cart_value);
        if($res==true){
            $res2 = $this->Curd->get_promo($promo_code);
            if($res2==true){
                foreach($res as $row){
                    $discount_type = $row->discount_type;
                    $discount = $row->discount;
                    $min_value =$row->min_value; 
                    $status =$row->status; 
                }
                if($status ==1){
                    if($min_value<=$cat_val){
                        echo json_encode(array("status"=>1,"msg"=>"Promocode applied successfully","discount_type"=>$discount_type,"discount"=>$discount,"min_price"=>$min_price[0]->min_price,"total_cart"=>$min_price[0]->total_cart)); 
                     }else{
                         echo json_encode(array("status"=>2,"msg"=>"Promocode applicable on minimum cart value of Rs. ".$min_value));
                     }
                }else{
                  echo json_encode(array("status"=>2,"msg"=>"promo code already used"));   
                }
            }else{
                echo json_encode(array("status"=>2,"msg"=>"Promocode Expired"));
            }
        }else{
            echo json_encode(array("status"=>0,"msg"=>"Please enter a valid Promocode"));
        }
    }

    public function offer($id){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['main_cat_home'] = $this->Curd->fetch_where_order_limit("tb_main_category",array("*"),array("status"=>1),"ASC",6);
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $data['offer_res'] = $this->Curd->fetch_where("tb_offer",array("*"),array("id"=>base64_decode($id)));
        $this->load->view("home/offer",$data);
    }
    
    public function script(){
        $this->load->view('home/script');
    }
    
 

    public function contacts(){
        $data['main_cat'] = $this->Curd->fetch_where_order("tb_main_category",array("*"),array("status"=>1),"ASC");
        $data['cat'] = $this->Curd->fetch_where("tb_category",array("*"),array("status"=>1));
        $this->load->view('home/contacts',$data);
    }
        function mailtemp1(){
      $ds ='<div style=" width: 577px;    margin-left: 10%;     background: #fbfcfc;">
<table style="width:100%"> 
<tbody><tr style=" background: #fbfcfc;; "><td colspan="2" style="text-align:center;"><img src="'.base_url('images/gutlooks.jpeg').'" style="height:100px;padding-bottom: 9px;margin-bottom: 8px;"></td></tr>
<tr><td colspan="2" style="text-align:left;">
#cust_d
<p style="    margin: 2px 0px;    padding: 39px 15px;    background: #fbfcfc;    text-align: left;    border-radius: 11px; line-height: 23px;    text-align: justify;">
 
<br>
Thanks,<br><br>
Team  Gutlooks .

</p>
</td></tr>

<tr style=" 
    background: #fbfcfc; 
"><td colspan="2" style="text-align:left;"><img src="'.base_url('images/gutlooks.jpeg').'" style="height:100px;/* padding: 7px 15px; *//* background: #fbfcfc; */text-align: left;border-radius: 11px;"></td></tr>

<tr><td colspan="2" style="text-align:left;">
<p style=" 
    background: #fbfcfc;
    text-align: left;
    border-radius: 11px;
">For your records, here is a copy of the information you submitted to us.</p>

</td></tr> 

<tr><td colspan="2" style="text-align:left;">
<p style=" 
    background: #fbfcfc;
    text-align: left;
    border-radius: 11px;
">You may also contact us at:  info@gutlooks.com</p> 
</td></tr>
</tbody></table>





</div>';
return $ds;
    }
    function mailtemp(){
      $ds ='<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#f7f7f7" style="max-width:500px;margin:auto;padding:12px;font-family:arial;color:#565a5c;background-color:#f5f5f5;border:1px solid #e8e8e8">
            <tbody>
                <tr>
                    <td align="center">
                        <img src="'.base_url('images/gutlooks.jpeg').'" style="height:100px;" title="Gutlooks" alt="Gutlooks" class="CToWUd">
                        <hr style="border:none;border-bottom:1px solid #bbbbbb;margin-top:15px">
                    </td>
                </tr>
                <tr>
                    <td>
                       
                        <p style="font-size:14px"> #cust_d</p>
                    </td>
                </tr>
                <tr>
                    <td> 
                        <p style="font-size:14px">Best Regards,<br>Team Gutlooks</p>
                    </td>
                </tr>
            </tbody>
        </table> ';
return $ds;
    }
    
     function sendEmail_3($to_email,$msg,$subject){ 
       require_once(APPPATH.'third_party/class.phpmailer.php');   
       require_once(APPPATH.'third_party/class.smtp.php');
       $mail = new PHPMailer();
       $mail->isSMTP();
       $mail->Host = "gutlooks.com";
       $mail->SMTPAuth = true;
        $mail->SMTPSecure = 'ssl';
        $mail->Port = 465;
        $mail->Username = "info@gutlooks.com";
        $mail->Password = "AD#%#kP#5";
        $mail->AddAddress($to_email);
        $mail->SetFrom($mail->Username);
        $mail->isHTML(true);
        $mail->Subject   = $subject;
        $mail->Body = $msg; 
        if($mail->Send()){return true;}else {return false;}
        
    }
     function sendEmail($to_email,$msg,$subject){
        $d_temp = $this->mailtemp();
        $temp_msg = str_ireplace('#cust_d',$msg,  $d_temp); 
       require_once(APPPATH.'third_party/class.phpmailer.php');   
       require_once(APPPATH.'third_party/class.smtp.php');
       $mail = new PHPMailer();
       $mail->isSMTP();
       $mail->Host = "gutlooks.com";
       $mail->SMTPAuth = true;
        $mail->SMTPSecure = 'ssl';
        $mail->Port = 465;
        $mail->Username = "info@gutlooks.com";
        $mail->Password = "AD#%#kP#5";
        $mail->AddAddress($to_email);
        $mail->SetFrom($mail->Username);
        $mail->isHTML(true);
        $mail->Subject   = $subject;
        $mail->Body = $temp_msg; 
        if($mail->Send()){return true;}else {return false;}
        
    }
public function sendEmail_old1($to_email,$msg,$subject){
     $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        $headers .= "From: Gutlooks <info@gutlooks.com>\r\n";
//        $headers .= "Reply-To: info@gutlooks.com\r\n"; 
        if($to_email) {
            $d_temp = $this->mailtemp();
            $temp_msg = str_ireplace('#cust_d',$msg,  $d_temp);
        mail($to_email,$subject,$temp_msg,$headers);
         return true;
        }else{
            return false;
        } 
    }
    public function enquiry_process(){
        $this->load->library('email');
        $config['mailtype'] = 'html';
        $this->email->initialize($config);
        $name = $this->input->post("name");
        $email = $this->input->post("email");
        $mobile = $this->input->post("mobile");
        $message = $this->input->post("message");
        
        $subject= "Details from Enquiry by ".$name;
        $mail_body='
            <table width="500" border="0" align="left" cellpadding="5" cellspacing="0" style="border:1px #666666 solid;">
            <tr><td><table width="100%" cellspacing="0" cellpadding="5">
            <tr><td><strong> Name:</strong></td><td>'.$name.'</td></tr>
            <tr><td><strong> Email:</strong></td><td>'.$email.'</td></tr>
            <tr><td><strong> Mobile:</strong></td><td>'.$mobile.'</td></tr>
            <tr><td><strong> Message:</strong></td><td>'.$message.'</td></tr>
            </table>
            </td></tr>
            <tr>
            <td></td></tr>
            </table>';
            
        $from_email = $email; 
        $to_email = "info@gutlooks.com";
        $this->email->from($from_email, "Contact Form"); 
        $this->email->to($to_email);
        $this->email->subject($subject); 
        $this->email->message($mail_body); 
        $this->email->set_mailtype("html");
         //Send mail    
        if($this->email->send()){ 
            $this->session->set_flashdata("email_sent","<div class='alert alert-success'>Email sent successfully.</div>");
            redirect(base_url('home/contacts'));
         }else{ 
            $this->session->set_flashdata("email_sent","<div class='alert alert-danger'>Error in sending Email.</div>");
         } 
    }
     
    public function delivery_pincode_ajax(){
        $pincode = $this->input->post("pincode");
        $res = $this->Curd->fetch_where("locations",array("charge"),array("pincode"=>$pincode));
        if($res==true){
            foreach($res as $row){
                $charge = $row->charge;
            }
            $_SESSION['pincode'] = $pincode;
            $_SESSION['del_charges'] = 69;
            $_SESSION['delivery_duration'] = "Delivery Time 24 - 48 hours"; 
            $_SESSION['delivery_msg'] = "Available";
            echo json_encode(array("result"=>1,"delivery_charge"=>$charge,"msg"=>"Available","delivery_duration"=>"Delivery Time 24-48 Hours"));
        }else{
            $_SESSION['pincode'] = $pincode;
            $_SESSION['del_charges'] = 100;
            $_SESSION['delivery_duration'] = "Delivery Time is 4-5 Days";
            $_SESSION['delivery_msg'] = "Available";
            echo json_encode(array("result"=>0,"msg"=>"Available","delivery_duration"=>"Delivery Time is 4-5 Days"));
        }
    }
    
//     public function download_apk() {
//     $this->load->helper('download');
//     $file = './uploads/your_apk_file_name.apk'; // Path to the file
//     if (file_exists($file)) {
//         force_download($file, NULL);
//     } else {
//         show_404();
//     }
// }
    

}

?>
© 2026 GrazzMean