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