X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=web%2Fbrowse.cgi;h=0ea35b981dce6afb3cb6f463399a52992fa4ecf6;hb=4727bc68c05d61385c0c5e34f32ace1361b48892;hp=916d946ac31fe5fee3a00648f045e762198e2e13;hpb=d4fc673006523d2a972a74943f880fcd47c658dd;p=webpac2 diff --git a/web/browse.cgi b/web/browse.cgi index 916d946..0ea35b9 100755 --- a/web/browse.cgi +++ b/web/browse.cgi @@ -18,7 +18,9 @@ my $abs_path = abs_path($0); $abs_path =~ s#/[^/]*$#/../#; my $db_path = $abs_path . '/db/'; -my $template_file = 'html_ffzg.tt'; +my $template_path = "$abs_path/conf/output/tt"; +opendir(my $dir, $template_path) || die "can't open template path $template_path: $!"; +my @templates = grep { /\.tt$/i } readdir($dir); my $css_file = 'user.css'; my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8'); @@ -31,7 +33,7 @@ my $db = new WebPAC::DB( ); my $out = new WebPAC::Output::TT( - include_path => "$abs_path/conf/output/tt", + include_path => $template_path, filters => { foo => sub { shift } }, ); @@ -39,6 +41,7 @@ my $q = new CGI::Simple; my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 ); my $rec = $q->param('rec') || 1; +my $template_filename = $q->param('template') || $templates[0]; print $q->header( -charset => 'utf-8' ); @@ -76,14 +79,14 @@ sub get_file_in_html($) { if ($q->path_info =~ m#xml#) { - my @ds = $db->load_ds($rec); + my $ds = $db->load_ds($rec); - if (@ds && $#ds > 0) { + if ($ds) { print qq{ }, $iconv_utf8->convert( $out->apply( - template => $template_file, - data => \@ds, + template => $template_filename, + data => $ds, ) ), qq{ @@ -117,7 +120,7 @@ if ($q->path_info =~ m#xml#) { } elsif ($q->path_info =~ m#template#) { - my $template_path = $out->{'include_path'} . '/' . $template_file; + my $template_path = $out->{'include_path'} . '/' . $template_filename; if ($q->param('save_template')) { @@ -125,7 +128,7 @@ if ($q->path_info =~ m#xml#) { print qq{ -$template_file saved +$template_filename saved