diff --git a/public/index.php b/public/index.php
index ec4a7a2..6263fa0 100644
--- a/public/index.php
+++ b/public/index.php
@@ -32,6 +32,7 @@ Users\register_routes($r);
Help\register_routes($r);
Forum\register_routes($r);
Install\register_routes($r);
+Admin\register_routes($r);
$r->post('/move', 'move');
diff --git a/public/admin.php b/src/actions/admin.php
similarity index 95%
rename from public/admin.php
rename to src/actions/admin.php
index 32dbb86..fbe08d1 100644
--- a/public/admin.php
+++ b/src/actions/admin.php
@@ -2,41 +2,44 @@
// admin.php :: primary administration script.
-require_once '../src/lib.php';
+namespace Admin;
-if (!file_exists('../.installed')) redirect('install.php');
+use Router;
-$controlrow = get_control_row();
-
-// Login (or verify) if not logged in.
-if (($userrow = checkcookies()) === false) {
- if (isset($_GET['do']) && $_GET['do'] === 'verify') redirect('users.php?do=verify');
- redirect('/login');
+function register_routes(Router $r): Router
+{
+ global $userrow;
+ if (isset($userrow) && $userrow !== false && $userrow['authlevel'] === 1) {
+ $r->get('/admin', 'Admin\donothing');
+ $r->get('/admin/main', 'Admin\primary');
+ $r->post('/admin/main', 'Admin\primary');
+ $r->get('/admin/items', 'Admin\items');
+ $r->get('/admin/items/:id', 'Admin\edititem');
+ $r->post('/admin/items/:id', 'Admin\edititem');
+ $r->get('/admin/drops', 'Admin\drops');
+ $r->get('/admin/drops/:id', 'Admin\editdrop');
+ $r->post('/admin/drops/:id', 'Admin\editdrop');
+ $r->get('/admin/towns', 'Admin\towns');
+ $r->get('/admin/towns/:id', 'Admin\edittown');
+ $r->post('/admin/towns/:id', 'Admin\edittown');
+ $r->get('/admin/monsters', 'Admin\monsters');
+ $r->get('/admin/monsters/:id', 'Admin\editmonster');
+ $r->post('/admin/monsters/:id', 'Admin\editmonster');
+ $r->get('/admin/level', 'Admin\levels');
+ $r->get('/admin/level/:id', 'Admin\editlevel');
+ $r->post('/admin/level/:id', 'Admin\editlevel');
+ $r->get('/admin/spells', 'Admin\spells');
+ $r->get('/admin/spells/:id', 'Admin\editspell');
+ $r->post('/admin/spells/:id', 'Admin\editspell');
+ $r->get('/admin/users', 'Admin\users');
+ $r->get('/admin/users/:id', 'Admin\edituser');
+ $r->post('/admin/users/:id', 'Admin\edituser');
+ $r->get('/admin/news', 'Admin\addnews');
+ $r->post('/admin/news', 'Admin\addnews');
+ }
+ return $r;
}
-if ($userrow["authlevel"] !== 1) exit("You must have administrator privileges to use the control panel.");
-
-$do = explode(':', $_GET['do'] ?? '');
-match ($do[0]) {
- 'main' => primary(),
- 'items' => items(),
- 'edititem' => edititem($do[1]),
- 'drops' => drops(),
- 'editdrop' => editdrop($do[1]),
- 'towns' => towns(),
- 'edittown' => edittown($do[1]),
- 'monsters' => monsters(),
- 'editmonster' => editmonster($do[1]),
- 'levels' => levels(),
- 'editlevel' => editlevel(),
- 'spells' => spells(),
- 'editspell' => editspell($do[1]),
- 'users' => users(),
- 'edituser' => edituser($do[1]),
- 'news' => addnews(),
- default => donothing()
-};
-
function donothing()
{
$page = <<query('UPDATE control SET gamename=?, gamesize=?, class1name=?, class2name=?, class3name=?, gameopen=?, verifyemail=?, gameurl=?, adminemail=?, shownews=?, showonline=?, showbabble=? WHERE id=1;', [
- $form['gamename'], $form['gamesize'], $form['class1name'], $form['class1name'], $form['class1name'], $form['gameopen'], $form['verifyemail'], $form['gameurl'], $form['adminemail'], $form['shownews'], $form['showonline'], $form['showbabble']
+ $form['gamename'], $form['gamesize'], $form['class1name'], $form['class2name'], $form['class3name'], $form['gameopen'], $form['verifyemail'], $form['gameurl'], $form['adminemail'], $form['shownews'], $form['showonline'], $form['showbabble']
]);
admindisplay("Settings updated.", "Main Settings");
@@ -95,7 +98,7 @@ function primary()
$page = <<Main Settings
These options control several major settings for the overall game engine.
-