Add consultation module assets and libraries
This commit is contained in:
125
konsultasi/API/web/verifKonsultasi.php
Normal file
125
konsultasi/API/web/verifKonsultasi.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?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', '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();
|
||||
}
|
||||
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$nipDosen = $row['nip'];
|
||||
}
|
||||
|
||||
$sql = 'SELECT * FROM konsultasi LEFT JOIN tugas_akhir on konsultasi.idTugasAkhir = tugas_akhir.idTugasAkhir WHERE (pemb1 = :pemb1 OR pemb2 = :pemb2) AND idKonsul = :idKonsul';
|
||||
$stmt = $dbh->prepare($sql);
|
||||
$stmt->bindParam(':pemb1', $nipDosen);
|
||||
$stmt->bindParam(':pemb2', $nipDosen);
|
||||
$stmt->bindParam(':idKonsul', $id);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() == 0) {
|
||||
echo getUnauthorizedMessage();
|
||||
exit();
|
||||
}
|
||||
|
||||
$pemb1 = false;
|
||||
$pemb2 = false;
|
||||
$timestampDosen = 0;
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$pemb1Db = $row['pemb1'];
|
||||
$pemb2Db = $row['pemb2'];
|
||||
|
||||
if ($pemb1Db == $nipDosen) {
|
||||
$pemb1 = true;
|
||||
$timestampDosen = $row['timestampDosen1'];
|
||||
}
|
||||
|
||||
if ($pemb2Db == $nipDosen) {
|
||||
$pemb2 = true;
|
||||
$timestampDosen = $row['timestampDosen2'];
|
||||
}
|
||||
}
|
||||
/**
|
||||
if ($timestampDosen > 0) {
|
||||
echo json_encode(
|
||||
array(
|
||||
'status' => 1,
|
||||
'msg' => 'Berhasil melakukan verifikasi konsultasi ini!!!',
|
||||
)
|
||||
);
|
||||
exit();
|
||||
}
|
||||
*/
|
||||
$now = time();
|
||||
if ($pemb1) {
|
||||
$sql = 'UPDATE konsultasi SET tanggal = :tanggal, timestampDosen1 = :timestamp, catatanDosen1 = :catatan WHERE idKonsul = :idKonsul';
|
||||
$stmt = $dbh->prepare($sql);
|
||||
$stmt->bindParam(':tanggal', $tanggal);
|
||||
$stmt->bindParam(':timestamp', $now);
|
||||
$stmt->bindParam(':catatan', $catatan);
|
||||
$stmt->bindParam(':idKonsul', $id);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
if ($pemb2) {
|
||||
$sql = 'UPDATE konsultasi SET tanggal = :tanggal, timestampDosen2 = :timestamp, catatanDosen2 = :catatan WHERE idKonsul = :idKonsul';
|
||||
$stmt = $dbh->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!!!',
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user