<?php
  include("../../conection.php");
session_start();

$result_mode = $_POST['result_mode'] ?? 1;
$manual_result = $_POST['manual_result'] ?? null;

if (!in_array($result_mode, [1,2,3])) {
  echo "Invalid mode!";
  exit;
}

if ($result_mode != 2) {
  $manual_result = null;
}

$q = mysqli_query($con, "SELECT id FROM meddolic_config_game_admin_settings LIMIT 1");
if (mysqli_num_rows($q) > 0) {
  mysqli_query($con, "UPDATE meddolic_config_game_admin_settings SET result_mode='$result_mode', manual_result=" . ($manual_result ? "'$manual_result'" : "NULL") . " LIMIT 1");
} else {
  mysqli_query($con, "INSERT INTO meddolic_config_game_admin_settings (result_mode, manual_result) VALUES ('$result_mode', " . ($manual_result ? "'$manual_result'" : "NULL") . ")");
}

echo "Settings updated successfully!";
?>
