Work on scan window.
[egate.git] / www / search.egw
1 <html>
2 {
3 # $Id: search.egw,v 1.27 1996/01/12 10:03:19 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 {} $setNo
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 {![info exists hist($setNo,scan)]} return
254         if {$hist($setNo,scan) > 0} {
255             set scanNo [lindex $sessionParms 1]
256             set dir [lindex $sessionParms 2]
257             if {$scanNo == ""} {
258                 set scanNo 1000
259             }
260             start-scan $scanNo 1 $dir $setNo
261             html "</body></html>\n"
262             wabort
263         }
264     }
265     set host $hist($setNo,host)
266
267     html "<head><title> WWW/Z39.50 Gateway Search " $host " </title>\n"
268     html "</head><body>\n"
269
270     set startPos [lindex $sessionParms 1]
271     set endPos [lindex $sessionParms 2]
272     set setMax 0
273     set setOffset 0
274     if {$startPos == ""} {
275         if {[z39search $setNo 1 0 B] != "1"} {
276             return
277         }
278         set r [z39.$setNo resultCount]
279         set setOffset [z39.$setNo numberOfRecordsReturned]
280         if {$setOffset > 0} {
281             html {<h3> Records 1-} $setOffset " out of $r</h3>\n"
282         } else {
283             html "<h3> No hits</h3>\n"
284         }
285         wflush
286         html "<ul>\n"
287         display-rec 1 $setOffset display-brief 0
288         incr setOffset
289         set setMax [z39.$setNo resultCount]
290         if {$setMax > $hist($setNo,maxPresent)} {
291             set setMax $hist($setNo,maxPresent)
292         }
293     } else {
294         if {[z39search $setNo 0 0 B] != "1"} {
295             return 
296         }
297         set r [z39.$setNo resultCount]
298         set setOffset $startPos
299         set setMax [z39.$setNo resultCount]
300         if {$setMax > $endPos} {
301             set setMax $endPos
302         }
303         if {$setMax > 0} {
304             buttons $setNo $setMax $startPos 0
305         }
306         if {$setMax > 0} {
307             html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
308         } else {
309             html "<h3> No hits</h3>\n"
310         }
311         wflush
312         html "<ul>\n"
313     }
314     if {$setMax > 0} {
315         z39present $setNo 0 $setOffset $setMax display-brief B
316     }
317     html "</ul>\n"
318     buttons $setNo $setMax $startPos 1
319 }
320
321 {
322     global debug
323     if {!$debug} return
324     html "<hr>\n"
325     html "<h3>Debug information</h3>\n"
326     html "sessionId: $sessionId <br>\n"
327     html "sessionParms: $sessionParms <br>\n"
328     foreach n [array names env] {
329         html "env($n) = " $env($n) " <br>\n"
330     }
331     html "form: " [wform] " <br>\n"
332     html "target: " $host " <br>\n"
333     html "databases: " $hist($setNo,database) " <br>\n"
334     html "selected: " [wform base] " <br>\n"
335     html "query: --" $hist($setNo,query) "-- <br>"
336     html "setNo: " $setNo " <br>\n"
337     html "nextSetNo: " $nextSetNo " <br>\n"
338 }
339
340 </body>
341 </html>