aisa/scripts/get/get_db_delete_client.pl
2025-11-26 11:31:54 +02:00

83 lines
1.6 KiB
Perl

#!/usr/bin/perl
print "Content-type: text/html\n\n";
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
require cfg ;
use DBI;
use CGI::Carp qw(fatalsToBrowser);
#------------------------------------------------------------------------------------------
@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});
$id = $ARGV[0] ;
#------------------------------------------------------------------------------------------
&get_client_waybills_details ;
&delete_client ;
print $json ;
exit ;
#------------------------------------------------------------------------------------------
sub get_client_waybills_details {
unless ($id) { return ; }
&db_open_ro ;
my $sql = qq(SELECT * FROM waybills WHERE clientid = '$id') ;
my $sth = $dbh->prepare($sql) ;
$sth -> execute() or die "Could not execute SQL statement $sql ... maybe invalid? $!";
my $waybill_array_ref = $sth->fetchall_arrayref();
$sth->finish();
&db_close_conn ;
$json = '[' ;
foreach $row (@$waybill_array_ref) {
&db_waybills_fields ;
$do_not_delete = 1 ;
$json .= qq(
{"waybillno":"$wb{'waybillno'}"},) ;
}
$json = substr($json,0,-1) ;
$json =~ s/\\//g ;
$json .= ']' ;
} #------------------------------------------------------------------------------------------
sub delete_client {
unless ($id) { return ; }
if ($do_not_delete) { return ; }
&db_open_upd ;
$sql = qq(DELETE FROM clients WHERE id = '$id') ;
$sth = $dbh -> do ($sql) or die "could not execute :<BR>$sql<BR>$!" ;
&db_close_conn ;
$json = qq([{"deleted":"1"}]) ;
} #------------------------------------------------------------------------------------------
use db ;
1;