(function () { 'use strict'; document.addEventListener('DOMContentLoaded', function() { var dash = document.getElementById('elp-student-dashboard'); if (!dash) return; var CFG = window.ELP_DASH_CFG || {}; // 1. Handle Avatar Upload (Hover Overlay Method) var avatarWrap = document.getElementById('elp-avatar-trigger'); var avatarInput = document.getElementById('elp-avatar-input'); var avatarImg = document.getElementById('elp-dash-avatar'); if (avatarWrap) { avatarWrap.addEventListener('click', function() { avatarInput.click(); }); } if (avatarInput) { avatarInput.addEventListener('change', function(e) { var file = e.target.files[0]; if (!file) return; var reader = new FileReader(); reader.onload = function(event) { var base64Image = event.target.result; var overlay = document.querySelector('.elp-dash-avatar-overlay'); if (overlay) { overlay.innerHTML = 'Uploading...'; overlay.style.opacity = '1'; } fetch(CFG.restUrl + '/dashboard/update-avatar', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': CFG.nonce }, body: JSON.stringify({ image: base64Image }) }) .then(r => r.json()) .then(res => { if (res.success) { var newUrl = res.url + '?t=' + new Date().getTime(); avatarImg.src = newUrl; var headerAvatar = document.querySelector('.elp-header-avatar'); if (headerAvatar) headerAvatar.src = newUrl; } else { alert(res.message || 'Upload failed.'); } if (overlay) overlay.innerHTML = 'Change Photo'; }) .catch(() => { alert('Network error.'); if (overlay) overlay.innerHTML = 'Change Photo'; }); }; reader.readAsDataURL(file); }); } // 2. Fetch Real Recent Exam Attempts (Enhanced Error Reporting) var examList = document.getElementById('elp-recent-exams'); if (examList) { fetch(CFG.restUrl + '/dashboard/recent-exams', { headers: { 'X-WP-Nonce': CFG.nonce } }) .then(r => r.json().then(data => ({ status: r.status, body: data }))) .then(res => { if (res.status >= 400) { var errMsg = res.body.message || 'Failed to load exams.'; examList.innerHTML = '
Error: ' + errMsg + '
'; return; } if (res.body.exams && res.body.exams.length > 0) { examList.innerHTML = res.body.exams.map(function(exam) { var badgeClass = exam.passed ? 'passed' : 'failed'; var badgeText = exam.passed ? 'Passed' : 'Failed'; return `
${exam.title} ${exam.score} (${exam.percent})
${badgeText}
`; }).join(''); } else { examList.innerHTML = '
You haven\'t taken any exams yet. Start one!
'; } }) .catch(() => { examList.innerHTML = '
Network error loading exams.
'; }); } // 3. Handle Profile Update Form var profileForm = document.getElementById('elp-profile-form'); if (profileForm) { profileForm.addEventListener('submit', function(e) { e.preventDefault(); var msgBox = dash.querySelector('.elp-profile-msg'); var btn = profileForm.querySelector('button[type="submit"]'); msgBox.style.display = 'none'; btn.textContent = 'Saving...'; btn.disabled = true; var formData = new FormData(profileForm); var data = Object.fromEntries(formData); fetch(CFG.restUrl + '/dashboard/update-profile', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': CFG.nonce }, body: JSON.stringify(data) }) .then(r => r.json()) .then(res => { if (res.success) { msgBox.textContent = res.message; msgBox.style.color = '#10b981'; msgBox.style.display = 'block'; } else { msgBox.textContent = res.message || 'Update failed.'; msgBox.style.color = '#dc2626'; msgBox.style.display = 'block'; } btn.textContent = 'Update Profile'; btn.disabled = false; setTimeout(() => { msgBox.style.display = 'none'; }, 3000); }) .catch(() => { msgBox.textContent = 'Network error.'; msgBox.style.color = '#dc2626'; msgBox.style.display = 'block'; btn.textContent = 'Update Profile'; btn.disabled = false; }); }); } // 4. Handle "Become Ambassador" Upgrade var upgradeBtn = document.getElementById('elp-become-ambassador-btn'); if (upgradeBtn) { upgradeBtn.addEventListener('click', function() { upgradeBtn.textContent = 'Verifying...'; upgradeBtn.disabled = true; fetch(CFG.restUrl + '/dashboard/become-ambassador', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': CFG.nonce } }) .then(r => r.json()) .then(res => { if (res.success) { window.location.href = res.redirect; } else { if (res.code === 'not_purchased' && res.data && res.data.link) { alert('You must purchase the "Affiliate Marketing" course first. Redirecting you now...'); window.location.href = res.data.link; } else { alert(res.message || 'Upgrade failed.'); upgradeBtn.textContent = 'Become an Ambassador'; upgradeBtn.disabled = false; } } }) .catch(() => { alert('Network error.'); upgradeBtn.textContent = 'Become an Ambassador'; upgradeBtn.disabled = false; }); }); } // 5. Handle OTP Verification (Email & WhatsApp) using Event Delegation dash.addEventListener('click', function(e) { var sendBtn = e.target.closest('.elp-send-otp-btn'); var confirmBtn = e.target.closest('.elp-confirm-otp-btn'); // Send OTP Click if (sendBtn) { e.preventDefault(); var type = sendBtn.getAttribute('data-type'); var wrap = sendBtn.nextElementSibling; sendBtn.textContent = 'Sending...'; sendBtn.disabled = true; fetch(CFG.restUrl + '/dashboard/send-otp', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': CFG.nonce }, body: JSON.stringify({ type: type }) }) .then(r => r.json()) .then(res => { if (res.success) { alert(res.message); sendBtn.style.display = 'none'; if(wrap) wrap.style.display = 'flex'; } else { alert(res.message || 'Failed to send OTP.'); sendBtn.textContent = 'Send OTP'; sendBtn.disabled = false; } }) .catch(() => { alert('Network error.'); sendBtn.textContent = 'Send OTP'; sendBtn.disabled = false; }); } // Confirm OTP Click if (confirmBtn) { e.preventDefault(); var type = confirmBtn.getAttribute('data-type'); var input = confirmBtn.previousElementSibling; var otp = input ? input.value.trim() : ''; if (!otp) { alert('Please enter the OTP.'); return; } confirmBtn.textContent = 'Verifying...'; confirmBtn.disabled = true; fetch(CFG.restUrl + '/dashboard/verify-otp', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': CFG.nonce }, body: JSON.stringify({ type: type, otp: otp }) }) .then(r => r.json()) .then(res => { if (res.success) { alert(res.message); window.location.reload(); } else { alert(res.message || 'Invalid OTP.'); confirmBtn.textContent = 'Verify'; confirmBtn.disabled = false; } }) .catch(() => { alert('Network error.'); confirmBtn.textContent = 'Verify'; confirmBtn.disabled = false; }); } }); // 6. Handle Copy Referral Link (Ambassador Dashboard) var copyBtn = document.getElementById('elp-copy-ref-link'); var linkInput = document.getElementById('elp-ref-link'); if (copyBtn && linkInput) { copyBtn.addEventListener('click', function() { linkInput.select(); linkInput.setSelectionRange(0, 99999); // For mobile devices navigator.clipboard.writeText(linkInput.value).then(function() { var originalText = copyBtn.textContent; copyBtn.textContent = 'Copied!'; copyBtn.classList.add('copied'); setTimeout(function() { copyBtn.textContent = originalText; copyBtn.classList.remove('copied'); }, 2000); }).catch(function() { alert('Please copy the link manually.'); }); }); } }); })(); Youth SKill Development – Abacus, Computer Skill and Competetive education
logo leaf new
All under one roof- Certificate | Diploma | Degree

Abacus & Vedic Math

Computer Education

Skill Training

Competitive Preparation

Academic  Certification

Stay connected with us to learn, grow, and build a brighter future from childhood to career.

Dream Abacus

Vedic junior

Learn Computer

Best learning

Skill Training

Become job ready

Competetive

Govt. Job preparation

Popular Courses

logo leaf new
edu hat

From Foundation to Professional

For Kids

Dream Abacus, Vedic math Jr. Computer

For Students

School computer Certificate course

Career Starter

Placement ready skill development program

Competitive

Be ready to crack your dream Govt. job exam.

Register Your Academy Today !

Join Us For Free. Lifetime No Renewal Needed.

Educational Kits

logo leaf new

Students Testimonial

logo leaf new
Rated 5 out of 5
"This institute helped me improve my knowledge and confidence step by step. I highly recommend it to every student who wants a better future.” — Happy Student
rupsa das
Rupsa Das

Transforming Learners into Professionals

Learn - Empower - Lead

Rated 5 out of 5
"I am very happy with the support and cooperation from the staff. They helped me at every step and made learning easier for me.” — Happy Student
abhijit bose
Abhijit Bose

Our Recognition:

Scroll to Top