--- trunk/web/browse.cgi 2005/11/16 15:33:12 67 +++ trunk/web/browse.cgi 2005/11/20 20:44:15 77 @@ -18,7 +18,9 @@ $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 $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 $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' ); @@ -54,6 +57,7 @@ return $iconv_loc->convert(chr(hex($t))); } $content =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex; + $content =~ s/^[\n\r]+//s; $content =~ s/[\n\r]+$//s; write_file($path . '.new', $content) || die "can't save ${path}.new $!"; @@ -75,14 +79,14 @@ 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{ @@ -116,7 +120,7 @@ } 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')) { @@ -124,7 +128,7 @@ print qq{ -$template_file saved +$template_filename saved   idle - + @@ -226,6 +230,22 @@ exit; } else { + + my $template_form = qq{ +
+ + +
+ }; + print <<"_END_OF_HEAD_"; @@ -242,6 +262,7 @@ var rec = $rec ; var url = '$self'; +var template_filename = '$template_filename'; var css_rnd = 0; @@ -257,7 +278,7 @@ iwfShow('a_left_arr', 1); } update_status(nr+'...'); - iwfRequest( url+'/xml/?rec='+nr, 'div_record' ); + iwfRequest( url+'/xml/?template='+template_filename+'&rec='+nr, 'div_record' ); iwfOpacity('div_record', 30); } @@ -304,7 +325,7 @@ load_rec(rec); // load template editor - iwfRequest( url+'/template/', 'div_template' ); + iwfRequest( url+'/template/?template='+template_filename, 'div_template' ); // load css editor iwfRequest( url+'/css/', 'div_css' ); } @@ -318,7 +339,7 @@ db_path = $db_path
-template = $template_file
+template = $template_form
css = $css_file