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

97 lines
2.1 KiB
PHP

<?php
session_start();
include '../../conf/koneksiPDO.php';
include '../../conf/function.php';
header('Content-Type: application/json');
$conn = new createCon();
$dbh = $conn->connect();
$connBio = new createCon();
$dbhBio = $connBio->connectDbBio();
checkKey('POST', 'token');
checkKey('POST', 'id');
checkKey('POST', 'catatan');
checkKey('POST', 'tanggal');
$token = trim($_POST['token']);
$id = trim($_POST['id']);
$catatan = trim($_POST['catatan']);
$tanggal = trim($_POST['tanggal']);
$authorized = false;
$sql = 'SELECT * FROM dosen WHERE token = :token';
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':token', $token);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$authorized = true;
}
if (!$authorized) {
echo getUnauthorizedMessage();
exit();
}
$sql = 'SELECT * FROM konsultasi_kp WHERE idKonsul = :idKonsul';
$stmt = $dbhBio->prepare($sql);
$stmt->bindParam(':idKonsul', $id);
$stmt->execute();
if ($stmt->rowCount() == 0) {
echo getUnauthorizedMessage();
exit();
}
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$timestampDosen = $row['timestampVerif'];
}
if ($timestampDosen > 0) {
echo json_encode(
array(
'status' => 1,
'msg' => 'Berhasil melakukan verifikasi konsultasi ini!!!',
)
);
exit();
}
$now = time();
$sql = 'UPDATE konsultasi_kp SET tanggal = :tanggal, timestampVerif = :timestamp, catatanDosen = :catatan WHERE idKonsul = :idKonsul';
$stmt = $dbhBio->prepare($sql);
$stmt->bindParam(':tanggal', $tanggal);
$stmt->bindParam(':timestamp', $now);
$stmt->bindParam(':catatan', $catatan);
$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 melakukan verifikasi konsultasi ini!!!',
)
);
}