+sub read_config_txt {
+ my ( $file ) = @_;
+ my $input;
+ my $path ="$dir/$path/$path-$file.txt";
+ if ( ! -e $path ) {
+ warn "missing $path";
+ return;
+ }
+ foreach ( split(/[\n\r]+/, read_file( $path ) ) ) {
+ my ( $val,$label ) = split(/\s*\t\s*/,$_,2);
+ push @{ $input->{ '-values' } }, $val;
+ $input->{ '-labels' }->{$val} = $label;
+ }
+ return $input;
+}
+
+my $attr_labels = read_config_txt 'labels';
+my $attr_operators = read_config_txt 'operators';
+
+my @attr = @{ $attr_labels->{'-values'} } if $attr_labels;
+@attr = keys %{ $stats->{attr} } unless @attr;
+
+
+warn dump( $attr_labels, $attr_operators );
+
+my $only_input;
+my $inputs_available = 0;
+
+foreach ( @{ $db->{input} } ) {
+ my $input = $_->{name} || die "no name in ",dump( $_ );
+ next unless defined $stats->{input}->{$input}; # skip inputs without data
+ if ( ! $only_input->{'-labels'}->{$input} ) {
+ push @{ $only_input->{'-values'} }, $input;
+ $only_input->{'-labels'}->{$input} = $_->{description} || $input;
+ $inputs_available++;
+ }
+}
+
+warn "## only_input = ", dump( $only_input );
+
+my @style = ( '../../style.css' );
+push @style, "../../$path/$path.css" if -e "$dir/$path/$path.css";
+dump_yaml( 'style', \@style );
+
+sub search_form {
+
+ my $form_html = "$dir/$path/$path-search.html";
+ if ( -e $form_html ) {
+ my $html = read_file( $form_html );
+ my $q = CGI->new();
+ my $h = HTML::FillInForm::Lite->new();
+ return $h->fill(\$html, $q);
+ }
+
+ qq|<a name="form"></a>|,
+ start_form( -action => self_url( query => 0 ) ),
+ checkbox_group(
+ -name => 'attr',
+ %$attr_labels,
+# -linebreak => 0,
+ ),
+ textfield( -name => 'search' ),
+ $attr_operators ? popup_menu( -name => 'attr_operator', %$attr_operators ) : '',
+ submit( -value => 'Search' ),
+# hidden( -name => 'entries_per_page', -default => $entries_per_page ),
+ popup_menu( -name => 'entries_per_page', -values => [ @entries_per_page ], -title => 'entries per page' ),
+ # we need current_page fixed at 1 so that every submit through form will reset it
+ qq|<input type=hidden name=current_page value=1 >|,
+ checkbox( -name => 'debug', -default => 0 ), # FIXME hidden?
+ qq|<div id=inputs>|,
+ $inputs_available > 1 ?
+ h2( 'Select input' ) .
+ checkbox_group(
+ -name => 'only_input',
+ %$only_input,
+ -linebreak=> 'true',
+ ) : '',
+ qq|</div>|,
+ end_form,
+ ;
+}
+