+proc buttons-result-set-s {setNo targetNo setMax startPos after} {
+ global sessionId
+ global useIcons
+ global env
+ global hist
+
+ set zz z39$targetNo
+ html "<p>\n"
+ button-main
+ if {$setMax > 0 && $setMax < [$zz.$setNo resultCount]} {
+ if {!$useIcons} {
+ html "\n | "
+ }
+ html {<a href="http:} $env(SCRIPT_NAME)
+ html / $sessionId {/search.egw/} $setNo + $targetNo +
+ html [expr $setMax + 1] + [expr $setMax + $hist($setNo,maxPresent)]
+ if {$useIcons} {
+ html {"><img src="/egwgif/button-next-records.gif" }
+ html {alt="Next Records" border=0></a>}
+ } else {
+ html {">Next Records</a>}
+ }
+ }
+ if {$setMax > 0 && $startPos != "" && $startPos != "1"} {
+ if {!$useIcons} {
+ html "\n | "
+ }
+ html {<a href="http:} $env(SCRIPT_NAME)
+ html / $sessionId {/search.egw/} $setNo + $targetNo
+ html + [expr $startPos - $hist($setNo,maxPresent)]
+ html + [expr $startPos - 1]
+ if {$useIcons} {
+ html {"><img src="/egwgif/button-previous-records.gif" }
+ html {alt="Previous Records" border=0></a>}
+ } else {
+ html {">Previous Records</a>}
+ }
+ }
+ if {$targetNo > 0} {
+ button-result-set $setNo $targetNo
+ }
+ button-new-query $setNo
+ button-new-target
+ button-view-history
+
+ html "<p>\n"
+}
+
+proc score-sort {l r} {
+ return [expr [lindex $r 0] - [lindex $l 0]]
+}
+
+proc display-result-set-m-score {setNo} {
+ global hist
+ global useIcons
+ global zstatus
+ global targets
+
+ set not $hist($setNo,0,host)
+ for {set i 1} {$i <= $not} {incr i} {
+ if {$zstatus($i) != 2} continue
+ set status [z39$i.$setNo responseStatus]
+ if {[lindex $status 0] != "DBOSD"} continue
+ set nor $hist($setNo,$i,offset)
+ for {set j 1} {$j <= $nor} {incr j} {
+ if {![string compare [z39$i.$setNo recordType $j] USmarc]} {
+ set score [z39$i.$setNo getMarc $j field 999 * r]
+ if {[scan $score %d score] != 1} {
+ set score 10
+ }
+ } else {
+ set score 10
+ }
+ if {$score > 0} {
+ lappend scoreArray [list $score $i $j]
+ }
+ }
+ }
+ if {![info exists scoreArray]} {
+ html "<br><h3>Search produced no result</h3><br>\n"
+ } else {
+ html "<ul>\n"
+ set scoreSorted [lsort -command score-sort $scoreArray]
+ foreach r $scoreSorted {
+ set i [lindex $r 1]
+ set j [lindex $r 2]
+ display-$hist($setNo,format) z39$i.$setNo $j $setNo $i
+ }
+ html "<br></ul>\n"
+ }
+ for {set i 1} {$i <= $not} {incr i} {
+ if {$zstatus($i) != 2} continue
+ set status [z39$i.$setNo responseStatus]
+ if {[lindex $status 0] == "NSD"} {
+ z39$i.$setNo nextResultSetPosition 0
+ set code [lindex $status 1]
+ set msg [lindex $status 2]
+ set addinfo [lindex $status 3]
+ html {<dt>} [lindex $targets($hist($setNo,$i,host)) 0]
+ html "<dd>Error: $msg: $addinfo (code $code)<br>\n"
+ }
+ }
+ html "\n<br>"
+}
+
+proc display-result-set-m-server {setNo} {
+ global hist
+ global useIcons
+ global zstatus
+ global targets
+ global env
+ global sessionId
+
+ set not $hist($setNo,0,host)
+ html "<dl>\n"
+ for {set i 1} {$i <= $not} {incr i} {
+ if {$zstatus($i) != 2} continue
+ set status [z39$i.$setNo responseStatus]
+ if {[lindex $status 0] == "NSD"} {
+ html "<dt><h3>" [lindex $targets($hist($setNo,$i,host)) 0] ": "
+ z39$i.$setNo nextResultSetPosition 0
+ set code [lindex $status 1]
+ set msg [lindex $status 2]
+ set addinfo [lindex $status 3]
+ html "Error</h3>\n<dd>NSD$code: $msg: $addinfo"
+ } else {
+ html {<dt><a href="http:} $env(SCRIPT_NAME)
+ html / $sessionId {/search.egw/} $setNo + $i + 1
+ html + $hist($setNo,maxPresent) {">}
+ html "<h3>" [lindex $targets($hist($setNo,$i,host)) 0] "</a>: "
+ set r [z39$i.$setNo resultCount]
+ html "$r hits</h3>\n<dd>\n"
+
+ if {$hist($setNo,$i,offset) > $hist($setNo,maxPresent)} {
+ set nor $hist($setNo,maxPresent)
+ } else {
+ set nor $hist($setNo,$i,offset)
+ }
+ display-rec 1 $nor display-$hist($setNo,format) $setNo $i
+ }
+ html "\n"
+ }
+ html "</dl>\n"
+}
+
+proc display-result-set-m {setNo} {
+ global hist
+ global useIcons
+ global zstatus
+ global targets
+
+ egw_log debug "sort=$hist($setNo,sort)"
+ switch $hist($setNo,sort) {
+ score {
+ display-result-set-m-score $setNo
+ }
+ default {
+ display-result-set-m-server $setNo
+ }
+ }
+}
+
+proc display-result-set-s {setNo targetNo startPos endPos} {
+ global hist
+ global useIcons
+
+ set zz z39$targetNo
+ set host $hist($setNo,$targetNo,host)
+ set idAuth $hist($setNo,$targetNo,idAuthentication)
+ set database $hist($setNo,$targetNo,database)
+ set query $hist($setNo,$targetNo,query)
+
+ set useIcons 1
+
+ if {$startPos == ""} {
+ if {[z39search $setNo 1 $targetNo B] != "1"} {
+ return
+ }
+ set r [$zz.$setNo resultCount]
+
+ set setMax [$zz.$setNo resultCount]
+ if {$setMax > $hist($setNo,maxPresent)} {
+ set setMax $hist($setNo,maxPresent)
+ }
+ buttons-result-set-s $setNo $targetNo $setMax $startPos 0
+
+ set setOffset [$zz.$setNo numberOfRecordsReturned]
+ if {$setMax > 0} {
+ html {<h3> Records 1-} $setMax " out of $r</h3>\n"
+ } else {
+ html "<h3> No hits</h3>\n"
+ }
+ egw_flush
+ html "<ul>\n"
+ display-rec 1 $setMax display-brief $setNo $targetNo
+ incr setOffset
+
+ } else {
+ if {[z39search $setNo 0 $targetNo B] != "1"} {
+ return
+ }
+ set r [$zz.$setNo resultCount]
+ set setOffset $startPos
+ set setMax [$zz.$setNo resultCount]
+ if {$setMax > $endPos} {
+ set setMax $endPos
+ }
+ buttons-result-set-s $setNo $targetNo $setMax $startPos 0
+ if {$setMax > 0} {
+ html {<h3> Records } $startPos {-} $setMax " out of $r</h3>\n"
+ } else {
+ html "<h3> No hits</h3>\n"
+ }
+ egw_flush
+ html "<ul>\n"
+ }
+ if {$setMax > 0} {
+ z39present $setNo $targetNo $setOffset $setMax display-brief B
+ }
+ html "</ul>\n"
+ set useIcons 0
+ buttons-result-set-s $setNo $targetNo $setMax $startPos 1
+}
+