This is what I changed it to - and it appears to work with all functionality of the grid (not finished testing)
OnApplicationInit:
//select ALL locations a person is at
$arr_rows = array();
sc_select(rs, “SELECT loc_id FROM location_people WHERE user_id = [usr_id]”);
while(!$rs->EOF)
{
$arr_rows[] = $rs->fields[0];
$rs->MoveNext();
}
$rs->Close();
//print_r($arr_rows) ;
[locations] = implode (", ", $arr_rows);
OnScriptInit:
//20200710:bh Restrict view of client
// - client location is set on login
$check_table = ‘location’; // Table name
$check_where = “id = ‘[locations]’ AND is_owner = ‘N’”; // Where clause
// Check for record
$check_sql = ‘SELECT *’
. ’ FROM ’ . $check_table
. ’ WHERE ’ . $check_where;
sc_select(dataset, $check_sql);
if (false == {dataset})
{
// Error while accessing database
}
elseif ({dataset}->EOF)
{
//No record found - this is an employee - show all records
$is_employee = ‘Y’ ;
}
else
{
// Record found - this is a client - restrict view to client location
$is_employee = ‘N’ ;
}
if ($is_employee == ‘Y’)
{
// Hide private records
if([usr_priv_private] == 'Y')
{
sc_field_display({private}, 'on');
sc_btn_display('run_private_change', 'on') ;
} else {
sc_select_where(add) = " AND private = 'N' ";
sc_field_display({private}, 'off') ;
sc_btn_display('run_private_change', 'off') ;
}
}
else
{
//Hide private records
//Show items at user location only
if([usr_priv_private] == ‘Y’)
{
sc_select_where(add) = " AND loc_id IN ([locations])" ;
sc_field_display({private}, ‘on’);
sc_btn_display(‘run_private_change’, ‘on’) ;
} else {
sc_select_where(add) = " AND loc_id IN ([locations]) AND private = ‘N’" ;
sc_field_display({private}, ‘off’) ;
sc_btn_display(‘run_private_change’, ‘off’) ;
}
//client cannot add or edit
sc_btn_display(‘new’, ‘off’) ;
sc_apl_conf (“grid_asset”, “lig_edit”, “off”);
}
Modified the SQL to include a where statement:
SELECT
id,
name,
loc_id,
description,
category,
in_service
FROM
asset
WHERE trash = ‘N’