my $action = param("ACTION") || "NONESUCH"; #Bond the built-in and accessory components to the parent. if($action eq "BOND") { my $main = param("MAIN"); my @built = param("BUILT"); my @acc = param("ACC"); my $query = "SELECT location FROM demstock2 WHERE ds_id=?"; my $sth = $db->prepare($query); $sth->execute($main) or print "Can't execute
$query
: " . $db->errstr . "
\n"; my $mainlocation = $sth->fetchrow_hashref; $sth->finish(); if($mainlocation->{"location"} ne "STOCK") { print b("Refusing to bond items to $main, as it isn't in free stock") . br(); } else { for my $child (@built, @acc) { #Find out if it still is in free stock my $query = "SELECT curr_parent_id FROM demstock2 WHERE ds_id=?"; my $sth = $db->prepare($query); $sth->execute($child) or print "Can't execute $query: " . $sth->errstr . "
\n"; my $current_status = $sth->fetchrow_hashref; $sth->finish(); if($current_status->{"curr_parent_id"} != 0) { print "Refusing to modify the status of demstock $child. It has already been moved
\n"; next; } #Move the kit, and update the action table my $move_query = "UPDATE demstock2 SET curr_parent_id=? WHERE ds_id=?"; my $move_sth = $db->prepare($move_query); $move_sth->execute($main, $child) or print "Can't execute
$move_query
: " . $sth->errstr . br(); $move_sth->finish(); my $action_query = "INSERT INTO action "; $action_query .= "(action_id, action_type, ds_id, occurred, ref_no, staff_id) VALUES"; $action_query .= "(NULL, 'MOVE', ?, CURRENT_TIMESTAMP, ?, ?)"; my $action_sth = $db->prepare($action_query); $action_sth->execute($child, "0,$main", $caluser) or print "Can't execute
$action_query
: " . $sth->errstr . br(); $action_sth->finish; } } }