diff --git a/TODO.md b/TODO.md index a9b6648..42b1da9 100644 --- a/TODO.md +++ b/TODO.md @@ -6,6 +6,13 @@ - [ ] edit user data - change password, mail... ## Core of the app -- [ ] Habits list +- [ ] header and navbar +- [ ] dashboard + - [x] css + - [ ] its just plain + - [ ] graphs +- [x] Habits list + - [ ] css - [ ] Habits create + - [ ] validate cron input - [ ] Habits track diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php new file mode 100644 index 0000000..647d6d5 --- /dev/null +++ b/app/controllers/DashboardController.php @@ -0,0 +1,16 @@ +getHabitsByUser($_SESSION['user']['id']); + + $this->view('dashboard/index', [ + 'title' => 'Dashboard', + 'habits' => $habits, + ]); + } + + public function reroute(){ + $this->redirect('/dashboard'); + } +} diff --git a/app/controllers/HabitController.php b/app/controllers/HabitController.php index 9f7f6ce..9221113 100644 --- a/app/controllers/HabitController.php +++ b/app/controllers/HabitController.php @@ -2,7 +2,9 @@ class HabitController extends Controller { public function index() { - // Display the list of habits (to be implemented later) + $habit = new Habit(); + $habits = $habit->getHabitsByUser($_SESSION['user']['id']); + $this->view('habits/index', ['title' => 'Habits', 'habits' => $habits]); } public function create() { @@ -17,15 +19,12 @@ class HabitController extends Controller { } if ($frequency === 'Custom') { - var_dump($_POST); $daysOfWeek = $_POST['days_of_week'] ?? []; $daysOfMonth = $_POST['days_of_month'] ?? '*'; $months = $_POST['months'] ?? '*'; // Combine into crontab-like string $customFrequency = implode(',', $daysOfWeek) . " $daysOfMonth $months"; - var_dump($customFrequency); - } $habit = new Habit(); @@ -38,7 +37,7 @@ class HabitController extends Controller { ]); if ($result) { - //$this->redirect('/habits'); + $this->redirect('/habits'); } else { $this->view('habits/create', ['error' => 'Failed to create habit.']); } diff --git a/app/models/Habit.php b/app/models/Habit.php index 26d0df5..f7078b8 100644 --- a/app/models/Habit.php +++ b/app/models/Habit.php @@ -29,4 +29,18 @@ class Habit { return false; } } + + public function getHabitsByUser($userId) { + $stmt = $this->db->prepare("SELECT id, title, frequency, custom_frequency, reward_points, created_at FROM habits WHERE user_id = ?"); + $stmt->bind_param("i", $userId); + $stmt->execute(); + $result = $stmt->get_result(); + + $habits = []; + while ($row = $result->fetch_assoc()) { + $habits[] = $row; + } + + return $habits; + } } diff --git a/app/views/auth/signin.php b/app/views/auth/signin.php index d624326..7d9dbdd 100644 --- a/app/views/auth/signin.php +++ b/app/views/auth/signin.php @@ -1,5 +1,6 @@ -
+ +
Habit Tracker Logo

Sign in to Habit Tracker

diff --git a/app/views/auth/signup.php b/app/views/auth/signup.php index 5ab2a00..68cc2f7 100644 --- a/app/views/auth/signup.php +++ b/app/views/auth/signup.php @@ -1,5 +1,6 @@ -