From e8d9d89b7aec44c77f78f572a2588aac3e34df9c Mon Sep 17 00:00:00 2001 From: schism Date: Sat, 20 Feb 2021 19:01:42 +0530 Subject: [PATCH] Add schedule time to table, total requests in index --- web/dashboard.php | 10 ++++------ web/index.php | 8 ++------ web/php/Database.php | 4 ++-- web/php/Schedule.php | 13 +++++++++++-- web/php/helpers.php | 6 +++--- web/style/main.css | 16 ++++++++++++++-- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/web/dashboard.php b/web/dashboard.php index 3fae4e2..6c0e87a 100644 --- a/web/dashboard.php +++ b/web/dashboard.php @@ -1,8 +1,4 @@ Course + Time Attempts Last Try Status @@ -93,14 +90,15 @@ No schedules for today'; + echo 'No schedules for today'; } else { foreach ($schedules as $schedule) { echo ' '. $schedule["subject"] .' + '. Schedule::format_time($schedule["time"], "h:i A") .' '. $schedule["tries"] .' - '. $schedule["lastattempt"] .' + '. Schedule::format_time($schedule["lastattempt"], "h:i A") .' '. $schedule["status"] .' '; } diff --git a/web/index.php b/web/index.php index 88f5b54..d8415b8 100644 --- a/web/index.php +++ b/web/index.php @@ -1,8 +1,4 @@ getTotalCount("users"); + $num_requests = $db->getTotalCount("schedule", "WHERE status!=".Schedule::$STATUS_PENDING); $error = $username = ""; - - if ($_SERVER["REQUEST_METHOD"] === "POST") { @@ -64,6 +59,7 @@

Current users

+

Requests served

diff --git a/web/php/Database.php b/web/php/Database.php index c3ad0e4..318343f 100644 --- a/web/php/Database.php +++ b/web/php/Database.php @@ -39,8 +39,8 @@ class Database { return true; } - function getTotalCount($table_name) { - $sql = "SELECT COUNT(*) FROM $table_name"; + function getTotalCount($table_name, $suffix = "") { + $sql = "SELECT COUNT(*) FROM $table_name $suffix"; $result = $this->dbh->prepare($sql); $result->execute(); return $result->fetchColumn(); diff --git a/web/php/Schedule.php b/web/php/Schedule.php index 7c9caf9..6fea4f3 100644 --- a/web/php/Schedule.php +++ b/web/php/Schedule.php @@ -38,7 +38,7 @@ class Schedule { $schedules = []; $today = strtotime("00:00:00"); - $query = "SELECT subject, tries, status, lastattempt FROM schedule WHERE username = :username AND day >= :today"; + $query = "SELECT subject, time, tries, status, lastattempt FROM schedule WHERE username = :username AND day >= :today"; $stmt = $db->dbh->prepare($query); if ($db->isError()) { @@ -52,10 +52,19 @@ class Schedule { while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) { $data["status"] = self::getStatusString(intval($data["status"])); $schedules[] = $data; - + } return $schedules; } + + public static function format_time($time, $format) { + try { + $datetime = new DateTime($time); + return $datetime->format($format); + } catch (Exception $e) { + return ""; + } + } public static function getStatusString($status) { if ($status === self::$STATUS_PENDING || $status === self::$STATUS_REATTEMPT) { diff --git a/web/php/helpers.php b/web/php/helpers.php index e11a059..7214d76 100644 --- a/web/php/helpers.php +++ b/web/php/helpers.php @@ -31,17 +31,17 @@ function get_user_from_session($db, $show_error = true) { exit; } } - + } function connect_db() { try { $config = new Config(); - + $path = $config->DBPATH; $username = $config->DBUSERNAME; $password = $config->DBPASSWORD; - + $db = new Database($path); $db->connect($username, $password); $db->create_tables(); diff --git a/web/style/main.css b/web/style/main.css index 947b572..ece57d3 100644 --- a/web/style/main.css +++ b/web/style/main.css @@ -38,6 +38,7 @@ --font-medium: 18px; --font-large: 24px; --font-xl: 28px; + --font-2xl: 48px; } body { @@ -152,11 +153,22 @@ main#homepage .part.left { main#homepage .part.left .message-card { margin: 15px 0 30px 0; background-color: var(--color-primary-light); - padding: 30px 50px; + padding: 15px 50px; border-radius: 5px; - font-size: var(--font-large); color: var(--color-heading); +} + +main#homepage .part.left .message-card p { + display: flex; + font-size: var(--font-large); + justify-content: space-between; + padding: 15px 0; +} + +main#homepage .part.left .message-card p span { font-weight: 700; + margin-left: 35px; + font-size: var(--font-xl); } main#homepage .part.right {