Saves and all the fields are blocked

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
lramirez
Veteran Member
Posts: 47
Joined: 2019-11-01 23:23

Saves and all the fields are blocked

Post by lramirez » 2023-09-25 22:02

Hello good morning.
I need help...
I would like to know if I can add a code "X"
so that when the user selects "status" OFF and saves, all the fields are blocked, and that he himself cannot unlock, but only the administrator can unlock.
Could this be done?
ON -
OFF (block)

Excuse my English...
Thank you so much
Attachments
employees.png
employees.png (12.85 KiB) Viewed 1668 times
Luis Ramirez R.

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

Re: Saves and all the fields are blocked

Post by pbottcher » 2023-10-01 19:07

Hi,

you could use the _footer hook (case 'detailview':) to check if the status = OFF and if the group of the user != Admins then disable all input fields.
There might be a bit more to do, but I hope this give you a starting point.
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.

lramirez
Veteran Member
Posts: 47
Joined: 2019-11-01 23:23

Re: Saves and all the fields are blocked

Post by lramirez » 2023-10-01 21:28

Ok, I'm going to do some tests.
Thank you
Luis Ramirez R.

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Saves and all the fields are blocked

Post by zibrahim » 2023-10-02 00:18

Hi Luis,
Just sharing what I am doing to achieve similar result.
The following code I put in "before update function" in hooks/TABLENAME.php (in my case, the file is hooks/purchase_order.php)

Code: Select all

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

	// ONLY allow users from selected group(s) to update purchase_order with Approved or Completed status
	$memberInfo = getMemberInfo();
	$authorized = array('Admins', 'Manager');
	if (!in_array($memberInfo['group'], $authorized)) {
		$id = $data['selectedID'];
		$status = sqlValue("SELECT `status` FROM `purchase_order` WHERE `id`='$id'");
		$string1 = 'Approved';
		$string2 = 'Completed';
		// if the record status is Approved or Completed, don't allow updating it
		if ($status == $string1 || $status == $string2) {
			$args['error_message'] = 'You are not authorized to make the changes to Approved or Completed PO.';
			return false;
		}
	}

	return TRUE;
}
with this code, only users from Admins and Manager groups can make changes to Approved or Completed purchase orders.
You can change the query, groups & strings values as per your requirement.
Hope this help.

Have a nice day.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

Post Reply