<?php
    require_once("../../autoloader.php");
    header('Access-Control-Allow-Origin: *');
    header('Content-Type: application/json');
    header("Access-Control-Allow-Methods: POST");
    header("Allow: POST, OPTIONS, PUT, DELETE");
    header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Origin");

    $headers = apache_request_headers();
    $response = array();
    $controller = new SubscriberModel;
   
    date_default_timezone_set('Africa/Lagos');
          

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
   
    $id = $_POST['user_id'];


 

    $result = $controller->getNetworks();
  $r = json_encode($result);
    $data = json_decode($r);

$response = array();

foreach ($data as $item) {
    $network = $item->network;
    $networkStatus = $item->networkStatus;
    $rpinStatus = $item->airtimepinStatus;
    $vtuStatus = $item->vtuStatus;
    $networkId = $item->networkid;

    switch ($networkId) {
        case 1:
            $response['mtn_status'] = $networkStatus;
            $response['mtn_status_r'] = $rpinStatus;
            $response['mtn_vtu_status'] = $vtuStatus;
            break;
        case 2:
            $response['glo_status'] = $networkStatus;
            $response['glo_status_r'] = $rpinStatus;
            $response['glo_vtu_status'] = $vtuStatus;
            break;
        case 3:
            $response['etisalat_status'] = $networkStatus;
            $response['etisalat_status_r'] = $rpinStatus;
            $response['etisalat_vtu_status'] = $vtuStatus;
            break;
        case 4:
            $response['airtel_status'] = $networkStatus;
            $response['airtel_status_r'] = $rpinStatus;
            $response['airtel_vtu_status'] = $vtuStatus;
             $response['status'] = 'success';
            break;
        default:
            break;
    }

}

//echo json_encode($response);

file_put_contents("airtime__log.txt",json_encode($response, JSON_UNESCAPED_SLASHES));
$jsonString = json_encode($response, JSON_UNESCAPED_SLASHES);
echo $jsonString;
exit();
    
    }

    




?>