MMCT TEAM
Server IP : 162.214.80.37  /  Your IP : 216.73.216.68
Web Server : Apache
System : Linux sh013.webhostingservices.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : imyrqtmy ( 2189)
PHP Version : 8.2.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home2/imyrqtmy/public_html/agriba/function/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/imyrqtmy/public_html/agriba/function/ajax_function.php
<?php    
 	require_once '../includes/db-conn.inc.php';  
	
	$action = isset($_POST['action']) ? $_POST['action'] : ''; 
	switch($action) 
	{
		case 'addCart': 
		 	addCart($conn);
			break;
		case 'editCart': 
		 	  editCart($conn);
			break;
		case 'deleteCart': 
		 	  deleteCart($conn);
			break;			
		case 'deleteAllCart': 
		 	  deleteAllCart($conn);
			break;	
		case 'logout': 
		 	logout($conn);
			break;	
		case 'login': 
		 	login($conn);
			break;	
			case 'guestlogin': 
		 	guestlogin($conn);
			break;
// 		case 'autoLogin': 
// 		 	autoLogin($conn);
// 			break;	
	
			
		default :
		//header('Location: ../product_category.php');
	}
	

	
// 	function autoLogin($conn){
// 	$userid = $_POST['userid'];
// 	if(isset($_SESSION['customer_id'])){
// 		echo "2";
// 	}else{
// 		$sql=mysqli_query($conn,"select * from tbl_registration where id='$userid'") or die(mysqli_error($conn));
// 	    if(mysqli_num_rows($sql)>0)
// 	    { 
// 	    	$row=mysqli_fetch_array($sql);
// 	        $customerID 					= $row['id'];
// 			$_SESSION['customer_id'] 		= $row['id'];
// 			$_SESSION['customer_name'] 		= $row['name'];
// 			$_SESSION['customer_email'] 	= $row['email'];
// 			$_SESSION['customer_phone'] 	= $row['mobile'];  
// 	        echo '1'; 
// 	    }	
// 	}
    
    
// }
function addCart($conn)
{  
	// =====================Json Regarding variable  =====
	 $responsee=array();
	 $finalTotalRecordAry['data']=array();
	// =========================================
	if(isset($_SESSION['customer_id'])){
		$phone 		= $_SESSION['customer_phone'];
		$customerid = $_SESSION['customer_id'];
		$email 		= $_SESSION['customer_email'];
		// $cartkey    = $_SESSION['rand'];
		// $rand =rand(10000000,99999999);
		// 	$cartkey = $_SESSION['rand'] =$rand;
		if(isset($_SESSION['rand'])){
			$cartkey = $_SESSION['rand'];
	}else{
		$sqlt=mysqli_query($conn,"select * from tbl_order where customer_id='$customerid' and cart_status='0'") or die(mysqli_query($conn));
		if(mysqli_num_rows($sqlt)>0){
				$rowt = mysqli_fetch_assoc($sqlt);
				$cartkey = $rowt['order_id'];	
			}else{
				$rand =rand(100000000,999999999);
				$cartkey = $_SESSION['rand'] =$rand;
			}
		}
	}else{	
	if(isset($_SESSION['rand'])){
			$cartkey = $_SESSION['rand'];
		}else{
			$rand =rand(100000000,999999999);
			$cartkey = $_SESSION['rand'] =$rand;
		}
		$phone 		= "";
		$customerid = "0";
		$email 		= "";
	}	
	$quantity	= mysqli_real_escape_string($conn,$_POST['quantity']); 
	$price	= mysqli_real_escape_string($conn,$_POST['price']); 
	$productid	= mysqli_real_escape_string($conn,$_POST['productid']); 
	$sku	= mysqli_real_escape_string($conn,$_POST['sku']);
	$mrp	= mysqli_real_escape_string($conn,$_POST['mrp']);
	$size	= mysqli_real_escape_string($conn,$_POST['size']);
	$unit	= mysqli_real_escape_string($conn,$_POST['unit']);
	$varientid	= "TSST";
	$ordernote	= mysqli_real_escape_string($conn,$_POST['ordernote']);
	$vistingcarddetail	=mysqli_real_escape_string($conn,$_POST['vistingcarddetail']);
	$image1	=mysqli_real_escape_string($conn,$_POST['image1']);
  $image2	=mysqli_real_escape_string($conn,$_POST['image2']);
  $name	=mysqli_real_escape_string($conn,$_POST['name']);
  $mobile	=mysqli_real_escape_string($conn,$_POST['mobile']);
  $address	=mysqli_real_escape_string($conn,$_POST['address']);
  $email	=mysqli_real_escape_string($conn,$_POST['email']);

$sqlc=mysqli_query($conn,"select * from tbl_order where order_id='$cartkey' and cart_status='0'") or die(mysqli_error($conn));
	if(mysqli_num_rows($sqlc)>0){

		// ================ insert product in product details ===============

		$sqlc=mysqli_query($conn,"select * from tbl_order_details where order_id='$cartkey' and product_id='$productid' and sku='$sku'") or die(mysqli_error($conn));
		if(mysqli_num_rows($sqlc)>0){
			$sqladd = mysqli_query($conn,"update tbl_order_details set 
					sku='$sku',
					quanitity='$quantity',
					price='$price',
					mrp='$mrp',
					size='$size',
					unit='$unit',
					ordernote='$ordernote',
					vistingcarddetail='$vistingcarddetail',
					image1='$image1',
					image2='$image2',
					name='$name',
					mobile='$mobile',
					email='$email',
					address='$address',
					varientid='$varientid' where order_id = '$cartkey' and product_id ='$productid' and sku='$sku'") or die(mysqli_error($conn));
				if(mysqli_affected_rows($conn) > 0){}
					 $totalValue = getCartValue($conn,$cartkey);
					 $responsee['cart']=$totalValue;
					 $responsee['message']="Success";
					 $responsee['status']="1";
					 array_push($finalTotalRecordAry['data'],$responsee);
				     echo json_encode($finalTotalRecordAry);
					
			}else{
				$sqls="insert into tbl_order_details(order_id,product_id,quanitity,price,mrp,sku,size,varientid,unit,ordernote,vistingcarddetail,image1,image2,name,mobile,email,address) 
				values('$cartkey','$productid','$quantity','$price','$mrp','$sku','$size','$varientid','$unit','$ordernote','$vistingcarddetail','$image1','$image2','$name','$mobile','$email','$address')";
				if(mysqli_query($conn,$sqls) or die(mysqli_error($conn)))
				{
					$totalValue = getCartValue($conn,$cartkey);
					 $responsee['cart']=$totalValue;
					 $responsee['message']="Success";
					 $responsee['status']="1";
					 array_push($finalTotalRecordAry['data'],$responsee);
				     echo json_encode($finalTotalRecordAry);
				}
			}
			//===================================================================
			}else{
				$sql="insert into tbl_order(order_id,phone,email,order_status,cart_status,payment_status,customer_id) values('$cartkey','$phone','$email','1','0','1','$customerid')";
		if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
		{
		// ================ insert product in product details ===============
			$sqls="insert into tbl_order_details(order_id,product_id,quanitity,price,mrp,sku,size,varientid,unit,ordernote,vistingcarddetail,image1,image2,name,mobile,email,address) 
			values('$cartkey','$productid','$quantity','$price','$mrp','$sku','$size','$varientid','$unit','$ordernote','$vistingcarddetail','$image1','$image2','$name','$mobile','$email','$address')";
			if(mysqli_query($conn,$sqls) or die(mysqli_error($conn)))
			{
				 $totalValue = getCartValue($conn,$cartkey);
				 $responsee['cart']=$totalValue;
				 $responsee['message']="Success";
				 $responsee['status']="1";
				 array_push($finalTotalRecordAry['data'],$responsee);
			     echo json_encode($finalTotalRecordAry);
			}
			//===================================================================
		}
		else
		{
			echo "0";
		}
	}	
}




function getCartValue($conn,$orderid){
	
	$sqlc=mysqli_query($conn,"select * from tbl_order_details where order_id='$orderid'") or die(mysqli_query($conn));
	$totalValue = mysqli_num_rows($sqlc);
	return $totalValue;
}

function editCart($conn)
{  
	// =====================Json Regarding variable  =====
	 $responsee=array();
	 $finalTotalRecordAry['data']=array();
	// =========================================
	$quantity		= mysqli_real_escape_string($conn,$_POST['quantity']); 
	$cartitemid		= mysqli_real_escape_string($conn,$_POST['cartitemid']); 
	
	// ================ insert product in product details ===============
	$sqlc=mysqli_query($conn,"select * from tbl_order_details where id='$cartitemid'") or die(mysqli_error($conn));
	$rowc = mysqli_fetch_assoc($sqlc);
	$cartkey = $rowc['uid'];
	$size = $rowc['size'];
	if(mysqli_num_rows($sqlc)>0){
		$sqladd = mysqli_query($conn,"update tbl_order_details set 
			quanitity='$quantity' where id='$cartitemid' and size='$size' ") or die(mysqli_error($conn));
			if(mysqli_affected_rows($conn) > 0){}
			 $totalValue = getCartValue($conn,$cartkey);
			 $responsee['cart']=$totalValue;
			 $responsee['message']="Success";
			 $responsee['status']="1";
			 array_push($finalTotalRecordAry['data'],$responsee);
		     echo json_encode($finalTotalRecordAry);
	}else{
		 $totalValue = getCartValue($conn,$cartkey);
		 $responsee['cart']=$totalValue;
		 $responsee['message']="Success";
		 $responsee['status']="1";
		 array_push($finalTotalRecordAry['data'],$responsee);
	     echo json_encode($finalTotalRecordAry);
		
	}
	
	//===================================================================
	
}

function deleteCart($conn)
{
 	$id =isset($_POST['cartitemid'])? $_POST['cartitemid'] : "";
	
	
	//echo "value is ".$id;

	$del =	"delete from tbl_order_details where id = '$id' ";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
	
		echo "1";
	}
	else
	{
	
		echo "0";
	}
	
}

function logout($conn){
	session_destroy();
}
function login($conn){
	 $cemail		= mysqli_real_escape_string($conn,$_POST['txtemail']); 
	 $cpassword		= mysqli_real_escape_string($conn,$_POST['txtpassword']); 
	if(isset($_SESSION['rand'])){
		$cartkey = $_SESSION['rand'];
	}else{
		$cartkey ="";
	}
	$sql=mysqli_query($conn,"select * from tbl_registration where email='$cemail' and password='$cpassword' and login_type ='1'") or die(mysqli_error($conn));

	if(mysqli_num_rows($sql)>0)
	{

		$row=mysqli_fetch_array($sql);
		 extract($row);
		if($cpassword==$password && $cemail == $email){
		    
		  //  session_start(); 

		  	 
			$customerID 					= $row['id'];
			$_SESSION['customer_id'] 		= $row['id'];
			$_SESSION['customer_name'] 		= $row['name'];
			$_SESSION['customer_email'] 	= $row['email'];
			$_SESSION['customer_phone'] 	= $row['mobile'];

// 			$_SESSION['lasr_login_timestamp'] =time();
            
  //       if (!isset($_COOKIE["COOKEMAIL"])  && !isset($_COOKIE["COOKPASS"]) ){ 
  //       setcookie("COOKEMAIL",$email, time() + (86400 * 365), "/"); 
  //       setcookie("COOKPASS",$password, time() + (86400 * 365), "/"); 
		// }
			
		
			// ====================================

			$sqlc = mysqli_query($conn,"select * from tbl_order where order_id='$cartkey'") or die(mysqli_error($conn));
			if(mysqli_num_rows($sqlc)>0){
				
				$sqladd = mysqli_query($conn,"update tbl_order 
					set  customer_id= '$customerID' where order_id = '$cartkey'") or die(mysqli_error($conn));
	 			if(mysqli_affected_rows($conn) > 0)
	 			{
	 				echo "2";
	 			}
			}else{

				$sqlc = mysqli_query($conn,"select * from tbl_order where customer_id='$customerID' and cart_status='0'") or die(mysqli_error($conn));
				if(mysqli_num_rows($sqlc)>0){
					echo "1";
				}else{
					echo "1";	
				}
			}
			// ==================================

		}else{
			echo "222";
		}
	}else{
		echo "333";
	}
}

?>	 
	

MMCT - 2023