<!DOCTYPE html>
<?php
// Start the session at the very beginning
session_start();

// Check if the user is logged in
if (!isset($_SESSION['email'])) {
    header("Location: login.php");
    exit();
}

// Include necessary files
require("_common/global.php");
require("_common/conn.php");

// Connect to the database using mysqli
$link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
if ($link === false) {
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Get user information
$email = $_SESSION['email'];
$result = mysqli_query($link, "SELECT * FROM user WHERE email='$email'");
if (!$result) {
    die("Error: " . mysqli_error($link));
}

$test = mysqli_fetch_array($result);
$name = $test['name'];
$post = $test['post'];
$role = $test['role'];

// Close the database connection
mysqli_close($link);
?>

<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title>VAC-DOS | Vaccine Dossier Mapping Tool</title>
    <link rel="shortcut icon" href="assets/images/favicon.ico">
    <link rel="stylesheet" href="assets/css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="assets/css/icons.css" type="text/css">
    <link rel="stylesheet" href="assets/css/style.css" type="text/css">
</head>

<body>
    <!-- Loader -->
    <div id="preloader"><div id="status"><div class="spinner"></div></div></div>

    <!-- Navigation Bar-->
    <header id="topnav">
        <div class="topbar-main">
            <div class="container-fluid">
                <div class="logo">
                    <a href="index.html" class="logo">
                        <img src="assets/images/logo-sm.png" alt="" height="32" class="logo-small">
                        <img src="assets/images/logo.png" alt="" height="20" class="logo-large">
                    </a>
                </div>
                <div class="menu-extras topbar-custom">
                    <ul class="list-inline float-right mb-0">
                        <li class="list-inline-item dropdown notification-list">
                            <a class="nav-link dropdown-toggle arrow-none waves-effect nav-user" data-toggle="dropdown" href="#" role="button" aria-haspopup="false" aria-expanded="false">
                                <img src="assets/images/users/user-1.jpg" alt="user" class="rounded-circle">
                            </a>
                            <div class="dropdown-menu dropdown-menu-right dropdown-menu-animated profile-dropdown ">
                                <a class="dropdown-item" href="profile.php"><i class="mdi mdi-account-circle m-r-5 text-muted"></i> Profile</a>
                                <a class="dropdown-item" href="logout.php"><i class="mdi mdi-logout m-r-5 text-muted"></i> Logout</a>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>

        <div class="navbar-custom">
            <div class="container-fluid">
                <div id="navigation">
                    <ul class="navigation-menu">
                        <li class="has-submenu"><a href="dashboard.php"><i class="dripicons-meter"></i>Dashboard</a></li>
                        <li class="has-submenu"><a href="#"><i class="dripicons-user"></i>User</a>
                            <ul class="submenu megamenu">
                                <li>
                                    <ul>
                                        <li><a href="addnewuser.php">Add New User</a></li>
                                        <li><a href="usermanage.php">User  Management</a></li>
                                    </ul>
                                </li>
                            </ul>
                        </li>
                        <li class="has-submenu"><a href="#"><i class="ion-eye"></i>Pre-screen</a>
                            <ul class="submenu">
                                <li><a href="pre/addnewPS.php">New Pre-Screen Dossier</a></li>
                                <li><a href="pre/pendinglist.php">All List</a></li>
                                <li><a href="pre/kivlist.php">KIV List</a></li>
                                <li><a href="pre/passlist.php">Accepted List</a></li>
                                <li><a href="pre/rejectlist.php">Rejected List</a></li>
                                <li class="has-submenu">
                                    <a href="#">Add Data</a>
                                    <ul class="submenu">
                                        <li><a href="pre/pre-applicantcompany.php">Applicant Company</a></li>
                                        <li><a href="pre/pre-disease.php">Disease</a></li>
                                        <li><a href="pre/pre-strain.php">Strain</a></li>
                                        <li><a href="pre/pre-species.php">Target Species</a></li>
                                        <li><a href="pre/pre-vaccine.php">Nature of Vaccine</a></li>
                                        <li><a href="pre/pre-manu.php">Approved Manufacturer</a></li>
                                        <li><a href="pre/pre-refcount.php">Ref. Country (Certificate)</a></li>
                                        <li><a href="pre/pre-asian.php">Asian Country (Certificate)</a></li>
                                        <li><a href="pre/pre-source.php">Approved Source SPF Eggs</a></li>
                                    </ul>
                                </li>
                            </ul>
                        </li>
                        <li class="has-submenu"><a href="#"><i class="dripicons-copy"></i>Dossier</a>
                            <ul class="submenu">
                                <li><a href="addnewtask0.php">Assign New Dossier</a></li>
                                <li><a href="assignevaluator.php">Assign Evaluator</a></li>
                                <li><a href="assigned.php">View List</a></li>
                            </ul>
                        </li>
                        <li class="has-submenu"><a href="#"><i class="ion-folder"></i>Records</a>
                            <ul class="submenu">
                                <li class="has-submenu">
                                    <a href="#">By Individual</a>
                                    <ul class="submenu">
                                        <li><a href="viewall.php">View All</a></li>
                                        <li><a href="viewcomplete.php">Complete</a></li>
                                        <li><a href="viewpending.php">Pending</a></li>
                                    </ul>
                                </li>
                                <li class="has-submenu">
                                    <a href="#">By Group</a>
                                    <ul class="submenu">
                                        <li><a href="groupview.php">View All</a></li>
                                        <li><a href="groupcomplete.php">Complete</a></li>
                                        <li><a href="grouppending.php">Pending</a></li>
                                    </ul>
                                </li>
                            </ul>
                        </li>
                        <li class="has-submenu"><a href="#"><i class="dripicons-archive"></i>Documents</a>
                            <ul class="submenu">
                                <li class="has-submenu">
                                    <a href="#">System Manual</a>
                                    <ul class="submenu">
                                        <li><a href="#.php">Administrator Manual</a></li>
                                        <li><a href="#.php">Evaluator Manual</a></li>
                                    </ul>
                                </li>
                                <li class="has-submenu">
                                    <a href="#">Other Documents</a>
                                    <ul class="submenu">
                                        <li><a href="#.php">Add New Document</a></li>
                                        <li><a href="#.php">Document Category</a></li>
                                        <li><a href="#.php">View All Documents</a></li>
                                    </ul>
                                </li>
                            </ul>
                        </li>
                        <li class="has-submenu"><a href="#"><i class="ion-information-circled"></i>About</a>
                            <ul class="submenu">
                                <li><a href="#">About VACDOS</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </header>
    <!-- End Navigation Bar-->

    <div class="wrapper">
        <div class="container-fluid">
            <!-- Page-Title -->
            <div class="row">
                <div class="col-sm-12">
                    <div class="page-title-box">
                        <div class="btn-group float-right">
                            <ol class="breadcrumb hide-phone p-0 m-0">
                                <li class="breadcrumb-item"><a href="#">VACDOS</a></li>
                                <li class="breadcrumb-item active">Dashboard</li>
                            </ol>
                        </div>
                                               <h4 class="page-title">Dashboard</h4>
                    </div>
                </div>
            </div>
            <!-- end page title end breadcrumb -->

            <div class="row">
                <div class="col-xl-4">
                    <div class="card m-b-30 text-white bg-primary">
                        <div class="card-body">
                            <p>Welcome to VACDOS!</p>
                            <p><?php echo $name; ?><br><?php echo $post; ?><br><?php echo $email; ?><br><br>System Role: <?php echo $role; ?></p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-xl-3 col-md-6">
                    <div class="card mini-stat m-b-30">
                        <div class="p-3 bg-primary text-white">
                            <div class="mini-stat-icon">
                                <i class="mdi mdi-account-network float-right mb-0"></i>
                            </div>
                            <h6 class="text-uppercase mb-0">ADMINISTRATOR</h6>
                        </div>
                        <div class="card-body">
                            <div class="border-bottom pb-4">
                                <?php
                                $link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
                                $result = mysqli_query($link, "SELECT count(*) as total FROM user WHERE role='Administrator'");
                                $data = mysqli_fetch_assoc($result);
                                mysqli_close($link);
                                ?>
                                <span class="badge badge-success"></span> <a href="usermanage.php"><h1><?php echo $data['total']; ?></h1></a><span class="ml-2 text-muted">Registered VACDOS Administrator</span>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-xl-3 col-md-6">
                    <div class="card mini-stat m-b-30">
                        <div class="p-3 bg-primary text-white">
                            <div class="mini-stat-icon">
                                <i class="mdi mdi-account-network float-right mb-0"></i>
                            </div>
                            <h6 class="text-uppercase mb-0">DOSSIER READER/EVALUATOR</h6>
                        </div>
                        <div class="card-body">
                            <div class="border-bottom pb-4">
                                <?php
                                $link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
                                $result = mysqli_query($link, "SELECT count(*) as total FROM user WHERE role='Evaluator'");
                                $data2 = mysqli_fetch_assoc($result);
                                mysqli_close($link);
                                ?>
                                <span class="badge badge-success"></span><a href="usermanage.php"><h1><?php echo $data2['total']; ?></h1></a><span class="ml-2 text-muted">Registered Dossier Reader / Evaluator</span>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-xl-3 col-md-6">
                    <div class="card mini-stat m-b-30">
                        <div class="p-3 bg-primary text-white">
                            <div class="mini-stat-icon">
                                <i class="mdi mdi-account-network float-right mb-0"></i>
                            </div>
                            <h6 class="text-uppercase mb-0">PRE-SCREEN NEW DOSSIER</h6>
                        </div>
                        <div class="card-body">
                            <div class="border-bottom pb-4">
                                <?php
                                $link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
                                $result = mysqli_query($link, "SELECT count(*) as total FROM prescreen");
                                $data3 = mysqli_fetch_assoc($result);
                                mysqli_close($link);
                                ?>
                                <span class="badge badge-success"></span><a href="pre/pendinglist.php"><h1><?php echo $data3['total']; ?></h1></a><span class="ml-2 text-muted">Pre-Screen Dossier Screening</span>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-xl-3 col-md-6">
                    <div class="card mini-stat m-b-30">
                        <div class="p-3 bg-primary text-white">
                            <div class="mini-stat-icon">
                                <i class="mdi mdi-account-network float-right mb-0"></i>
                            </div>
                            <h6 class="text-uppercase mb-0">DOSSIER EVALUATION</h6>
                        </div>
                        <div class="card-body">
                            <div class="border-bottom pb-4">
                                <?php
                                $link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
                                $result = mysqli_query($link, "SELECT count(*) as total FROM dossierform WHERE Assess!=''");
                                $data4 = mysqli_fetch_assoc($result);
                                mysqli_close($link);
                                ?>
                                <span class="badge badge-success"></span><a href="viewall.php"><h1><?php echo $data4['total']; ?></h1></a><span class="ml-2 text-muted">Dossier Evaluation</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- end row -->

            <div class="row">
                <div class="col-xl-6">
                    <div class="card m-b-30">
                        <div class="card-body">
                            <?php
                            $link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
                            $result = mysqli_query($link, "SELECT count(*) as total FROM prescreen WHERE submission='Pending'");
                            $data5 = mysqli_fetch_assoc($result);
                            mysqli_close($link);
                            ?>
                            <h4 class="mt-0 header-title mb-4">Pending Pre-Screen Dossier: <?php echo $data5['total']; ?></h4>
                            <div class="table-responsive">
                                <table class="table table-hover mb-0">
                                    <?php
                                    // Connect to the database
                                    $link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
                                    $result = mysqli_query($link, "SELECT * FROM prescreen WHERE submission='Pending'");
                                    if ($result && mysqli_num_rows($result) > 0) {
                                        echo "
                                            <thead>
                                                <tr>
                                                    <th><center>Dossier<br>Tradename</center></th>
                                                    <th><center>Vaccine<br>Nature</center></th>
                                                    <th><center>Applicant<br>Company</center></th>
                                                    <th><center>Pre-screen<br>Date</center></th>
                                                    <th><center>Due<br>Date</center></th>
                                                    <th><center>Pre-Screen<br>By</center></th>
                                                    <th><center>View</center></th>
                                                </tr>
                                            </thead>";
                                        while ($row = mysqli_fetch_object($result)) {
                                            echo "<tr>
                                                <td>" . $row->tradename . "</td>
                                                <td>" . $row->nature . "</td>
                                                <td>" . $row->appcomp . "</td>
                                                <td>" . $row->prescreendate . "</td>
                                                <td>" . $row->duedate . "</td>
                                                <td>" . $row->prescreenby . "</td>
                                                <td><a href='pre/PS-edit.php?id=" . $row->id . "'><center><i class='fa fa-edit fa-2x'></i></center></a></td>
                                            </tr>";
                                        }
                                    } else {
                                        echo "<tr><td colspan='7'>No Pending Pre-Screen Dossier</td></tr>";
                                    }
                                    mysqli_close($link);
                                    ?>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-xl-6">
                    <div class="card m-b-30">
                        <div class="card-body">
                            <?php
                            $link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
                            $result = mysqli_query($link, "SELECT count(*) as total FROM dossierform WHERE statusform='Draft' AND Assess!=''");
                            $data6 = mysqli_fetch_assoc($result);
                            mysqli_close($link);
                            ?>
                            <h4 class="mt-0 header-title mb-4">Pending Dossier Evaluation: <?php echo $data6['total']; ?></h4>
                            <div class="table-responsive">
                                <table class="table table-hover mb-0">
                                    <?php
                                    // Connect to the database
                                    $link = mysqli_connect("localhost", "dvsvigov_vacc","DVSvacdos123", "dvsvigov_vacdos");
                                    $result = mysqli_query($link, "SELECT * FROM dossierform WHERE statusform='Draft' AND Assess!=''");
                                    if ($result && mysqli_num_rows($result) > 0) {
                                        echo "
                                            <thead>
                                                <tr>
                                                    <th><center>Dossier<br>Tradename</center></th>
                                                    <th><center>Vaccine<br>Nature</center></th>
                                                    <th><center>Applicant<br>Company</center></th>
                                                    <th><center>Assessor</center></th>
                                                    <th><center>View</center></th>
                                                </tr>
                                            </thead>";
                                        while ($row = mysqli_fetch_object($result)) {
                                            echo "<tr>
                                                <td><center>" . $row->tradename . "</center></td>
                                                <td><center>" . $row->vacctype . "</center></td>
                                                <td><center>" . $row->manufacturername . "</center></td>
                                                <td><center>" . $row->Assess . "</center></td>
                                                <td><center><a href='vacdosform.php?idvac=" . $row->idvac . "&&Assess=" . $row->Assess . "' target='_blank'><i class='fa fa-edit fa-2x'></i></a></center></td>
                                            </tr>";
                                        }
                                    } else {
                                        echo "<tr><td colspan='5'>No results to display!</td></tr>";
                                    }
                                    mysqli_close($link);
                                    ?>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- end row -->

        </div> <!-- end container -->
    </div>
    <!-- end wrapper -->

    <!-- Footer -->
    <footer class="footer">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    © 2020 <b>VACDOS</b> V1.0 <span class="d-none d-sm-inline-block"> Crafted by <b>Veterinary Research Division</b> (BPVV), DVS</span>
                </div>
            </div>
        </div>
    </footer>
    <!-- End Footer -->

    <!-- jQuery -->
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/bootstrap.bundle.min.js"></script>
    <script src="assets/js/modernizr.min.js"></script>
    <script src="assets/js/detect.js"></script>
    <script src="assets/js/fastclick.js"></script>
    <script src="assets/js/jquery.slimscroll.js"></script>
    <script src="assets/js/jquery.blockUI.js"></script>
    <script src="assets/js/waves.js"></script>
    <!-- skycons -->
    <script src="assets/plugins/skycons/skycons.min.js"></script>
    <!-- skycons -->
    <script src="assets/plugins/peity/jquery.peity.min.js"></script>
    <!--Morris Chart-->
    <script src="assets/plugins/morris/morris.min.js"></script>
    <script src="assets/plugins/raphael/raphael-min.js"></script>
    <!-- dashboard -->
    <script src="assets/pages/dashboard.js"></script>
    <!-- App js -->
    <script src="assets/js/app.js"></script>

</body>
</html>