<?php
include('header.php');
include('../../form.php');
$frm = new formBuilder;

$id = $_GET['id'];
$res = mysqli_query($con, "SELECT * FROM tbl_theatre WHERE id='$id'");
if (!$res || mysqli_num_rows($res) == 0) {
  echo "<div class='alert alert-danger'>Theatre not found.</div>";
  exit;
}
$row = mysqli_fetch_assoc($res);
?>

<div class="content-wrapper">
  <section class="content-header">
    <h1>Edit Theatre</h1>
  </section>

  <section class="content">
    <div class="box">
      <div class="box-body">
        <form method="post" action="update_theatre.php" id="editForm">
          <input type="hidden" name="id" value="<?php echo $row['id']; ?>">

          <div class="form-group">
            <label>Theatre Name</label>
            <input type="text" name="name" class="form-control" value="<?php echo $row['name']; ?>">
            <?php $frm->validate("name", ["required", "label" => "Theatre Name"]); ?>
          </div>

          <div class="form-group">
            <label>Address</label>
            <input type="text" name="address" class="form-control" value="<?php echo $row['address']; ?>">
            <?php $frm->validate("address", ["required", "label" => "Address"]); ?>
          </div>

          <div class="form-group">
            <label>Place</label>
            <input type="text" name="place" class="form-control" value="<?php echo $row['place']; ?>">
            <?php $frm->validate("place", ["required", "label" => "Place"]); ?>
          </div>

          <div class="form-group">
            <label>State</label>
            <input type="text" name="state" class="form-control" value="<?php echo $row['state']; ?>">
            <?php $frm->validate("state", ["required", "label" => "State"]); ?>
          </div>

          <div class="form-group">
            <label>Pin Code</label>
            <input type="text" name="pin" class="form-control" value="<?php echo $row['pin']; ?>">
            <?php $frm->validate("pin", ["required", "label" => "Pin Code", "regexp" => "pin"]); ?>
          </div>

          <button class="btn btn-primary">Update Theatre</button>
          <a href="theatre_list.php" class="btn btn-secondary">Cancel</a>
        </form>
      </div>
    </div>
  </section>
</div>

<script>
<?php $frm->applyvalidations("editForm"); ?>
</script>

<?php include('footer.php'); ?>
