<?php
include 'includes/config.php';
session_start();
if (strlen($_SESSION['id']==0)) {
  header('location:logout.php');
  } else{
	
?>
<?php 
 if(isset($_POST['update'])){
    $name = $_POST["studentname"];
    $password = $_POST["password"];
    $email = $_POST["email"];

    
    
          $sqls="UPDATE `admin` SET `username`='$name',`password`='$password',`email`='$email' WHERE id ='".$_POST['id']."'";
  $results = mysqli_query($con,$sqls);
if($results){
 $message ="Sucess update";
  echo "<script>alert('Success Update');
      window.location='welcome.php'</script>";
    
}else{
  echo "Failed";
   header("location:profile.php");  
}  
        

   
}
 ?>
  <?php 
       $sql = "SELECT * FROM admin WHERE id = '".$_SESSION['id']."'";
          
            $result = mysqli_query($con, $sql);
            $row = mysqli_fetch_array($result);
            
    ?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
<meta name="robots" content="noindex">
<meta name="googlebot" content="noindex">
    <title>Admin Profile </title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/heroic-features.css" rel="stylesheet">
    <style type="">
        .navbar-inverse{
            background-color: #0b0454!important;
        }
        a{
            color: #fdc010!important;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-inverse bg-success navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="welcome.php"><i class="glyphicon glyphicon-home"></i> Home</a>
            </div>
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                     <li>
                        <a href="profile.php"><i class="glyphicon glyphicon-user"></i> <?php echo $_SESSION['sname'];?></a>
                    </li>
                    <li>
                      <a href="employee-details.php"><i class="glyphicon glyphicon-folder-open"></i> Employee Data</a>
                    </li>
                    <li>
                      <a href="nps.php"><i class="glyphicon glyphicon-globe"></i> NPS</a>
                    </li>
                    <li>
                      <a href="salary-income.php"><i class="glyphicon glyphicon-screenshot"></i> Salary/Income tax </a>
                    </li>
                    <li>
                      <a href="loans.php"><i class="glyphicon glyphicon-screenshot"></i> Loans/Advance </a>
                    </li>
                    <li>
                        <a href="logout.php"><i class="glyphicon glyphicon-log-out"></i> Logout</a>
                    </li>
                    
                  
                </ul>
            </div>
        </div>
    </nav>
   
    <div class="container">
        <div class="row">
          <div class="col-md-12 ">
            <div class="col-md-12 bg-success">
                <h3 class="h3"><?php echo $_SESSION['sname']; ?>, You can change your profile here.</h3>
            </div>
              <div class="col-md-6 col-lg-6 col-md-offset-3">
                  <form action="" method="post" enctype="multipart/form-data">
                      <div class="form-group">
                            <label >Admin Name <span class="text-danger">*</span></label>
                            <input type="text" name="id" value="<?php echo $row['id'] ?>" hidden>
                             <input type="text" class="form-control" id="studentname"
                                                            placeholder="Enter Admin Name" value="<?php echo $row['username'] ?>" name="studentname" required>
                            
                        </div>
                         
                        
                        
                         <div class="form-group">
                            <label >Person Email <span class="text-danger">*</span></label>
                            <input type="email" class="form-control" id="exampleInputmail"
                                                            placeholder="Enter Person Email" value="<?php echo $row['email'] ?>" name="email" required>
                            
                        </div>
                        <div class="form-group">
                            <label >Password <span class="text-danger">*</span></label>
                            <input type="password" class="form-control" id="myInput"
                                                            placeholder="Enter Person password" value="<?php echo $row['password'] ?>" name="password" required>
                                                            <!-- An element to toggle between password visibility -->
<input type="checkbox" onclick="myFunction()"> Show Password
                           
                        </div>

                        <input type="reset" name="" value="reset" class="btn btn-warning">
                        <input type="submit" name="update" value="Update" class="btn btn-primary">
                  </form>
              </div> 
          </div>  
        </div>
    </div>
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script>
        function myFunction() {
  var x = document.getElementById("myInput");
  if (x.type === "password") {
    x.type = "text";
  } else {
    x.type = "password";
  }
} 
    </script>
</body>

</html>
<?php }?>