« Back to History
user_work_define.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('user_work_define'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $msg = ''; // ===== ADD ===== if (isset($_POST['add_work'])) { $fields = [ 'module_name', 'page_slug', 'action_name', 'work_label', 'work_code', 'count_type', 'is_active', 'sort_order', 'notes' ]; $data = []; foreach ($fields as $f) { $data[$f] = isset($_POST[$f]) ? trim($_POST[$f]) : null; } $data['is_active'] = isset($_POST['is_active']) ? 1 : 0; $data['sort_order'] = ($data['sort_order'] !== '') ? (int)$data['sort_order'] : 0; try { $q = $pdo->prepare("INSERT INTO user_work_definitions ( company_id, module_name, page_slug, action_name, work_label, work_code, count_type, is_active, sort_order, notes, created_at, updated_at ) VALUES ( :cid, :module_name, :page_slug, :action_name, :work_label, :work_code, :count_type, :is_active, :sort_order, :notes, NOW(), NOW() )"); $q->execute([ ':cid' => $company_id, ':module_name' => $data['module_name'], ':page_slug' => $data['page_slug'], ':action_name' => $data['action_name'], ':work_label' => $data['work_label'], ':work_code' => $data['work_code'], ':count_type' => $data['count_type'], ':is_active' => $data['is_active'], ':sort_order' => $data['sort_order'], ':notes' => $data['notes'], ]); $msg = "<div class='alert alert-success'>Work Definition Added Successfully!</div>"; } catch (Throwable $e) { $msg = "<div class='alert alert-danger'>Error: " . htmlspecialchars($e->getMessage()) . "</div>"; } } // ========================================================================= // 1. PEHLE HEADER INCLUDE KAREIN (Taaki iske andar ka koi bhi code data clash na kare) // ========================================================================= require_once __DIR__ . '/partials/header.php'; // ========================================================================= // 2. AB DATA FETCH KAREIN (Header ke baad fetch karne se data safe rahega) // ========================================================================= $work_define_records = []; try { $l = $pdo->prepare("SELECT * FROM user_work_definitions WHERE company_id = :cid ORDER BY id DESC"); $l->execute([':cid' => $company_id]); $work_define_records = $l->fetchAll(PDO::FETCH_ASSOC); } catch (Throwable $e) { $work_define_records = []; } ?> <div class="container-fluid mt-4"> <div class="card"> <div class="card-header fw-bold bg-light text-dark">User Work Define</div> <div class="card-body"> <?php if (!empty($msg)) echo $msg; ?> <form method="post" class="mb-4"> <div class="row g-2"> <div class="col-md-2"><input type="text" name="module_name" class="form-control" placeholder="Module Name" required></div> <div class="col-md-2"><input type="text" name="page_slug" class="form-control" placeholder="Page Slug" required></div> <div class="col-md-2"><input type="text" name="action_name" class="form-control" placeholder="Action Name" required></div> <div class="col-md-2"><input type="text" name="work_label" class="form-control" placeholder="Work Label" required></div> <div class="col-md-2"><input type="text" name="work_code" class="form-control" placeholder="Work Code" required></div> <div class="col-md-1"><input type="text" name="count_type" class="form-control" placeholder="Count Type" required></div> <div class="col-md-1"><input type="number" name="sort_order" class="form-control" placeholder="Sort" min="0" value="0"></div> <div class="col-md-2"><input type="text" name="notes" class="form-control" placeholder="Notes"></div> <div class="col-md-1 d-flex align-items-center"> <div class="form-check"> <input type="checkbox" name="is_active" id="is_active" class="form-check-input" checked> <label for="is_active" class="form-check-label">Active</label> </div> </div> <div class="col-md-1"><button class="btn btn-primary w-100" name="add_work">Add</button></div> </div> </form> <hr> <div class="table-responsive"> <table class="table table-bordered table-striped table-sm align-middle"> <thead class="table-light"> <tr> <th>ID</th> <th>Module</th> <th>Page Slug</th> <th>Action</th> <th>Label</th> <th>Code</th> <th>Count</th> <th>Active</th> <th>Sort</th> <th>Notes</th> <th>Created</th> </tr> </thead> <tbody> <?php if (empty($work_define_records)): ?> <tr> <td colspan="11" class="text-center text-muted">No records found.</td> </tr> <?php else: ?> <?php foreach($work_define_records as $r): ?> <tr> <td><strong><?=htmlspecialchars($r['id'] ?? '')?></strong></td> <td><?=htmlspecialchars($r['module_name'] ?? '')?></td> <td><?=htmlspecialchars($r['page_slug'] ?? '')?></td> <td><?=htmlspecialchars($r['action_name'] ?? '')?></td> <td><?=htmlspecialchars($r['work_label'] ?? '')?></td> <td><?=htmlspecialchars($r['work_code'] ?? '')?></td> <td><?=htmlspecialchars($r['count_type'] ?? '')?></td> <td> <?=(($r['is_active'] ?? 0) == 1 ? '<span class="badge bg-success">Yes</span>' : '<span class="badge bg-danger">No</span>')?> </td> <td><?=htmlspecialchars($r['sort_order'] ?? '0')?></td> <td class="text-muted"><?=htmlspecialchars($r['notes'] ?? '-')?></td> <td class="small"><?=htmlspecialchars($r['created_at'] ?? '')?></td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> </div> </div>