86 lines
1.9 KiB
PHP
86 lines
1.9 KiB
PHP
<?php
|
|
|
|
session_start();
|
|
include '../../conf/koneksiPDO.php';
|
|
include '../../conf/function.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$conn = new createCon();
|
|
$dbh = $conn->connect();
|
|
|
|
checkKey('POST', 'token');
|
|
checkKey('POST', 'id');
|
|
|
|
$token = trim($_POST['token']);
|
|
$id = trim($_POST['id']);
|
|
|
|
$authorized = false;
|
|
|
|
$sql = 'SELECT * FROM tugas_akhir LEFT JOIN mahasiswa ON tugas_akhir.nim = mahasiswa.nim WHERE token = :token AND idTugasAkhir = (SELECT idTugasAkhir FROM konsultasi WHERE idKonsul = :idKonsul)';
|
|
$stmt = $dbh->prepare($sql);
|
|
$stmt->bindParam(':token', $token);
|
|
$stmt->bindParam(':idKonsul', $id);
|
|
$stmt->execute();
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
$authorized = true;
|
|
}
|
|
|
|
if (!$authorized) {
|
|
echo getUnauthorizedMessage();
|
|
exit();
|
|
}
|
|
|
|
$sql = 'SELECT * FROM konsultasi WHERE idKonsul = :idKonsul';
|
|
$stmt = $dbh->prepare($sql);
|
|
$stmt->bindParam(':idKonsul', $id);
|
|
$stmt->execute();
|
|
|
|
$timestamp1 = 0;
|
|
$timestamp2 = 0;
|
|
|
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
$timestamp1 = intval($row['timestampDosen1']);
|
|
$timestamp2 = intval($row['timestampDosen2']);
|
|
}
|
|
|
|
if ($timestamp1 > 0 || $timestamp2 > 0) {
|
|
echo json_encode(
|
|
array(
|
|
'status' => 0,
|
|
'msg' => 'Tidak dapat menghapus data konsultasi ini, data telah di verifikasi pembimbing!!!',
|
|
)
|
|
);
|
|
exit();
|
|
}
|
|
|
|
$sql = 'DELETE FROM konsultasi WHERE idKonsul = :idKonsul';
|
|
$stmt = $dbh->prepare($sql);
|
|
$stmt->bindParam(':idKonsul', $id);
|
|
$stmt->execute();
|
|
|
|
$error = $stmt->errorInfo();
|
|
|
|
$isError = true;
|
|
|
|
if ($error[0] == '00000') {
|
|
$isError = false;
|
|
}
|
|
|
|
if ($isError) {
|
|
echo json_encode(
|
|
array(
|
|
'status' => 0,
|
|
'msg' => 'Terjadi kesalahan teknis!!!',
|
|
)
|
|
);
|
|
} else {
|
|
echo json_encode(
|
|
array(
|
|
'status' => 1,
|
|
'msg' => 'Berhasil menghapus data konsultasi!!!',
|
|
)
|
|
);
|
|
}
|