Skip to content

Commit

Permalink
setting variable worlds as globally on admin area.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed Sep 5, 2024
1 parent 04f26cb commit a63f126
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
7 changes: 6 additions & 1 deletion admin/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php global $db, $config, $twig, $logged, $status;
// few things we'll need
require '../common.php';

Expand Down Expand Up @@ -38,6 +38,11 @@
error_reporting(E_ALL);
}

// set worlds in global php and twig
$worlds = $db->hasTable('worlds') ? $db->query("SELECT * FROM `worlds` ORDER BY `id` ASC")->fetchAll() : [];
define('WORLDS', $worlds);
$twig->addGlobal('worlds', $worlds);

// event system
require_once SYSTEM . 'hooks.php';
$hooks = new Hooks();
Expand Down
6 changes: 2 additions & 4 deletions admin/pages/worlds.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ class="fa fa-remove"></i> Cancel</span></a>
</div>
</div>
</form>
<?php } else {
$worlds = $db->query("SELECT * FROM `worlds` ORDER BY `id` ASC")->fetchAll();
?>
<?php } else { ?>
<div class="row">
<div class="col-12 col-md-9">
<div class="box">
Expand All @@ -215,7 +213,7 @@ class="fa fa-plus-circle"></i> New</span></a>
<th style="width: 220px; text-align: center">Created at</th>
<th style="width: 40px;"></th>
</tr>
<?php foreach ($worlds as $world) { ?>
<?php foreach (WORLDS as $world) { ?>
<tr>
<td style="text-align: center"><?= $world['id'] ?></td>
<td><?= $world['name'] ?></td>
Expand Down
27 changes: 15 additions & 12 deletions admin/template/template.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
global $config, $db, $account_logged, $logged, $template_path, $page, $status, $content;

defined('MYAAC') or die('Direct access not allowed!');

$menus = [
'dashboard' => ['Dashboard', 'dashboard'],
'news' => ['News', 'newspaper'],
Expand Down Expand Up @@ -35,7 +37,17 @@
],
];

defined('MYAAC') or die('Direct access not allowed!'); ?>
function getWorldsStatus($style = ''): string
{
global $status;
$output = "";
foreach (WORLDS as $world) {
$_s = $status['online'] ? 'success' : 'danger';
$output .= "<span class='badge ms-1 bg-$_s' style='$style'>{$world['name']}</span>";
}
return $output;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -143,10 +155,7 @@
<section class="content-header">
<h1><?= ($title ?? ''); ?>
<small> - Admin Panel</small>
<div class="float-end">
<span
class="badge bg-<?= (($status['online']) ? 'success' : 'danger'); ?>"><?= configLua('serverName') ?></span>
</div>
<div class="float-end"><?= getWorldsStatus() ?></div>
</h1>
</section>
<section class="content">
Expand All @@ -157,13 +166,7 @@ class="badge bg-<?= (($status['online']) ? 'success' : 'danger'); ?>"><?= config

<footer class="main-footer">
<div class="hidden-xs float-end">
<div id="status">
<?php if ($status['online']): ?>
<p class="badge bg-success" style="width: 120px; text-align: center;">Server Online</p>
<?php else: ?>
<p class="badge bg-danger" style="width: 120px; text-align: center;">Server Offline</p>
<?php endif; ?>
</div>
<div id="status"><?= getWorldsStatus('width: 110px') ?></div>
</div>
<?= base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwczovL2dpdGh1Yi5jb20vb3BlbnRpYmlhYnIvbXlhYWMiIHRhcmdldD0iX2JsYW5rIj5PcGVuVGliaWFCUjwvYT4gYW5kIENvbnRyaWJ1dG9ycy4=') ?>
</footer>
Expand Down

0 comments on commit a63f126

Please sign in to comment.