<?php
if ( ! defined( 'ABSPATH' ) ) exit;
global $current_user, $wpdb, $wp_query;
$wpttarCurrentuserId = $current_user->ID;
$wpttarUserRole = $this->WPTTARGetCurrentUserCall();
$usercounter = '';
$userBirthday = '';
$leavecounter = '';

$adminRequest = $this->WPTTARGetResultsByID('pending', $this->WpttarCustomProjectLogTable,'wpttarStatus');
$userRequest = $this->WPTTARGetResultsByMultipleFields($this->WpttarCustomProjectLogTable, 'wpttarStatus','wpttarUserID', 'pending', $wpttarCurrentuserId, 'get_results');

$details='';
$members=array();
$wpttarGetPagePermissions = $this->WPTTARGetPagePermissions();
$wpttarGetTableDataByID = $this->WPTTARGetTableDataByID('', $this->WpttarProjectsTable, '');
$wpttarGetTableData = count($wpttarGetTableDataByID);
foreach($wpttarGetPagePermissions as $wpttarGetPagePermission){
    if($wpttarGetPagePermission == 'manage_options_projects'){
        $details = 'manage_options_projects';
    }else if($wpttarGetPagePermission == 'manage_options_projectView'){
        $details = 'manage_options_projectView';
    }
}
$WpttarUsers = get_users();
$wpttarTeamMemberInfo = $this->WPTTARGetSettings('wpttarTeamMemberInfo');

 foreach ($WpttarUsers as $key => $userdata) {
            if(isset($userdata->roles) && !empty($userdata->roles)){
               $wpttarMembersRoles = implode(',', $userdata->roles);
                if((isset($wpttarMembersRoles) && !empty($wpttarMembersRoles)) && (isset($wpttarTeamMemberInfo) && !empty($wpttarTeamMemberInfo))){
                if(in_array($wpttarMembersRoles, $wpttarTeamMemberInfo)){
                        $members[]=$userdata->ID;
                    }
                }
            }
         }

$wpttarViewOnlyPermissionPages = $this->WPTTARViewOnlyPermissionPages();


?>
<style>
    .fc-title {
    cursor: pointer!important;
}
    .buttonclass {
   float: right;position: relative;top: -40px;
}
</style>
<div class="preloader">
<span class="preloader-custom-gif"></span>
</div>
<div style="padding-left: 0px; padding-right:20px; padding-top:0px;" class="col-md-12">
    <!-- BEGIN PAGE HEADER-->
    <h3 class="page-title"><?php _e('Dashboard', 'wpttar'); ?></h3>
    <div class="page-bar" style="margin-bottom: 23px;">
        <?php 
       
        if(isset($wpttarUserRole) && !in_array('administrator', $current_user->roles)){
            $changeRole = $this->WPTTARChangeRolePermission('status');
            $assignRole =  str_replace('_', ' ', $wpttarUserRole);
            $checkPermission = $this->WPTTARChangeRoleGet();
         if(!empty($checkPermission)){ 
         if($changeRole == 'yes'){ 
            ?>
          <a class="btn yellow buttonclass" onclick="wpttarChangeRole('adddatabaserole');"><?php _e('Switch to ', 'wpttar'); ?><?php echo strtoupper($assignRole); ?><?php _e(' Profile', 'wpttar'); ?></a>
         <?php }else{
            ?>
          <a class="btn blue buttonclass" onclick="wpttarChangeRole('adddefaultrole');"><?php _e('Switch to User Profile', 'wpttar'); ?></a>
       
        <?php  } } } ?>
        <ul class="page-breadcrumb">
            <li><i class="fa fa-home"></i><?php _e('Home', 'wpttar'); ?><i class="fa fa-angle-right"></i></li>
            <li><?php _e('Dashboard', 'wpttar'); ?></li>
        </ul>
    </div>
    <!-- END PAGE HEADER-->
    <!-- BEGIN DASHBOARD MODULES STATS -->
    <input type="hidden" id="employee_id" value="<?php echo esc_attr($current_user->ID); ?>">

    <!-- WP-HRM Attendances Module -->
  
        
    <?php if ($details=='manage_options_projects' && !in_array('administrator', $current_user->roles)) { ?>
    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <a class="dashboard-stat dashboard-stat-light red-soft" href="?page=wpttar-projects">
                <div class="visual"><i style="padding: 4px 8px !important;" class="fa fa-product-hunt" ></i></div>
                <div class="details">
                    <div class="number"><?php echo esc_html($wpttarGetTableData); ?></div>
                    <div class="desc"><?php _e("Total Projects", 'wpttar'); ?></div>
                </div>
            </a>
        </div>
     <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <a class="dashboard-stat dashboard-stat-light green" href="?page=wpttar-development-team">
                <div class="visual"><i style="padding: 4px 8px !important;" class="fa fa-user"></i></div>
                <div class="details">
                    <div class="number"><?php echo esc_html(count($members)); ?></div>
                    <div class="desc"><?php _e('Team Members', 'wpttar'); ?></div>
                </div>
            </a>
        </div>
    <?php } else if ($details=='manage_options_projectView' && !in_array('administrator', $current_user->roles)) { ?>
       <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <a class="dashboard-stat dashboard-stat-light purple" href="?page=wpttar-project-custom-log">
                <div class="visual"><i style="padding: 4px 8px !important;" class="fa fa-clock-o"></i></div>
                <div class="details">
                    <div class="number"><?php echo esc_html(count($userRequest)); ?></div>
                    <div class="desc"><?php _e('Request for Add Log', 'wpttar'); ?></div>
                </div>
            </a>
        </div>
    <?php }
    if(isset($wpttarUserRole) && in_array('administrator', $current_user->roles)){ ?>
        <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <a class="dashboard-stat dashboard-stat-light red-soft" href="?page=wpttar-projects">
                <div class="visual"><i style="padding: 4px 8px !important;" class="fa fa-product-hunt"></i></div>
                <div class="details">
                    <div class="number"><?php echo esc_html($wpttarGetTableData); ?></div>
                    <div class="desc"><?php _e("Total Projects", 'wpttar'); ?></div>
                </div>
            </a>
        </div> 
     <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <a class="dashboard-stat dashboard-stat-light green" href="?page=wpttar-development-team">
                <div class="visual"><i style="padding: 4px 8px !important;" class="fa fa-user"></i></div>
                <div class="details">
                    <div class="number"><?php echo esc_html(count($members)); ?></div>
                    <div class="desc"><?php _e('Team Members', 'wpttar'); ?></div>
                </div>
            </a>
        </div>
    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <a class="dashboard-stat dashboard-stat-light purple" href="?page=wpttar-project-custom-log">
                <div class="visual"><i style="padding: 4px 8px !important;" class="fa fa-clock-o"></i></div>
                <div class="details">
                    <div class="number"><?php echo esc_html(count($adminRequest)); ?></div>
                    <div class="desc"><?php _e('Request for Log', 'wpttar'); ?></div>
                </div>
            </a>
        </div>
   <?php } ?>