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