1.0.0.1.2 Event Horizon
Creators: name: Kunferman, C.R. Kunferman
Publisher: name: Zphero
Year: 2025

description: <0 Event Horizon 0>
<?php
// Database connection settings
<0 cl:dbconnect 0>

// User input
$addressToDestroy = $_POST['address']; // e.g., 13.0.0.1.1
$userAddress = $_POST['user_address']; // User’s address (dpown)
$destroyRequest = $_POST['destroy_to_zero'] ?? false;

if ($destroyRequest !== 'yes' || empty($addressToDestroy) || empty($userAddress)) {
    die("Invalid destruction request.");
}

// Calculate XYZ of the datapoint to destroy
$coords = explode('.', $addressToDestroy);
if (count($coords) !== 5) die("0");
list($radius, $upperLat, $upperLong, $lowerLat, $lowerLong) = array_map('floatval', $coords);
if ($upperLat > 0 && $lowerLong == 0 && $lowerLat == 0) {
    $x = $radius * sin($upperLat) * cos($upperLong);
    $y = $radius * sin($upperLat) * sin($upperLong);
    $z = $radius * cos($upperLat);
} elseif ($lowerLat > 0 && $upperLong == 0 && $upperLat == 0) {
    $x = $radius * sin($lowerLat) * cos($lowerLong) * (-1);
    $y = $radius * sin($lowerLat) * sin($lowerLong) * (-1);
    $z = $radius * cos($lowerLat) * (-1);
} else {
    die("0");
}

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // Step 1: Check ownership
    $stmt = $conn->prepare("SELECT dpown, odpown FROM your_table WHERE x = :x AND y = :y AND z = :z");
    $stmt->bindParam(':x', $x);
    $stmt->bindParam(':y', $y);
    $stmt->bindParam(':z', $z);
    $stmt->execute();
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$result) {
        die("Datapoint not found.");
    }
    
    if ($userAddress !== $result['odpown']) {
        die("Only the original owner ({$result['odpown']}) can initiate destruction. Current user: $userAddress.");
    }
    
    // Step 2: Prompt for memorial
    if (!isset($_POST['memorial_type'])) {
        echo "Destruction authorized. Please select a memorial:\n";
        echo "<form method='POST' action='event_horizon.php' enctype='multipart/form-data'>";
        echo "<input type='hidden' name='address' value='$addressToDestroy'>";
        echo "<input type='hidden' name='user_address' value='$userAddress'>";
        echo "<input type='hidden' name='destroy_to_zero' value='yes'>";
        echo "<label><input type='radio' name='memorial_type' value='custom'> Upload custom:</label>";
        echo "<input type='file' name='custom_memorial'><br>";
        echo "<label><input type='radio' name='memorial_type' value='sphere'> Select from memorial sphere (4.0.0.1.1 - 4.10.18.0.0):</label>";
        echo "<input type='text' name='memorial_address' placeholder='e.g., 4.5.5.0.0'><br>";
        echo "<input type='submit' value='Submit Memorial'>";
        echo "</form>";
        exit;
    }
    
    // Step 3: Handle memorial can be provided at a sphere 4 address or uploaded by user
    $memorialType = $_POST['memorial_type'];
    if ($memorialType === 'custom' && isset($_FILES['custom_memorial']) && $_FILES['custom_memorial']['error'] === UPLOAD_ERR_OK) {
        $memorialContent = file_get_contents($_FILES['custom_memorial']['tmp_name']);
        $memorialHead = $_FILES['custom_memorial']['name'];
        $memorialExt = pathinfo($memorialHead, PATHINFO_EXTENSION);
    } elseif ($memorialType === 'sphere') {
        $memorialAddress = $_POST['memorial_address'];
        $mCoords = explode('.', $memorialAddress);
        if (count($mCoords) !== 5 || $mCoords[0] != 4 || ($mCoords[1] > 10 || $mCoords[2] > 18) || $mCoords[3] != 0 || $mCoords[4] != 0) {
            die("Invalid memorial sphere address.");
        }
        list($mRadius, $mUpperLat, $mUpperLong, $mLowerLat, $mLowerLong) = array_map('floatval', $mCoords);
        $mx = $mRadius * sin($mUpperLat) * cos($mUpperLong);
        $my = $mRadius * sin($mUpperLat) * sin($mUpperLong);
        $mz = $mRadius * cos($mUpperLat);
        
        $stmt = $conn->prepare("SELECT dphead, dpact, dpext FROM your_table WHERE x = :x AND y = :y AND z = :z");
        $stmt->bindParam(':x', $mx);
        $stmt->bindParam(':y', $my);
        $stmt->bindParam(':z', $mz);
        $stmt->execute();
        $memorialResult = $stmt->fetch(PDO::FETCH_ASSOC);
        
        if ($memorialResult) {
            $memorialHead = $memorialResult['dphead'];
            $memorialContent = $memorialResult['dpact'];
            $memorialExt = $memorialResult['dpext'];
        } else {
            die("Memorial not found at $memorialAddress.");
        }
    } else {
        die("Invalid memorial selection.");
    }
    
    // Step 4: Check for tethers
    $stmt = $conn->prepare("SELECT COUNT(*) FROM your_table WHERE aprocs = :address");
    $stmt->bindParam(':address', $addressToDestroy);
    $stmt->execute();
    $tetherCount = $stmt->fetchColumn();
    
    if ($tetherCount > 0) {
        echo "Destruction aborted: $tetherCount dependent tethers found. Redirecting to consensus petition...";
        // header("Location: consensus_petition.php?address=$addressToDestroy");
        exit;
    }
    
    // Step 5: Pass to black hole with memorial data
    header("Location: 0.0.0.0.0?address=$addressToDestroy&memorial_head=" . urlencode($memorialHead) . "&memorial_content=" . urlencode($memorialContent) . "&memorial_ext=" . urlencode($memorialExt));
    exit;
    
} catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}

$conn = null;
?>