false,'message'=>'POST required.']);exit;} try { include_once './Home_include.php'; require_once __DIR__.'/PA_SHOP_RECOVERY_REQUEST.php'; require_once __DIR__.'/PA_CLIENT_CONTACT_DETAILS.php'; $admin=PAShopRecoveryRequest::admin($PAAPP_CONFIG_DB_LINK,$_COOKIE['PHPSESSID']??null,$_POST['DUMMYSESSID']??null,$_SERVER['REMOTE_ADDR']??null); if(session_status()!==PHP_SESSION_ACTIVE||session_id()!==($_COOKIE['PHPSESSID']??null))throw new InvalidArgumentException('Please sign in again.'); foreach(['clientId','deviceId','contactId'] as $field)if(!is_string($_POST[$field]??null)||!preg_match('/^[1-9][0-9]{0,9}$/D',$_POST[$field]))throw new InvalidArgumentException('Invalid contact selection.'); $client=(int)$_POST['clientId'];$device=(int)$_POST['deviceId'];$contact=(int)$_POST['contactId']; if(($_POST['action']??'')==='prepare')$result=PAAdminContactDetails::prepare($PAAPP_CONFIG_DB_LINK,$_SESSION,$admin,$client,$device,$contact); elseif(($_POST['action']??'')==='save') { if(!is_string($_POST['changes']??null)||strlen($_POST['changes'])>1000)throw new InvalidArgumentException('Invalid contact changes.'); $changes=json_decode($_POST['changes'],true,16,JSON_THROW_ON_ERROR); if(!is_array($changes))throw new InvalidArgumentException('Invalid contact changes.'); $result=PAAdminContactDetails::save($PAAPP_CONFIG_DB_LINK,$_SESSION,$admin,$client,$device,$contact,$_POST['token']??null,$changes); error_log('PA contact details updated | AdminID='.$admin.' | ClientID='.$client.' | ClientContactsID='.$contact); }else throw new InvalidArgumentException('Invalid operation.'); echo json_encode(['status'=>true,'data'=>$result]); }catch(Throwable $e){ http_response_code(400); echo json_encode(['status'=>false,'message'=>$e instanceof InvalidArgumentException?$e->getMessage():'Contact details could not be saved. Refresh and try again.']); }