- Ajout système complet de gestion des secteurs avec contours géographiques - Import des contours départementaux depuis GeoJSON - API REST pour la gestion des secteurs (/api/sectors) - Service de géolocalisation pour déterminer les secteurs - Migration base de données avec tables x_departements_contours et sectors_adresses - Interface Flutter pour visualisation et gestion des secteurs - Ajout thème sombre dans l'application - Corrections diverses et optimisations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
98 lines
3.1 KiB
PHP
Executable File
98 lines
3.1 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
class ClientDetector {
|
|
/**
|
|
* Détecte le type de client basé sur l'User-Agent
|
|
*
|
|
* @return string 'mobile', 'web' ou 'unknown'
|
|
*/
|
|
public static function getClientType(): string {
|
|
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
|
|
|
|
// Détection des applications mobiles natives
|
|
if (preg_match('/(Android|iOS)\/[0-9\.]+\s+\w+\/[0-9\.]+/', $userAgent)) {
|
|
return 'mobile';
|
|
}
|
|
|
|
// Détection des navigateurs mobiles
|
|
if (preg_match('/(Android|iPhone|iPad|iPod|Windows Phone)/i', $userAgent)) {
|
|
return 'mobile';
|
|
}
|
|
|
|
// Détection des navigateurs web
|
|
if (preg_match('/(Mozilla|Chrome|Safari|Firefox|Edge|MSIE|Trident)/i', $userAgent)) {
|
|
return 'web';
|
|
}
|
|
|
|
return 'unknown';
|
|
}
|
|
|
|
/**
|
|
* Récupère l'identifiant de l'application mobile depuis l'User-Agent
|
|
* Format attendu: AppName/VersionNumber (Platform/Version)
|
|
*
|
|
* @return string Identifiant de l'application ou 'unknown'
|
|
*/
|
|
public static function getAppIdentifier(): string {
|
|
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
|
|
|
|
// Extraction de l'identifiant de l'application
|
|
if (preg_match('/^([A-Za-z0-9_]+)\/[0-9\.]+/', $userAgent, $matches)) {
|
|
return $matches[1];
|
|
}
|
|
|
|
// Extraction depuis un format alternatif
|
|
if (preg_match('/\b(GeoSector|Prokov|Resalice)\/[0-9\.]+\b/i', $userAgent, $matches)) {
|
|
return $matches[1];
|
|
}
|
|
|
|
return 'unknown';
|
|
}
|
|
|
|
/**
|
|
* Récupère des informations détaillées sur le client
|
|
*
|
|
* @return array Informations sur le client
|
|
*/
|
|
public static function getClientInfo(): array {
|
|
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
|
|
|
|
// Information par défaut
|
|
$clientInfo = [
|
|
'type' => self::getClientType(),
|
|
'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown',
|
|
'userAgent' => $userAgent,
|
|
'browser' => [
|
|
'name' => 'unknown',
|
|
'version' => 'unknown'
|
|
],
|
|
'os' => [
|
|
'name' => 'unknown',
|
|
'version' => 'unknown'
|
|
]
|
|
];
|
|
|
|
// Détection du navigateur
|
|
if (preg_match('/(Chrome|Safari|Firefox|Edge|MSIE|Trident)[\s\/]([0-9\.]+)/i', $userAgent, $matches)) {
|
|
$clientInfo['browser']['name'] = $matches[1];
|
|
$clientInfo['browser']['version'] = $matches[2];
|
|
}
|
|
|
|
// Détection du système d'exploitation
|
|
if (preg_match('/(Android|iOS|iPhone OS|iPad|iPod|Windows NT|Mac OS X|Linux)[\s\/]([0-9\._]+)/i', $userAgent, $matches)) {
|
|
$clientInfo['os']['name'] = $matches[1];
|
|
$clientInfo['os']['version'] = $matches[2];
|
|
}
|
|
|
|
// Si c'est une application mobile, ajouter l'identifiant
|
|
if ($clientInfo['type'] === 'mobile') {
|
|
$clientInfo['appIdentifier'] = self::getAppIdentifier();
|
|
}
|
|
|
|
return $clientInfo;
|
|
}
|
|
}
|