Added authentication functionality and simple role based model

This commit is contained in:
2026-02-11 15:02:37 -08:00
parent c247631de6
commit 11889e3f93
17 changed files with 341 additions and 57 deletions

View File

@@ -1,19 +1,26 @@
<?php
require 'db.php';
require 'auth.php';
$projects = $pdo->query("SELECT * FROM projects ORDER BY sort_order ASC")->fetchAll();
header('Content-Type: application/json');
require_login();
$user_id = current_user_id();
$stmt = $pdo->prepare("SELECT * FROM projects WHERE user_id = ? ORDER BY sort_order ASC");
$stmt->execute([$user_id]);
$projects = $stmt->fetchAll();
foreach ($projects as &$project) {
$stmt = $pdo->prepare("SELECT * FROM tasks WHERE project_id = ? ORDER BY created_at");
$stmt->execute([$project['id']]);
$stmt = $pdo->prepare("SELECT * FROM tasks WHERE project_id = ? AND user_id = ? ORDER BY created_at");
$stmt->execute([$project['id'], $user_id]);
$project['tasks'] = $stmt->fetchAll();
foreach ($project['tasks'] as &$task) {
$stmt = $pdo->prepare("SELECT * FROM subtasks WHERE task_id = ? ORDER BY created_at");
$stmt->execute([$task['id']]);
$stmt = $pdo->prepare("SELECT * FROM subtasks WHERE task_id = ? AND user_id = ? ORDER BY created_at");
$stmt->execute([$task['id'], $user_id]);
$task['subtasks'] = $stmt->fetchAll();
}
}
echo json_encode($projects);
?>
echo json_encode($projects);