?>
 
<?php 
//Get user department to find the department request
$user = User::find_by_id($_SESSION['user_id']);
$department = $user->department;
if (empty($department)) {
    $message = "Department not found!";
    redirect_to('index.php');
}
// 1. the current page number ($current_page)
$page = !empty($_GET['page']) ? (int) $_GET['page'] : 1;
// 2. records per page ($per_page)
$per_page = 10;
// 3. total record count ($total_count)
$total_count = Request::department_requests_count_all($department);
//4. to limit pagination number
// 3 means abc[page]efg -> 3 right, 3 left
$stages = 2;
$pagination = new Pagination($page, $per_page, $total_count);
// Instead of finding all records, just find the records
// for this page
$sql = "SELECT * FROM requests ";
$sql .= "WHERE department = '{$department}' ";
$sql .= "LIMIT {$per_page} ";
$sql .= "OFFSET {$pagination->offset()} ";
$requests = Request::find_by_sql($sql);
if (empty($requests)) {
    $session->message("You have not submitted any requests yet.");
    redirect_to('index.php');
}