<?php
declare(strict_types=1);
ini_set('display_errors','0');header('Cache-Control: private, no-store, max-age=0');header('Content-Type: application/json; charset=UTF-8');header('X-Content-Type-Options: nosniff');require_once __DIR__.'/../../includes/console_shell.php';require_login();require_acl('can_view','reports/attendance/gatepass-pending-for-approval.php');require_once __DIR__.'/gatepass-pending-for-approval-common.php';
try{$query=trim((string)($_GET['query']??''));if(mb_strlen($query)<2){echo json_encode(['suggestions'=>[]]);exit;}$scope=gpa_scope($con);$types='s';$params=['%'.$query.'%'];$where=['LOWER(e.name) LIKE LOWER(?)','e.status IN (0,1)'];$where=array_merge($where,gpa_employee_where($scope,$types,$params));$rows=dal_rows($con,'SELECT DISTINCT e.id,e.name,e.payroll_location FROM jos_app_employee e WHERE '.implode(' AND ',$where).' ORDER BY e.name,e.id LIMIT 20',$types,$params);$suggestions=[];foreach($rows as$r)$suggestions[]=['value'=>$r['name'],'data'=>(int)$r['id'],'orgid'=>(int)$r['payroll_location']];echo json_encode(['suggestions'=>$suggestions],JSON_UNESCAPED_UNICODE);}catch(Throwable $e){http_response_code(500);echo json_encode(['suggestions'=>[]]);}
