2 # $Id: z39util.tcl,v 1.36 1996/03/07 12:46:09 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-brief {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]
87 if {$rtype == "SUTRS"} {
88 html [join [$zset getSutrs $no]]
92 if {$rtype == "WAIS"} {
93 html { <a href="http:} $env(SCRIPT_NAME) /
94 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
95 html [join [$zset getWAIS $no headline]]
101 set author [$zset getMarc $no field 100 * a]
102 set corp [$zset getMarc $no field 110 * a]
103 set meet [$zset getMarc $no field 111 * a]
104 set title [$zset getMarc $no field 245 * a]
105 if {[llength $author] == 0} {
106 set cover [$zset getMarc $no field 245 * {[bc]}]
108 set cover [$zset getMarc $no field 245 * b]
110 set location [$zset getMarc $no field 260 * a]
111 set publisher [$zset getMarc $no field 260 * b]
112 set year [$zset getMarc $no field 260 * c]
114 html { <a href="http:} $env(SCRIPT_NAME) /
115 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
147 set v [join $cover ""]
148 if {[string length $v] > 40} {
150 html [string range $v 0 38] "..."
151 } elseif {[string length $v] > 0} {
160 html { <a href="http:} $env(SCRIPT_NAME) /
161 html $sessionId {/showfull.egw/} $setNo + $targetNo + $no + full {">}
164 html "Error: " $dispError "\n"
169 proc display-raw {zset no tno} {
170 set type [$zset type $no]
172 set err [lindex [$zset diag $no] 1]
173 set add [lindex [$zset diag $no] 2]
177 html "<h3>${no}</h3>\n"
178 html "Error ${err}${add} <br>\n"
184 set rtype [$zset recordType $no]
185 if {$rtype == "SUTRS"} {
186 html [join [$zset getSutrs $no]] "<br>\n"
189 if {[catch {set r [$zset getMarc $no line * * *]}]} {
190 html "Unknown record type: $rtype <br>\n"
194 set tag [lindex $line 0]
195 set indicator [lindex $line 1]
196 set fields [lindex $line 2]
197 set l [string length $indicator]
200 for {set i 0} {$i < $l} {incr i} {
201 if {[string index $indicator $i] == " "} {
204 html [string index $tag $i]
209 foreach field $fields {
210 set id [lindex $field 0]
211 set data [lindex $field 1]
213 html " <b>\$$id</b> "
221 proc put-marc-contents {cc} {
223 if {[string first :// $cc] > 0} {
224 foreach urltype {gopher http ftp mailto} {
225 if {[string first ${urltype}:// $cc] == 0} {
240 proc dl-marc-field {zset no tag id la lb sep} {
242 set c [$zset getMarc $no field $tag * $id]
247 if {$len > 1 && "x$lb" != "x"} {
248 html "<dt><b>$lb</b>\n<dd>"
250 html "<dt><b>$la</b>\n<dd>"
256 put-marc-contents $cc
262 proc dd-marc-field {zset no tag id start stop} {
264 set c [$zset getMarc $no field $tag * $id]
271 put-marc-contents $cc
278 proc dl-marc-field-rec {zset no tag lead start stop startid sep} {
280 set lines [$zset getMarc $no line $tag * *]
281 foreach line $lines {
282 foreach field [lindex $line 2] {
284 html "<dt><b>$lead</b>"
287 set id [lindex $field 0]
288 if {$id == $startid} {
294 html [lindex $field 1]
297 html [lindex $field 1]
306 proc display-full-wais {zset no setNo targetNo} {
313 htmlToken l [join [$zset getWAIS $no text]] {
314 if {[string compare [string index $l 0] {<}]} {
315 set data($element) $l
323 set element dateOfLastModification
326 set element controlIdentifier
329 set element lastChecked
341 set element "$i,linkage"
344 set element "$i,title"
351 if {![info exists data(title)] || ![info exists data(linkage)]} {
352 html "<tt>" [join [$zset getWAIS $no text]] "</tt>\n"
355 html {Title: } {<a href="} $data(linkage) {">} $data(title) "</a><br>\n"
356 html {URL: } $data(linkage) "<br>\n"
357 html {Score: } [$zset getWAIS $no score] "<br>\n"
358 html {Lines: } [$zset getWAIS $no lines] "<br>\n"
359 if {[info exists data(bytes)]} {
360 html {Bytes: } $data(bytes) "<br>\n"
362 if {[info exists data(dateOfLastModification)]} {
363 html {Last modified: } $data(dateOfLastModification) "<br>\n"
365 if {[info exists data(lastChecked)]} {
366 html {Last checked: } $data(lastChecked) "<br>\n"
368 html {<a href="} $env(SCRIPT_NAME) / $sessionId {/sameas.egw/}
369 html $setNo + $targetNo + 1 + $hist($setNo,maxPresent) +
370 html [egw_enc [$zset getWAIS $no documentID]] {">}
371 html {Similar WAIS record</a><br>}
373 for {set i 1} {[info exists data($i,linkage)]} {incr i} {
374 html {<li><a href="} $data($i,linkage) {">}
375 html $data($i,title) "</a><br>\n"
376 html "URL: " $data($i,linkage)
381 proc display-full {zset no setNo targetNo} {
382 set type [$zset type $no]
384 set err [lindex [$zset diag $no] 1]
385 set add [lindex [$zset diag $no] 2]
389 html "Error ${err}${add} <br>\n"
395 set rtype [$zset recordType $no]
396 if {$rtype == "SUTRS"} {
397 html [join [$zset getSutrs $no]] "<br>\n"
400 if {$rtype == "WAIS"} {
401 display-full-wais $zset $no $setNo $targetNo
404 if {[catch {set r [$zset getMarc $no line * * *]}]} {
405 html "Unknown record type: $rtype <br>\n"
409 set n [dl-marc-field $zset $no 700 a "Author" "Authors" "<br>\n"]
411 set n [dl-marc-field $zset $no 100 a "Author" "Authors" "<br>\n"]
413 set n [dl-marc-field $zset $no 710 a "Corporate Name" {} ", "]
415 set n [dl-marc-field $zset $no 110 a "Corporate Name" {} ", "]
417 set n [dl-marc-field $zset $no 711 a "Meeting Name" {} ", "]
419 dd-marc-field $zset $no 711 {[bndc]} " " ""
421 set n [dl-marc-field $zset $no 111 a "Meeting Name" {} ", "]
423 dd-marc-field $zset $no 111 {[bndc]} " " " "
426 set n [dl-marc-field $zset $no 245 {a} "Title" {} " "]
428 dd-marc-field $zset $no 245 b "<em>" "</em>"
429 dd-marc-field $zset $no 245 c " " ""
431 dl-marc-field $zset $no 245 {[ab]} "Title" {} " "
433 dl-marc-field $zset $no 520 a "Abstract" {} ", "
434 dl-marc-field $zset $no 072 * "Subject code" "Subject codes" ", "
435 dl-marc-field $zset $no 650 * "Subject" {} ", "
436 dl-marc-field $zset $no 260 * "Publisher" {} " "
437 dl-marc-field $zset $no 300 * "Physical Description" {} " "
439 dl-marc-field-rec $zset $no 500 "Notes" "" "<br>\n" "a" ", "
441 dl-marc-field-rec $zset $no 510 "References" "" "<br>\n" "a" ", "
443 dl-marc-field-rec $zset $no 511 "Participant note" "" "<br>\n" "a" ", "
445 dl-marc-field $zset $no 513 a "Report type" {} ", "
446 dl-marc-field $zset $no 513 b "Period covered" {} ", "
447 dl-marc-field-rec $zset $no 515 "Numbering notes" "" "<br>\n" "a" ", "
448 dl-marc-field-rec $zset $no 516 "Data notes" "" "<br>\n" "a" ", "
449 dl-marc-field-rec $zset $no 518 "Date/time notes" "" "<br>\n" "a" ", "
451 dl-marc-field $zset $no 350 a "Price" {} ", "
452 dl-marc-field $zset $no 362 a "Dates of publication" {} ", "
453 dl-marc-field $zset $no 850 a "Holdings" {} ", "
455 dl-marc-field-rec $zset $no 270 "Contact name" "" "<br>\n" p ", "
457 set n [dl-marc-field $zset $no 270 p "Contact name" {} ", "]
462 dl-marc-field $zset $no 270 a "Street" {} ", "
463 dl-marc-field $zset $no 270 b "City" {} ", "
464 dl-marc-field $zset $no 270 c "State" {} ", "
465 dl-marc-field $zset $no 270 e "Zip code" {} ", "
466 dl-marc-field $zset $no 270 d "Country" {} ", "
467 dl-marc-field $zset $no 270 m "Network address" {} ", "
468 dl-marc-field $zset $no 301 a "Service hours" {} ", "
469 dl-marc-field $zset $no 270 k "Phone" {} ", "
470 dl-marc-field $zset $no 270 l "Fax" {} ", "
472 dl-marc-field $zset $no 270 {[abcedmakl]} "Address" {} "<br>\n"
478 dl-marc-field $zset $no 010 a "LC control number" {} ", "
479 dl-marc-field $zset $no 010 b "NUCMC control number" {} ", "
480 dl-marc-field $zset $no 020 a "ISBN" {} ", "
481 dl-marc-field $zset $no 022 a "ISSN" {} ", "
482 set url [$zset getMarc $no field 856 * u]
483 set sp [$zset getMarc $no field 856 * 3]
484 if {"x$url" != "x"} {
485 html "<dt><b>URL</b>\n"
489 html {<dd><a href="} [join $url] {">} [join $sp] "</a>\n"
491 dl-marc-field $zset $no 037 {[abc]} "Acquisition" {} "<br>\n"
492 dl-marc-field $zset $no 037 {[f6]} "Form of issue" {} "<br>\n"
493 dl-marc-field $zset $no 537 * "Source of data" {} "<br>\n"
494 dl-marc-field $zset $no 538 * "System details" {} "<br>\n"
495 dl-marc-field $zset $no 787 {[rstw6]} "Related information" {} "<br>\n"
496 dl-marc-field $zset $no 001 * "Local control number" {} ", "
501 proc display-rec {from to dfunc setNo targetNo} {
502 while {$from <= $to} {
503 eval "$dfunc z39${targetNo}.${setNo} $from $setNo $targetNo"
508 proc build-scan {t i} {
511 set term [egw_form entry$i]
513 set field [join [egw_form menu$i]]
515 foreach x [lindex $targets($t) 2] {
516 if {[lindex $x 0] == $field} {
517 set attr [lindex $x 1]
520 return [list $term $attr]
525 proc build-query {t ilines} {
530 for {set i 1} {$i <= $ilines} {incr i} {
531 set term [join [egw_form entry$i]]
532 if {[lindex $targets($t) 6] == "1"} {
533 if {[string length $op] == 0} {
538 set op [egw_form logic$i]
541 if {[string length $term] > 0} {
542 set field [join [egw_form menu$i]]
543 foreach x [lindex $targets($t) 2] {
544 if {[lindex $x 0] == $field} {
545 set attr [lindex $x 1]
550 { set q "@and $q ${attr} \"${term}\"" }
552 { set q "@or $q ${attr} \"${term}\"" }
554 { set q "@not $q ${attr} \"${term}\"" }
556 { set q "${attr} \"${term}\"" }
558 set op [egw_form logic$i]
564 proc z39scan {setNo scanNo tno scanLines scanPos cache} {
570 set host $hist($setNo,$tno,host)
571 set idAuth $hist($setNo,$tno,idAuthentication)
572 set database $hist($setNo,$tno,database)
573 set scanAttr $hist($setNo,scanAttr)
574 set scanTerm $hist($setNo,$scanNo,scanTerm)
577 if {[catch [list set oldHost [$zz connect]]]} {
580 set zs $zz.s$scanNo.$setNo
581 $zz callback ok-response
582 $zz failback fail-response
583 set thisHost [splitHostSpec $host]
584 if {[string compare $oldHost $thisHost]} {
585 catch [list $zz disconnect]
588 if {[catch [list $zz connect $thisHost]]} {
589 displayError "Cannot connect to target" $thisHost
591 } elseif {$sessionWait == 0} {
592 if {[catch {egw_wait sessionWait 300}]} {
594 displayError "Cannot connect to target" $thisHost
597 if {$sessionWait != 1} {
598 displayError "Cannot connect to target" $thisHost
602 $zz idAuthentication $idAuth
604 if {[catch {$zz init}]} {
605 displayError "Cannot initialize target" $thisHost
609 if {[catch {egw_wait sessionWait 60}]} {
610 displayError "Cannot initialize target" $thisHost
614 if {$sessionWait != "1"} {
615 displayError "Cannot initialize target" $thisHost
619 if {![$zz initResult]} {
620 set u [$zz userInformationField]
622 displayError "Cannot initialize target $thisHost" $u
626 if {$cache && ![catch [list $zs numberOfTermsRequested 5]]} {
630 eval $zz databaseNames $database
634 $zs numberOfTermsRequested $scanLines
635 $zs preferredPositionInResponse $scanPos
637 $zz callback [list scan-response $zs]
639 egw_log debug "scan: ${scanAttr} ${scanTerm}"
641 $zs scan "${scanAttr} ${scanTerm}"
643 if {[catch {egw_wait sessionWait 60}]} {
644 egw_log debug "timeout/cancel in scan"
645 displayError "Timeout in scan" {}
646 html "</body></html>\n"
650 if {$sessionWait == -1} {
651 displayError "Scan fail" "Connection closed"
652 html "</body></html>\n"
655 if {$sessionWait != 1} {
661 proc display-scan {setNo scanNo tno} {
668 set zs $zz.s$scanNo.$setNo
669 set m [$zs numberOfEntriesReturned]
672 set t [lindex [$zs scanLine 0] 1]
674 set hist($setNo,$tno,[expr $scanNo - 1],scanTerm) $t
676 set hist($setNo,[expr $scanNo - 1],scanTerm) $t
678 set t [lindex [$zs scanLine [expr $m - 1]] 1]
680 set hist($setNo,$tno,[expr $scanNo + 1],scanTerm) $t
682 set hist($setNo,[expr $scanNo + 1],scanTerm) $t
685 html {<table width=500 border=0><tr>}
686 html {<td align=left><b>Scan term</b>}
687 html {<td align=right><b>Hits</b>}
690 for {set i 0} {$i < $m} {incr i} {
691 html {<td align=left>}
693 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
694 html {<a href="http:} $env(SCRIPT_NAME)
695 html / $sessionId {/query.egw/} $hist($setNo,host) + $setNo +
696 html $hist($setNo,scan) + $tterm {">}
698 regsub -all {\ } [lindex [$zs scanLine $i] 1] + tterm
699 html {<a href="http:} $env(SCRIPT_NAME)
700 html / $sessionId {/search.egw/} $setNo + $tno +
701 html hyper + $tterm {">}
703 html [lindex [$zs scanLine $i] 1]
705 html {<td align=right>}
706 html [lindex [$zs scanLine $i] 2]
712 proc z39search {setNo piggy tno elements} {
718 set host $hist($setNo,$tno,host)
719 set idAuth $hist($setNo,$tno,idAuthentication)
720 set database $hist($setNo,$tno,database)
721 set query $hist($setNo,$tno,query)
722 catch {set docId $hist($setNo,$tno,queryId)}
725 if {[catch [list set oldHost [$zz connect]]]} {
728 $zz callback ok-response
729 $zz failback fail-response
730 set thisHost [splitHostSpec $host]
731 if {[string compare $oldHost $thisHost]} {
732 catch [list $zz disconnect]
735 if {[catch [list $zz connect $thisHost]]} {
736 displayError "Cannot connect to target" $thisHost
738 } elseif {$sessionWait == 0} {
739 if {[catch {egw_wait sessionWait 300}]} {
741 displayError "Cannot connect to target" $thisHost
744 if {$sessionWait != 1} {
745 displayError "Cannot connect to target" $thisHost
749 $zz idAuthentication $idAuth
751 if {[catch {$zz init}]} {
752 displayError "Cannot initialize target" $thisHost
756 if {$sessionWait == 0 && [catch {egw_wait sessionWait 60}]} {
757 displayError "Cannot initialize target" $thisHost
761 if {$sessionWait != "1"} {
762 displayError "Cannot initialize target" $thisHost
766 if {![$zz initResult]} {
767 set u [$zz userInformationField]
769 displayError "Cannot initialize target $thisHost" $u
772 } elseif {![catch [list $zz.$setNo smallSetUpperBound 0]]} {
774 if {[info exists hist($setNo,$tno,hits)]} {
778 if {[info exists hist($setNo,hits)]} {
784 if {[lindex $targets($host) 6] == "1"} {
785 wais-set $zz.$setNo $zz
787 ir-set $zz.$setNo $zz
789 if {![lindex $targets($host) 5]} {
792 $zz.$setNo smallSetElementSetNames $elements
793 $zz.$setNo mediumSetElementSetNames $elements
794 $zz.$setNo recordElements $elements
796 egw_log debug "database=$database"
797 eval $zz.$setNo databaseNames $database
799 $zz.$setNo preferredRecordSyntax USMARC
801 $zz callback [list search-response $zz.$setNo]
803 $zz.$setNo largeSetLowerBound 999999
804 $zz.$setNo smallSetUpperBound 0
805 $zz.$setNo mediumSetPresentNumber $hist($setNo,maxPresent)
807 $zz.$setNo largeSetLowerBound 2
808 $zz.$setNo smallSetUpperBound 0
809 $zz.$setNo mediumSetPresentNumber 0
812 egw_log debug "search: $query"
814 if {[info exists docId]} {
815 $zz.$setNo search $query $docId
817 $zz.$setNo search $query
820 if {!$sessionWait && [catch {egw_wait sessionWait 60}]} {
821 egw_log debug "timeout/cancel in search"
822 displayError "Timeout in search" {}
823 html "</body></html>\n"
828 if {$sessionWait == -1} {
829 displayError "Search fail" "Connection closed"
830 html "</body></html>\n"
833 if {$sessionWait != 1} {
836 set hist($setNo,hits) [$zz.$setNo resultCount]
840 proc init-m-response {i} {
844 egw_log debug "init-m-response"
847 if {![z39$i initResult]} {
855 proc connect-m-response {i} {
859 egw_log debug "connect-m-response"
860 z39$i callback [list init-m-response $i]
861 if {[catch {z39$i init}]} {
867 proc fail-m-response {i} {
871 egw_log debug "fail-m-response"
876 proc search-m-response {setNo i start number} {
881 egw_log debug "search-m-response"
882 set status [z39$i.$setNo responseStatus]
883 egw_log debug "search-m-response1"
884 if {[lindex $status 0] == "OK"} {
886 } elseif {[lindex $status 0] == "DBOSD"} {
887 set nor [z39$i.$setNo numberOfRecordsReturned]
889 egw_log debug "search-m-response2"
894 set hist($setNo,$i,hits) [z39$i.$setNo resultCount]
895 egw_log debug "search-m-response3"
896 set hist($setNo,$i,offset) [expr $start + $nor -1]
897 if {[expr $nor + $start] > [z39$i.$setNo resultCount]} {
898 egw_log debug "search-m-response4"
903 egw_log debug "search-m-response5"
904 if {$nor >= $number} {
905 egw_log debug "search-m-response6 nor=$nor number=$number"
910 egw_log debug "search-m-response7"
911 set start [expr $start + $nor]
912 set number [expr $number - $nor]
913 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
914 set number [expr [z39$i.$setNo resultCount] - $start + 1]
916 z39$i callback [list search-m-response $setNo $i $start $number]
917 egw_log debug "mpresent start=$number number=$number"
918 z39$i.$setNo present $start $number
921 proc z39msearch {setNo elements start number cache} {
928 set not $hist($setNo,0,host)
930 egw_log debug "z39msearch start=$start number=$number elements=$elements"
931 for {set i 1} {$i <= $not} {incr i} {
932 set host $hist($setNo,$i,host)
934 set oldHost [z39$i connect]
935 set thisHost [splitHostSpec $host]
936 if {[string compare $oldHost $thisHost]} {
937 catch {z39$i disconnect}
939 z39$i callback [list connect-m-response $i]
940 z39$i failback [list fail-m-response $i]
943 for {set i 1} {$i <= $not} {incr i} {
944 set oldHost [z39$i connect]
945 set host $hist($setNo,$i,host)
946 set thisHost [splitHostSpec $host]
947 if {![string compare $oldHost $thisHost]} {
950 egw_log debug "old=$oldHost this=$thisHost"
951 z39$i idAuthentication $hist($setNo,$i,idAuthentication)
952 html "Connecting to target " $thisHost " <br>\n"
954 if {![catch {z39$i connect $thisHost}]} {
959 egw_log debug "Waiting for init response"
960 if {[catch {egw_wait zleft 20}]} {
965 for {set i 1} {$i <= $not} {incr i} {
966 set host $hist($setNo,$i,host)
968 html "host " [splitHostSpec $host] ": "
970 egw_log debug "i=$i zstatus=$zstatus($i)"
971 if {$zstatus($i) < 1} {
977 if {[catch [list z39$i.$setNo preferredRecordSyntax USMARC]]} {
982 if {[lindex $targets($host) 6] == "1"} {
983 wais-set z39$i.$setNo z39$i
985 ir-set z39$i.$setNo z39$i
987 set hist($setNo,$i,offset) 0
988 eval z39$i.$setNo databaseNames $hist($setNo,$i,database)
990 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
993 set thisElements $elements
995 z39$i.$setNo smallSetElementSetNames $thisElements
996 z39$i.$setNo mediumSetElementSetNames $thisElements
997 z39$i.$setNo elementSetNames $thisElements
998 z39$i.$setNo recordElements $thisElements
1000 z39$i.$setNo preferredRecordSyntax USMARC
1001 z39$i callback [list search-m-response $setNo $i $start $number]
1004 z39$i.$setNo largeSetLowerBound 999999
1005 z39$i.$setNo smallSetUpperBound 0
1006 z39$i.$setNo mediumSetPresentNumber $number
1008 z39$i.$setNo largeSetLowerBound 2
1009 z39$i.$setNo smallSetUpperBound 0
1010 z39$i.$setNo mediumSetPresentNumber 0
1014 egw_log debug "setNo=$setNo msearch " $hist($setNo,$i,query)
1015 z39$i.$setNo search $hist($setNo,$i,query)
1016 } elseif {[z39$i.$setNo resultCount] >= $start} {
1017 if {[expr $start + $number - 1] > [z39$i.$setNo resultCount]} {
1018 set tnumber [expr [z39$i.$setNo resultCount] - $start + 1]
1022 if {![lindex $targets($hist($setNo,$i,host)) 5]} {
1025 set thisElements $elements
1027 z39$i.$setNo smallSetElementSetNames $thisElements
1028 z39$i.$setNo mediumSetElementSetNames $thisElements
1029 z39$i.$setNo elementSetNames $thisElements
1030 z39$i.$setNo recordElements $thisElements
1032 for {set n 0} {$n < $tnumber} {incr n} {
1033 if {[z39$i.$setNo recordType [expr $start + $n]] == ""} {
1035 egw_log debug "failed on $n"
1038 html "no record at #" [expr $start + $n]
1039 html " el=-" $thisElements "-"
1044 if {$n == $tnumber} {
1051 html "present<br>\n"
1052 z39$i.$setNo preferredRecordSyntax USMARC
1053 z39$i callback [list search-m-response $setNo $i $start $tnumber]
1055 egw_log debug "mpresent start=$start number=$tnumber"
1056 z39$i.$setNo present $start $tnumber
1063 while {$zleft > 0} {
1064 egw_log debug "Waiting for search/present response"
1065 if {[catch {egw_wait zleft 60}]} {
1069 for {set i 1} {$i <= $not} {incr i} {
1070 if {$zstatus($i) != 2} continue
1071 set status [z39$i.$setNo responseStatus]
1072 if {0 && [lindex $status 0] != "NSD"} {
1073 set hist($setNo,$i,offset) [z39$i.$setNo numberOfRecordsReturned]
1078 proc z39present {setNo tno setOffset setMax dfunc elements} {
1084 set host $hist($setNo,$tno,host)
1086 if {![lindex $targets($host) 5]} {
1090 $zz.$setNo elementSetNames $elements
1091 $zz.$setNo recordElements $elements
1092 set toGet [expr 1 + $setMax - $setOffset]
1094 $zz callback [list search-response $zz.$setNo]
1096 while {$setMax > 0 && $toGet > 0} {
1097 for {set got 0} {$got < $toGet} {incr got} {
1098 if {[$zz.$setNo recordType [expr $setOffset + $got]] == ""} {
1102 if {$got < $toGet} {
1104 $zz.$setNo present $setOffset $toGet
1105 if {[catch {egw_wait sessionWait 300}]} {
1106 egw_log debug "timeout/cancel in present"
1110 if {$sessionWait == "0"} {
1113 if {$sessionWait != "1"} {
1116 set got [$zz.$setNo numberOfRecordsReturned]
1121 display-rec $setOffset [expr $got + $setOffset - 1] $dfunc $setNo $tno
1122 set setOffset [expr $got + $setOffset]
1123 set toGet [expr 1 + $setMax - $setOffset]
1128 proc buttons-result-set-s {setNo targetNo setMax startPos after} {
1137 if {$setMax > 0 && $setMax < [$zz.$setNo resultCount]} {
1138 html {<a href="http:} $env(SCRIPT_NAME)
1139 html / $sessionId {/search.egw/} $setNo + $targetNo +
1140 html [expr $setMax + 1] + [expr $setMax + $hist($setNo,maxPresent)]
1142 html {"><img src="/egwgif/button-next-records.gif" alt="Next Records"}
1143 html { border=0></a>}
1145 html {">Next Records</a>} " | \n"
1148 if {$setMax > 0 && $startPos != "" && $startPos != "1"} {
1149 html {<a href="http:} $env(SCRIPT_NAME)
1150 html / $sessionId {/search.egw/} $setNo + $targetNo
1151 html + [expr $startPos - $hist($setNo,maxPresent)]
1152 html + [expr $startPos - 1]
1154 html {"><img src="/egwgif/button-previous-records.gif" }
1155 html {alt="Previous Records" border=0></a>}
1157 html {">Previous Records</a>} " | \n"
1160 button-new-query 1 $setNo
1162 button-view-history 0
1167 proc display-result-set-s {setNo targetNo startPos endPos} {
1172 set host $hist($setNo,$targetNo,host)
1173 set idAuth $hist($setNo,$targetNo,idAuthentication)
1174 set database $hist($setNo,$targetNo,database)
1175 set query $hist($setNo,$targetNo,query)
1179 if {$startPos == ""} {
1180 if {[z39search $setNo 1 $targetNo B] != "1"} {
1183 set r [$zz.$setNo resultCount]
1185 set setMax [$zz.$setNo resultCount]
1186 if {$setMax > $hist($setNo,maxPresent)} {
1187 set setMax $hist($setNo,maxPresent)
1189 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1191 set setOffset [$zz.$setNo numberOfRecordsReturned]
1193 html {<h3> Records 1-} $setMax " out of $r</h3>\n"
1195 html "<h3> No hits</h3>\n"
1199 display-rec 1 $setMax display-brief $setNo $targetNo
1203 if {[z39search $setNo 0 $targetNo B] != "1"} {
1206 set r [$zz.$setNo resultCount]
1207 set setOffset $startPos
1208 set setMax [$zz.$setNo resultCount]
1209 if {$setMax > $endPos} {
1212 buttons-result-set-s $setNo $targetNo $setMax $startPos 0
1214 html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
1216 html "<h3> No hits</h3>\n"
1222 z39present $setNo $targetNo $setOffset $setMax display-brief B
1226 buttons-result-set-s $setNo $targetNo $setMax $startPos 1
1229 proc z39history {} {
1238 if {![info exists nextSetNo]} {
1241 html "<h2>History</h2><br>\n"
1243 html {<table width=500 border=1><tr>}
1244 html {<td align=center><b>Target</b>}
1245 html {<td align=center><b>Database</b>}
1246 html {<td align=center><b>Hits</b>}
1247 html {<td align=center><b>Query</b>}
1252 for {set setNo 1} {$setNo < $nextSetNo} {incr setNo} {
1253 if {$hist($setNo,scan) > 0} continue
1254 set host $hist($setNo,0,host)
1256 html {<td align=left>}
1260 html [lindex $targets($host) 0]
1262 html {<td align=left>} [join $hist($setNo,0,database)]
1264 if {[llength [lindex $targets($host) 1]] > 1} {
1266 foreach b $hist($setNo,0,database) {
1273 html {<td align=right>}
1275 if {[info exists hist($setNo,hits)]} {
1276 html { <a href="http:} $env(SCRIPT_NAME)
1277 html / $sessionId {/search.egw/} $setNo + $targetNo + 1
1278 html + $hist($setNo,maxPresent)
1280 html {">} $hist($setNo,hits) {</a>}
1282 html {">Result</a>: } $hist($setNo,hits) { hits.}
1288 html {Search failed.}
1292 html {<td align=left>}
1296 html { <a href="http:} $env(SCRIPT_NAME)
1297 html / $sessionId {/query.egw/} $host + $setNo
1301 html {">Query</a>: }
1304 for {set i 1} {$i <= 3} {incr i} {
1305 if {[string length $hist($setNo,form,entry$i)] > 0} {
1306 html " <b>" [join $op " "] "</b> "
1307 html [join $hist($setNo,form,menu$i)] "="
1308 html $hist($setNo,form,entry$i)
1309 set op $hist($setNo,form,logic$i)
1313 html {</a><tr>} "\n"
1324 proc displayError {msga msgb} {
1325 html "<p><center>\n"
1326 html {<img src="/egwgif/noway.gif" alt="Error">}
1327 html "<h2>" $msga "</h2>\n"
1329 html "<h3>" $msgb "</h3>\n"
1331 html "</center><p>\n"
1334 proc button-europagate {} {
1336 html {<a href="http://europagate.dtv.dk/">}
1338 html {<img src="/egwgif/button-egw.gif" alt="Europagate" border=0></a>}
1340 html {Europagate</a> | }
1344 proc button-define-target {more} {
1349 html {<a href="http:} $env(SCRIPT_NAME)
1350 html / $sessionId {/tform.egw}
1352 html {"><img src="/egwgif/button-define-target.gif" }
1353 html {alt="Define Target" border=0></a>}
1355 html {">Define Target</a>}
1364 proc button-new-target {more} {
1370 html {<a href="http:} $env(SCRIPT_NAME)
1373 html {/mtargets.egw}
1378 html {"><img src="/egwgif/button-new-target.gif" }
1379 html {alt="New Target" border=0></a>}
1381 html {">New Target</a>}
1390 proc button-view-history {more} {
1396 html {<a href="http:} $env(SCRIPT_NAME)
1397 html / $sessionId {/history.egw;}
1398 catch { html "/" $nextSetNo}
1400 html {"><img src="/egwgif/button-view-history.gif" alt="View History" }
1401 html {border=0></a>}
1403 html {">View History</a>}
1412 proc button-new-query {more setNo} {
1419 html {<a href="http:} $env(SCRIPT_NAME)
1422 html {/mquery.egw/} $setNo
1424 html {/query.egw/} $hist($setNo,0,host) + $setNo
1428 html {<img src="/egwgif/button-new-query.gif" }
1429 html {alt="New Query" border=0></a>}
1431 html {New Query</a>}
1440 proc button-scan-window {more setNo} {
1447 html {<a href="http:} $env(SCRIPT_NAME)
1448 html / $sessionId {/search.egw/} $setNo + $targetNo + {scan} {">}
1450 html {<img src="/egwgif/button-scan-window.gif" }
1451 html {alt="Scan" border=0></a>}
1462 proc maintenance {} {
1463 html {<hr>This page is maintained by }
1464 html {<a href="mailto:pwh@dtv.dk"> Peter Wad Hansen </a>.}
1465 html {Last modified 29. january 1996. <br>}
1466 html {<em> This and the following pages are under construction and }
1467 html {will continue to be so until the end of January 1996.</em>}
1470 proc splitHostSpec {host} {
1471 set i [string last . $host]
1474 return [string range $host 0 $i]
1479 proc mergeHostSpec {host databases} {
1480 return ${host}.[join $databases -]
1483 proc mkAssoc {assoc host} {
1486 if {[catch {$assoc failback fail-response}]} {
1487 if {[lindex $targets($host) 6] == "1"} {
1493 if {[lindex $targets($host) 6] == "1"} {
1494 if {[$assoc comstack] == "wais"} return
1497 if {[$assoc comstack] == "tcpip"} return