<?php

function get_user_project_access_inquiry($project_id, $user_id, $dag_id) {
    $sql = "SELECT da.value_name data_acc_group_name,
                pm.description project_name,
                pm.project_id,
                u.user_id, u.real_name, u.inactive  
            FROM ".TB_PREF."user_data_access_groups udg  
                JOIN ".TB_PREF."projects_master pm  
                    ON udg.dag_id = pm.dag_id  
                JOIN ".TB_PREF."list_values da  
                    ON udg.dag_id = da.id 
                JOIN ".TB_PREF."users u 
                    ON u.id = udg.user_id 
                   
            WHERE 1 = 1 ";
    
        if ($project_id > 0){
            $sql .= " AND pm.project_id = ".db_escape($project_id);
        }
        if($user_id > 0){
            $sql .= " AND udg.user_id = ".db_escape($user_id);
        }
        if($dag_id > 0){
            $sql .= " AND pm.dag_id = ".db_escape($dag_id);
        }
        
        $sql .= " ORDER BY pm.description, u.inactive, u.real_name";
        
    return db_query($sql, "get_user_project_access_inquiry");
}

?>