78 lines
1.8 KiB
PHP
78 lines
1.8 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 = :idTugasAkhir';
|
|
$stmt = $dbh->prepare($sql);
|
|
$stmt->bindParam(':token', $token);
|
|
$stmt->bindParam(':idTugasAkhir', $id);
|
|
$stmt->execute();
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
$authorized = true;
|
|
}
|
|
|
|
if (!$authorized) {
|
|
echo getUnauthorizedMessage();
|
|
exit();
|
|
}
|
|
|
|
if ($topik == '') {
|
|
echo getDataEmptyMessage();
|
|
exit();
|
|
}
|
|
$now = time();
|
|
$dateNow = date('d-m-Y', $now);
|
|
|
|
$sql = 'INSERT INTO konsultasi(tanggal, timestamp, idTugasAkhir, topik) VALUES (:tanggal, :timestamp, :idTA, :topik)';
|
|
$stmt = $dbh->prepare($sql);
|
|
$stmt->bindParam(':tanggal', $tanggal);
|
|
$stmt->bindParam(':timestamp', $now);
|
|
$stmt->bindParam(':idTA', $id);
|
|
$stmt->bindParam(':topik', $topik);
|
|
$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!!!',
|
|
'error' => $error,
|
|
)
|
|
);
|
|
} else {
|
|
echo json_encode(
|
|
array(
|
|
'status' => 1,
|
|
'msg' => 'Berhasil menambah data konsultasi!!!',
|
|
)
|
|
);
|
|
}
|