diff --git a/core/Api/User/Fetch.class.php b/core/Api/User/Fetch.class.php index e81c2fa..34dfa41 100644 --- a/core/Api/User/Fetch.class.php +++ b/core/Api/User/Fetch.class.php @@ -51,7 +51,7 @@ class Fetch extends Request { } $sql = $this->user->getSQL(); - $res = $sql->select("User.uid as userId", "User.name", "User.email", "User.created_at", + $res = $sql->select("User.uid as userId", "User.name", "User.email", "User.registered_at", "Group.uid as groupId", "Group.name as groupName") ->from("User") ->leftJoin("UserGroup", "User.uid", "UserGroup.user_id") @@ -76,7 +76,7 @@ class Fetch extends Request { "uid" => $userId, "name" => $row["name"], "email" => $row["email"], - "created_at" => $row["created_at"], + "registered_at" => $row["registered_at"], "groups" => array(), ); } @@ -90,4 +90,4 @@ class Fetch extends Request { return $this->success; } -} \ No newline at end of file +} diff --git a/core/Documents/Install.class.php b/core/Documents/Install.class.php index a693c80..62e1145 100644 --- a/core/Documents/Install.class.php +++ b/core/Documents/Install.class.php @@ -243,7 +243,7 @@ namespace Documents\Install { if(is_string($sql)) { $msg = "Error connecting to database: $sql"; } else if(!$sql->isConnected()) { - if (!$sql->checkRequirements()["success"]) { + if (!$sql->checkRequirements()) { $driverName = $sql->getDriverName(); $installLink = "https://www.php.net/manual/en/$driverName.setup.php"; $link = $this->createExternalLink($installLink); @@ -809,4 +809,4 @@ namespace Documents\Install { } } -} \ No newline at end of file +} diff --git a/core/Views/Admin/AdminDashboardBody.class.php b/core/Views/Admin/AdminDashboardBody.class.php index c705149..9b217b7 100644 --- a/core/Views/Admin/AdminDashboardBody.class.php +++ b/core/Views/Admin/AdminDashboardBody.class.php @@ -31,16 +31,6 @@ class AdminDashboardBody extends Body { } } - private function getUsers() : array { - $req = new \Api\User\Fetch($this->getDocument()->getUser()); - if(!$req->execute()) { - $this->errorMessages[] = $req->getLastError(); - return array(); - } else { - return $req->getResult()['users']; - } - } - private function getHeader() { // Locale @@ -75,7 +65,7 @@ class AdminDashboardBody extends Body { $home - +
@@ -87,7 +77,7 @@ class AdminDashboardBody extends Body {
- + "; @@ -241,8 +238,6 @@ class AdminDashboardBody extends Body { private function getContent() { - $this->getUsers(); - $view = $this->getView(); $html = "
"; diff --git a/core/Views/Admin/UserOverview.class.php b/core/Views/Admin/UserOverview.class.php index 77da258..4f467a0 100644 --- a/core/Views/Admin/UserOverview.class.php +++ b/core/Views/Admin/UserOverview.class.php @@ -85,13 +85,12 @@ class UserOverview extends AdminView { private function getUserRows() { - $dateFormat = L("Y/m/d"); $userRows = array(); foreach($this->users as $uid => $user) { $name = $user["name"]; $email = $user["email"] ?? ""; - $registeredAt = (new DateTime($user["created_at"]))->format($dateFormat); + $registeredAt = formatDate($user["registered_at"]); $groups = $this->getGroups($user["groups"]); $userRows[] = @@ -161,4 +160,4 @@ class UserOverview extends AdminView { return $html; } -} \ No newline at end of file +} diff --git a/core/datetime.php b/core/datetime.php index 9fa34f4..c09cefc 100644 --- a/core/datetime.php +++ b/core/datetime.php @@ -140,7 +140,13 @@ function dateFunction($str, $d = NULL) { } function getPeriodString($d) { - if(!is_a($d, "DateTime")) $d = new DateTime($d); + + try { + $d = new DateTime($d); + } catch(Exception $e) { + return L("Unknown"); + } + $diff = datetimeDiff(new DateTime(), $d); $diff = abs($diff); @@ -161,3 +167,27 @@ function getPeriodString($d) { return L(sprintf($str, $diff)); } + +function formatDateTime($d) { + $format = L("Y/m/d H:i:s"); + return apply_format($d, $format); +} + +function formatTime($d) { + $format = L("H:i:s"); + return apply_format($d, $format); +} + +function formatDate($d) { + $format = L("Y/m/d"); + return apply_format($d, $format); +} + +function apply_format($d, $fmt) { + try { + $dt = new DateTime($d); + return $dt->format($fmt); + } catch(Exception $e) { + return L("Unknown"); + } +} diff --git a/js/admin.js b/js/admin.js index 13a462b..e4e2d0c 100644 --- a/js/admin.js +++ b/js/admin.js @@ -48,4 +48,12 @@ $(document).ready(function() { alert(err); }); }); + + $("#btnLogout").click(function() { + jsCore.apiCall("/user/logout", function(data) { + document.location = "/admin"; + }, function(err) { + alert("err"); + }); + }); });