लोड होत आहे... (Loading Live Exam Data)

कृपया प्रतीक्षा करा, तुमचा पेपर सेट होत आहे.

\r\n\r\n\r\n","pre":"\r\n\r\n\r\n","top":"\r\n\r\n\r\n","middle":"\r\n\r\n\r\n","bottom":"\r\n\r\n\r\n","result":"\r\n\r\n\r\n","action":"\r\n\r\n\r\n"}; const initializedAdSlots = {}; function getAdCode(slot) { const specific = adSlotCodes[slot] || ''; if (specific.trim()) return specific; return adSlotCodes.global || ''; } function loadExternalScripts(container) { const scripts = Array.from(container.querySelectorAll('script')); scripts.forEach(function(oldScript) { const newScript = document.createElement('script'); Array.from(oldScript.attributes).forEach(function(attr) { newScript.setAttribute(attr.name, attr.value); }); if (oldScript.src) { newScript.src = oldScript.src; } else { newScript.textContent = oldScript.textContent; } oldScript.parentNode.replaceChild(newScript, oldScript); }); } function injectLiveAd(containerId, slot) { const container = document.getElementById(containerId); if (!container) return false; if (initializedAdSlots[containerId]) return true; const code = getAdCode(slot); if (!code || !code.trim()) { container.style.display = 'none'; return false; } container.style.display = 'flex'; container.innerHTML = code; initializedAdSlots[containerId] = true; // Google AdSense uses the adsbygoogle queue. Trigger it after the tag exists. const ads = container.querySelectorAll('ins.adsbygoogle'); if (ads.length) { window.adsbygoogle = window.adsbygoogle || []; ads.forEach(function(ad) { if (!ad.getAttribute('data-adsbygoogle-status')) { try { window.adsbygoogle.push({}); } catch (e) { console.warn('AdSense push error:', e); } } }); } // Re-run scripts for non-AdSense snippets. if (!ads.length) loadExternalScripts(container); return true; } function injectExamStaticAds() { injectLiveAd('exam-top-ad-container', 'top'); injectLiveAd('exam-middle-ad-container', 'middle'); injectLiveAd('exam-bottom-ad-container', 'bottom'); } let quizData = []; const examDurationMinutes = 30; const isSectionalTiming = false; const sectionDurationMinutes = 0; const globalDurationMinutes = 30; let totalDurationSeconds = isSectionalTiming ? (sectionDurationMinutes * 60) : (globalDurationMinutes * 60); const negRate = 0; const cutoffMarks = 20; const isPaidExam = 0; const examPrice = 49; const startAdSecs = 5; const resultAdSecs = 12; const razorpayKey = ""; let dynamicTotalExamMarks = 0; let assignedQIdsStr = ""; let sectionGroups = {}; let sectionNames = []; let activeSection = ""; let completedSections = []; let currentIdx = 0; let userAnswers = {}; let questionStatus = {}; let timeLeft = totalDurationSeconds; let timerInterval; let preAdInterval; let postAdInterval; let solutionsAdInterval; let rcAdInterval; let studentName = ""; let mobileNumber = ""; let currentLang = "mr"; let isOmrActive = false; let baseFontSize = 16; let tabSwitchCount = 0; let isExamFinished = false; let isCheatingDetected = false; let finalResultData = null; let autoTranslations = {}; document.addEventListener("DOMContentLoaded", function() { let formData = new FormData(); formData.append('action', 'get_mcq_quiz_data'); formData.append('exam_id', 2); const controller = new AbortController(); const loadTimeout = setTimeout(() => controller.abort(), 25000); fetch('https://nextupdates.in/wp-admin/admin-ajax.php', { method: 'POST', body: formData, credentials: 'same-origin', signal: controller.signal }).then(async res => { const rawText = await res.text(); let response; try { response = JSON.parse(rawText); } catch (parseError) { throw new Error('Server returned invalid response: ' + rawText.substring(0, 300)); } if(!res.ok && response && response.data && response.data.message) { throw new Error(response.data.message); } return response; }).then(response => { clearTimeout(loadTimeout); if(response.success) { quizData = response.data.quiz_data; dynamicTotalExamMarks = response.data.dynamic_total_marks; assignedQIdsStr = response.data.assigned_q_ids_str; if (quizData.length === 0) { document.getElementById("exam-loader").innerHTML = '

या परीक्षेत प्रश्न आढळले नाहीत.

'; return; } quizData.forEach((q, idx) => { let sec = q.section_name || 'General'; if(!sectionGroups[sec]) sectionGroups[sec] = []; sectionGroups[sec].push(idx); }); sectionNames = Object.keys(sectionGroups); if(sectionNames.length > 0) activeSection = sectionNames[0]; currentIdx = (sectionNames.length > 0) ? sectionGroups[activeSection][0] : 0; let startMarksEl = document.getElementById("start-total-marks"); if (startMarksEl) { startMarksEl.innerText = dynamicTotalExamMarks; } document.getElementById("exam-loader").style.display = "none"; document.getElementById("custom-mcq-wrapper").style.display = "block"; } else { document.getElementById("exam-loader").innerHTML = '

प्रश्न लोड करताना त्रुटी आली. पेज रिफ्रेश करा.

'; } }).catch(err => { clearTimeout(loadTimeout); const msg = (err && err.name === 'AbortError') ? 'प्रश्न लोड होण्यासाठी जास्त वेळ लागत आहे. Question Bank / Dynamic Rules तपासा.' : (err && err.message ? err.message : 'इंटरनेट किंवा सर्व्हर एरर.'); document.getElementById("exam-loader").innerHTML = '

प्रश्न लोड करताना त्रुटी

' + msg.replace(/[<>]/g, '') + '

'; }); }); const quizWrapper = document.getElementById("custom-mcq-wrapper"); if (quizWrapper) { document.addEventListener("contextmenu", e => { if (e.target.closest('#custom-mcq-wrapper')) { e.preventDefault(); } }); document.addEventListener("copy", e => { if (e.target.closest('#custom-mcq-wrapper')) { e.preventDefault(); alert("कॉपी करण्यास सक्त मनाई आहे! (Copying disabled)"); } }); document.addEventListener("cut", e => { if (e.target.closest('#custom-mcq-wrapper')) { e.preventDefault(); } }); document.addEventListener("selectstart", e => { if (e.target.closest('#custom-mcq-wrapper') && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA') { e.preventDefault(); } }); document.addEventListener("dragstart", e => { if (e.target.closest('#custom-mcq-wrapper')) { e.preventDefault(); } }); document.addEventListener("keydown", e => { if (e.target.closest('#custom-mcq-wrapper')) { if ((e.ctrlKey || e.metaKey) && ['c', 'p', 'a', 'x', 's', 'u'].includes(e.key.toLowerCase())) { e.preventDefault(); } } }); } const blurContent = () => { const wrapper = document.getElementById("custom-mcq-wrapper"); if (wrapper) { wrapper.style.opacity = "0"; wrapper.style.filter = "blur(20px)"; wrapper.style.pointerEvents = "none"; } }; const focusContent = () => { const wrapper = document.getElementById("custom-mcq-wrapper"); if (wrapper) { wrapper.style.opacity = "1"; wrapper.style.filter = "none"; wrapper.style.pointerEvents = "auto"; } }; window.addEventListener("blur", blurContent); window.addEventListener("pagehide", blurContent); document.addEventListener("visibilitychange", () => { if (document.hidden) { blurContent(); if (!isExamFinished && document.getElementById("quiz-main-screen").style.display === "block") { tabSwitchCount++; if (tabSwitchCount === 1) alert("सावधान! स्क्रीन सोडल्यास परीक्षा आपोआप सबमिट होईल व उत्तरपत्रिका ब्लॉक होईल!"); else if (tabSwitchCount >= 2) { alert("टॅब बदलल्यामुळे परीक्षा तत्काळ सबमिट होत आहे. उत्तरपत्रिका ब्लॉक केली आहे!"); isCheatingDetected = true; triggerPostExamWaitCountdown(true); } } } else { focusContent(); } }); window.addEventListener("focus", focusContent); function toggleFullScreen() { try { let elem = document.documentElement; if (!document.fullscreenElement && !document.webkitFullscreenElement) { if (elem.requestFullscreen) elem.requestFullscreen().catch(err => console.log(err)); else if (elem.webkitRequestFullscreen) elem.webkitRequestFullscreen(); } else { if (document.exitFullscreen) document.exitFullscreen(); else if (document.webkitExitFullscreen) document.webkitExitFullscreen(); } } catch(e) {} } function validateMobile(mob) { return /^[0-9]{10}$/.test(mob); } function showPaymentOptionsModal() { studentName = document.getElementById("student_name_input").value.trim(); mobileNumber = document.getElementById("mobile_number_input").value.trim(); if (!studentName || !validateMobile(mobileNumber)) { alert("कृपया नाव आणि अचूक १० अंकी WhatsApp नंबर प्रविष्ट करा!"); return; } document.getElementById("payment-options-modal").style.display = "flex"; } function payViaRazorpay() { document.getElementById("payment-options-modal").style.display = "none"; var options = { "key": razorpayKey, "amount": examPrice * 100, "currency": "INR", "name": "Next Academy", "description": "nishi Exam Fee", "prefill": { "name": studentName, "contact": mobileNumber }, "theme": { "color": "#0ea5e9" }, "handler": function (response) { startPreAdCountdown(); } }; var rzp = new Razorpay(options); rzp.open(); } function startPreAdCountdown() { studentName = document.getElementById("student_name_input").value.trim(); mobileNumber = document.getElementById("mobile_number_input").value.trim(); if (!studentName || !validateMobile(mobileNumber)) { alert("कृपया नाव आणि अचूक १० अंकी WhatsApp नंबर प्रविष्ट करा!"); return; } let startBtn = document.getElementById("start-btn-init"); if(startBtn) { startBtn.disabled = true; startBtn.innerHTML = "लोड होत आहे... (Loading)"; } document.getElementById("hdr-student-name").innerText = studentName; document.getElementById("payment-options-modal").style.display = "none"; document.getElementById("quiz-start-screen").style.display = "none"; document.getElementById("quiz-wait-screen").style.display = "block"; // INJECT AD HERE injectLiveAd('wait-ad-container', 'pre'); let adSecs = startAdSecs; document.getElementById("wait-counter").innerText = adSecs; document.getElementById("wait-counter").parentElement.style.display = "inline-block"; document.getElementById("manual-start-btn").style.display = "none"; if (adSecs <= 0) { document.getElementById("wait-counter").parentElement.style.display = "none"; document.getElementById("manual-start-btn").style.display = "block"; return; } preAdInterval = setInterval(() => { adSecs--; if (adSecs <= 0) { clearInterval(preAdInterval); document.getElementById("wait-counter").parentElement.style.display = "none"; document.getElementById("manual-start-btn").style.display = "block"; } else { document.getElementById("wait-counter").innerText = adSecs; } }, 1000); } function beginActualQuiz() { clearInterval(preAdInterval); document.getElementById("quiz-wait-screen").style.display = "none"; document.getElementById("quiz-main-screen").style.display = "block"; injectExamStaticAds(); toggleFullScreen(); quizData.forEach((q, idx) => { questionStatus[idx] = "unvisited"; }); renderSectionTabs(); buildQuestionPalette(); jumpToQuestion(0); startExamTimer(); } function startExamTimer() { timerInterval = setInterval(() => { if (timeLeft <= 0) { if(isSectionalTiming) { completedSections.push(activeSection); let nextSecIndex = sectionNames.indexOf(activeSection) + 1; if(nextSecIndex < sectionNames.length) { alert("या विभागाची वेळ संपली! पुढील विभाग सुरू होत आहे."); activeSection = sectionNames[nextSecIndex]; timeLeft = sectionDurationMinutes * 60; renderSectionTabs(); buildQuestionPalette(); jumpToQuestion(sectionGroups[activeSection][0]); } else { clearInterval(timerInterval); alert("शेवटच्या विभागाची वेळ संपली! परीक्षा सबमिट होत आहे."); triggerPostExamWaitCountdown(false); } } else { clearInterval(timerInterval); alert("वेळ संपली! परीक्षा सबमिट होत आहे."); triggerPostExamWaitCountdown(false); } } else { timeLeft--; let mins = Math.floor(timeLeft / 60); let secs = timeLeft % 60; document.getElementById("time-left").innerText = mins + " मि. " + (secs < 10 ? '0' : '') + secs + " से."; } }, 1000); } async function translateTextOnline(text) { if (text === null || text === undefined) return ""; text = String(text); if (text.trim() === "") return ""; let cleanText = text.replace(/[\r\n]+/g, ' '); if (autoTranslations[cleanText]) return autoTranslations[cleanText]; try { const url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=mr&tl=en&dt=t&q=" + encodeURIComponent(cleanText); const res = await fetch(url, { method: 'GET', mode: 'cors' }); if (!res.ok) throw new Error("API Limit"); const data = await res.json(); let translated = ""; if (data && data[0]) { data[0].forEach(item => { if (item[0]) translated += item[0]; }); } autoTranslations[cleanText] = translated || cleanText; autoTranslations[text] = translated || text; return translated; } catch(e) { return text; } } async function preTranslateCurrentQuestion() { const q = quizData[currentIdx]; if (q.question && !autoTranslations[q.question]) { autoTranslations[q.question] = await translateTextOnline(q.question); } if (q.passage && !autoTranslations[q.passage]) { autoTranslations[q.passage] = await translateTextOnline(q.passage); } for (let opt of q.options) { if (opt.option_text && !autoTranslations[opt.option_text]) { autoTranslations[opt.option_text] = await translateTextOnline(opt.option_text); } } } async function toggleAutoLanguage() { const langBtn = document.getElementById("lang-toggle-btn"); langBtn.disabled = true; langBtn.innerHTML = "⏳ Wait..."; currentLang = (currentLang === "mr") ? "en" : "mr"; try { if (currentLang === "en") { document.getElementById("question-container").innerHTML = "

⏳ इंग्रजी भाषांतर लोड होत आहे...

"; await preTranslateCurrentQuestion(); } } catch(e) { console.error(e); } finally { renderCurrentQuestion(); if (isOmrActive) renderSketchOmrStrip(); langBtn.innerHTML = "🌐 " + ((currentLang === 'mr') ? 'मराठी | English' : 'English') + ""; langBtn.disabled = false; } } function renderSectionTabs() { if(sectionNames.length <= 1) { document.getElementById("section-tabs-container").style.display = "none"; return; } document.getElementById("section-tabs-container").style.display = "flex"; let html = ''; sectionNames.forEach(sec => { let isActive = (sec === activeSection) ? 'active' : ''; let disabledClass = (isSectionalTiming && sec !== activeSection) ? 'disabled-tab' : ''; let qCount = sectionGroups[sec] ? sectionGroups[sec].length : 0; html += ``; }); document.getElementById("section-tabs-container").innerHTML = html; } function switchSection(sec) { if(isSectionalTiming && sec !== activeSection) return; updateCurrentStatusBeforeLeaving(); activeSection = sec; currentIdx = sectionGroups[sec][0]; renderSectionTabs(); buildQuestionPalette(); jumpToQuestion(currentIdx); } function changeFontSize(delta) { baseFontSize = Math.min(22, Math.max(13, baseFontSize + delta)); document.getElementById("cbt-question-box").style.fontSize = baseFontSize + "px"; } function toggleOmrMode() { isOmrActive = !isOmrActive; const stripPanel = document.getElementById("omr-strip-panel"); const btn = document.getElementById("omr-toggle-btn"); if (isOmrActive) { stripPanel.classList.add("active-omr-mode"); btn.style.background = "#0ea5e9"; btn.innerHTML = "◉ OMR Mode (सुरू)"; renderSketchOmrStrip(); } else { stripPanel.classList.remove("active-omr-mode"); btn.style.background = "#475569"; btn.innerHTML = "◉ OMR Mode"; } } function buildQuestionPalette() { const grid = document.getElementById("palette-grid"); grid.innerHTML = ""; let currentSecArray = sectionGroups[activeSection] || []; currentSecArray.forEach(idx => { const btn = document.createElement("button"); btn.type = "button"; btn.className = "palette-btn"; btn.id = "palette-btn-" + idx; btn.innerText = idx + 1; btn.onclick = () => { updateCurrentStatusBeforeLeaving(); jumpToQuestion(idx); }; grid.appendChild(btn); }); updatePaletteStyles(); } async function jumpToQuestion(idx) { currentIdx = idx; if (questionStatus[currentIdx] === "unvisited") questionStatus[currentIdx] = "not-answered"; if (currentLang === "en") { const container = document.getElementById("question-container"); if (container) container.innerHTML = "

⏳ इंग्रजी भाषांतर लोड होत आहे...

"; await preTranslateCurrentQuestion(); } renderCurrentQuestion(); if (isOmrActive) renderSketchOmrStrip(); updatePaletteStyles(); updateStatsSummary(); } function renderCurrentQuestion() { const q = quizData[currentIdx]; const container = document.getElementById("question-container"); let qText = q.question; if (currentLang === "en" && autoTranslations[qText]) qText = autoTranslations[qText]; document.getElementById("omr-box-title").innerText = `डिजिटल OMR (Q. ${currentIdx + 1})`; let html = ''; if (q.type === 'passage' && q.passage) { let pText = q.passage; if (currentLang === "en" && autoTranslations[pText]) pText = autoTranslations[pText]; html += `
Passage / उतारा:
${pText}
`; } let negInfo = negRate > 0 ? `Negative: -${negRate}` : `No Negative Marking`; html += `
Q. ${currentIdx + 1} (गुण: ${q.marks})
${negInfo}
`; if (q.image_url) { html += `
`; } html += `

${qText}

`; html += `
`; q.options.forEach((opt, optIdx) => { let savedAns = userAnswers[q.id]; let optLabel = String(opt.option_text); if (currentLang === "en" && autoTranslations[optLabel]) optLabel = autoTranslations[optLabel]; let letter = String.fromCharCode(65 + optIdx); let checked = ''; if (q.type === 'single' || q.type === 'passage' || q.type === 'sorting') { checked = (savedAns == opt.id) ? 'checked' : ''; html += ``; } else if (q.type === 'multiple') { checked = (savedAns && savedAns.includes(opt.id)) ? 'checked' : ''; html += ``; } }); if (q.type === 'free_choice') { let val = userAnswers[q.id] || ''; html += ``; } html += `
`; container.innerHTML = html; document.getElementById("prev-btn").disabled = (currentIdx === 0); let currentSecArray = sectionGroups[activeSection]; let isLastInSection = (currentSecArray.indexOf(currentIdx) === currentSecArray.length - 1); let nextBtn = document.getElementById("next-btn"); if(isSectionalTiming && isLastInSection) { nextBtn.innerHTML = "Submit Section & Next →"; nextBtn.style.background = "#f59e0b"; } else { nextBtn.innerHTML = "Save & Next →"; nextBtn.style.background = "#0ea5e9"; } if (typeof MathJax !== 'undefined') { MathJax.typesetPromise([container]).catch(function (err) { console.log('MathJax error: ', err.message); }); } } function renderSketchOmrStrip() { const q = quizData[currentIdx]; const strip = document.getElementById("sketch-omr-strip"); let html = ''; let savedAns = userAnswers[q.id]; q.options.forEach((opt, optIdx) => { let letter = String.fromCharCode(65 + optIdx); let isFilled = ''; if (q.type === 'multiple' && savedAns && savedAns.includes(opt.id)) isFilled = 'filled'; else if (savedAns == opt.id) isFilled = 'filled'; html += `
${letter}
`; }); strip.innerHTML = html; } function saveAnswerVal(qId, optId, type) { if (type === 'multiple') { if (!userAnswers[qId]) userAnswers[qId] = []; let index = userAnswers[qId].indexOf(optId); if (index > -1) userAnswers[qId].splice(index, 1); else userAnswers[qId].push(optId); if (userAnswers[qId].length === 0) delete userAnswers[qId]; } else { if (optId === '') delete userAnswers[qId]; else userAnswers[qId] = optId; } questionStatus[currentIdx] = "answered"; if (isOmrActive) renderSketchOmrStrip(); updatePaletteStyles(); updateStatsSummary(); checkAttemptStatus(); } function saveAnswerValOnlyOmr(qId, optId, type) { if (type === 'multiple') { if (!userAnswers[qId]) userAnswers[qId] = []; let index = userAnswers[qId].indexOf(optId); if (index > -1) userAnswers[qId].splice(index, 1); else userAnswers[qId].push(optId); if (userAnswers[qId].length === 0) delete userAnswers[qId]; } else { if (optId === '') delete userAnswers[qId]; else userAnswers[qId] = optId; } questionStatus[currentIdx] = "answered"; renderSketchOmrStrip(); updatePaletteStyles(); updateStatsSummary(); checkAttemptStatus(); } function updateCurrentStatusBeforeLeaving() { const qId = quizData[currentIdx].id; if (userAnswers[qId] !== undefined && userAnswers[qId] !== "") questionStatus[currentIdx] = "answered"; else if (questionStatus[currentIdx] !== "marked") questionStatus[currentIdx] = "not-answered"; } function saveAndNextQuestion() { updateCurrentStatusBeforeLeaving(); let currentSecArray = sectionGroups[activeSection]; let indexOfCurrent = currentSecArray.indexOf(currentIdx); if (indexOfCurrent < currentSecArray.length - 1) { jumpToQuestion(currentSecArray[indexOfCurrent + 1]); } else { if(isSectionalTiming) { let conf = confirm("या विभागातील सर्व प्रश्न संपले आहेत. तुम्ही पुढील विभागात गेल्यास या विभागात परत येता येणार नाही. पुढे जायचे?"); if(conf) { completedSections.push(activeSection); let secIndex = sectionNames.indexOf(activeSection); if (secIndex < sectionNames.length - 1) { activeSection = sectionNames[secIndex + 1]; timeLeft = sectionDurationMinutes * 60; renderSectionTabs(); buildQuestionPalette(); jumpToQuestion(sectionGroups[activeSection][0]); } else { updatePaletteStyles(); updateStatsSummary(); openSubmitConfirmationModal(); } } } else { let secIndex = sectionNames.indexOf(activeSection); if (secIndex < sectionNames.length - 1) { switchSection(sectionNames[secIndex + 1]); } else { updatePaletteStyles(); updateStatsSummary(); openSubmitConfirmationModal(); } } } } function prevQuestion() { updateCurrentStatusBeforeLeaving(); let currentSecArray = sectionGroups[activeSection]; let indexOfCurrent = currentSecArray.indexOf(currentIdx); if (indexOfCurrent > 0) { jumpToQuestion(currentSecArray[indexOfCurrent - 1]); } else { if(!isSectionalTiming) { let secIndex = sectionNames.indexOf(activeSection); if (secIndex > 0) { let prevSec = sectionNames[secIndex - 1]; let prevSecArray = sectionGroups[prevSec]; activeSection = prevSec; renderSectionTabs(); buildQuestionPalette(); jumpToQuestion(prevSecArray[prevSecArray.length - 1]); } } else { alert("विभागीय वेळ सुरू असल्याने तुम्ही मागील विभागात जाऊ शकत नाही."); } } } function markForReview() { questionStatus[currentIdx] = "marked"; let currentSecArray = sectionGroups[activeSection]; let indexOfCurrent = currentSecArray.indexOf(currentIdx); if (indexOfCurrent < currentSecArray.length - 1) { jumpToQuestion(currentSecArray[indexOfCurrent + 1]); } else { updatePaletteStyles(); updateStatsSummary(); } } function clearCurrentAnswer() { const qId = quizData[currentIdx].id; delete userAnswers[qId]; questionStatus[currentIdx] = "not-answered"; renderCurrentQuestion(); if (isOmrActive) renderSketchOmrStrip(); updatePaletteStyles(); updateStatsSummary(); checkAttemptStatus(); } function updatePaletteStyles() { let currentSecArray = sectionGroups[activeSection] || []; currentSecArray.forEach(idx => { const btn = document.getElementById("palette-btn-" + idx); if (!btn) return; btn.className = "palette-btn"; if (idx === currentIdx) btn.classList.add("active"); if (questionStatus[idx] === "answered") btn.classList.add("answered"); else if (questionStatus[idx] === "marked") btn.classList.add("marked"); else if (questionStatus[idx] === "not-answered") btn.classList.add("not-answered"); }); } function updateStatsSummary() { let ans = 0, unans = 0, rev = 0; quizData.forEach((q, idx) => { if (questionStatus[idx] === "answered") ans++; else if (questionStatus[idx] === "marked") rev++; else if (questionStatus[idx] === "not-answered") unans++; }); let elAns = document.getElementById("stat-count-ans"); if(elAns) elAns.innerText = ans; let elUnans = document.getElementById("stat-count-unans"); if(elUnans) elUnans.innerText = unans; let elRev = document.getElementById("stat-count-rev"); if(elRev) elRev.innerText = rev; let elRem = document.getElementById("stat-count-rem"); if(elRem) elRem.innerText = (quizData.length - ans); } function checkAttemptStatus() { let ans = 0; quizData.forEach((q, idx) => { if (questionStatus[idx] === "answered") ans++; }); let mainSubBtn = document.getElementById("final-main-submit-btn"); if(mainSubBtn) { if(ans === quizData.length) { mainSubBtn.disabled = false; mainSubBtn.style.background = "#16a34a"; mainSubBtn.innerText = "Submit Exam \u2713"; } else { mainSubBtn.disabled = true; mainSubBtn.style.background = "#94a3b8"; mainSubBtn.innerText = "सर्व प्रश्न सोडवा"; } } } function openSubmitConfirmationModal() { updateCurrentStatusBeforeLeaving(); updateStatsSummary(); let ans = 0, unans = 0, rev = 0; quizData.forEach((q, idx) => { if (questionStatus[idx] === "answered") ans++; else if (questionStatus[idx] === "marked") rev++; else unans++; }); document.getElementById("modal-total-q").innerText = quizData.length; document.getElementById("modal-att-count").innerText = ans; document.getElementById("modal-unans-count").innerText = unans; document.getElementById("modal-rev-count").innerText = rev; const warningMsg = document.getElementById("unanswered-warning-msg"); const submitBtn = document.getElementById("final-submit-btn"); if (unans > 0) { if(warningMsg) { warningMsg.innerText = "⚠️ सर्व प्रश्न सोडवणे अनिवार्य आहे! (अजून " + unans + " प्रश्न बाकी आहेत)"; warningMsg.style.display = "block"; } if(submitBtn) { submitBtn.disabled = true; submitBtn.style.background = "#94a3b8"; submitBtn.style.cursor = "not-allowed"; submitBtn.innerText = "सर्व प्रश्न सोडवा"; } } else { if(warningMsg) warningMsg.style.display = "none"; if(submitBtn) { submitBtn.disabled = false; submitBtn.style.background = "linear-gradient(135deg, #16a34a, #15803d)"; submitBtn.style.cursor = "pointer"; submitBtn.innerText = "Submit Test"; } } let modal = document.getElementById("submit-confirm-modal"); if(modal) modal.style.display = "flex"; } function closeSubmitModal() { document.getElementById("submit-confirm-modal").style.display = "none"; } function triggerPostExamWaitCountdown(cheated) { closeSubmitModal(); clearInterval(timerInterval); isExamFinished = true; if (cheated) isCheatingDetected = true; document.getElementById("quiz-main-screen").style.display = "none"; document.getElementById("quiz-processing-screen").style.display = "block"; // INJECT AD HERE injectLiveAd('processing-ad-container', 'result'); let resultAdSecs = 12; if(resultAdSecs <= 0) { document.getElementById("quiz-processing-screen").style.display = "none"; sendExamDataToServer(); return; } document.getElementById("processing-counter").innerText = resultAdSecs; postAdInterval = setInterval(() => { resultAdSecs--; if (resultAdSecs <= 0) { clearInterval(postAdInterval); document.getElementById("quiz-processing-screen").style.display = "none"; sendExamDataToServer(); } else { document.getElementById("processing-counter").innerText = resultAdSecs; } }, 1000); } function sendExamDataToServer() { let formData = new FormData(); formData.append('action', 'submit_mcq_exam'); formData.append('exam_id', 2); formData.append('student_name', studentName); formData.append('mobile_number', mobileNumber); formData.append('answers', JSON.stringify(userAnswers)); formData.append('time_taken', totalDurationSeconds - timeLeft); formData.append('is_disqualified', isCheatingDetected ? 1 : 0); formData.append('assigned_q_ids', assignedQIdsStr); fetch('https://nextupdates.in/wp-admin/admin-ajax.php', { method: 'POST', body: formData }) .then(res => res.text()) .then(text => { try { let jsonStart = text.indexOf('{'); let jsonEnd = text.lastIndexOf('}'); if(jsonStart !== -1 && jsonEnd !== -1) { let validJson = text.substring(jsonStart, jsonEnd + 1); const response = JSON.parse(validJson); if(response.success) { finalResultData = response.data; document.getElementById("quiz-result-box").style.display = "block"; let secHtml = ''; let secScores = response.data.section_scores; let secTotals = response.data.section_totals; for (let sec in secScores) { secHtml += ` ${sec} ${secTotals[sec]} ${secScores[sec].toFixed(2)} `; } document.getElementById("rc-section-body").innerHTML = secHtml; let currentUrl = window.location.href; document.getElementById("rc-qr-code").src = "https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=" + encodeURIComponent(currentUrl); let today = new Date(); document.getElementById("rc-date").innerText = "दिनांक: " + today.toLocaleDateString('en-GB'); document.getElementById("rc-student-name").innerText = studentName; document.getElementById("rc-exam-name").innerText = "nishi"; document.getElementById("rc-total-score").innerText = response.data.score + " / " + response.data.total_exam_marks; document.getElementById("rc-accuracy").innerText = response.data.accuracy + "%"; document.getElementById("rc-rank").innerText = "#" + response.data.rank; let acc = parseFloat(response.data.accuracy); let gradeText = ""; let gradeColor = ""; if(acc >= 90) { gradeText = "A+ (उत्कृष्ट)"; gradeColor = "#16a34a"; } else if(acc >= 75) { gradeText = "A (अतिशय छान)"; gradeColor = "#0ea5e9"; } else if(acc >= 60) { gradeText = "B (छान)"; gradeColor = "#ca8a04"; } else { gradeText = "C (सरावाची गरज)"; gradeColor = "#dc2626"; } document.getElementById("rc-grade").innerText = gradeText; document.getElementById("rc-grade").style.background = gradeColor + "20"; document.getElementById("rc-grade").style.color = gradeColor; document.getElementById("rc-grade").style.border = "1px solid " + gradeColor; let rank = parseInt(response.data.rank); if(rank === 1) document.getElementById("rc-medal").innerText = "🥇"; else if(rank === 2) document.getElementById("rc-medal").innerText = "🥈"; else if(rank === 3) document.getElementById("rc-medal").innerText = "🥉"; else document.getElementById("rc-medal").innerText = ""; let logoUrl = ""; if(logoUrl) { document.getElementById("rc-logo").src = logoUrl; document.getElementById("rc-logo").style.display = "block"; } let aiBox = document.getElementById("ai-analytics-box"); let aiHtml = ''; if(response.data.topic_analytics && response.data.topic_analytics.length > 0) { response.data.topic_analytics.forEach(ta => { let bg = "#f1f5f9", clr = "#475569"; if(ta.status === 'Strong') { bg = "#dcfce7"; clr = "#16a34a"; } else if(ta.status === 'Weak') { bg = "#fee2e2"; clr = "#dc2626"; } else { bg = "#fef08a"; clr = "#ca8a04"; } let lbl = (ta.topic === 'General') ? 'सर्वसाधारण' : ta.topic; aiHtml += `${lbl} (${ta.pct}%)`; }); aiBox.innerHTML = aiHtml; } else { aiBox.innerHTML = 'कोणताही घटक डेटा उपलब्ध नाही.'; } document.getElementById("explanation-section-wrapper").style.display = "none"; if (isCheatingDetected) { document.getElementById("disqualification-warning-box").style.display = "block"; document.getElementById("view-solutions-btn-wrapper").style.display = "none"; document.getElementById("rc-grade").innerText = "Disqualified"; document.getElementById("rc-grade").style.color = "#dc2626"; } else { document.getElementById("disqualification-warning-box").style.display = "none"; document.getElementById("view-solutions-btn-wrapper").style.display = "block"; buildExplanationSheet(); } document.getElementById("leaderboard-container").innerHTML = response.data.leaderboard_html; } else { alert("Error: " + response.data); document.getElementById("quiz-main-screen").style.display = "block"; isExamFinished = false; } } else { throw new Error("Invalid Server Response"); } } catch(e) { console.error("Server Parsing Error:", text); alert("Server Connection Error! कृपया इंटरनेट तपासा आणि पुन्हा 'Submit Test' वर क्लिक करा."); document.getElementById("quiz-main-screen").style.display = "block"; isExamFinished = false; } }) .catch(err => { alert("Network Error! कृपया इंटरनेट कनेक्शन तपासा आणि पुन्हा 'Submit Test' वर क्लिक करा."); document.getElementById("quiz-main-screen").style.display = "block"; isExamFinished = false; }); } function startSolutionsAdCountdown() { document.getElementById("view-solutions-btn-wrapper").style.display = "none"; document.getElementById("solutions-ad-screen").style.display = "block"; // INJECT AD HERE injectLiveAd('solutions-ad-container', 'action'); let counter = 15; document.getElementById("solutions-ad-counter").innerText = counter; solutionsAdInterval = setInterval(() => { counter--; if (counter <= 0) { clearInterval(solutionsAdInterval); document.getElementById("solutions-ad-screen").style.display = "none"; document.getElementById("explanation-section-wrapper").style.display = "block"; if (typeof MathJax !== 'undefined') { MathJax.typesetPromise([document.getElementById("explanations-wrapper")]).catch(function (err) { console.log('MathJax error: ', err.message); }); } } else { document.getElementById("solutions-ad-counter").innerText = counter; } }, 1000); } function startRcAdCountdown(actionType) { document.getElementById("download-rc-btn").parentElement.style.display = "none"; document.getElementById("rc-ad-screen").style.display = "block"; // INJECT AD HERE injectLiveAd('download-ad-container', 'action'); let counter = 10; document.getElementById("rc-ad-counter").innerText = counter; rcAdInterval = setInterval(() => { counter--; if (counter <= 0) { clearInterval(rcAdInterval); document.getElementById("rc-ad-screen").style.display = "none"; document.getElementById("download-rc-btn").parentElement.style.display = "flex"; if(actionType === 'download') { downloadReportCard(); } else if(actionType === 'share') { shareReportCardImage(); } } else { document.getElementById("rc-ad-counter").innerText = counter; } }, 1000); } async function downloadReportCard() { if (!finalResultData) return; const btn = document.getElementById("download-rc-btn"); const originalText = btn.innerHTML; btn.innerHTML = "⏳ डाउनलोड होत आहे..."; btn.disabled = true; const cardElement = document.getElementById("printable-certificate"); cardElement.classList.add("force-desktop-render"); try { const canvas = await html2canvas(cardElement, { scale: window.devicePixelRatio > 1 ? 2 : 1, useCORS: true, backgroundColor: "#ffffff", windowWidth: 800, onclone: function(clonedDoc) { const clonedCard = clonedDoc.getElementById("printable-certificate"); clonedCard.classList.add("force-desktop-render"); clonedCard.parentElement.style.width = "800px"; clonedCard.parentElement.style.minWidth = "800px"; clonedCard.parentElement.style.display = "block"; clonedDoc.body.style.width = "800px"; clonedDoc.body.style.minWidth = "800px"; clonedDoc.documentElement.style.width = "800px"; } }); cardElement.classList.remove("force-desktop-render"); const dataUrl = canvas.toDataURL("image/png"); const link = document.createElement('a'); link.download = studentName.replace(/\s+/g, '_') + '_Report_Card.png'; link.href = dataUrl; document.body.appendChild(link); link.click(); document.body.removeChild(link); } catch(error) { cardElement.classList.remove("force-desktop-render"); console.error("Download failed:", error); alert("डाउनलोड करताना तांत्रिक अडचण आली."); } finally { btn.innerHTML = originalText; btn.disabled = false; } } async function shareReportCardImage() { if (!finalResultData) return; const shareBtn = document.getElementById("wa-share-btn"); const originalHtml = shareBtn.innerHTML; shareBtn.innerHTML = "⏳ तयार होत आहे (Please Wait)..."; shareBtn.disabled = true; const cardElement = document.getElementById("printable-certificate"); cardElement.classList.add("force-desktop-render"); try { const canvas = await html2canvas(cardElement, { scale: window.devicePixelRatio > 1 ? 2 : 1, useCORS: true, backgroundColor: "#ffffff", width: 750, windowWidth: 800, onclone: function(clonedDoc) { const clonedCard = clonedDoc.getElementById("printable-certificate"); clonedCard.classList.add("force-desktop-render"); clonedCard.parentElement.style.width = "800px"; clonedCard.parentElement.style.minWidth = "800px"; clonedCard.parentElement.style.display = "block"; clonedDoc.body.style.width = "800px"; clonedDoc.body.style.minWidth = "800px"; clonedDoc.documentElement.style.width = "800px"; } }); cardElement.classList.remove("force-desktop-render"); let shareText = `*ऑनलाइन परीक्षा निकाल - Next Academy*\n` + `विद्यार्थी: ${studentName}\n` + `मिळालेले गुण: ${finalResultData.score} / ${dynamicTotalExamMarks}\n` + `अचूकता (Accuracy): ${finalResultData.accuracy}%\n` + `रँक: #${finalResultData.rank}\n\n` + `तुम्हीही ही परीक्षा द्या आणि निकाल तपासा 👇\n${window.location.href}`; const dataUrl = canvas.toDataURL("image/png"); const downloadAndShareFallback = () => { const link = document.createElement('a'); link.download = studentName.replace(/\s+/g, '_') + '_Report_Card.png'; link.href = dataUrl; document.body.appendChild(link); link.click(); document.body.removeChild(link); let url = "https://api.whatsapp.com/send?text=" + encodeURIComponent(shareText); window.open(url, '_blank'); }; canvas.toBlob(async (blob) => { const file = new File([blob], "ReportCard.png", { type: "image/png" }); if (navigator.canShare && navigator.canShare({ files: [file] })) { try { await navigator.share({ files: [file], title: 'My Exam Report Card', text: shareText }); } catch(e) { if(e.name !== 'AbortError') { downloadAndShareFallback(); } } } else { downloadAndShareFallback(); } shareBtn.innerHTML = originalHtml; shareBtn.disabled = false; }, "image/png"); } catch(error) { cardElement.classList.remove("force-desktop-render"); console.error("Image generation failed:", error); alert("इमेज तयार करताना तांत्रिक अडचण आली."); shareBtn.innerHTML = originalHtml; shareBtn.disabled = false; } } function buildExplanationSheet() { const wrap = document.getElementById("explanations-wrapper"); let html = ''; quizData.forEach((q, idx) => { let userAns = userAnswers[q.id]; html += `

Q. ${idx + 1} (${q.section_name}): ${q.question}

`; if (q.image_url) { html += `
`; } html += `
`; q.options.forEach((opt, oIdx) => { let isUserChoice = (userAns == opt.id || (Array.isArray(userAns) && userAns.includes(opt.id))); let colorStyle = ""; let icon = ""; if (opt.is_correct == 1) { colorStyle = "color:#15803d; font-weight:bold; background:#dcfce7; padding:4px 8px; border-radius:4px; margin-bottom:4px;"; icon = "✅"; } else if (isUserChoice) { colorStyle = "color:#b91c1c; text-decoration:line-through; background:#fee2e2; padding:4px 8px; border-radius:4px; margin-bottom:4px;"; icon = "❌"; } else { colorStyle = "color:#475569; padding:4px 8px; margin-bottom:4px;"; } html += `
${icon} (${String.fromCharCode(65 + oIdx)}) ${opt.option_text} ${isUserChoice && opt.is_correct != 1 ? ' [तुमचे उत्तर]' : ''}
`; }); html += `
`; if (q.explanation) { html += `
स्पष्टीकरण: ${q.explanation}
`; } html += `
`; }); wrap.innerHTML = html; } function restartExam() { currentIdx = (sectionNames.length > 0) ? sectionGroups[activeSection][0] : 0; if(sectionNames.length > 0) activeSection = sectionNames[0]; userAnswers = {}; questionStatus = {}; timeLeft = totalDurationSeconds; tabSwitchCount = 0; isExamFinished = false; isCheatingDetected = false; finalResultData = null; completedSections = []; clearInterval(timerInterval); clearInterval(preAdInterval); clearInterval(postAdInterval); if(typeof solutionsAdInterval !== 'undefined') clearInterval(solutionsAdInterval); if(typeof rcAdInterval !== 'undefined') clearInterval(rcAdInterval); let startBtn = document.getElementById("start-btn-init"); if(startBtn) { startBtn.disabled = false; if (isPaidExam == 1) { startBtn.innerHTML = "₹" + examPrice + " फी भरा आणि टेस्ट सुरू करा →"; } else { startBtn.innerHTML = "मोफत सराव परीक्षा सुरू करा →"; } } let mainSubBtn = document.getElementById("final-main-submit-btn"); if(mainSubBtn) { mainSubBtn.disabled = true; mainSubBtn.style.background = "#94a3b8"; mainSubBtn.innerText = "सर्व प्रश्न सोडवा"; } document.getElementById("manual-start-btn").style.display = "none"; document.getElementById("wait-counter").parentElement.style.display = "inline-block"; document.getElementById("explanation-section-wrapper").style.display = "none"; document.getElementById("solutions-ad-screen").style.display = "none"; document.getElementById("view-solutions-btn-wrapper").style.display = "none"; document.getElementById("rc-ad-screen").style.display = "none"; document.getElementById("quiz-result-box").style.display = "none"; document.getElementById("quiz-start-screen").style.display = "flex"; } // Disable initial submit button check checkAttemptStatus();