1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use Cwd qw/abs_path/; |
4 |
use CGI::Carp qw(fatalsToBrowser); |
5 |
use CGI::Simple; |
6 |
use File::Slurp; |
7 |
|
8 |
use lib '../lib'; |
9 |
|
10 |
use WebPAC::DB; |
11 |
use WebPAC::Output::TT; |
12 |
|
13 |
my $abs_path = abs_path($0); |
14 |
$abs_path =~ s#/[^/]*$#/../#; |
15 |
|
16 |
my $db_path = $abs_path . '/db/'; |
17 |
my $template = 'html_ffzg.tt'; |
18 |
|
19 |
my $db = new WebPAC::DB( |
20 |
path => $db_path, |
21 |
read_only => 1, |
22 |
debug => 1, |
23 |
); |
24 |
|
25 |
my $out = new WebPAC::Output::TT( |
26 |
include_path => "$abs_path/conf/output/tt", |
27 |
filters => { foo => sub { shift } }, |
28 |
); |
29 |
|
30 |
my $q = new CGI::Simple; |
31 |
my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 ); |
32 |
|
33 |
my $rec = $q->param('rec') || 1; |
34 |
|
35 |
print $q->header; |
36 |
|
37 |
if ($q->path_info =~ m#xml#) { |
38 |
|
39 |
my @ds = $db->load_ds($rec); |
40 |
|
41 |
if (@ds && $#ds > 0) { |
42 |
print qq{<response> |
43 |
<action type='html' target='div_record' errorCode='' errorMessage='' > |
44 |
}, $out->apply( |
45 |
template => $template, |
46 |
data => \@ds, |
47 |
), qq{ |
48 |
|
49 |
<script type='text/javascript'> |
50 |
<!-- |
51 |
var el = iwfGetById('div_record_nr'); |
52 |
if (el) el.innerHTML = '# <b>$rec</b>'; |
53 |
//iwfShow('div_record'); |
54 |
iwfOpacity('div_record', 100); |
55 |
//--> |
56 |
</script> |
57 |
|
58 |
</action> |
59 |
</response> |
60 |
}; |
61 |
exit; |
62 |
} else { |
63 |
print qq{<response> |
64 |
<action type='html' target='div_record' errorCode='' errorMessage='' > |
65 |
|
66 |
<b>Record $rec not found!</b> |
67 |
<script type='text/javascript'> |
68 |
<!-- |
69 |
var el = iwfGetById('div_record_nr'); |
70 |
if (el) el.innerHTML = '<strike>$rec</strike>'; |
71 |
//--> |
72 |
</script> |
73 |
|
74 |
</action> |
75 |
</response> |
76 |
}; |
77 |
exit; |
78 |
} |
79 |
|
80 |
} elsif ($q->path_info =~ m#template#) { |
81 |
|
82 |
my $tmpl = read_file($out->{'include_path'} . '/' . $template); |
83 |
$tmpl = $q->escapeHTML($tmpl); |
84 |
|
85 |
print qq{<response> |
86 |
<action type='html' target='div_template' errorCode='' errorMessage='' > |
87 |
<textarea name="tt_template" cols="80" rows="10"> |
88 |
$tmpl |
89 |
</textarea> |
90 |
<br/><input type="button" name="save" value="Save"> |
91 |
</action> |
92 |
</response> |
93 |
}; |
94 |
|
95 |
} else { |
96 |
print qq{ |
97 |
<html> |
98 |
<head> |
99 |
<title>WebPAC simple browse interface</title> |
100 |
<script type='text/javascript' src='iwf/iwfcore.js'></script> |
101 |
<script type='text/javascript' src='iwf/iwfgui.js'></script> |
102 |
<script type='text/javascript' src='iwf/iwfxml.js'></script> |
103 |
<script type='text/javascript' src='iwf/iwfajax.js'></script> |
104 |
<script type='text/javascript'> |
105 |
|
106 |
var rec = $rec ; |
107 |
var url = '$self'; |
108 |
|
109 |
function update_status(text) { |
110 |
var el = iwfGetById('div_record_nr'); |
111 |
if (el) el.innerHTML = text; |
112 |
} |
113 |
|
114 |
function load_rec(nr) { |
115 |
update_status(nr+'...'); |
116 |
iwfRequest( url+'/xml/?rec='+nr, 'div_record' ); |
117 |
iwfOpacity('div_record', 30); |
118 |
} |
119 |
|
120 |
function inc_rec() { |
121 |
rec++; |
122 |
load_rec(rec); |
123 |
return false; |
124 |
} |
125 |
|
126 |
function dec_rec() { |
127 |
rec--; |
128 |
load_rec(rec); |
129 |
return false; |
130 |
} |
131 |
|
132 |
function reload_rec() { |
133 |
load_rec(rec); |
134 |
return false; |
135 |
} |
136 |
|
137 |
function init_page() { |
138 |
load_rec(rec); |
139 |
// load template |
140 |
iwfRequest( url+'/template/', 'div_template' ); |
141 |
} |
142 |
|
143 |
</script> |
144 |
</head> |
145 |
<body onload="init_page();"> |
146 |
|
147 |
db_path = <tt>$db_path</tt><br/> |
148 |
|
149 |
<div id="iwfLog" style="display: none;"> |
150 |
</div> |
151 |
|
152 |
<div style="background: #e0e0e0; padding: 0.5em; display: block;"> |
153 |
<a href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">⇦</a> |
154 |
<span id="div_record_nr"> none </span> |
155 |
|
156 |
<a href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">⇨</a> |
157 |
<a href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">↺</a> |
158 |
<a href="#" onClick="iwfRefreshLog(); return false;">▤</a> |
159 |
</div> |
160 |
|
161 |
<div id="div_template"> |
162 |
<span style="color: #808080;"> no template loaded yet. </span> |
163 |
</div> |
164 |
|
165 |
<div id="div_record" style="display: block;"> |
166 |
<span style="color: #808080;"> no record loaded yet. </span> |
167 |
</div> |
168 |
|
169 |
|
170 |
</body> |
171 |
</html>}; |
172 |
|
173 |
}; |