<?php
require_once("dbconn.php");
require_once("phpFunctions.php");

$data_id = isset($_GET["data_id"]) ? $_GET["data_id"] : null;
$data_table = isset($_GET["data_table"]) ? $_GET["data_table"] : null;

$response = array(); 

// Whitelist of allowed table names
$allowed_tables = ["predata_ip", "predata_ew", "predata_fd", "predata_temp", "input_production", "egg_weight", "feed_delivery", "input_temp"]; // Replace with your actual table names

if (!in_array($data_table, $allowed_tables)) {
	die(json_encode(["status" => "error", "message" => "ipRowData - Table name not found."]));
}

$result = executeQuery($conn, "SELECT * FROM {$data_table} WHERE id = ?", "i", [$data_id]);

if ($result === false) { 
	throw new Exception("Error executing query: " . $conn->error);
} 

if ($result->num_rows > 0) {
	while($row = $result->fetch_assoc()) 
	{
		$response["id"] = $row["id"];
	}
} 

if (empty($response)) {
	echo json_encode(["status" => "error", "message" => "ipRowData - An error occurred while processing your request."]);
} else {
    echo json_encode($response);
}
?>