34 lines
1.0 KiB
PHP
34 lines
1.0 KiB
PHP
<?php
|
|
require 'db.php';
|
|
require 'auth.php';
|
|
|
|
header('Content-Type: application/json');
|
|
require_login();
|
|
|
|
$user_id = current_user_id();
|
|
$profile_id = $_SESSION['active_profile_id'] ?? null;
|
|
|
|
if (!$profile_id) {
|
|
http_response_code(400);
|
|
echo json_encode(['success' => false, 'error' => 'No active profile']);
|
|
exit;
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM projects WHERE user_id = ? AND profile_id = ? ORDER BY sort_order ASC");
|
|
$stmt->execute([$user_id, $profile_id]);
|
|
$projects = $stmt->fetchAll();
|
|
|
|
foreach ($projects as &$project) {
|
|
$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 = ? AND user_id = ? ORDER BY created_at");
|
|
$stmt->execute([$task['id'], $user_id]);
|
|
$task['subtasks'] = $stmt->fetchAll();
|
|
}
|
|
}
|
|
|
|
echo json_encode($projects);
|