6 use CGI::Carp qw(fatalsToBrowser);
15 use WebPAC::Output::TT;
17 my $abs_path = abs_path($0);
18 $abs_path =~ s#/[^/]*$#/../#;
20 my $db_path = $abs_path . '/db/';
21 my $template_file = 'html_ffzg.tt';
22 my $css_file = 'user.css';
24 my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8');
25 my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2');
27 my $db = new WebPAC::DB(
33 my $out = new WebPAC::Output::TT(
34 include_path => "$abs_path/conf/output/tt",
35 filters => { foo => sub { shift } },
38 my $q = new CGI::Simple;
39 my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 );
41 my $rec = $q->param('rec') || 1;
43 print $q->header( -charset => 'utf-8' );
45 ##---- some handy subs
48 my ($path, $content) = @_;
50 $content = $iconv_loc->convert( $content ) || die "no content?";
53 my $t = shift || return;
54 return $iconv_loc->convert(chr(hex($t)));
56 $content =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex;
57 $content =~ s/^[\n\r]+//s;
58 $content =~ s/[\n\r]+$//s;
60 write_file($path . '.new', $content) || die "can't save ${path}.new $!";
61 rename $path . '.new', $path || die "can't rename to $path: $!";
64 sub get_file_in_html($) {
67 die "no path?" unless ($path);
69 my $content = read_file($path) || die "can't read $path: $!";
70 $content = $q->escapeHTML($iconv_utf8->convert($content));
77 if ($q->path_info =~ m#xml#) {
79 my @ds = $db->load_ds($rec);
81 if (@ds && $#ds > 0) {
83 <action type='html' target='div_record' errorCode='' errorMessage='' >
84 }, $iconv_utf8->convert( $out->apply(
85 template => $template_file,
90 <action type='javascript' errorCode='' errorMessage='' >
92 var el = iwfGetById('div_record_nr');
93 if (el) el.innerHTML = '# <b>$rec</b>';
94 //iwfShow('div_record');
95 iwfOpacity('div_record', 100);
103 <action type='html' target='div_record' errorCode='' errorMessage='' >
105 <b>Record $rec not found!</b>
107 <action type='javascript' errorCode='' errorMessage='' >
109 var el = iwfGetById('div_record_nr');
110 if (el) el.innerHTML = '<strike> $rec </strike>';
118 } elsif ($q->path_info =~ m#template#) {
120 my $template_path = $out->{'include_path'} . '/' . $template_file;
122 if ($q->param('save_template')) {
124 update_file($template_path, $q->param('tt_template'));
127 <action type='html' target='div_template_status' errorCode='' errorMessage='' >
128 <tt>$template_file</tt> saved
132 iwfShow('div_template_status', 1);
134 iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
143 my $tmpl = get_file_in_html($template_path);
146 <action type='html' target='div_template' errorCode='' errorMessage='' >
148 <form name="frmEditor" action="$self" method="post" iwfTarget="div_template_status" >
150 <textarea name="tt_template" cols="80" rows="10" style="display: block;">
155 <input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
157 <input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin
159 <span id="div_template_status" style="color: #808080;">idle</span>
161 <input type='hidden' value='hidden post value' name='hidValue' />
167 iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
175 } elsif ($q->path_info =~ m#css#) {
177 my $css_path = $abs_path . '/web/' . $css_file;
180 if ($q->param('save_css')) {
181 update_file($css_path, $q->param('user_css'));
184 <action type='html' target='div_css_status' errorCode='' errorMessage='' >
185 <tt>$css_file</tt> saved
189 iwfShow('div_css_status', 1);
192 iwfLog('loading user.css?'+css_rnd);
193 iwfGetById('user_css_link').href = 'user.css?'+css_rnd;
194 iwfHideGentlyDelay('div_css_status', 2, 2000, 1);
203 my $user_css = get_file_in_html($css_path);
206 <action type='html' target='div_css' errorCode='' errorMessage='' >
208 <form name="frmCSSEditor" action="$self" method="post" iwfTarget="div_css_status" >
210 <textarea name="user_css" cols="80" rows="10" style="display: block; width: 100%;">
215 <input type="button" name="save_css" value="Save" onclick="javascript:iwfRequest(this);" />
216 <span id="div_css_status" style="color: #808080;">idle</span>
221 iwfLog('loaded CSS template');
230 print <<"_END_OF_HEAD_";
233 <title>WebPAC simple browse interface</title>
235 <link id="user_css_link" href="user.css" type="text/css" rel="stylesheet">
237 <script type='text/javascript' src='iwf/iwfcore.js'></script>
238 <script type='text/javascript' src='iwf/iwfgui.js'></script>
239 <script type='text/javascript' src='iwf/iwfxml.js'></script>
240 <script type='text/javascript' src='iwf/iwfajax.js'></script>
241 <script type='text/javascript' src='iwf/iwconfig.js'></script>
242 <script type='text/javascript'>
249 function update_status(text) {
250 var el = iwfGetById('div_record_nr');
251 if (el) el.innerHTML = text;
254 function load_rec(nr) {
256 iwfHide('a_left_arr', 1);
258 iwfShow('a_left_arr', 1);
260 update_status(nr+'...');
261 iwfRequest( url+'/xml/?rec='+nr, 'div_record' );
262 iwfOpacity('div_record', 30);
279 function reload_rec() {
284 function edit_template() {
285 iwfHideGently('div_css', 30, 1);
286 iwfShowGently('div_template', 30, 1);
290 function edit_css() {
291 iwfHideGently('div_template', 30, 1);
292 iwfShowGently('div_css', 30, 1);
296 function init_page() {
297 iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
298 iwfLog('div_template = ' + iwfX('div_template') + ':' + iwfY('div_template'));
300 iwfX('div_css', iwfX('div_template'));
301 iwfY('div_css', iwfY('div_template'));
303 iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css'));
307 // load template editor
308 iwfRequest( url+'/template/', 'div_template' );
310 iwfRequest( url+'/css/', 'div_css' );
316 <body onload="init_page();">
321 db_path = <tt>$db_path</tt><br/>
322 template = <tt>$template_file</tt><br/>
323 css = <tt>$css_file</tt>
325 <div style="background: #e0e0e0; padding: 0.5em; display: block;">
326 <a id="a_left_arr" href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">⇦</a>
327 <span id="div_record_nr"> none </span>
329 <a id="a_right_arr" href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">⇨</a>
330 <a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">↺</a>
331 <a href="#" onClick="iwfShowLog(); return false;">▤</a>
337 <div style="display: block;">
339 <a id="a_template" href="#" onClick="return edit_template();">template</a>
340 <a id="a_css" href="#" onClick="return edit_css();">css</a>
342 <div id="div_template">
343 <span style="color: #808080;"> no template loaded yet. </span>
346 <div id="div_css" style="position: absolute; display: none;">
347 <span style="color: #808080;"> no CSS loaded yet. </span>
352 <div id="div_record" style="display: block;">
353 <span style="color: #808080;"> no record loaded yet. </span>