File Update
indentations
This commit is contained in:
@@ -1 +1,131 @@
|
||||
<?php require_once __DIR__.'/guard.php'; require_login(); $file=__DIR__.'/../data/commands.json'; $out=__DIR__.'/../data/outbox.txt'; $cmds=file_exists($file)?json_decode(file_get_contents($file),true):[]; $editing=''; $editText=''; if($_SERVER['REQUEST_METHOD']==='POST'){ $a=$_POST['action']??''; if($a==='save'){ $name=strtolower(trim($_POST['name']??'')); $text=trim($_POST['text']??''); if($name&&$text){ $cmds[$name]=$text; file_put_contents($file,json_encode($cmds,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); } header('Location: commands.php?saved=1'); exit; } if($a==='delete'){ $name=strtolower(trim($_POST['name']??'')); if(isset($cmds[$name])){ unset($cmds[$name]); file_put_contents($file,json_encode($cmds,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); } header('Location: commands.php?deleted=1'); exit; } if($a==='edit'){ $editing=strtolower(trim($_POST['name']??'')); $editText=$cmds[$editing]??''; } if($a==='send'){ $name=strtolower(trim($_POST['name']??'')); if(isset($cmds[$name])) file_put_contents($out,$cmds[$name].PHP_EOL,FILE_APPEND); header('Location: commands.php?sent=1'); exit; } } ?><!DOCTYPE html><html><head><meta charset="utf-8"><title>Kommandoer</title><link rel="stylesheet" href="style.css"><script>function confirmDelete(n){return confirm('Slet !'+n+'?')}</script></head><body><div class="wrap"><div class="card"><h2>Bot-kommandoer</h2><p><a class="btn" href="index.php">← Tilbage</a><a class="btn" href="help.php" target="_blank">📖 Hjælp</a></p><form method="post" style="margin-bottom:1rem"><input type="hidden" name="action" value="save"><label>!kommando (uden !) <input name="name" required value="<?php echo htmlspecialchars($editing); ?>"></label><br><label>Svar <textarea name="text" rows="3" required><?php echo htmlspecialchars($editText); ?></textarea></label><br><button class="btn"><?php echo $editing?'Opdater':'Gem'; ?></button></form><table><tr><th>!kommando</th><th>Svar</th><th>Handling</th></tr><?php foreach($cmds as $k=>$v): ?><tr><td><?php echo '!'.htmlspecialchars($k); ?></td><td><?php echo htmlspecialchars($v); ?></td><td><form method="post" style="display:inline"><input type="hidden" name="action" value="edit"><input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>"><button class="btn">Redigér</button></form> <form method="post" style="display:inline" onsubmit="return confirmDelete('<?php echo htmlspecialchars($k); ?>')"><input type="hidden" name="action" value="delete"><input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>"><button class="btn">Slet</button></form> <form method="post" style="display:inline"><input type="hidden" name="action" value="send"><input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>"><button class="btn">Send nu</button></form></td></tr><?php endforeach; ?></table></div></div></body></html>
|
||||
<?php
|
||||
require_once __DIR__ . '/guard.php';
|
||||
require_login();
|
||||
|
||||
$file = __DIR__ . '/../data/commands.json';
|
||||
$out = __DIR__ . '/../data/outbox.txt';
|
||||
|
||||
$cmds = file_exists($file) ? json_decode(file_get_contents($file), true) : [];
|
||||
|
||||
$editing = '';
|
||||
$editText = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$a = $_POST['action'] ?? '';
|
||||
|
||||
if ($a === 'save') {
|
||||
$name = strtolower(trim($_POST['name'] ?? ''));
|
||||
$text = trim($_POST['text'] ?? '');
|
||||
|
||||
if ($name && $text) {
|
||||
$cmds[$name] = $text;
|
||||
file_put_contents($file, json_encode($cmds, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
header('Location: commands.php?saved=1');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($a === 'delete') {
|
||||
$name = strtolower(trim($_POST['name'] ?? ''));
|
||||
if (isset($cmds[$name])) {
|
||||
unset($cmds[$name]);
|
||||
file_put_contents($file, json_encode($cmds, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
header('Location: commands.php?deleted=1');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($a === 'edit') {
|
||||
$editing = strtolower(trim($_POST['name'] ?? ''));
|
||||
$editText = $cmds[$editing] ?? '';
|
||||
}
|
||||
|
||||
if ($a === 'send') {
|
||||
$name = strtolower(trim($_POST['name'] ?? ''));
|
||||
if (isset($cmds[$name])) {
|
||||
file_put_contents($out, $cmds[$name] . PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
header('Location: commands.php?sent=1');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Kommandoer</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script>
|
||||
function confirmDelete(n) {
|
||||
return confirm('Slet !' + n + '?');
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<div class="card">
|
||||
<h2>Bot-kommandoer</h2>
|
||||
<p>
|
||||
<a class="btn" href="index.php">← Tilbage</a>
|
||||
<a class="btn" href="help.php" target="_blank">📖 Hjælp</a>
|
||||
</p>
|
||||
|
||||
<form method="post" style="margin-bottom:1rem">
|
||||
<input type="hidden" name="action" value="save">
|
||||
|
||||
<label>
|
||||
!kommando (uden !)
|
||||
<input name="name" required value="<?php echo htmlspecialchars($editing); ?>">
|
||||
</label>
|
||||
<br>
|
||||
|
||||
<label>
|
||||
Svar
|
||||
<textarea name="text" rows="3" required><?php echo htmlspecialchars($editText); ?></textarea>
|
||||
</label>
|
||||
<br>
|
||||
|
||||
<button class="btn"><?php echo $editing ? 'Opdater' : 'Gem'; ?></button>
|
||||
</form>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>!kommando</th>
|
||||
<th>Svar</th>
|
||||
<th>Handling</th>
|
||||
</tr>
|
||||
|
||||
<?php foreach ($cmds as $k => $v): ?>
|
||||
<tr>
|
||||
<td><?php echo '!' . htmlspecialchars($k); ?></td>
|
||||
<td><?php echo htmlspecialchars($v); ?></td>
|
||||
<td>
|
||||
<form method="post" style="display:inline">
|
||||
<input type="hidden" name="action" value="edit">
|
||||
<input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>">
|
||||
<button class="btn">Redigér</button>
|
||||
</form>
|
||||
|
||||
<form method="post" style="display:inline" onsubmit="return confirmDelete('<?php echo htmlspecialchars($k); ?>')">
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>">
|
||||
<button class="btn">Slet</button>
|
||||
</form>
|
||||
|
||||
<form method="post" style="display:inline">
|
||||
<input type="hidden" name="action" value="send">
|
||||
<input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>">
|
||||
<button class="btn">Send nu</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user