['label' => 'To sign', 'icon' => 'fa-file-signature', 'where' => portalContractWaitingSql()], 'active' => ['label' => 'In force', 'icon' => 'fa-check-circle', 'where' => "contract_status = 'Active'"], 'all' => ['label' => 'All', 'icon' => 'fa-list', 'where' => '1 = 1'], ]; $q = trim((string) ($_GET['q'] ?? '')); $where = portalContractScopeSql(); if ($q !== '') { $q_sql = escapeSql($q); $where .= " AND contract_name LIKE '%$q_sql%'"; } $count_sql = []; foreach ($tabs as $key => $t) { $count_sql[] = "COALESCE(SUM({$t['where']}), 0) AS `$key`"; } $counts = array_map('intval', mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . " FROM contracts WHERE $where"))); // The tab with something to sign when there is one, else the ones in force, else all $tab = isset($tabs[$_GET['tab'] ?? '']) ? $_GET['tab'] : ($counts['waiting'] ? 'waiting' : ($counts['active'] ? 'active' : 'all')); $total = $counts[$tab]; $pages = max(1, (int) ceil($total / $per_page)); $page = min(max(1, intval($_GET['page'] ?? 1)), $pages); $offset = ($page - 1) * $per_page; $contracts = mysqli_query($mysqli, "SELECT * FROM contracts WHERE $where AND {$tabs[$tab]['where']} ORDER BY contract_status = 'Active' DESC, contract_end_date IS NULL, contract_end_date ASC, contract_name ASC LIMIT $per_page OFFSET $offset"); /** This page's address with some of its settings changed. */ function contractsUrl(array $changes) { global $tab, $q; $params = array_merge(['tab' => $tab, 'q' => $q !== '' ? $q : null], $changes); $params = array_filter($params, function ($v) { return $v !== null && $v !== ''; }); return 'contracts.php' . ($params ? '?' . http_build_query($params) : ''); } ?>

Contracts

'contracts', 'filtered' => true, 'match_text' => 'Nothing here has “' . escapeHtml($q) . '” in its name.', 'clear_url' => contractsUrl(['q' => null, 'page' => null])]) ?> 'Nothing to sign', 'text' => 'When we send you a contract to sign, it waits here.', 'icon' => 'fa-check', 'filtered' => false]) ?> 'No contracts here', 'text' => '', 'icon' => 'fa-file-contract', 'filtered' => false]) ?> 1) { ?>
- of