3 # $Id: search.egw,v 1.5 1995/10/31 16:56:24 adam Exp $
5 proc search-response {} {
8 set status [z39.1 responseStatus]
9 if {[lindex $status 0] == "NSD"} {
10 z39.1 nextResultSetPosition 0
11 set code [lindex $status 1]
12 set msg [lindex $status 2]
13 set addinfo [lindex $status 3]
14 htmlr {<strong>Error} $code {: } $msg {: } $addinfo { </strong><br>}
26 proc fail-response {} {
31 proc display-brief {zset no} {
35 set type [$zset type $no]
37 set err [lindex [$zset diag $no] 1]
38 set add [lindex [$zset diag $no] 2]
42 htmlr "${no} Error ${err}${add} <br>"
49 set rtype [$zset recordType $no]
50 if {$rtype == "SUTRS"} {
51 html [join [$zset getSutrs $no]]
56 set title [lindex [$zset getMarc $no field 245 * a] 0]
57 set year [lindex [$zset getMarc $no field 260 * c] 0]
59 html {<a href="http://} $env(SERVER_NAME) $env(SCRIPT_NAME) /
60 html $sessionId {/showfull.egw/} $no {"> } $title {</a>}
61 html " <i> ${year} </i>"
66 proc display-full {zset no} {
67 set type [$zset type $no]
69 set err [lindex [$zset diag $no] 1]
70 set add [lindex [$zset diag $no] 2]
74 htmlr "<hr> ${no} <br>"
75 htmlr "Error ${err}${add} <br>"
81 htmlr "<hr> ${no} <br>"
82 set rtype [$zset recordType $no]
83 if {$rtype == "SUTRS"} {
84 htmlr [join [$zset getSutrs $no]]
87 if {[catch {set r [$zset getMarc $no line * * *]}]} {
88 htmlr "Unknown record type: $rtype"
92 set tag [lindex $line 0]
93 set indicator [lindex $line 1]
94 set fields [lindex $line 2]
95 set l [string length $indicator]
98 for {set i 0} {$i < $l} {incr i} {
99 if {[string index $tag $i] == " "} {
102 html [string index $tag $i]
106 foreach field $fields {
107 set id [lindex $field 0]
108 set data [lindex $field 1]
110 html " <b>\$$id</b> "
118 proc display-rec {from to} {
119 while {$from <= $to} {
120 display-brief z39.1 $from
125 proc build-query {} {
131 for {set i 1} {$i < 4} {incr i} {
132 set term [wform entry$i]
134 set field [wform menu$i]
135 foreach x [lindex $targets($t) 2] {
136 if {[lindex $x 0] == $field} {
137 set attr [lindex $x 1]
142 { set q "@and $q ${attr} ${term}" }
144 { set q "@or $q ${attr} ${term}" }
146 { set q "@not $q ${attr} ${term}" }
148 { set q "${attr} ${term}" }
150 set op [wform logic$i]
159 set newHost $sessionParms
160 set databases [lindex $targets($newHost) 1]
162 htmlr {<head><title> WWW/Z39.50 Gateway Search } $newHost { </title>}
163 htmlr {</head><body>}
166 if {[catch {z39 callback ok-response}]} {
169 if {$newHost != $host} {
172 z39 callback ok-response
173 z39 failback fail-response
175 htmlr {Connecting to target } $host { <br>}
177 if {[catch {z39 connect $host}]} {
178 htmlr "Cannot connect to target ${host} <br>"
179 htmlr "</body></html>"
181 } elseif {$sessionWait == 0} {
183 if {$sessionWait != 1} {
184 htmlr "Cannot connect to target ${host} <br>"
185 htmlr "</body></html>"
192 if {$sessionWait != "1"} {
193 htmlr "Cannot initialize with target ${host} <br>"
194 htmlr "</body></html>"
201 z39.1 databaseNames [lindex $targets($host) 1]
203 z39.1 databaseNames [list $b]
204 htmlr {selected: } $b { <br>}
206 z39.1 preferredRecordSyntax USMARC
208 set query [build-query]
210 htmlr {<hr>query: --} $query {-- <br>}
211 htmlr {sessionId: } $sessionId {<br>}
212 htmlr {sessionParms: } $sessionParms {<br>}
213 htmlr {form: } [wform] { <br>}
214 htmlr {databases: } $databases { <br>}
215 htmlr {selected: } [wform base] { <br><hr>}
217 z39 callback search-response
222 if {$sessionWait == 1} {
223 set r [z39.1 resultCount]
224 htmlr {<strong> } $r { hits</strong><br><br>}
226 htmlr {</body></html>}
229 set setOffset [z39.1 numberOfRecordsReturned]
230 display-rec 1 $setOffset
233 set setMax [z39.1 resultCount]
237 set toGet [expr 1 + $setMax - $setOffset]
240 z39.1 present $setOffset $toGet
242 if {$sessionWait != "1"} {
245 set got [z39.1 numberOfRecordsReturned]
246 display-rec $setOffset [expr $got + $setOffset - 1]
247 set setOffset [expr $got + $setOffset]
248 set toGet [expr 1 + $setMax - $setOffset]