batch 1 update style & dahsboard for rec.nurinda.co.id

This commit is contained in:
dirga committed 2026-10-14 13:52:12 +07:00
1 parent 9107ffb158
commit f39aa60384
18485 files changed
+843 -2881869

No files matched your search

+39 -49
View File
@@ -1,50 +1,40 @@
<?php
include 'includes/session.php';
date_default_timezone_set("Asia/Jakarta");
if(isset($_POST['submit'])){
$today = date('Y-m-d');
$time = date('H:i:s');
$ts = $today.' '.$time;
$idap = $user['id'];
$cbox1 = $_POST['dataid']; //isoal
$jawab = $_POST['jawab']; //jawab
$cel = "SELECT * FROM in_daper WHERE id='$idap'";
$qel = $conn->query($cel);
$rel = $qel->fetch_assoc();
$ile = $rel['level'];
$nlev = $ile + 1;
$nema = 'x_'.$rel['email'];
for ($i=0; $i<sizeof ($cbox1);$i++) {
$query="INSERT INTO in_jawab (isoal, jawab, idap, ts)
VALUES ('".$cbox1[$i]."', '".$jawab[$i]."', '$idap', '$ts')";
if($conn->query($query)){
if($nlev<='3'){
$_SESSION['success'] = 'Jawaban test berhasil di submit - Silahkan lanjut ketahap selanjutnya';
$mas = "UPDATE in_daper SET level='$nlev' WHERE id='$idap'";
$sam = $conn->query($mas);
}else{
$_SESSION['success'] = 'Seluruh Tahapan Test telah Selesai - Kami akan menghubungi anda jika sesuai dengan kriteria';
$mas = "UPDATE in_daper SET level='$nlev', password='_x_', email='$nema' WHERE id='$idap'";
$sam = $conn->query($mas);
}
}
else{
$_SESSION['error'] = $conn->error;
}
}
}else{
$_SESSION['error'] = 'Contack your Web Administrator';
}
header('location: home.php');
?>
require __DIR__.'/includes/candidate.php'; $p=candidate();
if($_SERVER['REQUEST_METHOD']!=='POST') cgo('home.php');
cverify();
$action=$_POST['action']??'submit'; $json=$action!=='submit';
function exam_reply($data,$status=200) { http_response_code($status); header('Content-Type: application/json'); echo json_encode($data); exit; }
$phase=(int)($_POST['phase']??0);
if(!isset(CPHASES[$phase])) { if($json) exam_reply(['error'=>'Fase tidak valid.'],400); cgo('home.php'); }
cdb()->begin_transaction();
try {
$current=cq('SELECT level FROM in_daper WHERE id=? FOR UPDATE','i',[(int)$p['id']])->get_result()->fetch_assoc();
$attempt=exam_find((int)$p['id'],$phase);
if(!$attempt || $attempt['status']!=='active' || (int)$current['level']!==$phase-1) {
cdb()->rollback(); if($json) exam_reply(['closed'=>true,'redirect'=>'home.php'],409); cgo('home.php');
}
if(!hash_equals($attempt['active_token'],(string)($_POST['attempt_token']??''))) {
exam_event($attempt,'stale_tab'); cdb()->commit();
if($json) exam_reply(['stale'=>true,'error'=>'Halaman ini sudah digantikan tab atau sesi lain. Muat ulang untuk melanjutkan.'],409);
$_SESSION['error']='Halaman tes sudah digantikan tab atau sesi lain. Buka kembali fase aktif.'; cgo('home.php');
}
if(time()>=(int)$attempt['deadline']) {
exam_finalize($attempt,json_decode($attempt['answers_json'],true),true); cdb()->commit();
$_SESSION['success']='Waktu fase '.$phase.' habis. Hanya draft yang diterima sebelum deadline yang disimpan.';
if($json) exam_reply(['closed'=>true,'redirect'=>'home.php']); cgo('home.php');
}
if($action==='event') { exam_event($attempt,(string)($_POST['event']??'')); cdb()->commit(); exam_reply(['ok'=>true,'remaining'=>max(0,(int)$attempt['deadline']-time())]); }
if(!in_array($action,['save','submit'],true)) throw new InvalidArgumentException('Aksi tidak valid.');
$answers=exam_answers($attempt,$_POST['answers']??[]);
if($action==='save') {
cq('UPDATE rec_exam_attempt SET answers_json=? WHERE id=?','si',[json_encode($answers,JSON_UNESCAPED_UNICODE),(int)$attempt['id']]); cdb()->commit();
exam_reply(['ok'=>true,'remaining'=>max(0,(int)$attempt['deadline']-time())]);
}
exam_finalize($attempt,$answers); cdb()->commit(); $_SESSION['level']=$phase;
$_SESSION['success']=$phase===4?'Seluruh fase berhasil dikirim. Terima kasih telah mengikuti psikotest Nurinda.':'Jawaban fase '.$phase.' tersimpan. Silakan lanjutkan ke fase berikutnya.';
} catch(InvalidArgumentException $error) {
cdb()->rollback(); if($json) exam_reply(['error'=>$error->getMessage()],422); $_SESSION['error']=$error->getMessage();
} catch(Throwable $error) {
cdb()->rollback(); error_log($error->getMessage()); if($json) exam_reply(['error'=>'Sinkronisasi gagal. Coba kembali.'],503); $_SESSION['error']='Jawaban belum tersimpan. Buka kembali fase aktif untuk melanjutkan.';
}
cgo('home.php');