<?php 
include '../../koneksi/koneksi.php';

$nama_toko  = $_POST['nama_toko'];
$nama_admin = $_POST['nama_admin'];
$username   = $_POST['username'];
$password   = $_POST['password'];
$level      = $_POST['level'];
$tanggal    = date('Y-m-d H:i:s');

// hash password sebelum simpan
$hash = password_hash($password, PASSWORD_DEFAULT);

// simpan ke database
$result = mysqli_query($conn, "INSERT INTO admin (nama_toko, nama_admin, username, password, level, tanggal) 
                               VALUES('$nama_toko','$nama_admin','$username','$hash', '$level', '$tanggal')");

if($result){
    echo "
        <script>
            alert('Admin berhasil ditambahkan');
            window.location = '../m_admin.php';
        </script>
    ";
}else{
    echo "
        <script>
            alert('Gagal menambahkan admin: ".mysqli_error($conn)."');
            window.location = '../tambah_admin.php';
        </script>
    ";
}
?>
