Main shell loop implemented as a separate function called wshmain.
[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.33 1996/02/21 16:57:38 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     z39 callback ok-response
48     z39 failback fail-response
49     set thisHost [splitHostSpec $host]
50     if {[string compare $thisHost $oldHost]} {
51         catch {z39 disconnect}
52
53         set sessionWait 0
54         if {[catch {z39 connect $thisHost}]} {
55             displayError "Cannot connect to target ${thisHost}" {}
56             html "</body></html>\n"
57             z39 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                 z39 disconnect
64                 egw_abort
65             }
66             if {$sessionWait != 1} {
67                 displayError "Cannot connect to target ${thisHost}" {}
68                 html "</body></html>\n"
69                 z39 disconnect
70                 egw_abort
71             }
72         }
73         set sessionWait 0
74         z39 idAuthentication $hist($setNo,idAuthentication)
75         if {[catch {z39 init}]} {
76             displayError "Cannot initialize target ${thisHost}" {}
77             html "</body></html>\n"
78             egw_abort
79         }
80         if {[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 {![z39 initResult]} {
91             displayError "Connection rejected by target ${thisHost}" \
92                  [z39 userInformationField]
93             z39 disconnect
94             html "</body></html>\n"
95             egw_abort
96         }
97     }
98
99     set useIcons 1
100     button-europagate
101     button-new-target 1
102     if {[lsearch [z39 options] scan] >= 0} {
103         button-scan-window 1 $setNo
104     }
105     button-view-history 0 
106
107     html "<h2>" [lindex $targets($host) 0] "</h2><br>\n"
108
109     html [lindex $targets($host) 4] "<br>\n"
110
111     set databases [lindex $targets($host) 1]
112
113     if {$initSet == ""} {
114         set databaseDefault [lindex $databases 0]
115         set oSetNo 0
116     } else {
117         set oSetNo $initSet
118         set databaseDefault $hist($oSetNo,database)
119     }
120     
121     html {<form action="http:} $env(SCRIPT_NAME)
122     html / $sessionId {/search.egw/} $setNo {" method=get>} \n
123     set nodb [llength $databases]
124     if {$nodb > 1} {
125         if {$nodb > 2} {
126             html "The chosen target supports searching in "
127             html "several databases. <br>\n"
128             html "Choose the bases you want to search: <br>\n"
129         }
130         set i 0
131         foreach d $databases {
132             html {<input type="checkbox" name="base" value="} $d 
133             if {[lsearch $databaseDefault $d] == -1} {
134                 html {"> } $d \n
135             } else {
136                 html {" checked> } $d \n
137             }
138         }
139         html "<br>\n"
140         if {$nodb > 2} {
141             html {<input type="checkbox" name="baseall" value="} 
142             html [concat $databases] {"> All <br>} \n
143         }
144     }
145     html "Input your search criteria:<br>\n"
146     set fields [lindex $targets($host) 2]
147     for {set no 1} {$no < 4} {incr no} {
148         html {<select name="menu} $no {">} \n
149         set template {}
150         if {$oSetNo > 0} {
151             set template [join $hist($oSetNo,form,menu$no)]
152         }
153         if {[string length $template] > 0} {
154             html {<option> } $template "\n"
155         }
156         foreach f $fields {
157             set name [lindex $f 0]
158             if {$template == $name} continue
159             html {<option> } $name \n
160         }
161         html "</select>\n"
162         html {<input type="text" name="entry} $no {"}
163         set template {}
164         if {$scanLine == $no} {
165             set template [join $scanTerm " "] 
166         } elseif {[info exists hist($oSetNo,form,entry$no)]} {
167             set template [join $hist($oSetNo,form,entry$no) " "]
168         }
169         if {[string length $template] > 0} {
170             html { value="} $template {"}
171         }
172         html { size=43> }
173         if {0 && [lsearch [z39 options] scan] >= 0} {
174             html {<input type="checkbox" name="scan} $no {" value="1" scan>}
175         }
176         if {$no < 3} {
177             html {<select name="logic} $no {">} \n
178             set template {}
179             if {$oSetNo > 0} {
180                 set template [join $hist($oSetNo,form,logic$no) " "]
181             }
182             if {[string length $template] > 0} {
183                 html "<option> " $template \n
184             }
185             foreach op {And Or {And not}} {
186                 if {$template == $op} continue
187                 html "<option> " [join $op " "] \n
188             }
189             html "</select>\n"
190         }
191         html "<br>\n"
192     }
193 }
194
195 <input type=submit name=submit value="Search">
196 <input type=reset value="Reset">
197 <br>
198 {
199     html {Number of records to display in the result set list: }
200     html {<input type="text" name="hits" value="}
201     if {$oSetNo > 0} {
202         html $hist($oSetNo,maxPresent)
203     } else {
204         html 20
205     }
206     html {" size=4>}
207     html "</form>\n"
208     html "<p>\n"
209
210     set useIcons 0
211     button-europagate
212     button-new-target 1
213     if {[lsearch [z39 options] scan] >= 0} {
214         button-scan-window 1 $setNo
215     }
216     button-view-history 0 
217 }
218
219 {
220     catch maintenance
221     global debug
222     if {!$debug} return
223     html "<hr>\n"
224     html "<h3>Debug information</h3>\n"
225     html "sessionId: $sessionId <br>\n"
226     html "sessionParms: $sessionParms <br>\n"
227     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
228         html $e {: } $env($e) {<br>} \n
229     }
230     html "form: " [egw_form] " <br>\n"
231     html "target: " $host " <br>\n"
232     html "databases: " $databases " <br>\n"
233     html "setNo: " $setNo " <br>\n"
234     html "nextSetNo: " $nextSetNo " <br>\n"
235     html "initSet: " $initSet " <br>\n"
236     html "scanLine: " $scanLine " <br>\n"
237     html "scanTerm: " $scanTerm " <br>\n"
238 }
239 </body></html>