632f35ed8496f6a3241f800429c59f241e5ec6a1
[egate.git] / www / query.egw
1 <html>
2 <head>
3 <title> WWW/Z39.50 Gateway Query Form</title>
4 </head>
5 <body>
6 {
7 # $Id: query.egw,v 1.31 1996/01/24 16:59:28 adam Exp $
8
9     if {[info commands saveState] == ""} {
10         source z39util.tcl
11     }
12
13 proc fail-response {} {
14     global sessionWait
15     set sessionWait -1
16 }
17
18 proc ok-response {} {
19     global sessionWait
20     set sessionWait 1
21 }
22
23     global setNo
24     global nextSetNo
25     global hist
26
27     set host [lindex $sessionParms 0]
28     set initSet [lindex $sessionParms 1]
29     set scanLine [lindex $sessionParms 2]
30     set scanTerm [lrange $sessionParms 3 end]
31
32     if {[catch {set setNo $nextSetNo}]} {
33         set nextSetNo 1
34         set setNo 1
35     }
36     if {[catch {set oldHost [z39 connect]}]} {
37         set oldHost ""
38     }
39
40     set hist($setNo,host) $host
41     set hist($setNo,idAuthentication) [lindex $targets($host) 3]
42
43     if {[catch {z39 failback fail-response}]} {
44         ir z39
45     }
46
47     html "<h2>Search in " [lindex $targets($host) 0] "</h2><br>\n"
48     z39 callback ok-response
49     z39 failback fail-response
50     set thisHost [splitHostSpec $host]
51     if {$thisHost != $oldHost} {
52         catch {z39 disconnect}
53
54         set sessionWait 0
55         if {[catch {z39 connect $thisHost}]} {
56             displayError "Cannot connect to target ${thisHost}" {}
57             html "</body></html>\n"
58             z39 disconnect
59             egw_abort
60         } elseif {$sessionWait == 0} {
61             if {[catch {egw_wait sessionWait 35}]} {
62                 displayError "Cannot connect to target ${thisHost}" {}
63                 html "</body></html>\n"
64                 z39 disconnect
65                 egw_abort
66             }
67             if {$sessionWait != 1} {
68                 displayError "Cannot connect to target ${thisHost}" {}
69                 html "</body></html>\n"
70                 z39 disconnect
71                 egw_abort
72             }
73         }
74         set sessionWait 0
75         z39 idAuthentication $hist($setNo,idAuthentication)
76         if {[catch {z39 init}]} {
77             displayError "Cannot initialize target ${thisHost}" {}
78             html "</body></html>\n"
79             egw_abort
80         }
81         if {[catch {egw_wait sessionWait 60}]} {
82             displayError "Cannot initialize target ${thisHost}" {}
83             html "</body></html>\n"
84             egw_abort
85         }       
86         if {$sessionWait != "1"} {
87             displayError "Cannot initialize target ${thisHost}" {}
88             html "</body></html>\n"
89             egw_abort
90         }
91         if {![z39 initResult]} {
92             displayError "Connection rejected by target ${thisHost}" \
93                  [z39 userInformationField]
94             z39 disconnect
95             html "</body></html>\n"
96             egw_abort
97         }
98     }
99     set databases [lindex $targets($host) 1]
100
101     if {$initSet == ""} {
102         set databaseDefault [lindex $databases 0]
103         set oSetNo 0
104     } else {
105         set oSetNo $initSet
106         set databaseDefault $hist($oSetNo,database)
107     }
108     
109     html {<form action="http:} $env(SCRIPT_NAME)
110     html / $sessionId {/search.egw/} $setNo {" method=get>} \n
111     set nodb [llength $databases]
112     if {$nodb > 1} {
113         if {$nodb > 2} {
114             html "The chosen target supports searching in "
115             html "several databases. <br>\n"
116             html "Choose the bases you want to search: <br>\n"
117         }
118         set i 0
119         foreach d $databases {
120             html {<input type="checkbox" name="base" value="} $d 
121             if {[lsearch $databaseDefault $d] == -1} {
122                 html {"> } $d \n
123             } else {
124                 html {" checked> } $d \n
125             }
126         }
127         html "<br>\n"
128         if {$nodb > 2} {
129             html {<input type="checkbox" name="baseall" value="} 
130             html [concat $databases] {"> All <br>} \n
131         }
132     }
133     html "Input your search criteria:<br>\n"
134     set fields [lindex $targets($host) 2]
135     for {set no 1} {$no < 4} {incr no} {
136         html {<select name="menu} $no {">} \n
137         set template {}
138         if {$oSetNo > 0} {
139             set template [join $hist($oSetNo,form,menu$no)]
140         }
141         if {[string length $template] > 0} {
142             html {<option> } $template "\n"
143         }
144         foreach f $fields {
145             set name [lindex $f 0]
146             if {$template == $name} continue
147             html {<option> } $name \n
148         }
149         html "</select>\n"
150         html {<input type="text" name="entry} $no {"}
151         set template {}
152         if {$scanLine == $no} {
153             set template [join $scanTerm " "] 
154         } elseif {[info exists hist($oSetNo,form,entry$no)]} {
155             set template [join $hist($oSetNo,form,entry$no) " "]
156         }
157         if {[string length $template] > 0} {
158             html { value="} $template {"}
159         }
160         html { size=43> }
161         if {0 && [lsearch [z39 options] scan] >= 0} {
162             html {<input type="checkbox" name="scan} $no {" value="1" scan>}
163         }
164         if {$no < 3} {
165             html {<select name="logic} $no {">} \n
166             set template {}
167             if {$oSetNo > 0} {
168                 set template [join $hist($oSetNo,form,logic$no) " "]
169             }
170             if {[string length $template] > 0} {
171                 html "<option> " $template \n
172             }
173             foreach op {And Or {And not}} {
174                 if {$template == $op} continue
175                 html "<option> " [join $op " "] \n
176             }
177             html "</select>\n"
178         }
179         html "<br>\n"
180     }
181 }
182
183 <input type=submit name=submit value="Search">
184 <input type=reset value="Reset">
185 <br>
186 {
187     html {Number of records to display in the result set list: }
188     html {<input type="text" name="hits" value="}
189     if {$oSetNo > 0} {
190         html $hist($oSetNo,maxPresent)
191     } else {
192         html 20
193     }
194     html {" size=4>}
195 }
196 </form>
197 <p>
198
199 {
200     button-europagate
201
202     button-new-target 1
203
204     if {[lsearch [z39 options] scan] >= 0} {
205         button-scan-window 1 $setNo
206     }
207     button-view-history 0 
208 }
209
210 {
211     catch maintenance
212     global debug
213     if {!$debug} return
214     html "<hr>\n"
215     html "<h3>Debug information</h3>\n"
216     html "sessionId: $sessionId <br>\n"
217     html "sessionParms: $sessionParms <br>\n"
218     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
219         html $e {: } $env($e) {<br>} \n
220     }
221     html "form: " [egw_form] " <br>\n"
222     html "target: " $host " <br>\n"
223     html "databases: " $databases " <br>\n"
224     html "setNo: " $setNo " <br>\n"
225     html "nextSetNo: " $nextSetNo " <br>\n"
226     html "initSet: " $initSet " <br>\n"
227     html "scanLine: " $scanLine " <br>\n"
228     html "scanTerm: " $scanTerm " <br>\n"
229 }
230 </body></html>
231
232