<?php include('lib/config.php');?>
<?php 
  //--------------- Category Info ----------
  $srno = 0;
								  
  $selQry_depts = "SELECT * FROM ".TBL_DEPARTMENTS." ORDER BY name";
  $deptsInfo =  $con->getMultiRow($selQry_depts, __FILE__,__LINE__);
  $totDeptsListings = count($deptsInfo);
	if($totDeptsListings>0)
	{
		?>

<table id="tblDepartmentsListings" class="table table-striped table-bordered" style="width:100%">
  <thead>
    <tr>
      <th>Sr#</th>
      <th>Name</th>
      <th>Description</th>
      <th>Status</th>
      <th>Edit</th>
      <th>Delete</th>
    </tr>
  </thead>
  <tbody>
    <?php 
		for($dept=0;$dept<$totDeptsListings;$dept++)
		{
			$srno++;
  //----------------------------------------
?>
    <tr>
      <td><?php echo $srno;?>.</td>
      <td style="text-align:left;"><?php echo $deptsInfo[$dept]['name'];?></td>
      <td style="text-align:left;"><?php echo $deptsInfo[$dept]['description'];?></td>
      <td style="text-align:left;"><?php if($deptsInfo[$dept]['status']=='1'){?>
        <button type="button" class="btn btn-sm btn-success">Active</button>
        <?php }else if($deptsInfo[$dept]['status']=='0'){?>
        <button type="button" class="btn btn-sm btn-danger">InActive</button>
        <?php }?>
      </td>
      <td><p data-placement="top" data-toggle="tooltip" title="">
          <button class="btn btn-primary btn-xs openPopup" data-title="Edit Department" data-target="edit-department.php?did=<?php echo $deptsInfo[$dept]['id'];?>"><span class="glyphicon glyphicon-pencil"></span> Edit</button>
        </p></td>
      <td><p data-placement="top" data-toggle="tooltip" title="">
          <button class="btn btn-danger btn-xs openPopup" data-title="Delete Department" data-toggle="modal" data-target="del-department.php?did=<?php echo $deptsInfo[$dept]['id'];?>" ><span class="glyphicon glyphicon-trash"></span> Delete</button>
        </p></td>
    </tr>
    <?php }
?>
  </tbody>
</table>
<?php
}?>
<script>
$(document).ready(function(e){
	
	$('#tblDepartmentsListings').DataTable();
	
	$( ".openPopup" ).click(function() {
	 
	  var dataURL = $(this).attr('data-target');
	  var dataTitle = $(this).attr('data-title');
	  
	  $('#myModal').find('.modal-title').text(dataTitle);
      //$('#myModal').modal({show:true});  
		$('.modal-body').load(dataURL,function(){
            $('#myModal').modal({show:true});
        });
	});
});
</script>
