$username = trim($_POST["username"]); $email = trim($_POST["email"]); $password = $_POST["password"]; $passwordConfirm = $_POST["passwordConfirm"]; // Add the user to the database if no problem with all the data if (User::isValidRegistrationData($username, $email, $password, $passwordConfirm)) { $user = new User(); $user->username = $username; $user->email = $email; $user->password = password_hash($password, PASSWORD_BCRYPT); $user->save(); // Create default income/expense categories $incomeCategories = array("Work", "Other"); $expenseCategories = array("Food", "Home", "Clothing", "Entertainment", "Transportation", "Other"); foreach ($incomeCategories as $category) { $incomeType = new IncomeType(); $incomeType->userID = $user->id; $incomeType->category = $category; $incomeType->save(); } foreach ($expenseCategories as $category) { $expenseType = new ExpenseType(); $expenseType->userID = $user->id; $expenseType->category = $category; $expenseType->save(); } // Create default wishlist group $wishlistGroup = new WishlistGroup(); $wishlistGroup->userID = $user->id; $wishlistGroup->groupName = "General"; $wishlistGroup->save();
<?php $user = User::findById($session->userID); $incomeTypes = IncomeType::findBySql('SELECT * FROM incometypes WHERE userID = "' . $user->id . '" ORDER BY id'); $expenseTypes = ExpenseType::findBySql('SELECT * FROM expensetypes WHERE userID = "' . $user->id . '" ORDER BY id'); // Fetch income and expense data based on the current view if ($view === "daily") { $incomes = Income::findBySql('SELECT * FROM incomes WHERE userID = "' . $user->id . '" AND date = "' . $mySqlFormatedDate . '" ORDER BY id'); $expenses = Expense::findBySql('SELECT * FROM expenses WHERE userID = "' . $user->id . '" AND date = "' . $mySqlFormatedDate . '" ORDER BY id'); } else { if ($view === "monthly" || $view === "yearly") { $incomes = Income::findBySql('SELECT * FROM incomes WHERE userID = "' . $user->id . '" AND date BETWEEN "' . $mySqlFormatedDateStart . '" AND "' . $mySqlFormatedDateEnd . '"'); $expenses = Expense::findBySql('SELECT * FROM expenses WHERE userID = "' . $user->id . '" AND date BETWEEN "' . $mySqlFormatedDateStart . '" AND "' . $mySqlFormatedDateEnd . '"'); } else { if ($view === "allTime") { $incomes = Income::findBySql('SELECT * FROM incomes WHERE userID = "' . $user->id . '" ORDER BY date'); $expenses = Expense::findBySql('SELECT * FROM expenses WHERE userID = "' . $user->id . '" ORDER BY date'); } } }