<?php









//user_action.php









include('db_con.php');




if (isset($_SESSION['user_id'])) {




		$user_type = $_SESSION['user_type'];




		$user_id = $_SESSION['user_id'];




		$user_name = $_SESSION['user_name'];




		$branch_id = $_SESSION['branch_id'];




		$branch_name = $_SESSION['branch_name'];




		$store_id = $_SESSION['store_id'];




    $store_name = $_SESSION['store_name'];




}else{




	header('Location: login');




	die();




}




$dated = date('Y-m-d');









if(isset($_POST['btn_action']))









{









	if($_POST['btn_action'] == 'Add')




	{




		




		




		$query = "




		INSERT INTO store (dated,store_name,city,country,status)




        VALUES (:dated, :store_name, :city, :country, :status)




    ";	




		$statement = $connect->prepare($query);




		$statement->execute(




			array(




          




          ':dated'             =>  $dated,




          ':store_name'          =>  trim($_POST["store_name"]),




          ':city'          =>  trim($_POST["city"]),




          ':country'          =>  trim($_POST["country"]),          




          ':status'       =>  trim($_POST["status"]),




          




          )




		);




		$result = $statement->fetchAll();




		if(isset($result))




		{




			echo 'New store Added';




		}




	}




	if($_POST['btn_action'] == 'fetch_single')




	{




		$query = "




		SELECT * FROM store WHERE store_id = :store_id";




		




		$statement = $connect->prepare($query);




		$statement->execute(




			array(




				':store_id'	=>	$_POST["store_id"]




			)




		);




		$result = $statement->fetchAll();




		foreach($result as $row)




		{




			




			




			//$output['dated']          =  $row['dated'];




          $output['store_name']          =  $row['store_name'];




         $output['city']          =  $row['city'];




          $output['country']          =  $row['country'];




          $output['status']       =  $row["status"];




          




		}




		echo json_encode($output);




	}




	if($_POST['btn_action'] == 'Edit')




	{




		




		




			$query = "




			UPDATE store SET




				dated = '".$dated."',




				store_name = '".$_POST["store_name"]."',




				city = '".$_POST["city"]."',




				country = '".$_POST["country"]."',													




				status = '".$_POST["status"]."'




				WHERE store_id = '".$_POST["store_id"]."'




			";




		




		$statement = $connect->prepare($query);




		$statement->execute();




		$result = $statement->fetchAll();




		if(isset($result))




		{




			echo 'store Details Edited';




		}




	}




	if($_POST['btn_action'] == 'delete')




	{




		$status = 'Inactive';




		if($_POST['status'] == 'Active')




		{




			$status = 'Inactive';




		}




		$query = "




		UPDATE store




		SET status = :status 




		WHERE store_id = :store_id




		";




		$statement = $connect->prepare($query);




		$statement->execute(




			array(




				':status'	=>	$status,




				':store_id'		=>	$_POST["store_id"]




			)




		);	




		$result = $statement->fetchAll();	




		if(isset($result))




		{




			echo 'store Status change to ' . $status;




		}




	}




}









?>