<?php
	include '../db/db.php';
	session_start();
	$log=htmlspecialchars(trim($_SESSION['user']), ENT_QUOTES, 'UTF-8');
	if (empty($log)) {
	     
	  $redirectUrl = "index.php";
	  echo "<script type=\"text/javascript\">";
	  echo "window.location.href = '$redirectUrl'";
	  echo "</script>";
		 
	}else{

	  $sqlu="SELECT * FROM details_of_users WHERE user='$log' and val='1'";
	  $resultu=mysqli_query($conn, $sqlu);
	  $countu=mysqli_num_rows($resultu);
	  
	if($countu==1){

	  $sqlc="SELECT * FROM details_of_users where user='$log'";
	  $resultc=mysqli_query($conn, $sqlc);
	  while ($rowc = mysqli_fetch_array($resultc)){
	  $name=$rowc['id'];
	}

	} else{
	  $redirectUrl = "index.php";
	  echo "<script type=\"text/javascript\">";
	  echo "window.location.href = '$redirectUrl'";
	  echo "</script>";

	}}


	if (array_key_exists('load_data', $_POST)) {
		/*echo $_POST['uname'];*/
		$sql = mysqli_query($conn, "SELECT rate_hold FROM currency_rate");
		$row = mysqli_fetch_assoc($sql);
		
		echo json_encode($row);
		//echo "In";
	}

	if (isset($_POST['txt_rate'])) {

		$rate=htmlspecialchars(trim($_POST['txt_rate']), ENT_QUOTES, 'UTF-8');

		$sql = "UPDATE currency_rate SET rate_hold='$rate'";
      	$result = mysqli_query($conn, $sql);
      	if ($sql) {
			echo "ok";
		}else{
			echo "error";
		}
	}

	if (isset($_POST['delivery_rate'])) {

		$rate=htmlspecialchars(trim($_POST['delivery_rate']), ENT_QUOTES, 'UTF-8');

		$sql = "UPDATE delivery_charge SET price='$rate'";
      	$result = mysqli_query($conn, $sql);
      	if ($sql) {
			echo "ok";
		}else{
			echo "error";
		}
	}
?>