<?php 
ob_start(); // Start output buffering
include 'header_guru.php';
include 'koneksi.php';

// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $nip = $_POST['nip'];
    $nama_guru = $_POST['nama_guru'];
    $alamat = $_POST['alamat'];
    $no_telepon = $_POST['no_telepon'];
    $id_pengguna = $_POST['id_pengguna']; // Ensure this relates to an entry in `pengguna`

    // Insert the new 'guru' record
    $query = "INSERT INTO guru (nip, nama_guru, alamat, no_telepon, id_pengguna) VALUES ('$nip', '$nama_guru', '$alamat', '$no_telepon', '$id_pengguna')";
    
    if (mysqli_query($koneksi, $query)) {
        header("Location: guru.php");
        exit();
    } else {
        echo "<div class='alert alert-danger'>Error: " . mysqli_error($koneksi) . "</div>";
    }
}

ob_end_flush(); // End output buffering
?>

<style>
    .android-btn {
        display: block; /* Full width */
        padding: 15px 30px;
        font-size: 18px;
        color: #fff;
        background-color: #6200ea; /* Android Material Design color */
        border: none;
        border-radius: 25px; /* Rounded button */
        text-align: center;
        transition: background-color 0.3s ease;
        text-decoration: none;
        margin-top: 20px; /* Space above button */
    }

    .android-btn:hover {
        background-color: #3700b3; /* Darker shade on hover */
    }

    .input-field {
        padding: 12px;
        border: 1px solid #ccc;
        border-radius: 5px; /* Rounded edges */
        font-size: 16px;
        margin-bottom: 15px; /* Space between fields */
    }

    .container {
        padding-bottom: 100px; /* Extra padding at the bottom for the button */
    }
</style>

<div class="container mt-10">
    <h2 class="text-center mb-10">Tambah Data Guru</h2>
    <form method="POST">
        <input type="text" class="input-field" id="nip" name="nip" placeholder="NIP" required>
        <input type="text" class="input-field" id="nama_guru" name="nama_guru" placeholder="Nama Guru" required>
        <input type="text" class="input-field" id="alamat" name="alamat" placeholder="Alamat" required>
        <input type="text" class="input-field" id="no_telepon" name="no_telepon" placeholder="No Telepon" required>
        <input type="text" class="input-field" id="id_pengguna" name="id_pengguna" placeholder="ID Pengguna" required>
        <button type="submit" class="android-btn">Tambah</button> <!-- Updated button -->
    </form>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
