<?php 
session_start();
include_once '../config.php';
$user_id = $_SESSION['Admin']['id'];
if($_REQUEST['action'] == 'getBedNo'){
$ConsultantId = $_REQUEST['id'];?>
<option value="" disabled="" selected="">Select Bed No</option>
<?php 
	$sql4 = "SELECT * FROM tbl_beds WHERE ConsultantId='$ConsultantId' AND Occupy=0";
    $row4 = getList($sql4);
    foreach($row4 as $result){
?>
    <option value="<?php echo $result['id']; ?>"><?php echo $result['Name']; ?></option>
<?php } } 

if($_POST['action']=='getOldRecord'){?>
<table id="example" class="table table-striped table-bordered" style="width:100%">
        <thead>
            <tr>
            	<th>Mrd No</th>
             <th>#</th>
             <th>Patient Name</th>
             <th>Gender</th>
             <th>Age</th>
             <th>Department</th>
            
            </tr>
        </thead>
        <tbody>
          <?php 
 $srno = 1;
 $CreatedDate = $_REQUEST['id'];
  $sql = "SELECT * FROM tbl_queue_managements WHERE InDate='$CreatedDate'";
   $rx = $conn->query($sql);
  while($nx = $rx->fetch_assoc()){

  ?>
           <tr>
           	<td><?php echo $nx['MrdNo'];?>
             <td><input type="checkbox" name="PatientChk[]" value="<?php echo $nx['MrdNo'];?>" id="PatientChk<?php echo $nx['MrdNo'];?>" class="common_selector Proccedures" onclick="chnageChkVal(<?php echo $nx['MrdNo'];?>)"></td>
              <input type="hidden" name="PatientChkVal[]" id="PatientChkVal<?php echo $nx['MrdNo'];?>" value="0"> 
               <input type="hidden" id="Mrd_No<?php echo $nx['MrdNo'];?>" name="Mrd_No[]" value="<?php echo $nx['MrdNo'];?>"> 
              <td><?php echo $nx['PatientName']; ?></td>
              <td><?php echo $nx['Gender']; ?></td>
              <td><?php echo $nx['Age']; ?></td>
        	  <td> <select class="form-control" id="Consultant<?php echo $nx['MrdNo'];?>" name="Consultant[]" required="">
              <?php 
                $sql4 = "SELECT Name,id FROM tbl_users WHERE Type='Department'";
                $row4 = getList($sql4);
                foreach($row4 as $result){
             ?>
               <option <?php if($nx['Consultant'] == $result['id']) {?> selected <?php } ?> value="<?php echo $result['id']; ?>"><?php echo $result['Name']; ?></option>
               <?php } ?>           
            </select>
        </td>            
            </tr>
             <?php $srno++;} ?>
        </tbody>
    </table>
    <input type="hidden" id="MrdNo" name="MrdNo[]" value="">
    <script type="text/javascript">
    	function chnageChkVal(mrdno){
 		if($('#PatientChk'+mrdno).prop('checked') == true) {
            $('#PatientChkVal'+mrdno).val(1);
        }
        else{
           $('#PatientChkVal'+mrdno).val(0);
            }
    	}
      $(document).ready(function() {
      $('#example').DataTable( {
        "pageLength": 1000,
        'paging': false
      });

       function get_filter(class_name)
    {
        var filter = [];
        $('.'+class_name+':checked').each(function(){
            filter.push($(this).val());
        });
        return filter;
    }

    $('.common_selector').click(function(){
        //filter_data();
        var ProccedureId = get_filter('Proccedures');
        console.log(ProccedureId);
         if(ProccedureId == ''){
              $('#MrdNo').val(0);
         }
         else{
        $('#MrdNo').val(ProccedureId);
         }

          var ProccedureIdLength = ProccedureId.length;
          var TotLength = Number(ProccedureIdLength);
          $('#totalselect').html(TotLength);
        
    });
      });
    </script>
 <?php }
?>	