<?php
	session_start();
	include("library/conn.php");
?>
<!DOCTYPE html>
<html lang="en">
	<head>
        <?php include("library/head.php");?>
        <title>Working Areas | <?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-globe fa-lg"></i> WORKING AREAS</h4>
					<p>Employee Working Areas 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="working-areas">Working Areas</a></li>
				</ul>
			</div>
      
			<?php include("models/admin_config.php");?>
			<?php include("models/system_config.php");?>

			<div class="row">
				
				<div class="col-md-4">
					<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 New Area</h5>									
                                    <hr />
								</div>
    							<div class="col-md-12">
									<form action="#" method="POST" id="registerNewWorkingAreaForm">
										<div class="row">
											<div class="form-group col-md-12">
												<label class="control-label">Area Name</label>
												<input class="form-control font-weight-bold" type="text" name="txtWorkingAreaNameRegisterNewWorkingArea" id="txtWorkingAreaNameRegisterNewWorkingArea" placeholder="Enter working area name" required>
											</div>
											<div class="form-group col-md-12">
												<label class="control-label">Description</label>
												<textarea class="form-control" rows="2" name="txtWorkingAreaDescriptionRegisterNewWorkingArea" id="txtWorkingAreaDescriptionRegisterNewWorkingArea" placeholder="Enter area description" required></textarea>
												<input class="form-control" type="hidden" name="txtRegisteredByRegisterNewWorkingArea" id="txtRegisteredByRegisterNewWorkingArea" value="<?php echo $_SESSION['userIdd']; ?>" required>
												<input class="form-control" type="hidden" name="txtRegisterDateRegisterNewWorkingArea" id="txtRegisterDateRegisterNewWorkingArea" value="<?php echo date("Y-m-d H:i:s"); ?>" required>
											</div>
											<div class="form-group col-md-12 text-right">
												<button type="submit" class="btn btn-success" name="btnRegisterNewWorkingArea" id="btnRegisterNewWorkingArea"><i class="fa fa-fw fa-lg fa-save"></i>Register Area</button>
											</div>
										</div>
									</form> 							
					            </div>
						    </div>
					    </div>
				    </div>
			    </div>
			
			    <div class="col-md-8">
					<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> Working Areas List</h5>
									<hr />
								</div>
    							<div class="col-md-12">
    								<table class="table table-bordered table-sm" id="workingAreasTable">
    									<thead>
    										<tr class="text-center bg-dark text-white" height="35px">
                                                <th class="align-middle">No</th>
                                                <th class="align-middle">Area Name</th>
                                                <th class="align-middle">Description</th>
                                                <th class="align-middle">Action</th>
    										</tr>
    									</thead>
    									<tbody>
    										<?php
    										    $count_areas = 1;
    											$getWorkingAreas = mysqli_query($conn, "SELECT * FROM working_areas ORDER BY workingAreaID ASC") or die(mysqli_error($conn));
    											while ($areas_rs = mysqli_fetch_array($getWorkingAreas)) { ?>
                                                    <tr>
                                                        <td class="align-middle text-center"><?php echo $count_areas; ?></td>
                                                        <td class="align-middle font-weight-bold"><?php echo $areas_rs[2]; ?></td>
                                                        <td class="align-middle"><?php echo $areas_rs[3]; ?></td>
                                                        <td class="align-middle text-center" width="25%">
                                                            <div class="btn-group col-md-12">
                                                                <button type="button" class="btn btn-primary" data-toggle="dropdown">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 btnUpdateWorkingArea" id="<?php echo "Update". $areas_rs[1]; ?>" data-id="<?php echo $areas_rs[1]; ?>" data-toggle="modal" data-target="#updateWorkingAreaModal"><i class="fa fa-edit"></i> Edit</a>
                                                                    <a href="#" class="dropdown-item text-danger btnDeleteWorkingArea" id="<?php echo "Delete". $areas_rs[1]; ?>" data-id="<?php echo $areas_rs[1]; ?>"><i class="fa fa-trash"></i> Delete</a>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr><?php
                                                    $count_areas++;
    											}
    										?>
    									</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">
		    $("#workingAreasTable").DataTable({"pageLength": 100, "order": []})
            $("#cmbTableSectionRegisterNewTable").select2({ tags: false})
            $("#cmbTableSectionUpdateTable").select2({ tags: false, dropdownParent: $("#updateTableModal") })

		</script>

	</body>
</html>