Skip to content

Commit

Permalink
Next pass at bootstrap conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Jun 30, 2021
1 parent ba8f14d commit bfb3bd7
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 175 deletions.
168 changes: 78 additions & 90 deletions src/templates/EventLog/Index.phtml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
<?php

<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
namespace BNETDocs\Templates\EventLog;

use \BNETDocs\Libraries\Event;
use \BNETDocs\Libraries\Exceptions\UserNotFoundException;
use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Pair;

$title = 'Event Logs';
$description = 'The index for event logs on BNETDocs';
$title = 'Event Logs';
$description = 'All triggered event logs on BNETDocs';
$this->opengraph->attach(new Pair('url', '/eventlog/index'));

$form_order_by = [
'datetime-asc' => 'Timestamp (Ascending)',
'datetime-desc' => 'Timestamp (Descending)',
'id-asc' => 'Event Id (Ascending)',
'id-desc' => 'Event Id (Descending)',
];

$page = $this->getContext()->page;
$pages = $this->getContext()->pages;
$limit = $this->getContext()->limit;
Expand All @@ -19,90 +25,72 @@ $order = $this->getContext()->order;
$no_prev = ($page <= 1);
$no_next = ($page >= $pages);

require('./header.inc.phtml');
?>
<article>
<?php if (!$this->getContext()->acl_allowed) { ?>
<header class="red"><?php echo $title; ?></header>
<section class="red">
<p>You are not authorized to view this page.</p>
</section>
<?php } else { ?>
<header><?php echo $title; ?></header>
<section>
<?php require('./NYI.inc.phtml'); ?><hr/>
<form method="GET">
<input type="hidden" name="page" value="<?php echo $page; ?>"/>
<input type="hidden" name="limit" value="<?php echo $limit; ?>"/>
<label for="order">Order by:</label>
<select name="order" id="order" onchange="form.submit();"
style="display:inline-block;width:200px;">
<option value="id-asc"<?php
if ($order === 'id-asc') { echo ' selected="selected"';
} ?>>Event Id (Ascending)</option>
<option value="id-desc"<?php
if ($order === 'id-desc') { echo ' selected="selected"';
} ?>>Event Id (Descending)</option>
<option value="datetime-asc"<?php
if ($order === 'datetime-asc') { echo ' selected="selected"';
} ?>>Timestamp (Ascending)</option>
<option value="datetime-desc"<?php
if ($order === 'datetime-desc') { echo ' selected="selected"';
} ?>>Timestamp (Descending)</option>
</select>
<input type="submit" value="Reorder"/>
</form>
<table>
<thead>
<tr>
<th class="right" style="width:70px;">Id</th>
<th class="left" style="width:220px;">Event Type</th>
<th class="left" style="width:200px;">Timestamp</th>
<th class="left">User Account</th>
</tr>
</thead><tbody>
<?php foreach ($this->getContext()->events as $event) {
$e_id = $event->getId();
try { $e_user = $event->getUser(); }
catch ( UserNotFoundException $e ) { $e_user = null; }
if ( is_null( $e_user ) ) { $e_user = '<em>(null)</em>'; }
else {
$e_user_url = $e_user->getURI();
$e_user_avatar = $e_user->getAvatarURI(22);
$e_user = filter_var( $e_user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$e_user = '<a href="' . $e_user_url . '"><img class="avatar" src="' . $e_user_avatar . '"/>&nbsp;' . $e_user . '</a>';
}
require('./header.inc.phtml'); ?>
<div class="container mb-3">
<? if (!$this->getContext()->acl_allowed) { ?>
<div class="alert alert-danger">
<h1><?=$title?></h1>
<p class="mb-0">You are not authorized to view this page.</p>
</div>
<? } else { ?>
<h1><?=$title?></h1>
<p><?=$description?></p>
<form method="GET" class="m-2" id="filter_form">
<input type="hidden" name="page" value="<? echo $page; ?>"/>
<input type="hidden" name="limit" value="<? echo $limit; ?>"/>
<label for="order" class="font-weight-bold m-1">Order by:</label>
<select class="form-control form-control-sm" name="order" id="order" onchange="form.submit();" style="display:inline-block;width:200px;">
<? foreach ($form_order_by as $item_value => $item_label) {
$item_selected = ($order === $item_value ? ' selected="selected"' : '');
echo sprintf('<option value="%s"%s>%s</option>' . PHP_EOL, $item_value, $item_selected, $item_label);
} ?>
</select>
<input class="btn btn-sm btn-secondary" type="submit" value="Reorder"/>
</form>
<table class="table table-hover table-sm table-striped">
<thead>
<tr>
<th class="text-right">Id</th>
<th>Event Type</th>
<th>Timestamp</th>
<th>User Account</th>
</tr>
</thead><tbody>
<? foreach ($this->getContext()->events as $event) {
$e_id = $event->getId();
try { $e_user = $event->getUser(); }
catch ( UserNotFoundException $e ) { $e_user = null; }
if ( is_null( $e_user ) ) { $e_user = '<em>(null)</em>'; }
else {
$e_user_url = $e_user->getURI();
$e_user_avatar = $e_user->getAvatarURI(22);
$e_user = filter_var( $e_user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$e_user = '<a href="' . $e_user_url . '"><img class="avatar" src="' . $e_user_avatar . '"/>&nbsp;' . $e_user . '</a>';
}
?>
<tr>
<td class="right"><a href="<?php echo Common::relativeUrlToAbsolute('/eventlog/view?id=' . $e_id); ?>"><?php echo $e_id; ?></a></td>
<td><?php echo $event->getEventTypeName(); ?></td>
<td><time datetime="<?php echo $event->getEventDateTime()->format('c'); ?>"><?php echo $event->getEventDateTime()->format('l, F j, Y'); ?></time></td>
<td><?php echo $e_user; ?></td>
</tr>
<?php } ?>
</tbody></table>
</section>
<section>
<hr/>
<span class="float-left">
<?php if (!$no_prev) { ?>
<a class="button" href="<?php echo Common::relativeUrlToAbsolute('/eventlog/index?page=' . ($page - 1) . '&limit=' . $limit . '&order=' . $order); ?>">Prev</a>
<?php } else { ?>
<button class="button button-disabled" disabled="disabled">Prev</button>
<?php } ?>
</span>
<span class="float-right">
<?php if (!$no_next) { ?>
<a class="button" href="<?php echo Common::relativeUrlToAbsolute('/eventlog/index?page=' . ($page + 1) . '&limit=' . $limit . '&order=' . $order); ?>">Next</a>
<?php } else { ?>
<button class="button button-disabled" disabled="disabled">Next</button>
<?php } ?>
</span>
<p class="center" style="line-height:24px;">
<strong><?php echo number_format($page); ?></strong> of <?php echo number_format($pages); ?>
</p>
</section>
</article>
<?php } ?>
</article>
<?php require("./footer.inc.phtml"); ?>
<tr>
<td class="text-right"><a href="<?=Common::relativeUrlToAbsolute('/eventlog/view?id=' . $e_id)?>"><?=$e_id?></a></td>
<td><?=$event->getEventTypeName()?></td>
<td><time datetime="<?=$event->getEventDateTime()->format('c')?>"><?=$event->getEventDateTime()->format('l, F j, Y')?></time></td>
<td><?=$e_user?></td>
</tr>
<? } ?>
</tbody></table>
<nav aria-label="User list navigation" class="d-flex justify-content-center">
<ul class="pagination">
<? if (!$no_prev) { ?>
<li class="page-item"><a class="page-link" href="<?=Common::relativeUrlToAbsolute('/eventlog/index?page=' . ($page - 1) . '&limit=' . $limit . '&order=' . $order)?>">Previous</a></li>
<? } else { ?>
<li class="page-item disabled"><span class="page-link">Previous</span></li>
<? } ?>
<li class="page-item disabled"><span class="page-link"><?=number_format($page)?> of <?=number_format($pages)?></span></li>
<? if (!$no_next) { ?>
<li class="page-item"><a class="page-link" href="<?=Common::relativeUrlToAbsolute('/eventlog/index?page=' . ($page + 1) . '&limit=' . $limit . '&order=' . $order)?>">Next</a></li>
<? } else { ?>
<li class="page-item disabled"><span class="page-link">Next</span></li>
<? } ?>
</ul>
</nav>
</div>
<? } ?>
<? require("./footer.inc.phtml"); ?>
150 changes: 66 additions & 84 deletions src/templates/EventLog/View.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */
namespace BNETDocs\Templates\EventLog;

use \BNETDocs\Libraries\Event;
Expand All @@ -8,111 +7,94 @@ use \BNETDocs\Libraries\User;
use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Pair;

$title = 'Event Log Viewer';
$title = 'Event Log Viewer';
$description = 'The event log viewer on BNETDocs';
$this->opengraph->attach( new Pair( 'url', '/eventlog/view' ));

$object_id = $this->getContext()->id;
$object = $this->getContext()->event;
$user = $this->getContext()->user;

$object_ip_address = (
$object instanceof Event ? $object->getIPAddress() : null
);

$object_metadata = (
$object instanceof Event ? $object->getMetadata() : null
);
$object = $this->getContext()->event;
$user = $this->getContext()->user;

$object_user_id = (
$object instanceof Event ? $object->getUserId() : null
);
$object_ip_address = ($object instanceof Event ? $object->getIPAddress() : null);
$object_metadata = ($object instanceof Event ? $object->getMetadata() : null);
$object_user_id = ($object instanceof Event ? $object->getUserId() : null);

try {
$object_user = (
!is_null( $object_user_id ) ? new User( $object_user_id ) : null
);
} catch (UserNotFoundException $e) {
try
{
$object_user = (!is_null($object_user_id) ? new User($object_user_id) : null);
}
catch (UserNotFoundException $e)
{
$object_user = null;
}

if ( !$object instanceof Event ) {
if (!$object instanceof Event)
{
$title = 'Event Not Found';
$description = 'The event you tried to access could not be found.';
}

$tpl_user = (
is_null( $object_user ) ? '<em>(null)</em>' :
'<a href="' . $object_user->getURI() . '"><img class="avatar" src="' .
$object_user->getAvatarURI( 22 ) . '"/> ' . filter_var(
$object_user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS
)
is_null($object_user) ? '<em>(null)</em>' :
'<a href="' . $object_user->getURI() . '"><img class="mr-2" src="' .
$object_user->getAvatarURI(22) . '"/>' .
filter_var($object_user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS)
);

$tpl_metadata_j = @json_decode( $object_metadata );
$tpl_metadata_j = @json_decode($object_metadata);
$tpl_metadata = (
is_null( $object_metadata ) ? '<em>(null)</em>' : (
json_last_error() === JSON_ERROR_NONE ? (
'<pre><code class="wrap">' . filter_var(
json_encode( $tpl_metadata_j, JSON_PRETTY_PRINT ),
FILTER_SANITIZE_FULL_SPECIAL_CHARS
) .
'</code></pre>'
) : (
'<textarea rows="10" readonly="readonly">' . filter_var(
$object_metadata, FILTER_SANITIZE_FULL_SPECIAL_CHARS
) . '</textarea>'
)
is_null($object_metadata) ? '<em>(null)</em>' :
(
'<pre><code style="white-space:pre-wrap;" class="language-' . (
json_last_error() === JSON_ERROR_NONE ? 'json' : 'plaintext'
) . '">' . str_replace("\n", "<br/>\n", filter_var(
json_encode($tpl_metadata_j, JSON_PRETTY_PRINT), FILTER_SANITIZE_FULL_SPECIAL_CHARS)
) . '</code></pre>'
)
);

$tpl_referer = getenv( 'HTTP_REFERER' );
if ( !empty( $tpl_referer )) {
$tpl_referer = '<a href="' . filter_var(
$tpl_referer, FILTER_SANITIZE_FULL_SPECIAL_CHARS
) . '">&lt;&lt; Back to Previous</a>';
$tpl_referer = getenv('HTTP_REFERER');
if (!empty($tpl_referer))
{
$tpl_referer = '<a href="' . filter_var($tpl_referer, FILTER_SANITIZE_FULL_SPECIAL_CHARS) . '">&lt;&lt; Back to Previous</a>';
}
if ( stripos( $tpl_referer, getenv( 'HTTP_HOST' ) ) === false ) {
if (stripos($tpl_referer, getenv('HTTP_HOST')) === false)
{
$tpl_referer = '';
}
if ( stripos( $tpl_referer, '/eventlog/view?id=' . $object_id ) !== false ) {
if (stripos($tpl_referer, '/eventlog/view?id=' . $object_id) !== false)
{
$tpl_referer = '';
}

require('./header.inc.phtml');
?>
<article>
<?php if ( !$this->getContext()->acl_allowed ) { ?>
<header class="red"><?php echo $title; ?></header>
<section class="red">
<p>You are not authorized to view this page.</p>
</section>
<?php } else if ( is_null( $object )) { $title = 'Event Not Found' ?>
<header class="red"><?php echo $title; ?></header>
<section class="red">
<p><?php echo $description; ?></p>
<?php if ( !empty( $tpl_referer )) { ?>
<p><?php echo $tpl_referer; ?></p>
<?php } ?>
</section>
<?php } else { ?>
<header><?php echo $title; ?></header>
<section>
<table class="info">
<thead></thead><tbody>
<tr><th class="right" style="width:100px;">Id</th><td><a href="<?php echo Common::relativeUrlToAbsolute('/eventlog/view?id=' . $object_id); ?>"><?php echo $object_id; ?></a></td></tr>
<tr><th class="right">Event Type</th><td><?php echo $object->getEventTypeName(); ?></td></tr>
<tr><th class="right">Timestamp</th><td><time datetime='<?php echo $object->getEventDateTime()->format('c'); ?>'><?php echo $object->getEventDateTime()->format('l, F j, Y'); ?></time></td></tr>
<tr><th class="right">IP Address</th><td><?php echo ( $object_ip_address ? $object_ip_address : '<em>(null)</em>' ); ?></td></tr>
<tr><th class="right">User Account</th><td><?php echo $tpl_user; ?></td></tr>
<tr><th class="right" style="vertical-align:top;">Metadata</th><td><?php echo $tpl_metadata; ?></td></tr>
</tbody>
</table>
<?php if ( !empty( $tpl_referer )) { ?>
<hr/><p><?php echo $tpl_referer; ?></p>
<?php } ?>
</section>
</article>
<?php } ?>
</article>
<?php require("./footer.inc.phtml"); ?>
require('./header.inc.phtml'); ?>
<div class="container mb-3">
<? if (!$this->getContext()->acl_allowed) { ?>
<div class="alert alert-danger">
<h1><?=$title?></h1>
<p class="mb-0">You are not authorized to view this page.</p>
</div>
<? } else if (is_null($object)) { ?>
<div class="alert alert-danger">
<h1><?=$title?></h1>
<p><?=$description?></p>
<?=(!empty($tpl_referer) ? ' <p>' . $tpl_referer . '</p>' : '')?>
</div>
<? } else { ?>
<h1><?=$title?></h1>
<table class="table table-hover table-striped">
<thead></thead><tbody>
<tr><th scope="row" class="text-right">Id</th><td><code><a href="<?=Common::relativeUrlToAbsolute('/eventlog/view?id=' . $object_id)?>"><?=$object_id?></a></code></td></tr>
<tr><th scope="row" class="text-right">Event Type</th><td><?=$object->getEventTypeName()?></td></tr>
<tr><th scope="row" class="text-right">Timestamp</th><td><time datetime='<?=$object->getEventDateTime()->format('c')?>'><?=$object->getEventDateTime()->format('l, F j, Y')?></time></td></tr>
<tr><th scope="row" class="text-right">IP Address</th><td><?=($object_ip_address ? '<code>' . $object_ip_address . '</code>' : '<em>(null)</em>')?></td></tr>
<tr><th scope="row" class="text-right">User Account</th><td><?=$tpl_user?></td></tr>
</tbody>
</table>
<?=$tpl_metadata?>
<? if (!empty($tpl_referer)) { ?>
<hr/><p><?=$tpl_referer?></p>
<? } ?>
<? } ?>
</div>
<? require("./footer.inc.phtml"); ?>
2 changes: 1 addition & 1 deletion src/templates/User/Index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ require('./header.inc.phtml'); ?>
<li class="page-item disabled"><span class="page-link">Next</span></li>
<? } ?>
</ul>
</div>
</nav>
</div>
<? require("./footer.inc.phtml"); ?>

0 comments on commit bfb3bd7

Please sign in to comment.