« Back to History
company_edit.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/developer_bootstrap.php'; $pdo = developer_get_pdo(); $flashes = developer_take_flashes(); $companyId = (int)($_GET['id'] ?? $_POST['id'] ?? 0); $errors = []; if ($companyId <= 0) { http_response_code(400); exit('<h2>Invalid request</h2><p>Company ID missing hai.</p>'); } $stmt = $pdo->prepare('SELECT id, name, short_name, is_active FROM companies WHERE id = ? LIMIT 1'); $stmt->execute([$companyId]); $company = $stmt->fetch(PDO::FETCH_ASSOC); if (!$company) { http_response_code(404); exit('<h2>Company not found</h2><p>Given company record exist nahi karta.</p>'); } $form = [ 'name' => (string)($company['name'] ?? ''), 'short_name' => (string)($company['short_name'] ?? ''), 'is_active' => (string)((int)($company['is_active'] ?? 1)), ]; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $form['name'] = trim((string)($_POST['name'] ?? '')); $form['short_name'] = trim((string)($_POST['short_name'] ?? '')); $form['is_active'] = (string)((int)($_POST['is_active'] ?? 1)); if ($form['name'] === '') { $errors[] = 'Company name required hai.'; } if ($form['is_active'] !== '0' && $form['is_active'] !== '1') { $errors[] = 'Status invalid hai.'; } if (!$errors) { $update = $pdo->prepare( 'UPDATE companies SET name = :name, short_name = :short_name, is_active = :is_active WHERE id = :id' ); $update->execute([ ':name' => $form['name'], ':short_name' => $form['short_name'] !== '' ? $form['short_name'] : null, ':is_active' => (int)$form['is_active'], ':id' => $companyId, ]); developer_log_activity($pdo, 'Updated company: ' . $form['name']); developer_flash('Company updated successfully.', 'success'); header('Location: company_edit.php?id=' . $companyId); exit; } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Edit Company</title> <style> body{font-family:"Segoe UI",Tahoma,sans-serif;background:#f4f7fb;margin:0;padding:24px;color:#172033;} .page{max-width:900px;margin:0 auto;} .topbar{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;margin-bottom:20px;} .topbar h2{margin:0;} .topbar p{margin:6px 0 0;color:#637287;} .actions{display:flex;gap:10px;flex-wrap:wrap;} .btn{background:#0b5fff;color:#fff;padding:10px 14px;border:none;border-radius:8px;cursor:pointer;text-decoration:none;display:inline-block;} .btn-secondary{background:#e8f0ff;color:#17305c;} .card{background:#fff;padding:20px;border-radius:14px;box-shadow:0 12px 30px rgba(24,39,75,.08);border:1px solid #d9e2f0;} .grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px;} .field-full{grid-column:span 2;} label{display:block;font-weight:600;margin-bottom:6px;} input,select{width:100%;padding:10px 12px;border:1px solid #ccd6e3;border-radius:8px;font:inherit;} .flash,.errors{padding:14px 16px;border-radius:12px;margin-bottom:16px;} .flash{background:#e8fff1;border:1px solid #b7f2cb;color:#166534;} .errors{background:#fff0f0;border:1px solid #ffcaca;color:#991b1b;} .errors ul{margin:0;padding-left:18px;} .meta{display:grid;grid-template-columns:140px 1fr;gap:8px 14px;margin-bottom:18px;font-size:14px;} .meta .label{color:#637287;font-weight:600;} @media (max-width: 700px){.grid{grid-template-columns:1fr;}.field-full{grid-column:auto;}.meta{grid-template-columns:1fr;}} </style> </head> <body> <div class="page"> <div class="topbar"> <div> <h2>Edit Company</h2> <p>Company list se selected record ko yahan update kar sakte ho.</p> </div> <div class="actions"> <a class="btn btn-secondary" href="company_list.php">Back to Company List</a> <a class="btn btn-secondary" href="dashboard.php">Back to Dashboard</a> </div> </div> <?php foreach ($flashes as $flash): ?> <div class="flash"><?= h($flash['message'] ?? '') ?></div> <?php endforeach; ?> <?php if ($errors): ?> <div class="errors"> <strong>Update save nahi hua:</strong> <ul> <?php foreach ($errors as $error): ?> <li><?= h($error) ?></li> <?php endforeach; ?> </ul> </div> <?php endif; ?> <div class="card"> <div class="meta"> <div class="label">Company ID</div><div><?= (int)$company['id'] ?></div> <div class="label">Current Status</div><div><?= (int)$company['is_active'] === 1 ? 'Active' : 'Inactive' ?></div> </div> <form method="post"> <input type="hidden" name="id" value="<?= (int)$company['id'] ?>"> <div class="grid"> <div class="field-full"> <label for="name">Company Name</label> <input id="name" name="name" value="<?= h($form['name']) ?>" required> </div> <div> <label for="short_name">Short Name</label> <input id="short_name" name="short_name" value="<?= h($form['short_name']) ?>"> </div> <div> <label for="is_active">Status</label> <select id="is_active" name="is_active"> <option value="1" <?= $form['is_active'] === '1' ? 'selected' : '' ?>>Active</option> <option value="0" <?= $form['is_active'] === '0' ? 'selected' : '' ?>>Inactive</option> </select> </div> <div class="field-full"> <button class="btn" type="submit">Save Changes</button> </div> </div> </form> </div> </div> </body> </html>