Moved admin to new router/actions model
This commit is contained in:
parent
9ce0bab606
commit
30588252d8
|
@ -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');
|
||||
|
||||
|
|
|
@ -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 = <<<HTML
|
||||
|
@ -80,7 +83,7 @@ function primary()
|
|||
if (($form['gamesize'] % 5) != 0) exit('Map size must be divisible by five.');
|
||||
|
||||
db()->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 = <<<HTML
|
||||
<b><u>Main Settings</u></b><br>
|
||||
These options control several major settings for the overall game engine.<br><br>
|
||||
<form action="admin.php?do=main" method="post">
|
||||
<form action="/admin/main" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%"><span class="highlight">Game Open:</span></td><td><select name="gameopen"><option value="1" {{open1select}}>Open</option><option value="0" {{open0select}}>Closed</option></select><br><span class="small">Close the game if you are upgrading or working on settings and don't want to cause odd errors for end-users. Closing the game will completely halt all activity.</span></td></tr>
|
||||
<tr><td width="20%">Game Name:</td><td><input type="text" name="gamename" value="{{gamename}}" /><br><span class="small">Default is "Dragon Knight". Change this if you want to change to call your game something different.</span></td></tr>
|
||||
|
@ -136,7 +139,7 @@ function items()
|
|||
$hasItems = false;
|
||||
while ($row = $items->fetchArray(SQLITE3_BOTH)) {
|
||||
$hasItems = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=edititem:".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"/admin/items/".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$hasItems) $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No items found.</td></tr>\n";
|
||||
|
@ -171,7 +174,7 @@ function edititem($id)
|
|||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Items</u></b><br><br>
|
||||
<form action="admin.php?do=edititem:$id" method="post">
|
||||
<form action="/admin/items/$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" value="{{name}}" /></td></tr>
|
||||
|
@ -211,7 +214,7 @@ function drops()
|
|||
$has_drops = false;
|
||||
while ($row = $drops->fetchArray(SQLITE3_ASSOC)) {
|
||||
$has_drops = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=editdrop:".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"/admin/drops/".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$has_drops) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No drops found.</td></tr>\n"; }
|
||||
|
@ -249,7 +252,7 @@ function editdrop($id)
|
|||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Drops</u></b><br><br>
|
||||
<form action="admin.php?do=editdrop:$id" method="post">
|
||||
<form action="/admin/drops/$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" value="{{name}}" /></td></tr>
|
||||
|
@ -284,7 +287,7 @@ function towns()
|
|||
$has_towns = false;
|
||||
while ($row = $towns->fetchArray(SQLITE3_ASSOC)) {
|
||||
$has_towns = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=edittown:".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"/admin/towns/".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$has_towns) $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No towns found.</td></tr>\n";
|
||||
|
@ -330,7 +333,7 @@ function edittown($id)
|
|||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Towns</u></b><br><br>
|
||||
<form action="admin.php?do=edittown:$id" method="post">
|
||||
<form action="/admin/towns/$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" value="{{name}}" /></td></tr>
|
||||
|
@ -368,7 +371,7 @@ function monsters()
|
|||
$has_monsters = false;
|
||||
while ($row = $monsters->fetchArray(SQLITE3_ASSOC)) {
|
||||
$has_monsters = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=editmonster:".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"/admin/monsters/".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$has_monsters) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No monsters found.</td></tr>\n"; }
|
||||
|
@ -411,7 +414,7 @@ function editmonster($id)
|
|||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Monsters</u></b><br><br>
|
||||
<form action="admin.php?do=editmonster:$id" method="post">
|
||||
<form action="/admin/monsters/$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" size="30" maxlength="30" value="{{name}}" /></td></tr>
|
||||
|
@ -443,7 +446,7 @@ function spells()
|
|||
|
||||
while ($row = $spells->fetchArray(SQLITE3_ASSOC)) {
|
||||
$has_spells = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=editspell:".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"/admin/spells/".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$has_spells) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No spells found.</td></tr>\n"; }
|
||||
|
@ -478,7 +481,7 @@ function editspell($id)
|
|||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Spells</u></b><br><br>
|
||||
<form action="admin.php?do=editspell:$id" method="post">
|
||||
<form action="/admin/spells/$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" size="30" maxlength="30" value="{{name}}" /></td></tr>
|
||||
|
@ -511,7 +514,7 @@ function levels()
|
|||
$page = <<<HTML
|
||||
<b><u>Edit Levels</u></b><br>
|
||||
Select a level number from the dropdown box to edit it.<br><br>
|
||||
<form action="admin.php?do=editlevel" method="post">
|
||||
<form action="/admin/level" method="post">
|
||||
<select name="level">
|
||||
$options
|
||||
</select>
|
||||
|
@ -610,7 +613,7 @@ function editlevel()
|
|||
$page = <<<HTML
|
||||
<b><u>Edit Levels</u></b><br><br>
|
||||
Experience values for each level should be the cumulative total amount of experience up to this point. All other values should be only the new amount to add this level.<br><br>
|
||||
<form action="admin.php?do=editlevel" method="post">
|
||||
<form action="/admin/level" method="post">
|
||||
<input type="hidden" name="level" value="$id" />
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
|
@ -661,7 +664,7 @@ function users()
|
|||
|
||||
while ($row = $users->fetchArray(SQLITE3_ASSOC)) {
|
||||
$has_users = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=edituser:".$row["id"]."\">".$row["username"]."</a></td></tr>\n";
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"/admin/users/".$row["id"]."\">".$row["username"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$has_users) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No spells found.</td></tr>\n"; }
|
||||
|
@ -800,7 +803,7 @@ function edituser($id)
|
|||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Users</u></b><br><br>
|
||||
<form action="admin.php?do=edituser:$id" method="post">
|
||||
<form action="/admin/users/$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Username:</td><td>{{username}}</td></tr>
|
||||
|
@ -904,7 +907,7 @@ function addnews()
|
|||
|
||||
$page = <<<HTML
|
||||
<b><u>Add A News Post</u></b><br><br>
|
||||
<form action="admin.php?do=news" method="post">
|
||||
<form action="/admin/news" method="post">
|
||||
Type your post below and then click Submit to add it.<br>
|
||||
<textarea name="content" rows="5" cols="50"></textarea><br>
|
||||
<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />
|
|
@ -10,6 +10,7 @@ require_once 'actions/towns.php';
|
|||
require_once 'actions/fight.php';
|
||||
require_once 'actions/forum.php';
|
||||
require_once 'actions/install.php';
|
||||
require_once 'actions/admin.php';
|
||||
|
||||
$uri = uri();
|
||||
|
||||
|
@ -41,5 +42,10 @@ if (!file_exists('../.installed') && $uri[0] !== 'install') {
|
|||
header("Location: users.php?do=verify");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ensure the user can't use the admin panel.
|
||||
if ($userrow['authlevel'] !== 1 && $uri[0] === 'admin') {
|
||||
redirect('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true,
|
|||
if ($userrow["longitude"] < 0) { $userrow["longitude"] = $userrow["longitude"] * -1 . "W"; } else { $userrow["longitude"] .= "E"; }
|
||||
$userrow["experience"] = number_format($userrow["experience"]);
|
||||
$userrow["gold"] = number_format($userrow["gold"]);
|
||||
if ($userrow["authlevel"] == 1) { $userrow["adminlink"] = "<a href=\"admin.php\">Admin</a><br>"; } else { $userrow["adminlink"] = ""; }
|
||||
if ($userrow["authlevel"] == 1) { $userrow["adminlink"] = "<a href=\"/admin\">Admin</a><br>"; } else { $userrow["adminlink"] = ""; }
|
||||
|
||||
// HP/MP/TP bars.
|
||||
$stathp = ceil($userrow["currenthp"] / $userrow["maxhp"] * 100);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
$template = <<<THEVERYENDOFYOU
|
||||
$template = <<<HTML
|
||||
<head>
|
||||
<title>{{title}}</title>
|
||||
<style type="text/css">
|
||||
|
@ -53,19 +53,19 @@ a:hover {
|
|||
<td width="150" style="border-right: solid 1px black;">
|
||||
<b><u>DK Administration</u></b><br><br>
|
||||
<b>Links:</b><br>
|
||||
<a href="admin.php">Admin Home</a><br>
|
||||
<a href="/admina">Admin Home</a><br>
|
||||
<a href="/">Game Home</a><br><br>
|
||||
<b>Primary Data:</b><br>
|
||||
<a href="admin.php?do=main">Main Settings</a><br>
|
||||
<a href="admin.php?do=news">Add News Post</a><br>
|
||||
<a href="admin.php?do=users">Edit Users</a><br><br>
|
||||
<a href="/admin/main">Main Settings</a><br>
|
||||
<a href="/admin/news">Add News Post</a><br>
|
||||
<a href="/admin/users">Edit Users</a><br><br>
|
||||
<b>Game Data:</b><br>
|
||||
<a href="admin.php?do=items">Edit Items</a><br>
|
||||
<a href="admin.php?do=drops">Edit Drops</a><br>
|
||||
<a href="admin.php?do=towns">Edit Towns</a><br>
|
||||
<a href="admin.php?do=monsters">Edit Monsters</a><br>
|
||||
<a href="admin.php?do=levels">Edit Levels</a><br>
|
||||
<a href="admin.php?do=spells">Edit Spells</a><br>
|
||||
<a href="/admin/items">Edit Items</a><br>
|
||||
<a href="/admin/drops">Edit Drops</a><br>
|
||||
<a href="/admin/towns">Edit Towns</a><br>
|
||||
<a href="/admin/monsters">Edit Monsters</a><br>
|
||||
<a href="/admin/levels">Edit Levels</a><br>
|
||||
<a href="/admin/spells">Edit Spells</a><br>
|
||||
</td><td>
|
||||
{{content}}
|
||||
</td></tr></table>
|
||||
|
@ -74,5 +74,4 @@ a:hover {
|
|||
<td width="25%" align="center">Powered by <a href="http://dragon.se7enet.com/dev.php" target="_new">Dragon Knight</a></td><td width="25%" align="center">© 2003-2006 by renderse7en</td><td width="25%" align="center">{{totaltime}} Seconds, {{numqueries}} Queries</td><td width="25%" align="center">Version {{version}} {{build}}</td>
|
||||
</center></body>
|
||||
</html>
|
||||
THEVERYENDOFYOU;
|
||||
?>
|
||||
HTML;
|
||||
|
|
Loading…
Reference in New Issue
Block a user