Page 1 of 1

Saves and all the fields are blocked

Posted: 2023-09-25 22:02
by lramirez
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

Re: Saves and all the fields are blocked

Posted: 2023-10-01 19:07
by pbottcher
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.

Re: Saves and all the fields are blocked

Posted: 2023-10-01 21:28
by lramirez
Ok, I'm going to do some tests.
Thank you

Re: Saves and all the fields are blocked

Posted: 2023-10-02 00:18
by zibrahim
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.