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