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