2 # $Id: z39util.tcl,v 1.47 1996/09/03 14:06:43 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} {
72 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"
87 set rtype [$zset recordType $no]
90 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
91 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
92 html [join [$zset getSutrs $no]]
98 set author [$zset getMarc $no field 100 * a]
99 set corp [$zset getMarc $no field 110 * a]
100 set meet [$zset getMarc $no field 111 * a]
101 set title [$zset getMarc $no field 245 * a]
102 if {[llength $author] == 0} {
103 set cover [$zset getMarc $no field 245 * {[bc]}]
105 set cover [$zset getMarc $no field 245 * b]
107 set location [$zset getMarc $no field 260 * a]
108 set publisher [$zset getMarc $no field 260 * b]
109 set year [$zset getMarc $no field 260 * c]
110 set score [$zset getMarc $no field 999 * r]
112 html { <a href="http:} $env(SCRIPT_NAME) /
113 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
144 set v [join $cover ""]
145 if {[string length $v] > 0} {
152 if {[scan $score %d nscore] == 1} {
153 html "; Score " $nscore
156 html { <a href="http:} $env(SCRIPT_NAME) /
157 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
160 html "Error: " $dispError "\n"
165 proc display-brief {zset no setNo targetNo} {
169 set type [$zset type $no]
172 set err [lindex [$zset diag $no] 1]
173 set add [lindex [$zset diag $no] 2]
177 html "${no} Error ${err}${add} <br>\n"
184 set rtype [$zset recordType $no]
187 html { <a href="http:} $env(SCRIPT_NAME) / $sessionId
188 html {/showfull.egw/} $setNo + $targetNo + $no + full {">}
189 html [string range [join [$zset getSutrs $no]] 0 70]
195 set author [$zset getMarc $no field 100 * a]
196 set corp [$zset getMarc $no field 110 * a]
197 set meet [$zset getMarc $no field 111 * a]
198 set title [$zset getMarc $no field 245 * a]
199 if {[llength $author] == 0} {
200 set cover [$zset getMarc $no field 245 * {[bc]}]
202 set cover [$zset getMarc $no field 245 * b]
204 set location [$zset getMarc $no field 260 * a]
205 set publisher [$zset getMarc $no field 260 * b]
206 set year [$zset getMarc $no field 260 * c]
208 html { <a href="http:} $env(SCRIPT_NAME) /
209 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
243 set v [join $cover ""]
244 if {[string length $v] > 40} {
246 html [string range $v 0 38] "..."
247 } elseif {[string length $v] > 0} {
256 html { <a href="http:} $env(SCRIPT_NAME) /
257 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
260 html "Error: " $dispError "\n"
265 proc display-raw {zset no setNo targetNo} {
266 set type [$zset type $no]
269 set err [lindex [$zset diag $no] 1]
270 set add [lindex [$zset diag $no] 2]
274 html "<h3>${no}</h3>\n"
275 html "Error ${err}${add} <br>\n"
284 set rtype [$zset recordType $no]
287 html "<xmp>\n" [join [$zset getSutrs $no]] "\n</xmp>\n"
291 if {[catch {set r [$zset getMarc $no line * * *]}]} {
292 html "Unknown record type: $rtype <br>\n"
296 set tag [lindex $line 0]
297 set indicator [lindex $line 1]
298 set fields [lindex $line 2]
299 set l [string length $indicator]
302 for {set i 0} {$i < $l} {incr i} {
303 if {[string index $indicator $i] == " "} {
306 html [string index $tag $i]
311 foreach field $fields {
312 set id [lindex $field 0]
313 set data [lindex $field 1]
315 html " <b>\$$id</b> "
323 proc put-marc-contents {cc} {
325 if {[string first :// $cc] > 0} {
326 foreach urltype {gopher http ftp mailto} {
327 if {[string first ${urltype}:// $cc] == 0} {
342 proc dl-marc-field {zset no tag id la lb sep} {
344 set c [$zset getMarc $no field $tag * $id]
349 if {$len > 1 && "x$lb" != "x"} {
350 html "<dt><b>$lb</b>\n<dd>"
352 html "<dt><b>$la</b>\n<dd>"
358 put-marc-contents $cc
364 proc dd-marc-field {zset no tag id start stop} {
366 set c [$zset getMarc $no field $tag * $id]
373 put-marc-contents $cc
380 proc dl-marc-field-rec {zset no tag lead start stop startid sep} {
382 set lines [$zset getMarc $no line $tag * *]
383 foreach line $lines {
384 foreach field [lindex $line 2] {
386 html "<dt><b>$lead</b>"
389 set id [lindex $field 0]
390 if {$id == $startid} {
396 html [lindex $field 1]
399 html [lindex $field 1]
408 proc display-full-marc {zset no setNo targetNo} {
414 set n [dl-marc-field $zset $no 700 a "Author" "Authors" "<br>\n"]
416 set n [dl-marc-field $zset $no 100 a "Author" "Authors" "<br>\n"]
418 set n [dl-marc-field $zset $no 710 a "Corporate Name" {} ", "]
420 set n [dl-marc-field $zset $no 110 a "Corporate Name" {} ", "]
422 set n [dl-marc-field $zset $no 711 a "Meeting Name" {} ", "]
424 dd-marc-field $zset $no 711 {[bndc]} " " ""
426 set n [dl-marc-field $zset $no 111 a "Meeting Name" {} ", "]
428 dd-marc-field $zset $no 111 {[bndc]} " " " "
431 set n [dl-marc-field $zset $no 245 {a} "Title" {} " "]
433 dd-marc-field $zset $no 245 b "<em>" "</em>"
434 dd-marc-field $zset $no 245 c " " ""
436 dl-marc-field $zset $no 245 {[ab]} "Title" {} " "
438 dl-marc-field $zset $no 520 a "Abstract" {} ", "
439 dl-marc-field $zset $no 072 * "Subject code" "Subject codes" ", "
440 dl-marc-field $zset $no 650 * "Subject" {} ", "
441 dl-marc-field $zset $no 260 * "Publisher" {} " "
442 dl-marc-field $zset $no 300 * "Physical Description" {} " "
444 dl-marc-field-rec $zset $no 500 "Notes" "" "<br>\n" "a" ", "
446 dl-marc-field-rec $zset $no 510 "References" "" "<br>\n" "a" ", "
448 dl-marc-field-rec $zset $no 511 "Participant note" "" "<br>\n" "a" ", "
450 dl-marc-field $zset $no 513 a "Report type" {} ", "
451 dl-marc-field $zset $no 513 b "Period covered" {} ", "
452 dl-marc-field-rec $zset $no 515 "Numbering notes" "" "<br>\n" "a" ", "
453 dl-marc-field-rec $zset $no 516 "Data notes" "" "<br>\n" "a" ", "
454 dl-marc-field-rec $zset $no 518 "Date/time notes" "" "<br>\n" "a" ", "
456 dl-marc-field $zset $no 350 a "Price" {} ", "
457 dl-marc-field $zset $no 362 a "Dates of publication" {} ", "
458 dl-marc-field $zset $no 850 a "Holdings" {} ", "
460 dl-marc-field-rec $zset $no 270 "Contact name" "" "<br>\n" p ", "
462 set n [dl-marc-field $zset $no 270 p "Contact name" {} ", "]
467 dl-marc-field $zset $no 270 a "Street" {} ", "
468 dl-marc-field $zset $no 270 b "City" {} ", "
469 dl-marc-field $zset $no 270 c "State" {} ", "
470 dl-marc-field $zset $no 270 e "Zip code" {} ", "
471 dl-marc-field $zset $no 270 d "Country" {} ", "
472 dl-marc-field $zset $no 270 m "Network address" {} ", "
473 dl-marc-field $zset $no 301 a "Service hours" {} ", "
474 dl-marc-field $zset $no 270 k "Phone" {} ", "
475 dl-marc-field $zset $no 270 l "Fax" {} ", "
477 dl-marc-field $zset $no 270 {[abcedmakl]} "Address" {} "<br>\n"
483 dl-marc-field $zset $no 010 a "LC control number" {} ", "
484 dl-marc-field $zset $no 010 b "NUCMC control number" {} ", "
485 dl-marc-field $zset $no 020 a "ISBN" {} ", "
486 dl-marc-field $zset $no 022 a "ISSN" {} ", "
487 set url [$zset getMarc $no field 856 * u]
488 set sp [$zset getMarc $no field 856 * 3]
489 if {"x$url" != "x"} {
490 html "<dt><b>URL</b>\n"
494 html {<dd><a href="} [join $url] {">} [join $sp] "</a>\n"
496 dl-marc-field $zset $no 037 {[abc]} "Acquisition" {} "<br>\n"
497 dl-marc-field $zset $no 037 {[f6]} "Form of issue" {} "<br>\n"
498 dl-marc-field $zset $no 537 * "Source of data" {} "<br>\n"
499 dl-marc-field $zset $no 538 * "System details" {} "<br>\n"
500 dl-marc-field $zset $no 787 {[rstw6]} "Related information" {} "<br>\n"
501 dl-marc-field $zset $no 999 r "Score" {} ", "
502 dl-marc-field $zset $no 001 * "Local control number" {} ", "
506 proc display-full {zset no setNo targetNo} {
507 set type [$zset type $no]
510 set err [lindex [$zset diag $no] 1]
511 set add [lindex [$zset diag $no] 2]
515 html "Error ${err}${add} <br>\n"
524 set rtype [$zset recordType $no]
527 html "<pre>" [join [$zset getSutrs $no]] "</pre><br>\n"
531 if {[catch {set r [$zset getMarc $no line * * *]}]} {
532 html "Unknown record type: $rtype <br>\n"
535 display-full-marc $zset $no $setNo $targetNo
539 proc display-rec {from to dfunc setNo targetNo} {
540 while {$from <= $to} {
541 eval "$dfunc z39${targetNo}.${setNo} $from $setNo $targetNo"
546 proc build-scan {t i} {
549 set term [egw_form entry$i]
551 set field [join [egw_form menu$i]]
553 foreach x [lindex $targets($t) 2] {
554 if {[lindex $x 0] == $field} {
555 set attr [lindex $x 1]
558 return [list $term $attr]
563 proc build-query {t ilines} {
568 for {set i 1} {$i <= $ilines} {incr i} {
569 set term [join [egw_form entry$i]]
570 if {[string length $term] == 0} continue
571 set field [join [egw_form menu$i]]
573 foreach x [lindex $targets($t) 2] {
574 if {![string compare [lindex $x 0] $field]} {
575 set attr [lindex $x 1]
578 if {![info exists attr]} {
579 egw_log debug "attr failed for $t"
580 set attr [lindex [lindex [lindex $targets($t) 2] 0] 1]
582 egw_log debug "op=${op}"
585 { set q "@and $q ${attr} \"${term}\""; egw_log debug AND }
587 { set q "@or $q ${attr} \"${term}\""; egw_log debug OR }
589 { set q "${attr} \"${term}\""; egw_log debug NOPE }
591 { set q "@not $q ${attr} \"${term}\""; egw_log debug ANDNOT }
593 set op [egw_form logic$i]
598 proc z39scan {setNo scanNo tno scanLines scanPos cache} {
604 set host $hist($setNo,$tno,host)
605 set idAuth $hist($setNo,$tno,idAuthentication)
606 set database $hist($setNo,$tno,database)
607 set scanAttr $hist($setNo,scanAttr)
608 set scanTerm $hist($setNo,$scanNo,scanTerm)
611 if {[catch [list set oldHost [$zz connect]]]} {
614 set zs $zz.s$scanNo.$setNo
615 $zz callback ok-response
616 $zz failback fail-response
617 set thisHost [splitHostSpec $host]
618 if {[string compare $oldHost $thisHost]} {
619 catch [list $zz disconnect]
622 if {[catch [list $zz connect $thisHost]]} {
623 displayError "Cannot connect to target" $thisHost
625 } elseif {$sessionWait == 0} {
626 if {[catch {egw_wait sessionWait 300}]} {
628 displayError "Cannot connect to target" $thisHost
631 if {$sessionWait != 1} {
632 displayError "Cannot connect to target" $thisHost
636 $zz idAuthentication $idAuth
638 if {[catch {$zz init}]} {
639 displayError "Cannot initialize target" $thisHost
643 if {[catch {egw_wait sessionWait 60}]} {
644 displayError "Cannot initialize target" $thisHost
648 if {$sessionWait != "1"} {
649 displayError "Cannot initialize target" $thisHost
653 if {![$zz initResult]} {
654 set u [$zz userInformationField]
656 displayError "Cannot initialize target $thisHost" $u
660 if {$cache && ![catch [list $zs numberOfTermsRequested 5]]} {
664 eval $zz databaseNames $database
668 $zs numberOfTermsRequested $scanLines
669 $zs preferredPositionInResponse $scanPos
671 $zz callback [list scan-response $zs]
673 egw_log debug "scan: ${scanAttr} ${scanTerm}"
675 $zs scan "${scanAttr} ${scanTerm}"
677 if {[catch {egw_wait sessionWait 60}]} {
678 egw_log debug "timeout/cancel in scan"
679 displayError "Timeout in scan" {}
680 html "</body></html>\n"
684 if {$sessionWait == -1} {
685 displayError "Scan fail" "Connection closed"
686 html "</body></html>\n"
689 if {$sessionWait != 1} {
695 proc display-scan {setNo scanNo tno} {
703 set zs $zz.s$scanNo.$setNo
704 set m [$zs numberOfEntriesReturned]
707 set t [lindex [$zs scanLine 0] 1]
709 set hist($setNo,$tno,[expr $scanNo - 1],scanTerm) $t
711 set hist($setNo,[expr $scanNo - 1],scanTerm) $t
713 set t [lindex [$zs scanLine [expr $m - 1]] 1]
715 set hist($setNo,$tno,[expr $scanNo + 1],scanTerm) $t
717 set hist($setNo,[expr $scanNo + 1],scanTerm) $t
720 html {<table width=500 border=0><tr>}
721 html {<td align=left><b>Scan term</b>}
722 html {<td align=right><b>Hits</b>}
725 for {set i 0} {$i < $m} {incr i} {
726 html {<td align=left>}
728 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
729 html {<a href="http:} $env(SCRIPT_NAME)
730 html / $sessionId / $scriptQuery {;/} $setNo + $hist($setNo,host) +
731 html $hist($setNo,scan) + $tterm {">}
733 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
734 html {<a href="http:} $env(SCRIPT_NAME)
735 html / $sessionId {/search.egw/} $setNo + $tno +
736 html hyper + $tterm {">}
738 html [lindex [$zs scanLine $i] 1]
740 html {<td align=right>}
741 html [lindex [$zs scanLine $i] 2]
747 proc z39search {setNo piggy tno elements} {
753 set host $hist($setNo,$tno,host)
754 set idAuth $hist($setNo,$tno,idAuthentication)
755 set database $hist($setNo,$tno,database)
756 set query $hist($setNo,$tno,query)
757 catch {set docId $hist($setNo,$tno,queryId)}
760 if {[catch [list set oldHost [$zz connect]]]} {
763 $zz callback ok-response
764 $zz failback fail-response
765 set thisHost [splitHostSpec $host]
766 if {[string compare $oldHost $thisHost]} {
767 catch [list $zz disconnect]
770 if {[catch [list $zz connect $thisHost]]} {
771 displayError "Cannot connect to target" $thisHost
773 } elseif {$sessionWait == 0} {
774 if {[catch {egw_wait sessionWait 300}]} {
776 displayError "Cannot connect to target" $thisHost
779 if {$sessionWait != 1} {
780 displayError "Cannot connect to target" $thisHost
784 $zz idAuthentication $idAuth
786 if {[catch {$zz init}]} {
787 displayError "Cannot initialize target" $thisHost
791 if {$sessionWait == 0 && [catch {egw_wait sessionWait 60}]} {
792 displayError "Cannot initialize target" $thisHost
796 if {$sessionWait != "1"} {
797 displayError "Cannot initialize target" $thisHost
801 if {![$zz initResult]} {
802 set u [$zz userInformationField]
804 displayError "Cannot initialize target $thisHost" $u
807 } elseif {![catch [list $zz.$setNo smallSetUpperBound 0]]} {
808 if {[info exists hist($setNo,$tno,hits)]} {
813 ir-set $zz.$setNo $zz
814 $zz.$setNo preferredRecordSyntax [lindex $targets($host) 1]
815 egw_log debug "set syntax to [lindex $targets($host) 1]"
816 if {![lindex $targets($host) 5]} {
819 $zz.$setNo smallSetElementSetNames $elements
820 $zz.$setNo mediumSetElementSetNames $elements
821 $zz.$setNo recordElements $elements
823 egw_log debug "database=$database"
824 eval $zz.$setNo databaseNames $database
826 $zz callback [list search-response $zz.$setNo]
828 $zz.$setNo largeSetLowerBound 999999
829 $zz.$setNo smallSetUpperBound 0
830 $zz.$setNo mediumSetPresentNumber $hist($setNo,maxPresent)
832 $zz.$setNo largeSetLowerBound 2
833 $zz.$setNo smallSetUpperBound 0
834 $zz.$setNo mediumSetPresentNumber 0
837 egw_log debug "search: $query"
839 if {[info exists docId]} {
840 $zz.$setNo search $query $docId
842 $zz.$setNo search $query
845 if {!$sessionWait && [catch {egw_wait sessionWait 60}]} {
846 egw_log debug "timeout/cancel in search"
847 displayError "Timeout in search" {}
848 html "</body></html>\n"
853 if {$sessionWait == -1} {
854 displayError "Search fail" "Connection closed"
855 html "</body></html>\n"
858 if {$sessionWait != 1} {
861 set hist($setNo,$tno,hits) [$zz.$setNo resultCount]
865 proc init-m-response {i} {
869 egw_log debug "init-m-response"
872 if {![z39$i initResult]} {
880 proc connect-m-response {i} {
884 egw_log debug "connect-m-response"
885 z39$i callback [list init-m-response $i]
886 if {[catch {z39$i init}]} {
892 proc fail-m-response {i} {
896 egw_log debug "fail-m-response"
901 proc search-m-response {setNo i start number} {
906 egw_log debug "search-m-response"
907 set status [z39$i.$setNo responseStatus]
908 egw_log debug "search-m-response1"
909 if {[lindex $status 0] == "OK"} {
911 } elseif {[lindex $status 0] == "DBOSD"} {
912 set nor [z39$i.$setNo numberOfRecordsReturned]
914 egw_log debug "search-m-response2"
919 set hist($setNo,$i,hits) [z39$i.$setNo resultCount]
920 egw_log debug "search-m-response3"
921 set hist($setNo,$i,offset) [expr $start + $nor -1]
922 if {[expr $nor + $start] > [z39$i.$setNo resultCount]} {
923 egw_log debug "search-m-response4"
928 egw_log debug "search-m-response5"
929 if {$nor >= $number} {
930 egw_log debug "search-m-response6 nor=$nor number=$number"
935 egw_log debug "search-m-response7"
936 set start [expr $start + $nor]
937 set number [expr $number - $nor]
938 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
939 set number [expr [z39$i.$setNo resultCount] - $start + 1]
941 z39$i callback [list search-m-response $setNo $i $start $number]
942 egw_log debug "mpresent start=$number number=$number"
943 z39$i.$setNo present $start $number
946 proc z39msearch {setNo elements start number cache} {
953 set not $hist($setNo,0,host)
955 egw_log debug "z39msearch start=$start number=$number elements=$elements"
956 for {set i 1} {$i <= $not} {incr i} {
957 set host $hist($setNo,$i,host)
959 set oldHost [z39$i connect]
960 set thisHost [splitHostSpec $host]
961 if {[string compare $oldHost $thisHost]} {
962 catch {z39$i disconnect}
964 z39$i callback [list connect-m-response $i]
965 z39$i failback [list fail-m-response $i]
968 for {set i 1} {$i <= $not} {incr i} {
969 set oldHost [z39$i connect]
970 set host $hist($setNo,$i,host)
971 set thisHost [splitHostSpec $host]
972 if {![string compare $oldHost $thisHost]} {
975 egw_log debug "old=$oldHost this=$thisHost"
976 z39$i idAuthentication $hist($setNo,$i,idAuthentication)
977 html "Connecting to target " $thisHost " <br>\n"
979 if {![catch {z39$i connect $thisHost}]} {
984 egw_log debug "Waiting for init response"
985 if {[catch {egw_wait zleft 20} reason]} {
986 if {![string compare $reason cancel]} {
987 for {set i 1} {$i <= $not} {incr i} {
989 catch {z39$i disconnect}
993 for {set i 1} {$i <= $not} {incr i} {
994 if {$zstatus($i) == -1} {
995 catch {z39$i disconnect}
1003 for {set i 1} {$i <= $not} {incr i} {
1004 set host $hist($setNo,$i,host)
1006 html "host " [splitHostSpec $host] ": "
1008 egw_log debug "i=$i zstatus=$zstatus($i)"
1009 if {$zstatus($i) < 1} {
1015 if {[catch [list z39$i.$setNo preferredRecordSyntax]]} {
1020 ir-set z39$i.$setNo z39$i
1021 z39$i.$setNo preferredRecordSyntax [lindex $targets($host) 1]
1022 egw_log debug "set syntax to [lindex $targets($host) 1]"
1023 set hist($setNo,$i,offset) 0
1024 eval z39$i.$setNo databaseNames $hist($setNo,$i,database)
1026 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1029 set thisElements $elements
1031 z39$i.$setNo smallSetElementSetNames $thisElements
1032 z39$i.$setNo mediumSetElementSetNames $thisElements
1033 z39$i.$setNo elementSetNames $thisElements
1034 z39$i.$setNo recordElements $thisElements
1036 z39$i callback [list search-m-response $setNo $i $start $number]
1039 z39$i.$setNo largeSetLowerBound 999999
1040 z39$i.$setNo smallSetUpperBound 0
1041 z39$i.$setNo mediumSetPresentNumber $number
1043 z39$i.$setNo largeSetLowerBound 2
1044 z39$i.$setNo smallSetUpperBound 0
1045 z39$i.$setNo mediumSetPresentNumber 0
1049 egw_log debug "msearch host=" $hist($setNo,$i,host)
1050 egw_log debug "setNo=$setNo query=" $hist($setNo,$i,query) "="
1051 if {[catch {z39$i.$setNo search $hist($setNo,$i,query)}]} {
1055 } elseif {[z39$i.$setNo resultCount] >= $start} {
1056 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1057 set tnumber [expr [z39$i.$setNo resultCount] - $start + 1]
1061 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1064 set thisElements $elements
1066 z39$i.$setNo smallSetElementSetNames $thisElements
1067 z39$i.$setNo mediumSetElementSetNames $thisElements
1068 z39$i.$setNo elementSetNames $thisElements
1069 z39$i.$setNo recordElements $thisElements
1071 for {set n 0} {$n < $tnumber} {incr n} {
1072 if {[z39$i.$setNo recordType [expr $start + $n]] == ""} {
1074 egw_log debug "failed on $n"
1077 html "no record at #" [expr $start + $n]
1078 html " el=-" $thisElements "-"
1083 if {$n == $tnumber} {
1090 html "present<br>\n"
1091 z39$i callback [list search-m-response $setNo $i $start $tnumber]
1093 egw_log debug "mpresent start=$start number=$tnumber"
1094 z39$i.$setNo present $start $tnumber
1103 while {$zleft > 0} {
1104 egw_log debug "Waiting for search/present response"
1105 if {[catch {egw_wait zleft 60} reason]} {
1106 if {![string compare $reason cancel]} {
1107 for {set i 1} {$i <= $not} {incr i} {
1108 catch {z39$i disconnect}
1113 for {set i 1} {$i <= $not} {incr i} {
1114 if {$zstatus($i) != 2} {
1115 catch {z39$i disconnect}
1122 for {set i 1} {$i <= $not} {incr i} {
1123 if {$zstatus($i) != 2} continue
1124 set status [z39$i.$setNo responseStatus]
1125 if {0 && [lindex $status 0] != "NSD"} {
1126 set hist($setNo,$i,offset) [z39$i.$setNo numberOfRecordsReturned]
1131 proc z39present {setNo tno setOffset setMax dfunc elements} {
1137 set host $hist($setNo,$tno,host)
1139 if {![lindex $targets($host) 5]} {
1143 $zz.$setNo elementSetNames $elements
1144 $zz.$setNo recordElements $elements
1145 set toGet [expr 1 + $setMax - $setOffset]
1147 $zz callback [list search-response $zz.$setNo]
1149 while {$setMax > 0 && $toGet > 0} {
1150 for {set got 0} {$got < $toGet} {incr got} {
1151 if {[$zz.$setNo recordType [expr $setOffset + $got]] == ""} {
1155 if {$got < $toGet} {
1157 $zz.$setNo present $setOffset $toGet
1158 if {[catch {egw_wait sessionWait 300}]} {
1159 egw_log debug "timeout/cancel in present"
1163 if {$sessionWait == "0"} {
1166 if {$sessionWait != "1"} {
1169 set got [$zz.$setNo numberOfRecordsReturned]
1174 display-rec $setOffset [expr $got + $setOffset - 1] $dfunc $setNo $tno
1175 set setOffset [expr $got + $setOffset]
1176 set toGet [expr 1 + $setMax - $setOffset]
1181 proc buttons-result-set-s {setNo targetNo setMax startPos after} {
1190 if {$setMax > 0 && $setMax < [$zz.$setNo resultCount]} {
1194 html {<a href="http:} $env(SCRIPT_NAME)
1195 html / $sessionId {/search.egw/} $setNo + $targetNo +
1196 html [expr $setMax + 1] + [expr $setMax + $hist($setNo,maxPresent)]
1198 html {"><img src="/egwgif/button-next-records.gif" }
1199 html {alt="Next Records" border=0></a>}
1201 html {">Next Records</a>}
1204 if {$setMax > 0 && $startPos != "" && $startPos != "1"} {
1208 html {<a href="http:} $env(SCRIPT_NAME)
1209 html / $sessionId {/search.egw/} $setNo + $targetNo
1210 html + [expr $startPos - $hist($setNo,maxPresent)]
1211 html + [expr $startPos - 1]
1213 html {"><img src="/egwgif/button-previous-records.gif" }
1214 html {alt="Previous Records" border=0></a>}
1216 html {">Previous Records</a>}
1219 if {$targetNo > 0} {
1220 button-result-set $setNo $targetNo
1222 button-new-query $setNo
1229 proc score-sort {l r} {
1230 return [expr [lindex $r 0] - [lindex $l 0]]
1233 proc display-result-set-m-score {setNo} {
1239 set not $hist($setNo,0,host)
1240 for {set i 1} {$i <= $not} {incr i} {
1241 if {$zstatus($i) != 2} continue
1242 set status [z39$i.$setNo responseStatus]
1243 if {[lindex $status 0] != "DBOSD"} continue
1244 set nor $hist($setNo,$i,offset)
1245 for {set j 1} {$j <= $nor} {incr j} {
1246 if {![string compare [z39$i.$setNo recordType $j] USmarc]} {
1247 set score [z39$i.$setNo getMarc $j field 999 * r]
1248 if {[scan $score %d score] != 1} {
1255 lappend scoreArray [list $score $i $j]
1259 if {![info exists scoreArray]} {
1260 html "<br><h3>Search produced no result</h3><br>\n"
1263 set scoreSorted [lsort -command score-sort $scoreArray]
1264 foreach r $scoreSorted {
1267 display-$hist($setNo,format) z39$i.$setNo $j $setNo $i
1271 for {set i 1} {$i <= $not} {incr i} {
1272 if {$zstatus($i) != 2} continue
1273 set status [z39$i.$setNo responseStatus]
1274 if {[lindex $status 0] == "NSD"} {
1275 z39$i.$setNo nextResultSetPosition 0
1276 set code [lindex $status 1]
1277 set msg [lindex $status 2]
1278 set addinfo [lindex $status 3]
1279 html {<dt>} [lindex $targets($hist($setNo,$i,host)) 0]
1280 html "<dd>Error: $msg: $addinfo (code $code)<br>\n"
1286 proc display-result-set-m-server {setNo} {
1294 set not $hist($setNo,0,host)
1296 for {set i 1} {$i <= $not} {incr i} {
1297 if {$zstatus($i) != 2} continue
1298 set status [z39$i.$setNo responseStatus]
1299 if {[lindex $status 0] == "NSD"} {
1300 html "<dt><h3>" [lindex $targets($hist($setNo,$i,host)) 0] ": "
1301 z39$i.$setNo nextResultSetPosition 0
1302 set code [lindex $status 1]
1303 set msg [lindex $status 2]
1304 set addinfo [lindex $status 3]
1305 html "Error</h3>\n<dd>NSD$code: $msg: $addinfo"
1307 html {<dt><a href="http:} $env(SCRIPT_NAME)
1308 html / $sessionId {/search.egw/} $setNo + $i + 1
1309 html + $hist($setNo,maxPresent) {">}
1310 html "<h3>" [lindex $targets($hist($setNo,$i,host)) 0] "</a>: "
1311 set r [z39$i.$setNo resultCount]
1312 html "$r hits</h3>\n<dd>\n"
1314 if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
1315 set nor $hist($setNo,maxPresent)
1317 set nor $hist($setNo,$i,offset)
1319 display-rec 1 $nor display-$hist($setNo,format) $setNo $i
1326 proc display-result-set-m {setNo} {
1332 egw_log debug "sort=$hist($setNo,sort)"
1333 switch $hist($setNo,sort) {
1335 display-result-set-m-score $setNo
1338 display-result-set-m-server $setNo
1343 proc display-result-set-s {setNo targetNo startPos endPos} {
1348 set host $hist($setNo,$targetNo,host)
1349 set idAuth $hist($setNo,$targetNo,idAuthentication)
1350 set database $hist($setNo,$targetNo,database)
1351 set query $hist($setNo,$targetNo,query)
1355 if {$startPos == ""} {
1356 if {[z39search $setNo 1 $targetNo B] != "1"} {
1359 set r [$zz.$setNo resultCount]
1361 set setMax [$zz.$setNo resultCount]
1362 if {$setMax > $hist($setNo,maxPresent)} {
1363 set setMax $hist($setNo,maxPresent)
1365 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1367 set setOffset [$zz.$setNo numberOfRecordsReturned]
1369 html {<h3> Records 1-} $setMax " out of $r</h3>\n"
1371 html "<h3> No hits</h3>\n"
1375 display-rec 1 $setMax display-brief $setNo $targetNo
1379 if {[z39search $setNo 0 $targetNo B] != "1"} {
1382 set r [$zz.$setNo resultCount]
1383 set setOffset $startPos
1384 set setMax [$zz.$setNo resultCount]
1385 if {$setMax > $endPos} {
1388 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1390 html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
1392 html "<h3> No hits</h3>\n"
1398 z39present $setNo $targetNo $setOffset $setMax display-brief B
1402 buttons-result-set-s $setNo $targetNo $setMax $startPos 1
1405 proc z39history {} {
1414 if {![info exists nextSetNo]} {
1417 html "<h2>History</h2><br>\n"
1419 html {<table width=500 border=1><tr>}
1420 html {<td align=center><b>Target</b>}
1421 html {<td align=center><b>Database</b>}
1422 html {<td align=center><b>Hits</b>}
1423 html {<td align=center><b>Query</b>}
1428 for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} {
1429 if {[info exists hist($setNo,scan)]} {
1430 if {$hist($setNo,scan) > 0} continue
1432 if {[info exists hist($setNo,1,host)]} {
1434 set end $hist($setNo,0,host)
1439 for {set i $start} {$i <= $end} {incr i} {
1441 html {<td align=left>}
1445 set host $hist($setNo,$i,host)
1446 html [lindex $targets($host) 0]
1448 html {<td align=left>} [join $hist($setNo,$i,database)]
1450 if {[llength [lindex $targets($host) 1]] > 1} {
1452 foreach b $hist($setNo,$i,database) {
1459 html {<td align=right>}
1461 if {[info exists hist($setNo,$i,hits)]} {
1462 html { <a href="http:} $env(SCRIPT_NAME)
1463 html / $sessionId {/search.egw/} $setNo + $i + 1
1464 html + $hist($setNo,maxPresent)
1465 html {">} $hist($setNo,$i,hits) {</a>}
1470 html {Search failed.}
1474 html {<td align=left>}
1478 html { <a href="http:} $env(SCRIPT_NAME)
1479 html / $sessionId / $scriptQuery {;/} $setNo + $host
1483 html {">Query</a>: }
1486 for {set j 1} {$j <= 10} {incr j} {
1487 if {![info exists hist($setNo,form,entry$j)]} {
1490 if {[string length $hist($setNo,form,entry$j)] > 0} {
1491 html " <b>" [join $op " "] "</b> "
1492 set pre [join $hist($setNo,form,menu$j)]
1493 if {[string length $pre] > 0} {
1496 html $hist($setNo,form,entry$j)
1497 set op $hist($setNo,form,logic$j)
1501 html {</a><tr>} "\n"
1513 proc displayError {msga msgb} {
1514 html "<p><center>\n"
1515 html {<img src="/egwgif/noway.gif" alt="Error">}
1516 html "<h2>" $msga "</h2>\n"
1517 if {[string length $msgb] > 0} {
1518 html "<h3>" $msgb "</h3>\n"
1520 html "</center><p>\n"
1523 proc button-main {} {
1525 html {<a href="http://europagate.dtv.dk/">}
1527 html {<img src="/egwgif/button-egw.gif" alt="Europagate" border=0></a>}
1529 html {Europagate</a>}
1533 proc button-feedback {} {
1536 html {<a href="http://europagate.dtv.dk/wwwquest.html">}
1538 html {<img src="/egwgif/button-user-feedback.gif" alt="User Feedback"
1542 html {User Feedback</a>}
1546 proc button-define-target {} {
1554 html {<a href="http:} $env(SCRIPT_NAME)
1555 html / $sessionId {/tform.egw}
1557 html {"><img src="/egwgif/button-define-target.gif" }
1558 html {alt="Define Target" border=0></a>}
1560 html {">Define Target</a>}
1564 proc button-new-target {} {
1570 if {[string length $scriptTarget] == 0} return
1575 html {<a href="http:} $env(SCRIPT_NAME)
1576 html / $sessionId / $scriptTarget
1578 html {"><img src="/egwgif/button-new-target.gif" }
1579 html {alt="New Target" border=0></a>}
1581 html {">New Target</a>}
1585 proc button-view-history {} {
1594 html {<a href="http:} $env(SCRIPT_NAME)
1595 html / $sessionId {/history.egw;}
1596 catch { html "/" $nextSetNo}
1598 html {"><img src="/egwgif/button-view-history.gif" alt="View History" }
1599 html {border=0></a>}
1601 html {">View History</a>}
1605 proc button-new-query {setNo} {
1615 html {<a href="http:} $env(SCRIPT_NAME)
1616 html / $sessionId / $scriptQuery {;/} $setNo + $hist($setNo,0,host) {">}
1619 html {<img src="/egwgif/button-new-query.gif" }
1620 html {alt="New Query" border=0></a>}
1622 html {New Query</a>}
1626 proc button-result-set {setNo tno} {
1635 html {<a href="http:} $env(SCRIPT_NAME) / $sessionId
1637 html {/msearch.egw/} $setNo
1639 html {/search.egw/} $setNo + $tno
1641 html + 1 + $hist($setNo,maxPresent)
1643 html {"><img src="/egwgif/button-result-set.gif" }
1644 html {alt="Result Set" border=0></a>}
1646 html {">Result Set</a>}
1650 proc button-scan-window {setNo} {
1660 html {<a href="http:} $env(SCRIPT_NAME)
1661 html / $sessionId {/search.egw/} $setNo + $targetNo + {scan} {">}
1663 html {<img src="/egwgif/button-scan-window.gif" }
1664 html {alt="Scan" border=0></a>}
1670 proc maintenance {} {
1671 html {<hr>This page is maintained by }
1672 html {<a href="mailto:nobody"> Nobody </a>.}
1673 html {Last modified x x x. <br>}
1676 proc splitHostSpec {host} {
1677 set i [string first / $host]
1680 return [string range $host 0 $i]
1685 proc splitDatabaseSpec {host} {
1686 set i [string first / $host]
1689 regsub -all -- - [string range $host $i end] { } res
1692 regsub -all -- - $host {} res
1696 proc mergeHostSpec {host databases} {
1697 return ${host}/[join $databases -]
1700 proc mkAssoc {assoc host} {
1703 if {[catch {$assoc failback fail-response}]} {
1705 $assoc maximumRecordSize 1000000
1707 if {[$assoc comstack] == "tcpip"} return
1709 $assoc maximumRecordSize 1000000
1713 proc serverList {headlineProc targetProc} {
1715 global groupsDescription
1717 proc targetsCmp {l r} {
1719 return [string compare [string tolower [lindex $targets($l) 0]] \
1720 [string tolower [lindex $targets($r) 0]]]
1722 proc groupCmp {l r} {
1724 if {[catch {set lo $groupsOrder($l)}]} {
1727 if {[catch {set ro $groupsOrder($r)}]} {
1730 return [expr $lo - $ro]
1733 foreach tt [array names targets] {
1734 lappend groupsTmp([lindex $targets($tt) 6]) $tt
1736 set gts [lsort -command groupCmp [array names groupsTmp]]
1738 if {[info exists groupsDescription($gt)]} {
1739 eval $headlineProc [list $groupsDescription($gt)]
1741 eval $headlineProc $gt
1743 set tn [lsort -command targetsCmp $groupsTmp($gt)]
1749 rename targetsCmp {}
1752 proc session-lost {} {
1755 html {<head><title>WWW/Z39.50 Gateway: Session Expired</title></head>}
1759 html {<h1>Session Expired</h1>}
1760 html {Your session has expired. Please reload the gateways' }
1761 html {front page.<br><br>} \n
1764 html {</body></html>}
1767 if {[info exists utilExtension]} {
1768 source $utilExtension