Bug fix: shell might terminate even though new request was initiated
[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.19 1995/12/20 16:31:31 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
29     if {[catch {set setNo $nextSetNo}]} {
30         set nextSetNo 1
31         set setNo 1
32     }
33     if {[catch {set oldHost [z39 connect]}]} {
34         set oldHost ""
35     }
36
37     set hist($setNo,host) $host
38     set hist($setNo,idAuthentication) [lindex $targets($host) 3]
39
40     if {[catch {z39 failback fail-response}]} {
41         ir z39
42     }
43
44     html {<h2><img src="/gif/button-egw.gif" border=0 align=middle>}
45     html " Search in " [lindex $targets($host) 0] "</h2>\n"
46
47     z39 callback ok-response
48     z39 failback fail-response
49     if {$host != $oldHost} {
50         catch {z39 disconnect}
51
52         set sessionWait 0
53         if {[catch {z39 connect $host}]} {
54             displayError "Cannot connect to target ${host}" {}
55             html "</body></html>\n"
56             z39 disconnect
57             wabort
58         } elseif {$sessionWait == 0} {
59             if {[catch {zwait sessionWait 30}]} {
60                 displayError "Cannot connect to target ${host}" {}
61                 html "</body></html>\n"
62                 z39 disconnect
63                 wabort
64             }
65             if {$sessionWait != 1} {
66                 displayError "Cannot connect to target ${host}" {}
67                 html "</body></html>\n"
68                 z39 disconnect
69                 wabort
70             }
71         }
72         set sessionWait 0
73         z39 idAuthentication $hist($setNo,idAuthentication)
74         if {[catch {z39 init}]} {
75             displayError "Cannot initialize target ${host}" {}
76             html "</body></html>\n"
77             wabort
78         }
79         if {[catch {zwait sessionWait 60}]} {
80             displayError "Cannot initialize target ${host}" {}
81             html "</body></html>\n"
82             wabort
83         }       
84         if {$sessionWait != "1"} {
85             displayError "Cannot initialize target ${host}" {}
86             htmlr "</body></html>\n"
87             wabort
88         }
89         if {![z39 initResult]} {
90             displayError "Connection rejected by target ${host}" \
91                  [z39 userInformationField]
92             z39 disconnect
93             htmlr "</body></html>"
94             wabort
95         }
96     }
97     set databases [lindex $targets($host) 1]
98
99     if {$setNo > 1 && $hist([expr $setNo - 1],host) == $host} {
100         set oSetNo [expr $setNo - 1]
101         set databaseDefault $hist($oSetNo,database)
102     } else {
103         set databaseDefault [lindex $databases 0]
104         set oSetNo 0
105     }
106
107     html {<form action="http:} $env(SCRIPT_NAME)
108     html / $sessionId {/search.egw/} $setNo {" method=post>} \n
109     set nodb [llength $databases]
110     if {$nodb > 1} {
111         if {$nodb > 2} {
112             html "The chosen target supports searching in "
113             html "several databases. <br>\n"
114             html "Choose the bases you want to search: <br>\n"
115         }
116         set i 0
117         foreach d $databases {
118             html {<input type="checkbox" name="base" value="} $d 
119             if {[lsearch $databaseDefault $d] == -1} {
120                 html {"> } $d \n
121             } else {
122                 html {" checked> } $d \n
123             }
124         }
125         html "<br>\n"
126         if {$nodb > 2} {
127             html {<input type="checkbox" name="baseall" value="} 
128             html [concat $databases] {"> All <br>} \n
129         }
130         html "Input your search criteria:<br>\n"
131     }
132 }
133 {
134     set fields [lindex $targets($host) 2]
135     for {set no 1} {$no < 4} {incr no} {
136         html {<select name="menu} $no {">} \n
137         if {$oSetNo > 0} {
138             html {<option> } $hist($oSetNo,form,menu$no) \n
139         }
140         foreach f $fields {
141             set name [lindex $f 0]
142             if {$oSetNo > 0} {
143                 if {$hist($oSetNo,form,menu$no) == $name} continue
144             }
145             html {<option> } $name \n
146         }
147         html "</select>\n"
148         html {<input type="text" name="entry} $no {"}
149         html { size=30>} \n
150         if {$no < 3} {
151             html {<select name="logic} $no {">} \n
152             if {$oSetNo > 0} {
153                 html "<option> " $hist($oSetNo,form,logic$no) \n
154             }
155             foreach op {And Or {And not}} {
156                 if {$oSetNo > 0} {
157                     if {$hist($oSetNo,form,logic$no) == $op} continue
158                 }
159                 html "<option> " $op \n
160             }
161             html "</select>\n"
162         }
163         html "<br>\n"
164     }
165 }
166
167 <input type=submit value="Search"><input type=reset value="Reset">
168 <br>
169 {
170     html {Number of records to display in the result set list: }
171     html {<input type="text" name="hits" value="}
172     if {$oSetNo > 0} {
173         html $hist($oSetNo,maxPresent)
174     } else {
175         html 20
176     }
177     html {" size=3>}
178 }
179 <br>
180 <p>
181 </form>
182
183 {
184     html {<img src="/gif/button-egw.gif" border=0></a>}
185     html {<a href="http:} $env(SCRIPT_NAME)
186     html / $sessionId {/targets.egw}
187     html {"><img src="/gif/button-new-target.gif" border=0></a>}
188 }
189
190 <hr>
191 This page is maintained by <a href="mailto:pwh@dtv.dk"> Peter Wad Hansen </a>.
192 Last modified 29. september 1995. <br>
193 <em> This and the following pages are under construction
194 and will continue to be so until the end of December 1995.</em>
195
196 {
197     html "<hr>\n"
198     html "<h3>Debug information</h3>\n"
199     html "sessionId: $sessionId <br>\n"
200     html "sessionParms: $sessionParms <br>\n"
201     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
202         html $e {: } $env($e) {<br>} \n
203     }
204     html "form: " [wform] " <br>\n"
205     html "target: " $host " <br>\n"
206     html "databases: " $databases " <br>\n"
207     html "setNo: " $setNo " <br>\n"
208     html "nextSetNo: " $nextSetNo " <br>\n"
209 }
210 </body></html>
211
212