Bug fix: shell might terminate even though new request was initiated
[egate.git] / www / search.egw
1 <html>
2 {
3 # $Id: search.egw,v 1.18 1995/12/20 16:31:31 adam Exp $
4
5 proc buttons {setNo setMax startPos after} {
6     global sessionId
7     global useIcons
8     global env
9     global hist
10
11     if {!$useIcons && $after && $setMax < [z39.$setNo resultCount]} {
12         html "<p>\n"
13         html "<center>\n"
14         html {<a href="http:} $env(SCRIPT_NAME)
15         html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
16         html + [expr $setMax + $hist($setNo,maxPresent)]
17         html {"><img src="/gif/darrw.gif"></a>}
18         html "</center>\n"
19     }
20
21     html "<p>\n"
22     if {$useIcons} {
23         html {<img src="/gif/button-egw.gif">}
24     }
25     if {$setMax < [z39.$setNo resultCount]} {
26         html {<a href="http:} $env(SCRIPT_NAME)
27         html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
28         html + [expr $setMax + $hist($setNo,maxPresent)]
29         if {$useIcons} {
30             html {"><img src="/gif/button-next-records.gif" border=0></a>}
31         } else {
32             html {">Next records</a>} " | \n"
33         }
34     }
35     if {$startPos != "" && $startPos != "1"} {
36         html {<a href="http:} $env(SCRIPT_NAME)
37         html / $sessionId {/search.egw/} $setNo 
38         html + [expr $startPos - $hist($setNo,maxPresent)]
39         html + [expr $startPos - 1]
40         if {$useIcons} {
41             html {"><img src="/gif/button-previous-records.gif" border=0></a>}
42         } else {
43             html {">Previous records</a>} " | \n"
44         }
45     }
46     html {<a href="http:} $env(SCRIPT_NAME)
47     html / $sessionId {/query.egw/} $hist($setNo,host) + $setNo 
48     if {$useIcons} {
49         html {"><img src="/gif/button-new-query.gif" border=0></a>}
50     } else {
51         html {">New query</a>} " | \n"
52     }
53
54     html {<a href="http:} $env(SCRIPT_NAME)
55     html / $sessionId {/targets.egw}
56     if {$useIcons} {
57         html {"><img src="/gif/button-new-target.gif" border=0></a>}
58     } else {
59         html {">New target</a>}
60     }
61     html "<p>\n"
62     if {!$useIcons && !$after && $startPos != "" && $startPos != "1"} {
63         html "<center>\n"
64         html {<a href="http:} $env(SCRIPT_NAME)
65         html / $sessionId {/search.egw/} $setNo 
66         html + [expr $startPos - $hist($setNo,maxPresent)]
67         html + [expr $startPos - 1]
68         html {"><img src="/gif/uarrw.gif"></a>}
69         html "</center><p>\n"
70     }
71
72 }
73
74     if {[info commands saveState] == ""} {
75         source z39util.tcl
76     }
77     global sessionWait
78     global nextSetNo
79     global setNo
80     global hist
81
82     set setNo [lindex $sessionParms 0]
83     if {[wform menu1] != ""} {
84         set hist($nextSetNo,idAuthentication) $hist($setNo,idAuthentication)
85         set hist($nextSetNo,host) $hist($setNo,host)
86         set setNo $nextSetNo
87
88         set query [build-query $hist($setNo,host)]
89         if {"x$query" == "x"} {
90             html "<head><title> WWW/Z39.50 Gateway Search</title>\n<body>\n"
91             displayError "Empty query" \
92                 "You must specify at least one search word"
93             html "</body></html>\n"
94             wabort
95         }
96         set hist($setNo,query) $query
97
98         set hist($setNo,form,menu1) [wform menu1]
99         set hist($setNo,form,menu2) [wform menu2]
100         set hist($setNo,form,menu3) [wform menu3]
101
102         set hist($setNo,form,entry1) [wform entry1]
103         set hist($setNo,form,entry2) [wform entry2]
104         set hist($setNo,form,entry3) [wform entry3]
105
106         set hist($setNo,form,logic1) [wform logic1]
107         set hist($setNo,form,logic2) [wform logic2]
108
109         incr nextSetNo
110     
111         set host $hist($setNo,host)
112         set databases [lindex $targets($host) 1]
113
114         set b [wform base]
115         if {[wform baseall] != ""} {
116             set hist($setNo,database) $databases
117         } elseif {$b == ""} {
118             set hist($setNo,database) $databases
119         } else {
120             set hist($setNo,database) $b
121         }
122         set hist($setNo,maxPresent) [wform hits]
123         if {$hist($setNo,maxPresent) == ""} {
124             set hist($setNo,maxPresent) 30
125         }
126     }
127     set host $hist($setNo,host)
128     set databases [lindex $targets($host) 1]
129
130     html "<head><title> WWW/Z39.50 Gateway Search " $host " </title>\n"
131     html "</head><body>\n"
132
133     set startPos [lindex $sessionParms 1]
134     set endPos [lindex $sessionParms 2]
135     set setMax 0
136     set setOffset 0
137     if {$startPos == ""} {
138         if {[z39search $setNo 1 0 B] != "1"} {
139             return
140         }
141         set r [z39.$setNo resultCount]
142         html "<h2> Search result $r hits</h2>\n"
143         wflush
144         set setOffset [z39.$setNo numberOfRecordsReturned]
145         display-rec 1 $setOffset display-brief 0
146         incr setOffset
147         set setMax [z39.$setNo resultCount]
148         if {$setMax > $hist($setNo,maxPresent)} {
149             set setMax $hist($setNo,maxPresent)
150         }
151     } else {
152         if {[z39search $setNo 0 0 B] != "1"} {
153             return 
154         }
155         set r [z39.$setNo resultCount]
156         html "<h2> Search result $r hits</h2>\n"
157         wflush
158         set setOffset $startPos
159         set setMax [z39.$setNo resultCount]
160         if {$setMax > $endPos} {
161             set setMax $endPos
162         }
163         if {$setMax > 0} {
164             buttons $setNo $setMax $startPos 0
165         }
166     }
167     if {$setMax > 0} {
168         z39present $setNo 0 $setOffset $setMax display-brief B
169     }
170
171     buttons $setNo $setMax $startPos 1
172 }
173
174 {
175     html "<hr>\n"
176     html "<h3>Debug information</h3>\n"
177     html "sessionId: $sessionId <br>\n"
178     html "sessionParms: $sessionParms <br>\n"
179     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
180         html $e {: } $env($e) {<br>} \n
181     }
182     html "form: " [wform] " <br>\n"
183     html "target: " $host " <br>\n"
184     html "databases: " $hist($setNo,database) " <br>\n"
185     html "selected: " [wform base] " <br>\n"
186     html "query: --" $hist($setNo,query) "-- <br>"
187     html "setNo: " $setNo " <br>\n"
188     html "nextSetNo: " $nextSetNo " <br>\n"
189 }
190
191 </body>
192 </html>