/[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 54 - (hide annotations)
Mon Nov 14 16:16:57 2005 UTC (18 years, 6 months ago) by dpavlin
File size: 4818 byte(s)
 r8863@llin:  dpavlin | 2005-11-14 16:59:48 +0100
 edit template in browser

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 46 }, $out->apply(
52 dpavlin 49 template => $template,
53 dpavlin 46 data => \@ds,
54     ), qq{
55    
56     <script type='text/javascript'>
57     <!--
58 dpavlin 49 var el = iwfGetById('div_record_nr');
59 dpavlin 46 if (el) el.innerHTML = '# <b>$rec</b>';
60 dpavlin 49 //iwfShow('div_record');
61     iwfOpacity('div_record', 100);
62 dpavlin 46 //-->
63     </script>
64    
65     </action>
66     </response>
67     };
68     exit;
69     } else {
70 dpavlin 49 print qq{<response>
71     <action type='html' target='div_record' errorCode='' errorMessage='' >
72    
73     <b>Record $rec not found!</b>
74     <script type='text/javascript'>
75     <!--
76     var el = iwfGetById('div_record_nr');
77     if (el) el.innerHTML = '<strike>$rec</strike>';
78     //-->
79     </script>
80    
81     </action>
82     </response>
83     };
84     exit;
85 dpavlin 46 }
86    
87 dpavlin 49 } elsif ($q->path_info =~ m#template#) {
88    
89 dpavlin 54 my @actions;
90 dpavlin 49
91 dpavlin 54 if ($q->param('save_template')) {
92    
93     my $tmpl = $q->param('tt_template') || die "no template?";
94     my $tmpl_file = $out->{'include_path'} . '/' . $template;
95     write_file($tmpl_file . '.new', $iconv_loc->convert($tmpl)) || die "can't save $tmpl_file: $!";
96     rename $tmpl_file . '.new', $tmpl_file || die "can't rename to $tmpl_file: $!";
97    
98     print qq{<response>
99     <action type='html' target='div_status' errorCode='' errorMessage='' >
100     $template saved
101     </action>
102     <action type='js'>
103     <!--
104     reload_rec();
105     -->
106     </action>
107     </response>
108     };
109     exit;
110    
111     }
112    
113     my $tmpl = read_file($out->{'include_path'} . '/' . $template) || die "can't read template $template: $!";
114     $tmpl = $q->escapeHTML($iconv_utf8->convert($tmpl));
115    
116 dpavlin 49 print qq{<response>
117     <action type='html' target='div_template' errorCode='' errorMessage='' >
118 dpavlin 54 <pre>}, Dumper($q->Vars), qq{</pre>
119    
120     <form name="frmEditor" action="$self" method="post"
121     iwfTarget="div_status"
122     >
123    
124     <textarea name="tt_template" cols="80" rows="10" style="display: block;">
125 dpavlin 49 $tmpl
126     </textarea>
127 dpavlin 54
128     <br/>
129     <input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
130     <input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" />
131     <span id="div_status" style="color: #808080;">idle</span>
132    
133     <input type='hidden' value='hidden post value' name='hidValue' />
134    
135     </form>
136 dpavlin 49 </action>
137     </response>
138 dpavlin 54 };
139 dpavlin 49
140 dpavlin 54 exit;
141    
142 dpavlin 46 } else {
143     print qq{
144     <html>
145     <head>
146     <title>WebPAC simple browse interface</title>
147     <script type='text/javascript' src='iwf/iwfcore.js'></script>
148     <script type='text/javascript' src='iwf/iwfgui.js'></script>
149     <script type='text/javascript' src='iwf/iwfxml.js'></script>
150     <script type='text/javascript' src='iwf/iwfajax.js'></script>
151     <script type='text/javascript'>
152    
153     var rec = $rec ;
154     var url = '$self';
155    
156     function update_status(text) {
157 dpavlin 49 var el = iwfGetById('div_record_nr');
158 dpavlin 46 if (el) el.innerHTML = text;
159     }
160    
161     function load_rec(nr) {
162     update_status(nr+'...');
163 dpavlin 49 iwfRequest( url+'/xml/?rec='+nr, 'div_record' );
164     iwfOpacity('div_record', 30);
165 dpavlin 46 }
166    
167     function inc_rec() {
168     rec++;
169     load_rec(rec);
170     return false;
171     }
172    
173     function dec_rec() {
174     rec--;
175     load_rec(rec);
176     return false;
177     }
178    
179 dpavlin 47 function reload_rec() {
180     load_rec(rec);
181     return false;
182     }
183    
184 dpavlin 49 function init_page() {
185     load_rec(rec);
186     // load template
187     iwfRequest( url+'/template/', 'div_template' );
188     }
189    
190 dpavlin 46 </script>
191     </head>
192 dpavlin 49 <body onload="init_page();">
193 dpavlin 46
194     db_path = <tt>$db_path</tt><br/>
195 dpavlin 54 template = <tt>$template</tt><br/>
196 dpavlin 46
197 dpavlin 49 <div id="iwfLog" style="display: none;">
198     </div>
199    
200 dpavlin 46 <div style="background: #e0e0e0; padding: 0.5em; display: block;">
201     <a href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">&#8678;</a>&nbsp;
202 dpavlin 49 <span id="div_record_nr"> none </span>
203 dpavlin 47
204 dpavlin 46 <a href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">&#8680;</a>&nbsp;
205 dpavlin 47 <a href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">&#8634;</a>&nbsp;
206 dpavlin 49 <a href="#" onClick="iwfRefreshLog(); return false;">&#9636;</a>&nbsp;
207 dpavlin 54
208 dpavlin 46 </div>
209    
210 dpavlin 49 <div id="div_template">
211     <span style="color: #808080;"> no template loaded yet. </span>
212     </div>
213    
214     <div id="div_record" style="display: block;">
215 dpavlin 46 <span style="color: #808080;"> no record loaded yet. </span>
216     </div>
217    
218 dpavlin 49
219 dpavlin 46 </body>
220     </html>};
221    
222     };

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26