From 6a8891a1dc72640909c3f5b2003f208dd2174bfc Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Wed, 3 Jun 2026 22:08:00 +0100 Subject: contact: add lookup_contact.php JSON autocomplete endpoint Searches contacts by title or SCREF short name. Used by stock edit_movement.tpl From field datalist. Co-Authored-By: Claude Sonnet 4.6 --- includes/lookup_contact.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 includes/lookup_contact.php diff --git a/includes/lookup_contact.php b/includes/lookup_contact.php new file mode 100644 index 0000000..1be1658 --- /dev/null +++ b/includes/lookup_contact.php @@ -0,0 +1,45 @@ +hasPermission( 'p_contact_view' ) ) { + header( 'Content-Type: application/json' ); + echo '[]'; + exit; +} + +$q = trim( $_GET['q'] ?? '' ); +if( strlen( $q ) < 2 ) { + header( 'Content-Type: application/json' ); + echo '[]'; + exit; +} + +$like = '%'.strtolower( $q ).'%'; + +$rows = $gBitDb->getArray( + "SELECT FIRST 30 lc.content_id, lc.title, + (SELECT FIRST 1 sx.data FROM ".BIT_DB_PREFIX."liberty_xref sx + WHERE sx.content_id=lc.content_id AND sx.item='SCREF') AS scref + FROM ".BIT_DB_PREFIX."liberty_content lc + WHERE lc.content_type_guid='contact' + AND (LOWER(lc.title) LIKE ? OR EXISTS ( + SELECT 1 FROM ".BIT_DB_PREFIX."liberty_xref sx + WHERE sx.content_id=lc.content_id AND sx.item='SCREF' AND LOWER(sx.data) LIKE ? + )) + ORDER BY lc.title", + [ $like, $like ] +); + +header( 'Content-Type: application/json' ); +echo json_encode( array_values( $rows ?? [] ) ); +exit; -- cgit v1.3