# HG changeset patch # User Michiel Broek # Date 1625421673 -7200 # Node ID ae1195153fa2016b98443dae2ae1bb92bd0e2f98 # Parent 08c0343b622ba7ca7b03debf177030e84c737332 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup. diff -r 08c0343b622b -r ae1195153fa2 www/includes/db_product.php --- a/www/includes/db_product.php Sun Jul 04 14:25:52 2021 +0200 +++ b/www/includes/db_product.php Sun Jul 04 20:01:13 2021 +0200 @@ -280,7 +280,6 @@ $sql .= "', divide_factor='" . floatval($_POST['divide_factor']); $sql .= "', divide_parts='" . $_POST['divide_parts']; $sql .= "', divide_part='" . $_POST['divide_part']; - //syslog(LOG_NOTICE, $sql); $fermentables = '['; $comma = FALSE; @@ -331,7 +330,6 @@ } } $fermentables .= ']'; - //syslog(LOG_NOTICE, $fermentables); $sql .= "', json_fermentables='" . $fermentables; $hops = '['; @@ -377,7 +375,6 @@ } } $hops .= ']'; - //syslog(LOG_NOTICE, 'hops: ' . $hops); $sql .= "', json_hops='" . $hops; $miscs = '['; @@ -414,7 +411,6 @@ } } $miscs .= ']'; - //syslog(LOG_NOTICE, 'miscs: ' . $miscs); $sql .= "', json_miscs='" . $miscs; $yeasts = '['; @@ -467,7 +463,6 @@ } } $yeasts .= ']'; - //syslog(LOG_NOTICE, $yeasts); $sql .= "', json_yeasts='" . $yeasts; $mashs = '['; @@ -515,7 +510,6 @@ } } $mashs .= ']'; - //syslog(LOG_NOTICE, $mashs); $sql .= "', json_mashs='" . $mashs; if (isset($_POST['insert'])) { @@ -529,14 +523,13 @@ if (! $result) { syslog(LOG_NOTICE, "db_product: result: ".mysqli_error($connect)); $response['error'] = true; - $response['msg'] = "SQL fout: ".mysqli_error($link); + $response['msg'] = "SQL fout: ".mysqli_error($connect); } else { if (isset($_POST['update'])) { //syslog(LOG_NOTICE, "db_product: updated record ".$_POST['record']); inventory_reduce(); } else { $lastid = mysqli_insert_id($connect); - //syslog(LOG_NOTICE, "db_product: inserted record ".$lastid); } } echo json_encode($response); @@ -556,7 +549,7 @@ if (! $result) { syslog(LOG_NOTICE, "db_product: result: ".mysqli_error($connect)); $response['error'] = true; - $response['msg'] = "SQL update fout: ".mysqli_error($link); + $response['msg'] = "SQL update fout: ".mysqli_error($connect); } else { syslog(LOG_NOTICE, "db_product: updated (divide) record ".$_POST['record']); } @@ -571,7 +564,7 @@ if (! $result) { syslog(LOG_NOTICE, "db_product: ".$sql." result: ".mysqli_error($connect)); $response['error'] = true; - $response['msg'] = "SQL delete fout: ".mysqli_error($link); + $response['msg'] = "SQL delete fout: ".mysqli_error($connect); } else { syslog(LOG_NOTICE, "db_product: deleted product uuid ".$_POST['uuid']); } @@ -596,8 +589,7 @@ ); } header("Content-type: application/json"); - echo json_encode($brews, JSON_UNESCAPED_UNICODE); - return; + exit(json_encode($brews, JSON_UNESCAPED_UNICODE)); } if (isset($_GET['select']) && ($_GET['select'] == "archname")) { @@ -616,8 +608,7 @@ ); } header("Content-type: application/json"); - echo json_encode($brews, JSON_UNESCAPED_UNICODE); - return; + exit(json_encode($brews, JSON_UNESCAPED_UNICODE)); } if (isset($_GET['select']) && ($_GET['select'] == "archcode")) { @@ -636,8 +627,7 @@ ); } header("Content-type: application/json"); - echo json_encode($brews, JSON_UNESCAPED_UNICODE); - return; + exit(json_encode($brews, JSON_UNESCAPED_UNICODE)); } if (isset($_GET['select']) && ($_GET['select'] == "archdate")) { @@ -657,8 +647,7 @@ ); } header("Content-type: application/json"); - echo json_encode($brews, JSON_UNESCAPED_UNICODE); - return; + exit(json_encode($brews, JSON_UNESCAPED_UNICODE)); } /* @@ -690,8 +679,7 @@ ); } header("Content-type: application/json"); - echo json_encode($brews, JSON_UNESCAPED_UNICODE); - return; + exit(json_encode($brews, JSON_UNESCAPED_UNICODE)); } /* @@ -1083,12 +1071,11 @@ } $brew .= '}'; -// syslog(LOG_NOTICE, $brew); $brews .= $brew; } $brews .= ']'; header("Content-type: application/json"); - echo $brews; + exit($brews); } diff -r 08c0343b622b -r ae1195153fa2 www/includes/db_profile_fermentation.php --- a/www/includes/db_profile_fermentation.php Sun Jul 04 14:25:52 2021 +0200 +++ b/www/includes/db_profile_fermentation.php Sun Jul 04 20:01:13 2021 +0200 @@ -10,6 +10,11 @@ } mysqli_set_charset($connect, "utf8" ); +$response = array( + 'error' => false, + 'msg' => 'Ok', +); + $rescapers = array("'"); $rreplacements = array("\\'"); @@ -60,20 +65,13 @@ if (isset($_POST['update'])) { $sql .= "' WHERE record='" . $_POST['record'] . "';"; } - //syslog(LOG_NOTICE, $sql); - $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_profile_fermentation: ".$sql." result: ".mysqli_error($connect)); - //} else { - // if (isset($_POST['update'])) { - // syslog(LOG_NOTICE, "db_profile_fermentation: updated record ".$_POST['record']); - // } else { - // $lastid = mysqli_insert_id($connect); - // syslog(LOG_NOTICE, "db_profile_fermentation: inserted record ".$lastid); - // } - } - echo $result; + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($connect); + } + exit(json_encode($response)); } else if (isset($_POST['delete'])) { // DELETE COMMAND @@ -81,10 +79,10 @@ $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_profile_fermentation: ".$sql." result: ".mysqli_error($connect)); - } else { - syslog(LOG_NOTICE, "db_profile_fermentation: deleted record ".$_POST['record']); - } - echo $result; + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($connect); + } + exit(json_encode($response)); } else { // SELECT COMMAND @@ -111,8 +109,13 @@ $profiles .= '}'; } $profiles .= ']'; -// syslog(LOG_NOTICE, $profiles); header("Content-type: application/json"); - echo $profiles; + exit($profiles); } + +syslog(LOG_NOTICE, "db_profile_fermentation: missing arguments"); +$response['error'] = true; +$response['msg'] = "missing arguments"; +echo json_encode($response); + ?> diff -r 08c0343b622b -r ae1195153fa2 www/includes/db_profile_mash.php --- a/www/includes/db_profile_mash.php Sun Jul 04 14:25:52 2021 +0200 +++ b/www/includes/db_profile_mash.php Sun Jul 04 20:01:13 2021 +0200 @@ -13,6 +13,11 @@ $rescapers = array("'"); $rreplacements = array("\\'"); +$response = array( + 'error' => false, + 'msg' => 'Ok', +); + if (isset($_POST['insert']) || isset($_POST['update'])) { if (isset($_POST['insert'])) { $sql = "INSERT INTO"; @@ -48,20 +53,13 @@ if (isset($_POST['update'])) { $sql .= "' WHERE record='" . $_POST['record'] . "';"; } - //syslog(LOG_NOTICE, $sql); - $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_profile_mash: ".$sql." result: ".mysqli_error($connect)); - //} else { - // if (isset($_POST['update'])) { - // syslog(LOG_NOTICE, "db_profile_mash: updated record ".$_POST['record']); - // } else { - // $lastid = mysqli_insert_id($connect); - // syslog(LOG_NOTICE, "db_profile_mash: inserted record ".$lastid); - // } - } - echo $result; + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($connect); + } + exit(json_encode($response)); } else if (isset($_POST['delete'])) { // DELETE COMMAND @@ -69,10 +67,10 @@ $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_profile_mash: ".$sql." result: ".mysqli_error($connect)); - } else { - syslog(LOG_NOTICE, "db_profile_mash: deleted record ".$_POST['record']); - } - echo $result; + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($connect); + } + exit(json_encode($response)); } else { // SELECT COMMAND @@ -90,11 +88,16 @@ $mashprofile .= ',"name":' . $row['JSON_QUOTE(name)']; $mashprofile .= ',"notes":' . $row['JSON_QUOTE(notes)']; $mashprofile .= ',"steps":' . $row['steps'] . '}'; -//syslog(LOG_NOTICE, $mashprofile); $mashprofiles .= $mashprofile; } $mashprofiles .= ']'; header("Content-type: application/json"); - echo $mashprofiles; + exit($mashprofiles); } + +syslog(LOG_NOTICE, "db_profile_mash: missing arguments"); +$response['error'] = true; +$response['msg'] = "missing arguments"; +echo json_encode($response); + ?> diff -r 08c0343b622b -r ae1195153fa2 www/includes/db_profile_styles.php --- a/www/includes/db_profile_styles.php Sun Jul 04 14:25:52 2021 +0200 +++ b/www/includes/db_profile_styles.php Sun Jul 04 20:01:13 2021 +0200 @@ -10,6 +10,11 @@ } mysqli_set_charset($connect, "utf8" ); +$response = array( + 'error' => false, + 'msg' => 'Ok', +); + if (isset($_POST['insert']) || isset($_POST['update'])) { if (isset($_POST['insert'])) { $sql = "INSERT INTO `profile_styles` SET "; @@ -46,19 +51,13 @@ if (isset($_POST['update'])) { $sql .= "' WHERE record='" . $_POST['record'] . "';"; } - $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_profile_styles: ".$sql." result: ".mysqli_error($connect)); - //} else { - // if (isset($_POST['update'])) { - // syslog(LOG_NOTICE, "db_profile_styles: updated record ".$_POST['record']); - // } else { - // $lastid = mysqli_insert_id($connect); - // syslog(LOG_NOTICE, "db_profile_styles: inserted record ".$lastid); - // } - } - echo $result; + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($connect); + } + exit(json_encode($response)); } else if (isset($_POST['delete'])) { // DELETE COMMAND @@ -66,10 +65,10 @@ $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_profile_styles: ".$sql." result: ".mysqli_error($connect)); - } else { - syslog(LOG_NOTICE, "db_profile_styles: deleted record ".$_POST['record']); - } - echo $result; + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($connect); + } + exit(json_encode($response)); } else { // SELECT COMMAND @@ -103,6 +102,12 @@ ); } header("Content-type: application/json"); - echo json_encode($styles); + exit(json_encode($styles)); } + +syslog(LOG_NOTICE, "db_profile_styles: missing arguments"); +$response['error'] = true; +$response['msg'] = "missing arguments"; +echo json_encode($response); + ?> diff -r 08c0343b622b -r ae1195153fa2 www/includes/db_profile_water.php --- a/www/includes/db_profile_water.php Sun Jul 04 14:25:52 2021 +0200 +++ b/www/includes/db_profile_water.php Sun Jul 04 20:01:13 2021 +0200 @@ -10,6 +10,11 @@ } mysqli_set_charset($connect, "utf8" ); +$response = array( + 'error' => false, + 'msg' => 'Ok', +); + if (isset($_POST['insert']) || isset($_POST['update'])) { if (isset($_POST['insert'])) { $sql = "INSERT INTO `profile_water` SET "; @@ -34,20 +39,13 @@ if (isset($_POST['update'])) { $sql .= "' WHERE record='" . $_POST['record'] . "';"; } - //syslog(LOG_NOTICE, $sql); - $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect)); - //} else { - // if (isset($_POST['update'])) { - // syslog(LOG_NOTICE, "db_profile_water: updated record ".$_POST['record']); - // } else { - // $lastid = mysqli_insert_id($connect); - // syslog(LOG_NOTICE, "db_profile_water: inserted record ".$lastid); - // } - } - echo $result; + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($connect); + } + exit(json_encode($response)); } else if (isset($_POST['delete'])) { // DELETE COMMAND @@ -55,10 +53,10 @@ $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect)); - } else { - syslog(LOG_NOTICE, "db_profile_water: deleted record ".$_POST['record']); - } - echo $result; + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($connect); + } + exit(json_encode($response)); } else { // SELECT COMMAND @@ -80,6 +78,12 @@ ); } header("Content-type: application/json"); - echo json_encode($waters); + exit(json_encode($waters)); } + +syslog(LOG_NOTICE, "db_profile_water: missing arguments"); +$response['error'] = true; +$response['msg'] = "missing arguments"; +echo json_encode($response); + ?> diff -r 08c0343b622b -r ae1195153fa2 www/includes/db_setup.php --- a/www/includes/db_setup.php Sun Jul 04 14:25:52 2021 +0200 +++ b/www/includes/db_setup.php Sun Jul 04 20:01:13 2021 +0200 @@ -12,6 +12,11 @@ $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c"); $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b"); +$response = array( + 'error' => false, + 'msg' => 'Ok', +); + $query = "SELECT * FROM profile_setup WHERE record='1'"; if (isset($_POST['update'])) { @@ -36,14 +41,14 @@ $sql .= "', default_water='" . $default_water; $sql .= "', my_yeastlab='" . $_POST['my_yeastlab']; $sql .= "' WHERE record='1';"; - //syslog(LOG_NOTICE, $sql); $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_profile_setup: ".$sql." result: ".mysqli_error($connect)); - } else { - syslog(LOG_NOTICE, "db_profile_setup: updated record 1"); - } - echo $result; + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($connect); + } + exit(json_encode($response)); + } else { $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { @@ -70,6 +75,6 @@ $data .= '"}'; } header("Content-type: application/json"); - echo $data; + exit($data); } ?> diff -r 08c0343b622b -r ae1195153fa2 www/js/profile_fermentation.js --- a/www/js/profile_fermentation.js Sun Jul 04 14:25:52 2021 +0200 +++ b/www/js/profile_fermentation.js Sun Jul 04 20:01:13 2021 +0200 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2019-2020 + * Copyright (C) 2019-2021 * * Michiel Broek * @@ -75,8 +75,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('delete: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('delete: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } @@ -90,8 +95,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('insert: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('insert: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } @@ -105,8 +115,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('updaterow: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('updaterow: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } diff -r 08c0343b622b -r ae1195153fa2 www/js/profile_mash.js --- a/www/js/profile_mash.js Sun Jul 04 14:25:52 2021 +0200 +++ b/www/js/profile_mash.js Sun Jul 04 20:01:13 2021 +0200 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2014-2020 + * Copyright (C) 2014-2021 * * Michiel Broek * @@ -71,8 +71,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('delete: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('delete: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { @@ -89,8 +94,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('insert: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('insert: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { @@ -107,8 +117,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('updaterow: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('updaterow: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { diff -r 08c0343b622b -r ae1195153fa2 www/js/profile_setup.js --- a/www/js/profile_setup.js Sun Jul 04 14:25:52 2021 +0200 +++ b/www/js/profile_setup.js Sun Jul 04 20:01:13 2021 +0200 @@ -167,7 +167,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { + success: function(data) { + if (data.error) { + console.log('update: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('update: success'); + } }, error: function(jqXHR, textStatus, errorThrown) { } diff -r 08c0343b622b -r ae1195153fa2 www/js/profile_styles.js --- a/www/js/profile_styles.js Sun Jul 04 14:25:52 2021 +0200 +++ b/www/js/profile_styles.js Sun Jul 04 20:01:13 2021 +0200 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2014-2020 + * Copyright (C) 2014-2021 * * Michiel Broek * @@ -85,8 +85,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('delete: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('delete: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } @@ -100,8 +105,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('insert: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('insert: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } @@ -115,8 +125,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('updaterow: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('updaterow: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } diff -r 08c0343b622b -r ae1195153fa2 www/js/profile_water.js --- a/www/js/profile_water.js Sun Jul 04 14:25:52 2021 +0200 +++ b/www/js/profile_water.js Sun Jul 04 20:01:13 2021 +0200 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2014-2020 + * Copyright (C) 2014-2021 * * Michiel Broek * @@ -73,8 +73,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('delete: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('delete: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } @@ -88,8 +93,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('insert: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('insert: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } @@ -103,8 +113,13 @@ cache: false, data: data, type: 'POST', - success: function(data, status, xhr) { - commit(true); + success: function(data) { + if (data.error) { + console.log('updaterow: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('updaterow: success'); + } location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); }