<?php function getSubsystemByID(string $id) { global $subsystems; $subsystem = null; foreach ($subsystems as $ss) { if ($ss["source"] === $id) { $subsystem = $ss; } } return $subsystem; } require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/functions.inc"; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.inc"; if (!isset($_GET['_']) || trim($_GET['_']) === "") header("Location: /?error=Invalid request") and die(); $parts = explode("/", $_GET['_']); array_shift($parts); array_shift($parts); $system = $parts[0]; $member = !isset($parts[1]) || $parts[1] === "" ? null : $parts[1]; if ($system !== "cloudburst" && $system !== "raindrops") header("Location: /?error=Invalid system name: " . $system) and die(); $systemCommonName = $system === "cloudburst" ? "Cloudburst System" : "Raindrops System"; $systemID = $system === "cloudburst" ? "ynmuc" : "gdapd"; $subsystems = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/subsystems/$systemID.json"), true) ?? []; if ($member === null) { require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/sysedit.inc'; } else { $isSubsystem = false; $members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $systemID . "/members.json"), true); $memberData = null; $memberCommonName = null; $memberID = null; foreach ($members as $m) { if ($m['name'] === $member) { $memberData = $m; $memberCommonName = $m['display_name'] ?? $m['name']; $memberID = $m['id']; } } if ($memberData === null) { header("Location: /?error=Not found") and die(); } if (isset($_GET["submit"])) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $memberID . ".json")) { $metadata = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $memberID . ".json"), true); } else { die(); } $toUpdate = []; header("Content-Type: text/plain"); if (isset($_GET["bitset"]) && is_numeric($_GET["bitset"])) { $toUpdate["bitset"] = (int)$_GET["bitset"]; } if (isset($_GET["interest"])) { $toUpdate["interest"] = strip_tags($_GET["interest"]); } if (isset($_GET["marefriends"])) { $toUpdate["marefriends"] = array_values(array_filter(array_map(function ($i) { return trim($i); }, explode(",", $_GET["marefriends"])), function ($i) { return !!preg_match("/^(ynmuc|gdapd)\/[a-z]{5}$/m", $i); })); } if (isset($_GET["sisters"])) { $toUpdate["sisters"] = array_values(array_filter(array_map(function ($i) { return trim($i); }, explode(",", $_GET["sisters"])), function ($i) { return !!preg_match("/^(ynmuc|gdapd)\/[a-z]{5}$/m", $i); })); } if (isset($_GET["caretakers"])) { $toUpdate["caretakers"] = array_values(array_filter(array_map(function ($i) { return trim($i); }, explode(",", $_GET["caretakers"])), function ($i) { return !!preg_match("/^(ynmuc|gdapd)\/[a-z]{5}$/m", $i); })); } if (isset($_GET['regressed'])) { if (!!preg_match("/^[a-z]{5}$/m", $_GET['regressed'])) { $toUpdate["regression"] = $_GET['regressed']; } else { $toUpdate["regression"] = null; } } $toUpdate["birth"] = [ "date" => "01-01", "year" => null, "age" => 0 ]; if (isset($_GET["age"]) && is_numeric($_GET["age"])) { $toUpdate["birth"]["age"] = (int)$_GET["age"]; } if (isset($_GET["birth"]) && trim($_GET['birth']) !== "" && !!preg_match("/^\d{4}-\d{2}-\d{2}$/m", $_GET['birth'])) { $toUpdate["birth"]["year"] = (int)substr($_GET["birth"],0, 4); $toUpdate["birth"]["date"] = substr($_GET["birth"],5); } if (isset($_GET["membc"])) { $toUpdate["code"] = $_GET['membc']; } foreach ($toUpdate as $item => $value) { $metadata[$item] = $value; } $metadata = [ "bitset" => $metadata["bitset"] ?? 0, "regression" => $metadata["regression"] ?? null, "median" => $metadata["median"] ?? null, "marefriends" => $metadata["marefriends"] ?? [], "sisters" => $metadata["sisters"] ?? [], "caretakers" => $metadata["caretakers"] ?? [], "heat" => $metadata["heat"] ?? null, "birth" => $metadata["birth"] ?? ["age" => 0, "date" => "01-01", "year" => null], "code" => $metadata["code"] ?? null, "interest" => $metadata["interest"] ?? null ]; file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $memberID . ".json", json_encode($metadata)); header("Location: /" . $_GET['_']); } else { require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/metadata.inc'; } } exit;