<?php

//<----------------------------------------------------------->
//<-------------------COPIA AI BRUXÃO------------------------->
//<-------------CONTATO: https://t.me/eonbry------------------>
//<-------------DEVELOPER: EMANUEL NASCIMENTO----------------->
//<----------------------------------------------------------->


error_reporting(0);

if(isset($_GET['ref_id'])) {
    
    $revenda = $_GET['ref_id'];
    $file_to_get = "qrcode.json";
    $db1 = new SQLite3('../a/.eggziedb.db');
    
    if($revenda == "ADM") {
        $file_to_get = "qrcode.json";
    } else {
        
        $result = $db1->query("SELECT COUNT(id) AS total FROM revenda WHERE usuario = '$revenda'");
        $rownew = $result->fetchArray();
        $count = $rownew['total'];
        $result = $db1->query("SELECT COUNT(id) AS total FROM sub_revenda WHERE usuario = '$revenda'");
        $rownew = $result->fetchArray();
        $count2 = $rownew['total'];
        
        if(($count > 0 || $count2 > 0) && file_exists("qrcode_$revenda.json")) {
             $file_to_get = "qrcode_$revenda.json";
        } else {
             $file_to_get = "qrcode.json";
        }
    }
 
  $jsonData = file_get_contents($file_to_get);
  header('Content-type: application/json; charset=UTF-8');
  $final = json_decode($jsonData);
  echo json_encode($final, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    
} else {
    echo json_encode(["INVALID RESPONSE COD: 1"]);
}


?>
