Загрузка данных
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Редактирование JSON</title>
</head>
<body>
<h2>Редактирование JSON-файла</h2>
<?php
$id_team = $_GET["id_team"] ?? null;
// Если ID не указан - показываем список групп
if ($id_team === null) {
$json = file_get_contents("team.json");
$teams = json_decode($json, true);
echo "<h3>Выберите группу для редактирования:</h3>";
echo "<ul>";
foreach ($teams as $team) {
echo "<li><a href='?id_team={$team['id_team']}'>ID: {$team['id_team']} - {$team['name']}</a></li>";
}
echo "</ul>";
exit;
}
// Читаем файл
$json = file_get_contents("team.json");
$teams = json_decode($json, true);
$foundRecord = null;
foreach ($teams as $record) {
if ($record["id_team"] == $id_team) {
$foundRecord = $record;
break;
}
}
if ($foundRecord === null) {
echo "<p style='color: red;'>Запись с id_team = $id_team не найдена</p>";
echo "<p><a href='index.php'>Выбрать другую группу</a></p>";
exit;
}
?>
<form action="server.php" method="post">
<input type="hidden" name="id_team" value="<?php echo $foundRecord['id_team']; ?>">
Название: <input type="text" name="name" value="<?php echo $foundRecord['name']; ?>"><br>
Псевдоним: <input type="text" name="alias" value="<?php echo $foundRecord['alias']; ?>"><br>
Страна: <input type="text" name="country" value="<?php echo $foundRecord['country']; ?>"><br>
Описание: <input type="text" name="content" value="<?php echo $foundRecord['content']; ?>"><br>
Год: <input type="text" name="date" value="<?php echo $foundRecord['date']; ?>"><br>
Стиль: <input type="text" name="style" value="<?php echo $foundRecord['style']; ?>"><br><br>
<input type="submit" name="submit" value="Сохранить">
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Удаление записи</title>
</head>
<body>
<h2>Удаление записи из JSON</h2>
<?php
$id_team = $_GET["id_team"] ?? null;
// Если ID не указан - показываем список групп
if ($id_team === null) {
$json = file_get_contents("team.json");
$teams = json_decode($json, true);
echo "<h3>Выберите группу для удаления:</h3>";
echo "<ul>";
foreach ($teams as $team) {
echo "<li><a href='?id_team={$team['id_team']}' style='color: red;'>ID: {$team['id_team']} - {$team['name']}</a></li>";
}
echo "</ul>";
exit;
}
$json = file_get_contents("team.json");
$teams = json_decode($json, true);
$foundRecord = null;
$foundIndex = null;
foreach ($teams as $index => $record) {
if ($record["id_team"] == $id_team) {
$foundRecord = $record;
$foundIndex = $index;
break;
}
}
if ($foundRecord === null) {
echo "<p style='color: red;'>Запись с id_team = $id_team не найдена</p>";
echo "<p><a href='index.php'>Выбрать другую группу</a></p>";
exit;
}
// Удаляем
unset($teams[$foundIndex]);
$teams = array_values($teams);
$target = __DIR__ . '/team.json';
$hardlink = __DIR__ . '/team_hard.json';
// Удаляем старую жесткую ссылку если есть
if (file_exists($hardlink)) {
unlink($hardlink);
}
if (link($target, $hardlink)) {
$updatedJson = json_encode($teams, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
file_put_contents($hardlink, $updatedJson);
unlink($hardlink);
echo "<h3 style='color: green;'>✅ Запись успешно удалена через жесткую ссылку!</h3>";
echo "<h3>Удаленная запись:</h3>";
echo "<pre>";
print_r($foundRecord);
echo "</pre>";
echo "<h3>Обновленное содержимое team.json:</h3>";
echo "<pre>";
print_r($teams);
echo "</pre>";
} else {
echo "<h3 style='color: red;'>❌ Ошибка создания жесткой ссылки</h3>";
}
echo "<p><a href='index.php'>← Вернуться к списку групп</a></p>";
?>
</body>
</html>