prepare('SELECT COUNT(*) FROM Admin WHERE AdminID=? AND RecordStatus=0 AND LoginAccess>=0');$q->execute([$admin]); if((int)$q->fetchColumn()!==1)throw new RuntimeException('Admin access is unavailable.'); if(($gate['AllowAllActiveAdmins']??false)!==true&&!in_array($admin,$gate['AllowedAdminIDs']??[],true))throw new RuntimeException('This Admin is not authorized.'); $gate['AllowedAdminIDs']=[$admin]; if($client!==null){ $q=$db->prepare('SELECT COUNT(*) FROM Client WHERE ClientID=? AND RecordStatus=1');$q->execute([$client]); if((int)$q->fetchColumn()!==1||(($gate['AllowAllClients']??false)!==true&&!in_array($client,$gate['AllowedClientIDs']??[],true)))throw new RuntimeException('Customer requires review or is outside the rollout.'); $gate['AllowedClientIDs']=[$client]; } return $gate; } public static function subscription(PDO $db,array $config,string $name,int $admin,int $id): array { $q=$db->prepare("SELECT ClientID FROM ClientDeviceTransaction WHERE OrderID=? AND TransactionType='subscription'");$q->execute([$id]);$clients=$q->fetchAll(PDO::FETCH_COLUMN); if(count($clients)!==1)throw new RuntimeException('Subscription device link requires review.'); return self::resolve($db,$config,$name,$admin,(int)$clients[0]); } }