/[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

Diff of /trunk/web/browse.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 63 by dpavlin, Tue Nov 15 16:56:40 2005 UTC revision 77 by dpavlin, Sun Nov 20 20:44:15 2005 UTC
# Line 18  my $abs_path = abs_path($0); Line 18  my $abs_path = abs_path($0);
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');
# Line 30  my $db = new WebPAC::DB( Line 33  my $db = new WebPAC::DB(
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    
# Line 38  my $q = new CGI::Simple; Line 41  my $q = new CGI::Simple;
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                  }, $iconv_utf8->convert( $out->apply(                  }, $iconv_utf8->convert( $out->apply(
88                          template => $template,                          template => $template_filename,
89                          data => \@ds,                          data => $ds,
90                  ) ), qq{                  ) ), qq{
91    
92  </action>  </action>
# Line 84  if ($q->path_info =~ m#xml#) { Line 120  if ($q->path_info =~ m#xml#) {
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 = $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;  
                         $tmpl =~ s/[\n\r]+$//s;  
   
                         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: $!";  
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  <tt>$template</tt> saved  <tt>$template_filename</tt> saved
132  </action>  </action>
133  <action type='js'>  <action type='js'>
134  <!--  <!--
135  iwfShow('div_status', 1);  iwfShow('div_template_status', 1);
136  reload_rec();  reload_rec();
137  iwfHideGentlyDelay('div_status', 2, 2000, 1);  iwfHideGentlyDelay('div_template_status', 2, 2000, 1);
138  -->  -->
139  </action>  </action>
140  </response>  </response>
# Line 117  iwfHideGentlyDelay('div_status', 2, 2000 Line 143  iwfHideGentlyDelay('div_status', 2, 2000
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" iwfTarget="div_status" >  <form name="frmEditor" action="$self" method="post" iwfTarget="div_template_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
# Line 135  $tmpl Line 159  $tmpl
159  <!--  <!--
160  <input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin  <input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" /> checkin
161  -->  -->
162  &nbsp;&nbsp;<span id="div_status" style="color: #808080;">idle</span>  &nbsp;&nbsp;<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    &nbsp;&nbsp;<span id="div_css_status" style="color: #808080;">idle</span>
220  </form>  </form>
221  </action>  </action>
222  <action type='js'>  <action type='js'>
223  <!--  <!--
224  iwfHideGentlyDelay('div_status', 2, 2000, 1);  iwfLog('loaded CSS template');
225  -->  -->
226  </action>  </action>
227  </response>  </response>
# Line 152  iwfHideGentlyDelay('div_status', 2, 2000 Line 230  iwfHideGentlyDelay('div_status', 2, 2000
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');
# Line 177  function load_rec(nr) { Line 278  function load_rec(nr) {
278                  iwfShow('a_left_arr', 1);                  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    
# Line 200  function reload_rec() { Line 301  function reload_rec() {
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 id="a_left_arr" href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">&#8678;</a>          <a id="a_left_arr" href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">&#8678;</a>
347          <span id="div_record_nr"> none </span>          <span id="div_record_nr"> none </span>
348    
349          <a id="a_right_arr" href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">&#8680;</a>          <a id="a_right_arr" href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">&#8680;</a>
350          <a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">&#8634;</a>          <a id="a_reload" href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">&#8634;</a>
351          <a href="#" onClick="iwfRefreshLog(); return false;">&#9636;</a>          <a href="#" onClick="iwfShowLog(); return false;">&#9636;</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  };  }

Legend:
Removed from v.63  
changed lines
  Added in v.77

  ViewVC Help
Powered by ViewVC 1.1.26