{"id":1185,"date":"2026-06-26T19:44:20","date_gmt":"2026-06-26T19:44:20","guid":{"rendered":"https:\/\/ph-taskportal.zyneventures.com\/?page_id=1185"},"modified":"2026-06-26T21:08:22","modified_gmt":"2026-06-26T21:08:22","slug":"import-assignment","status":"publish","type":"page","link":"https:\/\/ph-portal-v2.zyneventures.com\/index.php\/import-assignment\/","title":{"rendered":"Import assignment"},"content":{"rendered":"\n<style>\n    \/* PHP layouts.app + importData.blade.php + public\/assets\/css\/style.css *\/\n    .import-submitted-page {\n        font-family: 'Sora', sans-serif;\n        color: #2C2F4B;\n        background: transparent;\n    }\n\n    .import-submitted-page h1,\n    .import-submitted-page h2,\n    .import-submitted-page h3,\n    .import-submitted-page h4,\n    .import-submitted-page h5,\n    .import-submitted-page h6 {\n        font-weight: 500;\n    }\n\n    .import-submitted-page .page-body.patient-book {\n        min-height: calc(100vh - 70px);\n        position: relative;\n    }\n\n    .import-submitted-page .container-fluid {\n        width: 100%;\n        padding-right: 15px;\n        padding-left: 15px;\n        margin-right: auto;\n        margin-left: auto;\n    }\n\n    .import-submitted-page .login-box-wrap {\n        width: 100%;\n        display: block;\n        padding: 1.5rem !important;\n    }\n\n    .import-submitted-page .login-main {\n        width: 100%;\n    }\n\n    .import-submitted-page h4.mb-4 {\n        margin-bottom: 1.5rem;\n        font-size: 1.5rem;\n        font-weight: 500;\n        color: #2C2F4B;\n        line-height: 1.2;\n    }\n\n    .import-submitted-page h4.mb-4::after {\n        content: \"\";\n        display: table;\n        clear: both;\n    }\n\n    .import-submitted-page h4.mb-4 .import-download-wrap {\n        float: right;\n    }\n\n    .import-submitted-page .cbtn {\n        font-size: 12px !important;\n        min-width: 120px;\n        height: 38px;\n        padding: 6px 12px;\n        display: inline-flex;\n        align-items: center;\n        justify-content: center;\n        text-decoration: none;\n        cursor: pointer;\n        box-sizing: border-box;\n    }\n\n    .import-submitted-page .btn-action {\n        background-color: #0180FF;\n        border-radius: 6px;\n        color: #fff;\n        border: none;\n    }\n\n    .import-submitted-page .btn-action:hover {\n        color: #fff;\n        opacity: 0.8;\n    }\n\n    .import-submitted-page .btn-default {\n        background: transparent;\n        border: none;\n        color: #333;\n        box-shadow: none;\n    }\n\n    .import-submitted-page .btn-default:hover {\n        color: #999;\n        background: transparent;\n    }\n\n    .import-submitted-page .mb-3 {\n        margin-bottom: 1rem;\n    }\n\n    .import-submitted-page .form-label {\n        display: inline-block;\n        margin-bottom: 0.5rem;\n        font-size: 14px;\n        color: #2C2F4B;\n    }\n\n    .import-submitted-page .text-danger {\n        color: #dc3545;\n    }\n\n    .import-submitted-page .form-control {\n        display: block;\n        width: 100%;\n        padding: 0.375rem 0.75rem;\n        font-size: 14px;\n        font-weight: 300;\n        line-height: 1.5;\n        color: #212529;\n        background-color: #fff;\n        border: 1px solid #ECEFEF;\n        border-radius: 10px;\n        box-sizing: border-box;\n        min-height: 42px;\n    }\n\n    .import-submitted-page .form-control:focus {\n        outline: none;\n        border-color: #0180FF;\n    }\n\n    .import-submitted-page .form-control[type=\"file\"] {\n        padding: 0.375rem 0.75rem;\n    }\n\n    .import-submitted-page .form-control[type=\"file\"]::file-selector-button {\n        padding: 0.375rem 0.75rem;\n        margin-right: 0.75rem;\n        border: 1px solid #dee2e6;\n        border-radius: 6px;\n        background-color: #f8f9fa;\n        color: #212529;\n        font-size: 14px;\n        cursor: pointer;\n    }\n\n    .import-submitted-page .import-actions-row {\n        display: flex;\n        flex-wrap: wrap;\n        justify-content: flex-end;\n        margin-top: 1.5rem;\n        margin-right: 0;\n        margin-left: 0;\n        gap: 0;\n    }\n\n    .import-submitted-page .import-actions-row .col-2 {\n        flex: 0 0 auto;\n        width: 16.66666667%;\n        max-width: 16.66666667%;\n        padding: 0 12px;\n        box-sizing: border-box;\n    }\n\n    .import-submitted-page .import-actions-row .cbtn {\n        width: 100%;\n    }\n\n    .import-submitted-page .import-alert {\n        display: none;\n        margin-bottom: 16px;\n        padding: 12px 14px;\n        border-radius: 4px;\n        font-size: 14px;\n    }\n\n    .import-submitted-page .import-alert.error {\n        display: block;\n        background: #fdecea;\n        color: #b42318;\n        border: 1px solid #f5c2c0;\n    }\n\n    .import-submitted-page .import-alert.success {\n        display: block;\n        background: #e8f5e9;\n        color: #1b5e20;\n        border: 1px solid #c8e6c9;\n    }\n\n    @media (max-width: 768px) {\n        .import-submitted-page h4.mb-4 .import-download-wrap {\n            float: none;\n            display: block;\n            margin-top: 12px;\n        }\n\n        .import-submitted-page .import-actions-row .col-2 {\n            width: 50%;\n            max-width: 50%;\n        }\n    }\n<\/style>\n\n<div class=\"import-submitted-page\">\n    <div class=\"page-body patient-book\">\n        <div class=\"container-fluid\">\n            <div class=\"login-box-wrap d-block p-4\">\n                <div class=\"login-main\">\n                    <form id=\"importForm\" class=\"theme-form\" enctype=\"multipart\/form-data\">\n                        <input type=\"hidden\" name=\"isForm\" value=\"1\">\n\n                        <h4 class=\"mb-4\">\n                            Import Submitted Work Assignment Data\n                            <span class=\"import-download-wrap\">\n                                <a href=\"#\" id=\"btnSampleCsv\" class=\"btn btn-action cbtn col-4\" onclick=\"downloadSampleCSV(event)\">+Download Sample CSV<\/a>\n                            <\/span>\n                        <\/h4>\n\n                        <div id=\"importAlert\" class=\"import-alert\"><\/div>\n\n                        <div class=\"mb-3\">\n                            <label for=\"formFile\" class=\"form-label\">Upload CSV File<span class=\"text-danger\">*<\/span><\/label>\n                            <input class=\"form-control\" type=\"file\" name=\"file\" id=\"formFile\" accept=\".csv\">\n                        <\/div>\n\n                        <div class=\"import-actions-row mx-0 mt-4\">\n                            <div class=\"col-2\">\n                                <button type=\"button\" class=\"btn btn-default cbtn\" onclick=\"closeImportPage()\">Close<\/button>\n                            <\/div>\n                            <div class=\"col-2\">\n                                <button type=\"submit\" class=\"btn btn-action cbtn\" id=\"btnSave\">Save<\/button>\n                            <\/div>\n                        <\/div>\n                    <\/form>\n                <\/div>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n<script>\n    const BASE_URL = 'https:\/\/api-ph-portal.zyneventures.com\/api\/v1';\n    const ENDPOINTS = {\n        SUBMIT_IMPORT: `${BASE_URL}\/work_assignment\/import`,\n        SUBMIT_SAMPLE: `${BASE_URL}\/work_assignment\/submitted-sample-csv`,\n        SUBMITTED_LIST: 'https:\/\/ph-portal-v2.zyneventures.com\/index.php\/submitted-work-assignment\/'\n    };\n\n    const PERMISSION_TIER = (localStorage.getItem('PERMISSION_TIER') || 'none').toLowerCase();\n\n    function getUserRole() {\n        let user = {};\n        try {\n            const raw = localStorage.getItem('USER_DATA') ||\n                        localStorage.getItem('USER') ||\n                        localStorage.getItem('user_data');\n            if (raw) user = JSON.parse(raw);\n        } catch (_) {}\n        const roleRaw = user.role || localStorage.getItem('USER_ROLE') || user.user_role || '';\n        return (typeof roleRaw === 'object'\n            ? (roleRaw.name || roleRaw.role || '')\n            : roleRaw).toString().toLowerCase().trim();\n    }\n\n    function isAdministratorUser() {\n        if (PERMISSION_TIER === 'admin') return true;\n        return getUserRole() === 'administrator';\n    }\n\n    function showAlert(message, type) {\n        const el = document.getElementById('importAlert');\n        if (!el) return;\n        el.textContent = message;\n        el.className = `import-alert ${type || 'error'}`;\n    }\n\n    function clearAlert() {\n        const el = document.getElementById('importAlert');\n        if (!el) return;\n        el.textContent = '';\n        el.className = 'import-alert';\n    }\n\n    \/** PHP Close \u2014 back to submitted list *\/\n    function closeImportPage() {\n        window.location.href = ENDPOINTS.SUBMITTED_LIST;\n    }\n\n    \/** PHP download-work-assignment-submitted-sample-file *\/\n    async function downloadSampleCSV(event) {\n        event.preventDefault();\n        clearAlert();\n        try {\n            const token = localStorage.getItem('TOKEN');\n            if (!token) {\n                showAlert('You are not logged in. Please login again.');\n                return;\n            }\n            const res = await fetch(ENDPOINTS.SUBMIT_SAMPLE, {\n                method: 'GET',\n                headers: { Authorization: `Bearer ${token}` }\n            });\n            if (!res.ok) {\n                showAlert('Failed to download sample CSV.');\n                return;\n            }\n            const blob = await res.blob();\n            const objectUrl = URL.createObjectURL(blob);\n            const link = document.createElement('a');\n            link.href = objectUrl;\n            link.download = 'work-assignment.csv';\n            document.body.appendChild(link);\n            link.click();\n            document.body.removeChild(link);\n            URL.revokeObjectURL(objectUrl);\n        } catch (error) {\n            console.error('Sample CSV download error', error);\n            showAlert('Failed to download sample CSV.');\n        }\n    }\n\n    \/** PHP form POST workAssignmentSubmittedFileImport with isForm=1 \u2192 redirect submitted list *\/\n    async function submitImportForm(event) {\n        event.preventDefault();\n        clearAlert();\n\n        const fileInput = document.getElementById('formFile');\n        const file = fileInput && fileInput.files ? fileInput.files[0] : null;\n        if (!file) {\n            showAlert('Please select a CSV file.');\n            return;\n        }\n        if (!file.name.toLowerCase().endsWith('.csv')) {\n            showAlert('Please select a valid .csv file.');\n            return;\n        }\n\n        const token = localStorage.getItem('TOKEN');\n        if (!token) {\n            showAlert('You are not logged in. Please login again.');\n            return;\n        }\n\n        const btn = document.getElementById('btnSave');\n        const originalText = btn ? btn.textContent : 'Save';\n        if (btn) {\n            btn.disabled = true;\n            btn.textContent = 'Saving...';\n        }\n\n        try {\n            const formData = new FormData();\n            formData.append('file', file);\n            formData.append('isForm', '1');\n\n            const res = await fetch(ENDPOINTS.SUBMIT_IMPORT, {\n                method: 'POST',\n                headers: { Authorization: `Bearer ${token}` },\n                body: formData\n            });\n\n            let payload = null;\n            try {\n                payload = await res.json();\n            } catch (_) {\n                payload = null;\n            }\n\n            if (!res.ok) {\n                const message = payload?.message || payload?.messages?.[0] || `Failed to import CSV (HTTP ${res.status}).`;\n                showAlert(message);\n                return;\n            }\n\n            const msg = encodeURIComponent(\n                payload?.messages?.join(\" \") ||\n                    \"Submitted Work Assignment imported successfully.\",\n            );            window.location.href = `${ENDPOINTS.SUBMITTED_LIST}?success=${msg}`;\n        } catch (error) {\n            console.error('CSV import error', error);\n            showAlert('Failed to import CSV. Please try again.');\n        } finally {\n            if (btn) {\n                btn.disabled = false;\n                btn.textContent = originalText;\n            }\n        }\n    }\n\n    function initImportPage() {\n        if (!isAdministratorUser()) {\n            window.location.href = ENDPOINTS.SUBMITTED_LIST;\n            return;\n        }\n        document.getElementById('importForm').addEventListener('submit', submitImportForm);\n    }\n\n    window.onload = initImportPage;\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>Import Submitted Work Assignment Data +Download Sample CSV Upload CSV File* Close Save<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"class_list":["post-1185","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ph-portal-v2.zyneventures.com\/index.php\/wp-json\/wp\/v2\/pages\/1185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ph-portal-v2.zyneventures.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ph-portal-v2.zyneventures.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ph-portal-v2.zyneventures.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ph-portal-v2.zyneventures.com\/index.php\/wp-json\/wp\/v2\/comments?post=1185"}],"version-history":[{"count":3,"href":"https:\/\/ph-portal-v2.zyneventures.com\/index.php\/wp-json\/wp\/v2\/pages\/1185\/revisions"}],"predecessor-version":[{"id":1192,"href":"https:\/\/ph-portal-v2.zyneventures.com\/index.php\/wp-json\/wp\/v2\/pages\/1185\/revisions\/1192"}],"wp:attachment":[{"href":"https:\/\/ph-portal-v2.zyneventures.com\/index.php\/wp-json\/wp\/v2\/media?parent=1185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}