2 # $Id: z39util.tcl,v 1.49 1997/11/19 13:29:13 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 $indicator $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)
978 if {![catch {z39$i connect $thisHost}]} {
983 egw_log debug "Waiting for init response"
984 if {[catch {egw_wait zleft 20} reason]} {
985 if {![string compare $reason cancel]} {
986 for {set i 1} {$i <= $not} {incr i} {
988 catch {z39$i disconnect}
992 for {set i 1} {$i <= $not} {incr i} {
993 if {$zstatus($i) == -1} {
994 catch {z39$i disconnect}
1002 for {set i 1} {$i <= $not} {incr i} {
1003 set host $hist($setNo,$i,host)
1005 html "host " [splitHostSpec $host] ": "
1007 egw_log debug "i=$i zstatus=$zstatus($i)"
1008 if {$zstatus($i) < 1} {
1014 if {[catch [list z39$i.$setNo preferredRecordSyntax]]} {
1019 ir-set z39$i.$setNo z39$i
1020 z39$i.$setNo preferredRecordSyntax [lindex $targets($host) 1]
1021 egw_log debug "set syntax to [lindex $targets($host) 1]"
1022 set hist($setNo,$i,offset) 0
1023 eval z39$i.$setNo databaseNames $hist($setNo,$i,database)
1025 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1028 set thisElements $elements
1030 z39$i.$setNo smallSetElementSetNames $thisElements
1031 z39$i.$setNo mediumSetElementSetNames $thisElements
1032 z39$i.$setNo elementSetNames $thisElements
1033 z39$i.$setNo recordElements $thisElements
1035 z39$i callback [list search-m-response $setNo $i $start $number]
1038 z39$i.$setNo largeSetLowerBound 999999
1039 z39$i.$setNo smallSetUpperBound 0
1040 z39$i.$setNo mediumSetPresentNumber $number
1042 z39$i.$setNo largeSetLowerBound 2
1043 z39$i.$setNo smallSetUpperBound 0
1044 z39$i.$setNo mediumSetPresentNumber 0
1048 egw_log debug "msearch host=" $hist($setNo,$i,host)
1049 egw_log debug "setNo=$setNo query=" $hist($setNo,$i,query) "="
1050 if {[catch {z39$i.$setNo search $hist($setNo,$i,query)}]} {
1054 } elseif {[z39$i.$setNo resultCount] >= $start} {
1055 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1056 set tnumber [expr [z39$i.$setNo resultCount] - $start + 1]
1060 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1063 set thisElements $elements
1065 z39$i.$setNo smallSetElementSetNames $thisElements
1066 z39$i.$setNo mediumSetElementSetNames $thisElements
1067 z39$i.$setNo elementSetNames $thisElements
1068 z39$i.$setNo recordElements $thisElements
1070 for {set n 0} {$n < $tnumber} {incr n} {
1071 if {[z39$i.$setNo recordType [expr $start + $n]] == ""} {
1073 egw_log debug "failed on $n"
1076 html "no record at #" [expr $start + $n]
1077 html " el=-" $thisElements "-"
1082 if {$n == $tnumber} {
1089 html "present<br>\n"
1090 z39$i callback [list search-m-response $setNo $i $start $tnumber]
1092 egw_log debug "mpresent start=$start number=$tnumber"
1093 z39$i.$setNo present $start $tnumber
1102 while {$zleft > 0} {
1103 egw_log debug "Waiting for search/present response"
1104 if {[catch {egw_wait zleft 60} reason]} {
1105 if {![string compare $reason cancel]} {
1106 for {set i 1} {$i <= $not} {incr i} {
1107 catch {z39$i disconnect}
1112 for {set i 1} {$i <= $not} {incr i} {
1113 if {$zstatus($i) != 2} {
1114 catch {z39$i disconnect}
1121 for {set i 1} {$i <= $not} {incr i} {
1122 if {$zstatus($i) != 2} continue
1123 set status [z39$i.$setNo responseStatus]
1124 if {0 && [lindex $status 0] != "NSD"} {
1125 set hist($setNo,$i,offset) [z39$i.$setNo numberOfRecordsReturned]
1130 proc z39present {setNo tno setOffset setMax dfunc elements} {
1136 set host $hist($setNo,$tno,host)
1138 if {![lindex $targets($host) 5]} {
1142 $zz.$setNo elementSetNames $elements
1143 $zz.$setNo recordElements $elements
1144 set toGet [expr 1 + $setMax - $setOffset]
1146 $zz callback [list search-response $zz.$setNo]
1148 while {$setMax > 0 && $toGet > 0} {
1149 for {set got 0} {$got < $toGet} {incr got} {
1150 if {[$zz.$setNo recordType [expr $setOffset + $got]] == ""} {
1154 if {$got < $toGet} {
1156 $zz.$setNo present $setOffset $toGet
1157 if {[catch {egw_wait sessionWait 300}]} {
1158 egw_log debug "timeout/cancel in present"
1162 if {$sessionWait == "0"} {
1165 if {$sessionWait != "1"} {
1168 set got [$zz.$setNo numberOfRecordsReturned]
1173 display-rec $setOffset [expr $got + $setOffset - 1] $dfunc $setNo $tno
1174 set setOffset [expr $got + $setOffset]
1175 set toGet [expr 1 + $setMax - $setOffset]
1180 proc buttons-result-set-s {setNo targetNo setMax startPos after} {
1189 if {$setMax > 0 && $setMax < [$zz.$setNo resultCount]} {
1193 html {<a href="http:} $env(SCRIPT_NAME)
1194 html / $sessionId {/search.egw/} $setNo + $targetNo +
1195 html [expr $setMax + 1] + [expr $setMax + $hist($setNo,maxPresent)]
1197 html {"><img src="/egwgif/button-next-records.gif" }
1198 html {alt="Next Records" border=0></a>}
1200 html {">Next Records</a>}
1203 if {$setMax > 0 && $startPos != "" && $startPos != "1"} {
1207 html {<a href="http:} $env(SCRIPT_NAME)
1208 html / $sessionId {/search.egw/} $setNo + $targetNo
1209 html + [expr $startPos - $hist($setNo,maxPresent)]
1210 html + [expr $startPos - 1]
1212 html {"><img src="/egwgif/button-previous-records.gif" }
1213 html {alt="Previous Records" border=0></a>}
1215 html {">Previous Records</a>}
1218 if {$targetNo > 0} {
1219 button-result-set $setNo $targetNo
1221 button-new-query $setNo
1228 proc score-sort {l r} {
1229 return [expr [lindex $r 0] - [lindex $l 0]]
1232 proc display-result-set-m-score {setNo} {
1238 set not $hist($setNo,0,host)
1239 for {set i 1} {$i <= $not} {incr i} {
1240 if {$zstatus($i) != 2} continue
1241 set status [z39$i.$setNo responseStatus]
1242 if {[lindex $status 0] != "DBOSD"} continue
1243 set nor $hist($setNo,$i,offset)
1244 for {set j 1} {$j <= $nor} {incr j} {
1245 if {![string compare [z39$i.$setNo recordType $j] USmarc]} {
1246 set score [z39$i.$setNo getMarc $j field 999 * r]
1247 if {[scan $score %d score] != 1} {
1254 lappend scoreArray [list $score $i $j]
1258 if {![info exists scoreArray]} {
1259 html "<br><h3>Search produced no result</h3><br>\n"
1262 set scoreSorted [lsort -command score-sort $scoreArray]
1263 foreach r $scoreSorted {
1266 display-$hist($setNo,format) z39$i.$setNo $j $setNo $i
1270 for {set i 1} {$i <= $not} {incr i} {
1271 if {$zstatus($i) != 2} continue
1272 set status [z39$i.$setNo responseStatus]
1273 if {[lindex $status 0] == "NSD"} {
1274 z39$i.$setNo nextResultSetPosition 0
1275 set code [lindex $status 1]
1276 set msg [lindex $status 2]
1277 set addinfo [lindex $status 3]
1278 html {<dt>} [lindex $targets($hist($setNo,$i,host)) 0]
1279 html "<dd>Error: $msg: $addinfo (code $code)<br>\n"
1285 proc display-result-set-m-server {setNo} {
1293 set not $hist($setNo,0,host)
1295 for {set i 1} {$i <= $not} {incr i} {
1296 if {$zstatus($i) != 2} continue
1297 set status [z39$i.$setNo responseStatus]
1298 if {[lindex $status 0] == "NSD"} {
1299 html "<dt><h3>" [lindex $targets($hist($setNo,$i,host)) 0] ": "
1300 z39$i.$setNo nextResultSetPosition 0
1301 set code [lindex $status 1]
1302 set msg [lindex $status 2]
1303 set addinfo [lindex $status 3]
1304 html "Error</h3>\n<dd>NSD$code: $msg: $addinfo"
1306 html {<dt><a href="http:} $env(SCRIPT_NAME)
1307 html / $sessionId {/search.egw/} $setNo + $i + 1
1308 html + $hist($setNo,maxPresent) {">}
1309 html "<h3>" [lindex $targets($hist($setNo,$i,host)) 0] "</a>: "
1310 set r [z39$i.$setNo resultCount]
1311 html "$r hits</h3>\n<dd>\n"
1313 if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
1314 set nor $hist($setNo,maxPresent)
1316 set nor $hist($setNo,$i,offset)
1318 display-rec 1 $nor display-$hist($setNo,format) $setNo $i
1325 proc display-result-set-m {setNo} {
1331 egw_log debug "sort=$hist($setNo,sort)"
1332 switch $hist($setNo,sort) {
1334 display-result-set-m-score $setNo
1337 display-result-set-m-server $setNo
1342 proc display-result-set-s {setNo targetNo startPos endPos} {
1347 set host $hist($setNo,$targetNo,host)
1348 set idAuth $hist($setNo,$targetNo,idAuthentication)
1349 set database $hist($setNo,$targetNo,database)
1350 set query $hist($setNo,$targetNo,query)
1354 if {$startPos == ""} {
1355 if {[z39search $setNo 1 $targetNo B] != "1"} {
1358 set r [$zz.$setNo resultCount]
1360 set setMax [$zz.$setNo resultCount]
1361 if {$setMax > $hist($setNo,maxPresent)} {
1362 set setMax $hist($setNo,maxPresent)
1364 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1366 set setOffset [$zz.$setNo numberOfRecordsReturned]
1368 html {<h3> Records 1-} $setMax " out of $r</h3>\n"
1370 html "<h3> No hits</h3>\n"
1374 display-rec 1 $setMax display-brief $setNo $targetNo
1378 if {[z39search $setNo 0 $targetNo B] != "1"} {
1381 set r [$zz.$setNo resultCount]
1382 set setOffset $startPos
1383 set setMax [$zz.$setNo resultCount]
1384 if {$setMax > $endPos} {
1387 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1389 html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
1391 html "<h3> No hits</h3>\n"
1397 z39present $setNo $targetNo $setOffset $setMax display-brief B
1401 buttons-result-set-s $setNo $targetNo $setMax $startPos 1
1404 proc z39history {} {
1413 if {![info exists nextSetNo]} {
1416 html "<h2>History</h2><br>\n"
1418 html {<table width=500 border=1><tr>}
1419 html {<td align=center><b>Target</b>}
1420 html {<td align=center><b>Database</b>}
1421 html {<td align=center><b>Hits</b>}
1422 html {<td align=center><b>Query</b>}
1427 for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} {
1428 if {[info exists hist($setNo,scan)]} {
1429 if {$hist($setNo,scan) > 0} continue
1431 if {[info exists hist($setNo,1,host)]} {
1433 set end $hist($setNo,0,host)
1438 for {set i $start} {$i <= $end} {incr i} {
1440 html {<td align=left>}
1444 set host $hist($setNo,$i,host)
1445 html [lindex $targets($host) 0]
1447 html {<td align=left>} [join $hist($setNo,$i,database)]
1449 if {[llength [lindex $targets($host) 1]] > 1} {
1451 foreach b $hist($setNo,$i,database) {
1458 html {<td align=right>}
1460 if {[info exists hist($setNo,$i,hits)]} {
1461 html { <a href="http:} $env(SCRIPT_NAME)
1462 html / $sessionId {/search.egw/} $setNo + $i + 1
1463 html + $hist($setNo,maxPresent)
1464 html {">} $hist($setNo,$i,hits) {</a>}
1469 html {Search failed.}
1473 html {<td align=left>}
1477 html { <a href="http:} $env(SCRIPT_NAME)
1478 html / $sessionId / $scriptQuery {;/} $setNo + $host
1482 html {">Query</a>: }
1485 for {set j 1} {$j <= 10} {incr j} {
1486 if {![info exists hist($setNo,form,entry$j)]} {
1489 if {[string length $hist($setNo,form,entry$j)] > 0} {
1490 html " <b>" [join $op " "] "</b> "
1491 set pre [join $hist($setNo,form,menu$j)]
1492 if {[string length $pre] > 0} {
1495 html $hist($setNo,form,entry$j)
1496 set op $hist($setNo,form,logic$j)
1500 html {</a><tr>} "\n"
1512 proc displayError {msga msgb} {
1513 html "<p><center>\n"
1514 html {<img src="/egwgif/noway.gif" alt="Error">}
1515 html "<h2>" $msga "</h2>\n"
1516 if {[string length $msgb] > 0} {
1517 html "<h3>" $msgb "</h3>\n"
1519 html "</center><p>\n"
1522 proc button-main {} {
1524 html {<a href="http://europagate.dtv.dk/">}
1526 html {<img src="/egwgif/button-egw.gif" alt="Europagate" border=0></a>}
1528 html {Europagate</a>}
1532 proc button-feedback {} {
1535 html {<a href="http://europagate.dtv.dk/wwwquest.html">}
1537 html {<img src="/egwgif/button-user-feedback.gif" alt="User Feedback"
1541 html {User Feedback</a>}
1545 proc button-define-target {} {
1553 html {<a href="http:} $env(SCRIPT_NAME)
1554 html / $sessionId {/tform.egw}
1556 html {"><img src="/egwgif/button-define-target.gif" }
1557 html {alt="Define Target" border=0></a>}
1559 html {">Define Target</a>}
1563 proc button-new-target {} {
1569 if {[string length $scriptTarget] == 0} return
1574 html {<a href="http:} $env(SCRIPT_NAME)
1575 html / $sessionId / $scriptTarget
1577 html {"><img src="/egwgif/button-new-target.gif" }
1578 html {alt="New Target" border=0></a>}
1580 html {">New Target</a>}
1584 proc button-view-history {} {
1593 html {<a href="http:} $env(SCRIPT_NAME)
1594 html / $sessionId {/history.egw;}
1595 catch { html "/" $nextSetNo}
1597 html {"><img src="/egwgif/button-view-history.gif" alt="View History" }
1598 html {border=0></a>}
1600 html {">View History</a>}
1604 proc button-new-query {setNo} {
1614 html {<a href="http:} $env(SCRIPT_NAME)
1615 html / $sessionId / $scriptQuery {;/} $setNo + $hist($setNo,0,host) {">}
1618 html {<img src="/egwgif/button-new-query.gif" }
1619 html {alt="New Query" border=0></a>}
1621 html {New Query</a>}
1625 proc button-result-set {setNo tno} {
1634 html {<a href="http:} $env(SCRIPT_NAME) / $sessionId
1636 html {/msearch.egw/} $setNo
1638 html {/search.egw/} $setNo + $tno
1640 html + 1 + $hist($setNo,maxPresent)
1642 html {"><img src="/egwgif/button-result-set.gif" }
1643 html {alt="Result Set" border=0></a>}
1645 html {">Result Set</a>}
1649 proc button-scan-window {setNo} {
1659 html {<a href="http:} $env(SCRIPT_NAME)
1660 html / $sessionId {/search.egw/} $setNo + $targetNo + {scan} {">}
1662 html {<img src="/egwgif/button-scan-window.gif" }
1663 html {alt="Scan" border=0></a>}
1669 proc maintenance {} {
1670 html {<hr>This page is maintained by }
1671 html {<a href="mailto:nobody"> Nobody </a>.}
1672 html {Last modified x x x. <br>}
1675 proc splitHostSpec {host} {
1676 set i [string first / $host]
1679 return [string range $host 0 $i]
1684 proc splitDatabaseSpec {host} {
1685 set i [string first / $host]
1688 regsub -all -- - [string range $host $i end] { } res
1691 regsub -all -- - $host {} res
1695 proc mergeHostSpec {host databases} {
1696 return ${host}/[join $databases -]
1699 proc mkAssoc {assoc host} {
1702 if {[catch {$assoc failback fail-response}]} {
1704 $assoc maximumRecordSize 1000000
1706 if {[$assoc comstack] == "tcpip"} return
1708 $assoc maximumRecordSize 1000000
1712 proc serverList {headlineProc targetProc} {
1714 global groupsDescription
1716 proc targetsCmp {l r} {
1718 return [string compare [string tolower [lindex $targets($l) 0]] \
1719 [string tolower [lindex $targets($r) 0]]]
1721 proc groupCmp {l r} {
1723 if {[catch {set lo $groupsOrder($l)}]} {
1726 if {[catch {set ro $groupsOrder($r)}]} {
1729 return [expr $lo - $ro]
1732 foreach tt [array names targets] {
1733 lappend groupsTmp([lindex $targets($tt) 6]) $tt
1735 set gts [lsort -command groupCmp [array names groupsTmp]]
1737 if {[info exists groupsDescription($gt)]} {
1738 eval $headlineProc [list $groupsDescription($gt)]
1740 eval $headlineProc $gt
1742 set tn [lsort -command targetsCmp $groupsTmp($gt)]
1748 rename targetsCmp {}
1751 proc session-lost {} {
1754 html {<head><title>WWW/Z39.50 Gateway: Session Expired</title></head>}
1758 html {<h1>Session Expired</h1>}
1759 html {Your session has expired. Please reload the gateways' }
1760 html {front page.<br><br>} \n
1763 html {</body></html>}
1766 if {[info exists utilExtension]} {
1767 source $utilExtension