<?php 
	require_once('../Connections/conn_ama.php');
	
	if(!isset($_SESSION)){
        session_start();
    }
    if(isset($_POST['d'])){
        $colname = $_POST['d'];
        $deptname =$_POST['dn'];
    }

    	//Retrieve UnitsList
    	$query_rsUnitsList = "CALL deptsub_list('".$colname."')";//"SELECT deptID, `deptname`, subdeptdetailsID, dateadded  FROM v_depts ORDER BY dateadded DESC";
	    $rsUnitsList = mysqli_query($conn_ama, $query_rsUnitsList ) or die(mysqli_error($conn_ama));
	    $row_rsUnitsList = mysqli_fetch_assoc($rsUnitsList);
	    $totalRows_rsUnitsList = mysqli_num_rows($rsUnitsList);/**/
 ?>
<!-- <div class="col-md-9 data-area"> -->
	
	<div class="data-area-wrap">
        
		<div class="form-wrapper">
			<h3 class="float-left"><?php echo $deptname; ?></h3>
			<div class="float-right">
				
				<span><a href="#" class="btn btn-primary addsubunit" data-dept="<?php echo $row_rsUnitsList['deptname']; ?>" data-deptid="<?php echo $row_rsUnitsList['subdeptdetailsID']; ?>">Add Unit</a></span>
				
			</div>
			<br class="clearfix">
			<hr>
			<table id="example" class="table" cellspacing="0" width="100%">
		        <thead>
		            <tr>
		                <th>Unit</th>
		                <!-- <th>Category</th> -->
		                <!-- <th>Postion</th> -->
		                <!-- <th nowrap="nowrap">Date Added</th> -->
		                <!-- <th>Country</th> -->
		                <th>Edit</th>
		                <th>Delete</th>
		            </tr>
		        </thead>
	
		 
		        <tbody>
		        <?php do { ?>
		            <tr>
		                <td>
							<a href="#" 
								class="listunitofficers" 
								data-subunit="<?php echo $row_rsUnitsList['subunitname']; ?>"
                            	data-deptname="<?php echo $row_rsUnitsList['deptname']; ?>"
                            	data-unitid="<?php echo $row_rsUnitsList['subsubdeptID']; ?>" >
                                <?php echo $row_rsUnitsList['subunitname']; ?>
                            </a>
                        </td>
						<td><a href="#" 
								class="editunit" 
								data-editunit="<?php echo $row_rsUnitsList['subsubdeptID']; ?>"
								data-deptname="<?php echo $row_rsUnitsList['deptname']; ?>"
							><i class="fas fa-edit"></i></a></td>
						<td><a href="#"
								class="deleteunit"
								data-deleteunit="<?php echo $row_rsUnitsList['subsubdeptID']; ?>"
							><i class="fas fa-times-circle fa-1x"></i></a>
						</td>
		            </tr>
		        <?php } while($row_rsUnitsList = mysqli_fetch_assoc($rsUnitsList));?>
		            
		    	</tbody>
		    </table>
		</div><!-- End .form-wrapper-->
	</div><!-- End .data-area-wrap-->	
<!-- </div> -->

<script>

    $(document).ready( function() {
        $('#example').dataTable({
        	"pageLength": 10,
        	"order": []
        });
    });
</script>