/[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 46 by dpavlin, Mon Nov 14 16:13:17 2005 UTC revision 57 by dpavlin, Tue Nov 15 14:30:11 2005 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3    use strict;
4    
5  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
6  use CGI::Carp qw(fatalsToBrowser);  use CGI::Carp qw(fatalsToBrowser);
7  use CGI::Simple;  use CGI::Simple;
8    use File::Slurp;
9    use Data::Dumper;
10    use Text::Iconv;
11    
12  use lib '../lib';  use lib '../lib';
13    
# Line 13  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';
22    
23    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  my $db = new WebPAC::DB(  my $db = new WebPAC::DB(
27          path => $db_path,          path => $db_path,
# Line 30  my $self = $q->url( '-path_info'=>1, '-q Line 39  my $self = $q->url( '-path_info'=>1, '-q
39    
40  my $rec = $q->param('rec') || 1;  my $rec = $q->param('rec') || 1;
41    
42  print $q->header;  print $q->header( -charset    => 'utf-8' );
43    
44  if ($q->path_info =~ m#xml#) {  if ($q->path_info =~ m#xml#) {
45    
46          my @ds = $db->load_ds($rec);          my @ds = $db->load_ds($rec);
47    
48          if (@ds) {          if (@ds && $#ds > 0) {
49                  print qq{<response>                  print qq{<response>
50  <action type='html' target='divRecord' errorCode='' errorMessage='' >  <action type='html' target='div_record' errorCode='' errorMessage='' >
51                  }, $out->apply(                  }, $out->apply(
52                          template => 'html_ffzg.tt',                          template => $template,
53                          data => \@ds,                          data => \@ds,
54                  ), qq{                  ), qq{
55    
56  <script type='text/javascript'>  </action>
57    <action type='javascript' errorCode='' errorMessage='' >
58  <!--  <!--
59          var el = iwfGetById('divRecordNr');          var el = iwfGetById('div_record_nr');
60          if (el) el.innerHTML = '# <b>$rec</b>';          if (el) el.innerHTML = '# <b>$rec</b>';
61          //iwfShow('divRecord');          //iwfShow('div_record');
62          iwfOpacity('divRecord', 100);          iwfOpacity('div_record', 100);
63  //-->  //-->
 </script>  
   
64  </action>  </action>
65  </response>  </response>
66  };  };
67                  exit;                  exit;
68          } else {          } else {
69                  print qq{                  print qq{<response>
70                          <b>Record $rec not found!</b>  <action type='html' target='div_record' errorCode='' errorMessage='' >
71                  };  
72    <b>Record $rec not found!</b>
73    </action>
74    <action type='javascript' errorCode='' errorMessage='' >
75    <!--
76            var el = iwfGetById('div_record_nr');
77            if (el) el.innerHTML = '<strike>$rec</strike>';
78    //-->
79    </action>
80    </response>
81    };
82                    exit;
83          }          }
84    
85    } elsif ($q->path_info =~ m#template#) {
86    
87                    my @actions;
88    
89                    if ($q->param('save_template')) {
90    
91                            my $tmpl = $q->param('tt_template') || die "no template?";
92                            my $tmpl_file = $out->{'include_path'} . '/' . $template;
93                            write_file($tmpl_file . '.new', $iconv_loc->convert($tmpl)) || die "can't save $tmpl_file: $!";
94                            rename $tmpl_file . '.new', $tmpl_file || die "can't rename to $tmpl_file: $!";
95    
96                            print qq{<response>
97    <action type='html' target='div_status' errorCode='' errorMessage='' >
98    $template saved
99    </action>
100    <action type='js'>
101    <!--
102    reload_rec();
103    -->
104    </action>
105    </response>
106                            };
107                            exit;
108    
109                    }
110    
111                    my $tmpl = read_file($out->{'include_path'} . '/' . $template) || die "can't read template $template: $!";
112                    $tmpl = $q->escapeHTML($iconv_utf8->convert($tmpl));
113    
114                    print qq{<response>
115    <action type='html' target='div_template' errorCode='' errorMessage='' >
116    <pre>}, Dumper($q->Vars), qq{</pre>
117    
118    <form name="frmEditor" action="$self" method="post"
119    iwfTarget="div_status"
120    >
121    
122    <textarea name="tt_template" cols="80" rows="10" style="display: block;">
123    $tmpl
124    </textarea>
125    
126    <br/>
127    <input type="button" name="save_template" value="Save" onclick="javascript:iwfRequest(this);" />
128    <input type="checkbox" name="checkin_template" id="checkin_checkbox" label="checkin" />
129    <span id="div_status" style="color: #808080;">idle</span>
130    
131    <input type='hidden' value='hidden post value' name='hidValue' />
132    
133    </form>
134    </action>
135    </response>
136                    };
137    
138                    exit;
139    
140  } else {  } else {
141          print qq{          print qq{
142  <html>  <html>
# Line 78  var rec = $rec ; Line 152  var rec = $rec ;
152  var url = '$self';  var url = '$self';
153    
154  function update_status(text) {  function update_status(text) {
155          var el = iwfGetById('divRecordNr');          var el = iwfGetById('div_record_nr');
156          if (el) el.innerHTML = text;          if (el) el.innerHTML = text;
157  }  }
           
158    
159  function load_rec(nr) {  function load_rec(nr) {
160          update_status(nr+'...');          update_status(nr+'...');
161          iwfRequest( url+'/xml/?rec='+nr, 'divRecord' );          iwfRequest( url+'/xml/?rec='+nr, 'div_record' );
162          iwfOpacity('divRecord', 30);          iwfOpacity('div_record', 30);
163  }  }
164    
165  function inc_rec() {  function inc_rec() {
# Line 101  function dec_rec() { Line 174  function dec_rec() {
174          return false;          return false;
175  }  }
176    
177    function reload_rec() {
178            load_rec(rec);
179            return false;
180    }
181    
182    function init_page() {
183            load_rec(rec);
184            // load template
185            iwfRequest( url+'/template/', 'div_template' );
186    }
187    
188  </script>  </script>
189  </head>  </head>
190  <body onload="load_rec($rec);">  <body onload="init_page();">
191    
192  db_path = <tt>$db_path</tt><br/>  db_path = <tt>$db_path</tt><br/>
193    template = <tt>$template</tt><br/>
194    
195    <div id="iwfLog" style="display: none;">
196    </div>
197    
198  <div style="background: #e0e0e0; padding: 0.5em; display: block;">  <div style="background: #e0e0e0; padding: 0.5em; display: block;">
199          <a href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">&#8678;</a>&nbsp;          <a href="$self?rec=}, $rec - 1, qq{" onClick="return dec_rec();">&#8678;</a>&nbsp;
200          <span id="divRecordNr"> none </span>          <span id="div_record_nr"> none </span>
201    
202          <a href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">&#8680;</a>&nbsp;          <a href="$self?rec=}, $rec + 1, qq{" onClick="return inc_rec();">&#8680;</a>&nbsp;
203            <a href="$self?rec=}, $rec, qq{" onClick="return reload_rec();">&#8634;</a>&nbsp;
204            <a href="#" onClick="iwfRefreshLog(); return false;">&#9636;</a>&nbsp;
205    
206  </div>  </div>
207    
208  <div id="divRecord">  <div id="div_template">
209    <span style="color: #808080;"> no template loaded yet. </span>
210    </div>
211    
212    <div id="div_record" style="display: block;">
213  <span style="color: #808080;"> no record loaded yet. </span>  <span style="color: #808080;"> no record loaded yet. </span>
214  </div>  </div>
215    
216    
217  </body>  </body>
218  </html>};  </html>};
219    

Legend:
Removed from v.46  
changed lines
  Added in v.57

  ViewVC Help
Powered by ViewVC 1.1.26