diff --git a/global_search.php b/global_search.php index 9cba6465..d947462d 100644 --- a/global_search.php +++ b/global_search.php @@ -13,19 +13,71 @@ if (isset($_GET['query'])) { $ticket_num_query = str_replace("$config_ticket_prefix", "", "$query"); - $sql_clients = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN locations ON clients.client_id = locations.location_client_id AND location_primary = 1 WHERE client_name LIKE '%$query%' ORDER BY client_id DESC LIMIT 5"); - $sql_contacts = mysqli_query($mysqli, "SELECT * FROM contacts LEFT JOIN clients ON client_id = contact_client_id WHERE (contact_name LIKE '%$query%' OR contact_title LIKE '%$query%' OR contact_email LIKE '%$query%' OR contact_phone LIKE '%$phone_query%' OR contact_mobile LIKE '%$phone_query%') ORDER BY contact_id DESC LIMIT 5"); - $sql_vendors = mysqli_query($mysqli, "SELECT * FROM vendors WHERE (vendor_name LIKE '%$query%' OR vendor_phone LIKE '%$phone_query%') ORDER BY vendor_id DESC LIMIT 5"); - $sql_products = mysqli_query($mysqli, "SELECT * FROM products WHERE product_name LIKE '%$query%' ORDER BY product_id DESC LIMIT 5"); - $sql_documents = mysqli_query($mysqli, "SELECT * FROM documents LEFT JOIN clients on document_client_id = clients.client_id WHERE MATCH(document_content_raw) AGAINST ('$query') ORDER BY document_id DESC LIMIT 5"); - $sql_tickets = mysqli_query($mysqli, "SELECT * FROM tickets LEFT JOIN clients on tickets.ticket_client_id = clients.client_id WHERE (ticket_subject LIKE '%$query%' OR ticket_number = '$ticket_num_query') ORDER BY ticket_id DESC LIMIT 5"); - $sql_logins = mysqli_query($mysqli, "SELECT * FROM logins WHERE (login_name LIKE '%$query%' OR login_description LIKE '%$query%') ORDER BY login_id DESC LIMIT 5"); + $sql_clients = mysqli_query($mysqli, "SELECT * FROM clients + LEFT JOIN locations ON clients.client_id = locations.location_client_id AND location_primary = 1 + WHERE client_archived_at IS NULL + AND client_name LIKE '%$query%' + ORDER BY client_id DESC LIMIT 5" + ); + + $sql_contacts = mysqli_query($mysqli, "SELECT * FROM contacts + LEFT JOIN clients ON client_id = contact_client_id + WHERE contact_archived_at IS NULL + AND (contact_name LIKE '%$query%' + OR contact_title LIKE '%$query%' + OR contact_email LIKE '%$query%' + OR contact_phone LIKE '%$phone_query%' + OR contact_mobile LIKE '%$phone_query%') + ORDER BY contact_id DESC LIMIT 5" + ); + + $sql_vendors = mysqli_query($mysqli, "SELECT * FROM vendors + LEFT JOIN clients ON vendor_client_id = client_id + WHERE vendor_archived_at IS NULL + AND vendor_template = 0 + AND (vendor_name LIKE '%$query%' OR vendor_phone LIKE '%$phone_query%') + ORDER BY vendor_id DESC LIMIT 5" + ); + + $sql_products = mysqli_query($mysqli, "SELECT * FROM products + WHERE product_archived_at IS NULL + AND product_name LIKE '%$query%' + ORDER BY product_id DESC LIMIT 5" + ); + + $sql_documents = mysqli_query($mysqli, "SELECT * FROM documents + LEFT JOIN clients on document_client_id = clients.client_id + WHERE document_archived_at IS NULL + AND MATCH(document_content_raw) AGAINST ('$query') + ORDER BY document_id DESC LIMIT 5" + ); + + $sql_tickets = mysqli_query($mysqli, "SELECT * FROM tickets + LEFT JOIN clients on tickets.ticket_client_id = clients.client_id + WHERE ticket_archived_at IS NULL + AND (ticket_subject LIKE '%$query%' + OR ticket_number = '$ticket_num_query') + ORDER BY ticket_id DESC LIMIT 5" + ); + + $sql_logins = mysqli_query($mysqli, "SELECT * FROM logins + LEFT JOIN contacts ON login_contact_id = contact_id + LEFT JOIN clients ON login_client_id = client_id + WHERE login_archived_at IS NULL + AND (login_name LIKE '%$query%' OR login_description LIKE '%$query%') + ORDER BY login_id DESC LIMIT 5" + ); - $sql_invoices = mysqli_query($mysqli, "SELECT * FROM invoices LEFT JOIN clients ON invoice_client_id = client_id LEFT JOIN categories ON invoice_category_id = category_id - WHERE (CONCAT(invoice_prefix,invoice_number) LIKE '%$query%' OR invoice_scope LIKE '%$query%') ORDER BY invoice_number DESC LIMIT 5"); + $sql_invoices = mysqli_query($mysqli, "SELECT * FROM invoices + LEFT JOIN clients ON invoice_client_id = client_id + LEFT JOIN categories ON invoice_category_id = category_id + WHERE invoice_archived_at IS NULL + AND (CONCAT(invoice_prefix,invoice_number) LIKE '%$query%' OR invoice_scope LIKE '%$query%') + ORDER BY invoice_number DESC LIMIT 5" + ); - $sql_assets = mysqli_query($mysqli,"SELECT * FROM assets - LEFT JOIN contacts ON asset_contact_id = contact_id + $sql_assets = mysqli_query($mysqli,"SELECT * FROM assets + LEFT JOIN contacts ON asset_contact_id = contact_id LEFT JOIN locations ON asset_location_id = location_id LEFT JOIN clients ON asset_client_id = client_id WHERE asset_archived_at IS NULL @@ -34,6 +86,7 @@ if (isset($_GET['query'])) { ); $q = nullable_htmlentities($_GET['query']); + ?>