<?php

include("db.php");


$tbl = "db_users";
$pro_img = $site_url.'assets/images/profile_av.svg';
$show_name = 'Placeholder Name';
$show_email = 'placeholder@example.com';
$show_phone = '+ 123-456-7890';
$emp_list   = array();
$is_admin_login = 0;
$curr_user_type = '';

if(isset($_SESSION['loggedin_user']) && !empty($_SESSION['loggedin_user'])){
    $emp_list   = mysqli_fetch_assoc(mysqli_query($conn, "select * from db_users where id=".$_SESSION['loggedin_user']));
    
    if(!empty($emp_list['profile_img'])){
        $pro_img = $site_url.'dist/assets/profile/'.$emp_list['profile_img'];
    }
    $show_name  = $emp_list['full_name'];
    $show_email = $emp_list['email'];
    $show_phone = $emp_list['phone'];
    //if($emp_list['type'] == 'company'){ $emp_list['type'] = 'admin'; }
    $is_admin_login = ($emp_list['type'] == 'admin') ? 1 : 0;
    $curr_user_type = $emp_list['type'];
}

$curr_file = basename($_SERVER['REQUEST_URI'],'.php');
$pass_url = $site_url;
if(strpos($_SERVER['REQUEST_URI'], "/company/") !== false){
    $req_url = explode('/', $_SERVER['REQUEST_URI']);
    $req_url = array_filter($req_url);
    
    if(isset($req_url[2]) && !empty($req_url[2])){
        $pass_url = $site_url.$req_url[1].'/'.$req_url[2]."/";
    }
}
?>
<!doctype html>
<html class="no-js" lang="en" dir="ltr">

<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">
    <title><?= ucwords(str_replace('_', ' ', $curr_file)); ?> | Timetracker  </title>
    <link rel="icon" href="<?= $site_url; ?>dist/favicon.ico" type="image/x-icon"> <!-- Favicon-->
    <!-- plugin css file  -->
    <link rel="stylesheet" href="<?= $site_url; ?>dist/assets/plugin/datatables/responsive.dataTables.min.css">
    <link rel="stylesheet" href="<?= $site_url; ?>dist/assets/plugin/datatables/dataTables.bootstrap5.min.css">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
    <!-- project css file  -->
    <link rel="stylesheet" href="<?= $site_url; ?>dist/assets/css/timetracker.style.min.css?<?= time(); ?>">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/fontawesome.min.css">
   
</head>
<style type="text/css">
    span.fa.fa-bar.menu-to-icon svg {
        width: 20px;
    }
    .main-search.border-start input.form-control {
        width: 0;
        pointer-events: none;
        border: 0;
    }
    .dropdown-menu.show small:last-child {
    text-transform: capitalize;
    }
    @media(max-width: 767px){
        .notifications-inner a.nav-link.dropdown-toggle.pulse {
        padding-left: 0;
    }
    }
    @media(max-width:575px){
    .notifications-inner.h-right {
        width: 100%;
        justify-content: flex-start;
        max-width: 260px;
        margin-left: 0;
    }
    .dropdown-menu-end[data-bs-popper] {
        right: auto;
        left: auto;
    }
    .h-right .notifications {
        display: block;
    }
    }
</style>
<body class="login-as-<?= sanitize($emp_list['type']); ?>">
    <div id="timetracker-layout" class="theme-mist">

       <?php 
     
            include('sidebar.php');
            $new_site_url = $site_url;
            if(strpos($_SERVER['REQUEST_URI'], "/company/") !== false){
            $req_url = explode('/', $_SERVER['REQUEST_URI']);
            $req_url = array_filter($req_url);
            
            if(isset($req_url[2]) && !empty($req_url[2])){
                $new_site_url = $site_url.$req_url[1].'/'.$req_url[2]."/";
            }
        }
       
    ?>

        <!-- main body area -->
        <div class="main px-lg-4 px-md-4"> 

            <!-- Body: Header -->
            <div class="header">
                <nav class="navbar py-4">
                    <div class="container-xxl">

                        <!-- header rightbar icon -->
                        <div class="h-right d-flex align-items-center mr-5 mr-lg-0 order-1 notifications-inner">
                            <div class="dropdown notifications">
                                <a class="nav-link dropdown-toggle pulse" href="#" role="button" data-bs-toggle="dropdown">
                                    <svg xmlns="http://www.w3.org/2000/svg"  x="0px" y="0px" width="25px" height="25px" viewBox="0 0 38 38">
                                        <path  d="M36,34v-2h-2.98c-0.598-0.363-1.081-3.663-1.4-5.847c-0.588-4.075-1.415-9.798-4.146-13.723  C26.584,12.154,25.599,12,24.5,12c-3.646,0-5.576,1.657-7.106,4.086C15.089,19.746,14,30.126,14,33c0,2.757,2.243,5,5,5  c2.414,0,4.435-1.721,4.898-4H36z" style="fill:var(--primary-color);" data-st="fill:var(--chart-color4);"></path>
                                        <path class="st0" d="M33.02,32c-0.598-0.363-1.081-3.663-1.4-5.847c-0.851-5.899-2.199-15.254-9.101-17.604  C23.433,7.643,24,6.386,24,5c0-2.757-2.243-5-5-5s-5,2.243-5,5c0,1.386,0.567,2.643,1.482,3.549  c-6.902,2.35-8.25,11.705-9.101,17.604C6.209,27.324,5.991,28.813,5.733,30h2.042c0.192-0.961,0.376-2.127,0.586-3.562  C9.36,19.501,10.73,10,19,10c8.27,0,9.64,9.501,10.641,16.442c0.386,2.636,0.682,4.394,1.108,5.558H2v2h12.101  c0.464,2.279,2.485,4,4.899,4c2.415,0,4.435-1.721,4.899-4H36v-2H33.02z M19,8c-1.654,0-3-1.346-3-3s1.346-3,3-3s3,1.346,3,3  S20.654,8,19,8z M19,36c-1.304,0-2.416-0.836-2.829-2h5.658C21.416,35.164,20.304,36,19,36z" ></path>
                                    </svg>
                                    <span class="pulse-ring"></span>
                                </a>
                                <div id="NotificationsDiv" class="dropdown-menu rounded-lg shadow border-0 dropdown-animation dropdown-menu-md-end p-0 m-0">
                                    <div class="card border-0 w380">
                                        <div class="card-header border-0 p-3">
                                            <h5 class="mb-0 font-weight-light d-flex justify-content-between">
                                                <span>Notifications</span>
                                            
                                            </h5>
                                        </div>
                                        <div class="tab-content card-body">
                                            <div class="tab-pane fade show active">
                                                <ul class="list-unstyled list mb-0">
                                                    <?php
                                                    $get_activity = mysqli_query($conn, "SELECT * FROM db_user_activity WHERE to_user_id='".$_SESSION['loggedin_user']."' order by id DESC limit 5");
                                                    if($get_activity->num_rows > 0){
                                                        while($single_act = mysqli_fetch_array($get_activity)){
                                                            $avtar = '/assets/images/xs/avatar1.svg';
                                                            $user_name = '';
                                                            $get_user = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_users WHERE id=".$single_act['created_by']));
                                                            $user_name = $get_user['full_name'];
                                                            if(isset($get_user['profile_img']) && !empty($get_user['profile_img'])){
                                                                $avtar = $site_url."dist/assets/profile/".$get_user['profile_img'];

                                                            }
                                                            echo '<li class="py-2 mb-1 border-bottom">
                                                                        <a href="javascript:void(0);" class="d-flex">
                                                                        <img class="avatar rounded-circle" src="'.$avtar.'" alt="">
                                                                        <div class="flex-fill ms-2">
                                                                            <p class="d-flex justify-content-between mb-0 "><span class="font-weight-bold">'.$user_name.'</span> <small>'.$single_act['date_time'].'</small></p>
                                                                            <span class="">'.$single_act['title'].'</span>
                                                                        </div>
                                                                    </a>
                                                    
                                                            </li>';  
                                                        }
                                                         
                                                    } else {
                                                        echo '<li class="py-2 mb-1 border-bottom">
                                                                <p>No Notification Found.</p>
                                                            </li>';
                                                    }
                                                    ?>
                                                    
                                                    
                                                </ul>
                                            </div>
                                        </div>
                                        <a class="card-footer text-center border-top-0" href="<?= $site_url."dist/notifications.php"; ?>"> View all notifications</a>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="dropdown user-profile ml-2 ml-sm-3 d-flex align-items-center">
                                <a class="nav-link dropdown-toggle pulse p-0" href="#" role="button" data-bs-toggle="dropdown" data-bs-display="static">
                                    <img class="avatar lg rounded-circle img-thumbnail" src="<?= $pro_img; ?>" alt="profile">
                                </a>
                                <div class="dropdown-menu rounded-lg shadow border-0 dropdown-animation dropdown-menu-end p-0 m-0">
                                    <div class="card border-0 w280">
                                        <div class="card-body pb-0">
                                            <div class="d-flex py-1">
                                                <img class="avatar rounded-circle" src="<?= $pro_img; ?>" alt="profile">
                                                <div class="flex-fill ms-3" style="overflow: hidden;">
                                                    <p class="mb-0"><span class="font-weight-bold" style="text-transform: capitalize;"><?= $show_name; ?></span></p>
                                                    <small class=""><?= $show_email; ?></small>
                                                    <small class="" style="display:block;">role : <?= $emp_list['type']; ?></small>
                                                </div>
                                            </div>
                                            
                                            <div><hr class="dropdown-divider border-dark"></div>
                                        </div>
                                        <div class="list-group m-2 ">
                                            <a href="<?= $new_site_url; ?>dist/profile.php" class="list-group-item list-group-item-action border-0">
                                                <svg xmlns="http://www.w3.org/2000/svg"  x="0px" y="0px" width="24px" height="24px" viewBox="0 0 38 38" class="me-3">
                                                    <path xmlns="http://www.w3.org/2000/svg"   d="M36.15,38H1.85l0.16-1.14c0.92-6.471,3.33-7.46,6.65-8.83c0.43-0.17,0.87-0.36,1.34-0.561  c0.19-0.08,0.38-0.17,0.58-0.26c1.32-0.61,2.14-1.05,2.64-1.45c0.18,0.48,0.47,1.13,0.93,1.78C15.03,28.78,16.53,30,19,30  c2.47,0,3.97-1.22,4.85-2.46c0.46-0.65,0.75-1.3,0.931-1.78c0.5,0.4,1.319,0.84,2.64,1.45c0.2,0.09,0.39,0.17,0.58,0.26  c0.47,0.2,0.91,0.391,1.34,0.561c3.32,1.37,5.73,2.359,6.65,8.83L36.15,38z M20,13v4h-2v-4H20z" style="fill:var(--primary-color);" data-st="fill:var(--chart-color4);"></path>
                                                    <path xmlns="http://www.w3.org/2000/svg" class="st0" d="M21.67,17.34C21.22,18.27,20.29,19,19,19s-2.22-0.73-2.67-1.66l-1.79,0.891C15.31,19.78,16.88,21,19,21  s3.69-1.22,4.46-2.77L21.67,17.34z M15,10.85c-0.61,0-1.1,0.38-1.1,1.65s0.49,1.65,1.1,1.65s1.1-0.38,1.1-1.65S15.61,10.85,15,10.85  z M23,10.85c-0.61,0-1.1,0.38-1.1,1.65s0.489,1.65,1.1,1.65s1.1-0.38,1.1-1.65S23.61,10.85,23,10.85z M35.99,36.86  c-0.92-6.471-3.33-7.46-6.65-8.83c-0.43-0.17-0.87-0.36-1.34-0.561c-0.19-0.09-0.38-0.17-0.58-0.26c-1.32-0.61-2.14-1.05-2.64-1.45  c-0.521-0.42-0.7-0.8-0.761-1.29C26.55,22.74,28,19.8,28,17V4.56l-1.18,0.21C26.1,4.91,25.58,5,25.05,5  c-1.439,0-2.37-0.24-3.35-0.49C20.71,4.26,19.68,4,18.21,4c-1.54,0-2.94,0.69-3.83,1.9l1.61,1.18C16.5,6.39,17.31,6,18.21,6  c1.22,0,2.08,0.22,3,0.45C22.22,6.71,23.36,7,25.05,7c0.32,0,0.63-0.02,0.95-0.06V17c0,3.44-2.62,7-7,7s-7-3.56-7-7V6.29  C12.23,5.59,13.61,2,18.21,2c1.61,0,2.76,0.28,3.88,0.55C23.06,2.78,23.98,3,25.05,3C26.12,3,27.19,2.74,28,2.47V0.34  C27.34,0.61,26.17,1,25.05,1c-0.83,0-1.6-0.18-2.49-0.4C21.38,0.32,20.05,0,18.21,0c-5.24,0-7.64,3.86-8.18,5.89L10,17  c0,2.8,1.45,5.74,3.98,7.47c-0.06,0.49-0.24,0.87-0.76,1.29c-0.5,0.4-1.32,0.84-2.64,1.45c-0.2,0.09-0.39,0.18-0.58,0.26  c-0.47,0.2-0.91,0.391-1.34,0.561c-3.32,1.37-5.73,2.359-6.65,8.83L1.85,38h34.3L35.99,36.86z M4.18,36c0.81-4.3,2.28-4.9,5.24-6.12  c0.62-0.25,1.29-0.53,2-0.86c1.09-0.5,2.01-0.949,2.73-1.479c0.8-0.56,1.36-1.22,1.64-2.12C16.76,25.78,17.83,26,19,26  s2.24-0.22,3.21-0.58c0.28,0.9,0.84,1.561,1.64,2.12c0.721,0.53,1.641,0.979,2.73,1.479c0.71,0.33,1.38,0.61,2,0.86  c2.96,1.22,4.43,1.83,5.24,6.12H4.18z"></path>
                                                </svg>Profile
                                            </a>
                                            
                                
                                            <a href="<?= $site_url; ?>?signout=1" class="list-group-item list-group-item-action border-0 ">
                                                <svg xmlns="http://www.w3.org/2000/svg"  x="0px" y="0px" width="24px" height="24px" viewBox="0 0 24 24" class="me-3">
                                                <rect xmlns="http://www.w3.org/2000/svg" class="st0" width="24" height="24" style="fill:none;;" fill="none"></rect>
                                                <path xmlns="http://www.w3.org/2000/svg"  d="M20,4c0-1.104-0.896-2-2-2H6C4.896,2,4,2.896,4,4v16c0,1.104,0.896,2,2,2h12  c1.104,0,2-0.896,2-2V4z" style="fill:var(--primary-color);" data-st="fill:var(--chart-color4);"></path>
                                                <path xmlns="http://www.w3.org/2000/svg" class="st0" d="M15,6.81v2.56c0.62,0.7,1,1.62,1,2.63c0,2.21-1.79,4-4,4s-4-1.79-4-4c0-1.01,0.38-1.93,1-2.63V6.81  C7.21,7.84,6,9.78,6,12c0,3.31,2.69,6,6,6c3.31,0,6-2.69,6-6C18,9.78,16.79,7.84,15,6.81z M13,6.09C12.68,6.03,12.34,6,12,6  s-0.68,0.03-1,0.09V12h2V6.09z"></path>
                                                </svg>Signout
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        
                        </div>
        
                        <!-- menu toggler -->
                        <button class="navbar-toggler p-0 border-0 menu-toggle order-3" type="button" data-bs-toggle="collapse" data-bs-target="#mainHeader">
                            <span class="fa fa-bar menu-to-icon">
                                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Pro 6.1.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M0 96C0 78.33 14.33 64 32 64H416C433.7 64 448 78.33 448 96C448 113.7 433.7 128 416 128H32C14.33 128 0 113.7 0 96zM0 256C0 238.3 14.33 224 32 224H416C433.7 224 448 238.3 448 256C448 273.7 433.7 288 416 288H32C14.33 288 0 273.7 0 256zM416 448H32C14.33 448 0 433.7 0 416C0 398.3 14.33 384 32 384H416C433.7 384 448 398.3 448 416C448 433.7 433.7 448 416 448z"/></svg>
                            </span>
                        </button>
        
                        <!-- main menu Search-->
                        <div class="order-0 col-lg-4 col-md-6 col-sm-12 col-12 mb-3 mb-md-0 d-flex align-items-center">
                            <?php 
                                $comp_info = '';
                                if(!empty($emp_list['company_name']) || $emp_list['type'] == 'company' ){

                                    $cmp = ($emp_list['type'] == 'company') ? $emp_list : get_user_by_id($emp_list['company_name']);
                                    if(!empty($cmp['company_logo'])){
                                        $comp_info = "<div class='cmp_info'><a href='".$pass_url."'><img class='company-logo' src='".$site_url.'dist/assets/images/logo/'.$cmp['company_logo']."' style='    width: 90px;'> <span class='company-domain' style='font-size: 25px; display:none;'>".$cmp['username']."</span></a></div>";

                                    }

                                }
                                if(!empty($comp_info)){
                                    echo $comp_info;
                                } else {
                            ?>
                            <a class="menu-toggle-option me-3 text-primary d-flex align-items-center" href="#" title="Menu Option">
                                <svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="var(--secondary-color)" class="bi bi-ui-checks-grid" viewBox="0 0 16 16">
                                    <path style="fill:var(--secondary-color)" d="M2 10h3a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1zm9-9h3a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1h-3a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zm0 9a1 1 0 0 0-1 1v3a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-3zm0-10a2 2 0 0 0-2 2v3a2 2 0 0 0 2 2h3a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2h-3zM2 9a2 2 0 0 0-2 2v3a2 2 0 0 0 2 2h3a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H2zm7 2a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2h-3a2 2 0 0 1-2-2v-3zM0 2a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2zm5.354.854a.5.5 0 1 0-.708-.708L3 3.793l-.646-.647a.5.5 0 1 0-.708.708l1 1a.5.5 0 0 0 .708 0l2-2z"/>
                                </svg>
                            </a>
                            <div class="main-search border-start px-3 flex-fill">
                                <input class="form-control" type="text" placeholder="Enter your search key word">
                                <div class="card border-0 shadow rounded-3 search-result slidedown">
                                     <div class="card-body text-start">
                
                                        <small class="dropdown-header">Recent searches</small>
                                        <div class="dropdown-item bg-transparent text-wrap my-2">
                                            <a class="badge bg-primary" href="#">Pixelwibes <i class="fa fa-search ms-1"></i></a>
                                            <a class="badge bg-primary" href="#">Theme <i class="fa fa-search ms-1"></i></a>
                                            <a class="badge bg-primary" href="#">Tracker <i class="fa fa-search ms-1"></i></a>
                                        </div>
                
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                        </div>
                        
                    </div>
                </nav>

                <!-- topmain menu -->
                <div class="container-xxl position-relative">
                    <div class="row">
                        <div class="col-md-12">
                            
                        </div>
                    </div>
                
                </div>

            </div>