<%doc> Performs advanced searches in specific tables. User is allowed to specify values for one or more fields. Fields that are foreign keys are shown as a drop-down list of possible values. If the foreign table has more than $maxselect objects, the user will be presented with a text box to fill in with keywords. A javascript script will then call another CGI which will return a set of matched objects. These will be copied to the list of Arguments: table - The name of the table to search res - A flag to distinguish between showing the form or showing the results adv_search - If adv_search=1 is passed then show radio buttons for boolean fields (unset, true, false) instead of checkboxes (which only has true, false) ARGS - The rest are fields to be passed to the search_like method. <%args> $table => undef $res => undef $adv_search => 0 <%attr> title => 'Specific Search' section => 'Generic' <%init> my $user = $ui->get_current_user($r); my $manager = $ui->get_permission_manager($r); unless ( $manager && $manager->can($user, "access_section", 'search_obj.html') ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to access this page"); } my $maxselect = 100; my $DEBUG = 0; print "%ARGS is
", Dumper(%ARGS), "

" if $DEBUG; my %reserved = ( 'submit' => '', 'table' => '', 'res' => '', 'showheader' => '', ); my $title = "$table " . $ui->table_descr_link($table, "[?]"); unless ( $table ){ # offer a list of tables to select $m->comp( 'table.mhtml', width => 3, link => "search_obj.html", title => "Please select a table to search:"); } else { # we have a table # Get some Meta info my %linksto = $table->meta_data->get_links_to();
%if ( ! $res ){ # show the fill-out form
<% $title %>: Specify one or more of the following as search criteria:
<& form.mhtml, table => $table, allow_create => 0, adv_search => $adv_search &>
% } else { # Process input and search <%perl> my %sarg; foreach my $j (keys %ARGS){ # Ignore empty, zeroed and reserved fields next unless ( $ARGS{$j} ); next if ( exists $reserved{$j} ); next if ( $j =~ /_srch/ ); next if ( $ARGS{$j} =~ /radio_unset/ ); $ARGS{$j} =~ s/radio_yes/1/; $ARGS{$j} =~ s/radio_no/0/; $ARGS{$j} = undef if $ARGS{$j} eq 'undef'; # "/^_/" is added to avoid using reserved words in javascript # chop it off my $k = $j; $k =~ s/^_//; $sarg{$k} = $ARGS{$j}; } print "sarg is
", Dumper(%sarg), "

" if $DEBUG; # Check that we have at least one parameter unless ( scalar keys(%sarg) ){ $m->comp('/generic/error.mhtml', error => "Missing Search Criteria"); } my @objs = $table->search_like(%sarg);
Total <% $table %> matches: <% scalar (@objs) %>
<& sortresults.mhtml, table => "$table", object => \@objs, withedit => 1 &>
% } # endif !res %}