2 # $Id: z39util.tcl,v 1.46 1996/08/28 09:36:03 adam Exp $
6 set f [open "tcl.state.${sessionId}" w]
7 foreach var [info globals] {
8 if {$var == "f"} continue
9 if {$var == "sessionId"} continue
10 if {$var == "errorInfo"} continue
11 if {[catch {set names [array names $var]}]} {
13 puts $f "set ${var} \{$v\}"
16 eval "set v \$${var}(\$n)"
17 puts $f "set ${var}($n) \{$v\}"
21 puts $f "set ${var} \{$v\}"
29 proc search-response {zz} {
32 set status [$zz responseStatus]
33 if {[lindex $status 0] == "NSD"} {
34 $zz nextResultSetPosition 0
35 set code [lindex $status 1]
36 set msg [lindex $status 2]
37 set addinfo [lindex $status 3]
38 displayError "Diagnostic message" \
39 "$msg: $addinfo<br>\n(error code $code)"
46 proc scan-response {zz} {
49 set status [$zz scanStatus]
51 displayError "Scan fail" ""
63 proc fail-response {} {
68 proc display-medium {zset no setNo targetNo} {
73 set type [$zset type $no]
75 set err [lindex [$zset diag $no] 1]
76 set add [lindex [$zset diag $no] 2]
80 html "${no} Error ${err}${add} <br>\n"
86 set rtype [$zset recordType $no]
89 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
90 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
91 html [join [$zset getSutrs $no]]
97 set author [$zset getMarc $no field 100 * a]
98 set corp [$zset getMarc $no field 110 * a]
99 set meet [$zset getMarc $no field 111 * a]
100 set title [$zset getMarc $no field 245 * a]
101 if {[llength $author] == 0} {
102 set cover [$zset getMarc $no field 245 * {[bc]}]
104 set cover [$zset getMarc $no field 245 * b]
106 set location [$zset getMarc $no field 260 * a]
107 set publisher [$zset getMarc $no field 260 * b]
108 set year [$zset getMarc $no field 260 * c]
109 set score [$zset getMarc $no field 999 * r]
111 html { <a href="http:} $env(SCRIPT_NAME) /
112 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
143 set v [join $cover ""]
144 if {[string length $v] > 0} {
151 if {[scan $score %d nscore] == 1} {
152 html "; Score " $nscore
155 html { <a href="http:} $env(SCRIPT_NAME) /
156 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
159 html "Error: " $dispError "\n"
164 proc display-brief {zset no setNo targetNo} {
169 set type [$zset type $no]
171 set err [lindex [$zset diag $no] 1]
172 set add [lindex [$zset diag $no] 2]
176 html "${no} Error ${err}${add} <br>\n"
182 set rtype [$zset recordType $no]
185 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
186 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
187 html [string range [join [$zset getSutrs $no]] 0 70]
193 set author [$zset getMarc $no field 100 * a]
194 set corp [$zset getMarc $no field 110 * a]
195 set meet [$zset getMarc $no field 111 * a]
196 set title [$zset getMarc $no field 245 * a]
197 if {[llength $author] == 0} {
198 set cover [$zset getMarc $no field 245 * {[bc]}]
200 set cover [$zset getMarc $no field 245 * b]
202 set location [$zset getMarc $no field 260 * a]
203 set publisher [$zset getMarc $no field 260 * b]
204 set year [$zset getMarc $no field 260 * c]
206 html { <a href="http:} $env(SCRIPT_NAME) /
207 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
241 set v [join $cover ""]
242 if {[string length $v] > 40} {
244 html [string range $v 0 38] "..."
245 } elseif {[string length $v] > 0} {
254 html { <a href="http:} $env(SCRIPT_NAME) /
255 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
258 html "Error: " $dispError "\n"
263 proc display-raw {zset no setNo targetNo} {
264 set type [$zset type $no]
267 set err [lindex [$zset diag $no] 1]
268 set add [lindex [$zset diag $no] 2]
272 html "<h3>${no}</h3>\n"
273 html "Error ${err}${add} <br>\n"
282 set rtype [$zset recordType $no]
285 html "<xmp>\n" [join [$zset getSutrs $no]] "\n</xmp>\n"
289 if {[catch {set r [$zset getMarc $no line * * *]}]} {
290 html "Unknown record type: $rtype <br>\n"
294 set tag [lindex $line 0]
295 set indicator [lindex $line 1]
296 set fields [lindex $line 2]
297 set l [string length $indicator]
300 for {set i 0} {$i < $l} {incr i} {
301 if {[string index $indicator $i] == " "} {
304 html [string index $tag $i]
309 foreach field $fields {
310 set id [lindex $field 0]
311 set data [lindex $field 1]
313 html " <b>\$$id</b> "
321 proc put-marc-contents {cc} {
323 if {[string first :// $cc] > 0} {
324 foreach urltype {gopher http ftp mailto} {
325 if {[string first ${urltype}:// $cc] == 0} {
340 proc dl-marc-field {zset no tag id la lb sep} {
342 set c [$zset getMarc $no field $tag * $id]
347 if {$len > 1 && "x$lb" != "x"} {
348 html "<dt><b>$lb</b>\n<dd>"
350 html "<dt><b>$la</b>\n<dd>"
356 put-marc-contents $cc
362 proc dd-marc-field {zset no tag id start stop} {
364 set c [$zset getMarc $no field $tag * $id]
371 put-marc-contents $cc
378 proc dl-marc-field-rec {zset no tag lead start stop startid sep} {
380 set lines [$zset getMarc $no line $tag * *]
381 foreach line $lines {
382 foreach field [lindex $line 2] {
384 html "<dt><b>$lead</b>"
387 set id [lindex $field 0]
388 if {$id == $startid} {
394 html [lindex $field 1]
397 html [lindex $field 1]
406 proc display-full-marc {zset no setNo targetNo} {
412 set n [dl-marc-field $zset $no 700 a "Author" "Authors" "<br>\n"]
414 set n [dl-marc-field $zset $no 100 a "Author" "Authors" "<br>\n"]
416 set n [dl-marc-field $zset $no 710 a "Corporate Name" {} ", "]
418 set n [dl-marc-field $zset $no 110 a "Corporate Name" {} ", "]
420 set n [dl-marc-field $zset $no 711 a "Meeting Name" {} ", "]
422 dd-marc-field $zset $no 711 {[bndc]} " " ""
424 set n [dl-marc-field $zset $no 111 a "Meeting Name" {} ", "]
426 dd-marc-field $zset $no 111 {[bndc]} " " " "
429 set n [dl-marc-field $zset $no 245 {a} "Title" {} " "]
431 dd-marc-field $zset $no 245 b "<em>" "</em>"
432 dd-marc-field $zset $no 245 c " " ""
434 dl-marc-field $zset $no 245 {[ab]} "Title" {} " "
436 dl-marc-field $zset $no 520 a "Abstract" {} ", "
437 dl-marc-field $zset $no 072 * "Subject code" "Subject codes" ", "
438 dl-marc-field $zset $no 650 * "Subject" {} ", "
439 dl-marc-field $zset $no 260 * "Publisher" {} " "
440 dl-marc-field $zset $no 300 * "Physical Description" {} " "
442 dl-marc-field-rec $zset $no 500 "Notes" "" "<br>\n" "a" ", "
444 dl-marc-field-rec $zset $no 510 "References" "" "<br>\n" "a" ", "
446 dl-marc-field-rec $zset $no 511 "Participant note" "" "<br>\n" "a" ", "
448 dl-marc-field $zset $no 513 a "Report type" {} ", "
449 dl-marc-field $zset $no 513 b "Period covered" {} ", "
450 dl-marc-field-rec $zset $no 515 "Numbering notes" "" "<br>\n" "a" ", "
451 dl-marc-field-rec $zset $no 516 "Data notes" "" "<br>\n" "a" ", "
452 dl-marc-field-rec $zset $no 518 "Date/time notes" "" "<br>\n" "a" ", "
454 dl-marc-field $zset $no 350 a "Price" {} ", "
455 dl-marc-field $zset $no 362 a "Dates of publication" {} ", "
456 dl-marc-field $zset $no 850 a "Holdings" {} ", "
458 dl-marc-field-rec $zset $no 270 "Contact name" "" "<br>\n" p ", "
460 set n [dl-marc-field $zset $no 270 p "Contact name" {} ", "]
465 dl-marc-field $zset $no 270 a "Street" {} ", "
466 dl-marc-field $zset $no 270 b "City" {} ", "
467 dl-marc-field $zset $no 270 c "State" {} ", "
468 dl-marc-field $zset $no 270 e "Zip code" {} ", "
469 dl-marc-field $zset $no 270 d "Country" {} ", "
470 dl-marc-field $zset $no 270 m "Network address" {} ", "
471 dl-marc-field $zset $no 301 a "Service hours" {} ", "
472 dl-marc-field $zset $no 270 k "Phone" {} ", "
473 dl-marc-field $zset $no 270 l "Fax" {} ", "
475 dl-marc-field $zset $no 270 {[abcedmakl]} "Address" {} "<br>\n"
481 dl-marc-field $zset $no 010 a "LC control number" {} ", "
482 dl-marc-field $zset $no 010 b "NUCMC control number" {} ", "
483 dl-marc-field $zset $no 020 a "ISBN" {} ", "
484 dl-marc-field $zset $no 022 a "ISSN" {} ", "
485 set url [$zset getMarc $no field 856 * u]
486 set sp [$zset getMarc $no field 856 * 3]
487 if {"x$url" != "x"} {
488 html "<dt><b>URL</b>\n"
492 html {<dd><a href="} [join $url] {">} [join $sp] "</a>\n"
494 dl-marc-field $zset $no 037 {[abc]} "Acquisition" {} "<br>\n"
495 dl-marc-field $zset $no 037 {[f6]} "Form of issue" {} "<br>\n"
496 dl-marc-field $zset $no 537 * "Source of data" {} "<br>\n"
497 dl-marc-field $zset $no 538 * "System details" {} "<br>\n"
498 dl-marc-field $zset $no 787 {[rstw6]} "Related information" {} "<br>\n"
499 dl-marc-field $zset $no 999 r "Score" {} ", "
500 dl-marc-field $zset $no 001 * "Local control number" {} ", "
504 proc display-full {zset no setNo targetNo} {
505 set type [$zset type $no]
508 set err [lindex [$zset diag $no] 1]
509 set add [lindex [$zset diag $no] 2]
513 html "Error ${err}${add} <br>\n"
522 set rtype [$zset recordType $no]
525 html "<pre>" [join [$zset getSutrs $no]] "</pre><br>\n"
529 if {[catch {set r [$zset getMarc $no line * * *]}]} {
530 html "Unknown record type: $rtype <br>\n"
533 display-full-marc $zset $no $setNo $targetNo
537 proc display-rec {from to dfunc setNo targetNo} {
538 while {$from <= $to} {
539 eval "$dfunc z39${targetNo}.${setNo} $from $setNo $targetNo"
544 proc build-scan {t i} {
547 set term [egw_form entry$i]
549 set field [join [egw_form menu$i]]
551 foreach x [lindex $targets($t) 2] {
552 if {[lindex $x 0] == $field} {
553 set attr [lindex $x 1]
556 return [list $term $attr]
561 proc build-query {t ilines} {
566 for {set i 1} {$i <= $ilines} {incr i} {
567 set term [join [egw_form entry$i]]
568 if {[string length $term] == 0} continue
569 set field [join [egw_form menu$i]]
571 foreach x [lindex $targets($t) 2] {
572 if {![string compare [lindex $x 0] $field]} {
573 set attr [lindex $x 1]
576 if {![info exists attr]} {
577 egw_log debug "attr failed for $t"
578 set attr [lindex [lindex [lindex $targets($t) 2] 0] 1]
580 egw_log debug "op=${op}"
583 { set q "@and $q ${attr} \"${term}\""; egw_log debug AND }
585 { set q "@or $q ${attr} \"${term}\""; egw_log debug OR }
587 { set q "${attr} \"${term}\""; egw_log debug NOPE }
589 { set q "@not $q ${attr} \"${term}\""; egw_log debug ANDNOT }
591 set op [egw_form logic$i]
596 proc z39scan {setNo scanNo tno scanLines scanPos cache} {
602 set host $hist($setNo,$tno,host)
603 set idAuth $hist($setNo,$tno,idAuthentication)
604 set database $hist($setNo,$tno,database)
605 set scanAttr $hist($setNo,scanAttr)
606 set scanTerm $hist($setNo,$scanNo,scanTerm)
609 if {[catch [list set oldHost [$zz connect]]]} {
612 set zs $zz.s$scanNo.$setNo
613 $zz callback ok-response
614 $zz failback fail-response
615 set thisHost [splitHostSpec $host]
616 if {[string compare $oldHost $thisHost]} {
617 catch [list $zz disconnect]
620 if {[catch [list $zz connect $thisHost]]} {
621 displayError "Cannot connect to target" $thisHost
623 } elseif {$sessionWait == 0} {
624 if {[catch {egw_wait sessionWait 300}]} {
626 displayError "Cannot connect to target" $thisHost
629 if {$sessionWait != 1} {
630 displayError "Cannot connect to target" $thisHost
634 $zz idAuthentication $idAuth
636 if {[catch {$zz init}]} {
637 displayError "Cannot initialize target" $thisHost
641 if {[catch {egw_wait sessionWait 60}]} {
642 displayError "Cannot initialize target" $thisHost
646 if {$sessionWait != "1"} {
647 displayError "Cannot initialize target" $thisHost
651 if {![$zz initResult]} {
652 set u [$zz userInformationField]
654 displayError "Cannot initialize target $thisHost" $u
658 if {$cache && ![catch [list $zs numberOfTermsRequested 5]]} {
662 eval $zz databaseNames $database
666 $zs numberOfTermsRequested $scanLines
667 $zs preferredPositionInResponse $scanPos
669 $zz callback [list scan-response $zs]
671 egw_log debug "scan: ${scanAttr} ${scanTerm}"
673 $zs scan "${scanAttr} ${scanTerm}"
675 if {[catch {egw_wait sessionWait 60}]} {
676 egw_log debug "timeout/cancel in scan"
677 displayError "Timeout in scan" {}
678 html "</body></html>\n"
682 if {$sessionWait == -1} {
683 displayError "Scan fail" "Connection closed"
684 html "</body></html>\n"
687 if {$sessionWait != 1} {
693 proc display-scan {setNo scanNo tno} {
701 set zs $zz.s$scanNo.$setNo
702 set m [$zs numberOfEntriesReturned]
705 set t [lindex [$zs scanLine 0] 1]
707 set hist($setNo,$tno,[expr $scanNo - 1],scanTerm) $t
709 set hist($setNo,[expr $scanNo - 1],scanTerm) $t
711 set t [lindex [$zs scanLine [expr $m - 1]] 1]
713 set hist($setNo,$tno,[expr $scanNo + 1],scanTerm) $t
715 set hist($setNo,[expr $scanNo + 1],scanTerm) $t
718 html {<table width=500 border=0><tr>}
719 html {<td align=left><b>Scan term</b>}
720 html {<td align=right><b>Hits</b>}
723 for {set i 0} {$i < $m} {incr i} {
724 html {<td align=left>}
726 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
727 html {<a href="http:} $env(SCRIPT_NAME)
728 html / $sessionId / $scriptQuery {;/} $setNo + $hist($setNo,host) +
729 html $hist($setNo,scan) + $tterm {">}
731 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
732 html {<a href="http:} $env(SCRIPT_NAME)
733 html / $sessionId {/search.egw/} $setNo + $tno +
734 html hyper + $tterm {">}
736 html [lindex [$zs scanLine $i] 1]
738 html {<td align=right>}
739 html [lindex [$zs scanLine $i] 2]
745 proc z39search {setNo piggy tno elements} {
751 set host $hist($setNo,$tno,host)
752 set idAuth $hist($setNo,$tno,idAuthentication)
753 set database $hist($setNo,$tno,database)
754 set query $hist($setNo,$tno,query)
755 catch {set docId $hist($setNo,$tno,queryId)}
758 if {[catch [list set oldHost [$zz connect]]]} {
761 $zz callback ok-response
762 $zz failback fail-response
763 set thisHost [splitHostSpec $host]
764 if {[string compare $oldHost $thisHost]} {
765 catch [list $zz disconnect]
768 if {[catch [list $zz connect $thisHost]]} {
769 displayError "Cannot connect to target" $thisHost
771 } elseif {$sessionWait == 0} {
772 if {[catch {egw_wait sessionWait 300}]} {
774 displayError "Cannot connect to target" $thisHost
777 if {$sessionWait != 1} {
778 displayError "Cannot connect to target" $thisHost
782 $zz idAuthentication $idAuth
784 if {[catch {$zz init}]} {
785 displayError "Cannot initialize target" $thisHost
789 if {$sessionWait == 0 && [catch {egw_wait sessionWait 60}]} {
790 displayError "Cannot initialize target" $thisHost
794 if {$sessionWait != "1"} {
795 displayError "Cannot initialize target" $thisHost
799 if {![$zz initResult]} {
800 set u [$zz userInformationField]
802 displayError "Cannot initialize target $thisHost" $u
805 } elseif {![catch [list $zz.$setNo smallSetUpperBound 0]]} {
806 if {[info exists hist($setNo,$tno,hits)]} {
811 ir-set $zz.$setNo $zz
812 $zz.$setNo preferredRecordSyntax [lindex $targets($host) 1]
813 egw_log debug "set syntax to [lindex $targets($host) 1]"
814 if {![lindex $targets($host) 5]} {
817 $zz.$setNo smallSetElementSetNames $elements
818 $zz.$setNo mediumSetElementSetNames $elements
819 $zz.$setNo recordElements $elements
821 egw_log debug "database=$database"
822 eval $zz.$setNo databaseNames $database
824 $zz callback [list search-response $zz.$setNo]
826 $zz.$setNo largeSetLowerBound 999999
827 $zz.$setNo smallSetUpperBound 0
828 $zz.$setNo mediumSetPresentNumber $hist($setNo,maxPresent)
830 $zz.$setNo largeSetLowerBound 2
831 $zz.$setNo smallSetUpperBound 0
832 $zz.$setNo mediumSetPresentNumber 0
835 egw_log debug "search: $query"
837 if {[info exists docId]} {
838 $zz.$setNo search $query $docId
840 $zz.$setNo search $query
843 if {!$sessionWait && [catch {egw_wait sessionWait 60}]} {
844 egw_log debug "timeout/cancel in search"
845 displayError "Timeout in search" {}
846 html "</body></html>\n"
851 if {$sessionWait == -1} {
852 displayError "Search fail" "Connection closed"
853 html "</body></html>\n"
856 if {$sessionWait != 1} {
859 set hist($setNo,$tno,hits) [$zz.$setNo resultCount]
863 proc init-m-response {i} {
867 egw_log debug "init-m-response"
870 if {![z39$i initResult]} {
878 proc connect-m-response {i} {
882 egw_log debug "connect-m-response"
883 z39$i callback [list init-m-response $i]
884 if {[catch {z39$i init}]} {
890 proc fail-m-response {i} {
894 egw_log debug "fail-m-response"
899 proc search-m-response {setNo i start number} {
904 egw_log debug "search-m-response"
905 set status [z39$i.$setNo responseStatus]
906 egw_log debug "search-m-response1"
907 if {[lindex $status 0] == "OK"} {
909 } elseif {[lindex $status 0] == "DBOSD"} {
910 set nor [z39$i.$setNo numberOfRecordsReturned]
912 egw_log debug "search-m-response2"
917 set hist($setNo,$i,hits) [z39$i.$setNo resultCount]
918 egw_log debug "search-m-response3"
919 set hist($setNo,$i,offset) [expr $start + $nor -1]
920 if {[expr $nor + $start] > [z39$i.$setNo resultCount]} {
921 egw_log debug "search-m-response4"
926 egw_log debug "search-m-response5"
927 if {$nor >= $number} {
928 egw_log debug "search-m-response6 nor=$nor number=$number"
933 egw_log debug "search-m-response7"
934 set start [expr $start + $nor]
935 set number [expr $number - $nor]
936 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
937 set number [expr [z39$i.$setNo resultCount] - $start + 1]
939 z39$i callback [list search-m-response $setNo $i $start $number]
940 egw_log debug "mpresent start=$number number=$number"
941 z39$i.$setNo present $start $number
944 proc z39msearch {setNo elements start number cache} {
951 set not $hist($setNo,0,host)
953 egw_log debug "z39msearch start=$start number=$number elements=$elements"
954 for {set i 1} {$i <= $not} {incr i} {
955 set host $hist($setNo,$i,host)
957 set oldHost [z39$i connect]
958 set thisHost [splitHostSpec $host]
959 if {[string compare $oldHost $thisHost]} {
960 catch {z39$i disconnect}
962 z39$i callback [list connect-m-response $i]
963 z39$i failback [list fail-m-response $i]
966 for {set i 1} {$i <= $not} {incr i} {
967 set oldHost [z39$i connect]
968 set host $hist($setNo,$i,host)
969 set thisHost [splitHostSpec $host]
970 if {![string compare $oldHost $thisHost]} {
973 egw_log debug "old=$oldHost this=$thisHost"
974 z39$i idAuthentication $hist($setNo,$i,idAuthentication)
975 html "Connecting to target " $thisHost " <br>\n"
977 if {![catch {z39$i connect $thisHost}]} {
982 egw_log debug "Waiting for init response"
983 if {[catch {egw_wait zleft 20} reason]} {
984 if {![string compare $reason cancel]} {
985 for {set i 1} {$i <= $not} {incr i} {
987 catch {z39$i disconnect}
991 for {set i 1} {$i <= $not} {incr i} {
992 if {$zstatus($i) == -1} {
993 catch {z39$i disconnect}
1001 for {set i 1} {$i <= $not} {incr i} {
1002 set host $hist($setNo,$i,host)
1004 html "host " [splitHostSpec $host] ": "
1006 egw_log debug "i=$i zstatus=$zstatus($i)"
1007 if {$zstatus($i) < 1} {
1013 if {[catch [list z39$i.$setNo preferredRecordSyntax]]} {
1018 ir-set z39$i.$setNo z39$i
1019 z39$i.$setNo preferredRecordSyntax [lindex $targets($host) 1]
1020 egw_log debug "set syntax to [lindex $targets($host) 1]"
1021 set hist($setNo,$i,offset) 0
1022 eval z39$i.$setNo databaseNames $hist($setNo,$i,database)
1024 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1027 set thisElements $elements
1029 z39$i.$setNo smallSetElementSetNames $thisElements
1030 z39$i.$setNo mediumSetElementSetNames $thisElements
1031 z39$i.$setNo elementSetNames $thisElements
1032 z39$i.$setNo recordElements $thisElements
1034 z39$i callback [list search-m-response $setNo $i $start $number]
1037 z39$i.$setNo largeSetLowerBound 999999
1038 z39$i.$setNo smallSetUpperBound 0
1039 z39$i.$setNo mediumSetPresentNumber $number
1041 z39$i.$setNo largeSetLowerBound 2
1042 z39$i.$setNo smallSetUpperBound 0
1043 z39$i.$setNo mediumSetPresentNumber 0
1047 egw_log debug "msearch host=" $hist($setNo,$i,host)
1048 egw_log debug "setNo=$setNo query=" $hist($setNo,$i,query) "="
1049 if {[catch {z39$i.$setNo search $hist($setNo,$i,query)}]} {
1053 } elseif {[z39$i.$setNo resultCount] >= $start} {
1054 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1055 set tnumber [expr [z39$i.$setNo resultCount] - $start + 1]
1059 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1062 set thisElements $elements
1064 z39$i.$setNo smallSetElementSetNames $thisElements
1065 z39$i.$setNo mediumSetElementSetNames $thisElements
1066 z39$i.$setNo elementSetNames $thisElements
1067 z39$i.$setNo recordElements $thisElements
1069 for {set n 0} {$n < $tnumber} {incr n} {
1070 if {[z39$i.$setNo recordType [expr $start + $n]] == ""} {
1072 egw_log debug "failed on $n"
1075 html "no record at #" [expr $start + $n]
1076 html " el=-" $thisElements "-"
1081 if {$n == $tnumber} {
1088 html "present<br>\n"
1089 z39$i callback [list search-m-response $setNo $i $start $tnumber]
1091 egw_log debug "mpresent start=$start number=$tnumber"
1092 z39$i.$setNo present $start $tnumber
1101 while {$zleft > 0} {
1102 egw_log debug "Waiting for search/present response"
1103 if {[catch {egw_wait zleft 60} reason]} {
1104 if {![string compare $reason cancel]} {
1105 for {set i 1} {$i <= $not} {incr i} {
1106 catch {z39$i disconnect}
1111 for {set i 1} {$i <= $not} {incr i} {
1112 if {$zstatus($i) != 2} {
1113 catch {z39$i disconnect}
1120 for {set i 1} {$i <= $not} {incr i} {
1121 if {$zstatus($i) != 2} continue
1122 set status [z39$i.$setNo responseStatus]
1123 if {0 && [lindex $status 0] != "NSD"} {
1124 set hist($setNo,$i,offset) [z39$i.$setNo numberOfRecordsReturned]
1129 proc z39present {setNo tno setOffset setMax dfunc elements} {
1135 set host $hist($setNo,$tno,host)
1137 if {![lindex $targets($host) 5]} {
1141 $zz.$setNo elementSetNames $elements
1142 $zz.$setNo recordElements $elements
1143 set toGet [expr 1 + $setMax - $setOffset]
1145 $zz callback [list search-response $zz.$setNo]
1147 while {$setMax > 0 && $toGet > 0} {
1148 for {set got 0} {$got < $toGet} {incr got} {
1149 if {[$zz.$setNo recordType [expr $setOffset + $got]] == ""} {
1153 if {$got < $toGet} {
1155 $zz.$setNo present $setOffset $toGet
1156 if {[catch {egw_wait sessionWait 300}]} {
1157 egw_log debug "timeout/cancel in present"
1161 if {$sessionWait == "0"} {
1164 if {$sessionWait != "1"} {
1167 set got [$zz.$setNo numberOfRecordsReturned]
1172 display-rec $setOffset [expr $got + $setOffset - 1] $dfunc $setNo $tno
1173 set setOffset [expr $got + $setOffset]
1174 set toGet [expr 1 + $setMax - $setOffset]
1179 proc buttons-result-set-s {setNo targetNo setMax startPos after} {
1188 if {$setMax > 0 && $setMax < [$zz.$setNo resultCount]} {
1192 html {<a href="http:} $env(SCRIPT_NAME)
1193 html / $sessionId {/search.egw/} $setNo + $targetNo +
1194 html [expr $setMax + 1] + [expr $setMax + $hist($setNo,maxPresent)]
1196 html {"><img src="/egwgif/button-next-records.gif" }
1197 html {alt="Next Records" border=0></a>}
1199 html {">Next Records</a>}
1202 if {$setMax > 0 && $startPos != "" && $startPos != "1"} {
1206 html {<a href="http:} $env(SCRIPT_NAME)
1207 html / $sessionId {/search.egw/} $setNo + $targetNo
1208 html + [expr $startPos - $hist($setNo,maxPresent)]
1209 html + [expr $startPos - 1]
1211 html {"><img src="/egwgif/button-previous-records.gif" }
1212 html {alt="Previous Records" border=0></a>}
1214 html {">Previous Records</a>}
1217 if {$targetNo > 0} {
1218 button-result-set $setNo $targetNo
1220 button-new-query $setNo
1227 proc score-sort {l r} {
1228 return [expr [lindex $r 0] - [lindex $l 0]]
1231 proc display-result-set-m-score {setNo} {
1237 set not $hist($setNo,0,host)
1238 for {set i 1} {$i <= $not} {incr i} {
1239 if {$zstatus($i) != 2} continue
1240 set status [z39$i.$setNo responseStatus]
1241 if {[lindex $status 0] != "DBOSD"} continue
1242 set nor $hist($setNo,$i,offset)
1243 for {set j 1} {$j <= $nor} {incr j} {
1244 if {![string compare [z39$i.$setNo recordType $j] USmarc]} {
1245 set score [z39$i.$setNo getMarc $j field 999 * r]
1246 if {[scan $score %d score] != 1} {
1253 lappend scoreArray [list $score $i $j]
1257 if {![info exists scoreArray]} {
1258 html "<br><h3>Search produced no result</h3><br>\n"
1261 set scoreSorted [lsort -command score-sort $scoreArray]
1262 foreach r $scoreSorted {
1265 display-$hist($setNo,format) z39$i.$setNo $j $setNo $i
1269 for {set i 1} {$i <= $not} {incr i} {
1270 if {$zstatus($i) != 2} continue
1271 set status [z39$i.$setNo responseStatus]
1272 if {[lindex $status 0] == "NSD"} {
1273 z39$i.$setNo nextResultSetPosition 0
1274 set code [lindex $status 1]
1275 set msg [lindex $status 2]
1276 set addinfo [lindex $status 3]
1277 html {<dt>} [lindex $targets($hist($setNo,$i,host)) 0]
1278 html "<dd>Error: $msg: $addinfo (code $code)<br>\n"
1284 proc display-result-set-m-server {setNo} {
1292 set not $hist($setNo,0,host)
1294 for {set i 1} {$i <= $not} {incr i} {
1295 if {$zstatus($i) != 2} continue
1296 set status [z39$i.$setNo responseStatus]
1297 if {[lindex $status 0] == "NSD"} {
1298 html "<dt><h3>" [lindex $targets($hist($setNo,$i,host)) 0] ": "
1299 z39$i.$setNo nextResultSetPosition 0
1300 set code [lindex $status 1]
1301 set msg [lindex $status 2]
1302 set addinfo [lindex $status 3]
1303 html "Error</h3>\n<dd>NSD$code: $msg: $addinfo"
1305 html {<dt><a href="http:} $env(SCRIPT_NAME)
1306 html / $sessionId {/search.egw/} $setNo + $i + 1
1307 html + $hist($setNo,maxPresent) {">}
1308 html "<h3>" [lindex $targets($hist($setNo,$i,host)) 0] "</a>: "
1309 set r [z39$i.$setNo resultCount]
1310 html "$r hits</h3>\n<dd>\n"
1312 if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
1313 set nor $hist($setNo,maxPresent)
1315 set nor $hist($setNo,$i,offset)
1317 display-rec 1 $nor display-$hist($setNo,format) $setNo $i
1324 proc display-result-set-m {setNo} {
1330 egw_log debug "sort=$hist($setNo,sort)"
1331 switch $hist($setNo,sort) {
1333 display-result-set-m-score $setNo
1336 display-result-set-m-server $setNo
1341 proc display-result-set-s {setNo targetNo startPos endPos} {
1346 set host $hist($setNo,$targetNo,host)
1347 set idAuth $hist($setNo,$targetNo,idAuthentication)
1348 set database $hist($setNo,$targetNo,database)
1349 set query $hist($setNo,$targetNo,query)
1353 if {$startPos == ""} {
1354 if {[z39search $setNo 1 $targetNo B] != "1"} {
1357 set r [$zz.$setNo resultCount]
1359 set setMax [$zz.$setNo resultCount]
1360 if {$setMax > $hist($setNo,maxPresent)} {
1361 set setMax $hist($setNo,maxPresent)
1363 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1365 set setOffset [$zz.$setNo numberOfRecordsReturned]
1367 html {<h3> Records 1-} $setMax " out of $r</h3>\n"
1369 html "<h3> No hits</h3>\n"
1373 display-rec 1 $setMax display-brief $setNo $targetNo
1377 if {[z39search $setNo 0 $targetNo B] != "1"} {
1380 set r [$zz.$setNo resultCount]
1381 set setOffset $startPos
1382 set setMax [$zz.$setNo resultCount]
1383 if {$setMax > $endPos} {
1386 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1388 html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
1390 html "<h3> No hits</h3>\n"
1396 z39present $setNo $targetNo $setOffset $setMax display-brief B
1400 buttons-result-set-s $setNo $targetNo $setMax $startPos 1
1403 proc z39history {} {
1412 if {![info exists nextSetNo]} {
1415 html "<h2>History</h2><br>\n"
1417 html {<table width=500 border=1><tr>}
1418 html {<td align=center><b>Target</b>}
1419 html {<td align=center><b>Database</b>}
1420 html {<td align=center><b>Hits</b>}
1421 html {<td align=center><b>Query</b>}
1426 for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} {
1427 if {[info exists hist($setNo,scan)]} {
1428 if {$hist($setNo,scan) > 0} continue
1430 if {[info exists hist($setNo,1,host)]} {
1432 set end $hist($setNo,0,host)
1437 for {set i $start} {$i <= $end} {incr i} {
1439 html {<td align=left>}
1443 set host $hist($setNo,$i,host)
1444 html [lindex $targets($host) 0]
1446 html {<td align=left>} [join $hist($setNo,$i,database)]
1448 if {[llength [lindex $targets($host) 1]] > 1} {
1450 foreach b $hist($setNo,$i,database) {
1457 html {<td align=right>}
1459 if {[info exists hist($setNo,$i,hits)]} {
1460 html { <a href="http:} $env(SCRIPT_NAME)
1461 html / $sessionId {/search.egw/} $setNo + $i + 1
1462 html + $hist($setNo,maxPresent)
1463 html {">} $hist($setNo,$i,hits) {</a>}
1468 html {Search failed.}
1472 html {<td align=left>}
1476 html { <a href="http:} $env(SCRIPT_NAME)
1477 html / $sessionId / $scriptQuery {;/} $setNo + $host
1481 html {">Query</a>: }
1484 for {set j 1} {$j <= 10} {incr j} {
1485 if {![info exists hist($setNo,form,entry$j)]} {
1488 if {[string length $hist($setNo,form,entry$j)] > 0} {
1489 html " <b>" [join $op " "] "</b> "
1490 set pre [join $hist($setNo,form,menu$j)]
1491 if {[string length $pre] > 0} {
1494 html $hist($setNo,form,entry$j)
1495 set op $hist($setNo,form,logic$j)
1499 html {</a><tr>} "\n"
1511 proc displayError {msga msgb} {
1512 html "<p><center>\n"
1513 html {<img src="/egwgif/noway.gif" alt="Error">}
1514 html "<h2>" $msga "</h2>\n"
1515 if {[string length $msgb] > 0} {
1516 html "<h3>" $msgb "</h3>\n"
1518 html "</center><p>\n"
1521 proc button-main {} {
1523 html {<a href="http://europagate.dtv.dk/">}
1525 html {<img src="/egwgif/button-egw.gif" alt="Europagate" border=0></a>}
1527 html {Europagate</a>}
1531 proc button-feedback {} {
1534 html {<a href="http://europagate.dtv.dk/wwwquest.html">}
1536 html {<img src="/egwgif/button-user-feedback.gif" alt="User Feedback"
1539 html {User Feedback</a>}
1543 proc button-define-target {} {
1551 html {<a href="http:} $env(SCRIPT_NAME)
1552 html / $sessionId {/tform.egw}
1554 html {"><img src="/egwgif/button-define-target.gif" }
1555 html {alt="Define Target" border=0></a>}
1557 html {">Define Target</a>}
1561 proc button-new-target {} {
1567 if {[string length $scriptTarget] == 0} return
1572 html {<a href="http:} $env(SCRIPT_NAME)
1573 html / $sessionId / $scriptTarget
1575 html {"><img src="/egwgif/button-new-target.gif" }
1576 html {alt="New Target" border=0></a>}
1578 html {">New Target</a>}
1582 proc button-view-history {} {
1591 html {<a href="http:} $env(SCRIPT_NAME)
1592 html / $sessionId {/history.egw;}
1593 catch { html "/" $nextSetNo}
1595 html {"><img src="/egwgif/button-view-history.gif" alt="View History" }
1596 html {border=0></a>}
1598 html {">View History</a>}
1602 proc button-new-query {setNo} {
1612 html {<a href="http:} $env(SCRIPT_NAME)
1613 html / $sessionId / $scriptQuery {;/} $setNo + $hist($setNo,0,host) {">}
1616 html {<img src="/egwgif/button-new-query.gif" }
1617 html {alt="New Query" border=0></a>}
1619 html {New Query</a>}
1623 proc button-result-set {setNo tno} {
1632 html {<a href="http:} $env(SCRIPT_NAME) / $sessionId
1634 html {/msearch.egw/} $setNo
1636 html {/search.egw/} $setNo + $tno
1638 html + 1 + $hist($setNo,maxPresent)
1640 html {"><img src="/egwgif/button-result-set.gif" }
1641 html {alt="Result Set" border=0></a>}
1643 html {">Result Set</a>}
1647 proc button-scan-window {setNo} {
1657 html {<a href="http:} $env(SCRIPT_NAME)
1658 html / $sessionId {/search.egw/} $setNo + $targetNo + {scan} {">}
1660 html {<img src="/egwgif/button-scan-window.gif" }
1661 html {alt="Scan" border=0></a>}
1667 proc maintenance {} {
1668 html {<hr>This page is maintained by }
1669 html {<a href="mailto:nobody"> Nobody </a>.}
1670 html {Last modified x x x. <br>}
1673 proc splitHostSpec {host} {
1674 set i [string first / $host]
1677 return [string range $host 0 $i]
1682 proc splitDatabaseSpec {host} {
1683 set i [string first / $host]
1686 regsub -all -- - [string range $host $i end] { } res
1689 regsub -all -- - $host {} res
1693 proc mergeHostSpec {host databases} {
1694 return ${host}/[join $databases -]
1697 proc mkAssoc {assoc host} {
1700 if {[catch {$assoc failback fail-response}]} {
1702 $assoc maximumRecordSize 1000000
1704 if {[$assoc comstack] == "tcpip"} return
1706 $assoc maximumRecordSize 1000000
1710 proc serverList {headlineProc targetProc} {
1712 global groupsDescription
1714 proc targetsCmp {l r} {
1716 return [string compare [string tolower [lindex $targets($l) 0]] \
1717 [string tolower [lindex $targets($r) 0]]]
1719 proc groupCmp {l r} {
1721 if {[catch {set lo $groupsOrder($l)}]} {
1724 if {[catch {set ro $groupsOrder($r)}]} {
1727 return [expr $lo - $ro]
1730 foreach tt [array names targets] {
1731 lappend groupsTmp([lindex $targets($tt) 6]) $tt
1733 set gts [lsort -command groupCmp [array names groupsTmp]]
1735 if {[info exists groupsDescription($gt)]} {
1736 eval $headlineProc [list $groupsDescription($gt)]
1738 eval $headlineProc $gt
1740 set tn [lsort -command targetsCmp $groupsTmp($gt)]
1746 rename targetsCmp {}
1749 proc session-lost {} {
1752 html {<head><title>WWW/Z39.50 Gateway: Session Expired</title></head>}
1756 html {<h1>Session Expired</h1>}
1757 html {Your session has expired. Please reload the gateways' }
1758 html {front page.<br><br>} \n
1761 html {</body></html>}
1764 if {[info exists utilExtension]} {
1765 source $utilExtension