Better error handling.
[egate.git] / www / search.egw
1 <html>
2 {
3 # $Id: search.egw,v 1.16 1995/11/13 18:17:48 adam Exp $
4
5 proc buttons {setNo setMax startPos after} {
6     global sessionId
7     global env
8     global hist
9
10     if {$after && $setMax < [z39.$setNo resultCount]} {
11         html "<p>\n"
12         html "<center>\n"
13         html {<a href="http:} $env(SCRIPT_NAME)
14         html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
15         html + [expr $setMax + $hist($setNo,maxPresent)]
16         html {"><img src="/gif/darrw.gif"></a>}
17         html "</center>\n"
18     }
19
20     html "<p>\n"
21     if {$setMax < [z39.$setNo resultCount]} {
22         html {<a href="http:} $env(SCRIPT_NAME)
23         html / $sessionId {/search.egw/} $setNo + [expr $setMax + 1]
24         html + [expr $setMax + $hist($setNo,maxPresent)]
25         html {">Next records</a>} " | \n"
26     }
27     if {$startPos != "" && $startPos != "1"} {
28         html {<a href="http:} $env(SCRIPT_NAME)
29         html / $sessionId {/search.egw/} $setNo 
30         html + [expr $startPos - $hist($setNo,maxPresent)]
31         html + [expr $startPos - 1]
32         html {">Previous records</a>} " | \n"
33     }
34     html {<a href="http:} $env(SCRIPT_NAME)
35     html / $sessionId {/query.egw/} $hist($setNo,host) + $setNo 
36     html {">New query</a>} " | \n"
37
38     html {<a href="http:} $env(SCRIPT_NAME)
39     html / $sessionId {/targets.egw">New target</a>} "<p>\n"
40
41     if {!$after && $startPos != "" && $startPos != "1"} {
42         html "<center>\n"
43         html {<a href="http:} $env(SCRIPT_NAME)
44         html / $sessionId {/search.egw/} $setNo 
45         html + [expr $startPos - $hist($setNo,maxPresent)]
46         html + [expr $startPos - 1]
47         html {"><img src="/gif/uarrw.gif"></a>}
48         html "</center><p>\n"
49     }
50
51 }
52
53     if {[info commands saveState] == ""} {
54         source z39util.tcl
55     }
56     global sessionWait
57     global nextSetNo
58     global setNo
59     global hist
60
61     set setNo [lindex $sessionParms 0]
62     if {[wform menu1] != ""} {
63         set hist($nextSetNo,idAuthentication) $hist($setNo,idAuthentication)
64         set hist($nextSetNo,host) $hist($setNo,host)
65         set setNo $nextSetNo
66         html "using host " $hist($setNo,host) " <br\n"
67
68         set query [build-query $hist($setNo,host)]
69         if {"x$query" == "x"} {
70             html "<head><title> WWW/Z39.50 Gateway Search</title>\n<body>\n"
71             displayError "Empty query" \
72                 "You must specify at least one search word"
73             html "</body></html>\n"
74             wabort
75         }
76         set hist($setNo,query) $query
77
78         set hist($setNo,form,menu1) [wform menu1]
79         set hist($setNo,form,menu2) [wform menu2]
80         set hist($setNo,form,menu3) [wform menu3]
81
82         set hist($setNo,form,entry1) [wform entry1]
83         set hist($setNo,form,entry2) [wform entry2]
84         set hist($setNo,form,entry3) [wform entry3]
85
86         set hist($setNo,form,logic1) [wform logic1]
87         set hist($setNo,form,logic2) [wform logic2]
88
89         incr nextSetNo
90         set b [wform base]
91         if {$b == ""} {
92             set hist($setNo,database) $databases
93         } else {
94             set hist($setNo,database) $b
95         }
96         set hist($setNo,maxPresent) [wform hits]
97         if {$hist($setNo,maxPresent) == ""} {
98             set hist($setNo,maxPresent) 30
99         }
100     }
101     set host $hist($setNo,host)
102     set databases [lindex $targets($host) 1]
103
104     html "<head><title> WWW/Z39.50 Gateway Search " $host " </title>\n"
105     html "</head><body>\n"
106
107     set startPos [lindex $sessionParms 1]
108     set endPos [lindex $sessionParms 2]
109     set setMax 0
110     set setOffset 0
111     if {$startPos == ""} {
112         if {[z39search $setNo 1 0 B] != "1"} {
113             return
114         }
115         set r [z39.$setNo resultCount]
116         html "<h2> Search result $r hits</h2>\n"
117         wflush
118         set setOffset [z39.$setNo numberOfRecordsReturned]
119         display-rec 1 $setOffset display-brief 0
120         incr setOffset
121         set setMax [z39.$setNo resultCount]
122         if {$setMax > $hist($setNo,maxPresent)} {
123             set setMax $hist($setNo,maxPresent)
124         }
125     } else {
126         if {[z39search $setNo 0 0 B] != "1"} {
127             return 
128         }
129         set r [z39.$setNo resultCount]
130         html "<h2> Search result $r hits</h2>\n"
131         wflush
132         set setOffset $startPos
133         set setMax [z39.$setNo resultCount]
134         if {$setMax > $endPos} {
135             set setMax $endPos
136         }
137         if {$setMax > 0} {
138             buttons $setNo $setMax $startPos 0
139         }
140     }
141     if {$setMax > 0} {
142         z39present $setNo 0 $setOffset $setMax display-brief B
143     }
144
145     buttons $setNo $setMax $startPos 1
146 }
147
148 {
149     html "<hr>\n"
150     html "<h3>Debug information</h3>\n"
151     html "sessionId: $sessionId <br>\n"
152     html "sessionParms: $sessionParms <br>\n"
153     foreach e {SERVER_NAME PATH_INFO SCRIPT_NAME} {
154         html $e {: } $env($e) {<br>} \n
155     }
156     html "form: " [wform] " <br>\n"
157     html "target: " $host " <br>\n"
158     html "databases: " $hist($setNo,database) " <br>\n"
159     html "selected: " [wform base] " <br>\n"
160     html "query: --" $hist($setNo,query) "-- <br>"
161     html "setNo: " $setNo " <br>\n"
162     html "nextSetNo: " $nextSetNo " <br>\n"
163 }
164
165 </body>
166 </html>