['label' => 'Open', 'icon' => 'fa-link', 'where' => shareOpenSql(), 'title' => 'Still work - not used up, expired or turned off'], 'received' => ['label' => 'Sent back', 'icon' => 'fa-inbox', 'where' => "item_type = 'Request' AND item_received_at IS NOT NULL AND item_ended_at IS NULL", 'title' => 'Logins clients sent back, waiting to be saved'], 'ended' => ['label' => 'Ended', 'icon' => 'fa-history', 'where' => 'NOT (' . shareLiveSql() . ')', 'title' => 'Used up, expired, turned off, locked - kept for ' . SHARE_KEEP_DAYS . ' days'], 'all' => ['label' => 'All', 'where' => '1'], ]; $show = isset($shows[$_GET['show'] ?? '']) ? ($_GET['show'] ?? '') : ''; $show_query = 'AND ' . $shows[$show]['where']; // Only these sort - filter_header.php will hand through any lowercase word $sortable_columns = ['item_created_at' => 'item_created_at', 'item_name' => 'item_name', 'item_recipient' => 'item_recipient', 'item_expire_at' => 'item_expire_at', 'item_last_viewed_at' => 'item_last_viewed_at', 'client_name' => 'client_name']; if (!isset($sortable_columns[$sort])) { $sort = 'item_created_at'; } $sort_sql = ($sort === 'item_last_viewed_at' ? 'item_last_viewed_at IS NULL, ' : '') . $sortable_columns[$sort] . " $order"; $search_query = "AND (item_name LIKE '%$q%' OR item_recipient LIKE '%$q%' OR item_note LIKE '%$q%' OR creator.user_name LIKE '%$q%' OR client_name LIKE '%$q%')"; $scope_query = clientScopeSql('item_client_id'); $visible_sql = "item_type IN (" . shareVisibleTypesSql() . ")"; $filters = "$visible_sql $type_query $search_query $scope_query $client_query"; $shares = shareRows("$filters $show_query", "$sort_sql, shared_items.item_id DESC", $user_config_records_per_page, $record_from); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); // How many of each, for the pills - everything in scope, before the pill itself $count_sql = []; foreach ($shows as $key => $s) { $count_sql[] = "COALESCE(SUM({$s['where']}), 0)"; } $row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . " FROM shared_items LEFT JOIN clients ON client_id = item_client_id LEFT JOIN users creator ON creator.user_id = item_created_by WHERE $filters")); $counts = []; foreach (array_keys($shows) as $i => $key) { $counts[$key] = intval($row[$i]); } $filter_url = function ($changes) { $params = array_merge($_GET, $changes); unset($params['page']); return '?' . http_build_query(array_filter($params, function ($v) { return $v !== '' && $v !== null; })); }; ?>