<?php

session_start();

if (!isset($_SESSION['login'])) {
    header('location:login');
    exit;
}

// $_SESSION['role'];
require 'function.php';
require 'config.php';

include_once 'reset.php';

// Membuat fungsi tambah
function tambah1()
{
    global $koneksi;
    $event_id = get_active_event_id();
    
    $nama = $_POST["decodedText"];
    $tamu = $_POST["tamuqr"];
    $tgl = date('d-m-Y');
    $jam = date('H:i');
    $whatsapp = isset($_POST['whatsapp']) ? htmlspecialchars($_POST['whatsapp']) : '';
    $jumlah_tamu = isset($_POST['jumlah_tamu']) ? (int)$_POST['jumlah_tamu'] : 1;

    $sql = "INSERT INTO `comment_id` (`nama`,`tgl`,`jam`, `tamu`, `whatsapp`, `event_id`, `jumlah_tamu`) VALUES ('$nama', '$tgl', '$jam', '$tamu', '$whatsapp', '$event_id', '$jumlah_tamu')";

    mysqli_query($koneksi, $sql);

    return mysqli_affected_rows($koneksi);
    
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $result = tambah1($_POST);
}