<?php
require("config/koneksi.php");
require("config/function.php");

$token = isset($_GET['token']) ? $_GET['token'] : 'false';

$querys = mysqli_query($koneksi, "select token_api from aplikasi where token_api='$token' ");
$cektoken = mysqli_num_rows($querys);
if ($cektoken <> 0) {
  $querybank = mysqli_query($koneksi, "select * from banksoal ");
  $array_bank = array();
  while ($bank = mysqli_fetch_assoc($querybank)) {
    $array_bank[] = $bank;
  }
  $querysoal = mysqli_query($koneksi, "select * from soal ");
  $array_soal = array();
  while ($soalx = mysqli_fetch_assoc($querysoal)) {
    $array_soal[] = $soalx;
  }
  $queryjadwal = mysqli_query($koneksi, "select * from ujian");
  $array_jadwal = array();
  while ($jadwal = mysqli_fetch_assoc($queryjadwal)) {
    $array_jadwal[] = $jadwal;
  }
   $querymapel = mysqli_query($koneksi, "select * from mata_pelajaran");
  $array_mapel = array();
  while ($mapel = mysqli_fetch_assoc($querymapel)) {
    $array_mapel[] = $mapel;
  }
 
  $queryinformasi = mysqli_query($koneksi, "select * from informasi");
  $array_informasi = array();
  while ($informasi = mysqli_fetch_assoc($queryinformasi)) {
    $array_informasi[] = $informasi;
  }
  $queryjenis = mysqli_query($koneksi, "select * from jenis");
  $array_jenis = array();
  while ($jenis = mysqli_fetch_assoc($queryjenis)) {
    $array_jenis[] = $jenis;
  }
  $queryfile = mysqli_query($koneksi, "select * from file_pendukung");
  $array_file = array();
  while ($file = mysqli_fetch_assoc($queryfile)) {
    $array_file[] = $file;
  }
 $queryuser = mysqli_query($koneksi, "select * from users");
  $array_user = array();
  while ($users = mysqli_fetch_assoc($queryuser)) {
    $array_user[] = $users;
  }
  echo json_encode(
    [
      "bank" => $array_bank,
      "soal" => $array_soal,
      "jadwal" => $array_jadwal,
	   "mapel" => $array_mapel,
	   "informasi" => $array_informasi,
	   "jenis" => $array_jenis,
      "file" => $array_file,
	   "users" => $array_user
    ]
  );
} else {
  echo "<script>location.href='.'</script>";
}
