summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-06-03 17:04:44 +0100
committerLester Caine <lester@lsces.co.uk>2026-06-03 17:04:44 +0100
commit687fe972b2bc693e15491aadb5a7c74e0f20ef85 (patch)
tree0c8747141fd1e56a0b0c4b64601a1b2abd9f254c /includes
parent4f3243d80abc15dbc5a22ffb03330e2290de1a4d (diff)
downloadstock-687fe972b2bc693e15491aadb5a7c74e0f20ef85.tar.gz
stock-687fe972b2bc693e15491aadb5a7c74e0f20ef85.tar.bz2
stock-687fe972b2bc693e15491aadb5a7c74e0f20ef85.zip
stock: add BOM component add page with autocomplete
- add_component.php: find component by title and store BOM xref; redirect to component_order.php on success, or edit_component.php (title pre-filled) if component not found - add_component.tpl: form with datalist autocomplete via lookup_component.php - includes/lookup_component.php: JSON endpoint for component title search - edit_component.php: pre-fill title from request for new components - view_xref_bom_group.tpl: add button now goes to add_component.php Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'includes')
-rw-r--r--includes/lookup_component.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/includes/lookup_component.php b/includes/lookup_component.php
new file mode 100644
index 0000000..18d47a6
--- /dev/null
+++ b/includes/lookup_component.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * JSON autocomplete endpoint — returns component titles matching ?q=
+ * Used by add_component.tpl datalist.
+ *
+ * @package stock
+ */
+
+namespace Bitweaver\Stock;
+
+require_once '../../kernel/includes/setup_inc.php';
+
+global $gBitDb, $gBitUser;
+
+if( !$gBitUser->hasPermission( 'p_stock_view' ) ) {
+ header( 'Content-Type: application/json' );
+ echo '[]';
+ exit;
+}
+
+$q = trim( $_GET['q'] ?? '' );
+if( strlen( $q ) < 2 ) {
+ header( 'Content-Type: application/json' );
+ echo '[]';
+ exit;
+}
+
+$rows = $gBitDb->getArray(
+ "SELECT FIRST 30 lc.content_id, lc.title
+ FROM liberty_content lc
+ WHERE lc.content_type_guid=? AND LOWER(lc.title) LIKE ?
+ ORDER BY lc.title",
+ [ 'stockcomponent', '%'.strtolower( $q ).'%' ]
+);
+
+header( 'Content-Type: application/json' );
+echo json_encode( array_values( $rows ?? [] ) );
+exit;