From c6831f3495cabc16fffce7d6fbb42e97cd69ac01 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Tue, 24 Jul 2012 15:51:01 +0200 Subject: [PATCH 01/16] Kosmeticka uprava po novinkach --- index.php | 2 +- locale/cs/messages.inc.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index cf90185..b90738f 100755 --- a/index.php +++ b/index.php @@ -267,7 +267,7 @@ EOF; if($count) $assistants[$item] = "assistant/$item"; } - $tables=array('item','model','category','producer','vendor','room','status','location'); + $tables=array('item','barcode','model','category','producer','vendor','room','status','location'); foreach($tables as $table) { $listable[$table] = $table; diff --git a/locale/cs/messages.inc.php b/locale/cs/messages.inc.php index f2a0b7b..26273f4 100644 --- a/locale/cs/messages.inc.php +++ b/locale/cs/messages.inc.php @@ -25,6 +25,9 @@ $LOCALE_MESSAGES = array( 'item_valid_till' => 'Položka platná do', 'item_valid_from' => 'Položka platná od', + 'barcode_name' => 'Čárový kód modelu', + 'barcode_name:' => 'Čárový kód modelu:', + 'model_image' => 'Obrázek', 'model_name' => 'Model', 'model_descript' => 'Popis modelu', @@ -67,6 +70,7 @@ $LOCALE_MESSAGES = array( 'item_quantity_to_buy' => 'Nakoupit minimálně', 'item' => '[položka]', + 'barcode' => '[čárový kód]', 'producer' => '[výrobce]', 'room' => '[sklad]', 'status' => '[stav]', -- 2.30.2 From 67360e5092c34ffeae0fa67624c8dafc743b381e Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Tue, 24 Jul 2012 16:20:27 +0200 Subject: [PATCH 02/16] Pridani nekolikanasobnych carovych kodu do vypisu modelu --- index.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index b90738f..b69500f 100755 --- a/index.php +++ b/index.php @@ -628,10 +628,16 @@ class Sklad_DB extends PDO { 'item' => array('barcode', 'model', 'category', 'producer', 'vendor', 'room', 'location', 'status'), 'model' => array('category', 'producer') ); //TODO Autodetect using foreign keys? + $join2 = array( + 'model' => array('barcode'=>'model_id') + ); $fields_search = array( 'item' => array('item_id','item_serial','model_name','barcode_name','model_barcode','model_descript','producer_name','vendor_name'), 'model' => array('model_id','model_name','barcode_name','model_barcode','model_descript','producer_name') ); //TODO Autodetect + $group_concat = array( + 'model' => array('barcode_name'=>'model_id') + ); //Init if(is_array($where)) foreach($where as $key => $value) $where[$key] = $key.' '.$value; //TODO: escape SQLi!!! @@ -639,10 +645,20 @@ class Sklad_DB extends PDO { //Escaping $class = $this->escape($class); + //GROUP_CONCAT + $group_concat_query = ''; + $group_by = ''; + if(isset($group_concat[$class])) foreach($group_concat[$class] as $gc => $gb) { + $group_concat_query .= ",group_concat($gc separator ', ')"; + $group_by .= "GROUP BY $gb\n"; + } + //SELECT - $sql="SELECT * FROM `$class`\n"; + $sql="SELECT *$group_concat_query FROM `$class`\n"; + //$sql="SELECT * FROM `$class`\n"; //JOIN if(isset($join[$class])) foreach($join[$class] as $j) $sql .= "LEFT JOIN `$j` USING($j$suffix_id)\n"; + if(isset($join2[$class])) foreach($join2[$class] as $j => $c) $sql .= "LEFT JOIN `$j` USING($c)\n"; //WHERE/REGEXP if($search) { $search = $this->quote($search); @@ -654,6 +670,10 @@ class Sklad_DB extends PDO { if(!$history && $this->contains_history($class)) $where[] = $class.'_valid_till=0'; if($where) $sql .= 'WHERE ('.implode(') AND (', $where).")\n"; + + //GROUP BY + $sql.=$group_by; + //ORDER if(!$order) $order = $class.$suffix_id.' DESC'; if($this->contains_history($class)) $order .= ",${class}_valid_from DESC"; -- 2.30.2 From 4d4ca2918fbfe23f3bbe9901057783a68a7c77e9 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Wed, 25 Jul 2012 22:46:02 +0200 Subject: [PATCH 03/16] Schovan bordel z vypisu --- index.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.php b/index.php index b69500f..2bcad25 100755 --- a/index.php +++ b/index.php @@ -457,6 +457,8 @@ EOF; function table_hide_columns(&$table, $class) { //TODO: Move to build_query_select() !!! :-))) $fields_hide = array( + 'model' => array('model_barcode','barcode_name'), + 'barcode' => array('model_barcode'), 'item' => array('model_descript','model_price_in','model_price_out','barcode_name','model_barcode','model_countable','model_reserve','model_eshop_hide','room_descript','room_author','producer_name','producer_note','vendor_note','location_author','location_gps','location_description') ); //print_r($table); die(); -- 2.30.2 From dda9984c1ca739cae5d0a7d1ecbfc1da6795bfa9 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Wed, 25 Jul 2012 23:20:30 +0200 Subject: [PATCH 04/16] Trochu vic user-friendly prace se sloucenymi carovymi kody --- index.php | 18 ++++++++++++------ locale/cs/messages.inc.php | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index 2bcad25..b40fc88 100755 --- a/index.php +++ b/index.php @@ -357,10 +357,11 @@ EOF; function table_add_relations(&$table, $class, $suffix_relations='_relations') { $where_url = '%d/?where[%c]==%v'; + $insert_url = '%d/new?insert[%c]=%v'; $relations = array( //TODO: Autodetect??? //TODO: Add [edit] link to all classes 'model' => array( - 'model_id' => array(array('item',$where_url),array('edit','model/%v/edit/')), - 'model_barcode' => array(array('store','assistant/%d?barcode=%v')), + 'model_id' => array(array('item',$where_url),array('barcode',$where_url),array('edit','model/%v/edit/'),array('barcode',$insert_url)), + //'model_barcode' => array(array('store','assistant/%d?barcode=%v')), 'barcode_name' => array(array('store','assistant/%d?barcode=%v')), 'model_name' => array(array('google','http://google.com/search?q=%v')) //TODO: add manufacturer to google query ), @@ -458,7 +459,7 @@ EOF; function table_hide_columns(&$table, $class) { //TODO: Move to build_query_select() !!! :-))) $fields_hide = array( 'model' => array('model_barcode','barcode_name'), - 'barcode' => array('model_barcode'), + 'barcode' => array('model_barcode','model_price_in','model_price_out','model_reserve','producer_name','producer_note','model_eshop_hide','category_name','model_countable','model_descript'), 'item' => array('model_descript','model_price_in','model_price_out','barcode_name','model_barcode','model_countable','model_reserve','model_eshop_hide','room_descript','room_author','producer_name','producer_note','vendor_note','location_author','location_gps','location_description') ); //print_r($table); die(); @@ -560,9 +561,14 @@ EOF; //echo('
'); print_r($selectbox);
 		//echo('
'); print_r($current);
 		$update = false;
+		$current_new=array();
 		if(is_array($current)) {
 			$update = true;
-			$current = array_shift($current);
+			$current_new = array_merge($current_new,array_shift($current));
+		}
+		if(isset($_GET['insert']) && is_array($_GET['insert'])) {
+			$update = true;
+			$current_new = array_merge($current_new,$_GET['insert']);
 		}
 
 		if(!is_array($hidecols)) $hidecols = array();
@@ -575,7 +581,7 @@ EOF;
 		}
 
 		if(!is_array($parts) || in_array('inputs', $parts))
-			$html.=$this->render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update);
+			$html.=$this->render_insert_inputs($class,$columns,$selectbox,$current_new,$hidecols,$update);
 
 		if(!is_array($parts) || in_array('foot', $parts)) {
 			$html .= '
'; @@ -591,7 +597,7 @@ EOF; EOF; } - $btn = is_array($current) ? 'UPDATE' : 'INSERT'; //TODO: $current may be set even when inserting... + $btn = count($current_new)>0 ? 'UPDATE' : 'INSERT'; //TODO: $current may be set even when inserting... $html.=$this->input(false, $btn, 'submit'); $html.=''; } diff --git a/locale/cs/messages.inc.php b/locale/cs/messages.inc.php index 26273f4..a6241b4 100644 --- a/locale/cs/messages.inc.php +++ b/locale/cs/messages.inc.php @@ -70,7 +70,7 @@ $LOCALE_MESSAGES = array( 'item_quantity_to_buy' => 'Nakoupit minimálně', 'item' => '[položka]', - 'barcode' => '[čárový kód]', + 'barcode' => '[čárový kód]', 'producer' => '[výrobce]', 'room' => '[sklad]', 'status' => '[stav]', -- 2.30.2 From 7661315fc5e169b250fb080552d18050040d9108 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Wed, 25 Jul 2012 23:41:34 +0200 Subject: [PATCH 05/16] Oprava nekterych veci rozbitych pri prechodu na novy system carovych kodu --- assistants/stats/reserve.inc.php | 12 +++++------- assistants/stats/stock.inc.php | 2 +- index.php | 6 +++--- install.sql | 8 +++----- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/assistants/stats/reserve.inc.php b/assistants/stats/reserve.inc.php index b60ec2d..d8e92db 100644 --- a/assistants/stats/reserve.inc.php +++ b/assistants/stats/reserve.inc.php @@ -1,14 +1,12 @@ 'SELECT model_id,model_name,model_barcode,model_reserve,model_reserve as item_quantity_to_buy'. - ' FROM model'. + "Nakoupit: DoÅ¡lo úplně (Urgent WishList)" + => 'SELECT model_id,model_name,barcode_name,model_reserve,model_reserve as item_quantity_to_buy'. + ' FROM model LEFT JOIN barcode USING(model_id)'. ' WHERE model_reserve>0 AND NOT EXISTS'. - ' (SELECT item_id FROM item WHERE model.model_id=item.model_id AND status_id=1 AND item_quantity>0 AND item_valid_till=0)', -*/ + ' (SELECT item_id FROM item WHERE barcode.barcode_id=item.barcode_id AND status_id=1 AND item_quantity>0 AND item_valid_till=0)', "Nakoupit: Dochází (WishList)" - => 'SELECT model_id,model_name,model_barcode,model_reserve,'. + => 'SELECT model_id,model_name,barcode_name,model_reserve,'. ' COUNT(item_id),SUM(item_quantity),model_reserve-SUM(item_quantity) as item_quantity_to_buy'. ' FROM item LEFT JOIN barcode USING(barcode_id) LEFT JOIN model USING(model_id)'. ' WHERE item_valid_till=0 AND status_id=1'. diff --git a/assistants/stats/stock.inc.php b/assistants/stats/stock.inc.php index 1cec846..82eb2bc 100644 --- a/assistants/stats/stock.inc.php +++ b/assistants/stats/stock.inc.php @@ -1,7 +1,7 @@ 'SELECT room_id,room_name,model_id,model_name,model_barcode,model_price_out,COUNT(item_id),SUM(item_quantity)'. + => 'SELECT room_id,room_name,model_id,model_name,barcode_name,model_price_out,COUNT(item_id),SUM(item_quantity)'. ' FROM item LEFT JOIN barcode USING(barcode_id) LEFT JOIN model USING(model_id) LEFT JOIN room USING(room_id)'. ' WHERE item_valid_till=0 AND status_id=1'. ' GROUP BY model_id,room_id'. diff --git a/index.php b/index.php index b40fc88..ced77fb 100755 --- a/index.php +++ b/index.php @@ -361,7 +361,7 @@ EOF; $relations = array( //TODO: Autodetect??? //TODO: Add [edit] link to all classes 'model' => array( 'model_id' => array(array('item',$where_url),array('barcode',$where_url),array('edit','model/%v/edit/'),array('barcode',$insert_url)), - //'model_barcode' => array(array('store','assistant/%d?barcode=%v')), + 'model_barcode' => array(array('store','assistant/%d?barcode=%v')), 'barcode_name' => array(array('store','assistant/%d?barcode=%v')), 'model_name' => array(array('google','http://google.com/search?q=%v')) //TODO: add manufacturer to google query ), @@ -458,8 +458,8 @@ EOF; function table_hide_columns(&$table, $class) { //TODO: Move to build_query_select() !!! :-))) $fields_hide = array( - 'model' => array('model_barcode','barcode_name'), - 'barcode' => array('model_barcode','model_price_in','model_price_out','model_reserve','producer_name','producer_note','model_eshop_hide','category_name','model_countable','model_descript'), + 'model' => array('barcode_name'), + 'barcode' => array('model_price_in','model_price_out','model_reserve','producer_name','producer_note','model_eshop_hide','category_name','model_countable','model_descript'), 'item' => array('model_descript','model_price_in','model_price_out','barcode_name','model_barcode','model_countable','model_reserve','model_eshop_hide','room_descript','room_author','producer_name','producer_note','vendor_note','location_author','location_gps','location_description') ); //print_r($table); die(); diff --git a/install.sql b/install.sql index c69ac1a..aedb948 100644 --- a/install.sql +++ b/install.sql @@ -230,7 +230,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2012-07-24 15:47:56 +-- Dump completed on 2012-07-25 23:41:18 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -273,7 +273,7 @@ CREATE TABLE `item` ( CONSTRAINT `item_ibfk_6` FOREIGN KEY (`vendor_id`) REFERENCES `vendor` (`vendor_id`), CONSTRAINT `item_ibfk_8` FOREIGN KEY (`status_id`) REFERENCES `status` (`status_id`), CONSTRAINT `item_ibfk_9` FOREIGN KEY (`room_id`) REFERENCES `room` (`room_id`) -) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci; +) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci; /*!40101 SET character_set_client = @saved_cs_client */; DROP TABLE IF EXISTS `model`; /*!40101 SET @saved_cs_client = @@character_set_client */; @@ -283,7 +283,6 @@ CREATE TABLE `model` ( `model_name` varchar(64) COLLATE utf8_czech_ci NOT NULL, `producer_id` int(11) NOT NULL DEFAULT '0', `category_id` int(11) NOT NULL DEFAULT '0', - `model_barcode` varchar(128) COLLATE utf8_czech_ci NOT NULL, `model_countable` int(1) NOT NULL DEFAULT '1', `model_price_in` decimal(9,2) DEFAULT NULL, `model_price_out` decimal(9,2) DEFAULT NULL, @@ -291,7 +290,6 @@ CREATE TABLE `model` ( `model_eshop_hide` int(1) unsigned NOT NULL DEFAULT '0', `model_descript` varchar(1024) COLLATE utf8_czech_ci NOT NULL, PRIMARY KEY (`model_id`), - UNIQUE KEY `model_barcode` (`model_barcode`), KEY `category_id` (`category_id`), KEY `producer_id` (`producer_id`), CONSTRAINT `model_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `category` (`category_id`), @@ -308,7 +306,7 @@ CREATE TABLE `barcode` ( PRIMARY KEY (`barcode_id`), KEY `model_id` (`model_id`), CONSTRAINT `barcode_ibfk_1` FOREIGN KEY (`model_id`) REFERENCES `model` (`model_id`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci; +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; -- 2.30.2 From 113c586b885aeaf164dba3c421057c7ad3544ceb Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Wed, 25 Jul 2012 23:45:38 +0200 Subject: [PATCH 06/16] Ucesani zahlavi tabulky --- locale/cs/messages.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/cs/messages.inc.php b/locale/cs/messages.inc.php index a6241b4..4fb5173 100644 --- a/locale/cs/messages.inc.php +++ b/locale/cs/messages.inc.php @@ -134,7 +134,7 @@ $LOCALE_MESSAGES = array( 'Something \(i guess it was ([^ ]*)\) is gone. :\'-\(' => 'Neco (pravdepodobne \1) bylo asi smazano. Fnuk :\'-(', 'Somebody do not want you to upload pictures for ([^ ]*) class' => 'Nekdo nechce k DB Tride \'\1\' prirazovat obrazky!', 'Can\'t search in ([^ ]*) table yet :-\(' => 'Ve tride \1 zatim vyhledavat nemozno :-(', - '' => '', + " separator '.*'" => '', '' => '', '' => '', 'hello\((.*)\)' => 'Ahoj(\1)' -- 2.30.2 From a9516ef763e4ef55ddc8c0d5418f2be6a5e20fc6 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Wed, 25 Jul 2012 23:51:24 +0200 Subject: [PATCH 07/16] Oprava statistiky --- assistants/stats/reserve.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assistants/stats/reserve.inc.php b/assistants/stats/reserve.inc.php index d8e92db..f161fa4 100644 --- a/assistants/stats/reserve.inc.php +++ b/assistants/stats/reserve.inc.php @@ -1,10 +1,10 @@ 'SELECT model_id,model_name,barcode_name,model_reserve,model_reserve as item_quantity_to_buy'. - ' FROM model LEFT JOIN barcode USING(model_id)'. + => 'SELECT model_id,model_name,model_reserve,model_reserve as item_quantity_to_buy'. + ' FROM model'. ' WHERE model_reserve>0 AND NOT EXISTS'. - ' (SELECT item_id FROM item WHERE barcode.barcode_id=item.barcode_id AND status_id=1 AND item_quantity>0 AND item_valid_till=0)', + ' (SELECT item_id FROM item LEFT JOIN barcode USING(barcode_id) WHERE barcode.model_id=model.model_id AND status_id=1 AND item_quantity>0 AND item_valid_till=0)', "Nakoupit: Dochází (WishList)" => 'SELECT model_id,model_name,barcode_name,model_reserve,'. ' COUNT(item_id),SUM(item_quantity),model_reserve-SUM(item_quantity) as item_quantity_to_buy'. -- 2.30.2 From 1fb6317fc48de7e2324f51a280ea9e97b9cf3ed8 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Wed, 25 Jul 2012 23:54:49 +0200 Subject: [PATCH 08/16] Po zmenach v DB se umoudrilo ORDER BY --- index.php | 3 +-- install.sql | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index ced77fb..7467bbf 100755 --- a/index.php +++ b/index.php @@ -663,7 +663,6 @@ class Sklad_DB extends PDO { //SELECT $sql="SELECT *$group_concat_query FROM `$class`\n"; - //$sql="SELECT * FROM `$class`\n"; //JOIN if(isset($join[$class])) foreach($join[$class] as $j) $sql .= "LEFT JOIN `$j` USING($j$suffix_id)\n"; if(isset($join2[$class])) foreach($join2[$class] as $j => $c) $sql .= "LEFT JOIN `$j` USING($c)\n"; @@ -685,7 +684,7 @@ class Sklad_DB extends PDO { //ORDER if(!$order) $order = $class.$suffix_id.' DESC'; if($this->contains_history($class)) $order .= ",${class}_valid_from DESC"; - //$sql .= "ORDER BY $order\n"; //TODO: fixnout az budou opraveny vicenasobny carovy kody + $sql .= "ORDER BY $order\n"; //LIMIT/OFFSET if($limit) { $limit = $this->escape((int)$limit); diff --git a/install.sql b/install.sql index aedb948..7ac736c 100644 --- a/install.sql +++ b/install.sql @@ -230,7 +230,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2012-07-25 23:41:18 +-- Dump completed on 2012-07-25 23:54:42 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -- 2.30.2 From 2aa69d71f2e8f1055d0e40af3f917eba75e84906 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Thu, 26 Jul 2012 00:11:04 +0200 Subject: [PATCH 09/16] =?utf8?q?Vylep=C5=A1en=C3=AD=20podprahov=C3=A9ho=20?= =?utf8?q?=C5=A1kolen=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- locale/cs/fortunes.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/locale/cs/fortunes.txt b/locale/cs/fortunes.txt index fbb5ebb..e939a76 100644 --- a/locale/cs/fortunes.txt +++ b/locale/cs/fortunes.txt @@ -18,6 +18,10 @@ Středověk trvá Čárové kódy i sériová čísla musí být jedinečná! Položky jsou skutečné věci skladem. Modely jsou "typ" věcí (jen virtuální) a skladem nemusí být. +Každý MODEL může mít několik ČÁROVÝCH KÓDÅ® +Každý ČÁROVÝ KÓD může mít několik POLOŽEK +Každá POLOŽKA má buď sériové číslo nebo množství (počet kusů, metráž,...), podle toho, o jaký se jedná MODEL. +Každý MODEL může mít několik ČÁROVÝCH KÓDÅ® z nichž každý může mít několik POLOŽEK podle sériových čísel nebo na množství. Při naskladňování nezapomeň vyplnit dodavatele a sklad na který zboží půjde. Pokud si něco bereÅ¡ ze skladu, tak to vyskladni. Nevyskladňuj něco, co nemáš v ruce. -- 2.30.2 From 37595945b02d6e45cfe1d524245a983615383944 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Sun, 29 Jul 2012 01:28:32 +0200 Subject: [PATCH 10/16] GUI pro locky --- assistants/lock.inc.php | 33 +++++++++++++++++++++++++++++++++ index.php | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 assistants/lock.inc.php diff --git a/assistants/lock.inc.php b/assistants/lock.inc.php new file mode 100644 index 0000000..c042ee9 --- /dev/null +++ b/assistants/lock.inc.php @@ -0,0 +1,33 @@ +db->safe_query_fetch("SELECT * FROM `lock`;"); + if(empty($result)) { + echo 'Not locked...'; + $user=$this->db->auth->get_user_id(); + $username=$this->db->auth->get_username_by_id($user); + echo $this->html->form("$URL/2", 'POST', array( + array('reason',$username,'textarea',false,'autofocus','reason:'), + array('lock','lock','submit') + )); + } else { + echo $this->html->render_item_table($result); + echo $this->html->form("$URL/2", 'POST', array( + array('unlock','unlock','submit') + )); + } + + break; + case 2: + if(isset($_POST['lock'])) { + $lock = $this->db->quote($_POST['reason']); + $this->db->safe_query("INSERT INTO `lock` (lock_name) VALUES ($lock);"); + $this->post_redirect_get("$URL_INTERNAL/1", T('Lock set')); + } + if(isset($_POST['unlock'])) { + $this->db->safe_query("TRUNCATE TABLE `lock`;"); + $this->post_redirect_get("$URL_INTERNAL/1", T('Lock unset')); + } + $this->post_redirect_get("$URL_INTERNAL/1","Lock: No value passed!", true); + break; +} diff --git a/index.php b/index.php index 7467bbf..439ffae 100755 --- a/index.php +++ b/index.php @@ -743,7 +743,7 @@ class Sklad_DB extends PDO { function get_columns($class,$disable_cols=array()) { //TODO: Not sure if compatible with non-MySQL DBs $class = $this->escape($class); - $sql = "SHOW COLUMNS FROM $class;"; + $sql = "SHOW COLUMNS FROM `$class`;"; $columns = $this->safe_query_fetch($sql); /*foreach($columns as $colk => $col) foreach($col as $key => $val) { if(in_array($col['Field'],$disable_cols)) $columns[$colk]['Extra']='auto_increment'; -- 2.30.2 From cd65d0c40fb1b5f385079fe028d377a5b9b80562 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Sun, 29 Jul 2012 01:35:35 +0200 Subject: [PATCH 11/16] Zamky sice zatim nic nezamykaji, ale ukazuji varovani nahore v zahlavi --- index.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 439ffae..3200b84 100755 --- a/index.php +++ b/index.php @@ -185,7 +185,7 @@ class HTML { * @author Tomas Mudrunka */ class Sklad_HTML extends HTML { //TODO: Split into few more methods - function header($title='', $user=array()) { + function header($title='', $user=array(), $headerhtml) { $home = URL_HOME; $script = $_SERVER['SCRIPT_NAME']; $search = htmlspecialchars(@trim($_GET['q'])); @@ -308,7 +308,7 @@ EOF;
- $message + $headerhtml $message
$fortune @@ -1096,8 +1096,11 @@ class Sklad_UI { $PATH_CHUNKS = preg_split('/\//', $PATH_INFO); //Sephirot: if(!isset($PATH_CHUNKS[1])) $PATH_CHUNKS[1]=''; - if($_SERVER['REQUEST_METHOD'] != 'POST' && $PATH_CHUNKS[1]!='barcodeimg' && $PATH_CHUNKS[1]!='api') //TODO: tyhle podminky naznacujou, ze je v navrhu nejaka drobna nedomyslenost... - echo $this->html->header($PATH_INFO,$this->db->auth->get_user()); + if($_SERVER['REQUEST_METHOD'] != 'POST' && $PATH_CHUNKS[1]!='barcodeimg' && $PATH_CHUNKS[1]!='api') { //TODO: tyhle podminky naznacujou, ze je v navrhu nejaka drobna nedomyslenost... + $result = $this->db->safe_query_fetch("SELECT * FROM `lock`;"); + $headerhtml = !empty($result) ? T('There are locks:').' '.$this->html->render_item_table($result) : ''; + echo $this->html->header($PATH_INFO,$this->db->auth->get_user(),$headerhtml); + } switch($PATH_CHUNKS[1]) { //TODO: Move some branches to plugins if possible case 'test': //test die('Tell me why you cry'); -- 2.30.2 From 7f1203c4b619b9ece292aa38fbf0d264c1291de7 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Sun, 29 Jul 2012 01:38:51 +0200 Subject: [PATCH 12/16] Vylepseni zamku --- assistants/lock.inc.php | 2 +- index.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/assistants/lock.inc.php b/assistants/lock.inc.php index c042ee9..b943864 100644 --- a/assistants/lock.inc.php +++ b/assistants/lock.inc.php @@ -7,7 +7,7 @@ switch($SUBPATH[0]) { $user=$this->db->auth->get_user_id(); $username=$this->db->auth->get_username_by_id($user); echo $this->html->form("$URL/2", 'POST', array( - array('reason',$username,'textarea',false,'autofocus','reason:'), + array('reason',"$username: ",'textarea',false,'autofocus','reason:'), array('lock','lock','submit') )); } else { diff --git a/index.php b/index.php index 3200b84..3c078e9 100755 --- a/index.php +++ b/index.php @@ -421,6 +421,7 @@ EOF; 'status_id' => 'status_name', 'item_author' => 'item_author_backend', 'item_customer' => 'item_customer', + 'lock_id' => 'lock_name', ); foreach($table as $id => $row) { -- 2.30.2 From 98f4d4120541dd9e7b9026a993afcdf055d93217 Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Sun, 29 Jul 2012 01:47:08 +0200 Subject: [PATCH 13/16] Fix indentace --- index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 3c078e9..d4c3cb3 100755 --- a/index.php +++ b/index.php @@ -1098,8 +1098,8 @@ class Sklad_UI { //Sephirot: if(!isset($PATH_CHUNKS[1])) $PATH_CHUNKS[1]=''; if($_SERVER['REQUEST_METHOD'] != 'POST' && $PATH_CHUNKS[1]!='barcodeimg' && $PATH_CHUNKS[1]!='api') { //TODO: tyhle podminky naznacujou, ze je v navrhu nejaka drobna nedomyslenost... - $result = $this->db->safe_query_fetch("SELECT * FROM `lock`;"); - $headerhtml = !empty($result) ? T('There are locks:').' '.$this->html->render_item_table($result) : ''; + $result = $this->db->safe_query_fetch("SELECT * FROM `lock`;"); + $headerhtml = !empty($result) ? T('There are locks:').' '.$this->html->render_item_table($result) : ''; echo $this->html->header($PATH_INFO,$this->db->auth->get_user(),$headerhtml); } switch($PATH_CHUNKS[1]) { //TODO: Move some branches to plugins if possible -- 2.30.2 From 539ab3c14dbbc9f63623eab416033856574c348b Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Sun, 29 Jul 2012 02:00:53 +0200 Subject: [PATCH 14/16] Zamky uz umoznuji zamknout POST akce --- index.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.php b/index.php index d4c3cb3..94d8002 100755 --- a/index.php +++ b/index.php @@ -1019,6 +1019,14 @@ class Sklad_UI { return true; } + function check_locks() { + $result = $this->db->safe_query_fetch("SELECT * FROM `lock`;"); + if(!empty($result)) { + echo T('There are locks:').' '.$this->html->render_item_table($result); + $this->post_redirect_get('', 'There are locks!', true); + } + } + function process_http_request_post($action=false, $class=false, $id=false, $force_redirect=false) { if($_SERVER['REQUEST_METHOD'] != 'POST') return; //echo('
'); //DEBUG (maybe todo remove), HEADERS ALREADY SENT!!!!
@@ -1030,6 +1038,7 @@ class Sklad_UI {
 		 * do:	$values[$table][$id][$column]
 		 */
 		if(isset($_POST['values'])) {
+			$this->check_locks();
 			$values=array();
 			foreach($_POST['values'] as $table => $columns) {
 				foreach($columns as $column => $ids) {
@@ -1050,6 +1059,7 @@ class Sklad_UI {
 			case 'new':
 				$replace = false;
 			case 'edit':
+				$this->check_locks();
 				if(!isset($replace)) $replace = true;
 				$table = $class ? $class : 'item';
 				//print_r($values); //debug
@@ -1060,6 +1070,7 @@ class Sklad_UI {
 				$this->post_redirect_get($last, $message);
 				break;
 			case 'delete':
+				$this->check_locks();
 				if(!isset($_POST['sure']) || !$_POST['sure']) $this->post_redirect_get("$class/$id/edit", 'Sure user expected :-)');
 				$this->db->delete($class, $id) || $this->post_redirect_get("$class/$id/edit", "V tabulce $class jentak neco mazat nebudes chlapecku :-P");
 				$this->post_redirect_get("$class", "Neco (pravdepodobne /$class/$id) bylo asi smazano. Fnuk :'-(");
-- 
2.30.2


From cdc31e71314eea7d9955b15bbb5cc0dc205d57d0 Mon Sep 17 00:00:00 2001
From: Thomas Mudrunka 
Date: Sun, 29 Jul 2012 14:24:14 +0200
Subject: [PATCH 15/16] SQL databaze s podporou locku

---
 dump_sql.php |  2 +-
 install.sql  | 13 +++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/dump_sql.php b/dump_sql.php
index d0346f6..5a68437 100755
--- a/dump_sql.php
+++ b/dump_sql.php
@@ -1,7 +1,7 @@
 #!/usr/bin/php
 
Date: Sun, 29 Jul 2012 21:03:06 +0200
Subject: [PATCH 16/16] Lepsi escapovani v migratoru

---
 assistants/migrations.inc.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/assistants/migrations.inc.php b/assistants/migrations.inc.php
index c00b8e3..dd7b436 100644
--- a/assistants/migrations.inc.php
+++ b/assistants/migrations.inc.php
@@ -1,13 +1,13 @@
 
 

-- populate barcode table

db->safe_query_fetch('SELECT model_id as id, model_barcode as bar FROM model;'); +$data = $this->db->safe_query_fetch('SELECT model_id as id, model_barcode as bar FROM model;', false); //print_r($data); echo("UPDATE item SET barcode_id=model_id;\n"); echo("INSERT INTO barcode (barcode_id,model_id,barcode_name) VALUES\n"); -foreach($data as $line) echo("('".$line['id']."','".$line['id']."','".$line['bar']."'),\n"); +foreach($data as $line) echo("('".$line['id']."','".$line['id']."',".$this->db->quote($line['bar'])."),\n"); ?>

-- populate columns item_date_bought and item_date_sold

db->safe_query_fetch('SELECT item_id,MIN(item_valid_from) AS min,MAX(item_valid_from) AS max FROM item GROUP BY item_id;'); +$data = $this->db->safe_query_fetch('SELECT item_id,MIN(item_valid_from) AS min,MAX(item_valid_from) AS max FROM item GROUP BY item_id;', false); //print_r($data); echo("START TRANSACTION;\n"); foreach($data as $line) echo("UPDATE item SET item_date_bought='".$line['min']."',item_date_sold='".$line['max']."' WHERE item_id=".$line['item_id'].";\n"); -- 2.30.2