<?php 
// Function to generate an employee ID without hyphens
function generateEmployeeID() {
    $prefix = 'VTSEMP'; // Your desired prefix
    $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $employeeID = '';
    $length = 5; // Change the length as needed

    for ($i = 0; $i < $length; $i++) {
        $employeeID .= $characters[rand(0, strlen($characters) - 1)];
    }

    return $prefix . $employeeID;
}

?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin : Add Employee</title>
    <?php include("headerlink.php")?>
    <style>
    .image-container {
        width: 200px;
        position: relative;
    }

    .image-container img {
        width: 190px;
        height: 150px;
        border: 1px solid #ccc;
        cursor: pointer;
        transition: filter 0.5s, opacity 0.5s;
    }

    .image-container:hover img {
        filter: brightness(70%) blur(5px);
    }

    .upload-options {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 100%;
        text-align: center;
        display: none;
        z-index: 1;
    }

    .image-container:hover .upload-options {
        display: block;
    }

    .upload-options a {
        text-decoration: underline;
        cursor: pointer;
    }
    </style>
</head>

<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">
        <!-- Preloader -->
        <div class="preloader flex-column justify-content-center align-items-center">
            <img class="animation__shake" src="dist/img/AdminLTELogo.png" alt="AdminLTELogo" height="60" width="60">
        </div>

        <?php include("navbar.php")?>

        <?php include("sidebar.php")?>

        <div class="content-wrapper">

            <div class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1 class="m-0 fw-bold text-uppercase">Employee</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                <li class="breadcrumb-item"><a href="#">Home</a></li>
                                <li class="breadcrumb-item active">Employee</li>
                                <li class="breadcrumb-item active">Add New</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>

            <section class="content">
                <div class="container-fluid">
                    <div class="row">

                        <div class="col-md-12">

                            <div class="card card-primary">
                                <div class="card-header" style="background: #343a40; ">
                                    <h3 class="card-title text-uppercase fw-bold">Add Employee</h3>
                                </div>
                                <form method="POST" action="add_employee_code.php" enctype=multipart/form-data>
                                    <div class="card-body">


                                        <div class="row">
                                            <div class="col-9">
                                                <div class="row">
                                                    <div class="col-6">
                                                        <div class="form-group">
                                                            <label for="exampleInputName">Employee Name</label>
                                                            <input type="text" name="name" class="form-control"
                                                                placeholder="Employee Name">
                                                        </div>
                                                    </div>
                                                    <div class="col-6">
                                                        <div class="form-group">
                                                            <label for="exampleInputPurpose">Generate Employee
                                                                ID</label>
                                                            <input type="text" name="employee_id"
                                                                value="<?php echo generateEmployeeID(); ?>" readonly
                                                                class="form-control" placeholder="Employee ID">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-6">
                                                        <div class="form-group">
                                                            <label for="exampleInputContact1">Contact Number 1</label>

                                                            <input type="text" class="form-control"
                                                                id="exampleInputName" placeholder="Contact Number"
                                                                name="number1"
                                                                oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                                        </div>
                                                    </div>
                                                    <div class="col-6">
                                                        <div class="form-group">
                                                            <label for="exampleInputContact2">Contact Number 2</label>
                                                            <input type="text" class="form-control"
                                                                id="exampleInputName" placeholder="Contact Number"
                                                                name="number2"
                                                                oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                                        </div>
                                                    </div>

                                                </div>

                                            </div>


                                            <div class="col-3 text-center">
                                                <div class="image-container"
                                                    style="margin-left: 53px; margin-top: 16px;">

                                                    <img id="selectedImage" src="dist/img/avatar5.png" alt=" "
                                                        class="img-thumbnail form-control shadow">

                                                    <div class="upload-options">
                                                        <a onclick="openFileInput()" class="fw-bold text-white">Upload
                                                            Profile</a>
                                                    </div>
                                                    <input type="file" name="file" id="fileInput"
                                                        onchange="showSelectedImage(this)" style="display: none;">
                                                </div>
                                            </div>

                                        </div>
                                        <div class="row">
                                            <div class="col-6">
                                                <div class="form-group">
                                                    <label for="exampleInputContact3">Contact Email 1</label>
                                                    <input type="email" name="email1" class="form-control"
                                                        placeholder="Contact Email">
                                                </div>
                                            </div>
                                            <div class="col-6">

                                                <label for="exampleInputContact3"> Password</label>
                                                <div class="input-group mb-3">
                                                    <input type="text" id="passwordInput" name="password"
                                                        class="form-control">
                                                    <div class="input-group-append">
                                                        <button class="btn border fw-bold"
                                                            style="background-color: #e9ecef;" type="button"
                                                            id="generatePasswordButton">Generate Password</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-3">

                                                <div class="form-group">
                                                    <label for="exampleInputContact3">Contact Email 2</label>
                                                    <input type="email" name="email2" class="form-control"
                                                        placeholder="Contact Email">
                                                </div>
                                            </div>
                                            <div class="col-3">
                                                <div class="form-group">
                                                    <label for="exampleInputContact2">Salary</label>
                                                    <input type="text" name="salary" class="form-control"
                                                        id="exampleInputContact2" placeholder="Salary">
                                                </div>
                                            </div>
                                            <div class="col-3">
                                                <div class="form-group">
                                                    <label for="exampleInputContact3">Joining Date</label>
                                                    <input type="date" name="joining_date" class="form-control"
                                                        id="exampleInputContact3" placeholder="Joining Date">
                                                </div>
                                            </div>

                                            <div class="col-3">

                                                <div class="form-group">
                                                    <label for="exampleInputContact1">Designation</label>
                                                    <input type="text" name="designation" class="form-control" i
                                                        placeholder="Designation">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-3">
                                                <div class="form-group">
                                                    <label for="exampleInputCompany">Previous Company</label>
                                                    <input type="text" name="previous_company" class="form-control"
                                                        id="exampleInputCompany" placeholder="Previous Company">
                                                </div>
                                            </div>
                                            <div class="col-3">
                                                <div class="form-group">
                                                    <label for="exampleInputCompany">Company Website</label>
                                                    <input type="text" name="company_website" class="form-control"
                                                        id="exampleInputCompany" placeholder="Company Website">
                                                </div>
                                            </div>
                                            <div class="col-2">
                                                <div class="form-group">
                                                    <label for="exampleInputCompany">Contact Person</label>
                                                    <input type="text" name="contact_person" class="form-control"
                                                        id="exampleInputCompany" placeholder="Contact Person">
                                                </div>
                                            </div>
                                            <div class="col-2">
                                                <div class="form-group">
                                                    <label for="exampleInputCompany">Contact Number</label>
                                                 
                                                    <input type="text" class="form-control" id="exampleInputName"
                                                        placeholder="Contact Number" name="contact_number"
                                                        oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                                </div>
                                            </div>
                                            <div class="col-2">
                                                <div class="form-group">
                                                    <label for="exampleInputCompany">Last Salary</label>
                                                    <input type="text" name="last_salary" class="form-control"
                                                        id="exampleInputCompany" placeholder="Last Salary">
                                                </div>
                                            </div>

                                        </div>
                                        <label for="exampleInputEmail1">Account Details</label>
                                        <div class="row">
                                            <div class="col-3">
                                                <div class="input-group mb-3">
                                                    <input type="text" name="bank_name" class="form-control"
                                                        placeholder="Bank Name">
                                                </div>
                                            </div>
                                            <div class="col-3">
                                                <div class="input-group mb-3">

                                                    <input type="text" name="account_name" class="form-control"
                                                        placeholder="Account Holder Name">
                                                </div>
                                            </div>
                                            <div class="col-3">
                                                <div class="input-group mb-3">


                                                    <input type="text" class="form-control" id="exampleInputName"
                                                        placeholder="Contact Number" name="account_number"
                                                        oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                                </div>
                                            </div>
                                            <div class="col-3">
                                                <div class="input-group mb-3">

                                                    <input type="text" name="ifsc_code" class="form-control"
                                                        placeholder="IFSC Code">
                                                </div>
                                            </div>
                                        </div>
                                        <label for="exampleInputEmail1">Social Handels</label>
                                        <div class="row">

                                            <div class="col-3">
                                                <div class="input-group mb-3">
                                                    <div class="input-group-prepend">
                                                        <span class="input-group-text"><i
                                                                class="fab fa-facebook"></i></span>
                                                    </div>
                                                    <input type="text" name="facebook_username" class="form-control"
                                                        placeholder="Facebook Username" required>
                                                    <input type="hidden" name="facebook"
                                                        value="https://www.facebook.com/">
                                                </div>
                                            </div>
                                            <div class="col-3">
                                                <div class="input-group mb-3">
                                                    <div class="input-group-prepend">
                                                        <span class="input-group-text"><i
                                                                class="fab fa-twitter"></i></span>
                                                    </div>
                                                    <input type="text" name="twitter_username" class="form-control"
                                                        placeholder="Twitter Username">
                                                    <input type="hidden" name="twitter" value="https://twitter.com/">
                                                </div>
                                            </div>
                                            <div class="col-3">
                                                <div class="input-group mb-3">
                                                    <div class="input-group-prepend">
                                                        <span class="input-group-text"><i
                                                                class="fab fa-instagram fw-bold"></i></span>
                                                    </div>
                                                    <input type="text" name="instagram_username" class="form-control"
                                                        placeholder="Instagram Username">
                                                    <input type="hidden" name="instagram"
                                                        value="https://www.instagram.com/">
                                                </div>
                                            </div>

                                            <div class="col-3">
                                                <div class="input-group mb-3">
                                                    <div class="input-group-prepend">
                                                        <span class="input-group-text"><i
                                                                class="nav-icon fa fa-linkedin"></i></span>
                                                    </div>
                                                    <input type="text" class="form-control" name="linkedin"
                                                        placeholder="LinkedIn Username">
                                                    <input type="hidden" name="linkedin"
                                                        value="https://www.linkedin.com/in/">
                                                </div>
                                            </div>


                                        </div>

                                    </div>

                                    <div class="card-footer">
                                        <button type="submit" class="btn text-white fw-bold"
                                            style="background: #343a40; ">Add Employee</button>
                                    </div>
                                </form>
                            </div>

                        </div>

                    </div>

                </div>
            </section>

        </div>
        <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>

        <script>
        document.addEventListener('DOMContentLoaded', function() {
            document.getElementById('generatePasswordButton').addEventListener('click', function() {
                var password = generateRandomPassword(); // Call the password generation function
                document.getElementById('passwordInput').value = password;
            });

            function generateRandomPassword() {
                // Implement your password generation logic here
                // This is a simple example; customize it based on your requirements
                var charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                var password = "";
                for (var i = 0; i < 8; i++) { // Change 8 to the desired password length
                    var randomIndex = Math.floor(Math.random() * charset.length);
                    password += charset.charAt(randomIndex);
                }
                return password;
            }
        });
        </script>

        <script>
        $(document).ready(function() {
            <?php if (isset($_GET['error'])) { ?>
            Swal.fire({
                title: 'Error',
                text: '<?php echo $_GET['error']; ?>',
                icon: 'error',
                confirmButtonText: 'OK',
                confirmButtonClass: 'btn btn-success btn-lg',
            });
            <?php } ?>
            <?php if (isset($_GET['success'])) { ?>
            Swal.fire({
                title: 'Success',
                text: '<?php echo $_GET['success']; ?>',
                icon: 'success',
                confirmButtonText: 'OK',
                confirmButtonClass: 'btn btn-success btn-lg',
            });
            <?php } ?>
        });
        </script>
        <script>
        function showSelectedImage(input) {
            var file = input.files[0];
            if (file) {
                var reader = new FileReader();

                reader.onload = function(e) {
                    var image = document.getElementById("selectedImage");
                    image.src = e.target.result;
                };

                reader.readAsDataURL(file);
            }
        }

        function openFileInput() {
            document.getElementById("fileInput").click();
        }
        </script>

        <?php include("footer.php")?>
    </div>


    <?php include("footerlink.php")?>
</body>

</html>