Lots of changes. They aren't visible though.
[egate.git] / www / search.egw
1 <html>
2 {
3 # $Id: search.egw,v 1.34 1996/03/07 12:46:09 adam Exp $
4
5 proc start-scan {scanNo targetNo 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,$targetNo,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 + $targetNo + 
44         html [expr $scanNo - 1] + b {">}
45         if {$useIcons} {
46             html {<img src="/egwgif/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 + $targetNo +
54         html [expr $scanNo + 1] + f {">}
55         if {$useIcons} {
56             html {<img src="/egwgif/button-next-terms.gif" }
57             html {alt="Next Terms" border=0></a>}
58         } else {
59             html {Next Terms</a> | }
60         }
61         html {</a>}
62     }
63     button-new-query 0 $setNo
64
65     set databases [lindex $targets($host) 1]
66
67     if {$initSet == ""} {
68         set databaseDefault [lindex $databases 0]
69         set oSetNo 0
70     } else {
71         set oSetNo $initSet
72         set databaseDefault $hist($oSetNo,$targetNo,database)
73     }
74     
75     html {<form action="http:} $env(SCRIPT_NAME)
76     html / $sessionId {/search.egw/} $setNo + $targetNo {+1" method=get>} \n
77     set nodb [llength $databases]
78     if {$nodb > 1} {
79         if {$nodb > 2} {
80             html "Databases:<br>\n"
81         }
82         set i 0
83         foreach d $databases {
84             html {<input type="checkbox" name="base" value="} $d 
85             if {[lsearch $databaseDefault $d] == -1} {
86                 html {"> } $d \n
87             } else {
88                 html {" checked> } $d \n
89             }
90         }
91         html "<br>\n"
92         if {$nodb > 2} {
93             html {<input type="checkbox" name="baseall" value="} 
94             html [concat $databases] {"> All <br>} \n
95         }
96     }
97     html "Input your scan criteria:<br>\n"
98     set fields [lindex $targets($host) 2]
99     set no 1
100     html {<select name="menu} $no {">} \n
101     set template {}
102     if {$oSetNo > 0} {
103         set template [join $hist($oSetNo,form,menu$no)]
104         egw_log debug "template=$template"
105     }
106     if {[string length $template] > 0} {
107         html {<option> } $template \n
108     }
109     foreach f $fields {
110         set name [lindex $f 0]
111         if {$template == $name} continue
112         html {<option> } $name \n
113     }
114     html "</select>\n"
115     html {<input type="text" name="entry} $no {"}
116     html { size=35> }
117     html {<input type=submit name=submit value="Scan">}
118     html "\n"
119     html {</form><br>}
120
121     set useIcons 0
122     if {$hist($setNo,$scanNo,scanTerm) == ""} {
123         button-europagate
124         button-new-query 0 $setNo        
125         return
126     }
127
128     html "<p>\n"
129     display-scan $setNo $scanNo 0
130     html "<p>\n"
131
132     button-europagate
133
134     html {<a href="http:} $env(SCRIPT_NAME)
135     html / $sessionId {/search.egw/} $setNo + $targetNo +
136     html [expr $scanNo - 1] + b {">}
137     if {$useIcons} {
138         html {<img src="/egwgif/button-previous-terms.gif" }
139         html {alt="Next Terms" border=0></a>}
140     } else {
141         html {Previous Terms</a> | }
142     }
143
144     html {<a href="http:} $env(SCRIPT_NAME)
145     html / $sessionId {/search.egw/} $setNo + $targetNo +
146     html [expr $scanNo + 1] + f {">}
147     if {$useIcons} {
148         html {<img src="/egwgif/button-next-terms.gif" }
149         html {alt="Next Terms" border=0></a>}
150     } else {
151         html {Next Terms</a> | }
152     }
153     html {</a>}
154     button-new-query 0 $setNo
155
156     if {!$debug} return
157     html "<hr>\n"
158     html "<h3>Debug information</h3>\n"
159     html "sessionId: $sessionId <br>\n"
160     html "sessionParms: $sessionParms <br>\n"
161     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
162         html $e {: } $env($e) {<br>} \n
163     }
164     html "form: " [egw_form] " <br>\n"
165     html "target: " $host " <br>\n"
166     html "databases: " $hist($setNo,$targetNo,database) " <br>\n"
167     html "selected: " [egw_form base] " <br>\n"
168     html "setNo: " $setNo " <br>\n"
169     html "nextSetNo: " $nextSetNo " <br>\n"    
170 }
171
172     if {[info commands saveState] == ""} {
173         source z39util.tcl
174     }
175     global sessionWait
176     global nextSetNo
177     global setNo
178     global hist
179
180     set setNo [lindex $sessionParms 0]
181     set targetNo [lindex $sessionParms 1]
182     set startPos [lindex $sessionParms 2]
183     set endPos [lindex $sessionParms 3]
184
185     if {[egw_form] != ""} {
186         set hist($nextSetNo,$targetNo,idAuthentication) \
187             $hist($setNo,$targetNo,idAuthentication)
188         set hist($nextSetNo,$targetNo,host) \
189             $hist($setNo,$targetNo,host)
190
191         if {$nextSetNo == $setNo} {
192             set setNo $nextSetNo
193             incr nextSetNo
194         } else {
195             catch {unset hist($setNo,hits)}
196         }
197         set hist($setNo,scan) 0
198
199         set hist($setNo,form,menu1) [egw_form menu1]
200         set hist($setNo,form,menu2) [egw_form menu2]
201         set hist($setNo,form,menu3) [egw_form menu3]
202
203         set hist($setNo,form,entry1) [egw_form entry1]
204         set hist($setNo,form,entry2) [egw_form entry2]
205         set hist($setNo,form,entry3) [egw_form entry3]
206
207         set hist($setNo,form,logic1) [egw_form logic1]
208         set hist($setNo,form,logic2) [egw_form logic2]
209         set hist($setNo,form,logic3) {}
210         
211         set host $hist($setNo,0,host)
212         set databases [lindex $targets($host) 1]
213
214         set b [egw_form base]
215         if {[egw_form baseall] != ""} {
216             set hist($setNo,0,database) $databases
217         } elseif {$b == ""} {
218             set hist($setNo,0,database) $databases
219         } else {
220             set hist($setNo,0,database) $b
221         }
222         set hist($setNo,maxPresent) [egw_form hits]
223         if {$hist($setNo,maxPresent) == ""} {
224             set hist($setNo,maxPresent) 30
225         }
226         set i [lindex $sessionParms 2]
227         if {$i == ""} {
228             for {set j 1} {$j <= 3} {incr j} {
229                 if {[egw_form scan$j] != ""} {
230                     set i $j
231                     break
232                 }
233             }
234         }
235         if {$i != ""} {
236             set scanNo 1000
237             set hist($setNo,scan) $i
238             set termPlusAttr [build-scan $hist($setNo,0,host) $i]
239             set hist($setNo,$scanNo,scanTerm) [lindex $termPlusAttr 0]
240             set hist($setNo,scanAttr) [lindex $termPlusAttr 1]
241             start-scan $scanNo $targetNo 0 {} $setNo
242             html "</body></html>\n"
243             egw_abort
244             return
245         }
246         set query [build-query $hist($setNo,0,host) 3]
247         if {"x$query" == "x"} {
248             html "<head><title> WWW/Z39.50 Gateway Search</title>\n<body>\n"
249             displayError "Empty query" \
250                 "You must specify at least one search word"
251             html "</body></html>\n"
252             egw_abort
253         }
254         set hist($setNo,0,query) $query
255     } elseif {[lindex $sessionParms 2] == "hyper"} {
256         egw_log debug "hyper search"
257         set hist($nextSetNo,$targetNo,idAuthentication) \
258             $hist($setNo,$targetNo,idAuthentication)
259         set hist($nextSetNo,$targetNo,host) \
260             $hist($setNo,$targetNo,host)
261         set hist($nextSetNo,$targetNo,database) \
262             $hist($setNo,$targetNo,database)
263
264         if {$nextSetNo == $setNo} {
265             set setNo $nextSetNo
266             incr nextSetNo
267         } else {
268             catch {unset hist($setNo,hits)}
269         }
270         set hist($setNo,scan) 0
271         set hist($setNo,$targetNo,query) \
272             "$hist($setNo,scanAttr) \"[lindex $sessionParms 3]\""
273         egw_log debug "hyper databases: $hist($setNo,$targetNo,database)"
274         set hist($setNo,form,entry1) [lindex $sessionParms 3]
275         set startPos ""
276     } elseif {[lindex $sessionParms 2] == "scan"} {
277         egw_log debug "star scan"
278         set scanNo 1000
279         set hist($setNo,$scanNo,scanTerm) {}
280         start-scan $scanNo $targetNo 0 {} {}
281         html "</body></html>\n"
282         egw_abort
283     } else {
284         if {![info exists hist($setNo,scan)]} return
285         if {$hist($setNo,scan) > 0} {
286             set scanNo [lindex $sessionParms 2]
287             set dir [lindex $sessionParms 3]
288             if {$scanNo == ""} {
289                 set scanNo 1000
290             }
291             start-scan $scanNo $targetNo 1 $dir $setNo
292             html "</body></html>\n"
293             egw_abort
294         }
295     }
296     set host $hist($setNo,$targetNo,host)
297
298     html "<head><title> WWW/Z39.50 Gateway Search " [splitHostSpec $host] 
299     html " </title>\n"
300     html "</head><body>\n"
301
302     display-result-set-s $setNo $targetNo $startPos $endPos
303 }
304 {
305     global debug
306     if {!$debug} return
307     html "<hr>\n"
308     html "<h3>Debug information</h3>\n"
309     html "sessionId: $sessionId <br>\n"
310     html "sessionParms: $sessionParms <br>\n"
311     foreach n [array names env] {
312         html "env($n) = " $env($n) " <br>\n"
313     }
314     html "form: " [egw_form] " <br>\n"
315     html "target: " $host " <br>\n"
316     html "databases: " $hist($setNo,$targetNo,database) " <br>\n"
317     html "selected: " [egw_form base] " <br>\n"
318     html "query: --" $hist($setNo,$targetNo,query) "-- <br>"
319     html "setNo: " $setNo " <br>\n"
320     html "nextSetNo: " $nextSetNo " <br>\n"
321 }
322 </body>
323 </html>