mvp.8
This commit is contained in:
parent
c1f814ac1a
commit
c6e4994eb6
47
index.php
47
index.php
@ -2,26 +2,54 @@
|
|||||||
require_once 'db/config.php';
|
require_once 'db/config.php';
|
||||||
|
|
||||||
// Fetch all processes from the database
|
// Fetch all processes from the database
|
||||||
|
// Pagination settings
|
||||||
|
$items_per_page = 5;
|
||||||
|
$current_page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||||
|
$offset = ($current_page - 1) * $items_per_page;
|
||||||
|
|
||||||
$processes = [];
|
$processes = [];
|
||||||
$search_query = $_GET['search'] ?? '';
|
$search_query = $_GET['search'] ?? '';
|
||||||
|
$total_processes = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
|
|
||||||
|
// First, get the total number of processes (with search filter if applied)
|
||||||
|
$count_sql = "SELECT COUNT(*) FROM processes";
|
||||||
|
if (!empty($search_query)) {
|
||||||
|
$count_sql .= " WHERE name LIKE :search_query OR description LIKE :search_query";
|
||||||
|
}
|
||||||
|
$count_stmt = $pdo->prepare($count_sql);
|
||||||
|
if (!empty($search_query)) {
|
||||||
|
$count_stmt->bindValue(':search_query', '%' . $search_query . '%', PDO::PARAM_STR);
|
||||||
|
}
|
||||||
|
$count_stmt->execute();
|
||||||
|
$total_processes = $count_stmt->fetchColumn();
|
||||||
|
|
||||||
|
// Then, fetch the processes for the current page (with search filter and pagination)
|
||||||
$sql = "SELECT id, name, description, created_at FROM processes";
|
$sql = "SELECT id, name, description, created_at FROM processes";
|
||||||
if (!empty($search_query)) {
|
if (!empty($search_query)) {
|
||||||
$sql .= " WHERE name LIKE :search_query OR description LIKE :search_query";
|
$sql .= " WHERE name LIKE :search_query OR description LIKE :search_query";
|
||||||
}
|
}
|
||||||
$sql .= " ORDER BY created_at DESC";
|
$sql .= " ORDER BY created_at DESC LIMIT :limit OFFSET :offset";
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
|
|
||||||
if (!empty($search_query)) {
|
if (!empty($search_query)) {
|
||||||
$stmt->bindValue(':search_query', '%' . $search_query . '%', PDO::PARAM_STR);
|
$stmt->bindValue(':search_query', '%' . $search_query . '%', PDO::PARAM_STR);
|
||||||
}
|
}
|
||||||
|
$stmt->bindValue(':limit', $items_per_page, PDO::PARAM_INT);
|
||||||
|
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$processes = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$processes = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
// Silently log error, or display a friendly message.
|
// Silently log error, or display a friendly message.
|
||||||
error_log("DB Error: " . $e->getMessage());
|
error_log("DB Error: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$total_pages = ceil($total_processes / $items_per_page);
|
||||||
|
|
||||||
|
|
||||||
$project_name = htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'ProcessFlow Optimizer');
|
$project_name = htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'ProcessFlow Optimizer');
|
||||||
$project_description = htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'Analyze and optimize your business processes.');
|
$project_description = htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'Analyze and optimize your business processes.');
|
||||||
$project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');
|
$project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');
|
||||||
@ -176,6 +204,23 @@ $project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '');
|
|||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
|
<?php if ($total_pages > 1): ?>
|
||||||
|
<nav aria-label="Page navigation">
|
||||||
|
<ul class="pagination justify-content-center mt-4">
|
||||||
|
<li class="page-item <?php echo ($current_page <= 1) ? 'disabled' : ''; ?>">
|
||||||
|
<a class="page-link" href="?page=<?php echo $current_page - 1; ?><?php echo (!empty($search_query) ? '&search=' . urlencode($search_query) : ''); ?>" tabindex="-1" aria-disabled="true">Previous</a>
|
||||||
|
</li>
|
||||||
|
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
|
||||||
|
<li class="page-item <?php echo ($current_page == $i) ? 'active' : ''; ?>">
|
||||||
|
<a class="page-link" href="?page=<?php echo $i; ?><?php echo (!empty($search_query) ? '&search=' . urlencode($search_query) : ''); ?>"><?php echo $i; ?></a>
|
||||||
|
</li>
|
||||||
|
<?php endfor; ?>
|
||||||
|
<li class="page-item <?php echo ($current_page >= $total_pages) ? 'disabled' : ''; ?>">
|
||||||
|
<a class="page-link" href="?page=<?php echo $current_page + 1; ?><?php echo (!empty($search_query) ? '&search=' . urlencode($search_query) : ''); ?>">Next</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user