<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization");
header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
    header('Access-Control-Allow-Origin: *');
    header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization");
    header("HTTP/1.1 200 OK");
    die();
}
require '../../../../config/db.php';

$orders = 0;
$nameOrders = 0;
$businessNameOrders = 0;
$astrologyOrders = 0;
$horoscapeOrders = 0;
$auspiciousOrders = 0;
$promisesOrders = 0;

if ($_SERVER['REQUEST_METHOD'] === 'GET') {

    $order_query = "SELECT * FROM Orders;";
    if ($orderResults = mysqli_query($con, $order_query)) {
        $orders = mysqli_num_rows($orderResults);
    }

    $name_order_query = "SELECT * FROM NameOrders;";
    if ($nameOrderResults = mysqli_query($con, $name_order_query)) {
        $nameOrders = mysqli_num_rows($nameOrderResults);
    }

    $business_order_query = "SELECT * FROM BusinessNameOrders;";
    if ($businessNameResult = mysqli_query($con, $business_order_query)) {
        $businessNameOrders = mysqli_num_rows($businessNameResult);
    }

    $horoscape_order_query = "SELECT * FROM HoroscopeOrders;";
    if ($horoscapeResult = mysqli_query($con, $horoscape_order_query)) {
        $horoscapeOrders = mysqli_num_rows($horoscapeResult);
    }

    $auspicious_order_query = "SELECT * FROM AuspiciousOrders;";
    if ($auspiciousResult = mysqli_query($con, $auspicious_order_query)) {
        $auspiciousOrders = mysqli_num_rows($auspiciousResult);
    }

    $promises_order_query = "SELECT * FROM PromisesOrders;";
    if ($promisesResult = mysqli_query($con, $promises_order_query)) {
        $promisesOrders = mysqli_num_rows($promisesResult);
    }

    echo json_encode([
        'status' => 1,
        'data' => [
            'orders' => $orders, 'nameOrders' => $nameOrders, 'businessNameOrders' => $businessNameOrders, 'astrologyOrders' => $horoscapeOrders + $auspiciousOrders + $promisesOrders
        ],
        'message' => '',
    ]);
} else {
    echo json_encode([
        'status' => -1,
        'data' => []
    ]);
    die();
}
