-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.php
309 lines (285 loc) · 15.1 KB
/
home.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
include './includes/connect.php';
session_start();
// checking whether a user is logged in or not. If the user is not logged in, it redirects them to the sign-in page.
if (!isset($_SESSION["user"])) {
header("Location: signIn.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./bootstrap-5.3.0-alpha1-dist/css/bootstrap.min.css" />
<script src="./bootstrap-5.3.0-alpha1-dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="style.css">
<title>Budget Management</title>
</head>
<body class="d-flex flex-column flex-lg-row ">
<!-- style home page to atcive at navigaion -->
<?php $activeNav = 'home';
include './includes/nav.php'; ?>
<section class="body-content mt-3">
<div class="header-content d-flex align-items-center justify-content-between ">
<h5>Hi,<?php echo $_SESSION["first_name"]; ?></h5>
<?php
// If the form has been submitted, the value of the myDate input field is stored in a session variable $_SESSION['myDate']. This will be used to remember the date that the user selected.
if (isset($_POST["myDate"])) {
$_SESSION['myDate'] = $_POST['myDate'];
}
?>
<form id="myForm" method="post" action="home.php">
<?php
$firefox = strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false;
if ($firefox) {
// For Firefox browser
echo ' <input type="date" id="myDate" name="myDate" value="' . $_SESSION["myDate"] . '">';
} else {
// For other browsers
echo ' <input type="date" id="myDate" name="myDate" value="' . $_SESSION["myDate"] . '">';
}
?>
</form>
<script>
document.getElementById("myDate").addEventListener("change", function() {
document.getElementById("myForm").submit();
});
</script>
</div>
<div class="welcome-content d-flex flex-column flex-md-row align-items-center align-items-md-start justify-content-between">
<div class="left-sec d-flex align-items-center justify-content-between">
<h6>Manage your money!</h6>
<img src="./Image/Savings-pana.png" alt="saveMoneyImage">
</div>
<div class="right-sec d-flex flex-column align-items-center justify-content-around text-center">
<h5 class="fs-4">Your total expenses</h5>
<?php
// extract the year and month from the selected date stored in the $_SESSION['myDate'] variable.
$_SESSION['year'] = date("Y", strtotime($_SESSION['myDate']));;
$_SESSION['month'] = date('m', strtotime($_SESSION['myDate']));
$sql = "SELECT SUM(price) AS total_price FROM (
SELECT price FROM food_items WHERE user_id = {$_SESSION['user_id']} and month(date) = {$_SESSION['month']} and year(date)={$_SESSION['year']}
UNION ALL
SELECT price FROM shopping_items WHERE user_id = {$_SESSION['user_id']} and month(date) = {$_SESSION['month']} and year(date)={$_SESSION['year']}
UNION ALL
SELECT price FROM health_items WHERE user_id = {$_SESSION['user_id']} and month(date) = {$_SESSION['month']} and year(date)={$_SESSION['year']}
UNION ALL
SELECT price FROM other_items WHERE user_id = {$_SESSION['user_id']} and month(date) = {$_SESSION['month']} and year(date)={$_SESSION['year']}
) t";
$result = mysqli_query($con, $sql);
$totalExp = 0;
while ($row = mysqli_fetch_assoc($result)) {
$totalExp += $row['total_price'];
}
echo " <h3 class='fs-1'>" . $totalExp . "$</h3>";
?>
<p class="fs-6"><?php echo $_SESSION['myDate']; ?></p>
</div>
</div>
<div class="container pages-data d-flex flex-column flex-lg-row align-items-center justify-content-between ">
<div class="field-debt d-flex flex-column align-items-center justify-content-between">
<div class="field-container d-flex flex-column align-items-center justify-content-center ">
<div class="fields d-flex flex-column flex-sm-row align-items-center justify-content-around">
<div class=" box food">
<?php
$query = "SELECT SUM(price) as total_food FROM food_items WHERE user_id = {$_SESSION['user_id']} and month(date)={$_SESSION['month']} and year(date)={$_SESSION['year']}";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
$total_food = $row['total_food'];
?>
<a href="./food.php">
<div class=" content">
<h3 class="fs-4">Food</h3>
<p class="fs-6"><span>Total:</span>
<?php
if ($total_food > 0) {
echo $total_food;
} else {
$total_food = 0;
echo $total_food;
}
?>$</p>
</div>
</a>
</div>
<div class="box health">
<?php
$query = "SELECT SUM(price) as total_health FROM health_items WHERE user_id = {$_SESSION['user_id']} and month(date)={$_SESSION['month']} and year(date)={$_SESSION['year']}";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
$total_health = $row['total_health'];
?>
<a href="./health.php">
<div class="content">
<h3 class="fs-4">Health</h3>
<p class="fs-6"><span>Total: </span>
<?php
if ($total_health > 0) {
echo $total_health;
} else {
$total_health = 0;
echo $total_health;
}
?>$
</p>
</div>
</a>
</div>
<div class="box shopping">
<?php
$query = "SELECT SUM(price) as total_shopping FROM shopping_items WHERE user_id = {$_SESSION['user_id']} and month(date)={$_SESSION['month']} and year(date)={$_SESSION['year']}";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
$total_shopping = $row['total_shopping'];
?>
<a href="./shopping.php">
<div class=" content">
<h3 class="fs-4">shopping</h3>
<p class="fs-6"><span>Total:</span>
<?php
if ($total_shopping > 0) {
echo $total_shopping;
} else {
$total_shopping = 0;
echo $total_shopping;
}
?>$</p>
</div>
</a>
</div>
</div>
<?php
$query = "SELECT SUM(price) as total_others FROM other_items WHERE user_id = {$_SESSION['user_id']} and month(date)={$_SESSION['month']} and year(date)={$_SESSION['year']}";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
$total_others = $row['total_others'];
if (!($total_shopping > 0)) {
$total_shopping = 0;
}
?>
<a href="./others.php">more>></a>
</div>
<div class="debt d-flex flex-column flex-sm-row align-items-center justify-content-around">
<?php
$query = "SELECT SUM(amount) as total_lent FROM lent_items WHERE user_id = {$_SESSION['user_id']} and month(date)={$_SESSION['month']} and year(date)={$_SESSION['year']}";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
$total_lent = $row['total_lent'];
?>
<a href="./lent.php" style="color:#3f5a9f;">
<div class="lent box d-flex align-items-center justify-content-center ">
<div class="icon d-flex align-items-center justify-content-center">
<img src="./Image/money.png" alt="lent" width="45px">
</div>
<div class="detail">
<p>Lent</p>
<p class="fs-3 fw-bold">
<?php
if ($total_lent > 0) {
echo $total_lent;
} else {
$total_lent = 0;
echo $total_lent;
}
?>$</p>
</div>
</div>
</a>
<?php
$query = "SELECT SUM(amount) as total_borrow FROM borrow_items WHERE user_id = {$_SESSION['user_id']} and month(date)={$_SESSION['month']} and year(date)={$_SESSION['year']}";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
$total_borrow = $row['total_borrow'];
?>
<a href="./borrow.php" style="color:#3f5a9f;">
<div class="borrow box d-flex align-items-center justify-content-center ">
<div class="icon d-flex align-items-center justify-content-center">
<img src="./Image/money.png" alt="lent" width="45px">
</div>
<div class="detail">
<p>Borrow</p>
<p class="fs-3 fw-bold">
<?php
if ($total_borrow > 0) {
echo $total_borrow;
} else {
$total_borrow = 0;
echo $total_borrow;
}
?>$</p>
</div>
</div>
</a>
</div>
</div>
<div class="chart d-flex align-items-center justify-content-center">
<?php
// Your dynamic data array
if ($total_food == 0 and $total_shopping == 0 and $total_health == 0 and $total_others == 0) {
$empty = 1;
} else {
$empty = 0;
}
$dataVal = [$empty, $total_food, $total_shopping, $total_health, $total_others];
// Generate the Chart.js configuration options in PHP
$options = [
"type" => 'doughnut',
'data' => [
'labels' => ['Empty', 'Food', 'shopping', 'Health', 'others'],
'datasets' => [
[
'data' => $dataVal,
'backgroundColor' => [
'#eceef9',
'#FCE1CA',
'#EAD1EE',
'#DEF7E5',
'#FFF5DE'
],
'borderColor' => [
'#eceef9',
'#FCE1CA',
'#EAD1EE',
'#DEF7E5',
'#FFF5DE'
],
]
]
],
'options' => [
'responsive' => 'false',
'plugins' => [
'legend' => [
'display' => 'true',
'position' => 'bottom',
'labels' => [
'usePointStyle' => 'true'
],
'padding' => [
'top' => 15,
]
]
]
]
];
// Convert the PHP options array to a JSON string
$options_json = json_encode($options);
?>
<canvas id="myChart"></canvas>
</div>
</div>
</section>
<!-- chart js CDN -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="./jquery-3.6.0.min.js"></script>
<!-- <script src="index.js"></script> -->
<script>
var ctx = document.getElementById('myChart').getContext('2d');
var options = <?php echo $options_json; ?>; // Pass the options from PHP to JavaScript
var myChart = new Chart(ctx, options);
</script>
</body>
</html>