<?php
session_start();
include('includes/config.php');

if(isset($_POST['login']))
  {
    $uname=$_POST['username'];
    $Password=md5($_POST['inputpwd']);
    $query=mysqli_query($con,"select ID, FullName, UserType from tblusers where UserName='$uname' && Password='$Password'");
    $ret=mysqli_fetch_array($query);
    if($ret>0){
      $_SESSION['uid']=$ret['ID'];
      $_SESSION['fullname']=$ret['FullName'];
      $_SESSION['usertype']=$ret['UserType'];
      header('location:dashboard.php');
    }
    else{
    echo "<script>alert('Invalid Details.');</script>";          
    }
  }
?>
<!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, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Mariyappa Nadar Ricemill | Login</title>

    <!-- Custom fonts for this template-->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link
        href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
        rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
            min-height: 100vh;
        }
        .bg-login-image {
            background: url('img/feal-industries.jpg'), linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 100%);
            background-size: cover;
            background-position: center;
        }
        .card {
            border-radius: 1rem;
            background: linear-gradient(135deg, #fcb69f 0%, #ffecd2 100%);
            box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
        }
        .ihita-title {
            font-size: 2rem;
            font-weight: 700;
            color: #ff6f61;
            letter-spacing: 1px;
            text-shadow: 1px 1px 0 #fff, 0 1px 2px #fcb69f;
        }
        .ihita-subtitle {
            font-size: 1rem;
            color: #6c757d;
            margin-bottom: 1.5rem;
        }
        .btn-ihita {
            background: linear-gradient(90deg, #43cea2 0%, #185a9d 100%);
            color: #fff;
            font-weight: 600;
            border-radius: 2rem;
            transition: background 0.2s;
            border: none;
        }
        .btn-ihita:hover {
            background: linear-gradient(90deg, #185a9d 0%, #43cea2 100%);
            color: #fff;
        }
        .form-control {
            border-radius: 1.5rem;
            border: 1px solid #fcb69f;
        }
        .card .text-center h1 {
            color: #185a9d;
        }
        .card .text-center p {
            color: #43cea2;
        }
        .form-group input:focus {
            border-color: #43cea2;
            box-shadow: 0 0 0 0.2rem rgba(67,206,162,.25);
        }
        a.small {
            color: #185a9d !important;
        }
        a.small:hover {
            color: #43cea2 !important;
            text-decoration: underline;
        }
    </style>

</head>

<body class="bg-gradient-primary">

    <div class="container">

        <!-- Outer Row -->
        <div class="row justify-content-center">

            <div class="col-xl-10 col-lg-12 col-md-9">
                <div class="text-center" style="margin-top:4%;">
                    <span class="ihita-title">Mariyappa Nadar Ricemill</span>
                    <div class="ihita-subtitle">User Login</div>
                </div>
                <div class="card o-hidden border-0 shadow-lg my-5">

                    <div class="card-body p-0">
                        <!-- Nested Row within Card Body -->
<form name="login" method="post">
                        <div class="row">
                            <div class="col-lg-6 d-none d-lg-block bg-login-image"></div>
                            <div class="col-lg-6">
                                <div class="p-5">
                                    <div class="text-center">
                                        <h1 class="h4 mb-4" style="font-weight:600;">Welcome Back</h1>
                                        <p style="font-size:0.95rem;color:#6c757d;">Sign in to your account</p>
                                    </div>
                                    <div class="form-group">
                                        <input type="text" class="form-control" name="username" 
                                            id="username" placeholder="Enter username" required="true">
                                    </div>
                                    <div class="form-group">
                                        <input type="password" class="form-control" name="inputpwd" 
                                            id="inputpwd" placeholder="Password" required="true">
                                    </div>
                        <input type="submit" name="login" class="btn btn-ihita btn-user btn-block" value="Login">
                                    <hr>
                                    <div class="text-center">
                                        <a class="small" href="password-recovery.php" style="font-weight:bold">Forgot Password?</a>
                                    </div>

                                     <div class="text-center">
                                        <a class="small" href="index.php" style="font-weight:bold;"><i class="fa fa-home" aria-hidden="true"></i> Home Page</a>
                                    </div>
                        
                                </div>
                            </div>
                        </div>

</form>

                    </div>
                </div>

            </div>

        </div>

    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="js/sb-admin-2.min.js"></script>

</body>

</html>