Files
spota-dev/konsultasi/API/web/getTugasAkhirMahasiswa.php
2026-05-02 10:11:07 +07:00

69 lines
1.4 KiB
PHP

<?php
include '../../conf/koneksiPDO.php';
include '../../conf/function.php';
header('Content-Type: application/json');
$conn = new createCon();
$dbh = $conn->connect();
checkKey('POST', 'token');
checkKey('POST', 'tipe');
$token = trim($_POST['token']);
$tipe = trim($_POST['tipe']);
$mahasiswa = false;
$dosen = false;
switch ($tipe) {
case 'mahasiswa': $tabel = 'mahasiswa'; $mahasiswa = true; break;
case 'dosen': $tabel = 'dosen'; $dosen = true; break;
default: echo getUnknownTypeMessage(); exit();
}
$sql = "SELECT * FROM $tabel WHERE token = :token";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':token', $token);
$stmt->execute();
$authorized = false;
if ($stmt->rowCount() > 0) {
$authorized = true;
}
if ($mahasiswa) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$nim = $row['nim'];
}
}
if ($dosen) {
checkKey('POST', 'nim');
$nim = $_POST['nim'];
}
$sql = 'SELECT * FROM tugas_akhir WHERE nim = :nim ORDER BY idTugasAkhir DESC';
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':nim', $nim);
$stmt->execute();
$data = array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$id = $row['idTugasAkhir'];
$judul = $row['judul'];
$semester = $row['semester'];
array_push($data, array(
'id' => $id,
'judul' => $judul,
'semester' => $semester,
));
}
echo json_encode(utf8ize(array(
'status' => 1,
'tugasAkhir' => $data,
)));