<?php
session_start();

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

// Optional: access admin ID like this
$admin_id = $_SESSION['admin_id'];

include 'dbconn.php';

// Get the ID from the URL
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// Handle status update
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
    $new_status = $_POST['action'] === 'approve' ? 'Approved' : 'Disapproved';
    $timestamp = date('Y-m-d H:i:s');
    
    $update_sql = "UPDATE basic_information SET status = ?, status_updated_at = ? WHERE id = ?";
    $stmt = $mysqli->prepare($update_sql);
    $stmt->bind_param('ssi', $new_status, $timestamp, $id);
    $stmt->execute();

    // Refresh data after update
    header("Location: basic_information.php?id=$id");
    exit;
}


// Fetch the record for this ID
$sql = "SELECT * FROM basic_information WHERE id = $id";
$result = $mysqli->query($sql);
$row = $result->fetch_assoc();
?>

                   
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CRA - Clinical Research Analysis
    </title>

    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/bootstrap.css">

    <link rel="stylesheet" href="assets/vendors/iconly/bold.css">

    <link rel="stylesheet" href="assets/vendors/perfect-scrollbar/perfect-scrollbar.css">
    <link rel="stylesheet" href="assets/vendors/bootstrap-icons/bootstrap-icons.css">
    <link rel="stylesheet" href="assets/css/app.css">
    <link rel="shortcut icon" href="assets/images/favicon.svg" type="image/x-icon">
</head>

<body>
    <div id="app">
        <div id="sidebar" class="active">
            <div class="sidebar-wrapper active">
                <div class="sidebar-header">
                    <div class="d-flex justify-content-between">
                        <div class="logo">
                              <a href="dashboard.php"><img src="img/logo.png" alt="Logo" style="width: 150px; height:50px" srcset=""></a>
                        </div>
                        <div class="toggler">
                            <a href="#" class="sidebar-hide d-xl-none d-block"><i class="bi bi-x bi-middle"></i></a>
                        </div>
                    </div>
                </div>
                <div class="sidebar-menu">
                    <ul class="menu">
                      
                        <li class="sidebar-item  ">
                            <a href="dashboard.php" class='sidebar-link'>
                                <i class="bi bi-grid-fill"></i>
                                <span>Dashboard</span>
                            </a>
                        </li>
                         <li class="sidebar-item  ">
                            <a href="add_clinic.php" class='sidebar-link'>
                                <i class="bi bi-cloud-arrow-up-fill"></i>
                                <span>Add Clinics</span>
                            </a>
                        </li>

                        <li class="sidebar-item ">
                            <a href="all_clinics.php" class='sidebar-link'>
                                <i class="bi bi-stack"></i>
                                <span>Clinics</span>
                            </a>
                        
                        </li>


                       <li class="sidebar-item active ">
                            <a href="basic_information.php" class='sidebar-link'>
                                <i class="bi bi-collection-fill"></i>
                                <span>Basic Information</span>
                            </a>
                           
                        </li>

                        <li class="sidebar-item ">
                            <a href="principal_investigator.php" class='sidebar-link'>
                                <i class="bi bi-grid-1x2-fill"></i>
                                <span>Principal Investigator</span>
                            </a>
                        </li>
                        <li class="sidebar-item  ">
                            <a href="study_design.php" class='sidebar-link'>
                                <i class="bi bi-hexagon-fill"></i>
                                <span>Study Design</span>
                            </a>
                        </li>

                        <li class="sidebar-item  ">
                            <a href="site_facility.php" class='sidebar-link'>
                                <i class="bi bi-file-earmark-medical-fill"></i>
                                <span>Site & Facility</span>
                            </a>
                        </li>

                        <li class="sidebar-item  ">
                            <a href="investigational_products.php" class='sidebar-link'>
                                <i class="bi bi-pen-fill"></i>
                                <span>Investigational Product</span>
                            </a>
                        </li>

                        <li class="sidebar-item  ">
                            <a href="requirement_datacollection.php" class='sidebar-link'>
                                <i class="bi bi-grid-1x2-fill"></i>
                                <span>Recruitment & Data<br> Collection</span>
                            </a>
                        </li>
                        
                        <li class="sidebar-item  ">
                            <a href="logout.php" class='sidebar-link'>
                                <i class="bi bi-x-octagon-fill"></i>
                                <span>Log Out</span>
                            </a>
                           
                        </li>

                    </ul>
                </div>
                <button class="sidebar-toggler btn x"><i data-feather="x"></i></button>
            </div>
        </div>
        <div id="main">
            <header class="mb-3">
                <a href="#" class="burger-btn d-block d-xl-none">
                    <i class="bi bi-justify fs-3"></i>
                </a>
            </header>

            <div class="page-heading">
                                <h3>Admin</h3>

            </div>
            <div class="page-content">
                  <section class="section">
                    <div class="row" id="table-striped">
                        <div class="col-12">
                            <div class="card mt-4">
    <div class="card-header">
        <h4 class="card-title">Basic Information Details</h4>
    </div>
    <div class="card-body">
        <?php if ($row): ?>
        <table class="table table-bordered">
            <tr>
                <th>Study Title</th>
                <td><?php echo htmlspecialchars($row['study_title']); ?></td>
            </tr>
            <tr>
                <th>Study Acronym</th>
                <td><?php echo htmlspecialchars($row['study_acronym']); ?></td>
            </tr>
            <tr>
                <th>Protocol Number</th>
                <td><?php echo htmlspecialchars($row['protocol_number']); ?></td>
            </tr>
            <tr>
                <th>Sponsor Name</th>
                <td><?php echo htmlspecialchars($row['sponsor_name']); ?></td>
            </tr>
            <tr>
                <th>CRO Name</th>
                <td><?php echo htmlspecialchars($row['cro_name']); ?></td>
            </tr>
            <tr>
                <th>Type of Study</th>
                <td><?php echo htmlspecialchars($row['study_type']); ?></td>
            </tr>
            <tr>
                <th>Study Phase</th>
                <td><?php echo htmlspecialchars($row['study_phase']); ?></td>
            </tr>
            <tr>
                <th>Therapeutic Area</th>
                <td><?php echo htmlspecialchars($row['therapeutic_area']); ?></td>
            </tr>
            <tr>
                <th>Study Objectives</th>
                <td><?php echo htmlspecialchars($row['study_objectives']); ?></td>
            </tr>
            <tr>
                <th>Brief Study Summary</th>
                <td><?php echo htmlspecialchars($row['study_summary']); ?></td>
            </tr>
            <tr>
    <th>Status</th>
    <td colspan="3">
        <?php
            $status = htmlspecialchars($row['status'] ?? 'Pending');
            $updatedAt = !empty($row['status_updated_at']) 
                ? ' (' . date('Y-m-d H:i:s', strtotime($row['status_updated_at'])) . ')'
                : '';
            echo $status . $updatedAt;
        ?>
    </td>
</tr>

        </table>
        <form method="post" class="mt-3">
            <button type="submit" name="action" value="approve" class="btn btn-success me-2">Approve</button>
            <button type="submit" name="action" value="disapprove" class="btn btn-danger">Disapprove</button>
        </form>
        <?php else: ?>
        <p>No record found.</p>
        <?php endif; ?>
    </div>
</div>
                        </div>
                    </div>
                </section>
            </div>

            <footer>
                <div class="footer clearfix mb-0 text-muted">
                    <div class="float-start">
                        <p>2025 &copy; Phaseon Clinical Research</p>
                    </div>
                    <div class="float-end">
                        <p>Design by PoojaInfotech</p>
                    </div>
                </div>
            </footer>
        </div>
    </div>
    <script src="assets/vendors/perfect-scrollbar/perfect-scrollbar.min.js"></script>
    <script src="assets/js/bootstrap.bundle.min.js"></script>

    <script src="assets/vendors/apexcharts/apexcharts.js"></script>
    <script src="assets/js/pages/dashboard.js"></script>

    <script src="assets/js/main.js"></script>
</body>

</html>