Sindbad~EG File Manager
<?php
// ThreeBody.php
// Set HTTP header to prevent caching
header('Content-Type: text/html; charset=UTF-8');
header("Cache-Control: no-cache, must-revalidate");
// Start or resume the session
session_start();
$sessionId = session_id(); // guaranteed not to contain a tilde
ini_set('display_errors', 1);
error_reporting(E_ALL);
// If simulation data is submitted via POST (for example, from BrowseThreeBody.php),
// store it in the session so it can be used to prepopulate the form.
if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['nbodies']) || isset($_POST['mass']))) {
$_SESSION['caption'] = $_POST;
}
if ($_SERVER['SERVER_NAME'] == 'localhost') {
$nextpagegraph = "https://localhost:8443/GraphSolution.php";
$serverAddress = 'localhost';
$username = $password = null;
} else {
$nextpagegraph = "https://mathxpert.org/GraphSolution.php";
$serverAddress = 'mathxpert.org';
$username = 'beeson';
$password = 'Turing2024';
}
$serverPort = 12350; // Ending in 50 for ThreeBody, 49 for MathXpert
$timeout = 3600; // Connection timeout in seconds.
$startupDelay = 5; // Delay for server startup if needed
// Clear saved session data if requested
if (isset($_GET['clear']) && $_GET['clear'] == '1') {
unset($_SESSION['caption']);
header("Location: ThreeBody.php");
exit();
}
if (!(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1)
|| isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) {
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
?>
<script>
// This function updates the hidden input fields with the actual viewport dimensions.
function updateFields() {
// Update viewport dimensions using client window size
var w = window.innerWidth;
var h = window.innerHeight;
document.getElementById("pxminField").value = 0;
document.getElementById("pxmaxField").value = w;
document.getElementById("pyminField").value = 0;
document.getElementById("pymaxField").value = h;
console.log("Updated viewport dimensions: " + w + " x " + h);
// alert("Updating viewport dimensions: " + w + " x " + h);
}
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Process submitted bodies and store them in session
$bodies = array();
if (isset($_POST['mass']) && is_array($_POST['mass'])) {
$count = count($_POST['mass']);
for ($i = 0; $i < $count; $i++) {
$bodies[] = array(
'mass' => (double) $_POST['mass'][$i],
'color' => $_POST['color'][$i], // expected in "rgb(R, G, B)" format
'r' => (double) $_POST['r'][$i],
'x0' => (double) $_POST['x0'][$i],
'y0' => (double) $_POST['y0'][$i],
'p0' => (double) $_POST['p0'][$i],
'q0' => (double) $_POST['q0'][$i]
);
}
}
// Save submitted form data in session for repopulation if needed.
$_SESSION['caption'] = $_POST;
}
// Helper function: Convert a color string "rgb(R, G, B)" to "R,G,B"
function convertColor($colorStr) {
$colorStr = trim($colorStr);
if (strpos($colorStr, "rgb(") === 0) {
$inside = substr($colorStr, 4, -1);
return str_replace(' ', '', $inside);
}
return $colorStr;
}
?>
</script>
<!DOCTYPE html>
<html>
<head>
<title>Review Entries</title>
<style>
body { font-family: Arial, sans-serif; }
.color-swatch {
display: inline-block;
width: 20px;
height: 20px;
border: 1px solid #000;
vertical-align: middle;
}
.button-group button,
.button-group input[type="submit"] {
padding: 10px 20px;
font-size: 16px;
background-color: rgb(0,0,128);
color: white;
border: none;
cursor: pointer;
margin-right: 5px;
}
.button-group button:hover,
.button-group input[type="submit"]:hover {
background-color: rgb(0,0,150);
}
</style>
</head>
<body>
<h1>Submitted Entries</h1>
<?php foreach ($bodies as $index => $body): ?>
<h3>Body <?php echo $index + 1; ?></h3>
<p>
Mass: <?php echo htmlspecialchars($body['mass']); ?><br>
Color:
<span class="color-swatch" style="background-color: <?php echo htmlspecialchars($body['color']); ?>;"></span>
<?php echo htmlspecialchars($body['color']); ?><br>
Radius: <?php echo htmlspecialchars($body['r']); ?><br>
Initial Position: (<?php echo htmlspecialchars($body['x0']); ?>, <?php echo htmlspecialchars($body['y0']); ?>)<br>
Initial Velocity: (<?php echo htmlspecialchars($body['p0']); ?>, <?php echo htmlspecialchars($body['q0']); ?>)
</p>
<hr>
<?php endforeach; ?>
<!-- Form to re-submit data with hidden "solve" field, with timestamp to prevent caching -->
<form id="solveForm" method="post" action="ThreeBody.php?v=timestamp">
<?php
if (isset($_SESSION['caption'])) {
foreach ($_SESSION['caption'] as $field => $values) {
if (is_array($values)) {
foreach ($values as $value) {
echo '<input type="hidden" name="' . htmlspecialchars($field) . '[]" value="' . htmlspecialchars($value) . '">' . "\n";
}
} else {
echo '<input type="hidden" name="' . htmlspecialchars($field) . '" value="' . htmlspecialchars($values) . '">' . "\n";
}
}
}
?>
<input type="hidden" name="solve" value="1">
<div class="button-group">
<button type="submit">Solve and Draw</button>
<button type="button" onclick="window.location.href='ThreeBody.php'">Edit Bodies</button>
</div>
</form>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists