<?php
 session_start();
 include "header.php";
 include "sidebar.php";
  
?>
 
       <main id="main" class="main">
     	
<?php 

require_once("config.php");

if(isset($_POST['login'])){

    $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
    $password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
	$username=$_POST['username'];
	$password=$_POST['password'];

	$result=mysqli_query($mysqli,"SELECT * FROM user where userguru='$username' and password='$password'");
	$res = mysqli_fetch_assoc($result);
	if (isset($res['Iduser']))
	{
 		
		$_SESSION['userrpp'] = $username;
		$_SESSION['namarpp']= $res['nama'];
		$_SESSION['levelrpp'] = $res['level'];
		$_SESSION['Iduser'] = $res['Iduser'];

		header("Location: index.php");
			
	}else{
	   ?>
		
       <!-- Customers Card -->
            <div class="col-xxl-3 col-md-12">
              <div class="card info-card sales-card">

               
                <div class="card-body">
                  <h5 class="card-title">Login</h5>
				  <div class="col-12">
                      <font size="2" color="#ff0000">Username dan password tidak sesuai</font>

                  <form class="row g-3 needs-validation" novalidate action="" method="POST">

                    <div class="col-12">
                      <label for="yourUsername" class="form-label">Username</label>
                      <div class="input-group has-validation">
                        
                        <input type="text" name="username" class="form-control" id="username" required>
                        <div class="invalid-feedback">Please enter your username.</div>
                      </div>
                    </div>

                    <div class="col-12">
                      <label for="yourPassword" class="form-label">Password</label>
                      <input type="password" name="password" class="form-control" id="password" required>
                      <div class="invalid-feedback">Please enter your password!</div>
                    </div>

                    <div class="col-12">
                      <div class="form-check">
                        <input class="form-check-input" type="checkbox" name="remember" value="true" id="rememberMe">
                        <label class="form-check-label" for="rememberMe">Remember me</label>
                      </div>
                    </div>
                    <div class="col-12">
                      <button class="btn btn-primary w-100" type="submit" name="login">Login</button>
                    </div>
                    <div class="col-12">
                      
                    </div>
                  </form>

                </div>
              </div>

            </div><!-- End Customers Card -->
		<?php
		
	}
} else {
	
	?>
		
	 <!-- Customers Card -->
            <div class="col-xxl-3 col-md-12">
              <div class="card info-card sales-card">

               
                <div class="card-body">
                  <h5 class="card-title">Login</h5>

                  <form class="row g-3 needs-validation" novalidate action="" method="POST">

                    <div class="col-12">
                      <label for="yourUsername" class="form-label">Username</label>
                      <div class="input-group has-validation">
                        
                        <input type="text" name="username" class="form-control" id="username" required>
                        <div class="invalid-feedback">Please enter your username.</div>
                      </div>
                    </div>

                    <div class="col-12">
                      <label for="yourPassword" class="form-label">Password</label>
                      <input type="password" name="password" class="form-control" id="password" required>
                      <div class="invalid-feedback">Please enter your password!</div>
                    </div>

                    <div class="col-12">
                      <div class="form-check">
                        <input class="form-check-input" type="checkbox" name="remember" value="true" id="rememberMe">
                        <label class="form-check-label" for="rememberMe">Remember me</label>
                      </div>
                    </div>
                    <div class="col-12">
                      <button class="btn btn-primary w-100" type="submit" name="login">Login</button>
                    </div>
                    <div class="col-12">
                      
                    </div>
                  </form>

                </div>
              </div>

            </div><!-- End Customers Card -->
		<?php
	
}
		
?>			
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			 
			


            
    
<?php
 include "footer.php";
?>
 