<%doc> ############################################################################### # A customized version of the generic dynamic_list_query.html ############################################################################### <%args> $field => $ARGS{field}; $val => $ARGS{val}; <%shared> my $DEBUG = 0; <%perl> if ( $DEBUG ){ use Data::Dumper; print "

     ", Dumper(%ARGS), "

"; print &closet_floor_search("end_id", "14"); } else { do "jsrsServer.pm"; jsrsDispatch("closet_floor_search"); } sub closet_floor_search { # Arguments: # - field: Form element to add the results into # - val: Criteria. The ID of the floor to query for closets my $field = shift; my $val = shift; my @terms; if ($val =~ /\w+/) { if ($val =~ /\w+\s+\w+/) { # if there's more than one word @terms = split /\s+/, $val; } else { $val =~ s/\s+//; push @terms, $val; } } my @results = (); my $floor_id = $terms[0]; my $floor; if ( $floor = Floor->retrieve($floor_id) ){ foreach my $room ($floor->rooms) { foreach my $closet ($room->closets) { push (@results, $closet); } } } my $response = $field."&"; @results = sort { $a->name cmp $b->name } @results; @results = sort { $a->room->name cmp $b->room->name } @results; $response .= "0=".$ui->url_encode("No matches") unless (scalar(@results)); if (scalar(@results)) { $response .= "0=-- Select --&"; foreach my $closet (@results) { $response .= $closet->id."=".$ui->url_encode($closet->name." (Room ".$closet->room->name.")")."&"; } } return $response; }