<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Job Fit to Role Assessment / Penilaian Kendiri Kesesuaian Kerja</title>
<!-- Add Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<?php
$lang = isset($_GET['lang']) ? $_GET['lang'] : 'en';
//echo $lang;
// Database connection parameters
require_once "include/config.php";
// Create a database connection
$conn = new mysqli($host, $username, $password, $database);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the hash value from the query string
$hash_value = isset($_GET['h']) ? $_GET['h'] : '';
if ($hash_value == "") {
echo "<h1 class='text-center'>Penilaian Kendiri Kesesuaian Kerja</h1>";
exit();
}
// Later replace with Hash from URL
$sql = "SELECT aa.for_candidate_name, aa.assessment_id, aa.name as assessor, aa.self_or_ext, a.name as position, aa.status, p.name as project_name, p.nama as project_nama FROM assessment_by_assessor as aa inner join assessment as a ON aa.assessment_id = a.id inner join project as p ON a.project_id = p.id where aa.hash = '".$hash_value."' ";
$result = $conn->query($sql);
$baseURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$fullURL = strtok($baseURL, '&'); // Get the URL before the query string
//echo $fullURL;
// Display assessment data
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
?>
<form id="assessmentForm" action="submit.php" method="post">
<?php
if ($row["status"] == 2) {
echo "<br /><center><div style='color:green'><i>Borang penilaian ini telah diterima. Terima kasih!</i></div></center>";
} else {
?>
<div class="container mt-4">
<div class="text-center" style="padding-bottom:5px"><small>
<?php if ($row["project_nama"] != 'Penilaian Kendiri Kesesuaian Kerja LPB') {?>
<?php if ($lang === 'bm') {?>
<strong>Bahasa Melayu</strong> | <a href="<?php echo $fullURL?>&lang=en">English</a>
<?php } else { ?>
<a href="<?php echo $fullURL?>&lang=bm">Bahasa Melayu</a> | <strong>English</strong>
<?php } ?>
<?php } ?>
</small>
</div>
<h1 class="text-center"><?php echo ($lang === 'bm') ? $row["project_nama"] : $row["project_name"]; ?></h1>
<?php if ($row["self_or_ext"] == 1) {?>
<h5 class="text-center"><?php echo ($lang === 'bm') ? "Penilaian ini bertujuan mengukur kecekapan anda bagi kompetensi yang diperlukan untuk jawatan." : "This assessment aims to measure your competence for the competencies required for the position."; ?></h5>
<?php } else { ?>
<h5 class="text-center"><?php echo ($lang === 'bm') ? "Penilaian ini bertujuan mengukur kecekapan " : "This assessment aims to measure "; ?><?php echo $row["for_candidate_name"]?><?php echo ($lang === 'bm') ? " bagi kompetensi yang diperlukan untuk jawatan." : "'s competencies required for the position."; ?></h5>
<?php } ?>
<!-- Example Card -->
<div class="card mt-4">
<div class="card-body">
<h5 class="card-title"><?php echo ($lang === 'bm') ? "Penilaian Kesesuaian Kerja untuk" : "Job fit to role assessment for"; ?> <strong><u><?php echo $row["for_candidate_name"]?></u></strong>
<!--<?php echo ($lang === 'bm') ? "bagi jawatan" : "for the position of"; ?> <strong><u><?php echo $row["position"]?></u></strong>--></h5>
<?php if ($row["self_or_ext"] == 1) {?>
<h6 class="card-title"><?php echo ($lang === 'bm') ? "Arahan: Sila pilih tahap kecekapan anda berdasarkan skala berikut:" : "Instructions: Please select your level of proficiency based on the following scale:"; ?> </h6>
<?php } else { ?>
<h6 class="card-title"><?php echo ($lang === 'bm') ? "Arahan: Sila pilih tahap kecekapan berdasarkan skala berikut:" : "Instructions: Please select the level of proficiency based on the following scale:"; ?> </h6>
<?php } ?>
<?php if ($row["project_nama"] = 'Penilaian Kendiri Kesesuaian Kerja LPB') {?>
<p class="card-text"><img src="<?php echo ($lang === 'bm') ? "img/lpb.png" : "img/lpb.png"; ?>" width="100%"></p>
<?php } else { ?>
<p class="card-text"><img src="<?php echo ($lang === 'bm') ? "img/BM-Description.png" : "img/BI-Descriptionv3.png"; ?>" width="100%"></p>
<?php } ?>
</div>
</div>
<?php
// Get Behavioral Indicators (BIs)
$bi_sql = "SELECT bi.id, bi.name, bi.nama FROM assess_bi as ab INNER JOIN behavioral_indicator as bi ON ab.bi_id = bi.id where assessment_id = ".$row['assessment_id'] ;
$bi_result = $conn->query($bi_sql);
// Display BIs as Questions
for ($i = 1; $i <= $bi_result->num_rows; $i++) {
$bi_row = $bi_result->fetch_assoc();
?>
<div class="mt-4">
<h4><?php echo ($lang === 'bm') ? $i. ". " .$bi_row["nama"] : $i. ". " .$bi_row["name"]; ?></h4>
<div class="form-check">
<input class="form-check-input" type="radio" name="q<?php echo $bi_row["id"]?>" id="q<?php echo $bi_row["id"]?>_option5" value="5" data-question="<?php echo $bi_row["id"]?>" required>
<label class="form-check-label" for="q<?php echo $bi_row["id"]?>_option5"><?php echo ($lang === 'bm') ? "Pakar Rujuk Bidang" : "Subject Matter Expert"; ?></label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="q<?php echo $bi_row["id"]?>" id="q<?php echo $bi_row["id"]?>_option4" value="4" data-question="<?php echo $bi_row["id"]?>" required>
<label class="form-check-label" for="q<?php echo $bi_row["id"]?>_option4"><?php echo ($lang === 'bm') ? "Cekap" : "Advanced"; ?></label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="q<?php echo $bi_row["id"]?>" id="q<?php echo $bi_row["id"]?>_option3" value="3" data-question="<?php echo $bi_row["id"]?>" required>
<label class="form-check-label" for="q<?php echo $bi_row["id"]?>_option3"><?php echo ($lang === 'bm') ? "Kompeten" : "Competent"; ?></label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="q<?php echo $bi_row["id"]?>" id="q<?php echo $bi_row["id"]?>_option2" value="2" data-question="<?php echo $bi_row["id"]?>" required>
<label class="form-check-label" for="q<?php echo $bi_row["id"]?>_option2"><?php echo ($lang === 'bm') ? "Pengalaman Terhad" : "Limited Experience"; ?></label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="q<?php echo $bi_row["id"]?>" id="q<?php echo $bi_row["id"]?>_option1" value="1" data-question="<?php echo $bi_row["id"]?>" required>
<label class="form-check-label" for="q<?php echo $bi_row["id"]?>_option1"><?php echo ($lang === 'bm') ? "Pengetahuan Asas" : "Basic Knowledge"; ?>
</label>
</div>
</div>
<?php
}
echo "<hr>";
?>
<input type="hidden" name="jsonAnswers" id="jsonAnswers" value="">
<input type="hidden" name="hash" id="hash" value="<?php echo $hash_value ?>">
<div><?php echo ($lang === 'bm') ? "Saya" : "I"; ?>, <u><?php echo $row["assessor"]?></u> <?php echo ($lang === 'bm') ? "dengan ini mengesahkan bahawa semua maklumat yang diberikan adalah tepat, lengkap dan benar." : "hereby confirm that all information provided is accurate, complete and true."; ?></div>
<br />
<center><button type="submit" class="btn btn-primary"><?php echo ($lang === 'bm') ? "Hantar" : "Submit"; ?></button></center>
<br /><br />
<?php
}
?>
</form>
</div>
</div>
<?php
} // Close if ($row["status"] == 2)
} else {
echo "<h1><center>No assessment found / <i>Tiada penilaian</></center></h1>";
}
// Close the database connection
$conn->close();
?>
</div>
<!-- Add Bootstrap JS and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!--Check to ensure all fields are filled up -->
<script>
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("assessmentForm");
form.addEventListener("submit", function (event) {
event.preventDefault(); // Prevent form submission
const questions = {};
// Loop through all radio inputs in the form
const radioInputs = document.querySelectorAll('input[type="radio"]');
radioInputs.forEach(function (input) {
if (input.checked) {
const questionNumber = input.getAttribute('data-question');
const selectedOption = input.value;
questions[`q${questionNumber}`] = selectedOption;
}
});
// Get the total number of questions
const totalQuestions = radioInputs.length / 5; // Divide by 5 since there are two options per question
// Check if all questions are answered
if (Object.keys(questions).length !== totalQuestions) {
alert("Please answer all questions. / Sila jawab semua soalan.");
return; // Prevent further processing if any question is not answered
}
// Convert the questions object to JSON
const jsonAnswers = JSON.stringify(questions);
// Display the JSON result (you can save it to your database here)
console.log("JSON Answers:", jsonAnswers);
document.getElementById("jsonAnswers").value = jsonAnswers;
form.submit();
});
});
</script>
</body>
</html>