# Copyright for the Uniform Repository Service (c) 1995 - 2022,
# by Gerald Banon. All rights reserved.
# Version 2.1
# mirrorrecent.tcl
# created in 2021-04-22 by GJFB to allow progressive loading
# example:
# http://gjfb:1905/col/dpi.inpe.br/banon/1999/06.19.17.00/doc/mirrorrecent.cgi?languagebutton=pt-BR&returnbutton=yes
# http://www.urlib.net/col/dpi.inpe.br/banon/2004/02.16.09.30.00/doc/mirrorrecent.cgi?languagebutton=pt-BR&returnbutton=yes

# ----------------------------------------------------------------------
# MirrorRecent

proc MirrorRecent {} {
if [catch {
	
if 0 {
# testing progressive loading
	puts {Content-Type: text/html}
	puts {}
	puts 1
	puts "<!-- [string repeat a 4096] -->"	;# to have the previous puts displayed
	set x 0; after 1000 {set x 1}; vwait x
	puts 2
	return
}

	global currentProcedureName	;# used in LoopOverEntries
	global currentProcedureFileName	;# used in CreateOutput and LoopOverEntries
	global env
	global cgi
	global currentRep
	global language
#	global administratorUserName	;# used in CreateReturnButton
	global homePath	;# used in CreateOutput and FindLanguage
	global URLibServiceRepository	;# used in MultipleSubmit (called in MultipleExecute2 called in CreateOutput)
	global queueLengthFlag	;# used in MultipleSubmit (called in MultipleExecute2 called in CreateOutput)
	global serverAddressWithIP	;# used in SynchronizeRepository called in sourceDisplayControl
	global mirrorHomePageRepository	;# used in LoopOverEntries to access submission.js

	puts {Content-Type: text/html}
	puts {}
	
#	array set environment [array get env]	;# used in MultipleSubmit
	set col ../../../../..
	set URLibServiceRepository dpi.inpe.br/banon/1998/08.02.08.56
	source ../$col/$URLibServiceRepository/doc/utilities1.tcl
	source ../$col/$URLibServiceRepository/doc/cgi/mirrorfind-.tcl
	source ../$col/$URLibServiceRepository/doc/utilitiesMirror.tcl	;# FindIdentifierNameFromIBI
#	set queueLengthFlag 1	;# could be anything - added by GJFB in 2013-04-17 in order to detect not writable site (site that doesn't reply)

# homePath (used in CreateReturnButton and FindLanguage)
	set homePath $env(DOCUMENT_ROOT)
# pathInfo
	set pathInfo [file split $env(PATH_INFO)]
# currentRep
	regsub -all { } [lrange $pathInfo 1 4] {/} currentRep
# mirrorIdentifier (childIdentifier)
	set mirrorIdentifier [FindIdentifierNameFromIBI $currentRep]	;# added by GJFB in 2022-06-13

	set display [GetFrameName]	;# added by GJFB in 2020-06-19 - used when setting window.name javascript property in cgi/submit mirror/xxSubmit.tcl and xxUpdateSubmission.html

	set currentProcedureName MirrorRecent
	set currentProcedureFileName $homePath/col/$URLibServiceRepository/doc/cgi/MirrorRecent.tcl

#	set serverAddress [list $env(SERVER_NAME) $env(URLIB_PORT)]
# serverAddressWithIP
	set serverAddressWithIP [list $env(IP_ADDR) $env(URLIB_PORT)]
# administratorUserName
##	regsub {@.*$} $env(SERVER_ADMIN) {} administratorUserName
#	set administratorUserName administrator

# Find the language and the language repository
	foreach {language languageRep1 languageRep2 firstLanguageRep \
	submissionFormRep submissionFormLanguage submissionFormLanguageRep} \
	[FindLanguage $currentRep] {break}
# Find the language and the language repository - end

# used with GET
# doesn't hidden password1 and codedpassword1
	if [info exists env(QUERY_STRING)] {
		if [regexp {^(.*)&(returnaddress)=(.+)$} $env(QUERY_STRING) m queryString name value] {
			set cgi($name) $value
		} else {
			set queryString $env(QUERY_STRING)
		}
		foreach {name value} [split $queryString &=] {
			set cgi([DecodeURL $name]) [DecodeURL $value]
		}
	}
if 0 {
 puts {Content-Type: text/html}
 puts {}
 puts --$env(QUERY_STRING)--
 puts <BR>
 puts <BR>
 puts --[array get cgi]--
}

	if {[info exists cgi(choice)] && [info exists cgi(outputformat)]} {	;# added by GJFB in 2021-04-25 to speed up search result display
		set choice $cgi(choice)
		set outputFormat $cgi(outputformat)
		ConditionalSet searchInputValue cgi(searchinputvalue) {}
		ConditionalSet forceRecentFlag cgi(forcerecentflag) 1
		ConditionalSet forceHistoryBackFlag cgi(forcehistorybackflag) 1	;# added by GJFB in 2023-06-09
		
# path of forceRecentFlag from xxButton.html to mirrorHomePage.html:
# xxButton.html (set forceRecentFlag to 1)
# MirrorRecent
# CreateOutput
# LoopOverEntries
# ServeLocalCollection
# GetEntry
# CreateBriefEntry
# Get
# mirror/xxCover.tcl (click '<')
# CreateMirror
# mirrorHomePage.html (uses forceRecentFlag)
	} else {	
# mirrorHomePageRepository
# used in sourceDisplayControl
		set mirrorHomePageRepository dpi.inpe.br/banon/2000/01.23.20.24	;# added by GJFB in 2018-05-28 - required in sourceDisplayControl
# Source displayControl.tcl - added by GJFB in 2018-05-28
		set enableOutput 0
		eval $sourceDisplayControl	;# required for setting choice and outputFormat only
# Source displayControl.tc - end
	}

#	set cgi(choice) $choice	;# used in LoopOverEntries when displaying the similars button with the brief choice

	set maximumNumberOfEntries $env(MAX_NUMBER_OF_ENTRIES)
	set query [list list GetMostRecentMetadataRep $currentRep $maximumNumberOfEntries]
	set query2String {}	;# needed because it is an argument of CreateOutput
	set maximumNumberOfReferences 10
	if ![info exists cgi(imageflag)] {set cgi(imageflag) 0}	;# added by GJFB in 2018-05-28 - don't display the thumbnail (if any) - required when setting choice == CreateBriefTitleAuthorEntry in displayControl.tcl
#	CreateOutput $language $languageRep1 $languageRep2 $query $query2String Recent \
	../ 0 $maximumNumberOfReferences brief
	set linkType 1	;# added by GJFB in 2018-05-28 - required to get the rep link type

	CreateOutput \
	$language $languageRep1 $languageRep2 $query $query2String Recent ../ \
	0 $maximumNumberOfReferences $choice 1 \
	^$ 0 {} $outputFormat \
	{#EEEEEE #E3E3E3} {} no \
	yes $linkType 0 \
	$cgi(targetvalue) metadatalastupdate \
	site no {} \
	short {; } $searchInputValue $mirrorIdentifier \
	$forceRecentFlag $forceHistoryBackFlag
	
	return
} m] {
	if ![string equal {} $m] {
		puts {Content-Type: text/html}
		puts {}
		puts "<PRE>MirrorRecent (2): $m</PRE>"
		if 0 {global errorInfo; puts <PRE>$errorInfo</PRE>}
	}
}
}

# MirrorRecent - end
# ----------------------------------------------------------------------
