 <?php
$curr_file = basename($_SERVER['SCRIPT_NAME']);
$old_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])){
        $site_url = $site_url.$req_url[1].'/'.$req_url[2]."/";
    }
}
?>

 <!-- sidebar -->
        <div class="sidebar px-4 py-4 py-md-5 me-0">
            <div class="d-flex flex-column h-100">

                <a href="<?= $site_url; ?>" class="mb-0 brand-icon">
                    <span class="logo-icon">
                        <i class="icofont-stopwatch fs-2"></i>
                    </span>
                    <span class="logo-text">Timesheethub</span>
                </a>

                <!-- Menu: main ul -->
                <ul class="menu-list flex-grow-1 mt-3">
                    <li><a class="m-link <?= (($curr_file == 'index.php') ? "active" : ""); ?>" href="<?= $site_url; ?>"><i class="icofont-home fs-5"></i> <span>Dashboard</span></a></li>
                    <!-- <li class="collapsed">
                        <a class="m-link" data-bs-toggle="collapse" data-bs-target="#menu-report" href="#">
                            <i class="icofont-chart-pie fs-5"></i><span>Reports</span><span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span>
                        </a>
                        
                        <ul class="sub-menu collapse" id="menu-report">
                            <li><a class="ms-link" href="#">Attendance</a></li>
                            <li><a class="ms-link" href="#">Hours Tracked</a></li>
                            <li><a class="ms-link" href="#">Timeline</a></li>
                            <li><a class="ms-link" href="#">Employee Logs</a></li>
                        </ul>
                    </li>
                    <li><a class="m-link" href="#"><i class="icofont-computer fs-5"></i> <span>Screencasts</span></a></li> -->
                    <li class="collapsed">
                        <a class="m-link" data-bs-toggle="collapse" data-bs-target="#menu-order" href="#">
                            <i class="icofont-tasks fs-5"></i> <span>Projects</span> <span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span>
                        </a>
                        <!-- Menu: Sub menu ul -->
                        <ul class="sub-menu collapse" id="menu-order">
                            <li><a class="ms-link <?= (($curr_file == 'projects.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/projects.php">Project List</a></li>
                           <?php if($emp_list['type'] != 'employee'){ ?>
                            <li><a class="ms-link <?= (($curr_file == 'project_category.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/project_category.php">Project Categories</a></li>
                            <?php } ?>
                
                            <li><a class="ms-link <?= (($curr_file == 'task.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/task.php">Task Management</a></li>
                            <!-- <li><a class="ms-link <?= (($curr_file == 'task_category.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/task_category.php">Task Category</a></li> -->
                            <!-- <li><a class="ms-link" href="tickets.html">Ticket List</a></li>
                            <li><a class="ms-link" href="ticket-detail.html">Ticket Details</a></li>
                            <li><a class="ms-link" href="timesheet.html">Timesheet</a></li> -->
                        </ul>
                    </li>
                    <?php 
                    
                    if($emp_list['type'] == 'company'){
                        ?>
                        <li class="collapsed">
                            <a class="m-link" data-bs-toggle="collapse" data-bs-target="#menu-company" href="#">
                                <i class="icofont-company fs-5"></i> <span>Company</span> <span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span>
                            </a>
                            <!-- Menu: Sub menu ul -->
                            <ul class="sub-menu collapse" id="menu-company">
                               <li><a  class="ms-link <?= (($curr_file == 'profile.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/profile.php">Company Profile</a></li>
                                <li><a class="ms-link <?= (($curr_file == 'employee.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/employee.php">Your Employee</a></li>
                                <li><a class="ms-link <?= (($curr_file == 'managers.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/managers.php">Your Manager</a></li>
                            
                            </ul>
                        </li>
                        <?php
                    }

                    if($emp_list['type'] == 'company' || $emp_list['type'] == 'admin'){

                    ?>
                     
                    <!-- <li class="collapsed">
                        <a class="m-link" data-bs-toggle="collapse" data-bs-target="#employee-single" href="#">
                            <i class="icofont-business-man fs-5"></i> <span>Employee</span> <span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span>
                        </a>
                        Menu: Sub menu ul
                        <ul class="sub-menu collapse" id="employee-single">
                        
                            <li><a class="ms-link <?= (($curr_file == 'employee.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/employee.php">Employee</a></li>
                        
                        </ul>
                    </li> -->
                    <?php
                        }
                        $total_cnt = 0;
                        if($emp_list['type'] == 'manager'){
                                $all_projects = mysqli_query($conn, "SELECT * FROM db_projects WHERE manager_id=".$_SESSION['loggedin_user']);
                           $my_projects = array();
                            while($row = mysqli_fetch_array($all_projects)){
                                array_push($my_projects, $row['id']);
                            }
                            $query = mysqli_query($conn, "select * from db_timelog where status = 'pending approval' and project_id in(".implode(',',$my_projects).") ORDER BY id DESC");  
                            $total_cnt = "<span class='t_count'>".$query->num_rows."</span>";

                        }
                    ?>
                    <!-- <li class="collapsed">
                        <a class="m-link" data-bs-toggle="collapse" data-bs-target="#app" href="#">
                            <i class="icofont-code-alt fs-5"></i> <span>App</span> <span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span>
                        </a>
                        
                        <ul class="sub-menu collapse" id="app">
                            <li><a class="ms-link" href="calendar.html">Calandar</a></li>
                            <li><a class="ms-link" href="chat.html"> Communication</a></li>
                        </ul>
                    </li> -->
                    <li class="collapsed">
                        <a class="m-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#menu-timelog-order">
                            <i class="icofont-clock-time fs-5"></i> <span>Timelog</span> <?php  
                            if($emp_list['type'] == 'manager'){ $total_cnt; } ?>
                            <span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span>
                        </a>
                        <ul class="sub-menu collapse" id="menu-timelog-order" style="">
                            <li><a class="ms-link <?= (($curr_file == 'timelog.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/timelog.php">Timelog List</a></li>
                            <li><a class="ms-link <?= (($curr_file == 'timelog_summery.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/timelog_summery.php">Timelog Summery</a></li>
                            <?php if($emp_list['type'] != 'employee'): ?>
                            <li><a class="ms-link <?= (($curr_file == 'timelog_approval.php') ? "active" : ""); ?>" href="<?= $site_url; ?>dist/timelog_approval.php">Timelog Approval</a></li>
                        <?php endif; ?>
                        </ul>
                    </li>
                    <li class="collapsed">
                        <a class="m-link" href="#" data-bs-toggle="collapse" data-bs-target="#menu-users-report">
                            <i class="icofont-chart-pie fs-5"></i> <span>Reports</span>
                            <span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span> 
                        </a>
                        <ul class="sub-menu collapse" id="menu-users-report" style="">
                            <li>
                                <a class="ms-link <?= ($curr_file == 'all_reports.php') ? "active" : ""; ?>" href="<?= $site_url; ?>dist/all_reports.php">All Reports</a></li>
                        </ul>
                    </li>
                    <?php 
                        if($emp_list['type'] == 'admin'){
                    ?>
                     <li class="collapsed">
                        <a class="m-link" href="<?= $site_url; ?>dist/help_request.php">
                            <i class="icofont-question-circle"></i> <span>Help Request</span> 
                        </a>
                    </li>
                    <li class="collapsed">
                        <a class="m-link" href="<?= $site_url; ?>dist/contact_submission.php">
                            <i class="icofont-ui-message"></i> <span>Contact Submission</span> 
                        </a>
                    </li>
                     <li class="collapsed">
                        <a class="m-link" href="#" data-bs-toggle="collapse" data-bs-target="#menu-users-order">
                            <i class="icofont-users-alt-2 fs-5"></i> <span>Users</span>
                            <span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span> 
                        </a>
                        <ul class="sub-menu collapse" id="menu-users-order" style="">
                            <?php
                                $user_active = '';
                                $emp_active = '';
                                $man_active = ''; 
                                if($curr_file == 'all_users.php'){
                                    if(isset($_GET['filter_user']) && $_GET['filter_user'] == 'emp'){
                                        $emp_active = "active";
                                    } elseif(isset($_GET['filter_user']) && $_GET['filter_user'] == 'man'){
                                        $man_active = "active";
                                    } else {
                                        $user_active = "active";
                                    }
                                }
                            ?>
                            <li><a class="ms-link <?= $user_active; ?>" href="<?= $site_url; ?>dist/all_users.php">All Users</a></li>
                            <li><a class="ms-link <?= $emp_active; ?>" href="<?= $site_url; ?>dist/all_users.php?filter_user=emp">Employes</a></li>
                            <li><a class="ms-link <?= $man_active; ?>" href="<?= $site_url; ?>dist/all_users.php?filter_user=man">Managers</a></li>
                        </ul>

                    </li>
                    <?php
                        }
                    ?>
                    <!-- <li><a class="m-link" href="ui-elements/ui-alerts.html"><i class="icofont-paint fs-5"></i> <span>UI Components</span></a></li> -->
                    <!-- <li class="divider mt-2 py-2 text-uppercase"><small>Ready UI</small></li>
                     <li class="collapsed">
                        <a class="m-link" data-bs-toggle="collapse" data-bs-target="#form" href="#">
                            <i class="icofont-file-text fs-5"></i> <span>Form Input</span><span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span>
                        </a>
                       
                        <ul class="sub-menu collapse" id="form">
                            <li><a class="ms-link" href="form-bootstrap.html">Bootstrap Form</a></li>
                            <li><a class="ms-link" href="form-custome.html">Custome Form</a></li>
                            <li><a class="ms-link" href="form-wizard.html">Wizard Form</a></li>
                        </ul>
                    </li>
                    <li class="collapsed">
                        <a class="m-link" data-bs-toggle="collapse" data-bs-target="#font" href="#">
                            <i class="icofont-brand-icofont fs-5"></i><span>Icon Example</span><span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span>
                        </a>
                        
                        <ul class="sub-menu collapse" id="font">
                            <li><a class="ms-link" href="icon-iconfont.html">Icofont Icon</a></li>
                            <li><a class="ms-link" href="icon-bootstrap.html"> Bootstrap Icon</a></li>
                            <li><a class="ms-link" href="icon-fontawesome.html"> Font-Awesome Icon</a></li>
                        </ul>
                    </li>
                    <li class="collapsed">
                        <a class="m-link" data-bs-toggle="collapse" data-bs-target="#widget" href="#">
                            <i class="icofont-code fs-5"></i><span>Widget</span><span class="arrow icofont-rounded-down ms-auto text-end fs-5"></span>
                        </a>
                       
                        <ul class="sub-menu collapse" id="widget">
                            <li><a class="ms-link" href="widget-example.html">Widget Example</a></li>
                            <li><a class="ms-link" href="apexchart.html">Apex Chart</a></li>
                            <li><a class="ms-link" href="priceplan.html"> Price Plan</a></li>
                            <li><a class="ms-link" href="profile.html"> Profile Page</a></li>
                            <li><a class="ms-link" href="table.html"> Tables</a></li>
                        </ul>
                    </li>    -->
                </ul>
                
                <!-- Menu: menu collepce btn -->
                <button type="button" class="btn btn-link sidebar-mini-btn text-light">
                    <span class="ms-2"><i class="icofont-bubble-right"></i></span>
                </button>

            </div>
        </div> 
        <style>
            span.t_count {
                width: 25px;
                height: 25px;
                background-color: #fff;
                text-align: center;
                line-height: 25px;
                font-size: 12px;
                margin-left: 10px;
                border-radius: 50%;
                color: #163339;
                font-weight: bold;
            }@media only screen and (max-width: 1279px){
                .sidebar {
                    position: unset;
                }
                .menu-toggle{
                    display: none;
                }
                .notifications-inner {
                    padding-right: 0;
                }
            }

            @media(max-width:767px){
            .sidebar {
                display: none;
            }
            .sidebar.open {
                position: fixed;
                display: block;
            }

                .menu-toggle{
                    display: block;
                }
            }
        </style> 
        <?php 
        $site_url = $old_site_url;
        ?>
        