18 |
$abs_path =~ s#/[^/]*$#/../#; |
$abs_path =~ s#/[^/]*$#/../#; |
19 |
|
|
20 |
my $db_path = $abs_path . '/db/'; |
my $db_path = $abs_path . '/db/'; |
21 |
my $template = 'html_ffzg.tt'; |
my $template_path = "$abs_path/conf/output/tt"; |
22 |
|
opendir(my $dir, $template_path) || die "can't open template path $template_path: $!"; |
23 |
|
my @templates = grep { /\.tt$/i } readdir($dir); |
24 |
|
my $css_file = 'user.css'; |
25 |
|
|
26 |
my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8'); |
my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8'); |
27 |
my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2'); |
my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2'); |
33 |
); |
); |
34 |
|
|
35 |
my $out = new WebPAC::Output::TT( |
my $out = new WebPAC::Output::TT( |
36 |
include_path => "$abs_path/conf/output/tt", |
include_path => $template_path, |
37 |
filters => { foo => sub { shift } }, |
filters => { foo => sub { shift } }, |
38 |
); |
); |
39 |
|
|
41 |
my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 ); |
my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 ); |
42 |
|
|
43 |
my $rec = $q->param('rec') || 1; |
my $rec = $q->param('rec') || 1; |
44 |
|
my $template_filename = $q->param('template') || $templates[0]; |
45 |
|
|
46 |
print $q->header( -charset => 'utf-8' ); |
print $q->header( -charset => 'utf-8' ); |
47 |
|
|
48 |
|
##---- some handy subs |
49 |
|
|
50 |
|
sub update_file($$) { |
51 |
|
my ($path, $content) = @_; |
52 |
|
|
53 |
|
$content = $iconv_loc->convert( $content ) || die "no content?"; |
54 |
|
|
55 |
|
sub _conv_js { |
56 |
|
my $t = shift || return; |
57 |
|
return $iconv_loc->convert(chr(hex($t))); |
58 |
|
} |
59 |
|
$content =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex; |
60 |
|
$content =~ s/^[\n\r]+//s; |
61 |
|
$content =~ s/[\n\r]+$//s; |
62 |
|
|
63 |
|
write_file($path . '.new', $content) || die "can't save ${path}.new $!"; |
64 |
|
rename $path . '.new', $path || die "can't rename to $path: $!"; |
65 |
|
} |
66 |
|
|
67 |
|
sub get_file_in_html($) { |
68 |
|
my ($path) = @_; |
69 |
|
|
70 |
|
die "no path?" unless ($path); |
71 |
|
|
72 |
|
my $content = read_file($path) || die "can't read $path: $!"; |
73 |
|
$content = $q->escapeHTML($iconv_utf8->convert($content)); |
74 |
|
|
75 |
|
return $content; |
76 |
|
} |
77 |
|
|
78 |
|
##---- |
79 |
|
|
80 |
if ($q->path_info =~ m#xml#) { |
if ($q->path_info =~ m#xml#) { |
81 |
|
|
82 |
my @ds = $db->load_ds($rec); |
my $ds = $db->load_ds($rec); |
83 |
|
|
84 |
if (@ds && $#ds > 0) { |
if ($ds) { |
85 |
print qq{<response> |
print qq{<response> |
86 |
<action type='html' target='div_record' errorCode='' errorMessage='' > |
<action type='html' target='div_record' errorCode='' errorMessage='' > |
87 |
}, $out->apply( |
}, $iconv_utf8->convert( $out->apply( |
88 |
template => $template, |
template => $template_filename, |
89 |
data => \@ds, |
data => $ds, |
90 |
), qq{ |
) ), qq{ |
91 |
|
|
92 |
<script type='text/javascript'> |
</action> |
93 |
|
<action type='javascript' errorCode='' errorMessage='' > |
94 |
<!-- |
<!-- |
95 |
var el = iwfGetById('div_record_nr'); |
var el = iwfGetById('div_record_nr'); |
96 |
if (el) el.innerHTML = '# <b>$rec</b>'; |
if (el) el.innerHTML = '# <b>$rec</b>'; |
97 |
//iwfShow('div_record'); |
//iwfShow('div_record'); |
98 |
iwfOpacity('div_record', 100); |
iwfOpacity('div_record', 100); |
99 |
//--> |
//--> |
|
</script> |
|
|
|
|
100 |
</action> |
</action> |
101 |
</response> |
</response> |
102 |
}; |
}; |
106 |
<action type='html' target='div_record' errorCode='' errorMessage='' > |
<action type='html' target='div_record' errorCode='' errorMessage='' > |
107 |
|
|
108 |
<b>Record $rec not found!</b> |
<b>Record $rec not found!</b> |
109 |
<script type='text/javascript'> |
</action> |
110 |
|
<action type='javascript' errorCode='' errorMessage='' > |
111 |
<!-- |
<!-- |
112 |
var el = iwfGetById('div_record_nr'); |
var el = iwfGetById('div_record_nr'); |
113 |
if (el) el.innerHTML = '<strike>$rec</strike>'; |
if (el) el.innerHTML = '<strike> $rec </strike>'; |
114 |
//--> |
//--> |
|
</script> |
|
|
|
|
115 |
</action> |
</action> |
116 |
</response> |
</response> |
117 |
}; |
}; |
120 |
|
|
121 |
} elsif ($q->path_info =~ m#template#) { |
} elsif ($q->path_info =~ m#template#) { |
122 |
|
|
123 |
my @actions; |
my $template_path = $out->{'include_path'} . '/' . $template_filename; |
124 |
|
|
125 |
if ($q->param('save_template')) { |
if ($q->param('save_template')) { |
126 |
|
|
127 |
my $tmpl = $q->param('tt_template') || die "no template?"; |
update_file($template_path, $q->param('tt_template')); |
|
my $tmpl_file = $out->{'include_path'} . '/' . $template; |
|
|
write_file($tmpl_file . '.new', $iconv_loc->convert($tmpl)) || die "can't save $tmpl_file: $!"; |
|
|
rename $tmpl_file . '.new', $tmpl_file || die "can't rename to $tmpl_file: $!"; |
|
128 |
|
|
129 |
print qq{<response> |
print qq{<response> |
130 |
<action type='html' target='div_status' errorCode='' errorMessage='' > |
<action type='html' target='div_template_status' errorCode='' errorMessage='' > |
131 |
$template saved |
<tt>$template_filename</tt> saved |
132 |
</action> |
</action> |
133 |
<action type='js'> |
<action type='js'> |
134 |
<!-- |
<!-- |
135 |
|
iwfShow('div_template_status', 1); |
136 |
reload_rec(); |
reload_rec(); |
137 |
|
iwfHideGentlyDelay('div_template_status', 2, 2000, 1); |
138 |
--> |
--> |
139 |
</action> |
</action> |
140 |
</response> |
</response> |
143 |
|
|
144 |
} |
} |
145 |
|
|
146 |
my $tmpl = read_file($out->{'include_path'} . '/' . $template) || die "can't read template $template: $!"; |
my $tmpl = get_file_in_html($template_path); |
|
$tmpl = $q->escapeHTML($iconv_utf8->convert($tmpl)); |
|
147 |
|
|
148 |
print qq{<response> |
print qq{<response> |
149 |
<action type='html' target='div_template' errorCode='' errorMessage='' > |
<action type='html' target='div_template' errorCode='' errorMessage='' > |
|
<pre>}, Dumper($q->Vars), qq{</pre> |
|
150 |
|
|
151 |
<form name="frmEditor" action="$self" method="post" |
<form name="frmEditor" action="$self" method="post" iwfTarget="div_template_status" > |
|
iwfTarget="div_status" |
|
|
> |
|
152 |
|
|
153 |
<textarea name="tt_template" cols="80" rows="10" style="display: block;"> |
<textarea name="tt_template" cols="80" rows="10" style="display: block;"> |
154 |
$tmpl |
$tmpl |
156 |
|
|
157 |
<br/> |
<br/> |
158 |
<input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" /> |
<input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" /> |
159 |
<input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> |
<!-- |
160 |
<span id="div_status" style="color: #808080;">idle</span> |
<input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin |
161 |
|
--> |
162 |
|
<span id="div_template_status" style="color: #808080;">idle</span> |
163 |
|
|
164 |
|
<input type="hidden" name="template" value="$template_filename" /> |
165 |
|
|
166 |
|
</form> |
167 |
|
</action> |
168 |
|
<action type='js'> |
169 |
|
<!-- |
170 |
|
iwfHideGentlyDelay('div_template_status', 2, 2000, 1); |
171 |
|
--> |
172 |
|
</action> |
173 |
|
</response> |
174 |
|
}; |
175 |
|
|
176 |
|
exit; |
177 |
|
|
178 |
|
} elsif ($q->path_info =~ m#css#) { |
179 |
|
|
180 |
|
my $css_path = $abs_path . '/web/' . $css_file; |
181 |
|
|
182 |
|
|
183 |
|
if ($q->param('save_css')) { |
184 |
|
update_file($css_path, $q->param('user_css')); |
185 |
|
|
186 |
|
print qq{<response> |
187 |
|
<action type='html' target='div_css_status' errorCode='' errorMessage='' > |
188 |
|
<tt>$css_file</tt> saved |
189 |
|
</action> |
190 |
|
<action type='js'> |
191 |
|
<!-- |
192 |
|
iwfShow('div_css_status', 1); |
193 |
|
// switch css |
194 |
|
css_rnd++; |
195 |
|
iwfLog('loading user.css?'+css_rnd); |
196 |
|
iwfGetById('user_css_link').href = 'user.css?'+css_rnd; |
197 |
|
iwfHideGentlyDelay('div_css_status', 2, 2000, 1); |
198 |
|
--> |
199 |
|
</action> |
200 |
|
</response> |
201 |
|
}; |
202 |
|
exit; |
203 |
|
|
204 |
|
} |
205 |
|
|
206 |
|
my $user_css = get_file_in_html($css_path); |
207 |
|
|
208 |
|
print qq{<response> |
209 |
|
<action type='html' target='div_css' errorCode='' errorMessage='' > |
210 |
|
|
211 |
|
<form name="frmCSSEditor" action="$self" method="post" iwfTarget="div_css_status" > |
212 |
|
|
213 |
<input type='hidden' value='hidden post value' name='hidValue' /> |
<textarea name="user_css" cols="80" rows="10" style="display: block; width: 100%;"> |
214 |
|
$user_css |
215 |
|
</textarea> |
216 |
|
|
217 |
|
<br/> |
218 |
|
<input type="button" name="save_css" value="Save" onclick="javascript:iwfRequest(this);" /> |
219 |
|
<span id="div_css_status" style="color: #808080;">idle</span> |
220 |
</form> |
</form> |
221 |
</action> |
</action> |
222 |
|
<action type='js'> |
223 |
|
<!-- |
224 |
|
iwfLog('loaded CSS template'); |
225 |
|
--> |
226 |
|
</action> |
227 |
</response> |
</response> |
228 |
}; |
}; |
229 |
|
|
230 |
exit; |
exit; |
231 |
|
|
232 |
} else { |
} else { |
233 |
print qq{ |
|
234 |
|
my $template_form = qq{ |
235 |
|
<form action="$self" method="get" style="display: inline;"> |
236 |
|
<select name="template"> |
237 |
|
}; |
238 |
|
foreach my $t (@templates) { |
239 |
|
my $s = ''; |
240 |
|
$s = ' selected' if ($t eq $template_filename); |
241 |
|
$template_form .= qq{<option$s>$t</option>}; |
242 |
|
} |
243 |
|
$template_form .= qq{ |
244 |
|
</select> |
245 |
|
<input type="submit" name="ch_template" value="Switch"/> |
246 |
|
</form> |
247 |
|
}; |
248 |
|
|
249 |
|
print <<"_END_OF_HEAD_"; |
250 |
<html> |
<html> |
251 |
<head> |
<head> |
252 |
<title>WebPAC simple browse interface</title> |
<title>WebPAC simple browse interface</title> |
253 |
|
|
254 |
|
<link id="user_css_link" href="user.css" type="text/css" rel="stylesheet"> |
255 |
|
|
256 |
<script type='text/javascript' src='iwf/iwfcore.js'></script> |
<script type='text/javascript' src='iwf/iwfcore.js'></script> |
257 |
<script type='text/javascript' src='iwf/iwfgui.js'></script> |
<script type='text/javascript' src='iwf/iwfgui.js'></script> |
258 |
<script type='text/javascript' src='iwf/iwfxml.js'></script> |
<script type='text/javascript' src='iwf/iwfxml.js'></script> |
259 |
<script type='text/javascript' src='iwf/iwfajax.js'></script> |
<script type='text/javascript' src='iwf/iwfajax.js'></script> |
260 |
|
<script type='text/javascript' src='iwf/iwconfig.js'></script> |
261 |
<script type='text/javascript'> |
<script type='text/javascript'> |
262 |
|
|
263 |
var rec = $rec ; |
var rec = $rec ; |
264 |
var url = '$self'; |
var url = '$self'; |
265 |
|
var template_filename = '$template_filename'; |
266 |
|
|
267 |
|
var css_rnd = 0; |
268 |
|
|
269 |
function update_status(text) { |
function update_status(text) { |
270 |
var el = iwfGetById('div_record_nr'); |
var el = iwfGetById('div_record_nr'); |
272 |
} |
} |
273 |
|
|
274 |
function load_rec(nr) { |
function load_rec(nr) { |
275 |
|
if (nr == 1) { |
276 |
|
iwfHide('a_left_arr', 1); |
277 |
|
} else { |
278 |
|
iwfShow('a_left_arr', 1); |
279 |
|
} |
280 |
update_status(nr+'...'); |
update_status(nr+'...'); |
281 |
iwfRequest( url+'/xml/?rec='+nr, 'div_record' ); |
iwfRequest( url+'/xml/?template='+template_filename+'&rec='+nr, 'div_record' ); |
282 |
iwfOpacity('div_record', 30); |
iwfOpacity('div_record', 30); |
283 |
} |
} |
284 |
|
|
289 |
} |
} |
290 |
|
|
291 |
function dec_rec() { |
function dec_rec() { |
292 |
rec--; |
if (rec > 1) { |
293 |
load_rec(rec); |
rec--; |
294 |
|
load_rec(rec); |
295 |
|
} |
296 |
return false; |
return false; |
297 |
} |
} |
298 |
|
|
301 |
return false; |
return false; |
302 |
} |
} |
303 |
|
|
304 |
|
function edit_template() { |
305 |
|
iwfHideGently('div_css', 30, 1); |
306 |
|
iwfShowGently('div_template', 30, 1); |
307 |
|
return false; |
308 |
|
} |
309 |
|
|
310 |
|
function edit_css() { |
311 |
|
iwfHideGently('div_template', 30, 1); |
312 |
|
iwfShowGently('div_css', 30, 1); |
313 |
|
return false; |
314 |
|
} |
315 |
|
|
316 |
function init_page() { |
function init_page() { |
317 |
|
iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css')); |
318 |
|
iwfLog('div_template = ' + iwfX('div_template') + ':' + iwfY('div_template')); |
319 |
|
|
320 |
|
iwfX('div_css', iwfX('div_template')); |
321 |
|
iwfY('div_css', iwfY('div_template')); |
322 |
|
|
323 |
|
iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css')); |
324 |
|
|
325 |
load_rec(rec); |
load_rec(rec); |
326 |
// load template |
|
327 |
iwfRequest( url+'/template/', 'div_template' ); |
// load template editor |
328 |
|
iwfRequest( url+'/template/?template='+template_filename, 'div_template' ); |
329 |
|
// load css editor |
330 |
|
iwfRequest( url+'/css/', 'div_css' ); |
331 |
} |
} |
332 |
|
|
333 |
</script> |
</script> |
334 |
|
|
335 |
</head> |
</head> |
336 |
<body onload="init_page();"> |
<body onload="init_page();"> |
337 |
|
|
338 |
db_path = <tt>$db_path</tt><br/> |
<div id="iwfLog"> |
|
template = <tt>$template</tt><br/> |
|
|
|
|
|
<div id="iwfLog" style="display: none;"> |
|
339 |
</div> |
</div> |
340 |
|
|
341 |
|
db_path = <tt>$db_path</tt><br/> |
342 |
|
template = $template_form<br/> |
343 |
|
css = <tt>$css_file</tt> |
344 |
|
|
345 |
<div style="background: #e0e0e0; padding: 0.5em; display: block;"> |
<div style="background: #e0e0e0; padding: 0.5em; display: block;"> |
346 |
<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> |
347 |
<span id="div_record_nr"> none </span> |
<span id="div_record_nr"> none </span> |
348 |
|
|
349 |
<a href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">⇨</a> |
<a id="a_right_arr" href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">⇨</a> |
350 |
<a href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">↺</a> |
<a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">↺</a> |
351 |
<a href="#" onClick="iwfRefreshLog(); return false;">▤</a> |
<a href="#" onClick="iwfShowLog(); return false;">▤</a> |
352 |
|
|
353 |
</div> |
</div> |
354 |
|
|
355 |
|
<div> |
356 |
|
|
357 |
|
<div style="display: block;"> |
358 |
|
Editor |
359 |
|
<a id="a_template" href="#" onClick="return edit_template();">template</a> |
360 |
|
<a id="a_css" href="#" onClick="return edit_css();">css</a> |
361 |
|
|
362 |
<div id="div_template"> |
<div id="div_template"> |
363 |
<span style="color: #808080;"> no template loaded yet. </span> |
<span style="color: #808080;"> no template loaded yet. </span> |
364 |
</div> |
</div> |
365 |
|
|
366 |
|
<div id="div_css" style="position: absolute; display: none;"> |
367 |
|
<span style="color: #808080;"> no CSS loaded yet. </span> |
368 |
|
</div> |
369 |
|
|
370 |
|
</div> |
371 |
|
|
372 |
<div id="div_record" style="display: block;"> |
<div id="div_record" style="display: block;"> |
373 |
<span style="color: #808080;"> no record loaded yet. </span> |
<span style="color: #808080;"> no record loaded yet. </span> |
374 |
</div> |
</div> |
375 |
|
|
376 |
|
|
377 |
</body> |
</body> |
378 |
</html>}; |
</html> |
379 |
|
_END_OF_HEAD_ |
380 |
|
|
381 |
}; |
} |