« Back to History
mill_master.php
|
20260921_175631.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('mill_master'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; require_once __DIR__ . '/partials/header.php'; require_once __DIR__ . '/helpers/activity_helper.php'; /* ===== SAVE / UPDATE ===== */ if($_SERVER['REQUEST_METHOD']==='POST'){ $name = trim($_POST['mill_name']); $short = trim($_POST['short_name']); $edit_id = (int)($_POST['edit_id'] ?? 0); if($name){ try{ if($edit_id > 0){ $stmt = $pdo->prepare(" UPDATE mill_master SET mill_name=:name, short_name=:short WHERE id=:id AND company_id=:cid "); $stmt->execute([ ':name'=>$name, ':short'=>$short, ':id'=>$edit_id, ':cid'=>$company_id ]); // Activity Log log_activity([ 'activity_type' => 'master', 'module_name' => 'mill_master', 'action_name' => 'update', 'activity_note' => "Updated Mill: $name ($short)", 'reference_id' => $edit_id, ]); }else{ $stmt = $pdo->prepare(" INSERT INTO mill_master (company_id, mill_name, short_name) VALUES (:cid,:name,:short) "); $stmt->execute([ ':cid'=>$company_id, ':name'=>$name, ':short'=>$short ]); // Activity Log $new_id = $pdo->lastInsertId(); log_activity([ 'activity_type' => 'master', 'module_name' => 'mill_master', 'action_name' => 'create', 'activity_note' => "Created Mill: $name ($short)", 'reference_id' => $new_id, ]); } }catch(PDOException $e){ if(($e->errorInfo[1] ?? 0)==1062){ echo "<div class='alert alert-danger'>Duplicate mill</div>"; }else{ throw $e; } } } } /* ===== EDIT FETCH ===== */ $edit = null; if(isset($_GET['edit'])){ $id = (int)$_GET['edit']; $stmt = $pdo->prepare(" SELECT * FROM mill_master WHERE id=:id AND company_id=:cid "); $stmt->execute([':id'=>$id, ':cid'=>$company_id]); $edit = $stmt->fetch(PDO::FETCH_ASSOC); } /* ===== LIST ===== */ $rows = $pdo->prepare(" SELECT * FROM mill_master WHERE company_id=:cid ORDER BY id DESC "); $rows->execute([':cid'=>$company_id]); $rows = $rows->fetchAll(PDO::FETCH_ASSOC); ?> <div class="container mt-4"> <div class="card p-3"> <h4>Mill Master</h4> <form method="post" class="row g-3 mb-3"> <input type="hidden" name="edit_id" value="<?= $edit['id'] ?? '' ?>"> <div class="col-md-5"> <input type="text" name="mill_name" class="form-control" placeholder="Mill Name" value="<?= htmlspecialchars($edit['mill_name'] ?? '') ?>" required> </div> <div class="col-md-3"> <input type="text" name="short_name" class="form-control" placeholder="Short Name" value="<?= htmlspecialchars($edit['short_name'] ?? '') ?>"> </div> <div class="col-md-2"> <button class="btn btn-primary w-100"><?= $edit ? 'Update' : 'Add' ?></button> </div> <div class="col-md-2"> <?php if($edit): ?> <a href="?" class="btn btn-secondary w-100">Cancel</a> <?php endif; ?> </div> </form> <div class="table-responsive"> <table class="table table-bordered table-sm"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Short</th> <th>Status</th> <th>Action</th> </tr> </thead> <tbody> <?php foreach($rows as $r): ?> <tr> <td><?= $r['id'] ?></td> <td><?= htmlspecialchars($r['mill_name']) ?></td> <td><?= htmlspecialchars($r['short_name']) ?></td> <td><?= $r['is_active'] ? 'Active' : 'Inactive' ?></td> <td><a href="?edit=<?= $r['id'] ?>" class="btn btn-sm btn-warning">Edit</a></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>