Lots of changes. They aren't visible though.
[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.35 1996/03/07 12:46:08 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 [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-europagate
99     button-new-target 1
100     if {[lsearch [z390 options] scan] >= 0} {
101         button-scan-window 1 $setNo
102     }
103     button-view-history 0 
104
105     html "<h2>" [lindex $targets($host) 0] "</h2><br>\n"
106
107     html [lindex $targets($host) 4] "<br>\n"
108
109     set databases [lindex $targets($host) 1]
110
111     if {$initSet == ""} {
112         set databaseDefault [lindex $databases 0]
113         set oSetNo 0
114     } else {
115         set oSetNo $initSet
116         set databaseDefault $hist($oSetNo,0,database)
117     }
118     
119     html {<form action="http:} $env(SCRIPT_NAME)
120     html / $sessionId {/search.egw/} $setNo + 0 {" method=get>} \n
121     set nodb [llength $databases]
122     if {$nodb > 1} {
123         if {$nodb > 2} {
124             html "The chosen target supports searching in "
125             html "several databases. <br>\n"
126             html "Choose the bases you want to search: <br>\n"
127         }
128         set i 0
129         foreach d $databases {
130             html {<input type="checkbox" name="base" value="} $d 
131             if {[lsearch $databaseDefault $d] == -1} {
132                 html {"> } $d \n
133             } else {
134                 html {" checked> } $d \n
135             }
136         }
137         html "<br>\n"
138         if {$nodb > 2} {
139             html {<input type="checkbox" name="baseall" value="} 
140             html [concat $databases] {"> All <br>} \n
141         }
142     }
143     html "Input your search criteria:<br>\n"
144     set fields [lindex $targets($host) 2]
145     for {set no 1} {$no < 4} {incr no} {
146         html {<select name="menu} $no {">} \n
147         set template {}
148         if {$oSetNo > 0} {
149             set template [join $hist($oSetNo,form,menu$no)]
150         }
151         if {[string length $template] > 0} {
152             html {<option> } $template "\n"
153         }
154         foreach f $fields {
155             set name [lindex $f 0]
156             if {$template == $name} continue
157             html {<option> } $name \n
158         }
159         html "</select>\n"
160         html {<input type="text" name="entry} $no {"}
161         set template {}
162         if {$scanLine == $no} {
163             set template [join $scanTerm " "] 
164         } elseif {[info exists hist($oSetNo,form,entry$no)]} {
165             set template [join $hist($oSetNo,form,entry$no) " "]
166         }
167         if {[string length $template] > 0} {
168             html { value="} $template {"}
169         }
170         html { size=43> }
171         if {0 && [lsearch [z390 options] scan] >= 0} {
172             html {<input type="checkbox" name="scan} $no {" value="1" scan>}
173         }
174         if {$no < 3} {
175             html {<select name="logic} $no {">} \n
176             set template {}
177             if {$oSetNo > 0} {
178                 set template [join $hist($oSetNo,form,logic$no) " "]
179             }
180             if {[string length $template] > 0} {
181                 html "<option> " $template \n
182             }
183             foreach op {And Or {And not}} {
184                 if {$template == $op} continue
185                 html "<option> " [join $op " "] \n
186             }
187             html "</select>\n"
188         }
189         html "<br>\n"
190     }
191 }
192
193 <input type=submit name=submit value="Search">
194 <input type=reset value="Reset">
195 <br>
196 {
197     html {Number of records to display in the result set list: }
198     html {<input type="text" name="hits" value="}
199     if {$oSetNo > 0} {
200         html $hist($oSetNo,maxPresent)
201     } else {
202         html 20
203     }
204     html {" size=4>}
205     html "</form>\n"
206     html "<p>\n"
207
208     set useIcons 0
209     button-europagate
210     button-new-target 1
211     if {[lsearch [z390 options] scan] >= 0} {
212         button-scan-window 1 $setNo
213     }
214     button-view-history 0 
215 }
216
217 {
218     catch maintenance
219     global debug
220     if {!$debug} return
221     html "<hr>\n"
222     html "<h3>Debug information</h3>\n"
223     html "sessionId: $sessionId <br>\n"
224     html "sessionParms: $sessionParms <br>\n"
225     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
226         html $e {: } $env($e) {<br>} \n
227     }
228     html "form: " [egw_form] " <br>\n"
229     html "target: " $host " <br>\n"
230     html "databases: " $databases " <br>\n"
231     html "setNo: " $setNo " <br>\n"
232     html "nextSetNo: " $nextSetNo " <br>\n"
233     html "initSet: " $initSet " <br>\n"
234     html "scanLine: " $scanLine " <br>\n"
235     html "scanTerm: " $scanTerm " <br>\n"
236 }
237 </body></html>