get the id_user from dadabik_users

JtheBAB

New member
Hi

I am currently building a HR database with dadabik. In the HR database every person is registered and gets a person_id.

Now i want to build on top of it an absence database. As the users should only see his absences i use the ID_user form field. "Unfortunate" it looks like it is only possible to save the username with this field and not the id.

As i need to connect the absence with the person_id it came to my mind to use a calculated field to fetch with the username the person_id and add this to the forgein key field.

Code:

PHP:
function dadabik_fill_person_id ($params){
   global $conn;

    // get the name from the ID
    $sql = "SELECT id_user FROM dadabik_absence_users WHERE username_user = :username_user";

    $res_prepare = prepare_db($conn, $sql);

    $res_bind = bind_param_db($res_prepare, ':username_user', $absence_created_by);

    $res = execute_prepared_db($res_prepare,0);

    $row = fetch_row_db($res_prepare);

        return $row['id_user'];
}

I guess i made something wrong as the field isn't filled with something.

Two questions:

- Is there a way to debug and see what the function actually really does?
- What is wrong with my code?

Thanks

---------------
Your current DaDaBIK version

You are using DaDaBIK version 11.7-Elba platinum, installed on 25.10.2022 (installation code: 183606357f1db7e961), the latest version of DaDaBIK is 11.7-Elba released on 18.08.2022

You are running the latest release of DaDaBIK

In case you want to upgrade to a more powerful edition (from Pro to Enterprise/Platinum, from Enterprise to Platinum) please contact us.
System info

PHP Version: 7.4.30

mysql version: 5.7.39

Web server: Apache

Client: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0
--------------------
 

JtheBAB

New member
So i am a bit further.

It looks like the field "absence_created_by" (with the formtype "ID_user") is not available in the params array. So $params['absence_created_by'] is just empty. As a test i used another field that was can be filled by the user and that exist in the $params.

Why?
 

eugenio

Administrator
Staff member
Hello,
$params only contains the values coming from the form, I guess that field is not in the insert form (and it shouldn't, since it is a ID_user field).
You can easily get the id_user of the current logged in user using the global variable $current_id_user

Best,
 

JtheBAB

New member
Hi

I guess i make something wrong as this:

PHP:
function dadabik_fill_person_id ($params)
{
        return $current_id_user;
}

just enter NULL to the field. When i enter a number directly in the code like

return "12";

i get something so the function is being executed.
 
Top