&$update) { if ($update['build'] === $build) { if (isset($update['changes'][$idx])) { array_splice($update['changes'], $idx, 1); if (count($update['changes']) === 0) { array_splice($versionData['updates'], $uKey, 1); } file_put_contents($jsonFile, json_encode($versionData, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); } break; } } } if (isset($_POST['build'])) { http_response_code(204); exit(); } $versionData = []; if (file_exists($jsonFile)) { $jsonContent = file_get_contents($jsonFile); $versionData = json_decode($jsonContent, true); if (!is_array($versionData)) { $versionData = ['updates' => []]; } } else { $versionData = ['updates' => []]; } // Alapértelmezett értékek a legutóbbi build alapján $defaultEnv = 'l'; // Éles $defaultStatus = 'a'; // Aktív $defaultDateTime = date('Y-m-d\TH:i'); if (!empty($versionData['updates'])) { $lastBuild = $versionData['updates'][0]['build']; if (strlen($lastBuild) >= 2) { $defaultEnv = substr($lastBuild, 0, 1); $defaultStatus = substr($lastBuild, 1, 1); $timestamp = (int) substr($lastBuild, 2); $defaultDateTime = date('Y-m-d\TH:i', $timestamp); } } $message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['env']) && isset($_POST['status']) && isset($_POST['datetime']) && isset($_POST['change']) && isset($_POST['anticsrfid']) && $_POST['anticsrfid'] == $_SESSION["anticsrfid"]) { $env = trim($_POST['env']); $status = trim($_POST['status']); $datetime = trim($_POST['datetime']); $change = trim($_POST['change']); if ($env !== '' && $status !== '' && $datetime !== '' && $change !== '') { // Build szám generálása $timestamp = strtotime($datetime); $build = $env . $status . $timestamp; $found = false; foreach ($versionData['updates'] as &$update) { if ($update['build'] === $build) { if (!in_array($change, $update['changes'], true)) { array_unshift($update['changes'], $change); } $found = true; break; } } unset($update); if (!$found) { array_unshift($versionData['updates'], [ 'build' => $build, 'changes' => [$change] ]); } if (file_put_contents($jsonFile, json_encode($versionData, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)) === false) { $message = 'Mentés sikertelen: nem lehet írni a fájlt. Útvonal: ' . htmlspecialchars($jsonFile); } else { $message = 'A változtatás mentve lett. Build szám: ' . htmlspecialchars($build); } } else { $message = 'Minden mező kitöltése kötelező.'; } } $anticsrfid = bin2hex(random_bytes(24)); $_SESSION["anticsrfid"] = $anticsrfid; ?>