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