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