Просмотр исходного кода

Add log to show location updates

Alan Lam 6 лет назад
Родитель
Сommit
45457905ea
4 измененных файлов с 68 добавлено и 0 удалено
  1. 2 0
      controllers/account.php
  2. 15 0
      controllers/log.php
  3. 3 0
      routes.php
  4. 48 0
      views/log.php

+ 2 - 0
controllers/account.php

@@ -95,6 +95,8 @@ if($user->level >= User::LEVEL_ADMIN) {
 	$invoice_icon = new AccountIcon(__("Invoices"), "/account/tests?status_tester_invoice=100", "file-invoice");
 	$invoice_icon->setCounter($pending_tester_invoice_test_count);
 
+	$icons[] = new AccountIcon(__("Log"), "/account/log", "database");
+
 	$icons[] = $invoice_icon;
 
 }

+ 15 - 0
controllers/log.php

@@ -0,0 +1,15 @@
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+
+$page_title = "Log";
+
+Core::addBreadcrumb("/account", "Account");
+Core::addBreadcrumb("/account/log", $page_title);
+
+$entries = LocationUpdateLogEntry::query([], ["sort" => "id", "order" => "desc", "limit" => 1000]);
+
+User::load(array_column($entries, "user_id"));
+Location::load(array_column($entries, "location_id"));
+
+View::includeOnce("header", compact("page_title"));
+View::include("log", ["entries" => $entries]);
+View::includeOnce("footer");

+ 3 - 0
routes.php

@@ -47,6 +47,9 @@ $routes = [
 	"/^account\/reactivate$/" => ["controller" => "account_reactivate", "require_log_in" => true],
 	"/^account\/delete$/" => ["controller" => "account_delete", "require_log_in" => true],
 
+	// Log
+	"/^account\/log$/" => ["controller" => "log", "require_user_level" => User::LEVEL_ADMIN],
+
 	// Addresses
 	"/^account\/addresses$/" => ["controller" => "addresses", "require_log_in" => true],
 	"/^account\/addresses\/add$/" => ["controller" => "address_add", "require_log_in" => true],

+ 48 - 0
views/log.php

@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * @var LocationUpdateLogEntry[] $entries
+ */
+
+?>
+<div class="container-fluid mt-3 py-4">
+
+	<h2>Log</h2>
+
+	<table class="table table-sm table-bordered">
+		<thead>
+		<tr>
+			<th>Location</th>
+			<th>Date/Time</th>
+			<th>User</th>
+			<th>Field</th>
+			<th>Before</th>
+			<th>After</th>
+		</tr>
+		</thead>
+		<tbody>
+		<?php
+		foreach($entries as $entry) {
+			$location = $entry->getLocation();
+			$user = $entry->getUser();
+			$dts = Util::getDisplayDateTimeFromUTC($entry->dts);
+			$modifications = $entry->getModifications();
+			foreach($modifications as $modification) {
+				?>
+				<tr>
+					<td><?=htmlspecialchars($dts)?></td>
+					<td><a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a></td>
+					<td><a href="<?=htmlspecialchars($user->getURL())?>"><?=htmlspecialchars($user->email)?></a></td>
+					<td class="text-monospace"><?=htmlspecialchars($modification->field)?></td>
+					<td class="text-monospace"><?=htmlspecialchars($modification->before)?></td>
+					<td class="text-monospace"><?=htmlspecialchars($modification->after)?></td>
+				</tr>
+				<?php
+			}
+			?>
+			<?php
+		}
+		?>
+		</tbody>
+	</table>
+</div>