0) { $stmt = $pdo->prepare("UPDATE objects SET customer_id=?, name=?, address=?, object_type=?, contact_person=?, contact_phone=?, status=?, notes=? WHERE id=?"); $stmt->execute([$customerId ?: null, $name, $address, $objType, $contact, $cphone, $status, $notes, $id]); $message = 'Объект обновлён.'; } else { $stmt = $pdo->prepare("INSERT INTO objects (customer_id, name, address, object_type, contact_person, contact_phone, status, notes, created_by) VALUES (?,?,?,?,?,?,?,?,?)"); $stmt->execute([$customerId ?: null, $name, $address, $objType, $contact, $cphone, $status, $notes, $session['user_id']]); $message = 'Объект создан.'; } auth_log($session['user_id'], $id > 0 ? 'object_update' : 'object_create', "Name: $name"); } catch (\PDOException $e) { $message = 'Ошибка: ' . $e->getMessage(); } } } if (isset($_GET['delete']) && auth_has_role('owner')) { $id = (int)$_GET['delete']; if (auth_csrf_verify($_GET['csrf'] ?? '')) { $pdo->prepare("DELETE FROM objects WHERE id=?")->execute([$id]); $message = 'Объект удалён.'; auth_log($session['user_id'], 'object_delete', "ID: $id"); } } $editObj = null; if (isset($_GET['edit'])) { $stmt = $pdo->prepare("SELECT * FROM objects WHERE id=?"); $stmt->execute([(int)$_GET['edit']]); $editObj = $stmt->fetch(); } $search = trim($_GET['search'] ?? ''); $customerId = (int)($_GET['customer_id'] ?? 0); if ($customerId > 0) { $stmt = $pdo->prepare(" SELECT o.*, c.name as customer_name FROM objects o LEFT JOIN customers c ON c.id = o.customer_id WHERE o.customer_id = ? ORDER BY o.name "); $stmt->execute([$customerId]); } elseif ($search !== '') { $stmt = $pdo->prepare(" SELECT o.*, c.name as customer_name FROM objects o LEFT JOIN customers c ON c.id = o.customer_id WHERE o.name LIKE ? OR o.address LIKE ? ORDER BY o.name "); $stmt->execute(["%$search%", "%$search%"]); } else { $stmt = $pdo->query(" SELECT o.*, c.name as customer_name FROM objects o LEFT JOIN customers c ON c.id = o.customer_id ORDER BY o.name "); } $objects = $stmt->fetchAll(); $customers = $pdo->query("SELECT id, name FROM customers WHERE status='active' ORDER BY name")->fetchAll(); $csrf = auth_csrf_token(); require __DIR__ . '/../../inc/header.php'; ?>
| Название | Клиент | Тип | Адрес | Статус | Risk Score | Object Index | Действия |
|---|---|---|---|---|---|---|---|
| Нет объектов | |||||||
| = htmlspecialchars($o['name']) ?> | = $o['customer_name'] ? '' . htmlspecialchars($o['customer_name']) . '' : '—' ?> | = htmlspecialchars($o['object_type'] ?: '—') ?> | = htmlspecialchars($o['address'] ?: '—') ?> | = $o['status'] ?> | = $o['risk_score'] ?: '—' ?> | = $o['object_index'] ?: '—' ?> | ✏️ 📝 📋 SLA 🗑️ |