diff --git a/database.sql b/database.sql index 5bf343f..c480b4c 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 192d5e2..32dbc82 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 9bfabdc..cd01883 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 = ''; @@ -9,19 +10,22 @@ class Product { private $info = array(); private $tags = array(); - public static function create_product($name = '', - $invoice = '', - $serial = '', - $info = array(), - $tags = array()) { + public static function create_product( + $brand, + $name, + $invoice, + $serial, + $info = array(), + $tags = array() + ) { $now = time(); 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) { @@ -70,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']; @@ -118,6 +123,7 @@ class Product { case 'status': $matchvalues[] = $this->get_status(); case 'fritext': + $matchvalues[] = $this->brand; $matchvalues[] = $this->name; $matchvalues[] = $this->serial; $matchvalues[] = $this->invoice; @@ -188,6 +194,18 @@ class Product { return new Service($result['id']); } + 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 065bdaa..04e48c8 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(), diff --git a/include/SearchPage.php b/include/SearchPage.php index 0536cdb..ac2748d 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; 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); }