<?php
$mysqli = new mysqli("127.0.0.1", "root", "", "siakad");
$res = $mysqli->query("SELECT * FROM pengaturan");
$settings = [];
while($row = $res->fetch_assoc()) {
    $settings[$row['pengaturan_key']] = $row['pengaturan_value'];
}
$url = $settings['pddikti_url'];
$username = $settings['pddikti_username'];
$password = $settings['pddikti_password'];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$payload = json_encode(['act' => 'GetToken', 'username' => $username, 'password' => $password]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = json_decode(curl_exec($ch), true);
$token = $result['data']['token'];

echo "=== GetKurikulum ===\n";
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['act' => 'GetDictionary', 'token' => $token, 'fungsi' => 'GetKurikulum']));
print_r(json_decode(curl_exec($ch), true)['data'] ?? 'Not found');

echo "\n=== GetListMataKuliah ===\n";
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['act' => 'GetDictionary', 'token' => $token, 'fungsi' => 'GetListMataKuliah']));
print_r(json_decode(curl_exec($ch), true)['data'] ?? 'Not found');

echo "\n=== GetMataKuliah ===\n";
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['act' => 'GetDictionary', 'token' => $token, 'fungsi' => 'GetMataKuliah']));
print_r(json_decode(curl_exec($ch), true)['data'] ?? 'Not found');
