« Back to History
pages_check.php
|
20260920_164915.php
Initial Domain Snapshot
Copy Code
<?php // erp/pages_check.php // ----- CONFIG ----- $erpDir = __DIR__; // agar aap chahte ho ki koi aur folder scan ho to yahan full path de do $saveFile = __DIR__ . '/pages_header_status.json'; // persistent storage // ---- helper: load/save ---- function load_status($file) { if (!file_exists($file)) return []; $json = file_get_contents($file); $arr = json_decode($json, true); return is_array($arr) ? $arr : []; } function save_status($file, $data) { file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT)); } // ---- handle AJAX JSON save ---- $raw = file_get_contents('php://input'); if ($raw) { // try parse JSON body (AJAX saves) $body = json_decode($raw, true); if (!empty($body) && isset($body['action']) && $body['action'] === 'save_status' && isset($body['data'])) { $existing = load_status($saveFile); // merge/replace with incoming foreach ($body['data'] as $k => $v) { // normalize: accept 'done','pending','not_required' $existing[$k] = $v; } save_status($saveFile, $existing); header('Content-Type: application/json'); echo json_encode(['ok' => true]); exit; } // export request if (!empty($body) && isset($body['action']) && $body['action'] === 'export') { $existing = load_status($saveFile); header('Content-Type: application/json'); header('Content-Disposition: attachment; filename="pages_header_status.json"'); echo json_encode($existing, JSON_PRETTY_PRINT); exit; } } // ---- If normal POST fallback (not required, but kept) ---- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fallback_save'])) { $incoming = $_POST['status'] ?? []; $mapped = []; foreach ($incoming as $file => $state) { $mapped[$file] = $state; // state expected as done/pending/not_required } save_status($saveFile, $mapped); $message = "Saved (fallback)."; } // ---- scan ERP folder recursively for php files ---- $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($erpDir)); $files = []; foreach ($rii as $fileinfo) { if ($fileinfo->isDir()) continue; if (pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION) !== 'php') continue; // skip this script itself if (realpath($fileinfo->getPathname()) === realpath(__FILE__)) continue; // relative path from erp dir $rel = ltrim(str_replace($erpDir, '', $fileinfo->getPathname()), '/\\'); $files[] = $rel; } sort($files); // load saved statuses $saved = load_status($saveFile); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>ERP - Header Status Manager</title> <style> body{font-family: Arial, sans-serif; padding:18px; background:#fafafa;} h1{margin-bottom:6px;} .topbar{display:flex; gap:12px; align-items:center; margin-bottom:12px; flex-wrap:wrap;} select, button {padding:8px 10px; border-radius:6px; border:1px solid #ccc;} .filter-btn {cursor:pointer; background:#fff;} table{width:100%; border-collapse:collapse; box-shadow:0 1px 3px rgba(0,0,0,0.05);} th,td{padding:10px; border-bottom:1px solid #eee; text-align:left; font-size:14px;} th{background:#f7f7f7; position:sticky; top:0;} tr.done{opacity:0.25; transform:translateX(6px); transition:all .2s ease;} tr.not_required{background:#fff7d6;} tr.pending{opacity:1;} tr:hover{background:#fcfcfc;} .state-select{padding:6px 8px; border-radius:5px; border:1px solid #ccc;} .msg{padding:8px; background:#e2ffe2; border:1px solid #a3e6a3; display:inline-block; margin-bottom:8px;} .small{font-size:12px; color:#666;} .controls{margin-left:auto; display:flex; gap:8px;} .export-btn{background:#2d7de0; color:white; border:none; padding:8px 12px; border-radius:6px; cursor:pointer;} .clear-fade{opacity:1 !important; transform:none !important;} .file-link{font-family:monospace; color:#333; text-decoration:none;} .tag{display:inline-block; padding:4px 8px; border-radius:12px; font-size:12px; border:1px solid #ddd; background:#fff;} </style> </head> <body> <h1>ERP Pages — Header Status Manager</h1> <div class="topbar"> <div> <label class="small">Filter:</label> <select id="filter"> <option value="all">All</option> <option value="pending">Pending</option> <option value="done">Done</option> <option value="not_required">Not Required</option> </select> </div> <div style="display:flex; gap:8px; align-items:center;"> <label class="small">Quick set visible to:</label> <select id="quick_set"> <option value="">— choose —</option> <option value="done">Mark visible as Done</option> <option value="pending">Mark visible as Pending</option> <option value="not_required">Mark visible as Not Required</option> </select> <button id="apply_quick" class="filter-btn">Apply</button> </div> <div class="controls"> <button id="export" class="export-btn">Export JSON</button> <button id="refresh" class="filter-btn">Refresh</button> </div> </div> <?php if (!empty($message)): ?> <div class="msg"><?php echo htmlspecialchars($message); ?></div> <?php endif; ?> <table id="files_table"> <thead> <tr> <th style="width:55%;">File</th> <th style="width:25%;">Status</th> <th style="width:20%;">Preview / Actions</th> </tr> </thead> <tbody> <?php foreach ($files as $f): $state = $saved[$f] ?? 'pending'; // default pending $rowClass = $state === 'done' ? 'done' : ($state === 'not_required' ? 'not_required' : 'pending'); ?> <tr data-file="<?php echo htmlspecialchars($f); ?>" class="<?php echo $rowClass; ?>"> <td> <a class="file-link" href="<?php echo htmlspecialchars('/erp/' . $f); ?>" target="_blank"><?php echo htmlspecialchars($f); ?></a> </td> <td> <select class="state-select"> <option value="done" <?php echo $state==='done'?'selected':''; ?>>Done (has header)</option> <option value="pending" <?php echo $state==='pending'?'selected':''; ?>>Pending</option> <option value="not_required" <?php echo $state==='not_required'?'selected':''; ?>>Not Required</option> </select> </td> <td> <span class="tag">State: <strong class="current-state"><?php echo $state; ?></strong></span> <button class="open-btn" onclick="window.open('/erp/<?php echo rawurlencode($f); ?>','_blank')">Open</button> </td> </tr> <?php endforeach; ?> </tbody> </table> <script> (function(){ // utility function qs(sel, ctx){ return (ctx||document).querySelector(sel); } function qsa(sel, ctx){ return Array.from((ctx||document).querySelectorAll(sel)); } const rows = qsa('#files_table tbody tr'); const saveUrl = location.pathname; // same page handles AJAX let debounceTimer = null; // collect current state object from DOM function collectStates() { const data = {}; qsa('#files_table tbody tr').forEach(tr => { const file = tr.getAttribute('data-file'); const sel = tr.querySelector('.state-select'); if (!file || !sel) return; data[file] = sel.value; }); return data; } // update row class / label based on selection function applyRowState(tr, state) { tr.classList.remove('done','pending','not_required'); tr.classList.add(state === 'done' ? 'done' : (state === 'not_required' ? 'not_required' : 'pending')); const lbl = tr.querySelector('.current-state'); if (lbl) lbl.textContent = state; } // save via fetch (AJAX) function saveStates(partialData) { const payload = { action:'save_status', data: partialData }; fetch(saveUrl, { method:'POST', body: JSON.stringify(payload), headers: {'Content-Type':'application/json'} }).then(r=>r.json()).then(j=>{ // optional visual feedback // console.log('saved', j); }).catch(e=>{ console.error('Save failed', e); }); } // attach change listeners to selects qsa('.state-select').forEach(sel=>{ sel.addEventListener('change', e=>{ const tr = sel.closest('tr'); const file = tr.getAttribute('data-file'); const state = sel.value; applyRowState(tr, state); // save only this file (partial) saveStates({ [file]: state }); }); }); // filter dropdown qs('#filter').addEventListener('change', e=>{ const v = e.target.value; qsa('#files_table tbody tr').forEach(tr=>{ if (v === 'all') { tr.style.display = ''; return; } if (tr.classList.contains(v)) tr.style.display = ''; else tr.style.display = 'none'; }); }); // quick set: mark all visible rows to chosen state qs('#apply_quick').addEventListener('click', ()=>{ const mode = qs('#quick_set').value; if (!mode) return alert('Choose a Quick action first.'); const visible = qsa('#files_table tbody tr').filter(tr => tr.style.display !== 'none'); const batch = {}; visible.forEach(tr=>{ const file = tr.getAttribute('data-file'); const sel = tr.querySelector('.state-select'); sel.value = mode; applyRowState(tr, mode); batch[file] = mode; }); // save batch if (Object.keys(batch).length) saveStates(batch); }); // export qs('#export').addEventListener('click', ()=>{ // POST {action:export} and open response as download fetch(saveUrl, { method:'POST', body: JSON.stringify({action:'export'}), headers: {'Content-Type':'application/json'} }).then(r => r.blob()) .then(blob => { const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'pages_header_status.json'; document.body.appendChild(a); a.click(); a.remove(); URL.revokeObjectURL(url); }); }); // refresh: just reload page qs('#refresh').addEventListener('click', ()=> location.reload()); // keyboard: filter shortcuts (optional) document.addEventListener('keydown', function(e){ if (e.key === '1') qs('#filter').value = 'all'; if (e.key === '2') qs('#filter').value = 'pending'; if (e.key === '3') qs('#filter').value = 'done'; if (e.key === '4') qs('#filter').value = 'not_required'; qs('#filter').dispatchEvent(new Event('change')); }); })(); </script> <!-- fallback simple form in case JS disabled --> <noscript> <div style="margin-top:12px;padding:10px;background:#fff3cd;border:1px solid #ffeeba;"> JavaScript disabled — use fallback save button below. (Page still usable but not interactive.) </div> <form method="post"> <input type="hidden" name="fallback_save" value="1"> <table> <?php foreach ($files as $f): $state = $saved[$f] ?? 'pending'; ?> <tr> <td><?php echo htmlspecialchars($f); ?></td> <td> <select name="status[<?php echo htmlspecialchars($f); ?>]"> <option value="done" <?php echo $state==='done'?'selected':''; ?>>Done</option> <option value="pending" <?php echo $state==='pending'?'selected':''; ?>>Pending</option> <option value="not_required" <?php echo $state==='not_required'?'selected':''; ?>>Not Required</option> </select> </td> </tr> <?php endforeach; ?> </table> <button type="submit" style="margin-top:10px;padding:8px 12px;">Save (fallback)</button> </form> </noscript> </body> </html>