partially implemented todo tracker

This commit is contained in:
2025-04-20 17:05:41 -06:00
parent 9e47110758
commit ab30859446
29 changed files with 546 additions and 157 deletions
+10 -10
View File
@@ -1,16 +1,16 @@
<?php
function admin_article_view()
{
$display = '
$display = '
<div class="view_card">
<div class="row">
<div class="row_space_between">
<h3>Articles</h3>
<a href="admin.php?view=users">View Users</a>
</div>
<div class="line"></div>
<form method="post">
<input type="hidden" name="form_id" value="articles">
<div class="row">
<div class="row_space_between">
<label for="delete" class="form_checkbox_container">Delete
<input type="radio" class="button" name="action" id="delete" value="delete">
<span class="checkmark"></span>
@@ -33,11 +33,11 @@ function admin_article_view()
</thead>
<tbody>
';
$conn = get_connection();
$results = $conn->query('SELECT article_id, username, title, read_count, article.created_at, updated_at, published_at, excerpt FROM article INNER JOIN user ON article.author_id = user.user_id;');
$conn = get_connection();
$results = $conn->query('SELECT article_id, username, title, read_count, article.created_at, updated_at, published_at, excerpt FROM article INNER JOIN user ON article.author_id = user.user_id;');
foreach ($results as $key => $result) {
$display .= '
foreach ($results as $key => $result) {
$display .= '
<tr data-href="articles.php?view=read&article_id=' . $result['article_id'] . '">
<td class="excluded_cell">
<label class="form_checkbox_container">
@@ -54,9 +54,9 @@ function admin_article_view()
<td>' . $result['read_count'] . '</td>
</tr>
';
}
}
$display .= '
$display .= '
</tbody>
</table>
@@ -64,5 +64,5 @@ function admin_article_view()
</div>
';
return $display;
return $display;
}
+10 -10
View File
@@ -1,16 +1,16 @@
<?php
function admin_user_view()
{
$display = '
$display = '
<div class="view_card">
<div class="row">
<div class="row_space_between">
<h3>Users</h3>
<a href="admin.php?view=articles">View Articles</a>
</div>
<div class="line"></div>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="form_id" value="users">
<div class="row">
<div class="row_space_between">
<label for="delete" class="form_checkbox_container">Delete
<input type="radio" class="button" name="action" id="delete" value="delete">
<span class="checkmark"></span>
@@ -36,11 +36,11 @@ function admin_user_view()
<th>Profile Picture</th>
</tr>
';
$conn = get_connection();
$results = $conn->query('SELECT user_id, username, email, last_active, role, created_at, is_active, profile_picture FROM user INNER JOIN roles ON user.role_id = roles.role_id;');
$conn = get_connection();
$results = $conn->query('SELECT user_id, username, email, last_active, role, created_at, is_active, profile_picture FROM user INNER JOIN roles ON user.role_id = roles.role_id;');
foreach ($results as $key => $result) {
$display .= '
foreach ($results as $key => $result) {
$display .= '
<tr data-href="user.php?action=view&user_id=' . $result['user_id'] . '">
<td class="excluded_cell">
<label class="form_checkbox_container">
@@ -58,14 +58,14 @@ function admin_user_view()
<td><img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $result['profile_picture'] . '" class="card_profile_picture"></td>
</tr>
';
}
}
$display .= '
$display .= '
</table>
</form>
</div>
';
return $display;
return $display;
}
+3 -3
View File
@@ -17,12 +17,12 @@ function article_page_from_markdown($article_id)
$html = '
<div class="article">
<div class="row">
<div class="row_space_between">
<h1>' . $article['title'] . '</h1>
' . (isset($_SESSION['user_id']) && $_SESSION['user_id'] == $article['author_id'] ? '<a href="articles.php?view=compose&article_id=' . $article_id . '"><i class="nf nf-fa-edit"></i></a>' : '') . '
</div>
<div class="row">
<div class="row">
<div class="row_space_between">
<div class="row_space_between">
<div class="col_right">
<h5>Written by <a href="user.php?view=display&user_id=' . $author['user_id'] . '">' . $author['username'] . '</a></h5>
<p>Published on ' . $article['published_at'] . '<br>
+2 -2
View File
@@ -23,7 +23,7 @@ function article_card($article_id)
$card = '
<div class="article_card">
<div class="row">
<div class="row_space_between">
<h4>' . $article['title'] . '</h4>
<div class="card_info_box">
<div class="col-right">
@@ -38,7 +38,7 @@ function article_card($article_id)
</div>
<div class="line"></div>
<p>' . $article['excerpt'] . '</p>
<div class="row">
<div class="row_space_between">
<a href="/articles.php?view=read&article_id=' . $article['article_id'] . '" class="button">Read More</a>
<div class="tag_box">' . $tags_html . '</div>
</div>
+1 -1
View File
@@ -5,7 +5,7 @@ function article_list($list = null)
$filters = '
<form method="get" action="articles.php">
<input type="hidden" name="view" value="sort">
<div class="row_no_margin">
<div class="row_space_between no_margin">
';
if (!isset($_GET['sort']) || $_GET['sort'] == 'newest') {
+16 -14
View File
@@ -24,27 +24,27 @@
if (isset($args['view'])) {
if ($args['view'] == 'signup') {
echo '
<script src="js/profile_picture_cropper_modal.js"></script>
<script src="js/upload.js"></script>
';
<script src="js/profile_picture_cropper_modal.js"></script>
<script src="js/upload.js"></script>
';
} else if ($args['view'] == 'display') {
echo '
<script src="js/user_actions_modal.js"></script>
<script src="js/upload.js"></script>
';
<script src="js/user_actions_modal.js"></script>
<script src="js/upload.js"></script>
';
}
}
} else if ($_SERVER['SCRIPT_NAME'] == '/admin.php') {
echo '
<script src="js/clickable_rows.js"></script>
';
<script src="js/clickable_rows.js"></script>
';
$args = get_args_from_url();
if (isset($args['view'])) {
if ($args['view'] == 'users') {
echo '
<script src="js/upload.js"></script>
';
<script src="js/upload.js"></script>
';
}
}
} else if ($_SERVER['SCRIPT_NAME'] == '/articles.php') {
@@ -53,15 +53,17 @@
if (isset($args['view'])) {
if ($args['view'] == 'compose') {
echo '
<script src="js/md_preview.js"></script>
';
<script src="js/md_preview.js"></script>
';
}
}
} else if ($_SERVER['SCRIPT_NAME'] == '/todo.php') {
echo '<script src="js/todo.js"></script>';
}
echo '
<script src="js/override_browser_styles.js"></script>
';
<script src="js/override_browser_styles.js"></script>
';
?>
</footer>
+1
View File
@@ -3,6 +3,7 @@
<head>
<link href="css/base.css" rel="stylesheet" type="text/css">
<link href="css/rewrite.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://nerdfonts.com/assets/css/webfont.css">
<link rel="icon" type="image/x-icon" href="data/vintagecoding-favicon.png" </link>
<?php
+9 -8
View File
@@ -2,22 +2,23 @@
$current_page = $_SERVER['SCRIPT_NAME'];
$nav = '
<nav>
<div class="row_no_margin">
<div class="row_space_between no_margin">
<div class="site_navigation">
<ul>
<li><a href="/index.php"' . ($current_page == '/index.php' ? ' class="underline"' : '') . '>Home</a></li>
<li><a href="/articles.php?view=sort&sort=newest"' . ($current_page == '/articles.php' ? ' class="underline"' : '') . '>Articles</a></li>
';
if (isset($_SESSION['role_id']) && $_SESSION['role_id'] <= 2) {
$nav .= '
if (isset($_SESSION['role_id']) && $_SESSION['role_id'] <= admin) {
$nav .= '
<li><a href="/admin.php?view=users"' . ($current_page == '/admin.php' ? ' class="underline"' : '') . '>Admin</a></li>
';
}
if (isset($_SESSION['user_id'])) {
$nav .= '
$nav .= '
<li><a href="/user.php?view=display&user_id=' . $_SESSION['user_id'] . '"' . ($current_page == '/user.php' ? ' class="underline"' : '') . '>Account</a></li>
<li><a href="/todo.php?view=display"' . ($current_page == '/todo.php' ? ' class="underline"' : '') . '>Todos</a></li>
';
}
@@ -30,9 +31,9 @@ $nav .= '
$theme_toggle = '';
if ($_SESSION['theme'] == 'dark')
$theme_toggle = 'light';
$theme_toggle = 'light';
else
$theme_toggle = 'dark';
$theme_toggle = 'dark';
$nav .= '
<button id="theme_toggle" value="' . $theme_toggle . '" name="theme"><i class="nf ' . ($theme_toggle == 'dark' ? 'nf-oct-moon' : 'nf-oct-sun') . '"></i></button>
@@ -40,11 +41,11 @@ $nav .= '
';
if (isset($_SESSION['username'])) {
$nav .= '
$nav .= '
<a href="user.php?view=logout">Log Out</a>
';
} else {
$nav .= '
$nav .= '
<a href="user.php?view=login">Login</a>
<a href="user.php?view=signup">Sign Up</a>
';
+20
View File
@@ -0,0 +1,20 @@
<?php
function todo_actions()
{
$actions = '
<div class="todo_actions">
<form method="post">
<button name="action" value="new">New</button>
<button name="action" value="new">New</button>
<button name="action" value="new">New</button>
<button name="action" value="new">New</button>
<button name="action" value="new">New</button>
<button name="action" value="new">New</button>
<button name="action" value="new">New</button>
</form>
</div>
';
return $actions;
}
+13
View File
@@ -0,0 +1,13 @@
<?php
function todo_category($category, $todos)
{
$category = '
<div class="todo_category med_border padding">
<h4 class="padding">' . ucwords($category) . '</h4>
<div class="line bottom_margin"></div>
' . todo_list($todos) . '
</div>
';
return $category;
}
+66
View File
@@ -0,0 +1,66 @@
<?php
function sort_by_completion($a, $b)
{
// Ensure $a and $b are arrays before proceeding
if (!is_array($a) || !is_array($b)) {
// Handle the case where one or both are not arrays.
// This shouldn't ideally happen with uasort on your $categories array,
// but adding a safeguard is good practice.
return 0; // Maintain original order if not arrays
}
$a_completed = true;
foreach ($a as $todo) {
if (isset($todo['status']) && $todo['status'] !== 'completed') {
$a_completed = false;
break;
}
}
$b_completed = true;
foreach ($b as $todo) {
if (isset($todo['status']) && $todo['status'] !== 'completed') {
$b_completed = false;
break;
}
}
if ($a_completed && $b_completed) {
return 0;
} elseif ($a_completed && !$b_completed) {
return 1;
} elseif (!$a_completed && $b_completed) {
return -1;
} else {
return 0;
}
}
function todo_display($todos)
{
$categories = [];
while ($row = $todos->fetch_assoc())
$categories[$row['category']][] = $row;
foreach ($categories as $c)
uasort($c, 'sort_by_completion');
$display = '
<div class="todo_display">
' . todo_actions() . '
<div class="todo_category_window">
';
foreach ($categories as $c)
$c = array_reverse($c);
foreach (array_keys($categories) as $key)
$display .= todo_category($key, $categories[$key]);
$display .= '
</div>
</div>
';
return $display;
}
+28
View File
@@ -0,0 +1,28 @@
<?php
function todo_item($todo)
{
$item = '
<div class="todo_item bottom_margin top_padding bottom_padding sm_border">
<div class="row left_margin">
<div class="column center">
<label class="form_checkbox_container no_margin">
<input type="hidden" name="todo_id" value="' . $todo['todo_id'] . '">
<input type="checkbox"' . ($todo['status'] == 'completed' ? ' checked' : '') . '>
<span class="checkmark no_margin"></span>
</label>
</div>
<div class="column center">
<small>' . $todo['task'] . '</small>
</div>
</div>
</div>
<div class="todo_item_details" style="display: none;">
</div>
';
return $item;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
function todo_list($todos)
{
$list = '
<div class="todo_list">
';
foreach ($todos as $todo)
$list .= todo_item($todo);
$list .= '
</div>
';
return $list;
}
+2
View File
@@ -0,0 +1,2 @@
<?php
function modal() {}
+5 -5
View File
@@ -12,12 +12,12 @@ function user_view($user_id)
$view = '
<div class="user_view">
<div class="row">
<div class="row">
<div class="row_space_between">
<div class="row_space_between">
<h1>' . $user['username'] . '</h1>
';
if ($_SESSION['user_id'] != $user_id && !$following) {
if ($_SESSION['user_id'] != $user_id && isset($following) && !$following) {
$view .= '
<div class="dropdown">
<span>Follow</span>
@@ -31,7 +31,7 @@ function user_view($user_id)
</div>
</div>
';
} else if ($following) {
} else if (isset($following) && $following) {
$view .= '
<div class="margin_right">
<form method="post">
@@ -55,7 +55,7 @@ function user_view($user_id)
// TODO: Allow user to update profile picture.
// <button id="update_profile_picture_form_button" class="modal_button underline">Update Profile Picture</button>
// <div id="update_profile_picture_form" class="modal_form">' . update_profile_picture_form() . '</div>
if ((isset($_SESSION['user_id']) && $_SESSION['user_id'] == $user_id) || (isset($_SESSION['role_id']) && $_SESSION['role_id'] <= 2)) {
if ((isset($_SESSION['user_id']) && $_SESSION['user_id'] == $user_id) || (isset($_SESSION['role_id']) && $_SESSION['role_id'] <= admin)) {
$view .= '
<h3>User Actions</h3>
<div class="user_actions">