b4217107d87d923984950c562e1fa46e06d58ca7
[egate.git] / www / query.egw
1 <html>
2 {
3 # $Id: query.egw,v 1.40 1996/05/24 11:16:01 adam Exp $
4
5     if {[info commands saveState] == ""} {
6         source z39util.tcl
7         if {![info exists debug]} {
8             session-lost
9             egw_abort
10         }
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     html {<head><title> WWW/Z39.50 Gateway Query Form</title></head><body>}
28
29     set initSet [lindex $sessionParms 0]
30     set host [lindex $sessionParms 1]
31     set scanLine [lindex $sessionParms 2]
32     set scanTerm [lrange $sessionParms 3 end]
33
34     if {[catch {set setNo $nextSetNo}]} {
35         set nextSetNo 1
36         set setNo 1
37     }
38     if {[catch {set oldHost [z390 connect]}]} {
39         set oldHost ""
40     }
41
42     set hist($setNo,0,host) $host
43     set hist($setNo,0,idAuthentication) [lindex $targets($host) 3]
44
45     mkAssoc z390 $host
46
47     z390 callback ok-response
48     z390 failback fail-response
49     set thisHost [splitHostSpec $host]
50     if {[string compare $thisHost $oldHost]} {
51         catch {z390 disconnect}
52
53         set sessionWait 0
54         if {[catch {z390 connect $thisHost}]} {
55             displayError "Cannot connect to target ${thisHost}" {}
56             html "</body></html>\n"
57             z390 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                 z390 disconnect
64                 egw_abort
65             }
66             if {$sessionWait != 1} {
67                 displayError "Cannot connect to target ${thisHost}" {}
68                 html "</body></html>\n"
69                 z390 disconnect
70                 egw_abort
71             }
72         }
73         set sessionWait 0
74         z390 idAuthentication $hist($setNo,0,idAuthentication)
75         if {[catch {z390 init}]} {
76             displayError "Cannot initialize target ${thisHost}" {}
77             html "</body></html>\n"
78             egw_abort
79         }
80         if {$sessionWait == 0 && [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 {![z390 initResult]} {
91             displayError "Connection rejected by target ${thisHost}" \
92                  [z390 userInformationField]
93             z390 disconnect
94             html "</body></html>\n"
95             egw_abort
96         }
97     }
98
99     set useIcons 1
100     button-main
101     button-feedback
102     button-new-target
103     if {[lsearch [z390 options] scan] >= 0} {
104         button-scan-window $setNo
105     }
106     button-view-history
107
108     html "<h2>" [lindex $targets($host) 0] "</h2><br>\n"
109
110     html [lindex $targets($host) 4] "<br>\n"
111
112     set databases [splitDatabaseSpec $host]
113     if {$initSet == -1} {
114         set databaseDefault [lindex $databases 0]
115         set oSetNo 0
116     } else {
117         set oSetNo $initSet
118         set databaseDefault $hist($oSetNo,0,database)
119     }
120     
121     html {<form action="http:} $env(SCRIPT_NAME)
122     html / $sessionId {/search.egw/} $setNo + 0 {" 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 "<b>Fill-in this search form:</b><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=35> }
173         if {0 && [lsearch [z390 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-main
212     button-feedback
213     button-new-target
214     if {[lsearch [z390 options] scan] >= 0} {
215         button-scan-window $setNo
216     }
217     button-view-history
218 }
219
220 {
221     catch maintenance
222     global debug
223     if {!$debug} return
224     html "<hr>\n"
225     html "<h3>Debug information</h3>\n"
226     html "sessionId: $sessionId <br>\n"
227     html "sessionParms: $sessionParms <br>\n"
228     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
229         html $e {: } $env($e) {<br>} \n
230     }
231     html "form: " [egw_form] " <br>\n"
232     html "target: " $host " <br>\n"
233     html "databases: " $databases " <br>\n"
234     html "setNo: " $setNo " <br>\n"
235     html "nextSetNo: " $nextSetNo " <br>\n"
236     html "initSet: " $initSet " <br>\n"
237     html "scanLine: " $scanLine " <br>\n"
238     html "scanTerm: " $scanTerm " <br>\n"
239 }
240 </body></html>