123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- class AdminDashboard implements IDashboard {
- public function display($urlTree) {
- $dashboardPage = isset($urlTree[1]) ? $urlTree[1] : "home";
- switch($dashboardPage) {
- case "accounts":
- return $this->accounts();
- case "users":
- return $this->users();
- case "data":
- return $this->data();
- case "home":
- case "":
- return $this->home();
- default:
- header('Location: /dashboard/');
- }
- }
- public function home() {
- $data = array();
- $data['sectionName'] = "";
- $data['displayName'] = $_SESSION['display_name'];
- $log = new SecurityLogger();
- $data['activity_log'] = $log->read();
- $data['last_seven_days'] = array($this->getDayAgo(6), $this->getDayAgo(5), $this->getDayAgo(4), $this->getDayAgo(3), $this->getDayAgo(2), $this->getDayAgo(1), $this->getDayAgo(0));
- $data['user_logins'] = array(2, 3, 5, 4, 2, 4, 8);
- $data['admin_logins'] = array(2, 3, 5, 4, 2, 4, 8);
- $data['client_logins'] = array(8, 4, 2, 4, 4, 3, 2);
- $data['failed_logins'] = array(0, 8, 4, 8, 7, 6, 4);
- return (new View())->render("admin/dashboard.php", $data);
- }
- private function getDayAgo($daysAgo) {
- return date('l', strtotime('-'.$daysAgo.' days'));
- }
- public function accounts() {
- $database = SqliteDatabase::getSingleton();
- $accounts = $database->queryArray("SELECT rowid AS client_id, * FROM accounts;");
- $data = array();
- $data['sectionName'] = "Accounts";
- $data['displayName'] = $_SESSION['display_name'];
- $data['accounts'] = $accounts;
- return (new View())->render("admin/accounts.php", $data);
- }
- public function users() {
- $database = SqliteDatabase::getSingleton();
- $users = $database->queryArray("SELECT rowid AS user_id, display_name, username FROM users;");
- foreach($users as $index => $user) {
- $domains = $database->queryArray("SELECT subdomain, display_name FROM user_accounts JOIN accounts ON accounts.rowid = user_accounts.account_id WHERE user_id = " . $user['user_id']. ";");
- foreach($domains as $domain) {
- $users[$index]['domains'][] = $domain['subdomain'];
- }
- }
- $data = array();
- $data['sectionName'] = "Users";
- $data['displayName'] = $_SESSION['display_name'];
- $data['users'] = $users;
- return (new View())->render("admin/users.php", $data);
- }
- public function data() {
- //http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-s3.html
- $database = SqliteDatabase::getSingleton();
- $projects = $database->queryArray("SELECT rowid AS project_id, * FROM projects;");
- foreach($projects as $index => $project) {
- $accounts = $database->queryArray("SELECT display_name FROM account_projects JOIN accounts ON accounts.rowid = account_projects.account_id WHERE project_id = " . $project['project_id']. ";");
- foreach($accounts as $account) {
- $projects[$index]['clients'][] = $account['display_name'];
- }
- }
- $data = array();
- $data['sectionName'] = "Data";
- $data['displayName'] = $_SESSION['display_name'];
- $data['projects'] = $projects;
- return (new View())->render("admin/data.php", $data);
- }
- }
|