-
Notifications
You must be signed in to change notification settings - Fork 0
/
hc_dash.php
250 lines (212 loc) · 9.35 KB
/
hc_dash.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
<?php
/**
* Holding Cage Dashboard Script
*
* This script displays the holding cage dashboard for logged-in users. It includes functionalities such as
* adding new cages, printing cage cards, searching cages, and pagination. The page content is dynamically
* loaded using JavaScript and AJAX.
*
*/
// Start a new session or resume the existing session
session_start();
// Include the database connection file
require 'dbcon.php';
// Check if the user is not logged in, redirect them to index.php with the current URL for redirection after login
if (!isset($_SESSION['username'])) {
$currentUrl = urlencode($_SERVER['REQUEST_URI']);
header("Location: index.php?redirect=$currentUrl");
exit; // Exit to ensure no further code is executed
}
// Include the header file
require 'header.php';
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags for character encoding and responsive design -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FontAwesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<!-- Bootstrap for tooltips and styling -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script>
// Initialize tooltips when the document is ready
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
});
// Confirm deletion function with a dialog
function confirmDeletion(id) {
var confirmDelete = confirm("Are you sure you want to delete cage - '" + id + "' and related mouse data?");
if (confirmDelete) {
window.location.href = "hc_drop.php?id=" + id + "&confirm=true"; // Redirect to deletion script
}
}
// Fetch data function to load data dynamically
function fetchData(page = 1, search = '') {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'hc_fetch_data.php?page=' + page + '&search=' + encodeURIComponent(search), true);
xhr.onload = function() {
if (xhr.status === 200) {
try {
var response = JSON.parse(xhr.responseText);
if (response.tableRows && response.paginationLinks) {
document.getElementById('tableBody').innerHTML = response.tableRows; // Insert table rows
document.getElementById('paginationLinks').innerHTML = response.paginationLinks; // Insert pagination links
document.getElementById('searchInput').value = search; // Preserve search input
// Update the URL with the current page and search query
const newUrl = new URL(window.location.href);
newUrl.searchParams.set('page', page);
newUrl.searchParams.set('search', search);
window.history.replaceState({
path: newUrl.href
}, '', newUrl.href);
} else {
console.error('Invalid response format:', response);
}
} catch (e) {
console.error('Error parsing JSON response:', e);
}
} else {
console.error('Request failed. Status:', xhr.status);
}
};
xhr.onerror = function() {
console.error('Request failed. An error occurred during the transaction.');
};
xhr.send();
}
// Search function to initiate data fetch based on search query
function searchCages() {
var searchQuery = document.getElementById('searchInput').value;
fetchData(1, searchQuery);
}
// Fetch initial data when the DOM content is loaded
document.addEventListener('DOMContentLoaded', function() {
const urlParams = new URLSearchParams(window.location.search);
const page = urlParams.get('page') || 1;
const search = urlParams.get('search') || '';
fetchData(page, search);
});
</script>
<title>Dashboard Holding Cage | <?php echo htmlspecialchars($labName); ?></title>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
.container {
max-width: 800px;
background-color: #f8f9fa;
padding: 20px;
border-radius: 8px;
margin-top: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.table-wrapper {
margin-bottom: 50px;
overflow-x: auto;
}
.table-wrapper table {
width: 100%;
border-collapse: collapse;
}
.table-wrapper th,
.table-wrapper td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
.btn-sm {
margin-right: 5px;
}
.btn-icon {
width: 30px;
height: 30px;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0;
}
.btn-icon i {
font-size: 16px;
margin: 0;
}
.action-icons a {
margin-right: 10px;
margin-bottom: 10px;
}
.action-icons a:last-child {
margin-right: 0;
}
@media (max-width: 768px) {
.table-wrapper th,
.table-wrapper td {
padding: 12px 8px;
text-align: center;
}
}
</style>
</head>
<body>
<div class="container content mt-4">
<!-- Include message file for displaying messages -->
<?php include('message.php'); ?>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header d-flex flex-column flex-md-row justify-content-between align-items-center">
<h4>Holding Cage Dashboard</h4>
<div class="action-icons mt-3 mt-md-0">
<!-- Add new cage button with tooltip -->
<a href="hc_addn.php" class="btn btn-primary btn-icon" data-toggle="tooltip" data-placement="top" title="Add New Cage">
<i class="fas fa-plus"></i>
</a>
<!-- Print cage card button with tooltip -->
<a href="hc_slct_crd.php" class="btn btn-success btn-icon" data-toggle="tooltip" data-placement="top" title="Print Cage Card">
<i class="fas fa-print"></i>
</a>
<!-- Maintenance button with tooltip -->
<a href="maintenance.php?from=hc_dash" class="btn btn-warning btn-icon" data-toggle="tooltip" data-placement="top" title="Cage Maintenance">
<i class="fas fa-wrench"></i>
</a>
</div>
</div>
<div class="card-body">
<!-- Holding Cage Search Box -->
<div class="input-group mb-3">
<input type="text" id="searchInput" class="form-control" placeholder="Enter Cage ID" onkeyup="searchCages()"> <!-- Call search function on keyup -->
<button class="btn btn-primary" type="button" onclick="searchCages()">Search</button>
</div>
<div class="table-wrapper" id="tableContainer">
<table class="table table-bordered" id="mouseTable">
<thead>
<tr>
<th style="width: 50%;">Cage ID</th>
<th style="width: 50%;">Action</th>
</tr>
</thead>
<tbody id="tableBody">
<!-- Table rows will be inserted here by JavaScript -->
</tbody>
</table>
</div>
<!-- Pagination -->
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center" id="paginationLinks">
<!-- Pagination links will be inserted here by JavaScript -->
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer.php'; ?> <!-- Include footer file -->
<!-- Bootstrap and jQuery for tooltips -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>
</html>