Work on scan.
[egate.git] / www / search.egw
1 <html>
2 {
3 # $Id: search.egw,v 1.28 1996/01/12 13:08:30 adam Exp $
4
5 proc start-scan {scanNo cache dir initSet} {
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     global useIcons
15     global debug
16
17     set host $hist($setNo,host)
18
19     html "<head><title> WWW/Z39.50 Gateway Scan " $host " </title>\n"
20     html "</head><body>\n"
21
22     set databases [lindex $targets($host) 1]
23
24     if {$initSet == ""} {
25         set databaseDefault [lindex $databases 0]
26         set oSetNo 0
27     } else {
28         set oSetNo $initSet
29         set databaseDefault $hist($oSetNo,database)
30     }
31     
32     html {<form action="http:} $env(SCRIPT_NAME)
33     html / $sessionId {/search.egw/} $setNo {+1" method=get>} \n
34     set nodb [llength $databases]
35     if {$nodb > 1} {
36         if {$nodb > 2} {
37             html "Databases:<br>\n"
38         }
39         set i 0
40         foreach d $databases {
41             html {<input type="checkbox" name="base" value="} $d 
42             if {[lsearch $databaseDefault $d] == -1} {
43                 html {"> } $d \n
44             } else {
45                 html {" checked> } $d \n
46             }
47         }
48         html "<br>\n"
49         if {$nodb > 2} {
50             html {<input type="checkbox" name="baseall" value="} 
51             html [concat $databases] {"> All <br>} \n
52         }
53         html "Input your search criteria:<br>\n"
54     }
55     set fields [lindex $targets($host) 2]
56     set no 1
57     html {<select name="menu} $no {">} \n
58     set template {}
59     if {$oSetNo > 0} {
60         set template [join $hist($oSetNo,form,menu$no)]
61     }
62     if {[string length $template] > 0} {
63         html {<option> } $template \n
64     }
65     foreach f $fields {
66         set name [lindex $f 0]
67         if {$template == $name} continue
68         html {<option> } $name \n
69     }
70     html "</select>\n"
71     html {<input type="text" name="entry} $no {"}
72     html { size=35> }
73     html {<input type=submit name=submit value="Scan">}
74     html "\n"
75     html {</form>}
76     if {$hist($setNo,$scanNo,scanTerm) == ""} {
77         wabort
78         return
79     }
80     if {$dir == "b"} {
81         set lines 20
82         set pos 20
83     } elseif {$dir == "f"} {
84         set lines 20
85         set pos 1
86     } else {
87         set lines 20
88         set pos 10
89     }
90     if {[z39scan $setNo $scanNo 0 $lines $pos $cache] != "1"} {
91         return
92     }
93
94     html "<br><p>\n"
95     display-scan $setNo $scanNo 0
96     html "<p>\n"
97
98     button-europagate
99
100     html {<a href="http:} $env(SCRIPT_NAME)
101     html / $sessionId {/search.egw/} $setNo + [expr $scanNo - 1] + b {">}
102     if {$useIcons} {
103         html {<img src="/egwgif/button-previous-terms.gif" }
104         html {alt="Next Terms" border=0></a>}
105     } else {
106         html {Previous Terms</a> | }
107     }
108
109     html {<a href="http:} $env(SCRIPT_NAME)
110     html / $sessionId {/search.egw/} $setNo + [expr $scanNo + 1] + f {">}
111     if {$useIcons} {
112         html {<img src="/egwgif/button-next-terms.gif" }
113         html {alt="Next Terms" border=0></a>}
114     } else {
115         html {Next Terms</a> | }
116     }
117     html {</a>}
118     button-new-query 0 $setNo
119
120     if {!$debug} return
121     html "<hr>\n"
122     html "<h3>Debug information</h3>\n"
123     html "sessionId: $sessionId <br>\n"
124     html "sessionParms: $sessionParms <br>\n"
125     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
126         html $e {: } $env($e) {<br>} \n
127     }
128     html "form: " [wform] " <br>\n"
129     html "target: " $host " <br>\n"
130     html "databases: " $hist($setNo,database) " <br>\n"
131     html "selected: " [wform base] " <br>\n"
132     html "setNo: " $setNo " <br>\n"
133     html "nextSetNo: " $nextSetNo " <br>\n"    
134 }
135
136 proc buttons {setNo setMax startPos after} {
137     global sessionId
138     global useIcons
139     global env
140     global hist
141
142     html "<p>\n"
143     button-europagate
144     if {$setMax < [z39.$setNo resultCount]} {
145         html {<a href="http:} $env(SCRIPT_NAME)
146         html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
147         html + [expr $setMax + $hist($setNo,maxPresent)]
148         if {$useIcons} {
149             html {"><img src="/egwgif/button-next-records.gif" alt="Next Records"}
150             html { border=0></a>}
151         } else {
152             html {">Next Records</a>} " | \n"
153         }
154     }
155     if {$startPos != "" && $startPos != "1"} {
156         html {<a href="http:} $env(SCRIPT_NAME)
157         html / $sessionId {/search.egw/} $setNo 
158         html + [expr $startPos - $hist($setNo,maxPresent)]
159         html + [expr $startPos - 1]
160         if {$useIcons} {
161             html {"><img src="/egwgif/button-previous-records.gif" }
162             html {alt="Previous Records" border=0></a>}
163         } else {
164             html {">Previous Records</a>} " | \n"
165         }
166     }
167     button-new-query 1 $setNo
168     button-new-target 1
169     button-view-history 0
170
171     html "<p>\n"
172 }
173
174     if {[info commands saveState] == ""} {
175         source z39util.tcl
176     }
177     global sessionWait
178     global nextSetNo
179     global setNo
180     global hist
181
182     set setNo [lindex $sessionParms 0]
183
184     if {[wform] != ""} {
185         set hist($nextSetNo,idAuthentication) $hist($setNo,idAuthentication)
186         set hist($nextSetNo,host) $hist($setNo,host)
187
188         if {$nextSetNo == $setNo} {
189             set setNo $nextSetNo
190             incr nextSetNo
191         } else {
192             catch {unset hist($setNo,hits)}
193         }
194         set hist($setNo,scan) 0
195
196         set hist($setNo,form,menu1) [wform menu1]
197         set hist($setNo,form,menu2) [wform menu2]
198         set hist($setNo,form,menu3) [wform menu3]
199
200         set hist($setNo,form,entry1) [wform entry1]
201         set hist($setNo,form,entry2) [wform entry2]
202         set hist($setNo,form,entry3) [wform entry3]
203
204         set hist($setNo,form,logic1) [wform logic1]
205         set hist($setNo,form,logic2) [wform logic2]
206         set hist($setNo,form,logic3) {}
207         
208         set host $hist($setNo,host)
209         set databases [lindex $targets($host) 1]
210
211         set b [wform base]
212         if {[wform baseall] != ""} {
213             set hist($setNo,database) $databases
214         } elseif {$b == ""} {
215             set hist($setNo,database) $databases
216         } else {
217             set hist($setNo,database) $b
218         }
219         set hist($setNo,maxPresent) [wform hits]
220         if {$hist($setNo,maxPresent) == ""} {
221             set hist($setNo,maxPresent) 30
222         }
223         set i [lindex $sessionParms 1]
224         if {$i == ""} {
225             for {set j 1} {$j <= 3} {incr j} {
226                 if {[wform scan$j] != ""} {
227                     set i $j
228                     break
229                 }
230             }
231         }
232         if {$i != ""} {
233             set scanNo 1000
234             set hist($setNo,scan) $i
235             set termPlusAttr [build-scan $hist($setNo,host) $i]
236             set hist($setNo,$scanNo,scanTerm) [lindex $termPlusAttr 0]
237             set hist($setNo,scanAttr) [lindex $termPlusAttr 1]
238             start-scan $scanNo 0 {} {}
239             html "</body></html>\n"
240             wabort
241             return
242         }
243         set query [build-query $hist($setNo,host) 3]
244         if {"x$query" == "x"} {
245             html "<head><title> WWW/Z39.50 Gateway Search</title>\n<body>\n"
246             displayError "Empty query" \
247                 "You must specify at least one search word"
248             html "</body></html>\n"
249             wabort
250         }
251         set hist($setNo,query) $query
252     } else {
253         if {[lindex $sessionParms 1] == "scan"} {
254             set scanNo 1000
255             set hist($setNo,$scanNo,scanTerm) {}
256             start-scan $scanNo 0 {} {}
257             html "</body></html>\n"
258             wabort
259         }
260         if {![info exists hist($setNo,scan)]} return
261         if {$hist($setNo,scan) > 0} {
262             set scanNo [lindex $sessionParms 1]
263             set dir [lindex $sessionParms 2]
264             if {$scanNo == ""} {
265                 set scanNo 1000
266             }
267             start-scan $scanNo 1 $dir $setNo
268             html "</body></html>\n"
269             wabort
270         }
271     }
272     set host $hist($setNo,host)
273
274     html "<head><title> WWW/Z39.50 Gateway Search " $host " </title>\n"
275     html "</head><body>\n"
276
277     set startPos [lindex $sessionParms 1]
278     set endPos [lindex $sessionParms 2]
279     set setMax 0
280     set setOffset 0
281     if {$startPos == ""} {
282         if {[z39search $setNo 1 0 B] != "1"} {
283             return
284         }
285         set r [z39.$setNo resultCount]
286         set setOffset [z39.$setNo numberOfRecordsReturned]
287         if {$setOffset > 0} {
288             html {<h3> Records 1-} $setOffset " out of $r</h3>\n"
289         } else {
290             html "<h3> No hits</h3>\n"
291         }
292         wflush
293         html "<ul>\n"
294         display-rec 1 $setOffset display-brief 0
295         incr setOffset
296         set setMax [z39.$setNo resultCount]
297         if {$setMax > $hist($setNo,maxPresent)} {
298             set setMax $hist($setNo,maxPresent)
299         }
300     } else {
301         if {[z39search $setNo 0 0 B] != "1"} {
302             return 
303         }
304         set r [z39.$setNo resultCount]
305         set setOffset $startPos
306         set setMax [z39.$setNo resultCount]
307         if {$setMax > $endPos} {
308             set setMax $endPos
309         }
310         if {$setMax > 0} {
311             buttons $setNo $setMax $startPos 0
312         }
313         if {$setMax > 0} {
314             html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
315         } else {
316             html "<h3> No hits</h3>\n"
317         }
318         wflush
319         html "<ul>\n"
320     }
321     if {$setMax > 0} {
322         z39present $setNo 0 $setOffset $setMax display-brief B
323     }
324     html "</ul>\n"
325     buttons $setNo $setMax $startPos 1
326 }
327
328 {
329     global debug
330     if {!$debug} return
331     html "<hr>\n"
332     html "<h3>Debug information</h3>\n"
333     html "sessionId: $sessionId <br>\n"
334     html "sessionParms: $sessionParms <br>\n"
335     foreach n [array names env] {
336         html "env($n) = " $env($n) " <br>\n"
337     }
338     html "form: " [wform] " <br>\n"
339     html "target: " $host " <br>\n"
340     html "databases: " $hist($setNo,database) " <br>\n"
341     html "selected: " [wform base] " <br>\n"
342     html "query: --" $hist($setNo,query) "-- <br>"
343     html "setNo: " $setNo " <br>\n"
344     html "nextSetNo: " $nextSetNo " <br>\n"
345 }
346
347 </body>
348 </html>