-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
138 lines (129 loc) · 5.16 KB
/
index.php
File metadata and controls
138 lines (129 loc) · 5.16 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
<?php
session_start();
if(!isset($_SESSION['user_id'])){
header('location: login.php');
exit;
}
// Fetch data from the database
include 'php/db_connect.php';
$parent_id = $_SESSION['user_id'];
// Fetch total children
$sql = "SELECT COUNT(*) as total_children FROM children WHERE parent_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $parent_id);
$stmt->execute();
$result = $stmt->get_result();
$total_children = $result->fetch_assoc()['total_children'];
$stmt->close();
// Fetch total medication
$sql = "
SELECT COUNT(*) as total_medication
FROM medicine m
JOIN children c ON m.child_id = c.id
WHERE c.parent_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $parent_id);
$stmt->execute();
$result = $stmt->get_result();
$medication_data = $result->fetch_assoc();
$stmt->close();
// Fetch children medication data
$sql = "
SELECT c.first_name, c.last_name, m.name as medication_name, m.start_date, m.end_date
FROM medicine m
JOIN children c ON m.child_id = c.id
WHERE c.parent_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $parent_id);
$stmt->execute();
$result = $stmt->get_result();
$children_medications = [];
while ($row = $result->fetch_assoc()) {
$children_medications[] = $row;
}
$stmt->close();
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
<?php require('includes/header.scripts.php'); ?>
</head>
<body>
<main class="main dashboard-main">
<?php require('includes/user_header.php'); ?>
<div class="main-content">
<div class="container">
<section class="section-flex-col">
<div class="d-flex align-items-center justify-content-between">
<h1 class="text-primary">Dashboard</h1>
</div>
<div>
<ul class="custom-grid-list">
<li class="custom-card">
<div class="d-flex align-items-center justify-content-between gap-3">
<div class="d-flex flex-column gap-2">
<span class="text-primary fw-bold">Total Children</span>
<span class="text-primary fw-bold fs-2"><?php echo $total_children; ?></span>
</div>
<img src="./assets/users-icon.svg" />
</div>
</li>
<li class="custom-card">
<div class="d-flex align-items-center justify-content-between gap-3">
<div class="d-flex flex-column gap-2">
<span class="text-primary fw-bold">Total Medication</span>
<span class="text-primary fw-bold fs-2"><?php echo $medication_data['total_medication']; ?></span>
</div>
<img src="./assets/pills-icon.svg" />
</div>
</li>
</ul>
</div>
</section>
<section class="section-flex-col mt-5">
<div class="d-flex align-items-center justify-content-between">
<h3 class="text-primary">Children</h3>
<a href="addNewChild.php" class="btn btn-primary">Add Child</a>
</div>
<div class="custom-card">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Child</th>
<th scope="col">Medication</th>
<th scope="col">Start date</th>
<th scope="col">End Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($children_medications as $index => $medication): ?>
<tr>
<td><?php echo $index + 1; ?></td>
<td><?php echo $medication['first_name'] . ' ' . $medication['last_name']; ?></td>
<td><?php echo $medication['medication_name']; ?></td>
<td><?php echo $medication['start_date']; ?></td>
<td><?php echo $medication['end_date']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</section>
</div>
</div>
<footer class="footer">
<div>
<p class="mb-0">© 2024 <span class="text-primary">Medication.</span> All rights reserved.</p>
</div>
</footer>
</main>
<?php require ('includes/footer.php'); ?>
</body>
</html>