--- trunk/web/browse.cgi 2005/11/15 16:56:40 63
+++ trunk/web/browse.cgi 2005/11/20 21:45:09 79
@@ -18,7 +18,10 @@
$abs_path =~ s#/[^/]*$#/../#;
my $db_path = $abs_path . '/db/';
-my $template = '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');
my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2');
@@ -30,7 +33,7 @@
);
my $out = new WebPAC::Output::TT(
- include_path => "$abs_path/conf/output/tt",
+ include_path => $template_path,
filters => { foo => sub { shift } },
);
@@ -38,19 +41,69 @@
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' );
+##---- some handy subs
+
+sub update_file($$) {
+ my ($path, $content) = @_;
+
+ $content = $iconv_loc->convert( $content ) || die "no content?";
+
+ sub _conv_js {
+ my $t = shift || return;
+ 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 $!";
+ rename $path . '.new', $path || die "can't rename to $path: $!";
+}
+
+sub get_file_in_html($) {
+ my ($path) = @_;
+
+ die "no path?" unless ($path);
+
+ my $content = read_file($path) || die "can't read $path: $!";
+ $content = $q->escapeHTML($iconv_utf8->convert($content));
+
+ return $content;
+}
+
+sub template_list_html($) {
+ my $current = shift || die;
+
+ my $html = qq{ Template\n
};
+
+ foreach my $t (sort @templates) {
+ if ($t eq $current) {
+ $html .= qq{ - $t
};
+ } else {
+ $html .= qq{ - $t
};
+ }
+ }
+
+ $html .= qq{
};
+ return $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,
- data => \@ds,
+ template => $template_filename,
+ data => $ds,
) ), qq{
@@ -82,33 +135,34 @@
exit;
}
+} elsif ($q->path_info =~ m#template_list#) {
+
+ print qq{
+
+} . template_list_html($template_filename) . qq{
+
+
+ };
+
+ exit;
+
} elsif ($q->path_info =~ m#template#) {
- my @actions;
+ my $template_path = $out->{'include_path'} . '/' . $template_filename;
if ($q->param('save_template')) {
- my $tmpl = $iconv_loc->convert( $q->param('tt_template') ) || die "no template?";
- sub _conv_js {
- my $t = shift || return;
- return $iconv_loc->convert(chr(hex($t)));
- }
- $tmpl =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex;
- $tmpl =~ s/[\n\r]+$//s;
-
- my $tmpl_file = $out->{'include_path'} . '/' . $template;
- write_file($tmpl_file . '.new', $tmpl) || die "can't save $tmpl_file: $!";
- rename $tmpl_file . '.new', $tmpl_file || die "can't rename to $tmpl_file: $!";
+ update_file($template_path, $q->param('tt_template'));
print qq{
-
-$template saved
+
+$template_filename saved
@@ -117,14 +171,12 @@
}
- my $tmpl = read_file($out->{'include_path'} . '/' . $template) || die "can't read template $template: $!";
- $tmpl = $q->escapeHTML($iconv_utf8->convert($tmpl));
+ my $tmpl = get_file_in_html($template_path);
print qq{
-}, Dumper($q->Vars), qq{
-
+
+
+
+
+
+ };
+
+ exit;
+
+} elsif ($q->path_info =~ m#css#) {
+
+ my $css_path = $abs_path . '/web/' . $css_file;
+
+
+ if ($q->param('save_css')) {
+ update_file($css_path, $q->param('user_css'));
+
+ print qq{
+
+$css_file saved
+
+
+
+
+
+ };
+ exit;
-
+ }
+
+ my $user_css = get_file_in_html($css_path);
+ print qq{
+
+
+
@@ -152,18 +259,28 @@
exit;
} else {
- print qq{
+
+ my $template_list_html = template_list_html($template_filename);
+
+ print <<"_END_OF_HEAD_";
WebPAC simple browse interface
+
+
+
+
+
-db_path = $db_path
-template = $template
-
-
+
+db_path =
$db_path
+css =
$css_file
+
+
+
+$template_list_html
+
+
+
+
+
+
+Editor
+
template
+
css
+
+
no template loaded yet.
+
+ no CSS loaded yet.
+
+
+
+
no record loaded yet.
-};
+