123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- class HomeAdminDashboard {
- public function display() {
- $userId = $_SESSION['user_id'];
- $data = array();
- $data['sectionName'] = "";
- $data['displayName'] = $_SESSION['display_name'];
- $log = new SecurityLogger();
- $data['activity_log'] = $log->readPage(0, 20);
- $data['last_seven_days'] = array();
- $data['user_logins'] = array();
- $data['admin_logins'] = array();
- $data['client_logins'] = array();
- $data['failed_logins'] = array();
- for($i = 6; $i >= 0; $i--) {
- $data['last_seven_days'][] = $this->getDayAgo($i);
- $data['user_logins'][] = $this->getLogCountForDayAgo('login', $i);
- $data['failed_logins'][] = $this->getLogCountForDayAgo('login-failed', $i);
- }
- $data['admin_logins'] = array(2, 3, 5, 4, 2, 4, 8);
- $data['client_logins'] = array(8, 4, 2, 4, 4, 3, 2);
- $abandonedUploads = new GetAbandonedUploads();
- $data['abandoned_uploads'] = $abandonedUploads->get();
- $data['superadmin'] = $_SESSION['superadmin'] ?? false;
- return (new View())->render("admin/dashboard.php", $data);
- }
- private function getLogCountForDayAgo($action, $daysAgo) {
- $pastDateStart = date("Y-m-d 00:00:00", strtotime('-'.$daysAgo.' days'));
- $pastDateEnd = date("Y-m-d 23:59:59", strtotime('-'.$daysAgo.' days'));
- $sql = "SELECT count(*) as count FROM security_logs WHERE action = '".$action."' AND recordtime > '" . $pastDateStart . "' AND recordtime < '" . $pastDateEnd . "';";
- $database = SqliteDatabase::getSingleton();
- $result = $database->queryArray($sql);
- return $result[0]["count"];
- }
- private function getDayAgo($daysAgo) {
- return date('l', strtotime('-'.$daysAgo.' days'));
- }
- }
|