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