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 |
|
sub template_list_html($) { |
79 |
|
my $current = shift || die; |
80 |
|
|
81 |
|
my $html = qq{ Template\n<ul> }; |
82 |
|
|
83 |
|
foreach my $t (sort @templates) { |
84 |
|
if ($t eq $current) { |
85 |
|
$html .= qq{ <li><b>$t</b></li> }; |
86 |
|
} else { |
87 |
|
$html .= qq{ <li><a href="#" onClick="load_template('$t'); return false;">$t</a></li> }; |
88 |
|
} |
89 |
|
} |
90 |
|
|
91 |
|
$html .= qq{ </ul> }; |
92 |
|
return $html; |
93 |
|
} |
94 |
|
|
95 |
|
##---- |
96 |
|
|
97 |
if ($q->path_info =~ m#xml#) { |
if ($q->path_info =~ m#xml#) { |
98 |
|
|
99 |
my @ds = $db->load_ds($rec); |
my $ds = $db->load_ds($rec); |
100 |
|
|
101 |
if (@ds && $#ds > 0) { |
if ($ds) { |
102 |
print qq{<response> |
print qq{<response> |
103 |
<action type='html' target='div_record' errorCode='' errorMessage='' > |
<action type='html' target='div_record' errorCode='' errorMessage='' > |
104 |
}, $iconv_utf8->convert( $out->apply( |
}, $iconv_utf8->convert( $out->apply( |
105 |
template => $template, |
template => $template_filename, |
106 |
data => \@ds, |
data => $ds, |
107 |
) ), qq{ |
) ), qq{ |
108 |
|
|
109 |
</action> |
</action> |
135 |
exit; |
exit; |
136 |
} |
} |
137 |
|
|
138 |
|
} elsif ($q->path_info =~ m#template_list#) { |
139 |
|
|
140 |
|
print qq{<response> |
141 |
|
<action type='html' target='div_template_list' errorCode='' errorMessage='' > |
142 |
|
<div>} . template_list_html($template_filename) . qq{</div> |
143 |
|
</action> |
144 |
|
</response> |
145 |
|
}; |
146 |
|
|
147 |
|
exit; |
148 |
|
|
149 |
} elsif ($q->path_info =~ m#template#) { |
} elsif ($q->path_info =~ m#template#) { |
150 |
|
|
151 |
my @actions; |
my $template_path = $out->{'include_path'} . '/' . $template_filename; |
152 |
|
|
153 |
if ($q->param('save_template')) { |
if ($q->param('save_template')) { |
154 |
|
|
155 |
my $tmpl = $iconv_loc->convert( $q->param('tt_template') ) || die "no template?"; |
update_file($template_path, $q->param('tt_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: $!"; |
|
156 |
|
|
157 |
print qq{<response> |
print qq{<response> |
158 |
<action type='html' target='div_status' errorCode='' errorMessage='' > |
<action type='html' target='div_template_status' errorCode='' errorMessage='' > |
159 |
$template saved |
<tt>$template_filename</tt> saved |
160 |
</action> |
</action> |
161 |
<action type='js'> |
<action type='js'> |
162 |
<!-- |
<!-- |
163 |
|
iwfShow('div_template_status', 1); |
164 |
reload_rec(); |
reload_rec(); |
165 |
|
iwfHideGentlyDelay('div_template_status', 2, 2000, 1); |
166 |
--> |
--> |
167 |
</action> |
</action> |
168 |
</response> |
</response> |
171 |
|
|
172 |
} |
} |
173 |
|
|
174 |
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)); |
|
175 |
|
|
176 |
print qq{<response> |
print qq{<response> |
177 |
<action type='html' target='div_template' errorCode='' errorMessage='' > |
<action type='html' target='div_template' errorCode='' errorMessage='' > |
|
<pre>}, Dumper($q->Vars), qq{</pre> |
|
178 |
|
|
179 |
<form name="frmEditor" action="$self" method="post" |
<form name="frmEditor" action="$self" method="post" iwfTarget="div_template_status" > |
|
iwfTarget="div_status" |
|
|
> |
|
180 |
|
|
181 |
<textarea name="tt_template" cols="80" rows="10" style="display: block;"> |
<textarea name="tt_template" cols="80" rows="10" style="display: block;"> |
182 |
$tmpl |
$tmpl |
184 |
|
|
185 |
<br/> |
<br/> |
186 |
<input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" /> |
<input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" /> |
187 |
<input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> |
<!-- |
188 |
<span id="div_status" style="color: #808080;">idle</span> |
<input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin |
189 |
|
--> |
190 |
|
<span id="div_template_status" style="color: #808080;">idle</span> |
191 |
|
|
192 |
|
<input type="hidden" name="template" value="$template_filename" /> |
193 |
|
|
194 |
|
</form> |
195 |
|
</action> |
196 |
|
<action type='js'> |
197 |
|
<!-- |
198 |
|
iwfOpacity('div_template', 100); |
199 |
|
iwfHideGentlyDelay('div_template_status', 2, 2000, 1); |
200 |
|
--> |
201 |
|
</action> |
202 |
|
</response> |
203 |
|
}; |
204 |
|
|
205 |
|
exit; |
206 |
|
|
207 |
|
} elsif ($q->path_info =~ m#css#) { |
208 |
|
|
209 |
|
my $css_path = $abs_path . '/web/' . $css_file; |
210 |
|
|
211 |
|
|
212 |
|
if ($q->param('save_css')) { |
213 |
|
update_file($css_path, $q->param('user_css')); |
214 |
|
|
215 |
|
print qq{<response> |
216 |
|
<action type='html' target='div_css_status' errorCode='' errorMessage='' > |
217 |
|
<tt>$css_file</tt> saved |
218 |
|
</action> |
219 |
|
<action type='js'> |
220 |
|
<!-- |
221 |
|
iwfShow('div_css_status', 1); |
222 |
|
// switch css |
223 |
|
css_rnd++; |
224 |
|
iwfLog('loading user.css?'+css_rnd); |
225 |
|
iwfGetById('user_css_link').href = 'user.css?'+css_rnd; |
226 |
|
iwfHideGentlyDelay('div_css_status', 2, 2000, 1); |
227 |
|
--> |
228 |
|
</action> |
229 |
|
</response> |
230 |
|
}; |
231 |
|
exit; |
232 |
|
|
233 |
|
} |
234 |
|
|
235 |
|
my $user_css = get_file_in_html($css_path); |
236 |
|
|
237 |
|
print qq{<response> |
238 |
|
<action type='html' target='div_css' errorCode='' errorMessage='' > |
239 |
|
|
240 |
|
<form name="frmCSSEditor" action="$self" method="post" iwfTarget="div_css_status" > |
241 |
|
|
242 |
<input type='hidden' value='hidden post value' name='hidValue' /> |
<textarea name="user_css" cols="80" rows="10" style="display: block; width: 100%;"> |
243 |
|
$user_css |
244 |
|
</textarea> |
245 |
|
|
246 |
|
<br/> |
247 |
|
<input type="button" name="save_css" value="Save" onclick="javascript:iwfRequest(this);" /> |
248 |
|
<span id="div_css_status" style="color: #808080;">idle</span> |
249 |
</form> |
</form> |
250 |
</action> |
</action> |
251 |
|
<action type='js'> |
252 |
|
<!-- |
253 |
|
iwfLog('loaded CSS template'); |
254 |
|
--> |
255 |
|
</action> |
256 |
</response> |
</response> |
257 |
}; |
}; |
258 |
|
|
259 |
exit; |
exit; |
260 |
|
|
261 |
} else { |
} else { |
262 |
print qq{ |
|
263 |
|
my $template_list_html = template_list_html($template_filename); |
264 |
|
|
265 |
|
print <<"_END_OF_HEAD_"; |
266 |
<html> |
<html> |
267 |
<head> |
<head> |
268 |
<title>WebPAC simple browse interface</title> |
<title>WebPAC simple browse interface</title> |
269 |
|
|
270 |
|
<link id="user_css_link" href="user.css" type="text/css" rel="stylesheet"> |
271 |
|
|
272 |
<script type='text/javascript' src='iwf/iwfcore.js'></script> |
<script type='text/javascript' src='iwf/iwfcore.js'></script> |
273 |
<script type='text/javascript' src='iwf/iwfgui.js'></script> |
<script type='text/javascript' src='iwf/iwfgui.js'></script> |
274 |
<script type='text/javascript' src='iwf/iwfxml.js'></script> |
<script type='text/javascript' src='iwf/iwfxml.js'></script> |
275 |
<script type='text/javascript' src='iwf/iwfajax.js'></script> |
<script type='text/javascript' src='iwf/iwfajax.js'></script> |
276 |
|
<script type='text/javascript' src='iwf/iwconfig.js'></script> |
277 |
<script type='text/javascript'> |
<script type='text/javascript'> |
278 |
|
|
279 |
var rec = $rec ; |
var rec = $rec ; |
280 |
var url = '$self'; |
var url = '$self'; |
281 |
|
var template_filename = '$template_filename'; |
282 |
|
|
283 |
|
var css_rnd = 0; |
284 |
|
|
285 |
function update_status(text) { |
function update_status(text) { |
286 |
var el = iwfGetById('div_record_nr'); |
var el = iwfGetById('div_record_nr'); |
294 |
iwfShow('a_left_arr', 1); |
iwfShow('a_left_arr', 1); |
295 |
} |
} |
296 |
update_status(nr+'...'); |
update_status(nr+'...'); |
297 |
iwfRequest( url+'/xml/?rec='+nr, 'div_record' ); |
iwfRequest( url+'/xml/?template='+template_filename+'&rec='+nr, 'div_record' ); |
298 |
iwfOpacity('div_record', 30); |
iwfOpacity('div_record', 30); |
299 |
} |
} |
300 |
|
|
317 |
return false; |
return false; |
318 |
} |
} |
319 |
|
|
320 |
function init_page() { |
function edit_template() { |
321 |
|
iwfHideGently('div_css', 30, 1); |
322 |
|
iwfShowGently('div_template', 30, 1); |
323 |
|
return false; |
324 |
|
} |
325 |
|
|
326 |
|
function edit_css() { |
327 |
|
iwfHideGently('div_template', 30, 1); |
328 |
|
iwfShowGently('div_css', 30, 1); |
329 |
|
return false; |
330 |
|
} |
331 |
|
|
332 |
|
function load_template(name) { |
333 |
|
iwfLog('changing template to '+name); |
334 |
|
iwfOpacity('div_template', 30); |
335 |
|
template_filename = name; |
336 |
|
// load template editor |
337 |
|
iwfRequest( url+'/template/?template='+template_filename, 'div_template' ); |
338 |
load_rec(rec); |
load_rec(rec); |
339 |
// load template |
|
340 |
iwfRequest( url+'/template/', 'div_template' ); |
// refresh template list |
341 |
|
iwfRequest( url+'/template_list/?template='+template_filename, 'div_template_list' ); |
342 |
|
} |
343 |
|
|
344 |
|
function init_page() { |
345 |
|
iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css')); |
346 |
|
iwfLog('div_template = ' + iwfX('div_template') + ':' + iwfY('div_template')); |
347 |
|
|
348 |
|
iwfX('div_css', iwfX('div_template')); |
349 |
|
iwfY('div_css', iwfY('div_template')); |
350 |
|
|
351 |
|
iwfLog('div_css = ' + iwfX('div_css') + ':' + iwfY('div_css')); |
352 |
|
|
353 |
|
// load template editor and record |
354 |
|
load_template(template_filename); |
355 |
|
|
356 |
|
// load css editor |
357 |
|
iwfRequest( url+'/css/', 'div_css' ); |
358 |
} |
} |
359 |
|
|
360 |
</script> |
</script> |
361 |
|
|
362 |
</head> |
</head> |
363 |
<body onload="init_page();"> |
<body onload="init_page();"> |
364 |
|
|
365 |
db_path = <tt>$db_path</tt><br/> |
<div id="iwfLog"> |
|
template = <tt>$template</tt><br/> |
|
|
|
|
|
<div id="iwfLog" style="display: none;"> |
|
366 |
</div> |
</div> |
367 |
|
|
368 |
|
db_path = <tt>$db_path</tt><br/> |
369 |
|
css = <tt>$css_file</tt> |
370 |
|
|
371 |
<div style="background: #e0e0e0; padding: 0.5em; display: block;"> |
<div style="background: #e0e0e0; padding: 0.5em; display: block;"> |
372 |
<a id="a_left_arr" 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> |
373 |
<span id="div_record_nr"> none </span> |
<span id="div_record_nr"> none </span> |
374 |
|
|
375 |
<a id="a_right_arr" 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> |
376 |
<a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">↺</a> |
<a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">↺</a> |
377 |
<a href="#" onClick="iwfRefreshLog(); return false;">▤</a> |
<a href="#" onClick="iwfShowLog(); return false;">▤</a> |
378 |
|
|
379 |
</div> |
</div> |
380 |
|
|
381 |
|
|
382 |
|
<div id="div_template_list" style="display: inline; border: 2px solid #ffcc88; float: right; z-index: 10;"> |
383 |
|
$template_list_html |
384 |
|
</div> |
385 |
|
|
386 |
|
<div> |
387 |
|
|
388 |
|
<div style="border: 2px solid #ffff80;"> |
389 |
|
|
390 |
|
Editor |
391 |
|
<a id="a_template" href="#" onClick="return edit_template();">template</a> |
392 |
|
<a id="a_css" href="#" onClick="return edit_css();">css</a> |
393 |
|
|
394 |
|
|
395 |
<div id="div_template"> |
<div id="div_template"> |
396 |
<span style="color: #808080;"> no template loaded yet. </span> |
<span style="color: #808080;"> no template loaded yet. </span> |
397 |
</div> |
</div> |
398 |
|
|
399 |
|
<div id="div_css" style="position: absolute; display: none;"> |
400 |
|
<span style="color: #808080;"> no CSS loaded yet. </span> |
401 |
|
</div> |
402 |
|
|
403 |
|
</div> |
404 |
|
|
405 |
<div id="div_record" style="display: block;"> |
<div id="div_record" style="display: block;"> |
406 |
<span style="color: #808080;"> no record loaded yet. </span> |
<span style="color: #808080;"> no record loaded yet. </span> |
407 |
</div> |
</div> |
408 |
|
|
409 |
|
|
410 |
</body> |
</body> |
411 |
</html>}; |
</html> |
412 |
|
_END_OF_HEAD_ |
413 |
|
|
414 |
}; |
} |