Many improvements and bug fixes.
[egate.git] / www / search.egw
1 <html>
2 {
3 # $Id: search.egw,v 1.11 1995/11/08 16:14:33 adam Exp $
4
5 proc buttons {setNo setMax startPos} {
6     global sessionId
7     global env
8     global hist
9
10     html "<p>\n"
11     if {$setMax < [z39.$setNo resultCount]} {
12         html {<a href="http:} $env(SCRIPT_NAME)
13         html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
14         html + [expr $setMax + $hist($setNo,maxPresent)] {"> Next </a>} "| \n"
15     }
16     if {$startPos != "" && $startPos != "1"} {
17         html {<a href="http:} $env(SCRIPT_NAME)
18         html / $sessionId {/search.egw/} $setNo 
19         if {[expr $startPos - $hist($setNo,maxPresent)] > 1} {
20             html + [expr $startPos - $hist($setNo,maxPresent)]
21             html + [expr $startPos - 1]
22         }
23         html {"> Prev </a>} "| \n"
24     }
25     html {<a href="http:} $env(SCRIPT_NAME)
26     html / $sessionId {/targets.egw"> New target </a>} " | \n"
27     html {<a href="http:} $env(SCRIPT_NAME)
28     html / $sessionId {/query.egw/} $hist($setNo,host) + $setNo 
29     html {"> New query </a>} "<p>\n"
30 }
31
32     if {[info commands saveState] == ""} {
33         source z39util.tcl
34     }
35     global sessionWait
36     global nextSetNo
37     global setNo
38     global hist
39
40     if {[wform menu1] == ""} {
41         set setNo [lindex $sessionParms 0]
42     } else {
43         if {![info exists hist($nextSetNo,host)]} {
44             set hist($nextSetNo,idAuthentication) $hist($setNo,idAuthentication)
45             set hist($nextSetNo,host) $hist($setNo,host)
46         }
47         set setNo $nextSetNo
48         html "using host " $hist($setNo,host) " <br\n"
49         incr nextSetNo
50
51         set hist($setNo,query) [build-query $hist($setNo,host)]
52         set b [wform base]
53         if {$b == ""} {
54             set hist($setNo,database) $databases
55         } else {
56             set hist($setNo,database) $b
57         }
58         set hist($setNo,maxPresent) [wform hits]
59         if {$hist($setNo,maxPresent) == ""} {
60             set hist($setNo,maxPresent) 30
61         }
62     }
63     set host $hist($setNo,host)
64     set databases [lindex $targets($host) 1]
65
66     html "<head><title> WWW/Z39.50 Gateway Search " $host " </title>\n"
67     html "</head><body>\n"
68
69     set startPos [lindex $sessionParms 1]
70     set endPos [lindex $sessionParms 2]
71     set setMax 0
72     set setOffset 0
73     if {$startPos == ""} {
74         if {[z39search $setNo 1] != "1"} {
75             return
76         }
77         set r [z39.$setNo resultCount]
78         html "<h2> Search result $r hits</h2>\n"
79         wflush
80         set setOffset [z39.$setNo numberOfRecordsReturned]
81         display-rec 1 $setOffset display-brief z39
82         incr setOffset
83         set setMax [z39.$setNo resultCount]
84         if {$setMax > $hist($setNo,maxPresent)} {
85             set setMax $hist($setNo,maxPresent)
86         }
87     } else {
88         if {[z39search $setNo 0] != "1"} {
89             return 
90         }
91         set r [z39.$setNo resultCount]
92         html "<h2> Search result $r hits</h2>\n"
93         wflush
94         set setOffset $startPos
95         set setMax [z39.$setNo resultCount]
96         if {$setMax > $endPos} {
97             set setMax $endPos
98         }
99         if {$setMax > 0} {
100             buttons $setNo $setMax $startPos
101         }
102     }
103     if {$setMax > 0} {
104         z39present $setNo $setOffset $setMax display-brief
105     }
106
107     buttons $setNo $setMax $startPos
108 }
109
110 {
111     html "<hr>\n"
112     html "<h3>Debug information</h3>\n"
113     html "sessionId: $sessionId <br>\n"
114     html "sessionParms: $sessionParms <br>\n"
115     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
116         html $e {: } $env($e) {<br>} \n
117     }
118     html "form: " [wform] " <br>\n"
119     html "target: " $host " <br>\n"
120     html "databases: " $hist($setNo,database) " <br>\n"
121     html "selected: " [wform base] " <br>\n"
122     html "query: --" $hist($setNo,query) "-- <br>"
123     html "setNo: " $setNo " <br>\n"
124     html "nextSetNo: " $nextSetNo " <br>\n"
125 }
126
127 </body>
128 </html>