<?php include('session.php'); ?>
<!DOCTYPE html>
<html lang="en">
  <head>
	<title>ECIMS ADMIN | UPDATE SUBDIVISION </title>
    <?php include('includes/head.php'); ?>
  </head>
  <body>
    <div class="container-scroller">
      <div class="horizontal-menu">
        <?php include('includes/header.php'); ?>
      </div>
      <div class="container-fluid page-body-wrapper">
        <div class="main-panel">
          <div class="content-wrapper">
            <div class="page-header">
              <h3 class="page-title"> Update Subdivision </h3>
            </div>
            <div class="row">
              <div class="col-12 grid-margin stretch-card">
                <div class="card">
                  <div class="card-body">
                      <?php $err = $msg = '';
							if(isset($_POST['submit'])) {
								$value = mysqli_real_escape_string($conn, $_POST['subvalue']);
								$id = mysqli_real_escape_string($conn, $_POST['id']);
							$insert = $conn->query("UPDATE subdivision SET value='".$value."' WHERE id='".$id."'");
							if($insert){
								$msg = 'Data Updated Successfully.';
							} else {
								$err = $conn->error;
							}
						}
						if(!empty($err)){
						  echo "
							<div class='alert alert-danger alert-dismissible'>
							  <h4><i class='fa fa-warning'></i> Error!</h4>
							  ".$err."
							</div>
						  ";
						}
						if(!empty($msg)){
						  echo "
							<div class='alert alert-success alert-dismissible'>
							  <h4><i class='fa fa-check'></i> Success!</h4>
							  ".$msg."
							</div>
						  ";
						}
                        $department = $conn->query("SELECT * FROM subdivision WHERE id='".$_GET['id']."'")->fetch_assoc();
						?>
                    <form class="forms-sample" method="POST">
                        <input type="hidden" name="id" value="<?php echo $department['id']; ?>"/>
                      <div class="form-group">
                        <label for="bNo">Subdivision</label>
                        <input type="text" class="form-control" value="<?php echo $department['value']; ?>" required name="subvalue" id="bNo" placeholder="Building No">
                      </div>
                      <button type="submit" name="submit" class="btn btn-primary me-2">Submit</button>
                    </form>
                  </div>
                </div>
              </div>
            </div>
          </div>
		  <?php include('includes/footer.php'); ?>
        </div>
      </div>
    </div>
    <?php include('includes/foot.php'); ?>
  </body>
</html>