{"id":105,"date":"2026-03-10T18:22:28","date_gmt":"2026-03-10T18:22:28","guid":{"rendered":"https:\/\/testsbombers.com\/?page_id=105"},"modified":"2026-03-12T14:44:30","modified_gmt":"2026-03-12T14:44:30","slug":"afegir-preguntes","status":"publish","type":"page","link":"https:\/\/testsbombers.com\/?page_id=105","title":{"rendered":"Afegir preguntes"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">Introdu\u00efu preguntes que tinguin sentit i que no siguin fumades. Si \u00e9s alguna cosa massa fora de temari, pot ser que no s\u2019accepti. Es poden posar tantes respostes com volgueu per pregunta.<\/h5>\n\n\n\n<p class=\"has-text-align-center\">\u00a1\u00a1No poseu respostes com &#8220;La resposta a) i b) s\u00f3n correctes&#8221; ja que la app barreja les respostes!!<\/p>\n\n\n    <div id=\"formulari-pregunta-opo\" style=\"\n        max-width:800px;\n        margin:40px auto;\n        padding:25px;\n        background:#fff;\n        border-radius:8px;\n        box-shadow:0 2px 8px rgba(0,0,0,0.08);\n        box-sizing:border-box;\n    \">\n        <form id=\"opoForm\" method=\"post\" style=\"width:100%; margin:0;\">\n\n<div id=\"missatgeFormulari\" style=\"display:none; margin-top:15px; padding:10px; border-radius:4px;\"><\/div>\n\n            <div style=\"display:flex; gap:10px; align-items:end; margin-bottom:20px; width:100%;\">\n                <div style=\"flex:1;\">\n                    <label for=\"opo_tema\" style=\"display:block; margin-bottom:6px;\"><strong>Tema *<\/strong><\/label>\n                    <select id=\"opo_tema\" name=\"tema\" required style=\"display:block; width:100%; max-width:none; box-sizing:border-box;\">\n                        <option value=\"\">Selecciona un tema<\/option>\n\n                               <option value=\"5\">\n        Tema 1 Constituci\u00f3 espa\u00f1ola i estatut d&#039;autonomia (4)    <\/option>\n        <option value=\"6\">\n        Tema 2 Personal al servei de les administracions p\u00fabliques (7)    <\/option>\n        <option value=\"7\">\n        Tema 3 Llei 31\/95 Prevenci\u00f3 riscos laborals (7)    <\/option>\n        <option value=\"8\">\n        Tema 4 Llei 19\/20 d&#039;igualtat de tracte i no discriminaci\u00f3 (5)    <\/option>\n        <option value=\"9\">\n        Tema 5 Llei 17\/15 d&#039;igualtat efectiva de dones i homes (3)    <\/option>\n        <option value=\"10\">\n        Tema 6 Llei 5\/94 dels SPEIS i Llei 4\/97 de Protecci\u00f3 civil (4)    <\/option>\n        <option value=\"11\">\n        Tema 7 Funcions de gu\u00e0rdia i SisCom. Departament d&#039;interior (9)    <\/option>\n        <option value=\"12\">\n        Tema 8 F\u00edsica (15)    <\/option>\n        <option value=\"13\">\n        Tema 9 Naturalesa del foc (7)    <\/option>\n        <option value=\"14\">\n        Tema 10 Metodes i agents extintors (9)    <\/option>\n        <option value=\"15\">\n        Tema 11 Qu\u00edmica (13)    <\/option>\n        <option value=\"16\">\n        Tema 12 Hidr\u00e0ulica (9)    <\/option>\n        <option value=\"17\">\n        Tema 13 Electricitat i magnituds el\u00e8ctriques (7)    <\/option>\n        <option value=\"18\">\n        Tema 14 Meteorologia (7)    <\/option>\n        <option value=\"19\">\n        Tema 15 Conceptes m\u00e8dics b\u00e0sics (17)    <\/option>\n        <option value=\"20\">\n        Tema 16 Vegetaci\u00f3 (4)    <\/option>\n        <option value=\"21\">\n        Tema 17 Mec\u00e0nica (9)    <\/option>\n        <option value=\"22\">\n        Tema 18 Motors (8)    <\/option>\n        <option value=\"23\">\n        Tema 19 Fluids (7)    <\/option>\n        <option value=\"24\">\n        Tema 20 Mec\u00e0nica de vehicles (2)    <\/option>\n        <option value=\"4\">\n        Tema 21 Risc Qu\u00edmic (83)    <\/option>\n        <option value=\"25\">\n        Tema 22 Protecci\u00f3 activa i pasiva (6)    <\/option>\n        <option value=\"26\">\n        Tema 23 Atenci\u00f3 sanitaria (29)    <\/option>\n        <option value=\"27\">\n        Tema 24 Materials de construcci\u00f3 (14)    <\/option>\n        <option value=\"28\">\n        Tema 25 Construcci\u00f3 i edificaci\u00f3 (31)    <\/option>\n        <option value=\"29\">\n        Tema 26 Components i aparells electrics (5)    <\/option>\n        <option value=\"36\">\n        Tema 27 Instal\u00b7lacions el\u00e8ctriques (91)    <\/option>\n        <option value=\"31\">\n        Tema 28 Instal\u00b7lacions de gas (7)    <\/option>\n        <option value=\"32\">\n        Tema 29 Cartografia (4)    <\/option>\n        <option value=\"33\">\n        Tema 30 Geografia (9)    <\/option>\n        <option value=\"34\">\n        Tema 31 Geografia humana (8)    <\/option>\n        <option value=\"35\">\n        Tema 32 Organitzaci\u00f3 administrativa (2)    <\/option>\n                    <\/select>\n                <\/div>\n\n                <div style=\"flex:0 0 auto;\">\n                    <button type=\"button\" id=\"netejarCamps\">\n                        Netejar camps\n                    <\/button>\n                <\/div>\n            <\/div>\n\n            <div style=\"margin-bottom:15px; width:100%;\">\n                <label for=\"opo_pregunta\" style=\"display:block; margin-bottom:6px;\"><strong>Introduir pregunta *<\/strong><\/label>\n                <textarea id=\"opo_pregunta\" name=\"pregunta\" required style=\"display:block; width:100%; max-width:none; min-height:100px; box-sizing:border-box;\"><\/textarea>\n            <\/div>\n\n            <div style=\"margin-bottom:10px; width:100%;\">\n                <strong>Respostes *<\/strong>\n            <\/div>\n\n            <div id=\"respostesFrontend\" style=\"width:100%;\">\n                <div class=\"resposta-item\" style=\"display:flex; gap:10px; align-items:center; margin-bottom:10px; width:100%;\">\n                    <input type=\"text\" name=\"respostes[]\" style=\"flex:1 1 auto; width:100%; max-width:none; min-width:0; box-sizing:border-box;\" placeholder=\"Resposta\" required>\n                    <label style=\"white-space:nowrap; flex:0 0 auto;\">\n                        <input type=\"radio\" name=\"correcta\" value=\"0\" required>\n                        Correcta\n                    <\/label>\n                <\/div>\n            <\/div>\n\n            <div style=\"margin-bottom:20px; width:100%;\">\n                <button type=\"button\" id=\"afegirRespostaFrontend\">+ Afegir una altra resposta<\/button>\n            <\/div>\n\n            <div style=\"margin-bottom:15px; width:100%;\">\n                <label for=\"opo_explicacio\" style=\"display:block; margin-bottom:6px;\"><strong>Explicaci\u00f3<\/strong><\/label>\n                <textarea id=\"opo_explicacio\" name=\"explicacio\" style=\"display:block; width:100%; max-width:none; min-height:120px; box-sizing:border-box;\"><\/textarea>\n                <div style=\"font-size:12px; color:#666; margin-top:4px;\">Opcional<\/div>\n            <\/div>\n\n            <div style=\"margin-top:20px;\">\n                <button type=\"submit\" id=\"enviarPreguntaBtn\">Enviar pregunta<\/button>\n            <\/div>\n\n        <\/form>\n    <\/div>\n\n    <script>\n    (function(){\n        const form = document.getElementById('opoForm');\n        const respostesBox = document.getElementById('respostesFrontend');\n        const afegirBtn = document.getElementById('afegirRespostaFrontend');\n        const netejarBtn = document.getElementById('netejarCamps');\n        const missatgeBox = document.getElementById('missatgeFormulari');\n        const temaSelect = document.getElementById('opo_tema');\n        const submitBtn = document.getElementById('enviarPreguntaBtn');\n\n        if (!form) return;\n\n        function escapeHtml(str) {\n            return String(str)\n                .replace(\/&\/g, '&amp;')\n                .replace(\/\"\/g, '&quot;')\n                .replace(\/<\/g, '&lt;')\n                .replace(\/>\/g, '&gt;');\n        }\n\n        function actualitzarIndexosRadios() {\n            const items = respostesBox.querySelectorAll('.resposta-item');\n            items.forEach((item, index) => {\n                const radio = item.querySelector('input[type=\"radio\"]');\n                if (radio) {\n                    radio.value = index;\n                }\n            });\n        }\n\n        function crearResposta(value = '', checked = false) {\n            const index = respostesBox.querySelectorAll('.resposta-item').length;\n\n            const fila = document.createElement('div');\n            fila.className = 'resposta-item';\n            fila.style.display = 'flex';\n            fila.style.gap = '10px';\n            fila.style.alignItems = 'center';\n            fila.style.marginBottom = '10px';\n            fila.style.width = '100%';\n\n            fila.innerHTML = `\n                <input type=\"text\" name=\"respostes[]\" style=\"flex:1 1 auto; width:100%; max-width:none; min-width:0; box-sizing:border-box;\" placeholder=\"Resposta\" value=\"${escapeHtml(value)}\" required>\n                <label style=\"white-space:nowrap; flex:0 0 auto;\">\n                    <input type=\"radio\" name=\"correcta\" value=\"${index}\" ${checked ? 'checked' : ''} required>\n                    Correcta\n                <\/label>\n                <button type=\"button\" class=\"eliminarResposta\">\u00d7<\/button>\n            `;\n\n            respostesBox.appendChild(fila);\n            actualitzarIndexosRadios();\n        }\n\n        afegirBtn.addEventListener('click', function(){\n            crearResposta();\n        });\n\n        respostesBox.addEventListener('click', function(e){\n            if (e.target.classList.contains('eliminarResposta')) {\n                const items = respostesBox.querySelectorAll('.resposta-item');\n\n                if (items.length <= 1) {\n                    alert('Has de tenir almenys una resposta.');\n                    return;\n                }\n\n                const fila = e.target.closest('.resposta-item');\n                const radio = fila.querySelector('input[type=\"radio\"]');\n                const estavaMarcada = radio && radio.checked;\n\n                fila.remove();\n                actualitzarIndexosRadios();\n\n                if (estavaMarcada) {\n                    const primerRadio = respostesBox.querySelector('input[type=\"radio\"]');\n                    if (primerRadio) primerRadio.checked = true;\n                }\n            }\n        });\n\n        netejarBtn.addEventListener('click', function(){\n            const temaActual = temaSelect.value;\n\n            form.reset();\n            temaSelect.value = temaActual;\n\n            respostesBox.innerHTML = `\n                <div class=\"resposta-item\" style=\"display:flex; gap:10px; align-items:center; margin-bottom:10px; width:100%;\">\n                    <input type=\"text\" name=\"respostes[]\" style=\"flex:1 1 auto; width:100%; max-width:none; min-width:0; box-sizing:border-box;\" placeholder=\"Resposta\" required>\n                    <label style=\"white-space:nowrap; flex:0 0 auto;\">\n                        <input type=\"radio\" name=\"correcta\" value=\"0\" required>\n                        Correcta\n                    <\/label>\n                <\/div>\n            `;\n\n            missatgeBox.style.display = 'none';\n            missatgeBox.innerHTML = '';\n        });\n\n        form.addEventListener('submit', function(e){\n            e.preventDefault();\n\n            const tema = temaSelect.value.trim();\n            const pregunta = document.getElementById('opo_pregunta').value.trim();\n            const respostes = Array.from(form.querySelectorAll('input[name=\"respostes[]\"]'))\n                .map(el => el.value.trim())\n                .filter(Boolean);\n            const correcta = form.querySelector('input[name=\"correcta\"]:checked');\n            const explicacio = document.getElementById('opo_explicacio').value.trim();\n\n            if (!tema) {\n                mostrarMissatge('Has de seleccionar un tema.', true);\n                return;\n            }\n\n            if (!pregunta) {\n                mostrarMissatge('Has d\\'introduir una pregunta.', true);\n                return;\n            }\n\n            if (respostes.length < 2) {\n                mostrarMissatge('Has d\\'afegir almenys dues respostes.', true);\n                return;\n            }\n\n            if (!correcta) {\n                mostrarMissatge('Has de marcar quina \u00e9s la resposta correcta.', true);\n                return;\n            }\n\n            submitBtn.disabled = true;\n\n            const dades = new FormData();\n            dades.append('action', 'enviar_pregunta_opo');\n            dades.append('nonce', '873a494100');\n            dades.append('tema', tema);\n            dades.append('pregunta', pregunta);\n            dades.append('correcta', correcta.value);\n            dades.append('explicacio', explicacio);\n\n            respostes.forEach(function(r){\n                dades.append('respostes[]', r);\n            });\n\n            fetch('https:\/\/testsbombers.com\/wp-admin\/admin-ajax.php', {\n                method: 'POST',\n                body: dades\n            })\n            .then(res => res.json())\n            .then(data => {\n                submitBtn.disabled = false;\n\n                if (data.success) {\n                    mostrarMissatge(data.data.message, false);\n                } else {\n                    mostrarMissatge(\n                        data.data && data.data.message ? data.data.message : 'S\\'ha produ\u00eft un error.',\n                        true\n                    );\n                }\n            })\n            .catch(() => {\n                submitBtn.disabled = false;\n                mostrarMissatge('Error d\\'enviament. Torna-ho a provar.', true);\n            });\n        });\n\n     function mostrarMissatge(text, esError) {\n    missatgeBox.style.display = 'block';\n    missatgeBox.innerHTML = text;\n\n    window.scrollTo({ top: 0, behavior: \"smooth\" });\n\n    missatgeBox.style.background = esError ? '#fbeaea' : '#e7f7e7';\n    missatgeBox.style.color = esError ? '#9b1c1c' : '#1f5f1f';\n    missatgeBox.style.border = esError ? '1px solid #e0a4a4' : '1px solid #9ed39e';\n\n    setTimeout(() => {\n        missatgeBox.style.display = 'none';\n        missatgeBox.innerHTML = '';\n    }, 4000);\n}\n    })();\n    <\/script>\n    \n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introdu\u00efu preguntes que tinguin sentit i que no siguin fumades. Si \u00e9s alguna cosa massa fora de temari, pot ser que no s\u2019accepti. Es poden posar tantes respostes com volgueu per pregunta. \u00a1\u00a1No poseu respostes com &#8220;La resposta a) i b) s\u00f3n correctes&#8221; ja que la app barreja les respostes!!<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-105","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/testsbombers.com\/index.php?rest_route=\/wp\/v2\/pages\/105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/testsbombers.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/testsbombers.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/testsbombers.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/testsbombers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=105"}],"version-history":[{"count":5,"href":"https:\/\/testsbombers.com\/index.php?rest_route=\/wp\/v2\/pages\/105\/revisions"}],"predecessor-version":[{"id":535,"href":"https:\/\/testsbombers.com\/index.php?rest_route=\/wp\/v2\/pages\/105\/revisions\/535"}],"wp:attachment":[{"href":"https:\/\/testsbombers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}