Initial commit
This commit is contained in:
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../inc/auth.php';
|
||||
require_once __DIR__ . '/../../inc/functions.php';
|
||||
$session = auth_require('engineer', 'technician');
|
||||
|
||||
$pdo = getDB();
|
||||
$message = '';
|
||||
$userId = $session['user_id'];
|
||||
$role = $session['user_role'];
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$objectId = (int)($_POST['object_id'] ?? 0);
|
||||
$title = trim($_POST['title'] ?? '');
|
||||
$desc = trim($_POST['description'] ?? '');
|
||||
$severity = $_POST['severity'] ?? 'P3';
|
||||
$assignedTo = (int)($_POST['assigned_to'] ?? 0);
|
||||
$csrf = $_POST['csrf_token'] ?? '';
|
||||
|
||||
if (!auth_csrf_verify($csrf)) {
|
||||
$message = 'Ошибка безопасности.';
|
||||
} elseif (!$objectId || !$title) {
|
||||
$message = 'Объект и название обязательны.';
|
||||
} else {
|
||||
try {
|
||||
if ($id > 0) {
|
||||
$stmt = $pdo->prepare("UPDATE incidents SET object_id=?, title=?, description=?, severity=?, assigned_to=? WHERE id=?");
|
||||
$stmt->execute([$objectId, $title, $desc, $severity, $assignedTo ?: null, $id]);
|
||||
} else {
|
||||
$stmt = $pdo->prepare("INSERT INTO incidents (object_id, reported_by, assigned_to, title, description, severity) VALUES (?,?,?,?,?,?)");
|
||||
$stmt->execute([$objectId, $userId, $assignedTo ?: null, $title, $desc, $severity]);
|
||||
}
|
||||
$message = 'Инцидент сохранён.';
|
||||
auth_log($userId, 'incident_save', "Title: $title");
|
||||
} catch (\PDOException $e) {
|
||||
$message = 'Ошибка: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve incident
|
||||
if (isset($_GET['resolve'])) {
|
||||
$id = (int)$_GET['resolve'];
|
||||
$csrf = $_GET['csrf'] ?? '';
|
||||
if (auth_csrf_verify($csrf)) {
|
||||
$resolution = trim($_GET['resolution'] ?? '');
|
||||
$pdo->prepare("UPDATE incidents SET status='resolved', resolution=?, resolved_at=NOW() WHERE id=?")
|
||||
->execute([$resolution ?: 'Выполнено', $id]);
|
||||
$message = 'Инцидент закрыт.';
|
||||
}
|
||||
}
|
||||
|
||||
$editInc = null;
|
||||
if (isset($_GET['edit'])) {
|
||||
$stmt = $pdo->prepare("SELECT * FROM incidents WHERE id=?");
|
||||
$stmt->execute([(int)$_GET['edit']]);
|
||||
$editInc = $stmt->fetch();
|
||||
}
|
||||
|
||||
$statusFilter = $_GET['status'] ?? '';
|
||||
$severityFilter = $_GET['severity'] ?? '';
|
||||
|
||||
$sql = "SELECT i.*, o.name as object_name, u.full_name as assigned_name, r.full_name as reported_name
|
||||
FROM incidents i
|
||||
JOIN objects o ON o.id = i.object_id
|
||||
LEFT JOIN users u ON u.id = i.assigned_to
|
||||
LEFT JOIN users r ON r.id = i.reported_by
|
||||
WHERE 1=1";
|
||||
$params = [];
|
||||
|
||||
if ($role === 'technician') {
|
||||
$sql .= " AND (i.assigned_to = ? OR i.reported_by = ?)";
|
||||
$params[] = $userId;
|
||||
$params[] = $userId;
|
||||
}
|
||||
if ($statusFilter) {
|
||||
$sql .= " AND i.status = ?";
|
||||
$params[] = $statusFilter;
|
||||
}
|
||||
if ($severityFilter) {
|
||||
$sql .= " AND i.severity = ?";
|
||||
$params[] = $severityFilter;
|
||||
}
|
||||
$sql .= " ORDER BY FIELD(i.severity,'P1','P2','P3'), i.created_at DESC";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$incidents = $stmt->fetchAll();
|
||||
|
||||
$objects = $pdo->query("SELECT id, name FROM objects WHERE status='active' ORDER BY name")->fetchAll();
|
||||
$engineers = $pdo->query("SELECT id, full_name FROM users WHERE is_active=1 ORDER BY full_name")->fetchAll();
|
||||
|
||||
$csrf = auth_csrf_token();
|
||||
require __DIR__ . '/../../inc/header.php';
|
||||
?>
|
||||
|
||||
<div class="main-header">
|
||||
<div>
|
||||
<h1>Инциденты</h1>
|
||||
<div class="breadcrumb"><a href="/service/dashboard.php">Главная</a> / Инциденты</div>
|
||||
</div>
|
||||
<button class="btn btn-primary btn-sm" onclick="openModal()">+ Создать</button>
|
||||
</div>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-info"><?= htmlspecialchars($message) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="filter-bar">
|
||||
<form method="get">
|
||||
<select name="severity" onchange="this.form.submit()">
|
||||
<option value="">Все уровни</option>
|
||||
<option value="P1" <?= $severityFilter === 'P1' ? 'selected' : '' ?>>P1 — Критический</option>
|
||||
<option value="P2" <?= $severityFilter === 'P2' ? 'selected' : '' ?>>P2 — Частичный</option>
|
||||
<option value="P3" <?= $severityFilter === 'P3' ? 'selected' : '' ?>>P3 — Незначительный</option>
|
||||
</select>
|
||||
<select name="status" onchange="this.form.submit()">
|
||||
<option value="">Все статусы</option>
|
||||
<option value="open" <?= $statusFilter === 'open' ? 'selected' : '' ?>>Открытые</option>
|
||||
<option value="in_progress" <?= $statusFilter === 'in_progress' ? 'selected' : '' ?>>В работе</option>
|
||||
<option value="resolved" <?= $statusFilter === 'resolved' ? 'selected' : '' ?>>Решённые</option>
|
||||
</select>
|
||||
<?php if ($statusFilter || $severityFilter): ?><a href="incidents.php" class="btn btn-secondary btn-sm">Сброс</a><?php endif; ?>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Уровень</th>
|
||||
<th>Название</th>
|
||||
<th>Объект</th>
|
||||
<th>Назначен</th>
|
||||
<th>Статус</th>
|
||||
<th>Создан</th>
|
||||
<th class="actions">Действия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($incidents)): ?>
|
||||
<tr><td colspan="7" style="text-align:center;color:var(--text-muted);">Нет инцидентов</td></tr>
|
||||
<?php endif; ?>
|
||||
<?php foreach ($incidents as $inc): ?>
|
||||
<tr>
|
||||
<td><span class="badge badge-<?= strtolower($inc['severity']) ?>"><?= $inc['severity'] ?></span></td>
|
||||
<td><strong><?= htmlspecialchars($inc['title']) ?></strong></td>
|
||||
<td><?= htmlspecialchars($inc['object_name']) ?></td>
|
||||
<td><?= htmlspecialchars($inc['assigned_name'] ?: '—') ?></td>
|
||||
<td><span class="badge badge-<?= $inc['status'] ?>"><?= $inc['status'] ?></span></td>
|
||||
<td><?= date('d.m.Y H:i', strtotime($inc['created_at'])) ?></td>
|
||||
<td class="actions">
|
||||
<a href="?edit=<?= $inc['id'] ?>" class="btn btn-secondary btn-sm">✏️</a>
|
||||
<?php if ($inc['status'] !== 'resolved' && $inc['status'] !== 'closed'): ?>
|
||||
<a href="?resolve=<?= $inc['id'] ?>&csrf=<?= $csrf ?>" class="btn btn-success btn-sm" onclick="return confirm('Закрыть инцидент?')">✓</a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-overlay <?= $editInc ? 'open' : '' ?>" id="incModal">
|
||||
<div class="modal">
|
||||
<button class="modal-close" onclick="closeModal()">×</button>
|
||||
<h2><?= $editInc ? 'Редактировать' : 'Создать' ?> инцидент</h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
|
||||
<input type="hidden" name="id" value="<?= $editInc['id'] ?? 0 ?>">
|
||||
<div class="form-group">
|
||||
<label for="title">Название *</label>
|
||||
<input type="text" id="title" name="title" value="<?= htmlspecialchars($editInc['title'] ?? '') ?>" required>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="object_id">Объект *</label>
|
||||
<select id="object_id" name="object_id" required>
|
||||
<option value="">— выберите —</option>
|
||||
<?php foreach ($objects as $o): ?>
|
||||
<option value="<?= $o['id'] ?>" <?= ($editInc['object_id'] ?? 0) === $o['id'] ? 'selected' : '' ?>><?= htmlspecialchars($o['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="severity">Уровень</label>
|
||||
<select id="severity" name="severity">
|
||||
<option value="P1" <?= ($editInc['severity'] ?? '') === 'P1' ? 'selected' : '' ?>>P1 — Критический</option>
|
||||
<option value="P2" <?= ($editInc['severity'] ?? '') === 'P2' ? 'selected' : '' ?>>P2 — Частичный</option>
|
||||
<option value="P3" <?= ($editInc['severity'] ?? '') === 'P3' ? 'selected' : '' ?>>P3 — Незначительный</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="assigned_to">Назначить</label>
|
||||
<select id="assigned_to" name="assigned_to">
|
||||
<option value="">— не назначено —</option>
|
||||
<?php foreach ($engineers as $e): ?>
|
||||
<option value="<?= $e['id'] ?>" <?= ($editInc['assigned_to'] ?? 0) === $e['id'] ? 'selected' : '' ?>><?= htmlspecialchars($e['full_name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description">Описание</label>
|
||||
<textarea id="description" name="description"><?= htmlspecialchars($editInc['description'] ?? '') ?></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Сохранить</button>
|
||||
<button type="button" class="btn btn-secondary" onclick="closeModal()">Отмена</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function openModal() { document.getElementById('incModal').classList.add('open'); }
|
||||
function closeModal() { document.getElementById('incModal').classList.remove('open'); window.location.href = 'incidents.php'; }
|
||||
</script>
|
||||
|
||||
<?php require __DIR__ . '/../../inc/footer.php'; ?>
|
||||
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../inc/auth.php';
|
||||
require_once __DIR__ . '/../../inc/functions.php';
|
||||
$session = auth_require('engineer', 'technician');
|
||||
|
||||
$pdo = getDB();
|
||||
$message = '';
|
||||
$userId = $session['user_id'];
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$objectId = (int)($_POST['object_id'] ?? 0);
|
||||
$type = $_POST['report_type'] ?? 'service';
|
||||
$title = trim($_POST['title'] ?? '');
|
||||
$desc = trim($_POST['description'] ?? '');
|
||||
$findings = trim($_POST['findings'] ?? '');
|
||||
$recs = trim($_POST['recommendations'] ?? '');
|
||||
$workDone = trim($_POST['work_done'] ?? '');
|
||||
$cause = trim($_POST['cause_classification'] ?? '');
|
||||
$status = $_POST['status'] ?? 'draft';
|
||||
$result = $_POST['result_status'] ?? 'ok';
|
||||
$csrf = $_POST['csrf_token'] ?? '';
|
||||
|
||||
if (!auth_csrf_verify($csrf)) {
|
||||
$message = 'Ошибка безопасности.';
|
||||
} elseif (!$objectId) {
|
||||
$message = 'Объект обязателен.';
|
||||
} else {
|
||||
try {
|
||||
if ($id > 0) {
|
||||
$stmt = $pdo->prepare("UPDATE reports SET object_id=?, report_type=?, title=?, description=?, findings=?, recommendations=?, work_done=?, cause_classification=?, status=?, result_status=? WHERE id=? AND created_by=?");
|
||||
$stmt->execute([$objectId, $type, $title, $desc, $findings, $recs, $workDone, $cause, $status, $result, $id, $userId]);
|
||||
} else {
|
||||
$stmt = $pdo->prepare("INSERT INTO reports (object_id, created_by, report_type, title, description, findings, recommendations, work_done, cause_classification, status, result_status) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
|
||||
$stmt->execute([$objectId, $userId, $type, $title, $desc, $findings, $recs, $workDone, $cause, $status, $result]);
|
||||
}
|
||||
$message = 'Отчёт сохранён.';
|
||||
auth_log($userId, 'report_save', "Object: $objectId");
|
||||
} catch (\PDOException $e) {
|
||||
$message = 'Ошибка: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$editReport = null;
|
||||
if (isset($_GET['edit'])) {
|
||||
$stmt = $pdo->prepare("SELECT * FROM reports WHERE id=? AND created_by=?");
|
||||
$stmt->execute([(int)$_GET['edit'], $userId]);
|
||||
$editReport = $stmt->fetch();
|
||||
}
|
||||
|
||||
$typeFilter = $_GET['type'] ?? '';
|
||||
$sql = "SELECT r.*, o.name as object_name FROM reports r JOIN objects o ON o.id=r.object_id WHERE 1=1";
|
||||
$params = [];
|
||||
if ($session['user_role'] === 'technician') {
|
||||
$sql .= " AND r.created_by = ?";
|
||||
$params[] = $userId;
|
||||
}
|
||||
if ($typeFilter) {
|
||||
$sql .= " AND r.report_type = ?";
|
||||
$params[] = $typeFilter;
|
||||
}
|
||||
$sql .= " ORDER BY r.created_at DESC";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$reports = $stmt->fetchAll();
|
||||
|
||||
$objects = $pdo->query("SELECT id, name FROM objects WHERE status IN ('active','audit') ORDER BY name")->fetchAll();
|
||||
|
||||
$csrf = auth_csrf_token();
|
||||
require __DIR__ . '/../../inc/header.php';
|
||||
?>
|
||||
|
||||
<div class="main-header">
|
||||
<div>
|
||||
<h1>Отчёты</h1>
|
||||
<div class="breadcrumb"><a href="/service/dashboard.php">Главная</a> / Отчёты</div>
|
||||
</div>
|
||||
<button class="btn btn-primary btn-sm" onclick="openModal()">+ Создать</button>
|
||||
</div>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-info"><?= htmlspecialchars($message) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="filter-bar">
|
||||
<form method="get">
|
||||
<select name="type" onchange="this.form.submit()">
|
||||
<option value="">Все типы</option>
|
||||
<option value="inspection" <?= $typeFilter === 'inspection' ? 'selected' : '' ?>>Осмотр</option>
|
||||
<option value="service" <?= $typeFilter === 'service' ? 'selected' : '' ?>>Обслуживание</option>
|
||||
<option value="emergency" <?= $typeFilter === 'emergency' ? 'selected' : '' ?>>Аварийный</option>
|
||||
<option value="audit" <?= $typeFilter === 'audit' ? 'selected' : '' ?>>Аудит</option>
|
||||
<option value="monthly" <?= $typeFilter === 'monthly' ? 'selected' : '' ?>>Месячный</option>
|
||||
</select>
|
||||
<?php if ($typeFilter): ?><a href="reports.php" class="btn btn-secondary btn-sm">Сброс</a><?php endif; ?>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Тип</th>
|
||||
<th>Название</th>
|
||||
<th>Объект</th>
|
||||
<th>Статус</th>
|
||||
<th>Результат</th>
|
||||
<th>Дата</th>
|
||||
<th class="actions">Действия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($reports)): ?>
|
||||
<tr><td colspan="7" style="text-align:center;color:var(--text-muted);">Нет отчётов</td></tr>
|
||||
<?php endif; ?>
|
||||
<?php foreach ($reports as $r): ?>
|
||||
<tr>
|
||||
<td><span class="badge badge-medium"><?= $r['report_type'] ?></span></td>
|
||||
<td><strong><?= htmlspecialchars($r['title'] ?: 'Без названия') ?></strong></td>
|
||||
<td><?= htmlspecialchars($r['object_name']) ?></td>
|
||||
<td><span class="badge badge-<?= $r['status'] ?>"><?= $r['status'] ?></span></td>
|
||||
<td><span class="badge badge-<?= $r['result_status'] === 'ok' ? 'done' : ($r['result_status'] === 'partial' ? 'high' : 'medium') ?>"><?= $r['result_status'] ?></span></td>
|
||||
<td><?= date('d.m.Y', strtotime($r['created_at'])) ?></td>
|
||||
<td class="actions">
|
||||
<a href="?edit=<?= $r['id'] ?>" class="btn btn-secondary btn-sm">✏️</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-overlay <?= $editReport ? 'open' : '' ?>" id="reportModal">
|
||||
<div class="modal">
|
||||
<button class="modal-close" onclick="closeModal()">×</button>
|
||||
<h2><?= $editReport ? 'Редактировать' : 'Создать' ?> отчёт</h2>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
|
||||
<input type="hidden" name="id" value="<?= $editReport['id'] ?? 0 ?>">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="object_id">Объект *</label>
|
||||
<select id="object_id" name="object_id" required>
|
||||
<option value="">— выберите —</option>
|
||||
<?php foreach ($objects as $o): ?>
|
||||
<option value="<?= $o['id'] ?>" <?= ($editReport['object_id'] ?? 0) === $o['id'] ? 'selected' : '' ?>><?= htmlspecialchars($o['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="report_type">Тип</label>
|
||||
<select id="report_type" name="report_type">
|
||||
<option value="inspection" <?= ($editReport['report_type'] ?? '') === 'inspection' ? 'selected' : '' ?>>Осмотр</option>
|
||||
<option value="service" <?= ($editReport['report_type'] ?? '') === 'service' ? 'selected' : '' ?>>Обслуживание</option>
|
||||
<option value="emergency" <?= ($editReport['report_type'] ?? '') === 'emergency' ? 'selected' : '' ?>>Аварийный</option>
|
||||
<option value="audit" <?= ($editReport['report_type'] ?? '') === 'audit' ? 'selected' : '' ?>>Аудит</option>
|
||||
<option value="monthly" <?= ($editReport['report_type'] ?? '') === 'monthly' ? 'selected' : '' ?>>Месячный</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="title">Название</label>
|
||||
<input type="text" id="title" name="title" value="<?= htmlspecialchars($editReport['title'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="status">Статус</label>
|
||||
<select id="status" name="status">
|
||||
<option value="draft" <?= ($editReport['status'] ?? '') === 'draft' ? 'selected' : '' ?>>Черновик</option>
|
||||
<option value="final" <?= ($editReport['status'] ?? '') === 'final' ? 'selected' : '' ?>>Итоговый</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="result_status">Результат</label>
|
||||
<select id="result_status" name="result_status">
|
||||
<option value="ok" <?= ($editReport['result_status'] ?? '') === 'ok' ? 'selected' : '' ?>>Исправлено</option>
|
||||
<option value="fixed" <?= ($editReport['result_status'] ?? '') === 'fixed' ? 'selected' : '' ?>>Исправлено</option>
|
||||
<option value="partial" <?= ($editReport['result_status'] ?? '') === 'partial' ? 'selected' : '' ?>>Частично</option>
|
||||
<option value="revisit" <?= ($editReport['result_status'] ?? '') === 'revisit' ? 'selected' : '' ?>>Повторный выезд</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description">Описание</label>
|
||||
<textarea id="description" name="description"><?= htmlspecialchars($editReport['description'] ?? '') ?></textarea>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="findings">Выявленные проблемы</label>
|
||||
<textarea id="findings" name="findings"><?= htmlspecialchars($editReport['findings'] ?? '') ?></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="recommendations">Рекомендации</label>
|
||||
<textarea id="recommendations" name="recommendations"><?= htmlspecialchars($editReport['recommendations'] ?? '') ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="work_done">Выполненные работы</label>
|
||||
<textarea id="work_done" name="work_done"><?= htmlspecialchars($editReport['work_done'] ?? '') ?></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="cause_classification">Классификация причины</label>
|
||||
<select id="cause_classification" name="cause_classification">
|
||||
<option value="">—</option>
|
||||
<option value="Hardware" <?= ($editReport['cause_classification'] ?? '') === 'Hardware' ? 'selected' : '' ?>>Hardware</option>
|
||||
<option value="Software" <?= ($editReport['cause_classification'] ?? '') === 'Software' ? 'selected' : '' ?>>Software</option>
|
||||
<option value="Network" <?= ($editReport['cause_classification'] ?? '') === 'Network' ? 'selected' : '' ?>>Network</option>
|
||||
<option value="Human error" <?= ($editReport['cause_classification'] ?? '') === 'Human error' ? 'selected' : '' ?>>Человеческий фактор</option>
|
||||
<option value="External" <?= ($editReport['cause_classification'] ?? '') === 'External' ? 'selected' : '' ?>>Внешний фактор</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Сохранить</button>
|
||||
<button type="button" class="btn btn-secondary" onclick="closeModal()">Отмена</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function openModal() { document.getElementById('reportModal').classList.add('open'); }
|
||||
function closeModal() { document.getElementById('reportModal').classList.remove('open'); window.location.href = 'reports.php'; }
|
||||
</script>
|
||||
|
||||
<?php require __DIR__ . '/../../inc/footer.php'; ?>
|
||||
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../inc/auth.php';
|
||||
require_once __DIR__ . '/../../inc/functions.php';
|
||||
$session = auth_require('engineer', 'technician');
|
||||
|
||||
$pdo = getDB();
|
||||
$message = '';
|
||||
$userId = $session['user_id'];
|
||||
$role = $session['user_role'];
|
||||
|
||||
// Create / update task (engineer+)
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $role !== 'technician') {
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$objectId = (int)($_POST['object_id'] ?? 0);
|
||||
$assignedTo = (int)($_POST['assigned_to'] ?? 0);
|
||||
$title = trim($_POST['title'] ?? '');
|
||||
$desc = trim($_POST['description'] ?? '');
|
||||
$priority = $_POST['priority'] ?? 'P3';
|
||||
$deadline = $_POST['deadline'] ?? '';
|
||||
$csrf = $_POST['csrf_token'] ?? '';
|
||||
|
||||
if (!auth_csrf_verify($csrf)) {
|
||||
$message = 'Ошибка безопасности.';
|
||||
} elseif (!$objectId || !$title) {
|
||||
$message = 'Объект и название обязательны.';
|
||||
} else {
|
||||
try {
|
||||
if ($id > 0) {
|
||||
$stmt = $pdo->prepare("UPDATE tasks SET object_id=?, assigned_to=?, title=?, description=?, priority=?, deadline=? WHERE id=?");
|
||||
$stmt->execute([$objectId, $assignedTo ?: null, $title, $desc, $priority, $deadline ?: null, $id]);
|
||||
} else {
|
||||
$stmt = $pdo->prepare("INSERT INTO tasks (object_id, assigned_to, created_by, title, description, priority, deadline) VALUES (?,?,?,?,?,?,?)");
|
||||
$stmt->execute([$objectId, $assignedTo ?: null, $userId, $title, $desc, $priority, $deadline ?: null]);
|
||||
}
|
||||
$message = 'Задача сохранена.';
|
||||
auth_log($userId, 'task_save', "Title: $title");
|
||||
} catch (\PDOException $e) {
|
||||
$message = 'Ошибка: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close task
|
||||
if (isset($_GET['close'])) {
|
||||
$id = (int)$_GET['close'];
|
||||
$csrf = $_GET['csrf'] ?? '';
|
||||
if (auth_csrf_verify($csrf)) {
|
||||
$pdo->prepare("UPDATE tasks SET status='completed', closed_at=NOW() WHERE id=? AND (assigned_to=? OR ? IN ('owner','engineer'))")
|
||||
->execute([$id, $userId, $role]);
|
||||
$message = 'Задача закрыта.';
|
||||
}
|
||||
}
|
||||
|
||||
$editTask = null;
|
||||
if (isset($_GET['edit']) && $role !== 'technician') {
|
||||
$stmt = $pdo->prepare("SELECT * FROM tasks WHERE id=?");
|
||||
$stmt->execute([(int)$_GET['edit']]);
|
||||
$editTask = $stmt->fetch();
|
||||
}
|
||||
|
||||
// Filter
|
||||
$statusFilter = $_GET['status'] ?? '';
|
||||
$search = trim($_GET['search'] ?? '');
|
||||
$sql = "SELECT t.*, o.name as object_name, u.full_name as assigned_name
|
||||
FROM tasks t
|
||||
JOIN objects o ON o.id = t.object_id
|
||||
LEFT JOIN users u ON u.id = t.assigned_to
|
||||
WHERE 1=1";
|
||||
$params = [];
|
||||
|
||||
if ($role === 'technician') {
|
||||
$sql .= " AND t.assigned_to = ?";
|
||||
$params[] = $userId;
|
||||
}
|
||||
if ($statusFilter) {
|
||||
$sql .= " AND t.status = ?";
|
||||
$params[] = $statusFilter;
|
||||
}
|
||||
if ($search) {
|
||||
$sql .= " AND (t.title LIKE ? OR o.name LIKE ?)";
|
||||
$params[] = "%$search%";
|
||||
$params[] = "%$search%";
|
||||
}
|
||||
$sql .= " ORDER BY FIELD(t.priority,'P1','P2','P3','P4'), t.deadline ASC, t.created_at DESC";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$tasks = $stmt->fetchAll();
|
||||
|
||||
$activeObjects = $pdo->query("SELECT id, name FROM objects WHERE status='active' ORDER BY name")->fetchAll();
|
||||
$engineers = $pdo->query("SELECT id, full_name FROM users WHERE role IN ('engineer','technician') AND is_active=1 ORDER BY full_name")->fetchAll();
|
||||
|
||||
$csrf = auth_csrf_token();
|
||||
require __DIR__ . '/../../inc/header.php';
|
||||
?>
|
||||
|
||||
<div class="main-header">
|
||||
<div>
|
||||
<h1>Задачи</h1>
|
||||
<div class="breadcrumb"><a href="/service/dashboard.php">Главная</a> / Задачи</div>
|
||||
</div>
|
||||
<?php if ($role !== 'technician'): ?>
|
||||
<button class="btn btn-primary btn-sm" onclick="openModal()">+ Создать</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-info"><?= htmlspecialchars($message) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="filter-bar">
|
||||
<form method="get">
|
||||
<select name="status" onchange="this.form.submit()">
|
||||
<option value="">Все статусы</option>
|
||||
<option value="open" <?= $statusFilter === 'open' ? 'selected' : '' ?>>Открытые</option>
|
||||
<option value="in_progress" <?= $statusFilter === 'in_progress' ? 'selected' : '' ?>>В работе</option>
|
||||
<option value="completed" <?= $statusFilter === 'completed' ? 'selected' : '' ?>>Завершённые</option>
|
||||
</select>
|
||||
<input type="text" name="search" placeholder="Поиск..." value="<?= htmlspecialchars($search) ?>">
|
||||
<button type="submit" class="btn btn-secondary btn-sm">Фильтр</button>
|
||||
<?php if ($statusFilter || $search): ?><a href="tasks.php" class="btn btn-secondary btn-sm">Сброс</a><?php endif; ?>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Приоритет</th>
|
||||
<th>Название</th>
|
||||
<th>Объект</th>
|
||||
<th>Назначена</th>
|
||||
<th>Статус</th>
|
||||
<th>Дедлайн</th>
|
||||
<th>Результат</th>
|
||||
<th class="actions">Действия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($tasks)): ?>
|
||||
<tr><td colspan="8" style="text-align:center;color:var(--text-muted);">Нет задач</td></tr>
|
||||
<?php endif; ?>
|
||||
<?php foreach ($tasks as $t): ?>
|
||||
<?php
|
||||
$slaOk = null;
|
||||
if ($t['deadline']) {
|
||||
$slaOk = strtotime($t['deadline']) > time();
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td><span class="badge badge-<?= strtolower($t['priority']) ?>"><?= $t['priority'] ?></span></td>
|
||||
<td><strong><?= htmlspecialchars($t['title']) ?></strong></td>
|
||||
<td><?= htmlspecialchars($t['object_name']) ?></td>
|
||||
<td><?= htmlspecialchars($t['assigned_name'] ?: '—') ?></td>
|
||||
<td><span class="badge badge-<?= $t['status'] ?>"><?= $t['status'] ?></span></td>
|
||||
<td style="color:<?= $slaOk === false ? 'var(--danger)' : 'var(--text-secondary)' ?>"><?= $t['deadline'] ? date('d.m.Y H:i', strtotime($t['deadline'])) : '—' ?></td>
|
||||
<td><?= $t['sla_compliant'] !== null ? ($t['sla_compliant'] ? '<span class="badge badge-done">OK</span>' : '<span class="badge badge-critical">❌</span>') : '—' ?></td>
|
||||
<td class="actions">
|
||||
<?php if ($t['status'] !== 'completed'): ?>
|
||||
<a href="?close=<?= $t['id'] ?>&csrf=<?= $csrf ?>" class="btn btn-success btn-sm" onclick="return confirm('Закрыть задачу?')">✓</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($role !== 'technician'): ?>
|
||||
<a href="?edit=<?= $t['id'] ?>" class="btn btn-secondary btn-sm">✏️</a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($role !== 'technician'): ?>
|
||||
<div class="modal-overlay <?= $editTask ? 'open' : '' ?>" id="taskModal">
|
||||
<div class="modal">
|
||||
<button class="modal-close" onclick="closeModal()">×</button>
|
||||
<h2><?= $editTask ? 'Редактировать' : 'Создать' ?> задачу</h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
|
||||
<input type="hidden" name="id" value="<?= $editTask['id'] ?? 0 ?>">
|
||||
<div class="form-group">
|
||||
<label for="title">Название *</label>
|
||||
<input type="text" id="title" name="title" value="<?= htmlspecialchars($editTask['title'] ?? '') ?>" required>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="object_id">Объект *</label>
|
||||
<select id="object_id" name="object_id" required>
|
||||
<option value="">— выберите —</option>
|
||||
<?php foreach ($activeObjects as $o): ?>
|
||||
<option value="<?= $o['id'] ?>" <?= ($editTask['object_id'] ?? 0) === $o['id'] ? 'selected' : '' ?>><?= htmlspecialchars($o['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="assigned_to">Назначить</label>
|
||||
<select id="assigned_to" name="assigned_to">
|
||||
<option value="">— не назначено —</option>
|
||||
<?php foreach ($engineers as $e): ?>
|
||||
<option value="<?= $e['id'] ?>" <?= ($editTask['assigned_to'] ?? 0) === $e['id'] ? 'selected' : '' ?>><?= htmlspecialchars($e['full_name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="priority">Приоритет</label>
|
||||
<select id="priority" name="priority">
|
||||
<option value="P1" <?= ($editTask['priority'] ?? '') === 'P1' ? 'selected' : '' ?>>P1 — Критический</option>
|
||||
<option value="P2" <?= ($editTask['priority'] ?? '') === 'P2' ? 'selected' : '' ?>>P2 — Высокий</option>
|
||||
<option value="P3" <?= ($editTask['priority'] ?? '') === 'P3' ? 'selected' : '' ?>>P3 — Средний</option>
|
||||
<option value="P4" <?= ($editTask['priority'] ?? '') === 'P4' ? 'selected' : '' ?>>P4 — Низкий</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="deadline">Дедлайн</label>
|
||||
<input type="datetime-local" id="deadline" name="deadline" value="<?= $editTask['deadline'] ? date('Y-m-d\TH:i', strtotime($editTask['deadline'])) : '' ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description">Описание</label>
|
||||
<textarea id="description" name="description"><?= htmlspecialchars($editTask['description'] ?? '') ?></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Сохранить</button>
|
||||
<button type="button" class="btn btn-secondary" onclick="closeModal()">Отмена</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function openModal() { document.getElementById('taskModal').classList.add('open'); }
|
||||
function closeModal() { document.getElementById('taskModal').classList.remove('open'); window.location.href = 'tasks.php'; }
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php require __DIR__ . '/../../inc/footer.php'; ?>
|
||||
Reference in New Issue
Block a user