<?php


session_start();

if (!isset($_SESSION['user'])) {
    // Redirect to login page if not logged in
    header('Location: ../login');
    exit();
}

$user = $_SESSION['user'];
//$email = $user['email_address'];


// Include database connection file
include_once './dbconn.php';

$counttotal = "SELECT COUNT(*) as total_items FROM web_app_enrollee_data";
$counttotalinducted = "SELECT COUNT(*) as total_principal FROM web_app_enrollee_data WHERE hmo_level = 'Principal'";
$counttotanewinductee = "SELECT COUNT(*) as total_dependant FROM web_app_enrollee_data WHERE hmo_level != 'Principal'";
$pendingapproval = "SELECT COUNT(*) as total_pending_approval FROM web_app_enrollee_data WHERE status = 'Pending'";


// Fetch total items
$total_items = 0;
$result = $conn->query($counttotal);
if ($result && $result->num_rows > 0) {
    $row = $result->fetch_assoc();
    $total_items = $row["total_items"];
}

// Fetch total inducted items
$total_principal = 0;
$result = $conn->query($counttotalinducted);
if ($result && $result->num_rows > 0) {
    $row = $result->fetch_assoc();
    $total_principal = $row["total_principal"];
}

// Fetch total new Inductee
$total_dependant = 0;
$result = $conn->query($counttotanewinductee);
if ($result && $result->num_rows > 0) {
    $row = $result->fetch_assoc();
    $total_dependant = $row["total_dependant"];
}

// Fetch total Pending Approval
$total_pending_approval = 0;
$result = $conn->query($pendingapproval);
if ($result && $result->num_rows > 0) {
    $row = $result->fetch_assoc();
    $total_pending_approval = $row["total_pending_approval"];
}

$url="http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

  if(strpos($url, 'error') == true){


 echo '<script>
    setTimeout(function() {
        swal({
            title: "Error!",
            text: "Error Occured",
            type: "error"
        }, function() {
            window.location = "#0";
        });
    }, 1000);
  </script>';
  

    }elseif (strpos($url, 'updated') == true) {
        
 echo '<script>
    setTimeout(function() {
        swal({
            title: "Success!",
            text: "Provider data updated successfully",
            type: "success"
        }, function() {
            window.location = "#0";
        });
    }, 1000);
</script>';

    } 



?>

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


<!-- datatables.html  21 Nov 2019 03:55:21 GMT -->
<head>
  <meta charset="UTF-8">
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no" name="viewport">
  <title>Health Assur - Admin Dashboard</title>
  <!-- General CSS Files -->
  <link rel="stylesheet" href="assets/css/app.min.css">
  <link rel="stylesheet" href="assets/bundles/datatables/datatables.min.css">
  <link rel="stylesheet" href="assets/bundles/datatables/DataTables-1.10.16/css/dataTables.bootstrap4.min.css">
  <!-- Template CSS -->
  <link rel="stylesheet" href="assets/css/style.css">
  <link rel="stylesheet" href="assets/css/components.css">
  <!-- Custom style CSS -->
  <link rel="stylesheet" href="assets/css/custom.css">
  <link rel='shortcut icon' type='image/x-icon' href='../images/Red-logo.png' />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert-dev.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css">
  <style>
    /* Modal styles */
    .modal,
    .modal2 {
        display: none;
        position: fixed;
        z-index: 1000;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        overflow: auto;
        background-color: rgba(0, 0, 0, 0.4);
    }

    .modal-content,
    .modal-content2 {
        background-color: #fefefe;
        margin: 2% auto;
        padding: 20px 50px;
        border: 1px solid #888;
        width: 70%;
        height: 90vh;
        overflow-y: auto;

    }

    .close,
    .close2 {
        color: #aaa;
        /* float: right; */
        font-size: 38px;
        font-weight: bold;
    }

    .close:hover,
    .close:focus,
    .close2:hover,
    .close2:focus {
        color: black;
        text-decoration: none;
        cursor: pointer;
    }



    .inputdiv {
        display: block;
    }

    .inputdiv input {
        padding: 10px 20px;
        outline: none;
        border-radius: 10px;
        border: 2px solid gray;

    }
    </style>
</head>

<body>
  <div class="loader"></div>
  <div id="app">
    <div class="main-wrapper main-wrapper-1">
      <div class="navbar-bg"></div>
      <nav class="navbar navbar-expand-lg main-navbar sticky">
        <div class="form-inline mr-auto">
          <ul class="navbar-nav mr-3">
            <li><a href="#" data-toggle="sidebar" class="nav-link nav-link-lg
									collapse-btn"> <i data-feather="align-justify"></i></a></li>
            <li><a href="#" class="nav-link nav-link-lg fullscreen-btn">
                <i data-feather="maximize"></i>
              </a>
            </li>
          </ul>
        </div>
        <ul class="navbar-nav navbar-right">
          <li class="dropdown"><a href="#" data-toggle="dropdown"
              class="nav-link dropdown-toggle nav-link-lg nav-link-user"> <img alt="image" src="assets/img/user.png"
                class="user-img-radious-style"> <span class="d-sm-none d-lg-inline-block"></span></a>
            <div class="dropdown-menu dropdown-menu-right pullDown">
              <div class="dropdown-title">Hello Health Assur Admin</div>
              
              <div class="dropdown-divider"></div>
              <a href="../login/logout.php" class="dropdown-item has-icon text-danger"> <i class="fas fa-sign-out-alt"></i>
                Logout
              </a>
            </div>
          </li>
        </ul>
      </nav>
      <div class="main-sidebar sidebar-style-2">
        <aside id="sidebar-wrapper">
          <div class="sidebar-brand">
            <a href="index.php"> <img alt="image" src="../images/Red-logo.png" class="header-logo" /> <span
                class="logo-name"></span>
            </a>
          </div>
          <ul class="sidebar-menu">
            <li class="menu-header">Menu</li>
            <li class="dropdown">
              <a href="enrolleeview.php" class="nav-link"><i data-feather="user"></i><span>Members</span></a>
              <a href="companyview.php" class="nav-link"><i data-feather="briefcase"></i><span>Clients</span></a>
              <a href="providers.php" class="nav-link"><i data-feather="heart"></i><span>providers</span></a>
            </li>
          </ul>
        </aside>
      </div>
    
        <!-- Main Content -->
      <div class="main-content">
        <section class="section">
        <?php
            include_once 'dbconn.php';

            if(isset($_GET['id'])) {
                $id = $_GET['id'];

                $sql = "SELECT * FROM  web_app_provider_list WHERE id = '$id'";
                $result = mysqli_query($conn, $sql);
                $result_checker = mysqli_num_rows($result);
                if ($result_checker > 0) {
                    while ($data = mysqli_fetch_assoc($result)) {
                        
                        $state = $data['state'];
                        $location = $data['location'];
                        $provider_name = $data['provider_name'];
                        $provider_email = $data['provider_email'];
                        $address = $data['address'];
                        $specialization = $data['specialization'];
                        $provider_category = $data['provider_category'];
                        $mdname = $data['mdname'];
                        $mdphone = $data['mdphone'];
                        $mdemail = $data['mdemail'];
                        $hmoofficername = $data['hmoofficername'];
                        $hmoofficerphone = $data['hmoofficerphone'];
                        $hmoofficeremail = $data['hmoofficeremail'];
                        $status = $data['status'];
                        $provider_phone = $data['provider_phone'];
                        $active_days = $data['active_days'];
                        $type = $data['type'];
                        $bank_name = $data['bank_name'];
                        $account_name = $data['account_name'];
                        $account_number = $data['account_number'];
                        
                    }
                } 
                                

            } else {
                // header("Location: ./index.php");
                die();
            }

            ?>
                <div class="card">
                  <div class="card-header">
                  <a href="providers.php" class="btn btn-danger mb-3">Go Back</a>
                  </div>
                  <div class="card-header">
                    <h4>Edit Provider</h4>
                  </div>
                  <div class="card-body">
                  <form id="editprovider" action="editprovider_db.php" method="post" enctype="multipart/form-data">
                    <div class="form-row">
                    <div class="form-group col-md-6">
                    <input type="hidden" name="id" value="<?=$id?>">
                    <label for="providername">Provider Name</label>
                    <input type="text" class="form-control" id="providername" name="providername" value='<?= $provider_name ?>'>
                    </div>

                    <div class="form-group col-md-6">
                    <label for="provideremail">Provider Email</label>
                    <input type="email" class="form-control" id="provideremail" name="provideremail" value='<?= $provider_email ?>'>
                    </div>

                    <div class="form-group col-md-6">
                    <label for="provider_phone">Provider Phone</label>
                    <input type="text" class="form-control" id="provider_phone" name="provider_phone" value='<?= $provider_phone ?>'>
                    </div>
                    
                    <div class="form-group col-md-6">
                    <label for="address">Address</label>
                    <input type="text" class="form-control" id="address" name="address" value='<?= $address ?>'>
                    </div>

                    <div class="form-group col-md-6">
                    <label for="location">Location</label>
                    <input type="text" class="form-control" id="location" name="location" value='<?= $location ?>'>
                    </div>

                    <div class="form-group col-md-6">
                        <label for="provider_state">State</label>
                        <select id="provider_state" name="provider_state" class="form-control">
                        <option value='<?= $state?>' selected><?= $state?></option>
                            <option value="Abia">Abia</option>
                            <option value="Adamawa">Adamawa</option>
                            <option value="Abuja">Abuja</option>
                            <option value="AkwaIbom">Akwa Ibom</option>
                            <option value="Anambra">Anambra</option>
                            <option value="Bauchi">Bauchi</option>
                            <option value="Bayelsa">Bayelsa</option>
                            <option value="Benue">Benue</option>
                            <option value="Borno">Borno</option>
                            <option value="CrossRiver">Cross River</option>
                            <option value="Delta">Delta</option>
                            <option value="Ebonyi">Ebonyi</option>
                            <option value="Edo">Edo</option>
                            <option value="Ekiti">Ekiti</option>
                            <option value="Enugu">Enugu</option>
                            <option value="Gombe">Gombe</option>
                            <option value="Imo">Imo</option>
                            <option value="Jigawa">Jigawa</option>
                            <option value="Kaduna">Kaduna</option>
                            <option value="Kano">Kano</option>
                            <option value="Katsina">Katsina</option>
                            <option value="Kebbi">Kebbi</option>
                            <option value="Kogi">Kogi</option>
                            <option value="Kwara">Kwara</option>
                            <option value="Lagos">Lagos</option>
                            <option value="Nassarawa">Nassarawa</option>
                            <option value="Niger">Niger</option>
                            <option value="Ogun">Ogun</option>
                            <option value="Ondo">Ondo</option>
                            <option value="Osun">Osun</option>
                            <option value="Oyo">Oyo</option>
                            <option value="Plateau">Plateau</option>
                            <option value="Rivers">Rivers</option>
                            <option value="Sokoto">Sokoto</option>
                            <option value="Taraba">Taraba</option>
                            <option value="Yobe">Yobe</option>
                            <option value="Zamfara">Zamfara</option>
                        </select>
                    </div>

                    <div class="form-group col-md-6">
                    <label for="specialization">Specialization</label>
                    <input type="text" class="form-control" id="specialization" name="specialization" value='<?= $specialization ?>'>
                    </div>

                    <div class="form-group col-md-6">
                        <label for="band">Band</label>
                        <select id="band" name="band" class="form-control">
                        <option value='<?= $provider_category?>' selected><?= $provider_category?></option>
                        <option value="BANDA">Band A</option>
                        <option value="BANDB">Band B</option>
                        <option value="BANDC">Band C</option>
                        <option value="BANDD">Band D</option>
                        <!-- Add more options as needed -->
                        </select>
                    </div>

                    <div class="form-group col-md-4">
                    <label for="active_days">Active Days</label>
                    <input type="text" class="form-control" id="active_days" name="active_days" value='<?= $active_days ?>'>
                    </div>
                    
                    <div class="form-group col-md-4">
                        <label for="type">Provider Type</label>
                        <select id="type" name="type" class="form-control">
                        <option value='<?= $type?>' selected><?= $type?></option>
                        <option value="Primary">Primary</option>
                        <option value="Secondary">Secondary</option>
                        <option value="Tertiary">Tertiary</option>
                        <!-- Add more options as needed -->
                        </select>
                    </div>

                    <div class="form-group col-md-4">
                        <label for="status">Status</label>
                        <select id="status" name="status" class="form-control">
                        <option value='<?= $status?>' selected><?= $status?></option>
                        <option value="Active">Active</option>
                        <option value="Terminated">Terminated</option>
                        <option value="Pending">Pending</option>
                        <!-- Add more options as needed -->
                        </select>
                    </div>

                    <hr style="width: 100%; border: 1px solid #ccc;">
                    <div class="card-header">
                        <h4>Other Details</h4>
                    </div>
                    
                    <div class="form-group col-md-4">
                        <label for="mdname">MD Name</label>
                        <input type="text" class="form-control" id="mdname" name="mdname"value='<?= $mdname ?>'>
                    </div>

                    <div class="form-group col-md-4">
                        <label for="mdphone">MD Phone</label>
                        <input type="text" class="form-control" id="mdphone" name="mdphone" value='<?= $mdphone ?>'>
                    </div>

                    <div class="form-group col-md-4">
                        <label for="mdemail">MD Email</label>
                        <input type="email" class="form-control" id="mdemail" name="mdemail" value='<?= $mdemail ?>'>
                    </div>

                    <div class="form-group col-md-4">
                    <label for="hmoofficername">HMO Officer Name</label>
                    <input type="text" class="form-control" id="hmoofficername" name="hmoofficername" value='<?= $hmoofficername ?>'>
                    </div>

                    <div class="form-group col-md-4">
                    <label for="hmoofficerphone">HMO Officer Phone</label>
                    <input type="text" class="form-control" id="hmoofficerphone" name="hmoofficerphone" value='<?= $hmoofficerphone ?>'>
                    </div>

                    <div class="form-group col-md-4">
                    <label for="hmoofficeremail">HMO Officer Email</label>
                    <input type="email" class="form-control" id="hmoofficeremail" name="hmoofficeremail" value='<?= $hmoofficeremail ?>'>
                    </div>
                    
                    <div class="form-group col-md-4">
                    <label for="bank_name">Bank Name</label>
                    <input type="text" class="form-control" id="bank_name" name="bank_name" value='<?= $bank_name ?>'>
                    </div>

                    <div class="form-group col-md-4">
                    <label for="account_name">Account Name</label>
                    <input type="text" class="form-control" id="account_name" name="account_name" value='<?= $account_name ?>'>
                    </div>

                    <div class="form-group col-md-4">
                    <label for="account_number">Account Number</label>
                    <input type="text" class="form-control" id="account_number" name="account_number" value='<?= $account_number ?>'>
                    </div>

                  </div>
                  <div class="card-footer">
                  <button class="btn btn-primary" name="update">Update</button>
                  </div>
                </div>
        </form>
        </section>
        <!-- Main Content end -->
                 <div class="settingSidebar">
          <a href="javascript:void(0)" class="settingPanelToggle"> <i class="fa fa-spin fa-cog"></i>
          </a>
          <div class="settingSidebar-body ps-container ps-theme-default">
            <div class=" fade show active">
              <div class="setting-panel-header">Setting Panel
              </div>
              <div class="p-15 border-bottom">
                <h6 class="font-medium m-b-10">Select Layout</h6>
                <div class="selectgroup layout-color w-50">
                  <label class="selectgroup-item">
                    <input type="radio" name="value" value="1" class="selectgroup-input-radio select-layout" checked>
                    <span class="selectgroup-button">Light</span>
                  </label>
                  <label class="selectgroup-item">
                    <input type="radio" name="value" value="2" class="selectgroup-input-radio select-layout">
                    <span class="selectgroup-button">Dark</span>
                  </label>
                </div>
              </div>
              <div class="p-15 border-bottom">
                <h6 class="font-medium m-b-10">Sidebar Color</h6>
                <div class="selectgroup selectgroup-pills sidebar-color">
                  <label class="selectgroup-item">
                    <input type="radio" name="icon-input" value="1" class="selectgroup-input select-sidebar">
                    <span class="selectgroup-button selectgroup-button-icon" data-toggle="tooltip"
                      data-original-title="Light Sidebar"><i class="fas fa-sun"></i></span>
                  </label>
                  <label class="selectgroup-item">
                    <input type="radio" name="icon-input" value="2" class="selectgroup-input select-sidebar" checked>
                    <span class="selectgroup-button selectgroup-button-icon" data-toggle="tooltip"
                      data-original-title="Dark Sidebar"><i class="fas fa-moon"></i></span>
                  </label>
                </div>
              </div>
              <div class="p-15 border-bottom">
                <h6 class="font-medium m-b-10">Color Theme</h6>
                <div class="theme-setting-options">
                  <ul class="choose-theme list-unstyled mb-0">
                    <li title="white" class="active">
                      <div class="white"></div>
                    </li>
                    <li title="cyan">
                      <div class="cyan"></div>
                    </li>
                    <li title="black">
                      <div class="black"></div>
                    </li>
                    <li title="purple">
                      <div class="purple"></div>
                    </li>
                    <li title="orange">
                      <div class="orange"></div>
                    </li>
                    <li title="green">
                      <div class="green"></div>
                    </li>
                    <li title="red">
                      <div class="red"></div>
                    </li>
                  </ul>
                </div>
              </div>
              <div class="p-15 border-bottom">
                <div class="theme-setting-options">
                  <label class="m-b-0">
                    <input type="checkbox" name="custom-switch-checkbox" class="custom-switch-input"
                      id="mini_sidebar_setting">
                    <span class="custom-switch-indicator"></span>
                    <span class="control-label p-l-10">Mini Sidebar</span>
                  </label>
                </div>
              </div>
              <div class="p-15 border-bottom">
                <div class="theme-setting-options">
                  <label class="m-b-0">
                    <input type="checkbox" name="custom-switch-checkbox" class="custom-switch-input"
                      id="sticky_header_setting">
                    <span class="custom-switch-indicator"></span>
                    <span class="control-label p-l-10">Sticky Header</span>
                  </label>
                </div>
              </div>
              <div class="mt-4 mb-4 p-3 align-center rt-sidebar-last-ele">
                <a href="#" class="btn btn-icon icon-left btn-primary btn-restore-theme">
                  <i class="fas fa-undo"></i> Restore Default
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
      <footer class="main-footer">
        <div class="footer-left">
          <a href="https://visuretech.com">Visure Tech Limited</a></a>
        </div>
        <div class="footer-right">
        </div>
      </footer>
    </div>
  </div>
  <!-- General JS Scripts -->
  <script src="assets/js/app.min.js"></script>
  <!-- JS Libraies -->
  <script src="assets/bundles/datatables/datatables.min.js"></script>
  <script src="assets/bundles/datatables/DataTables-1.10.16/js/dataTables.bootstrap4.min.js"></script>
  <script src="assets/bundles/jquery-ui/jquery-ui.min.js"></script>
  <!-- Page Specific JS File -->
  <script src="assets/js/page/datatables.js"></script>
  <!-- Template JS File -->
  <script src="assets/js/scripts.js"></script>
  <!-- Custom JS File -->
  <script src="assets/js/custom.js"></script>
  <script>
  function deleteItem(id) {
    if (confirm('Are you sure you want to delete this item?')) {
        $.ajax({
            url: 'delete.php',
            type: 'POST',
            dataType: 'json',
            data: { id: id },
            success: function(response) {
                if (response.success) {
                    alert('Item deleted successfully.');
                    location.reload(); // Reload the page to see the changes
                } else {
                    alert('Failed to delete the item.');
                }
            },
            error: function(xhr, status, error) {
                console.error(xhr.responseText);
                alert('Error occurred during deletion: ' + xhr.responseText);
            }
        });
    }
  }
</script>
<script>
function exportTableToCSV() {
    var csv = [];
    var rows = document.querySelectorAll("table tr");

    for (var i = 0; i < rows.length; i++) {
        var row = [], cols = rows[i].querySelectorAll("td, th");

        for (var j = 0; j < cols.length; j++) {
            row.push(cols[j].innerText);
        }

        csv.push(row.join(",")); 
    }

    // Download CSV file
    downloadCSV(csv.join("\n"), 'table_data.csv');
}

function downloadCSV(csv, filename) {
    var csvFile;
    var downloadLink;

    // CSV file
    csvFile = new Blob([csv], {type: "text/csv"});

    // Create download link
    downloadLink = document.createElement("a");

    // File name
    downloadLink.download = filename;

    // Link to the file
    downloadLink.href = window.URL.createObjectURL(csvFile);

    // Hide the link
    downloadLink.style.display = "none";

    // Add the link to the DOM
    document.body.appendChild(downloadLink);

    // Click the link to download
    downloadLink.click();
}
</script>
</body>


<!-- datatables.html  21 Nov 2019 03:55:25 GMT -->
</html>