-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
310 lines (299 loc) · 9.61 KB
/
dashboard.php
File metadata and controls
310 lines (299 loc) · 9.61 KB
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
310
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HabitHub Dashboard</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}
body {
background-color: #f4f4f4;
}
.container {
display: flex;
min-height: 100vh;
}
.sidebar {
width: 250px;
background-color: #4CAF50;
color: white;
padding: 20px;
position: fixed;
height: 100%;
}
.sidebar h1 {
font-size: 24px;
margin-bottom: 20px;
}
.sidebar ul {
list-style: none;
}
.sidebar ul li {
margin: 10px 0;
}
.sidebar ul li a {
color: white;
text-decoration: none;
display: block;
padding: 10px;
border-radius: 5px;
}
.sidebar ul li a:hover {
background-color: #45a049;
}
.sidebar ul li.active a {
background-color: white;
color: #4CAF50;
}
.main-content {
margin-left: 250px;
padding: 20px;
flex: 1;
}
.header {
margin-bottom: 20px;
}
.header h2 {
font-size: 28px;
color: #333;
}
.header p {
color: #666;
}
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 20px;
}
.stat-card {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
display: flex;
align-items: center;
}
.stat-card i {
font-size: 24px;
color: #4CAF50;
margin-right: 10px;
}
.habits {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.habits-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.add-habit-btn {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 15px;
border-radius: 5px;
cursor: pointer;
}
.habit-card {
background-color: #f9f9f9;
padding: 15px;
border-radius: 5px;
margin-bottom: 15px;
}
.habit-card h3 {
margin-bottom: 5px;
color: #333;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
align-items: center;
justify-content: center;
}
.modal-content {
background-color: white;
width: 90%;
max-width: 500px;
padding: 20px;
border-radius: 5px;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.close-modal {
background: none;
border: none;
font-size: 20px;
cursor: pointer;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
}
.form-group input {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 5px;
}
.form-actions {
display: flex;
justify-content: flex-end;
gap: 10px;
}
.btn {
padding: 10px 15px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.cancel-btn {
background-color: #ccc;
}
.create-btn {
color: black;
}
@media (max-width: 768px) {
.sidebar {
width: 100%;
height: auto;
position: static;
}
.main-content {
margin-left: 0;
}
.stats {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="container">
<div class="sidebar">
<h1>HabitHub</h1>
<ul>
<li class="active"><a href="#"><i class="fas fa-home"></i> Dashboard</a></li>
<li><a href="#"><i class="fas fa-chart-line"></i> Statistics</a></li>
</ul>
</div>
<main class="main-content">
<header class="header">
<h2>Welcome back, </h2>
<p id="current-date"></p>
</header>
<section class="stats">
<div class="stat-card">
<i class="fas fa-check-circle"></i>
<div>
<h3 id="active-habits">0</h3>
<p>Active Habits</p>
</div>
</div>
<div class="stat-card">
<i class="fas fa-fire"></i>
<div>
<h3 id="current-streak">0</h3>
<p>Current Streak</p>
</div>
</div>
</section>
<section class="habits">
<div class="habits-header">
<h2>Your Habits</h2>
<button class="add-habit-btn"><i class="fas fa-plus"></i> New Habit</button>
</div>
<div class="habits-container" id="habits-container">
<?php
include 'db_connection.php';
$result = $conn->query("SELECT * FROM habits");
while ($habit = $result->fetch_assoc()) {
echo '<div class="habit-card">';
echo '<h3>' . htmlspecialchars($habit['name_of_habit']) . '</h3>';
echo '<p>' . htmlspecialchars($habit['description'] ?: 'No description') . '</p>';
echo '</div>';
}
$conn->close();
?>
</div>
</section>
</main>
</div>
<div class="modal" id="add-habit-modal">
<div class="modal-content">
<div class="modal-header">
<h2>Add New Habit</h2>
<button class="close-modal">×</button>
</div>
<form id="add-habit-form" action="add_habit.php" method="post">
<div class="form-group">
<label for="habit-name">Habit Name</label>
<input type="text" id="habit-name" name="habit_name" placeholder="e.g., Morning Exercise" required>
</div>
<div class="form-group">
<label for="habit-description">Description</label>
<input type="text" id="habit-description" name="description" placeholder="e.g., 30 minutes daily workout">
</div>
<div class="form-actions">
<button type="button" class="btn cancel-btn">Cancel</button>
<button type="submit" class="btn create-btn">Create Habit</button>
</div>
</form>
</div>
</div>
<script>
// Set current date
const dateElement = document.getElementById('current-date');
const today = new Date();
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
dateElement.textContent = today.toLocaleDateString('en-US', options);
// Handle modal
const modal = document.getElementById('add-habit-modal');
const addHabitBtn = document.querySelector('.add-habit-btn');
const closeModalBtn = document.querySelector('.close-modal');
const cancelBtn = document.querySelector('.cancel-btn');
addHabitBtn.addEventListener('click', () => {
modal.style.display = 'flex';
});
closeModalBtn.addEventListener('click', () => {
modal.style.display = 'none';
});
cancelBtn.addEventListener('click', () => {
modal.style.display = 'none';
});
// Update stats
function updateStats() {
fetch('get_stats.php')
.then(response => response.json())
.then(data => {
document.getElementById('active-habits').textContent = data.activeHabits;
document.getElementById('current-streak').textContent = data.currentStreak;
});
}
// Initial load
updateStats();
</script>
</body>
</html>