1 ? implode(', ', array_slice($search_kinds, 0, -1)) . ' and ' . end($search_kinds) : (string) ($search_kinds[0] ?? 'nothing'); $sections = []; if ($q !== '') { $q_sql = escapeSql($q); $q_number = intval(preg_replace('/\D/', '', $q)); // Tickets - the subject, the number, or something said on it they can see; none while ticketing is switched off (Admin > Settings > Modules) if (moduleOn('ticketing')) { $where = portalTicketScopeSql() . " AND tickets.ticket_archived_at IS NULL AND (tickets.ticket_subject LIKE '%$q_sql%' OR CONCAT(tickets.ticket_prefix, tickets.ticket_number) LIKE '%$q_sql%'" . ($q_number ? " OR tickets.ticket_number = $q_number" : '') . " OR EXISTS (SELECT 1 FROM ticket_replies WHERE ticket_reply_ticket_id = tickets.ticket_id AND ticket_reply_type != 'Internal' AND ticket_reply_archived_at IS NULL AND ticket_reply LIKE '%$q_sql%'))"; $total = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM tickets WHERE $where"))[0]); $rows = []; if ($total) { $sql = mysqli_query($mysqli, "SELECT " . portalTicketColumnsSql() . " FROM tickets LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id WHERE $where ORDER BY " . TICKET_OPEN_SQL . " DESC, COALESCE(tickets.ticket_updated_at, tickets.ticket_created_at) DESC LIMIT $limit"); while ($row = mysqli_fetch_assoc($sql)) { $rows[] = $row; } } $sections['tickets'] = ['label' => 'Tickets', 'icon' => 'fa-life-ring', 'total' => $total, 'rows' => $rows, 'all' => 'tickets.php?' . http_build_query(['tab' => 'all', 'q' => $q])]; } // Documents shared with them - for those who see the company's IT if ($can_documents) { $where = "document_client_id = $session_client_id AND document_client_visible = 1 AND document_archived_at IS NULL AND (document_name LIKE '%$q_sql%' OR document_description LIKE '%$q_sql%' OR document_content_raw LIKE '%$q_sql%')"; $total = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM documents WHERE $where"))[0]); $rows = []; if ($total) { $sql = mysqli_query($mysqli, "SELECT document_id, document_name, document_description, document_created_at, document_updated_at, folder_name, (SELECT file_ext FROM document_files JOIN files ON files.file_id = document_files.file_id WHERE document_files.document_id = documents.document_id ORDER BY files.file_id LIMIT 1) AS file_ext FROM documents LEFT JOIN folders ON folder_id = document_folder_id AND folder_client_id = $session_client_id WHERE $where ORDER BY (document_name LIKE '%$q_sql%') DESC, COALESCE(document_updated_at, document_created_at) DESC LIMIT $limit"); while ($row = mysqli_fetch_assoc($sql)) { $rows[] = $row; } } $sections['documents'] = ['label' => 'Documents', 'icon' => 'fa-folder-open', 'total' => $total, 'rows' => $rows, 'all' => 'documents.php?' . http_build_query(['q' => $q])]; } // Help - the articles shared with them if ($can_help) { $where = kbClientSql($session_client_id) . " AND (kb_article_title LIKE '%$q_sql%' OR kb_article_summary LIKE '%$q_sql%' OR MATCH(kb_article_content_raw) AGAINST ('$q_sql'))"; $total = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM kb_articles WHERE $where"))[0]); $rows = []; if ($total) { $sql = mysqli_query($mysqli, "SELECT kb_article_id, kb_article_title, kb_article_summary, kb_article_content, kb_article_created_at, kb_article_updated_at, category_name, category_icon FROM kb_articles LEFT JOIN categories ON category_id = kb_article_category_id AND kb_article_category_id > 0 WHERE $where ORDER BY (kb_article_title LIKE '%$q_sql%') DESC, MATCH(kb_article_content_raw) AGAINST ('$q_sql') DESC, kb_article_title ASC LIMIT $limit"); while ($row = mysqli_fetch_assoc($sql)) { $rows[] = $row; } } elseif (!portalViewingAs()) { // Nothing in Help - on the Knowledge Base's Not found list, as a search in Help is kbSearchMissSave($q, 'portal', $session_client_id); } $sections['help'] = ['label' => 'Help', 'icon' => 'fa-book', 'total' => $total, 'rows' => $rows, 'all' => 'kb.php?' . http_build_query(['q' => $q])]; } } $found = array_sum(array_column($sections, 'total')); ?>
= $q === '' ? escapeHtml(ucfirst(moduleOn('ticketing') ? 'Your ' . $search_list : $search_list)) . (count($search_kinds) > 1 ? ', all at once' : '') : ($found ? $found . ' found for “' . escapeHtml($q) . '”' : 'Nothing found for “' . escapeHtml($q) . '”') ?>