begin_transaction(); try { $current=cq('SELECT level FROM in_daper WHERE id=? FOR UPDATE','i',[(int)$p['id']])->get_result()->fetch_assoc(); if((int)$current['level']!==$phase-1) { cdb()->rollback(); cgo('home.php'); } $attempt=exam_find((int)$p['id'],$phase); if(!$attempt) { $questions=[]; foreach($info[4] as $kat=>$limit) { $found=cq('SELECT id,kat,soal,soal1,opa,opb,opc,opd,ope FROM in_soal WHERE kat=? ORDER BY RAND() LIMIT '.$limit,'i',[$kat])->get_result()->fetch_all(MYSQLI_ASSOC); if(count($found)<$limit) throw new RuntimeException('Soal fase ini belum lengkap. Hubungi tim Human Capital.'); $questions=array_merge($questions,$found); } cq('INSERT INTO rec_exam_attempt(participant_id,phase,questions_json,answers_json,deadline,active_token) VALUES(?,?,?,\'{}\',?,?)','iisis',[(int)$p['id'],$phase,json_encode($questions,JSON_UNESCAPED_UNICODE),time()+$info[3],bin2hex(random_bytes(32))]); $attempt=exam_find((int)$p['id'],$phase); } if($attempt['status']!=='active') { cdb()->rollback(); 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. Draft terakhir yang diterima server telah disimpan.'; cgo('home.php'); } $attemptToken=bin2hex(random_bytes(32)); cq('UPDATE rec_exam_attempt SET active_token=? WHERE id=?','si',[$attemptToken,(int)$attempt['id']]); cdb()->commit(); } catch(Throwable $error) { cdb()->rollback(); error_log($error->getMessage()); $_SESSION['error']='Tes belum dapat dibuka. Periksa koneksi atau hubungi Human Capital.'; cgo('home.php'); } $exam=['questions'=>json_decode($attempt['questions_json'],true),'deadline'=>(int)$attempt['deadline']]; $draft=json_decode($attempt['answers_json'],true); cstart('Fase '.$phase.' · '.$info[0],$p); ?>← Beranda peserta
=ce($info[1])?> · =$phase===4?'Pilih satu pernyataan yang paling sesuai dengan diri Anda.':'Jawab dengan teliti dan periksa sebelum mengirim.'?>