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

97 lines
2.2 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');
checkKey('POST', 'topik');
checkKey('POST', 'tanggal');
$token = trim($_POST['token']);
$id = trim($_POST['id']);
$topik = trim($_POST['topik']);
$tanggal = trim($_POST['tanggal']);
$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();
}
if ($topik == '') {
echo getDataEmptyMessage();
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 mengedit data konsultasi ini, data telah di verifikasi pembimbing!!!',
)
);
exit();
}
$sql = 'UPDATE konsultasi SET tanggal = :tanggal, topik = :topik WHERE idKonsul = :idKonsul';
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':tanggal', $tanggal);
$stmt->bindParam(':topik', $topik);
$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 mengedit data konsultasi!!!',
)
);
}