<?php
    include("header.php");
    if(isset($_POST['hidden_task_id']) && isset($_POST['update_task'])){

        mysqli_query($conn, "Update db_tasks SET name='".$_POST['task_title']."', project_id='".$_POST['task_pro_name']."', emplyee_id='".serialize($_POST['task_employe'])."' WHERE id=".$_POST['hidden_task_id']);
        $task_details = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_tasks WHERE id=".$_POST['hidden_task_id']));
        $proj_details = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects WHERE id=".$_POST['task_pro_name']));

        unserialize($task_details['emplyee_id']);
        $diff_arr = array_diff($_POST['task_employe'],unserialize($task_details['emplyee_id']));
           if(!empty($diff_arr)){
            foreach($diff_arr as $da):
                $emp = get_user_by_id($da);
                $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>".$proj_details['name']."</b>.<br><br> Below is details of task:<br><b>Task Name :</b> ".$_POST['task_title']."<br><br> Regards,<br> Timesheethub.";
                send_zoho_mail($emp['email'],"New Task Assigned to You.",$msg); 
            endforeach;
           }                
        
    }
    if(isset($_POST['create_task'])){
        
        if(!empty($_POST['task_pro_name'])){
            //foreach($_POST['task_pro_name'] as $key => $single){
                mysqli_query($conn, "Insert into db_tasks(name,project_id,description,emplyee_id,status,user_id,creation_time) values('".$_POST['task_title']."','".$_POST['task_pro_name']."','".$_POST['task_description']."', '".serialize(array($_POST['task_employe'][0]))."','in-progress', '".$_SESSION['loggedin_user']."','".date("Y-m-d h:i:s")."' )");
                $last_task_id = mysqli_insert_id($conn);
                $get_porject_detail = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects where id=".$_POST['task_pro_name']));
                //$last_task_id = mysqli_insert_id($conn);
                
                $e_ids = unserialize($get_porject_detail['employee_ids']);
                $e_t_ids = unserialize($get_porject_detail['employee_task_ids']);
                foreach($e_ids as $k => $s){
                    if($s['employe_id'] == $_POST['task_employe'][0]){
                        array_push($s['task_name'], $_POST['task_title']);
                        $e_ids[$k]['task_name'] = $s['task_name'];
                    }
                }
                foreach($e_t_ids as $k => $es){
                    if($es['employe_id'] == $_POST['task_employe'][0]){
                        array_push($es['task_name'], $last_task_id);
                        $e_t_ids[$k]['task_name'] = $es['task_name'];
                    }
                }
                
                mysqli_query($conn, "UPDATE db_projects SET employee_ids='".serialize($e_ids)."', employee_task_ids='".serialize($e_t_ids)."' where id=".$_POST['task_pro_name']);
                

                $title = $_POST['task_title']." task from this project : <b>".$get_porject_detail['name']."</b>.";
                $desc = $_POST['task_title']." task from this project : <b>".$get_porject_detail['name']."</b>. Assigned by ".get_user_by_id($_SESSION['loggedin_user']);
                $emp  = get_user_by_id($_POST['task_employe'][0]);
                $msg = "Hello ".ucwords($emp['full_name']).",<br><br> New task assigned to you by ".get_user_by_id($_SESSION['loggedin_user'])['full_name'].".<br> Here is details of task:<br><b>Task Name :</b> ".$_POST['task_title']."<br><b>Project Name : </b> ".$get_porject_detail['name']."<br><br> Regards,<br> Timesheethub.";
                send_zoho_mail($emp['email'],"New Task Assigned to you.",$msg);
                mysqli_query($conn, "INSERT INTO db_user_activity(title, description, created_by, to_user_id, date_time) VALUES('$title', '$desc','".$_SESSION['loggedin_user']."', '".$_POST['task_employe'][0]."', '".date("Y-m-d h:i:s")."')");

                
            //}
        }
        
    }
    if(isset($_GET['delete_task']) && !empty($_GET['delete_task'])){
        mysqli_query($conn, "DELETE from db_tasks WHERE id=".$_GET['delete_task']);
        mysqli_query($conn, "DELETE FROM db_timelog WHERE task_id =".$_GET['delete_task']);
        echo "<script>window.history.pushState('', '', window.location.pathname);</script>";
    }
    $all_projects_arr = array();
    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']);
     } elseif ($emp_list['type'] == 'company') {
        $all_managers = mysqli_fetch_assoc(mysqli_query($conn, "SELECT GROUP_CONCAT(id SEPARATOR ',') AS ids FROM db_users where company_name='".$_SESSION['loggedin_user']."' and type='manager'"));
        if(isset($all_managers['ids'])){
            $all_projects = mysqli_query($conn, "SELECT * FROM db_projects WHERE manager_id in(".$all_managers['ids'].")");
        }
       

     } else {

        $all_projects = mysqli_query($conn, "SELECT * FROM db_projects t1, db_tasks t2 where t2.id=t1.project_id and t1.user_id=".$_SESSION['loggedin_user']." or t1.employee_ids REGEXP '.*\"employe_id\";s:[0-9]+:\"".$_SESSION['loggedin_user']."\".*'  order by t1.id DESC");
     }
    while ($single_project = mysqli_fetch_array($all_projects)) {
        /* if (!empty($_GET['filter_proj'])) {
            if($_GET['filter_proj'] == $single_project['id']){
                $all_projects_arr[$single_project['id']]= $single_project;
            }

        } else { */
            $all_projects_arr[$single_project['id']]= $single_project;
            if(isset($_GET['filter_date']) && !empty($_GET['filter_date'])){
                $emp_data = unserialize($single_project['employee_task_ids']);
                
                foreach($emp_data as $ed){
                    if($ed['employe_id'] == $_SESSION['loggedin_user']):
                        $pass_date = explode(' - ', $_GET['filter_date']);
                    if((strtotime($ed['start_date'])  <=  strtotime($pass_date[0]) && strtotime($ed['end_date'])  >=  strtotime($pass_date[0])) 
                        || (strtotime($ed['start_date'])  <=  strtotime($pass_date[1]) && strtotime($ed['end_date'])  >=  strtotime($pass_date[1])) 
                        || (strtotime($t['start_date'])  >=  strtotime($pass_date[0]) && strtotime($ed['end_date'])  <=  strtotime($pass_date[1]))){
                            
                        }
                    endif;
                    
                }

            }

        /* } */
        
        
    }

   
    if($emp_list['type'] == 'admin'){
        $all_tasks_inpro = mysqli_query($conn, "SELECT * FROM db_tasks where status='in-progress' order by id DESC");
        
        if (!empty($_GET['filter_proj']) && !empty($_GET['filter_date'])) {
            $pass_date = explode(' - ', $_GET['filter_date']);
            //if($pass_date[0] == $pass_date[1]){ $pass_date[1] = date("Y-m-d", strtotime($pass_date[0]. "+1 day"));  }
            $all_tasks_inpro = mysqli_query($conn, "SELECT * FROM db_tasks where project_id = '".$_GET['filter_proj']."' and (cast(creation_time as date) >= DATE('".$pass_date[0]."') and cast(creation_time as date) <=  DATE('".$pass_date[1]."')) order by id DESC");
        }else if (!empty($_GET['filter_proj'])) {
            $all_tasks_inpro = mysqli_query($conn, "SELECT * FROM db_tasks where project_id = '".$_GET['filter_proj']."' and status='in-progress' order by id DESC");
        } else if (!empty($_GET['filter_date'])) {
            $pass_date = explode(' - ', $_GET['filter_date']);
            
            $query = "SELECT * FROM db_tasks where cast(creation_time as date) between DATE('".$pass_date[0]."') and DATE('".$pass_date[1]."') order by id DESC";
            $all_tasks_inpro = mysqli_query($conn,$query);
          

        }
     } elseif($emp_list['type'] == 'manager' || $emp_list['type'] == 'company'){
        $all_tasks_inpro = mysqli_query($conn, "SELECT * FROM db_tasks where status='in-progress' and project_id in(".implode(',', array_keys($all_projects_arr)).")  order by id DESC");
        if (!empty($_GET['filter_proj']) && !empty($_GET['filter_date'])) {
            $pass_date = explode(' - ', $_GET['filter_date']);
           
            $all_tasks_inpro = mysqli_query($conn, "SELECT * FROM db_tasks where project_id = '".$_GET['filter_proj']."' and (cast(creation_time as date) >= DATE('".$pass_date[0]."') and cast(creation_time as date) <=  DATE('".$pass_date[1]."')) and project_id in(".implode(',', array_keys($all_projects_arr)).") order by id DESC");
        } else if (!empty($_GET['filter_proj'])) {
            $all_tasks_inpro = mysqli_query($conn, "SELECT * FROM db_tasks where project_id = '".$_GET['filter_proj']."' and status='in-progress' and project_id in(".implode(',', array_keys($all_projects_arr)).") order by id DESC");
        } else if (!empty($_GET['filter_date'])) {
            $pass_date = explode(' - ', $_GET['filter_date']);
            
            $query = "SELECT * FROM db_tasks where cast(creation_time as date) >= DATE('".$pass_date[0]."') and cast(creation_time as date) <=  DATE('".$pass_date[1]."') and project_id in(".implode(',', array_keys($all_projects_arr)).") order by id DESC";
            $all_tasks_inpro = mysqli_query($conn,$query);
        }
     } else {
        $all_tasks_inpro = mysqli_query($conn, "SELECT * FROM db_tasks where  (user_id=".$_SESSION['loggedin_user']." or emplyee_id REGEXP '.*[0-9]+;s:[0-9]+:\"".$_SESSION['loggedin_user']."\".*') order by id DESC");
        if (!empty($_GET['filter_proj']) && !empty($_GET['filter_date'])) {
            $pass_date = explode(' - ', $_GET['filter_date']);
          
            $all_tasks_inpro = mysqli_query($conn, "SELECT * FROM db_tasks where project_id = '".$_GET['filter_proj']."' and (user_id=".$_SESSION['loggedin_user']." or emplyee_id REGEXP '.*[0-9]+;s:[0-9]+:\"".$_SESSION['loggedin_user']."\".*') order by id DESC");
            //echo "SELECT * FROM db_tasks where project_id = '".$_GET['filter_proj']."' and (cast(creation_time as date) >= DATE('".$pass_date[0]."') and cast(creation_time as date) <=  DATE('".$pass_date[1]."')) and (user_id=".$_SESSION['loggedin_user']." or emplyee_id REGEXP '.*[0-9]+;s:[0-9]+:\"".$_SESSION['loggedin_user']."\".*') order by id DESC";
        }else if (!empty($_GET['filter_proj'])) {
            $all_tasks_inpro = mysqli_query($conn, "SELECT * FROM db_tasks where project_id = '".$_GET['filter_proj']."' and status='in-progress' and (user_id=".$_SESSION['loggedin_user']." or emplyee_id REGEXP '.*[0-9]+;s:[0-9]+:\"".$_SESSION['loggedin_user']."\".*') order by id DESC");
        }else if (!empty($_GET['filter_date'])) {
            $pass_date = explode(' - ', $_GET['filter_date']);
            
            $query = "SELECT * FROM db_tasks where (user_id=".$_SESSION['loggedin_user']." or emplyee_id REGEXP '.*[0-9]+;s:[0-9]+:\"".$_SESSION['loggedin_user']."\".*') order by id DESC";
           
            $all_tasks_inpro = mysqli_query($conn,$query);

        }
     }
    $all_tasks_list = 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($at = mysqli_fetch_assoc($all_tasks_inpro)){
       
        if($emp_list['type'] != 'employee'){
            //array_push($all_tasks_list, $at);
            $all_tasks_list[$at['id']] = $at;
        } else {
            

            $get_proj = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects WHERE id=".$at['project_id']));
            if(isset($_GET['filter_date']) && !empty($_GET['filter_date'])){
                $pass_date = explode(' - ', $_GET['filter_date']);
                $this_week_monday = $pass_date[0];
                $this_week_sunday = $pass_date[1];
            } 
            
            $t_ids      = unserialize($get_proj['employee_task_ids']);
            $p = 0;
            foreach($t_ids as $t){
               
                if(in_array($at['id'], $t['task_name'])){

                     if((strtotime($t['start_date'])  <=  strtotime($this_week_monday) && strtotime($t['end_date'])  >=  strtotime($this_week_monday)) 
                        || (strtotime($t['start_date'])  <=  strtotime($this_week_sunday) && strtotime($t['end_date'])  >=  strtotime($this_week_sunday)) 
                        || (strtotime($t['start_date'])  >=  strtotime($this_week_monday) && strtotime($t['end_date'])  <=  strtotime($this_week_sunday))){
                                $p = 1;
                                
                        }
                }
            }
            
           
            if($p == 1){
                //array_push($all_tasks_list, $at);
                if(!isset($all_tasks_list[$at['id']])){
                    $all_tasks_list[$at['id']] = $at;
                }
                
            }
            
        }
        
        if(!in_array($at['project_id'], $all_projects_arr)){
            
            $all_projects_arr[$at['project_id']] = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects where id=".$at['project_id']));
        }
     }
     $new_all_tasks = $all_tasks_list;
    //echo "<pre>"; print_r($new_all_tasks); echo "</pre>";
     
   
?>
<link rel="stylesheet" href="<?= $site_url; ?>/assets/plugin/nestable/jquery-nestable.css"/>  

            <!-- 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 py-3 no-bg bg-transparent d-flex align-items-center px-0 justify-content-between border-bottom flex-wrap">
                                <h3 class="h4 mb-0">Task Management</h3>

                                <div class="inline-filter" style="display:flex;">
                                <select class="project_filter" style="margin-right: 10px;">
                                    <option value=""> -- Select Project -- </option>
                                    <?php 
                                        if(!empty($all_projects_arr)){
                                            foreach($all_projects_arr as $single_pro){
                                               
                                                 //$fetch_pro = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects WHERE id=".$single_pro['id']));
                                            
                                                $selected_proj = ($_GET['filter_proj'] == $single_pro['id']) ? "selected" : "";
                                                //if(!empty($fetch_pro)){

                                                    echo '<option value="'.$single_pro['id'].'" '.$selected_proj.'>'.$single_pro['name'].'</option>';
                                                //}
                                                
                                            }
                                        }
                                      
                                    ?>

                                </select>
                                
                                <input type="text" name="daterange" value="" placeholder="Filter By Date" autocomplete="off" style="width:195px;">
                                    <button class="btn btn-dark clear_filter" style="display: none;">Clear Filter</button>
                                
                            </div>
                                <div class="col-auto d-flex w-sm-100 mt-2 mt-sm-0">
                                    <?php if($emp_list['type'] != 'employee'){ ?>
                                    
                                    <button type="button" class="btn btn-dark btn-set-task w-sm-100" data-bs-toggle="modal" data-bs-target="#createtask" title="Create Task"><i class="icofont-plus-circle me-2 fs-6"></i>Create Task</button>
                                <?php } ?>
                                   
                                </div>
                            </div>
                        </div>
                    </div> <!-- Row end  -->  
                    
                    <div class="row clearfix g-3">
                        <div class="col-lg-12 col-md-12 flex-column">
                            <div class="row taskboard g-3 pb-xxl-4">
                                
                       
                                <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 mt-xxl-12 mt-xl-12 mt-lg-12 mt-md-12 mt-sm-12 mt-12">
                                    
                                    <div class="progress_task">
                                        <div>
                                            <ol class="dd-list">
                                                <?php

                                               

                                                    $i = 1;
                                                   
                                                    if( !empty($all_tasks_list)):
                                            
                                                   // while ($single_task_inpro = mysqli_fetch_array($all_tasks_inpro)) {
                                                   
                                                    foreach ($all_tasks_list as $k => $single_task_inpro) {
                                                       
                                            
                                                        
                                                         $employee_ids = unserialize($single_task_inpro['emplyee_id']);
                                                         /*if(!isset($all_projects_arr[$single_task_inpro['project_id']])){
                                                            continue;
                                                         }*/
                                                         //$pro_name = $all_projects_arr[$single_task_inpro['project_id']]['name'];
                                                         $pro_name = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects where id=".$single_task_inpro['project_id']));

                                                         $fetch_cat = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_tasks_cat WHERE cat_id=".$single_task_inpro['cat_id']));
                                                         /*$priority_class = '';
                                                         if($single_task_inpro['priority'] == 'High' || $single_task_inpro['priority'] == 'Highest'){
                                                                $priority_class = 'bg-danger';
                                                         } else if($single_task_inpro['priority'] == 'Medium'){
                                                                $priority_class = 'bg-warning';
                                                         } else if($single_task_inpro['priority'] == 'Low'){
                                                                $priority_class = 'bg-success';
                                                         }*/
                                                        $show_delete = ($single_task_inpro['user_id'] == $_SESSION['loggedin_user'] || $emp_list['type'] == 'admin') ? '<div class="action-div"><i class="icofont-close-circled ic"  data-id="'.$single_task_inpro['id'].'" title="Remove"></i><i class="icofont-pencil-alt-5 edit_task" style="margin-left: 5px;"  data-id="'.$single_task_inpro['id'].'" title="Edit"></i><i class="icofont-eye-alt text-warning" title="View"></i></div>' : ''; 

                                                        $show_date = date('d M' ,strtotime($single_task_inpro['creation_time']));
                                                        if($emp_list['type'] == 'employee'){
                                                            $task_info = unserialize($pro_name['employee_task_ids']);
                                                           if(!empty($task_info)){
                                                                foreach($task_info as $ti){
                                                                    if($ti['employe_id'] == $_SESSION['loggedin_user']){
                                                                        $show_date = date('d M' ,strtotime($ti['start_date']))." - ".date('d M' ,strtotime($ti['end_date']));
                                                                    }
                                                                }
                                                           }
                                                            //$show_date = 
                                                        }

                                                    
                                                          echo '<li class="dd-item" data-id="'.$i.'" data-task-id="'.$single_task_inpro['id'].'">
                                                    <div class="dd-handle">
                                                        '.$show_delete.'
                                                        <div class="task-info d-flex align-items-center justify-content-between">
                                                            <h6 class="light-success-bg py-1 px-2 rounded-1 d-inline-block fw-bold small-14 mb-0">'.$single_task_inpro['name'].'
                                                            </h6>
                                                            <div class="task-priority d-flex flex-column align-items-center justify-content-center">
                                                                <div class="avatar-list avatar-list-stacked m-0">
                                                                    ';
                                                                    foreach ( $employee_ids as $single_emp) {
                                                                        // show only loggedin employee profile
                                                                        if($emp_list['type'] == 'employee' && $single_emp == $emp_list['id']){
                                                                            $fetch_user = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_users WHERE id=".$single_emp));
                                                                            $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 small-avt" src="'.$profile_img.'" alt="'.$fetch_user['full_name'].'" title="'.$fetch_user['full_name'].'">';
                                                                        } elseif( $emp_list['type'] != 'employee') {
                                                                            // show all employee profiles
                                                                            $fetch_user = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_users WHERE id=".$single_emp));
                                                                            $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 small-avt" src="'.$profile_img.'" alt="'.$fetch_user['full_name'].'" title="'.$fetch_user['full_name'].'">';

                                                                        }
                                                                        
                                                                       
                                                                    }

                                                                    echo '
                                                            
                                                                </div>
                                                                
                                                            </div>
                                                        </div>
                                                        <p class="py-2 mb-0">'.substr($single_task_inpro['description'], 0, 100).'</p>
                                                        <div class="tikit-info row g-3 align-items-center">
                                                            <div class="col-sm">
                                                                <ul class="d-flex list-unstyled align-items-center flex-wrap">
                                                                    <li class="me-2">
                                                                        <div class="d-flex align-items-center">
                                                                            <i class="icofont-calendar"></i>
                                                                            <span class="ms-1">'.$show_date.'</span>
                                                                        </div>
                                                                    </li>
                                                            
                                                                </ul>
                                                            </div>
                                                            <div class="col-sm text-end">
                                                                
                                                                <div class="small text-truncate light-danger-bg py-1 px-2 rounded-1 d-inline-block fw-bold small">'.$pro_name['name'].'</div>
                                                            </div>
                                                        </div>
                                                    </div>
            
                                                </li>';  
                                                $i++;
                                                }
                                                    else:
                                            echo '<li class="dd-item" data-id="1">No Tasks Found Here.</li>';
                                        endif;
                                                ?>
                                                
                                            </ol>
                                        </div>
                                    </div>
                                </div>

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


            <!-- Create task-->  
            <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="">
                                <div class="form-data">
                                    
                                    <div class="input-group">
                                        <div class="lable-name">
                                            Title
                                        </div>
                                        <input type="text" name="task_title" required="" placeholder="Title here" value="<?= $task_name; ?>">
                                    </div>
                                     <div class="input-group">
                                        <div class="lable-name">
                                            Project
                                        </div>
                                        <select class="form-select" aria-label="Default select Project Category" name="task_pro_name" style="width: auto; max-width: 260px;" required>
                                            <option value="">Select Project Name</option>
                                                    <?php
                                                    foreach($all_projects_arr as $single_pro){
                                                        
                                                      echo '<option value="'.$single_pro['id'].'">'.$single_pro['name'].'</option>'; 
                                                    }
                                                    ?>
                                                </select>
                                    </div>
                                     <div class="input-group">
                                        <div class="lable-name">
                                            Assign Person
                                        </div>
                                         <?php 
                                        
                                                    $readonly = '';
                                                    if($curr_user_type != 'admin' && $curr_user_type != 'manager'){
                                                        $readonly = 'readonly';
                                                    }
                                                    
                                                ?>
                                                <select class="form-select" aria-label="Default select Priority" name="task_employe[]" <?= $readonly; ?> multiple style="width: auto; max-width: 260px; pointer-events:none;" required="true">
                                                    <option value="">Select Person</option>
                                                <?php
                                                    $query = mysqli_query($conn, "SELECT * FROM db_users where type in('employee','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']);
                                                    } else if(get_user_by_id($_SESSION['loggedin_user'])['type'] == 'manager') {
                                                        $query = mysqli_query($conn, "SELECT * FROM db_users where id not in(".$_SESSION['loggedin_user'].") and company_name=".get_user_by_id($_SESSION['loggedin_user'])['company_name']);
                                                        
                                                    }
                                                    if(isset($_POST['get_project_info']) && !empty($_POST['get_project_info'])){
                                                        $get_pro = mysqli_fetch_assoc(mysqli_query($conn,"SELECT * FROM db_projects WHERE id=".$_POST['get_project_info']));
                                                        
                                                        if(!empty($get_pro)){
                                                           $u_ids = unserialize($get_pro['employee_ids']);
                                                              if(!empty($u_ids)){
                                                                $ids_with_comma = implode(",",array_column($u_ids, 'employe_id'));
                                                                $query = mysqli_query($conn, "SELECT * FROM db_users where id not in(".$_SESSION['loggedin_user'].") and id in($ids_with_comma)");
                                                              }

                                                        }
                                                    }

                                                    while($row = mysqli_fetch_array($query) ){
                                                       // $selected = ($row['id'] == $_SESSION['loggedin_user']) ? "selected" : ""; 
                                                       if(isset($_POST['get_project_info'])){
                                                        echo '<option value="'.$row['id'].'">'.$row['full_name'].'</option>';
                                                       }
                                                    }

                                                ?>
                                                </select>
                                                 <?php 
                                                     if(isset($_GET['edit_task']) && !empty($_GET['edit_task'])){ 
                                                        echo "<input type='hidden' class='hidden_task_id' name='hidden_task_id' value='".$_GET['edit_task']."'>";
                                                     }
                                                     ?>
                                    </div>

                                </div>
                            
                                
                                <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 create_task_btn" title="Create">Create</button>
                        <button type="button" class="btn btn-primary clear-btn" title="Clear">Clear</button>

                    </div>
                </div>
                </div>
            </div>
            
            <div class="modal fade" id="edit_task" 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"> Edit 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="">
                                <div class="form-data">
                                <?php 
                                        $task_name = '';
                                        $task_proj = '';
                                        $task_person  = array();
                                        if(isset($_GET['edit_task']) && !empty($_GET['edit_task'])){

                                            $get_data = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_tasks WHERE id=".$_GET['edit_task']));

                                            $task_name = $get_data['name'];
                                            $task_proj = $get_data['project_id'];
                                            $task_person = unserialize($get_data['emplyee_id']);
                                            
                                        }
                                    ?> 

                                    <div class="input-group">
                                        <div class="lable-name">
                                            Title
                                        </div>
                                        <input type="text" name="task_title" required="" placeholder="Title here" value="<?= $task_name; ?>">
                                    </div>
                                     <div class="input-group">
                                        <div class="lable-name">
                                            Project
                                        </div>
                                        <select class="form-select" aria-label="Default select Project Category" name="task_pro_name">
                                                    <option value="">Select Project Name</option>
                                                    <?php
                                                    foreach($all_projects_arr as $single_pro){
                                                        $selected = ($task_proj == $single_pro['id']) ? "selected" : "";
                                                      echo '<option value="'.$single_pro['id'].'" '.$selected.'>'.$single_pro['name'].'</option>'; 
                                                    }
                                                    ?>
                                                </select>
                                    </div>
                                     <div class="input-group">
                                        <div class="lable-name">
                                            Assign Person
                                        </div>
                                         <?php 
                                        
                                                    $readonly = '';
                                                    if($curr_user_type != 'admin' && $curr_user_type != 'manager'){
                                                        $readonly = 'readonly';
                                                    }
                                                ?>
                                                <select class="form-select" aria-label="Default select Priority" name="task_employe[]" <?= $readonly; ?> multiple required="">
                                                    <option value="">Select Person</option>
                                                <?php
                                                    $query = mysqli_query($conn, "SELECT * FROM db_users where type in('employee','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']);
                                                    } else if(get_user_by_id($_SESSION['loggedin_user'])['type'] == 'manager') {
                                                        $query = mysqli_query($conn, "SELECT * FROM db_users where id not in(".$_SESSION['loggedin_user'].") and company_name=".get_user_by_id($_SESSION['loggedin_user'])['company_name']);
                                                        
                                                    }

                                                    if(isset($_POST['get_project_info']) && !empty($_POST['get_project_info'])){
                                                        $get_pro = mysqli_fetch_assoc(mysqli_query($conn,"SELECT * FROM db_projects WHERE id=".$_POST['get_project_info']));
                                                        
                                                        if(!empty($get_pro)){
                                                           $u_ids = unserialize($get_pro['employee_ids']);
                                                              if(!empty($u_ids)){
                                                                $ids_with_comma = implode(",",array_column($u_ids, 'employe_id'));
                                                                $query = mysqli_query($conn, "SELECT * FROM db_users where id not in(".$_SESSION['loggedin_user'].") and id in($ids_with_comma)");
                                                              }

                                                        }
                                                    }

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

                                                ?>
                                                </select>
                                                 <?php 
                                                     if(isset($_GET['edit_task']) && !empty($_GET['edit_task'])){ 
                                                        echo "<input type='hidden' class='hidden_task_id' name='hidden_task_id' value='".$_GET['edit_task']."'>";
                                                     }
                                                     ?>
                                    </div>

                                </div>
                            
                                
                                <input type="submit" name="update_task" class="update_task" value="create task" style="display: none;">
                            </form>
                        </div>
                    </div>
                       
        
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" onclick="$('.update_task').click()" title="Update">Update</button>
                        <button type="button" class="btn btn-primary clear-btn" title="Clear">Clear</button>

                    </div>
                </div>
                </div>
            </div>
            
            <div class="modal fade" id="viewtask" 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">View 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="deadline-form">
                             <?php 
                             $task_name = "Placeholder Task Name";
                             $ass_html = '';
                             $project_name = "Placeholder Project";
                             $exist = 0;
                                            if(isset($_POST['pass_task_id']) && !empty($_POST['pass_task_id'])){
                                              $get_task = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_tasks WHERE id=".$_POST['pass_task_id']));
                                              $task_name = $get_task['name'];
                                              $task_project = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM db_projects WHERE id=".$get_task['project_id']));
                                
                                              $project_name = $task_project['name'];
                                              $project_tasks_list = $task_project['employee_task_ids'];
                                              $task_arr = unserialize($project_tasks_list);
                                              foreach($task_arr as $s){
                                                if(!empty($s['task_name']) && is_array($s['task_name'])){
                                                    foreach($s['task_name'] as $tn){
                                                        if($tn == $_POST['pass_task_id']){
                                                            $exist = 1;
                                                            if($emp_list['type'] == 'employee' && $s['employe_id'] == $emp_list['id']){
                                                                $full_name = get_user_by_id($s['employe_id'])['full_name'];
                                                                $start_date = $s['start_date'];
                                                                $end_date = $s['end_date'];
                                                                $ass_html .= '<tr>
                                                                                <td>
                                                                                    '.$full_name.'
                                                                                </td> 
                                                                                <td>
                                                                                    '.$start_date.'
                                                                                </td>
                                                                                <td>
                                                                                    '.$end_date.' 
                                                                                </td>
                                                                            </tr>';
                                                            } elseif($emp_list['type'] != 'employee') {
                                                                $full_name = get_user_by_id($s['employe_id'])['full_name'];
                                                                $start_date = $s['start_date'];
                                                                $end_date = $s['end_date'];
                                                                $ass_html .= '<tr>
                                                                                <td>
                                                                                    '.$full_name.'
                                                                                </td> 
                                                                                <td>
                                                                                    '.$start_date.'
                                                                                </td>
                                                                                <td>
                                                                                    '.$end_date.' 
                                                                                </td>
                                                                            </tr>';
                                                            }
                                                            
                                                        }

                                                    }
                                                }
                                                  
                                              }

                                            }
                                            if(!empty($get_task['emplyee_id']) && $exist == 0){
                                                $emp_ids = unserialize($get_task['emplyee_id']);
                                                foreach($emp_ids as $e_id){
                                                    $full_name = get_user_by_id($e_id)['full_name'];
                                                    $ass_html .= '<tr>
                                                    <td>
                                                        '.$full_name.'
                                                    </td> 
                                                    <td>
                                                         -
                                                    </td>
                                                    <td>
                                                         - 
                                                    </td>
                                                </tr>';
                                                }
                                            }
                                        ?>
                            <div class="mb-3 project-sec">
                                <label class="form-label">Title</label> <div class="show_val"><?= $task_name; ?></div>
                            </div>
                            <div class="mb-3 project-sec">
                                <label class="form-label">Project</label> <div class="show_val"><?= $project_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($ass_html)){
                                                    echo '<tr><td colspan="3"><center>No Details Found. </center></td></tr>';
                                                } else {
                                                    echo $ass_html;
                                                }
                                              ?>                                              
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                       
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" title="Close">Close</button>
                    </div>
                </div>
                </div>
            </div>
             <div class="spinner-border float-right" role="status" style="display:none;">
                <span class="sr-only">Loading...</span>
              </div>
<style type="text/css">
.form-data {
    display: flex;
    align-items: center;
}
.form-data input {
    max-width: 260px;
    padding: 9px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    border-top-left-radius: 4px !important;
    border-bottom-left-radius: 4px !important;
}
.form-data .input-group {
    position: relative;
    display: inline-grid;
    flex-wrap: wrap;
    align-items: stretch;
    width: 100%;
}
.form-data input:focus-visible {
    outline: 1px solid #000;
}

.action-div i:last-child {
    margin-left: 5px;
}
.action-div {
    display: flex;
    align-items: center;
    position: absolute;
    top: 4px;
    left: 10px;
    opacity: 0;
    visibility: hidden;
}
.taskboard .dd-handle {
    padding-top: 25px;
}
.action-div i {
    position: unset !important;
}
.spinner-border.float-right {
        position: fixed;
        top: 45%;
        right: 50%;
        z-index: 99999999;
    }
.progress_task .dd-handle {
    min-height: 145px;
}
span.select2-container {
    z-index: 99999;
    width: 179px !important;
    margin-right: 5px;
}
.tbody_cls{
    vertical-align: top;
}
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;
}

button.add_person:hover, button.remove_person:hover, 
button.add_person:focus, button.remove_person:focus{
    background-color: #fff;
    color: #163339;
}
button.add_person{
    margin-bottom: 5px;
}
i.icofont-close-circled.ic {
    position: absolute;
    left: 5px;
    top: 5px;
    font-size: 20px;
    z-index: 999999;
    color: red;
    cursor: pointer;
}
li.dd-item:hover i.ic, li.dd-item:hover i.edit_task {
    display: block !important;
}
li.dd-item:hover .action-div {
    opacity: 1;
    visibility: visible;
    z-index: 999;
}
li.dd-item:hover {
    cursor: pointer !important;
}
ol.dd-list {
    display: flex;
    flex-wrap: wrap;
}
li.dd-item {
    width: calc(100% / 3 - 10px);
    margin: 5px !important;
    transition: all 0.5s;
}
select.form-select[readonly] + span {
    pointer-events: none;
    /* display: none; */
}
div#createtask table {
    width: 100%;
}
div#createtask .select2-container--default .select2-selection--single {
    height:40px;
    background-clip: padding-box;
    border: 1px solid #ced4da;
}
div#createtask span.select2-selection.select2-selection--single:hover {
    box-shadow: 0 0 10px rgb(33 37 41 / 15%);
    background-color: var(--card-color);
    border-color: var(--primary-color) !important;
    color: var(--text-color);
}
div#createtask span.select2-container {
    width: 280px !important;
    margin-right: 0px;
}
div#createtask table input {
    width: 280px;
    height: 40px;
    padding: 4px 9px 6px;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    outline: none;
}
div#createtask table input:focus{
    box-shadow: 0 0 10px rgb(33 37 41 / 15%);
    background-color: var(--card-color);
    border-color: var(--primary-color);
    color: var(--text-color);
}
div#createtask .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 35px;
    height:40px;
    padding-left: 10px;
}
div#createtask .select2-container--default .select2-selection--single .select2-selection__arrow b {
    margin-left: -6px;
    margin-top:4px;
}
div#createtask .deadline-form th {
    padding-bottom: 5px;
}

@media(max-width: 1024px){
.form-data .input-group {
    display: inline-grid;
}
}

@media(max-width: 991px){
li.dd-item {
    width: calc(100% / 2 - 10px);
    margin: 5px !important;
}
.form-data .input-group {
    margin: 0 10px;
}
.form-data input {
    max-width: 100%;
}
}

@media(max-width: 575px){
    li.dd-item {
    width: 100%;
    margin: 0px !important;
    }
}

@media (min-width: 576px){
    .modal-dialog{
        max-width: 900px;
    }
    
}
div#viewtask .deadline-form .project-sec {
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 10px !important;
    align-items: center;
}
div#viewtask .deadline-form .project-sec label.form-label {
    margin-bottom: 0;
    padding-right: 10px;
}
div#viewtask .deadline-form .task-table table {
    width: 100%;
    border: 1px solid #163339;
    padding: 10px;
    border-collapse: separate;
}

</style>
<?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>
<script src="<?= $site_url; ?>assets/plugin/nestable/jquery.nestable.js"></script>
<script src="<?= $site_url; ?>/js/page/task.js"></script>

<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('change', 'div.modal select[name="task_pro_name"]', function(){
        if($(this).val() == ''){
                $(this).closest("form").find("select[name='task_employe[]']").css("pointer-events", "none");
                $(this).closest("form").find("select[name='task_employe[]']").val('').change();
                $(this).closest("form").find("select[name='task_employe[]']").html('');
        } else {
            var proj_id = $(this).val();
            var targeted_model = ($(this).closest('.modal').attr('id') == 'createtask') ? 'createtask' : 'edit_task';
            $.ajax({
                url:window.location.pathname,
                type:"post",
                data:{get_project_info:proj_id},
                success:function(res){
                    
                        $("#"+targeted_model+" select[name='task_employe[]']").html($(res).find("#"+targeted_model).find("select[name='task_employe[]']").html());
                }
            });
            $(this).closest("form").find("select[name='task_employe[]']").css("pointer-events", "all");
        }
    });
$(document).on("click", ".create_task_btn", function(){
    if($('div#createtask[name="task_title"]').val() == ''){
        $('.create_task').click()

    } else if($('div#createtask select[name="task_pro_name"]').val() == '') {
        $('.create_task').click()

    } else if($('div#createtask select[name="task_employe[]"]').val().length == 0){
        alert("You musrt need to select Employee");
      } else {
        $('.create_task').click();

      }
});
 function apply_custom_filter(){
        var selected_proj = $(".project_filter").val();
        var selected_date = $('input[name="daterange"]').val();
       

        $(".spinner-border").show();
        $.ajax({
            type:"get",
            url:"?filter_proj="+selected_proj+"&filter_date="+selected_date,
            success:function(res){
                $(".spinner-border").hide();
                if(selected_proj != '' &&  selected_date != '') {
                    window.history.pushState('', '', "?filter_proj="+selected_proj+"&filter_date="+selected_date);
                    $(".clear_filter").show();
                } else if(selected_proj != '') {
                    window.history.pushState('', '', "?filter_proj="+selected_proj);
                    $(".clear_filter").show();
                } else if(selected_date != '') {
                    window.history.pushState('', '', "?filter_date="+selected_date);
                    $(".clear_filter").show();
                } else {
                    window.history.pushState('', '', window.location.pathname);
                    $(".clear_filter").hide();
                }
                if($('.manager_tbl').length){
                        $('.manager_tbl').html($(res).find('.manager_tbl').html());
                } else {
                    $('#myProjectTable').html($(res).find('#myProjectTable').html());
                     // Use $("#dailyNews").DataTable().destroy() for DataTables 1.10.x
                    $("#myProjectTable").dataTable().fnDestroy()

                    $("#myProjectTable").dataTable({});
                }

                if($(res).find(".load_more_btn").length){
                    $(".load_more_btn").show();
                }
                $(".dd-list").html($(res).find(".dd-list").html());
                 $(".spinner-border").hide();
            }
        });
    }
     $(document).on("click", ".clear_filter", function(){
        $(".spinner-border").show();
        $("input[name='daterange']").val("");
        $("select.project_filter").val("");
        //$("select.project_filter").change();
        $(this).hide();
        window.history.pushState('', '', window.location.pathname);
        window.location.href = window.location.pathname;

        $.get(window.location.pathname, function(res){
             $(".spinner-border").hide();
             $(".dd-list").html($(res).find(".dd-list").html());
            if($(res).find(".load_more_btn").length){
                $(".load_more_btn").show();
            }
            

        });
    });
    $('input[name="daterange"]').on('apply.daterangepicker', function(ev, picker) {
       apply_custom_filter();
    });
    var clone_tr = '';
    jQuery(window).bind("load", function(){
        clone_tr = jQuery(".tbody_cls tr")[0].outerHTML;
        $("tbody.tbody_cls select").select2({
            placeholder: "-- Select --",
        });
    });
    jQuery(document).on("click", ".add_person", function(){
        jQuery(".tbody_cls").append(clone_tr);
       $("tbody.tbody_cls select:not(.select2-hidden-accessible)").select2({
            placeholder: " -- Select -- ",
        });
    });
    jQuery(document).on("click", ".remove_person", function(){
        if(jQuery(".tbody_cls tr").length > 1){
            if(confirm("Are you sure?")){
                jQuery(this).closest("tr").remove();
            }
        }
            
    });
    jQuery(document).on("click", "li i.ic", function(e){
        e.preventDefault();
        
        if(confirm("All timelog related to this task will deleted. Are you sure?")){
            
            window.location.href = "?delete_task="+jQuery(this).attr('data-id');
        }
        
            
    });
    $(document).on("change", ".project_filter", function(){

        var selected_proj = $(this).val();
        
        //$(".spinner-border").show();
        apply_custom_filter();
        /*$.ajax({
            type:"get",
            url:"?filter_proj="+selected_proj,
            success:function(res){
                $(".spinner-border").hide();
                if(selected_proj != '') {
                    window.history.pushState('', '', "?filter_proj="+selected_proj);
                    
                } else {
                    window.history.pushState('', '', window.location.pathname);
                    
                }
                $(".dd-list").html($(res).find(".dd-list").html());
            }
        });*/

    });
    $(document).on("click", ".edit_task", function(){
        $('#edit_task').modal('show');
        var task_id = $(this).attr('data-id');
        $(".spinner-border").show();
        $.ajax({
            type:"get",
            url:"?edit_task="+task_id,
            success:function(res){
                $(".spinner-border").hide();
            
                $("#edit_task .form-data").html($(res).find("#edit_task").find(".form-data").html());
                $("#edit_task .form-data select").select2({
                    dropdownParent: $("#edit_task")
                });
            }
        });
    });
    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();
    });
    $(document).ready(function(){
        var start = moment().startOf('isoWeek');
        var end = moment().endOf('isoWeek');
        <?php
                if(isset($_GET['filter_date']) && !empty($_GET['filter_date'])){
                    $ex_date = explode(" - ", $_GET['filter_date']);
                    echo 'start = moment(new Date("'.$ex_date[0].'")); end = moment(new Date("'.$ex_date[1].'")); ';
                }
        ?>
       setTimeout(function(){
            <?php
                if(!isset($_GET['filter_date'])){
                     echo '$("input[name=\'daterange\']").val("");';
                }
                if(isset($_GET['filter_date']) && !empty($_GET['filter_date'])){
                    $ex_date = explode(" - ", $_GET['filter_date']);
                    echo 'apply_custom_filter(); start = "'.$ex_date[0].'"; end = "'.$ex_date[1].'"; ';
                } elseif(isset($_GET['filter_proj']) && !empty($_GET['filter_proj'])){
                    echo 'apply_custom_filter();';
                }else{
                    echo '$("input[name=\'daterange\']").val("");';
                }

            ?>
            },500);
         function cb(start, end) {
                //$(".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();
                        $(".dd-list").html($(res).find(".dd-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);
    });
    $(document).on("click",".progress_task li.dd-item", function(e){
        if(!$(e.target).hasClass('edit_task') && !$(e.target).hasClass('icofont-close-circled')){
            $(".spinner-border").show();
            var pass_task_id = $(this).attr("data-task-id");
            $.ajax({
                    type:"post",
                    url:window.location.pathname,
                    data:{pass_task_id:pass_task_id},
                    success: function(res){
                        $(".spinner-border").hide();
                        $('#viewtask').modal('show');
                        $('#viewtask').html($(res).find('#viewtask').html());
                        //console.log($(res).find("div#All-list").html());
                    }
                })
            
        }
      
    });
    
</script>