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