<%doc> Performs retrieve_all queries whose return values are used to fill in objects in HTML pages via asynnchronous javascript calls. <%flags> inherit => undef <%shared> my $DEBUG = 0; <%args> $table => undef $form_field => 'form_field' <%perl> if ( $DEBUG ){ use Data::Dumper; print "
 ", Dumper(%ARGS), "

"; if ( $table ){ print &retrieve_all($table, $form_field); } }else{ # Do not use 'require' here. # We need to make sure the file is read *each time* do "jsrsServer.pm"; jsrsDispatch("retrieve_all"); } # Arguments: # - table: Table to search. # - form_field: Name of the form field to add the results into sub retrieve_all { my ( $table, $form_field ) = @_; my $response = $form_field."&"; my $MAX = $ui->config->get('DEFAULT_SELECTMAX'); $response .= "null=-- Select --&"; if ( $table eq 'Ipblock' ){ my $dbh = Netdot::Model->db_Main(); my $rows = $dbh->selectall_arrayref("SELECT id,version,address,prefix FROM ipblock WHERE (version=4 AND prefix!=32) OR (version=6 AND prefix!=128) ORDER BY address"); if ( my $n = scalar @$rows ){ if( $n <= $MAX ){ foreach my $row ( @$rows ){ my ($id, $version, $intaddr, $prefix) = @$row; my $address = Ipblock->int2ip($intaddr, $version); my $lbl = $address.'/'.$prefix; $response .= $id."=".$ui->url_encode($lbl)."&"; } }else{ $response .= "null=".$ui->url_encode("More than ".$MAX." matches.")."&"; $response .= "null=".$ui->url_encode("Refine search."); } }else{ $response .= "null=".$ui->url_encode("No matches"); } }else{ my @rows = $table->retrieve_all(); if ( my $n = scalar @rows ){ if( $n <= $MAX){ my $count = 0; my @objs = sort { $a->get_label cmp $b->get_label } @rows; foreach my $o ( @objs ){ my $lbl = $o->get_label(); $response .= $o->id."=".$ui->url_encode($lbl)."&"; } }else{ $response .= "null=".$ui->url_encode("More than ".$MAX." matches.")."&"; $response .= "null=".$ui->url_encode("Refine search."); } }else{ $response .= "null=".$ui->url_encode("No matches"); } } return $response; }