Plugins and Language Packs for Family Historian

Add GRO Index Source Citation.fh_lua

--[[
@Title:			Add GRO Index Source Citation
@Type:				Standard
@Author:			Mike Tate
@Contributors:	Jane Taubman
@Version:			1.8
@Keywords:		
@LastUpdated:		04 Nov 2026
@Licence:			This plugin is copyright (c) 2026 Mike Tate & contributors and is licensed under the MIT License which is hereby incorporated by reference (see https://pluginstore.family-historian.co.uk/fh-plugin-licence)
@Description:		Add a GRO Index Source Citation to an Event and optionally create the event and/or set its fields.
					Saves the selected Source record(s) and options in a parameter file for each Project. If run without a project the options will need to be selected each time.
@V1.8:				Allow filename suffix; Centre windows on FH window; Check for Updates button; iup.GetParam() emulator; Earliest GRO year 1837;
@V1.0:				Derived from Add GRO Source V1.3 with options for selecting Source Records, for Where within Source v Text From Source v Event Note Only, mode of Entry Date, mode of Event date, and adding citation to Names
]]

require("iuplua")																	-- To access GUI window builder

local strVersion = "1.8"
local strPlugin = "Add GRO Index Source Citation"
local strTitle = strPlugin.."  "..strVersion

fhSetStringEncoding("UTF-8")
iup.SetGlobal("UTF8MODE","YES")
iup.SetGlobal("CUSTOMQUITMESSAGE","YES")										-- Needed for IUP 3.28

--[[
@Function:		CheckVersionInStore
@Author:			Mike Tate
@Version:			1.4
@LastUpdated:		15 Feb 2026
@Description:		Check plugin version against version in Plugin Store
@Parameter:		Plugin name and version
@Returns:			None
@Requires:		luacom
@V1.4:				Dispense with files and assume called via IUP button;
@V1.3:				Save and retrieve latest version in file;
@V1.2:				Ensure the Plugin Data folder exists;
@V1.1:				Monthly interval between checks; Report if Internet is inaccessible;
@V1.0:				Initial version;
]]

function CheckVersionInStore(strPlugin,strVersion)							-- Check if later Version available in Plugin Store

	require("luacom")
	local FSO = luacom.CreateObject("Scripting.FileSystemObject")
	local strFile = fhGetContextInfo("CI_APP_DATA_FOLDER").."\\Plugin Data\\VersionInStore "..strPlugin..".dat"
	if FSO:FileExists(strFile) then FSO:DeleteFile(strFile,true) end		-- Delete obsolete file

	local function httpRequest(strRequest)										-- Luacom http request protected by pcall() below
		local http = luacom.CreateObject("winhttp.winhttprequest.5.1")
		http:Open("GET",strRequest,false)
		http:Send()
		return http.Responsebody
	end -- local function httpRequest

	local function intVersion(strVersion)										-- Convert version string to comparable integer
		local intVersion = 0
		local arrNumbers = {}
		strVersion:gsub("(%d+)", function(strDigits) table.insert(arrNumbers,strDigits) end)
		for i = 1, 5 do
			intVersion = intVersion * 100 + tonumber(arrNumbers[i] or 0)
		end
		return intVersion
	end -- local function intVersion

	local strLatest = "0"
	if strPlugin then
		local strRequest ="http://www.family-historian.co.uk/lnk/checkpluginversion.php?name="..tostring(strPlugin)
		local isOK, strReturn = pcall(httpRequest,strRequest)
		if not isOK then																-- Problem with Internet access
			fhMessageBox(strReturn.."\n The Internet appears to be inaccessible. ")
		elseif strReturn then
			strLatest = strReturn:match("([%d%.]*),%d*")						-- Version digits & dots then comma and Id digits 
		end
	end
	local strMessage = "No later Version"
	if intVersion(strLatest) > intVersion(strVersion or "0") then
		strMessage = "Later Version "..strLatest
	end
	fhMessageBox(strMessage.." of this Plugin is available from the 'Plugin Store'.")
end -- function CheckVersionInStore

function getParamEmulator()														-- 	Prototype for iup.GetParam(...)	-- V1.8

	if fhGetAppVersion() > 6 then unpack = table.unpack end

	local iupDialog = nil
	local isSuccess = false
	local strPlugin = fhGetContextInfo("CI_PLUGIN_NAME"):gsub(" %- .*","")

	local function handleButton(iupDialog,intIndex,strTitle)					-- Handle the dialog buttons
		if intIndex == (iup.GETPARAM_OK or -1) then
			-- strTitle sometimes needed to determine the function			-- 1st button action				-- FH V5 needs -1
			isSuccess = true
		elseif intIndex == (iup.GETPARAM_CANCEL or -3) then					-- 2nd 'Cancel Plugin' button		-- FH V5 needs -3
			isSuccess = false
		elseif intIndex == (iup.GETPARAM_HELP or -4) then						-- 3rd 'Later Version?' button	-- FH V5 needs -4
			iupDialog.Active = "NO"
			CheckVersionInStore(strPlugin,strVersion)
			iupDialog.Active = "YES"
			iupDialog.BringFront = "YES"
			return 0
		end
		return 1
	end -- function handleButton

	local function makeDialog(strTitle,strFormat,arrValues)					-- Make emulated iup.GetParam(...) dialog	-- V1.8
		local arrParam = {}
		local intParam = 0
		for strForm in strFormat:gmatch(".-\n") do								-- Construct parameters format and values
			local iupParam = iup.param{ format=strForm; }
			local anyValue = nil
			if iupParam.DataType ~= "NONE" then									-- Some data types have no value
				intParam = intParam + 1
				anyValue = arrValues[intParam]
			end
			table.insert(arrParam,iup.param{ format=strForm; value=anyValue; })
		end
		local iupParams = iup.parambox{ unpack(arrParam) }
		local iupButton = iup.button{ Title="Help && Advice"; Padding="12x8"; }	-- Example of extra button
--		iupDialog = iup.dialog{ Title=strTitle; iup.vbox{ iupParams; iupButton; ALIGNMENT="ACENTER"; MARGIN="10x10"; }; close_cb=function() isSuccess = false return iup.CLOSE end; }
		iupDialog = iup.dialog{ Title=strTitle; iupParams; close_cb=function() isSuccess = false return iup.CLOSE end; }
		if fhGetAppVersion() > 6 then 											-- Window centres on FH parent
			iup.SetAttribute(iupDialog,"NATIVEPARENT",fhGetContextInfo("CI_PARENT_HWND"))
		end

		function iupParams:param_cb(intIndex)									-- Parameter call back actions
			if intIndex >= 0 then
				local iupParam = iupParams:GetParamParam(intIndex)			-- Save any parameter value
				arrValues[intIndex+1] = tonumber(iupParam.Value) or iupParam.Value
				return 1
			else
				return handleButton(iupDialog,intIndex,strTitle)				-- Handle buttons
			end
		end -- function iupParams:param_cb

		function iupButton:action(intButton)										-- Display Help Page
			local strPlugin = strPlugin:gsub(" ","-"):lower()
			fhShellExecute("https://pluginstore.family-historian.co.uk/page/help/"..strPlugin,"","","open")
			fhSleep(3000,500)
			iupDialog.BringFront = "YES"
			return 1
		end -- function iupButton:action

	end -- local function makeDialog

	local function getParam(strTitle,strSize,strFormat,...)					-- Emulate iup.GetParam(...)	-- V1.8
		local arrValues = {...}
		if fhGetAppVersion() > 6 then
			makeDialog(strTitle,strFormat,arrValues)
			if strSize then iupDialog.Size = strSize end
			iupDialog:map()
			iupDialog.MinSize = iupDialog.NaturalSize
			iupDialog:showxy(iup.CENTERPARENT,iup.CENTERPARENT)
			if iup.MainLoopLevel()==0 then iup.MainLoop() end
			iup.Destroy(iupDialog)
			iupDialog = nil
		else
			local function fncAction(iupDialog,intIndex)
				return handleButton(iupDialog,intIndex,strTitle)				-- Handle buttons
			end -- local function fncAction

			arrValues = { iup.GetParam(strTitle,fncAction,strFormat,unpack(arrValues)) }
			isSuccess = arrValues[1]
			table.remove(arrValues,1)	
		end
		return isSuccess, unpack(arrValues)
	end -- local function getParam

	return getParam

end -- function getParamEmulator

local getParam = getParamEmulator()

function doError(strMessage)
	error("\n\n "..strMessage.." - Plugin Aborted.\n\n")
end -- function doError

function addParam( arrParams, strText, strType, strTip )
	table.insert( arrParams, strText..strType.."{"..(strTip or "").."}" )
end -- function addParam

function Main()

	-- Set Lookup Tables and Prompt Dialogue
	local arrEvents = { "BIRT"; "MARR"; "DEAT"; }
	local arrGROType= { "Birth"; "Marriage"; "Death"; }
	local arrShortP = {"Q1";"Q2";"Q3";"Q4";"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec";}
	local arrPeriod = {"Q1 Jan-Feb-Mar";"Q2 Apr-May-Jun";"Q3 Jul-Aug-Sep";"Q4 Oct-Nov-Dec";"January";"February";"March";"April";"May";"June";"July";"August";"September";"October";"November";"December";}
	local strPeriod = table.concat(arrPeriod,"|")
	local strIfDate = "|No Event Date|Year Only Event Date|Inexact Event Date|"
	local strFields = "|Where within Source|Text From Source|Event Note Only|"
	local strAssess = "|None |Unreliable |Questionable |Secondary Evidence  |Primary Evidence  |"
	local tblAssess = { "Unreliable"; "Questionable"; "Secondary Evidence"; "Primary Evidence"; "<clear assessment>"; }
	local arrParams = { "%t" }
	addParam( arrParams, "GRO Index Type:"                        , "%l|  Birth  |  Marriage  |  Death  |"         , "Type of GRO Index Event" )
	addParam( arrParams, "Registration Year:"                     , "%i"                                           , "Registration Year for the Event" )
	addParam( arrParams, "Registration Quarter or Month:"         , "%l|"..strPeriod.."|"                          , "Registration Quarter or Month"   )
	addParam( arrParams, "Registration District:"                 , "%s"                                           , "Registration District Placename" )
	addParam( arrParams, "GRO Index Reference && Names:"          , "%s"                                           , "GRO Index Volume, Page & Names"  )
	addParam( arrParams, "Mothers Maiden Name (Birth only):"      , "%s"                                           , "Applies to GRO Birth Index only" )
	addParam( arrParams, "Recorded Age at Death (Death only):"    , "%s"                                           , "Applies to GRO Death Index only" )
	addParam( arrParams, "Put GRO Index Date in Event Date when:" , "%l"..strIfDate                                , "Overwrite Event Date Criteria"   )
	addParam( arrParams, "Select Citation Reference Field:"       , "%l"..strFields                                , "Which Citation Field for References?" )
	addParam( arrParams, "If 'Event Note Only' selected, ignore settings below" , "%t" )
	addParam( arrParams, "Birth Source Record Id:"                , "%i"                                           , "GRO Birth Index Source Record Id"    )
	addParam( arrParams, "Marriage Source Record Id:"             , "%i"                                           , "GRO Marriage Index Source Record Id" )
	addParam( arrParams, "Death Source Record Id:"                , "%i"                                           , "GRO Death Index Source Record Id"    )
	addParam( arrParams, "Set Citation Entry Date:"               , "%l|No Date|Today's Date|GRO Index Reg Date |" , "Citation Entry Date" )
	addParam( arrParams, "Set Citation Assessment:"               , "%l"..strAssess                                , "Citation Assessment" )
	addParam( arrParams, "Add Citation to Name:"                  , "%b[  No ,  Yes ]"                             , "Add Citation to Name of Person/Spouses?" )
	addParam( arrParams, "Button Names:"                          , "%u[ Add GRO Index , Cancel Plugin , Later Version? ]" )	-- V1.8
	local strParams = table.concat(arrParams,"\n").."\n"

	-- Set Parameter Default Values
	local intPtype = 0			-- GRO Index Event Type
	local intPyear = 1837		-- Registration Year
	local intPquat = 0			-- Registration Quarter or Month
	local strPdist = ""			-- Registration District
	local strPrefn = ""			-- GRO Index Reference
	local strPmaid = ""			-- Mothers Maiden Name
	local strPaged = ""			-- Age at Death
	local intPeven = 0			-- Overwrite Event Date Criteria
	local intPcite = 0			-- Select Citation Field for Ref
	local intPbirt = nil		-- Source Record Id Birth
	local intPmarr = nil		-- Source Record Id Marriage
	local intPdeat = nil		-- Source Record Id Death
	local intPdate = 0			-- Select Citation Entry Date
	local intPqual = 0			-- Select Citation Assessment
	local intPname = 0			-- Add Citation to Name?

	-- Get Parameters from Previous Sticky Data
	local strParamFile = fhGetPluginDataFileName():gsub(" %- V%d.-dat$",".dat")	-- V1.8
	local strChunk = fhLoadTextFile(strParamFile)
	if strChunk then
		local doChunk = load(strChunk)
		intPeven, intPcite, intPbirt, intPmarr, intPdeat, intPdate, intPqual, intPname = doChunk()
	end

	-- Otherwise Select Source Records
	if intPbirt == nil then
		local strAns = "Retry"
		while strAns == "Retry" do
			strAns = ""
			fhMessageBox("\n Please select just one generic GRO Index source record. \n                        ALTERNATIVELY \n Select 3 source records for Birth, Marriage, and Death, \n ensuring they are in that order in the righthand pane. \n","MB_OK","MB_ICONINFORMATION")
			-- Get Source Records to use.
			local ptrList = fhPromptUserForRecordSel("SOUR",3)
			if #ptrList == 0 then
				strAns = fhMessageBox("\n No source records have been selected ...\n\n   Click  'Abort'  to cancel the plugin\n   Click  'Retry'    to select the sources again\n   Click  'Ignore'  to continue without sources \n","MB_ABORTRETRYIGNORE","MB_ICONQUESTION")
				if strAns == "Abort" then return end
				intPbirt = 0
				intPmarr = 0
				intPdeat = 0
			elseif #ptrList == 1 then
				intPbirt = fhGetRecordId(ptrList[1])
				intPmarr = fhGetRecordId(ptrList[1])
				intPdeat = fhGetRecordId(ptrList[1])
			elseif #ptrList == 2 then
				strAns = fhMessageBox("\n Only two source records were selected ...\n\n   Click  'Retry'    to select the sources again \n   Click  'Cancel'  to cancel the plugin \n","MB_RETRYCANCEL","MB_ICONQUESTION")
				if strAns == "Cancel" then return end
			else --#ptrList == 3 then
				intPbirt = fhGetRecordId(ptrList[1])
				intPmarr = fhGetRecordId(ptrList[2])
				intPdeat = fhGetRecordId(ptrList[3])
			end
		end
	end

	-- Get Current Individual Record if Available
	local ptrList = fhGetCurrentRecordSel("INDI")
	if #ptrList == 1 then
		strName = "Current Record: "..fhGetItemText(ptrList[1],"~.NAME"):gsub("%%","%%%%").." ("..fhCallBuiltInFunction("LifeDates",ptrList[1])..")"
	else
		strName = "No record selected"
	end

	-- Get GRO Information Parameters
	local isOK
	isOK,	intPtype, intPyear, intPquat, strPdist, strPrefn, strPmaid, strPaged, intPeven, intPcite, intPbirt, intPmarr, intPdeat, intPdate, intPqual, intPname = getParam(strTitle, nil, strName..strParams,	-- V1.8
			intPtype, intPyear, intPquat, strPdist, strPrefn, strPmaid, strPaged, intPeven, intPcite, intPbirt, intPmarr, intPdeat, intPdate, intPqual, intPname )
	-- Check for Cancel
	if not isOK then return end

	-- Save Sticky Parameters
	if fhGetContextInfo("CI_APP_MODE") == "Project Mode" then
		local strParams = "return "..intPeven..","..intPcite..","..intPbirt..","..intPmarr..","..intPdeat..","..intPdate..","..intPqual..","..intPname.."\n"
		fhSaveTextFile(strParamFile, strParams, "UTF-8")
	end

	-- Select Source Record
	local intSource = 0
	local intEvent = intPtype + 1
	if intEvent == 1 then intSource = intPbirt end
	if intEvent == 2 then intSource = intPmarr end
	if intEvent == 3 then intSource = intPdeat end
	local ptrSource = fhNewItemPtr()
	ptrSource:MoveToRecordById("SOUR",intSource)
	if ptrSource:IsNull() then
		doError("Source Record Id "..intSource.." Not Found")
	end

	-- Obtain Desired Record
	if intPtype == 1 then
		ptrList = fhGetCurrentRecordSel("FAM")
		if #ptrList == 0 then
			ptrList = fhGetCurrentRecordSel("INDI")
			if #ptrList == 1 then
				ptrList = getSpouseFamilies(ptrList[1])
			end
		end
		if #ptrList ~= 1 then
			ptrList = fhPromptUserForRecordSel("FAM",1)
		end
	else
		ptrList = fhGetCurrentRecordSel("INDI")
		if #ptrList ~= 1 then
			ptrList = fhPromptUserForRecordSel("INDI",1)
		end
	end
	if #ptrList == 0 then
		doError("No Principal Record Selected")
	end

	-- Check Registration Year
	if intPyear < 1837 then
		doError("Registration Year before 1837")
	end

	-- Event Note Only inhibits Citation options
	if intPcite == 2 then
		intPdate = 0
		intPqual = 0
		intPname = 0
	end

	local ptrEvent = fhNewItemPtr()
	local ptrField = fhNewItemPtr()
	ptrEvent:MoveTo(ptrList[1],"~."..arrEvents[intEvent])
	if ptrEvent:IsNull() then
		-- Create Event
		ptrEvent = fhCreateItem(arrEvents[intEvent],ptrList[1])
	end

	-- Set Event Date
	ptrField:MoveTo(ptrEvent,"~.DATE")
	if ptrField:IsNull() then
		ptrField = fhCreateItem("DATE",ptrEvent)
	end
	local dtDate = fhGetValueAsDate(ptrField)
	local dpOne = dtDate:GetDatePt1()
	local dpTwo = dtDate:GetDatePt2()
	local Month = dpOne:GetMonth()
	local DayNo = dpOne:GetDay()
	if intPeven >= 0 and dpOne:IsNull()        and dpTwo:IsNull()
	or intPeven >= 1 and dpOne:GetMonth() == 0 and dpTwo:GetMonth() == 0
	or intPeven >= 2 and dpOne:GetDay()   == 0 and dpTwo:GetDay()   == 0
	then
		dtDate:SetValueAsText(arrShortP[intPquat + 1].." "..intPyear)
		fhSetValueAsDate(ptrField,dtDate)
	end

	-- Set Event Place & Address
	strPdist = promptPlace(strPdist)
	ptrField:MoveTo(ptrEvent,"~.PLAC")
	if ptrField:IsNull() then
		ptrField = fhCreateItem("PLAC",ptrEvent)
	end
	if fhGetValueAsText(ptrField) == "" then
		fhSetValueAsText(ptrField,strPdist)
		-- If Place was added, add "Registration District" as the Address field
		ptrField:MoveTo(ptrEvent,"~.ADDR")
		if ptrField:IsNull() then
			ptrField = fhCreateItem("ADDR",ptrEvent)
		end
		if fhGetValueAsText(ptrField) == "" then
			fhSetValueAsText(ptrField,"Registration District")
		end
	end

	-- For Death Add age if entered
	if intEvent == 3 and strPaged:len() > 0 then
		ptrField:MoveTo(ptrEvent,"~.AGE")
		if ptrField:IsNull() then
			ptrField = fhCreateItem("AGE",ptrEvent)
			fhSetValueAsText(ptrField,strPaged)
		end
	end

	-- Add Source Citation
	local strQtr = arrPeriod[intPquat + 1]
	local strAge = arrGROType[intEvent].." "..strQtr.." "..intPyear.." "..strPdist.." "..strPrefn
	if intEvent == 1 and strPmaid:len() > 1 then
		strAge = strAge.." Mothers Maiden Name: "..strPmaid
	end
	if intEvent == 3 and strPaged:len() > 0 then
		strAge = strAge.." Age: "..strPaged
	end
	local eDate = nil
	if intPdate > 0 then
		-- Record Entry Date
		eDate = fhNewDate()
		if intPdate == 1 then
			eDate:SetSimpleDate(fhCallBuiltInFunction("today"))
		else
			eDate:SetValueAsText(arrShortP[intPquat + 1].." "..intPyear)
		end
	end

	-- Add Citation to Event
	addSource(ptrEvent,ptrSource,strAge,intPcite,eDate,tblAssess[intPqual])

	-- Add Citation to Name(s)
	local tblTags = { {"~.NAME[1]"}; {"~.HUSB[1]>NAME[1]"; "~.WIFE[1]>NAME[1]"; "~.HUSB[2]>NAME[1]"; "~.WIFE[2]>NAME[1]"}; {"~.NAME[1]"}; }
	if intPname > 0 then
		for _, strTag in ipairs ( tblTags[intEvent] ) do
			ptrField:MoveTo(ptrList[1],strTag)
			if ptrField:IsNotNull() then
				addSource(ptrField,ptrSource,strAge,intPcite,eDate,tblAssess[intPqual])
			end
		end
	end

	-- Check Data
	ptrField:MoveTo(ptrEvent,"~.DATE")
	local strResult = fhCallBuiltInFunction("GetDataWarning",ptrField,1)
	if strResult ~= "" then
		local strButton = fhMessageBox(strResult.."\nDo you wish to undo the entry?","MB_YESNO","MB_ICONEXCLAMATION")
		if strButton == "Yes" then
			doError("Date Validation Failed")
		end
	end

end -- function Main

function addSource(ptrFact,ptrSource,strAge,intCite,eDate,strAssess)
	if intCite == 2 then -- Event Note Only
		local ptrNote = fhNewItemPtr()
		ptrNote:MoveTo(ptrFact,"~.NOTE2")
		if ptrNote:IsNull() then
			ptrNote = fhCreateItem("NOTE2",ptrFact)								-- FACT.NOTE2
		end
		local strNote = fhGetValueAsText(ptrNote)
		if strNote ~= "" then strNote = strNote.."\n" end
		strNote = strNote.."GRO Index "..strAge
		fhSetValueAsText(ptrNote,strNote)
	else -- intCite ~= 2 -- Add Citation
		local ptrCite = fhCreateItem("SOUR",ptrFact)							-- FACT.SOUR
		fhSetValueAsLink(ptrCite,ptrSource)
		local ptrData = fhNewItemPtr()
		local ptrAge  = fhNewItemPtr()
		if eDate or intCite == 1 then
			ptrData = fhCreateItem("DATA",ptrCite)								-- FACT.SOUR.DATA
		end
		if eDate then
			local ptrDate = fhCreateItem("DATE",ptrData)						-- FACT.SOUR.DATA.DATE
			fhSetValueAsDate(ptrDate,eDate)
		end
		if strAssess then
			ptrQuay = fhCreateItem("QUAY",ptrCite)								-- FACT.SOUR.QUAY
			fhSetValueAsText(ptrQuay,strAssess)
		end
		if intCite == 0 then
			ptrAge = fhCreateItem("PAGE",ptrCite)								-- FACT.SOUR.PAGE
		else
			ptrAge = fhCreateItem("TEXT",ptrData)								-- FACT.SOUR.DATA.TEXT
		end
		fhSetValueAsText(ptrAge,strAge)
	end
end -- function addSource

function getSpouseFamilies(ptrIndi)
	local arrFams = {}
	local ptrFams = fhNewItemPtr()
	ptrFams:MoveTo(ptrIndi,"~.FAMS")
	while ptrFams:IsNotNull() do
		table.insert(arrFams,fhGetValueAsLink(ptrFams))
		ptrFams:MoveNext("SAME_TAG")
	end
	return arrFams
end -- function getSpouseFamilies

function promptPlace(strDistrict)
	local arrPlaces = placeList(strDistrict)									-- List of Place names matching Registration District entered
	local arrPrompt = {}
	addParam( arrPrompt, "Please select a Place from the list or "	, "%t" )
	addParam( arrPrompt, "use the entry box to enter a Place name "	, "%t" )
	addParam( arrPrompt, "  Enter the District Place name: "			, "%s" )
	addParam( arrPrompt, "  Select from District Place list: "		, "%l|Use Place Above|"..table.concat(arrPlaces,"|").."|" )
	addParam( arrPrompt, "Button Names: "								, "%u[ Use District Place name entered , Use District Place selected from list ]" )	-- V1.8
	local strPrompt = table.concat(arrPrompt,"\n").."\n"
	local isOK, strPlace, intPlace = getParam("Select District Place Name", nil, strPrompt, strDistrict, 0)			-- V1.8
	if not isOK and intPlace > 0 then
		strPlace = arrPlaces[intPlace]											-- V1.8
	end
	return strPlace
end -- function promptPlace

function placeList(strFind)
	strFind = strFind:lower()
	local arrPlac = {}
	local ptrPlac = fhNewItemPtr()
	ptrPlac:MoveToFirstRecord("_PLAC")
	while ptrPlac:IsNotNull() do
		local strPlac = fhGetDisplayText(ptrPlac)
		if strPlac:lower():find(strFind) then
			table.insert(arrPlac,strPlac)
		end
		ptrPlac:MoveNext()
	end
	table.sort(arrPlac)
	return arrPlac
end -- function placeList

-- Main Code Section Starts Here --

	fhInitialise(7,0,10,"save_recommended")

	Main()

Source: Add-GRO-Index-Source-Citation-1.fh_lua