<?php
include('head.php');
include('header.php'); 
include('sidebar.php'); 

$stmt = $pdo->prepare("SELECT * FROM tblpharmacy WHERE isDeleted='N' ORDER BY id DESC");
$stmt->execute();
$pharmacies = $stmt->fetchAll();
?>
<style>
.card-header.mgtop.inlineflex {
    padding: 20px;
}
a.white {
    color: white;
}
.mgtop {
    margin-top: 20px;
    margin-bottom: 20px;
}
#example_wrapper select:not([size]) {
    width: 10%;
    margin: 10px;
}
.rxtitle {
    font-size: 24px;
    font-weight: 600;
    color: #1a70b8;
}
table a.btn {
    height: max-content;
    width: max-content;
    display: inline-flex;
}
.dt-length, .dt-search {
    display: flex;
    vertical-align: middle;
    align-items: center;
}
.customdewidth {
    margin-left: 15%;
    margin-top: 80px;
    width: 85%;
    background-color: whitesmoke;
}
aside {
   width: 15%; 
}
.deindexpage .dt-search {
    float: right;
}
</style>

<section class="bgcolordefault deindexpage">
    <div class="container-fluid customdewidth">
        <div class="row">
            <div class="col-md-12">
                <div class="page-header mgtop">
                    <h1 class="rxtitle">
                        Pharmacies
                        <a href="add_pharmacy.php" class="btn float-right btn-primary">Add New Pharmacy</a>
                    </h1>
                </div>
                <div class="card">
                    <div class="card-body">
                        <table id="example" class="table table-striped table-bordered" style="width:100%;">
                            <thead>
                                <tr>
                                    <th>Pharmacy Name</th>
                                    <th>Contact Name</th>
                                    <th>Email</th>
                                    <th class="text-center">Fax</th>
                                    <th>Primary Phone</th>
                                    <!--<th>Alternate Phone</th>-->
                                    <th>Billing Address</th>
                                    <th>Type</th>
                                    <?php if($_SESSION['empType'] == 'S' || $_SESSION['empType'] == 'A'){ ?>
                                    <th class="text-center">Action</th>
                                    <?php } ?>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach($pharmacies as $pharmacy){ ?>
                                <tr>
                                    <td><?= htmlspecialchars($pharmacy['Pharmacy_Name']); ?></td>
                                    <td><?= htmlspecialchars($pharmacy['Contact_Name']); ?></td>
                                    <td><?= htmlspecialchars($pharmacy['Email']); ?></td>
                                    <td class="text-center"><?= htmlspecialchars($pharmacy['Fax']); ?></td>
                                    <td>
                                        <?= htmlspecialchars($pharmacy['Pharmacy_Primary_Phone']); ?>
                                        <?= !empty($pharmacy['Primary_Phone_Ext']) ? ' Ext: ' . htmlspecialchars($pharmacy['Primary_Phone_Ext']) : ''; ?>
                                    </td>
                                    <!--<td>-->
                                    <!--    <?= htmlspecialchars($pharmacy['Alternate_Phone']); ?>-->
                                    <!--    <?= !empty($pharmacy['Alternate_Phone_Ext']) ? ' Ext: ' . htmlspecialchars($pharmacy['Alternate_Phone_Ext']) : ''; ?>-->
                                    <!--</td>-->
                                    <td>
                                        <?= htmlspecialchars($pharmacy['BillingStreet']); ?>,
                                        <?= htmlspecialchars($pharmacy['BillingCity']); ?>,
                                        <?= htmlspecialchars($pharmacy['BillingState']); ?>,
                                        <?= htmlspecialchars($pharmacy['BillingPostalCode']); ?>
                                    </td>
                                    <td><?= htmlspecialchars($pharmacy['pharmacyType']); ?></td>
                                    <?php if($_SESSION['empType'] == 'S' || $_SESSION['empType'] == 'A'){ ?>
                                    <td class="text-center">
                                        <a href="edit_pharmacy.php?id=<?= $pharmacy['id']; ?>" title="Edit Pharmacy"><i class="fa fa-edit"></i></a>
                                    </td>
                                    <?php } ?>
                                </tr>
                                <?php } ?>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <th>Pharmacy Name</th>
                                    <th>Contact Name</th>
                                    <th>Email</th>
                                    <th class="text-center">Fax</th>
                                    <th>Primary Phone</th>
                                    <!--<th>Alternate Phone</th>-->
                                    <th>Billing Address</th>
                                    <th>Type</th>
                                    <?php if($_SESSION['empType'] == 'S' || $_SESSION['empType'] == 'A'){ ?>
                                    <th class="text-center">Action</th>
                                    <?php } ?>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <!-- /.card-body -->
                </div>
            </div>
        </div>
    </div>
</section>
<script>
    $('#example').dataTable({
        "order": [],
        "pageLength": 100
    });
</script>
<?php include('footer.php'); ?>
