<!DOCTYPE html>
<html lang="en">
<?php
require_once "config.php";

if (!isset($_SESSION['emp_id'])) {
    echo "<script>location.href='index';</script>";
}


$currentPageName = pathinfo(substr($_SERVER['PHP_SELF'], 1), PATHINFO_FILENAME);

$only_top_array = array('dashboard', 'importEmployees', 'importAttendance', 'importEmployeesSalary', 'add_salary', 'all_salary', 'paySlipRequest', 'departments', 'designations', 'asset_types', 'promotions', 'leave_policy', 'work_policy', 'probation', 'utilize_leaves', 'raw_attendance', 'leave_incash', 'notALeave');
if ((in_array($currentPageName, $only_top_array) && ($_SESSION['user_role'] != 0))) {
    echo "<script>location.href='404';</script>";
    exit();
}

$top_array = array('add_users', 'all_users','punctualityResult', 'add_password', 'add_assets', 'all_letters', 'internship_letter', 'full_time_letter', 'appraisal_letter', 'relieving_letter');
if ((in_array($currentPageName, $top_array) && ($_SESSION['user_role'] == 2))) {
    echo "<script>location.href='404';</script>";
    exit();
}

$mid_array_letter = array('all_letters', 'internship_letter', 'full_time_letter', 'appraisal_letter', 'relieving_letter');
if ((in_array($currentPageName, $mid_array_letter) && ($_SESSION['user_role'] == 1) && ($_SESSION['emp_id']!='NI97'))) {
    echo "<script>location.href='404';</script>";
    exit();
}

$low_array = array('add_issueDate', 'add_leaveRequest');
if ((in_array($currentPageName, $low_array) && ($_SESSION['user_role'] == 0))) {
    echo "<script>location.href='404';</script>";
    exit();
}


?>

<head>
    <meta charset="utf8" />
    <title>Employee - Jobaaj </title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="A fully featured admin theme which can be used to build CRM, CMS, etc." name="description" />
    <meta content="Coderthemes" name="author" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <!-- Favicon -->
    <link rel="shortcut icon" href="https://cdn.nishtyainfotech.com/content/jobaaj/assets/img/jobaaj-favicon.ico">

    <!-- plugin css -->
    
    <link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css" rel="stylesheet" type="text/css" />
    <link href="https://cdn.datatables.net/buttons/2.4.2/css/buttons.bootstrap5.min.css" rel="stylesheet" type="text/css">
    <link href="https://cdn.datatables.net/colreorder/1.7.0/css/colReorder.bootstrap5.min.css" rel="stylesheet" type="text/css">
    <link href="https://cdn.datatables.net/fixedheader/3.4.0/css/fixedHeader.dataTables.min.css" rel="stylesheet" type="text/css">
    <link href="https://cdn.datatables.net/keytable/2.10.0/css/keyTable.dataTables.min.css" rel="stylesheet" type="text/css">
    <link href="https://cdn.datatables.net/responsive/2.5.0/css/responsive.dataTables.min.css" rel="stylesheet" type="text/css" />
    <link href="https://cdn.datatables.net/rowreorder/1.4.1/css/rowReorder.dataTables.min.css" rel="stylesheet" type="text/css">
    <link href="https://cdn.datatables.net/select/1.7.0/css/select.dataTables.min.css" rel="stylesheet" type="text/css" />



    <!-- plugins -->
    <link href="assets/libs/flatpickr/flatpickr.min.css" rel="stylesheet" type="text/css" />

    <!-- select picker -->
    <link href="assets/libs/bootstrap-tagsinput/bootstrap-tagsinput.css" rel="stylesheet" />
    <link href="assets/libs/select2/select2.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/libs/multiselect/multi-select.css" rel="stylesheet" type="text/css" />

    <!-- App css -->
    <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />

    <!-- <link href="assets/css/bootstrap-dark.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/app-dark.min.css" rel="stylesheet" type="text/css" /> -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/app.min.css" rel="stylesheet" type="text/css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
</head>
<style>
    /* width */
    ::-webkit-scrollbar {
        width: 5px;
        height: 5px;
    }

    /* Track */
    ::-webkit-scrollbar-track {
        background: #f1f1f1;
    }

    /* Handle */
    ::-webkit-scrollbar-thumb {
        background: #7e8ce9;
        border-radius: 10px;
    }

    /* Handle on hover */
    ::-webkit-scrollbar-thumb:hover {
        background: #5369f8;
    }
</style>
<style>
    .btn-padding {
            padding: 0.2rem;
            /* padding-bottom: 0.2rem; */
        }
    .btn-filter {
            cursor: default !important;
            border-radius: 40px !important;
            background-color: #188758 !important;
        }

        .btn-filter i {
            cursor: pointer;
            margin-bottom:-2px
        }
</style>
<style>
    /* The switch - the box around the slider */
    .switch {
        position: relative;
        display: inline-block;
        width: 50px;
        height: 20px;
    }

    /* The slider */
    .slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: #ccc;
        -webkit-transition: 0.3s;
        transition: 0.3s;
    }

    .slider:before {
        position: absolute;
        content: "";
        height: 15px;
        width: 15px;
        right: 4px;
        top: 50%;
        transform: translateY(-50%);
        background-color: white;
        -webkit-transition: 0.3s;
        transition: 0.3s;
    }

    .slider-active {
        background-color: #2196F3;
        box-shadow: 0 0 1px #2196F3;
    }

    .slider-active:before {
        /* -webkit-transform: translateX(26px);
        -ms-transform: translateX(26px);
        transform: translateX(26px); */
        right: auto;
        left: 4px;
        transition: 0.3s all ease-in-out;
    }

    /* Rounded sliders */
    .slider.round {
        border-radius: 34px;
    }

    .slider.round:before {
        border-radius: 50%;
    }
</style>

<style>
    .dataTables_processing{
        z-index: 99;
    }
    .dataTables_wrapper .top{
        display: flex;
        align-items: end;
        padding-bottom: 0.5rem;
    }
    .dataTables_wrapper .top label{
        margin: 0;
    }
    .dataTables_wrapper .top > div:nth-child(1){
        margin-right: 1rem;
    }
    .dataTables_wrapper .top > div:nth-child(3){
        flex:1;
    }
    div.dt-buttons {
        display: inline-flex !important;
        margin-bottom:0 !important;
    }
    .dataTables_wrapper .bottom{
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-top: 0.5rem;
    }
    .dataTables_wrapper .bottom > .dataTables_info{
        padding: 0;
    }
    .dataTables_length select{
        font-weight: 400;
        color: #4b4b5a;
        background-color: #fff;
        background-clip: padding-box;
        border: 1px solid #e2e7f1;
        height: calc(1.5em + 0.5rem + 2px);
        padding: 0.25rem 0.5rem;
        font-size: .76562rem;
        /* line-height: 1.5; */
        border-radius: 0.2rem;
    }

    .dt-buttons button{
        font-weight: 400;
        /* color: #4b4b5a !important; */
        /* background-color: #fff !important; */
        /* background-clip: padding-box; */
        /* border: 2px solid #e2e7f1 !important; */
        /* height: calc(1.5em + 0.5rem + 2px); */
        padding: 0.5rem 0.5rem !important;
        font-size: .76562rem;
        line-height: 1.5;
        border-radius: 0.2rem;
    }
    /* .buttons-collection:hover, .buttons-collection:active{
        background-color: #fff;
        border: 1px solid #e2e7f1;
        color: #4b4b5a;
        box-shadow: none;
    } */
    @media only screen and (max-width:575px){
        .dataTables_wrapper .top{
            flex-direction: column;
            justify-content: start;
            align-items:start;
            gap:0.5rem;
        }
        .dataTables_wrapper .bottom{
            flex-direction: column;
            justify-content: start;
            align-items: start;
        }
    }
    </style>


<body>

    <script src="./cookieFunction.js"></script>

    <!-- Begin page -->
    <div id="wrapper">

        <div class="toast mb-0 px-3 text-dark" id="changesSuccessToast" style="position:fixed; top:5rem; right:0; z-index:99; padding-top:0.7rem; padding-bottom:0.7rem; background:#aaebd3; max-width:fit-content; opacity:1; display:none;" role="alert">
            <strong>Hey ! <span id="userChangeSuccName"></span></strong> <span id="SuccessMSG"></span>
            <button type="button" class="btn btn-sm text-dark p-0" data-bs-dismiss="alert" aria-label="Close" onclick="$('#changesSuccessToast').fadeOut('slow');"><i data-feather="x"></i></button>
        </div>
        <div class="toast mb-0 px-3 text-white" id="changesFailedToast" style="position:fixed; top:5rem; right:0; z-index:99; padding-top:0.7rem; padding-bottom:0.7rem; background:#ff8787; max-width:fit-content; opacity:1; display:none;" role="alert">
            <strong>Hey ! <span id="userChangeFailName"></span></strong> <span id="FailedMSG"></span>
            <button type="button" class="btn btn-sm text-white p-0" data-bs-dismiss="alert" aria-label="Close" onclick="$('#changesSuccessToast').fadeOut('slow');"><i data-feather="x"></i></button>
        </div>
        <script>
            function successMessage(message, name = '') {
                $("#userChangeSuccName").text(name)
                $("#SuccessMSG").text(message)
                $("#changesSuccessToast").fadeIn('slow');

                setTimeout(() => {
                    $("#changesSuccessToast").fadeOut('slow');
                }, 3000);
            }

            function failedMessage(message, name = '') {
                $("#userChangeFailName").text(name)
                $("#FailedMSG").text(message)
                $("#changesFailedToast").fadeIn('slow');

                setTimeout(() => {
                    $("#changesFailedToast").fadeOut('slow');
                }, 3000);
            }
        </script>

        <?php if(!isset($_COOKIE['birthday_strip'])){ ?>
            <?php
            $today_date = date("Y-m");
            $birthday = mysqli_query($db, "SELECT employee_id, name, dob FROM users where (COALESCE(working_status_date,'')='' or DATE_FORMAT(STR_TO_DATE(working_status_date, '%Y-%m-%d'),'%Y-%m')>='$today_date') ORDER BY name asc");
            $today = date("d-m");
            $top = 0;
            $birthdayBoy = false;
            while ($birth = mysqli_fetch_assoc($birthday)) {
                $dob = date("d-m", strtotime($birth['dob']));
                if (!empty($birth['dob']) && $today == $dob && $_SESSION['emp_id']==$birth['employee_id']) {
                    $birthdayBoy = true;
                }
                if (!empty($birth['dob']) && $today == $dob && $_SESSION['emp_id']!=$birth['employee_id']) {
                    $top += 5;
            ?>
                <div class="toast mb-0 px-3 text-white" id="birthdayToast<?php echo $top; ?>" style="position:fixed; top:<?php echo $top; ?>rem; right:50%; z-index:99; padding-top:0.7rem; padding-bottom:0.6rem; background:#ff0023; max-width:fit-content; opacity:1; transform: translateX(50%); font-size:1rem;" role="alert">
                    <div class="d-flex align-items-center justify-content-between">
                        <div class="d-flex align-items-center justify-content-start flex-wrap">
                            <strong>Hey&nbsp;!&nbsp;<span><?php echo str_replace(" ","&nbsp;",$_SESSION['user_name']); ?></span></strong> <span>Today&nbsp;is&nbsp;<strong><?php echo str_replace(" ","&nbsp;",$birth['name']); ?>'s&nbsp;Birthday</strong>, Wish&nbsp;him/her&nbsp;a <strong>HAPPY&nbsp;BIRTHDAY</strong></span>
                        </div>
                        <button type="button" class="btn btn-sm text-white p-0 ml-3" data-bs-dismiss="alert" aria-label="Close" onclick="$('#birthdayToast<?php echo $top; ?>').fadeOut('slow'); setCookie('birthday_strip','seen',1);"><i data-feather="x"></i></button>
                    </div>
                </div>
            <?php }} ?>
        <?php } ?>

        <?php if(!isset($_COOKIE['confetti']) && $birthdayBoy){ ?>
            <style>
                #birthday_cake{
                    position: fixed; 
                    top: 5rem; 
                    left: 50%; 
                    z-index: 99; 
                    width: 400px; 
                    transform:translateX(-50%); 
                    display:none;
                }
                @media screen and (max-width:575px){
                    #birthday_cake{
                        width: 100%;
                    }
                }
            </style>
            <img src="<?php echo $url; ?>birthday/birthday_cake.gif" id="birthday_cake" alt="">
            <script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.4.0/dist/confetti.browser.min.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.2.3/howler.min.js"></script>
            <script>
                var colors = ["#377DFF", "#efd430", "$ff0000"];
                let time = true;
                setTimeout(() => {
                    time = false;
                    $("#birthday_cake").fadeOut('slow');
                }, 20000);
                function frame() {
                    if (time) {
                    confetti({
                        particleCount: 3,
                        angle: 60,
                        spread: 80,
                        origin: {
                        x: 0,
                        y: 1
                        },
                        colors: colors,
                    });
                    confetti({
                        particleCount: 3,
                        angle: 120,
                        spread: 80,
                        origin: {
                        x: 1,
                        y: 1
                        },
                        colors: colors,
                    });
                    requestAnimationFrame(frame);
                    }

                }
                $("#birthday_cake").fadeIn('slow');
                frame();
                var sound = new Howl({
                    src: ['<?php echo $url; ?>birthday/Happy Birthday.mp3'],
                    html5: true,
                    volume: 1
                });
                sound.play();
                setCookie("confetti","seen",1);
            </script>
        <?php } ?>
        
        <!-- Topbar Start -->
        <div class="navbar navbar-expand flex-column flex-md-row navbar-custom">
            <div class="container-fluid">
                <!-- LOGO -->
                <a href="index" class="navbar-brand mr-0 mr-md-2 logo">
                    <span class="logo-lg">
                        <img src="https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj1.png" alt="" width="80" />
                        <!-- <span class="d-inline h5 ml-1 text-logo">Shreyu</span> -->
                    </span>
                    <span class="logo-sm">
                        <img src="https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj1.png" alt="" height="24">
                    </span>
                </a>

                <ul class="navbar-nav bd-navbar-nav flex-row list-unstyled menu-left mb-0">
                    <li class="">
                        <button class="button-menu-mobile open-left disable-btn">
                            <i data-feather="menu" class="menu-icon"></i>
                            <i data-feather="x" class="close-icon"></i>
                        </button>
                    </li>
                </ul>

                <ul class="navbar-nav flex-row ml-auto d-flex list-unstyled topnav-menu float-right mb-0">

                    <!-- <li class="dropdown notification-list mr-3">
                        <a href="javascript:;" class="nav-link">
                            <div class="d-flex align-items-center justify-content-center">
                                <span class="mr-2"><strong> Punch In </strong></span>
                                <label class="switch mb-0" id="wfhSwitch">
                                    <span class="slider round" id="wfhSlider"></span>
                                </label>
                                <span class="ml-2"><strong> Punch Out </strong></span>
                            </div>
                        </a>
                    </li> -->

                    <?php if($_SESSION['user_role']==0){ ?>
                    <li class="dropdown notification-list" data-toggle="tooltip" data-placement="left" title="Settings">
                        <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="false"
                            aria-expanded="false">
                            <i data-feather="settings"></i>
                            <!-- <span class="noti-icon-badge"></span> -->
                        </a>
                        <div class="dropdown-menu dropdown-menu-right dropdown-lg">

                            <!-- item-->
                            <div class="dropdown-item noti-title border-bottom">
                                <h4 class="m-0">
                                    <i class="uil uil-info-circle text-primary mr-1"></i> More Settings
                                </h4>
                            </div>

                            <div class="slimscroll noti-scroll">

                                <style>
                                    .dropdown-item:focus, .dropdown-item:hover{
                                        color: #5369f8;
                                        background-color: #f7f7ff;
                                    }
                                    .dropdown-item.active{
                                        border-left: 3px solid #5369f8;
                                        color: #5369f8;
                                        background-color: #f7f7ff;
                                    }
                                </style>

                                <!-- item-->
                                <a href="departments" class="dropdown-item notify-item border-bottom <?php echo ($currentPageName=='departments')?'active':''; ?> py-2">
                                    <p class="d-flex align-items-center mb-0"><i class="uil uil-building mr-2 text-primary" style="font-size:16px;"></i> <span style="font-size:14px;">Departments</span></p>
                                </a>

                                <!-- item-->
                                <a href="designations" class="dropdown-item notify-item border-bottom <?php echo ($currentPageName=='designations')?'active':''; ?> py-2">
                                    <p class="d-flex align-items-center mb-0"><i class="uil uil-arrow-growth mr-2 text-primary" style="font-size:16px;"></i> <span style="font-size:14px;">Designations</span></p>
                                </a>

                                <!-- item-->
                                <a href="asset_types" class="dropdown-item notify-item border-bottom <?php echo ($currentPageName=='asset_types')?'active':''; ?> py-2">
                                    <p class="d-flex align-items-center mb-0"><i class="uil uil-list-ui-alt mr-2 text-primary" style="font-size:16px;"></i> <span style="font-size:14px;">Asset Types</span></p>
                                </a>

                                <!-- item-->
                                <a href="promotions" class="dropdown-item notify-item border-bottom <?php echo ($currentPageName=='promotions')?'active':''; ?> py-2">
                                    <p class="d-flex align-items-center mb-0"><i class="uil uil-chart-growth mr-2 text-primary" style="font-size:16px;"></i> <span style="font-size:14px;">Promotions</span></p>
                                </a>

                                <!-- item-->
                                <a href="leave_policy" class="dropdown-item notify-item border-bottom <?php echo ($currentPageName=='leave_policy')?'active':''; ?> py-2">
                                    <p class="d-flex align-items-center mb-0"><i class="uil uil-database mr-2 text-primary" style="font-size:16px;"></i> <span style="font-size:14px;">Leave Policy</span></p>
                                </a>

                                <!-- item-->
                                <a href="utilize_leaves" class="dropdown-item notify-item border-bottom <?php echo ($currentPageName=='utilize_leaves')?'active':''; ?> py-2">
                                    <p class="d-flex align-items-center mb-0"><i class="uil uil-calendar-slash mr-2 text-primary" style="font-size:16px;"></i> <span style="font-size:14px;">Utilize Leaves</span></p>
                                </a>
                                <!-- item-->
                                <a href="leave_incash" class="dropdown-item notify-item border-bottom <?php echo ($currentPageName=='leave_incash')?'active':''; ?> py-2">
                                    <p class="d-flex align-items-center mb-0"><i class="uil uil-dollar-alt mr-2 text-primary" style="font-size:16px;"></i> <span style="font-size:14px;">In Cash Leaves</span></p>
                                </a>

                                <!-- item-->
                                <a href="probation" class="dropdown-item notify-item border-bottom <?php echo ($currentPageName=='probation')?'active':''; ?> py-2">
                                    <p class="d-flex align-items-center mb-0">
                                        <i class="uil uil-info-circle mr-2 text-primary" style="font-size:16px;"></i> 
                                        <span style="font-size:14px;">Probation Complete</span> 
                                        <?php
                                            echo '<span class="btn btn-danger badge ml-3" style="font-size:10px;" id="" data-toggle="tooltip" data-placement="top" title="Total no of Probation Complete">';
                                            $today_date = date("Y-m-d");
                                            $ps = mysqli_num_rows(mysqli_query($db, "SELECT * FROM users where probation_date!='' and probation_date<='$today_date' and (con_after_prob='' or con_after_prob is null)"));
                                            echo $ps;
                                            echo '</span>';
                                        ?>
                                    </p>
                                </a>

                                 <!-- item-->
                                 <a href="raw_attendance" class="dropdown-item notify-item border-bottom <?php echo ($currentPageName=='raw_attendance')?'active':''; ?> py-2">
                                    <p class="d-flex align-items-center mb-0"><i class="uil uil-calendar-alt mr-2 text-primary" style="font-size:16px;"></i> <span style="font-size:14px;">Raw Attendance Data</span></p>
                                </a>

                                <!-- item-->
                                <a href="work_policy" class="dropdown-item notify-item border-bottom <?php echo ($currentPageName=='work_policy')?'active':''; ?> py-2">
                                    <p class="d-flex align-items-center mb-0"><i class="uil uil-file-check-alt mr-2 text-primary" style="font-size:16px;"></i> <span style="font-size:14px;">Work Policy</span></p>
                                </a>

                            </div>

                        </div>
                    </li>
                    <?php } ?>

                    
                    <li data-toggle="tooltip" data-placement="left" title="Logout">
                        <a href="logout.php" class="nav-link">
                            <i data-feather="log-out"></i>
                        </a>
                    </li>

                </ul>
            </div>

        </div>
        <!-- end Topbar -->