<?php
session_start();

require_once('functions.php');
require_once('dbconnection.php');
require_once('includes/init.php');

$password = $_SESSION['password'];
$admin_data = get_admin($conn, $password);
if ($password != $admin_data['password']) {
	header('location: login.php');
}
if ( !isset($_SESSION['password']) ) {
	header('location: login.php');
}
if ( empty( $admin_data ) ) header('location: login.php');

$pageTitle = 'Auto Pay Setting';

$data_file = "app-data.json";
$success = false ;

if ( isset($_POST['submit']) ) {
	$data = json_decode(file_get_contents($data_file), true) ?? array();
	$data = array_merge($data, $_POST);
	file_put_contents($data_file, json_encode($data, JSON_PRETTY_PRINT));
	snack ("success", "Success");
	$success = true ;
}

$app_data = json_decode(file_get_contents($data_file), true);

foreach( $app_data as $key => $val ) {
	$$key = $val;
}

?>
<!DOCTYPE html>
<html>
	<head>
		<title>Auto Pay Setting</title>
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=false, shrink-to-fit=no">
		<link rel="stylesheet" href="css/style.css">
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
		<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
	</head>
	<body class="bg-gray-200">
		<?php include("header.php") ?>
	<main>
	<div class="fr-container fr-lg pb-0">
	    <section>
				<div class="mx-2 col-sm">
				         <?php if ($success) :?>
				    <div class="alert alert-success">
                       <strong>Success!</strong> changes Saved.
                         </div>
                    <?php endif ?>
					<form class="py-3" action="" autocomplete="off" method="POST">
					
					<section class="row">
						<div class="form-group col-sm">
					   

					    <section class="row">
				
					<div class="form-group col-sm">
						<label>API Key</label>
						<input name="auto_server_key" value="<?= $auto_server_key ?? '' ?>" type="text" autocorrect="off" autocapitalize="none" class="form-control" required>
					</div>

					<div class="form-group col-sm">
						<label>API Username</label>
						<input name="auto_server_user" value="<?= $auto_server_user ?? '' ?>" type="text" autocorrect="off" autocapitalize="none" class="form-control" required>
					</div>
					</section>
					 <section class="row">
				
					<div class="form-group col-sm">
						<label>Recharge Amount (server)</label>
						<input name="auto_server_amount" value="<?= $auto_server_amount ?? '' ?>" type="number" autocorrect="off" autocapitalize="none" class="form-control" required>
						
					</div>
					
						
				</section>
				
				
					<section class="row">
					<div class="form-group col-sm">
						    	<label>Recharge User Auto</label>
							<select name="recharge_user_auto_server" class="form-control">
							<?php
								$op3 = ( $recharge_user_auto_server == 1 ) ? 'Enabled' : 'Disabled';
							?>
							<option value="<?= $recharge_user_auto_server ?? '' ?>" hidden><?= $op3 ?></option>
							<option value="1">Enabled</option>
							<option value="0">Disabled</option>
						</select> 
					
					
					<div class="form-group col-sm">
					</div>
					</section>
					<a href="https://alviappbuild.com/AlviPay.apk">অ্যাকাউন্ট করতে এখানে ক্লিক করুন</a>
					<p> Only Prepaid Method Allow</p>
 
 
					<button name="submit" type="submit" class="fab bg-primary material-icons border-0">done_all</button>
				</form>
				
				</div>
		</main>
		<?php include('footer.php') ?>
	</body>
</html>