Assign record to other user

9 posts by 3 authors in: Forums > CMS Builder
Last Post: June 14   (RSS)

By andreasml - June 5


I use CSMB to record medical records. Various users have access to their personal data only by using their own username/password to login and by having "Author" privileges. Thus, each user logs in, inserts data of his/her patients and he/she is the only user that can have access (modify, delete etc) to these data.

I wonder whether it was possible to let a user, inserting data of a patient and assign them to another user. For example, I would like the user A to log in as Author, create a record and then assign this record to user B. From now on, this record would be seen only by user B and not user A. 

I suspect that a way to solve it could be if user A was able to change the "Created by" field on the top of each record, in this case to user B. Thus, this new patient's record would be visible (and editable) by the user B only. Unfortunately, this is not allowed to be done by a user who has access privileges as an "Author". I wonder whether it would be possible to leave this "Created by" field free to be changed by those who have "Author" privileges apart from those who have "Editor" privileges.

Of course I am free of any other way to get around this issue.

Kind regards and thank you for your great support.

Andreas Lazaris 

By pgplast - June 6

This can be done with a simple plugin.

First you include a user list in your section (e.g. 'new_owner') that pulls the nums and names of all your users from your accounts.

When the person creates a new section record, he selects from this list the person to whom he wishes the ownership re-assigned.

On save of the record, a 'post_save' plugin then captures the record number of the section record and the 'new_owner' value and updates the value of createByUseNum  (only if a value for 'new_owner' has been saved).

By andreasml - June 7


Thank you for your reply. 

On save of the record, a 'post_save' plugin then captures the record number of the section record and the 'new_owner' value and updates the value of createByUseNum  (only if a value for 'new_owner' has been saved).

How can I create this? Could you please give an example?



By andreasml - June 8


Many thanks for you kind answer. 

Unfortunately, I did not make it work.

Although, i insert the name of the owner (from the drop-down menu list), after saving the record, the owner and the updater of the record remain unchanged (there are still the original owners). I will have another look when I find some time and let you know for sure. Just a small clarification: if I need to have the same property to more than one sections what should I do? Just add the new section's name or something else? (see the following exam)


$query = "UPDATE infected_grafts, aortic_aneurysm_disease, carotid_disease SET


Kind regards, 


By pgplast - June 9

Yes, sorry.

First, add a checkbox field to your section called 'assign_new_owner.'

(Leave the default as 0 (false).)

Before saving a record, check the 'assign_new_owner.' checkbox and select a new owner from the list.

When the record is saved, the ownership will be changed and the 'assign_new_owner.' and 'new_owner' valses will be resret so another save of the record will have no effect.

Use the plugin code below

This works fine on my server.

Plugin Name: Reassign record ownership
Description: Plugin file: new_record_owner.php, table: 'test_update_owner'
Version: #####
Requires at least: 3.0

addAction('record_postsave', 'new_record_owner', null, 2);

function new_record_owner($tableName,$recordNum) {

if($tableName!="test_update_owner") {

if (@$_REQUEST['assign_new_owner'] && @$_REQUEST['new_owner']) {

$new_owner_num = $_REQUEST['new_owner'];
$record_num = $_REQUEST['num'];



$query = "UPDATE cmsb_test_update_owner SET

assign_new_owner = '0',
new_owner = NULL,
updatedDate = NOW(),
createdByUserNum = '".$new_owner_num."',
updatedByUserNum = '".$new_owner_num."'
WHERE num = '".mysql_escape( $record_num )."'";
mysqli()->query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysqli()->error) . "\n");

}// end if

}// end function

By andreasml - June 9


Thanks again!! It seems to work for me also (with some very mild modifications). I will let you know in more detail as long as I try it a bit more.

Kind regards,


By andreasml - June 10


It does work!! 

I wonder if there is a way to apply this to more than one sections, or you need to create a different plugin for every different section. 

Again, thanks for your assistance, 

Kind regards, 


By daniel - June 14

Hey Andreas,

Glad you were able to get this sorted out!

In regards to getting it working for different sections, the key is the "$tableName" variable and this portion of the code:

if($tableName!="test_update_owner") {

As it stands, this checks the current section and halts if it's not "test_update_owner" - it could be modified to permit multiple sections:

if($tableName!="test_update_owner" && $tableName != "other_permitted_table") {

It could also be updated to take different actions depending on the section with some moderate modifications:

if($tableName == "test_update_owner") {

 // run code here

} elseif ($tableName == "other_permitted_table") {

 // run alternate code here


Hope that helps!

Technical Lead