59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
require_once __DIR__ . '/../config/database.php';
|
|
|
|
$database = new Database();
|
|
$db = $database->getConnection();
|
|
|
|
$response = array('success' => false, 'message' => '', 'data' => null);
|
|
|
|
try {
|
|
// Get item counts by type
|
|
$query = "SELECT it.name as item_type, COUNT(i.id) as count
|
|
FROM item_types it
|
|
LEFT JOIN ftth_items i ON it.id = i.item_type_id
|
|
GROUP BY it.id, it.name
|
|
ORDER BY it.id";
|
|
|
|
$stmt = $db->prepare($query);
|
|
$stmt->execute();
|
|
|
|
$statistics = array();
|
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
$key = strtolower(str_replace(' ', '_', $row['item_type']));
|
|
$statistics[$key] = (int)$row['count'];
|
|
}
|
|
|
|
// Get total routes
|
|
$query = "SELECT COUNT(*) as total_routes FROM cable_routes";
|
|
$stmt = $db->prepare($query);
|
|
$stmt->execute();
|
|
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
$statistics['total_routes'] = (int)$result['total_routes'];
|
|
|
|
// Get route status counts
|
|
$query = "SELECT status, COUNT(*) as count FROM cable_routes GROUP BY status";
|
|
$stmt = $db->prepare($query);
|
|
$stmt->execute();
|
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
$statistics['routes_' . $row['status']] = (int)$row['count'];
|
|
}
|
|
|
|
// Calculate total distance
|
|
$query = "SELECT SUM(distance) as total_distance FROM cable_routes WHERE distance IS NOT NULL";
|
|
$stmt = $db->prepare($query);
|
|
$stmt->execute();
|
|
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
$statistics['total_distance_km'] = round((float)$result['total_distance'] / 1000, 2);
|
|
|
|
$response['success'] = true;
|
|
$response['data'] = $statistics;
|
|
|
|
} catch (Exception $e) {
|
|
$response['message'] = 'Database error: ' . $e->getMessage();
|
|
}
|
|
|
|
echo json_encode($response);
|
|
?>
|