<?php
	session_start();
	include("library/conn.php");
?>
<!DOCTYPE html>
<html lang="en">
	<head>
        <?php include("library/head.php");?>
        <title>Tables | <?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-bank fa-lg"></i> TABLES</h4>
					<p>Tables List 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="tables">Tables</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 Table</h5>									
                                    <hr />
								</div>
    							<div class="col-md-12">
									<form action="#" method="POST" id="registerNewTableForm">
										<div class="row">
											<div class="form-group col-md-12">
												<label class="control-label">Table Name</label>
												<input class="form-control font-weight-bold" type="text" name="txtTableNameRegisterNewTable" id="txtTableNameRegisterNewTable" placeholder="Enter table name" required>
											</div>
                                            <div class="form-group col-md-12">
                                                <label class="control-label">Table Section</label>
                                                <select id="cmbTableSectionRegisterNewTable" name="cmbTableSectionRegisterNewTable" class="form-control" style="width:100%" required />
                                                    <option value="">Select Section</option>
                                                    <option value="0">Ground Floor</option>
                                                    <option value="1">First Floor</option>
                                                </select>
                                            </div>
											<div class="form-group col-md-12">
												<label class="control-label">Description</label>
												<textarea class="form-control" rows="2" name="txtTableDescriptionRegisterNewTable" id="txtTableDescriptionRegisterNewTable" required></textarea>
												<input class="form-control" type="hidden" name="txtRegisteredByRegisterNewTable" id="txtRegisteredByRegisterNewTable" value="<?php echo $_SESSION['userIdd']; ?>" required>
												<input class="form-control" type="hidden" name="txtRegisterDateRegisterNewTable" id="txtRegisterDateRegisterNewTable" 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="btnRegisterNewTable" id="btnRegisterNewTable"><i class="fa fa-fw fa-lg fa-save"></i>Register Table</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> Tables List</h5>
									<hr />
								</div>
    							<div class="col-md-12">
    								<table class="table table-bordered table-sm" id="tablesTable">
    									<thead>
    										<tr class="text-center bg-dark text-white" height="35px">
                                                <th class="align-middle">No</th>
                                                <th class="align-middle">Table Name</th>
                                                <th class="align-middle">Table Section</th>
                                                <th class="align-middle">Action</th>
    										</tr>
    									</thead>
    									<tbody>
    										<?php
    										    $count_tables = 1;
    											$getTables = mysqli_query($conn, "SELECT * FROM tables ORDER BY tableName ASC") or die(mysqli_error($conn));
    											while ($tables_rs = mysqli_fetch_array($getTables)) { ?>
                                                    <tr>
                                                        <td class="align-middle text-center"><?php echo $count_tables; ?></td>
                                                        <td class="align-middle font-weight-bold"><?php echo $tables_rs[2]; ?></td>
                                                        <td class="align-middle" width="40%"><?php if ($tables_rs[3] == 0) echo "Ground Floor"; else echo "First Floor"; ?></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 btnUpdateTable" id="<?php echo "Update". $tables_rs[1]; ?>" data-id="<?php echo $tables_rs[1]; ?>" data-toggle="modal" data-target="#updateTableModal"><i class="fa fa-edit"></i> Edit</a>
                                                                    <a href="#" class="dropdown-item text-danger btnDeleteTable" id="<?php echo "Delete". $tables_rs[1]; ?>" data-id="<?php echo $tables_rs[1]; ?>"><i class="fa fa-trash"></i> Delete</a>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr><?php
                                                    $count_tables++;
    											}
    										?>
    									</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">
		    $("#tablesTable").DataTable({"pageLength": 100, "order": []})
            $("#cmbTableSectionRegisterNewTable").select2({ tags: false})
            $("#cmbTableSectionUpdateTable").select2({ tags: false, dropdownParent: $("#updateTableModal") })

		</script>

	</body>
</html>