<?php
if (isset($_POST['save_manager']))
{
    include("db.php");

    $comp       =   $_POST['comp'];
    $u_info     =   get_user_by_id($_SESSION['loggedin_user']);

    if($u_info['type'] == 'company'){
        $comp = $u_info['id'];
    }
    
    $fetch_user = mysqli_query($conn, "SELECT * FROM db_users WHERE email='".$_POST['email']."' and company_name='".$comp."' "); 
    if($fetch_user->num_rows == 0){

        $username   =   $_POST['username'];
        $password   =   md5($_POST['password']);
        if(isset($_POST['pwd_type']) && $_POST['pwd_type'] == 'mail'):
            $new_password   = generate_password(12); 
            $password       = md5($new_password);
        endif;
        $email      =   $_POST['email'];
        $phone      =   $_POST['phone'];
        $ename      =   $_POST['ename'];
        
        $desc       =   $_POST['desc'];
        $type       =   $_POST['user_type'];
       
        
        $fname      =   "";
        $time       =   date('Y-m-d h:i:s');
        
        if(isset($_FILES['eimage']['name']) && !empty($_FILES['eimage']['name'])){

            $rawBaseName = pathinfo($_FILES['eimage']['name'], PATHINFO_FILENAME );
            $extension = pathinfo($_FILES['eimage']['name'], PATHINFO_EXTENSION );
            $counter = 0;
            $fname = basename($_FILES["eimage"]["name"]);

            $doc_root = $_SERVER['DOCUMENT_ROOT'];
            if (strpos($_SERVER['REQUEST_URI'], 'timesheet_new') !== false) {
                $doc_root = $_SERVER['DOCUMENT_ROOT']."/timesheet_new";
                
            }

            while(file_exists($doc_root."/dist/assets/profile/".$fname)) {
                $fname = $rawBaseName . $counter . '.' . $extension;
                $counter++;
            }
            move_uploaded_file($_FILES['eimage']['tmp_name'], $doc_root."/dist/assets/profile/".$fname);

        }

        $query = "insert into db_users(username, password, email,phone,full_name,company_name, description,profile_img,type,date_time) values ('$username', '$password', '$email', '$phone','$ename', '$comp', '$desc', '$fname', '$type', '$time' )";
        
        $sql=mysqli_query($conn,$query);
        if($sql && $_POST['pwd_type'] == 'mail'){
            $comp_domain = get_user_by_id($comp)['username'];
            $msg = "Profile created successfully on $site_url. <br>Here is login details<br><br> <b>Company Domain :</b> $comp_domain<br><b>Email : </b> $email<br><b>Password : </b> $new_password <br> <small>(Note: Above Password is system generated. You can login here and reset your password : <a hre='".$site_url."'>$site_url</a>)</small> <br><br> Regards,<br> Timesheethub.";
            send_zoho_mail($email,"System Generated Password",$msg);
        } else {
            $comp_domain = get_user_by_id($comp)['username'];
            $msg = "Profile created successfully on $site_url. <br>Here is login details<br><br> <b>Company Domain :</b> $comp_domain<br><b>Email : </b> $email<br><b>Password : </b> ".$_POST['password']." <br><br> Regards,<br> Timesheethub.";
            send_zoho_mail($email,"Profile Created Successfully on $site_url",$msg);
        }
        $last_id = mysqli_insert_id($conn);
        $manager_list = mysqli_query($conn, "select * from db_users where type='$type' ");
        if(get_user_by_id($_SESSION['loggedin_user'])['type'] == 'company'){
            $manager_list = mysqli_query($conn, "select * from db_users where type='$type' and company_name=".$_SESSION['loggedin_user']);
        }
        
        while($edit_single_man = mysqli_fetch_array($manager_list)){
            //$selected = ($last_id == $edit_single_man['id']) ?  "selected" : "";
            echo '<option value="'.$edit_single_man['id'].'">'.$edit_single_man['full_name'].'</option>';
        }
        die();
    } else {
        echo "email exist";
        die();
    }
}
if(isset($_POST['check_project_name_exist']) && !empty($_POST['check_project_name_exist'])){
    include("db.php");
    if(get_user_by_id($_SESSION['loggedin_user'])['type'] == 'company'){
        $manager_list = mysqli_fetch_assoc(mysqli_query($conn, "select GROUP_CONCAT(id SEPARATOR ',') AS ids from db_users where type='manager' and company_name=".$_SESSION['loggedin_user']));
        if(!empty($manager_list)){
            $get_data =  mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects where LOWER(name) = LOWER('".$_POST['project_name']."') and manager_id in(".$manager_list['ids'].")"));
            if(!empty($get_data)){
                echo "Project name already exist.";
            }
        }
        
    } elseif(get_user_by_id($_SESSION['loggedin_user'])['type'] == 'manager'){
        $get_data =  mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects where LOWER(name) = LOWER('".$_POST['project_name']."') and manager_id=".$_SESSION['loggedin_user']));
        if(!empty($get_data)){
            echo "Project name already exist.";
        }
    } else {
        $get_data =  mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects where LOWER(name) = LOWER('".$_POST['project_name']."')"));
        if(!empty($get_data)){
            echo "Project name already exist.";
        }
    }
    
    
    die();
    
}
include("header.php"); 
if(isset($_POST['create_project'])){

    $pass_data = array();
    $start_top = 0;
    foreach($_POST['project_employe'] as $key => $pe){
        $task_arr = array();
        if(!empty($_POST['hidden_task_list'][$key])){
            $limit_top = $_POST['hidden_task_list'][$key];
            $j = 0;
            foreach($_POST['project_task'] as $tk => $p_t){
                if($tk >= $start_top && $j < $limit_top){
                    if(!is_numeric($p_t) ){
                        array_push($task_arr,$p_t);
                    }
                    $j++; $start_top++;
                }
            }
        }
        array_push($pass_data, array('employe_id'=>$pe, 'start_date'=> $_POST['project_start_date'][$key],'end_date'=> $_POST['project_end_date'][$key], 'task_count'=>$_POST['hidden_task_list'][$key], 'task_name'=>$task_arr) );

    }

    mysqli_query($conn, "Insert into db_projects(name, description,manager_id, employee_ids, user_id, cat_id) values('".$_POST['project_name']."','".$_POST['project_description']."','".$_POST['select_manager']."', '".serialize($pass_data)."','".$_SESSION['loggedin_user']."','".$_POST['select_cat']."')");

    $last_id = mysqli_insert_id($conn);
    /*if(isset($_POST['task_name']) && !empty($_POST['task_name'])){
        foreach($_POST['task_name'] as $st){
            mysqli_query($conn, "Insert into db_tasks(name,project_id,status,user_id,creation_time,emplyee_id) values('".$st."','".$last_id."','in-progress', '".$_SESSION['loggedin_user']."','".date("Y-m-d h:i:s")."', '".serialize($_POST['project_employe'])."' )");
    
        }
    }*/
   
    if(isset($_POST['project_task'])){
        $pass_data_new = array();
        $all_task_arr = array();
        $start = 0;
        $start_inner = 0; // For newly created task id fields

        $task_ids_with_employees_id = array();
        foreach($_POST['project_employe'] as $key => $pe){
            $task_arr_new = array();
            if(!empty($_POST['hidden_task_list'][$key])){
                $limit = $_POST['hidden_task_list'][$key];
                $i = 0;
                $i_inner = 0;
                $task_count = 0;

                foreach(array_unique($_POST['project_task']) as $nk => $pt){
                    if($nk >= $start && $i < $limit){
                        if(!is_numeric($pt) ){
                            
                            mysqli_query($conn, "Insert into db_tasks(name,project_id,status,user_id,creation_time,emplyee_id) values('".$pt."','".$last_id."','in-progress', '".$_SESSION['loggedin_user']."','".date("Y-m-d h:i:s")."', '".serialize(array($pe))."' )");
                            $task_id = mysqli_insert_id($conn);
                            $all_task_arr[$task_id] = $pt;
                            $task_count++;
                            $emp = get_user_by_id($pe);
                            $msg = "Hello ".ucwords($emp['full_name']).",<br><br> New task assigned to you by ".get_user_by_id($_SESSION['loggedin_user'])['full_name'].". from this project <b>".$_POST['project_name']."</b>.<br><br> Below is details of task:<br><b>Task Name :</b> ".$pt."<br><br> Regards,<br> Timesheethub.";
                            send_zoho_mail($emp['email'],"New Task Assigned to You.",$msg);
                        }
                        $i++; $start++; 
                    }
                    
                }
                foreach($_POST['project_task'] as $nk => $pt){
                    if($nk >= $start_inner && $i_inner < $limit){
                        if(!is_numeric($pt) ){
                            $t_id = array_search($pt, $all_task_arr);
                            array_push($task_arr_new, $t_id);
                            if(!is_array($task_ids_with_employees_id[$t_id])){ $task_ids_with_employees_id[$t_id] = array(); }
                            array_push($task_ids_with_employees_id[$t_id],$pe); 
                        }
                        $i_inner++; $start_inner++; 
                    }
                }

            }
            if($task_count > 0){
                $title = $task_count." tasks from this project : <b>".$_POST['project_name']."</b>.";
                $desc = $task_count." tasks from this project : <b>".$_POST['project_name']."</b>. Assigned by ".get_user_by_id($_SESSION['loggedin_user']);
                mysqli_query($conn, "INSERT INTO db_user_activity(title, description, created_by, to_user_id, date_time) VALUES('$title', '$desc','".$_SESSION['loggedin_user']."', '".$pe."', '".date("Y-m-d h:i:s")."')");

            }
            
            array_push($pass_data_new, array('employe_id'=>$pe, 'start_date'=> $_POST['project_start_date'][$key],'end_date'=> $_POST['project_end_date'][$key], 'task_count'=>$_POST['hidden_task_list'][$key], 'task_name'=>$task_arr_new));
            /*if(!is_array($pass_data_new[$pe])){
                $pass_data_new[$pe] = array();
            }

            array_push($pass_data_new[$pe], $task_arr_new);*/
            
             //array_push($pass_data_new, $task_arr_new );
        }
       if(!empty($task_ids_with_employees_id)){
        foreach($task_ids_with_employees_id as $tsk_id => $emp_arr){
            mysqli_query($conn, "UPDATE db_tasks SET emplyee_id='".serialize(array_unique($emp_arr))."' where id=".$tsk_id);
        }
       }
    }
    mysqli_query($conn, "UPDATE db_projects SET employee_task_ids='".serialize($pass_data_new)."' WHERE id=".$last_id);
    if(!empty($_POST['select_manager'])){
        $act_title = 'Assigned you as a manager for project : <b>'.$_POST['project_name'].'</b>.';
        mysqli_query($conn, "INSERT INTO db_user_activity(title, description, created_by, to_user_id, date_time) VALUES('$act_title', '$act_title','".$_SESSION['loggedin_user']."', '".$_POST['select_manager']."', '".date("Y-m-d h:i:s")."')");
        $u_info = get_user_by_id($_POST['select_manager']);
        send_zoho_mail($u_info['email'], 'Assigned you as a manager for project.', 'Hello '.ucwords($u_info['full_name']).',<br><br> '.$act_title.'<br><br> Regards,<br> Timesheethub.' );
    }

    
    

}
$edit_id    = '';
$edit_name  = '';
$edit_desc  = '';
$edit_eid   = '';
$edit_stime = '';
$edit_etime = '';
$edit_cat_id = '';
$edit_man_id = '';
$employee_list = array();

if(isset($_POST['action']) && $_POST['action'] == 'edit_poject'){
    $get_data =  mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects where id=".$_POST['edit_id']));
    $get_task = mysqli_query($conn, "SELECT * FROM db_tasks where project_id=".$_POST['edit_id']);


    $edit_name  = $get_data["name"];
    $edit_desc  = $get_data["description"];
    $edit_eid   = $get_data["employee_ids"];
    $edit_stime = date("Y-m-d", strtotime($get_data["start_time"]));
    $edit_etime = date("Y-m-d",strtotime($get_data["end_time"]));
    $edit_id    = $get_data["id"];
    $edit_cat_id = $get_data["cat_id"];
    $edit_man_id = $get_data["manager_id"];
    $manger_name = get_user_by_id($edit_man_id)['full_name'];
    $employee_list = (!empty($edit_eid)) ? unserialize($edit_eid) : array();

}
if(isset($_GET['delete_id']) && !empty($_GET['delete_id'])){
     mysqli_query($conn, "DELETE FROM db_projects WHERE id=".$_GET['delete_id']);
     mysqli_query($conn, "DELETE FROM db_tasks WHERE project_id=".$_GET['delete_id']);
     mysqli_query($conn, "DELETE FROM db_timelog WHERE project_id =".$_GET['delete_id']);
     echo '<script>window.history.replaceState("", "", window.location.pathname);</script>';
}
if (isset($_POST['update_project'])) {

    $pass_data = array();
    $start_top = 0;
    $start_inner = 0;
    $all_task_arr = array();
    $pass_data_new = array();
    $task_ids_with_employees_id = array();
    $get_project_old_data = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM db_projects WHERE id=".$_POST['edit_id']));

    foreach($_POST['project_employe'] as $key => $pe){

        $task_arr = array();
        $task_arr_new = array();
        $task_count = 0;

        if(!empty($_POST['hidden_task_list'][$key])){

            $limit_top = $_POST['hidden_task_list'][$key];
            $j = 0; $j_inner = 0;

            foreach($_POST['project_task'] as $tk => $p_t){

                if($tk >= $start_top && $j < $limit_top){
                    if(!is_numeric($p_t) ){

                        array_push($task_arr,$p_t);
                        mysqli_query($conn, "Insert into db_tasks(name,project_id,status,user_id,creation_time,emplyee_id) values('".$p_t."','".$_POST['edit_id']."','in-progress', '".$_SESSION['loggedin_user']."','".date("Y-m-d h:i:s")."', '".serialize(array($pe))."' )");

                        $task_id = mysqli_insert_id($conn);
                        $all_task_arr[$task_id] = $p_t;
                        $task_count++;

                    } else {

                        $get_task = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_tasks where id=".$p_t));


                        if(isset($get_task['name'])){
                            array_push($task_arr,$get_task['name']);
                            $all_task_arr[$get_task['id']] = $get_task['name'];
                        }
                        if(isset($get_task['emplyee_id']) && !empty($get_task['emplyee_id'])){
                            if(!in_array($pe, unserialize($get_task['emplyee_id']))){
                                $task_count++;
                            }
                        }
                        
                    }
                    $j++; $start_top++;
                }
            }

            foreach($_POST['project_task'] as $tk => $p_t){

                if($tk >= $start_inner && $j_inner < $limit_top){ 
                    if(!is_numeric($p_t) ){
                        $t_id = array_search($p_t, $all_task_arr);
                        array_push($task_arr_new, $t_id);
                        if(!is_array($task_ids_with_employees_id[$t_id])){ $task_ids_with_employees_id[$t_id] = array(); }
                        array_push($task_ids_with_employees_id[$t_id],$pe); 

                    } else {

                        $get_task = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_tasks where id=".$p_t));
                        if(isset($get_task['name'])){
                            $t_id =  array_search($get_task['name'], $all_task_arr);
                            array_push($task_arr_new,$t_id); 
                            if(!is_array($task_ids_with_employees_id[$t_id])){ $task_ids_with_employees_id[$t_id] = array(); }
                            array_push($task_ids_with_employees_id[$t_id],$pe);
                        }

                    }
                    $j_inner++; $start_inner++;
                }
            }
        }

        if($task_count > 0){
            $title = $task_count." tasks from this project : <b>".$_POST['project_name']."</b>.";
            $desc = $task_count." tasks from this project : <b>".$_POST['project_name']."</b>. Assigned by ".get_user_by_id($_SESSION['loggedin_user']);
            mysqli_query($conn, "INSERT INTO db_user_activity(title, description, created_by, to_user_id, date_time) VALUES('$title', '$desc','".$_SESSION['loggedin_user']."', '".$pe."', '".date("Y-m-d h:i:s")."')");

        }

        array_push($pass_data, array('employe_id'=>$pe, 'start_date'=> $_POST['project_start_date'][$key],'end_date'=> $_POST['project_end_date'][$key], 'task_count'=>$_POST['hidden_task_list'][$key], 'task_name'=>$task_arr));

        array_push($pass_data_new, array('employe_id'=>$pe, 'start_date'=> $_POST['project_start_date'][$key],'end_date'=> $_POST['project_end_date'][$key], 'task_count'=>$_POST['hidden_task_list'][$key], 'task_name'=>$task_arr_new));
         /*if(!is_array($pass_data_new[$pe])){
                $pass_data_new[$pe] = array();
            }
            
        array_push($pass_data_new[$pe], $task_arr_new);*/
        //array_push($pass_data_new, $task_arr_new );
    
    }
    if(!empty($task_ids_with_employees_id)){
        foreach($task_ids_with_employees_id as $tsk_id => $emp_arr){
            mysqli_query($conn, "UPDATE db_tasks SET emplyee_id='".serialize(array_unique($emp_arr))."' where id=".$tsk_id);
        }
       }
   

    mysqli_query($conn, "UPDATE db_projects SET name='".$_POST['project_name']."', description='".$_POST['project_description']."', employee_ids='".serialize($pass_data)."', employee_task_ids='".serialize($pass_data_new)."', cat_id='".$_POST['select_cat']."', manager_id='".$_POST['select_manager']."' WHERE id=".$_POST['edit_id']);
    $new_task_ids = array();
    if(!empty($pass_data_new)){
        if(!empty($get_project_old_data)){
            $old_task_ids = unserialize($get_project_old_data['employee_task_ids']);
            foreach($pass_data_new as $pdn){
                $is_old = 0;
                 foreach($old_task_ids as $oi){
                    if($pdn['employe_id'] == $oi['employe_id'] ){
                        $is_old = 1;
                        $diff_arr = array_diff($pdn['task_name'],$oi['task_name']);
                        if(!empty($diff_arr)){
                            if(!is_array($new_task_ids[$oi['employe_id']])){$new_task_ids[$oi['employe_id']] = array(); }
                            array_push($new_task_ids[$oi['employe_id']], $diff_arr);
                        }
                    }  
                }
                if($is_old  == 0){
                    if(!is_array($new_task_ids[$pdn['employe_id']])){$new_task_ids[$pdn['employe_id']] = array(); }
                    array_push($new_task_ids[$oi['employe_id']], $pdn['task_name']);
                }
            }
        } else {
            foreach($pass_data_new as $pdn){
                if(!is_array($new_task_ids[$pdn['employe_id']])){$new_task_ids[$pdn['employe_id']] = array(); }
                    array_push($new_task_ids[$oi['employe_id']], $pdn['task_name']);
               
            }

        }
        if(!empty($new_task_ids)){
            foreach($new_task_ids as $n_key => $nti){
                $emp  = get_user_by_id($n_key);
                $task_list_li = '';
                if(!empty($nti)){
                    $task_list_li = '<ol>';
                
                    foreach($nti as $si){
                        
                        
                        if(!empty($si)){
                            foreach($si as $s){
                                $task_list_li .= "<li>".mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM db_tasks where id=".$s))['name']."</li>";
                            }
                           
                        }
                       
                        
                    }
                    $task_list_li .= '</ol>';
                    
                    
                }
                if(!empty($task_list_li)):
                    $msg = "Hello ".ucwords($emp['full_name']).",<br><br> New task assigned to you by ".get_user_by_id($_SESSION['loggedin_user'])['full_name']." from this project <b>".$_POST['project_name']."</b>.<br><br> Below is details of task:<br><b>Task Name :</b> ".$task_list_li."<br><br> Regards,<br> Timesheethub.";
                
                    send_zoho_mail($emp['email'],"New Task Assigned to You.",$msg);
                endif; 
            }
        }
    }

    
    /*if(isset($_POST['task_name']) && !empty($_POST['task_name'])){
        foreach($_POST['task_name'] as $st){
            mysqli_query($conn, "Insert into db_tasks(name,project_id,status,user_id,creation_time,emplyee_id) values('".$st."','".$_POST['edit_id']."','in-progress', '".$_SESSION['loggedin_user']."','".date("Y-m-d h:i:s")."', '".serialize($_POST['project_employe'])."' )");
    
        }
    }*/
    /*if(isset($_POST['project_task'])){
        $start = 0;
        foreach($_POST['project_employe'] as $key => $pe){
            if(!empty($_POST['hidden_task_list'][$key])){
                $limit = $_POST['hidden_task_list'][$key];
                $i = 0;
                foreach($_POST['project_task'] as $nk => $pt){
                    if($nk >= $start && $i < $limit){
                        if(!is_numeric($pt) ){
                            mysqli_query($conn, "Insert into db_tasks(name,project_id,status,user_id,creation_time,emplyee_id) values('".$pt."','".$last_id."','in-progress', '".$_SESSION['loggedin_user']."','".date("Y-m-d h:i:s")."', '".serialize(array($pe))."' )");
                        }
                        $i++; $start++; 
                    }
                }
            }
            
        }
       
    }*/
}

if(isset($_POST['create_task'])){
    if(!empty($_POST['task_title'])){
        foreach($_POST['task_title'] as $t_key => $t_single){
            mysqli_query($conn, "Insert into db_tasks(name,project_id,description,cat_id,emplyee_id,status,user_id,creation_time) values('".$t_single."','".$_POST['project_id']."','".$_POST['task_description'][$t_key]."', '".$_POST['task_category'][$t_key]."', '".serialize(array($_POST['task_employe'][$t_key]))."','in-progress', '".$_SESSION['loggedin_user']."','".date("Y-m-d h:i:s")."' )");
        }
    }        
}
if(isset($_POST['add_cat'])){
    $cat_name = $_POST['cat_name'];
    $cat_desc = $_POST['cat_description'];
    $cat_img = $_POST['cat_img'];
    mysqli_query($conn, "INSERT INTO db_projects_cat(cat_name, cat_slug, cat_img, description, user_id, date_time) VALUES('".$cat_name."', '".sanitize($cat_name)."', '".$cat_img."','".$cat_desc."', '".$_SESSION['loggedin_user']."', '".date('Y-m-d h:i:s')."')");
    
}
?>
        

            <!-- Body: Body -->
            <div class="body d-flex py-lg-3 py-md-2">
                <div class="container-xxl">
                    <div class="row align-items-center">
                        <div class="border-0 mb-4">
                            <div class="card-header p-0 no-bg bg-transparent align-items-center px-0 d-flex border-bottom flex-wrap">
                                <h3 class="h4 py-3 mb-0">Projects</h3>
                                <?php  if($curr_user_type == 'employee'): ?>
                                <div class="inline-filter" style="margin: auto;"> 
                                    <input type="text" name="daterange" value="" placeholder="Filter By Date" autocomplete="off" style="width:105%">
                                    <button class="btn btn-dark clear_filter" style="display: none;">Clear Filter</button>
                                </div>
                            <?php endif; ?>
                                <div class="d-flex py-2 project-tab flex-wrap w-sm-100 ms-auto">
                                    
                                <?php if($curr_user_type == 'admin' || $curr_user_type == 'company'):  ?>
                                        <button type="button" class="btn btn-dark w-sm-100 mb-2 mb-md-0 create_proj" data-bs-toggle="modal" data-bs-target="#createproject" title="Create Project"><i class="icofont-plus-circle me-2 fs-6"></i>Create Project</button>
                                <?php endif; ?>

                                </div>
                            </div>
                        </div>
                    </div> <!-- Row end  -->

                    <div class="row align-items-center">
                        <div class="col-lg-12 col-md-12 flex-column">
                            <div class="tab-content mt-4 project-board">
                                <div class="tab-pane fade show active" id="All-list">
                                    <div class="row g-3 gy-5 py-3 row-deck">
                                        <?php 
                                         $img_arr = array(
                                                    '<div class="project-block light-info-bg"><i class="icofont-paint"></i></div>',
                                                    '<div class="project-block bg-lightgreen"><i class="icofont-vector-path"></i></div>',
                                                    '<div class="project-block bg-lightyellow"><i class="icofont-ui-touch-phone"></i></div>',
                                                    '<div class="project-block light-success-bg"><i class="icofont-tick-boxed"></i></div>',
                                                    '<div class="project-block light-orange-bg"><i class="icofont-dashboard-web"></i></div>',
                                                    '<div class="project-block bg-careys-pink"><i class="icofont-site-map"></i></div>',
                                                    '<div class="project-block bg-lightblue"><i class="icofont-tasks"></i></div>'
                                                );
                                         if($emp_list['type'] == 'admin'){
                                                $all_projects = mysqli_query($conn, "SELECT * FROM db_projects order by id DESC");
                                         } elseif ($emp_list['type'] == 'manager') {
                                               $all_projects = mysqli_query($conn, "SELECT * FROM db_projects WHERE manager_id=".$_SESSION['loggedin_user']);
                                         } else {
                                                $all_projects = mysqli_query($conn, "SELECT * FROM db_projects where (user_id=".$_SESSION['loggedin_user']." or employee_ids REGEXP '.*\"employe_id\";s:[0-9]+:\"".$_SESSION['loggedin_user']."\".*')  order by id DESC");
                                                //echo "SELECT * FROM db_projects where user_id=".$_SESSION['loggedin_user']." or employee_ids REGEXP '.*\"employe_id\";s:[0-9]+:\"".$_SESSION['loggedin_user']."\".*'  order by id DESC";
                                         }
                                         $all_projects_array = array();

                                         $d     = strtotime("now");
                                
                                         $this_week_monday = date('Y-m-d', strtotime("this week monday",$d));
                                         $this_week_sunday = date('Y-m-d', strtotime("this week sunday",$d));

                                        if(isset($_POST['pass_start_date']) && !empty($_POST['pass_start_date']) &&  !empty($_POST['pass_end_date'])){
                                                
                                                $this_week_monday = date('Y-m-d', strtotime($_POST['pass_start_date']));
                                                $this_week_sunday = date('Y-m-d', strtotime($_POST['pass_end_date']));

                                        }
                                

                                         while ($s_proj = mysqli_fetch_array($all_projects)) {

                                            $employee_ids = unserialize($s_proj['employee_ids']); 
                                            if($emp_list['type'] == 'employee' && !empty($employee_ids)){

                                                $is_pass = 0;
                                                foreach($employee_ids as $e_data){
                                                    if($e_data['employe_id'] == $_SESSION['loggedin_user']){
                                                        
                                                        /*if(strtotime('now') >= strtotime($e_data['start_date'])  &&  strtotime('now') <= strtotime($e_data['end_date']." 11:59:59") ){
                                                           $is_pass = 1;
                                                        }*/

                                                        if((strtotime($e_data['start_date'])  <=  strtotime($this_week_monday) && strtotime($e_data['end_date'])  >=  strtotime($this_week_monday)) 
                                                            || (strtotime($e_data['start_date'])  <=  strtotime($this_week_sunday) && strtotime($e_data['end_date'])  >=  strtotime($en_date)) 
                                                            || (strtotime($e_data['start_date'])  >=  strtotime($this_week_monday) && strtotime($e_data['end_date'])  <=  strtotime($this_week_sunday))){

                                                            $is_pass = 1;

                                                        }
                                                    }

                                                }
                                                if($is_pass == 0){
                                                    continue;
                                                }

                                            }
                                            array_push($all_projects_array, $s_proj);
                                         }
                                         
                                         if(count($all_projects_array) == 0){
                                                echo "<p class='no-proj-found'>No Project Found.</p>";
                                         } else {

                                            if($emp_list['type'] == 'manager'){
                                                echo '<div class="card-header p-0 no-bg bg-transparent align-items-center px-0 d-flex border-bottom flex-wrap">
                                                <h3 class="h4 py-3 mb-0">Manage By You:</h3></div>';
                                            }
                                            
                                        foreach($all_projects_array as $single_project){   
                                        
                                                $employee_ids = unserialize($single_project['employee_ids']);
                                                $e_count = count($employee_ids);


                                                /*$start = new DateTime($single_project['start_time']);
                                                $end = new DateTime($single_project['end_time']);
                            
                                                $interval = $start->diff($end);

                                                $show_diff = '';

                                                if(!empty($interval->y)){
                                                    $show_diff .= $interval->y . " years, ";
                                                }
                                                if(!empty($interval->m)){
                                                    $show_diff .= $interval->m." months,";
                                                }
                                                $show_diff .= $interval->d." days ";*/
                                                $show_date = date('d M Y', strtotime($single_project['creation_time']));

                                            

                                                ?>
                                                <div class="col-xxl-4 col-xl-4 col-lg-4 col-md-6 col-sm-6">
                                            <div class="card" data-id="<?= $single_project['id']; ?>">
                                                <div class="card-body">
                                                    <div class="d-flex align-items-center justify-content-between mt-5">
                                                        <div class="lesson_name">
                                                            <?php 
                                                            $fetch_cat = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects_cat WHERE cat_id=".$single_project['cat_id']));
                                                            /*$img_id =  $fetch_cat['cat_img']-1;
                                                            $show_img = $img_arr[$img_id];*/
                                                            if(is_numeric($fetch_cat['cat_img'])){
                                                                $img_id =  $fetch_cat['cat_img']-1;
                                                                $show_img = $img_arr[$img_id];
                                                            } else {
                                                                $show_img = "<div class='project-block'><img src='".$site_url."/dist/assets/images/cat/".$fetch_cat['cat_img']."' style='width:60px;height: 60px; object-fit: cover;'></div>";
                                                            }
                                                            
                                                            echo $show_img;

                                                            ?>
                                                            <span class="small text-muted project_name fw-bold"> <?= $fetch_cat['cat_name']; ?> </span>
                                                            <h6 class="mb-0 fw-bold  fs-6  mb-2"><?= $single_project['name']; ?></h6>
                                                        </div>
                                        
                                                        <div class="btn-group" role="group" aria-label="Basic outlined example">
                                                            <button type="button" class="btn btn-outline-secondary view_pro" data-bs-toggle="modal" data-bs-target="#viewproject" data-id="<?= $single_project['id']; ?>" title="View"><i class="icofont-eye-alt text-warning"></i></button>
                                                            <?php 

                                                                if($single_project['user_id'] == $_SESSION['loggedin_user'] || ($emp_list['type'] == 'manager' && $emp_list['type'] == 'admin')):
                                                            ?>
                                                            <button type="button" class="btn btn-outline-secondary edit_pro" data-bs-toggle="modal" data-bs-target="#editproject" data-id="<?= $single_project['id']; ?>" title="Edit"><i class="icofont-edit text-success"></i></button>
                                                            <button type="button" class="btn btn-outline-secondary del_project" data-bs-toggle="modal" data-bs-target="#deleteproject" data-id="<?= $single_project['id']; ?>" title="Delete"><i class="icofont-ui-delete text-danger"></i></button>
                                                                <?php endif; ?>
                                                        </div>
                                                    </div>
                                                    <div class="d-flex align-items-center">
                                                        <div class="avatar-list avatar-list-stacked pt-2">
                                                            <!-- <img class="avatar rounded-circle sm" src="assets/images/xs/avatar2.svg" alt=""> -->
                                                            <?php 
                                                            $emp_ids = array();
                                                                foreach ( $employee_ids as $single_emp) {
                                                                    $e_id = $single_emp;
                                                                    if(isset($single_emp['employe_id'])){
                                                                        $e_id = $single_emp['employe_id'];
                                                                    }
                                                                    if(!in_array( $e_id, $emp_ids)){
                                                                        if($emp_list['type'] == 'employee' && $_SESSION['loggedin_user'] != $e_id){
                                                                            continue;
                                                                        }
                                                                        array_push($emp_ids, $single_emp['employe_id']);
                                                                    
                                                                        $fetch_user = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_users WHERE id=".$e_id));
                                                                        $profile_img = !empty($fetch_user['profile_img']) ? $site_url.'dist/assets/profile/'.$fetch_user['profile_img'] : $site_url.'assets/images/xs/avatar1.svg';
                                                                        echo '<img class="avatar rounded-circle sm" src="'.$profile_img.'" alt="">';
                                                                    }
                                                                }
                                                            ?>
                                                        
                                                            <span class="avatar rounded-circle text-center pointer sm" data-bs-toggle="modal" data-bs-target="#addUser"><i class="icofont-ui-add"></i></span>
                                                        </div>
                                                    </div>
                                                    <div class="row g-2 pt-4">
                                                        
                                                        <div class="col-6">
                                                            <div class="d-flex align-items-center">
                                                                <i class="icofont-sand-clock"></i>
                                                                <span class="ms-2"><?= $show_date; ?></span>
                                                            </div>
                                                        </div>
                                                        <div class="col-6">
                                                            <div class="d-flex align-items-center">
                                                                <i class="icofont-group-students "></i>
                                                                <span class="ms-2"><?= count($emp_ids); ?> Members</span>
                                                            </div>
                                                        </div>
                                                        
                                                    </div>
                                                    <div class="dividers-block"></div>
                                                    <!-- <div class="d-flex align-items-center justify-content-between mb-2">
                                                        <h4 class="small fw-bold mb-0">Progress</h4>
                                                        <span class="small light-danger-bg  p-1 rounded"><i class="icofont-ui-clock"></i> 35 Days Left</span>
                                                    </div> -->
                                                    <!-- <div class="progress" style="height: 8px;">
                                                        <div class="progress-bar bg-secondary" role="progressbar" style="width: 25%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
                                                        <div class="progress-bar bg-secondary ms-1" role="progressbar" style="width: 25%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"></div>
                                                        <div class="progress-bar bg-secondary ms-1" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
                                                    </div> -->
                                                </div>
                                            </div>
                                        </div>
                                                <?php
                                            }

                                            if($emp_list['type'] == 'manager'){
                                                echo '<div class="card-header p-0 no-bg bg-transparent align-items-center px-0 d-flex border-bottom flex-wrap">
                                                <h3 class="h4 py-3 mb-0">Assigned to You:</h3></div>';
                                                $all_projects = mysqli_query($conn, "SELECT * FROM db_projects where (user_id=".$_SESSION['loggedin_user']." or employee_ids REGEXP '.*\"employe_id\";s:[0-9]+:\"".$_SESSION['loggedin_user']."\".*')  order by id DESC");
                                                $all_projects_array = array();
                                                while ($s_proj = mysqli_fetch_array($all_projects)) {

                                                    $employee_ids = unserialize($s_proj['employee_ids']); 
                                                    if($emp_list['type'] == 'employee' && !empty($employee_ids)){
        
                                                        $is_pass = 0;
                                                        foreach($employee_ids as $e_data){
                                                            if($e_data['employe_id'] == $_SESSION['loggedin_user']){
                                                                
                                                                /*if(strtotime('now') >= strtotime($e_data['start_date'])  &&  strtotime('now') <= strtotime($e_data['end_date']." 11:59:59") ){
                                                                   $is_pass = 1;
                                                                }*/
        
                                                                if((strtotime($e_data['start_date'])  <=  strtotime($this_week_monday) && strtotime($e_data['end_date'])  >=  strtotime($this_week_monday)) 
                                                                    || (strtotime($e_data['start_date'])  <=  strtotime($this_week_sunday) && strtotime($e_data['end_date'])  >=  strtotime($en_date)) 
                                                                    || (strtotime($e_data['start_date'])  >=  strtotime($this_week_monday) && strtotime($e_data['end_date'])  <=  strtotime($this_week_sunday))){
        
                                                                    $is_pass = 1;
        
                                                                }
                                                            }
        
                                                        }
                                                        if($is_pass == 0){
                                                            continue;
                                                        }
        
                                                    }
                                                    array_push($all_projects_array, $s_proj);
                                                 }
                                            
                                            
                                        foreach($all_projects_array as $single_project){   
                                        
                                                $employee_ids = unserialize($single_project['employee_ids']);
                                                $e_count = count($employee_ids);


                                                /*$start = new DateTime($single_project['start_time']);
                                                $end = new DateTime($single_project['end_time']);
                            
                                                $interval = $start->diff($end);

                                                $show_diff = '';

                                                if(!empty($interval->y)){
                                                    $show_diff .= $interval->y . " years, ";
                                                }
                                                if(!empty($interval->m)){
                                                    $show_diff .= $interval->m." months,";
                                                }
                                                $show_diff .= $interval->d." days ";*/
                                                $show_date = date('d M Y', strtotime($single_project['creation_time']));

                                            

                                                ?>
                                                <div class="col-xxl-4 col-xl-4 col-lg-4 col-md-6 col-sm-6">
                                            <div class="card" data-id="<?= $single_project['id']; ?>">
                                                <div class="card-body">
                                                    <div class="d-flex align-items-center justify-content-between mt-5">
                                                        <div class="lesson_name">
                                                            <?php 
                                                            $fetch_cat = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects_cat WHERE cat_id=".$single_project['cat_id']));
                                                            /*$img_id =  $fetch_cat['cat_img']-1;
                                                            $show_img = $img_arr[$img_id];*/
                                                            if(is_numeric($fetch_cat['cat_img'])){
                                                                $img_id =  $fetch_cat['cat_img']-1;
                                                                $show_img = $img_arr[$img_id];
                                                            } else {
                                                                $show_img = "<div class='project-block'><img src='".$site_url."/dist/assets/images/cat/".$fetch_cat['cat_img']."' style='width:60px;height: 60px; object-fit: cover;'></div>";
                                                            }
                                                            
                                                            echo $show_img;

                                                            ?>
                                                            <span class="small text-muted project_name fw-bold"> <?= $fetch_cat['cat_name']; ?> </span>
                                                            <h6 class="mb-0 fw-bold  fs-6  mb-2"><?= $single_project['name']; ?></h6>
                                                        </div>
                                        
                                                        <div class="btn-group" role="group" aria-label="Basic outlined example">
                                                            <button type="button" class="btn btn-outline-secondary view_pro" data-bs-toggle="modal" data-bs-target="#viewproject" data-id="<?= $single_project['id']; ?>" title="View"><i class="icofont-eye-alt text-warning"></i></button>
                                                            <?php 

                                                                if($single_project['user_id'] == $_SESSION['loggedin_user'] || ($emp_list['type'] == 'manager' && $emp_list['type'] == 'admin')):
                                                            ?>
                                                            <button type="button" class="btn btn-outline-secondary edit_pro" data-bs-toggle="modal" data-bs-target="#editproject" data-id="<?= $single_project['id']; ?>"  title="Edit"><i class="icofont-edit text-success"></i></button>
                                                            <button type="button" class="btn btn-outline-secondary del_project" data-bs-toggle="modal" data-bs-target="#deleteproject" data-id="<?= $single_project['id']; ?>" title="Delete"><i class="icofont-ui-delete text-danger"></i></button>
                                                                <?php endif; ?>
                                                        </div>
                                                    </div>
                                                    <div class="d-flex align-items-center">
                                                        <div class="avatar-list avatar-list-stacked pt-2">
                                                            <!-- <img class="avatar rounded-circle sm" src="assets/images/xs/avatar2.svg" alt=""> -->
                                                            <?php 
                                                            $emp_ids = array();
                                                                foreach ( $employee_ids as $single_emp) {
                                                                    $e_id = $single_emp;
                                                                    if(isset($single_emp['employe_id'])){
                                                                        $e_id = $single_emp['employe_id'];
                                                                    }
                                                                    if(!in_array( $e_id, $emp_ids)){
                                                                        if($emp_list['type'] == 'employee' && $_SESSION['loggedin_user'] != $e_id){
                                                                            continue;
                                                                        }
                                                                        array_push($emp_ids, $single_emp['employe_id']);
                                                                    
                                                                        $fetch_user = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_users WHERE id=".$e_id));
                                                                        $profile_img = !empty($fetch_user['profile_img']) ? $site_url.'dist/assets/profile/'.$fetch_user['profile_img'] : $site_url.'assets/images/xs/avatar1.svg';
                                                                        echo '<img class="avatar rounded-circle sm" src="'.$profile_img.'" alt="">';
                                                                    }
                                                                }
                                                            ?>
                                                        
                                                            <span class="avatar rounded-circle text-center pointer sm" data-bs-toggle="modal" data-bs-target="#addUser"><i class="icofont-ui-add"></i></span>
                                                        </div>
                                                    </div>
                                                    <div class="row g-2 pt-4">
                                                        
                                                        <div class="col-6">
                                                            <div class="d-flex align-items-center">
                                                                <i class="icofont-sand-clock"></i>
                                                                <span class="ms-2"><?= $show_date; ?></span>
                                                            </div>
                                                        </div>
                                                        <div class="col-6">
                                                            <div class="d-flex align-items-center">
                                                                <i class="icofont-group-students "></i>
                                                                <span class="ms-2"><?= count($emp_ids); ?> Members</span>
                                                            </div>
                                                        </div>
                                                        
                                                    </div>
                                                    <div class="dividers-block"></div>
                                                    <!-- <div class="d-flex align-items-center justify-content-between mb-2">
                                                        <h4 class="small fw-bold mb-0">Progress</h4>
                                                        <span class="small light-danger-bg  p-1 rounded"><i class="icofont-ui-clock"></i> 35 Days Left</span>
                                                    </div> -->
                                                    <!-- <div class="progress" style="height: 8px;">
                                                        <div class="progress-bar bg-secondary" role="progressbar" style="width: 25%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
                                                        <div class="progress-bar bg-secondary ms-1" role="progressbar" style="width: 25%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"></div>
                                                        <div class="progress-bar bg-secondary ms-1" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
                                                    </div> -->
                                                </div>
                                            </div>
                                        </div>
                                                <?php
                                                }
                                            }
                                        } 
                                        ?>
                                        
                                        
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Create Project-->
            <div class="modal fade" id="createproject" tabindex="-1"  aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered modal-md modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title  fw-bold" id="createprojectlLabel"> Create Project</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" title="Close"></button>
                    </div>
                    <div class="modal-body">
                    	<form action="" method="post">
                        <div class="mb-3">
                            <label for="exampleFormControlInput77" class="form-label">Project Name</label>
                            <input type="text" class="form-control" name="project_name" id="exampleFormControlInput77" placeholder="Explain what the Project Name" required="">
                            <p class="show_error" style="display:none; color:red;">Project Name already exist.</p>
                        </div>
                        <div class="mb-3 category-inner">
                            <div class="category-item">
                                <label class="form-label">Select Category</label>
                                <select class="form-select" aria-label="Default select example" name="select_cat">
                                    <option value=""> --- Select Category --- </option>
                                   <?php
                                    if($curr_user_type == 'admin'){
                                            $cat_query = mysqli_query($conn, "SELECT * FROM db_projects_cat");
                                     } else if($curr_user_type == 'employee' || $curr_user_type == 'manager'){

                                        $com_id = (!empty($emp_list['company_name'])) ? $emp_list['company_name'] : 0;
                                        $cat_query = mysqli_query($conn, "SELECT * FROM db_projects_cat WHERE user_id=".$com_id);

                                     } else {

                                        $cat_query = mysqli_query($conn, "SELECT * FROM db_projects_cat WHERE user_id=".$_SESSION['loggedin_user']);

                                     }
                                        //$cat_query = mysqli_query($conn, "SELECT * FROM db_projects_cat");
                                        while($single_cat =  mysqli_fetch_array($cat_query)){
                                                $img_id = $single_cat['cat_img']-1;
                                               // $show_img = $img_arr[$img_id];
                                                echo '<option value="'.$single_cat['cat_id'].'">'.$single_cat['cat_name'].'</option>';
                                        }
                                   ?>
                                </select>
                            </div>
                            <div class="category-btn">
                                 <button type="button" class="category-button btn btn-dark btn-set-task w-sm-100" data-bs-toggle="modal" data-bs-target="#add_category" title="Add Category"><i class="icofont-plus-circle me-2 fs-6"></i>Add Category</button>
                            </div>
                            
                        </div>
                        <div class="mb-3 manager-inner">
                                <div class="manager-itm">
                                    <label for="select_manager" class="form-label">Manager</label>
                                <select name="select_manager" required="" class="form-control form-select" id="select_manager">
                                    <option value=""> --- Select Manager --- </option>
                                    <?php
                                        $manager_list = mysqli_query($conn, "select * from db_users where type='manager' ");
                                        if(get_user_by_id($_SESSION['loggedin_user'])['type'] == 'company'){
                                            $manager_list = mysqli_query($conn, "select * from db_users where type='manager' and company_name=".$_SESSION['loggedin_user']);
                                        }
                                        while($edit_single_man = mysqli_fetch_array($manager_list)){
                                            
                                            
                                            echo '<option value="'.$edit_single_man['id'].'">'.$edit_single_man['full_name'].'</option>';
                                        }
                                    ?>
                                    
                                </select>
                                </div>
                                
                                <div class="manager-btn">
                                     <button type="button" class="manager-button btn btn-dark btn-set-task w-sm-100" data-bs-toggle="modal" data-bs-target="#manager" title="Add Manager"><i class="icofont-plus-circle me-2 fs-6"></i>Add Manager</button>
                                </div>
                            </div>
                        <!-- <div class="mb-3">
                            <label for="formFileMultipleone" class="form-label">Project Images & Document</label>
                            <input class="form-control" type="file" name="project_img" id="formFileMultipleone"  multiple required="">
                        </div> -->
                        <div class="deadline-form">
                           
                                <!-- <div class="row g-3 mb-3">
                                <div class="col">
                                    <label for="datepickerded" class="form-label">Project Start Date</label>
                                    <input type="date" class="form-control" id="datepickerded"  name="project_start_date" required="">
                                </div>
                                <div class="col">
                                    <label for="datepickerdedone" class="form-label">Project End Date</label>
                                    <input type="date" class="form-control" id="datepickerdedone" name="project_end_date" required="">
                                </div>
                                </div> -->
                                <div class="row g-3 mb-3">
                                   
                                     <div class="col-sm-12">
                                        <label for="formFileMultipleone" class="form-label">Project Assign Person</label>
                                        <table class="tbl_person">
                                            <thead>
                                                <tr>
                                                    <th>Person</th>
                                                    <th>Start Date</th>
                                                    <th>End Date</th>
                                                    <th></th>
                                                    <th>Tasks</th>
                                                </tr>
                                            </thead>
                                            <tbody class="tbody_cls">
                                                <tr>
                                                    <td>
                                                        <select class="form-select proj_empl" aria-label="Default select Priority" name="project_employe[]" required="">
                                                            <option value=""> --- Select User --- </option>
                                                            <?php
                                                                $query = mysqli_query($conn, "SELECT * FROM db_users where type='employee' or type='manager' ");
                                                                if(get_user_by_id($_SESSION['loggedin_user'])['type'] == 'company'){
                                                                    $query = mysqli_query($conn, "SELECT * FROM db_users where company_name=".$_SESSION['loggedin_user']);
                                                                }
                                                                while($row = mysqli_fetch_array($query) ){
                                                                    echo '<option value="'.$row['id'].'">'.$row['full_name'].'</option>';
                                                                }
                                                            ?>
                                                        </select>
                                                        <input type="hidden" name="hid_selcted_emp" value="">
                                                    </td> 
                                                    <td>
                                                         <input type="date" class="form-control" id="datepickerded"  name="project_start_date[]" required="">
                                                    </td>
                                                    <td>
                                                         <input type="date" class="form-control" id="datepickerded"  name="project_end_date[]" required="">
                                                    </td>
                                                    <td>
                                                        <button class="add_person" type="button" title="Add Employe">+</button>
                                                        <button class="remove_person" type="button" title="Remove Employe">-</button>
                                                        
                                                    </td>
                                                    <td>
                                                        <select class="select_task" multiple="" name="project_task[]">
                                                            <option value=""> -- Select Task --- </option>
                                                        </select>
                                                        <input type="hidden" class="hidden_task_list" name="hidden_task_list[]" value="0">
                                                    </td>

                                                </tr>
                                            </tbody>
                                            <tfoot>
                                                <tr>
                                                    <td colspan="5">
                                                        <div class="add-person-btn">
                                                            <button type="button" class="person-button btn btn-dark btn-set-task w-sm-100" data-bs-toggle="modal" data-bs-target="#add_person" title="Add New Employe"><i class="icofont-plus-circle me-2 fs-6"></i>Add New Person</button>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </tfoot>
                                        </table>
                                        
                                    </div> 
                                </div>
                           
                        </div>
                        <!-- <div class="row g-3 mb-3">
                            <div class="col-sm">
                                <label for="formFileMultipleone" class="form-label">Budget</label>
                                <input type="number" class="form-control">
                            </div>
                            <div class="col-sm">
                                <label for="formFileMultipleone" class="form-label">Priority</label>
                                <select class="form-select" aria-label="Default select Priority">
                                    <option selected>Highest</option>
                                    <option value="1">Medium</option>
                                    <option value="2">Low</option>
                                    <option value="3">Lowest</option>
                                </select>
                            </div>
                        </div> -->
                        <div class="mb-3">
                            <label for="exampleFormControlTextarea78" class="form-label">Description (optional)</label>
                            <textarea class="form-control" id="exampleFormControlTextarea78"  name="project_description" rows="3" placeholder="Add any extra details about the request"></textarea>
                        </div>
                        <input type="submit" name="create_project" class="create_project" style="display:none;">
                        
                        <div class="dividers-block"></div>
                        <div class="create-task" style="display: none;">
                            <div class="task-button">
                                <button type="button" class="btn btn-dark btn-set-task w-sm-100"><i class="icofont-plus-circle me-2 fs-6"></i>Create Task</button>
                            </div>
                            <div class="create-task-list">
                                <h5>Task</h5>
                                <div class="create-task-inner">
                                    <!-- <div class="task-item">
                                        <h6>Website Design</h4>
                                        <p>Need to work on new design. Please start on this task asap.</p>
                                    </div> -->
                                    
                                </div>
                                <div class="no-task"><span>No Task Available</span></div>
                            </div>
                                
                        </div>
                    </form>
                    </div>
                    <div class="modal-footer">
                        <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Done</button> -->
                        <button type="button" class="btn btn-primary create_proj_btn" title="Create">Create</button>
                        <button type="button" class="btn btn-primary clear-btn" title="Clear">Clear</button>
                    </div>
                </div>
                </div>
            </div>

            <!-- Edit Project-->
            <div class="modal fade" id="editproject" tabindex="-1"  aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered modal-md modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title  fw-bold" id="editprojectLabel"> Edit Project</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" title="Close"></button>
                    </div>
                    <div class="modal-body">
                        <form action="" method="post">
                    
                        <!-- <div class="mb-3">
                            <label for="formFileMultiple456" class="form-label">Project Images & Document</label>
                            <input class="form-control" type="file" id="formFileMultiple456">
                        </div> -->
                        <div class="deadline-form">
                           
                                <div class="mb-3">
                                    <label for="exampleFormControlInput78" class="form-label">Project Name</label>
                                    <input type="text" class="form-control" name="project_name" id="exampleFormControlInput78" value="<?= $edit_name; ?>">
                                </div>
                            
                                <div class="mb-3 category-inner">
                                    <div class="category-item">
                                        <label class="form-label">Select Category</label>
                                        <select class="form-select" aria-label="Default select example" name="select_cat">
                                            <option value=""> --- Select Category --- </option>
                                           <?php
                                               // $cat_query = mysqli_query($conn, "SELECT * FROM db_projects_cat");
                                           if($curr_user_type == 'admin'){
                                                    $cat_query = mysqli_query($conn, "SELECT * FROM db_projects_cat");
                                            } else if($curr_user_type == 'employee' || $curr_user_type == 'manager'){

                                                $com_id = (!empty($emp_list['company_name'])) ? $emp_list['company_name'] : 0;
                                                $cat_query = mysqli_query($conn, "SELECT * FROM db_projects_cat WHERE user_id=".$com_id);
                                            } else {
                                                $cat_query = mysqli_query($conn, "SELECT * FROM db_projects_cat WHERE user_id=".$_SESSION['loggedin_user']);

                                            }
                                                while($single_cat =  mysqli_fetch_array($cat_query)){
                                                        $img_id = $single_cat['cat_img']-1;
                                                        $selected_cat = ($single_cat['cat_id'] == $edit_cat_id) ? "selected" : ""; 
                                                       // $show_img = $img_arr[$img_id];
                                                        echo '<option value="'.$single_cat['cat_id'].'" '.$selected_cat.'>'.$single_cat['cat_name'].'</option>';
                                                }
                                           ?>
                                        </select>
                                    </div>
                                    <div class="category-btn">
                                         <button type="button" class="category-button btn btn-dark btn-set-task w-sm-100" data-bs-toggle="modal" data-bs-target="#add_category" title="Add Category"><i class="icofont-plus-circle me-2 fs-6"></i>Add Category</button>
                                    </div>
                                    
                                </div>
                                 <div class="mb-3 manager-inner">
                                <div class="manager-itm">
                                    <label for="select_manager" class="form-label">Manager</label>
                                <select name="select_manager" required="" class="form-control form-select" id="select_manager">
                                    <option value=""> --- Select Manager --- </option>
                                    <?php
                                        $manager_list = mysqli_query($conn, "select * from db_users where type='manager' ");
                                        if(get_user_by_id($_SESSION['loggedin_user'])['type'] == 'company'){
                                            $manager_list = mysqli_query($conn, "select * from db_users where type='manager' and company_name=".$_SESSION['loggedin_user']);
                                        }
                                        while($edit_single_man = mysqli_fetch_array($manager_list)){
                                            $selected = ($edit_man_id == $edit_single_man['id']) ? "selected" : "";
                                            
                                            echo '<option value="'.$edit_single_man['id'].'" '.$selected.'>'.$edit_single_man['full_name'].'</option>';
                                        }
                                    ?>
                                    
                                </select>
                                </div>
                                
                                <div class="manager-btn">
                                     <button type="button" class="manager-button btn btn-dark btn-set-task w-sm-100" data-bs-toggle="modal" data-bs-target="#manager" title="Add Manager"><i class="icofont-plus-circle me-2 fs-6"></i>Add Manager</button>
                                </div>
                            </div>
                                <!-- <div class="row g-3 mb-3">
                                <div class="col">
                                    <label for="project_start" class="form-label">Project Start Date</label>
                                    <input type="date" class="form-control" name="project_start_date" id="project_start" value="<?= $edit_stime; ?>">
                                </div>
                                <div class="col">
                                    <label for="project_end" class="form-label">Project End Date</label>
                                    <input type="date" class="form-control" name="project_end_date" id="project_end" value="<?= $edit_etime; ?>">
                                </div>
                                </div> -->
                                <div class="row g-3 mb-3">
                                    <!-- <div class="col-sm-12">
                                        <label class="form-label">Notifation Sent</label>
                                        <select class="form-select" aria-label="Default select example">
                                            <option selected>All</option>
                                            <option value="1">Team Leader Only</option>
                                            <option value="2">Team Member Only</option>
                                        </select>
                                    </div> -->
                                    <div class="col-sm-12">
                                         <label for="formFileMultipleone" class="form-label">Project Assign Person</label>
                                        <table>
                                            <thead>
                                                <tr>
                                                    <th>Person</th>
                                                    <th>Start Date</th>
                                                    <th>End Date</th>
                                                    <th></th>
                                                    <th>Tasks</th>
                                                </tr>
                                            </thead>
                                            <tbody class="tbody_cls">
                                                <?php    

                                                    if(!empty($employee_list)){
                                                        foreach($employee_list as $k => $el){

                                                            $task_c = 0;
                                                            $get_task = mysqli_query($conn, "SELECT * FROM db_tasks where project_id=".$_POST['edit_id']); 
                                                            if(isset($el['task_count']) && !empty($el['task_count'])){
                                                                $task_c = $el['task_count'];
                                                            }

                                                           
                                                           
                                                            echo '<tr>
                                                    <td>
                                                        <select class="form-select proj_empl disabled" style="pointer-events:none;" aria-label="Default select Priority" name="project_employe[]" required=""><option value=""> --- Select User --- </option>';
                                                            
                                                                $query = mysqli_query($conn, "SELECT * FROM db_users where type='employee' or type='manager' ");
                                                                if(get_user_by_id($_SESSION['loggedin_user'])['type'] == 'company'){
                                                                    $query = mysqli_query($conn, "SELECT * FROM db_users where company_name=".$_SESSION['loggedin_user']);
                                                                }

                                                                while($row = mysqli_fetch_array($query) ){
                                                                    $selected = ($row['id']==$el['employe_id']) ? "selected" : ""; 
                                                                    echo '<option value="'.$row['id'].'" '.$selected.'>'.$row['full_name'].'</option>';
                                                                }

                                                            echo '
                                                    
                                                        </select>
                                                        <input type="hidden" name="hid_selcted_emp" value="'.$el['employe_id'].'">
                                                       
                                                    </td> 
                                                    <td>
                                                         <input type="date" class="form-control" id="datepickerded" style="pointer-events:none;"  name="project_start_date[]" required="" value="'.$el['start_date'].'">
                                                    </td>
                                                    <td>
                                                         <input type="date" class="form-control" id="datepickerded"  name="project_end_date[]" required="" value="'.$el['end_date'].'"> 
                                                    </td>
                                                    <td>
                                                        <button class="add_person" type="button" title="Add Employe">+</button>
                                                        <button class="remove_person" type="button" title="Remove Employe">-</button>
                                                    </td>
                                                    <td>
                                                        <select class="select_task" multiple="" name="project_task[]">
                                                            <option value=""> -- Select Task --- </option>
                                                             ';
                                                             $t_count = 0;
                                                             $slected_array = array();
                                                            while($single_t = mysqli_fetch_array($get_task)){

                                                                $sel = '';
                                                                if(isset($el['task_name'])){
                                                                    if(in_array($single_t['name'], $el['task_name']) && !in_array($single_t['name'], $slected_array)){
                                                                        $sel = "selected";
                                                                        $t_count++;
                                                                        array_push($slected_array, $single_t['name']);
                                                                    }
                                                                }
                                                               
                                                                echo '<option value="'.$single_t['id'].'" '.$sel.'>'.$single_t['name'].'</option>';
                                                            }

                                                             echo '   
                                                        </select>
                                                        <input type="hidden" class="hidden_task_list" name="hidden_task_list[]" value="'.$task_c.'">
                                                    </td>

                                                </tr>';
                                                        }
                                                    } else {
                                                         echo '<tr>
                                                    <td>
                                                        <select class="form-select proj_empl" aria-label="Default select Priority" name="project_employe[]" required="">';
                                                            $query = mysqli_query($conn, "SELECT * FROM db_users where type='employee'");
                                                            if(get_user_by_id($_SESSION['loggedin_user'])['type'] == 'company'){
                                                                    $query = mysqli_query($conn, "SELECT * FROM db_users where company_name=".$_SESSION['loggedin_user']);
                                                                }

                                                                while($row = mysqli_fetch_array($query) ){
                                                                   
                                                                    echo '<option value="'.$row['id'].'">'.$row['full_name'].'</option>';
                                                                }

                                                            echo '
                                                    
                                                        </select>
                                                        <input type="hidden" name="hid_selcted_emp" value="">
                                                       
                                                    </td> 
                                                    <td>
                                                         <input type="date" class="form-control" id="datepickerded"  name="project_start_date[]" required="" value="">
                                                    </td>
                                                    <td>
                                                         <input type="date" class="form-control" id="datepickerded"  name="project_end_date[]" required="" value=""> 
                                                    </td>
                                                    <td>
                                                        <button class="add_person" type="button" title="Add Employe">+</button>
                                                        <button class="remove_person" type="button" title="Remove Employe">-</button>
                                                    </td>
                                                    <td>
                                                        <select class="select_task" multiple="" name="project_task[]">
                                                            <option value=""> -- Select Task --- </option>

                                                        </select>
                                                        <input type="hidden" class="hidden_task_list" name="hidden_task_list[]" value="0">
                                                    </td>
                                                </tr>';
                                                    }
                                                ?>
                                                
                                            </tbody>
                                            <tfoot>
                                                <tr>
                                                    <td colspan="5">
                                                        <div class="add-person-btn">
                                                            <button type="button" class="person-button btn btn-dark btn-set-task w-sm-100" data-bs-toggle="modal" data-bs-target="#add_person" title="Add New Employe"><i class="icofont-plus-circle me-2 fs-6"></i>Add New Person</button>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </tfoot>
                                        </table>

                                    </div>
                                </div>
                                <div class="mb-3">
                                    <label for="exampleFormControlTextarea786" class="form-label">Description (optional)</label>
                                    <textarea class="form-control" id="exampleFormControlTextarea786" rows="3" name="project_description"><?= $edit_desc; ?></textarea>
                                </div>
                                <input type="hidden" name="edit_id" value="<?= $edit_id; ?>">
                                <input type="submit" name="update_project" class="update_project" value="update" >
                            
                        </div>
                        <!-- <div class="row g-3 mb-3">
                            <div class="col-sm">
                                <label for="formFileMultipleone" class="form-label">Priority</label>
                                <select class="form-select" aria-label="Default select Priority">
                                    <option selected>Medium</option>
                                    <option value="1">Highest</option>
                                    <option value="2">Low</option>
                                    <option value="3">Lowest</option>
                                </select>
                            </div>
                        </div> -->
                        <div class="dividers-block"></div>
                        <div class="create-task" style="display: none;">
                            <div class="task-button">
                                <button type="button" class="btn btn-dark btn-set-task w-sm-100" data-id="<?= $_POST['edit_id']; ?>"><i class="icofont-plus-circle me-2 fs-6"></i>Create Task</button>
                            </div>
                            <div class="create-task-list">
                                <h5>Task</h5>
                                <div class="create-task-inner">
                                    <?php
                                        if(isset($_POST['action']) && $_POST['action'] == 'edit_poject'){
    
                                            $get_task = mysqli_query($conn, "SELECT * FROM db_tasks where project_id=".$_POST['edit_id']." order by id desc limit 4");

                                            $rowcount=mysqli_num_rows($get_task);
                                            if($rowcount > 0){
                                                while($single_task = mysqli_fetch_array($get_task)):
                                                        $fetch_cat = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_tasks_cat WHERE cat_id=".$single_task['cat_id']));
                                                       
                                                        echo '<div class="task-item">
                                                            <h6>'.$single_task['name'].'</h6>
                                                            <p>'.$single_task['description'].'</p>
                                                        </div>';
                                
                                                endwhile;
                                                echo '<div class="task-btn"><a href="'.$site_url.'dist/task.php?filter_proj='.$_POST['edit_id'].'" class="btn btn-dark btn-set-task w-sm-100 ts-btn">View More Task</a></div>'; // VIEW MORE TASK.
                                            } else {
                                                 echo '<div class="no-task"><span>No Task Available</span></div>'; // NO TASK AVAILABLE
                                            }
                                            
                                        } else {
                                            echo '<div class="no-task"><span>No Task Available</span></div>';// NO TASK AVAILABLE
                                        }
                                    ?>
                                   
                                </div>
                            </div>
                                
                        </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Done</button> -->
                        <button type="button" class="btn btn-primary" onclick="$('.update_project').click();" title="Update">Update</button>
                        <button type="button" class="btn btn-primary clear-btn" title="Clear">Clear</button>
                    </div>
                </div>
                </div>
            </div>

            <!-- View Project-->
            <div class="modal fade view-modal-dl" id="viewproject" tabindex="-1"  aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered modal-md modal-dialog-scrollable ">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title  fw-bold" id="editprojectLabel"> View Project</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" title="Close"></button>
                    </div>
                    <div class="modal-body">

                        <div class="deadline-form">
                           
                                <div class="mb-3 project-sec">
                                    <label class="form-label">Project Name</label> <div class="show_val"><?= $edit_name; ?></div>
                            
                                </div>
                                <div class="mb-3 project-sec">
                                    <label class="form-label">Project Category</label>
                                    <div class="show_val">
                                    <?php
                                        $cat_query = '';
                                        if(!empty($edit_cat_id)){
                                             $cat_query = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects_cat where cat_id=".$edit_cat_id));
                                        }
                                           
                                            if(!empty($cat_query)){
                                                echo $cat_query['cat_name'];
                                            }
                                       ?>
                                       </div>
                                </div>
                                 <div class="mb-3 project-sec">
                                    <label class="form-label">Project Manager</label> <div class="show_val"><?= $manger_name; ?></div>
                            
                                </div>
                               
                                <div class="row g-3 mb-3 view-table">
                                   
                                    <div class="col-sm-12 task-table">
                                         <label for="formFileMultipleone" class="form-label">Project Assign Person</label>
                                        <table>
                                            <thead>
                                                <tr>
                                                    <th>Person</th>
                                                    <th>Start Date</th>
                                                    <th>End Date</th>  
                                                </tr>
                                            </thead>
                                            <tbody class="tbody_cls">
                                                <?php    

                                                    if(!empty($employee_list)){
                                                        foreach($employee_list as $k => $el){
                                                           $get_employe_name = get_user_by_id($el['employe_id']);
                                                           $full_name = !empty($get_employe_name) ? $get_employe_name['full_name'] : '-';
                                                           
                                                           if($emp_list['type'] == 'employee' && $_SESSION['loggedin_user'] != $el['employe_id']){
                                                            continue;
                                                           }
                                                            echo '<tr>
                                                    <td>
                                                    '.$full_name.' 
                                                    </td> 
                                                    <td>
                                                         '.$el['start_date'].'
                                                    </td>
                                                    <td>
                                                         '.$el['end_date'].' 
                                                    </td>
                                                    
                                                </tr>';
                                                        }
                                                    } else {
                                                         echo '<tr>
                                                                <td colspan="3">
                                                                   No data Found
                                                                </td>

                                                            </tr>';
                                                    }
                                                ?>
                                                
                                            </tbody>
                                        </table>

                                    </div>
                                </div>
                                <div class="mb-3 view-description">
                                    <label for="exampleFormControlTextarea786" class="form-label">Description (optional)</label>
                                    <div class="show_val"><?= $edit_desc; ?></div>
                                    
                                </div>
                                <input type="hidden" name="edit_id" value="<?= $edit_id; ?>">
                                <input type="submit" name="update_project" class="update_project" value="update" style="display: none;">
                            
                        </div>
                        <div class="dividers-block"></div>
                        <?php 
                            $style="";
                            if($emp_list['type'] == 'employee'){
                                    $style="display:none;";
                            }
                        ?>
                        <div class="create-task" style="<?= $style; ?>">
                            <div class="task-button">
                                <!-- <button type="button" class="btn btn-dark btn-set-task w-sm-100"><i class="icofont-plus-circle me-2 fs-6"></i>Create Task</button> -->
                            </div>
                            <div class="create-task-list">
                                <h5>Task</h5>
                                <div class="create-task-inner">
                                    <?php
                                        if(isset($_POST['action']) && $_POST['action'] == 'edit_poject'){
    
                                            $get_task = mysqli_query($conn, "SELECT * FROM db_tasks where project_id=".$_POST['edit_id']." limit 4");

                                            $rowcount=mysqli_num_rows($get_task);
                                            if($rowcount > 0){
                                                while($single_task = mysqli_fetch_array($get_task)):
                                                        $fetch_cat = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_tasks_cat WHERE cat_id=".$single_task['cat_id']));
                                                       
                                                        echo '<div class="task-item">
                                                            <h6>'.$single_task['name'].'</h6>
                                                            <p>'.$single_task['description'].'</p>
                                                        </div>';
                                
                                                endwhile;
                                                echo '<div class="task-btn"><a class="btn btn-dark btn-set-task w-sm-100 ts-btn" href="'.$site_url.'dist/task.php?filter_proj='.$_POST['edit_id'].'">View More Task</a></div>'; // VIEW MORE TASK.
                                            } else {
                                                 echo '<div class="no-task"><span>No Task Available</span></div>'; // NO TASK AVAILABLE
                                            }
                                            
                                        } else {
                                            echo '<div class="no-task"><span>No Task Available</span></div>';// NO TASK AVAILABLE
                                        }
                                    ?>
                                </div>
                            </div>
                                
                        </div>
                        
                    </div>
                    <div class="modal-footer">
                        <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Done</button> -->
                        <button type="button" class="btn btn-primary" data-bs-dismiss="modal" title="Close">Close</button>
                    </div>
                </div>
                </div>
            </div>

            <!-- Modal  Delete Folder/ File-->
            <div class="modal fade" id="deleteproject" tabindex="-1"  aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered modal-md modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title  fw-bold" id="deleteprojectLabel"> Delete item Permanently? </h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" title="Close"></button>
                    </div>
                    <div class="modal-body justify-content-center flex-column d-flex">
                        <i class="icofont-ui-delete text-danger display-2 text-center mt-2"></i>
                        <p class="mt-4 fs-5 text-center">By Deleting this project all task and all timelog related to this project will be deleted.</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                        <a href="?delete_id=" class="del_id"><button type="button" class="btn btn-danger color-fff">Delete</button></a>
                    </div>
                </div>
                </div>
            </div>

            <div class="modal fade" id="add_person" tabindex="-1"  aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered modal-lg modal-dialog-scrollable">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title  fw-bold" id="createprojectlLabel"> Add Person </h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" title="Close"></button>
                        </div>
                        <div class="modal-body"> 
                        
                             <form name="f1" method="POST" enctype="multipart/form-data" autocomplete="off">
                            <div class="mb-3">
                                <label for="exampleFormControlInput877" class="form-label">Full Name</label>
                                <input type="text" name="ename" class="form-control" id="exampleFormControlInput877" placeholder="Full Name Here" required="" onkeydown="if(/[a-z ]/i.test(event.key) == false || (event.which === 32 && event.target.selectionStart === 0)) {return false; }">
                            </div>

                            <div class="mb-3">
                                <label for="formFileMultipleoneone" class="form-label">User Image</label>
                                <input class="form-control" name="eimage" type="file" id="formFileMultipleoneone" accept="image/jpg, image/jpeg, image/png" onchange="return fileValidation(this);">
                            </div>
                          <div class="deadline-form">
                               <div class="row mb-3">  
                           
                                <div class="col">
                                    <label for="exampleFormControlInput177" class="form-label">Password Prefence:</label> 
                                        <label class="pwd-pref">
                                            <input type="radio" name="pwd_type" class="pwd_type" value="manually" checked="">
                                            Set Manually
                                        </label>
                                        <label class="pwd-pref">
                                            <input type="radio" name="pwd_type" class="pwd_type" value="mail">
                                            Sent in Mail
                                        </label>
                                </div>
                            </div>
                            
                            <div class="row g-3 mb-3">
                                <div class="col">
                                    <label for="exampleFormControlInput177" class="form-label">User Name</label>
                                    <input type="text" name="username" class="form-control" id="exampleFormControlInput177" placeholder="User Name" required="" autocomplete="new-username" onkeydown="return /[A-Za-z]/i.test(event.key);">
                                </div>
                                <div class="col">
                                    <label for="exampleFormControlInput277" class="form-label">Password</label>
                                    <div class="password-text">
                                        <input type="Password" name="password" class="form-control pwd-manually" id="exampleFormControlInput277" placeholder="Password" required="" autocomplete="new-password" onkeyup="checkPasswordStrength(this);" style="width: 95%;display: inline-block;">
                                        <i class="icofont-eye pwd-toggle"></i>
                                        <div id="password-strength-status"></div>
                                    </div>
                                    <span class="pwd-mail" style="display:none;">System Generated Password will be sent to user email id.</span>
                                </div>
                            </div> 
                            <div class="row g-3 mb-3">
                                <div class="col">
                                    <label for="exampleFormControlInput477" class="form-label">Email ID</label>
                                    <input type="email" name="email" class="form-control" id="exampleFormControlInput477" placeholder="Email Address" required="">
                                    <span class="email_error" style="display:none">Email Already Exist.</span>
                                </div>
                            <div class="col">
                                    <label for="exampleFormControlInput777" class="form-label">Phone</label>
                                    <input type="text" name="phone" class="form-control" id="exampleFormControlInput777" placeholder="Phone Number" maxlength="10" required="" onkeypress="return onlyNumberKey(event)">
                                </div>
                            </div>
                              
                                
                        </div> 
                          <div class="mb-3">          
                                <label for="exampleFormControlTextarea78" class="form-label">Description (optional)</label>
                                <textarea class="form-control" name="desc" id="exampleFormControlTextarea78" rows="3" placeholder="Add any extra details about employee"></textarea>
                            </div> 
                            <input type="hidden" name="user_type" value="employee">
                            <input type="submit" name="save_employee" class="save_employee" style="display: none;">
                           
                            </form>
                        </div>
                        <div class="modal-footer">
                            <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Done</button> -->
                            <button type="submit" class="btn btn-primary employee_profile" name="employee_profile" title="Add Employee"> Add Employee</button>
                            <button type="button" class="btn btn-primary clear-btn" title="Clear">Clear</button>
                        </div> 
                    </div>  
                </div>
            </div>
            

            <div class="modal fade" id="manager" tabindex="-1"  aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered modal-lg modal-dialog-scrollable">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title  fw-bold" id="createprojectlLabel"> Add Manager</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" title="Close"></button>
                        </div>
                        <div class="modal-body"> 
                        
                             <form name="f1" method="POST" enctype="multipart/form-data">
                            <div class="mb-3">
                                <label for="exampleFormControlInput877" class="form-label">Full Name</label>
                                <input type="text" name="ename" class="form-control" id="exampleFormControlInput877" placeholder="Full Name Here" required="" onkeydown="if(/[a-z ]/i.test(event.key) == false || (event.which === 32 && event.target.selectionStart === 0)) {return false; }">
                            </div>


                            <div class="mb-3">
                                <label for="formFileMultipleoneone" class="form-label">User Image</label>
                                <input class="form-control" name="eimage" type="file" id="formFileMultipleoneone" accept="image/jpg, image/jpeg, image/png" onchange="return fileValidation(this);">
                            </div>
                          <div class="deadline-form">
                              <div class="row mb-3">  
                           
                                <div class="col">
                                    <label for="exampleFormControlInput177" class="form-label">Password Prefence:</label> 
                                        <label class="pwd-pref">
                                            <input type="radio" name="pwd_type" class="pwd_type" value="manually" checked="">
                                            Set Manually
                                        </label>
                                        <label class="pwd-pref">
                                            <input type="radio" name="pwd_type" class="pwd_type" value="mail">
                                            Sent in Mail
                                        </label>
                                </div>
                            </div>
                               
                            
                            <div class="row g-3 mb-3">
                                <div class="col">
                                    <label for="exampleFormControlInput177" class="form-label">User Name</label>
                                    <input type="text" name="username" class="form-control" id="exampleFormControlInput177" placeholder="User Name" required="" autocomplete="new-username" onkeydown="return /[A-Za-z]/i.test(event.key);">
                                </div>
                                <div class="col">
                                    <label for="exampleFormControlInput277" class="form-label">Password</label>
                                    
                                
                                     <div class="password-text">
                                         <input type="Password" name="password" class="form-control  pwd-manually" id="exampleFormControlInput277" placeholder="Password" required="" autocomplete="new-password" onkeyup="checkPasswordStrength(this);"  style="width: 95%;display: inline-block;">
                                        
                                        <i class="icofont-eye pwd-toggle"></i>
                                        <div id="password-strength-status"></div>
                                    </div>
                                    <span class="pwd-mail" style="display:none;">System Generated Password will be sent to user email id.</span>
                                </div>
                            </div> 
                            <div class="row g-3 mb-3">
                                <div class="col">
                                    <label for="exampleFormControlInput477" class="form-label">Email ID</label>
                                    <input type="email" name="email" class="form-control" id="exampleFormControlInput477" placeholder="Email Address" required="">
                                    <span class="email_error" style="display:none">Email Already Exist.</span>
                                </div>
                            <div class="col">
                                    <label for="exampleFormControlInput777" class="form-label">Phone</label>
                                    <input type="text" name="phone" class="form-control" id="exampleFormControlInput777" placeholder="Phone Number" maxlength="10" required="" onkeypress="return onlyNumberKey(event)">
                                </div>
                            </div>
                              
                                
                        </div> 
                          <div class="mb-3">          
                                <label for="exampleFormControlTextarea78" class="form-label">Description (optional)</label>
                                <textarea class="form-control" name="desc" id="exampleFormControlTextarea78" rows="3" placeholder="Add any extra details about employee"></textarea>
                            </div> 
                            <input type="hidden" name="user_type" value="manager">
                            <input type="submit" name="save_manager" class="save_manager" style="display: none;">
                           
                            </form>
                        </div>
                        <div class="modal-footer">
                            <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Done</button> -->
                            <button type="submit" class="btn btn-primary update_profile" name="update_profile" title="Add Manager">Add Manager</button>
                            <button type="button" class="btn btn-primary clear-btn" title="Clear">Clear</button>
                        </div> 
                    </div>  
                </div>
            </div>

            <div class="modal fade" id="createtask" tabindex="-1"  aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered modal-md modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title  fw-bold" id="createprojectlLabel"> Create Task</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" title="Close"></button>
                    </div>
                    <div class="modal-body">
                       
                        <!-- <div class="mb-3">
                            <label for="formFileMultipleone" class="form-label">Task Images & Document</label>
                            <input class="form-control" type="file" id="formFileMultipleone"  multiple>
                        </div> -->
                        <div class="deadline-form mb-3">
                            <form method="post" action="">
                                <table>
                                    <thead>
                                        <tr>
                                            <th>Task Title</th>
                                            <th>Category</th>
                                            <th>Assign Person</th>
                                            <th>Description</th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody class="tbody_cls">
                                        <tr>
                                            <td>
                                            <input type="text" name="task_title[]" required="" placeholder="Title here">
                                            </td>
                                            <td>
                                                <select class="form-select" aria-label="Default select Project Category" name="task_category[]">
                                                    <option value="">Select Category</option>
                                                     <?php
                                                        $all_cats = mysqli_query($conn, "SELECT * FROM db_tasks_cat");
                                                        while ($single_cat = mysqli_fetch_array($all_cats)) {
                                                            echo '<option value="'.$single_cat['cat_id'].'">'.$single_cat['cat_name'].'</option>';
                                                        }
                                                    ?>
                                                </select> 
                                            </td>
                                            <td>
                                                <select class="form-select" aria-label="Default select Priority" name="task_employe[]">
                                                    <option value="">Select Person</option>
                                                <?php
                                                    $query = mysqli_query($conn, "SELECT * FROM db_users where type='employee' or type='manager' ");

                                                    while($row = mysqli_fetch_array($query) ){
                                                        $selected = in_array($row['id'], $employee_list) ? "selected" : ""; 
                                                        echo '<option value="'.$row['id'].'" '.$selected.'>'.$row['full_name'].'</option>';
                                                    }

                                                ?>
                                                </select>
                                            </td>
                                            <td>
                                                <textarea class="form-control" id="exampleFormControlTextarea786" name="task_description[]" rows="2" placeholder="Description"></textarea>
                                            </td>
                                            <td>
                                                <button class="add_person add_task" type="button">+</button>
                                                <button class="remove_person remove_task" type="button">-</button>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                                 <!-- <div class="mb-3">
                                    <label  class="form-label">Project Name</label>
                                    <select class="form-select" aria-label="Default select Project Category" name="task_pro_name">
                                        <option value="">Project Name Select</option>
                                        <?php
                                        foreach($all_projects_arr as $single_pro){
                                          echo '<option value="'.$single_pro['id'].'">'.$single_pro['name'].'</option>'; 
                                        }
                                        ?>
                                    </select>
                                </div>
                                <div class="mb-3">
                                    <label  class="form-label">Task Category</label>
                                    <select class="form-select" aria-label="Default select Project Category" name="task_category">
                                        <option value="">Select Category</option>
                                         <?php
                                            $all_cats = mysqli_query($conn, "SELECT * FROM db_tasks_cat");
                                            while ($single_cat = mysqli_fetch_array($all_cats)) {
                                                echo '<option value="'.$single_cat['cat_id'].'">'.$single_cat['cat_name'].'</option>';
                                            }
                                        ?>
                                    
                                    </select>
                                </div>
                                <div class="row"> -->
                                   <!--  <div class="col">
                                        <label for="datepickerded" class="form-label">Task Start Date</label>
                                        <input type="date" class="form-control" id="datepickerded" name="task_start_date">
                                    </div>
                                    <div class="col">
                                        <label for="datepickerdedone" class="form-label">Task End Date</label>
                                        <input type="date" class="form-control" id="datepickerdedone" name="task_end_date">
                                    </div> -->
                                <!-- </div>
                                <div class="row g-3 mb-3">
                                    <div class="col-sm">
                                        <label  class="form-label">Project Assign Person</label>
                                        <select class="form-select" multiple aria-label="Default select Priority" name="task_employe[]">
                                            <?php
                                                $query = mysqli_query($conn, "SELECT * FROM db_users where type='employee'");

                                                while($row = mysqli_fetch_array($query) ){
                                                    $selected = in_array($row['id'], $employee_list) ? "selected" : ""; 
                                                    echo '<option value="'.$row['id'].'" '.$selected.'>'.$row['full_name'].'</option>';
                                                }

                                            ?>
                                            
                                        </select>
                                    </div>
                                </div>
                                <div class="row g-3 mb-3"> -->
                                    <!-- <div class="col-sm">
                                        <label  class="form-label">Task Priority</label>
                                        <select class="form-select" aria-label="Default select Priority" name="task_priority">
                                            <option value="">Select Priority</option>
                                            <option value="Highest">Highest</option>
                                            <option value="Medium">Medium</option>
                                            <option value="Low">Low</option>
                                            <option value="Lowest">Lowest</option>
                                        </select>
                                    </div> -->
                                <!-- </div>
                                <div class="mb-3">
                                    <label for="exampleFormControlTextarea786" class="form-label">Description (optional)</label>
                                    <textarea class="form-control" id="exampleFormControlTextarea786" name="task_description" rows="3" placeholder="Add any extra details about the request"></textarea>
                                </div> -->
                                <input type="hidden" name="project_id" value="">
                                <input type="submit" name="create_task" class="create_task" value="create task" style="display: none;">
                            </form>
                        </div>
                    </div>
                       
        
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" onclick="$('.create_task').click()">Create</button>
                        <button type="button" class="btn btn-primary clear-btn" title="Clear">Clear</button>
                    </div>
                </div>
                </div>
            </div>

            <div class="modal fade" id="add_category" tabindex="-1"  aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered modal-md modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title  fw-bold" id="leaveaddLabel"> Add Category</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" title="Close"></button>
                    </div>
                    <div class="modal-body">
                        
                        <div class="deadline-form">
                            <form method="post">
                                <div class="mb-3">
                                        <label for="sub" class="form-label">Category Name</label>
                                        <input type="text" class="form-control" id="sub" name="cat_name" required="">
                                </div>
                                <div class="mb-3">
                                    <label for="exampleFormControlTextarea78" class="form-label">Description (optional)</label>
                                    <textarea class="form-control" id="exampleFormControlTextarea78" name="cat_description" rows="3" placeholder="Add any extra details about the request"></textarea>
                                </div>
                                <div class="mb-3">
                                    <label for="formFileMultipleoneone" class="form-label">Category Image</label>
                                    <div class="icon_groups">
                                            <input type="radio" name="cat_img" value="1" id="img_1" checked>
                                            <label class="light-info-bg" for="img_1">
                                                <i class="icofont-paint"></i>
                                            </label> 
                                           <input type="radio" name="cat_img" value="2" id="img_2">
                                            <label class="bg-lightgreen" for="img_2">
                                                <i class="icofont-vector-path"></i>
                                            </label>
                                            <input type="radio" name="cat_img" value="3" id="img_3">
                                            <label class="bg-lightyellow" for="img_3">
                                                <i class="icofont-ui-touch-phone"></i>
                                                
                                            </label>
                                            <input type="radio" name="cat_img" value="4" id="img_4">
                                            <label class="light-success-bg" for="img_4">
                                                <i class="icofont-tick-boxed"></i>
                                                
                                            </label>
                                            <input type="radio" name="cat_img" value="5" id="img_5">
                                            <label class="light-orange-bg" for="img_5">
                                                <i class="icofont-dashboard-web"></i>
                                                
                                            </label>
                                            <input type="radio" name="cat_img" value="6" id="img_6">
                                            <label class="bg-careys-pink" for="img_6">
                                                <i class="icofont-site-map"></i>
                                                
                                            </label>
                                            <input type="radio" name="cat_img" value="7" id="img_7">
                                            <label class="bg-lightblue" for="img_7">
                                                <i class="icofont-tasks"></i>
                                                
                                            </label>
                                    </div>
                                </div>
                                <input type="submit" name="add_cat" class="add_cat" style="display:none;"> 
                            </form>
                        </div>
                        
                    </div>
                    <div class="modal-footer">
                        <!-- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Done</button> -->
                        <button type="submit" class="btn btn-primary add_cat_btn" onclick="" title="Save">Save</button>
                        <button type="button" class="btn btn-primary clear-btn" title="Clear">Clear</button>
                    </div>
                </div>
                </div>
            </div>
            <div class="spinner-border float-right" role="status" style="display:none;">
                <span class="sr-only">Loading...</span>
              </div>
 <?php
	include("footer.php");   
?>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>


<style type="text/css">
.modal-footer button:hover {
    background-color: #fff;
    color: #163339;
    transition: all 0.3s ease-in-out;
}
button.btn.clear-btn:hover {
    background-color: #163339;
    color: #fff;
}

button.manager-button:hover, button.category-button:hover {
    background-color: #fff;
    color: #212529;
    transition: all 0.4s ease-in-out;
}

.project-tab button.create_proj:hover {
    background-color: #fff;
    color: #212529;
    transition: all 0.4s ease-in-out;
}
.tbl_person th{
     
    width: 21.3%;

}
div#createtask {
    background: rgb(0 0 0 / 50%);
}
.mb-3.manager-inner {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
}
.manager-itm {
    width: 80%;
}
.icon_groups div, .icon_groups label{
    width: 60px;
    height: 60px;
    text-align: center;
    cursor: pointer;
    display: inline-block;
    color: black;
    font-size: 30px;
}
.icon_groups i {
    vertical-align: middle;
}
.icon_groups input[type="radio"] {
    display: none;
}
.icon_groups input:checked + label {
    border: 1px solid #000;
}
.ts-btn {
    margin: 14px 0 0 auto;
}
@media(max-width:991px){
    .manager-itm {
        width: 100%;
    }
    .manager-btn, .edit-manager {
        margin-top: 12px;
    }
}
 .no-task {
    width: 100%;
    border: 1px dotted #d0d2d3;
    padding: 20px;
    text-align: center;
}       
span.select2-container {
    z-index: 99999;
    width: 179px !important;
    margin-right: 5px;
}
button.add_person, button.remove_person{
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    line-height: 26px;
    background-color: #163339;
    border: 2px solid #163339;
    color: #fff;
    font-size: 17px;
    margin-left: 10px;
    transition: all 0.5s ease-in-out;
}
.task-btn {
    width: 100%;
    text-align: right;
}
.view-table table {
    padding: 10px;
    border-collapse: separate;
}
.view-description {
    padding-bottom: 12px;
}
.task-button {
    text-align: right;
}
.create-task-list h5 {
    margin: 14px 0 20px;
    font-weight: 700;
}
.create-task-inner {
    display: flex;
    flex-wrap: wrap;
}
.task-item {
    width: calc(100% / 2 - 10px);
    margin-right: 20px !important;
    border: 1px dotted #000;
    padding: 10px;
    margin-bottom: 20px;
}
.create-task-inner .task-item:nth-child(even) {
    margin-right: 0 !important;
}
.task-item p {
    margin-bottom: 0;
}
select.form-select.proj_empl.disabled + span {
    pointer-events: none;
}
button.add_person:hover, button.remove_person:hover, 
button.add_person:focus, button.remove_person:focus{
    background-color: #fff;
    color: #163339;
}
.create-task-inner a.btn.btn-dark.btn-set-task.w-sm-100.ts-btn {
    background: transparent;
    border-bottom: 1px solid #000 !important;
    border: none;
    border-radius: 0px;
    color: #000;
    font-weight: 700;
    font-size: 16px;
    padding: 0px;
    height: 24px;
}
/*.view-table table th, .view-table table tr {
    border-right: 1px solid #163339;
}
.view-table table th:last-child{
    border-right: 0;
}*/
button.add_person{
    margin-bottom: 5px;
}
.mb-3.project-sec {
    display: flex;
    flex-wrap: wrap;
}
.project-sec label.form-label {
    padding-right: 10px;
}
.task-table table {
    width: 100%;
    border: 1px solid #163339;
}
.view-modal-dl .modal-body {
    padding-top: 20px;
}
.view-modal-dl .project-sec {
    margin-bottom: 10px !important;
}
.view-modal-dl .project-sec label.form-label {
    margin-bottom: 0;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
    top: 6px;
}
.select2-container--default .select2-selection--single:focus {
    border: 1px solid #163339;
    box-shadow: 0 0 10px rgb(33 37 41 / 15%);
}
.select2-container--default .select2-selection--single {
    border: 1px solid #f0f0f0;
    height: 38px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
    padding: 4px 20px 3px 8px;
}
.spinner-border.float-right {
        position: fixed;
        top: 45%;
        right: 50%;
        z-index: 99999999;
    }
.mb-3.category-inner {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
}
.category-inner .category-item {
    width: 80%;
}
input.task_name{
    background: transparent;
    width: 100%;
    border: none;
}
input.task_name:focus {
    outline: none;
}
.task-item {
    position: relative;
}
.task-item:hover i.task_delete  {
    display: block;
}
i.task_delete {
    display: none;
    position: absolute;
    right: 4px;
    top: 4px;
    cursor: pointer;
}
p.no-proj-found {
    margin: 0 auto;
    display: flex;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
}
table.tbl_person tfoot td {
    padding-top: 20px;
}
i.pwd-toggle {
    padding: 11px 6px 9px 0px;
    cursor: pointer;
    background: #fff;
    margin-left: -5px;
    border: 1px solid #f0f0f0;
    border-left: 0px;
    border-radius: 0px 0.25rem 0.25rem 0px;
}
.form-control:focus + i.pwd-toggle {
    /* box-shadow: 0 0 10px rgb(33 37 41 / 15%); */
    background-color: var(--card-color);
    border-color: var(--primary-color);
}
@media(max-width:768px){
    .form-control[type="Password"] {
    width: 94% !important;
}
}
@media (min-width: 576px){
    .modal-dialog{
        max-width: 900px;
    }
}
.form-control[type="Password"] {
    border-right: 0px;
    border-radius: 0.25rem 0px 0px 0.25rem;
}
span.email_error {
    color: red;
}
span.avatar.rounded-circle.text-center.pointer.sm {
    display: none;
}
</style>

<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />

<script type="text/javascript">
    $(document).on("click",".manager-button", function(){
        $("#manager").modal('show');
        $("#manager").attr("data-selected",jQuery(this).closest(".modal").attr("id"));
            
    });
    $(document).on("click",".progress_task li.dd-item", function(){
      $('#myModal').modal('show')
    });
    $(document).on("click",".category-button", function(){

        $("#add_category").attr("data-selected",jQuery(this).closest(".modal").attr("id"));
            
    });
    $(document).on("click",".person-button", function(){

        $("#add_person").attr("data-selected",jQuery(this).closest(".modal").attr("id"));
            
    });
    $("#add_category").on("hidden.bs.modal", function () {
         $("#"+$("#add_category").attr("data-selected")).modal('show');
    });
     $("#manager").on("hidden.bs.modal", function () {
         $("#"+$("#manager").attr("data-selected")).modal('show');
    });
     $("#add_person").on("hidden.bs.modal", function () {
         $("#"+$("#add_person").attr("data-selected")).modal('show');
    });
     jQuery(document).on("click", "#manager .update_profile", function(){
          let valid = true;
          var pwd = $(this).closest(".modal-content").find("input[name='password']");

          $('#manager form [required]').each(function() {
            if ($(this).is(':invalid') || !$(this).val()) valid = false;
          })
          if (!valid){
             $('.save_manager').click();
          } else if(!checkPasswordStrength(pwd) && $(this).closest(".modal-content").find("input[name='password']:visible").length){
                alert("Password Must be strong.");
          } else {
            $(".spinner-border").show();
           // var form_arr = $("#manager form").serializeArray();
            var form_arr = new FormData($("#manager form")[0]);
            form_arr.append('save_manager', '1');
        
            $.ajax({
                type:"post",
                url:window.location.pathname,
                data:form_arr,
               contentType: false,
                     cache: false,
               processData:false,
                success:function(res){
                    if(res == 'email exist'){
                        $(".email_error").show();
                        
                    } else {
                        $(".email_error").hide();
                        $("#manager").modal('hide');
                        $("#"+$("#manager").attr("data-selected")).modal('show');
                        $("select[name='select_manager']").html(res);
                       
                    }
                    $(".spinner-border").hide();
                    
                }

            });
          }
        
     });

     
     jQuery(document).on("click", "#add_person .employee_profile", function(){
          let valid = true;
          var pwd = $(this).closest(".modal-content").find("input[name='password']");

          $('#add_person form [required]').each(function() {
            if ($(this).is(':invalid') || !$(this).val()) valid = false;
          })
          if (!valid){
             $('.save_employee').click();
          } else if(!checkPasswordStrength(pwd) && $(this).closest(".modal-content").find("input[name='password']:visible").length){
            alert("Password Must be strong.");
          } else {
            $(".spinner-border").show();
           // var form_arr = $("#manager form").serializeArray();
            var form_arr = new FormData($("#add_person form")[0]);
            form_arr.append('save_manager', '1');
        
            $.ajax({
                type:"post",
                url:window.location.pathname,
                data:form_arr,
               contentType: false,
                     cache: false,
               processData:false,
                success:function(res){
                    if(res == 'email exist'){
                        $(".email_error").show();
                        
                    } else {
                        $(".email_error").hide();
                        $("#add_person").modal('hide');
                        $("#"+$("#add_person").attr("data-selected")).modal('show');
                        $(".tbody_cls select[name='project_employe[]']").html(res);
                        setTimeout(function(){
                            $(".tbody_cls select[name='project_employe[]']").each(function(){
                                var already_selected = $(this).closest("td").find("input[name='hid_selcted_emp']").val();
                           
                                $(this).val(already_selected).change();
                            
                            });
                            $("div#add_person form")[0].reset();
                        },300);
                        
                       
                    }
                    $(".spinner-border").hide();
                    
                }

            });
          }
        
     });


     $(document).on("click", ".add_cat_btn", function(){
        let valid1 = true;
          $('#add_category form [required]').each(function() {
            if ($(this).is(':invalid') || !$(this).val()) valid1 = false;
          })
          if (!valid1){
             $('.add_cat').click();
          } else {
            $(".spinner-border").show();
            var form_arr_1 = new FormData($("#add_category form")[0]);
            form_arr_1.append('add_cat', '1');

        
            $.ajax({
                type:"post",
                url:window.location.pathname,
                data:form_arr_1, 
                contentType: false,
                cache: false,
                processData:false,
                success:function(res){
                       
                    $("#add_category").modal('hide');
                    $("#"+$("#add_category").attr("data-selected")).modal('show');
                    $("select[name='select_cat']").html($(res).find("select[name='select_cat']").html());
                   
                    $(".spinner-border").hide();
                    
                }

            });
          }
            

     });
    var clone_tr = '';
    var clone_task_tr = '';
    jQuery(window).bind("load", function(){
        clone_tr = jQuery(".tbody_cls tr")[0].outerHTML;
        clone_task_tr = jQuery("#createtask .tbody_cls tr")[0].outerHTML;
         $("tbody.tbody_cls select").select2({
            placeholder: "Select",
            dropdownParent: $("#createproject")
        });
        
    });

    jQuery(document).on("click", ".add_task", function(){
        jQuery(this).closest(".tbody_cls").append(clone_task_tr);
        $("tbody.tbody_cls select:not(.select2-hidden-accessible)").select2({
            placeholder: "Select",
        });
    });
    jQuery(document).on("click", ".remove_task", function(){
        if(jQuery(this).closest(".tbody_cls").find("tr").length > 1){
            if(confirm("Are you sure?")){
                jQuery(this).closest("tr").remove();
            }
        }
        
    });


    jQuery(document).on("click", ".add_person:not(.add_task)", function(){

        jQuery(this).closest(".tbody_cls").append('<tr><td><select class="form-select proj_empl new" name="project_employe[]" required="">'+jQuery(this).closest('.tbody_cls').find('.proj_empl').first().html()+'</select><input type="hidden" name="hid_selcted_emp" value=""></td><td><input type="date" class="form-control" id="datepickerded"  name="project_start_date[]" required=""></td><td><input type="date" class="form-control" id="datepickerded"  name="project_end_date[]" required=""></td><td><button class="add_person" type="button" title="Add Employe">+</button><button class="remove_person" type="button" title="Remove Employe">-</button></td><td><select class="select_task" name="project_task[]" multiple="">'+jQuery(this).closest('.tbody_cls').find('.select_task').first().html()+'</select><input type="hidden" class="hidden_task_list" name="hidden_task_list[]"></td></tr>');
        
         //jQuery(this).closest(".tbody_cls").append(jQuery(this).closest("tr")[0].outerHTML);
         var cur = this;
         var m = jQuery(this).closest('.modal').attr('id');
         /*setTimeout(function(){
             jQuery(cur).closest(".tbody_cls").find("tr").last().find("select.select_task").select2("destroy").select2({
                tags: true,
                placeholder: "Select or Create Task",
                dropdownParent: $("#"+m)
            });
       
        });*/
    jQuery(this).closest('.tbody_cls').find('.proj_empl.new:not(.select2-hidden-accessible)').find('option').removeAttr('selected');
    jQuery(this).closest('.tbody_cls').find('.proj_empl.new:not(.select2-hidden-accessible)').find('option').removeAttr('data-select2-id').removeAttr('data-select2-tag');
    jQuery(this).closest('.tbody_cls').find('.select_task:not(.select2-hidden-accessible)').find('option').removeAttr('selected');
    jQuery(this).closest('.tbody_cls').find('.select_task:not(.select2-hidden-accessible)').find('option').removeAttr('data-select2-id').removeAttr('data-select2-tag');

        $("tbody.tbody_cls select:not(.select2-hidden-accessible):not(.select_task)").select2({
            placeholder: "Select",
            dropdownParent: $("#"+m)
        });
        $(".select_task:not(.select2-hidden-accessible)").select2({
            tags: true,
            placeholder: "Select or Create Task",
            dropdownParent: $("#"+m)
        });

    });
    jQuery(document).on("click", ".remove_person:not(.remove_task)", function(){
        if(jQuery(this).closest(".tbody_cls").find("tr").length > 1){
            if(confirm("Are you sure?")){
                jQuery(this).closest("tr").remove();
            }
        }
        
    });

 jQuery(document).on("click",".edit_pro", function(){
    jQuery("#editemp").modal('show');
    var edit_id = jQuery(this).attr("data-id");
    jQuery.ajax({
        type:"post",
        url:"",
        data:{action:"edit_poject",edit_id:edit_id},
        success:function(res){
            
            jQuery('#editproject').html(jQuery(res).find('#editproject').html());

            jQuery(".select_task:not(.select2-hidden-accessible)").select2({
                tags: true,
                placeholder: "Select or Create Task",
                dropdownParent: $("#editproject")
            });
            jQuery(".proj_empl:not(.select2-hidden-accessible)").select2({
                dropdownParent: $("#editproject")
            });
            jQuery('#editproject tbody.tbody_cls tr').each(function(){
                var st_date = jQuery(this).find('input[name="project_start_date[]"]').val();
                if(st_date != ''){
                    jQuery(this).find('input[name="project_end_date[]"]').attr('min', st_date);
                }
            });

        }

    });
});
 jQuery(document).on("click", ".view_pro, div#All-list .card", function(e){
    var edit_id = jQuery(this).attr("data-id");
    if(!jQuery(e.target).hasClass('edit_pro') && jQuery(e.target).closest(".edit_pro").length == 0 && !jQuery(e.target).hasClass('del_project') && jQuery(e.target).closest(".del_project").length == 0){
        $("#viewproject").modal('show');
        jQuery.ajax({
            type:"post",
            url:"",
            data:{action:"edit_poject",edit_id:edit_id},
            success:function(res){
                
                jQuery('#viewproject').html(jQuery(res).find('#viewproject').html());
            }
        });
    }
 });
 jQuery(document).on("click", ".del_project", function(){
    var del_id = jQuery(this).attr("data-id");
    jQuery(".del_id").attr("href", "?delete_id="+del_id);
 });

  jQuery(document).on("click",".task-button button", function(){
    jQuery(".no-task").hide();
    jQuery(".create-task-inner").prepend('<div class="task-item"><i class="icofont-ui-delete text-danger task_delete"></i><h6><input type="text" name="task_name[]" class="task_name"></h6><p></p></div>');
    jQuery(".create-task-inner input").eq(0).focus();
    /*jQuery("#createtask").modal('show');
    var project_id = jQuery(this).attr("data-id");
    jQuery("#createtask input[name='project_id']").val(project_id);*/

  });
  jQuery(document).on("click","i.task_delete", function(){
    if(confirm("Are you sure?")){
        jQuery(this).closest(".task-item").remove();
        if(jQuery(".create-task-inner .task-item").length == 0){
            jQuery(".no-task").show();
        }
    }

  });
  jQuery(document).on('click', '.create_proj', function(){
        setTimeout(function(){
            jQuery(".select_task").select2({
                tags: true,
                dropdownParent: $("#createproject"),
                placeholder: "Select or Create Task"
            });
        },100);
  });
  jQuery(document).on('input', 'input[name="project_start_date[]"]', function(){
   if(jQuery(this).val() != ''){
        var next_dis_date =  new Date(jQuery(this).val()).toISOString().split('T')[0];
        jQuery(this).closest('tr').find('input[name="project_end_date[]"').attr('min', next_dis_date);
   } else{
       jQuery(this).closest('tr').find('input[name="project_end_date[]"').attr('min', '');
   }
   
});
  jQuery(document).on("click", ".pwd-toggle", function(){
    var cur_type = jQuery(this).prev('input').attr('type');
    if(cur_type == 'password'){
        jQuery(this).prev('input').attr('type','text');
        jQuery(this).removeClass('icofont-eye');
        jQuery(this).addClass('icofont-eye-blocked');
    } else {
        jQuery(this).prev('input').attr('type','password');
        jQuery(this).removeClass('icofont-eye-blocked');
        jQuery(this).addClass('icofont-eye');
        
    }
  });
   jQuery(document).on("click", "button.clear-btn", function(){
            jQuery(this).closest(".modal-content").find("input").val('');
            jQuery(this).closest(".modal-content").find("textarea").val("");
            jQuery(this).closest(".modal-content").find("select").val('').change();
    });
    /*** for count how much task assign to current row ****/
    jQuery(document).on("change", ".select_task", function(){
       
        jQuery(this).closest('td').find('input.hidden_task_list').val(jQuery(this).val().length);
        
    });
    jQuery(document).on('change', 'select[name="select_manager"]', function (e) { 
        var manger_val = jQuery(this).val();
        jQuery(this).closest('form').find(".proj_empl").each(function(){ 
            if(jQuery(this).val() == manger_val){
               
                jQuery(this).val('');
                jQuery(this).change(); 
            }
        
        });
    });
    jQuery(document).on('select2:open', '.proj_empl', function (e) {
        var cur = this;
        var all_select_val = [];
        jQuery(cur).find('option').removeAttr('disabled');
        var manger_val = jQuery(this).closest('form').find('#select_manager').val();
        jQuery(this).closest("table").find(".proj_empl").each(function(){
            if(this != cur){ 

                jQuery(cur).find('option[value="'+jQuery(this).val()+'"]').attr("disabled", "");
            }
            if(manger_val != ''){
                jQuery(cur).find('option[value="'+manger_val+'"]').attr("disabled", "");
            }
          
        });
       
    });
    jQuery(document).on('change', '.proj_empl', function (e) {
        var selected_emp = jQuery(this).val();
        jQuery(this).closest("td").find("input[type='hidden']").val(selected_emp);
    });
    jQuery(document).on("click", ".pwd_type", function(){
        if(jQuery(this).val() == 'manually'){
            jQuery(this).closest("form").find(".pwd-manually").removeAttr('readonly');
            jQuery(this).closest("form").find(".pwd-manually, i.icofont-eye.pwd-toggle").show();
            jQuery(this).closest("form").find(".pwd-mail").hide();
        } else {
            jQuery(this).closest("form").find(".pwd-manually").attr('readonly','');
            jQuery(this).closest("form").find(".pwd-manually, i.icofont-eye.pwd-toggle").hide();
            jQuery(this).closest("form").find(".pwd-mail").show();
        }
    });
    $(document).on("click", ".create_proj_btn", function(){
        var project_name = $('div#createproject input[name="project_name"]').val();
        if(project_name != ''){
            $(".spinner-border").show();
            $.ajax({
                type:"post",
                url:window.location.pathname,
                data:{check_project_name_exist:1,project_name:project_name},
                success:function(res){
                    if(res==''){
                        $('.create_project').click();
                        $('div#createproject .show_error').hide();
                        
                    } else {
                        $('div#createproject .show_error').show();
                    }
                    $(".spinner-border").hide();
                }

            })

        } else {
            $('.create_project').click();
        }

        
    });
    $(document).ready(function(){
        var start = moment().startOf('isoWeek');
        var end = moment().endOf('isoWeek');
         function cb(start, end) {
               // $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
               //start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY');
               //$('input.top_range').html(moment(start, "YYYY-MM-DD").startOf('isoWeek').format('MMMM D, YYYY') + ' - ' + moment(start, "YYYY-MM-DD").endOf('isoWeek').format('MMMM D, YYYY'));
                /*start = moment(start, "YYYY-MM-DD").startOf('isoWeek');
                for(var n = 0; n<=6; n++){
                    $(".show_week_date").eq(n).text(moment(start).add(n,'days').format('dd')+', '+moment(start).add(n,'days').format('MMM')+" "+moment(start).add(n,'days').format('DD'));
                    $(".show_week_date").eq(n).next("input").val(moment(start).add(n,'days').format('YYYY-MM-DD'));
                }*/
                $(".spinner-border").show();
                $.ajax({
                    type:"post",
                    url:window.location.pathname,
                    data:{pass_start_date:start.format('DD-MM-YYYY'),pass_end_date:end.format('DD-MM-YYYY')},
                    success: function(res){
                        $(".spinner-border").hide();
                        $("div#All-list").html($(res).find("div#All-list").html());
                        //console.log($(res).find("div#All-list").html());
                    }
                })
               
            }
            $('input[name="daterange"]').daterangepicker({
                locale: {
                    format: 'YYYY-MM-DD',
                    firstDay:1,
                },weekStart: 1,
                startDate: moment().startOf('isoWeek'),
                endDate: moment().endOf('isoWeek')
                
            }, cb);
            cb(start, end);
    });
function onlyNumberKey(evt) {
      
    // Only ASCII character in that range allowed
    var ASCIICode = (evt.which) ? evt.which : evt.keyCode
    if (ASCIICode > 31 && (ASCIICode < 48 || ASCIICode > 57))
        return false;
    return true;
}
function fileValidation(e){
    var fileInput = e;
    var filePath = fileInput.value;
    if(filePath == ''){ return false; }
    var allowedExtensions = /(\.jpg|\.jpeg|\.png)$/i;
    if(!allowedExtensions.exec(filePath)){
        alert('Please upload file having extensions .jpeg/.jpg/.png only.');
        fileInput.value = '';
        return false;
    }
}

function checkPasswordStrength(curr) {
    var number = /([0-9])/;
    var alphabets = /([a-zA-Z])/;
    var special_characters = /([~,!,@,#,$,%,^,&,*,-,_,+,=,?,>,<])/;
    var password = $(curr).val().trim();
    if (password.length < 6) {
        $(curr).closest("div").find('#password-strength-status').removeClass();
        $(curr).closest("div").find('#password-strength-status').addClass('weak-password');
        $(curr).closest("div").find('#password-strength-status').html("Weak (should be atleast 6 characters.)");
    } else {
        if (password.match(number) && password.match(alphabets) && password.match(special_characters)) {
            $(curr).closest("div").find('#password-strength-status').removeClass();
            $(curr).closest("div").find('#password-strength-status').addClass('strong-password');
            $(curr).closest("div").find('#password-strength-status').html("Strong");
            return true;
        }
        else {
            $(curr).closest("div").find('#password-strength-status').removeClass();
            $(curr).closest("div").find('#password-strength-status').addClass('medium-password');
            $(curr).closest("div").find('#password-strength-status').html("Medium (should include alphabets, numbers and special characters.)");
        }
    }
    return false;
}
</script>
    