<?php
    require('db_connection.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    // Generate unique id_router
    $id_router = uniqid('router_', true);

    // Mikrotik Data
    $dns = $_POST['dns'];
    $user_mikrotik = $_POST['user_mikrotik'];
    $password_mikrotik = $_POST['password_mikrotik'];
    $ip_mikrotik = $_POST['ip_mikrotik'];
    $mikrotik_port = $_POST['mikrotik_port'];

    // Payment Data
    $endpoint = $_POST['Endpoint'];
    $apiKey = $_POST['apiKey'];
    $privateKey = $_POST['privateKey'];
    $merchantCode = $_POST['merchantCode'];

    // Insert Mikrotik Data
    $queryMikrotik = "INSERT INTO mikrotik (id_router, dns, user_mikrotik, password_mikrotik, ip_mikrotik, mikrotik_port) VALUES (?, ?, ?, ?, ?, ?)";
    $stmtMikrotik = $db->prepare($queryMikrotik);
    $stmtMikrotik->bind_param('sssssi', $id_router, $dns, $user_mikrotik, $password_mikrotik, $ip_mikrotik, $mikrotik_port);

    if ($stmtMikrotik->execute()) {
        // Insert Payment Data with the generated id_router
        $queryPayment = "INSERT INTO payment_options (id_router, endpoint, apiKey, privateKey, merchantCode) VALUES (?, ?, ?, ?, ?)";
        $stmtPayment = $db->prepare($queryPayment);
        $stmtPayment->bind_param('sssss', $id_router, $endpoint, $apiKey, $privateKey, $merchantCode);

        if ($stmtPayment->execute()) {
            echo '<div class="alert alert-success" role="alert">Pendaftaran Mikrotik dan Payment berhasil.</div>';
        } else {
            echo '<div class="alert alert-danger" role="alert">Terjadi kesalahan: ' . $stmtPayment->error . '</div>';
        }
        $stmtPayment->close();
    } else {
        echo '<div class="alert alert-danger" role="alert">Terjadi kesalahan: ' . $stmtMikrotik->error . '</div>';
    }

    $stmtMikrotik->close();
    $db->close();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
	<meta name="Author" content="Acil" />
	<meta name="theme-color" content="#16ac91" />
	<meta name="msapplication-navbutton-color" content="#16ac91" />
	<meta name="apple-mobile-web-app-status-bar-style" content="#16ac91" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<link rel="icon" href="img/favicon.png" />
	<title>Registrasi</title>
	<link rel="stylesheet" href="css/all.min.css" />
	<link rel="stylesheet" href="css/style.css" />

	<style>
	input[type=checkbox]{
		width:auto;
		padding:5px 12px;
		margin:8px 0;
		display:inline-block;
		border:1px solid #ccc;
		box-sizing:border-box;
		text-align:left
	}
	a{ 
		color: #35aadc;
		text-decoration:none;
	}
	.toolbar a{ 
		color: #313131;
		text-decoration:none;
	}
	.content-writter p {
	max-width:47rem;
	font-family: 'Poppins', sans-serif;
	font-size: 14px; .'[ii'
	color: #000000;
	margin: 1rem auto;
	}
	.content-writter ul li{	
		
	font-family: 'Poppins', sans-serif;	
	max-width:44rem;
	font-size: 14px;
    list-style-type: number;
	color: #000000;
	display: list-item;	
	margin: 3px auto;
}

        .icon-big {
            font-size: 2em;
        }
        .icon-color-red { color: red; }
        .icon-color-green { color: green; }
        .icon-color-blue { color: blue; }
        .icon-color-yellow { color: yellow; }
        .icon-color-orange { color: orange; }
        .icon-color-purple { color: purple; }
        .icon-color-pink { color: pink; }
        .icon-color-brown { color: brown; }
        .icon-color-grey { color: grey; }
        

.registration-form {
            padding: 20px;
        }
        .form-section {
            border: 1px solid #ccc;
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 20px;
        }
</style>
</head>
<body>
	<div class="app-container">
		<div class="page page-home page-with-subnavbar">

		<header class="background-main">
			<div class="back-panel color-white"><i class="fas fa-chevron-left"></i></div>
			<h1 class="color-white margin-left-small">$(identity)</h1>

				<div class="header-right">
					<ul class="links">
						<li class="rad-dropdown"><a class="rad-menu-item" href="#"><i class="fas fa-bell"><span class="rad-menu-badge">1</span></i></a></li>
						<li>
							<ul class="rad-dropmenu-item"><li id="statusServer"></li></ul>
						</li>
					</ul>
				</div>
			</header> 
			<!-- end header -->
			<div class="border-radius-style background-main">
				<div class="container">
					<div class="padding-box-middle box-shadow background-white border-radius text-center">
						<h6 class="page-content paket-habis">
							<i class="fa fa fa-info-circle"></i>
							   Pendaftaran Mikrotik dan Payment
							</h6>
					 </div>
				   </div>
			</div> 

        <!--<div class="separator-small"></div>-->
				<div class="container">
 <div class="registration-form">
        <div class="margin-bottom-small">
            <form id="registrationForm" action="" method="post">
                
  <div class="row">
   <div class="col">
    					<div class="margin-bottom-small border-radius text-center background-white">
    						<h4 class="mb-3">Pendaftaran Mikrotik</h4>
    					 </div>
                        <div class="form-section background-white box-shadow">
                            <div class="form-group">
                                <label for="dns">DNS</label>
                                <input type="text" class="form-control" id="dns" name="dns" required>
                            </div>
                            <div class="form-group">
                                <label for="user_mikrotik">User Mikrotik</label>
                                <input type="text" class="form-control" id="user_mikrotik" name="user_mikrotik" required>
                            </div>
                            <div class="form-group">
                                <label for="password_mikrotik">Password Mikrotik</label>
                                <input type="password" class="form-control" id="password_mikrotik" name="password_mikrotik" required>
                            </div>
                            <div class="form-group">
                                <label for="ip_mikrotik">IP Mikrotik</label>
                                <input type="text" class="form-control" id="ip_mikrotik" name="ip_mikrotik" required>
                            </div>
                            <div class="form-group">
                                <label for="mikrotik_port">Mikrotik Port</label>
                                <input type="number" class="form-control" id="mikrotik_port" name="mikrotik_port" required>
                            </div>
                        </div>
                    </div>
                    
                       <div class="col">
                         <div class="margin-bottom-small border-radius text-center background-white">
    						<h4 class="mb-3">Pendaftaran Pilihan Payment</h4>
    					 </div>
                        <div class="form-section background-white box-shadow">
                            <div class="form-group">
                                <label for="Endpoint">Endpoint</label>
                                <input type="text" class="form-control" id="Endpoint" name="Endpoint" required>
                            </div>
                            <div class="form-group">
                                <label for="apiKey">API Key</label>
                                <input type="text" class="form-control" id="apiKey" name="apiKey" required>
                            </div>
                            <div class="form-group">
                                <label for="privateKey">Private Key</label>
                                <input type="text" class="form-control" id="privateKey" name="privateKey" required>
                            </div>
                            <div class="form-group">
                                <label for="merchantCode">Merchant Code</label>
                                <input type="text" class="form-control" id="merchantCode" name="merchantCode" required>
                            </div>
                        </div>
                    </div>
                </div>

                
                <div class="text-center">
                    <button type="submit" class="btn btn-primary mt-4">Submit</button>
                </div>
            </form>
        </div>
    </div>
    </div>
    <div class="separator"></div>
<div class="separator-bottom"></div>
<script type="text/javascript" src="js/jquery.js"></script>

<footer class="copyright">
    <small> Copyright &copy;acil-2022 $(identity)</small>
</footer>
</body>
</html>


