<?php
session_start();

if (!isset($_SESSION['clinic_logged_in']) || $_SESSION['clinic_logged_in'] !== true) {
    header('Location: index.php');
    exit;
}

// Optional: access admin ID like this
$admin_id = $_SESSION['clinic_id'];
include 'dbconn.php'; // Ensure $mysqli is your DB connection

// Sanitize and collect POST data
$start_date        = $_POST['start_date'];
$end_date          = $_POST['end_date'];
$enrollment_plan   = $_POST['enrollment_plan'];
$informed_consent  = $_POST['informed_consent'];
$edc_system        = $_POST['edc_system'];
$crf_format        = $_POST['crf_format'];
$monitoring_plan   = $_POST['monitoring_plan'];

// Prepare and execute the insert query
$stmt = $mysqli->prepare("INSERT INTO recruitment_data 
    (start_date, end_date, enrollment_plan, informed_consent, edc_system, crf_format, monitoring_plan, clinic_id) 
    VALUES (?, ?, ?, ?, ?, ?, ?,?)");

$stmt->bind_param("sssssssi", $start_date, $end_date, $enrollment_plan, $informed_consent, $edc_system, $crf_format, $monitoring_plan, $admin_id);

if ($stmt->execute()) {
    echo "<script>alert('Recruitment data saved successfully.'); window.location.href='requirement_datacollection.php';</script>";
} else {
    echo "<script>alert('Error saving data.'); window.history.back();</script>";
}

$stmt->close();
$mysqli->close();
?>
