<?php include('session.php'); ?>
<!DOCTYPE html>
<html lang="en">
  <head>
	<title>ECIMS ADMIN | ADD OFFICER MASTER DATA</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"> Add Officer Master Data </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'])) {
								$title = mysqli_real_escape_string($conn, $_POST['title']);
								$mobile = mysqli_real_escape_string($conn, $_POST['mobile']);
								$password = mysqli_real_escape_string($conn, $_POST['password']);
								$designation = mysqli_real_escape_string($conn, $_POST['designation']);
								$subdivision = $_POST['subdivision'];
							$insert = $conn->query("INSERT INTO admin (name,status,mobile,password,designation,type,subdivision) VALUES('".$title."','1','".$mobile."','".$password."','".$designation."','dept','".$subdivision."')");
							if($insert){
								$msg = 'Data Added 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>
						  ";
						}
						?>
                    <form class="forms-sample" method="POST">
                      <div class="form-group">
                        <label for="title">Name</label>
                        <input type="text" class="form-control" required name="title" id="title" placeholder="Name">
                      </div>
                      <div class="form-group">
                        <label for="mobile">Mobile</label>
                        <input type="text" class="form-control" required name="mobile" id="mobile" placeholder="Mobile">
                      </div>
                      <div class="form-group">
                        <label for="password">Password</label>
                        <input type="password" class="form-control" required name="password" id="password" placeholder="Password">
                      </div>
                      <div class="form-group">
                        <label for="designation">Designation</label>
                        <select class="form-control" name="designation" required id="designation">
                          <option value="">Select</option>
                          <option value="GE">GE</option>
                          <option value="AGE E/M">AGE E/M</option>
                          <option value="AGE B&R1">AGE B&R1</option>
                          <option value="JE CIV">JE CIV</option>
                          <option value="JE E/M">JE E/M</option>
                        </select>
                      </div>
                      <div class="form-group">
                        <label for="subdivision">Subdivision</label>
                        <select class="form-control" name="subdivision" required id="subdivision">
                          <option value="">Select</option>
						  <?php  $dept = $conn->query("SELECT * FROM subdivision WHERE isDeleted='0'"); 
						  while($fetchdept = $dept->fetch_assoc()) { ?>
                          <option value="<?php echo $fetchdept['id']; ?>"><?php echo $fetchdept['value']; ?></option>
						  <?php } ?>
                        </select>
                      </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>