<?php 
session_start();
require_once 'config.php';
require_once 'auth.php';
$MainPage="Master";
$Page = "Referral-Letter";
?>
<!DOCTYPE html>

<html lang="en" class="default-style">

<head>
    <title><?php echo $Proj_Title; ?></title>

    <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=no, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="" />
    <meta name="keywords" content="">
    <meta name="author" content="Codedthemes" />
    <?php include_once 'header_script.php'; ?>
    <link rel="stylesheet" href="assets/libs/datatable-buttons/buttons.dataTables.min.css">
</head>

<body>
  
    <!-- [ Layout wrapper ] Start -->
  <div class="layout-wrapper layout-1 layout-without-sidenav">
        <div class="layout-inner">
         
         <?php include 'sidenavi.php'; ?>

<div class="layout-container">
                 <div class="layout-content">

                    <!-- [ content ] Start -->
                    <div class="container-fluid flex-grow-1 container-p-y">
                     

                        <div class="row">
                            <!-- customar project  start -->
                            <div class="col-xl-12">
                                <div class="card">
                                    <div class="card-body">
                                        <div class="row align-items-center m-l-0">
                                            
                                              
                                            
                                            <div class="col-sm-2 text-left">
                                                <a href="referral-letter.php" class="btn btn-success btn-sm mb-3 btn-round"><i class="feather icon-plus"></i> Create New</a>
                                            </div>
                                         
                                           
                                        </div>
                                        <hr>

  <style>
table, td, th {  
  border: 1px solid #ddd;
  text-align: left;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  padding: 15px;
}
</style>     

<?php
if($_REQUEST["action"]=="delete")
{
  $id = $_REQUEST["id"];
  $sql11 = "DELETE FROM tbl_referral_letter WHERE id = '$id'";
  $conn->query($sql11);
  ?>
    <script type="text/javascript">
      alert("Deleted Successfully!");
      window.location.href="view-referral-letter.php";
    </script>
<?php } 
?>       
<h4 class="font-weight-bold py-3 mb-0">View Referral Letter</h4>
<div class="card mb-4">
<div class="card-body">
<div id="alert_message"></div>
<form id="validation-form" method="post" enctype="multipart/form-data">
<div class="form-row">

<div class="form-group col-md-3">
<label class="form-label">From Date </label>
<input type="date" name="FromDate" id="FromDate" class="form-control" value="<?php echo $_POST['FromDate'] ?>" autocomplete="off">
</div>
<div class="form-group col-md-3">
<label class="form-label">To Date</label>
<input type="date" name="ToDate" id="ToDate" class="form-control" value="<?php echo $_POST['ToDate'] ?>" autocomplete="off" >
</div>
<input type="hidden" name="Search" value="Search">
<div class="form-group col-md-2" style="padding-top:20px;">
<button type="submit" name="submit" class="btn btn-primary btn-finish">Search</button>
</div>
</div>

</form>
</div>
</div>
    <div class="table-responsive">
         <table id="example" class="table-striped table-bordered">
            <thead>
             <tr>
                <th>#</th>
                <th>Mrd. No</th>
                <th>Patient Name</th>
                <th>Age/Gender</th>
                <th>Address</th>   
                <th>Letter Date</th>
                                                          
                <th>Action</th>
                 <th>Print</th>


            </tr>
            </thead>
            <tbody>
          <?php 
          $i=1;
          $sql3 = "SELECT * FROM tbl_referral_letter WHERE Status=1";
          if($_REQUEST['FromDate']!=''){
                $FromDate = $_REQUEST['FromDate'];
                $sql3.=" AND CreatedDate>='$FromDate'";
          }
          if($_REQUEST['ToDate']!=''){
                $ToDate = $_REQUEST['ToDate'];
                $sql3.=" AND CreatedDate<='$ToDate'";
          }   
          //echo $sql3;
          $row3 = getList($sql3);
          foreach($row3 as $result){
           ?>      
                <tr>
                    <td><?php echo $i; ?></td>
                    <td><?php echo $result['MrdNo']; ?></td>
                 
                    <td><?php echo $result['PatientName']; ?></td>
                    <td><?php echo $result['Age']."/".$result['Gender']; ?></td>
                  
                    <td><?php echo $result['Address']; ?></td>
                    
                  
                    <td><?php echo date("d/m/Y", strtotime(str_replace('-', '/',$result['CreatedDate']))); ?></td>
                  
                    
                    <td>
                        <a href='referral-letter.php?id=<?php echo $result['id']; ?>' class="btn btn-info btn-sm"><i class="feather icon-edit"></i>&nbsp;Edit </a>
                        <a onClick="return confirm('Are you sure you want delete this record?');" href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $result['id']; ?>&action=delete" class="btn btn-danger btn-sm"><i class="feather icon-trash-2"></i>&nbsp;Delete </a>
                    </td>
                    <td><a href='javascript:void(0)' class="btn btn-info btn-sm"><i class="feather icon-printer"></i>&nbsp;Print </a></td>
               </tr>
           <?php $i++;} ?>
            </tbody>
        </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- customar project  end -->
                        </div>
                    </div>
                    <!-- [ content ] End -->
                    <!-- [ Layout footer ] Start -->
                   <?php include 'footer.php'; ?>
                    <!-- [ Layout footer ] End -->
                </div>

                
                <!-- [ Layout content ] Start -->
            </div>
            <!-- [ Layout container ] End -->
        </div>
        <!-- Overlay -->
        <div class="layout-overlay layout-sidenav-toggle"></div>
    </div>


    <!-- [ Layout wrapper] End -->



<?php include_once 'footer_script.php'; ?>
<script src="assets/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script> -->
<script src="assets/js/buttons.html5.min.js"></script>

   <script type="text/javascript">
    $(document).ready(function() {
    $('#example').DataTable({
      
       "scrollX": true,
        dom: 'Bfrtip',
        buttons: [
            
            'excelHtml5'
           
        ]
    });
});
</script>
</body>

</html>
