From 8654206c72eadd637bfbf079022d0a450db558b9 Mon Sep 17 00:00:00 2001 From: Erik Thuning <boooink@gmail.com> Date: Tue, 16 Jul 2019 14:45:58 +0200 Subject: [PATCH 1/3] Added the ability to search for presence of fields --- include/functions.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/functions.php b/include/functions.php index f82ba69..cf979db 100644 --- a/include/functions.php +++ b/include/functions.php @@ -219,6 +219,10 @@ function suggest($type) { } function match($testvalues, $matchvalues) { + # match only presence of field (if no value given) + if(!$testvalues && $matchvalues) { + return true; + } if(!is_array($testvalues)) { $testvalues = array($testvalues); } From 720551af8d570cbde33214e267e3c79d3564ef06 Mon Sep 17 00:00:00 2001 From: Erik Thuning <boooink@gmail.com> Date: Tue, 16 Jul 2019 14:47:44 +0200 Subject: [PATCH 2/3] Changed products to always have a manufacturer field --- database.sql | 1 + html/fragments.html | 10 ++++++++++ include/Product.php | 28 ++++++++++++++++++++++------ include/ProductPage.php | 1 + 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/database.sql b/database.sql index 3d5f035..7531a4f 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,7 @@ create table `product` ( `id` bigint(20) not null auto_increment, primary key(`id`), + `brand` varchar(64) not null, `name` varchar(64) not null, `invoice` varchar(64) not null, `serial` varchar(64) not null, diff --git a/html/fragments.html b/html/fragments.html index d97a63f..593d0d4 100644 --- a/html/fragments.html +++ b/html/fragments.html @@ -180,6 +180,16 @@ value="¤name¤" /> </td> </tr> + <tr> + <td> + Tillverkare: + </td> + <td> + <input type="text" + name="brand" + value="¤brand¤" /> + </td> + </tr> <tr> <td> Fakturanummer: diff --git a/include/Product.php b/include/Product.php index 0b8a806..c48b7c7 100644 --- a/include/Product.php +++ b/include/Product.php @@ -1,6 +1,7 @@ <?php class Product { private $id = 0; + private $brand = ''; private $name = ''; private $invoice = ''; private $serial = ''; @@ -10,9 +11,10 @@ class Product { private $tags = array(); public static function create_product( - $name = '', - $invoice = '', - $serial = '', + $brand, + $name, + $invoice, + $serial, $info = array(), $tags = array() ) { @@ -20,10 +22,10 @@ class Product { begin_trans(); try { $stmt = 'insert into - `product`(`name`, `invoice`, `serial`, `createtime`) - values (?, ?, ?, ?)'; + `product`(`brand`, `name`, `invoice`, `serial`, `createtime`) + values (?, ?, ?, ?, ?)'; $ins_prod = prepare($stmt); - bind($ins_prod, 'sssi', $name, $invoice, $serial, $now); + bind($ins_prod, 'ssssi', $brand, $name, $invoice, $serial, $now); execute($ins_prod); $product = new Product($serial, 'serial'); foreach($info as $field => $value) { @@ -72,6 +74,7 @@ class Product { bind($get, 'i', $this->id); execute($get); $product = result_single($get); + $this->brand = $product['brand']; $this->name = $product['name']; $this->invoice = $product['invoice']; $this->serial = $product['serial']; @@ -120,6 +123,7 @@ class Product { case 'status': $matchvalues[] = $this->get_loan_status(); case 'fritext': + $matchvalues[] = $this->brand; $matchvalues[] = $this->name; $matchvalues[] = $this->serial; $matchvalues[] = $this->invoice; @@ -160,6 +164,18 @@ class Product { return true; } + public function get_brand() { + return $this->brand; + } + + public function set_brand($newbrand) { + $update = prepare('update `product` set `brand`=? where `id`=?'); + bind($update, 'si', $newbrand, $this->id); + execute($update); + $this->brand = $newbrand; + return true; + } + public function get_name() { return $this->name; } diff --git a/include/ProductPage.php b/include/ProductPage.php index e9d23fe..1c6dccb 100644 --- a/include/ProductPage.php +++ b/include/ProductPage.php @@ -74,6 +74,7 @@ class ProductPage extends Page { $this->fragments['tag']); } $fields = array('id' => $this->product->get_id(), + 'brand' => $this->product->get_brand(), 'name' => $this->product->get_name(), 'serial' => $this->product->get_serial(), 'invoice' => $this->product->get_invoice(), From 59395ad31122a696a8218f0542e0b9b6ab1c1d07 Mon Sep 17 00:00:00 2001 From: Erik Thuning <boooink@gmail.com> Date: Tue, 16 Jul 2019 14:48:27 +0200 Subject: [PATCH 3/3] Added support for searching for brands and fixed a bug where the query was presented in translated form to the user --- include/SearchPage.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/SearchPage.php b/include/SearchPage.php index 49d6970..b765a57 100644 --- a/include/SearchPage.php +++ b/include/SearchPage.php @@ -8,7 +8,7 @@ class SearchPage extends Page { if(isset($_GET['q']) && !$_GET['q']) { unset($_GET['q']); } - $this->terms = $this->translate_keys($_GET); + $this->terms = $_GET; } private function do_search() { @@ -17,7 +17,7 @@ class SearchPage extends Page { return $out; } foreach(array('user', 'product') as $type) { - $result = $this->search($type, $this->terms); + $result = $this->search($type, $this->translate_keys($this->terms)); if($result) { $out[$type] = $result; } @@ -33,6 +33,10 @@ class SearchPage extends Page { case 'q': $newkey = 'fritext'; break; + case 'tillverkare': + case 'märke': + $newkey = 'brand'; + break; case 'namn': $newkey = 'name'; break;