Contact Us

Have a question, feedback, or need help with your account? Reach out and our team will respond within 24-48 hours.

โœ“ Message sent! We'll get back to you soon.

Reach Us Directly

๐Ÿ“ง support@ustaadonline.pk

๐Ÿ“ฑ WhatsApp: 0300-0000000

๐Ÿ• Response time: 24-48 hours

For Teachers

Want to be featured or have questions about your listing? Email us at teachers@ustaadonline.pk

For Students & Parents

Need help finding the right teacher? Email students@ustaadonline.pk

AFTER your existing scripts. * Needs the PHP snippet: ustad-student-board.php */ (function () { "use strict"; if (window.__usgLoaded) return; window.__usgLoaded = true; var API = "/wp-json/ustad/v1"; var TOKEN_KEY = "usg_teacher_token"; var NAME_KEY = "usg_teacher_name"; var CAT_LABELS = { primary: "Primary (1-8)", senior: "Senior Classes (9-10)", college: "College (11-12)", olevel: "O Level", alevel: "A Level", quran: "Quran Teaching" }; var COLORS = ["#c9a227", "#16324f", "#7c5a1e", "#2d4a6b", "#a3820f", "#1f3a54"]; var students = []; var activeCat = "all"; var token = store("get", TOKEN_KEY) || ""; var teacherName = store("get", NAME_KEY) || ""; var target = null; var loginEmail = ""; var els = {}; /* ---------- helpers ---------- */ function $(id) { return document.getElementById(id); } function store(op, key, value) { try { if (op === "get") return window.localStorage.getItem(key); if (op === "set") window.localStorage.setItem(key, value); if (op === "del") window.localStorage.removeItem(key); } catch (e) {} return null; } function esc(v) { return String(v == null ? "" : v) .replace(/&/g, "&").replace(//g, ">") .replace(/"/g, """).replace(/'/g, "'"); } function initials(name) { return String(name || "?").trim().split(/\s+/).map(function (n) { return n.charAt(0); }) .slice(0, 2).join("").toUpperCase(); } function avatarColor(id) { var s = String(id), h = 0; for (var i = 0; i < s.length; i++) h += s.charCodeAt(i); return COLORS[h % COLORS.length]; } function catLabel(c) { return CAT_LABELS[c] || c || "-"; } function api(path, opts) { opts = opts || {}; var headers = { "Content-Type": "application/json" }; if (opts.token) headers["X-Ustad-Teacher-Token"] = opts.token; return fetch(API + path, { method: opts.method || "GET", headers: headers, credentials: "same-origin", cache: "no-store", body: opts.body ? JSON.stringify(opts.body) : undefined }).then(function (r) { return r.text().then(function (t) { var d = null; try { d = JSON.parse(t); } catch (e) {} if (!r.ok || d === null) { var err = new Error((d && d.message) || "Server error. Please try again."); err.status = r.status; throw err; } return d; }); }); } /* ---------- styles ---------- */ function injectStyles() { if ($("usgStyles")) return; // CSS already pasted in the page var css = [ ".usg-section{background:var(--bg,#f8f9fb);border-top:1px solid var(--border,#e4e5e7);padding:44px 0 50px;}", ".usg-wrap{max-width:1200px;margin:0 auto;padding:0 20px;}", ".usg-head{display:flex;justify-content:space-between;align-items:flex-end;gap:16px;flex-wrap:wrap;margin-bottom:16px;}", ".usg-head h2{font-size:26px;font-weight:900;color:var(--dark,#0d1b2e);margin:0 0 6px;}", ".usg-head p{font-size:13.5px;color:var(--gray,#62646a);max-width:640px;line-height:1.55;margin:0;}", ".usg-search input{border:1px solid var(--border,#e4e5e7);border-radius:8px;padding:11px 14px;font-size:13.5px;min-width:240px;outline:none;font-family:inherit;background:#fff;}", ".usg-search input:focus{border-color:var(--gold,#b8860b);}", ".usg-chips{display:flex;gap:8px;overflow-x:auto;padding:4px 0 14px;}", ".usg-chip{flex-shrink:0;padding:8px 16px;border-radius:24px;border:1.5px solid var(--border,#e4e5e7);background:#fff;font-size:13px;font-weight:700;color:var(--text,#404145);cursor:pointer;white-space:nowrap;font-family:inherit;transition:all .2s;}", ".usg-chip.active,.usg-chip:hover{border-color:var(--gold,#b8860b);background:rgba(201,162,39,.09);color:var(--gold-dark,#96690a);}", ".usg-count{font-size:13px;color:var(--gray,#62646a);margin:0 0 14px;}", ".usg-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(230px,1fr));gap:18px;}", ".usg-empty{color:var(--gray,#62646a);grid-column:1/-1;font-size:14px;}", ".usg-card{background:#fff;border:1px solid var(--border,#e4e5e7);border-radius:10px;overflow:hidden;transition:box-shadow .2s,transform .2s;display:flex;flex-direction:column;}", ".usg-card:hover{box-shadow:0 8px 24px rgba(0,0,0,.09);transform:translateY(-3px);}", ".usg-top{padding:18px 16px 14px;display:flex;align-items:center;gap:12px;}", ".usg-avatar{width:44px;height:44px;border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:800;font-size:15px;flex-shrink:0;}", ".usg-avatar.sm{width:36px;height:36px;font-size:13px;}", ".usg-name{font-weight:700;font-size:14px;color:var(--dark,#0d1b2e);margin-bottom:5px;word-break:break-word;}", ".usg-badge{display:inline-block;background:#fbf3de;color:var(--gold-dark,#96690a);font-size:10.5px;font-weight:800;padding:3px 9px;border-radius:12px;}", ".usg-msg{margin-top:auto;border:none;border-top:1px solid var(--border,#e4e5e7);background:#fff;padding:12px 16px;text-align:left;font-size:12px;font-weight:800;color:var(--gold-dark,#96690a);cursor:pointer;font-family:inherit;}", ".usg-msg:hover{background:#fbf3de;}", ".usg-overlay{position:fixed;inset:0;background:rgba(13,27,46,.65);display:none;align-items:center;justify-content:center;z-index:300;padding:16px;}", ".usg-overlay.show{display:flex;}", ".usg-box{background:#fff;border-radius:14px;max-width:480px;width:100%;max-height:90vh;overflow-y:auto;}", ".usg-mhead{padding:18px 22px;border-bottom:1px solid var(--border,#e4e5e7);display:flex;justify-content:space-between;align-items:center;gap:10px;}", ".usg-mhead h3{font-size:17px;font-weight:800;color:var(--dark,#0d1b2e);margin:0;word-break:break-word;}", ".usg-x{background:none;border:none;font-size:24px;color:var(--gray,#62646a);cursor:pointer;line-height:1;}", ".usg-mbody{padding:22px;}", ".usg-help{font-size:13.5px;line-height:1.6;color:var(--text,#404145);margin:0 0 14px;}", ".usg-help a,.usg-link a{color:var(--gold-dark,#96690a);font-weight:700;}", ".usg-f{margin-bottom:14px;}", ".usg-f label{display:block;font-size:12.5px;font-weight:700;color:var(--gray,#62646a);margin-bottom:5px;}", ".usg-f input,.usg-f textarea{width:100%;border:1px solid var(--border,#e4e5e7);border-radius:7px;padding:11px 13px;font-size:14px;outline:none;font-family:inherit;box-sizing:border-box;}", ".usg-f input:focus,.usg-f textarea:focus{border-color:var(--gold,#b8860b);}", ".usg-counter{text-align:right;font-size:11.5px;color:var(--gray,#62646a);margin-top:4px;}", ".usg-note{font-size:12px;line-height:1.55;color:var(--gray,#62646a);background:var(--bg,#f8f9fb);border:1px solid var(--border,#e4e5e7);border-radius:8px;padding:10px 12px;margin:0 0 14px;}", ".usg-btn{width:100%;background:var(--gold,#b8860b);color:#fff;border:none;padding:13px;border-radius:8px;font-weight:800;font-size:14.5px;cursor:pointer;font-family:inherit;}", ".usg-btn:hover{background:var(--gold-dark,#96690a);}", ".usg-btn:disabled{opacity:.6;cursor:not-allowed;}", ".usg-status{font-size:13px;margin:10px 0 0;min-height:18px;}", ".usg-status.err{color:#b3261e;}", ".usg-link{font-size:13px;margin:12px 0 0;text-align:center;}", ".usg-to{display:flex;align-items:center;gap:10px;margin-bottom:14px;}", ".usg-to strong{display:block;font-size:14px;color:var(--dark,#0d1b2e);margin-bottom:3px;}", ".usg-done{text-align:center;padding:10px 0 4px;}", ".usg-done .tick{width:54px;height:54px;border-radius:50%;background:#fbf3de;color:var(--gold-dark,#96690a);font-size:28px;font-weight:900;display:flex;align-items:center;justify-content:center;margin:0 auto 14px;}" ].join("\n"); var st = document.createElement("style"); st.id = "usgStyles"; st.textContent = css; document.head.appendChild(st); } /* ---------- section + grid ---------- */ function buildSection(page) { // If the section HTML is already in the page, just use it. if (!$("usgSection")) createSection(page); els.chips = $("usgChips"); els.count = $("usgCount"); els.grid = $("usgGrid"); els.search = $("usgSearch"); } function createSection(page) { var sec = document.createElement("section"); sec.className = "usg-section"; sec.id = "usgSection"; sec.innerHTML = '
' + '
' + '
' + '

Students Looking for Teachers

' + '

Verified teachers can message a student directly through Ustaad Online. Students\' phone numbers and emails are never shown here.

' + '
' + '' + '
' + '
' + '

Loading students...

' + '
' + '
'; var anchor = page && page.querySelector(".how-section"); if (anchor && anchor.parentNode) { anchor.parentNode.insertBefore(sec, anchor); } else if (page) { page.appendChild(sec); } else { (document.querySelector("main") || document.body).appendChild(sec); } els.chips = $("usgChips"); els.count = $("usgCount"); els.grid = $("usgGrid"); els.search = $("usgSearch"); } function renderChips() { var html = ''; Object.keys(CAT_LABELS).forEach(function (k) { html += '"; }); if (!els.chips.children.length) els.chips.innerHTML = html; els.chips.addEventListener("click", function (e) { var b = e.target.closest(".usg-chip"); if (!b) return; activeCat = b.getAttribute("data-usg"); Array.prototype.forEach.call(els.chips.querySelectorAll(".usg-chip"), function (c) { c.classList.toggle("active", c === b); }); renderGrid(); }); } function renderGrid() { var q = els.search.value.trim().toLowerCase(); var list = students.filter(function (s) { var catOk = activeCat === "all" || s.category === activeCat; var nameOk = q === "" || String(s.name || "").toLowerCase().indexOf(q) !== -1; return catOk && nameOk; }).sort(function (a, b) { return (b.posted || 0) - (a.posted || 0); }); els.count.textContent = list.length + " student" + (list.length !== 1 ? "s" : "") + " found"; if (!list.length) { els.grid.innerHTML = '

No students match your filters yet.

'; return; } els.grid.innerHTML = list.map(function (s) { return '
' + '
' + '
' + esc(initials(s.name)) + "
" + "
" + '
' + esc(s.name) + "
" + '' + esc(catLabel(s.category)) + "" + "
" + "
" + '' + "
"; }).join(""); } function loadStudents() { els.count.textContent = "Loading students..."; api("/students").then(function (d) { if (!Array.isArray(d)) throw new Error("Invalid student data"); students = d; renderGrid(); }).catch(function (e) { console.error("Student board error:", e); els.count.textContent = "Unable to load students."; els.grid.innerHTML = ""; }); } /* ---------- message popup ---------- */ function buildModal() { // If the modal HTML is already in the page, just use it. wireModal($("usgModal") || createModalEl()); } function createModalEl() { var o = document.createElement("div"); o.className = "usg-overlay"; o.id = "usgModal"; o.setAttribute("role", "dialog"); o.setAttribute("aria-modal", "true"); o.setAttribute("aria-labelledby", "usgTitle"); o.innerHTML = '
' + '

' + '
' + '
' + "
"; document.body.appendChild(o); return o; } function wireModal(o) { els.overlay = o; els.title = $("usgTitle"); els.body = $("usgBody"); $("usgClose").addEventListener("click", closeModal); o.addEventListener("click", function (e) { if (e.target === o) closeModal(); }); document.addEventListener("keydown", function (e) { if (e.key === "Escape") closeModal(); }); } function openFor(student) { target = student; els.overlay.classList.add("show"); if (token) stepCompose(); else stepEmail(); } function closeModal() { if (els.overlay) els.overlay.classList.remove("show"); } function setStatus(msg, isErr) { var s = els.body.querySelector(".usg-status"); if (!s) return; s.textContent = msg || ""; s.className = "usg-status" + (isErr ? " err" : ""); } function busy(btn, on, label) { btn.disabled = on; btn.textContent = label; } function logout() { token = ""; teacherName = ""; store("del", TOKEN_KEY); store("del", NAME_KEY); } function stepEmail(note) { els.title.textContent = "Verify you're a teacher"; els.body.innerHTML = '

Only registered teachers can message students. Enter the email you used to register and we will send you a 6-digit code.

' + '
' + '
' + '' + '

'; if (note) setStatus(note, true); var input = $("usgEmail"), btn = $("usgSendCode"); function go() { var email = input.value.trim(); if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) { setStatus("Please enter a valid email address.", true); return; } loginEmail = email; busy(btn, true, "Sending..."); api("/teacher-login/request", { method: "POST", body: { email: email } }) .then(stepCode) .catch(function (e) { busy(btn, false, "Send code"); setStatus(e.message, true); }); } btn.addEventListener("click", go); input.addEventListener("keydown", function (e) { if (e.key === "Enter") go(); }); input.focus(); } function stepCode() { els.title.textContent = "Enter your code"; els.body.innerHTML = '

If ' + esc(loginEmail) + ' belongs to an approved teacher, a 6-digit code was just sent. It expires in 10 minutes. Please check your spam folder too.

' + '
' + '
' + '' + '

' + ''; var input = $("usgCode"), btn = $("usgVerify"); function go() { var code = input.value.replace(/\D/g, ""); if (code.length !== 6) { setStatus("Please enter the 6-digit code.", true); return; } busy(btn, true, "Verifying..."); api("/teacher-login/verify", { method: "POST", body: { email: loginEmail, code: code } }) .then(function (d) { token = d.token || ""; teacherName = d.name || ""; store("set", TOKEN_KEY, token); store("set", NAME_KEY, teacherName); stepCompose(); }) .catch(function (e) { busy(btn, false, "Verify"); setStatus(e.message, true); }); } btn.addEventListener("click", go); input.addEventListener("keydown", function (e) { if (e.key === "Enter") go(); }); $("usgBack").addEventListener("click", function (e) { e.preventDefault(); stepEmail(); }); input.focus(); } function stepCompose() { if (!target) { closeModal(); return; } els.title.textContent = "Message " + target.name; els.body.innerHTML = '
' + '
' + esc(initials(target.name)) + "
" + "
" + esc(target.name) + '' + esc(catLabel(target.category)) + "
" + "
" + '

Sending as ' + esc(teacherName || "teacher") + ' ยท Not you?

' + '
' + '' + '
0/500
' + '

The student receives this message by email from Ustaad Online, together with your name, phone and email so they can reply. The student\'s own contact details are not shown to you.

' + '' + '

'; var text = $("usgText"), btn = $("usgSend"); text.addEventListener("input", function () { $("usgLen").textContent = text.value.length; setStatus(""); }); $("usgSwitch").addEventListener("click", function (e) { e.preventDefault(); logout(); stepEmail(); }); btn.addEventListener("click", function () { var msg = text.value.trim(); if (msg.length < 10) { setStatus("Please write at least 10 characters.", true); return; } busy(btn, true, "Sending..."); api("/student-message", { method: "POST", token: token, body: { student_id: target.id, message: msg } }) .then(stepDone) .catch(function (e) { if (e.status === 401) { logout(); stepEmail("Your session expired. Please verify again."); return; } busy(btn, false, "Send message"); setStatus(e.message, true); }); }); text.focus(); } function stepDone() { els.title.textContent = "Message sent"; els.body.innerHTML = '
โœ“
' + '

Your message was emailed to ' + esc(target.name) + ". They can reply to you directly.

" + '
'; $("usgOk").addEventListener("click", closeModal); } /* ---------- init ---------- */ function build(page) { injectStyles(); buildSection(page); buildModal(); renderChips(); els.search.addEventListener("input", renderGrid); els.grid.addEventListener("click", function (e) { var b = e.target.closest(".usg-msg"); if (!b) return; var id = b.getAttribute("data-id"); var s = students.filter(function (x) { return String(x.id) === String(id); })[0]; if (s) openFor(s); }); loadStudents(); } function init() { var tries = 0; (function attempt() { var page = $("page-home"); if (!page && tries++ < 25) { setTimeout(attempt, 300); return; } build(page); })(); } if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init); else init(); })();