588f13a4d6cc9585402281689f447ad3686428d3
[egate.git] / www / search.egw
1 <html>
2 {
3 # $Id: search.egw,v 1.30 1996/01/24 08:27:29 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><br>}
76
77     button-europagate
78
79     if {$hist($setNo,$scanNo,scanTerm) == ""} {
80         button-new-query 0 $setNo
81         egw_abort
82         return
83     }
84     if {$dir == "b"} {
85         set lines 20
86         set pos 20
87     } elseif {$dir == "f"} {
88         set lines 20
89         set pos 1
90     } else {
91         set lines 20
92         set pos 10
93     }
94     if {[z39scan $setNo $scanNo 0 $lines $pos $cache] != "1"} {
95         return
96     }
97
98     html {<a href="http:} $env(SCRIPT_NAME)
99     html / $sessionId {/search.egw/} $setNo + [expr $scanNo - 1] + b {">}
100     if {$useIcons} {
101         html {<img src="/egwgif/button-previous-terms.gif" }
102         html {alt="Next Terms" border=0></a>}
103     } else {
104         html {Previous Terms</a> | }
105     }
106
107     html {<a href="http:} $env(SCRIPT_NAME)
108     html / $sessionId {/search.egw/} $setNo + [expr $scanNo + 1] + f {">}
109     if {$useIcons} {
110         html {<img src="/egwgif/button-next-terms.gif" }
111         html {alt="Next Terms" border=0></a>}
112     } else {
113         html {Next Terms</a> | }
114     }
115     html {</a>}
116     button-new-query 0 $setNo
117
118     html "<p>\n"
119     display-scan $setNo $scanNo 0
120     html "<p>\n"
121
122     button-europagate
123
124     html {<a href="http:} $env(SCRIPT_NAME)
125     html / $sessionId {/search.egw/} $setNo + [expr $scanNo - 1] + b {">}
126     if {$useIcons} {
127         html {<img src="/egwgif/button-previous-terms.gif" }
128         html {alt="Next Terms" border=0></a>}
129     } else {
130         html {Previous Terms</a> | }
131     }
132
133     html {<a href="http:} $env(SCRIPT_NAME)
134     html / $sessionId {/search.egw/} $setNo + [expr $scanNo + 1] + f {">}
135     if {$useIcons} {
136         html {<img src="/egwgif/button-next-terms.gif" }
137         html {alt="Next Terms" border=0></a>}
138     } else {
139         html {Next Terms</a> | }
140     }
141     html {</a>}
142     button-new-query 0 $setNo
143
144     if {!$debug} return
145     html "<hr>\n"
146     html "<h3>Debug information</h3>\n"
147     html "sessionId: $sessionId <br>\n"
148     html "sessionParms: $sessionParms <br>\n"
149     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
150         html $e {: } $env($e) {<br>} \n
151     }
152     html "form: " [egw_form] " <br>\n"
153     html "target: " $host " <br>\n"
154     html "databases: " $hist($setNo,database) " <br>\n"
155     html "selected: " [egw_form base] " <br>\n"
156     html "setNo: " $setNo " <br>\n"
157     html "nextSetNo: " $nextSetNo " <br>\n"    
158 }
159
160 proc buttons {setNo setMax startPos after} {
161     global sessionId
162     global useIcons
163     global env
164     global hist
165
166     html "<p>\n"
167     button-europagate
168     if {$setMax < [z39.$setNo resultCount]} {
169         html {<a href="http:} $env(SCRIPT_NAME)
170         html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
171         html + [expr $setMax + $hist($setNo,maxPresent)]
172         if {$useIcons} {
173             html {"><img src="/egwgif/button-next-records.gif" alt="Next Records"}
174             html { border=0></a>}
175         } else {
176             html {">Next Records</a>} " | \n"
177         }
178     }
179     if {$startPos != "" && $startPos != "1"} {
180         html {<a href="http:} $env(SCRIPT_NAME)
181         html / $sessionId {/search.egw/} $setNo 
182         html + [expr $startPos - $hist($setNo,maxPresent)]
183         html + [expr $startPos - 1]
184         if {$useIcons} {
185             html {"><img src="/egwgif/button-previous-records.gif" }
186             html {alt="Previous Records" border=0></a>}
187         } else {
188             html {">Previous Records</a>} " | \n"
189         }
190     }
191     button-new-query 1 $setNo
192     button-new-target 1
193     button-view-history 0
194
195     html "<p>\n"
196 }
197
198     if {[info commands saveState] == ""} {
199         source z39util.tcl
200     }
201     global sessionWait
202     global nextSetNo
203     global setNo
204     global hist
205
206     set setNo [lindex $sessionParms 0]
207
208     if {[egw_form] != ""} {
209         set hist($nextSetNo,idAuthentication) $hist($setNo,idAuthentication)
210         set hist($nextSetNo,host) $hist($setNo,host)
211
212         if {$nextSetNo == $setNo} {
213             set setNo $nextSetNo
214             incr nextSetNo
215         } else {
216             catch {unset hist($setNo,hits)}
217         }
218         set hist($setNo,scan) 0
219
220         set hist($setNo,form,menu1) [egw_form menu1]
221         set hist($setNo,form,menu2) [egw_form menu2]
222         set hist($setNo,form,menu3) [egw_form menu3]
223
224         set hist($setNo,form,entry1) [egw_form entry1]
225         set hist($setNo,form,entry2) [egw_form entry2]
226         set hist($setNo,form,entry3) [egw_form entry3]
227
228         set hist($setNo,form,logic1) [egw_form logic1]
229         set hist($setNo,form,logic2) [egw_form logic2]
230         set hist($setNo,form,logic3) {}
231         
232         set host $hist($setNo,host)
233         set databases [lindex $targets($host) 1]
234
235         set b [egw_form base]
236         if {[egw_form baseall] != ""} {
237             set hist($setNo,database) $databases
238         } elseif {$b == ""} {
239             set hist($setNo,database) $databases
240         } else {
241             set hist($setNo,database) $b
242         }
243         set hist($setNo,maxPresent) [egw_form hits]
244         if {$hist($setNo,maxPresent) == ""} {
245             set hist($setNo,maxPresent) 30
246         }
247         set i [lindex $sessionParms 1]
248         if {$i == ""} {
249             for {set j 1} {$j <= 3} {incr j} {
250                 if {[egw_form scan$j] != ""} {
251                     set i $j
252                     break
253                 }
254             }
255         }
256         if {$i != ""} {
257             set scanNo 1000
258             set hist($setNo,scan) $i
259             set termPlusAttr [build-scan $hist($setNo,host) $i]
260             set hist($setNo,$scanNo,scanTerm) [lindex $termPlusAttr 0]
261             set hist($setNo,scanAttr) [lindex $termPlusAttr 1]
262             start-scan $scanNo 0 {} {}
263             html "</body></html>\n"
264             egw_abort
265             return
266         }
267         set query [build-query $hist($setNo,host) 3]
268         if {"x$query" == "x"} {
269             html "<head><title> WWW/Z39.50 Gateway Search</title>\n<body>\n"
270             displayError "Empty query" \
271                 "You must specify at least one search word"
272             html "</body></html>\n"
273             egw_abort
274         }
275         set hist($setNo,query) $query
276     } else {
277         if {[lindex $sessionParms 1] == "scan"} {
278             set scanNo 1000
279             set hist($setNo,$scanNo,scanTerm) {}
280             start-scan $scanNo 0 {} {}
281             html "</body></html>\n"
282             egw_abort
283         }
284         if {![info exists hist($setNo,scan)]} return
285         if {$hist($setNo,scan) > 0} {
286             set scanNo [lindex $sessionParms 1]
287             set dir [lindex $sessionParms 2]
288             if {$scanNo == ""} {
289                 set scanNo 1000
290             }
291             start-scan $scanNo 1 $dir $setNo
292             html "</body></html>\n"
293             egw_abort
294         }
295     }
296     set host $hist($setNo,host)
297
298     html "<head><title> WWW/Z39.50 Gateway Search " $host " </title>\n"
299     html "</head><body>\n"
300
301     set startPos [lindex $sessionParms 1]
302     set endPos [lindex $sessionParms 2]
303     set setMax 0
304     set setOffset 0
305     if {$startPos == ""} {
306         if {[z39search $setNo 1 0 B] != "1"} {
307             return
308         }
309         set r [z39.$setNo resultCount]
310         set setOffset [z39.$setNo numberOfRecordsReturned]
311         if {$setOffset > 0} {
312             html {<h3> Records 1-} $setOffset " out of $r</h3>\n"
313         } else {
314             html "<h3> No hits</h3>\n"
315         }
316         egw_flush
317         html "<ul>\n"
318         display-rec 1 $setOffset display-brief 0
319         incr setOffset
320         set setMax [z39.$setNo resultCount]
321         if {$setMax > $hist($setNo,maxPresent)} {
322             set setMax $hist($setNo,maxPresent)
323         }
324     } else {
325         if {[z39search $setNo 0 0 B] != "1"} {
326             return 
327         }
328         set r [z39.$setNo resultCount]
329         set setOffset $startPos
330         set setMax [z39.$setNo resultCount]
331         if {$setMax > $endPos} {
332             set setMax $endPos
333         }
334         if {$setMax > 0} {
335             buttons $setNo $setMax $startPos 0
336         }
337         if {$setMax > 0} {
338             html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
339         } else {
340             html "<h3> No hits</h3>\n"
341         }
342         egw_flush
343         html "<ul>\n"
344     }
345     if {$setMax > 0} {
346         z39present $setNo 0 $setOffset $setMax display-brief B
347     }
348     html "</ul>\n"
349     buttons $setNo $setMax $startPos 1
350 }
351
352 {
353     global debug
354     if {!$debug} return
355     html "<hr>\n"
356     html "<h3>Debug information</h3>\n"
357     html "sessionId: $sessionId <br>\n"
358     html "sessionParms: $sessionParms <br>\n"
359     foreach n [array names env] {
360         html "env($n) = " $env($n) " <br>\n"
361     }
362     html "form: " [egw_form] " <br>\n"
363     html "target: " $host " <br>\n"
364     html "databases: " $hist($setNo,database) " <br>\n"
365     html "selected: " [egw_form base] " <br>\n"
366     html "query: --" $hist($setNo,query) "-- <br>"
367     html "setNo: " $setNo " <br>\n"
368     html "nextSetNo: " $nextSetNo " <br>\n"
369 }
370
371 </body>
372 </html>