query('SELECT id, country_id, mcc, mnc, brand FROM operators ORDER BY brand')->fetchAll(PDO::FETCH_ASSOC); $successMessage = null; $errorMessage = null; function composeLocationDesc(string $tech, ?string $enb, ?string $band, ?string $frequency, $azimuth, ?string $bandwidth, string $address): string { $techLabel = ['2G' => 'GSM', '3G' => 'UMTS', '4G' => 'LTE', '5G' => 'NR', 'CDMA' => 'CDMA'][$tech] ?? $tech; $segments = []; if ($enb !== null && $enb !== '') { $segments[] = "eNB ID $enb"; } $radioLine = trim($techLabel . ' ' . ($band ?? '') . ' ' . ($frequency ?? '')); if ($radioLine !== $techLabel) { $segments[] = $radioLine; } if ($azimuth !== null && $azimuth !== '') { $segments[] = $azimuth . '°'; } if ($bandwidth !== null && $bandwidth !== '') { $segments[] = $bandwidth; } if ($address !== '') { $segments[] = $address; } return implode(' - ', $segments); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { require_csrf_token(); $operatorId = (int)($_POST['operator_id'] ?? 0); $lat = (float)($_POST['lat'] ?? 0); $lon = (float)($_POST['lon'] ?? 0); $addressDesc = trim($_POST['address_desc'] ?? ''); $batchLabel = trim($_POST['batch_label'] ?? ('Saisie manuelle - ' . $addressDesc)); $techs = $_POST['cell_tech'] ?? []; $cellIds = $_POST['cell_id'] ?? []; $areaCodes = $_POST['cell_area_code'] ?? []; $subIds = $_POST['cell_sub_id'] ?? []; $subIds2 = $_POST['cell_sub_id2'] ?? []; $arfcns = $_POST['cell_arfcn'] ?? []; $bands = $_POST['cell_band'] ?? []; $frequencies = $_POST['cell_frequency'] ?? []; $azimuths = $_POST['cell_azimuth'] ?? []; $bandwidths = $_POST['cell_bandwidth'] ?? []; if (!$operatorId || !$lat || !$lon || empty($techs)) { $errorMessage = "Operateur, coordonnees et au moins une cellule sont obligatoires."; } else { $opStmt = $db->prepare('SELECT mcc, mnc FROM operators WHERE id = ?'); $opStmt->execute([$operatorId]); $op = $opStmt->fetch(PDO::FETCH_ASSOC); if (!$op) { $errorMessage = "Operateur invalide."; } else { $db->beginTransaction(); try { $batchStmt = $db->prepare('INSERT INTO staging_batches (label, created_by) VALUES (?, ?)'); $batchStmt->execute([$batchLabel, $user]); $batchId = (int)$db->lastInsertId(); $insertStmt = $db->prepare(' INSERT INTO staging_cells (batch_id, tech, mcc, mnc, operator_guess, cell_id, area_code, sub_id, sub_id2, band, frequency, azimuth, bandwidth, address_desc, lat, lon, location_desc, arfcn, source, status) VALUES (:batch_id, :tech, :mcc, :mnc, :operator_guess, :cell_id, :area_code, :sub_id, :sub_id2, :band, :frequency, :azimuth, :bandwidth, :address_desc, :lat, :lon, :location_desc, :arfcn, "manual_form", "pending") '); $count = 0; foreach ($techs as $i => $tech) { if ($tech === '' || $cellIds[$i] === '' || $areaCodes[$i] === '') continue; $enb = $subIds2[$i] !== '' ? $subIds2[$i] : null; $band = $bands[$i] !== '' ? $bands[$i] : null; $frequency = $frequencies[$i] !== '' ? $frequencies[$i] : null; $azimuth = $azimuths[$i] !== '' ? (int)$azimuths[$i] : null; $bandwidth = $bandwidths[$i] !== '' ? $bandwidths[$i] : null; $composedLocation = composeLocationDesc($tech, $enb, $band, $frequency, $azimuth, $bandwidth, $addressDesc); $insertStmt->execute([ ':batch_id' => $batchId, ':tech' => $tech, ':mcc' => $op['mcc'], ':mnc' => $op['mnc'], ':operator_guess' => $operatorId, ':cell_id' => $cellIds[$i], ':area_code' => $areaCodes[$i], ':sub_id' => $subIds[$i] !== '' ? $subIds[$i] : null, ':sub_id2' => $enb, ':band' => $band, ':frequency' => $frequency, ':azimuth' => $azimuth, ':bandwidth' => $bandwidth, ':address_desc' => $addressDesc, ':lat' => $lat, ':lon' => $lon, ':location_desc' => $composedLocation, ':arfcn' => $arfcns[$i] !== '' ? $arfcns[$i] : null, ]); $count++; } $db->commit(); $successMessage = "$count cellule(s) envoyee(s) en validation (lot #$batchId)."; } catch (Throwable $e) { $db->rollBack(); $errorMessage = "Erreur : " . $e->getMessage(); } } } } ?>
Un site peut porter plusieurs cellules/secteurs, chacune avec sa propre bande, frequence, azimut et largeur de bande.
= htmlspecialchars($successMessage) ?>
= htmlspecialchars($errorMessage) ?>