<?php
require_once "../config.php";


if(isset($_GET['currentPageName'])){

    $curr_page = $_GET['currentPageName'];
    $curr_query = $_GET['current_query'];

    // if($curr_page=='all_users'){
    //     $ids = mysqli_fetch_all(mysqli_query($db, "SELECT * FROM ($curr_query) sub_table"), MYSQLI_ASSOC);
    //     $all_ids = array_column($ids, 'employee_id');
    //     echo json_encode($all_ids);
    // }else if($curr_page=='all_salary'){
    //     $ids = mysqli_fetch_all(mysqli_query($db, "SELECT * FROM ($curr_query) sub_table"), MYSQLI_ASSOC);
    //     $all_ids = array_column($ids, 'employee_id');
    //     echo json_encode($all_ids);
    // }else 
    if($curr_page=='all_password'){
        if($_SESSION['user_role']==0){
            $ids = mysqli_fetch_all(mysqli_query($db, "SELECT * FROM ($curr_query) sub_table"), MYSQLI_ASSOC);
        }else{
            $ids = mysqli_fetch_all(mysqli_query($db,"SELECT * FROM ($curr_query) sub_table where l_eid='$_SESSION[emp_id]' ORDER BY id DESC"), MYSQLI_ASSOC);
        }
        $all_ids = array_column($ids, 'id');
        echo json_encode($all_ids);
    }else if($curr_page=='raw_attendance'){
        $ids = mysqli_fetch_all(mysqli_query($db, "SELECT * FROM ($curr_query) sub_table"), MYSQLI_ASSOC);
        $all_ids = array_column($ids, 'id');
        echo json_encode($all_ids);
    }else{
        $ids = mysqli_fetch_all(mysqli_query($db, "SELECT * FROM ($curr_query) sub_table"), MYSQLI_ASSOC);
        $all_ids = array_column($ids, 'employee_id');
        echo json_encode($all_ids);
    }

}

?>