Improved history.
[egate.git] / www / search.egw
1 <html>
2 {
3 # $Id: search.egw,v 1.23 1996/01/03 15:19:41 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 {$hist($setNo,scan) > 0} {
216             set scanNo [lindex $sessionParms 1]
217             set dir [lindex $sessionParms 2]
218             if {$scanNo == ""} {
219                 set scanNo 1000
220             }
221             start-scan $scanNo 1 $dir
222             html "</body></html>\n"
223             wabort
224         }
225     }
226     set host $hist($setNo,host)
227
228     html "<head><title> WWW/Z39.50 Gateway Search " $host " </title>\n"
229     html "</head><body>\n"
230
231     set startPos [lindex $sessionParms 1]
232     set endPos [lindex $sessionParms 2]
233     set setMax 0
234     set setOffset 0
235     if {$startPos == ""} {
236         if {[z39search $setNo 1 0 B] != "1"} {
237             return
238         }
239         set r [z39.$setNo resultCount]
240         set setOffset [z39.$setNo numberOfRecordsReturned]
241         html {<h3> Records 1-} $setOffset " out of $r</h3>\n"
242         wflush
243         html "<ul>\n"
244         display-rec 1 $setOffset display-brief 0
245         incr setOffset
246         set setMax [z39.$setNo resultCount]
247         if {$setMax > $hist($setNo,maxPresent)} {
248             set setMax $hist($setNo,maxPresent)
249         }
250     } else {
251         if {[z39search $setNo 0 0 B] != "1"} {
252             return 
253         }
254         set r [z39.$setNo resultCount]
255         set setOffset $startPos
256         set setMax [z39.$setNo resultCount]
257         if {$setMax > $endPos} {
258             set setMax $endPos
259         }
260         if {$setMax > 0} {
261             buttons $setNo $setMax $startPos 0
262         }
263         html {<h3> Records } $startPos {-} $setMax " out $r</h3>\n"
264         wflush
265         html "<ul>\n"
266     }
267     if {$setMax > 0} {
268         z39present $setNo 0 $setOffset $setMax display-brief B
269     }
270     html "</ul>\n"
271     buttons $setNo $setMax $startPos 1
272 }
273
274 {
275     global debug
276     if {!$debug} return
277     html "<hr>\n"
278     html "<h3>Debug information</h3>\n"
279     html "sessionId: $sessionId <br>\n"
280     html "sessionParms: $sessionParms <br>\n"
281     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
282         html $e {: } $env($e) {<br>} \n
283     }
284     html "form: " [wform] " <br>\n"
285     html "target: " $host " <br>\n"
286     html "databases: " $hist($setNo,database) " <br>\n"
287     html "selected: " [wform base] " <br>\n"
288     html "query: --" $hist($setNo,query) "-- <br>"
289     html "setNo: " $setNo " <br>\n"
290     html "nextSetNo: " $nextSetNo " <br>\n"
291 }
292
293 </body>
294 </html>