#!/usr/bin/perl -w
+use strict;
+
use Cwd qw/abs_path/;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Simple;
use File::Slurp;
+use Data::Dumper;
+use Text::Iconv;
use lib '../lib';
my $db_path = $abs_path . '/db/';
my $template = 'html_ffzg.tt';
+my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8');
+my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2');
+
my $db = new WebPAC::DB(
path => $db_path,
read_only => 1,
my $rec = $q->param('rec') || 1;
-print $q->header;
+print $q->header( -charset => 'utf-8' );
if ($q->path_info =~ m#xml#) {
if (@ds && $#ds > 0) {
print qq{<response>
<action type='html' target='div_record' errorCode='' errorMessage='' >
- }, $out->apply(
+ }, $iconv_utf8->convert( $out->apply(
template => $template,
data => \@ds,
- ), qq{
+ ) ), qq{
-<script type='text/javascript'>
+</action>
+<action type='javascript' errorCode='' errorMessage='' >
<!--
var el = iwfGetById('div_record_nr');
if (el) el.innerHTML = '# <b>$rec</b>';
//iwfShow('div_record');
iwfOpacity('div_record', 100);
//-->
-</script>
-
</action>
</response>
};
<action type='html' target='div_record' errorCode='' errorMessage='' >
<b>Record $rec not found!</b>
-<script type='text/javascript'>
+</action>
+<action type='javascript' errorCode='' errorMessage='' >
<!--
var el = iwfGetById('div_record_nr');
- if (el) el.innerHTML = '<strike>$rec</strike>';
+ if (el) el.innerHTML = '<strike> $rec </strike>';
//-->
-</script>
-
</action>
</response>
};
} elsif ($q->path_info =~ m#template#) {
- my $tmpl = read_file($out->{'include_path'} . '/' . $template);
- $tmpl = $q->escapeHTML($tmpl);
+ my @actions;
+
+ 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;
+
+ 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: $!";
+
+ print qq{<response>
+<action type='html' target='div_status' errorCode='' errorMessage='' >
+<tt>$template</tt> saved
+</action>
+<action type='js'>
+<!--
+iwfShow('div_status', 1);
+reload_rec();
+iwfHideGentlyDelay('div_status', 2, 2000, 1);
+-->
+</action>
+</response>
+ };
+ exit;
+
+ }
+
+ my $tmpl = read_file($out->{'include_path'} . '/' . $template) || die "can't read template $template: $!";
+ $tmpl = $q->escapeHTML($iconv_utf8->convert($tmpl));
print qq{<response>
<action type='html' target='div_template' errorCode='' errorMessage='' >
-<textarea name="tt_template" cols="80" rows="10">
+<pre>}, Dumper($q->Vars), qq{</pre>
+
+<form name="frmEditor" action="$self" method="post" iwfTarget="div_status" >
+
+<textarea name="tt_template" cols="80" rows="10" style="display: block;">
$tmpl
</textarea>
-<br/><input type="button" name="save" value="Save">
+
+<br/>
+<input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
+<!--
+<input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin
+-->
+ <span id="div_status" style="color: #808080;">idle</span>
+
+<input type='hidden' value='hidden post value' name='hidValue' />
+
+</form>
+</action>
+<action type='js'>
+<!--
+iwfHideGentlyDelay('div_status', 2, 2000, 1);
+-->
</action>
</response>
-};
+ };
+
+ exit;
} else {
print qq{
}
function load_rec(nr) {
+ if (nr == 1) {
+ iwfHide('a_left_arr', 1);
+ } else {
+ iwfShow('a_left_arr', 1);
+ }
update_status(nr+'...');
iwfRequest( url+'/xml/?rec='+nr, 'div_record' );
iwfOpacity('div_record', 30);
}
function dec_rec() {
- rec--;
- load_rec(rec);
+ if (rec > 1) {
+ rec--;
+ load_rec(rec);
+ }
return false;
}
<body onload="init_page();">
db_path = <tt>$db_path</tt><br/>
+template = <tt>$template</tt><br/>
<div id="iwfLog" style="display: none;">
</div>
<div style="background: #e0e0e0; padding: 0.5em; display: block;">
- <a href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">⇦</a>
+ <a id="a_left_arr" href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">⇦</a>
<span id="div_record_nr"> none </span>
- <a href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">⇨</a>
- <a href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">↺</a>
- <a href="#" onClick="iwfRefreshLog(); return false;">▤</a>
+ <a id="a_right_arr" href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">⇨</a>
+ <a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">↺</a>
+ <a href="#" onClick="iwfRefreshLog(); return false;">▤</a>
+
</div>
<div id="div_template">