<?php
require("config/koneksi.php");
require("config/function.php");
require("config/crud.php");
$waktu = date('d M Y H:i:s');
$token = isset($_GET['token']) ? $_GET['token'] : 'false';
$npsn = isset($_GET['npsn']) ? $_GET['npsn'] : 'false';
$querys = mysqli_query($koneksi, "select token_api from aplikasi where token_api='$token'");
$cektoken = mysqli_num_rows($querys);

if ($cektoken <> 0) {

    $sql_server = '';
    if (!empty($npsn)) {
        $sql_npsn = " where npsn='$npsn'";
    }
    $query = mysqli_query($koneksi, "select * from sekolah " . $sql_npsn);
    $array_data = array();
    while ($baris = mysqli_fetch_assoc($query)) {
        $array_data[] = $baris;
    }

    echo json_encode([
        'sekolah' => $array_data
    ]);
} else {
    echo "<script>location.href='.'</script>";
}
