Page 1 of 1

Hide records for a group if a checbox field is unchecked

Posted: 2021-12-27 23:40
by fgazza
Hi everyone.
I would need some expert help to solve this problem:

In a "calendar" table I have a checkbox field named "active".
I have set up a "phone_operator" group that can see all records in the "calendar" table (but cannot edit them).

Now I would like to take a step forward:

Hide from the members of the "phone_operator" group, both in the table view and in the detail and print view, all the records where the "active" checkbox field is NOT checked.

I have no idea how to code!

Thanks for your help!

Fabiano

Re: Hide records for a group if a checbox field is unchecked

Posted: 2021-12-28 10:37
by pbottcher
Hi Fabiano,

in order to acheive this you need to edit the _init hook and the _dv hook.

Within the _init hook you can modify the query to select only record that have the the checkbox checked.

Something like

Code: Select all

		if ($memberInfo['group'] == "phone_operator") {
			$options->QueryWhere .= ($options->QueryWhere ? " AND " : " WHERE ") . "active=1";
		}
In the _dv hook you need to check if the caller is a member of the group and if the record he is calling has the correct value, otherwise send him back to the tableview.
Somewhat something like:

Code: Select all

		if ($memberInfo['group'] == "phone_operator") {
			$record=get_joined_record('calendar',$selectedID);
			if (empty($record['active'])) {
				redirect('calendar_view.php');
				exit;
			}
		}

Re: Hide records for a group if a checbox field is unchecked

Posted: 2021-12-28 14:45
by pbottcher
Hi,

just to correct the last entry.

please try for the _dv hook:

Code: Select all

		if ($memberInfo['group'] == "phone_operator" && $selectedID) {
			$record=get_joined_record('calendar',$selectedID);
			if (empty($record['active'])) {
				redirect('calendar_view.php');
				exit;
			}
		}