What is wrong with this hook code.
<?php
use WHMCS\Database\Capsule;
add_hook('AdminAreaHeadOutput', 1, function($vars) {
// Replace 3 with the ID of the admin user you want to restrict
$adminUserId = 3;
$productGroupId = 2;
$clientGroupId = 1;
$currentAdminUser = Capsule::table('tbladmins')->find($adminUserId);
if ($currentAdminUser) {
$loggedInAdminUserId = $_SESSION['adminid'];
if ($adminUserId == $loggedInAdminUserId) {
add_hook('AdminProductsServices', 1, function($vars) use ($productGroupId) {
$productsServices = Capsule::table('tblproducts')
->join('tblproductgroups', 'tblproducts.gid', '=', 'tblproductgroups.id')
->where('tblproductgroups.id', $productGroupId)
->select('tblproducts.*')
->get();
$productsServicesIds = array();
foreach ($productsServices as $productService) {
$productsServicesIds[] = $productService->id;
}
foreach ($vars['products'] as $key => $product) {
if (!in_array($product['id'], $productsServicesIds)) {
unset($vars['products'][$key]);
}
}
return $vars;
});
add_hook('AdminClientsSearch', 1, function($vars) use ($clientGroupId) {
$clients = Capsule::table('tblclients')
->join('tblclientgroups', 'tblclients.groupid', '=', 'tblclientgroups.id')
->where('tblclientgroups.id', $clientGroupId)
->select('tblclients.*')
->get();
$clientsIds = array();
foreach ($clients as $client) {
$clientsIds[] = $client->id;
}
foreach ($vars['results'] as $key => $result) {
if (!in_array($result['id'], $clientsIds)) {
unset($vars['results'][$key]);
}
}
return $vars;
});
}
}
});
I want to restrict one admin user to see only products/services that belong to specific product group on the dashboard. I don't want them to see other product details that are in different groups. The same with clients, I want the admin user be able to see only details of clients that have specific client group, I don't want for them to display in client list those clients who don't have any group or different one. They shouldn"t be able also to search clients and products that they are not allowed to view.
It doesn't work, my IDs are correct, when I login as admin with id 3 they can still see all clients and products.