« Back to History
karigar_mobile_update.php
|
20260721_154032.php
Initial Bulk Import
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('karigar_mobile_update'); $pdo = $ctx['pdo'] ?? null; $company_id = (int)($ctx['company_id'] ?? 0); if (!$pdo) { require_once __DIR__ . '/core/db.php'; $pdo = $GLOBALS['pdo']; } function h($value) { return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); } $msg = ''; $msg_type = 'success'; /* ── POST Handler: Update Mobile & Password ── */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_karigar'])) { $karigar_id = (int)($_POST['karigar_id'] ?? 0); $mobile = trim($_POST['mobile'] ?? ''); if ($karigar_id > 0 && strlen($mobile) >= 10) { try { $pdo->beginTransaction(); // Password by default 12345678 $st = $pdo->prepare("UPDATE loom_karigar_master SET mobile = ?, password = ? WHERE id = ? AND company_id = ?"); $st->execute([$mobile, '12345678', $karigar_id, $company_id]); $pdo->commit(); $msg = "Mobile number updated successfully!"; } catch (Exception $e) { $pdo->rollBack(); $msg = "Error: " . $e->getMessage(); $msg_type = 'danger'; } } else { $msg = "Valid mobile number (10 digits) aur Karigar select karein."; $msg_type = 'danger'; } } /* ── Fetch Khatas for Dropdown ── */ $kh_st = $pdo->prepare("SELECT id, name, code FROM khatas WHERE company_id = ? AND is_active = 1 ORDER BY name"); $kh_st->execute([$company_id]); $khatas = $kh_st->fetchAll(PDO::FETCH_ASSOC); /* ── Fetch ALL Karigars (for JS filtering) ── */ $kg_st = $pdo->prepare("SELECT id, khata_id, karigar_name, machine_from, machine_to, mobile FROM loom_karigar_master WHERE company_id = ? ORDER BY karigar_name"); $kg_st->execute([$company_id]); $all_karigars = $kg_st->fetchAll(PDO::FETCH_ASSOC); require_once __DIR__ . '/partials/header.php'; ?> <div class="container-fluid mt-3" style="max-width: 600px;"> <div class="card shadow-sm border-0"> <div class="card-header bg-dark text-white py-3"> <h6 class="mb-0 fw-bold">Update Karigar Mobile No.</h6> </div> <div class="card-body p-4"> <?php if ($msg): ?> <div class="alert alert-<?= $msg_type ?> py-2 small"><?= htmlspecialchars($msg) ?></div> <?php endif; ?> <form method="POST" autocomplete="off"> <!-- 1. Khata Selection --> <div class="mb-3"> <label class="form-label small fw-bold">1. Khata Select Karein</label> <select id="khata_sel" class="form-select" onchange="filterKarigars()"> <option value="">-- Select Khata --</option> <?php foreach($khatas as $k): ?> <option value="<?= $k['id'] ?>"><?= h($k['name']) ?> (<?= h($k['code']) ?>)</option> <?php endforeach; ?> </select> </div> <!-- 2. Karigar Selection --> <div class="mb-3"> <label class="form-label small fw-bold">2. Karigar Name</label> <select name="karigar_id" id="karigar_sel" class="form-select" onchange="showDetails()" disabled required> <option value="">-- Pehle Khata Chunein --</option> </select> </div> <!-- 3. Detail Display Area --> <div id="detail_box" class="alert alert-light border d-none mb-3 py-2"> <div class="small"><strong>Machine Range:</strong> <span id="m_range">-</span></div> <div class="small"><strong>Current Mobile:</strong> <span id="curr_mob">-</span></div> </div> <!-- 4. Mobile Update Input --> <div class="mb-4"> <label class="form-label small fw-bold text-primary">Enter New Mobile Number</label> <input type="number" name="mobile" class="form-control form-control-lg" placeholder="10 Digit No." required maxlength="10"> <div class="form-text small">Password automatic <b>12345678</b> set ho jayega.</div> </div> <button type="submit" name="update_karigar" class="btn btn-primary w-100 fw-bold py-2 shadow-sm"> UPDATE MOBILE </button> </form> </div> </div> </div> <script> const karigars = <?= json_encode($all_karigars) ?>; function filterKarigars() { const khataId = document.getElementById('khata_sel').value; const kgSel = document.getElementById('karigar_sel'); const detailBox = document.getElementById('detail_box'); kgSel.innerHTML = '<option value="">-- Select Karigar --</option>'; detailBox.classList.add('d-none'); if (!khataId) { kgSel.disabled = true; return; } const filtered = karigars.filter(k => k.khata_id == khataId); filtered.forEach(k => { const opt = document.createElement('option'); opt.value = k.id; opt.textContent = k.karigar_name; kgSel.appendChild(opt); }); kgSel.disabled = false; } function showDetails() { const kgId = document.getElementById('karigar_sel').value; const detailBox = document.getElementById('detail_box'); if (!kgId) { detailBox.classList.add('d-none'); return; } const kg = karigars.find(k => k.id == kgId); if (kg) { document.getElementById('m_range').innerText = `${kg.machine_from} to ${kg.machine_to}`; document.getElementById('curr_mob').innerText = kg.mobile || 'Not Set'; detailBox.classList.remove('d-none'); } } </script> <?php require_once __DIR__ . '/partials/footer.php'; ?>