<?php include('session.php'); ?>
<!DOCTYPE html>
<html lang="en">
  <head>
	<title>ECIMS ADMIN | UPDATE PROFILE</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 Profile </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']);
								$id = mysqli_real_escape_string($conn, $_POST['id']);
							$insert = $conn->query("UPDATE admin SET name='".$title."',mobile='".$mobile."',password='".$password."' 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 admin WHERE id='".$_SESSION['admin']."'")->fetch_assoc();
						?>
                    <form class="forms-sample" method="POST">
                        <input type="hidden" name="id" value="<?php echo $department['id']; ?>"/>
                      <div class="form-group">
                        <label for="title">Name</label>
                        <input type="text" class="form-control" required name="title" id="title" value="<?php echo $department['name']; ?>">
                      </div>
                      <div class="form-group">
                        <label for="mobile">Mobile</label>
                        <input type="text" class="form-control" required name="mobile" id="mobile" value="<?php echo $department['mobile']; ?>">
                      </div>
                      <div class="form-group">
                        <label for="password">Password</label>
                        <input type="text" class="form-control" required name="password" id="password" value="<?php echo $department['password']; ?>">
                      </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>