<?php
session_start();
?>
<!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.0">
    <title>Emp_Prod_Benchmark</title>
    <link rel="shortcut icon" href="images/Files_Download.png" type="image/x-icon"/>
</head>
<style>
    .split.bor{
            margin-left:10%;
            transition: 1s;  
        }
    #nav-toggle:checked ~ .split.bor
        {
            margin-left:18%;
            transition: 1s; 
        }
    
    form{
        font-family:'Times New Roman', Times, serif;
        }
    h4{
      text-align:center;
         }

    b{
        font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
        }
    .container-table{
        height: 500px;
        width: 600px;
        overflow-y: scroll;
        background-color:#ffefea;
        border-radius: 10px;
        }
    th{
      color: #73191e;
        }
    td{
      color:black;
      font-weight:600;
        }
    input.form-control
        {
    box-shadow:none;
    /* color: red; */
    border:2px solid #ced4da;
    border-radius:15px 0px 15px 0px; 
    padding:1%;
        }
    input.form-control:focus
    {
    box-shadow:none;
    /* color: red; */
    border:2px solid #ced4da;
    border-radius:15px 0px 15px 0px; 
    padding:1%;
    }
</style>
    <body>
        
            <?php 
                include ("Nav.php");
                include "Connection.php";
                if(isset($_POST['submit'])){
                $name                        = $_POST['fullname'];
                $empcode                     = $_POST['name'];
                $password                    = $_POST['password'];
                date_default_timezone_set('Asia/Kolkata');
                $curdt                       =  date('Y-m-d h:i:s');
                $Query                       = mysqli_query($con, "INSERT INTO user_reg_tbl(fullname,name,password,created_at) VALUES ('$name','$empcode','$password','$curdt')");
                
                    if($Query){            
                        ?>
                            <script>  
                            swal("Record is successfully inserted",
                                    "....",
                                    "success",
                                    {
                                        dangerMode: true,
                                        buttons: false,
                                        closeOnClickOutside: true,
                                        timer:5000,     
                                    });
                            </script>
                        <?php
                    }else{
            ?>
                            <script>
                                swal("Sorry an error occured",
                                        "....",
                                            "error",
                                            {
                                            dangerMode: true,
                                            buttons: false,
                                            closeOnClickOutside: true,
                                            timer:5000,
                                });
                            </script>
            <?php
            }
            }
            ?>
 
    <br>
    <br><br><br>
<!-- content -->

<div class="container split bor">                                                                                                   
    <div class="container-fluid p-0 m-0">
       <div class="row">
           <div class="col-md-5" >
                <form class=""  role="form" method="POST" enctype="multipart/form-data" action="" onsubmit="return valid_details();">
                    <div class="form-control m-1" style="background-color:#ffefea;">
                        <h4 style="color:#73191e">Add New Employee</h4>
                            <div class="form-group">
                                <label class="control-label"><b>Add Name:</b></label>
                                <input class="form-control" type="text" name="fullname" placeholder="Enter Full Name" value=""  required autofocus>
                            </div>
                            <div class="form-group">
                                <label class="control-label"><b>Add Employee Code:</b></label>
                                <input class="form-control" type="text"  name="name" placeholder="Enter Employee Code" value="" >
                            </div>
                        
                            <div class="form-group">
                                <label class=" control-label"><b>Add Password:</b></label>
                                <input class="form-control" type="text"  name="password" placeholder="Enter Password" value="" >
                            </div>
                     
                    
<br>
                    <center>
                    <button class="btn btn-success btn-sm btn-block" type="submit" name="submit" style="border-radius:10px 0px 10px 0px;">Submit</button> 
                    </center>
 </div>
                </form> 
            </div>
        <div class="col-md-3">
        <div class="container-table " >
                     <?php
                    // Include config file
                    require_once "Connection.php";
                    
                    // Attempt select query execution
                    $sql = "SELECT * FROM user_reg_tbl";
                    if($result = mysqli_query($con, $sql)){
                        if(mysqli_num_rows($result) > 0){
                            echo '<table class="table table-bordered table-striped" >';
                                echo "<thead>";
                                    echo "<tr>";
                                        echo "<th>Id</th>";
                                        echo "<th>Name</th>";
                                        echo "<th>Action</th>";
                                    echo "</tr>";
                                echo "</thead>";
                                echo "<tbody>";
                                while($row = mysqli_fetch_array($result)){
                                    echo "<tr>";
                                        echo "<td>" . $row['name'] . "</td>";
                                        echo "<td>" . $row['fullname'] . "</td>";
                                        echo "<td>";
                                        // echo '<a href="read.php?ID='. $row['id'] .'" class="mr-3" title="View Record" data-toggle="tooltip"><span class="fa fa-eye"></span></a>';
                                        echo '<a href="update_emp.php?id='. $row['id'] .'" class="mr-3" title="Update Record" data-toggle="tooltip"><span class="fa fa-pencil" style="color:green"></span></a>';
                                        echo '<a href="delete_emp.php?id='. $row['id'] .'" title="Delete Record" data-toggle="tooltip"><span class="fa fa-trash " style="color:red"></span></a>';
                                        echo "</td>";
                                    echo "</tr>";
                                }
                                echo "</tbody>";                            
                            echo "</table>";
                            // Free result set
                            mysqli_free_result($result);
                        } else{
                            echo '<div class="alert alert-danger"><em>No records were found.</em></div>';
                        }
                    } else{
                        echo "Oops! Something went wrong. Please try again later.";
                    }
 
                    // Close connection
                    mysqli_close($con);
                    ?>
                    </div>
                </div>
        </div>
        </div>
    </div>
  
    
   