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