<!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;
// Проверяем существование файла
if (!file_exists("team.json")) {
echo "<p style='color: red;'>Файл team.json не найден!</p>";
exit;
}
// Если ID не указан - показываем список групп
if ($id_team === null) {
$json = file_get_contents("team.json");
$teams = json_decode($json, true);
if ($teams === null) {
echo "<p style='color: red;'>Ошибка чтения JSON файла</p>";
exit;
}
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>