Add schedule time to table, total requests in index

This commit is contained in:
schism 2021-02-20 19:01:42 +05:30
parent 2f031d38dc
commit e8d9d89b7a
6 changed files with 36 additions and 21 deletions

View File

@ -1,8 +1,4 @@
<?php
ini_set("display_errors", "1");
ini_set("display_startup_errors", "1");
error_reporting(E_ALL);
session_start();
require_once(__DIR__ ."/php/helpers.php");
@ -85,6 +81,7 @@
<thead>
<tr>
<th class="course">Course</th>
<th>Time</th>
<th>Attempts</th>
<th>Last Try</th>
<th>Status</th>
@ -93,14 +90,15 @@
<tbody>
<?php
if (count($schedules) < 1) {
echo '<tr><td colspan="4">No schedules for today</td></tr>';
echo '<tr><td colspan="5">No schedules for today</td></tr>';
} else {
foreach ($schedules as $schedule) {
echo '
<tr>
<td class="course">'. $schedule["subject"] .'</td>
<td>'. Schedule::format_time($schedule["time"], "h:i A") .'</td>
<td>'. $schedule["tries"] .'</td>
<td>'. $schedule["lastattempt"] .'</td>
<td>'. Schedule::format_time($schedule["lastattempt"], "h:i A") .'</td>
<td class="'. $schedule["status"] .'">'. $schedule["status"] .'</td>
</tr>';
}

View File

@ -1,8 +1,4 @@
<?php
ini_set("display_errors", "1");
ini_set("display_startup_errors", "1");
error_reporting(E_ALL);
session_start();
require_once(__DIR__ ."/php/helpers.php");
@ -11,10 +7,9 @@
$db = connect_db();
$num_users = $db->getTotalCount("users");
$num_requests = $db->getTotalCount("schedule", "WHERE status!=".Schedule::$STATUS_PENDING);
$error = $username = "";
if ($_SERVER["REQUEST_METHOD"] === "POST") {
@ -64,6 +59,7 @@
<div class="message-card">
<p>Current users <span class="accent"><?php echo $num_users; ?></span> </p>
<p>Requests served <span class="accent"><?php echo $num_requests; ?></span> </p>
</div>
</section>
<section class="part right" id="signup">

View File

@ -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();

View File

@ -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) {

View File

@ -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();

View File

@ -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 {