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