/[webpac2]/trunk/web/browse.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/web/browse.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 61 - (hide annotations)
Tue Nov 15 14:31:03 2005 UTC (18 years, 6 months ago) by dpavlin
File size: 5377 byte(s)
 r8883@llin:  dpavlin | 2005-11-14 21:39:14 +0100
 fade initial idle status

1 dpavlin 46 #!/usr/bin/perl -w
2    
3 dpavlin 54 use strict;
4    
5 dpavlin 46 use Cwd qw/abs_path/;
6     use CGI::Carp qw(fatalsToBrowser);
7     use CGI::Simple;
8 dpavlin 49 use File::Slurp;
9 dpavlin 54 use Data::Dumper;
10     use Text::Iconv;
11 dpavlin 46
12     use lib '../lib';
13    
14     use WebPAC::DB;
15     use WebPAC::Output::TT;
16    
17     my $abs_path = abs_path($0);
18     $abs_path =~ s#/[^/]*$#/../#;
19    
20     my $db_path = $abs_path . '/db/';
21 dpavlin 49 my $template = 'html_ffzg.tt';
22 dpavlin 46
23 dpavlin 54 my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8');
24     my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2');
25    
26 dpavlin 46 my $db = new WebPAC::DB(
27     path => $db_path,
28     read_only => 1,
29     debug => 1,
30     );
31    
32     my $out = new WebPAC::Output::TT(
33     include_path => "$abs_path/conf/output/tt",
34     filters => { foo => sub { shift } },
35     );
36    
37     my $q = new CGI::Simple;
38     my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 );
39    
40     my $rec = $q->param('rec') || 1;
41    
42 dpavlin 54 print $q->header( -charset => 'utf-8' );
43 dpavlin 46
44     if ($q->path_info =~ m#xml#) {
45    
46     my @ds = $db->load_ds($rec);
47    
48 dpavlin 49 if (@ds && $#ds > 0) {
49 dpavlin 46 print qq{<response>
50 dpavlin 49 <action type='html' target='div_record' errorCode='' errorMessage='' >
51 dpavlin 58 }, $iconv_utf8->convert( $out->apply(
52 dpavlin 49 template => $template,
53 dpavlin 46 data => \@ds,
54 dpavlin 58 ) ), qq{
55 dpavlin 46
56 dpavlin 57 </action>
57     <action type='javascript' errorCode='' errorMessage='' >
58 dpavlin 46 <!--
59 dpavlin 49 var el = iwfGetById('div_record_nr');
60 dpavlin 46 if (el) el.innerHTML = '# <b>$rec</b>';
61 dpavlin 49 //iwfShow('div_record');
62     iwfOpacity('div_record', 100);
63 dpavlin 46 //-->
64     </action>
65     </response>
66     };
67     exit;
68     } else {
69 dpavlin 49 print qq{<response>
70     <action type='html' target='div_record' errorCode='' errorMessage='' >
71    
72     <b>Record $rec not found!</b>
73 dpavlin 57 </action>
74     <action type='javascript' errorCode='' errorMessage='' >
75 dpavlin 49 <!--
76     var el = iwfGetById('div_record_nr');
77 dpavlin 59 if (el) el.innerHTML = '<strike>&nbsp;$rec&nbsp;</strike>';
78 dpavlin 49 //-->
79     </action>
80     </response>
81     };
82     exit;
83 dpavlin 46 }
84    
85 dpavlin 49 } elsif ($q->path_info =~ m#template#) {
86    
87 dpavlin 54 my @actions;
88 dpavlin 49
89 dpavlin 54 if ($q->param('save_template')) {
90    
91 dpavlin 58 my $tmpl = $iconv_loc->convert( $q->param('tt_template') ) || die "no template?";
92     sub _conv_js {
93     my $t = shift || return;
94     return $iconv_loc->convert(chr(hex($t)));
95     }
96     $tmpl =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex;
97    
98 dpavlin 54 my $tmpl_file = $out->{'include_path'} . '/' . $template;
99 dpavlin 58 write_file($tmpl_file . '.new', $tmpl) || die "can't save $tmpl_file: $!";
100 dpavlin 54 rename $tmpl_file . '.new', $tmpl_file || die "can't rename to $tmpl_file: $!";
101    
102     print qq{<response>
103     <action type='html' target='div_status' errorCode='' errorMessage='' >
104 dpavlin 60 <tt>$template</tt> saved
105 dpavlin 54 </action>
106     <action type='js'>
107     <!--
108 dpavlin 60 iwfShow('div_status', 1);
109 dpavlin 54 reload_rec();
110 dpavlin 60 iwfHideGentlyDelay('div_status', 2, 2000, 1);
111 dpavlin 54 -->
112     </action>
113     </response>
114     };
115     exit;
116    
117     }
118    
119     my $tmpl = read_file($out->{'include_path'} . '/' . $template) || die "can't read template $template: $!";
120     $tmpl = $q->escapeHTML($iconv_utf8->convert($tmpl));
121    
122 dpavlin 49 print qq{<response>
123     <action type='html' target='div_template' errorCode='' errorMessage='' >
124 dpavlin 54 <pre>}, Dumper($q->Vars), qq{</pre>
125    
126 dpavlin 61 <form name="frmEditor" action="$self" method="post" iwfTarget="div_status" >
127 dpavlin 54
128     <textarea name="tt_template" cols="80" rows="10" style="display: block;">
129 dpavlin 49 $tmpl
130     </textarea>
131 dpavlin 54
132     <br/>
133     <input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
134 dpavlin 61 <!--
135     <input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin
136     -->
137     &nbsp;&nbsp;<span id="div_status" style="color: #808080;">idle</span>
138 dpavlin 54
139     <input type='hidden' value='hidden post value' name='hidValue' />
140    
141     </form>
142 dpavlin 49 </action>
143 dpavlin 61 <action type='js'>
144     <!--
145     iwfHideGentlyDelay('div_status', 2, 2000, 1);
146     -->
147     </action>
148 dpavlin 49 </response>
149 dpavlin 54 };
150 dpavlin 49
151 dpavlin 54 exit;
152    
153 dpavlin 46 } else {
154     print qq{
155     <html>
156     <head>
157     <title>WebPAC simple browse interface</title>
158     <script type='text/javascript' src='iwf/iwfcore.js'></script>
159     <script type='text/javascript' src='iwf/iwfgui.js'></script>
160     <script type='text/javascript' src='iwf/iwfxml.js'></script>
161     <script type='text/javascript' src='iwf/iwfajax.js'></script>
162     <script type='text/javascript'>
163    
164     var rec = $rec ;
165     var url = '$self';
166    
167     function update_status(text) {
168 dpavlin 49 var el = iwfGetById('div_record_nr');
169 dpavlin 46 if (el) el.innerHTML = text;
170     }
171    
172     function load_rec(nr) {
173 dpavlin 59 if (nr == 1) {
174     iwfHide('a_left_arr', 1);
175     } else {
176     iwfShow('a_left_arr', 1);
177     }
178 dpavlin 46 update_status(nr+'...');
179 dpavlin 49 iwfRequest( url+'/xml/?rec='+nr, 'div_record' );
180     iwfOpacity('div_record', 30);
181 dpavlin 46 }
182    
183     function inc_rec() {
184     rec++;
185     load_rec(rec);
186     return false;
187     }
188    
189     function dec_rec() {
190 dpavlin 59 if (rec > 1) {
191     rec--;
192     load_rec(rec);
193     }
194 dpavlin 46 return false;
195     }
196    
197 dpavlin 47 function reload_rec() {
198     load_rec(rec);
199     return false;
200     }
201    
202 dpavlin 49 function init_page() {
203     load_rec(rec);
204     // load template
205     iwfRequest( url+'/template/', 'div_template' );
206     }
207    
208 dpavlin 46 </script>
209     </head>
210 dpavlin 49 <body onload="init_page();">
211 dpavlin 46
212     db_path = <tt>$db_path</tt><br/>
213 dpavlin 54 template = <tt>$template</tt><br/>
214 dpavlin 46
215 dpavlin 49 <div id="iwfLog" style="display: none;">
216     </div>
217    
218 dpavlin 46 <div style="background: #e0e0e0; padding: 0.5em; display: block;">
219 dpavlin 59 <a id="a_left_arr" href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">&#8678;</a>
220 dpavlin 49 <span id="div_record_nr"> none </span>
221 dpavlin 47
222 dpavlin 59 <a id="a_right_arr" href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">&#8680;</a>
223     <a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">&#8634;</a>
224     <a href="#" onClick="iwfRefreshLog(); return false;">&#9636;</a>
225 dpavlin 54
226 dpavlin 46 </div>
227    
228 dpavlin 49 <div id="div_template">
229     <span style="color: #808080;"> no template loaded yet. </span>
230     </div>
231    
232     <div id="div_record" style="display: block;">
233 dpavlin 46 <span style="color: #808080;"> no record loaded yet. </span>
234     </div>
235    
236 dpavlin 49
237 dpavlin 46 </body>
238     </html>};
239    
240     };

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26