' . $errorMapping[$_GET["error"]] . '
'; + } + ?> + +diff --git a/Controllers/ExpenseController.php b/Controllers/ExpenseController.php index 18d987f..f18370c 100644 --- a/Controllers/ExpenseController.php +++ b/Controllers/ExpenseController.php @@ -14,7 +14,7 @@ function getAll($idUser) $db = new MySqlDatabase(); $mysql = $db->connect(); - $sql = 'SELECT * FROM expenses WHERE idUser=?'; + $sql = 'SELECT * FROM expenses WHERE idUser=? ORDER BY date DESC'; $stmt = $mysql->prepare($sql); if (!$stmt) { @@ -91,7 +91,7 @@ function delete() { } - function update() + function update($obj, $uid) { } diff --git a/Controllers/RevenueController.php b/Controllers/RevenueController.php index 2167c83..1382738 100644 --- a/Controllers/RevenueController.php +++ b/Controllers/RevenueController.php @@ -4,6 +4,7 @@ include_once __DIR__ . '/../Interfaces/Controller.inter.php'; include_once __DIR__ . '/../Models/MySqlDatabase.class.php'; include_once __DIR__ . '/../Models/Revenue.class.php'; +include_once __DIR__ . '/../Utils/Constants.php'; class RevenueController implements Controller { @@ -59,7 +60,32 @@ function create($transaction) { function delete() {} - function update() {} + function update($obj, $uid) {} function delete_all() {} + + function sumAmount($idUser, $type) + { + $db = new MySqlDatabase(); + $mysql = $db->connect(); + + $subquery = $type == TODAY ? 'DATE(date) = CURDATE()' : 'DATE_FORMAT(date, "%Y-%m") = DATE_FORMAT(NOW(), "%Y-%m")'; + $sql = 'SELECT IFNULL(SUM(amount),0) AS total FROM revenues WHERE ' . $subquery . ' AND idUser=?;'; + $stmt = $mysql->prepare($sql); + + if (!$stmt) { + return null; + } else { + $stmt->bind_param('s', $idUser); + $stmt->execute(); + $result = $stmt->get_result(); + + if ($row = $result->fetch_assoc()) { + return $row['total']; + } else { + return 0; + } + } + $db->disconnect(); + } } \ No newline at end of file diff --git a/Controllers/UserController.php b/Controllers/UserController.php index 8281868..619330e 100644 --- a/Controllers/UserController.php +++ b/Controllers/UserController.php @@ -60,7 +60,26 @@ function create($user) { function delete() {} - function update() {} + function update($user, $uidUser) { + $db = new MySqlDatabase(); + $mysql = $db->connect(); + + $sql = 'UPDATE users SET uidUser=?, emailUser=?, pwdUser=? WHERE uidUser=?'; + $stmt = $mysql->prepare($sql); + + if (!$stmt) { + return 1064; + } + else { + $hashPassword = password_hash($user->password, PASSWORD_DEFAULT); + $stmt->bind_param('ssss', $user->username, $user->email, $hashPassword, $uidUser); + $stmt->execute(); + + return $stmt->errno; + } + + $db->disconnect(); + } function delete_all() {} } diff --git a/Interfaces/Controller.inter.php b/Interfaces/Controller.inter.php index 93c096c..1baf432 100644 --- a/Interfaces/Controller.inter.php +++ b/Interfaces/Controller.inter.php @@ -5,7 +5,7 @@ function get($id); function create($obj); function delete(); - function update(); + function update($obj, $uid); function delete_all(); } \ No newline at end of file diff --git a/models/Expense.class.php b/Models/Expense.class.php similarity index 100% rename from models/Expense.class.php rename to Models/Expense.class.php diff --git a/models/Revenue.class.php b/Models/Revenue.class.php similarity index 100% rename from models/Revenue.class.php rename to Models/Revenue.class.php diff --git a/models/User.class.php b/Models/User.class.php similarity index 100% rename from models/User.class.php rename to Models/User.class.php diff --git a/Public/includes/profile.inc.php b/Public/includes/profile.inc.php new file mode 100644 index 0000000..423e379 --- /dev/null +++ b/Public/includes/profile.inc.php @@ -0,0 +1,74 @@ +update($user_obj, $_SESSION['userUid']); + if ($result === SUCCESS) { + $_SESSION['userUid'] = $_POST["userUid"] = $username; + header("Location: /profile?edit=success"); + exit(); + } + else if ($result === ER_DUP_ENTRY) { + //User taken + header("Location: /profile?error=userTaken&mail=$email"); + exit(); + } + else if ($result === ER_PARSE_ERROR) { + header("Location: /profile?error=invalidsql"); + exit(); + } + else { + throw new Exception($result); + //header("Location: /profile?error=invalid"); + exit(); + } + } + } + else { + header("Location: /profile"); + exit(); + } diff --git a/Public/styles/profile.css b/Public/styles/profile.css new file mode 100644 index 0000000..2885b7d --- /dev/null +++ b/Public/styles/profile.css @@ -0,0 +1,50 @@ +budget-card { + margin: 0 25px; +} + +ul { + padding: 0; +} + +.list { + display: grid; + grid-template-columns: 1fr 1fr; +} + +.category { + text-align: left; + padding: 10px; + color: var(--secondary-color); +} + +.value { + text-align: right; + padding: 10px; + color: var(--primary-dark-color); +} + +#save, +#edit, +#cancel { + background-color: var(--primary-color); + padding: 8px 45px; + border-radius: 5px; + margin: 10px; + display: inline; +} + +#cancel { + background-color: var(--text-body); +} + +input { + border: none; +} + +*:focus { + outline: none; +} + +.hidden { + display: none; +} \ No newline at end of file diff --git a/Public/views/dashboard.php b/Public/views/dashboard.php index 2b1c47b..cd2115b 100644 --- a/Public/views/dashboard.php +++ b/Public/views/dashboard.php @@ -8,6 +8,7 @@ include_once __DIR__ . '/../../Controllers/RevenueController.php'; $expense_controller = new ExpenseController(); +$revenue_controller = new RevenueController(); $transactions = $expense_controller->getAll($_SESSION['userId']); $chartData = $expense_controller->spending_breakdown($_SESSION['userId']); ?> @@ -36,19 +37,18 @@
No recent transactions
"; } @@ -56,12 +56,6 @@No recent transactions
"; + } + ?> +