<?php
session_start();
if (!isset($_SESSION['admin'])) {
    header("Location: index.php");
    exit();
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['amounts'])) {
    $amounts = $_POST['amounts'];
    $json_file = 'data/language_amounts.json';
    file_put_contents($json_file, json_encode($amounts, JSON_PRETTY_PRINT));
    header("Location: dashboard.php?success=1");
    exit();
} else {
    header("Location: dashboard.php?error=1");
    exit();
}
?>
