# HG changeset patch # User Michiel Broek # Date 1537621363 -7200 # Node ID dbbe408108ea22493e3fe056caa360110ee9abdc # Parent ad28e09e3abd3e2d64538b4bd77c40b9125fcd70 Added miscs inline editor. Switched to http POST because of GET limitations. diff -r ad28e09e3abd -r dbbe408108ea www/getmiscsources.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/getmiscsources.php Sat Sep 22 15:02:43 2018 +0200 @@ -0,0 +1,23 @@ + $row['record'], + 'name' => $row['name'], + 'type' => $row['type'], + 'use_use' => $row['use_use'], + 'time' => $row['time'], + 'amount_is_weight' => $row['amount_is_weight'], + 'inventory' => $row['inventory'], + 'cost' => $row['cost'] + ); +} +echo json_encode($miscs); diff -r ad28e09e3abd -r dbbe408108ea www/import/from_brouwhulp.php --- a/www/import/from_brouwhulp.php Fri Sep 21 17:10:41 2018 +0200 +++ b/www/import/from_brouwhulp.php Sat Sep 22 15:02:43 2018 +0200 @@ -612,6 +612,13 @@ $hops .= ',"h_myrcene":' . floatval($hop->MYRCENE); if ($hop->TOTAL_OIL) $hops .= ',"h_total_oil":' . floatval($hop->TOTAL_OIL); + else + $hops .= ',"h_total_oil":0'; + if ($hop->ORIGIN) + $hops .= ',"h_origin":"' . mysqli_real_escape_string($db, $hop->ORIGIN) . '"'; + else + $hops .= ',"h_origin":""'; + $hops .= "}"; } @@ -636,11 +643,15 @@ $miscs .= ',"m_amount":' . floatval($misc->AMOUNT); if ($misc->COST) $miscs .= ',"m_cost":' . floatval($misc->COST); + else + $miscs .= ',"m_cost":0'; $miscs .= ',"m_type":"' . mysqli_real_escape_string($db, $misc->TYPE) . '"'; - $miscs .= ',"m_use":"' . mysqli_real_escape_string($db, $misc->USE) . '"'; + $miscs .= ',"m_use_use":"' . mysqli_real_escape_string($db, $misc->USE) . '"'; ($misc->AMOUNT_IS_WEIGHT== "TRUE") ? $miscs .= ',"m_amount_is_weight":true' : $miscs.= ',"m_amount_is_weight":false'; if ($misc->TIME) $miscs .= ',"m_time":' . floatval($misc->TIME); + else + $miscs .= ',"m_time":0'; $miscs .= "}"; } diff -r ad28e09e3abd -r dbbe408108ea www/includes/db_recipes.php --- a/www/includes/db_recipes.php Fri Sep 21 17:10:41 2018 +0200 +++ b/www/includes/db_recipes.php Sat Sep 22 15:02:43 2018 +0200 @@ -2,9 +2,6 @@ require($_SERVER['DOCUMENT_ROOT']."/config.php"); require($_SERVER['DOCUMENT_ROOT']."/version.php"); -//require("../config.php"); -//require("../version.php"); - #Connect to the database $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); @@ -18,87 +15,141 @@ // get data and store in a json array $query = "SELECT * FROM recipes ORDER BY st_guide,st_letter,st_name,name"; -if (isset($_GET['insert']) || isset($_GET['update'])) { - if (isset($_GET['insert'])) { +if (isset($_POST['insert']) || isset($_POST['update'])) { + if (isset($_POST['insert'])) { // INSERT COMMAND - $sql = "INSERT INTO `recipes` SET st_name='" . mysqli_real_escape_string($connect, $_GET['st_name']); + $sql = "INSERT INTO `recipes` SET "; + } + if (isset($_POST['update'])) { + // UPDATE COMMAND + $sql = "UPDATE `recipes` SET "; } - if (isset($_GET['update'])) { - // UPDATE COMMAND - $sql = "UPDATE `recipes` SET st_name='" . mysqli_real_escape_string($connect, $_GET['st_name']); + // Basic settings + $sql .= "st_name='" . mysqli_real_escape_string($connect, $_POST['st_name']); + $sql .= "', st_letter='" . mysqli_real_escape_string($connect, $_POST['st_letter']); + $sql .= "', st_guide='" . mysqli_real_escape_string($connect, $_POST['st_guide']); + $sql .= "', st_og_min='" . $_POST['st_og_min']; + $sql .= "', st_og_max='" . $_POST['st_og_max']; + $sql .= "', st_fg_min='" . $_POST['st_fg_min']; + $sql .= "', st_fg_max='" . $_POST['st_fg_max']; + $sql .= "', st_ibu_min='" . $_POST['st_ibu_min']; + $sql .= "', st_ibu_max='" . $_POST['st_ibu_max']; + $sql .= "', st_color_min='" . $_POST['st_color_min']; + $sql .= "', st_color_max='" . $_POST['st_color_max']; + $sql .= "', st_carb_min='" . $_POST['st_carb_min']; + $sql .= "', st_carb_max='" . $_POST['st_carb_max']; + $sql .= "', st_abv_min='" . $_POST['st_abv_min']; + $sql .= "', st_abv_max='" . $_POST['st_abv_max']; + $sql .= "', name='" . mysqli_real_escape_string($connect, $_POST['name']); + $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']); + $sql .= "', type='" . $_POST['type']; + $sql .= "', batch_size='" . $_POST['batch_size']; + $sql .= "', boil_time='" . $_POST['boil_time']; + $sql .= "', efficiency='" . $_POST['efficiency']; + $sql .= "', est_og='" . $_POST['est_og']; + $sql .= "', est_fg='" . $_POST['est_fg']; + $sql .= "', est_color='" . $_POST['est_color']; + $sql .= "', color_method='" . $_POST['color_method']; + $sql .= "', est_ibu='" . $_POST['est_ibu']; + $sql .= "', ibu_method='" . $_POST['ibu_method']; + $sql .= "', mash_sparge_temp='" . $_POST['mash_sparge_temp']; + $sql .= "', mash_ph='" . $_POST['mash_ph']; + $sql .= "', mash_name='" . $_POST['mash_name']; + syslog(LOG_NOTICE, $sql); + + if (isset($_POST['fermentables'])) { + $array = $_POST['fermentables']; + foreach($array as $key => $item){ + foreach ($disallowed as $disallowed_key) { + unset($array[$key]["$disallowed_key"]); + } + } + syslog(LOG_NOTICE, "json_fermentables=: ".json_encode($array)); + $sql .= "', json_fermentables='" . json_encode($array); } - $sql .= "', st_letter='" . mysqli_real_escape_string($connect, $_GET['st_letter']); - $sql .= "', st_guide='" . mysqli_real_escape_string($connect, $_GET['st_guide']); - $sql .= "', st_og_min='" . $_GET['st_og_min']; - $sql .= "', st_og_max='" . $_GET['st_og_max']; - $sql .= "', st_fg_min='" . $_GET['st_fg_min']; - $sql .= "', st_fg_max='" . $_GET['st_fg_max']; - $sql .= "', st_ibu_min='" . $_GET['st_ibu_min']; - $sql .= "', st_ibu_max='" . $_GET['st_ibu_max']; - $sql .= "', st_color_min='" . $_GET['st_color_min']; - $sql .= "', st_color_max='" . $_GET['st_color_max']; - $sql .= "', st_carb_min='" . $_GET['st_carb_min']; - $sql .= "', st_carb_max='" . $_GET['st_carb_max']; - $sql .= "', st_abv_min='" . $_GET['st_abv_min']; - $sql .= "', st_abv_max='" . $_GET['st_abv_max']; - $sql .= "', name='" . mysqli_real_escape_string($connect, $_GET['name']); - $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); - $sql .= "', type='" . $_GET['type']; - $sql .= "', batch_size='" . $_GET['batch_size']; - $sql .= "', boil_time='" . $_GET['boil_time']; - $sql .= "', efficiency='" . $_GET['efficiency']; - $sql .= "', est_og='" . $_GET['est_og']; - $sql .= "', est_fg='" . $_GET['est_fg']; - $sql .= "', est_color='" . $_GET['est_color']; - $sql .= "', color_method='" . $_GET['color_method']; - $sql .= "', est_ibu='" . $_GET['est_ibu']; - $sql .= "', ibu_method='" . $_GET['ibu_method']; - $sql .= "', mash_sparge_temp='" . $_GET['mash_sparge_temp']; - $sql .= "', mash_ph='" . $_GET['mash_ph']; - $sql .= "', mash_name='" . $_GET['mash_name']; + + if (isset($_POST['hops'])) { + $array = $_POST['hops']; + foreach($array as $key => $item){ + foreach ($disallowed as $disallowed_key) { + unset($array[$key]["$disallowed_key"]); + } + } + syslog(LOG_NOTICE, "json_hops: ".json_encode($array)); + $sql .= "', json_hops='" . json_encode($array); + } + + if (isset($_POST['miscs'])) { + $array = $_POST['miscs']; + foreach($array as $key => $item){ + foreach ($disallowed as $disallowed_key) { + unset($array[$key]["$disallowed_key"]); + } + } + syslog(LOG_NOTICE, "json_miscs: ".json_encode($array)); + $sql .= "', json_miscs='" . json_encode($array); + } - syslog(LOG_NOTICE, $sql); // Log upto this part. - - $array = $_GET['fermentables']; - foreach($array as $key => $item){ - foreach ($disallowed as $disallowed_key) { - unset($array[$key]["$disallowed_key"]); + if (isset($_POST['yeasts'])) { + $array = $_POST['yeasts']; + foreach($array as $key => $item){ + foreach ($disallowed as $disallowed_key) { + unset($array[$key]["$disallowed_key"]); + } } + syslog(LOG_NOTICE, "json_yeasts: ".json_encode($array)); + $sql .= "', json_yeasts='" . json_encode($array); } - syslog(LOG_NOTICE, "json_fermentables: " . json_encode($array)); - $sql .= "', json_fermentables='" . json_encode($array); - $array = $_GET['waters']; - foreach($array as $key => $item){ - foreach ($disallowed as $disallowed_key) { - unset($array[$key]["$disallowed_key"]); + if (isset($_POST['waters'])) { + $array = $_POST['waters']; + foreach($array as $key => $item){ + foreach ($disallowed as $disallowed_key) { + unset($array[$key]["$disallowed_key"]); + } } + syslog(LOG_NOTICE, "json_waters: ".json_encode($array)); + $sql .= "', json_waters='" . json_encode($array); } - syslog(LOG_NOTICE, "json_waters: " . json_encode($array)); - $sql .= "', json_waters='" . json_encode($array); - if (isset($_GET['insert'])) { + if (isset($_POST['mashs'])) { + $array = $_POST['mashs']; + foreach($array as $key => $item){ + foreach ($disallowed as $disallowed_key) { + unset($array[$key]["$disallowed_key"]); + } + } + syslog(LOG_NOTICE, "json_mashs: ".json_encode($array)); + $sql .= "', json_mashs='" . json_encode($array); + } + + if (isset($_POST['insert'])) { $sql .= "';"; } - if (isset($_GET['update'])) { - $sql .= "' WHERE record='" . $_GET['record'] . "';"; + if (isset($_POST['update'])) { + $sql .= "' WHERE record='" . $_POST['record'] . "';"; } -// $result = mysqli_query($connect, $sql); -// if (! $result) { -// syslog(LOG_NOTICE, "db_recipes: ".$sql." result: ".mysqli_error($connect)); -// } else { -// syslog(LOG_NOTICE, "db_recipes: inserted ".$_GET['name']); -// } -// echo $result; -} else if (isset($_GET['delete'])) { - // DELETE COMMAND - $sql = "DELETE FROM `recipes` WHERE record='".$_GET['record']."';"; $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_recipes: ".$sql." result: ".mysqli_error($connect)); } else { - syslog(LOG_NOTICE, "db_recipes: deleted record ".$_GET['record']); + if (isset($_POST['update'])) { + syslog(LOG_NOTICE, "db_recipes: updated record ".$_POST['record']); + } else { + syslog(LOG_NOTICE, "db_recipes: inserted ".$_POST['name']); + } + } + echo $result; + +} else if (isset($_POST['delete'])) { + // DELETE COMMAND + $sql = "DELETE FROM `recipes` WHERE record='".$_POST['record']."';"; + $result = mysqli_query($connect, $sql); + if (! $result) { + syslog(LOG_NOTICE, "db_recipes: ".$sql." result: ".mysqli_error($connect)); + } else { + syslog(LOG_NOTICE, "db_recipes: deleted record ".$_POST['record']); } echo $result; diff -r ad28e09e3abd -r dbbe408108ea www/js/recipes.js --- a/www/js/recipes.js Fri Sep 21 17:10:41 2018 +0200 +++ b/www/js/recipes.js Sat Sep 22 15:02:43 2018 +0200 @@ -102,6 +102,7 @@ url: url, cache: false, data: data, + type: "POST", success: function (data, status, xhr) { // delete command is executed. commit(true); @@ -118,6 +119,7 @@ url: url, cache: false, data: data, + type: "POST", success: function (data, status, xhr) { commit(true); }, @@ -133,6 +135,7 @@ url: url, cache: false, data: data, + type: "POST", success: function (data, status, xhr) { // update command is executed. commit(true); @@ -471,8 +474,125 @@ }) }; + // Inline miscs editor + var editMisc = function (data) { + var miscSource = { + localdata: data.miscs, + datatype: "local", + cache: false, + datafields: [ + { name: 'm_name', type: 'string' }, + { name: 'm_amount', type: 'float' }, + { name: 'm_cost', type: 'float' }, + { name: 'm_type', type: 'string' }, + { name: 'm_use_use', type: 'string' }, + { name: 'm_time', type: 'float' }, + { name: 'm_amount_is_weight', type: 'bool' } + ], + addrow: function (rowid, rowdata, position, commit) { + commit(true); + }, + deleterow: function (rowid, commit) { + commit(true); + } + }; + var miscAdapter = new $.jqx.dataAdapter(miscSource); + // dropdownlist datasource from inventory_miscs + var miscUrl = "getmiscsources.php"; + var miscInvSource = { + datatype: "json", + datafields: [ + { name: 'record', type: 'number' }, + { name: 'name', type: 'string' }, + { name: 'type', type: 'string' }, + { name: 'use_use', type: 'string' }, + { name: 'amount_is_weight', type: 'bool' }, + { name: 'time', type: 'float' }, + { name: 'cost', type: 'float' } + ], + url: miscUrl, + async: true + }; + var misclist = new $.jqx.dataAdapter(miscInvSource); - // Inline miscs editor + $("#miscGrid").jqxGrid({ + width: 960, + height: 400, + source: miscAdapter, + theme: theme, + selectionmode: 'singlerow', + editmode: 'selectedrow', + editable: true, + localization: getLocalization(), + showtoolbar: true, + rendertoolbar: function (toolbar) { + var me = this; + var container = $("
"); + toolbar.append(container); + container.append('
'); + container.append(''); + // add misc from dropdownlist. + $("#maddrowbutton").jqxDropDownList({ + placeHolder: "Kies ingredient:", + theme: theme, + source: misclist, + displayMember: "name", + width: 150, + height: 27, + dropDownWidth: 300 + }); + $("#maddrowbutton").on('select', function (event) { + if (event.args) { + var index = event.args.index; + var datarecord = misclist.records[index]; + var row = {}; + row["m_name"] = datarecord.name; + row["m_amount"] = 0; + row["m_cost"] = datarecord.cost; + row["m_type"] = datarecord.type; + row["m_use_use"] = datarecord.use_use; + row["m_time"] = 0; + row["m_amount_is_weight"] = datarecord.amount_is_weight; + var commit = $("#miscGrid").jqxGrid('addrow', null, row); + } + }); + // delete selected misc. + $("#mdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 }); + $("#mdeleterowbutton").on('click', function () { + var selectedrowindex = $("#miscGrid").jqxGrid('getselectedrowindex'); + var rowscount = $("#miscGrid").jqxGrid('getdatainformation').rowscount; + if (selectedrowindex >= 0 && selectedrowindex < rowscount) { + var id = $("#miscGrid").jqxGrid('getrowid', selectedrowindex); + var commit = $("#miscGrid").jqxGrid('deleterow', id); + } + }); + }, + columns: [ + { text: 'Ingredient', editable: false, datafield: 'm_name' }, + { text: 'Type', editable: false, width: 120, align: 'center', cellsalign: 'center', datafield: 'm_type' }, + { text: 'Gebruik', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'm_use_use' }, + { text: 'Gewicht', datafield: 'm_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f5', + columntype: 'numberinput', + validation: function (cell, value) { + if (value < 0 || value > 100000000000 ) { + return { result: false, message: "Volume moet 0-~ zijn" }; + } + return true; + } + }, + { text: 'Tijd', datafield: 'm_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0', + columntype: 'numberinput', + validation: function (cell, value) { + if (value < 0 || value > 100000000000 ) { + return { result: false, message: "De tijd moet 0-~ zijn" }; + } + return true; + } + } + ] + }) + }; + // Inline yeasts editor @@ -672,6 +792,7 @@ $("#mash_name").val(''); editFermentable(''); editHop(''); + editMisc(''); editWater(''); $("#popupWindow").jqxWindow('open'); }); @@ -716,6 +837,7 @@ $("#mash_sparge_temp").val(dataRecord.mash_sparge_temp); editFermentable(dataRecord); editHop(dataRecord); + editMisc(dataRecord); editWater(dataRecord); // show the popup window. $("#popupWindow").jqxWindow('open'); @@ -767,6 +889,7 @@ $("#Save").click(function () { var fermentablerow = $('#fermentableGrid').jqxGrid('getrows'); var hoprow = $('#hopGrid').jqxGrid('getrows'); + var miscrow = $('#miscGrid').jqxGrid('getrows'); var waterrow = $('#waterGrid').jqxGrid('getrows'); if (editrow >= 0) { var rowRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); @@ -805,10 +928,10 @@ mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')), fermentables: fermentablerow, hops: hoprow, + miscs: miscrow, waters: waterrow }; $('#jqxgrid').jqxGrid('updaterow', rowID, row); - $("#popupWindow").jqxWindow('hide'); } else { // Insert a record var newrow = { @@ -845,11 +968,12 @@ mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')), fermentables: fermentablerow, hops: hoprow, + miscs: miscrow, waters: waterrow }; $('#jqxgrid').jqxGrid('addrow', null, newrow); - $("#popupWindow").jqxWindow('hide'); } + $("#popupWindow").jqxWindow('hide'); }); createDelElements(); });