How i change Owner for Client ???

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

How i change Owner for Client ???

Post by xbox2007 » 2020-04-11 20:28

hello every one
i would like explain some things before i start post this topic
on AppGini there Are users and Group i understand this very well
lets say in my App there are three Group
1- Admin ( administrator )
2- Data Entry ( Add , edit , Delete data .........)
3- client / Customer ( he only should see has record and cant change or add or Delete ) i decide to apple GROUP ID NO 5

i want client / Customer can see has record only
How i can make that
i know how i can change owner by use ( change owner ) in table

but i like make every thing work automatically without Data Entry user or Admin do anyhing

with my little information i do some steps but i need help from professional people .
i do like this
1- i create new Group in my App name ( client ) without add any user
2- Manual change Group ID to 5 on membership_groups
3- give Client on Table permissions for this group to view only owner and not allow to edit or delete
4- was create table for client ( client table ) have information for client i add for him basic information and add User name , password ...
5- once i add new client on ( client table ) will add new information to membership_users ( user name , password , group , approve and ID )
i make this Query after insert function in hooks

Code: Select all

function cust_before_update(&$data, $memberInfo, &$args) {
		
	$CustomerID	= $data["selectedID"];
	$memberID	= $data['UserName'];
	$password	        = $data['Password'];
	$email		= $data['Email'];
	$Name		= $data['MoklNm'];

	$member =sqlValue("select COUNT(*) from membership_users where memberID='{$memberID}'");  
	if($member == 0) {
	sql("INSERT INTO `membership_users` set memberID='{$memberID}', passMD5='" . password_hash($password, PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID = 5, isBanned= 0, isApproved= 1 , custom1='{$Name}' , custom3='{$CustomerID}'", $eo);
	}	
	sql("UPDATE membership_userrecords SET memberID ='{$memberID}', groupID= 5 WHERE tableName='cust' AND pkValue='{$data['selectedID']}'", $eo);
	return TRUE;
	}
now i have client in client group , he can only see own records

if he login he will not see any things ( he can see only has information in client table )

like that everything is ok

now how i can change owner for client
i try many time to add query to change owner for him , to add query in table hooks after_insert but not working
its work only after_update , i already know why ,

Code: Select all

sql("UPDATE membership_userrecords SET memberID ='{$memberID}', groupID= 5 WHERE tableName='files'  AND pkValue='{$files_id}'", $eo);
i make to with Ajax , i add button on table and when press on will change owner for client like this

Code: Select all

sql("UPDATE membership_userrecords SET memberID ='{$memberID}', groupID= 5 WHERE tableName='files'  AND pkValue='{$files_id}'", $eo);
but this is manual Action
i make some change on xcxcxcx_dml.php file ----- Where xcxcxcx is table name

Code: Select all

// mm: save ownership data
	$memberID	= $data['Name'];
	$member =sqlValue("select memberID from membership_users where custom3='{$memberID}'");
	set_record_owner('xcxcxcx', $recID, $member);
now its work fine , ,,,, i want professional people to take look and let me know if there are any other way

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: How i change Owner for Client ???

Post by onoehring » 2020-04-12 07:35

Hi,

why don't you add another field to the table which can hold the owner? This could be a lookup field. Then, once your data entry person clicks the save button you set the new owner (which can be read from the new field).
To do this, utilize the hooks/tablname.php -> _after_insert function and return FALSE - as you set the owner yourself.

Olaf

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: How i change Owner for Client ???

Post by xbox2007 » 2020-04-12 12:54

hello , thanks a lot for your information

i was try code like this

Code: Select all

	function xcxcxcx_after_insert($data, $memberInfo, &$args) {
		$memberID	= $data['Name'];
		$member =sqlValue("select memberID from membership_users where custom3='{$memberID}'");
		set_record_owner('xcxcxcx', $recID, $member);
	return false;
	}
but its give me this result ( Not Add row but pKValue is NUll )
11.png
11.png (11.06 KiB) Viewed 2275 times
i change code like this :

Code: Select all

function xcxcxcx_after_insert($data, $memberInfo, &$args) {

	$memberID	= $data['Name'];
	$ID 		= $data["selectedID"];
	
	$member =sqlValue("select memberID from membership_users where custom3='{$memberID}'");
	set_record_owner('xcxcxcx', $ID, $member);
		return false;
	}
its Work fine ,, Thanks a lot

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: How i change Owner for Client ???

Post by onoehring » 2020-04-12 13:27

Hi

great to hear that it works. The images are a good help to understand what you want to to.
Take care and stay healthy
Olaf

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: How i change Owner for Client ???

Post by xbox2007 » 2020-04-12 16:21

thanks a lot

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: How i change Owner for Client ???

Post by pbottcher » 2020-04-12 17:54

Hi,

that sounds great.

Just to give a hint for the next question. If you would have provided the information that you have a field with the name of the member that you want to assign the ownership for the created record, this would have solved a lot of questions, and actually has nothing to do with the save as copy function.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Post Reply