<?php
	session_start();
	include("library/conn.php");
?>
<!DOCTYPE html>
<html lang="en">
	<head>
        <?php include("library/head.php");?>
        <title>Departments | <?php echo $_SESSION['systemName']; ?></title>
	</head>
	<body class="app sidebar-mini">

		<!-- Navbar-->
		<?php include("library/header.php");?>
		<!-- Sidebar menu-->
		<div class="app-sidebar__overlay" data-toggle="sidebar"></div>
		<?php include("library/sidebar.php");?>
  
		<main class="app-content">
			<div class="app-title">
				<div>
					<h4 class="text-primary"><i class="fa fa-list-ul fa-lg"></i> DEPARTMENTS</h4>
					<p>Departments Page</p>
				</div>
				<ul class="app-breadcrumb breadcrumb">
					<li class="breadcrumb-item"><i class="fa fa-home"></i></li>
					<li class="breadcrumb-item"><a href="departments">Departments</a></li>
				</ul>
			</div>
      
			<?php include("models/admin_config.php");?>
			<?php include("models/system_config.php");?>

			<div class="row">
				
				<div class="col-md-5">
					<div class="tile">
						<div class="tile-body">
							<div class="row">
								<div class="col-md-12">
                                    <h5 class="text-primary"><i class="fa fa-plus-square"></i> Register Department</h5>									
                                    <hr />
								</div>
    							<div class="col-md-12">
                                    <form action="#" method="POST" id="addNewDepartmentPageForm">
                    					<div class="row">
                    						<div class="form-group col-md-12">
                    							<label class="control-label">Department Name</label>
                    							<input class="form-control" type="text" name="txtPositionNameAddNewDepartmentPage" id="txtPositionNameAddNewDepartmentPage" placeholder="Ex: Finance department" required>
                    							<input type="hidden" name="txtRegisteredByAddNewDepartmentPage" id="txtRegisteredByAddNewDepartmentPage" value="<?php echo $_SESSION['userIdd']; ?>" required>
                    							<input type="hidden" name="txtRegisterDateAddNewDepartmentPage" id="txtRegisterDateAddNewDepartmentPage" value="<?php echo date("Y-m-d H:i:s");?>" required>
                    						</div>
                        					<div class="form-group col-md-12 text-right pt-2">
                        						<button type="submit" class="btn btn-success" name="btnAddNewDepartmentPage" id="btnAddNewDepartmentPage"><i class="fa fa-fw fa-lg fa-save"></i>Register Department</button>
                        					</div>
                        				</div>
					                </form>    							
					            </div>
						    </div>
					    </div>
				    </div>
			    </div>
			
			    <div class="col-md-7">
					<div class="tile">
						<div class="tile-body">
							<div class="row">
								<div class="col-md-12">
									<h5 class="text-primary"><i class="fa fa-list-ul"></i> Departments List</h5>
									<hr />
								</div>
    							<div class="col-md-12">
    								<table class="table table-bordered table-sm" id="propertyTypesTable">
    									<thead>
    										<tr class="text-center bg-dark text-white" height="35px">
                                                <th class="align-middle">No</th>
                                                <th class="align-middle">Department Name</th>
                                                <th class="align-middle">Action</th>
    										</tr>
    									</thead>
    									<tbody>
    										<?php
    										    $count_departments = 1;
    											$getDepartments = mysqli_query($conn, "SELECT * FROM departments ORDER BY departmentName ASC") or die(mysqli_error($conn));
    											while ($departments_rs = mysqli_fetch_array($getDepartments)) { ?>
                                                    <tr>
                                                        <td class="align-middle text-center"><?php echo $count_departments; ?></td>
                                                        <td class="align-middle" width="60%"><?php echo $departments_rs[2]; ?></td>
                                                        <td class="align-middle text-center" width="25%">
                                                            <div class="btn-group col-md-12">
                                                                <button type="button" class="btn btn-primary">Action</button>
                                                                <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown">
                                                                    <span class="caret"></span>
                                                                </button>
                                                                <div class="dropdown-menu" style="min-width: 8rem;">
                                                                    <a href="#" class="dropdown-item text-primary btnUpdateDepartment" id="<?php echo "Update". $departments_rs[1]; ?>" data-id="<?php echo $departments_rs[1]; ?>" data-toggle="modal" data-target="#updateDepartmentModal"><i class="fa fa-edit"></i> Edit</a>
                                                                    <a href="#" class="dropdown-item text-danger btnDeleteDepartment" id="<?php echo "Delete". $departments_rs[1]; ?>" data-id="<?php echo $departments_rs[1]; ?>"><i class="fa fa-trash"></i> Delete</a>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr><?php
                                                    $count_departments++;
    											}
    										?>
    									</tbody>
    								</table>
    							</div>
						</div>
					</div>
				</div>


			</div>
			
		</main>
  
		<!-- Essential javascripts for application to work-->
		<?php include("library/footer.php");?>  
		<?php include("library/scripts.php");?>
		
		<script type="text/javascript">
		    $("#propertyTypesTable").DataTable({"pageLength": 100, "order": []})
		</script>

	</body>
</html>