Untitled
unknown
plain_text
2 years ago
7.7 kB
44
Indexable
<!DOCTYPE html>
<html>
<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" type="text/css" href="../styles/styles.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<title>RITS | Item data</title>
<style>
.content-container {
margin-left: 290px;
}
@media (max-width: 1000px) {
.content-container {
padding-left: 0;
margin: 0;
}
}
</style>
</head>
<body class="content-container">
<?php
include('../templates/_navbar.php');
include('../templates/sidebar.php');
include('../db/db_connection.php');
$itemsPerPage = 8;
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
$currentPage = intval($_GET['page']);
} else {
$currentPage = 1;
}
$offset = ($currentPage - 1) * $itemsPerPage;
if (isset($_GET['search'])) {
$search = $_GET['search'];
$search = str_replace("'", '', $search);
$strsql = "SELECT * FROM ViewItemDetails
WHERE control_number LIKE '%$search%'
OR item_serial LIKE '%$search%'
OR item_name LIKE '%$search%'
OR cat_name LIKE '%$search%'
OR item_Remarks LIKE'%$search%'
OR item_availability LIKE '$search%'
ORDER BY item_id OFFSET $offset ROWS FETCH NEXT $itemsPerPage ROWS ONLY";
} else {
$strsql = "SELECT * FROM ViewItemDetails ORDER BY item_id OFFSET $offset ROWS FETCH NEXT $itemsPerPage ROWS ONLY";
}
$query = sqlsrv_query($conn, $strsql);
if (sqlsrv_has_rows($query)) {
// Rows were found, so you can display the results
//while ($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) {
// Display the results here
//}
} else {
// No data found
$strsql = "SELECT * FROM ViewItemDetails ORDER BY item_id OFFSET $offset ROWS FETCH NEXT $itemsPerPage ROWS ONLY";
$query = sqlsrv_query($conn, $strsql);
}
if (!$query) {
die("Query failed: " . sqlsrv_errors());
}
$totalItemsQuery = sqlsrv_query($conn, "SELECT COUNT(*) as total FROM ViewItemDetails");
$totalItems = sqlsrv_fetch_array($totalItemsQuery, SQLSRV_FETCH_ASSOC)['total'];
$totalPages = ceil($totalItems / $itemsPerPage);
?>
<div>
<div style="margin-left: 20px; margin-right: 20px; display: flex; justify-content: space-between; align-items: center;">
<h4 href="#" style="width: 150px; margin: 0;">Items</h4>
<div class="right" style="display: flex; align-items: center;">
<form action="../pages/items.php" method="get" style="display: flex; align-items: center;">
<input type="text" name="search" id="searchBox" placeholder="Search..." style="width: 300px; margin-right: 10px;" oninput="validateInput(this);">
<button class="waves-effect green-text btn-flat" type="submit">
<i class="material-icons">search</i>
</button>
<button class="waves-effect green-text btn-flat" type="button" onclick="refreshPage()">
<i class="material-icons">refresh</i>
</button>
</form>
<a class="waves-effect green darken-4 btn-large" href="../pages/itemAdd.php" style="margin: 0;">Add Items</a>
</div>
</div>
<div class="row">
<div class="col s12">
<table class="striped highlight responsive-table">
<thead>
<tr>
<th>Item ID</th>
<th>Control #</th>
<th>Serial #</th>
<th>Item Name</th>
<th>Category</th>
<th>Remarks</th>
<th>Availability</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php while ($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) {
echo "<tr>";
echo "<td>" . $row['item_id'] . "</td>";
echo "<td>" . $row['control_number'] . "</td>";
echo "<td>" . $row['item_serial'] . "</td>";
echo "<td>" . $row['item_name'] . "</td>";
echo "<td>" . $row['cat_name'] . "</td>";
echo "<td>" . $row['item_Remarks'] . "</td>";
$statusAvailability = $row['item_availability'] === 'Not Available' ? 'red-text' : 'green-text';
echo "<td class='$statusAvailability'>" . $row['item_availability'] . "</td>";
if ($statusAvailability === 'Not Available') {
echo "<td class = right>
<a class='btn light-blue accent-4 waves-effect' href='ViewItemDetails.php?id=" . $row['control_number'] . "'>View Details</a>
</td>";
echo "</tr>";
} else {
echo "<td class = right>
<a class='btn waves-effect' href='../pages/itemEdit.php?id=" . $row['control_number'] . "'>Edit</a>
<a class='btn light-blue accent-4 waves-effect' href='../pages/ViewItemDetails.php?id=" . $row['control_number'] . "'>View Details</a>
</td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
<?php
sqlsrv_close($conn);
?>
</div>
</div>
<div class="row">
<ul class="pagination center">
<?php
if ($totalPages > 1) {
if ($currentPage > 1) {
echo "<li class='waves-effect'><a href='../pages/items.php?page=" . ($currentPage - 1) . "'><i class='material-icons'>chevron_left</i></a></li>";
}
for ($i = 1; $i <= $totalPages; $i++) {
$activeClass = ($i === $currentPage) ? 'active' : '';
echo "<li class='waves-effect $activeClass'><a href='../pages/items.php?page=$i'>$i</a></li>";
}
if ($currentPage < $totalPages) {
echo "<li class='waves-effect'><a href='../pages/items.php?page=" . ($currentPage + 1) . "'><i class='material-icons'>chevron_right</i></a></li>";
}
}
?>
</ul>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script>
function refreshPage() {
window.location.href = '../pages/items.php';
}
function validateInput(input) {
input.value = input.value.replace(/'/g, '');
}
</script>
</body>
<?php include('../templates/footer.php'); ?>
</html>Editor is loading...
Leave a Comment