« Back to History
daily_folding_entry_edit.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================ File: daily_folding_entry_edit.php Purpose: Edit Folding Entry Scope: Company scoped, NO global edits ============================================================================ */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('daily_folding_entry_edit'); $pdo = $ctx['pdo'] ?? null; $company_id = (int)($ctx['company_id'] ?? 0); $user_id = (int)($ctx['user']['id'] ?? 0); if (!$pdo) require_once __DIR__ . '/core/db.php'; require_once __DIR__ . '/helpers/activity_helper.php'; /* ================= HELPERS ================= */ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ================= GET ID ================= */ $id = isset($_GET['id']) ? (int)$_GET['id'] : 0; if ($id <= 0) { die("Invalid ID"); } /* ================= FETCH ENTRY ================= */ $stmt = $pdo->prepare(" SELECT * FROM folding_entry WHERE id = :id AND company_id = :cid LIMIT 1 "); $stmt->execute([ ':id' => $id, ':cid' => $company_id ]); $entry = $stmt->fetch(PDO::FETCH_ASSOC); if (!$entry) { die("Entry not found."); } /* ================= FETCH DROPDOWNS ================= */ $qualities = $pdo->prepare(" SELECT id, quality_name FROM qualities WHERE company_id = :cid AND is_active = 1 ORDER BY quality_name ASC "); $qualities->execute([':cid' => $company_id]); $qualities = $qualities->fetchAll(PDO::FETCH_ASSOC); $khatas = $pdo->prepare(" SELECT id, name FROM khatas WHERE company_id = :cid AND is_active = 1 ORDER BY name ASC "); $khatas->execute([':cid' => $company_id]); $khatas = $khatas->fetchAll(PDO::FETCH_ASSOC); /* ================= CSRF ================= */ if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } /* ================= HANDLE UPDATE ================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'] ?? '')) { die("Invalid CSRF token"); } $entry_date = $_POST['entry_date'] ?? null; $folder_id = (int)($_POST['folder_id'] ?? 0); $khata_id = (int)($_POST['khata_id'] ?? 0); $quality_id = (int)($_POST['quality_id'] ?? 0); $total_taka = (int)($_POST['total_taka'] ?? 0); $total_meter = (float)($_POST['total_meter'] ?? 0); $total_saree = (int)($_POST['total_saree'] ?? 0); $total_weight = (float)($_POST['total_weight'] ?? 0); $remark = trim($_POST['remark'] ?? ''); $upd = $pdo->prepare(" UPDATE folding_entry SET entry_date = :entry_date, folder_id = :folder_id, khata_id = :khata_id, quality_id = :quality_id, total_taka = :total_taka, total_meter = :total_meter, total_saree = :total_saree, total_weight = :total_weight, remark = :remark WHERE id = :id AND company_id = :cid LIMIT 1 "); $upd->execute([ ':entry_date' => $entry_date, ':folder_id' => $folder_id, ':khata_id' => $khata_id, ':quality_id' => $quality_id, ':total_taka' => $total_taka, ':total_meter' => $total_meter, ':total_saree' => $total_saree, ':total_weight' => $total_weight, ':remark' => $remark, ':id' => $id, ':cid' => $company_id ]); activity_update('production', 'folding_entry_update', $id, 'Updated folding entry'); header("Location: daily_folding_entry_list.php?updated=1"); exit; } require_once __DIR__ . '/partials/header.php'; ?> <div class="card"> <div class="card-header"> <h5>Edit Folding Entry</h5> </div> <div class="card-body"> <form method="post"> <input type="hidden" name="csrf_token" value="<?= h($_SESSION['csrf_token']) ?>"> <div class="form-grid"> <div> <label>Entry Date</label> <input type="date" name="entry_date" class="form-control" value="<?= h($entry['entry_date']) ?>" required> </div> <div> <label>Folder ID</label> <input type="number" name="folder_id" class="form-control" value="<?= h($entry['folder_id']) ?>" required> </div> <div> <label>Khata</label> <select name="khata_id" class="form-control" required> <option value="">Select</option> <?php foreach ($khatas as $k): ?> <option value="<?= $k['id'] ?>" <?= $k['id']==$entry['khata_id']?'selected':'' ?>> <?= h($k['name']) ?> </option> <?php endforeach; ?> </select> </div> <div> <label>Quality</label> <select name="quality_id" class="form-control" required> <option value="">Select</option> <?php foreach ($qualities as $q): ?> <option value="<?= $q['id'] ?>" <?= $q['id']==$entry['quality_id']?'selected':'' ?>> <?= h($q['quality_name']) ?> </option> <?php endforeach; ?> </select> </div> <div> <label>Total Taka</label> <input type="number" name="total_taka" class="form-control" value="<?= h($entry['total_taka']) ?>"> </div> <div> <label>Total Meter</label> <input type="number" step="0.01" name="total_meter" class="form-control" value="<?= h($entry['total_meter']) ?>"> </div> <div> <label>Total Saree</label> <input type="number" name="total_saree" class="form-control" value="<?= h($entry['total_saree']) ?>"> </div> <div> <label>Total Weight</label> <input type="number" step="0.01" name="total_weight" class="form-control" value="<?= h($entry['total_weight']) ?>"> </div> <div style="grid-column: span 2;"> <label>Remark</label> <textarea name="remark" class="form-control"><?= h($entry['remark']) ?></textarea> </div> </div> <div class="mt-3"> <button type="submit" class="btn btn-primary"> Update Entry </button> <a href="daily_folding_entry_list.php" class="btn btn-secondary"> Cancel </a> </div> </form> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>