2020-06-03 15:31:18 +00:00
< ? php
2023-08-27 03:31:32 +00:00
$HTML -> setHTMLTitle ( " Deine Regionen " );
$HTML -> importSeitenInhalt ( " deine-regionen.html " );
2020-06-03 15:31:18 +00:00
2021-01-08 14:14:09 +00:00
function cleanSize ( $bytes )
{
2023-08-27 03:31:32 +00:00
if ( $bytes > 0 ) {
2021-01-08 14:14:09 +00:00
$unit = intval ( log ( $bytes , 1024 ));
$units = array ( 'B' , 'KB' , 'MB' , 'GB' );
2023-08-27 03:31:32 +00:00
if ( array_key_exists ( $unit , $units ) === true ) {
2021-01-08 14:14:09 +00:00
return sprintf ( '%d %s' , $bytes / pow ( 1024 , $unit ), $units [ $unit ]);
}
}
return $bytes ;
}
function getRegionStatsData ( $regionID )
{
global $RUNTIME ;
2023-08-23 16:16:34 +00:00
$statement = $RUNTIME [ 'PDO' ] -> prepare ( " SELECT Prims,SimFPS,PhyFPS,ProcMem,RegionVersion FROM regions_info WHERE regionID = ? " );
2023-08-27 03:31:32 +00:00
$statement -> execute ([ $regionID ]);
2021-01-08 14:14:09 +00:00
2023-08-27 03:31:32 +00:00
if ( $row = $statement -> fetch ()) {
2021-01-08 14:14:09 +00:00
$return = array ();
$return [ 'Prims' ] = $row [ 'Prims' ];
$return [ 'SimFPS' ] = $row [ 'SimFPS' ];
$return [ 'PhyFPS' ] = $row [ 'PhyFPS' ];
$return [ 'ProcMem' ] = cleanSize ( str_replace ( " . " , " " , str_replace ( " , " , " . " , $row [ 'ProcMem' ])) . " 000 " );
2021-01-08 14:17:32 +00:00
$return [ 'RegionVersion' ] = trim ( $row [ 'RegionVersion' ]);
2021-01-08 14:14:09 +00:00
return $return ;
}
return array ();
}
2023-08-27 03:31:32 +00:00
if ( $_SERVER [ 'REQUEST_METHOD' ] == 'POST' && isset ( $_REQUEST [ 'remove' ])) {
include_once 'app/FormValidator.php' ;
2023-08-23 16:16:36 +00:00
$validator = new FormValidator ( array (
'region' => array ( 'required' => true , 'regex' => '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/' )
));
2023-08-27 03:31:32 +00:00
if ( $validator -> isValid ( $_POST )) {
if ( isset ( $_SESSION [ 'LEVEL' ]) && $_SESSION [ 'LEVEL' ] >= 100 ) {
2023-08-23 16:16:36 +00:00
$statementMembership = $RUNTIME [ 'PDO' ] -> prepare ( " DELETE FROM regions WHERE uuid = ? " );
$statementMembership -> execute ( array ( $_POST [ 'region' ]));
} else {
$statementMembership = $RUNTIME [ 'PDO' ] -> prepare ( " DELETE FROM regions WHERE uuid = ? AND owner_uuid = ? " );
$statementMembership -> execute ( array ( $_POST [ 'region' ], $_SESSION [ 'UUID' ]));
}
2021-01-06 14:42:48 +00:00
}
2023-08-23 16:16:34 +00:00
header ( 'Location: index.php?page=regions' );
die ();
2021-01-06 14:42:48 +00:00
}
2020-06-03 15:31:18 +00:00
$table = '<table class="table"><thead><tr><th scope="col">Region Name</th><th scope="col">Eigentümer</th><th scope="col">Position</th><th scope="col">Aktionen</th></thead><tbody>%%ENTRY%%</tbody></table>' ;
2023-08-23 16:16:34 +00:00
$showAll = isset ( $_SESSION [ 'LEVEL' ]) && $_SESSION [ 'LEVEL' ] >= 100 && isset ( $_REQUEST [ 'SHOWALL' ]) && $_REQUEST [ 'SHOWALL' ] == " 1 " ;
$statement = $RUNTIME [ 'PDO' ] -> prepare ( " SELECT uuid,regionName,owner_uuid,locX,locY FROM regions " . ( $showAll ? " ORDER BY owner_uuid ASC " : " WHERE owner_uuid = ? ORDER BY uuid ASC " ));
2023-08-27 03:31:32 +00:00
$statement -> execute ( $showAll ? array () : array ( $_SESSION [ 'UUID' ]));
2020-06-03 15:31:18 +00:00
2023-08-27 03:31:32 +00:00
include_once 'app/OpenSim.php' ;
2023-08-23 16:16:35 +00:00
$opensim = new OpenSim ();
2023-08-27 03:31:32 +00:00
while ( $row = $statement -> fetch ()) {
2021-01-08 14:14:09 +00:00
$stats = getRegionStatsData ( $row [ 'uuid' ]);
2023-08-27 03:31:32 +00:00
$entry = '<tr><td>' . htmlspecialchars ( $row [ 'regionName' ]) . '<div class="blockquote-footer">' . ( ! empty ( $stats ) ? 'Prims: ' . $stats [ 'Prims' ] . '; RAM-Nutzung: ' . $stats [ 'ProcMem' ] . '; SIM/PHYS FPS: ' . $stats [ 'SimFPS' ] . '/' . $stats [ 'PhyFPS' ] . ' (' . $stats [ 'RegionVersion' ] . ')' : 'Keine Statistik verfügbar' ) . '</div></td><td>' . htmlspecialchars ( $opensim -> getUserName ( $row [ 'owner_uuid' ])) . '</td><td>' . fillString (( $row [ 'locX' ] / 256 ), 4 ) . ' / ' . fillString (( $row [ 'locY' ] / 256 ), 4 ) . '</td><td><form action="index.php?page=regions" method="post">%%CSRF%%<input type="hidden" name="region" value="' . $row [ 'uuid' ] . '"><button type="submit" name="remove" class="btn btn-link btn-sm">LÖSCHEN</button></form></td></tr>' ;
2020-06-03 15:31:18 +00:00
$table = str_replace ( " %%ENTRY%% " , $entry . " %%ENTRY%% " , $table );
}
$table = str_replace ( " %%ENTRY%% " , " " , $table );
$HTML -> ReplaceSeitenInhalt ( " %%REGION-LIST%% " , $table );
$HTML -> build ();
echo $HTML -> ausgabe ();