aboutsummaryrefslogtreecommitdiffhomepage
path: root/data/sisu/conf/cgi-bin/sisu_search_pgsql.cgi
blob: 0d2ed98264746cff37a4f7aabac989a15aaab8e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
#!/usr/bin/env ruby
=begin
 * Name: SiSU information Structuring Universe   
 * Author: Ralph Amissah
   * http://www.jus.uio.no/sisu
   * http://www.jus.uio.no/sisu/SiSU/download

 * Description: generates naive cgi search form for search of sisu database (pgsql)
   * $Id$

 Copyright (C) 2006 Ralph Amissah
 Copyright (C) 2005 Ralph Amissah (first release edition)
 Copyright (C) 1997 Ralph Amissah (first edition)

 * License: GPL 2 or later

  Summary of GPL 2

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the Free
  Software Foundation; either version 2 of the License, or (at your option)
  any later version.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA

  If you have Internet connection, the latest version of the GPL should be
  available at these locations:
    http://www.fsf.org/licenses/gpl.html
    http://www.gnu.org/copyleft/gpl.html
    http://www.jus.uio.no/sisu/gpl2.fsf

  SiSU was first released to the public on January 4th 2005

  SiSU uses:
  
  *  Standard SiSU markup syntax,
  *  Standard SiSU meta-markup syntax, and the
  *  Standard SiSU object citation numbering and system
  
  © Ralph Amissah 1997, current 2006.
  All Rights Reserved.

 * Ralph Amissah ralph@amissah.com
   Ralph Amissah ralph.amissah@gmail.com

=end
require 'cgi'
require 'fcgi'
require 'dbi'
@version='sisu_search_pgsql'
@url_base="http://corundum:8081/_sisu/image"
host=%x{echo $HOSTNAME}.chomp!
@hosturl="http://#{host}" +
  ':8081'
@base="#@hosturl/cgi-bin/#@version.cgi"
user='ralph'
class Form
  def initialize(base,search_field,selected_db,checked_index,checked_text,checked_tip,checked_searched,checked_url,checked_echo,checked_sql,checked_all,checked_none,checked_ignore,search_note,the_can='')
    search_note='' if checked_searched !~/\S/
    the_can='' if checked_url !~/\S/
    search_field='' if checked_echo !~/\S/
    @base,@search_field,@selected_db,@checked_index,@checked_text,@checked_tip,@checked_searched,@checked_url,@checked_echo,@checked_sql,@checked_all,@checked_none,@checked_ignore,@search_note,@the_can=base,search_field,selected_db,checked_index,checked_text,checked_tip,checked_searched,checked_url,checked_echo,checked_sql,checked_all,checked_none,checked_ignore,search_note,the_can
    @tip=if checked_tip =~/\S/
      '<font size="2" color="#666666">text:__; keywords:__; title:__; author:__; subject:__; description:__; publisher:__; contributor:__; date:__; type:__; format:__; identifier:__; source:__; language:__; relation:__; coverage:__; rights:__; comment:__; abstract:__; </font>'
    else '' 
    end
  end
  def submission_form
      search_form=<<-WOK
<label for="find"><b>SiSU PgSQL Search Form (sample):</b></label>
<table cellpadding="2">
<tr><td valign=\"top\">
  <table cellpadding="2">
    <form action="#@base" id="Test Form" method="post">
    <tr><td valign=\"top\">
      <!input type="text" id="find" name="find" value="#@search_field" />
      <!input type="text" id="find" name="find" value="" />
      <textarea id="find" name="find" type="text" rows="4" cols="30" maxlength="256">#@search_field</textarea><br />
    </td><td valign=\"top\"><p>
      <select name="db" size="1">
        #@selected_db
        <option value="SiSU_sisu">sisu</option>
        <option value="SiSU_document_samples_sisu_markup">document_samples_sisu_markup</option>
      </select><br />
      <font size="2" color="#222222">
      <input type="radio" name="view" value="index" #@checked_index> index
      <input type="radio" name="view" value="text" #@checked_text>  text
      </font>
      </p>
      <p><input type="submit" value="submit" /></p>
    </td></tr>
  </table>
    #@search_note
  </td><td valign=\"top\">
    #@tip
  </td></tr>
</table>           
      <font size="2" color="#222222">
      <input type="checkbox" name="echo" #@checked_echo> echo
      <input type="checkbox" name="searched" #@checked_searched> searched
      <input type="checkbox" name="url" #@checked_url> url
      <input type="checkbox" name="tip" #@checked_tip> search fields available
      <input type="checkbox" name="sql" #@checked_sql> sql statement
      </font>
      <br />
      <input type="radio" name="checks" value="check_ignore" #@checked_ignore> use selected
      <input type="radio" name="checks" value="check_all" #@checked_all> check all
      <input type="radio" name="checks" value="check_none" #@checked_none> check none
      <br />
  </form>
#@the_can
WOK
  end
end
class Search_request                                                       #% search_for
  attr_accessor :text1,:keywords,:title,:author,:subject,:description,:publisher,:contributor,:date,:type,:format,:identifier,:source,:language,:relation,:coverage,:rights,:comment,:abstract,:owner,:date_created,:date_issued,:date_modified,:date_available,:date_valid
  def initialize(search_field='',q='')
    @search_field,@q=search_field,q
    @text1=@keywords=@title=@author=@subject=@description=@publisher=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@comment=@abstract=@owner=@date_created=@date_issued=@date_modified=@date_available=@date_valid=''
    if @search_field=~/\S/
      @text1=text_to_match('text:')
      @keywords=text_to_match('key(?:words?)?:')
      @title=text_to_match('title:')                  # DublinCore 1  - title
      @author=text_to_match('(?:author|creator)s?:')  # DublinCore 2  - creator/author
      @subject=text_to_match('subj(?:ect)?:')         # DublinCore 3  - subject
      @description=text_to_match('description:')      # DublinCore 4  - description
      @publisher=text_to_match('pub(?:lisher)?:')     # DublinCore 5  - publisher
      @contributor=text_to_match('contributor:')      # DublinCore 6  - contributor
      @date=text_to_match('date:')                    # DublinCore 7  - date dd-mm-yy
      @type=text_to_match('type:')                    # DublinCore 8  - type
      @format=text_to_match('format:')                # DublinCore 9  - format
      @identifier=text_to_match('identifier:')        # DublinCore 10 - identifier
      @source=text_to_match('source:')                # DublinCore 11 - source
      @language=text_to_match('language:')            # DublinCore 12 - language
      @relation=text_to_match('relation:')            # DublinCore 13 - relation
      @coverage=text_to_match('coverage:')            # DublinCore 14 - coverage
      @rights=text_to_match('rights:')                # DublinCore 15 - rights
      @comment=text_to_match('comment:')
      @abstract=text_to_match('abs(?:tract)?:')
      @owner=text_to_match('owner:')
      @date_created=text_to_match('date_created:')
      @date_issued=text_to_match('date_issued:')
      @date_modified=text_to_match('date_modified:')
      @date_available=text_to_match('date_available:')
      @date_valid=text_to_match('date_valid:')
      @text1=text_to_match unless @keywords or @author or @title or @text1 or @comment or @abstract or @rights or @subject or @publisher or @date
    else
      @text1=q['s1'] if q['s1']=~/\S/
      @keywords=q['key'] if q['key']=~/\S/
      @title=q['ti'] if q['ti']=~/\S/
      @author=q['au'] if q['au']=~/\S/
      @subject=q['sj'] if q['sj']=~/\S/
      @description=q['dsc'] if q['dsc']=~/\S/
      @publisher=q['pb'] if q['pb']=~/\S/
      @contributor=q['cntr'] if q['cntr']=~/\S/
      @date=q['dt'] if q['dt']=~/\S/
      @type=q['ty'] if q['ty']=~/\S/
      @identifier=q['id'] if q['id']=~/\S/
      @source=q['src'] if q['src']=~/\S/
      @language=q['lang'] if q['lang']=~/\S/
      @relation=q['rel'] if q['rel']=~/\S/
      @coverage=q['cov'] if q['cov']=~/\S/
      @rights=q['cr'] if q['cr']=~/\S/
      @comment=q['co'] if q['co']=~/\S/
      @abstract=q['ab'] if q['ab']=~/\S/
      @date_created=q['dtc'] if q['dtc']=~/\S/
      @date_issued=q['dti'] if q['dti']=~/\S/
      @date_modified=q['dtm'] if q['dtm']=~/\S/
      @date_available=q['dta'] if q['dta']=~/\S/
      @date_valid=q['dtv'] if q['dtv']=~/\S/
    end
  end
  def text_to_match(identifier='')
    m=Hash.new
    m[:string]=/#{identifier}\s*(.+?)/
    m[:string]=/#{identifier}\s*(.+?)(?:;|\n|\r|$)/
    m[:word]=/#{identifier}[\s(]*(\S+)/
    search_string=if @search_field =~m[:word]
      search_string=if @search_field =~m[:braces]: m[:braces].match(@search_field)[1]
      elsif @search_field =~m[:string]:            m[:string].match(@search_field)[1]
      else
        str=m[:word].match(@search_field)[1]
        str.gsub!(/[()]/,'')
        str
      end
      search_string.strip!
      search_string.gsub!(/\s+/,'+')
      search_string
    #else
    #  "__"
    end
  end
end
class Dbi_search_string
  def initialize(l,t,q)
    @l,@t,@q=l,t,q
  end
  def string
    search=Hash.new
    search[:search]=Array.new
    search[:flag]=false
    if @t =~/\S+/ or @q =~/\S+/
      if @t =~/\S+/:     unescaped_search=CGI.unescape(@t)
      elsif @q =~/\S+/:  unescaped_search=CGI.unescape(@q)
      end
      search_construct=Array.new
      unescaped_search.gsub!(/\s*(AND|OR)\s*/,"' \) \\1 #@l~\( '")
      unescaped_search.gsub!(/(.+)/,"#@l~\( '\\1' \)")
      search_construct << unescaped_search
      search_construct=search_construct.join(' ')
      search[:search]                    << search_construct
      search[:flag]=true
      search
    end
    search
  end
end
class Dbi_search_statement
  attr_reader :text_search_flag,:sql_select_body_format,:sql_select_endnotes_format
  def initialize(conn,search_for,q)
    @conn=conn
    @text_search_flag=false
    search=Hash.new
    search[:text],search[:endnotes]=Array.new,Array.new
    st=Dbi_search_string.new('documents.clean',search_for.text1,q['s1']).string
    se=Dbi_search_string.new('endnotes.clean',search_for.text1,q['s1']).string
    @text_search_flag=st[:flag]
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << se[:search]
    end
    st=Dbi_search_string.new('metadata.keywords',search_for.keywords,q['key']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.title',search_for.title,q['ti']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.creator',search_for.author,q['au']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.subject',search_for.subject,q['sj']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.description',search_for.description,q['dsc']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.publisher',search_for.publisher,q['pb']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.contributor',search_for.contributor,q['cntr']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.date',search_for.date,q['dt']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.type',search_for.type,q['ty']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.identifier',search_for.identifier,q['id']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.source',search_for.source,q['src']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.language',search_for.language,q['lang']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.relation',search_for.relation,q['rel']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.coverage',search_for.coverage,q['cov']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.rights',search_for.rights,q['cr']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.comment',search_for.comment,q['co']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    st=Dbi_search_string.new('metadata.abstract',search_for.abstract,q['ab']).string
    if st[:flag]
      search[:text]                    << st[:search]
      search[:endnotes]                << st[:search]
    end
    @search_text,@search_endnotes=Array.new,Array.new
                                                                           #%
    search[:text].each{|x| @search_text << "#{x} AND " }
    search[:endnotes].each{|x| @search_endnotes << "#{x} AND " }
    @search_text=@search_text.to_s.gsub!(/AND\s+$/,'')
    @search_endnotes=@search_endnotes.to_s.gsub!(/AND\s+$/,'')
  end
  def sql_select_body
    %{SELECT metadata.title, metadata.creator, metadata.filename, metadata.suffix, documents.body, documents.seg, documents.ocn, metadata.tid FROM documents, metadata WHERE (#@search_text) AND documents.metadata_tid = metadata.tid ORDER BY metadata.title, documents.ocn ;}
  end
  def sql_select_endnotes
    %{SELECT metadata.title, metadata.creator, metadata.filename, endnotes.body, endnotes.nr, endnotes.ocn, endnotes.metadata_tid FROM metadata, endnotes WHERE (#@search_endnotes) AND metadata.tid = endnotes.metadata_tid ORDER BY metadata.title, endnotes.nr ;}
  end
  def sql_select_body_format
    %{<font color="#666666" size="2">#{sql_select_body}</font>} 
  end
  def sql_select_endnotes_format
    %{<font color="#666666" size="2">#{sql_select_endnotes}</font>} 
  end
  def contents
    @conn.select_all(sql_select_body)
  end
  def endnotes
    @conn.select_all(sql_select_endnotes)
  end
end
class Tail
  def tail
    <<-'WOK'
<br /><hr /><br />
<center><table align="center"bgcolor="#ffffff"><tr><td><font color="#666666"><table summary="" bgcolor="#ffffff" cellpadding="4" border="0" align="center">

<tr align="center">
  <td align="center"><p class="center"><font color="#666666" size="2">
  presentations' look and feel<br />
  generated by<br />
  <a href="http://www.jus.uio.no/sisu" ><img border="0" src="http://corundum:8081/_sisu/image/sisu.png" alt="SiSU on Debian/Gnu/Linux or a FreeBSD &amp; Ruby - better ways, well actually, Way Better!" width="120" height="38"></a><br />
  <a href="http://www.jus.uio.no/sisu" >SiSU</a><br />
  version 0.36<br />2006w07/6 (20060218)<br />

  <table summary="SiSU rights" bgcolor="#ffffff" cellpadding="4" border="0" align="center" width="40%">
    <sup>&copy;</sup> Ralph Amissah<br />
  1993, current 2006<br />
  GPL 2<br />
  <i>w3 since October 3 1993</i><br />
  <a href="mailto://ralph@amissah.com" >ralph@amissah.com</a><br />
</font></p>
</td></tr></table>

<p><center><font color="#666666" size="2">Developed<br />using <a href="http://www.ruby-lang.org/en/">Ruby</a><br />on <a href="http://www.debian.org/">Debian/Gnu/Linux</a> software infrastructure,<br />with the usual GPL (or OSS) suspects.<br />Better - "performance, reliability, scalability, security<br />& total cost of ownership"<br />[not to mention flexibility &amp; choice]<br /><br />&lt;&lt;<a href="http://www.jus.uio.no/sisu/">Way Better!</a>&gt;&gt;</font></center></p><tr align="center"><td align="center">

<table summary="browser suggestions" bgcolor="#ffffff" cellpadding="4" border="0">
<tr>
  <td><p><font color="#666666" size="2">
    If you have problems viewing pages on this site please update your browser:
  </font></p>
</td></tr></table>

<table summary="browser suggestions" bgcolor="#ffffff" cellpadding="4" border="0">
<tr><td>
<p>
<font color="#666666" size="2">
If you have problems viewing pages on this site please update your browser:
</font>
</p>
</td></tr>
</table>

<table summary="browser suggestions" bgcolor="#ffffff" cellpadding="4" border="0">
<tr><td>
<p>
<font color="#666666" size="1">
<a href="http://www.gnome.org/projects/epiphany/" target="external">
<img border="0" width="25" height="25" src="http://corundum:8081/_sisu/image/gnome.png" alt="Epiphany">
&nbsp;Epiphany
</a>
<sup>&reg;</sup>&nbsp;|
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://galeon.sourceforge.net/" target="external">
<img border="0" width="24" height="24" src="http://corundum:8081/_sisu/image/galeon.png" alt="Galeon">
&nbsp;Galeon
</a>
<sup>&reg;</sup>&nbsp;|
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://www.microsoft.com/windows/ie/default.asp" target="external">
<img border="0" width="29" height="25" src="http://corundum:8081/_sisu/image/internet.explorer.png" alt="MS I-Explorer">
I-Explorer
</a>
<sup>&reg;</sup>&nbsp;|
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://kazehakase.sourceforge.jp/" target="external">
Kazehakase</a>
<sup>&reg;</sup>&nbsp;|</font></p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://www.konqueror.org/" target="external">
<img border="0" width="29" height="25" src="http://corundum:8081/_sisu/image/konqueror.png" alt="Konqueror">
Konqueror</a>
<sup>&reg;</sup>&nbsp;|</font></p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://www.mozilla.org/" target="external">
<img border="0" width="30" height="24" src="http://corundum:8081/_sisu/image/mozilla.png" alt="Mozilla">
Mozilla
</a>
<a href="http://www.mozilla.org/products/firefox/" target="external">
<img border="0" width="25" height="25" src="http://corundum:8081/_sisu/image/firefox.png" alt="Firefox">
<b>Firefox</b>
</a>
<sup>&reg;</sup>&nbsp;|
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://home.netscape.com/comprod/mirror/client_download.html" target="external">
<img border="0" width="29" height="25" src="http://corundum:8081/_sisu/image/netscape.png" alt="Netscape">
Netscape
</a>
<sup>&reg;</sup>&nbsp;|
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://www.opera.com/" target="external">
<img border="0" width="29" height="25" src="http://corundum:8081/_sisu/image/opera.png" alt="Opera">
Opera
</a>
<sup>&reg;</sup>&nbsp;|
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://www.apple.com/safari/" target="external">
<img border="0" width="24" height="25" src="http://corundum:8081/_sisu/image/safari.png" alt="Safari">
Safari
</a>
<sup>&reg;</sup>
</font>
</p>
</td></tr>
</table>

<table summary="lightweight browser and text browser suggestions" bgcolor="#ffffff" cellpadding="4" border="0">
<tr><td>
<p>
<font color="#666666" size="1">
for console/text viewing:
</font>
</p>
</td>
<td>
<p>
<font color="#666666" size="1">
<a href="http://elinks.or.cz/" target="external">
<b>elinks</b>
</a>&nbsp;|
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://atrey.karlin.mff.cuni.cz/~clock/twibright/links" target="external">
<b>links2</b>
</a>&nbsp;|
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://w3m.sourceforge.net/" target="external">
<b>w3m</b>
</a>
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
for lightweight gui (X) viewing try:
</font>
</p>
</td>
<td>
<p>
<font color="#666666" size="1">
<a href="http://www.dillo.org/" target="external">
Dillo
</a>&nbsp;|</font></p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://www.gnome.org/projects/epiphany/" target="external">
<img border="0" width="25" height="25" src="http://corundum:8081/_sisu/image/gnome.png" alt="Epiphany">
&nbsp;Epiphany
</a>
<sup>&reg;</sup>&nbsp;|
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://galeon.sourceforge.net/" target="external">
<img border="0" width="24" height="24" src="http://corundum:8081/_sisu/image/galeon.png" alt="Galeon">
&nbsp;Galeon
</a>&nbsp;|
</font>
</p>
</td>

<td>
<p>
<font color="#666666" size="1">
<a href="http://atrey.karlin.mff.cuni.cz/~clock/twibright/links" target="external">
<b>links2 -g</b>
</a>
</font>
</p>
</td></tr>
</table>
</td></tr>

<tr align="center"><td align="center">

<table summary="pdf viewer suggestions" bgcolor="#ffffff" cellpadding="4" border="0">

<tr><td>
<p class="center">
<font color="#666666" size="1">
&amp; for
<a href="http://www.adobe.com/products/acrobat/adobepdf.html" target="external">
pdf
</a>
viewings of this site we recommend stand alone viewers
<br />
(rather than web browser plugins):
</font>
</p>
</td></tr>
</table>

<table summary="" bgcolor="#ffffff" cellpadding="4" border="0" align="center">
<tr align="center"><td align="center">
<p class="center">
<font color="#666666" size="1">
<a href="http://www.adobe.com/products/acrobat/readstep2.html" target="external">
<img border="0" height="18" width="15" src="http://corundum:8081/_sisu/image/b_pdf.png" alt="Adobe Acrobat Reader">
Acrobat Reader
</a>
<sup>&reg;</sup>
&nbsp;|
</font>
</p>
</td>

<td>
<p class="center">
<font color="#666666" size="1">
<a href="http://www.gnome.org/projects/evince/" target="external">
<img border="0" width="25" height="25" src="http://corundum:8081/_sisu/image/gnome.png" alt="Evince">
<b>Evince</b>
</a>
<sup>&reg;</sup>
</font>
</p>
</td>

<td>
<p class="center"><font color="#666666" size="1">
<a href="http://www.cs.wisc.edu/~ghost/gv/" target="external">
&nbsp;GhostView<sup>&reg;</sup>&nbsp;</a>,
<a href="http://wwwthep.physik.uni-mainz.de/~plass/gv/" target="external">
GV<sup>&reg;</sup>
</a>
&amp;
<a href="http://www.cs.wisc.edu/~ghost/gsview/" target="external">
GSview<sup>&reg;</sup>
</a>
&nbsp;|
</font>
</p>
</td>

<td>
<p class="center">
<font color="#666666" size="1">
<a href="http://www.foolabs.com/xpdf/" target="external">
<img border="0" width="16" height="16" src="http://corundum:8081/_sisu/image/xpdf.png" alt="Xpdf">
&nbsp;Xpdf
</a>
<sup>&reg;</sup>
</font>
</p>
</td></tr>
</table>

</font></center></td></tr></table></center> <a name="bottom" id="bottom"></a><a name="down" id="down"></a><a name="end" id="end"></a><a name="finish" id="finish"></a><a name="stop" id="stop"></a><a name="credits" id="credits"></a>
</body></html>
WOK
  end
end
@counter_txt_doc,@counter_txt_ocn,@counter_endn_doc,@counter_endn_ocn=0,0,0,0
@counters_txt,@counters_endn,@sql_select_body,@sql_select_endnotes='','','',''
FCGI.each_cgi do |cgi|
  begin # all code goes in begin section
    @search=Hash.new
    @search[:text],@search[:endnotes]=Array.new,Array.new
    q=CGI.new
    @db=if cgi['db'] =~/\S+/: 
      @stub=/SiSU_(\S+)/.match(cgi['db'])[1] 
      cgi['db']
    else
      @stub='sisu'
      'SiSU_sisu'
    end
    checked_url,checked_searched,checked_tip,checked_echo,checked_sql,checked_all,checked_none,checked_ignore,selected_db='','','','','','','',''
    if cgi['view']=~/text/: checked_index,checked_text='','checked'
    else                    checked_index,checked_text='checked',''
    end
    checked_url='checked' if cgi['url'] =~/\S/ or cgi['u'].to_i==1 
    checked_searched='checked' if cgi['searched'] =~/\S/ 
    checked_tip='checked' if cgi['tip'] =~/\S/ 
    checked_echo='checked' if cgi['echo'] =~/\S/ 
    checked_sql='checked' if cgi['sql'] =~/\S/ 
    if cgi['checks'] =~/check_all/ or cgi['check_all'] =~/\S/ or cgi['a'].to_i==1 
      checked_all=checked_url=checked_searched=checked_tip=checked_echo=checked_sql='checked'
      checked_none='' 
    elsif cgi['checks'] =~/check_none/ #or cgi['a'].to_i==0 
      checked_none='checked'
      checked_all=checked_url=checked_searched=checked_tip=checked_echo=checked_sql='' 
    else checked_ignore='checked'
    end
    selected_db=case cgi['db']
    when /SiSU_document_samples_sisu_markup/:        '<option value="SiSU_document_samples_sisu_markup">document_samples_sisu_markup</option>'
    when /SiSU_sisu/:        '<option value="SiSU_sisu">sisu</option>'
    end
    dbi="dbi:Pg:database=#{@db};port=5432"
    @conn=DBI.connect(dbi,user) 
    search_field=cgi['find'] if cgi['find'] # =~/\S+/
    @search_for=Search_request.new(search_field,q) #.analyze               #% search_for
                                                                           #% searches
    #Canned_search.new(@base,@search_for.text1,cgi)
    if @search_for.text1=~/\S+/ or @search_for.author=~/\S+/ #and search_field =~/\S/
      s1='s1=' + CGI.escape(@search_for.text1) if @search_for.text1=~/\S/
      key='key=' + CGI.escape(@search_for.keywords) if @search_for.keywords=~/\S/
      ti='&ti=' + CGI.escape(@search_for.title) if @search_for.title=~/\S/
      au='&au=' + CGI.escape(@search_for.author) if @search_for.author=~/\S/
      sj='&sj=' + CGI.escape(@search_for.subject) if @search_for.subject=~/\S/
      dsc='&dsc=' + CGI.escape(@search_for.description) if @search_for.description=~/\S/
      pb='&pb=' + CGI.escape(@search_for.publisher) if @search_for.publisher=~/\S/
      cntr='&cntr=' + CGI.escape(@search_for.contributor) if @search_for.contributor=~/\S/
      dt='&dt=' + CGI.escape(@search_for.date) if @search_for.date=~/\S/
      ty='&ty=' + CGI.escape(@search_for.type) if @search_for.type=~/\S/
      id='&id=' + CGI.escape(@search_for.identifier) if @search_for.identifier=~/\S/
      src='&src=' + CGI.escape(@search_for.source) if @search_for.source=~/\S/
      lang='&lang=' + CGI.escape(@search_for.language) if @search_for.language=~/\S/
      rel='&rel=' + CGI.escape(@search_for.relation) if @search_for.relation=~/\S/
      cov='&cov=' + CGI.escape(@search_for.coverage) if @search_for.coverage=~/\S/
      cr='&cr=' + CGI.escape(@search_for.rights) if @search_for.rights=~/\S/
      co='&co=' + CGI.escape(@search_for.comment) if @search_for.comment=~/\S/
      ab='&ab=' + CGI.escape(@search_for.abstract) if @search_for.abstract=~/\S/
      dtc='&dtc=' + CGI.escape(@search_for.date_created) if @search_for.date_created=~/\S/
      dti='&dti=' + CGI.escape(@search_for.date_issued) if @search_for.date_issued=~/\S/
      dtm='&dtm=' + CGI.escape(@search_for.date_modified) if @search_for.date_modified=~/\S/
      dta='&dta=' + CGI.escape(@search_for.date_available) if @search_for.date_available=~/\S/
      dtv='&dtv=' + CGI.escape(@search_for.date_valid) if @search_for.date_valid=~/\S/
      canned_search_url=if checked_all =~/checked/
        "#@base?#{s1}#{key}#{ti}#{au}#{sj}#{dsc}#{pb}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}&db=#{cgi['db']}&view=#{cgi['view']}&a=1"
      else "#@base?#{s1}#{key}#{ti}#{au}#{sj}#{dsc}#{pb}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}&db=#{cgi['db']}&view=#{cgi['view']}&u=1&e=1"
      end      
      @search[:text][1]=%{documents.clean~'#{@search_for.text1}'} #s1
      @search[:endnotes][1]=%{endnotes.clean~'#{@search_for.text1}'} #s1
      canned_note='previous search url:'
    else
      canned_search_url="#@base?s1=United+Nations&db=documents&view=index"
      canned_note='search url example:'
    end
    if search_field =~/\S+/
      analyze_format=search_field.gsub(/\s*\n/,'; ')
    elsif checked_all =~/checked/ or checked_url =~/checked/
      canned_search=canned_search_url.scan(/(?:s1|au|ti)=[^&]+/)
      af=canned_search.join('; ')
      af.gsub!(/s1=/,'text: ')
      af.gsub!(/au=/,'author: ')
      af.gsub!(/ti=/,'title: ')
      af.gsub!(/%2B/,' ')
      analyze_format=af
      st=af.split(/\s*;\s*/)
      search_field=st.join("\n")      
    end
    green=%{<font size="2" color="#004000">}
    the_can=%{<font size="2" color="#666666">#{canned_note}<br> <a href="#{canned_search_url}">#{canned_search_url}</a></font><br>}
    p_text=p_keywords=p_title=p_author=p_subject=p_description=p_publisher=p_contributor=p_date=p_type=p_format=p_identifier=p_source=p_language=p_relation=p_coverage=p_rights=p_comment=p_abstract=p_subject=''
    p_text=%{text: #{green}#{@search_for.text1}</font><br>} if @search_for.text1 =~/\S+/
    p_keywords=%{keywords: #{green}#{@search_for.keywords}</font><br>} if @search_for.keywords =~/\S+/
    p_title=%{title: #{green}#{@search_for.title}</font><br>} if @search_for.title =~/\S+/
    p_author=%{author: #{green}#{@search_for.author}</font><br>} if @search_for.author =~/\S+/
    p_subject=%{subject: #{green}#{@search_for.subject}</font><br>} if @search_for.subject =~/\S+/
    p_description=%{description: #{green}#{@search_for.description}</font><br>} if @search_for.description =~/\S+/
    p_publisher=%{publisher: #{green}#{@search_for.publisher}</font><br>} if @search_for.publisher =~/\S+/
    p_contributor=%{contributor: #{green}#{@search_for.contributor}</font><br>} if @search_for.contributor =~/\S+/
    p_date=%{date: #{green}#{@search_for.date}</font><br>} if @search_for.date =~/\S+/
    p_type=%{type: #{green}#{@search_for.type}</font><br>} if @search_for.type =~/\S+/
    p_format=%{format: #{green}#{@search_for.format}</font><br>} if @search_for.format =~/\S+/
    p_identifier=%{identifier: #{green}#{@search_for.identifier}</font><br>} if @search_for.identifier =~/\S+/
    p_source=%{source: #{green}#{@search_for.source}</font><br>} if @search_for.source =~/\S+/
    p_language=%{language: #{green}#{@search_for.language}</font><br>} if @search_for.language =~/\S+/
    p_relation=%{relation: #{green}#{@search_for.relation}</font><br>} if @search_for.relation =~/\S+/
    p_coverage=%{coverage: #{green}#{@search_for.coverage}</font><br>} if @search_for.coverage =~/\S+/
    p_rights=%{rights: #{green}#{@search_for.rights}</font><br>} if @search_for.rights =~/\S+/
    p_comment=%{comment: #{green}#{@search_for.comment}</font><br>} if @search_for.comment =~/\S+/
    p_abstract=%{abstract: #{green}#{@search_for.abstract}</font><br>} if @search_for.abstract =~/\S+/
    search_note=<<-WOK
<font size="2" color="#666666">
<br><b>previous selection</b>:<br>
database: #{green}#@db</font>; selected view: #{green}#{cgi['view']}</font><br>
search string: "#{green}#{analyze_format}</font>"<br>
#{p_text} #{p_keywords} #{p_title} #{p_author} #{p_subject} #{p_description} #{p_publisher} #{p_contributor} #{p_date} #{p_type} #{p_format} #{p_identifier} #{p_source} #{p_language} #{p_relation} #{p_coverage} #{p_rights} #{p_comment} #{p_abstract}
</font>
WOK
    #eg = %{canned search e.g.:<br> <a href="#{url}">#{url}</a><br>find: #{analyze}<br>database: #{database}}
    #dbi_canning
    @header=Form.new(@base,search_field,selected_db,checked_index,checked_text,checked_tip,checked_searched,checked_url,checked_echo,checked_sql,checked_all,checked_none,checked_ignore,search_note,the_can).submission_form #% form
    @tail=Tail.new.tail
    unless q['s1'] =~/\S/ or q['au'] =~/\S/ or @search[:text][1] =~/\S/ 
      print "Content-type: text/html\n\n"
      puts (@header+@tail)
    else #% searches
      s1=if @search_for.text1 =~/\S/
        @search_for.text1
      else 'Unavailable'
      end
      @search[:text]<<%{documents.clean~'#{CGI.unescape(s1)}'}
      @search[:endnotes]<<%{endnotes.clean~'#{CGI.unescape(s1)}'}
    #dbi_request
      dbi_statement=Dbi_search_statement.new(@conn,@search_for,q)
      @text_search_flag=false
      @text_search_flag=dbi_statement.text_search_flag
      s_contents=dbi_statement.contents
      s_endnotes=dbi_statement.endnotes
      @body_main=Array.new
      @endnotes=Array.new
      oldtid=0
      if @text_search_flag 
        if checked_sql =~/\S/
          sql_select_body=dbi_statement.sql_select_body_format
          sql_select_endnotes=dbi_statement.sql_select_endnotes_format
        else sql_select_body,sql_select_endnotes='',''
        end
        @body_main << "<p><hr><br><b>Main Text:</b><br>" << sql_select_body
        @endnotes  << "<p><hr><br><b>Endnotes:</b><br>"  << sql_select_endnotes
      else
      end
      #text_objects_body
      s_contents.each do |c|                                               #% text body
        location=c["filename"][/(.+?)\.ss[ftms]/, 1]
        file_suffix=c["filename"][/.+?\.(ss[ftms])/, 1]
      #metadata_found_body
        if c["tid"].to_i != oldtid.to_i
          title=%{<a href="#@hosturl/#@stub/#{location}/">#{c["title"]}</a> by #{c["creator"]} <a href="#@hosturl/#@stub/#{location}/portrait.pdf"><img border="0" width="15" height="18" src="#@url_base/b_pdf.png" alt="pdf portrait"></a><a href="#@hosturl/#@stub/#{location}/landscape.pdf"><img border="0" width="18" height="15" src="#@url_base/b_pdf.png" alt="pdf landscape"></a><br>}  if file_suffix=~/s/ #hmm watch file_suffix
           if @text_search_flag: title='<br><hr>'+title 
           else                  title='<br>'+title 
           end
           @counter_txt_doc+=1
           oldtid=c["tid"].to_i
          else                    title=''
          end
          if @text_search_flag 
            if cgi['view']=~/text/                                         #% txt body
              text=if c["suffix"] !~/1/ #seg
                if @search_for.text1 =~/\S+/ or q['s1'] =~/\S+/                         #% only this branch is working !!
                  if @search_for.text1 =~/\S+/:     unescaped_search=CGI.unescape(@search_for.text1)
                  elsif q['s1'] =~/\S+/:           unescaped_search=CGI.unescape(q['s1'])
                  end
                  search_regex=Array.new
                  build=unescaped_search.scan(/\S+/).each do |g|
                     if g.to_s =~/(AND|OR)/
                       search_regex << '|'
                     else search_regex << %{#{g.to_s}}
                     end
                  end
                  search_regex=search_regex.join(' ')
                  search_regex=search_regex.gsub(/\s*\|\s*/,'|')
                  @search_regx=search_regex.to_s
                end
                matched_para=c["body"].gsub(/(#@search_regx)/i,%{<span style="background-color: #ffff48">\\1</span>})
                %{<hr><p><font size="2">ocn <b><a href="#@hosturl/#@stub/#{location}/#{c["seg"]}.html##{c["ocn"]}">#{c["ocn"]}</a></b>:</font></p>#{matched_para}} 
              elsif c["suffix"] =~/1/ #doc
                %{#{title}<hr><p><font size="2">ocn #{c["ocn"]}:#{c["body"]}}
              end
              @counter_txt_ocn+=1
              output=if c["seg"] =~/\S+/: title+text
              else                        text 
              end
            elsif cgi['view']=~/index/                                     #% idx body
              if c["suffix"] !~/1/ #seg
                index=%{<a href="#@hosturl/#@stub/#{location}/#{c["seg"]}.html##{c["ocn"]}">#{c["ocn"]}</a>, } if @text_search_flag 
              elsif c["suffix"] =~/1/ #doc
                index=%{<a href="#@hosturl/#@stub/#{location}/doc.html##{c["ocn"]}">#{c["ocn"]}</a>, } 
              end
              if c["seg"] =~/\S+/ 
                if @text_search_flag 
                  @counter_txt_ocn+=1
                  output=title+index
                end
              else
                @counter_txt_ocn+=1
                output=unless c["suffix"] =~/1/: title+index
                else %{#{title}#{c["ocn"].sort}, }
                end
              end
            end
          else output=title 
          end 
        @counters_txt=if @counter_txt_doc > 0
          %{<font size="2" color="#666666">Found in the main body of #@counter_txt_doc documents, and at #@counter_txt_ocn locations within.</font><br />}
        else ''
        end
        @body_main << output #+ details
      end
      #text_objects_endnote
      oldtid = 0
      s_endnotes.each do |e|                                               #% endnotes
        location=e["filename"][/(.+?)\.ss[ftms]/, 1]
        file_suffix=e["filename"][/.+?\.(ss[ftms])/, 1]
      #metadata_found_endnotes
        if @text_search_flag
          if e["metadata_tid"].to_i != oldtid.to_i 
            title=%{<br><hr><a href="#@hosturl/#@stub/#{location}/">#{e["title"]}</a> by #{e["creator"]} <a href="#@hosturl/#@stub/#{location}/portrait.pdf"><img border="0" width="15" height="18" src="#@url_base/b_pdf.png" alt="pdf portrait"></a><a href="#@hosturl/#@stub/#{location}/landscape.pdf"><img border="0" width="18" height="15" src="#@url_base/b_pdf.png" alt="pdf landscape"></a><br>}  if file_suffix=~/s/
            @counter_endn_doc+=1
            oldtid=e["metadata_tid"].to_i
          else title = ''
          end
          if cgi['view']=~/text/                                           #% txt endnotes
            @counter_endn_ocn+=1
            matched_endnote=e["body"].gsub(/(#@search_regx)/i,%{<span style="background-color: #ffff48">\\1</span>})
            output=%{#{title}<hr><font size="2">note <b><a href="#@hosturl/#@stub/#{location}/endnotes.html##{e["nr"]}">#{e["nr"]}</a></b> referred to from ocn <a href="#@hosturl/#@stub/#{location}/doc.html##{e["ocn"]}">#{e["ocn"]}</a>:</font> #{matched_endnote}} 
          elsif cgi['view']=~/index/                                       #% idx endnotes
            @counter_endn_ocn+=1
            output=%{#{title}<a href="#@hosturl/#@stub/#{location}/endnotes.html#_#{e["nr"]}">#{e["nr"]}</a> [&sect; <a href="#@hosturl/#@stub/#{location}/doc.html##{e["ocn"]}">#{e["ocn"]}</a>], }
          end
          @counters_endn=if @counter_endn_doc > 0
          %{<font size="2" color="#666666">Found in the endnotes of #@counter_endn_doc documents, and at #@counter_endn_ocn locations within.</font><br />}
          end
          @endnotes << output #+ details
        else @endnotes=Array.new #does not take out yet
        end
      end
      cgi.out{@header + @counters_txt + @counters_endn + @body_main.join + @endnotes.join + @tail} #% print cgi_output_header+counters+body+endnotes
    end
  rescue Exception => e
    s='<pre>' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))
    s << CGI::escapeHTML(e.message) + '</pre>'
    cgi.out{s}
    next
  ensure # eg. disconnect from server
    @conn.disconnect if @conn
  end
end