summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-06-03 22:08:00 +0100
committerLester Caine <lester@lsces.co.uk>2026-06-03 22:08:00 +0100
commit6a8891a1dc72640909c3f5b2003f208dd2174bfc (patch)
tree7bb701c2ace29b4ed693f78babcc5c4c83a3eeb3 /includes
parent6ec8b826af73b5a2abb41a11fcb28dc9b4283305 (diff)
downloadcontact-6a8891a1dc72640909c3f5b2003f208dd2174bfc.tar.gz
contact-6a8891a1dc72640909c3f5b2003f208dd2174bfc.tar.bz2
contact-6a8891a1dc72640909c3f5b2003f208dd2174bfc.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'includes')
-rw-r--r--includes/lookup_contact.php45
1 files changed, 45 insertions, 0 deletions
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 @@
+<?php
+/**
+ * JSON autocomplete endpoint — returns contacts matching ?q= by title or SCREF short name.
+ *
+ * @package contact
+ */
+
+namespace Bitweaver\Contact;
+
+require_once '../../kernel/includes/setup_inc.php';
+
+global $gBitDb, $gBitUser;
+
+if( !$gBitUser->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;