🖨️ ระบบสร้างกระดาษคำตอบและเฉลยอัตโนมัติ (Authain Academy)
ชื่อ-นามสกุล: ………………………………………………………………….
ชั้น: ………………….. เลขที่: …………………..
คำชี้แจง: ระบายทึบในวงกลมตัวเลือกที่ต้องการ และระบายเลขที่ รหัส 5 หลัก และรหัสวิชาให้ถูกต้อง
Back to top button
const wpLabels = {
num: ["①", "②", "③", "④", "⑤"],
eng: ["A", "B", "C", "D", "E"],
thai: ["ก", "ข", "ค", "ง", "จ"]
};
function wpRenderKeys() {
const totalQEl = document.getElementById('wp-total-q');
const choiceTypeEl = document.getElementById('wp-choice-type');
const numChoicesEl = document.getElementById('wp-num-choices');
const answerKeyContainer = document.getElementById('wp-answer-key-inputs');
if (!totalQEl || !answerKeyContainer) return;
const totalQ = parseInt(totalQEl.value);
const choiceType = choiceTypeEl.value;
const numChoices = parseInt(numChoicesEl.value);
const labels = wpLabels[choiceType];
let html = "";
for (let i = 1; i <= totalQ; i++) {
html += `ข้อ ${i}:
`;
}
answerKeyContainer.innerHTML = html;
}
function wpRenderGrids() {
const gridContainer = document.getElementById('wp-grids');
if (!gridContainer) return;
let makeGrid = (title, cols) => {
let h = `${title}
`;
for(let col=1; col<=cols; col++) {
h += `
0`;
for(let d=0; d<=9; d++) {
h += `${d}`;
}
h += `
`;
}
return h + `
`;
};
gridContainer.innerHTML = makeGrid('เลขที่', 2) + makeGrid('รหัส 5 หลัก', 5) + makeGrid('รหัสวิชา', 3);
}
function wpGenerate(type) {
const school = document.getElementById('wp-school').value || "โรงเรียน Authain Academy";
const teacher = document.getElementById('wp-teacher').value || "-";
const subject = document.getElementById('wp-subject').value || "-";
const className = document.getElementById('wp-class').value || "-";
const term = document.getElementById('wp-term').value;
const year = document.getElementById('wp-year').value || "2569";
const totalQ = parseInt(document.getElementById('wp-total-q').value);
const choiceType = document.getElementById('wp-choice-type').value;
const numChoices = parseInt(document.getElementById('wp-num-choices').value);
const labels = wpLabels[choiceType];
document.getElementById('wp-prev-title').innerText = type === 'key' ? "🔑 กระดาษเฉลยคำตอบ (Answer Key)" : "📄 กระดาษคำตอบนักเรียน";
document.getElementById('wp-prev-info').innerHTML = `โรงเรียน: ${school} | วิชา: ${subject} | ชั้น: ${className} | ภาคเรียนที่ ${term}/${year} | ครูผู้สอน: ${teacher}`;
let html = "";
for (let i = 1; i <= totalQ; i++) {
let correctAns = 0;
if (type === 'key') {
const el = document.getElementById(`wp-k-${i}`);
if (el) correctAns = parseInt(el.value);
}
html += `
ข้อ ${i}
`;
for (let c = 1; c <= numChoices; c++) {
let isSelected = (type === 'key' && correctAns === c);
let bgColor = isSelected ? '#000000' : '#ffffff';
let textColor = isSelected ? '#ffffff' : '#444444';
let displayText = isSelected ? '●' : labels[c-1];
html += `${displayText}`;
}
html += `
`;
}
document.getElementById('wp-bubbles').innerHTML = html;
const area = document.querySelector('.print-area');
area.style.display = "block";
window.scrollTo({ top: area.offsetTop, behavior: 'smooth' });
}
// โหลดข้อมูลเริ่มต้นเมื่อเปิดหน้าเว็บ
window.addEventListener('DOMContentLoaded', () => {
wpRenderKeys();
wpRenderGrids();
});