-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_device.php
More file actions
41 lines (35 loc) · 1.34 KB
/
Copy pathdelete_device.php
File metadata and controls
41 lines (35 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
session_start();
require_once 'db_connect.php';
// Проверка авторизации
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
if (isset($_GET['id'])) {
$device_id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
// Проверка прав доступа
$stmt = $pdo->prepare("SELECT user_id FROM devices WHERE id_device = ?");
$stmt->execute([$device_id]);
$device = $stmt->fetch(PDO::FETCH_ASSOC);
if ($device && $device['user_id'] == $_SESSION['user_id']) {
try {
// Удаление связанных событий
$stmt = $pdo->prepare("DELETE FROM events WHERE device_id = ?");
$stmt->execute([$device_id]);
// Удаление устройства
$stmt = $pdo->prepare("DELETE FROM devices WHERE id_device = ?");
$stmt->execute([$device_id]);
header('Location: index.php');
exit;
} catch (PDOException $e) {
die("Ошибка при удалении устройства: " . $e->getMessage());
}
} else {
die("Недостаточно прав или устройство не найдено");
}
} else {
header('Location: index.php');
exit;
}
?>