<?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();
}

include '../../../../config/db.php';
$data = [];

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

    $query = "SELECT * FROM `Blog` WHERE `isDonation` = 1 AND isSiteGuide = 0";
    if ($result = mysqli_query($con, $query)) {
        $i = 0;
        while ($rows = mysqli_fetch_assoc($result)) {
            $data[$i]['blogId'] = $rows['blogId'];
            $data[$i]['title'] = $rows['title'];
            $data[$i]['slug'] = $rows['slug'];
            $data[$i]['author'] = $rows['author'];
            $data[$i]['image'] = $rows['image'];
            $data[$i]['isDonation'] = $rows['isDonation'];
            $data[$i]['donationVideo'] = $rows['donationVideo'];
            $data[$i]['shortDescription'] = $rows['shortDescription'];
            $data[$i]['article'] = $rows['article'];
            $data[$i]['status'] = $rows['status'];
            $data[$i]['dateCreated'] = $rows['dateCreated'];
            $data[$i]['dateModified'] = $rows['dateModified'];
            $i++;
        }
        echo json_encode($data);
    }
} else {
    echo json_encode([
        'status' => -1,
    ]);
    die();
}
