# HG changeset patch # User Michiel Broek # Date 1625393785 -7200 # Node ID 86289b0c4a27edfbce0128d442659339f6e08f35 # Parent 0218893a5b7f72246bf56a275139dd0ce12d0273 Version 0.3.38. Better error handling in inventory equipments. Check if equipment is in use before delete. diff -r 0218893a5b7f -r 86289b0c4a27 config.status --- a/config.status Thu Jul 01 13:24:19 2021 +0200 +++ b/config.status Sun Jul 04 12:16:25 2021 +0200 @@ -433,7 +433,7 @@ This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." -ac_pwd='/home/mbroek/MyProjects/bms' +ac_pwd='/mnt/home/mbroek/MyProjects/bms' srcdir='.' test -n "$AWK" || AWK=awk # The default lists apply if the user does not specify any file. @@ -621,7 +621,7 @@ S["CC"]="gcc" S["CYEARS"]="2016-2021" S["COPYRIGHT"]="Copyright (C) 2016-2021 Michiel Broek, All Rights Reserved" -S["VERSION"]="0.3.37" +S["VERSION"]="0.3.38" S["PACKAGE"]="bms" S["SUBDIRS"]="bmsd doc script tools www" S["target_alias"]="" @@ -643,7 +643,6 @@ S["docdir"]="${datarootdir}/doc/${PACKAGE}" S["oldincludedir"]="/usr/include" S["includedir"]="${prefix}/include" -S["runstatedir"]="${localstatedir}/run" S["localstatedir"]="${prefix}/var" S["sharedstatedir"]="${prefix}/com" S["sysconfdir"]="${prefix}/etc" @@ -710,7 +709,7 @@ D["PACKAGE_STRING"]=" \"\"" D["PACKAGE_BUGREPORT"]=" \"\"" D["PACKAGE_URL"]=" \"\"" -D["VERSION"]=" \"0.3.37\"" +D["VERSION"]=" \"0.3.38\"" D["COPYRIGHT"]=" \"Copyright (C) 2016-2021 Michiel Broek, All Rights Reserved\"" D["STDC_HEADERS"]=" 1" D["HAVE_SYS_TYPES_H"]=" 1" diff -r 0218893a5b7f -r 86289b0c4a27 configure --- a/configure Thu Jul 01 13:24:19 2021 +0200 +++ b/configure Sun Jul 04 12:16:25 2021 +0200 @@ -661,7 +661,6 @@ docdir oldincludedir includedir -runstatedir localstatedir sharedstatedir sysconfdir @@ -733,7 +732,6 @@ sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE}' @@ -986,15 +984,6 @@ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; - -runstatedir | --runstatedir | --runstatedi | --runstated \ - | --runstate | --runstat | --runsta | --runst | --runs \ - | --run | --ru | --r) - ac_prev=runstatedir ;; - -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ - | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ - | --run=* | --ru=* | --r=*) - runstatedir=$ac_optarg ;; - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1132,7 +1121,7 @@ for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir + libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1285,7 +1274,6 @@ --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -2043,7 +2031,7 @@ PACKAGE="bms" -VERSION="0.3.37" +VERSION="0.3.38" COPYRIGHT="Copyright (C) 2016-2021 Michiel Broek, All Rights Reserved" CYEARS="2016-2021" diff -r 0218893a5b7f -r 86289b0c4a27 configure.ac --- a/configure.ac Thu Jul 01 13:24:19 2021 +0200 +++ b/configure.ac Sun Jul 04 12:16:25 2021 +0200 @@ -8,7 +8,7 @@ dnl General settings dnl After changeing the version number, run autoconf! PACKAGE="bms" -VERSION="0.3.37" +VERSION="0.3.38" COPYRIGHT="Copyright (C) 2016-2021 Michiel Broek, All Rights Reserved" CYEARS="2016-2021" AC_SUBST(PACKAGE) diff -r 0218893a5b7f -r 86289b0c4a27 www/includes/db_inventory_equipments.php --- a/www/includes/db_inventory_equipments.php Thu Jul 01 13:24:19 2021 +0200 +++ b/www/includes/db_inventory_equipments.php Sun Jul 04 12:16:25 2021 +0200 @@ -9,6 +9,11 @@ } mysqli_set_charset($connect, "utf8" ); +$response = array( + 'error' => false, + 'msg' => 'Ok', +); + if (isset($_POST['insert']) || isset($_POST['update'])) { if (isset($_POST['insert'])) { // INSERT COMMAND @@ -51,27 +56,40 @@ $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); - //} else { - // if (isset($_POST['update'])) { - // syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_POST['record']); - // } else { - // $lastid = mysqli_insert_id($connect); - // syslog(LOG_NOTICE, "db_inventory_equipment: inserted record ".$lastid); - // } + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($link); } - echo $result; + exit(json_encode($response)); } else if (isset($_POST['delete'])) { - // DELETE COMMAND - // FIXME: need to check if the record is in use + // DELETE COMMAND. check if this record is in use. + $sql = "SELECT name FROM `inventory_equipments` WHERE record='".$_POST['record']."';"; + $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect)); + if (! $result) { + syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($link); + exit(json_encode($response)); + } + if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $sql = "SELECT eq_name FROM products WHERE eq_name='" . $row['name'] . "';"; + $result2 = mysqli_query($connect, $sql); + $ar = mysqli_affected_rows($connect); + if ($ar > 0) { + $response['error'] = true; + $response['msg'] = "Installatie wordt ".$ar." maal gebruikt."; + exit(json_encode($response)); + } + } + // Record not used, delete it. $sql = "DELETE FROM `inventory_equipments` WHERE record='".$_POST['record']."';"; $result = mysqli_query($connect, $sql); if (! $result) { syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); - } else { - syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_POST['record']); + $response['error'] = true; + $response['msg'] = "SQL fout: ".mysqli_error($link); } - echo $result; + exit(json_encode($response)); } else { // SELECT COMMAND @@ -107,6 +125,12 @@ ); } header("Content-type: application/json"); - echo json_encode($equipments); + exit(json_encode($equipments)); } + +syslog(LOG_NOTICE, "db_inventory_equipment: missing arguments"); +$response['error'] = true; +$response['msg'] = "missing arguments"; +echo json_encode($response); + ?> diff -r 0218893a5b7f -r 86289b0c4a27 www/js/inv_equipments.js --- a/www/js/inv_equipments.js Thu Jul 01 13:24:19 2021 +0200 +++ b/www/js/inv_equipments.js Sun Jul 04 12:16:25 2021 +0200 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2014-2020 + * Copyright (C) 2014-2021 * * Michiel Broek * @@ -129,7 +129,13 @@ data: data, type: 'POST', success: function(data, status, xhr) { - commit(true); + if (data.error) { + console.log('delete: ' + data.msg); + alert('Fout: ' + data.msg); + } else { + console.log('delete: success'); + } + //commit(true); location.reload(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } @@ -144,7 +150,12 @@ data: data, type: 'POST', success: function(data, status, xhr) { - commit(true); + 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); } @@ -158,11 +169,17 @@ 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'); + } + //commit(true); location.reload(true); }, - error: function(jqXHR, textStatus, errorThrown) { commit(false); } + error: function(jqXHR, textStatus, errorThrown) { console.log('updaterow: ' + textStatus); commit(false); } }); } },