HomeAdminDashboard.class.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. class HomeAdminDashboard {
  3. public function display() {
  4. $userId = $_SESSION['user_id'];
  5. $data = array();
  6. $data['sectionName'] = "";
  7. $data['displayName'] = $_SESSION['display_name'];
  8. $log = new SecurityLogger();
  9. $data['activity_log'] = $log->readPage(0, 20);
  10. $data['last_seven_days'] = array();
  11. $data['user_logins'] = array();
  12. $data['admin_logins'] = array();
  13. $data['client_logins'] = array();
  14. $data['failed_logins'] = array();
  15. for($i = 6; $i >= 0; $i--) {
  16. $data['last_seven_days'][] = $this->getDayAgo($i);
  17. $data['user_logins'][] = $this->getLogCountForDayAgo('login', $i);
  18. $data['failed_logins'][] = $this->getLogCountForDayAgo('login-failed', $i);
  19. }
  20. $data['admin_logins'] = array(2, 3, 5, 4, 2, 4, 8);
  21. $data['client_logins'] = array(8, 4, 2, 4, 4, 3, 2);
  22. $abandonedUploads = new GetAbandonedUploads();
  23. $data['abandoned_uploads'] = $abandonedUploads->get();
  24. $data['superadmin'] = $_SESSION['superadmin'] ?? false;
  25. return (new View())->render("admin/dashboard.php", $data);
  26. }
  27. private function getLogCountForDayAgo($action, $daysAgo) {
  28. $pastDateStart = date("Y-m-d 00:00:00", strtotime('-'.$daysAgo.' days'));
  29. $pastDateEnd = date("Y-m-d 23:59:59", strtotime('-'.$daysAgo.' days'));
  30. $sql = "SELECT count(*) as count FROM security_logs WHERE action = '".$action."' AND recordtime > '" . $pastDateStart . "' AND recordtime < '" . $pastDateEnd . "';";
  31. $database = SqliteDatabase::getSingleton();
  32. $result = $database->queryArray($sql);
  33. return $result[0]["count"];
  34. }
  35. private function getDayAgo($daysAgo) {
  36. return date('l', strtotime('-'.$daysAgo.' days'));
  37. }
  38. }