From c416ec09921cb0fe7e891f439779a023c2a3c9d8 Mon Sep 17 00:00:00 2001 From: Anonymous Contributor Date: Sun, 10 Sep 2023 01:31:26 +0200 Subject: [PATCH] Fix region deletion as admin --- app/page/Regions.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/page/Regions.php b/app/page/Regions.php index 8050d8e..7d2504e 100644 --- a/app/page/Regions.php +++ b/app/page/Regions.php @@ -11,29 +11,33 @@ use Mcp\Middleware\AdminMiddleware; class Regions extends \Mcp\RequestHandler { + private bool $showAll; + public function __construct(\Mcp\Mcp $app) { - parent::__construct($app, isset($_GET['SHOWALL']) ? new AdminMiddleware($app, $app->config('domain')) : new LoginRequiredMiddleware($app, $app->config('domain'))); + $this->showAll = isset($_GET['SHOWALL']) && $_GET['SHOWALL'] == "1"; + parent::__construct($app, $this->showAll ? new AdminMiddleware($app, $app->config('domain')) : new LoginRequiredMiddleware($app, $app->config('domain'))); } public function get(): void { $table = ''; - $showAll = isset($_GET['SHOWALL']) && $_GET['SHOWALL'] == "1"; - $statement = $this->app->db()->prepare("SELECT uuid,regionName,owner_uuid,locX,locY FROM regions ".($showAll ? "ORDER BY owner_uuid ASC" : "WHERE owner_uuid = ? ORDER BY uuid ASC")); - $statement->execute($showAll ? array() : array($_SESSION['UUID'])); + + $statement = $this->app->db()->prepare("SELECT uuid,regionName,owner_uuid,locX,locY FROM regions ".($this->showAll ? "ORDER BY owner_uuid ASC" : "WHERE owner_uuid = ? ORDER BY uuid ASC")); + $statement->execute($this->showAll ? array() : array($_SESSION['UUID'])); $opensim = new OpenSim($this->app->db()); $csrf = $this->app->csrfField(); + $urlShowall = $this->showAll ? '&SHOWALL=1' : ''; while ($row = $statement->fetch()) { $stats = $this->getRegionStatsData($row['uuid']); - $table = $table.''; + $table = $table.''; } $this->app->template('__dashboard.php')->vars([ - 'title' => isset($_GET["SHOWALL"]) ? 'Regionen verwalten' : 'Deine Regionen', + 'title' => $this->showAll ? 'Regionen verwalten' : 'Deine Regionen', 'username' => $_SESSION['DISPLAYNAME'] ])->unsafeVar('child-content', $table.'
Region NameEigentümerPositionAktionen
'.htmlspecialchars($row['regionName']).''.htmlspecialchars($opensim->getUserName($row['owner_uuid'])).''.Util::fillString(($row['locX'] / 256), 4).' / '.Util::fillString(($row['locY'] / 256), 4).'
'.$csrf.'
'.htmlspecialchars($row['regionName']).''.htmlspecialchars($opensim->getUserName($row['owner_uuid'])).''.Util::fillString(($row['locX'] / 256), 4).' / '.Util::fillString(($row['locY'] / 256), 4).'
'.$csrf.'
')->render(); } @@ -41,11 +45,10 @@ class Regions extends \Mcp\RequestHandler public function post(): void { $validator = new FormValidator(array( - 'remove' => array('required' => true), '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}$/') )); - if ($validator->isValid($_POST)) { + if (isset($_POST['remove']) && $validator->isValid($_POST)) { if (isset($_GET['SHOWALL'])) { $statementMembership = $this->app->db()->prepare("DELETE FROM regions WHERE uuid = ?"); $statementMembership->execute(array($_POST['region'])); @@ -55,7 +58,7 @@ class Regions extends \Mcp\RequestHandler } } - header('Location: index.php?page=regions'); + header('Location: index.php?page=regions'.($this->showAll ? '&SHOWALL=1' : '')); } private function cleanSize($bytes)