Add Update User item

abraun

Member
I would like to be able to do a last update user in a table. I think it would be beneficial to have a new dropdown menu appear when you select ID_user in field type to be able to select between insert or update as there are situations when I want to track the insert user as well as who last updated the record.
 
Upvote 1

eugenio

Administrator
Staff member
Hi,
you already have the insert_date_time field type if I correctly understood what you mean.
 

abraun

Member
If a record exists and I have a column called Update User, I would like to store the username of the person who last updated the record.

You already have insert_datetime and update_datetime.

I would like to have insert_user and update_user (you already have insert_user with ID_user).
 

eugenio

Administrator
Staff member
Ok sorry I did not get it, yes a sort of ID_user_last_update would be useful, I upvote this.
With minimum coding, you can however fill your "last update user" field using an after update hook.
 

dolhaps2000

New member
maybe you can add it also to the forms configuration on field type as Update_User_id. maybe on your next update.

function dadabik_update_user($id) {
global $conn;
// Get the current user's username directly from the session
$username = $_SESSION['logged_user_infos_ar']['username_user'];
// Update the Encodedby field in the Vehicle_Entry table with the username
$sql_update = "UPDATE Vehicle_Entry SET Encodedby = :username WHERE id = :id";
$res_prepare_update = prepare_db($conn, $sql_update);
bind_param_db($res_prepare_update, ':username', $username);
bind_param_db($res_prepare_update, ':id', $id);
execute_prepared_db($res_prepare_update, 0);
}


i have problem i don't know how to make like multiple tables but should same function.
 

deep64blue

DaDaBIK Guru
Here's how I do it:-


PHP:
$hooks['note']['update']['after'] = 'dadabik_note_updated';

function dadabik_note_updated($id_account)
{
    global $conn;
    $username = $_SESSION['logged_user_infos_ar']['username_user'];
    $sql = "UPDATE note
            SET lastupdated_note = NOW(), lastupdatedby = :username
            WHERE id_note = :id_account";

    // Prepare statement
    $res_prepare = prepare_db($conn, $sql);

    // Bind parameters
    $res_bind_user = bind_param_db($res_prepare, ':username', $username);
    $res_bind_id = bind_param_db($res_prepare, ':id_account', $id_account);

    // Execute prepared statement
    $res = execute_prepared_db($res_prepare, 0);
    
}
 

dolhaps2000

New member
Here's how I do it:-


PHP:
$hooks['note']['update']['after'] = 'dadabik_note_updated';

function dadabik_note_updated($id_account)
{
    global $conn;
    $username = $_SESSION['logged_user_infos_ar']['username_user'];
    $sql = "UPDATE note
            SET lastupdated_note = NOW(), lastupdatedby = :username
            WHERE id_note = :id_account";

    // Prepare statement
    $res_prepare = prepare_db($conn, $sql);

    // Bind parameters
    $res_bind_user = bind_param_db($res_prepare, ':username', $username);
    $res_bind_id = bind_param_db($res_prepare, ':id_account', $id_account);

    // Execute prepared statement
    $res = execute_prepared_db($res_prepare, 0);
   
}

Thank you, and noted on this. :)
 
Top