<?php
function getContactMap(){
static $cachedMap=null;
if($cachedMap!==null)return $cachedMap;
$contactDir=ABSPATH.'data/contacts/';
$currentUser=$_SESSION['user']??'';
$map=[];$files=[];
$publicFile=$contactDir.'public.json';
if(file_exists($publicFile))$files[]=$publicFile;
if($currentUser){
$safeUser=preg_replace('/[^a-zA-Z0-9_\-]/','',$currentUser);
$privateFile=$contactDir."user_{$safeUser}.json";
if(file_exists($privateFile))$files[]=$privateFile;
}
foreach($files as $file){
$data=loadMeta($file);
if(!is_array($data))continue;
foreach($data as $c){
if(isset($c['fax'],$c['name'])){$cleanFax=preg_replace('/[^0-9]/','',$c['fax']);if($cleanFax)$map[$cleanFax]=$c['name'];}
}}
return $cachedMap=$map;
}
function resolveContactName($faxNumber,$contactMap){
if(empty($faxNumber))return'';
$cleanNum=preg_replace('/[^0-9]/','',$faxNumber);
return $contactMap[$cleanNum]??$faxNumber;
}
?>
