More work on scan. The search.egw script takes care of cached
[egate.git] / www / search.egw
1 <html>
2 {
3 # $Id: search.egw,v 1.20 1995/12/22 14:21:15 adam Exp $
4
5 proc perform-scan {} {
6     global sessionId
7     global sessionParms
8     global sessionWait
9     global setNo
10     global hist
11     global targets
12     global nextSetNo
13     global env
14
15     set scanNo 1000
16
17     set termPlusAttr [build-scan $hist($setNo,host) 3]
18
19     if {"$termPlusAttr" == ""} {
20         html "<head><title> WWW/Z39.50 Gateway Scan</title>\n<body>\n"
21         displayError "Empty query" \
22             "You must specify at least one search word"
23         html "</body></html>\n"
24         wabort
25     }
26     set hist($setNo,scanAttr) [lindex $termPlusAttr 1]
27     set hist($setNo,$scanNo,scanTerm) [lindex $termPlusAttr 0]
28     
29     set hist($setNo,form,menu1) [wform menu1]
30     set hist($setNo,form,menu2) [wform menu2]
31     set hist($setNo,form,menu3) [wform menu3]
32
33     set hist($setNo,form,entry1) [wform entry1]
34     set hist($setNo,form,entry2) [wform entry2]
35     set hist($setNo,form,entry3) [wform entry3]
36
37     set hist($setNo,form,logic1) [wform logic1]
38     set hist($setNo,form,logic2) [wform logic2]
39
40     set host $hist($setNo,host)
41     set databases [lindex $targets($host) 1]
42
43     set b [wform base]
44     if {[wform baseall] != ""} {
45         set hist($setNo,database) $databases
46     } elseif {$b == ""} {
47         set hist($setNo,database) $databases
48     } else {
49         set hist($setNo,database) $b
50     }
51     set hist($setNo,maxPresent) [wform hits]
52     if {$hist($setNo,maxPresent) == ""} {
53         set hist($setNo,maxPresent) 30
54     }
55     set host $hist($setNo,host)
56     set databases [lindex $targets($host) 1]
57
58     html "<head><title> WWW/Z39.50 Gateway Scan " $host " </title>\n"
59     html "</head><body>\n"
60
61     if {[z39scan $setNo $scanNo 0 20 10] != "1"} {
62         return
63     }
64     display-scan $setNo $scanNo 0
65
66     html "<hr>\n"
67     html "<h3>Debug information</h3>\n"
68     html "sessionId: $sessionId <br>\n"
69     html "sessionParms: $sessionParms <br>\n"
70     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
71         html $e {: } $env($e) {<br>} \n
72     }
73     html "form: " [wform] " <br>\n"
74     html "target: " $host " <br>\n"
75     html "databases: " $hist($setNo,database) " <br>\n"
76     html "selected: " [wform base] " <br>\n"
77     html "setNo: " $setNo " <br>\n"
78     html "nextSetNo: " $nextSetNo " <br>\n"
79     
80     html "</body>\n"
81 }
82
83 proc buttons {setNo setMax startPos after} {
84     global sessionId
85     global useIcons
86     global env
87     global hist
88
89     if {!$useIcons && $after && $setMax < [z39.$setNo resultCount]} {
90         html "<p>\n"
91         html "<center>\n"
92         html {<a href="http:} $env(SCRIPT_NAME)
93         html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
94         html + [expr $setMax + $hist($setNo,maxPresent)]
95         html {"><img src="/gif/darrw.gif"></a>}
96         html "</center>\n"
97     }
98
99     html "<p>\n"
100     if {$useIcons} {
101         html {<img src="/gif/button-egw.gif">}
102     }
103     if {$setMax < [z39.$setNo resultCount]} {
104         html {<a href="http:} $env(SCRIPT_NAME)
105         html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
106         html + [expr $setMax + $hist($setNo,maxPresent)]
107         if {$useIcons} {
108             html {"><img src="/gif/button-next-records.gif" border=0></a>}
109         } else {
110             html {">Next records</a>} " | \n"
111         }
112     }
113     if {$startPos != "" && $startPos != "1"} {
114         html {<a href="http:} $env(SCRIPT_NAME)
115         html / $sessionId {/search.egw/} $setNo 
116         html + [expr $startPos - $hist($setNo,maxPresent)]
117         html + [expr $startPos - 1]
118         if {$useIcons} {
119             html {"><img src="/gif/button-previous-records.gif" border=0></a>}
120         } else {
121             html {">Previous records</a>} " | \n"
122         }
123     }
124     html {<a href="http:} $env(SCRIPT_NAME)
125     html / $sessionId {/query.egw/} $hist($setNo,host) + $setNo 
126     if {$useIcons} {
127         html {"><img src="/gif/button-new-query.gif" border=0></a>}
128     } else {
129         html {">New query</a>} " | \n"
130     }
131
132     html {<a href="http:} $env(SCRIPT_NAME)
133     html / $sessionId {/targets.egw}
134     if {$useIcons} {
135         html {"><img src="/gif/button-new-target.gif" border=0></a>}
136     } else {
137         html {">New target</a>}
138     }
139     html "<p>\n"
140     if {!$useIcons && !$after && $startPos != "" && $startPos != "1"} {
141         html "<center>\n"
142         html {<a href="http:} $env(SCRIPT_NAME)
143         html / $sessionId {/search.egw/} $setNo 
144         html + [expr $startPos - $hist($setNo,maxPresent)]
145         html + [expr $startPos - 1]
146         html {"><img src="/gif/uarrw.gif"></a>}
147         html "</center><p>\n"
148     }
149
150 }
151
152     if {[info commands saveState] == ""} {
153         source z39util.tcl
154     }
155     global sessionWait
156     global nextSetNo
157     global setNo
158     global hist
159
160     set setNo [lindex $sessionParms 0]
161
162     if {[wform menu1] != ""} {
163         set hist($nextSetNo,idAuthentication) $hist($setNo,idAuthentication)
164         set hist($nextSetNo,host) $hist($setNo,host)
165
166         if {$nextSetNo == $setNo} {
167             set setNo $nextSetNo
168             incr nextSetNo
169         } else {
170             catch {unset hist($setNo,hits)}
171         }
172         if {[wform submit] == "Scan"} {
173             perform-scan
174             wabort
175         }
176         set query [build-query $hist($setNo,host) 3]
177         if {"x$query" == "x"} {
178             html "<head><title> WWW/Z39.50 Gateway Search</title>\n<body>\n"
179             displayError "Empty query" \
180                 "You must specify at least one search word"
181             html "</body></html>\n"
182             wabort
183         }
184         set hist($setNo,query) $query
185
186         set hist($setNo,form,menu1) [wform menu1]
187         set hist($setNo,form,menu2) [wform menu2]
188         set hist($setNo,form,menu3) [wform menu3]
189
190         set hist($setNo,form,entry1) [wform entry1]
191         set hist($setNo,form,entry2) [wform entry2]
192         set hist($setNo,form,entry3) [wform entry3]
193
194         set hist($setNo,form,logic1) [wform logic1]
195         set hist($setNo,form,logic2) [wform logic2]
196
197         set host $hist($setNo,host)
198         set databases [lindex $targets($host) 1]
199
200         set b [wform base]
201         if {[wform baseall] != ""} {
202             set hist($setNo,database) $databases
203         } elseif {$b == ""} {
204             set hist($setNo,database) $databases
205         } else {
206             set hist($setNo,database) $b
207         }
208         set hist($setNo,maxPresent) [wform hits]
209         if {$hist($setNo,maxPresent) == ""} {
210             set hist($setNo,maxPresent) 30
211         }
212     }
213     set host $hist($setNo,host)
214     set databases [lindex $targets($host) 1]
215
216     html "<head><title> WWW/Z39.50 Gateway Search " $host " </title>\n"
217     html "</head><body>\n"
218
219     set startPos [lindex $sessionParms 1]
220     set endPos [lindex $sessionParms 2]
221     set setMax 0
222     set setOffset 0
223     if {$startPos == ""} {
224         if {[z39search $setNo 1 0 B] != "1"} {
225             return
226         }
227         set r [z39.$setNo resultCount]
228         html "<h3> Search result $r hits</h3>\n"
229         wflush
230         set setOffset [z39.$setNo numberOfRecordsReturned]
231         display-rec 1 $setOffset display-brief 0
232         incr setOffset
233         set setMax [z39.$setNo resultCount]
234         if {$setMax > $hist($setNo,maxPresent)} {
235             set setMax $hist($setNo,maxPresent)
236         }
237     } else {
238         if {[z39search $setNo 0 0 B] != "1"} {
239             return 
240         }
241         set r [z39.$setNo resultCount]
242         set setOffset $startPos
243         set setMax [z39.$setNo resultCount]
244         if {$setMax > $endPos} {
245             set setMax $endPos
246         }
247         if {$setMax > 0} {
248             buttons $setNo $setMax $startPos 0
249         }
250         html "<h3> Search result $r hits</h3>\n"
251         wflush
252     }
253     if {$setMax > 0} {
254         z39present $setNo 0 $setOffset $setMax display-brief B
255     }
256
257     buttons $setNo $setMax $startPos 1
258 }
259
260 {
261     html "<hr>\n"
262     html "<h3>Debug information</h3>\n"
263     html "sessionId: $sessionId <br>\n"
264     html "sessionParms: $sessionParms <br>\n"
265     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
266         html $e {: } $env($e) {<br>} \n
267     }
268     html "form: " [wform] " <br>\n"
269     html "target: " $host " <br>\n"
270     html "databases: " $hist($setNo,database) " <br>\n"
271     html "selected: " [wform base] " <br>\n"
272     html "query: --" $hist($setNo,query) "-- <br>"
273     html "setNo: " $setNo " <br>\n"
274     html "nextSetNo: " $nextSetNo " <br>\n"
275 }
276
277 </body>
278 </html>