« Back to History
company_list.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php /* File: /erp/company_list.php */ error_reporting(E_ALL); ini_set('display_errors',1); require __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('company_list'); $u = $ctx['user']; $role = strtolower($u['role'] ?? ''); $company_id = (int)$ctx['company_id']; $pdo = $ctx['pdo'] ?? null; if (!$pdo) { require __DIR__ . '/core/db.php'; } function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES,'UTF-8'); } $is_owner_admin = in_array($role, ['owner','admin'], true); // Owner/Admin → sab; others → sirf apni company if ($is_owner_admin) { $st = $pdo->query("SELECT id, name, is_active FROM companies ORDER BY id DESC"); } else { $st = $pdo->prepare("SELECT id, name, is_active FROM companies WHERE id=:cid"); $st->execute([':cid'=>$company_id]); } $rows = $st->fetchAll(PDO::FETCH_ASSOC); require __DIR__ . '/partials/header.php'; ?> <style> table.list{width:100%; border-collapse:collapse; background:#fff} table.list th, table.list td{padding:10px; border:1px solid #e5e5e5; font-size:14px; text-align:left} table.list th{background:#fafafa} .pill{padding:2px 8px; border:1px solid #ddd; border-radius:999px; font-size:12px} .ok{background:#e8f5e9; border-color:#c8e6c9} .off{background:#ffebee; border-color:#ffcdd2} .btn{padding:6px 10px; border:1px solid #ccc; border-radius:6px; text-decoration:none; background:#fafafa} .btn:hover{background:#eee} </style> <h2>Companies</h2> <table class="list"> <thead> <tr> <th style="width:80px">ID</th> <th>Name</th> <th style="width:120px">Status</th> <th style="width:90px">Action</th> </tr> </thead> <tbody> <?php if(!$rows): ?> <tr><td colspan="4" style="text-align:center">No companies found</td></tr> <?php else: foreach($rows as $r): ?> <tr> <td><?= (int)$r['id'] ?></td> <td><?= h($r['name']) ?></td> <td> <?php $active = (int)$r['is_active'] === 1; ?> <span class="pill <?= $active?'ok':'off' ?>"><?= $active?'Active':'Inactive' ?></span> </td> <td><a class="btn" href="company_edit.php?id=<?= (int)$r['id'] ?>">Edit</a></td> </tr> <?php endforeach; endif; ?> </tbody> </table>