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

<table id="tblFilesListings" class="table table-striped table-bordered" style="width:100%">
  <thead>
    <tr>
      <th>Sr#</th>
      <th>Name</th>
      <th>Description</th>
      <th>Department</th>
      <th>Status</th>
      <th>Edit</th>
      <th>Delete</th>
    </tr>
  </thead>
  <tbody>
    <?php 
		for($file=0;$file<$totDeptsListings;$file++)
		{
			$srno++;
			//----------------------------------------
			$selQry_depts = "SELECT * FROM ".TBL_DEPARTMENTS." WHERE id = '".$filesInfo[$file]['department_id']."' ORDER BY name";
			$deptsInfo =  $con->getSingleRow($selQry_depts, __FILE__,__LINE__);
			$fileDepartment = '';
			//----------------------------------------
?>
    <tr>
      <td><?php echo $srno;?>.</td>
      <td style="text-align:left;"><?php echo $filesInfo[$file]['name'];?></td>
      <td style="text-align:left;"><?php echo $filesInfo[$file]['description'];?></td>
      <td style="text-align:left;"><?php echo isset($deptsInfo['name'])?$deptsInfo['name']:'';?></td>
      <td style="text-align:left;"><?php if($filesInfo[$file]['status']=='1'){?>
        <button type="button" class="btn btn-sm btn-success">Active</button>
        <?php }else if($filesInfo[$file]['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 File" data-target="edit-file.php?fid=<?php echo $filesInfo[$file]['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 File" data-toggle="modal" data-target="del-file.php?fid=<?php echo $filesInfo[$file]['id'];?>" ><span class="glyphicon glyphicon-trash"></span> Delete</button>
        </p></td>
    </tr>
    <?php }
?>
  </tbody>
</table>
<?php
}?>
<script>
$(document).ready(function(e){
	
	$('#tblFilesListings').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>
