Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix fake barcode number handling, use library code for parsing item q…

…ueries
  • Loading branch information...
commit f8d80c3770a0a7e7024b662477b6184361d07ff0 1 parent ca608ba
@jimwins authored
Showing with 12 additions and 15 deletions.
  1. +10 −13 items.php
  2. +2 −2 lib/item.php
View
23 items.php
@@ -1,5 +1,6 @@
<?
require 'scat.php';
+require 'lib/item.php';
head("search");
@@ -45,18 +46,14 @@ function (data) {
if (!$q) exit;
-$terms= preg_split('/\s+/', $q);
-$criteria= array();
-foreach ($terms as $term) {
- $term= $db->real_escape_string($term);
- if (preg_match('/^code:(.+)/i', $term, $dbt)) {
- $criteria[]= "(item.code LIKE '{$dbt[1]}%')";
- } else {
- $criteria[]= "(item.name LIKE '%$term%'
- OR brand.name LIKE '%$term%'
- OR item.code LIKE '%$term%'
- OR barcode.code LIKE '%$term%')";
- }
+$begin= false;
+
+$options= 0;
+if ($_REQUEST['all'])
+ $options|= FIND_ALL;
+
+list($sql_criteria, $begin) = item_terms_to_sql($db, $q, $options);
+
}
# XXX allow option to include inactive and/or deleted
if (!$_REQUEST['all'])
@@ -85,7 +82,7 @@ function (data) {
FROM item
LEFT JOIN brand ON (item.brand = brand.id)
LEFT JOIN barcode ON (item.id = barcode.item)
- WHERE " . join(' AND ', $criteria) . "
+ WHERE $sql_criteria
GROUP BY item.id
ORDER BY 2";
View
4 lib/item.php
@@ -15,9 +15,9 @@ function item_terms_to_sql($db, $q, $options) {
if (preg_match('/^code:(.+)/i', $term, $dbt)) {
$andor[]= "(item.code LIKE '{$dbt[1]}%')";
} elseif (preg_match('/^400400(\d+)\d$/i', $term, $dbt)) {
- $andor[]= "(item.id = '{$dbt[1]}%')";
+ $andor[]= "(item.id = '{$dbt[1]}')";
} elseif (preg_match('/^item:(.+)/i', $term, $dbt)) {
- $andor[]= "(item.id = '{$dbt[1]}%')";
+ $andor[]= "(item.id = '{$dbt[1]}')";
} elseif (preg_match('/^begin:([-0-9]+)/i', $term, $dbt)) {
$begin= $dbt[1];
} elseif (preg_match('/^-(.+)/i', $term, $dbt)) {
Please sign in to comment.
Something went wrong with that request. Please try again.